From 72dd54eaa85f6b04bbc756bac3fe4e45f2d05991 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Fri, 23 Jan 2026 12:27:43 -0700 Subject: [PATCH] cpukit/libcsupport: reformat src with clang-format excludes cfmakeraw.c, cfmakesane.c, realpath.c Updates #3860. Closes #5355. --- cpukit/libcsupport/src/__assert.c | 9 +- cpukit/libcsupport/src/__getpid.c | 4 +- cpukit/libcsupport/src/__gettod.c | 15 +- cpukit/libcsupport/src/__times.c | 31 +- cpukit/libcsupport/src/__usrenv.c | 71 +- cpukit/libcsupport/src/_calloc_r.c | 8 +- cpukit/libcsupport/src/_free_r.c | 7 +- cpukit/libcsupport/src/_malloc_r.c | 7 +- cpukit/libcsupport/src/_realloc_r.c | 8 +- cpukit/libcsupport/src/_rename_r.c | 26 +- cpukit/libcsupport/src/access.c | 17 +- cpukit/libcsupport/src/alignedalloc.c | 7 +- cpukit/libcsupport/src/assoc32tostring.c | 2 +- cpukit/libcsupport/src/assoclocalbyname.c | 12 +- cpukit/libcsupport/src/assoclocalbyremote.c | 7 +- .../src/assoclocalbyremotebitfield.c | 20 +- cpukit/libcsupport/src/assocnamebad.c | 22 +- cpukit/libcsupport/src/assocnamebylocal.c | 9 +- .../src/assocnamebylocalbitfield.c | 15 +- cpukit/libcsupport/src/assocnamebyremote.c | 10 +- .../src/assocnamebyremotebitfield.c | 16 +- cpukit/libcsupport/src/assocptrbylocal.c | 11 +- cpukit/libcsupport/src/assocptrbyname.c | 14 +- cpukit/libcsupport/src/assocptrbyremote.c | 13 +- cpukit/libcsupport/src/assocremotebylocal.c | 9 +- .../src/assocremotebylocalbitfield.c | 21 +- cpukit/libcsupport/src/assocremotebyname.c | 7 +- .../src/assocthreadstatestostring.c | 50 +- cpukit/libcsupport/src/base_fs.c | 10 +- cpukit/libcsupport/src/cachealignedalloc.c | 2 +- cpukit/libcsupport/src/cachecoherentalloc.c | 15 +- cpukit/libcsupport/src/calloc.c | 11 +- cpukit/libcsupport/src/cfgetispeed.c | 6 +- cpukit/libcsupport/src/cfgetospeed.c | 6 +- cpukit/libcsupport/src/cfsetispeed.c | 10 +- cpukit/libcsupport/src/cfsetospeed.c | 10 +- cpukit/libcsupport/src/cfsetspeed.c | 10 +- cpukit/libcsupport/src/chdir.c | 9 +- cpukit/libcsupport/src/chmod.c | 8 +- cpukit/libcsupport/src/chown.c | 8 +- cpukit/libcsupport/src/chroot.c | 13 +- cpukit/libcsupport/src/clock.c | 2 +- cpukit/libcsupport/src/clonenode.c | 4 +- cpukit/libcsupport/src/close.c | 19 +- cpukit/libcsupport/src/consolesimple.c | 10 +- cpukit/libcsupport/src/consolesimple.h | 6 +- cpukit/libcsupport/src/consolesimpleread.c | 12 +- cpukit/libcsupport/src/consolesimpletask.c | 28 +- cpukit/libcsupport/src/ctermid.c | 9 +- cpukit/libcsupport/src/dup.c | 4 +- cpukit/libcsupport/src/dup2.c | 15 +- cpukit/libcsupport/src/error.c | 93 +- cpukit/libcsupport/src/fchdir.c | 8 +- cpukit/libcsupport/src/fchmod.c | 17 +- cpukit/libcsupport/src/fchown.c | 14 +- cpukit/libcsupport/src/fcntl.c | 75 +- cpukit/libcsupport/src/fdatasync.c | 6 +- cpukit/libcsupport/src/flockfile.c | 4 +- cpukit/libcsupport/src/fpathconf.c | 9 +- cpukit/libcsupport/src/free.c | 20 +- cpukit/libcsupport/src/freenode.c | 2 +- cpukit/libcsupport/src/fstat.c | 22 +- cpukit/libcsupport/src/fsync.c | 6 +- cpukit/libcsupport/src/ftruncate.c | 2 +- cpukit/libcsupport/src/ftrylockfile.c | 4 +- cpukit/libcsupport/src/funlockfile.c | 4 +- cpukit/libcsupport/src/futimens.c | 16 +- cpukit/libcsupport/src/getdents.c | 18 +- cpukit/libcsupport/src/getgrent.c | 69 +- cpukit/libcsupport/src/getgrnam.c | 16 +- cpukit/libcsupport/src/getgroups.c | 39 +- cpukit/libcsupport/src/getlogin.c | 18 +- cpukit/libcsupport/src/getpagesize.c | 2 +- cpukit/libcsupport/src/getpid.c | 6 +- cpukit/libcsupport/src/getpwent.c | 42 +- cpukit/libcsupport/src/getreentglobal.c | 4 +- cpukit/libcsupport/src/getrusage.c | 37 +- cpukit/libcsupport/src/getuid.c | 1 - cpukit/libcsupport/src/ioctl.c | 20 +- cpukit/libcsupport/src/isatty_r.c | 9 +- cpukit/libcsupport/src/issetugid.c | 6 +- cpukit/libcsupport/src/kill_noposix.c | 4 +- cpukit/libcsupport/src/lchown.c | 8 +- cpukit/libcsupport/src/libio.c | 40 +- cpukit/libcsupport/src/libio_exit.c | 8 +- cpukit/libcsupport/src/libio_init.c | 21 +- cpukit/libcsupport/src/link.c | 16 +- cpukit/libcsupport/src/lseek.c | 10 +- cpukit/libcsupport/src/malloc.c | 22 +- cpukit/libcsupport/src/malloc_deferred.c | 9 +- cpukit/libcsupport/src/malloc_dirtier.c | 7 +- cpukit/libcsupport/src/malloc_walk.c | 2 +- cpukit/libcsupport/src/mallocextenddefault.c | 4 +- cpukit/libcsupport/src/mallocinfo.c | 7 +- cpukit/libcsupport/src/mallocsetheapptr.c | 4 +- cpukit/libcsupport/src/mkdir.c | 7 +- cpukit/libcsupport/src/mkfifo.c | 5 +- cpukit/libcsupport/src/mknod.c | 27 +- cpukit/libcsupport/src/mount-mgr.c | 62 +- cpukit/libcsupport/src/mount-mktgt.c | 22 +- cpukit/libcsupport/src/mount.c | 94 +- cpukit/libcsupport/src/newlibc_exit.c | 14 +- cpukit/libcsupport/src/newlibc_reent.c | 16 +- cpukit/libcsupport/src/open.c | 67 +- cpukit/libcsupport/src/open_dev_console.c | 5 +- cpukit/libcsupport/src/pathconf.c | 8 +- cpukit/libcsupport/src/posix_devctl.c | 35 +- cpukit/libcsupport/src/posix_memalign.c | 6 +- cpukit/libcsupport/src/print_fprintf.c | 6 +- cpukit/libcsupport/src/print_printf.c | 6 +- cpukit/libcsupport/src/printerfprintfputc.c | 24 +- cpukit/libcsupport/src/printertask.c | 19 +- cpukit/libcsupport/src/printf_plugin.c | 6 +- cpukit/libcsupport/src/printk.c | 10 +- cpukit/libcsupport/src/printk_plugin.c | 10 +- cpukit/libcsupport/src/privateenv.c | 70 +- cpukit/libcsupport/src/putk.c | 11 +- cpukit/libcsupport/src/pwdgrp.c | 262 ++- cpukit/libcsupport/src/pwdgrp.h | 14 +- cpukit/libcsupport/src/read.c | 16 +- cpukit/libcsupport/src/readlink.c | 17 +- cpukit/libcsupport/src/readv.c | 6 +- cpukit/libcsupport/src/realloc.c | 8 +- cpukit/libcsupport/src/resource_snapshot.c | 63 +- cpukit/libcsupport/src/rmdir.c | 15 +- cpukit/libcsupport/src/rtems_heap_extend.c | 9 +- .../src/rtems_heap_extend_via_sbrk.c | 7 +- cpukit/libcsupport/src/rtems_heap_greedy.c | 19 +- .../libcsupport/src/rtems_heap_null_extend.c | 2 +- .../libcsupport/src/rtems_heap_sbrk_greedy.c | 9 +- cpukit/libcsupport/src/rtems_memalign.c | 18 +- cpukit/libcsupport/src/rtems_mkdir.c | 76 +- cpukit/libcsupport/src/rtemscalloc.c | 4 +- cpukit/libcsupport/src/setegid.c | 4 +- cpukit/libcsupport/src/setgid.c | 4 +- cpukit/libcsupport/src/setgroups.c | 10 +- cpukit/libcsupport/src/setpgid.c | 5 +- cpukit/libcsupport/src/setuid.c | 4 +- cpukit/libcsupport/src/stat.c | 20 +- cpukit/libcsupport/src/statvfs.c | 10 +- .../src/sup_fs_check_permissions.c | 55 +- cpukit/libcsupport/src/sup_fs_deviceio.c | 40 +- cpukit/libcsupport/src/sup_fs_eval_path.c | 185 +- .../src/sup_fs_eval_path_generic.c | 82 +- .../src/sup_fs_exist_in_same_instance.c | 4 +- cpukit/libcsupport/src/sup_fs_location.c | 142 +- cpukit/libcsupport/src/sup_fs_mount_iterate.c | 12 +- cpukit/libcsupport/src/sup_fs_next_token.c | 16 +- cpukit/libcsupport/src/symlink.c | 13 +- cpukit/libcsupport/src/tcdrain.c | 6 +- cpukit/libcsupport/src/tcflow.c | 9 +- cpukit/libcsupport/src/tcflush.c | 24 +- cpukit/libcsupport/src/tcgetattr.c | 7 +- cpukit/libcsupport/src/tcgetpgrp.c | 4 +- cpukit/libcsupport/src/tcsendbreak.c | 6 +- cpukit/libcsupport/src/tcsetattr.c | 29 +- cpukit/libcsupport/src/tcsetpgrp.c | 6 +- cpukit/libcsupport/src/termios.c | 1964 +++++++++-------- cpukit/libcsupport/src/termios_baud2index.c | 110 +- cpukit/libcsupport/src/termios_baud2num.c | 4 +- cpukit/libcsupport/src/termios_baudtable.c | 46 +- cpukit/libcsupport/src/termios_num2baud.c | 4 +- cpukit/libcsupport/src/termios_setbestbaud.c | 10 +- .../libcsupport/src/termios_setinitialbaud.c | 6 +- cpukit/libcsupport/src/termiosinitialize.c | 10 +- cpukit/libcsupport/src/truncate.c | 8 +- cpukit/libcsupport/src/uenvgetgroups.c | 4 +- cpukit/libcsupport/src/umask.c | 2 +- cpukit/libcsupport/src/unlink.c | 22 +- cpukit/libcsupport/src/unmount.c | 22 +- cpukit/libcsupport/src/utime.c | 15 +- cpukit/libcsupport/src/utimensat.c | 79 +- cpukit/libcsupport/src/utimes.c | 21 +- cpukit/libcsupport/src/utsname.c | 26 +- cpukit/libcsupport/src/write.c | 8 +- cpukit/libcsupport/src/write_r.c | 8 +- cpukit/libcsupport/src/writev.c | 6 +- 177 files changed, 2810 insertions(+), 2763 deletions(-) diff --git a/cpukit/libcsupport/src/__assert.c b/cpukit/libcsupport/src/__assert.c index 8b27952446..a2b9f130f3 100644 --- a/cpukit/libcsupport/src/__assert.c +++ b/cpukit/libcsupport/src/__assert.c @@ -40,7 +40,7 @@ #include #include -#if defined(RTEMS_NEWLIB) && !defined(HAVE___ASSERT_FUNC) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE___ASSERT_FUNC ) #include /** @@ -61,12 +61,13 @@ void __assert_func( .failed_expression = failedexpr }; - printk("assertion \"%s\" failed: file \"%s\", line %d%s%s\n", + printk( + "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", failedexpr, file, line, - (func) ? ", function: " : "", - (func) ? func : "" + ( func ) ? ", function: " : "", + ( func ) ? func : "" ); rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, (rtems_fatal_code) &assert_context ); } diff --git a/cpukit/libcsupport/src/__getpid.c b/cpukit/libcsupport/src/__getpid.c index aafca3f125..011c8b09c5 100644 --- a/cpukit/libcsupport/src/__getpid.c +++ b/cpukit/libcsupport/src/__getpid.c @@ -42,13 +42,13 @@ /* * Prototype to avoid warning */ -pid_t __getpid(void); +pid_t __getpid( void ); /** * Some C Libraries reference this routine since they think getpid is * a real system call. */ -pid_t __getpid(void) +pid_t __getpid( void ) { return getpid(); } diff --git a/cpukit/libcsupport/src/__gettod.c b/cpukit/libcsupport/src/__gettod.c index b43081c9eb..a1b900e2cb 100644 --- a/cpukit/libcsupport/src/__gettod.c +++ b/cpukit/libcsupport/src/__gettod.c @@ -37,7 +37,7 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) /* * Needed to get the prototype for the newlib helper method */ @@ -49,7 +49,7 @@ #include #include -#if defined(RTEMS_NEWLIB) && !defined(HAVE_GETTIMEOFDAY) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE_GETTIMEOFDAY ) /** * SVR4 and BSD4.3 extension required by Newlib @@ -62,8 +62,9 @@ int gettimeofday( ) { /* struct timezone* tzp = (struct timezone*) __tz; */ - if ( !tp ) + if ( !tp ) { rtems_set_errno_and_return_minus_one( EFAULT ); + } /* * POSIX does not seem to allow for not having a TOD so we just @@ -81,7 +82,7 @@ int gettimeofday( } #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE__GETTIMEOFDAY_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__GETTIMEOFDAY_R ) #include @@ -89,9 +90,9 @@ int gettimeofday( * "Reentrant" version */ int _gettimeofday_r( - struct _reent *ignored_reentrancy_stuff RTEMS_UNUSED, - struct timeval *tp, - void *__tz + struct _reent *ignored_reentrancy_stuff RTEMS_UNUSED, + struct timeval *tp, + void *__tz ) { struct timezone *tzp = __tz; diff --git a/cpukit/libcsupport/src/__times.c b/cpukit/libcsupport/src/__times.c index 14625b5aae..61c0106c8b 100644 --- a/cpukit/libcsupport/src/__times.c +++ b/cpukit/libcsupport/src/__times.c @@ -58,24 +58,23 @@ /** * POSIX 1003.1b 4.5.2 - Get Process Times */ -clock_t _times( - struct tms *ptms -) +clock_t _times( struct tms *ptms ) { uint32_t tick_interval; sbintime_t uptime; sbintime_t cpu_time_used; - if ( !ptms ) + if ( !ptms ) { rtems_set_errno_and_return_minus_one( EFAULT ); + } - tick_interval = (uint32_t) - (SBT_1US * rtems_configuration_get_microseconds_per_tick()); + tick_interval = + (uint32_t) ( SBT_1US * rtems_configuration_get_microseconds_per_tick() ); ptms = memset( ptms, 0, sizeof( *ptms ) ); _TOD_Get_zero_based_uptime( &uptime ); - ptms->tms_stime = ((clock_t) uptime) / tick_interval; + ptms->tms_stime = ( (clock_t) uptime ) / tick_interval; /* * RTEMS technically has no notion of system versus user time @@ -84,9 +83,10 @@ clock_t _times( * of ticks since boot and the number of ticks executed by this * this thread. */ - cpu_time_used = - _Thread_Get_CPU_time_used_after_last_reset( _Thread_Get_executing() ); - ptms->tms_utime = ((clock_t) cpu_time_used) / tick_interval; + cpu_time_used = _Thread_Get_CPU_time_used_after_last_reset( + _Thread_Get_executing() + ); + ptms->tms_utime = ( (clock_t) cpu_time_used ) / tick_interval; return ptms->tms_stime; } @@ -94,24 +94,19 @@ clock_t _times( /** * times() system call wrapper for _times() above. */ -clock_t times( - struct tms *ptms -) +clock_t times( struct tms *ptms ) { return _times( ptms ); } -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include /** * This is the Newlib dependent reentrant version of times(). */ -clock_t _times_r( - struct _reent *ptr RTEMS_UNUSED, - struct tms *ptms -) +clock_t _times_r( struct _reent *ptr RTEMS_UNUSED, struct tms *ptms ) { return _times( ptms ); } diff --git a/cpukit/libcsupport/src/__usrenv.c b/cpukit/libcsupport/src/__usrenv.c index a69d384ee9..22a2a660ea 100644 --- a/cpukit/libcsupport/src/__usrenv.c +++ b/cpukit/libcsupport/src/__usrenv.c @@ -47,9 +47,9 @@ static int null_handler_open( rtems_libio_t *iop, - const char *path, - int oflag, - mode_t mode + const char *path, + int oflag, + mode_t mode ) { (void) iop; @@ -62,7 +62,7 @@ static int null_handler_open( static int null_handler_fstat( const rtems_filesystem_location_info_t *pathloc, - struct stat *buf + struct stat *buf ) { (void) pathloc; @@ -101,10 +101,10 @@ static void null_op_lock_or_unlock( static int null_op_mknod( const rtems_filesystem_location_info_t *parentloc, - const char *name, - size_t namelen, - mode_t mode, - dev_t dev + const char *name, + size_t namelen, + mode_t mode, + dev_t dev ) { (void) parentloc; @@ -130,8 +130,8 @@ static int null_op_rmnod( static int null_op_link( const rtems_filesystem_location_info_t *parentloc, const rtems_filesystem_location_info_t *targetloc, - const char *name, - size_t namelen + const char *name, + size_t namelen ) { (void) parentloc; @@ -144,7 +144,7 @@ static int null_op_link( static int null_op_fchmod( const rtems_filesystem_location_info_t *pathloc, - mode_t mode + mode_t mode ) { (void) pathloc; @@ -155,8 +155,8 @@ static int null_op_fchmod( static int null_op_chown( const rtems_filesystem_location_info_t *loc, - uid_t owner, - gid_t group + uid_t owner, + gid_t group ) { (void) loc; @@ -166,9 +166,7 @@ static int null_op_chown( return -1; } -static int null_op_clonenode( - rtems_filesystem_location_info_t *loc -) +static int null_op_clonenode( rtems_filesystem_location_info_t *loc ) { (void) loc; @@ -177,7 +175,7 @@ static int null_op_clonenode( static int null_op_mount( rtems_filesystem_mount_table_entry_t *mt_entry, - const void *data + const void *data ) { (void) mt_entry; @@ -186,9 +184,7 @@ static int null_op_mount( return -1; } -static int null_op_unmount( - rtems_filesystem_mount_table_entry_t *mt_entry -) +static int null_op_unmount( rtems_filesystem_mount_table_entry_t *mt_entry ) { (void) mt_entry; @@ -206,7 +202,7 @@ static void null_op_fsunmount_me( static int null_op_utimens( const rtems_filesystem_location_info_t *loc, - struct timespec times[2] + struct timespec times[ 2 ] ) { (void) loc; @@ -217,9 +213,9 @@ static int null_op_utimens( static int null_op_symlink( const rtems_filesystem_location_info_t *parentloc, - const char *name, - size_t namelen, - const char *target + const char *name, + size_t namelen, + const char *target ) { (void) parentloc; @@ -232,8 +228,8 @@ static int null_op_symlink( static ssize_t null_op_readlink( const rtems_filesystem_location_info_t *loc, - char *buf, - size_t bufsize + char *buf, + size_t bufsize ) { (void) loc; @@ -247,8 +243,8 @@ static int null_op_rename( const rtems_filesystem_location_info_t *oldparentloc, const rtems_filesystem_location_info_t *oldloc, const rtems_filesystem_location_info_t *newparentloc, - const char *name, - size_t namelen + const char *name, + size_t namelen ) { (void) oldparentloc; @@ -306,13 +302,12 @@ rtems_filesystem_mount_table_entry_t rtems_filesystem_null_mt_entry = { }; rtems_filesystem_global_location_t rtems_filesystem_global_location_null = { - .location = { - .mt_entry_node = RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN( - &rtems_filesystem_null_mt_entry.location_chain - ), - .handlers = &rtems_filesystem_null_handlers, - .mt_entry = &rtems_filesystem_null_mt_entry - }, + .location = + { .mt_entry_node = RTEMS_CHAIN_NODE_INITIALIZER_ONE_NODE_CHAIN( + &rtems_filesystem_null_mt_entry.location_chain + ), + .handlers = &rtems_filesystem_null_handlers, + .mt_entry = &rtems_filesystem_null_mt_entry }, /* * The initial reference count accounts for the following references @@ -330,12 +325,12 @@ rtems_user_env_t rtems_global_user_env = { .umask = S_IWGRP | S_IWOTH }; -rtems_user_env_t *rtems_current_user_env_get(void) +rtems_user_env_t *rtems_current_user_env_get( void ) { - Thread_Control *executing = _Thread_Get_executing(); + Thread_Control *executing = _Thread_Get_executing(); rtems_user_env_t *env = executing->user_environment; - if (env == NULL) { + if ( env == NULL ) { return &rtems_global_user_env; } diff --git a/cpukit/libcsupport/src/_calloc_r.c b/cpukit/libcsupport/src/_calloc_r.c index 348dc8b393..8d73c32ffd 100644 --- a/cpukit/libcsupport/src/_calloc_r.c +++ b/cpukit/libcsupport/src/_calloc_r.c @@ -37,15 +37,11 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE__CALLOC_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__CALLOC_R ) #include #include -void *_calloc_r( - struct _reent *ignored, - size_t elements, - size_t size -) +void *_calloc_r( struct _reent *ignored, size_t elements, size_t size ) { (void) ignored; return calloc( elements, size ); diff --git a/cpukit/libcsupport/src/_free_r.c b/cpukit/libcsupport/src/_free_r.c index f5cbf406e4..ccbdeda879 100644 --- a/cpukit/libcsupport/src/_free_r.c +++ b/cpukit/libcsupport/src/_free_r.c @@ -37,14 +37,11 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE__FREE_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__FREE_R ) #include #include -void _free_r( - struct _reent *ignored, - void *ptr -) +void _free_r( struct _reent *ignored, void *ptr ) { (void) ignored; free( ptr ); diff --git a/cpukit/libcsupport/src/_malloc_r.c b/cpukit/libcsupport/src/_malloc_r.c index 986757bb64..3c85ea4d05 100644 --- a/cpukit/libcsupport/src/_malloc_r.c +++ b/cpukit/libcsupport/src/_malloc_r.c @@ -32,14 +32,11 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE__MALLOC_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__MALLOC_R ) #include #include -void *_malloc_r( - struct _reent *ignored, - size_t size -) +void *_malloc_r( struct _reent *ignored, size_t size ) { (void) ignored; return malloc( size ); diff --git a/cpukit/libcsupport/src/_realloc_r.c b/cpukit/libcsupport/src/_realloc_r.c index 93861dc849..7aead0f407 100644 --- a/cpukit/libcsupport/src/_realloc_r.c +++ b/cpukit/libcsupport/src/_realloc_r.c @@ -38,15 +38,11 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE__REALLOC_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__REALLOC_R ) #include #include -void *_realloc_r( - struct _reent *ignored, - void *ptr, - size_t size -) +void *_realloc_r( struct _reent *ignored, void *ptr, size_t size ) { (void) ignored; return realloc( ptr, size ); diff --git a/cpukit/libcsupport/src/_rename_r.c b/cpukit/libcsupport/src/_rename_r.c index 745316288b..5375c39e05 100644 --- a/cpukit/libcsupport/src/_rename_r.c +++ b/cpukit/libcsupport/src/_rename_r.c @@ -40,7 +40,7 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE__RENAME_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__RENAME_R ) #include @@ -51,18 +51,17 @@ */ int _rename_r( struct _reent *ptr RTEMS_UNUSED, - const char *old, - const char *new + const char *old, + const char *new ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t old_ctx; - int old_eval_flags = 0; - rtems_filesystem_location_info_t old_parentloc; - int old_parent_eval_flags = RTEMS_FS_PERMS_WRITE - | RTEMS_FS_FOLLOW_HARD_LINK; - const rtems_filesystem_location_info_t *old_currentloc = - rtems_filesystem_eval_path_start_with_parent( + int old_eval_flags = 0; + rtems_filesystem_location_info_t old_parentloc; + int old_parent_eval_flags = RTEMS_FS_PERMS_WRITE | RTEMS_FS_FOLLOW_HARD_LINK; + const rtems_filesystem_location_info_t + *old_currentloc = rtems_filesystem_eval_path_start_with_parent( &old_ctx, old, old_eval_flags, @@ -72,9 +71,8 @@ int _rename_r( rtems_filesystem_eval_path_context_t new_ctx; /* FIXME: This is not POSIX conform */ - int new_eval_flags = RTEMS_FS_FOLLOW_HARD_LINK - | RTEMS_FS_MAKE - | RTEMS_FS_EXCLUSIVE; + int new_eval_flags = RTEMS_FS_FOLLOW_HARD_LINK | RTEMS_FS_MAKE | + RTEMS_FS_EXCLUSIVE; const rtems_filesystem_location_info_t *new_currentloc = rtems_filesystem_eval_path_start( &new_ctx, new, new_eval_flags ); @@ -84,7 +82,7 @@ int _rename_r( new_currentloc ); if ( rv == 0 ) { - rv = (*new_currentloc->mt_entry->ops->rename_h)( + rv = ( *new_currentloc->mt_entry->ops->rename_h )( &old_parentloc, old_currentloc, new_currentloc, diff --git a/cpukit/libcsupport/src/access.c b/cpukit/libcsupport/src/access.c index 15d913f4c2..eb6b6345d9 100644 --- a/cpukit/libcsupport/src/access.c +++ b/cpukit/libcsupport/src/access.c @@ -42,29 +42,30 @@ #include #include -int access( - const char *path, - int amode -) +int access( const char *path, int amode ) { struct stat statbuf; - if ( stat(path, &statbuf) ) + if ( stat( path, &statbuf ) ) { return -1; + } if ( amode & R_OK ) { - if (!( statbuf.st_mode & S_IREAD )) + if ( !( statbuf.st_mode & S_IREAD ) ) { return -1; + } } if ( amode & W_OK ) { - if ( !( statbuf.st_mode & S_IWRITE ) ) + if ( !( statbuf.st_mode & S_IWRITE ) ) { return -1; + } } if ( amode & X_OK ) { - if ( !( statbuf.st_mode & S_IEXEC ) ) + if ( !( statbuf.st_mode & S_IEXEC ) ) { return -1; + } } return 0; diff --git a/cpukit/libcsupport/src/alignedalloc.c b/cpukit/libcsupport/src/alignedalloc.c index ca5cb09fd2..a9f990de94 100644 --- a/cpukit/libcsupport/src/alignedalloc.c +++ b/cpukit/libcsupport/src/alignedalloc.c @@ -42,6 +42,7 @@ void *aligned_alloc( size_t alignment, size_t size ) return rtems_heap_allocate_aligned_with_boundary( size, alignment, 0 ); } -void *memalign( size_t, size_t ) RTEMS_ALIAS( aligned_alloc ) __malloc_like - __alloc_align(1) __alloc_size(2) __result_use_check - __attribute__((__nothrow__)); +void *memalign( size_t, size_t ) RTEMS_ALIAS( + aligned_alloc +) __malloc_like __alloc_align( 1 ) __alloc_size( 2 ) __result_use_check + __attribute__(( __nothrow__ )); diff --git a/cpukit/libcsupport/src/assoc32tostring.c b/cpukit/libcsupport/src/assoc32tostring.c index 758aa0047c..64eaa206dc 100644 --- a/cpukit/libcsupport/src/assoc32tostring.c +++ b/cpukit/libcsupport/src/assoc32tostring.c @@ -58,7 +58,7 @@ size_t rtems_assoc_32_to_string( len = 0; - for ( i = 0; i < pair_count ; ++i ) { + for ( i = 0; i < pair_count; ++i ) { const rtems_assoc_32_pair *p; p = &pairs[ i ]; diff --git a/cpukit/libcsupport/src/assoclocalbyname.c b/cpukit/libcsupport/src/assoclocalbyname.c index 304d5f723c..aec533d33e 100644 --- a/cpukit/libcsupport/src/assoclocalbyname.c +++ b/cpukit/libcsupport/src/assoclocalbyname.c @@ -43,18 +43,16 @@ #include #include -#include /* strcat, strcmp */ +#include /* strcat, strcmp */ -uint32_t rtems_assoc_local_by_name( - const rtems_assoc_t *ap, - const char *name -) +uint32_t rtems_assoc_local_by_name( const rtems_assoc_t *ap, const char *name ) { const rtems_assoc_t *nap; - nap = rtems_assoc_ptr_by_name(ap, name); - if (nap) + nap = rtems_assoc_ptr_by_name( ap, name ); + if ( nap ) { return nap->local_value; + } return 0; } diff --git a/cpukit/libcsupport/src/assoclocalbyremote.c b/cpukit/libcsupport/src/assoclocalbyremote.c index be690a5a2d..f4640f47d5 100644 --- a/cpukit/libcsupport/src/assoclocalbyremote.c +++ b/cpukit/libcsupport/src/assoclocalbyremote.c @@ -42,7 +42,7 @@ #include #include -#include /* strcat, strcmp */ +#include /* strcat, strcmp */ uint32_t rtems_assoc_local_by_remote( const rtems_assoc_t *ap, @@ -51,9 +51,10 @@ uint32_t rtems_assoc_local_by_remote( { const rtems_assoc_t *nap; - nap = rtems_assoc_ptr_by_remote(ap, remote_value); - if (nap) + nap = rtems_assoc_ptr_by_remote( ap, remote_value ); + if ( nap ) { return nap->local_value; + } return 0; } diff --git a/cpukit/libcsupport/src/assoclocalbyremotebitfield.c b/cpukit/libcsupport/src/assoclocalbyremotebitfield.c index 08c7de3bc6..2b9d939e17 100644 --- a/cpukit/libcsupport/src/assoclocalbyremotebitfield.c +++ b/cpukit/libcsupport/src/assoclocalbyremotebitfield.c @@ -42,20 +42,20 @@ #include #include -#include /* strcat, strcmp */ +#include /* strcat, strcmp */ - -uint32_t rtems_assoc_local_by_remote_bitfield( - const rtems_assoc_t *ap, - uint32_t remote_value +uint32_t rtems_assoc_local_by_remote_bitfield( + const rtems_assoc_t *ap, + uint32_t remote_value ) { - uint32_t b; - uint32_t local_value = 0; + uint32_t b; + uint32_t local_value = 0; - for (b = 1; b; b <<= 1) { - if (b & remote_value) - local_value |= rtems_assoc_local_by_remote(ap, b); + for ( b = 1; b; b <<= 1 ) { + if ( b & remote_value ) { + local_value |= rtems_assoc_local_by_remote( ap, b ); + } } return local_value; diff --git a/cpukit/libcsupport/src/assocnamebad.c b/cpukit/libcsupport/src/assocnamebad.c index 4f70e5a297..71685c2942 100644 --- a/cpukit/libcsupport/src/assocnamebad.c +++ b/cpukit/libcsupport/src/assocnamebad.c @@ -43,23 +43,27 @@ #include #include -#include /* sprintf */ +#include /* sprintf */ -const char * -rtems_assoc_name_bad( +const char *rtems_assoc_name_bad( #ifdef RTEMS_DEBUG - uint32_t bad_value + uint32_t bad_value #else - uint32_t bad_value RTEMS_UNUSED + uint32_t bad_value RTEMS_UNUSED #endif ) { #ifdef RTEMS_DEBUG - static char bad_buffer[32]; + static char bad_buffer[ 32 ]; - sprintf(bad_buffer, "< %" PRId32 "[0x%" PRIx32 " ] >", bad_value, bad_value); + sprintf( + bad_buffer, + "< %" PRId32 "[0x%" PRIx32 " ] >", + bad_value, + bad_value + ); #else - static char bad_buffer[40] = ""; + static char bad_buffer[ 40 ] = ""; #endif - return bad_buffer; + return bad_buffer; } diff --git a/cpukit/libcsupport/src/assocnamebylocal.c b/cpukit/libcsupport/src/assocnamebylocal.c index 3c52c14ea7..b181978faf 100644 --- a/cpukit/libcsupport/src/assocnamebylocal.c +++ b/cpukit/libcsupport/src/assocnamebylocal.c @@ -42,7 +42,7 @@ #include #include -#include /* strcat, strcmp */ +#include /* strcat, strcmp */ const char *rtems_assoc_name_by_local( const rtems_assoc_t *ap, @@ -51,9 +51,10 @@ const char *rtems_assoc_name_by_local( { const rtems_assoc_t *nap; - nap = rtems_assoc_ptr_by_local(ap, local_value); - if (nap) + nap = rtems_assoc_ptr_by_local( ap, local_value ); + if ( nap ) { return nap->name; + } - return rtems_assoc_name_bad(local_value); + return rtems_assoc_name_bad( local_value ); } diff --git a/cpukit/libcsupport/src/assocnamebylocalbitfield.c b/cpukit/libcsupport/src/assocnamebylocalbitfield.c index 895b990e6f..10940d1f99 100644 --- a/cpukit/libcsupport/src/assocnamebylocalbitfield.c +++ b/cpukit/libcsupport/src/assocnamebylocalbitfield.c @@ -42,7 +42,7 @@ #include #include -#include /* strcat, strcmp */ +#include /* strcat, strcmp */ char *rtems_assoc_name_by_local_bitfield( const rtems_assoc_t *ap, @@ -50,15 +50,16 @@ char *rtems_assoc_name_by_local_bitfield( char *buffer ) { - uint32_t b; + uint32_t b; *buffer = 0; - for (b = 1; b; b <<= 1) { - if (b & value) { - if (*buffer) - strcat(buffer, " "); - strcat(buffer, rtems_assoc_name_by_local(ap, b)); + for ( b = 1; b; b <<= 1 ) { + if ( b & value ) { + if ( *buffer ) { + strcat( buffer, " " ); + } + strcat( buffer, rtems_assoc_name_by_local( ap, b ) ); } } diff --git a/cpukit/libcsupport/src/assocnamebyremote.c b/cpukit/libcsupport/src/assocnamebyremote.c index 4c8d27436c..748791e3a8 100644 --- a/cpukit/libcsupport/src/assocnamebyremote.c +++ b/cpukit/libcsupport/src/assocnamebyremote.c @@ -42,8 +42,7 @@ #include #include -#include /* strcat, strcmp */ - +#include /* strcat, strcmp */ const char *rtems_assoc_name_by_remote( const rtems_assoc_t *ap, @@ -51,10 +50,11 @@ const char *rtems_assoc_name_by_remote( ) { const rtems_assoc_t *nap; - nap = rtems_assoc_ptr_by_remote(ap, remote_value); + nap = rtems_assoc_ptr_by_remote( ap, remote_value ); - if (nap) + if ( nap ) { return nap->name; + } - return rtems_assoc_name_bad(remote_value); + return rtems_assoc_name_bad( remote_value ); } diff --git a/cpukit/libcsupport/src/assocnamebyremotebitfield.c b/cpukit/libcsupport/src/assocnamebyremotebitfield.c index 66ced51462..006c76b8e8 100644 --- a/cpukit/libcsupport/src/assocnamebyremotebitfield.c +++ b/cpukit/libcsupport/src/assocnamebyremotebitfield.c @@ -42,8 +42,7 @@ #include #include -#include /* strcat, strcmp */ - +#include /* strcat, strcmp */ char *rtems_assoc_name_by_remote_bitfield( const rtems_assoc_t *ap, @@ -51,15 +50,16 @@ char *rtems_assoc_name_by_remote_bitfield( char *buffer ) { - uint32_t b; + uint32_t b; *buffer = 0; - for (b = 1; b; b <<= 1) { - if (b & value) { - if (*buffer) - strcat(buffer, " "); - strcat(buffer, rtems_assoc_name_by_remote(ap, b)); + for ( b = 1; b; b <<= 1 ) { + if ( b & value ) { + if ( *buffer ) { + strcat( buffer, " " ); + } + strcat( buffer, rtems_assoc_name_by_remote( ap, b ) ); } } diff --git a/cpukit/libcsupport/src/assocptrbylocal.c b/cpukit/libcsupport/src/assocptrbylocal.c index b5c7588179..d135a34a4e 100644 --- a/cpukit/libcsupport/src/assocptrbylocal.c +++ b/cpukit/libcsupport/src/assocptrbylocal.c @@ -42,7 +42,7 @@ #include #include -#include /* strcat, strcmp */ +#include /* strcat, strcmp */ const rtems_assoc_t *rtems_assoc_ptr_by_local( const rtems_assoc_t *ap, @@ -51,12 +51,15 @@ const rtems_assoc_t *rtems_assoc_ptr_by_local( { const rtems_assoc_t *default_ap = 0; - if (rtems_assoc_is_default(ap)) + if ( rtems_assoc_is_default( ap ) ) { default_ap = ap++; + } - for ( ; ap->name; ap++) - if (ap->local_value == local_value) + for ( ; ap->name; ap++ ) { + if ( ap->local_value == local_value ) { return ap; + } + } return default_ap; } diff --git a/cpukit/libcsupport/src/assocptrbyname.c b/cpukit/libcsupport/src/assocptrbyname.c index b48cd38ba4..12196df23d 100644 --- a/cpukit/libcsupport/src/assocptrbyname.c +++ b/cpukit/libcsupport/src/assocptrbyname.c @@ -42,8 +42,7 @@ #include #include -#include /* strcat, strcmp */ - +#include /* strcat, strcmp */ const rtems_assoc_t *rtems_assoc_ptr_by_name( const rtems_assoc_t *ap, @@ -52,12 +51,15 @@ const rtems_assoc_t *rtems_assoc_ptr_by_name( { const rtems_assoc_t *default_ap = 0; - if (rtems_assoc_is_default(ap)) + if ( rtems_assoc_is_default( ap ) ) { default_ap = ap++; + } - for ( ; ap->name; ap++) - if (strcmp(ap->name, name) == 0) - return ap; + for ( ; ap->name; ap++ ) { + if ( strcmp( ap->name, name ) == 0 ) { + return ap; + } + } return default_ap; } diff --git a/cpukit/libcsupport/src/assocptrbyremote.c b/cpukit/libcsupport/src/assocptrbyremote.c index 0032928b60..8a32cd618e 100644 --- a/cpukit/libcsupport/src/assocptrbyremote.c +++ b/cpukit/libcsupport/src/assocptrbyremote.c @@ -42,21 +42,24 @@ #include #include -#include /* strcat, strcmp */ +#include /* strcat, strcmp */ const rtems_assoc_t *rtems_assoc_ptr_by_remote( const rtems_assoc_t *ap, - uint32_t remote_value + uint32_t remote_value ) { const rtems_assoc_t *default_ap = 0; - if (rtems_assoc_is_default(ap)) + if ( rtems_assoc_is_default( ap ) ) { default_ap = ap++; + } - for ( ; ap->name; ap++) - if (ap->remote_value == remote_value) + for ( ; ap->name; ap++ ) { + if ( ap->remote_value == remote_value ) { return ap; + } + } return default_ap; } diff --git a/cpukit/libcsupport/src/assocremotebylocal.c b/cpukit/libcsupport/src/assocremotebylocal.c index f4d5553a97..166dd68402 100644 --- a/cpukit/libcsupport/src/assocremotebylocal.c +++ b/cpukit/libcsupport/src/assocremotebylocal.c @@ -42,18 +42,19 @@ #include #include -#include /* strcat, strcmp */ +#include /* strcat, strcmp */ uint32_t rtems_assoc_remote_by_local( const rtems_assoc_t *ap, - uint32_t local_value + uint32_t local_value ) { const rtems_assoc_t *nap; - nap = rtems_assoc_ptr_by_local(ap, local_value); - if (nap) + nap = rtems_assoc_ptr_by_local( ap, local_value ); + if ( nap ) { return nap->remote_value; + } return 0; } diff --git a/cpukit/libcsupport/src/assocremotebylocalbitfield.c b/cpukit/libcsupport/src/assocremotebylocalbitfield.c index a5fcc711b2..3e5c3c0766 100644 --- a/cpukit/libcsupport/src/assocremotebylocalbitfield.c +++ b/cpukit/libcsupport/src/assocremotebylocalbitfield.c @@ -43,20 +43,21 @@ #include #include -#include /* strcat, strcmp */ +#include /* strcat, strcmp */ - -uint32_t rtems_assoc_remote_by_local_bitfield( - const rtems_assoc_t *ap, - uint32_t local_value +uint32_t rtems_assoc_remote_by_local_bitfield( + const rtems_assoc_t *ap, + uint32_t local_value ) { - uint32_t b; - uint32_t remote_value = 0; + uint32_t b; + uint32_t remote_value = 0; - for (b = 1; b; b <<= 1) - if (b & local_value) - remote_value |= rtems_assoc_remote_by_local(ap, b); + for ( b = 1; b; b <<= 1 ) { + if ( b & local_value ) { + remote_value |= rtems_assoc_remote_by_local( ap, b ); + } + } return remote_value; } diff --git a/cpukit/libcsupport/src/assocremotebyname.c b/cpukit/libcsupport/src/assocremotebyname.c index 263daeec09..4b5079eacc 100644 --- a/cpukit/libcsupport/src/assocremotebyname.c +++ b/cpukit/libcsupport/src/assocremotebyname.c @@ -42,7 +42,7 @@ #include #include -#include /* strcat, strcmp */ +#include /* strcat, strcmp */ uint32_t rtems_assoc_remote_by_name( const rtems_assoc_t *ap, @@ -51,9 +51,10 @@ uint32_t rtems_assoc_remote_by_name( { const rtems_assoc_t *nap; - nap = rtems_assoc_ptr_by_name(ap, name); - if (nap) + nap = rtems_assoc_ptr_by_name( ap, name ); + if ( nap ) { return nap->remote_value; + } return 0; } diff --git a/cpukit/libcsupport/src/assocthreadstatestostring.c b/cpukit/libcsupport/src/assocthreadstatestostring.c index 22e2643d1b..e3915ebe3f 100644 --- a/cpukit/libcsupport/src/assocthreadstatestostring.c +++ b/cpukit/libcsupport/src/assocthreadstatestostring.c @@ -33,35 +33,35 @@ #include static const rtems_assoc_32_pair state_pairs[] = { - { STATES_WAITING_FOR_MUTEX, "MTX" }, - { STATES_WAITING_FOR_SEMAPHORE, "SEM" }, - { STATES_WAITING_FOR_EVENT, "EV" }, - { STATES_WAITING_FOR_SYSTEM_EVENT, "SYSEV" }, - { STATES_WAITING_FOR_MESSAGE, "MSG" }, + { STATES_WAITING_FOR_MUTEX, "MTX" }, + { STATES_WAITING_FOR_SEMAPHORE, "SEM" }, + { STATES_WAITING_FOR_EVENT, "EV" }, + { STATES_WAITING_FOR_SYSTEM_EVENT, "SYSEV" }, + { STATES_WAITING_FOR_MESSAGE, "MSG" }, { STATES_WAITING_FOR_CONDITION_VARIABLE, "CV" }, - { STATES_WAITING_FOR_FUTEX, "FTX" }, - { STATES_WAITING_FOR_BSD_WAKEUP, "WK" }, - { STATES_WAITING_FOR_TIME, "TIME" }, - { STATES_WAITING_FOR_PERIOD, "PER" }, - { STATES_WAITING_FOR_SIGNAL, "SIG" }, - { STATES_WAITING_FOR_BARRIER, "BAR" }, - { STATES_WAITING_FOR_RWLOCK, "RW" }, - { STATES_WAITING_FOR_JOIN_AT_EXIT, "JATX" }, - { STATES_WAITING_FOR_JOIN, "JOIN" }, - { STATES_SUSPENDED, "SUSP" }, - { STATES_WAITING_FOR_SEGMENT, "SEG" }, - { STATES_LIFE_IS_CHANGING, "LIFE" }, - { STATES_DEBUGGER, "DBG" }, - { STATES_INTERRUPTIBLE_BY_SIGNAL, "IS" }, - { STATES_WAITING_FOR_RPC_REPLY, "RPC" }, - { STATES_ZOMBIE, "ZOMBI" }, - { STATES_DORMANT, "DORM" } + { STATES_WAITING_FOR_FUTEX, "FTX" }, + { STATES_WAITING_FOR_BSD_WAKEUP, "WK" }, + { STATES_WAITING_FOR_TIME, "TIME" }, + { STATES_WAITING_FOR_PERIOD, "PER" }, + { STATES_WAITING_FOR_SIGNAL, "SIG" }, + { STATES_WAITING_FOR_BARRIER, "BAR" }, + { STATES_WAITING_FOR_RWLOCK, "RW" }, + { STATES_WAITING_FOR_JOIN_AT_EXIT, "JATX" }, + { STATES_WAITING_FOR_JOIN, "JOIN" }, + { STATES_SUSPENDED, "SUSP" }, + { STATES_WAITING_FOR_SEGMENT, "SEG" }, + { STATES_LIFE_IS_CHANGING, "LIFE" }, + { STATES_DEBUGGER, "DBG" }, + { STATES_INTERRUPTIBLE_BY_SIGNAL, "IS" }, + { STATES_WAITING_FOR_RPC_REPLY, "RPC" }, + { STATES_ZOMBIE, "ZOMBI" }, + { STATES_DORMANT, "DORM" } }; size_t rtems_assoc_thread_states_to_string( - uint32_t states, - char *buffer, - size_t buffer_size + uint32_t states, + char *buffer, + size_t buffer_size ) { return rtems_assoc_32_to_string( diff --git a/cpukit/libcsupport/src/base_fs.c b/cpukit/libcsupport/src/base_fs.c index a76889c84d..71aa46f783 100644 --- a/cpukit/libcsupport/src/base_fs.c +++ b/cpukit/libcsupport/src/base_fs.c @@ -51,8 +51,8 @@ void rtems_filesystem_initialize( void ) { int rv = 0; - const rtems_filesystem_mount_configuration *root_config = - &rtems_filesystem_root_configuration; + const rtems_filesystem_mount_configuration + *root_config = &rtems_filesystem_root_configuration; rv = mount( root_config->source, @@ -61,8 +61,9 @@ void rtems_filesystem_initialize( void ) root_config->options, root_config->data ); - if ( rv != 0 ) + if ( rv != 0 ) { rtems_fatal_error_occurred( 0xABCD0002 ); + } /* * Traditionally RTEMS devices are under "/dev" so install this directory. @@ -71,8 +72,9 @@ void rtems_filesystem_initialize( void ) */ rv = mkdir( "/dev", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ); - if ( rv != 0 ) + if ( rv != 0 ) { rtems_fatal_error_occurred( 0xABCD0003 ); + } /* * You can't mount another filesystem properly until the mount point diff --git a/cpukit/libcsupport/src/cachealignedalloc.c b/cpukit/libcsupport/src/cachealignedalloc.c index 4acfab80c6..24bbd51ee5 100644 --- a/cpukit/libcsupport/src/cachealignedalloc.c +++ b/cpukit/libcsupport/src/cachealignedalloc.c @@ -42,7 +42,7 @@ void *rtems_cache_aligned_malloc( size_t nbytes ) /* Assume that the cache line size is a power of two */ size_t m = line_size - 1; - nbytes = (nbytes + m) & ~m; + nbytes = ( nbytes + m ) & ~m; } return rtems_heap_allocate_aligned_with_boundary( nbytes, line_size, 0 ); diff --git a/cpukit/libcsupport/src/cachecoherentalloc.c b/cpukit/libcsupport/src/cachecoherentalloc.c index ed17ebffcb..0c774f73b1 100644 --- a/cpukit/libcsupport/src/cachecoherentalloc.c +++ b/cpukit/libcsupport/src/cachecoherentalloc.c @@ -46,12 +46,12 @@ static Heap_Control cache_coherent_heap_instance; static Heap_Control *cache_coherent_heap; void *rtems_cache_coherent_allocate( - size_t size, + size_t size, uintptr_t alignment, uintptr_t boundary ) { - void *ptr; + void *ptr; Heap_Control *heap; _RTEMS_Lock_allocator(); @@ -97,10 +97,7 @@ void rtems_cache_coherent_free( void *ptr ) _RTEMS_Unlock_allocator(); } -static rtems_status_code add_area( - void *area_begin, - uintptr_t area_size -) +static rtems_status_code add_area( void *area_begin, uintptr_t area_size ) { Heap_Control *heap = cache_coherent_heap; @@ -112,7 +109,7 @@ static rtems_status_code add_area( } cache_coherent_heap = heap; } else { - if (_Heap_Extend( heap, area_begin, area_size, 0 ) == 0) { + if ( _Heap_Extend( heap, area_begin, area_size, 0 ) == 0 ) { return RTEMS_UNSATISFIED; } } @@ -120,12 +117,12 @@ static rtems_status_code add_area( } rtems_status_code rtems_cache_coherent_add_area( - void *area_begin, + void *area_begin, uintptr_t area_size ) { rtems_status_code sc; - bool needs_locking = _System_state_Is_up( _System_state_Get()); + bool needs_locking = _System_state_Is_up( _System_state_Get() ); if ( needs_locking ) { _RTEMS_Lock_allocator(); diff --git a/cpukit/libcsupport/src/calloc.c b/cpukit/libcsupport/src/calloc.c index 59a6ae9d3f..245610546c 100644 --- a/cpukit/libcsupport/src/calloc.c +++ b/cpukit/libcsupport/src/calloc.c @@ -37,7 +37,7 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE_CALLOC) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE_CALLOC ) #include #include @@ -45,13 +45,10 @@ #include -void *calloc( - size_t nelem, - size_t elsize -) +void *calloc( size_t nelem, size_t elsize ) { - void *cptr; - size_t length; + void *cptr; + size_t length; if ( nelem == 0 ) { return NULL; diff --git a/cpukit/libcsupport/src/cfgetispeed.c b/cpukit/libcsupport/src/cfgetispeed.c index d857be0cde..2e92380a43 100644 --- a/cpukit/libcsupport/src/cfgetispeed.c +++ b/cpukit/libcsupport/src/cfgetispeed.c @@ -38,16 +38,14 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include #include #include -speed_t cfgetispeed( - const struct termios *tp -) +speed_t cfgetispeed( const struct termios *tp ) { return tp->c_ispeed; } diff --git a/cpukit/libcsupport/src/cfgetospeed.c b/cpukit/libcsupport/src/cfgetospeed.c index 5e6403d9de..5d5782ee5c 100644 --- a/cpukit/libcsupport/src/cfgetospeed.c +++ b/cpukit/libcsupport/src/cfgetospeed.c @@ -38,7 +38,7 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -48,9 +48,7 @@ /** * POSIX 1003.1b 7.1.3 - Baud Rate Functions */ -speed_t cfgetospeed( - const struct termios *tp -) +speed_t cfgetospeed( const struct termios *tp ) { return tp->c_ospeed; } diff --git a/cpukit/libcsupport/src/cfsetispeed.c b/cpukit/libcsupport/src/cfsetispeed.c index 47b715a304..1f739e848f 100644 --- a/cpukit/libcsupport/src/cfsetispeed.c +++ b/cpukit/libcsupport/src/cfsetispeed.c @@ -38,7 +38,7 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -50,13 +50,11 @@ /** * POSIX 1003.1b 7.1.3 - Baud Rate Functions */ -int cfsetispeed( - struct termios *tp, - speed_t speed -) +int cfsetispeed( struct termios *tp, speed_t speed ) { - if ( rtems_termios_baud_to_index( speed ) == -1 ) + if ( rtems_termios_baud_to_index( speed ) == -1 ) { rtems_set_errno_and_return_minus_one( EINVAL ); + } tp->c_ispeed = speed; return 0; diff --git a/cpukit/libcsupport/src/cfsetospeed.c b/cpukit/libcsupport/src/cfsetospeed.c index d07922af4b..4f6a7de24d 100644 --- a/cpukit/libcsupport/src/cfsetospeed.c +++ b/cpukit/libcsupport/src/cfsetospeed.c @@ -38,7 +38,7 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -50,13 +50,11 @@ /** * POSIX 1003.1b 7.1.3 - Baud Rate Functions */ -int cfsetospeed( - struct termios *tp, - speed_t speed -) +int cfsetospeed( struct termios *tp, speed_t speed ) { - if ( rtems_termios_baud_to_index( speed ) == -1 ) + if ( rtems_termios_baud_to_index( speed ) == -1 ) { rtems_set_errno_and_return_minus_one( EINVAL ); + } tp->c_ospeed = speed; return 0; diff --git a/cpukit/libcsupport/src/cfsetspeed.c b/cpukit/libcsupport/src/cfsetspeed.c index 16940e1174..e7106ac08b 100644 --- a/cpukit/libcsupport/src/cfsetspeed.c +++ b/cpukit/libcsupport/src/cfsetspeed.c @@ -37,7 +37,7 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -46,13 +46,11 @@ #include #include -int cfsetspeed( - struct termios *tp, - speed_t speed -) +int cfsetspeed( struct termios *tp, speed_t speed ) { - if ( rtems_termios_baud_to_index( speed ) == -1 ) + if ( rtems_termios_baud_to_index( speed ) == -1 ) { rtems_set_errno_and_return_minus_one( EINVAL ); + } cfsetispeed( tp, speed ); cfsetospeed( tp, speed ); diff --git a/cpukit/libcsupport/src/chdir.c b/cpukit/libcsupport/src/chdir.c index f31c4f643c..c255ba4268 100644 --- a/cpukit/libcsupport/src/chdir.c +++ b/cpukit/libcsupport/src/chdir.c @@ -48,8 +48,8 @@ int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc ) { int rv = 0; - rtems_filesystem_global_location_t *global_loc = - rtems_filesystem_location_transform_to_global( loc ); + rtems_filesystem_global_location_t + *global_loc = rtems_filesystem_location_transform_to_global( loc ); mode_t type = rtems_filesystem_location_type( &global_loc->location ); if ( S_ISDIR( type ) ) { @@ -68,10 +68,9 @@ int rtems_filesystem_chdir( rtems_filesystem_location_info_t *loc ) int chdir( const char *path ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_PERMS_EXEC - | RTEMS_FS_FOLLOW_LINK; + int eval_flags = RTEMS_FS_PERMS_EXEC | RTEMS_FS_FOLLOW_LINK; rtems_filesystem_location_info_t pathloc; rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); diff --git a/cpukit/libcsupport/src/chmod.c b/cpukit/libcsupport/src/chmod.c index e387b79ca9..8d783313e4 100644 --- a/cpukit/libcsupport/src/chmod.c +++ b/cpukit/libcsupport/src/chmod.c @@ -46,11 +46,11 @@ */ int chmod( const char *path, mode_t mode ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_FOLLOW_LINK; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); + int eval_flags = RTEMS_FS_FOLLOW_LINK; + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); rv = rtems_filesystem_chmod( currentloc, mode ); diff --git a/cpukit/libcsupport/src/chown.c b/cpukit/libcsupport/src/chown.c index 2a72676676..6977fa6757 100644 --- a/cpukit/libcsupport/src/chown.c +++ b/cpukit/libcsupport/src/chown.c @@ -49,11 +49,11 @@ */ int chown( const char *path, uid_t owner, gid_t group ) { - int rv; + int rv; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_FOLLOW_LINK; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); + int eval_flags = RTEMS_FS_FOLLOW_LINK; + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); rv = rtems_filesystem_chown( currentloc, owner, group ); diff --git a/cpukit/libcsupport/src/chroot.c b/cpukit/libcsupport/src/chroot.c index 99ce869aa2..24f2d62888 100644 --- a/cpukit/libcsupport/src/chroot.c +++ b/cpukit/libcsupport/src/chroot.c @@ -50,12 +50,11 @@ int chroot( const char *path ) { - int rv = 0; - rtems_status_code sc = RTEMS_SUCCESSFUL; + int rv = 0; + rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_PERMS_EXEC - | RTEMS_FS_FOLLOW_LINK; - rtems_filesystem_location_info_t loc; + int eval_flags = RTEMS_FS_PERMS_EXEC | RTEMS_FS_FOLLOW_LINK; + rtems_filesystem_location_info_t loc; rtems_filesystem_global_location_t *new_current_loc; /* @@ -80,7 +79,7 @@ int chroot( const char *path ) if ( S_ISDIR( type ) ) { sc = rtems_libio_set_private_env(); - if (sc == RTEMS_SUCCESSFUL) { + if ( sc == RTEMS_SUCCESSFUL ) { rtems_filesystem_global_location_assign( &rtems_filesystem_root, new_root_loc @@ -90,7 +89,7 @@ int chroot( const char *path ) new_current_loc ); } else { - if (sc != RTEMS_UNSATISFIED) { + if ( sc != RTEMS_UNSATISFIED ) { errno = ENOMEM; } rv = -1; diff --git a/cpukit/libcsupport/src/clock.c b/cpukit/libcsupport/src/clock.c index 0e8a774c24..8fbd8cab3e 100644 --- a/cpukit/libcsupport/src/clock.c +++ b/cpukit/libcsupport/src/clock.c @@ -42,5 +42,5 @@ clock_t clock( void ) _Timecounter_Microuptime( &tv ); - return (clock_t) (tv.tv_sec - 1) * CLOCKS_PER_SEC + tv.tv_usec; + return (clock_t) ( tv.tv_sec - 1 ) * CLOCKS_PER_SEC + tv.tv_usec; } diff --git a/cpukit/libcsupport/src/clonenode.c b/cpukit/libcsupport/src/clonenode.c index 35af31ddd0..1eb37c3962 100644 --- a/cpukit/libcsupport/src/clonenode.c +++ b/cpukit/libcsupport/src/clonenode.c @@ -39,14 +39,14 @@ #include void rtems_filesystem_location_clone( - rtems_filesystem_location_info_t *clone, + rtems_filesystem_location_info_t *clone, const rtems_filesystem_location_info_t *master ) { int rv = 0; clone = rtems_filesystem_location_copy( clone, master ); - rv = (*clone->mt_entry->ops->clonenod_h)( clone ); + rv = ( *clone->mt_entry->ops->clonenod_h )( clone ); if ( rv != 0 ) { rtems_filesystem_location_remove_from_mt_entry( clone ); rtems_filesystem_location_initialize_to_null( clone ); diff --git a/cpukit/libcsupport/src/close.c b/cpukit/libcsupport/src/close.c index a566fb3fb7..48c3be2e32 100644 --- a/cpukit/libcsupport/src/close.c +++ b/cpukit/libcsupport/src/close.c @@ -40,9 +40,7 @@ #include -int close( - int fd -) +int close( int fd ) { rtems_libio_t *iop; int rc; @@ -54,7 +52,7 @@ int close( LIBIO_GET_IOP( fd, iop ); while ( true ) { - unsigned int flags; + unsigned int flags; unsigned int desired; bool success; flags = rtems_libio_iop_flags( iop ); @@ -87,13 +85,15 @@ int close( break; } - if ( ( flags & LIBIO_FLAGS_REFERENCE_MASK ) != LIBIO_FLAGS_REFERENCE_INC ) { + if ( + ( flags & LIBIO_FLAGS_REFERENCE_MASK ) != LIBIO_FLAGS_REFERENCE_INC + ) { rtems_libio_iop_drop( iop ); rtems_set_errno_and_return_minus_one( EBUSY ); } } - rc = (*iop->pathinfo.handlers->close_h)( iop ); + rc = ( *iop->pathinfo.handlers->close_h )( iop ); rtems_libio_iop_drop( iop ); @@ -106,14 +106,11 @@ int close( * This is the Newlib dependent reentrant version of close(). */ -#if defined(RTEMS_NEWLIB) && !defined(HAVE__CLOSE_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__CLOSE_R ) #include -int _close_r( - struct _reent *ptr RTEMS_UNUSED, - int fd -) +int _close_r( struct _reent *ptr RTEMS_UNUSED, int fd ) { return close( fd ); } diff --git a/cpukit/libcsupport/src/consolesimple.c b/cpukit/libcsupport/src/consolesimple.c index f398bc74fe..a0343613b8 100644 --- a/cpukit/libcsupport/src/consolesimple.c +++ b/cpukit/libcsupport/src/consolesimple.c @@ -75,11 +75,11 @@ static const rtems_filesystem_file_handlers_r _Console_simple_Handlers = { }; static const IMFS_node_control -_Console_simple_Node_control = IMFS_NODE_CONTROL_INITIALIZER( - &_Console_simple_Handlers, - IMFS_node_initialize_default, - IMFS_do_nothing_destroy -); + _Console_simple_Node_control = IMFS_NODE_CONTROL_INITIALIZER( + &_Console_simple_Handlers, + IMFS_node_initialize_default, + IMFS_do_nothing_destroy + ); static const char _Console_simple_Name[] = "console"; diff --git a/cpukit/libcsupport/src/consolesimple.h b/cpukit/libcsupport/src/consolesimple.h index a59e549646..bd51cd460f 100644 --- a/cpukit/libcsupport/src/consolesimple.h +++ b/cpukit/libcsupport/src/consolesimple.h @@ -25,8 +25,4 @@ * POSSIBILITY OF SUCH DAMAGE. */ -ssize_t _Console_simple_Read( - rtems_libio_t *iop, - void *buffer, - size_t count -); +ssize_t _Console_simple_Read( rtems_libio_t *iop, void *buffer, size_t count ); diff --git a/cpukit/libcsupport/src/consolesimpleread.c b/cpukit/libcsupport/src/consolesimpleread.c index 31968fa99f..c6caa45ea4 100644 --- a/cpukit/libcsupport/src/consolesimpleread.c +++ b/cpukit/libcsupport/src/consolesimpleread.c @@ -30,17 +30,13 @@ #include "consolesimple.h" -ssize_t _Console_simple_Read( - rtems_libio_t *iop, - void *buffer, - size_t count -) +ssize_t _Console_simple_Read( rtems_libio_t *iop, void *buffer, size_t count ) { (void) iop; - char *buf; - ssize_t i; - ssize_t n; + char *buf; + ssize_t i; + ssize_t n; buf = buffer; n = (ssize_t) count; diff --git a/cpukit/libcsupport/src/consolesimpletask.c b/cpukit/libcsupport/src/consolesimpletask.c index 1008b5121a..6f4a4a7901 100644 --- a/cpukit/libcsupport/src/consolesimpletask.c +++ b/cpukit/libcsupport/src/consolesimpletask.c @@ -44,10 +44,10 @@ typedef struct { IMFS_jnode_t Node; RTEMS_INTERRUPT_LOCK_MEMBER( buf_lock ) rtems_mutex output_mutex; - rtems_id task; - size_t head; - size_t tail; - char buf[ CONSOLE_SIMPLE_TASK_BUFFER_SIZE ]; + rtems_id task; + size_t head; + size_t tail; + char buf[ CONSOLE_SIMPLE_TASK_BUFFER_SIZE ]; } Console_simple_task_Control; static Console_simple_task_Control _Console_simple_task_Instance; @@ -144,7 +144,7 @@ static void _Console_simple_task_Put_chars( Console_simple_task_Control *cons ) rtems_interrupt_lock_release( &cons->buf_lock, &lock_context ); - for ( i = 0; i < available; ++i) { + for ( i = 0; i < available; ++i ) { rtems_putc( cons->buf[ tail ] ); tail = ( tail + 1 ) % CONSOLE_SIMPLE_TASK_BUFFER_SIZE; } @@ -186,11 +186,11 @@ static const rtems_filesystem_file_handlers_r _Console_simple_task_Handlers = { }; static const IMFS_node_control -_Console_simple_task_Node_control = IMFS_NODE_CONTROL_INITIALIZER( - &_Console_simple_task_Handlers, - IMFS_node_initialize_default, - IMFS_do_nothing_destroy -); + _Console_simple_task_Node_control = IMFS_NODE_CONTROL_INITIALIZER( + &_Console_simple_task_Handlers, + IMFS_node_initialize_default, + IMFS_do_nothing_destroy + ); static void _Console_simple_task_Task( rtems_task_argument arg ) { @@ -217,7 +217,7 @@ static const char _Console_simple_task_Name[] = "console"; void _Console_simple_task_Initialize( void ) { Console_simple_task_Control *cons; - rtems_status_code status; + rtems_status_code status; cons = &_Console_simple_task_Instance; @@ -235,19 +235,19 @@ void _Console_simple_task_Initialize( void ) IMFS_add_node( "/dev", &cons->Node, NULL ); status = rtems_task_create( - rtems_build_name('C', 'O', 'N', 'S'), + rtems_build_name( 'C', 'O', 'N', 'S' ), RTEMS_MAXIMUM_PRIORITY - 1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_ATTRIBUTES, RTEMS_DEFAULT_MODES, &cons->task ); - _Assert_Unused_variable_equals(status, RTEMS_SUCCESSFUL); + _Assert_Unused_variable_equals( status, RTEMS_SUCCESSFUL ); status = rtems_task_start( cons->task, _Console_simple_task_Task, (rtems_task_argument) cons ); - _Assert_Unused_variable_equals(status, RTEMS_SUCCESSFUL); + _Assert_Unused_variable_equals( status, RTEMS_SUCCESSFUL ); } diff --git a/cpukit/libcsupport/src/ctermid.c b/cpukit/libcsupport/src/ctermid.c index 2f53d0ed50..60c3fe9b52 100644 --- a/cpukit/libcsupport/src/ctermid.c +++ b/cpukit/libcsupport/src/ctermid.c @@ -38,7 +38,7 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -49,12 +49,11 @@ static char *ctermid_name = "/dev/console"; /** * ctermid() - POSIX 1003.1b 4.7.1 - Generate Terminal Pathname */ -char *ctermid( - char *s -) +char *ctermid( char *s ) { - if ( !s ) + if ( !s ) { return ctermid_name; + } /* * We have no way of knowing the length of the user provided buffer. diff --git a/cpukit/libcsupport/src/dup.c b/cpukit/libcsupport/src/dup.c index 50c56d796e..a2c90730e4 100644 --- a/cpukit/libcsupport/src/dup.c +++ b/cpukit/libcsupport/src/dup.c @@ -41,9 +41,7 @@ #include #include -int dup( - int fildes -) +int dup( int fildes ) { return fcntl( fildes, F_DUPFD, 0 ); } diff --git a/cpukit/libcsupport/src/dup2.c b/cpukit/libcsupport/src/dup2.c index 9206aae6e0..2e08f96321 100644 --- a/cpukit/libcsupport/src/dup2.c +++ b/cpukit/libcsupport/src/dup2.c @@ -45,29 +45,28 @@ /** * POSIX 1003.1b 6.2.1 Duplicate an Open File Descriptor */ -int dup2( - int fildes, - int fildes2 -) +int dup2( int fildes, int fildes2 ) { - int status; - struct stat buf; + int status; + struct stat buf; /* * If fildes is not valid, then fildes2 should not be closed. */ status = fstat( fildes, &buf ); - if ( status == -1 ) + if ( status == -1 ) { return -1; + } /* * If fildes2 is not valid, then we should not do anything either. */ status = fstat( fildes2, &buf ); - if ( status == -1 ) + if ( status == -1 ) { return -1; + } /* * This fcntl handles everything else. diff --git a/cpukit/libcsupport/src/error.c b/cpukit/libcsupport/src/error.c index 901d134f70..593248f82a 100644 --- a/cpukit/libcsupport/src/error.c +++ b/cpukit/libcsupport/src/error.c @@ -46,79 +46,92 @@ #include #include #include -#include /* _exit() */ +#include /* _exit() */ -int rtems_panic_in_progress; +int rtems_panic_in_progress; int rtems_verror( - rtems_error_code_t error_flag, - const char *printf_format, - va_list arglist + rtems_error_code_t error_flag, + const char *printf_format, + va_list arglist ) { int local_errno = 0; int chars_written = 0; rtems_status_code status; - if (error_flag & RTEMS_ERROR_PANIC) { - if (rtems_panic_in_progress++) - _Thread_Dispatch_disable(); /* disable task switches */ + if ( error_flag & RTEMS_ERROR_PANIC ) { + if ( rtems_panic_in_progress++ ) { + _Thread_Dispatch_disable(); /* disable task switches */ + } /* don't aggravate things */ - if (rtems_panic_in_progress > 2) + if ( rtems_panic_in_progress > 2 ) { return 0; + } } - (void) fflush(stdout); /* in case stdout/stderr same */ + (void) fflush( stdout ); /* in case stdout/stderr same */ status = error_flag & ~RTEMS_ERROR_MASK; - if (error_flag & RTEMS_ERROR_ERRNO) /* include errno? */ + if ( error_flag & RTEMS_ERROR_ERRNO ) { /* include errno? */ local_errno = errno; - - #if defined(RTEMS_MULTIPROCESSING) - if (_System_state_Is_multiprocessing) - fprintf(stderr, "[%" PRIu16 "] ", rtems_object_get_local_node()); - #endif - - chars_written += vfprintf(stderr, printf_format, arglist); - - if (status) - chars_written += - fprintf(stderr, " (status: %s)", rtems_status_text(status)); - - if (local_errno) { - if ((local_errno > 0) && *strerror(local_errno)) - chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno)); - else - chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno); } - chars_written += fprintf(stderr, "\n"); + #if defined( RTEMS_MULTIPROCESSING ) + if ( _System_state_Is_multiprocessing ) { + fprintf( stderr, "[%" PRIu16 "] ", rtems_object_get_local_node() ); + } + #endif - (void) fflush(stderr); + chars_written += vfprintf( stderr, printf_format, arglist ); + + if ( status ) { + chars_written += fprintf( + stderr, + " (status: %s)", + rtems_status_text( status ) + ); + } + + if ( local_errno ) { + if ( ( local_errno > 0 ) && *strerror( local_errno ) ) { + chars_written += fprintf( + stderr, + " (errno: %s)", + strerror( local_errno ) + ); + } else { + chars_written += fprintf( stderr, " (unknown errno=%d)", local_errno ); + } + } + + chars_written += fprintf( stderr, "\n" ); + + (void) fflush( stderr ); return chars_written; } int rtems_error( rtems_error_code_t error_flag, - const char *printf_format, + const char *printf_format, ... ) { va_list arglist; - int chars_written; + int chars_written; - va_start(arglist, printf_format); - chars_written = rtems_verror(error_flag, printf_format, arglist); - va_end(arglist); + va_start( arglist, printf_format ); + chars_written = rtems_verror( error_flag, printf_format, arglist ); + va_end( arglist ); - if (error_flag & RTEMS_ERROR_PANIC) { - rtems_error(0, "fatal error, exiting"); - _exit(errno); + if ( error_flag & RTEMS_ERROR_PANIC ) { + rtems_error( 0, "fatal error, exiting" ); + _exit( errno ); } - if (error_flag & RTEMS_ERROR_ABORT) { - rtems_error(0, "fatal error, aborting"); + if ( error_flag & RTEMS_ERROR_ABORT ) { + rtems_error( 0, "fatal error, aborting" ); abort(); } diff --git a/cpukit/libcsupport/src/fchdir.c b/cpukit/libcsupport/src/fchdir.c index 16441323ab..0e57f1ace9 100644 --- a/cpukit/libcsupport/src/fchdir.c +++ b/cpukit/libcsupport/src/fchdir.c @@ -49,9 +49,9 @@ */ int fchdir( int fd ) { - int rv = 0; - rtems_libio_t *iop; - struct stat st; + int rv = 0; + rtems_libio_t *iop; + struct stat st; rtems_filesystem_location_info_t loc; st.st_mode = 0; @@ -61,7 +61,7 @@ int fchdir( int fd ) LIBIO_GET_IOP( fd, iop ); rtems_filesystem_instance_lock( &iop->pathinfo ); - rv = (*iop->pathinfo.handlers->fstat_h)( &iop->pathinfo, &st ); + rv = ( *iop->pathinfo.handlers->fstat_h )( &iop->pathinfo, &st ); if ( rv == 0 ) { bool access_ok = rtems_filesystem_check_access( RTEMS_FS_PERMS_EXEC, diff --git a/cpukit/libcsupport/src/fchmod.c b/cpukit/libcsupport/src/fchmod.c index bc3d71f96a..ad5948c7dc 100644 --- a/cpukit/libcsupport/src/fchmod.c +++ b/cpukit/libcsupport/src/fchmod.c @@ -44,27 +44,28 @@ int rtems_filesystem_chmod( const rtems_filesystem_location_info_t *loc, - mode_t mode + mode_t mode ) { const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry; - int rv; + int rv; if ( mt_entry->writeable || rtems_filesystem_location_is_null( loc ) ) { struct stat st; - memset( &st, 0, sizeof(st) ); + memset( &st, 0, sizeof( st ) ); - rv = (*loc->handlers->fstat_h)( loc, &st ); + rv = ( *loc->handlers->fstat_h )( loc, &st ); if ( rv == 0 ) { uid_t uid = geteuid(); if ( uid == 0 || st.st_uid == uid ) { - mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX; + mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | + S_ISVTX; - mode = (st.st_mode & ~mask) | (mode & mask); + mode = ( st.st_mode & ~mask ) | ( mode & mask ); - rv = (*mt_entry->ops->fchmod_h)( loc, mode ); + rv = ( *mt_entry->ops->fchmod_h )( loc, mode ); } else { errno = EPERM; rv = -1; @@ -83,7 +84,7 @@ int rtems_filesystem_chmod( */ int fchmod( int fd, mode_t mode ) { - int rv; + int rv; rtems_libio_t *iop; LIBIO_GET_IOP( fd, iop ); diff --git a/cpukit/libcsupport/src/fchown.c b/cpukit/libcsupport/src/fchown.c index f0c9d2b23e..f7809a8067 100644 --- a/cpukit/libcsupport/src/fchown.c +++ b/cpukit/libcsupport/src/fchown.c @@ -44,24 +44,24 @@ int rtems_filesystem_chown( const rtems_filesystem_location_info_t *loc, - uid_t owner, - gid_t group + uid_t owner, + gid_t group ) { const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry; - int rv; + int rv; if ( mt_entry->writeable || rtems_filesystem_location_is_null( loc ) ) { struct stat st; - memset( &st, 0, sizeof(st) ); + memset( &st, 0, sizeof( st ) ); - rv = (*loc->handlers->fstat_h)( loc, &st ); + rv = ( *loc->handlers->fstat_h )( loc, &st ); if ( rv == 0 ) { uid_t uid = geteuid(); if ( uid == 0 || st.st_uid == uid ) { - rv = (*mt_entry->ops->chown_h)( loc, owner, group ); + rv = ( *mt_entry->ops->chown_h )( loc, owner, group ); } else { errno = EPERM; rv = -1; @@ -80,7 +80,7 @@ int rtems_filesystem_chown( */ int fchown( int fd, uid_t owner, gid_t group ) { - int rv; + int rv; rtems_libio_t *iop; LIBIO_GET_IOP( fd, iop ); diff --git a/cpukit/libcsupport/src/fcntl.c b/cpukit/libcsupport/src/fcntl.c index 43e202c055..02505045c0 100644 --- a/cpukit/libcsupport/src/fcntl.c +++ b/cpukit/libcsupport/src/fcntl.c @@ -53,7 +53,7 @@ static int duplicate_iop( rtems_libio_t *iop ) oflag = rtems_libio_to_fcntl_flags( rtems_libio_iop_flags( iop ) ); diop = rtems_libio_allocate(); - if (diop != NULL) { + if ( diop != NULL ) { rtems_filesystem_instance_lock( &iop->pathinfo ); rtems_filesystem_location_clone( &diop->pathinfo, &iop->pathinfo ); rtems_filesystem_instance_unlock( &iop->pathinfo ); @@ -64,7 +64,7 @@ static int duplicate_iop( rtems_libio_t *iop ) * * FIXME: What to do with the path? */ - rv = (*diop->pathinfo.handlers->open_h)( diop, NULL, oflag, 0 ); + rv = ( *diop->pathinfo.handlers->open_h )( diop, NULL, oflag, 0 ); if ( rv == 0 ) { rtems_libio_iop_flags_set( diop, LIBIO_FLAGS_OPEN ); rv = rtems_libio_iop_to_descriptor( diop ); @@ -89,15 +89,14 @@ static int duplicate2_iop( rtems_libio_t *iop, int fd2 ) iop2 = rtems_libio_iop( fd2 ); - if (iop != iop2) - { + if ( iop != iop2 ) { int oflag; - if ((rtems_libio_iop_flags( iop2 ) & LIBIO_FLAGS_OPEN) != 0) { - rv = (*iop2->pathinfo.handlers->close_h)( iop2 ); + if ( ( rtems_libio_iop_flags( iop2 ) & LIBIO_FLAGS_OPEN ) != 0 ) { + rv = ( *iop2->pathinfo.handlers->close_h )( iop2 ); } - if (rv == 0) { + if ( rv == 0 ) { oflag = rtems_libio_to_fcntl_flags( rtems_libio_iop_flags( iop ) ); rtems_libio_iop_flags_set( iop2, rtems_libio_from_fcntl_flags( oflag ) ); @@ -111,7 +110,7 @@ static int duplicate2_iop( rtems_libio_t *iop, int fd2 ) * * FIXME: What to do with the path? */ - rv = (*iop2->pathinfo.handlers->open_h)( iop2, NULL, oflag, 0 ); + rv = ( *iop2->pathinfo.handlers->open_h )( iop2, NULL, oflag, 0 ); if ( rv == 0 ) { rv = fd2; } @@ -121,11 +120,7 @@ static int duplicate2_iop( rtems_libio_t *iop, int fd2 ) return rv; } -static int vfcntl( - int fd, - int cmd, - va_list ap -) +static int vfcntl( int fd, int cmd, va_list ap ) { rtems_libio_t *iop; int fd2; @@ -144,20 +139,21 @@ static int vfcntl( */ switch ( cmd ) { - case F_DUPFD: /* dup */ + case F_DUPFD: /* dup */ ret = duplicate_iop( iop ); break; - case F_DUP2FD: /* dup2 */ + case F_DUP2FD: /* dup2 */ fd2 = va_arg( ap, int ); ret = duplicate2_iop( iop, fd2 ); break; - case F_GETFD: /* get f_flags */ - ret = ((rtems_libio_iop_flags(iop) & LIBIO_FLAGS_CLOSE_ON_EXEC) != 0); + case F_GETFD: /* get f_flags */ + ret = + ( ( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_CLOSE_ON_EXEC ) != 0 ); break; - case F_SETFD: /* set f_flags */ + case F_SETFD: /* set f_flags */ /* * Interpret the third argument as the "close on exec()" flag. * If this argument is 1, then the file descriptor is to be closed @@ -166,13 +162,14 @@ static int vfcntl( * F_GETFD work. */ - if ( va_arg( ap, int ) ) + if ( va_arg( ap, int ) ) { rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_CLOSE_ON_EXEC ); - else + } else { rtems_libio_iop_flags_clear( iop, LIBIO_FLAGS_CLOSE_ON_EXEC ); + } break; - case F_GETFL: /* more flags (cloexec) */ + case F_GETFL: /* more flags (cloexec) */ ret = rtems_libio_to_fcntl_flags( rtems_libio_iop_flags( iop ) ); break; @@ -203,12 +200,12 @@ static int vfcntl( ret = -1; break; - case F_SETOWN: /* for sockets. */ + case F_SETOWN: /* for sockets. */ errno = ENOTSUP; ret = -1; break; - case F_GETOWN: /* for sockets. */ + case F_GETOWN: /* for sockets. */ errno = ENOTSUP; ret = -1; break; @@ -224,12 +221,12 @@ static int vfcntl( * filesystem specific handler a chance to process this. */ - if (ret >= 0) { - int err = (*iop->pathinfo.handlers->fcntl_h)( iop, cmd ); - if (err == 0 && !rtems_libio_iop_is_open( iop ) ) { + if ( ret >= 0 ) { + int err = ( *iop->pathinfo.handlers->fcntl_h )( iop, cmd ); + if ( err == 0 && !rtems_libio_iop_is_open( iop ) ) { err = EBADF; } - if (err != 0) { + if ( err != 0 ) { errno = err; ret = -1; } @@ -239,37 +236,27 @@ static int vfcntl( return ret; } -int fcntl( - int fd, - int cmd, - ... -) +int fcntl( int fd, int cmd, ... ) { - int ret; - va_list ap; + int ret; + va_list ap; va_start( ap, cmd ); - ret = vfcntl(fd,cmd,ap); - va_end(ap); + ret = vfcntl( fd, cmd, ap ); + va_end( ap ); return ret; } - /* * _fcntl_r * * This is the Newlib dependent reentrant version of fcntl(). */ -#if defined(RTEMS_NEWLIB) && !defined(HAVE_FCNTL_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE_FCNTL_R ) #include -int _fcntl_r( - struct _reent *ptr RTEMS_UNUSED, - int fd, - int cmd, - int arg -) +int _fcntl_r( struct _reent *ptr RTEMS_UNUSED, int fd, int cmd, int arg ) { return fcntl( fd, cmd, arg ); } diff --git a/cpukit/libcsupport/src/fdatasync.c b/cpukit/libcsupport/src/fdatasync.c index a2cd2540e1..fe2c16da83 100644 --- a/cpukit/libcsupport/src/fdatasync.c +++ b/cpukit/libcsupport/src/fdatasync.c @@ -43,9 +43,7 @@ #include #include -int fdatasync( - int fd -) +int fdatasync( int fd ) { rtems_libio_t *iop; int rv; @@ -56,7 +54,7 @@ int fdatasync( * Now process the fdatasync(). */ - rv = (*iop->pathinfo.handlers->fdatasync_h)( iop ); + rv = ( *iop->pathinfo.handlers->fdatasync_h )( iop ); rtems_libio_iop_drop( iop ); return rv; } diff --git a/cpukit/libcsupport/src/flockfile.c b/cpukit/libcsupport/src/flockfile.c index 00f7db5852..66dcc279b4 100644 --- a/cpukit/libcsupport/src/flockfile.c +++ b/cpukit/libcsupport/src/flockfile.c @@ -16,14 +16,14 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE_FLOCKFILE) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE_FLOCKFILE ) #include /** * This is a non-functional stub */ -void flockfile(FILE* file) +void flockfile( FILE *file ) { (void) file; } diff --git a/cpukit/libcsupport/src/fpathconf.c b/cpukit/libcsupport/src/fpathconf.c index 471505bf07..fc3a8e5845 100644 --- a/cpukit/libcsupport/src/fpathconf.c +++ b/cpukit/libcsupport/src/fpathconf.c @@ -46,13 +46,10 @@ /** * POSIX 1003.1b - 5.7.1 - Configurable Pathname Varables */ -long fpathconf( - int fd, - int name -) +long fpathconf( int fd, int name ) { - long return_value; - rtems_libio_t *iop; + long return_value; + rtems_libio_t *iop; const rtems_filesystem_limits_and_options_t *the_limits; LIBIO_GET_IOP( fd, iop ); diff --git a/cpukit/libcsupport/src/free.c b/cpukit/libcsupport/src/free.c index c5716b214e..a07028b4bb 100644 --- a/cpukit/libcsupport/src/free.c +++ b/cpukit/libcsupport/src/free.c @@ -51,7 +51,7 @@ RTEMS_INTERRUPT_LOCK_DEFINE( static, _Malloc_GC_lock, "Malloc GC" ) static void *_Malloc_Get_deferred_free( void ) { rtems_interrupt_lock_context lock_context; - void *p; + void *p; rtems_interrupt_lock_acquire( &_Malloc_GC_lock, &lock_context ); p = rtems_chain_get_unprotected( &_Malloc_GC_list ); @@ -75,7 +75,7 @@ void _Malloc_Process_deferred_frees( void ) static void _Malloc_Deferred_free( void *p ) { rtems_interrupt_lock_context lock_context; - rtems_chain_node *node; + rtems_chain_node *node; node = (rtems_chain_node *) p; @@ -85,23 +85,25 @@ static void _Malloc_Deferred_free( void *p ) rtems_interrupt_lock_release( &_Malloc_GC_lock, &lock_context ); } -void free( - void *ptr -) +void free( void *ptr ) { - if ( !ptr ) + if ( !ptr ) { return; + } /* * Do not attempt to free memory if in a critical section or ISR. */ if ( _Malloc_System_state() != MALLOC_SYSTEM_STATE_NORMAL ) { - _Malloc_Deferred_free(ptr); - return; + _Malloc_Deferred_free( ptr ); + return; } if ( !_Protected_heap_Free( RTEMS_Malloc_Heap, ptr ) ) { - rtems_fatal( RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE, (rtems_fatal_code) ptr ); + rtems_fatal( + RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE, + (rtems_fatal_code) ptr + ); } } #endif diff --git a/cpukit/libcsupport/src/freenode.c b/cpukit/libcsupport/src/freenode.c index f37b8fae5f..9f5aa94c37 100644 --- a/cpukit/libcsupport/src/freenode.c +++ b/cpukit/libcsupport/src/freenode.c @@ -45,7 +45,7 @@ void rtems_filesystem_location_free( rtems_filesystem_location_info_t *loc ) { if ( loc->mt_entry != NULL ) { rtems_filesystem_instance_lock( loc ); - (*loc->mt_entry->ops->freenod_h)( loc ); + ( *loc->mt_entry->ops->freenod_h )( loc ); rtems_filesystem_instance_unlock( loc ); rtems_filesystem_location_remove_from_mt_entry( loc ); } diff --git a/cpukit/libcsupport/src/fstat.c b/cpukit/libcsupport/src/fstat.c index 3f6fb2bb4d..7c6068346a 100644 --- a/cpukit/libcsupport/src/fstat.c +++ b/cpukit/libcsupport/src/fstat.c @@ -39,10 +39,7 @@ #include #include -int fstat( - int fd, - struct stat *sbuf -) +int fstat( int fd, struct stat *sbuf ) { rtems_libio_t *iop; int rv; @@ -50,8 +47,9 @@ int fstat( /* * Check to see if we were passed a valid pointer. */ - if ( !sbuf ) + if ( !sbuf ) { rtems_set_errno_and_return_minus_one( EFAULT ); + } /* * Now process the stat() request. @@ -62,10 +60,10 @@ int fstat( * Zero out the stat structure so the various support * versions of stat don't have to. */ - memset( sbuf, 0, sizeof(struct stat) ); + memset( sbuf, 0, sizeof( struct stat ) ); - rv = (*iop->pathinfo.handlers->fstat_h)( &iop->pathinfo, sbuf ); - if (rv == 0 && !rtems_libio_iop_is_open( iop ) ) { + rv = ( *iop->pathinfo.handlers->fstat_h )( &iop->pathinfo, sbuf ); + if ( rv == 0 && !rtems_libio_iop_is_open( iop ) ) { errno = EBADF; rv = -1; } @@ -79,15 +77,11 @@ int fstat( * This is the Newlib dependent reentrant version of fstat(). */ -#if defined(RTEMS_NEWLIB) && !defined(HAVE_FSTAT_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE_FSTAT_R ) #include -int _fstat_r( - struct _reent *ptr RTEMS_UNUSED, - int fd, - struct stat *buf -) +int _fstat_r( struct _reent *ptr RTEMS_UNUSED, int fd, struct stat *buf ) { return fstat( fd, buf ); } diff --git a/cpukit/libcsupport/src/fsync.c b/cpukit/libcsupport/src/fsync.c index a145d0b1b7..0507520e20 100644 --- a/cpukit/libcsupport/src/fsync.c +++ b/cpukit/libcsupport/src/fsync.c @@ -45,9 +45,7 @@ /** * POSIX 1003.1b 6.6.1 - Synchronize the State of a File */ -int fsync( - int fd -) +int fsync( int fd ) { rtems_libio_t *iop; int rv; @@ -58,7 +56,7 @@ int fsync( * Now process the fsync(). */ - rv = (*iop->pathinfo.handlers->fsync_h)( iop ); + rv = ( *iop->pathinfo.handlers->fsync_h )( iop ); rtems_libio_iop_drop( iop ); return rv; } diff --git a/cpukit/libcsupport/src/ftruncate.c b/cpukit/libcsupport/src/ftruncate.c index 99c9046df7..ef9cdbd1b2 100644 --- a/cpukit/libcsupport/src/ftruncate.c +++ b/cpukit/libcsupport/src/ftruncate.c @@ -50,7 +50,7 @@ int ftruncate( int fd, off_t length ) LIBIO_GET_IOP_WITH_ACCESS( fd, iop, LIBIO_FLAGS_WRITE, EINVAL ); - rv = (*iop->pathinfo.handlers->ftruncate_h)( iop, length ); + rv = ( *iop->pathinfo.handlers->ftruncate_h )( iop, length ); rtems_libio_iop_drop( iop ); } else { errno = EINVAL; diff --git a/cpukit/libcsupport/src/ftrylockfile.c b/cpukit/libcsupport/src/ftrylockfile.c index c6886fbdf9..4849cdb4db 100644 --- a/cpukit/libcsupport/src/ftrylockfile.c +++ b/cpukit/libcsupport/src/ftrylockfile.c @@ -10,14 +10,14 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE_FTRYLOCKFILE) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE_FTRYLOCKFILE ) #include #include #include /* This is a non-functional stub */ -int ftrylockfile(FILE* file) +int ftrylockfile( FILE *file ) { (void) file; rtems_set_errno_and_return_minus_one( ENOTSUP ); diff --git a/cpukit/libcsupport/src/funlockfile.c b/cpukit/libcsupport/src/funlockfile.c index 53bb7e6110..9714c2ba28 100644 --- a/cpukit/libcsupport/src/funlockfile.c +++ b/cpukit/libcsupport/src/funlockfile.c @@ -17,14 +17,14 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE_FUNLOCKFILE) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE_FUNLOCKFILE ) #include /** * This is a non-functional stub */ -void funlockfile(FILE* file) +void funlockfile( FILE *file ) { (void) file; } diff --git a/cpukit/libcsupport/src/futimens.c b/cpukit/libcsupport/src/futimens.c index d4a9282e73..6b5cbdb1af 100644 --- a/cpukit/libcsupport/src/futimens.c +++ b/cpukit/libcsupport/src/futimens.c @@ -49,14 +49,11 @@ * * Set file access and modification times */ -int futimens( - int fd, - const struct timespec times[2] -) +int futimens( int fd, const struct timespec times[ 2 ] ) { - int rv; - rtems_libio_t *iop; - struct timespec new_times[2]; + int rv; + rtems_libio_t *iop; + struct timespec new_times[ 2 ]; const rtems_filesystem_location_info_t *currentloc = NULL; LIBIO_GET_IOP_WITH_ACCESS( fd, iop, LIBIO_FLAGS_READ, EBADF ); @@ -75,10 +72,7 @@ int futimens( return rv; } - rv = (*currentloc->mt_entry->ops->utimens_h)( - currentloc, - new_times - ); + rv = ( *currentloc->mt_entry->ops->utimens_h )( currentloc, new_times ); rtems_libio_iop_drop( iop ); diff --git a/cpukit/libcsupport/src/getdents.c b/cpukit/libcsupport/src/getdents.c index b04d26282c..03696eaa41 100644 --- a/cpukit/libcsupport/src/getdents.c +++ b/cpukit/libcsupport/src/getdents.c @@ -46,11 +46,7 @@ /* * Prototypes to avoid warnings */ -int getdents( - int dd_fd, - char *dd_buf, - int dd_len -); +int getdents( int dd_fd, char *dd_buf, int dd_len ); /** * SVR4 and SVID extension required by Newlib readdir() family. @@ -59,15 +55,11 @@ int getdents( * the current directory position index. These entries will be placed in * character array pointed to by -dd_buf- */ -int getdents( - int dd_fd, - char *dd_buf, - int dd_len -) +int getdents( int dd_fd, char *dd_buf, int dd_len ) { rtems_libio_t *iop; - mode_t type; - int result; + mode_t type; + int result; /* * Get the file control block structure associated with the file descriptor @@ -87,7 +79,7 @@ int getdents( * Return the number of bytes that were actually transfered as a result * of the read attempt. */ - result = (*iop->pathinfo.handlers->read_h)( iop, dd_buf, dd_len ); + result = ( *iop->pathinfo.handlers->read_h )( iop, dd_buf, dd_len ); rtems_libio_iop_drop( iop ); return result; } diff --git a/cpukit/libcsupport/src/getgrent.c b/cpukit/libcsupport/src/getgrent.c index 81527cddf9..069e9046fd 100644 --- a/cpukit/libcsupport/src/getgrent.c +++ b/cpukit/libcsupport/src/getgrent.c @@ -31,8 +31,8 @@ #include typedef struct { - FILE *fp; - char buf[256]; + FILE *fp; + char buf[ 256 ]; struct group grp; } grp_context; @@ -40,48 +40,57 @@ static pthread_once_t grp_once = PTHREAD_ONCE_INIT; static pthread_key_t grp_key; -static void grp_init(void) +static void grp_init( void ) { - pthread_key_create(&grp_key, free); + pthread_key_create( &grp_key, free ); } -static grp_context *grp_get_context(void) +static grp_context *grp_get_context( void ) { - pthread_once(&grp_once, grp_init); + pthread_once( &grp_once, grp_init ); - return pthread_getspecific(grp_key); + return pthread_getspecific( grp_key ); } -struct group *getgrent(void) +struct group *getgrent( void ) { grp_context *ctx = grp_get_context(); - if (ctx == NULL) + if ( ctx == NULL ) { return NULL; + } - if (ctx->fp == NULL) + if ( ctx->fp == NULL ) { return NULL; + } - if (!_libcsupport_scangr(ctx->fp, &ctx->grp, ctx->buf, sizeof(ctx->buf))) + if ( !_libcsupport_scangr( + ctx->fp, + &ctx->grp, + ctx->buf, + sizeof( ctx->buf ) + ) ) { return NULL; + } return &ctx->grp; } -void setgrent(void) +void setgrent( void ) { grp_context *ctx = grp_get_context(); - if (ctx == NULL) { + if ( ctx == NULL ) { int eno; - ctx = calloc(1, sizeof(*ctx)); - if (ctx == NULL) + ctx = calloc( 1, sizeof( *ctx ) ); + if ( ctx == NULL ) { return; + } - eno = pthread_setspecific(grp_key, ctx); - if (eno != 0) { - free(ctx); + eno = pthread_setspecific( grp_key, ctx ); + if ( eno != 0 ) { + free( ctx ); return; } @@ -89,25 +98,27 @@ void setgrent(void) _libcsupport_pwdgrp_init(); - if (ctx->fp != NULL) - fclose(ctx->fp); + if ( ctx->fp != NULL ) { + fclose( ctx->fp ); + } - ctx->fp = fopen("/etc/group", "r"); + ctx->fp = fopen( "/etc/group", "r" ); } -void endgrent(void) +void endgrent( void ) { grp_context *ctx = grp_get_context(); int sc; - if (ctx == NULL) + if ( ctx == NULL ) { return; - - if (ctx->fp != NULL) { - fclose(ctx->fp); } - free(ctx); - sc = pthread_setspecific(grp_key, NULL); - _Assert_Unused_variable_equals(sc, 0); + if ( ctx->fp != NULL ) { + fclose( ctx->fp ); + } + + free( ctx ); + sc = pthread_setspecific( grp_key, NULL ); + _Assert_Unused_variable_equals( sc, 0 ); } diff --git a/cpukit/libcsupport/src/getgrnam.c b/cpukit/libcsupport/src/getgrnam.c index 149a4f1f20..882181612c 100644 --- a/cpukit/libcsupport/src/getgrnam.c +++ b/cpukit/libcsupport/src/getgrnam.c @@ -29,27 +29,25 @@ /* * Static, thread-unsafe, buffers */ -static char grbuf[200]; +static char grbuf[ 200 ]; static struct group grent; -struct group *getgrnam( - const char *name -) +struct group *getgrnam( const char *name ) { struct group *p; - if(getgrnam_r(name, &grent, grbuf, sizeof grbuf, &p)) + if ( getgrnam_r( name, &grent, grbuf, sizeof grbuf, &p ) ) { return NULL; + } return p; } -struct group *getgrgid( - gid_t gid -) +struct group *getgrgid( gid_t gid ) { struct group *p; - if(getgrgid_r(gid, &grent, grbuf, sizeof grbuf, &p)) + if ( getgrgid_r( gid, &grent, grbuf, sizeof grbuf, &p ) ) { return NULL; + } return p; } diff --git a/cpukit/libcsupport/src/getgroups.c b/cpukit/libcsupport/src/getgroups.c index 56868b620b..8ce4be413f 100644 --- a/cpukit/libcsupport/src/getgroups.c +++ b/cpukit/libcsupport/src/getgroups.c @@ -48,21 +48,18 @@ /** * 4.2.3 Get Supplementary IDs, P1003.1b-1993, p. 86 */ -int getgroups( - int gidsetsize, - gid_t grouplist[] -) +int getgroups( int gidsetsize, gid_t grouplist[] ) { - int rv; - struct passwd pwd; + int rv; + struct passwd pwd; struct passwd *pwd_res; - char buf[256]; - gid_t gid; - const char *user; - struct group *grp; + char buf[ 256 ]; + gid_t gid; + const char *user; + struct group *grp; - rv = getpwuid_r(getuid(), &pwd, &buf[0], sizeof(buf), &pwd_res); - if (rv != 0) { + rv = getpwuid_r( getuid(), &pwd, &buf[ 0 ], sizeof( buf ), &pwd_res ); + if ( rv != 0 ) { return rv; } @@ -71,17 +68,17 @@ int getgroups( setgrent(); - while ((grp = getgrent()) != NULL) { - char **mem = &grp->gr_mem[0]; + while ( ( grp = getgrent() ) != NULL ) { + char **mem = &grp->gr_mem[ 0 ]; - if (grp->gr_gid == gid) { + if ( grp->gr_gid == gid ) { continue; } - while (*mem != NULL) { - if (strcmp(*mem, user) == 0) { - if (rv < gidsetsize) { - grouplist[rv] = grp->gr_gid; + while ( *mem != NULL ) { + if ( strcmp( *mem, user ) == 0 ) { + if ( rv < gidsetsize ) { + grouplist[ rv ] = grp->gr_gid; } ++rv; @@ -95,9 +92,9 @@ int getgroups( endgrent(); - if (gidsetsize == 0 || rv <= gidsetsize) { + if ( gidsetsize == 0 || rv <= gidsetsize ) { return rv; } else { - rtems_set_errno_and_return_minus_one(EINVAL); + rtems_set_errno_and_return_minus_one( EINVAL ); } } diff --git a/cpukit/libcsupport/src/getlogin.c b/cpukit/libcsupport/src/getlogin.c index 9d4c05645a..99424696ba 100644 --- a/cpukit/libcsupport/src/getlogin.c +++ b/cpukit/libcsupport/src/getlogin.c @@ -64,26 +64,26 @@ char *getlogin( void ) * * @note P1003.1c/D10, p. 49 adds getlogin_r(). */ -int getlogin_r( - char *name, - size_t namesize -) +int getlogin_r( char *name, size_t namesize ) { struct passwd *pw; char *pname; - if ( !name ) + if ( !name ) { return EFAULT; + } - if ( namesize < LOGIN_NAME_MAX ) + if ( namesize < LOGIN_NAME_MAX ) { return ERANGE; + } /* Set the pointer to a default name */ pname = ""; - pw = getpwuid(getuid()); - if ( pw ) - pname = pw->pw_name; + pw = getpwuid( getuid() ); + if ( pw ) { + pname = pw->pw_name; + } strncpy( name, pname, LOGIN_NAME_MAX ); return 0; diff --git a/cpukit/libcsupport/src/getpagesize.c b/cpukit/libcsupport/src/getpagesize.c index bfcb001cb2..b05592ab7a 100644 --- a/cpukit/libcsupport/src/getpagesize.c +++ b/cpukit/libcsupport/src/getpagesize.c @@ -47,7 +47,7 @@ * gcc 2.8.1 plus gnat 3.13p and gcc 3.0.1 require it to be there and * return a reasonable value. */ -int getpagesize(void) +int getpagesize( void ) { return PAGE_SIZE; } diff --git a/cpukit/libcsupport/src/getpid.c b/cpukit/libcsupport/src/getpid.c index 464504de7e..82f2d4e816 100644 --- a/cpukit/libcsupport/src/getpid.c +++ b/cpukit/libcsupport/src/getpid.c @@ -49,16 +49,14 @@ pid_t getpid( void ) return rtems_object_get_local_node(); } -#if defined(RTEMS_NEWLIB) && !defined(HAVE__GETPID_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__GETPID_R ) #include /** * This is the Newlib dependent reentrant version of getpid(). */ -pid_t _getpid_r( - struct _reent *ptr RTEMS_UNUSED -) +pid_t _getpid_r( struct _reent *ptr RTEMS_UNUSED ) { return getpid(); } diff --git a/cpukit/libcsupport/src/getpwent.c b/cpukit/libcsupport/src/getpwent.c index 4559474d3b..73bfddee50 100644 --- a/cpukit/libcsupport/src/getpwent.c +++ b/cpukit/libcsupport/src/getpwent.c @@ -29,52 +29,54 @@ /* * Static, thread-unsafe, buffers */ -static FILE *passwd_fp; -static char pwbuf[200]; +static FILE *passwd_fp; +static char pwbuf[ 200 ]; static struct passwd pwent; -struct passwd *getpwnam( - const char *name -) +struct passwd *getpwnam( const char *name ) { struct passwd *p; - if(getpwnam_r(name, &pwent, pwbuf, sizeof pwbuf, &p)) + if ( getpwnam_r( name, &pwent, pwbuf, sizeof pwbuf, &p ) ) { return NULL; + } return p; } -struct passwd *getpwuid( - uid_t uid -) +struct passwd *getpwuid( uid_t uid ) { struct passwd *p; - if(getpwuid_r(uid, &pwent, pwbuf, sizeof pwbuf, &p)) + if ( getpwuid_r( uid, &pwent, pwbuf, sizeof pwbuf, &p ) ) { return NULL; + } return p; } -struct passwd *getpwent(void) +struct passwd *getpwent( void ) { - if (passwd_fp == NULL) + if ( passwd_fp == NULL ) { return NULL; - if (!_libcsupport_scanpw(passwd_fp, &pwent, pwbuf, sizeof pwbuf)) + } + if ( !_libcsupport_scanpw( passwd_fp, &pwent, pwbuf, sizeof pwbuf ) ) { return NULL; + } return &pwent; } -void setpwent(void) +void setpwent( void ) { _libcsupport_pwdgrp_init(); - if (passwd_fp != NULL) - fclose(passwd_fp); - passwd_fp = fopen("/etc/passwd", "r"); + if ( passwd_fp != NULL ) { + fclose( passwd_fp ); + } + passwd_fp = fopen( "/etc/passwd", "r" ); } -void endpwent(void) +void endpwent( void ) { - if (passwd_fp != NULL) - fclose(passwd_fp); + if ( passwd_fp != NULL ) { + fclose( passwd_fp ); + } } diff --git a/cpukit/libcsupport/src/getreentglobal.c b/cpukit/libcsupport/src/getreentglobal.c index deeb6a35dd..9888b9e6ef 100644 --- a/cpukit/libcsupport/src/getreentglobal.c +++ b/cpukit/libcsupport/src/getreentglobal.c @@ -12,11 +12,11 @@ #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #ifndef _REENT_THREAD_LOCAL -struct _reent *__getreent(void) +struct _reent *__getreent( void ) { return _GLOBAL_REENT; } diff --git a/cpukit/libcsupport/src/getrusage.c b/cpukit/libcsupport/src/getrusage.c index e849f944f5..4fcc1c6171 100644 --- a/cpukit/libcsupport/src/getrusage.c +++ b/cpukit/libcsupport/src/getrusage.c @@ -61,9 +61,7 @@ static bool usage_visitor( Thread_Control *the_thread, void *arg ) return false; } -static int getrusage_RUSAGE_SELF( - struct rusage *usage -) +static int getrusage_RUSAGE_SELF( struct rusage *usage ) { /* * RTEMS only has a single process so there are no children. The @@ -84,13 +82,11 @@ static int getrusage_RUSAGE_SELF( return 0; } -static int getrusage_RUSAGE_THREAD( - struct rusage *usage -) +static int getrusage_RUSAGE_THREAD( struct rusage *usage ) { - Thread_Control *the_thread; - ISR_lock_Context lock_context; - Timestamp_Control used; + Thread_Control *the_thread; + ISR_lock_Context lock_context; + Timestamp_Control used; the_thread = _Thread_Get( OBJECTS_ID_OF_SELF, &lock_context ); used = _Thread_Get_CPU_time_used( the_thread ); _ISR_lock_ISR_enable( &lock_context ); @@ -100,22 +96,21 @@ static int getrusage_RUSAGE_THREAD( return 0; } -int getrusage( - int who, struct rusage *usage -) +int getrusage( int who, struct rusage *usage ) { - if ( !usage ) + if ( !usage ) { rtems_set_errno_and_return_minus_one( EFAULT ); + } switch ( who ) { - case RUSAGE_SELF: - return getrusage_RUSAGE_SELF( usage ); - case RUSAGE_THREAD: - return getrusage_RUSAGE_THREAD( usage ); - case RUSAGE_CHILDREN: - rtems_set_errno_and_return_minus_one( ENOSYS ); - default: - break; + case RUSAGE_SELF: + return getrusage_RUSAGE_SELF( usage ); + case RUSAGE_THREAD: + return getrusage_RUSAGE_THREAD( usage ); + case RUSAGE_CHILDREN: + rtems_set_errno_and_return_minus_one( ENOSYS ); + default: + break; } rtems_set_errno_and_return_minus_one( EINVAL ); diff --git a/cpukit/libcsupport/src/getuid.c b/cpukit/libcsupport/src/getuid.c index 00c3c6d167..202f1ecd81 100644 --- a/cpukit/libcsupport/src/getuid.c +++ b/cpukit/libcsupport/src/getuid.c @@ -49,4 +49,3 @@ uid_t getuid( void ) { return _POSIX_types_Uid; } - diff --git a/cpukit/libcsupport/src/ioctl.c b/cpukit/libcsupport/src/ioctl.c index 0c7cfc63df..c10c9a9837 100644 --- a/cpukit/libcsupport/src/ioctl.c +++ b/cpukit/libcsupport/src/ioctl.c @@ -48,27 +48,23 @@ #include -int ioctl( - int fd, - ioctl_command_t command, - ... -) +int ioctl( int fd, ioctl_command_t command, ... ) { - va_list ap; - int rc; - rtems_libio_t *iop; - void *buffer; + va_list ap; + int rc; + rtems_libio_t *iop; + void *buffer; LIBIO_GET_IOP( fd, iop ); - va_start(ap, command); + va_start( ap, command ); - buffer = va_arg(ap, void *); + buffer = va_arg( ap, void * ); /* * Now process the ioctl(). */ - rc = (*iop->pathinfo.handlers->ioctl_h)( iop, command, buffer ); + rc = ( *iop->pathinfo.handlers->ioctl_h )( iop, command, buffer ); va_end( ap ); rtems_libio_iop_drop( iop ); diff --git a/cpukit/libcsupport/src/isatty_r.c b/cpukit/libcsupport/src/isatty_r.c index 3ae285fb26..5f5e11c7e5 100644 --- a/cpukit/libcsupport/src/isatty_r.c +++ b/cpukit/libcsupport/src/isatty_r.c @@ -37,18 +37,15 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE__ISATTY_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__ISATTY_R ) - /** +/** * This is the Newlib dependent reentrant version of isatty(). */ #include #include -int _isatty_r( - struct _reent *ptr, - int fd -) +int _isatty_r( struct _reent *ptr, int fd ) { (void) ptr; return isatty( fd ); diff --git a/cpukit/libcsupport/src/issetugid.c b/cpukit/libcsupport/src/issetugid.c index bfc513a5ef..a18b8d28de 100644 --- a/cpukit/libcsupport/src/issetugid.c +++ b/cpukit/libcsupport/src/issetugid.c @@ -37,17 +37,17 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE_ISSETUGID) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE_ISSETUGID ) /* * Prototype to avoid warnings */ -int issetugid (void); +int issetugid( void ); /** * Dummy version of BSD routine */ -int issetugid (void) +int issetugid( void ) { return 0; } diff --git a/cpukit/libcsupport/src/kill_noposix.c b/cpukit/libcsupport/src/kill_noposix.c index add48517fa..7c34b343d8 100644 --- a/cpukit/libcsupport/src/kill_noposix.c +++ b/cpukit/libcsupport/src/kill_noposix.c @@ -33,7 +33,7 @@ * These are directly supported (and completely correct) in the posix api. */ -#if !defined(RTEMS_POSIX_API) +#if !defined( RTEMS_POSIX_API ) int kill( pid_t pid, int sig ) { (void) pid; @@ -42,7 +42,7 @@ int kill( pid_t pid, int sig ) return 0; } -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include int _kill_r( struct _reent *ptr, pid_t pid, int sig ) diff --git a/cpukit/libcsupport/src/lchown.c b/cpukit/libcsupport/src/lchown.c index 8da8bca197..a3ac6ee069 100644 --- a/cpukit/libcsupport/src/lchown.c +++ b/cpukit/libcsupport/src/lchown.c @@ -21,11 +21,11 @@ int lchown( const char *path, uid_t owner, gid_t group ) { - int rv; + int rv; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); + int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK; + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); rv = rtems_filesystem_chown( currentloc, owner, group ); diff --git a/cpukit/libcsupport/src/libio.c b/cpukit/libcsupport/src/libio.c index b7911d7786..c530f9f3f5 100644 --- a/cpukit/libcsupport/src/libio.c +++ b/cpukit/libcsupport/src/libio.c @@ -62,31 +62,31 @@ #undef ACCEPT_O_NDELAY_ALIAS static const rtems_assoc_t access_modes_assoc[] = { - { "READ", LIBIO_FLAGS_READ, O_RDONLY }, - { "WRITE", LIBIO_FLAGS_WRITE, O_WRONLY }, + { "READ", LIBIO_FLAGS_READ, O_RDONLY }, + { "WRITE", LIBIO_FLAGS_WRITE, O_WRONLY }, { "READ/WRITE", LIBIO_FLAGS_READ_WRITE, O_RDWR }, { 0, 0, 0 }, }; static const rtems_assoc_t status_flags_assoc[] = { #ifdef ACCEPT_O_NDELAY_ALIAS - { "NO DELAY", LIBIO_FLAGS_NO_DELAY, O_NDELAY }, + { "NO DELAY", LIBIO_FLAGS_NO_DELAY, O_NDELAY }, #endif - { "NONBLOCK", LIBIO_FLAGS_NO_DELAY, O_NONBLOCK }, - { "APPEND", LIBIO_FLAGS_APPEND, O_APPEND }, + { "NONBLOCK", LIBIO_FLAGS_NO_DELAY, O_NONBLOCK }, + { "APPEND", LIBIO_FLAGS_APPEND, O_APPEND }, { 0, 0, 0 }, }; unsigned int rtems_libio_from_fcntl_flags( int fcntl_flags ) { - unsigned int flags = 0; - uint32_t access_modes; + unsigned int flags = 0; + uint32_t access_modes; /* * Access mode is a small integer */ - access_modes = (unsigned int) (fcntl_flags & O_ACCMODE); + access_modes = (unsigned int) ( fcntl_flags & O_ACCMODE ); fcntl_flags &= ~O_ACCMODE; flags = rtems_assoc_local_by_remote( access_modes_assoc, access_modes ); @@ -94,7 +94,7 @@ unsigned int rtems_libio_from_fcntl_flags( int fcntl_flags ) * Everything else is single bits */ - flags |= (unsigned int ) rtems_assoc_local_by_remote_bitfield( + flags |= (unsigned int) rtems_assoc_local_by_remote_bitfield( status_flags_assoc, (uint32_t) fcntl_flags ); @@ -106,19 +106,19 @@ int rtems_libio_to_fcntl_flags( unsigned int flags ) { int fcntl_flags = 0; - if ( (flags & LIBIO_FLAGS_READ_WRITE) == LIBIO_FLAGS_READ_WRITE ) { + if ( ( flags & LIBIO_FLAGS_READ_WRITE ) == LIBIO_FLAGS_READ_WRITE ) { fcntl_flags |= O_RDWR; - } else if ( (flags & LIBIO_FLAGS_READ) == LIBIO_FLAGS_READ) { + } else if ( ( flags & LIBIO_FLAGS_READ ) == LIBIO_FLAGS_READ ) { fcntl_flags |= O_RDONLY; - } else if ( (flags & LIBIO_FLAGS_WRITE) == LIBIO_FLAGS_WRITE) { + } else if ( ( flags & LIBIO_FLAGS_WRITE ) == LIBIO_FLAGS_WRITE ) { fcntl_flags |= O_WRONLY; } - if ( (flags & LIBIO_FLAGS_NO_DELAY) == LIBIO_FLAGS_NO_DELAY ) { + if ( ( flags & LIBIO_FLAGS_NO_DELAY ) == LIBIO_FLAGS_NO_DELAY ) { fcntl_flags |= O_NONBLOCK; } - if ( (flags & LIBIO_FLAGS_APPEND) == LIBIO_FLAGS_APPEND ) { + if ( ( flags & LIBIO_FLAGS_APPEND ) == LIBIO_FLAGS_APPEND ) { fcntl_flags |= O_APPEND; } @@ -151,9 +151,7 @@ rtems_libio_t *rtems_libio_allocate( void ) return iop; } -void rtems_libio_free_iop( - rtems_libio_t *iop -) +void rtems_libio_free_iop( rtems_libio_t *iop ) { size_t zero; @@ -181,18 +179,16 @@ void rtems_libio_free_iop( rtems_libio_unlock(); } -int rtems_libio_count_open_iops( - void -) +int rtems_libio_count_open_iops( void ) { int open = 0; uint32_t i; /* * No locking needed to count the open iops */ - for (i = 0; i < rtems_libio_number_iops; ++i) { + for ( i = 0; i < rtems_libio_number_iops; ++i ) { const rtems_libio_t *iop = &rtems_libio_iops[ i ]; - if (( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_OPEN ) != 0 ) { + if ( ( rtems_libio_iop_flags( iop ) & LIBIO_FLAGS_OPEN ) != 0 ) { ++open; } } diff --git a/cpukit/libcsupport/src/libio_exit.c b/cpukit/libcsupport/src/libio_exit.c index e159e16bb2..24f06c9793 100644 --- a/cpukit/libcsupport/src/libio_exit.c +++ b/cpukit/libcsupport/src/libio_exit.c @@ -39,9 +39,9 @@ #include -void rtems_libio_exit(void) +void rtems_libio_exit( void ) { - (void)close(0); - (void)close(1); - (void)close(2); + (void) close( 0 ); + (void) close( 1 ); + (void) close( 2 ); } diff --git a/cpukit/libcsupport/src/libio_init.c b/cpukit/libcsupport/src/libio_init.c index 9a47319335..837db0001b 100644 --- a/cpukit/libcsupport/src/libio_init.c +++ b/cpukit/libcsupport/src/libio_init.c @@ -66,19 +66,18 @@ void **rtems_libio_iop_free_tail = &rtems_libio_iop_free_head; static void rtems_libio_init( void ) { - uint32_t i; - rtems_libio_t *iop; + uint32_t i; + rtems_libio_t *iop; - if (rtems_libio_number_iops > 0) - { - iop = rtems_libio_iop_free_head = &rtems_libio_iops[0]; - for (i = 0 ; (i + 1) < rtems_libio_number_iops ; i++, iop++) { - rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_FREE ); - iop->data1 = iop + 1; - } - iop->data1 = NULL; - rtems_libio_iop_free_tail = &iop->data1; + if ( rtems_libio_number_iops > 0 ) { + iop = rtems_libio_iop_free_head = &rtems_libio_iops[ 0 ]; + for ( i = 0; ( i + 1 ) < rtems_libio_number_iops; i++, iop++ ) { + rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_FREE ); + iop->data1 = iop + 1; } + iop->data1 = NULL; + rtems_libio_iop_free_tail = &iop->data1; + } } RTEMS_SYSINIT_ITEM( diff --git a/cpukit/libcsupport/src/link.c b/cpukit/libcsupport/src/link.c index 3a5b4ce730..71b1b30cfc 100644 --- a/cpukit/libcsupport/src/link.c +++ b/cpukit/libcsupport/src/link.c @@ -46,13 +46,11 @@ */ int link( const char *path1, const char *path2 ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx_1; rtems_filesystem_eval_path_context_t ctx_2; - int eval_flags_1 = RTEMS_FS_FOLLOW_LINK; - int eval_flags_2 = RTEMS_FS_FOLLOW_LINK - | RTEMS_FS_MAKE - | RTEMS_FS_EXCLUSIVE; + int eval_flags_1 = RTEMS_FS_FOLLOW_LINK; + int eval_flags_2 = RTEMS_FS_FOLLOW_LINK | RTEMS_FS_MAKE | RTEMS_FS_EXCLUSIVE; const rtems_filesystem_location_info_t *currentloc_1 = rtems_filesystem_eval_path_start( &ctx_1, path1, eval_flags_1 ); const rtems_filesystem_location_info_t *currentloc_2 = @@ -63,7 +61,7 @@ int link( const char *path1, const char *path2 ) currentloc_2 ); if ( rv == 0 ) { - rv = (*currentloc_2->mt_entry->ops->link_h)( + rv = ( *currentloc_2->mt_entry->ops->link_h )( currentloc_2, currentloc_1, rtems_filesystem_eval_path_get_token( &ctx_2 ), @@ -77,7 +75,7 @@ int link( const char *path1, const char *path2 ) return rv; } -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include @@ -86,8 +84,8 @@ int link( const char *path1, const char *path2 ) */ int _link_r( struct _reent *ptr RTEMS_UNUSED, - const char *path1, - const char *path2 + const char *path1, + const char *path2 ) { return link( path1, path2 ); diff --git a/cpukit/libcsupport/src/lseek.c b/cpukit/libcsupport/src/lseek.c index 095356aee9..c8017d3cc3 100644 --- a/cpukit/libcsupport/src/lseek.c +++ b/cpukit/libcsupport/src/lseek.c @@ -46,7 +46,7 @@ off_t lseek( int fd, off_t offset, int whence ) LIBIO_GET_IOP( fd, iop ); - rv = (*iop->pathinfo.handlers->lseek_h)( iop, offset, whence ); + rv = ( *iop->pathinfo.handlers->lseek_h )( iop, offset, whence ); rtems_libio_iop_drop( iop ); return rv; } @@ -57,15 +57,15 @@ off_t lseek( int fd, off_t offset, int whence ) * This is the Newlib dependent reentrant version of lseek(). */ -#if defined(RTEMS_NEWLIB) && !defined(HAVE__LSEEK_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__LSEEK_R ) #include off_t _lseek_r( struct _reent *ptr RTEMS_UNUSED, - int fd, - off_t offset, - int whence + int fd, + off_t offset, + int whence ) { return lseek( fd, offset, whence ); diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c index 761603ceee..adccd9b2b7 100644 --- a/cpukit/libcsupport/src/malloc.c +++ b/cpukit/libcsupport/src/malloc.c @@ -44,11 +44,9 @@ #include "malloc_p.h" -void *malloc( - size_t size -) +void *malloc( size_t size ) { - void *return_this; + void *return_this; if ( size == 0 ) { return NULL; @@ -63,13 +61,11 @@ void *malloc( return return_this; } -size_t malloc_usable_size( - void *area -) +size_t malloc_usable_size( void *area ) { - Heap_Block* block = NULL; - size_t size = 0; - bool needs_lock; + Heap_Block *block = NULL; + size_t size = 0; + bool needs_lock; if ( area == NULL ) { return 0; @@ -82,12 +78,12 @@ size_t malloc_usable_size( } block = _Heap_Block_of_alloc_area( - (uintptr_t)area, + (uintptr_t) area, RTEMS_Malloc_Heap->page_size ); - if (block) { - size = _Heap_Block_size(block); + if ( block ) { + size = _Heap_Block_size( block ); } if ( needs_lock ) { diff --git a/cpukit/libcsupport/src/malloc_deferred.c b/cpukit/libcsupport/src/malloc_deferred.c index f8efe8ed22..92fb77bb22 100644 --- a/cpukit/libcsupport/src/malloc_deferred.c +++ b/cpukit/libcsupport/src/malloc_deferred.c @@ -81,7 +81,7 @@ void *rtems_heap_allocate_aligned_with_boundary( ) { Heap_Control *heap = RTEMS_Malloc_Heap; - void *p; + void *p; switch ( _Malloc_System_state() ) { case MALLOC_SYSTEM_STATE_NORMAL: @@ -111,14 +111,15 @@ void *rtems_heap_allocate_aligned_with_boundary( } if ( p == NULL && alignment == 0 && boundary == 0 ) { - p = (*rtems_malloc_extend_handler)( heap, size ); + p = ( *rtems_malloc_extend_handler )( heap, size ); } /* * If the user wants us to dirty the allocated memory, then do it. */ - if ( p != NULL && rtems_malloc_dirty_helper != NULL ) - (*rtems_malloc_dirty_helper)( p, size ); + if ( p != NULL && rtems_malloc_dirty_helper != NULL ) { + ( *rtems_malloc_dirty_helper )( p, size ); + } return p; } diff --git a/cpukit/libcsupport/src/malloc_dirtier.c b/cpukit/libcsupport/src/malloc_dirtier.c index 173aedc889..a4164177d5 100644 --- a/cpukit/libcsupport/src/malloc_dirtier.c +++ b/cpukit/libcsupport/src/malloc_dirtier.c @@ -44,10 +44,7 @@ #include #include -void rtems_malloc_dirty_memory( - void *start, - size_t size -) +void rtems_malloc_dirty_memory( void *start, size_t size ) { - (void) memset(start, 0xCF, size); + (void) memset( start, 0xCF, size ); } diff --git a/cpukit/libcsupport/src/malloc_walk.c b/cpukit/libcsupport/src/malloc_walk.c index a693ccc02b..483fbb8f23 100644 --- a/cpukit/libcsupport/src/malloc_walk.c +++ b/cpukit/libcsupport/src/malloc_walk.c @@ -42,7 +42,7 @@ #include -bool malloc_walk(int source, bool printf_enabled) +bool malloc_walk( int source, bool printf_enabled ) { return _Protected_heap_Walk( RTEMS_Malloc_Heap, source, printf_enabled ); } diff --git a/cpukit/libcsupport/src/mallocextenddefault.c b/cpukit/libcsupport/src/mallocextenddefault.c index 9549cbdd29..24aa92797d 100644 --- a/cpukit/libcsupport/src/mallocextenddefault.c +++ b/cpukit/libcsupport/src/mallocextenddefault.c @@ -31,5 +31,5 @@ #include -const rtems_heap_extend_handler rtems_malloc_extend_handler = - rtems_heap_null_extend; +const rtems_heap_extend_handler + rtems_malloc_extend_handler = rtems_heap_null_extend; diff --git a/cpukit/libcsupport/src/mallocinfo.c b/cpukit/libcsupport/src/mallocinfo.c index d02e8a0017..5217ec46f7 100644 --- a/cpukit/libcsupport/src/mallocinfo.c +++ b/cpukit/libcsupport/src/mallocinfo.c @@ -40,12 +40,11 @@ #include #include -int malloc_info( - Heap_Information_block *the_info -) +int malloc_info( Heap_Information_block *the_info ) { - if ( !the_info ) + if ( !the_info ) { return -1; + } _Protected_heap_Get_information( RTEMS_Malloc_Heap, the_info ); return 0; diff --git a/cpukit/libcsupport/src/mallocsetheapptr.c b/cpukit/libcsupport/src/mallocsetheapptr.c index 496592e6b3..6b26f2a520 100644 --- a/cpukit/libcsupport/src/mallocsetheapptr.c +++ b/cpukit/libcsupport/src/mallocsetheapptr.c @@ -41,9 +41,7 @@ #include #include "malloc_p.h" -void malloc_set_heap_pointer( - Heap_Control *new_heap -) +void malloc_set_heap_pointer( Heap_Control *new_heap ) { RTEMS_Malloc_Heap = new_heap; } diff --git a/cpukit/libcsupport/src/mkdir.c b/cpukit/libcsupport/src/mkdir.c index 3f7fad4321..11fffd6215 100644 --- a/cpukit/libcsupport/src/mkdir.c +++ b/cpukit/libcsupport/src/mkdir.c @@ -46,10 +46,7 @@ /** * POSIX 1003.1b 5.4.1 - Make a Directory */ -int mkdir( - const char *pathname, - mode_t mode -) +int mkdir( const char *pathname, mode_t mode ) { - return mknod( pathname, mode | S_IFDIR, 0LL); + return mknod( pathname, mode | S_IFDIR, 0LL ); } diff --git a/cpukit/libcsupport/src/mkfifo.c b/cpukit/libcsupport/src/mkfifo.c index ac5d944898..2cfa7be9f4 100644 --- a/cpukit/libcsupport/src/mkfifo.c +++ b/cpukit/libcsupport/src/mkfifo.c @@ -44,10 +44,7 @@ /** * POSIX 1003.1b 5.4.1 - Make a FIFO Special File */ -int mkfifo( - const char *path, - mode_t mode -) +int mkfifo( const char *path, mode_t mode ) { return mknod( path, mode | S_IFIFO, 0LL ); } diff --git a/cpukit/libcsupport/src/mknod.c b/cpukit/libcsupport/src/mknod.c index cea3370374..7b91ed2eae 100644 --- a/cpukit/libcsupport/src/mknod.c +++ b/cpukit/libcsupport/src/mknod.c @@ -43,17 +43,17 @@ int rtems_filesystem_mknod( const rtems_filesystem_location_info_t *parentloc, - const char *name, - size_t namelen, - mode_t mode, - dev_t dev + const char *name, + size_t namelen, + mode_t mode, + dev_t dev ) { int rv = 0; mode &= ~rtems_filesystem_umask; - switch (mode & S_IFMT) { + switch ( mode & S_IFMT ) { case S_IFBLK: case S_IFCHR: case S_IFDIR: @@ -65,11 +65,11 @@ int rtems_filesystem_mknod( rv = -1; break; } - + if ( rv == 0 ) { const rtems_filesystem_operations_table *ops = parentloc->mt_entry->ops; - rv = (*ops->mknod_h)( parentloc, name, namelen, mode, dev ); + rv = ( *ops->mknod_h )( parentloc, name, namelen, mode, dev ); } return rv; @@ -82,14 +82,13 @@ int rtems_filesystem_mknod( */ int mknod( const char *path, mode_t mode, dev_t dev ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_FOLLOW_LINK - | RTEMS_FS_MAKE - | RTEMS_FS_EXCLUSIVE - | (S_ISDIR(mode) ? RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS : 0); - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); + int eval_flags = RTEMS_FS_FOLLOW_LINK | RTEMS_FS_MAKE | RTEMS_FS_EXCLUSIVE | + ( S_ISDIR( mode ) ? RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS + : 0 ); + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); rv = rtems_filesystem_mknod( currentloc, diff --git a/cpukit/libcsupport/src/mount-mgr.c b/cpukit/libcsupport/src/mount-mgr.c index 4658e7ad0b..a7e353b914 100644 --- a/cpukit/libcsupport/src/mount-mgr.c +++ b/cpukit/libcsupport/src/mount-mgr.c @@ -49,24 +49,24 @@ #include typedef struct { - rtems_chain_node node; + rtems_chain_node node; rtems_filesystem_table_t entry; } filesystem_node; -static RTEMS_CHAIN_DEFINE_EMPTY(filesystem_chain); +static RTEMS_CHAIN_DEFINE_EMPTY( filesystem_chain ); bool rtems_filesystem_iterate( rtems_per_filesystem_routine routine, - void *routine_arg + void *routine_arg ) { - rtems_chain_control *chain = &filesystem_chain; - const rtems_filesystem_table_t *table_entry = &rtems_filesystem_table [0]; - rtems_chain_node *node = NULL; - bool stop = false; + rtems_chain_control *chain = &filesystem_chain; + const rtems_filesystem_table_t *table_entry = &rtems_filesystem_table[ 0 ]; + rtems_chain_node *node = NULL; + bool stop = false; while ( table_entry->type && !stop ) { - stop = (*routine)( table_entry, routine_arg ); + stop = ( *routine )( table_entry, routine_arg ); ++table_entry; } @@ -79,7 +79,7 @@ bool rtems_filesystem_iterate( ) { const filesystem_node *fsn = (filesystem_node *) node; - stop = (*routine)( &fsn->entry, routine_arg ); + stop = ( *routine )( &fsn->entry, routine_arg ); } rtems_libio_unlock(); } @@ -88,11 +88,11 @@ bool rtems_filesystem_iterate( } typedef struct { - const char *type; + const char *type; rtems_filesystem_mount_t mount_h; } find_arg; -static bool find_handler(const rtems_filesystem_table_t *entry, void *arg) +static bool find_handler( const rtems_filesystem_table_t *entry, void *arg ) { find_arg *fa = arg; @@ -105,15 +105,9 @@ static bool find_handler(const rtems_filesystem_table_t *entry, void *arg) } } -rtems_filesystem_mount_t -rtems_filesystem_get_mount_handler( - const char *type -) +rtems_filesystem_mount_t rtems_filesystem_get_mount_handler( const char *type ) { - find_arg fa = { - .type = type, - .mount_h = NULL - }; + find_arg fa = { .type = type, .mount_h = NULL }; if ( type != NULL ) { rtems_filesystem_iterate( find_handler, &fa ); @@ -122,22 +116,22 @@ rtems_filesystem_get_mount_handler( return fa.mount_h; } -int -rtems_filesystem_register( - const char *type, - rtems_filesystem_mount_t mount_h +int rtems_filesystem_register( + const char *type, + rtems_filesystem_mount_t mount_h ) { rtems_chain_control *chain = &filesystem_chain; - size_t type_size = strlen(type) + 1; - size_t fsn_size = sizeof( filesystem_node ) + type_size; - filesystem_node *fsn = malloc( fsn_size ); - char *type_storage = (char *) fsn + sizeof( *fsn ); + size_t type_size = strlen( type ) + 1; + size_t fsn_size = sizeof( filesystem_node ) + type_size; + filesystem_node *fsn = malloc( fsn_size ); + char *type_storage = (char *) fsn + sizeof( *fsn ); - if ( fsn == NULL ) + if ( fsn == NULL ) { rtems_set_errno_and_return_minus_one( ENOMEM ); + } - memcpy(type_storage, type, type_size); + memcpy( type_storage, type, type_size ); fsn->entry.type = type_storage; fsn->entry.mount_h = mount_h; @@ -156,13 +150,10 @@ rtems_filesystem_register( return 0; } -int -rtems_filesystem_unregister( - const char *type -) +int rtems_filesystem_unregister( const char *type ) { rtems_chain_control *chain = &filesystem_chain; - rtems_chain_node *node = NULL; + rtems_chain_node *node = NULL; if ( type == NULL ) { rtems_set_errno_and_return_minus_one( EINVAL ); @@ -170,8 +161,7 @@ rtems_filesystem_unregister( rtems_libio_lock(); for ( - node = rtems_chain_first( chain ); - !rtems_chain_is_tail( chain, node ); + node = rtems_chain_first( chain ); !rtems_chain_is_tail( chain, node ); node = rtems_chain_next( node ) ) { filesystem_node *fsn = (filesystem_node *) node; diff --git a/cpukit/libcsupport/src/mount-mktgt.c b/cpukit/libcsupport/src/mount-mktgt.c index 97bde52870..95b8ae2a5b 100644 --- a/cpukit/libcsupport/src/mount-mktgt.c +++ b/cpukit/libcsupport/src/mount-mktgt.c @@ -42,25 +42,19 @@ #include int mount_and_make_target_path( - const char *source, - const char *target, - const char *filesystemtype, + const char *source, + const char *target, + const char *filesystemtype, rtems_filesystem_options_t options, - const void *data + const void *data ) { int rv = -1; - if (target != NULL) { - rv = rtems_mkdir(target, S_IRWXU | S_IRWXG | S_IRWXO); - if (rv == 0) { - rv = mount( - source, - target, - filesystemtype, - options, - data - ); + if ( target != NULL ) { + rv = rtems_mkdir( target, S_IRWXU | S_IRWXG | S_IRWXO ); + if ( rv == 0 ) { + rv = mount( source, target, filesystemtype, options, data ); } } else { errno = EINVAL; diff --git a/cpukit/libcsupport/src/mount.c b/cpukit/libcsupport/src/mount.c index 36ab29386a..3fa7aa4921 100644 --- a/cpukit/libcsupport/src/mount.c +++ b/cpukit/libcsupport/src/mount.c @@ -44,44 +44,45 @@ #include -RTEMS_CHAIN_DEFINE_EMPTY(rtems_filesystem_mount_table); +RTEMS_CHAIN_DEFINE_EMPTY( rtems_filesystem_mount_table ); -const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf = { - 5, /* link_max: count */ - 128, /* max_canon: max formatted input line size */ - 7, /* max_input: max input line size */ - 255, /* name_max: max name */ - 255, /* path_max: max path */ - 1024, /* pipe_buf: pipe buffer size */ - 0, /* posix_async_io: async IO supported on fs, 0=no, 1=yes */ - 0 , /* posix_chown_restrictions: can chown: 0=no, 1=yes */ - 1, /* posix_no_trunc: error on filenames > max name, 0=no, 1=yes */ - 0, /* posix_prio_io: priority IO, 0=no, 1=yes */ - 0, /* posix_sync_io: file can be sync'ed, 0=no, 1=yes */ - 0 /* posix_vdisable: special char processing, 0=no, 1=yes */ +const rtems_filesystem_limits_and_options_t rtems_filesystem_default_pathconf = + { + 5, /* link_max: count */ + 128, /* max_canon: max formatted input line size */ + 7, /* max_input: max input line size */ + 255, /* name_max: max name */ + 255, /* path_max: max path */ + 1024, /* pipe_buf: pipe buffer size */ + 0, /* posix_async_io: async IO supported on fs, 0=no, 1=yes */ + 0, /* posix_chown_restrictions: can chown: 0=no, 1=yes */ + 1, /* posix_no_trunc: error on filenames > max name, 0=no, 1=yes */ + 0, /* posix_prio_io: priority IO, 0=no, 1=yes */ + 0, /* posix_sync_io: file can be sync'ed, 0=no, 1=yes */ + 0 /* posix_vdisable: special char processing, 0=no, 1=yes */ }; static rtems_filesystem_mount_table_entry_t *alloc_mount_table_entry( const char *source_or_null, const char *target_or_null, const char *filesystemtype, - size_t *target_length_ptr + size_t *target_length_ptr ) { const char *target = target_or_null != NULL ? target_or_null : "/"; - size_t filesystemtype_size = strlen( filesystemtype ) + 1; - size_t source_size = source_or_null != NULL ? - strlen( source_or_null ) + 1 : 0; + size_t filesystemtype_size = strlen( filesystemtype ) + 1; + size_t source_size = source_or_null != NULL ? strlen( source_or_null ) + 1 + : 0; size_t target_size = strlen( target ) + 1; - size_t size = sizeof( rtems_filesystem_mount_table_entry_t ) - + filesystemtype_size + source_size + target_size - + sizeof( rtems_filesystem_global_location_t ); + size_t size = sizeof( rtems_filesystem_mount_table_entry_t ) + + filesystemtype_size + source_size + target_size + + sizeof( rtems_filesystem_global_location_t ); rtems_filesystem_mount_table_entry_t *mt_entry = calloc( 1, size ); if ( mt_entry != NULL ) { rtems_filesystem_global_location_t *mt_fs_root = - (rtems_filesystem_global_location_t *) - ((char *) mt_entry + sizeof( *mt_entry )); + (rtems_filesystem_global_location_t *) ( (char *) mt_entry + + sizeof( *mt_entry ) ); char *str = (char *) mt_fs_root + sizeof( *mt_fs_root ); memcpy( str, filesystemtype, filesystemtype_size ); @@ -108,7 +109,7 @@ static rtems_filesystem_mount_table_entry_t *alloc_mount_table_entry( &mt_entry->location_chain, mt_fs_root, 1, - sizeof(*mt_fs_root) + sizeof( *mt_fs_root ) ); } @@ -119,24 +120,28 @@ static rtems_filesystem_mount_table_entry_t *alloc_mount_table_entry( static int register_subordinate_file_system( rtems_filesystem_mount_table_entry_t *mt_entry, - const char *target + const char *target ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_PERMS_RWX - | RTEMS_FS_FOLLOW_LINK; - rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start( &ctx, target, eval_flags ); + int eval_flags = RTEMS_FS_PERMS_RWX | RTEMS_FS_FOLLOW_LINK; + rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start( &ctx, target, eval_flags ); if ( !rtems_filesystem_location_is_instance_root( currentloc ) ) { - rtems_filesystem_location_info_t targetloc; + rtems_filesystem_location_info_t targetloc; rtems_filesystem_global_location_t *mt_point_node; rtems_filesystem_eval_path_extract_currentloc( &ctx, &targetloc ); - mt_point_node = rtems_filesystem_location_transform_to_global( &targetloc ); + mt_point_node = rtems_filesystem_location_transform_to_global( + &targetloc + ); mt_entry->mt_point_node = mt_point_node; - rv = (*mt_point_node->location.mt_entry->ops->mount_h)( mt_entry, target ); + rv = ( *mt_point_node->location.mt_entry->ops->mount_h )( + mt_entry, + target + ); if ( rv == 0 ) { rtems_filesystem_mt_lock(); rtems_chain_append_unprotected( @@ -195,24 +200,25 @@ static int register_root_file_system( } int mount( - const char *source, - const char *target, - const char *filesystemtype, + const char *source, + const char *target, + const char *filesystemtype, rtems_filesystem_options_t options, - const void *data + const void *data ) { int rv = 0; if ( - options == RTEMS_FILESYSTEM_READ_ONLY - || options == RTEMS_FILESYSTEM_READ_WRITE + options == RTEMS_FILESYSTEM_READ_ONLY || + options == RTEMS_FILESYSTEM_READ_WRITE ) { - rtems_filesystem_mount_t mount_h = - rtems_filesystem_get_mount_handler( filesystemtype ); + rtems_filesystem_mount_t mount_h = rtems_filesystem_get_mount_handler( + filesystemtype + ); if ( mount_h != NULL ) { - size_t target_length = 0; + size_t target_length = 0; rtems_filesystem_mount_table_entry_t *mt_entry = alloc_mount_table_entry( source, target, @@ -223,7 +229,7 @@ int mount( if ( mt_entry != NULL ) { mt_entry->writeable = options == RTEMS_FILESYSTEM_READ_WRITE; - rv = (*mount_h)( mt_entry, data ); + rv = ( *mount_h )( mt_entry, data ); if ( rv == 0 ) { if ( target != NULL ) { rv = register_subordinate_file_system( mt_entry, target ); @@ -232,7 +238,7 @@ int mount( } if ( rv != 0 ) { - (*mt_entry->ops->fsunmount_me_h)( mt_entry ); + ( *mt_entry->ops->fsunmount_me_h )( mt_entry ); } } diff --git a/cpukit/libcsupport/src/newlibc_exit.c b/cpukit/libcsupport/src/newlibc_exit.c index c8dae30349..866232478e 100644 --- a/cpukit/libcsupport/src/newlibc_exit.c +++ b/cpukit/libcsupport/src/newlibc_exit.c @@ -15,31 +15,31 @@ #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include - #if defined(__USE_INIT_FINI__) + #if defined( __USE_INIT_FINI__ ) #if CPU_USE_LIBC_INIT_FINI_ARRAY == TRUE #define FINI_SYMBOL __libc_fini_array #else #define FINI_SYMBOL _fini #endif - extern void FINI_SYMBOL( void ); +extern void FINI_SYMBOL( void ); #endif -void _exit(int status) +void _exit( int status ) { /* * If the toolset uses init/fini sections, then we need to * run the global destructors now. */ - #if defined(FINI_SYMBOL) - FINI_SYMBOL(); + #if defined( FINI_SYMBOL ) + FINI_SYMBOL(); #endif - rtems_shutdown_executive(status); + rtems_shutdown_executive( status ); /* does not return */ } diff --git a/cpukit/libcsupport/src/newlibc_reent.c b/cpukit/libcsupport/src/newlibc_reent.c index b9cb134897..fdbaefccf9 100644 --- a/cpukit/libcsupport/src/newlibc_reent.c +++ b/cpukit/libcsupport/src/newlibc_reent.c @@ -22,7 +22,7 @@ #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -34,25 +34,25 @@ #ifndef _REENT_THREAD_LOCAL bool newlib_create_hook( rtems_tcb *current_task RTEMS_UNUSED, - rtems_tcb *creating_task + rtems_tcb *creating_task ) { - _REENT_INIT_PTR((creating_task->libc_reent)); /* GCC extension: structure constants */ + _REENT_INIT_PTR( + ( creating_task->libc_reent ) + ); /* GCC extension: structure constants */ return true; } #endif -void newlib_terminate_hook( - rtems_tcb *current_task -) +void newlib_terminate_hook( rtems_tcb *current_task ) { #ifdef _REENT_THREAD_LOCAL (void) current_task; - _reclaim_reent(NULL); + _reclaim_reent( NULL ); #else - _reclaim_reent(current_task->libc_reent); + _reclaim_reent( current_task->libc_reent ); #endif } diff --git a/cpukit/libcsupport/src/open.c b/cpukit/libcsupport/src/open.c index 319bdd1e8b..fcae23a758 100644 --- a/cpukit/libcsupport/src/open.c +++ b/cpukit/libcsupport/src/open.c @@ -49,14 +49,14 @@ static void create_regular_file( rtems_filesystem_eval_path_context_t *ctx, - mode_t mode + mode_t mode ) { int rv = 0; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_get_currentloc( ctx ); + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_get_currentloc( ctx ); const char *token = rtems_filesystem_eval_path_get_token( ctx ); - size_t tokenlen = rtems_filesystem_eval_path_get_tokenlen( ctx ); + size_t tokenlen = rtems_filesystem_eval_path_get_tokenlen( ctx ); rv = rtems_filesystem_mknod( currentloc, @@ -79,33 +79,32 @@ static void create_regular_file( static int do_open( rtems_libio_t *iop, - const char *path, - int oflag, - mode_t mode + const char *path, + int oflag, + mode_t mode ) { - int rv = 0; - int fd = rtems_libio_iop_to_descriptor( iop ); - int rwflag = oflag + 1; - bool read_access = (rwflag & _FREAD) == _FREAD; - bool write_access = (rwflag & _FWRITE) == _FWRITE; - bool make = (oflag & O_CREAT) == O_CREAT; - bool exclusive = (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL); - bool truncate = (oflag & O_TRUNC) == O_TRUNC; + int rv = 0; + int fd = rtems_libio_iop_to_descriptor( iop ); + int rwflag = oflag + 1; + bool read_access = ( rwflag & _FREAD ) == _FREAD; + bool write_access = ( rwflag & _FWRITE ) == _FWRITE; + bool make = ( oflag & O_CREAT ) == O_CREAT; + bool exclusive = ( oflag & ( O_CREAT | O_EXCL ) ) == ( O_CREAT | O_EXCL ); + bool truncate = ( oflag & O_TRUNC ) == O_TRUNC; bool open_dir; #ifdef O_NOFOLLOW - int follow = (oflag & O_NOFOLLOW) == O_NOFOLLOW ? 0 : RTEMS_FS_FOLLOW_LINK; + int follow = ( oflag & O_NOFOLLOW ) == O_NOFOLLOW ? 0 : RTEMS_FS_FOLLOW_LINK; #else int follow = RTEMS_FS_FOLLOW_LINK; #endif - int eval_flags = follow - | (read_access ? RTEMS_FS_PERMS_READ : 0) - | (write_access ? RTEMS_FS_PERMS_WRITE : 0) - | (make ? RTEMS_FS_MAKE : 0) - | (exclusive ? RTEMS_FS_EXCLUSIVE : 0); - rtems_filesystem_eval_path_context_t ctx; + int eval_flags = follow | ( read_access ? RTEMS_FS_PERMS_READ : 0 ) | + ( write_access ? RTEMS_FS_PERMS_WRITE : 0 ) | + ( make ? RTEMS_FS_MAKE : 0 ) | + ( exclusive ? RTEMS_FS_EXCLUSIVE : 0 ); + rtems_filesystem_eval_path_context_t ctx; const rtems_filesystem_location_info_t *currentloc; - bool create_reg_file; + bool create_reg_file; rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); @@ -139,7 +138,7 @@ static int do_open( rtems_libio_iop_flags_set( iop, rtems_libio_from_fcntl_flags( oflag ) ); - rv = (*iop->pathinfo.handlers->open_h)( iop, path, oflag, mode ); + rv = ( *iop->pathinfo.handlers->open_h )( iop, path, oflag, mode ); if ( rv == 0 ) { /* @@ -149,14 +148,14 @@ static int do_open( */ if ( truncate ) { if ( write_access ) { - rv = (*iop->pathinfo.handlers->ftruncate_h)( iop, 0 ); + rv = ( *iop->pathinfo.handlers->ftruncate_h )( iop, 0 ); } else { rv = -1; errno = EINVAL; } if ( rv != 0 ) { - (*iop->pathinfo.handlers->close_h)( iop ); + ( *iop->pathinfo.handlers->close_h )( iop ); } } @@ -176,9 +175,9 @@ static int do_open( */ int open( const char *path, int oflag, ... ) { - int rv = 0; - va_list ap; - mode_t mode = 0; + int rv = 0; + va_list ap; + mode_t mode = 0; rtems_libio_t *iop = NULL; va_start( ap, oflag ); @@ -201,9 +200,7 @@ int open( const char *path, int oflag, ... ) return rv; } - - -#if defined(RTEMS_NEWLIB) && !defined(HAVE__OPEN_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__OPEN_R ) #include @@ -212,9 +209,9 @@ int open( const char *path, int oflag, ... ) */ int _open_r( struct _reent *ptr RTEMS_UNUSED, - const char *buf, - int oflag, - int mode + const char *buf, + int oflag, + int mode ) { return open( buf, oflag, mode ); diff --git a/cpukit/libcsupport/src/open_dev_console.c b/cpukit/libcsupport/src/open_dev_console.c index 23d8927f54..67b436ce1a 100644 --- a/cpukit/libcsupport/src/open_dev_console.c +++ b/cpukit/libcsupport/src/open_dev_console.c @@ -45,7 +45,7 @@ /* * This is a replaceable stub which opens the console, if present. */ -void rtems_libio_post_driver(void) +void rtems_libio_post_driver( void ) { int fd = 0; /* @@ -77,6 +77,5 @@ void rtems_libio_post_driver(void) _Internal_error( INTERNAL_ERROR_LIBIO_STDERR_FD_OPEN_FAILED ); } - atexit(rtems_libio_exit); + atexit( rtems_libio_exit ); } - diff --git a/cpukit/libcsupport/src/pathconf.c b/cpukit/libcsupport/src/pathconf.c index ffa69bf2cf..9c5d7ab6cc 100644 --- a/cpukit/libcsupport/src/pathconf.c +++ b/cpukit/libcsupport/src/pathconf.c @@ -46,17 +46,15 @@ /** * POSIX 1003.1b - 5.7.1 - Configurable Pathname Varables */ -long pathconf( - const char *path, - int name -) +long pathconf( const char *path, int name ) { int status; int fd; fd = open( path, O_RDONLY ); - if ( fd == -1 ) + if ( fd == -1 ) { return -1; + } status = fpathconf( fd, name ); diff --git a/cpukit/libcsupport/src/posix_devctl.c b/cpukit/libcsupport/src/posix_devctl.c index fd190744e9..7303d299a2 100644 --- a/cpukit/libcsupport/src/posix_devctl.c +++ b/cpukit/libcsupport/src/posix_devctl.c @@ -34,15 +34,15 @@ #include #include -#include -#include +#include +#include int posix_devctl( - int fd, - int dcmd, + int fd, + int dcmd, void *__restrict dev_data_ptr, - size_t nbyte, - int *__restrict dev_info_ptr + size_t nbyte, + int *__restrict dev_info_ptr ) { int rv = 0; @@ -77,15 +77,14 @@ int posix_devctl( * is not going to be passed down. Fill it in with zero so the behavior * is defined. */ - if (dev_info_ptr != NULL) { + if ( dev_info_ptr != NULL ) { *dev_info_ptr = 0; } /* * */ - switch (dcmd) { - + switch ( dcmd ) { /* * The FACE Technical Standard Edition 3.0 and newer requires the SOCKCLOSE * ioctl command. This is because the Security Profile does not include @@ -94,8 +93,8 @@ int posix_devctl( * requirement but also lets the application close other file types. */ case SOCKCLOSE: - if (close(fd) != 0) { - rv = errno; + if ( close( fd ) != 0 ) { + rv = errno; errno = errno_copy; return rv; @@ -110,32 +109,32 @@ int posix_devctl( int tmp_flag; int flag; - if (nbyte != sizeof(int)) { + if ( nbyte != sizeof( int ) ) { return EINVAL; } - tmp_flag = fcntl(fd, F_GETFL, 0); - if (tmp_flag == -1) { + tmp_flag = fcntl( fd, F_GETFL, 0 ); + if ( tmp_flag == -1 ) { rv = errno; errno = errno_copy; return rv; } - flag = *(int *)dev_data_ptr; + flag = *(int *) dev_data_ptr; - if (flag != 0) { + if ( flag != 0 ) { tmp_flag |= O_NONBLOCK; } else { tmp_flag &= ~O_NONBLOCK; } - (void) fcntl(fd, F_SETFL, tmp_flag); + (void) fcntl( fd, F_SETFL, tmp_flag ); break; } default: - if (ioctl(fd, dcmd, dev_data_ptr) != 0) { + if ( ioctl( fd, dcmd, dev_data_ptr ) != 0 ) { rv = errno; errno = errno_copy; diff --git a/cpukit/libcsupport/src/posix_memalign.c b/cpukit/libcsupport/src/posix_memalign.c index 771eca1a62..f5c012820c 100644 --- a/cpukit/libcsupport/src/posix_memalign.c +++ b/cpukit/libcsupport/src/posix_memalign.c @@ -42,11 +42,7 @@ #include #include -int posix_memalign( - void **memptr, - size_t alignment, - size_t size -) +int posix_memalign( void **memptr, size_t alignment, size_t size ) { RTEMS_OBFUSCATE_VARIABLE( memptr ); diff --git a/cpukit/libcsupport/src/print_fprintf.c b/cpukit/libcsupport/src/print_fprintf.c index f747931e32..658ec4c8ee 100644 --- a/cpukit/libcsupport/src/print_fprintf.c +++ b/cpukit/libcsupport/src/print_fprintf.c @@ -39,12 +39,12 @@ #include -static int rtems_fprintf_plugin(void *context, const char *fmt, va_list ap) +static int rtems_fprintf_plugin( void *context, const char *fmt, va_list ap ) { - return vfprintf(context, fmt, ap); + return vfprintf( context, fmt, ap ); } -void rtems_print_printer_fprintf(rtems_printer *printer, FILE *file) +void rtems_print_printer_fprintf( rtems_printer *printer, FILE *file ) { printer->context = file; printer->printer = rtems_fprintf_plugin; diff --git a/cpukit/libcsupport/src/print_printf.c b/cpukit/libcsupport/src/print_printf.c index 0972d22e56..b4afb97d93 100644 --- a/cpukit/libcsupport/src/print_printf.c +++ b/cpukit/libcsupport/src/print_printf.c @@ -52,11 +52,7 @@ int rtems_vprintf( return len; } -int rtems_printf( - const rtems_printer *printer, - const char *format, - ... -) +int rtems_printf( const rtems_printer *printer, const char *format, ... ) { int len = 0; if ( rtems_print_printer_valid( printer ) ) { diff --git a/cpukit/libcsupport/src/printerfprintfputc.c b/cpukit/libcsupport/src/printerfprintfputc.c index c011fa9081..e983adc422 100644 --- a/cpukit/libcsupport/src/printerfprintfputc.c +++ b/cpukit/libcsupport/src/printerfprintfputc.c @@ -39,10 +39,10 @@ static pthread_once_t fprintf_putc_once = PTHREAD_ONCE_INIT; static FILE fprintf_putc_file; static _READ_WRITE_RETURN_TYPE fprintf_putc_write( - struct _reent *ptr, - void *cookie, - char const *buf, - _READ_WRITE_BUFSIZE_TYPE n + struct _reent *ptr, + void *cookie, + char const *buf, + _READ_WRITE_BUFSIZE_TYPE n ) { (void) ptr; @@ -52,14 +52,14 @@ static _READ_WRITE_RETURN_TYPE fprintf_putc_write( _READ_WRITE_RETURN_TYPE m; m = (_READ_WRITE_RETURN_TYPE) n; - for (i = 0; i < m; ++i) { - rtems_putc(buf[i]); + for ( i = 0; i < m; ++i ) { + rtems_putc( buf[ i ] ); } return m; } -static void fprintf_putc_init(void) +static void fprintf_putc_init( void ) { FILE *f; @@ -67,17 +67,17 @@ static void fprintf_putc_init(void) f->_flags = __SWR | __SNBF; f->_cookie = f; f->_write = fprintf_putc_write; - __lock_init_recursive(f->_lock); + __lock_init_recursive( f->_lock ); } -static int fprintf_putc_printer(void *context, const char *fmt, va_list ap) +static int fprintf_putc_printer( void *context, const char *fmt, va_list ap ) { - return vfprintf(context, fmt, ap); + return vfprintf( context, fmt, ap ); } -void rtems_print_printer_fprintf_putc(rtems_printer *printer) +void rtems_print_printer_fprintf_putc( rtems_printer *printer ) { - pthread_once(&fprintf_putc_once, fprintf_putc_init); + pthread_once( &fprintf_putc_once, fprintf_putc_init ); printer->context = &fprintf_putc_file; printer->printer = fprintf_putc_printer; } diff --git a/cpukit/libcsupport/src/printertask.c b/cpukit/libcsupport/src/printertask.c index c56732e629..6ad890669d 100644 --- a/cpukit/libcsupport/src/printertask.c +++ b/cpukit/libcsupport/src/printertask.c @@ -41,10 +41,7 @@ typedef struct { rtems_chain_node node; - enum { - ACTION_WRITE, - ACTION_DRAIN - } action_kind; + enum { ACTION_WRITE, ACTION_DRAIN } action_kind; union { size_t size; @@ -81,8 +78,8 @@ static printer_task_buffer *printer_task_get_buffer( { (void) ctx; - rtems_interrupt_lock_context lock_context; - printer_task_buffer *buffer; + rtems_interrupt_lock_context lock_context; + printer_task_buffer *buffer; printer_task_acquire( ctx, &lock_context ); buffer = (printer_task_buffer *) rtems_chain_get_unprotected( chain ); @@ -162,10 +159,10 @@ static void printer_task( rtems_task_argument arg ) printer_task_append_buffer( ctx, &ctx->free_buffers, buffer ); break; case ACTION_DRAIN: - err = fsync(fd); - _Assert_Unused_variable_equals(err, 0); + err = fsync( fd ); + _Assert_Unused_variable_equals( err, 0 ); sc = rtems_event_transient_send( buffer->action_data.task ); - _Assert_Unused_variable_equals(sc, RTEMS_SUCCESSFUL); + _Assert_Unused_variable_equals( sc, RTEMS_SUCCESSFUL ); break; } } @@ -184,7 +181,7 @@ int rtems_print_printer_task( } sc = rtems_task_create( - rtems_build_name( 'P', 'R', 'N', 'T'), + rtems_build_name( 'P', 'R', 'N', 'T' ), ctx->task_priority, ctx->task_stack_size, RTEMS_DEFAULT_MODES, @@ -209,7 +206,7 @@ int rtems_print_printer_task( printer->printer = printer_task_printer; sc = rtems_task_start( ctx->task, printer_task, (rtems_task_argument) ctx ); - _Assert_Unused_variable_equals(sc, RTEMS_SUCCESSFUL); + _Assert_Unused_variable_equals( sc, RTEMS_SUCCESSFUL ); return 0; } diff --git a/cpukit/libcsupport/src/printf_plugin.c b/cpukit/libcsupport/src/printf_plugin.c index a15100c440..e0478bc168 100644 --- a/cpukit/libcsupport/src/printf_plugin.c +++ b/cpukit/libcsupport/src/printf_plugin.c @@ -38,13 +38,13 @@ #include -static int rtems_printf_plugin(void *context, const char *format, va_list ap) +static int rtems_printf_plugin( void *context, const char *format, va_list ap ) { (void) context; - return vprintf(format, ap); + return vprintf( format, ap ); } -void rtems_print_printer_printf(rtems_printer *printer) +void rtems_print_printer_printf( rtems_printer *printer ) { printer->context = NULL; printer->printer = rtems_printf_plugin; diff --git a/cpukit/libcsupport/src/printk.c b/cpukit/libcsupport/src/printk.c index 0e41a31337..dfa1a508fd 100644 --- a/cpukit/libcsupport/src/printk.c +++ b/cpukit/libcsupport/src/printk.c @@ -31,12 +31,12 @@ /** * Kernel printf function requiring minimal infrastructure. */ -int printk(const char *fmt, ...) +int printk( const char *fmt, ... ) { - va_list ap; /* points to each unnamed argument in turn */ + va_list ap; /* points to each unnamed argument in turn */ int len; - va_start(ap, fmt); /* make ap point to 1st unnamed arg */ - len = vprintk(fmt, ap); - va_end(ap); /* clean up when done */ + va_start( ap, fmt ); /* make ap point to 1st unnamed arg */ + len = vprintk( fmt, ap ); + va_end( ap ); /* clean up when done */ return len; } diff --git a/cpukit/libcsupport/src/printk_plugin.c b/cpukit/libcsupport/src/printk_plugin.c index caf89e9e06..9c58a5ce7c 100644 --- a/cpukit/libcsupport/src/printk_plugin.c +++ b/cpukit/libcsupport/src/printk_plugin.c @@ -43,19 +43,13 @@ #include #include -int rtems_printk_printer( - void *ignored, - const char *format, - va_list ap -) +int rtems_printk_printer( void *ignored, const char *format, va_list ap ) { (void) ignored; return vprintk( format, ap ); } -void rtems_print_printer_printk( - rtems_printer *printer -) +void rtems_print_printer_printk( rtems_printer *printer ) { printer->context = NULL; printer->printer = rtems_printk_printer; diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c index 3fec6e3c69..729686b19f 100644 --- a/cpukit/libcsupport/src/privateenv.c +++ b/cpukit/libcsupport/src/privateenv.c @@ -50,38 +50,41 @@ * Instantiate a private user environment for the calling thread. */ -static void rtems_libio_free_user_env(rtems_user_env_t *env) +static void rtems_libio_free_user_env( rtems_user_env_t *env ) { bool uses_global_env = env == &rtems_global_user_env; - if (!uses_global_env) { - rtems_filesystem_global_location_release(env->current_directory, false); - rtems_filesystem_global_location_release(env->root_directory, false); - free(env); + if ( !uses_global_env ) { + rtems_filesystem_global_location_release( env->current_directory, false ); + rtems_filesystem_global_location_release( env->root_directory, false ); + free( env ); } } -rtems_status_code rtems_libio_set_private_env(void) +rtems_status_code rtems_libio_set_private_env( void ) { rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_user_env_t *old_env = rtems_current_user_env; - bool uses_global_env = old_env == &rtems_global_user_env; + bool uses_global_env = old_env == &rtems_global_user_env; - if (uses_global_env) { - Thread_Life_state life_state = - _Thread_Set_life_protection(THREAD_LIFE_PROTECTED); - rtems_user_env_t *new_env = calloc(1, sizeof(*new_env)); + if ( uses_global_env ) { + Thread_Life_state life_state = _Thread_Set_life_protection( + THREAD_LIFE_PROTECTED + ); + rtems_user_env_t *new_env = calloc( 1, sizeof( *new_env ) ); - if (new_env != NULL) { + if ( new_env != NULL ) { *new_env = *old_env; - new_env->root_directory = - rtems_filesystem_global_location_obtain(&old_env->root_directory); - new_env->current_directory = - rtems_filesystem_global_location_obtain(&old_env->current_directory); + new_env->root_directory = rtems_filesystem_global_location_obtain( + &old_env->root_directory + ); + new_env->current_directory = rtems_filesystem_global_location_obtain( + &old_env->current_directory + ); if ( - !rtems_filesystem_global_location_is_null(new_env->root_directory) - && !rtems_filesystem_global_location_is_null(new_env->current_directory) + !rtems_filesystem_global_location_is_null( new_env->root_directory ) && + !rtems_filesystem_global_location_is_null( new_env->current_directory ) ) { Thread_Control *executing = _Thread_Get_executing(); @@ -90,43 +93,44 @@ rtems_status_code rtems_libio_set_private_env(void) sc = RTEMS_UNSATISFIED; } - if (sc != RTEMS_SUCCESSFUL) { - rtems_libio_free_user_env(new_env); + if ( sc != RTEMS_SUCCESSFUL ) { + rtems_libio_free_user_env( new_env ); } } else { sc = RTEMS_NO_MEMORY; } - _Thread_Set_life_protection(life_state); + _Thread_Set_life_protection( life_state ); } return sc; } -void rtems_libio_use_global_env(void) +void rtems_libio_use_global_env( void ) { rtems_user_env_t *env = rtems_current_user_env; - bool uses_private_env = env != &rtems_global_user_env; + bool uses_private_env = env != &rtems_global_user_env; - if (uses_private_env) { - Thread_Life_state life_state = - _Thread_Set_life_protection(THREAD_LIFE_PROTECTED); + if ( uses_private_env ) { + Thread_Life_state life_state = _Thread_Set_life_protection( + THREAD_LIFE_PROTECTED + ); Thread_Control *executing; - rtems_libio_free_user_env(env); + rtems_libio_free_user_env( env ); executing = _Thread_Get_executing(); executing->user_environment = NULL; - _Thread_Set_life_protection(life_state); + _Thread_Set_life_protection( life_state ); } } -static void rtems_libio_env_thread_terminate(Thread_Control *the_thread) +static void rtems_libio_env_thread_terminate( Thread_Control *the_thread ) { rtems_user_env_t *env = the_thread->user_environment; - if (env != NULL) { - rtems_libio_free_user_env(env); + if ( env != NULL ) { + rtems_libio_free_user_env( env ); } } @@ -146,9 +150,9 @@ static User_extensions_Control rtems_libio_env_extensions = { } }; -static void rtems_libio_env_init(void) +static void rtems_libio_env_init( void ) { - _User_extensions_Add_API_set(&rtems_libio_env_extensions); + _User_extensions_Add_API_set( &rtems_libio_env_extensions ); } RTEMS_SYSINIT_ITEM( diff --git a/cpukit/libcsupport/src/putk.c b/cpukit/libcsupport/src/putk.c index 0ee938e3ba..bf5adf91f9 100644 --- a/cpukit/libcsupport/src/putk.c +++ b/cpukit/libcsupport/src/putk.c @@ -43,13 +43,14 @@ /** * Kernel putk (e.g. puts) function requiring minimal infrastrure. */ -int putk(const char *s) +int putk( const char *s ) { const char *p; - int len_out = 0; + int len_out = 0; - for (p=s ; *p ; p++, len_out++ ) - rtems_putc(*p); - rtems_putc('\n'); + for ( p = s; *p; p++, len_out++ ) { + rtems_putc( *p ); + } + rtems_putc( '\n' ); return len_out + 1; } diff --git a/cpukit/libcsupport/src/pwdgrp.c b/cpukit/libcsupport/src/pwdgrp.c index 5f4d2bd60d..45fc1946ab 100644 --- a/cpukit/libcsupport/src/pwdgrp.c +++ b/cpukit/libcsupport/src/pwdgrp.c @@ -44,7 +44,7 @@ static pthread_once_t pwdgrp_once = PTHREAD_ONCE_INIT; -static void init_file(const char *name, const char *content) +static void init_file( const char *name, const char *content ) { /* * Unlike to standard UNIX systems, these files are only readable and @@ -52,18 +52,18 @@ static void init_file(const char *name, const char *content) * /etc/shadow. In case more UNIX compatibility is desired, this can be * added on demand. */ - int fd = open(name, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR); + int fd = open( name, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR ); - if (fd >= 0) { - write(fd, content, strlen(content)); - close(fd); + if ( fd >= 0 ) { + write( fd, content, strlen( content ) ); + close( fd ); } } /** * Initialize useable but dummy databases */ -static void pwdgrp_init(void) +static void pwdgrp_init( void ) { /* * Do the best to create this directory. @@ -71,93 +71,107 @@ static void pwdgrp_init(void) * /etc could be created by the network stack initialization or an initial * filesystem image. Deliberately ignore the return value. */ - (void) mkdir("/etc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + (void) mkdir( "/etc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ); /* * Initialize /etc/passwd */ - init_file("/etc/passwd", "root::0:0::::\n"); + init_file( "/etc/passwd", "root::0:0::::\n" ); /* * Initialize /etc/group */ - init_file("/etc/group", "root::0:\n"); + init_file( "/etc/group", "root::0:\n" ); } -void _libcsupport_pwdgrp_init(void) +void _libcsupport_pwdgrp_init( void ) { - pthread_once(&pwdgrp_once, pwdgrp_init); + pthread_once( &pwdgrp_once, pwdgrp_init ); } /** * Extract a string value from the database */ -static int -scanString(FILE *fp, char **name, char **bufp, size_t *nleft, int nlFlag) +static int scanString( + FILE *fp, + char **name, + char **bufp, + size_t *nleft, + int nlFlag +) { int c; *name = *bufp; - for (;;) { - c = getc(fp); - if (c == ':') { - if (nlFlag) - return 0; - break; + for ( ;; ) { + c = getc( fp ); + if ( c == ':' ) { + if ( nlFlag ) { + return 0; + } + break; } - if (c == '\n') { - if (!nlFlag) - return 0; - break; + if ( c == '\n' ) { + if ( !nlFlag ) { + return 0; + } + break; } - if (c == EOF) + if ( c == EOF ) { return 0; - if (*nleft < 2) + } + if ( *nleft < 2 ) { return 0; + } **bufp = c; - ++(*bufp); - --(*nleft); + ++( *bufp ); + --( *nleft ); } **bufp = '\0'; - ++(*bufp); - --(*nleft); + ++( *bufp ); + --( *nleft ); return 1; } /** * Extract an integer value from the database */ -static int -scanInt(FILE *fp, int *val) +static int scanInt( FILE *fp, int *val ) { - int c; - int i = 0; - int limit = INT_MAX; - int sign = 0; + int c; + int i = 0; + int limit = INT_MAX; + int sign = 0; unsigned int d; - for (;;) { - c = getc(fp); - if (c == ':') + for ( ;; ) { + c = getc( fp ); + if ( c == ':' ) { break; - if (sign == 0) { - if (c == '-') { + } + if ( sign == 0 ) { + if ( c == '-' ) { sign = -1; limit++; continue; } sign = 1; } - if (!isdigit(c)) + if ( !isdigit( c ) ) { return 0; + } d = c - '0'; - if ((i > (limit / 10)) - || ((i == (limit / 10)) && (d > (limit % 10)))) + if ( + ( i > ( limit / 10 ) ) || + ( ( i == ( limit / 10 ) ) && ( d > ( limit % 10 ) ) ) + ) { return 0; + } i = i * 10 + d; } - if (sign == 0) + if ( sign == 0 ) { return 0; + } *val = i * sign; return 1; } @@ -166,23 +180,25 @@ scanInt(FILE *fp, int *val) * Extract a single password record from the database */ int _libcsupport_scanpw( - FILE *fp, + FILE *fp, struct passwd *pwd, - char *buffer, - size_t bufsize + char *buffer, + size_t bufsize ) { int pwuid, pwgid; - if (!scanString(fp, &pwd->pw_name, &buffer, &bufsize, 0) - || !scanString(fp, &pwd->pw_passwd, &buffer, &bufsize, 0) - || !scanInt(fp, &pwuid) - || !scanInt(fp, &pwgid) - || !scanString(fp, &pwd->pw_comment, &buffer, &bufsize, 0) - || !scanString(fp, &pwd->pw_gecos, &buffer, &bufsize, 0) - || !scanString(fp, &pwd->pw_dir, &buffer, &bufsize, 0) - || !scanString(fp, &pwd->pw_shell, &buffer, &bufsize, 1)) + if ( + !scanString( fp, &pwd->pw_name, &buffer, &bufsize, 0 ) || + !scanString( fp, &pwd->pw_passwd, &buffer, &bufsize, 0 ) || + !scanInt( fp, &pwuid ) || !scanInt( fp, &pwgid ) || + !scanString( fp, &pwd->pw_comment, &buffer, &bufsize, 0 ) || + !scanString( fp, &pwd->pw_gecos, &buffer, &bufsize, 0 ) || + !scanString( fp, &pwd->pw_dir, &buffer, &bufsize, 0 ) || + !scanString( fp, &pwd->pw_shell, &buffer, &bufsize, 1 ) + ) { return 0; + } pwd->pw_uid = pwuid; pwd->pw_gid = pwgid; return 1; @@ -198,31 +214,33 @@ static int getpw_r( ) { FILE *fp; - int match; + int match; _libcsupport_pwdgrp_init(); - if ((fp = fopen("/etc/passwd", "r")) == NULL) + if ( ( fp = fopen( "/etc/passwd", "r" ) ) == NULL ) { rtems_set_errno_and_return_minus_one( EINVAL ); + } - for(;;) { - if (!_libcsupport_scanpw(fp, pwd, buffer, bufsize)) + for ( ;; ) { + if ( !_libcsupport_scanpw( fp, pwd, buffer, bufsize ) ) { goto error_einval; - - if (name) { - match = (strcmp(pwd->pw_name, name) == 0); - } else { - match = (pwd->pw_uid == uid); } - if (match) { - fclose(fp); + if ( name ) { + match = ( strcmp( pwd->pw_name, name ) == 0 ); + } else { + match = ( pwd->pw_uid == uid ); + } + + if ( match ) { + fclose( fp ); *result = pwd; return 0; } } error_einval: - fclose(fp); + fclose( fp ); rtems_set_errno_and_return_minus_one( EINVAL ); } @@ -234,7 +252,7 @@ int getpwnam_r( struct passwd **result ) { - return getpw_r(name, 0, pwd, buffer, bufsize, result); + return getpw_r( name, 0, pwd, buffer, bufsize, result ); } int getpwuid_r( @@ -245,124 +263,130 @@ int getpwuid_r( struct passwd **result ) { - return getpw_r(NULL, uid, pwd, buffer, bufsize, result); + return getpw_r( NULL, uid, pwd, buffer, bufsize, result ); } /** * Extract a single group record from the database */ int _libcsupport_scangr( - FILE *fp, + FILE *fp, struct group *grp, - char *buffer, - size_t bufsize + char *buffer, + size_t bufsize ) { - int grgid; + int grgid; char *grmem, *cp; - int memcount; + int memcount; - if (!scanString(fp, &grp->gr_name, &buffer, &bufsize, 0) - || !scanString(fp, &grp->gr_passwd, &buffer, &bufsize, 0) - || !scanInt(fp, &grgid) - || !scanString(fp, &grmem, &buffer, &bufsize, 1)) + if ( + !scanString( fp, &grp->gr_name, &buffer, &bufsize, 0 ) || + !scanString( fp, &grp->gr_passwd, &buffer, &bufsize, 0 ) || + !scanInt( fp, &grgid ) || !scanString( fp, &grmem, &buffer, &bufsize, 1 ) + ) { return 0; + } grp->gr_gid = grgid; /* * Determine number of members */ - if (grmem[0] == '\0') { + if ( grmem[ 0 ] == '\0' ) { memcount = 0; } else { - for (cp = grmem, memcount = 1 ; *cp != 0 ; cp++) { - if(*cp == ',') + for ( cp = grmem, memcount = 1; *cp != 0; cp++ ) { + if ( *cp == ',' ) { memcount++; + } } } /* * Hack to produce (hopefully) a suitably-aligned array of pointers */ - if (bufsize < (((memcount+1)*sizeof(char *)) + 15)) + if ( bufsize < ( ( ( memcount + 1 ) * sizeof( char * ) ) + 15 ) ) { return 0; - grp->gr_mem = (char **)(((uintptr_t)buffer + 15) & ~15); + } + grp->gr_mem = (char **) ( ( (uintptr_t) buffer + 15 ) & ~15 ); /* * Fill in pointer array */ - if (grmem[0] == '\0') { + if ( grmem[ 0 ] == '\0' ) { memcount = 0; } else { - grp->gr_mem[0] = grmem; - for (cp = grmem, memcount = 1 ; *cp != 0 ; cp++) { - if(*cp == ',') { + grp->gr_mem[ 0 ] = grmem; + for ( cp = grmem, memcount = 1; *cp != 0; cp++ ) { + if ( *cp == ',' ) { *cp = '\0'; - grp->gr_mem[memcount++] = cp + 1; + grp->gr_mem[ memcount++ ] = cp + 1; } } } - grp->gr_mem[memcount] = NULL; + grp->gr_mem[ memcount ] = NULL; return 1; } static int getgr_r( - const char *name, - int gid, - struct group *grp, - char *buffer, - size_t bufsize, - struct group **result + const char *name, + int gid, + struct group *grp, + char *buffer, + size_t bufsize, + struct group **result ) { FILE *fp; - int match; + int match; _libcsupport_pwdgrp_init(); - if ((fp = fopen("/etc/group", "r")) == NULL) + if ( ( fp = fopen( "/etc/group", "r" ) ) == NULL ) { rtems_set_errno_and_return_minus_one( EINVAL ); + } - for(;;) { - if (!_libcsupport_scangr(fp, grp, buffer, bufsize)) + for ( ;; ) { + if ( !_libcsupport_scangr( fp, grp, buffer, bufsize ) ) { goto error_einval; - - if (name) { - match = (strcmp(grp->gr_name, name) == 0); - } else { - match = (grp->gr_gid == gid); } - if (match) { - fclose(fp); + if ( name ) { + match = ( strcmp( grp->gr_name, name ) == 0 ); + } else { + match = ( grp->gr_gid == gid ); + } + + if ( match ) { + fclose( fp ); *result = grp; return 0; } } error_einval: - fclose(fp); + fclose( fp ); rtems_set_errno_and_return_minus_one( EINVAL ); } int getgrnam_r( - const char *name, - struct group *grp, - char *buffer, - size_t bufsize, - struct group **result + const char *name, + struct group *grp, + char *buffer, + size_t bufsize, + struct group **result ) { - return getgr_r(name, 0, grp, buffer, bufsize, result); + return getgr_r( name, 0, grp, buffer, bufsize, result ); } int getgrgid_r( - gid_t gid, - struct group *grp, - char *buffer, - size_t bufsize, - struct group **result + gid_t gid, + struct group *grp, + char *buffer, + size_t bufsize, + struct group **result ) { - return getgr_r(NULL, gid, grp, buffer, bufsize, result); + return getgr_r( NULL, gid, grp, buffer, bufsize, result ); } diff --git a/cpukit/libcsupport/src/pwdgrp.h b/cpukit/libcsupport/src/pwdgrp.h index 96adfe9583..05c23c0e43 100644 --- a/cpukit/libcsupport/src/pwdgrp.h +++ b/cpukit/libcsupport/src/pwdgrp.h @@ -36,20 +36,20 @@ extern "C" { #endif /* __cplusplus */ -void _libcsupport_pwdgrp_init(void); +void _libcsupport_pwdgrp_init( void ); int _libcsupport_scanpw( - FILE *fp, + FILE *fp, struct passwd *pwd, - char *buffer, - size_t bufsize + char *buffer, + size_t bufsize ); int _libcsupport_scangr( - FILE *fp, + FILE *fp, struct group *grp, - char *buffer, - size_t bufsize + char *buffer, + size_t bufsize ); #ifdef __cplusplus diff --git a/cpukit/libcsupport/src/read.c b/cpukit/libcsupport/src/read.c index 396452cad8..323bd6d969 100644 --- a/cpukit/libcsupport/src/read.c +++ b/cpukit/libcsupport/src/read.c @@ -43,11 +43,7 @@ /** * POSIX 1003.1b 6.4.1 - Read From a File */ -ssize_t read( - int fd, - void *buffer, - size_t count -) +ssize_t read( int fd, void *buffer, size_t count ) { rtems_libio_t *iop; ssize_t n; @@ -60,12 +56,12 @@ ssize_t read( /* * Now process the read(). */ - n = (*iop->pathinfo.handlers->read_h)( iop, buffer, count ); + n = ( *iop->pathinfo.handlers->read_h )( iop, buffer, count ); rtems_libio_iop_drop( iop ); return n; } -#if defined(RTEMS_NEWLIB) && !defined(HAVE__READ_R) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE__READ_R ) #include @@ -74,9 +70,9 @@ ssize_t read( */ ssize_t _read_r( struct _reent *ptr RTEMS_UNUSED, - int fd, - void *buf, - size_t nbytes + int fd, + void *buf, + size_t nbytes ) { return read( fd, buf, nbytes ); diff --git a/cpukit/libcsupport/src/readlink.c b/cpukit/libcsupport/src/readlink.c index 198c3b4103..615c1f82af 100644 --- a/cpukit/libcsupport/src/readlink.c +++ b/cpukit/libcsupport/src/readlink.c @@ -44,19 +44,22 @@ /** * POSIX 1003.1b - X.X.X - XXX */ -ssize_t readlink( const char *__restrict path, char *__restrict buf, - size_t bufsize ) +ssize_t readlink( + const char *__restrict path, + char *__restrict buf, + size_t bufsize +) { - ssize_t rv = 0; + ssize_t rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); + int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK; + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops; mode_t type = rtems_filesystem_location_type( currentloc ); if ( S_ISLNK( type ) ) { - rv = (*ops->readlink_h)( currentloc, buf, bufsize ); + rv = ( *ops->readlink_h )( currentloc, buf, bufsize ); } else { rtems_filesystem_eval_path_error( &ctx, EINVAL ); rv = -1; diff --git a/cpukit/libcsupport/src/readv.c b/cpukit/libcsupport/src/readv.c index b2b4511e51..38b717b03e 100644 --- a/cpukit/libcsupport/src/readv.c +++ b/cpukit/libcsupport/src/readv.c @@ -58,11 +58,7 @@ static ssize_t readv_adapter( * * http://www.opengroup.org/onlinepubs/009695399/functions/readv.html */ -ssize_t readv( - int fd, - const struct iovec *iov, - int iovcnt -) +ssize_t readv( int fd, const struct iovec *iov, int iovcnt ) { return rtems_libio_iovec_eval( fd, diff --git a/cpukit/libcsupport/src/realloc.c b/cpukit/libcsupport/src/realloc.c index 6b165fc080..ce357a488e 100644 --- a/cpukit/libcsupport/src/realloc.c +++ b/cpukit/libcsupport/src/realloc.c @@ -67,10 +67,10 @@ static void *new_alloc( void *old_ptr, size_t new_size, size_t old_size ) void *realloc( void *ptr, size_t size ) { - Heap_Control *heap; - Heap_Resize_status status; - uintptr_t old_size; - uintptr_t avail_size; + Heap_Control *heap; + Heap_Resize_status status; + uintptr_t old_size; + uintptr_t avail_size; if ( ptr == NULL ) { return malloc( size ); diff --git a/cpukit/libcsupport/src/resource_snapshot.c b/cpukit/libcsupport/src/resource_snapshot.c index 73488c16cb..9f96c346e0 100644 --- a/cpukit/libcsupport/src/resource_snapshot.c +++ b/cpukit/libcsupport/src/resource_snapshot.c @@ -43,7 +43,7 @@ static const struct { Objects_APIs api; - uint16_t cls; + uint16_t cls; } objects_info_table[] = { { OBJECTS_POSIX_API, OBJECTS_POSIX_KEYS }, { OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS }, @@ -60,20 +60,20 @@ static const struct { { OBJECTS_POSIX_API, OBJECTS_POSIX_SEMAPHORES }, { OBJECTS_POSIX_API, OBJECTS_POSIX_THREADS } #ifdef RTEMS_POSIX_API - , - { OBJECTS_POSIX_API, OBJECTS_POSIX_TIMERS } + , + { OBJECTS_POSIX_API, OBJECTS_POSIX_TIMERS } #endif }; -static int open_files(void) +static int open_files( void ) { - int free_count = 0; + int free_count = 0; rtems_libio_t *iop; rtems_libio_lock(); iop = rtems_libio_iop_free_head; - while (iop != NULL) { + while ( iop != NULL ) { ++free_count; iop = iop->data1; @@ -84,58 +84,59 @@ static int open_files(void) return (int) rtems_libio_number_iops - free_count; } -static void get_heap_info(Heap_Control *heap, Heap_Information_block *info) +static void get_heap_info( Heap_Control *heap, Heap_Information_block *info ) { - _Heap_Get_information(heap, info); - memset(&info->Stats, 0, sizeof(info->Stats)); + _Heap_Get_information( heap, info ); + memset( &info->Stats, 0, sizeof( info->Stats ) ); } -static POSIX_Keys_Control *get_next_key(Objects_Id *id) +static POSIX_Keys_Control *get_next_key( Objects_Id *id ) { - return (POSIX_Keys_Control *) - _Objects_Get_next(*id, &_POSIX_Keys_Information, id); + return ( + POSIX_Keys_Control * + ) _Objects_Get_next( *id, &_POSIX_Keys_Information, id ); } -static uint32_t get_active_posix_key_value_pairs(void) +static uint32_t get_active_posix_key_value_pairs( void ) { - uint32_t count = 0; - Objects_Id id = OBJECTS_ID_INITIAL_INDEX; + uint32_t count = 0; + Objects_Id id = OBJECTS_ID_INITIAL_INDEX; POSIX_Keys_Control *the_key; - while ((the_key = get_next_key(&id)) != NULL ) { - count += _Chain_Node_count_unprotected(&the_key->Key_value_pairs); + while ( ( the_key = get_next_key( &id ) ) != NULL ) { + count += _Chain_Node_count_unprotected( &the_key->Key_value_pairs ); _Objects_Allocator_unlock(); } return count; } -void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot) +void rtems_resource_snapshot_take( rtems_resource_snapshot *snapshot ) { uint32_t *active; - size_t i; + size_t i; - memset(snapshot, 0, sizeof(*snapshot)); + memset( snapshot, 0, sizeof( *snapshot ) ); _RTEMS_Lock_allocator(); _Thread_Kill_zombies(); - get_heap_info(RTEMS_Malloc_Heap, &snapshot->heap_info); - get_heap_info(&_Workspace_Area, &snapshot->workspace_info); + get_heap_info( RTEMS_Malloc_Heap, &snapshot->heap_info ); + get_heap_info( &_Workspace_Area, &snapshot->workspace_info ); active = &snapshot->active_posix_keys; - for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) { + for ( i = 0; i < RTEMS_ARRAY_SIZE( objects_info_table ); ++i ) { const Objects_Information *information; information = _Objects_Get_information( - objects_info_table[i].api, - objects_info_table[i].cls + objects_info_table[ i ].api, + objects_info_table[ i ].cls ); - if (information != NULL) { - active[i] = _Objects_Active_count(information); + if ( information != NULL ) { + active[ i ] = _Objects_Active_count( information ); } } @@ -150,14 +151,14 @@ bool rtems_resource_snapshot_equal( const rtems_resource_snapshot *b ) { - return memcmp(a, b, sizeof(*a)) == 0; + return memcmp( a, b, sizeof( *a ) ) == 0; } -bool rtems_resource_snapshot_check(const rtems_resource_snapshot *snapshot) +bool rtems_resource_snapshot_check( const rtems_resource_snapshot *snapshot ) { rtems_resource_snapshot now; - rtems_resource_snapshot_take(&now); + rtems_resource_snapshot_take( &now ); - return rtems_resource_snapshot_equal(&now, snapshot); + return rtems_resource_snapshot_equal( &now, snapshot ); } diff --git a/cpukit/libcsupport/src/rmdir.c b/cpukit/libcsupport/src/rmdir.c index 7fe90e8c9d..3cef3c8ec2 100644 --- a/cpukit/libcsupport/src/rmdir.c +++ b/cpukit/libcsupport/src/rmdir.c @@ -46,15 +46,14 @@ */ int rmdir( const char *path ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_REJECT_TERMINAL_DOT; + int eval_flags = RTEMS_FS_REJECT_TERMINAL_DOT; rtems_filesystem_location_info_t parentloc; - int parent_eval_flags = RTEMS_FS_PERMS_WRITE - | RTEMS_FS_PERMS_EXEC - | RTEMS_FS_FOLLOW_LINK; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start_with_parent( + int parent_eval_flags = RTEMS_FS_PERMS_WRITE | RTEMS_FS_PERMS_EXEC | + RTEMS_FS_FOLLOW_LINK; + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start_with_parent( &ctx, path, eval_flags, @@ -66,7 +65,7 @@ int rmdir( const char *path ) if ( S_ISDIR( type ) ) { if ( !rtems_filesystem_location_is_instance_root( currentloc ) ) { - rv = (*ops->rmnod_h)( &parentloc, currentloc ); + rv = ( *ops->rmnod_h )( &parentloc, currentloc ); } else { rtems_filesystem_eval_path_error( &ctx, EBUSY ); rv = -1; diff --git a/cpukit/libcsupport/src/rtems_heap_extend.c b/cpukit/libcsupport/src/rtems_heap_extend.c index d751db91f7..0cbedd1f91 100644 --- a/cpukit/libcsupport/src/rtems_heap_extend.c +++ b/cpukit/libcsupport/src/rtems_heap_extend.c @@ -40,14 +40,11 @@ #ifdef RTEMS_NEWLIB #include "malloc_p.h" -rtems_status_code rtems_heap_extend( - void *area_begin, - uintptr_t area_size -) +rtems_status_code rtems_heap_extend( void *area_begin, uintptr_t area_size ) { - bool ok = _Protected_heap_Extend(RTEMS_Malloc_Heap, area_begin, area_size); + bool ok = _Protected_heap_Extend( RTEMS_Malloc_Heap, area_begin, area_size ); - if (ok) { + if ( ok ) { return RTEMS_SUCCESSFUL; } else { return RTEMS_INVALID_ADDRESS; diff --git a/cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c b/cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c index bb0f9f90ab..53a4e9e766 100644 --- a/cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c +++ b/cpukit/libcsupport/src/rtems_heap_extend_via_sbrk.c @@ -49,15 +49,12 @@ void rtems_heap_set_sbrk_amount( ptrdiff_t sbrk_amount ) RTEMS_Malloc_Sbrk_amount = sbrk_amount; } -void *rtems_heap_extend_via_sbrk( - Heap_Control *heap, - size_t alloc_size -) +void *rtems_heap_extend_via_sbrk( Heap_Control *heap, size_t alloc_size ) { ptrdiff_t sbrk_amount = RTEMS_Malloc_Sbrk_amount; ptrdiff_t sbrk_size = (ptrdiff_t) alloc_size; ptrdiff_t misaligned = sbrk_amount != 0 ? sbrk_size % sbrk_amount : 0; - void *return_this = NULL; + void *return_this = NULL; if ( misaligned != 0 ) { sbrk_size += sbrk_amount - misaligned; diff --git a/cpukit/libcsupport/src/rtems_heap_greedy.c b/cpukit/libcsupport/src/rtems_heap_greedy.c index a43cb20744..de666e7fe8 100644 --- a/cpukit/libcsupport/src/rtems_heap_greedy.c +++ b/cpukit/libcsupport/src/rtems_heap_greedy.c @@ -38,20 +38,24 @@ #include "malloc_p.h" -#define SBRK_ALLOC_SIZE (128 * 1024UL * 1024UL) +#define SBRK_ALLOC_SIZE ( 128 * 1024UL * 1024UL ) void *rtems_heap_greedy_allocate( const uintptr_t *block_sizes, - size_t block_count + size_t block_count ) { Heap_Control *heap = RTEMS_Malloc_Heap; - void *opaque; + void *opaque; rtems_heap_sbrk_greedy_allocate( heap, SBRK_ALLOC_SIZE ); _RTEMS_Lock_allocator(); - opaque = _Heap_Greedy_allocate( RTEMS_Malloc_Heap, block_sizes, block_count ); + opaque = _Heap_Greedy_allocate( + RTEMS_Malloc_Heap, + block_sizes, + block_count + ); _RTEMS_Unlock_allocator(); return opaque; @@ -62,15 +66,12 @@ void *rtems_heap_greedy_allocate_all_except_largest( ) { Heap_Control *heap = RTEMS_Malloc_Heap; - void *opaque; + void *opaque; rtems_heap_sbrk_greedy_allocate( heap, SBRK_ALLOC_SIZE ); _RTEMS_Lock_allocator(); - opaque = _Heap_Greedy_allocate_all_except_largest( - heap, - allocatable_size - ); + opaque = _Heap_Greedy_allocate_all_except_largest( heap, allocatable_size ); _RTEMS_Unlock_allocator(); return opaque; diff --git a/cpukit/libcsupport/src/rtems_heap_null_extend.c b/cpukit/libcsupport/src/rtems_heap_null_extend.c index 2c063c95be..76992f01e2 100644 --- a/cpukit/libcsupport/src/rtems_heap_null_extend.c +++ b/cpukit/libcsupport/src/rtems_heap_null_extend.c @@ -33,7 +33,7 @@ void *rtems_heap_null_extend( Heap_Control *heap RTEMS_UNUSED, - size_t alloc_size RTEMS_UNUSED + size_t alloc_size RTEMS_UNUSED ) { return NULL; diff --git a/cpukit/libcsupport/src/rtems_heap_sbrk_greedy.c b/cpukit/libcsupport/src/rtems_heap_sbrk_greedy.c index 49ae2a7c87..e253997f32 100644 --- a/cpukit/libcsupport/src/rtems_heap_sbrk_greedy.c +++ b/cpukit/libcsupport/src/rtems_heap_sbrk_greedy.c @@ -45,18 +45,15 @@ #include "malloc_p.h" -void rtems_heap_sbrk_greedy_allocate( - Heap_Control *heap, - size_t alloc_size -) +void rtems_heap_sbrk_greedy_allocate( Heap_Control *heap, size_t alloc_size ) { while ( alloc_size > 0 ) { - void *p = (*rtems_malloc_extend_handler)( heap, alloc_size ); + void *p = ( *rtems_malloc_extend_handler )( heap, alloc_size ); if ( p == NULL ) { alloc_size >>= 1; } else { if ( rtems_malloc_dirty_helper != NULL ) { - (*rtems_malloc_dirty_helper)( p, alloc_size ); + ( *rtems_malloc_dirty_helper )( p, alloc_size ); } } } diff --git a/cpukit/libcsupport/src/rtems_memalign.c b/cpukit/libcsupport/src/rtems_memalign.c index 7b67c73b55..3bef3b7098 100644 --- a/cpukit/libcsupport/src/rtems_memalign.c +++ b/cpukit/libcsupport/src/rtems_memalign.c @@ -43,19 +43,16 @@ #include #include -int rtems_memalign( - void **pointer, - size_t alignment, - size_t size -) +int rtems_memalign( void **pointer, size_t alignment, size_t size ) { void *return_this; /* * Parameter error checks */ - if ( !pointer ) + if ( !pointer ) { return EINVAL; + } *pointer = NULL; @@ -66,9 +63,14 @@ int rtems_memalign( /* * Perform the aligned allocation requested */ - return_this = rtems_heap_allocate_aligned_with_boundary( size, alignment, 0 ); - if ( !return_this ) + return_this = rtems_heap_allocate_aligned_with_boundary( + size, + alignment, + 0 + ); + if ( !return_this ) { return ENOMEM; + } *pointer = return_this; return 0; diff --git a/cpukit/libcsupport/src/rtems_mkdir.c b/cpukit/libcsupport/src/rtems_mkdir.c index 06d5028898..4f08ec4df1 100644 --- a/cpukit/libcsupport/src/rtems_mkdir.c +++ b/cpukit/libcsupport/src/rtems_mkdir.c @@ -57,28 +57,30 @@ * Returns 1 if a directory has been created, * 2 if it already existed, and 0 on failure. */ -static int -build(char *path, mode_t omode) +static int build( char *path, mode_t omode ) { struct stat sb; - mode_t numask, oumask; - int first, last, retval; - char *p; + mode_t numask, oumask; + int first, last, retval; + char *p; p = path; oumask = 0; retval = 1; - if (p[0] == '/') /* Skip leading '/'. */ + if ( p[ 0 ] == '/' ) { /* Skip leading '/'. */ ++p; - for (first = 1, last = 0; !last ; ++p) { - if (p[0] == '\0') + } + for ( first = 1, last = 0; !last; ++p ) { + if ( p[ 0 ] == '\0' ) { last = 1; - else if (p[0] != '/') + } else if ( p[ 0 ] != '/' ) { continue; + } *p = '\0'; - if (!last && p[1] == '\0') + if ( !last && p[ 1 ] == '\0' ) { last = 1; - if (first) { + } + if ( first ) { /* * POSIX 1003.2: * For each dir operand that does not name an existing @@ -91,50 +93,54 @@ build(char *path, mode_t omode) * We change the user's umask and then restore it, * instead of doing chmod's. */ - oumask = umask(0); - numask = oumask & ~(S_IWUSR | S_IXUSR); - (void)umask(numask); + oumask = umask( 0 ); + numask = oumask & ~( S_IWUSR | S_IXUSR ); + (void) umask( numask ); first = 0; } - if (last) - (void)umask(oumask); - if (mkdir(path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO) < 0) { - if (errno == EEXIST || errno == EISDIR) { - if (stat(path, &sb) < 0) { + if ( last ) { + (void) umask( oumask ); + } + if ( mkdir( path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO ) < 0 ) { + if ( errno == EEXIST || errno == EISDIR ) { + if ( stat( path, &sb ) < 0 ) { retval = 0; break; - } else if (!S_ISDIR(sb.st_mode)) { - if (last) + } else if ( !S_ISDIR( sb.st_mode ) ) { + if ( last ) { errno = EEXIST; - else + } else { errno = ENOTDIR; + } retval = 0; break; } - if (last) + if ( last ) { retval = 2; + } } else { retval = 0; break; } } - if (!last) - *p = '/'; + if ( !last ) { + *p = '/'; + } } - if (!first && !last) - (void)umask(oumask); - return (retval); + if ( !first && !last ) { + (void) umask( oumask ); + } + return ( retval ); } -int -rtems_mkdir(const char *path, mode_t mode) +int rtems_mkdir( const char *path, mode_t mode ) { - int success = 0; - char *dup_path = strdup(path); + int success = 0; + char *dup_path = strdup( path ); - if (dup_path != NULL) { - success = build(dup_path, mode); - free(dup_path); + if ( dup_path != NULL ) { + success = build( dup_path, mode ); + free( dup_path ); } return success != 0 ? 0 : -1; diff --git a/cpukit/libcsupport/src/rtemscalloc.c b/cpukit/libcsupport/src/rtemscalloc.c index 5cf9cd9613..753a93f08f 100644 --- a/cpukit/libcsupport/src/rtemscalloc.c +++ b/cpukit/libcsupport/src/rtemscalloc.c @@ -43,8 +43,8 @@ void *rtems_calloc( size_t nelem, size_t elsize ) { - size_t length; - void *p; + size_t length; + void *p; if ( nelem == 0 ) { return NULL; diff --git a/cpukit/libcsupport/src/setegid.c b/cpukit/libcsupport/src/setegid.c index 35fe006932..ce1a19ba09 100644 --- a/cpukit/libcsupport/src/setegid.c +++ b/cpukit/libcsupport/src/setegid.c @@ -47,9 +47,7 @@ * 4.2.1 Get Real User, Effective User, Ral Group, and Effective Group IDs, * P1003.1b-1993, p. 84 */ -int setegid( - gid_t gid -) +int setegid( gid_t gid ) { _POSIX_types_Egid = gid; return 0; diff --git a/cpukit/libcsupport/src/setgid.c b/cpukit/libcsupport/src/setgid.c index 80587707b4..6d47648d17 100644 --- a/cpukit/libcsupport/src/setgid.c +++ b/cpukit/libcsupport/src/setgid.c @@ -38,9 +38,7 @@ #include #include -int setgid( - gid_t gid -) +int setgid( gid_t gid ) { _POSIX_types_Gid = gid; return 0; diff --git a/cpukit/libcsupport/src/setgroups.c b/cpukit/libcsupport/src/setgroups.c index 8f7d7565d6..fd5769b851 100644 --- a/cpukit/libcsupport/src/setgroups.c +++ b/cpukit/libcsupport/src/setgroups.c @@ -27,13 +27,13 @@ #include -int setgroups(int size, const gid_t *list) +int setgroups( int size, const gid_t *list ) { - /* FIXME: Implement this function properly. Currently it only returns a + /* FIXME: Implement this function properly. Currently it only returns a * success. */ - (void) size; - (void) list; + (void) size; + (void) list; - return 0; + return 0; } diff --git a/cpukit/libcsupport/src/setpgid.c b/cpukit/libcsupport/src/setpgid.c index 2f3924655b..612910b7bf 100644 --- a/cpukit/libcsupport/src/setpgid.c +++ b/cpukit/libcsupport/src/setpgid.c @@ -44,10 +44,7 @@ /** * 4.3.3 Set Process Group ID for Job Control, P1003.1b-1993, p. 89 */ -int setpgid( - pid_t pid, - pid_t pgid -) +int setpgid( pid_t pid, pid_t pgid ) { (void) pid; (void) pgid; diff --git a/cpukit/libcsupport/src/setuid.c b/cpukit/libcsupport/src/setuid.c index 03c741cb71..fe91182374 100644 --- a/cpukit/libcsupport/src/setuid.c +++ b/cpukit/libcsupport/src/setuid.c @@ -38,9 +38,7 @@ * * 4.2.2 Set User and Group IDs, P1003.1b-1993, p. 84 */ -int setuid( - uid_t uid -) +int setuid( uid_t uid ) { _POSIX_types_Uid = uid; return 0; diff --git a/cpukit/libcsupport/src/stat.c b/cpukit/libcsupport/src/stat.c index 17aaea7bb8..91efc39374 100644 --- a/cpukit/libcsupport/src/stat.c +++ b/cpukit/libcsupport/src/stat.c @@ -65,22 +65,22 @@ int _STAT_NAME( const char *path, struct stat *buf ); */ int _STAT_NAME( const char *path, struct stat *buf ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = _STAT_FOLLOW_LINKS; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); + int eval_flags = _STAT_FOLLOW_LINKS; + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); memset( buf, 0, sizeof( *buf ) ); - rv = (*currentloc->handlers->fstat_h)( currentloc, buf ); + rv = ( *currentloc->handlers->fstat_h )( currentloc, buf ); rtems_filesystem_eval_path_cleanup( &ctx ); return rv; } -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include @@ -89,8 +89,8 @@ int _STAT_NAME( const char *path, struct stat *buf ) */ int _STAT_R_NAME( struct _reent *ptr RTEMS_UNUSED, - const char *path, - struct stat *buf + const char *path, + struct stat *buf ); /** @@ -98,8 +98,8 @@ int _STAT_R_NAME( */ int _STAT_R_NAME( struct _reent *ptr RTEMS_UNUSED, - const char *path, - struct stat *buf + const char *path, + struct stat *buf ) { return _STAT_NAME( path, buf ); diff --git a/cpukit/libcsupport/src/statvfs.c b/cpukit/libcsupport/src/statvfs.c index 86fcec17e2..701460c730 100644 --- a/cpukit/libcsupport/src/statvfs.c +++ b/cpukit/libcsupport/src/statvfs.c @@ -40,15 +40,15 @@ int statvfs( const char *__restrict path, struct statvfs *__restrict buf ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_FOLLOW_LINK; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); + int eval_flags = RTEMS_FS_FOLLOW_LINK; + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); memset( buf, 0, sizeof( *buf ) ); - rv = (*currentloc->mt_entry->ops->statvfs_h)( currentloc, buf ); + rv = ( *currentloc->mt_entry->ops->statvfs_h )( currentloc, buf ); rtems_filesystem_eval_path_cleanup( &ctx ); diff --git a/cpukit/libcsupport/src/sup_fs_check_permissions.c b/cpukit/libcsupport/src/sup_fs_check_permissions.c index a3e02dcca4..21a96fe2b8 100644 --- a/cpukit/libcsupport/src/sup_fs_check_permissions.c +++ b/cpukit/libcsupport/src/sup_fs_check_permissions.c @@ -45,53 +45,53 @@ #define RTEMS_FS_OTH_SHIFT 0 RTEMS_STATIC_ASSERT( - (RTEMS_FS_PERMS_READ << RTEMS_FS_USR_SHIFT) == S_IRUSR, + ( RTEMS_FS_PERMS_READ << RTEMS_FS_USR_SHIFT ) == S_IRUSR, S_IRUSR ); RTEMS_STATIC_ASSERT( - (RTEMS_FS_PERMS_READ << RTEMS_FS_GRP_SHIFT) == S_IRGRP, + ( RTEMS_FS_PERMS_READ << RTEMS_FS_GRP_SHIFT ) == S_IRGRP, S_IRGRP ); RTEMS_STATIC_ASSERT( - (RTEMS_FS_PERMS_READ << RTEMS_FS_OTH_SHIFT) == S_IROTH, + ( RTEMS_FS_PERMS_READ << RTEMS_FS_OTH_SHIFT ) == S_IROTH, S_IROTH ); RTEMS_STATIC_ASSERT( - (RTEMS_FS_PERMS_WRITE << RTEMS_FS_USR_SHIFT) == S_IWUSR, + ( RTEMS_FS_PERMS_WRITE << RTEMS_FS_USR_SHIFT ) == S_IWUSR, S_IWUSR ); RTEMS_STATIC_ASSERT( - (RTEMS_FS_PERMS_WRITE << RTEMS_FS_GRP_SHIFT) == S_IWGRP, + ( RTEMS_FS_PERMS_WRITE << RTEMS_FS_GRP_SHIFT ) == S_IWGRP, S_IWGRP ); RTEMS_STATIC_ASSERT( - (RTEMS_FS_PERMS_WRITE << RTEMS_FS_OTH_SHIFT) == S_IWOTH, + ( RTEMS_FS_PERMS_WRITE << RTEMS_FS_OTH_SHIFT ) == S_IWOTH, S_IWOTH ); RTEMS_STATIC_ASSERT( - (RTEMS_FS_PERMS_EXEC << RTEMS_FS_USR_SHIFT) == S_IXUSR, + ( RTEMS_FS_PERMS_EXEC << RTEMS_FS_USR_SHIFT ) == S_IXUSR, S_IXUSR ); RTEMS_STATIC_ASSERT( - (RTEMS_FS_PERMS_EXEC << RTEMS_FS_GRP_SHIFT) == S_IXGRP, + ( RTEMS_FS_PERMS_EXEC << RTEMS_FS_GRP_SHIFT ) == S_IXGRP, S_IXGRP ); RTEMS_STATIC_ASSERT( - (RTEMS_FS_PERMS_EXEC << RTEMS_FS_OTH_SHIFT) == S_IXOTH, + ( RTEMS_FS_PERMS_EXEC << RTEMS_FS_OTH_SHIFT ) == S_IXOTH, S_IXOTH ); static bool equals_supplementary_group( const rtems_user_env_t *uenv, - gid_t object_gid + gid_t object_gid ) { size_t i; - for (i = 0; i < uenv->ngroups; ++i) { - if (uenv->groups[i] == object_gid) { + for ( i = 0; i < uenv->ngroups; ++i ) { + if ( uenv->groups[ i ] == object_gid ) { return true; } } @@ -100,25 +100,24 @@ static bool equals_supplementary_group( } bool rtems_filesystem_check_access( - int flags, + int flags, mode_t object_mode, - uid_t object_uid, - gid_t object_gid + uid_t object_uid, + gid_t object_gid ) { const rtems_user_env_t *uenv = rtems_current_user_env_get(); - mode_t access_flags = flags & RTEMS_FS_PERMS_RWX; - uid_t task_uid = uenv->euid; + mode_t access_flags = flags & RTEMS_FS_PERMS_RWX; + uid_t task_uid = uenv->euid; - if (task_uid == 0 || task_uid == object_uid) { + if ( task_uid == 0 || task_uid == object_uid ) { access_flags <<= RTEMS_FS_USR_SHIFT; } else { gid_t task_gid = uenv->egid; if ( - task_gid == 0 - || task_gid == object_gid - || equals_supplementary_group(uenv, object_gid) + task_gid == 0 || task_gid == object_gid || + equals_supplementary_group( uenv, object_gid ) ) { access_flags <<= RTEMS_FS_GRP_SHIFT; } else { @@ -126,15 +125,15 @@ bool rtems_filesystem_check_access( } } - return (access_flags & object_mode) == access_flags; + return ( access_flags & object_mode ) == access_flags; } bool rtems_filesystem_eval_path_check_access( rtems_filesystem_eval_path_context_t *ctx, - int eval_flags, - mode_t node_mode, - uid_t node_uid, - gid_t node_gid + int eval_flags, + mode_t node_mode, + uid_t node_uid, + gid_t node_gid ) { bool access_ok = rtems_filesystem_check_access( @@ -144,8 +143,8 @@ bool rtems_filesystem_eval_path_check_access( node_gid ); - if (!access_ok) { - rtems_filesystem_eval_path_error(ctx, EACCES); + if ( !access_ok ) { + rtems_filesystem_eval_path_error( ctx, EACCES ); } return access_ok; diff --git a/cpukit/libcsupport/src/sup_fs_deviceio.c b/cpukit/libcsupport/src/sup_fs_deviceio.c index 3229f398cb..7ba23ea410 100644 --- a/cpukit/libcsupport/src/sup_fs_deviceio.c +++ b/cpukit/libcsupport/src/sup_fs_deviceio.c @@ -41,10 +41,10 @@ #include int rtems_deviceio_open( - rtems_libio_t *iop, - const char *path, - int oflag, - mode_t mode, + rtems_libio_t *iop, + const char *path, + int oflag, + mode_t mode, rtems_device_major_number major, rtems_device_minor_number minor ) @@ -52,7 +52,7 @@ int rtems_deviceio_open( (void) path; (void) oflag; - rtems_status_code status; + rtems_status_code status; rtems_libio_open_close_args_t args; args.iop = iop; @@ -65,12 +65,12 @@ int rtems_deviceio_open( } int rtems_deviceio_close( - rtems_libio_t *iop, + rtems_libio_t *iop, rtems_device_major_number major, rtems_device_minor_number minor ) { - rtems_status_code status; + rtems_status_code status; rtems_libio_open_close_args_t args; args.iop = iop; @@ -83,14 +83,14 @@ int rtems_deviceio_close( } ssize_t rtems_deviceio_read( - rtems_libio_t *iop, - void *buf, - size_t nbyte, + rtems_libio_t *iop, + void *buf, + size_t nbyte, rtems_device_major_number major, rtems_device_minor_number minor ) { - rtems_status_code status; + rtems_status_code status; rtems_libio_rw_args_t args; args.iop = iop; @@ -111,14 +111,14 @@ ssize_t rtems_deviceio_read( } ssize_t rtems_deviceio_write( - rtems_libio_t *iop, - const void *buf, - size_t nbyte, + rtems_libio_t *iop, + const void *buf, + size_t nbyte, rtems_device_major_number major, rtems_device_minor_number minor ) { - rtems_status_code status; + rtems_status_code status; rtems_libio_rw_args_t args; args.iop = iop; @@ -139,14 +139,14 @@ ssize_t rtems_deviceio_write( } int rtems_deviceio_control( - rtems_libio_t *iop, - ioctl_command_t command, - void *buffer, + rtems_libio_t *iop, + ioctl_command_t command, + void *buffer, rtems_device_major_number major, rtems_device_minor_number minor ) { - rtems_status_code status; + rtems_status_code status; rtems_libio_ioctl_args_t args; args.iop = iop; @@ -157,6 +157,6 @@ int rtems_deviceio_control( if ( status == RTEMS_SUCCESSFUL ) { return args.ioctl_return; } else { - return rtems_status_code_to_errno(status); + return rtems_status_code_to_errno( status ); } } diff --git a/cpukit/libcsupport/src/sup_fs_eval_path.c b/cpukit/libcsupport/src/sup_fs_eval_path.c index 43d7bbbff8..ea5e7dc87a 100644 --- a/cpukit/libcsupport/src/sup_fs_eval_path.c +++ b/cpukit/libcsupport/src/sup_fs_eval_path.c @@ -40,12 +40,12 @@ #include -static size_t get_parentpathlen(const char *path, size_t pathlen) +static size_t get_parentpathlen( const char *path, size_t pathlen ) { - while (pathlen > 0) { + while ( pathlen > 0 ) { size_t i = pathlen - 1; - if (rtems_filesystem_is_delimiter(path [i])) { + if ( rtems_filesystem_is_delimiter( path[ i ] ) ) { return pathlen; } @@ -56,22 +56,20 @@ static size_t get_parentpathlen(const char *path, size_t pathlen) } static void set_startloc( - rtems_filesystem_eval_path_context_t *ctx, + rtems_filesystem_eval_path_context_t *ctx, rtems_filesystem_global_location_t *const *global_root_ptr, rtems_filesystem_global_location_t *const *global_current_ptr ) { - if (ctx->pathlen > 0) { - char c = ctx->path [0]; + if ( ctx->pathlen > 0 ) { + char c = ctx->path[ 0 ]; - ctx->rootloc = rtems_filesystem_global_location_obtain(global_root_ptr); + ctx->rootloc = rtems_filesystem_global_location_obtain( global_root_ptr ); - if (rtems_filesystem_is_delimiter(c)) { + if ( rtems_filesystem_is_delimiter( c ) ) { ++ctx->path; --ctx->pathlen; - ctx->startloc = rtems_filesystem_global_location_obtain( - &ctx->rootloc - ); + ctx->startloc = rtems_filesystem_global_location_obtain( &ctx->rootloc ); } else { ctx->startloc = rtems_filesystem_global_location_obtain( global_current_ptr @@ -86,21 +84,21 @@ static void set_startloc( static void check_access( rtems_filesystem_eval_path_context_t *ctx, - int eval_flags + int eval_flags ) { - const rtems_filesystem_location_info_t *currentloc = &ctx->currentloc; + const rtems_filesystem_location_info_t *currentloc = &ctx->currentloc; const rtems_filesystem_mount_table_entry_t *mt_entry = currentloc->mt_entry; - if ((eval_flags & RTEMS_FS_PERMS_WRITE) == 0 || mt_entry->writeable) { + if ( ( eval_flags & RTEMS_FS_PERMS_WRITE ) == 0 || mt_entry->writeable ) { struct stat st; - int rv; + int rv; st.st_mode = 0; st.st_uid = 0; st.st_gid = 0; - rv = (*currentloc->handlers->fstat_h)(currentloc, &st); - if (rv == 0) { + rv = ( *currentloc->handlers->fstat_h )( currentloc, &st ); + if ( rv == 0 ) { bool access_ok = rtems_filesystem_check_access( eval_flags, st.st_mode, @@ -108,14 +106,14 @@ static void check_access( st.st_gid ); - if (!access_ok) { - rtems_filesystem_eval_path_error(ctx, EACCES); + if ( !access_ok ) { + rtems_filesystem_eval_path_error( ctx, EACCES ); } } else { - rtems_filesystem_eval_path_error(ctx, 0); + rtems_filesystem_eval_path_error( ctx, 0 ); } } else { - rtems_filesystem_eval_path_error(ctx, EROFS); + rtems_filesystem_eval_path_error( ctx, EROFS ); } } @@ -125,95 +123,93 @@ void rtems_filesystem_eval_path_continue( { int eval_flags; - while (ctx->pathlen > 0) { - (*ctx->currentloc.mt_entry->ops->eval_path_h)(ctx); + while ( ctx->pathlen > 0 ) { + ( *ctx->currentloc.mt_entry->ops->eval_path_h )( ctx ); } - eval_flags = rtems_filesystem_eval_path_get_flags(ctx); - if (rtems_filesystem_eval_path_has_token(ctx)) { - bool make = (eval_flags & RTEMS_FS_MAKE) != 0; + eval_flags = rtems_filesystem_eval_path_get_flags( ctx ); + if ( rtems_filesystem_eval_path_has_token( ctx ) ) { + bool make = ( eval_flags & RTEMS_FS_MAKE ) != 0; - if (make) { - check_access(ctx, RTEMS_FS_PERMS_WRITE); + if ( make ) { + check_access( ctx, RTEMS_FS_PERMS_WRITE ); } else { - rtems_filesystem_eval_path_error(ctx, ENOENT); + rtems_filesystem_eval_path_error( ctx, ENOENT ); } } else { - bool exclusive = (eval_flags & RTEMS_FS_EXCLUSIVE) != 0; + bool exclusive = ( eval_flags & RTEMS_FS_EXCLUSIVE ) != 0; - if (!exclusive) { - check_access(ctx, ctx->flags); + if ( !exclusive ) { + check_access( ctx, ctx->flags ); } else { - rtems_filesystem_eval_path_error(ctx, EEXIST); + rtems_filesystem_eval_path_error( ctx, EEXIST ); } } } rtems_filesystem_location_info_t * rtems_filesystem_eval_path_start_with_root_and_current( - rtems_filesystem_eval_path_context_t *ctx, - const char *path, - size_t pathlen, - int eval_flags, + rtems_filesystem_eval_path_context_t *ctx, + const char *path, + size_t pathlen, + int eval_flags, rtems_filesystem_global_location_t *const *global_root_ptr, rtems_filesystem_global_location_t *const *global_current_ptr ) { - memset(ctx, 0, sizeof(*ctx)); + memset( ctx, 0, sizeof( *ctx ) ); ctx->path = path; ctx->pathlen = pathlen; ctx->flags = eval_flags; - set_startloc(ctx, global_root_ptr, global_current_ptr); + set_startloc( ctx, global_root_ptr, global_current_ptr ); - rtems_filesystem_instance_lock(&ctx->startloc->location); + rtems_filesystem_instance_lock( &ctx->startloc->location ); rtems_filesystem_location_clone( &ctx->currentloc, &ctx->startloc->location ); - rtems_filesystem_eval_path_continue(ctx); + rtems_filesystem_eval_path_continue( ctx ); return &ctx->currentloc; } -rtems_filesystem_location_info_t * -rtems_filesystem_eval_path_start( +rtems_filesystem_location_info_t *rtems_filesystem_eval_path_start( rtems_filesystem_eval_path_context_t *ctx, - const char *path, - int eval_flags + const char *path, + int eval_flags ) { return rtems_filesystem_eval_path_start_with_root_and_current( ctx, path, - strlen(path), + strlen( path ), eval_flags, &rtems_filesystem_root, &rtems_filesystem_current ); } -rtems_filesystem_location_info_t * -rtems_filesystem_eval_path_start_with_parent( +rtems_filesystem_location_info_t *rtems_filesystem_eval_path_start_with_parent( rtems_filesystem_eval_path_context_t *ctx, - const char *path, - int eval_flags, - rtems_filesystem_location_info_t *parentloc, - int parent_eval_flags + const char *path, + int eval_flags, + rtems_filesystem_location_info_t *parentloc, + int parent_eval_flags ) { - size_t pathlen = strlen(path); + size_t pathlen = strlen( path ); const char *parentpath = path; - size_t parentpathlen = get_parentpathlen(path, pathlen); + size_t parentpathlen = get_parentpathlen( path, pathlen ); const char *name = NULL; - size_t namelen = 0; + size_t namelen = 0; const rtems_filesystem_location_info_t *currentloc = NULL; - if (pathlen > 0) { - if (parentpathlen == 0) { + if ( pathlen > 0 ) { + if ( parentpathlen == 0 ) { parentpath = "."; parentpathlen = 1; name = path; @@ -233,54 +229,54 @@ rtems_filesystem_eval_path_start_with_parent( &rtems_filesystem_current ); - rtems_filesystem_location_clone(parentloc, currentloc); + rtems_filesystem_location_clone( parentloc, currentloc ); ctx->path = name; ctx->pathlen = namelen; ctx->flags = eval_flags; - rtems_filesystem_eval_path_continue(ctx); + rtems_filesystem_eval_path_continue( ctx ); return &ctx->currentloc; } void rtems_filesystem_eval_path_recursive( rtems_filesystem_eval_path_context_t *ctx, - const char *path, - size_t pathlen + const char *path, + size_t pathlen ) { - if (pathlen > 0) { - if (ctx->recursionlevel < RTEMS_FILESYSTEM_SYMLOOP_MAX) { + if ( pathlen > 0 ) { + if ( ctx->recursionlevel < RTEMS_FILESYSTEM_SYMLOOP_MAX ) { const char *saved_path = ctx->path; - size_t saved_pathlen = ctx->pathlen; + size_t saved_pathlen = ctx->pathlen; - if (rtems_filesystem_is_delimiter(path [0])) { - rtems_filesystem_eval_path_restart(ctx, &ctx->rootloc); + if ( rtems_filesystem_is_delimiter( path[ 0 ] ) ) { + rtems_filesystem_eval_path_restart( ctx, &ctx->rootloc ); } ctx->path = path; ctx->pathlen = pathlen; ++ctx->recursionlevel; - while (ctx->pathlen > 0) { - (*ctx->currentloc.mt_entry->ops->eval_path_h)(ctx); + while ( ctx->pathlen > 0 ) { + ( *ctx->currentloc.mt_entry->ops->eval_path_h )( ctx ); } --ctx->recursionlevel; ctx->path = saved_path; ctx->pathlen = saved_pathlen; } else { - rtems_filesystem_eval_path_error(ctx, ELOOP); + rtems_filesystem_eval_path_error( ctx, ELOOP ); } } else { - rtems_filesystem_eval_path_error(ctx, ENOENT); + rtems_filesystem_eval_path_error( ctx, ENOENT ); } } void rtems_filesystem_eval_path_error( rtems_filesystem_eval_path_context_t *ctx, - int eno + int eno ) { ctx->path = NULL; @@ -288,56 +284,59 @@ void rtems_filesystem_eval_path_error( ctx->token = NULL; ctx->tokenlen = 0; - if (!rtems_filesystem_location_is_null(&ctx->currentloc)) { - if (eno != 0) { + if ( !rtems_filesystem_location_is_null( &ctx->currentloc ) ) { + if ( eno != 0 ) { errno = eno; } - rtems_filesystem_location_detach(&ctx->currentloc); + rtems_filesystem_location_detach( &ctx->currentloc ); } } -static void free_location(rtems_filesystem_location_info_t *loc) +static void free_location( rtems_filesystem_location_info_t *loc ) { - rtems_filesystem_mt_entry_declare_lock_context(lock_context); + rtems_filesystem_mt_entry_declare_lock_context( lock_context ); - (*loc->mt_entry->ops->freenod_h)(loc); + ( *loc->mt_entry->ops->freenod_h )( loc ); - rtems_filesystem_mt_entry_lock(lock_context); - rtems_chain_extract_unprotected(&loc->mt_entry_node); - rtems_filesystem_mt_entry_unlock(lock_context); + rtems_filesystem_mt_entry_lock( lock_context ); + rtems_chain_extract_unprotected( &loc->mt_entry_node ); + rtems_filesystem_mt_entry_unlock( lock_context ); } void rtems_filesystem_eval_path_cleanup( rtems_filesystem_eval_path_context_t *ctx ) { - free_location(&ctx->currentloc); - rtems_filesystem_instance_unlock(&ctx->startloc->location); - rtems_filesystem_global_location_release(ctx->startloc, false); - rtems_filesystem_global_location_release(ctx->rootloc, false); + free_location( &ctx->currentloc ); + rtems_filesystem_instance_unlock( &ctx->startloc->location ); + rtems_filesystem_global_location_release( ctx->startloc, false ); + rtems_filesystem_global_location_release( ctx->rootloc, false ); } void rtems_filesystem_eval_path_cleanup_with_parent( rtems_filesystem_eval_path_context_t *ctx, - rtems_filesystem_location_info_t *parentloc + rtems_filesystem_location_info_t *parentloc ) { - free_location(parentloc); - rtems_filesystem_eval_path_cleanup(ctx); + free_location( parentloc ); + rtems_filesystem_eval_path_cleanup( ctx ); } void rtems_filesystem_eval_path_restart( rtems_filesystem_eval_path_context_t *ctx, - rtems_filesystem_global_location_t **newstartloc_ptr + rtems_filesystem_global_location_t **newstartloc_ptr ) { - free_location(&ctx->currentloc); - rtems_filesystem_instance_unlock(&ctx->startloc->location); + free_location( &ctx->currentloc ); + rtems_filesystem_instance_unlock( &ctx->startloc->location ); rtems_filesystem_global_location_assign( &ctx->startloc, - rtems_filesystem_global_location_obtain(newstartloc_ptr) + rtems_filesystem_global_location_obtain( newstartloc_ptr ) + ); + rtems_filesystem_instance_lock( &ctx->startloc->location ); + rtems_filesystem_location_clone( + &ctx->currentloc, + &ctx->startloc->location ); - rtems_filesystem_instance_lock(&ctx->startloc->location); - rtems_filesystem_location_clone(&ctx->currentloc, &ctx->startloc->location); } diff --git a/cpukit/libcsupport/src/sup_fs_eval_path_generic.c b/cpukit/libcsupport/src/sup_fs_eval_path_generic.c index f388f91c3b..271ab640a2 100644 --- a/cpukit/libcsupport/src/sup_fs_eval_path_generic.c +++ b/cpukit/libcsupport/src/sup_fs_eval_path_generic.c @@ -41,64 +41,64 @@ static bool is_fs_root( const rtems_filesystem_location_info_t *loc ) { const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry; - const rtems_filesystem_location_info_t *mt_fs_root = - &mt_entry->mt_fs_root->location; + const rtems_filesystem_location_info_t + *mt_fs_root = &mt_entry->mt_fs_root->location; - return (*mt_entry->ops->are_nodes_equal_h)( loc, mt_fs_root ); + return ( *mt_entry->ops->are_nodes_equal_h )( loc, mt_fs_root ); } static bool is_eval_path_root( const rtems_filesystem_eval_path_context_t *ctx, - const rtems_filesystem_location_info_t *loc + const rtems_filesystem_location_info_t *loc ) { const rtems_filesystem_mount_table_entry_t *mt_entry = loc->mt_entry; const rtems_filesystem_location_info_t *rootloc = &ctx->rootloc->location; - return mt_entry == rootloc->mt_entry - && (*mt_entry->ops->are_nodes_equal_h)( loc, rootloc ); + return mt_entry == rootloc->mt_entry && + ( *mt_entry->ops->are_nodes_equal_h )( loc, rootloc ); } void rtems_filesystem_eval_path_generic( - rtems_filesystem_eval_path_context_t *ctx, - void *arg, + rtems_filesystem_eval_path_context_t *ctx, + void *arg, const rtems_filesystem_eval_path_generic_config *config ) { - rtems_filesystem_eval_path_generic_status status = - RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE; + rtems_filesystem_eval_path_generic_status + status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE; - while (status == RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE) { + while ( status == RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_CONTINUE ) { const char *token; - size_t tokenlen; + size_t tokenlen; - rtems_filesystem_eval_path_get_next_token(ctx, &token, &tokenlen); + rtems_filesystem_eval_path_get_next_token( ctx, &token, &tokenlen ); - if (tokenlen > 0) { - if ((*config->is_directory)(ctx, arg)) { - if (rtems_filesystem_is_current_directory(token, tokenlen)) { - if (rtems_filesystem_eval_path_has_path(ctx)) { - status = (*config->eval_token)(ctx, arg, ".", 1); + if ( tokenlen > 0 ) { + if ( ( *config->is_directory )( ctx, arg ) ) { + if ( rtems_filesystem_is_current_directory( token, tokenlen ) ) { + if ( rtems_filesystem_eval_path_has_path( ctx ) ) { + status = ( *config->eval_token )( ctx, arg, ".", 1 ); } else { - int eval_flags = rtems_filesystem_eval_path_get_flags(ctx); + int eval_flags = rtems_filesystem_eval_path_get_flags( ctx ); - if ((eval_flags & RTEMS_FS_REJECT_TERMINAL_DOT) == 0) { - status = (*config->eval_token)(ctx, arg, ".", 1); + if ( ( eval_flags & RTEMS_FS_REJECT_TERMINAL_DOT ) == 0 ) { + status = ( *config->eval_token )( ctx, arg, ".", 1 ); } else { - rtems_filesystem_eval_path_error(ctx, EINVAL); + rtems_filesystem_eval_path_error( ctx, EINVAL ); status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE; } } - } else if (rtems_filesystem_is_parent_directory(token, tokenlen)) { - rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_get_currentloc( ctx ); + } else if ( rtems_filesystem_is_parent_directory( token, tokenlen ) ) { + rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_get_currentloc( ctx ); - if (is_eval_path_root(ctx, currentloc)) { + if ( is_eval_path_root( ctx, currentloc ) ) { /* This prevents the escape from a chroot() environment */ - status = (*config->eval_token)(ctx, arg, ".", 1); - } else if (is_fs_root(currentloc)) { - if (currentloc->mt_entry->mt_point_node != NULL) { - rtems_filesystem_eval_path_put_back_token(ctx); + status = ( *config->eval_token )( ctx, arg, ".", 1 ); + } else if ( is_fs_root( currentloc ) ) { + if ( currentloc->mt_entry->mt_point_node != NULL ) { + rtems_filesystem_eval_path_put_back_token( ctx ); rtems_filesystem_eval_path_restart( ctx, ¤tloc->mt_entry->mt_point_node @@ -106,31 +106,31 @@ void rtems_filesystem_eval_path_generic( status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE; } else { /* This is the root file system */ - status = (*config->eval_token)(ctx, arg, ".", 1); + status = ( *config->eval_token )( ctx, arg, ".", 1 ); } } else { - status = (*config->eval_token)(ctx, arg, "..", 2); + status = ( *config->eval_token )( ctx, arg, "..", 2 ); } } else { - status = (*config->eval_token)(ctx, arg, token, tokenlen); + status = ( *config->eval_token )( ctx, arg, token, tokenlen ); } - if (status == RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY) { - if (rtems_filesystem_eval_path_has_path(ctx)) { + if ( status == RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_NO_ENTRY ) { + if ( rtems_filesystem_eval_path_has_path( ctx ) ) { int eval_flags; - rtems_filesystem_eval_path_eat_delimiter(ctx); - eval_flags = rtems_filesystem_eval_path_get_flags(ctx); + rtems_filesystem_eval_path_eat_delimiter( ctx ); + eval_flags = rtems_filesystem_eval_path_get_flags( ctx ); if ( - (eval_flags & RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS) == 0 - || rtems_filesystem_eval_path_has_path(ctx) + ( eval_flags & RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS ) == 0 || + rtems_filesystem_eval_path_has_path( ctx ) ) { - rtems_filesystem_eval_path_error(ctx, ENOENT); + rtems_filesystem_eval_path_error( ctx, ENOENT ); } } } } else { - rtems_filesystem_eval_path_error(ctx, ENOTDIR); + rtems_filesystem_eval_path_error( ctx, ENOTDIR ); status = RTEMS_FILESYSTEM_EVAL_PATH_GENERIC_DONE; } } else { diff --git a/cpukit/libcsupport/src/sup_fs_exist_in_same_instance.c b/cpukit/libcsupport/src/sup_fs_exist_in_same_instance.c index e7c8d755c8..ac1f62d597 100644 --- a/cpukit/libcsupport/src/sup_fs_exist_in_same_instance.c +++ b/cpukit/libcsupport/src/sup_fs_exist_in_same_instance.c @@ -46,8 +46,8 @@ int rtems_filesystem_location_exists_in_same_instance_as( int rv = -1; if ( - !rtems_filesystem_location_is_null( a ) - && !rtems_filesystem_location_is_null( b ) + !rtems_filesystem_location_is_null( a ) && + !rtems_filesystem_location_is_null( b ) ) { if ( a->mt_entry == b->mt_entry ) { rv = 0; diff --git a/cpukit/libcsupport/src/sup_fs_location.c b/cpukit/libcsupport/src/sup_fs_location.c index a121b252fb..2befa83dab 100644 --- a/cpukit/libcsupport/src/sup_fs_location.c +++ b/cpukit/libcsupport/src/sup_fs_location.c @@ -41,7 +41,7 @@ #include rtems_interrupt_lock rtems_filesystem_mt_entry_lock_control = - RTEMS_INTERRUPT_LOCK_INITIALIZER("mount table entry"); + RTEMS_INTERRUPT_LOCK_INITIALIZER( "mount table entry" ); RTEMS_INTERRUPT_LOCK_DEFINE( static, @@ -52,7 +52,7 @@ RTEMS_INTERRUPT_LOCK_DEFINE( static rtems_filesystem_global_location_t *deferred_released_global_locations; rtems_filesystem_location_info_t *rtems_filesystem_location_copy( - rtems_filesystem_location_info_t *dst, + rtems_filesystem_location_info_t *dst, const rtems_filesystem_location_info_t *src ) { @@ -60,8 +60,8 @@ rtems_filesystem_location_info_t *rtems_filesystem_location_copy( dst->node_access_2 = src->node_access_2; dst->handlers = src->handlers; dst->mt_entry = src->mt_entry; - rtems_chain_initialize_node(&dst->mt_entry_node); - rtems_filesystem_location_add_to_mt_entry(dst); + rtems_chain_initialize_node( &dst->mt_entry_node ); + rtems_filesystem_location_add_to_mt_entry( dst ); return dst; } @@ -70,8 +70,8 @@ void rtems_filesystem_location_detach( rtems_filesystem_location_info_t *detach ) { - rtems_filesystem_location_free(detach); - rtems_filesystem_location_initialize_to_null(detach); + rtems_filesystem_location_free( detach ); + rtems_filesystem_location_initialize_to_null( detach ); } void rtems_filesystem_location_copy_and_detach( @@ -79,25 +79,28 @@ void rtems_filesystem_location_copy_and_detach( rtems_filesystem_location_info_t *detach ) { - rtems_filesystem_location_copy(copy, detach); - rtems_filesystem_location_remove_from_mt_entry(detach); - rtems_filesystem_location_initialize_to_null(detach); + rtems_filesystem_location_copy( copy, detach ); + rtems_filesystem_location_remove_from_mt_entry( detach ); + rtems_filesystem_location_initialize_to_null( detach ); } -rtems_filesystem_global_location_t *rtems_filesystem_location_transform_to_global( +rtems_filesystem_global_location_t * +rtems_filesystem_location_transform_to_global( rtems_filesystem_location_info_t *loc ) { - rtems_filesystem_global_location_t *global_loc = malloc(sizeof(*global_loc)); + rtems_filesystem_global_location_t *global_loc = malloc( + sizeof( *global_loc ) + ); - if (global_loc != NULL) { + if ( global_loc != NULL ) { global_loc->reference_count = 1; global_loc->deferred_released_next = NULL; global_loc->deferred_released_count = 0; - rtems_filesystem_location_copy(&global_loc->location, loc); - rtems_filesystem_location_remove_from_mt_entry(loc); + rtems_filesystem_location_copy( &global_loc->location, loc ); + rtems_filesystem_location_remove_from_mt_entry( loc ); } else { - rtems_filesystem_location_free(loc); + rtems_filesystem_location_free( loc ); global_loc = rtems_filesystem_global_location_obtain_null(); errno = ENOMEM; } @@ -107,109 +110,109 @@ rtems_filesystem_global_location_t *rtems_filesystem_location_transform_to_globa void rtems_filesystem_global_location_assign( rtems_filesystem_global_location_t **lhs_global_loc_ptr, - rtems_filesystem_global_location_t *rhs_global_loc + rtems_filesystem_global_location_t *rhs_global_loc ) { - rtems_filesystem_mt_entry_declare_lock_context(lock_context); + rtems_filesystem_mt_entry_declare_lock_context( lock_context ); rtems_filesystem_global_location_t *lhs_global_loc; - rtems_filesystem_mt_entry_lock(lock_context); + rtems_filesystem_mt_entry_lock( lock_context ); lhs_global_loc = *lhs_global_loc_ptr; *lhs_global_loc_ptr = rhs_global_loc; - rtems_filesystem_mt_entry_unlock(lock_context); + rtems_filesystem_mt_entry_unlock( lock_context ); - rtems_filesystem_global_location_release(lhs_global_loc, true); + rtems_filesystem_global_location_release( lhs_global_loc, true ); } static void release_with_count( rtems_filesystem_global_location_t *global_loc, - int count + int count ) { - rtems_filesystem_mount_table_entry_t *mt_entry = - global_loc->location.mt_entry; - rtems_filesystem_mt_entry_declare_lock_context(lock_context); + rtems_filesystem_mount_table_entry_t + *mt_entry = global_loc->location.mt_entry; + rtems_filesystem_mt_entry_declare_lock_context( lock_context ); bool do_free; bool do_unmount; - rtems_filesystem_mt_entry_lock(lock_context); + rtems_filesystem_mt_entry_lock( lock_context ); global_loc->reference_count -= count; do_free = global_loc->reference_count == 0; - do_unmount = rtems_filesystem_is_ready_for_unmount(mt_entry); - rtems_filesystem_mt_entry_unlock(lock_context); + do_unmount = rtems_filesystem_is_ready_for_unmount( mt_entry ); + rtems_filesystem_mt_entry_unlock( lock_context ); - if (do_free) { - rtems_filesystem_location_free(&global_loc->location); - free(global_loc); + if ( do_free ) { + rtems_filesystem_location_free( &global_loc->location ); + free( global_loc ); } - if (do_unmount) { - rtems_filesystem_do_unmount(mt_entry); + if ( do_unmount ) { + rtems_filesystem_do_unmount( mt_entry ); } } -static void deferred_release(void) +static void deferred_release( void ) { rtems_filesystem_global_location_t *current = NULL; do { rtems_interrupt_lock_context lock_context; - int count = 0; + int count = 0; - rtems_interrupt_lock_acquire(&deferred_release_lock, &lock_context); + rtems_interrupt_lock_acquire( &deferred_release_lock, &lock_context ); current = deferred_released_global_locations; - if (current != NULL) { + if ( current != NULL ) { deferred_released_global_locations = current->deferred_released_next; count = current->deferred_released_count; current->deferred_released_next = NULL; current->deferred_released_count = 0; } - rtems_interrupt_lock_release(&deferred_release_lock, &lock_context); + rtems_interrupt_lock_release( &deferred_release_lock, &lock_context ); - if (current != NULL) { - release_with_count(current, count); + if ( current != NULL ) { + release_with_count( current, count ); } - } while (current != NULL); + } while ( current != NULL ); } rtems_filesystem_global_location_t *rtems_filesystem_global_location_obtain( rtems_filesystem_global_location_t *const *global_loc_ptr ) { - rtems_filesystem_mt_entry_declare_lock_context(lock_context); + rtems_filesystem_mt_entry_declare_lock_context( lock_context ); rtems_filesystem_global_location_t *global_loc; - if (deferred_released_global_locations != NULL) { + if ( deferred_released_global_locations != NULL ) { deferred_release(); } - rtems_filesystem_mt_entry_lock(lock_context); + rtems_filesystem_mt_entry_lock( lock_context ); global_loc = *global_loc_ptr; - if (global_loc == NULL || !global_loc->location.mt_entry->mounted) { + if ( global_loc == NULL || !global_loc->location.mt_entry->mounted ) { global_loc = &rtems_filesystem_global_location_null; errno = ENXIO; } ++global_loc->reference_count; - rtems_filesystem_mt_entry_unlock(lock_context); + rtems_filesystem_mt_entry_unlock( lock_context ); return global_loc; } void rtems_filesystem_global_location_release( rtems_filesystem_global_location_t *global_loc, - bool deferred + bool deferred ) { - if (!deferred) { - release_with_count(global_loc, 1); + if ( !deferred ) { + release_with_count( global_loc, 1 ); } else { rtems_interrupt_lock_context lock_context; - rtems_interrupt_lock_acquire(&deferred_release_lock, &lock_context); + rtems_interrupt_lock_acquire( &deferred_release_lock, &lock_context ); - if (global_loc->deferred_released_count == 0) { - rtems_filesystem_global_location_t *head = - deferred_released_global_locations; + if ( global_loc->deferred_released_count == 0 ) { + rtems_filesystem_global_location_t + *head = deferred_released_global_locations; global_loc->deferred_released_count = 1; global_loc->deferred_released_next = head; @@ -218,7 +221,7 @@ void rtems_filesystem_global_location_release( ++global_loc->deferred_released_count; } - rtems_interrupt_lock_release(&deferred_release_lock, &lock_context); + rtems_interrupt_lock_release( &deferred_release_lock, &lock_context ); } } @@ -226,16 +229,16 @@ void rtems_filesystem_location_remove_from_mt_entry( rtems_filesystem_location_info_t *loc ) { - rtems_filesystem_mt_entry_declare_lock_context(lock_context); + rtems_filesystem_mt_entry_declare_lock_context( lock_context ); bool do_unmount; - rtems_filesystem_mt_entry_lock(lock_context); - rtems_chain_extract_unprotected(&loc->mt_entry_node); - do_unmount = rtems_filesystem_is_ready_for_unmount(loc->mt_entry); - rtems_filesystem_mt_entry_unlock(lock_context); + rtems_filesystem_mt_entry_lock( lock_context ); + rtems_chain_extract_unprotected( &loc->mt_entry_node ); + do_unmount = rtems_filesystem_is_ready_for_unmount( loc->mt_entry ); + rtems_filesystem_mt_entry_unlock( lock_context ); - if (do_unmount) { - rtems_filesystem_do_unmount(loc->mt_entry); + if ( do_unmount ) { + rtems_filesystem_do_unmount( loc->mt_entry ); } } @@ -244,18 +247,19 @@ void rtems_filesystem_do_unmount( ) { rtems_filesystem_mt_lock(); - rtems_chain_extract_unprotected(&mt_entry->mt_node); + rtems_chain_extract_unprotected( &mt_entry->mt_node ); rtems_filesystem_mt_unlock(); - rtems_filesystem_global_location_release(mt_entry->mt_point_node, false); - (*mt_entry->ops->fsunmount_me_h)(mt_entry); + rtems_filesystem_global_location_release( mt_entry->mt_point_node, false ); + ( *mt_entry->ops->fsunmount_me_h )( mt_entry ); - if (mt_entry->unmount_task != 0) { - rtems_status_code sc = - rtems_event_transient_send(mt_entry->unmount_task); - if (sc != RTEMS_SUCCESSFUL) { - rtems_fatal_error_occurred(0xdeadbeef); + if ( mt_entry->unmount_task != 0 ) { + rtems_status_code sc = rtems_event_transient_send( + mt_entry->unmount_task + ); + if ( sc != RTEMS_SUCCESSFUL ) { + rtems_fatal_error_occurred( 0xdeadbeef ); } } - free(mt_entry); + free( mt_entry ); } diff --git a/cpukit/libcsupport/src/sup_fs_mount_iterate.c b/cpukit/libcsupport/src/sup_fs_mount_iterate.c index 59621dc095..1b2708de05 100644 --- a/cpukit/libcsupport/src/sup_fs_mount_iterate.c +++ b/cpukit/libcsupport/src/sup_fs_mount_iterate.c @@ -41,12 +41,12 @@ bool rtems_filesystem_mount_iterate( rtems_filesystem_mt_entry_visitor visitor, - void *visitor_arg + void *visitor_arg ) { rtems_chain_control *chain = &rtems_filesystem_mount_table; - rtems_chain_node *node = NULL; - bool stop = false; + rtems_chain_node *node = NULL; + bool stop = false; rtems_filesystem_mt_lock(); for ( @@ -54,10 +54,10 @@ bool rtems_filesystem_mount_iterate( !rtems_chain_is_tail( chain, node ) && !stop; node = rtems_chain_next( node ) ) { - const rtems_filesystem_mount_table_entry_t *mt_entry = - (rtems_filesystem_mount_table_entry_t *) node; + const rtems_filesystem_mount_table_entry_t + *mt_entry = (rtems_filesystem_mount_table_entry_t *) node; - stop = (*visitor)( mt_entry, visitor_arg ); + stop = ( *visitor )( mt_entry, visitor_arg ); } rtems_filesystem_mt_unlock(); diff --git a/cpukit/libcsupport/src/sup_fs_next_token.c b/cpukit/libcsupport/src/sup_fs_next_token.c index 1e096f2d37..36ea8a845b 100644 --- a/cpukit/libcsupport/src/sup_fs_next_token.c +++ b/cpukit/libcsupport/src/sup_fs_next_token.c @@ -45,34 +45,34 @@ void rtems_filesystem_eval_path_eat_delimiter( const char *current = ctx->path; const char *end = current + ctx->pathlen; - while (current != end && rtems_filesystem_is_delimiter(*current)) { + while ( current != end && rtems_filesystem_is_delimiter( *current ) ) { ++current; } ctx->path = current; - ctx->pathlen = (size_t) (end - current); + ctx->pathlen = (size_t) ( end - current ); } -static void next_token(rtems_filesystem_eval_path_context_t *ctx) +static void next_token( rtems_filesystem_eval_path_context_t *ctx ) { const char *begin = ctx->path; const char *end = begin + ctx->pathlen; const char *current = begin; - while (current != end && !rtems_filesystem_is_delimiter(*current)) { + while ( current != end && !rtems_filesystem_is_delimiter( *current ) ) { ++current; } ctx->path = current; - ctx->pathlen = (size_t) (end - current); + ctx->pathlen = (size_t) ( end - current ); ctx->token = begin; - ctx->tokenlen = (size_t) (current - begin); + ctx->tokenlen = (size_t) ( current - begin ); } void rtems_filesystem_eval_path_next_token( rtems_filesystem_eval_path_context_t *ctx ) { - rtems_filesystem_eval_path_eat_delimiter(ctx); - next_token(ctx); + rtems_filesystem_eval_path_eat_delimiter( ctx ); + next_token( ctx ); } diff --git a/cpukit/libcsupport/src/symlink.c b/cpukit/libcsupport/src/symlink.c index e0ad0af33a..5294e860ad 100644 --- a/cpukit/libcsupport/src/symlink.c +++ b/cpukit/libcsupport/src/symlink.c @@ -43,15 +43,14 @@ int symlink( const char *path1, const char *path2 ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK - | RTEMS_FS_MAKE - | RTEMS_FS_EXCLUSIVE; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start( &ctx, path2, eval_flags ); + int eval_flags = RTEMS_FS_FOLLOW_HARD_LINK | RTEMS_FS_MAKE | + RTEMS_FS_EXCLUSIVE; + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start( &ctx, path2, eval_flags ); - rv = (*currentloc->mt_entry->ops->symlink_h)( + rv = ( *currentloc->mt_entry->ops->symlink_h )( currentloc, rtems_filesystem_eval_path_get_token( &ctx ), rtems_filesystem_eval_path_get_tokenlen( &ctx ), diff --git a/cpukit/libcsupport/src/tcdrain.c b/cpukit/libcsupport/src/tcdrain.c index 2b947819c2..0f113d0bb9 100644 --- a/cpukit/libcsupport/src/tcdrain.c +++ b/cpukit/libcsupport/src/tcdrain.c @@ -38,7 +38,7 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -51,9 +51,7 @@ /** * POSIX 1003.1b 7.2.2 - Line Control Functions */ -int tcdrain( - int fd -) +int tcdrain( int fd ) { return ioctl( fd, TIOCDRAIN, 0 ); } diff --git a/cpukit/libcsupport/src/tcflow.c b/cpukit/libcsupport/src/tcflow.c index cda9b042e0..d051a1fac6 100644 --- a/cpukit/libcsupport/src/tcflow.c +++ b/cpukit/libcsupport/src/tcflow.c @@ -37,20 +37,17 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include #include #include -int tcflow ( - int fd, - int action -) +int tcflow( int fd, int action ) { (void) fd; - switch (action) { + switch ( action ) { case TCOOFF: case TCOON: case TCIOFF: diff --git a/cpukit/libcsupport/src/tcflush.c b/cpukit/libcsupport/src/tcflush.c index bc44a8fee8..2552c05c50 100644 --- a/cpukit/libcsupport/src/tcflush.c +++ b/cpukit/libcsupport/src/tcflush.c @@ -47,18 +47,18 @@ int tcflush( int fd, int which ) { int com; - switch (which) { - case TCIFLUSH: - com = FREAD; - break; - case TCOFLUSH: - com = FWRITE; - break; - case TCIOFLUSH: - com = FREAD | FWRITE; - break; - default: - rtems_set_errno_and_return_minus_one( EINVAL ); + switch ( which ) { + case TCIFLUSH: + com = FREAD; + break; + case TCOFLUSH: + com = FWRITE; + break; + case TCIOFLUSH: + com = FREAD | FWRITE; + break; + default: + rtems_set_errno_and_return_minus_one( EINVAL ); } return ioctl( fd, TIOCFLUSH, &com ); } diff --git a/cpukit/libcsupport/src/tcgetattr.c b/cpukit/libcsupport/src/tcgetattr.c index 730e60e6a1..c17e57b904 100644 --- a/cpukit/libcsupport/src/tcgetattr.c +++ b/cpukit/libcsupport/src/tcgetattr.c @@ -38,7 +38,7 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -48,10 +48,7 @@ #include -int tcgetattr( - int fd, - struct termios *tp -) +int tcgetattr( int fd, struct termios *tp ) { return ioctl( fd, TIOCGETA, tp ); } diff --git a/cpukit/libcsupport/src/tcgetpgrp.c b/cpukit/libcsupport/src/tcgetpgrp.c index b6a1213395..b1cbf08d33 100644 --- a/cpukit/libcsupport/src/tcgetpgrp.c +++ b/cpukit/libcsupport/src/tcgetpgrp.c @@ -37,7 +37,7 @@ #include "config.h" #endif -#if defined(RTEMS_NEWLIB) && !defined(HAVE_TCGETPGRP) +#if defined( RTEMS_NEWLIB ) && !defined( HAVE_TCGETPGRP ) #include #include @@ -45,7 +45,7 @@ /** * POSIX 1003.1b 7.2.3 - Get Foreground Process Group ID */ -pid_t tcgetpgrp(int fd) +pid_t tcgetpgrp( int fd ) { (void) fd; return getpid(); diff --git a/cpukit/libcsupport/src/tcsendbreak.c b/cpukit/libcsupport/src/tcsendbreak.c index 4a8aa7ded6..d4c6dd7b8c 100644 --- a/cpukit/libcsupport/src/tcsendbreak.c +++ b/cpukit/libcsupport/src/tcsendbreak.c @@ -38,7 +38,7 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -48,9 +48,7 @@ #include -int tcsendbreak ( - int fd RTEMS_UNUSED, - int duration RTEMS_UNUSED ) +int tcsendbreak( int fd RTEMS_UNUSED, int duration RTEMS_UNUSED ) { return 0; } diff --git a/cpukit/libcsupport/src/tcsetattr.c b/cpukit/libcsupport/src/tcsetattr.c index da931e6a34..a5cce1e3a0 100644 --- a/cpukit/libcsupport/src/tcsetattr.c +++ b/cpukit/libcsupport/src/tcsetattr.c @@ -38,7 +38,7 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -53,33 +53,28 @@ /** * POSIX 1003.1b 7.2.1 - Get and Set State */ -int tcsetattr( - int fd, - int opt, - const struct termios *tp -) +int tcsetattr( int fd, int opt, const struct termios *tp ) { struct termios localterm; - if (opt & TCSASOFT) { + if ( opt & TCSASOFT ) { localterm = *tp; localterm.c_cflag |= CIGNORE; tp = &localterm; } - switch (opt & ~TCSASOFT) { + switch ( opt & ~TCSASOFT ) { + case TCSANOW: + return ioctl( fd, TIOCSETA, tp ); - case TCSANOW: - return ioctl( fd, TIOCSETA, tp ); + case TCSADRAIN: + return ioctl( fd, TIOCSETAW, tp ); - case TCSADRAIN: - return ioctl( fd, TIOCSETAW, tp ); + case TCSAFLUSH: + return ioctl( fd, TIOCSETAF, tp ); - case TCSAFLUSH: - return ioctl( fd, TIOCSETAF, tp ); - - default: - rtems_set_errno_and_return_minus_one( EINVAL ); + default: + rtems_set_errno_and_return_minus_one( EINVAL ); } } #endif diff --git a/cpukit/libcsupport/src/tcsetpgrp.c b/cpukit/libcsupport/src/tcsetpgrp.c index b7ee951395..dc5ae33e39 100644 --- a/cpukit/libcsupport/src/tcsetpgrp.c +++ b/cpukit/libcsupport/src/tcsetpgrp.c @@ -38,7 +38,7 @@ #endif #include -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include #include @@ -51,9 +51,7 @@ /** * POSIX 1003.1b 7.2.4 - Set Foreground Process Group ID */ -int tcsetpgrp( - int fd RTEMS_UNUSED, - pid_t pid RTEMS_UNUSED ) +int tcsetpgrp( int fd RTEMS_UNUSED, pid_t pid RTEMS_UNUSED ) { return 0; } diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c index b1fe2d2c8a..b21f8f2449 100644 --- a/cpukit/libcsupport/src/termios.c +++ b/cpukit/libcsupport/src/termios.c @@ -37,49 +37,46 @@ /* * The size of the cooked buffer */ -#define CBUFSIZE (rtems_termios_cbufsize) +#define CBUFSIZE ( rtems_termios_cbufsize ) /* * The sizes of the raw message buffers. * On most architectures it is quite a bit more * efficient if these are powers of two. */ -#define RAW_INPUT_BUFFER_SIZE (rtems_termios_raw_input_size) -#define RAW_OUTPUT_BUFFER_SIZE (rtems_termios_raw_output_size) +#define RAW_INPUT_BUFFER_SIZE ( rtems_termios_raw_input_size ) +#define RAW_OUTPUT_BUFFER_SIZE ( rtems_termios_raw_output_size ) /* fields for "flow_ctrl" status */ -#define FL_IREQXOF 1U /* input queue requests stop of incoming data */ -#define FL_ISNTXOF 2U /* XOFF has been sent to other side of line */ -#define FL_IRTSOFF 4U /* RTS has been turned off for other side.. */ +#define FL_IREQXOF 1U /* input queue requests stop of incoming data */ +#define FL_ISNTXOF 2U /* XOFF has been sent to other side of line */ +#define FL_IRTSOFF 4U /* RTS has been turned off for other side.. */ -#define FL_ORCVXOF 0x10U /* XOFF has been received */ -#define FL_OSTOP 0x20U /* output has been stopped due to XOFF */ +#define FL_ORCVXOF 0x10U /* XOFF has been received */ +#define FL_OSTOP 0x20U /* output has been stopped due to XOFF */ -#define FL_MDRTS 0x100U /* input controlled with RTS/CTS handshake */ -#define FL_MDXON 0x200U /* input controlled with XON/XOFF protocol */ -#define FL_MDXOF 0x400U /* output controlled with XON/XOFF protocol */ +#define FL_MDRTS 0x100U /* input controlled with RTS/CTS handshake */ +#define FL_MDXON 0x200U /* input controlled with XON/XOFF protocol */ +#define FL_MDXOF 0x400U /* output controlled with XON/XOFF protocol */ -#define NODISC(n) \ - { NULL, NULL, NULL, NULL, \ - NULL, NULL, NULL, NULL } +#define NODISC( n ) { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } /* * FIXME: change rtems_termios_linesw entries consistent * with rtems_termios_linesw entry usage... */ -struct rtems_termios_linesw rtems_termios_linesw[MAXLDISC] = -{ - NODISC(0), /* 0- termios-built-in */ - NODISC(1), /* 1- defunct */ - NODISC(2), /* 2- NTTYDISC */ - NODISC(3), /* TABLDISC */ - NODISC(4), /* SLIPDISC */ - NODISC(5), /* PPPDISC */ - NODISC(6), /* loadable */ - NODISC(7), /* loadable */ +struct rtems_termios_linesw rtems_termios_linesw[ MAXLDISC ] = { + NODISC( 0 ), /* 0- termios-built-in */ + NODISC( 1 ), /* 1- defunct */ + NODISC( 2 ), /* 2- NTTYDISC */ + NODISC( 3 ), /* TABLDISC */ + NODISC( 4 ), /* SLIPDISC */ + NODISC( 5 ), /* PPPDISC */ + NODISC( 6 ), /* loadable */ + NODISC( 7 ), /* loadable */ }; -int rtems_termios_nlinesw = - sizeof (rtems_termios_linesw) / sizeof (rtems_termios_linesw[0]); +int rtems_termios_nlinesw = sizeof( rtems_termios_linesw ) / + sizeof( rtems_termios_linesw[ 0 ] ); static size_t rtems_termios_cbufsize = 256; static size_t rtems_termios_raw_input_size = 256; @@ -90,15 +87,15 @@ static const IMFS_node_control rtems_termios_imfs_node_control; static struct rtems_termios_tty *rtems_termios_ttyHead; static struct rtems_termios_tty *rtems_termios_ttyTail; -static RTEMS_CHAIN_DEFINE_EMPTY(rtems_termios_devices); +static RTEMS_CHAIN_DEFINE_EMPTY( rtems_termios_devices ); -static rtems_task rtems_termios_rxdaemon(rtems_task_argument argument); -static rtems_task rtems_termios_txdaemon(rtems_task_argument argument); +static rtems_task rtems_termios_rxdaemon( rtems_task_argument argument ); +static rtems_task rtems_termios_txdaemon( rtems_task_argument argument ); /* * some constants for I/O daemon task creation */ -#define TERMIOS_TXTASK_PRIO 10 -#define TERMIOS_RXTASK_PRIO 9 +#define TERMIOS_TXTASK_PRIO 10 +#define TERMIOS_RXTASK_PRIO 9 #define TERMIOS_TXTASK_STACKSIZE 1024 #define TERMIOS_RXTASK_STACKSIZE 1024 /* @@ -110,19 +107,18 @@ static rtems_task rtems_termios_txdaemon(rtems_task_argument argument); #define TERMIOS_RX_PROC_EVENT RTEMS_EVENT_1 #define TERMIOS_RX_TERMINATE_EVENT RTEMS_EVENT_0 -static rtems_mutex rtems_termios_ttyMutex = - RTEMS_MUTEX_INITIALIZER( "termios" ); +static rtems_mutex rtems_termios_ttyMutex = RTEMS_MUTEX_INITIALIZER( + "termios" +); -static void -rtems_termios_obtain (void) +static void rtems_termios_obtain( void ) { - rtems_mutex_lock (&rtems_termios_ttyMutex); + rtems_mutex_lock( &rtems_termios_ttyMutex ); } -static void -rtems_termios_release (void) +static void rtems_termios_release( void ) { - rtems_mutex_unlock (&rtems_termios_ttyMutex); + rtems_mutex_unlock( &rtems_termios_ttyMutex ); } rtems_status_code rtems_termios_device_install( @@ -133,14 +129,14 @@ rtems_status_code rtems_termios_device_install( ) { rtems_termios_device_node *new_device_node; - int rv; + int rv; - new_device_node = calloc (1, sizeof(*new_device_node)); - if (new_device_node == NULL) { + new_device_node = calloc( 1, sizeof( *new_device_node ) ); + if ( new_device_node == NULL ) { return RTEMS_NO_MEMORY; } - rtems_chain_initialize_node (&new_device_node->node); + rtems_chain_initialize_node( &new_device_node->node ); new_device_node->handler = handler; new_device_node->flow = flow; new_device_node->context = context; @@ -152,22 +148,22 @@ rtems_status_code rtems_termios_device_install( &rtems_termios_imfs_node_control, new_device_node ); - if (rv != 0) { - free (new_device_node); + if ( rv != 0 ) { + free( new_device_node ); return RTEMS_UNSATISFIED; } return RTEMS_SUCCESSFUL; } -static rtems_termios_tty * -legacyContextToTTY (rtems_termios_device_context *ctx) +static rtems_termios_tty *legacyContextToTTY( + rtems_termios_device_context *ctx +) { - return RTEMS_CONTAINER_OF (ctx, rtems_termios_tty, legacy_device_context); + return RTEMS_CONTAINER_OF( ctx, rtems_termios_tty, legacy_device_context ); } -static bool -rtems_termios_callback_firstOpen( +static bool rtems_termios_callback_firstOpen( rtems_termios_tty *tty, rtems_termios_device_context *ctx, struct termios *term, @@ -177,13 +173,12 @@ rtems_termios_callback_firstOpen( (void) ctx; (void) term; - (*tty->device.firstOpen) (tty->major, tty->minor, args); + ( *tty->device.firstOpen )( tty->major, tty->minor, args ); return true; } -static void -rtems_termios_callback_lastClose( +static void rtems_termios_callback_lastClose( rtems_termios_tty *tty, rtems_termios_device_context *ctx, rtems_libio_open_close_args_t *args @@ -191,143 +186,149 @@ rtems_termios_callback_lastClose( { (void) ctx; - (*tty->device.lastClose) (tty->major, tty->minor, args); + ( *tty->device.lastClose )( tty->major, tty->minor, args ); } -static int -rtems_termios_callback_pollRead (rtems_termios_device_context *ctx) +static int rtems_termios_callback_pollRead( rtems_termios_device_context *ctx ) { - rtems_termios_tty *tty = legacyContextToTTY (ctx); + rtems_termios_tty *tty = legacyContextToTTY( ctx ); - return (*tty->device.pollRead) (tty->minor); + return ( *tty->device.pollRead )( tty->minor ); } -static void -rtems_termios_callback_write( +static void rtems_termios_callback_write( rtems_termios_device_context *ctx, const char *buf, size_t len ) { - rtems_termios_tty *tty = legacyContextToTTY (ctx); + rtems_termios_tty *tty = legacyContextToTTY( ctx ); - (*tty->device.write) (tty->minor, buf, len); + ( *tty->device.write )( tty->minor, buf, len ); } -static bool -rtems_termios_callback_setAttributes( +static bool rtems_termios_callback_setAttributes( rtems_termios_device_context *ctx, const struct termios *term ) { - rtems_termios_tty *tty = legacyContextToTTY (ctx); + rtems_termios_tty *tty = legacyContextToTTY( ctx ); - (*tty->device.setAttributes) (tty->minor, term); + ( *tty->device.setAttributes )( tty->minor, term ); return true; } -static void -rtems_termios_callback_stopRemoteTx (rtems_termios_device_context *ctx) +static void rtems_termios_callback_stopRemoteTx( + rtems_termios_device_context *ctx +) { - rtems_termios_tty *tty = legacyContextToTTY (ctx); + rtems_termios_tty *tty = legacyContextToTTY( ctx ); - (*tty->device.stopRemoteTx) (tty->minor); + ( *tty->device.stopRemoteTx )( tty->minor ); } -static void -rtems_termios_callback_startRemoteTx (rtems_termios_device_context *ctx) +static void rtems_termios_callback_startRemoteTx( + rtems_termios_device_context *ctx +) { - rtems_termios_tty *tty = legacyContextToTTY (ctx); + rtems_termios_tty *tty = legacyContextToTTY( ctx ); - (*tty->device.startRemoteTx) (tty->minor); + ( *tty->device.startRemoteTx )( tty->minor ); } /* * Drain output queue */ -static void -drainOutput (struct rtems_termios_tty *tty) +static void drainOutput( struct rtems_termios_tty *tty ) { rtems_termios_device_context *ctx = tty->device_context; - rtems_interrupt_lock_context lock_context; + rtems_interrupt_lock_context lock_context; - if (tty->handler.mode != TERMIOS_POLLED) { - rtems_termios_device_lock_acquire (ctx, &lock_context); - while (tty->rawOutBuf.Tail != tty->rawOutBuf.Head) { + if ( tty->handler.mode != TERMIOS_POLLED ) { + rtems_termios_device_lock_acquire( ctx, &lock_context ); + while ( tty->rawOutBuf.Tail != tty->rawOutBuf.Head ) { tty->rawOutBufState = rob_wait; - rtems_termios_device_lock_release (ctx, &lock_context); - rtems_binary_semaphore_wait (&tty->rawOutBuf.Semaphore); - rtems_termios_device_lock_acquire (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); + rtems_binary_semaphore_wait( &tty->rawOutBuf.Semaphore ); + rtems_termios_device_lock_acquire( ctx, &lock_context ); } - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); } } -static bool -needDeviceMutex (rtems_termios_tty *tty) +static bool needDeviceMutex( rtems_termios_tty *tty ) { - return tty->handler.mode == TERMIOS_IRQ_SERVER_DRIVEN - || tty->handler.mode == TERMIOS_TASK_DRIVEN; + return tty->handler.mode == TERMIOS_IRQ_SERVER_DRIVEN || + tty->handler.mode == TERMIOS_TASK_DRIVEN; } -static void -rtems_termios_destroy_tty (rtems_termios_tty *tty, void *arg, bool last_close) +static void rtems_termios_destroy_tty( + rtems_termios_tty *tty, + void *arg, + bool last_close +) { - if (rtems_termios_linesw[tty->t_line].l_close != NULL) { + if ( rtems_termios_linesw[ tty->t_line ].l_close != NULL ) { /* * call discipline-specific close */ - (void) rtems_termios_linesw[tty->t_line].l_close(tty); - } else if (last_close) { + (void) rtems_termios_linesw[ tty->t_line ].l_close( tty ); + } else if ( last_close ) { /* * default: just flush output buffer */ - rtems_mutex_lock (&tty->osem); - drainOutput (tty); - rtems_mutex_unlock (&tty->osem); + rtems_mutex_lock( &tty->osem ); + drainOutput( tty ); + rtems_mutex_unlock( &tty->osem ); } - if (tty->handler.mode == TERMIOS_TASK_DRIVEN) { + if ( tty->handler.mode == TERMIOS_TASK_DRIVEN ) { rtems_status_code sc; /* * send "terminate" to I/O tasks */ sc = rtems_event_send( tty->rxTaskId, TERMIOS_RX_TERMINATE_EVENT ); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); + if ( sc != RTEMS_SUCCESSFUL ) { + rtems_fatal_error_occurred( sc ); + } sc = rtems_event_send( tty->txTaskId, TERMIOS_TX_TERMINATE_EVENT ); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); + if ( sc != RTEMS_SUCCESSFUL ) { + rtems_fatal_error_occurred( sc ); + } + } + if ( last_close && tty->handler.last_close ) { + ( *tty->handler.last_close )( tty, tty->device_context, arg ); } - if (last_close && tty->handler.last_close) - (*tty->handler.last_close)(tty, tty->device_context, arg); - if (tty->device_node != NULL) + if ( tty->device_node != NULL ) { tty->device_node->tty = NULL; - - rtems_mutex_destroy (&tty->isem); - rtems_mutex_destroy (&tty->osem); - rtems_binary_semaphore_destroy (&tty->rawOutBuf.Semaphore); - if ((tty->handler.poll_read == NULL) || - (tty->handler.mode == TERMIOS_TASK_DRIVEN)) - rtems_binary_semaphore_destroy (&tty->rawInBuf.Semaphore); - - if (needDeviceMutex (tty)) { - rtems_mutex_destroy (&tty->device_context->lock.mutex); - } else if (tty->device_context == &tty->legacy_device_context) { - rtems_interrupt_lock_destroy (&tty->legacy_device_context.lock.interrupt); } - free (tty->rawInBuf.theBuf); - free (tty->rawOutBuf.theBuf); - free (tty->cbuf); - free (tty); + rtems_mutex_destroy( &tty->isem ); + rtems_mutex_destroy( &tty->osem ); + rtems_binary_semaphore_destroy( &tty->rawOutBuf.Semaphore ); + if ( + ( tty->handler.poll_read == NULL ) || + ( tty->handler.mode == TERMIOS_TASK_DRIVEN ) + ) { + rtems_binary_semaphore_destroy( &tty->rawInBuf.Semaphore ); + } + + if ( needDeviceMutex( tty ) ) { + rtems_mutex_destroy( &tty->device_context->lock.mutex ); + } else if ( tty->device_context == &tty->legacy_device_context ) { + rtems_interrupt_lock_destroy( &tty->legacy_device_context.lock.interrupt ); + } + + free( tty->rawInBuf.theBuf ); + free( tty->rawOutBuf.theBuf ); + free( tty->cbuf ); + free( tty ); } -static void -deviceAcquireMutex( +static void deviceAcquireMutex( rtems_termios_device_context *ctx, rtems_interrupt_lock_context *lock_context ) @@ -335,22 +336,20 @@ deviceAcquireMutex( (void) ctx; (void) lock_context; - rtems_mutex_lock (&ctx->lock.mutex); + rtems_mutex_lock( &ctx->lock.mutex ); } -static void -deviceReleaseMutex( +static void deviceReleaseMutex( rtems_termios_device_context *ctx, rtems_interrupt_lock_context *lock_context ) { (void) lock_context; - rtems_mutex_unlock (&ctx->lock.mutex); + rtems_mutex_unlock( &ctx->lock.mutex ); } -static rtems_termios_tty * -rtems_termios_open_tty( +static rtems_termios_tty *rtems_termios_open_tty( rtems_device_major_number major, rtems_device_minor_number minor, rtems_libio_open_close_args_t *args, @@ -359,44 +358,44 @@ rtems_termios_open_tty( const rtems_termios_callbacks *callbacks ) { - if (tty == NULL) { - static char c = 'a'; + if ( tty == NULL ) { + static char c = 'a'; rtems_termios_device_context *ctx; /* * Create a new device */ - tty = calloc (1, sizeof (struct rtems_termios_tty)); - if (tty == NULL) { + tty = calloc( 1, sizeof( struct rtems_termios_tty ) ); + if ( tty == NULL ) { return NULL; } /* * allocate raw input buffer */ tty->rawInBuf.Size = RAW_INPUT_BUFFER_SIZE; - tty->rawInBuf.theBuf = malloc (tty->rawInBuf.Size); - if (tty->rawInBuf.theBuf == NULL) { - free(tty); + tty->rawInBuf.theBuf = malloc( tty->rawInBuf.Size ); + if ( tty->rawInBuf.theBuf == NULL ) { + free( tty ); return NULL; } /* * allocate raw output buffer */ tty->rawOutBuf.Size = RAW_OUTPUT_BUFFER_SIZE; - tty->rawOutBuf.theBuf = malloc (tty->rawOutBuf.Size); - if (tty->rawOutBuf.theBuf == NULL) { - free((void *)(tty->rawInBuf.theBuf)); - free(tty); + tty->rawOutBuf.theBuf = malloc( tty->rawOutBuf.Size ); + if ( tty->rawOutBuf.theBuf == NULL ) { + free( (void *) ( tty->rawInBuf.theBuf ) ); + free( tty ); return NULL; } /* * allocate cooked buffer */ - tty->cbuf = malloc (CBUFSIZE); - if (tty->cbuf == NULL) { - free((void *)(tty->rawOutBuf.theBuf)); - free((void *)(tty->rawInBuf.theBuf)); - free(tty); + tty->cbuf = malloc( CBUFSIZE ); + if ( tty->cbuf == NULL ) { + free( (void *) ( tty->rawOutBuf.theBuf ) ); + free( (void *) ( tty->rawInBuf.theBuf ) ); + free( tty ); return NULL; } /* @@ -406,7 +405,7 @@ rtems_termios_open_tty( tty->tty_snd.sw_arg = NULL; tty->tty_rcv.sw_pfn = NULL; tty->tty_rcv.sw_arg = NULL; - tty->tty_rcvwakeup = false; + tty->tty_rcvwakeup = false; tty->minor = minor; tty->major = major; @@ -414,56 +413,68 @@ rtems_termios_open_tty( /* * Set up mutex semaphores */ - rtems_mutex_init (&tty->isem, "termios input"); - rtems_mutex_init (&tty->osem, "termios output"); - rtems_binary_semaphore_init (&tty->rawOutBuf.Semaphore, - "termios raw output"); + rtems_mutex_init( &tty->isem, "termios input" ); + rtems_mutex_init( &tty->osem, "termios output" ); + rtems_binary_semaphore_init( + &tty->rawOutBuf.Semaphore, + "termios raw output" + ); tty->rawOutBufState = rob_idle; /* * Set callbacks */ - if (device_node != NULL) { + if ( device_node != NULL ) { device_node->tty = tty; tty->handler = *device_node->handler; - if (device_node->flow != NULL) { + if ( device_node->flow != NULL ) { tty->flow = *device_node->flow; } tty->device_node = device_node; tty->device_context = device_node->context; - memset(&tty->device, 0, sizeof(tty->device)); + memset( &tty->device, 0, sizeof( tty->device ) ); } else { - tty->handler.first_open = callbacks->firstOpen != NULL ? - rtems_termios_callback_firstOpen : NULL; - tty->handler.last_close = callbacks->lastClose != NULL ? - rtems_termios_callback_lastClose : NULL; - tty->handler.poll_read = callbacks->pollRead != NULL ? - rtems_termios_callback_pollRead : NULL; - tty->handler.write = callbacks->write != NULL ? - rtems_termios_callback_write : NULL; - tty->handler.set_attributes = callbacks->setAttributes != NULL ? - rtems_termios_callback_setAttributes : NULL; - tty->flow.stop_remote_tx = callbacks->stopRemoteTx != NULL ? - rtems_termios_callback_stopRemoteTx : NULL; - tty->flow.start_remote_tx = callbacks->startRemoteTx != NULL ? - rtems_termios_callback_startRemoteTx : NULL; + tty->handler.first_open = callbacks->firstOpen != NULL + ? rtems_termios_callback_firstOpen + : NULL; + tty->handler.last_close = callbacks->lastClose != NULL + ? rtems_termios_callback_lastClose + : NULL; + tty->handler.poll_read = callbacks->pollRead != NULL + ? rtems_termios_callback_pollRead + : NULL; + tty->handler.write = callbacks->write != NULL + ? rtems_termios_callback_write + : NULL; + tty->handler.set_attributes = callbacks->setAttributes != NULL + ? rtems_termios_callback_setAttributes + : NULL; + tty->flow.stop_remote_tx = callbacks->stopRemoteTx != NULL + ? rtems_termios_callback_stopRemoteTx + : NULL; + tty->flow.start_remote_tx = callbacks->startRemoteTx != NULL + ? rtems_termios_callback_startRemoteTx + : NULL; tty->handler.mode = callbacks->outputUsesInterrupts; tty->device_context = NULL; tty->device_node = NULL; tty->device = *callbacks; } - if (tty->device_context == NULL) { + if ( tty->device_context == NULL ) { tty->device_context = &tty->legacy_device_context; - rtems_termios_device_context_initialize (tty->device_context, "Termios"); + rtems_termios_device_context_initialize( + tty->device_context, + "Termios" + ); } ctx = tty->device_context; - if (needDeviceMutex (tty)) { - rtems_mutex_init (&ctx->lock.mutex, "termios device"); + if ( needDeviceMutex( tty ) ) { + rtems_mutex_init( &ctx->lock.mutex, "termios device" ); ctx->lock_acquire = deviceAcquireMutex; ctx->lock_release = deviceReleaseMutex; } else { @@ -474,35 +485,40 @@ rtems_termios_open_tty( /* * Create I/O tasks */ - if (tty->handler.mode == TERMIOS_TASK_DRIVEN) { + if ( tty->handler.mode == TERMIOS_TASK_DRIVEN ) { rtems_status_code sc; - sc = rtems_task_create ( - rtems_build_name ('T', 'x', 'T', c), - TERMIOS_TXTASK_PRIO, - TERMIOS_TXTASK_STACKSIZE, - RTEMS_NO_PREEMPT | RTEMS_NO_TIMESLICE | - RTEMS_NO_ASR, - RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, - &tty->txTaskId); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); - sc = rtems_task_create ( - rtems_build_name ('R', 'x', 'T', c), - TERMIOS_RXTASK_PRIO, - TERMIOS_RXTASK_STACKSIZE, - RTEMS_NO_PREEMPT | RTEMS_NO_TIMESLICE | - RTEMS_NO_ASR, - RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, - &tty->rxTaskId); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); - + sc = rtems_task_create( + rtems_build_name( 'T', 'x', 'T', c ), + TERMIOS_TXTASK_PRIO, + TERMIOS_TXTASK_STACKSIZE, + RTEMS_NO_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR, + RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, + &tty->txTaskId + ); + if ( sc != RTEMS_SUCCESSFUL ) { + rtems_fatal_error_occurred( sc ); + } + sc = rtems_task_create( + rtems_build_name( 'R', 'x', 'T', c ), + TERMIOS_RXTASK_PRIO, + TERMIOS_RXTASK_STACKSIZE, + RTEMS_NO_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR, + RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL, + &tty->rxTaskId + ); + if ( sc != RTEMS_SUCCESSFUL ) { + rtems_fatal_error_occurred( sc ); + } } - if ((tty->handler.poll_read == NULL) || - (tty->handler.mode == TERMIOS_TASK_DRIVEN)){ - rtems_binary_semaphore_init (&tty->rawInBuf.Semaphore, - "termios raw input"); + if ( + ( tty->handler.poll_read == NULL ) || + ( tty->handler.mode == TERMIOS_TASK_DRIVEN ) + ) { + rtems_binary_semaphore_init( + &tty->rawInBuf.Semaphore, + "termios raw input" + ); } /* @@ -511,64 +527,78 @@ rtems_termios_open_tty( tty->termios.c_iflag = BRKINT | ICRNL | IXON | IMAXBEL; tty->termios.c_oflag = OPOST | ONLCR | OXTABS; tty->termios.c_cflag = CS8 | CREAD | CLOCAL; - tty->termios.c_lflag = - ISIG | ICANON | IEXTEN | ECHO | ECHOK | ECHOE | ECHOCTL; + tty->termios.c_lflag = ISIG | ICANON | IEXTEN | ECHO | ECHOK | ECHOE | + ECHOCTL; tty->termios.c_ispeed = B9600; tty->termios.c_ospeed = B9600; - tty->termios.c_cc[VINTR] = '\003'; - tty->termios.c_cc[VQUIT] = '\034'; - tty->termios.c_cc[VERASE] = '\177'; - tty->termios.c_cc[VKILL] = '\025'; - tty->termios.c_cc[VEOF] = '\004'; - tty->termios.c_cc[VEOL] = '\000'; - tty->termios.c_cc[VEOL2] = '\000'; - tty->termios.c_cc[VSTART] = '\021'; - tty->termios.c_cc[VSTOP] = '\023'; - tty->termios.c_cc[VSUSP] = '\032'; - tty->termios.c_cc[VREPRINT] = '\022'; - tty->termios.c_cc[VDISCARD] = '\017'; - tty->termios.c_cc[VWERASE] = '\027'; - tty->termios.c_cc[VLNEXT] = '\026'; + tty->termios.c_cc[ VINTR ] = '\003'; + tty->termios.c_cc[ VQUIT ] = '\034'; + tty->termios.c_cc[ VERASE ] = '\177'; + tty->termios.c_cc[ VKILL ] = '\025'; + tty->termios.c_cc[ VEOF ] = '\004'; + tty->termios.c_cc[ VEOL ] = '\000'; + tty->termios.c_cc[ VEOL2 ] = '\000'; + tty->termios.c_cc[ VSTART ] = '\021'; + tty->termios.c_cc[ VSTOP ] = '\023'; + tty->termios.c_cc[ VSUSP ] = '\032'; + tty->termios.c_cc[ VREPRINT ] = '\022'; + tty->termios.c_cc[ VDISCARD ] = '\017'; + tty->termios.c_cc[ VWERASE ] = '\027'; + tty->termios.c_cc[ VLNEXT ] = '\026'; /* start with no flow control, clear flow control flags */ tty->flow_ctrl = 0; /* * set low/highwater mark for XON/XOFF support */ - tty->lowwater = tty->rawInBuf.Size * 1/2; - tty->highwater = tty->rawInBuf.Size * 3/4; + tty->lowwater = tty->rawInBuf.Size * 1 / 2; + tty->highwater = tty->rawInBuf.Size * 3 / 4; /* * Bump name characer */ - if (c++ == 'z') + if ( c++ == 'z' ) { c = 'a'; - + } } args->iop->data1 = tty; - if (!tty->refcount++) { - if (tty->handler.first_open && !(*tty->handler.first_open)( - tty, tty->device_context, &tty->termios, args)) { - rtems_termios_destroy_tty(tty, args, false); + if ( !tty->refcount++ ) { + if ( + tty->handler.first_open && !( *tty->handler.first_open )( + tty, + tty->device_context, + &tty->termios, + args + ) + ) { + rtems_termios_destroy_tty( tty, args, false ); return NULL; } /* * start I/O tasks, if needed */ - if (tty->handler.mode == TERMIOS_TASK_DRIVEN) { + if ( tty->handler.mode == TERMIOS_TASK_DRIVEN ) { rtems_status_code sc; sc = rtems_task_start( - tty->rxTaskId, rtems_termios_rxdaemon, (rtems_task_argument)tty); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); + tty->rxTaskId, + rtems_termios_rxdaemon, + (rtems_task_argument) tty + ); + if ( sc != RTEMS_SUCCESSFUL ) { + rtems_fatal_error_occurred( sc ); + } sc = rtems_task_start( - tty->txTaskId, rtems_termios_txdaemon, (rtems_task_argument)tty); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); + tty->txTaskId, + rtems_termios_txdaemon, + (rtems_task_argument) tty + ); + if ( sc != RTEMS_SUCCESSFUL ) { + rtems_fatal_error_occurred( sc ); + } } } @@ -578,8 +608,7 @@ rtems_termios_open_tty( /* * Open a termios device */ -rtems_status_code -rtems_termios_open ( +rtems_status_code rtems_termios_open( rtems_device_major_number major, rtems_device_minor_number minor, void *arg, @@ -591,81 +620,79 @@ rtems_termios_open ( /* * See if the device has already been opened */ - rtems_termios_obtain (); + rtems_termios_obtain(); - for (tty = rtems_termios_ttyHead ; tty != NULL ; tty = tty->forw) { - if ((tty->major == major) && (tty->minor == minor)) + for ( tty = rtems_termios_ttyHead; tty != NULL; tty = tty->forw ) { + if ( ( tty->major == major ) && ( tty->minor == minor ) ) { break; + } } - tty = rtems_termios_open_tty( - major, minor, arg, tty, NULL, callbacks); - if (tty == NULL) { - rtems_termios_release (); + tty = rtems_termios_open_tty( major, minor, arg, tty, NULL, callbacks ); + if ( tty == NULL ) { + rtems_termios_release(); return RTEMS_NO_MEMORY; } - if (tty->refcount == 1) { + if ( tty->refcount == 1 ) { /* * link tty */ tty->forw = rtems_termios_ttyHead; tty->back = NULL; - if (rtems_termios_ttyHead != NULL) + if ( rtems_termios_ttyHead != NULL ) { rtems_termios_ttyHead->back = tty; + } rtems_termios_ttyHead = tty; - if (rtems_termios_ttyTail == NULL) + if ( rtems_termios_ttyTail == NULL ) { rtems_termios_ttyTail = tty; + } } - rtems_termios_release (); + rtems_termios_release(); return RTEMS_SUCCESSFUL; } -static void -flushOutput (struct rtems_termios_tty *tty) +static void flushOutput( struct rtems_termios_tty *tty ) { rtems_termios_device_context *ctx = tty->device_context; - rtems_interrupt_lock_context lock_context; + rtems_interrupt_lock_context lock_context; - rtems_termios_device_lock_acquire (ctx, &lock_context); + rtems_termios_device_lock_acquire( ctx, &lock_context ); tty->rawOutBuf.Tail = 0; tty->rawOutBuf.Head = 0; tty->rawOutBufState = rob_idle; - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); } -static void -flushInput (struct rtems_termios_tty *tty) +static void flushInput( struct rtems_termios_tty *tty ) { rtems_termios_device_context *ctx = tty->device_context; - rtems_interrupt_lock_context lock_context; + rtems_interrupt_lock_context lock_context; - rtems_termios_device_lock_acquire (ctx, &lock_context); + rtems_termios_device_lock_acquire( ctx, &lock_context ); tty->rawInBuf.Tail = 0; tty->rawInBuf.Head = 0; - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); } -static void -rtems_termios_close_tty (rtems_termios_tty *tty, void *arg) +static void rtems_termios_close_tty( rtems_termios_tty *tty, void *arg ) { - if (--tty->refcount == 0) { - rtems_termios_destroy_tty (tty, arg, true); + if ( --tty->refcount == 0 ) { + rtems_termios_destroy_tty( tty, arg, true ); } } -rtems_status_code -rtems_termios_close (void *arg) +rtems_status_code rtems_termios_close( void *arg ) { rtems_libio_open_close_args_t *args = arg; - struct rtems_termios_tty *tty = args->iop->data1; + struct rtems_termios_tty *tty = args->iop->data1; - rtems_termios_obtain (); + rtems_termios_obtain(); - if (tty->refcount == 1) { - if (tty->forw == NULL) { + if ( tty->refcount == 1 ) { + if ( tty->forw == NULL ) { rtems_termios_ttyTail = tty->back; if ( rtems_termios_ttyTail != NULL ) { rtems_termios_ttyTail->forw = NULL; @@ -674,7 +701,7 @@ rtems_termios_close (void *arg) tty->forw->back = tty->back; } - if (tty->back == NULL) { + if ( tty->back == NULL ) { rtems_termios_ttyHead = tty->forw; if ( rtems_termios_ttyHead != NULL ) { rtems_termios_ttyHead->back = NULL; @@ -684,243 +711,253 @@ rtems_termios_close (void *arg) } } - rtems_termios_close_tty (tty, arg); + rtems_termios_close_tty( tty, arg ); - rtems_termios_release (); + rtems_termios_release(); return RTEMS_SUCCESSFUL; } -rtems_status_code rtems_termios_bufsize ( +rtems_status_code rtems_termios_bufsize( size_t cbufsize, size_t raw_input, size_t raw_output ) { - rtems_termios_cbufsize = cbufsize; - rtems_termios_raw_input_size = raw_input; + rtems_termios_cbufsize = cbufsize; + rtems_termios_raw_input_size = raw_input; rtems_termios_raw_output_size = raw_output; return RTEMS_SUCCESSFUL; } -static void -termios_set_flowctrl(struct rtems_termios_tty *tty) +static void termios_set_flowctrl( struct rtems_termios_tty *tty ) { rtems_termios_device_context *ctx = tty->device_context; - rtems_interrupt_lock_context lock_context; + rtems_interrupt_lock_context lock_context; /* * check for flow control options to be switched off */ /* check for outgoing XON/XOFF flow control switched off */ - if (( tty->flow_ctrl & FL_MDXON) && - !(tty->termios.c_iflag & IXON)) { + if ( ( tty->flow_ctrl & FL_MDXON ) && !( tty->termios.c_iflag & IXON ) ) { /* clear related flags in flow_ctrl */ - tty->flow_ctrl &= ~(FL_MDXON | FL_ORCVXOF); + tty->flow_ctrl &= ~( FL_MDXON | FL_ORCVXOF ); /* has output been stopped due to received XOFF? */ - if (tty->flow_ctrl & FL_OSTOP) { + if ( tty->flow_ctrl & FL_OSTOP ) { /* disable interrupts */ - rtems_termios_device_lock_acquire (ctx, &lock_context); + rtems_termios_device_lock_acquire( ctx, &lock_context ); tty->flow_ctrl &= ~FL_OSTOP; /* check for chars in output buffer (or rob_state?) */ - if (tty->rawOutBufState != rob_idle) { + if ( tty->rawOutBufState != rob_idle ) { /* if chars available, call write function... */ - (*tty->handler.write)( - ctx, &tty->rawOutBuf.theBuf[tty->rawOutBuf.Tail],1); + ( *tty->handler.write )( + ctx, + &tty->rawOutBuf.theBuf[ tty->rawOutBuf.Tail ], + 1 + ); } /* reenable interrupts */ - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); } } /* check for incoming XON/XOFF flow control switched off */ - if (( tty->flow_ctrl & FL_MDXOF) && !(tty->termios.c_iflag & IXOFF)) { + if ( ( tty->flow_ctrl & FL_MDXOF ) && !( tty->termios.c_iflag & IXOFF ) ) { /* clear related flags in flow_ctrl */ - tty->flow_ctrl &= ~(FL_MDXOF); + tty->flow_ctrl &= ~( FL_MDXOF ); /* FIXME: what happens, if we had sent XOFF but not yet XON? */ - tty->flow_ctrl &= ~(FL_ISNTXOF); + tty->flow_ctrl &= ~( FL_ISNTXOF ); } /* check for incoming RTS/CTS flow control switched off */ - if (( tty->flow_ctrl & FL_MDRTS) && !(tty->termios.c_cflag & CRTSCTS)) { + if ( ( tty->flow_ctrl & FL_MDRTS ) && !( tty->termios.c_cflag & CRTSCTS ) ) { /* clear related flags in flow_ctrl */ - tty->flow_ctrl &= ~(FL_MDRTS); + tty->flow_ctrl &= ~( FL_MDRTS ); /* restart remote Tx, if it was stopped */ - if ((tty->flow_ctrl & FL_IRTSOFF) && - (tty->flow.start_remote_tx != NULL)) { - tty->flow.start_remote_tx(ctx); + if ( + ( tty->flow_ctrl & FL_IRTSOFF ) && ( tty->flow.start_remote_tx != NULL ) + ) { + tty->flow.start_remote_tx( ctx ); } - tty->flow_ctrl &= ~(FL_IRTSOFF); + tty->flow_ctrl &= ~( FL_IRTSOFF ); } /* * check for flow control options to be switched on */ /* check for incoming RTS/CTS flow control switched on */ - if (tty->termios.c_cflag & CRTSCTS) { + if ( tty->termios.c_cflag & CRTSCTS ) { tty->flow_ctrl |= FL_MDRTS; } /* check for incoming XON/XOF flow control switched on */ - if (tty->termios.c_iflag & IXOFF) { + if ( tty->termios.c_iflag & IXOFF ) { tty->flow_ctrl |= FL_MDXOF; } /* check for outgoing XON/XOF flow control switched on */ - if (tty->termios.c_iflag & IXON) { + if ( tty->termios.c_iflag & IXON ) { tty->flow_ctrl |= FL_MDXON; } } -rtems_status_code -rtems_termios_ioctl (void *arg) +rtems_status_code rtems_termios_ioctl( void *arg ) { rtems_libio_ioctl_args_t *args = arg; struct rtems_termios_tty *tty = args->iop->data1; - struct ttywakeup *wakeup = (struct ttywakeup *)args->buffer; + struct ttywakeup *wakeup = (struct ttywakeup *) args->buffer; bool rawInBufSemaphoreWait; rtems_interval rawInBufSemaphoreTimeout; rtems_interval rawInBufSemaphoreFirstTimeout; - rtems_status_code sc; - int flags; + rtems_status_code sc; + int flags; sc = RTEMS_SUCCESSFUL; args->ioctl_return = 0; - rtems_mutex_lock (&tty->osem); - switch (args->command) { - default: - if (rtems_termios_linesw[tty->t_line].l_ioctl != NULL) { - sc = rtems_termios_linesw[tty->t_line].l_ioctl(tty,args); - } else if (tty->handler.ioctl) { - args->ioctl_return = (*tty->handler.ioctl) (tty->device_context, - args->command, args->buffer); - sc = RTEMS_SUCCESSFUL; - } else { - sc = RTEMS_INVALID_NUMBER; - } - break; - - case TIOCGETA: - *(struct termios *)args->buffer = tty->termios; - break; - - case TIOCSETA: - case TIOCSETAW: - case TIOCSETAF: - tty->termios = *(struct termios *)args->buffer; - - if (args->command == TIOCSETAW || args->command == TIOCSETAF) { - drainOutput (tty); - if (args->command == TIOCSETAF) { - flushInput (tty); - } - } - /* check for and process change in flow control options */ - termios_set_flowctrl(tty); - - rawInBufSemaphoreWait = tty->rawInBufSemaphoreWait; - rawInBufSemaphoreTimeout = tty->rawInBufSemaphoreTimeout; - rawInBufSemaphoreFirstTimeout = tty->rawInBufSemaphoreFirstTimeout; - - if (tty->termios.c_lflag & ICANON) { - tty->rawInBufSemaphoreWait = true; - tty->rawInBufSemaphoreTimeout = 0; - tty->rawInBufSemaphoreFirstTimeout = 0; - } else { - tty->vtimeTicks = tty->termios.c_cc[VTIME] * - rtems_clock_get_ticks_per_second() / 10; - if (tty->termios.c_cc[VTIME]) { - tty->rawInBufSemaphoreWait = true; - tty->rawInBufSemaphoreTimeout = tty->vtimeTicks; - if (tty->termios.c_cc[VMIN]) - tty->rawInBufSemaphoreFirstTimeout = 0; - else - tty->rawInBufSemaphoreFirstTimeout = tty->vtimeTicks; + rtems_mutex_lock( &tty->osem ); + switch ( args->command ) { + default: + if ( rtems_termios_linesw[ tty->t_line ].l_ioctl != NULL ) { + sc = rtems_termios_linesw[ tty->t_line ].l_ioctl( tty, args ); + } else if ( tty->handler.ioctl ) { + args->ioctl_return = ( *tty->handler.ioctl )( + tty->device_context, + args->command, + args->buffer + ); + sc = RTEMS_SUCCESSFUL; } else { - if (tty->termios.c_cc[VMIN]) { - tty->rawInBufSemaphoreWait = true; - tty->rawInBufSemaphoreTimeout = 0; - tty->rawInBufSemaphoreFirstTimeout = 0; - } else { - tty->rawInBufSemaphoreWait = false; + sc = RTEMS_INVALID_NUMBER; + } + break; + + case TIOCGETA: + *(struct termios *) args->buffer = tty->termios; + break; + + case TIOCSETA: + case TIOCSETAW: + case TIOCSETAF: + tty->termios = *(struct termios *) args->buffer; + + if ( args->command == TIOCSETAW || args->command == TIOCSETAF ) { + drainOutput( tty ); + if ( args->command == TIOCSETAF ) { + flushInput( tty ); } } - } - if (tty->handler.set_attributes) { - sc = (*tty->handler.set_attributes)(tty->device_context, &tty->termios) ? - RTEMS_SUCCESSFUL : RTEMS_IO_ERROR; - } - if (rawInBufSemaphoreWait == tty->rawInBufSemaphoreWait || + /* check for and process change in flow control options */ + termios_set_flowctrl( tty ); + + rawInBufSemaphoreWait = tty->rawInBufSemaphoreWait; + rawInBufSemaphoreTimeout = tty->rawInBufSemaphoreTimeout; + rawInBufSemaphoreFirstTimeout = tty->rawInBufSemaphoreFirstTimeout; + + if ( tty->termios.c_lflag & ICANON ) { + tty->rawInBufSemaphoreWait = true; + tty->rawInBufSemaphoreTimeout = 0; + tty->rawInBufSemaphoreFirstTimeout = 0; + } else { + tty->vtimeTicks = tty->termios.c_cc[ VTIME ] * + rtems_clock_get_ticks_per_second() / 10; + if ( tty->termios.c_cc[ VTIME ] ) { + tty->rawInBufSemaphoreWait = true; + tty->rawInBufSemaphoreTimeout = tty->vtimeTicks; + if ( tty->termios.c_cc[ VMIN ] ) { + tty->rawInBufSemaphoreFirstTimeout = 0; + } else { + tty->rawInBufSemaphoreFirstTimeout = tty->vtimeTicks; + } + } else { + if ( tty->termios.c_cc[ VMIN ] ) { + tty->rawInBufSemaphoreWait = true; + tty->rawInBufSemaphoreTimeout = 0; + tty->rawInBufSemaphoreFirstTimeout = 0; + } else { + tty->rawInBufSemaphoreWait = false; + } + } + } + if ( tty->handler.set_attributes ) { + sc = ( *tty->handler.set_attributes )( + tty->device_context, + &tty->termios + ) + ? RTEMS_SUCCESSFUL + : RTEMS_IO_ERROR; + } + if ( + rawInBufSemaphoreWait == tty->rawInBufSemaphoreWait || rawInBufSemaphoreTimeout == tty->rawInBufSemaphoreTimeout || - rawInBufSemaphoreFirstTimeout == - tty->rawInBufSemaphoreFirstTimeout) { - rtems_binary_semaphore_post (&tty->rawInBuf.Semaphore); - } - break; + rawInBufSemaphoreFirstTimeout == tty->rawInBufSemaphoreFirstTimeout + ) { + rtems_binary_semaphore_post( &tty->rawInBuf.Semaphore ); + } + break; - case TIOCDRAIN: - drainOutput (tty); - break; + case TIOCDRAIN: + drainOutput( tty ); + break; - case TIOCFLUSH: - flags = *((int *)args->buffer); + case TIOCFLUSH: + flags = *( (int *) args->buffer ); - if (flags == 0) { - flags = FREAD | FWRITE; - } else { - flags &= FREAD | FWRITE; - } - if (flags & FWRITE) { - flushOutput (tty); - } - if (flags & FREAD) { - flushInput (tty); - } - break; + if ( flags == 0 ) { + flags = FREAD | FWRITE; + } else { + flags &= FREAD | FWRITE; + } + if ( flags & FWRITE ) { + flushOutput( tty ); + } + if ( flags & FREAD ) { + flushInput( tty ); + } + break; - case RTEMS_IO_SNDWAKEUP: - tty->tty_snd = *wakeup; - break; + case RTEMS_IO_SNDWAKEUP: + tty->tty_snd = *wakeup; + break; - case RTEMS_IO_RCVWAKEUP: - tty->tty_rcv = *wakeup; - break; + case RTEMS_IO_RCVWAKEUP: + tty->tty_rcv = *wakeup; + break; - /* + /* * FIXME: add various ioctl code handlers */ #if 1 /* FIXME */ - case TIOCSETD: - /* + case TIOCSETD: + /* * close old line discipline */ - if (rtems_termios_linesw[tty->t_line].l_close != NULL) { - sc = rtems_termios_linesw[tty->t_line].l_close(tty); - } - tty->t_line=*(int*)(args->buffer); - tty->t_sc = NULL; /* ensure that no more valid data */ - /* + if ( rtems_termios_linesw[ tty->t_line ].l_close != NULL ) { + sc = rtems_termios_linesw[ tty->t_line ].l_close( tty ); + } + tty->t_line = *(int *) ( args->buffer ); + tty->t_sc = NULL; /* ensure that no more valid data */ + /* * open new line discipline */ - if (rtems_termios_linesw[tty->t_line].l_open != NULL) { - sc = rtems_termios_linesw[tty->t_line].l_open(tty); - } - break; - case TIOCGETD: - *(int*)(args->buffer)=tty->t_line; - break; + if ( rtems_termios_linesw[ tty->t_line ].l_open != NULL ) { + sc = rtems_termios_linesw[ tty->t_line ].l_open( tty ); + } + break; + case TIOCGETD: + *(int *) ( args->buffer ) = tty->t_line; + break; #endif - case FIONREAD: { + case FIONREAD: { int rawnc = tty->rawInBuf.Tail - tty->rawInBuf.Head; - if ( rawnc < 0 ) + if ( rawnc < 0 ) { rawnc += tty->rawInBuf.Size; + } /* Half guess that this is the right operation */ - *(int *)args->buffer = tty->ccount - tty->cindex + rawnc; - } - break; + *(int *) args->buffer = tty->ccount - tty->cindex + rawnc; + } break; } - rtems_mutex_unlock (&tty->osem); + rtems_mutex_unlock( &tty->osem ); return sc; } @@ -929,11 +966,10 @@ rtems_termios_ioctl (void *arg) * If transmitting==true then assume transmission is already running and * an explicit write(0) is needed if output has to stop for flow control. */ -static unsigned int -startXmit ( +static unsigned int startXmit( struct rtems_termios_tty *tty, - unsigned int newTail, - bool transmitting + unsigned int newTail, + bool transmitting ) { unsigned int nToSend; @@ -941,27 +977,31 @@ startXmit ( tty->rawOutBufState = rob_busy; /* if XOFF was received, do not (re)start output */ - if (tty->flow_ctrl & FL_ORCVXOF) { + if ( tty->flow_ctrl & FL_ORCVXOF ) { /* set flag, that output has been stopped */ tty->flow_ctrl |= FL_OSTOP; nToSend = 0; /* stop transmitter */ - if (transmitting) { - (*tty->handler.write) (tty->device_context, NULL, 0); + if ( transmitting ) { + ( *tty->handler.write )( tty->device_context, NULL, 0 ); } } else { /* when flow control XON or XOF, don't send blocks of data */ /* to allow fast reaction on incoming flow ctrl and low latency*/ /* for outgoing flow control */ - if (tty->flow_ctrl & (FL_MDXON | FL_MDXOF)) + if ( tty->flow_ctrl & ( FL_MDXON | FL_MDXOF ) ) { nToSend = 1; - else if (newTail > tty->rawOutBuf.Head) + } else if ( newTail > tty->rawOutBuf.Head ) { nToSend = tty->rawOutBuf.Size - newTail; - else + } else { nToSend = tty->rawOutBuf.Head - newTail; + } - (*tty->handler.write)( - tty->device_context, &tty->rawOutBuf.theBuf[newTail], nToSend); + ( *tty->handler.write )( + tty->device_context, + &tty->rawOutBuf.theBuf[ newTail ], + nToSend + ); } return nToSend; @@ -970,49 +1010,54 @@ startXmit ( /* * Send characters to device-specific code */ -static size_t -doTransmit (const char *buf, size_t len, rtems_termios_tty *tty, - bool wait, bool nextWait) +static size_t doTransmit( + const char *buf, + size_t len, + rtems_termios_tty *tty, + bool wait, + bool nextWait +) { - unsigned int newHead; + unsigned int newHead; rtems_termios_device_context *ctx = tty->device_context; - rtems_interrupt_lock_context lock_context; - size_t todo; + rtems_interrupt_lock_context lock_context; + size_t todo; - if (tty->handler.mode == TERMIOS_POLLED) { - (*tty->handler.write)(ctx, buf, len); + if ( tty->handler.mode == TERMIOS_POLLED ) { + ( *tty->handler.write )( ctx, buf, len ); return len; } todo = len; - while (todo > 0) { + while ( todo > 0 ) { size_t nToCopy; size_t nAvail; /* Check space for at least one char */ newHead = tty->rawOutBuf.Head + 1; - if (newHead >= tty->rawOutBuf.Size) + if ( newHead >= tty->rawOutBuf.Size ) { newHead -= tty->rawOutBuf.Size; + } - rtems_termios_device_lock_acquire (ctx, &lock_context); - if (newHead == tty->rawOutBuf.Tail) { - if (wait) { + rtems_termios_device_lock_acquire( ctx, &lock_context ); + if ( newHead == tty->rawOutBuf.Tail ) { + if ( wait ) { do { tty->rawOutBufState = rob_wait; - rtems_termios_device_lock_release (ctx, &lock_context); - rtems_binary_semaphore_wait (&tty->rawOutBuf.Semaphore); - rtems_termios_device_lock_acquire (ctx, &lock_context); - } while (newHead == tty->rawOutBuf.Tail); + rtems_termios_device_lock_release( ctx, &lock_context ); + rtems_binary_semaphore_wait( &tty->rawOutBuf.Semaphore ); + rtems_termios_device_lock_acquire( ctx, &lock_context ); + } while ( newHead == tty->rawOutBuf.Tail ); } else { - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); return len - todo; } } /* Determine free space up to current tail or end of ring buffer */ nToCopy = todo; - if (tty->rawOutBuf.Tail > tty->rawOutBuf.Head) { + if ( tty->rawOutBuf.Tail > tty->rawOutBuf.Head ) { /* Available space is contiguous from Head to Tail */ nAvail = tty->rawOutBuf.Tail - tty->rawOutBuf.Head - 1; } else { @@ -1020,27 +1065,30 @@ doTransmit (const char *buf, size_t len, rtems_termios_tty *tty, only the free space from Head to end during this iteration */ nAvail = tty->rawOutBuf.Size - tty->rawOutBuf.Head; /* Head may not touch Tail after wraparound */ - if (tty->rawOutBuf.Tail == 0) + if ( tty->rawOutBuf.Tail == 0 ) { nAvail--; + } } - if (nToCopy > nAvail) + if ( nToCopy > nAvail ) { nToCopy = nAvail; + } /* To minimize latency, the memcpy could be done * with interrupts enabled or with limit on nToCopy (TBD) */ - memcpy(&tty->rawOutBuf.theBuf[tty->rawOutBuf.Head], buf, nToCopy); + memcpy( &tty->rawOutBuf.theBuf[ tty->rawOutBuf.Head ], buf, nToCopy ); newHead = tty->rawOutBuf.Head + nToCopy; - if (newHead >= tty->rawOutBuf.Size) + if ( newHead >= tty->rawOutBuf.Size ) { newHead -= tty->rawOutBuf.Size; + } tty->rawOutBuf.Head = newHead; - if (tty->rawOutBufState == rob_idle) { - startXmit (tty, tty->rawOutBuf.Tail, false); + if ( tty->rawOutBufState == rob_idle ) { + startXmit( tty, tty->rawOutBuf.Tail, false ); } - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); buf += nToCopy; todo -= nToCopy; @@ -1050,126 +1098,134 @@ doTransmit (const char *buf, size_t len, rtems_termios_tty *tty, return len; } -void -rtems_termios_puts ( - const void *_buf, size_t len, struct rtems_termios_tty *tty) +void rtems_termios_puts( + const void *_buf, + size_t len, + struct rtems_termios_tty *tty +) { - doTransmit (_buf, len, tty, true, true); + doTransmit( _buf, len, tty, true, true ); } -static bool -canTransmit (rtems_termios_tty *tty, bool wait, size_t len) +static bool canTransmit( rtems_termios_tty *tty, bool wait, size_t len ) { rtems_termios_device_context *ctx; - rtems_interrupt_lock_context lock_context; - unsigned int capacity; + rtems_interrupt_lock_context lock_context; + unsigned int capacity; - if (wait || tty->handler.mode == TERMIOS_POLLED) { + if ( wait || tty->handler.mode == TERMIOS_POLLED ) { return true; } ctx = tty->device_context; - rtems_termios_device_lock_acquire (ctx, &lock_context); - capacity = (tty->rawOutBuf.Tail - tty->rawOutBuf.Head - 1) % - tty->rawOutBuf.Size; - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_acquire( ctx, &lock_context ); + capacity = ( tty->rawOutBuf.Tail - tty->rawOutBuf.Head - 1 ) % + tty->rawOutBuf.Size; + rtems_termios_device_lock_release( ctx, &lock_context ); return capacity >= len; } /* * Handle output processing */ -static bool -oproc (unsigned char c, rtems_termios_tty *tty, bool wait) +static bool oproc( unsigned char c, rtems_termios_tty *tty, bool wait ) { - char buf[8]; + char buf[ 8 ]; size_t len; - buf[0] = c; + buf[ 0 ] = c; len = 1; - if (tty->termios.c_oflag & OPOST) { + if ( tty->termios.c_oflag & OPOST ) { int oldColumn = tty->column; int columnAdj = 0; - switch (c) { - case '\n': - if (tty->termios.c_oflag & ONLRET) - columnAdj = -oldColumn; - if (tty->termios.c_oflag & ONLCR) { - len = 2; - - if (!canTransmit (tty, wait, len)) { - return false; - } - - columnAdj = -oldColumn; - buf[0] = '\r'; - buf[1] = c; - } - break; - - case '\r': - if ((tty->termios.c_oflag & ONOCR) && (oldColumn == 0)) - return true; - if (tty->termios.c_oflag & OCRNL) { - buf[0] = '\n'; - if (tty->termios.c_oflag & ONLRET) + switch ( c ) { + case '\n': + if ( tty->termios.c_oflag & ONLRET ) { columnAdj = -oldColumn; - } else { - columnAdj = -oldColumn; - } - break; - - case '\t': - columnAdj = 8 - (oldColumn & 7); - if ((tty->termios.c_oflag & TABDLY) == OXTABS) { - int i; - - len = (size_t) columnAdj; - - if (!canTransmit (tty, wait, len)) { - return false; } + if ( tty->termios.c_oflag & ONLCR ) { + len = 2; - for (i = 0; i < columnAdj; ++i) { - buf[i] = ' '; + if ( !canTransmit( tty, wait, len ) ) { + return false; + } + + columnAdj = -oldColumn; + buf[ 0 ] = '\r'; + buf[ 1 ] = c; } - } - break; + break; - case '\b': - if (oldColumn > 0) - columnAdj = -1; - break; + case '\r': + if ( ( tty->termios.c_oflag & ONOCR ) && ( oldColumn == 0 ) ) { + return true; + } + if ( tty->termios.c_oflag & OCRNL ) { + buf[ 0 ] = '\n'; + if ( tty->termios.c_oflag & ONLRET ) { + columnAdj = -oldColumn; + } + } else { + columnAdj = -oldColumn; + } + break; - default: - if (tty->termios.c_oflag & OLCUC) { - c = toupper(c); - buf[0] = c; - } - if (!iscntrl(c)) - columnAdj = 1; - break; + case '\t': + columnAdj = 8 - ( oldColumn & 7 ); + if ( ( tty->termios.c_oflag & TABDLY ) == OXTABS ) { + int i; + + len = (size_t) columnAdj; + + if ( !canTransmit( tty, wait, len ) ) { + return false; + } + + for ( i = 0; i < columnAdj; ++i ) { + buf[ i ] = ' '; + } + } + break; + + case '\b': + if ( oldColumn > 0 ) { + columnAdj = -1; + } + break; + + default: + if ( tty->termios.c_oflag & OLCUC ) { + c = toupper( c ); + buf[ 0 ] = c; + } + if ( !iscntrl( c ) ) { + columnAdj = 1; + } + break; } tty->column = oldColumn + columnAdj; } - return doTransmit (buf, len, tty, wait, true) > 0; + return doTransmit( buf, len, tty, wait, true ) > 0; } -static uint32_t -rtems_termios_write_tty (rtems_libio_t *iop, rtems_termios_tty *tty, - const char *buf, uint32_t len) +static uint32_t rtems_termios_write_tty( + rtems_libio_t *iop, + rtems_termios_tty *tty, + const char *buf, + uint32_t len +) { - bool wait = !rtems_libio_iop_is_no_delay (iop); + bool wait = !rtems_libio_iop_is_no_delay( iop ); - if (tty->termios.c_oflag & OPOST) { + if ( tty->termios.c_oflag & OPOST ) { uint32_t todo = len; - while (todo > 0) { - if (!oproc (*buf, tty, wait)) { + while ( todo > 0 ) { + if ( !oproc( *buf, tty, wait ) ) { break; } @@ -1180,46 +1236,50 @@ rtems_termios_write_tty (rtems_libio_t *iop, rtems_termios_tty *tty, return len - todo; } else { - return doTransmit (buf, len, tty, wait, false); + return doTransmit( buf, len, tty, wait, false ); } } -rtems_status_code -rtems_termios_write (void *arg) +rtems_status_code rtems_termios_write( void *arg ) { - rtems_libio_rw_args_t *args = arg; + rtems_libio_rw_args_t *args = arg; struct rtems_termios_tty *tty = args->iop->data1; - rtems_mutex_lock (&tty->osem); - if (rtems_termios_linesw[tty->t_line].l_write != NULL) { + rtems_mutex_lock( &tty->osem ); + if ( rtems_termios_linesw[ tty->t_line ].l_write != NULL ) { rtems_status_code sc; - sc = rtems_termios_linesw[tty->t_line].l_write(tty,args); - rtems_mutex_unlock (&tty->osem); + sc = rtems_termios_linesw[ tty->t_line ].l_write( tty, args ); + rtems_mutex_unlock( &tty->osem ); return sc; } - args->bytes_moved = rtems_termios_write_tty (args->iop, tty, - args->buffer, args->count); - rtems_mutex_unlock (&tty->osem); + args->bytes_moved = rtems_termios_write_tty( + args->iop, + tty, + args->buffer, + args->count + ); + rtems_mutex_unlock( &tty->osem ); return RTEMS_SUCCESSFUL; } /* * Echo a typed character */ -static void -echo (unsigned char c, struct rtems_termios_tty *tty) +static void echo( unsigned char c, struct rtems_termios_tty *tty ) { - if ((tty->termios.c_lflag & ECHOCTL) && - iscntrl(c) && (c != '\t') && (c != '\n')) { - char echobuf[2]; + if ( + ( tty->termios.c_lflag & ECHOCTL ) && iscntrl( c ) && ( c != '\t' ) && + ( c != '\n' ) + ) { + char echobuf[ 2 ]; - echobuf[0] = '^'; - echobuf[1] = c ^ 0x40; - doTransmit (echobuf, 2, tty, true, true); + echobuf[ 0 ] = '^'; + echobuf[ 1 ] = c ^ 0x40; + doTransmit( echobuf, 2, tty, true, true ); tty->column += 2; } else { - oproc (c, tty, true); + oproc( c, tty, true ); } } @@ -1228,45 +1288,47 @@ echo (unsigned char c, struct rtems_termios_tty *tty) * FIXME: Needs support for WERASE and ECHOPRT. * FIXME: Some of the tests should check for IEXTEN, too. */ -static void -erase (struct rtems_termios_tty *tty, int lineFlag) +static void erase( struct rtems_termios_tty *tty, int lineFlag ) { - if (tty->ccount == 0) + if ( tty->ccount == 0 ) { return; - if (lineFlag) { - if (!(tty->termios.c_lflag & ECHO)) { + } + if ( lineFlag ) { + if ( !( tty->termios.c_lflag & ECHO ) ) { tty->ccount = 0; return; } - if (!(tty->termios.c_lflag & ECHOE)) { + if ( !( tty->termios.c_lflag & ECHOE ) ) { tty->ccount = 0; - echo (tty->termios.c_cc[VKILL], tty); - if (tty->termios.c_lflag & ECHOK) - echo ('\n', tty); + echo( tty->termios.c_cc[ VKILL ], tty ); + if ( tty->termios.c_lflag & ECHOK ) { + echo( '\n', tty ); + } return; } } - while (tty->ccount) { - unsigned char c = tty->cbuf[--tty->ccount]; + while ( tty->ccount ) { + unsigned char c = tty->cbuf[ --tty->ccount ]; - if (tty->termios.c_lflag & ECHO) { - if (!lineFlag && !(tty->termios.c_lflag & ECHOE)) { - echo (tty->termios.c_cc[VERASE], tty); - } else if (c == '\t') { + if ( tty->termios.c_lflag & ECHO ) { + if ( !lineFlag && !( tty->termios.c_lflag & ECHOE ) ) { + echo( tty->termios.c_cc[ VERASE ], tty ); + } else if ( c == '\t' ) { int col = tty->read_start_column; size_t i = 0; /* * Find the character before the tab */ - while (i != tty->ccount) { - c = tty->cbuf[i++]; - if (c == '\t') { - col = (col | 7) + 1; - } else if (iscntrl (c)) { - if (tty->termios.c_lflag & ECHOCTL) + while ( i != tty->ccount ) { + c = tty->cbuf[ i++ ]; + if ( c == '\t' ) { + col = ( col | 7 ) + 1; + } else if ( iscntrl( c ) ) { + if ( tty->termios.c_lflag & ECHOCTL ) { col += 2; + } } else { col++; } @@ -1275,44 +1337,49 @@ erase (struct rtems_termios_tty *tty, int lineFlag) /* * Back up over the tab */ - while (tty->column > col) { - doTransmit ("\b", 1, tty, true, true); + while ( tty->column > col ) { + doTransmit( "\b", 1, tty, true, true ); tty->column--; } - } - else { - if (iscntrl (c) && (tty->termios.c_lflag & ECHOCTL)) { - doTransmit ("\b \b", 3, tty, true, true); - if (tty->column) + } else { + if ( iscntrl( c ) && ( tty->termios.c_lflag & ECHOCTL ) ) { + doTransmit( "\b \b", 3, tty, true, true ); + if ( tty->column ) { tty->column--; + } } - if (!iscntrl (c) || (tty->termios.c_lflag & ECHOCTL)) { - doTransmit ("\b \b", 3, tty, true, true); - if (tty->column) + if ( !iscntrl( c ) || ( tty->termios.c_lflag & ECHOCTL ) ) { + doTransmit( "\b \b", 3, tty, true, true ); + if ( tty->column ) { tty->column--; + } } } } - if (!lineFlag) + if ( !lineFlag ) { break; + } } } -static unsigned char -iprocEarly (unsigned char c, rtems_termios_tty *tty) +static unsigned char iprocEarly( unsigned char c, rtems_termios_tty *tty ) { - if (tty->termios.c_iflag & ISTRIP) + if ( tty->termios.c_iflag & ISTRIP ) { c &= 0x7f; + } - if (tty->termios.c_iflag & IUCLC) - c = tolower (c); + if ( tty->termios.c_iflag & IUCLC ) { + c = tolower( c ); + } - if (c == '\r') { - if (tty->termios.c_iflag & ICRNL) + if ( c == '\r' ) { + if ( tty->termios.c_iflag & ICRNL ) { c = '\n'; - } else if (c == '\n') { - if (tty->termios.c_iflag & INLCR) + } + } else if ( c == '\n' ) { + if ( tty->termios.c_iflag & INLCR ) { c = '\r'; + } } return c; @@ -1322,15 +1389,15 @@ iprocEarly (unsigned char c, rtems_termios_tty *tty) * This points to the currently registered method to perform * ISIG processing of VKILL and VQUIT characters. */ -static rtems_termios_isig_handler termios_isig_handler = - rtems_termios_default_isig_handler; +static rtems_termios_isig_handler + termios_isig_handler = rtems_termios_default_isig_handler; /* * This is the default method to process VKILL or VQUIT characters if * ISIG processing is enabled. Note that it does nothing. */ rtems_termios_iproc_status_code rtems_termios_default_isig_handler( - unsigned char c, + unsigned char c, struct rtems_termios_tty *tty ) { @@ -1348,7 +1415,7 @@ rtems_status_code rtems_termios_register_isig_handler( rtems_termios_isig_handler handler ) { - if (handler == NULL) { + if ( handler == NULL ) { return RTEMS_INVALID_ADDRESS; } @@ -1359,43 +1426,49 @@ rtems_status_code rtems_termios_register_isig_handler( /* * Process a single input character */ -static rtems_termios_iproc_status_code -iproc (unsigned char c, struct rtems_termios_tty *tty) +static rtems_termios_iproc_status_code iproc( + unsigned char c, + struct rtems_termios_tty *tty +) { /* * If signals are enabled, then allow possibility of VINTR causing * SIGINTR and VQUIT causing SIGQUIT. Invoke user provided isig handler. */ - if ((tty->termios.c_lflag & ISIG)) { - if ((c == tty->termios.c_cc[VINTR]) || (c == tty->termios.c_cc[VQUIT])) { - return (*termios_isig_handler)(c, tty); + if (( tty->termios.c_lflag & ISIG )) { + if ( + ( c == tty->termios.c_cc[ VINTR ] ) || + ( c == tty->termios.c_cc[ VQUIT ] ) + ) { + return ( *termios_isig_handler )( c, tty ); } } /* * Perform canonical character processing. */ - if ((c != '\0') && (tty->termios.c_lflag & ICANON)) { - if (c == tty->termios.c_cc[VERASE]) { - erase (tty, 0); + if ( ( c != '\0' ) && ( tty->termios.c_lflag & ICANON ) ) { + if ( c == tty->termios.c_cc[ VERASE ] ) { + erase( tty, 0 ); return RTEMS_TERMIOS_IPROC_CONTINUE; - } - else if (c == tty->termios.c_cc[VKILL]) { - erase (tty, 1); + } else if ( c == tty->termios.c_cc[ VKILL ] ) { + erase( tty, 1 ); return RTEMS_TERMIOS_IPROC_CONTINUE; - } - else if (c == tty->termios.c_cc[VEOF]) { + } else if ( c == tty->termios.c_cc[ VEOF ] ) { return RTEMS_TERMIOS_IPROC_DONE; - } else if (c == '\n') { - if (tty->termios.c_lflag & (ECHO | ECHONL)) - echo (c, tty); - tty->cbuf[tty->ccount++] = c; + } else if ( c == '\n' ) { + if ( tty->termios.c_lflag & ( ECHO | ECHONL ) ) { + echo( c, tty ); + } + tty->cbuf[ tty->ccount++ ] = c; return RTEMS_TERMIOS_IPROC_DONE; - } else if ((c == tty->termios.c_cc[VEOL]) || - (c == tty->termios.c_cc[VEOL2])) { - if (tty->termios.c_lflag & ECHO) - echo (c, tty); - tty->cbuf[tty->ccount++] = c; + } else if ( + ( c == tty->termios.c_cc[ VEOL ] ) || ( c == tty->termios.c_cc[ VEOL2 ] ) + ) { + if ( tty->termios.c_lflag & ECHO ) { + echo( c, tty ); + } + tty->cbuf[ tty->ccount++ ] = c; return RTEMS_TERMIOS_IPROC_DONE; } } @@ -1405,10 +1478,11 @@ iproc (unsigned char c, struct rtems_termios_tty *tty) * * FIXME: Should do IMAXBEL handling somehow */ - if (tty->ccount < (CBUFSIZE-1)) { - if (tty->termios.c_lflag & ECHO) - echo (c, tty); - tty->cbuf[tty->ccount++] = c; + if ( tty->ccount < ( CBUFSIZE - 1 ) ) { + if ( tty->termios.c_lflag & ECHO ) { + echo( c, tty ); + } + tty->cbuf[ tty->ccount++ ] = c; } return RTEMS_TERMIOS_IPROC_CONTINUE; } @@ -1416,29 +1490,35 @@ iproc (unsigned char c, struct rtems_termios_tty *tty) /* * Process input character, with semaphore. */ -static rtems_termios_iproc_status_code -siproc (unsigned char c, struct rtems_termios_tty *tty) +static rtems_termios_iproc_status_code siproc( + unsigned char c, + struct rtems_termios_tty *tty +) { rtems_termios_iproc_status_code rc; /* * Obtain output semaphore if character will be echoed */ - if (tty->termios.c_lflag & (ECHO|ECHOE|ECHOK|ECHONL|ECHOPRT|ECHOCTL|ECHOKE)) { - rtems_mutex_lock (&tty->osem); - rc = iproc (c, tty); - rtems_mutex_unlock (&tty->osem); - } - else { - rc = iproc (c, tty); + if ( + tty->termios.c_lflag & + ( ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOCTL | ECHOKE ) + ) { + rtems_mutex_lock( &tty->osem ); + rc = iproc( c, tty ); + rtems_mutex_unlock( &tty->osem ); + } else { + rc = iproc( c, tty ); } return rc; } -static rtems_termios_iproc_status_code -siprocPoll (unsigned char c, rtems_termios_tty *tty) +static rtems_termios_iproc_status_code siprocPoll( + unsigned char c, + rtems_termios_tty *tty +) { - if (c == '\r' && (tty->termios.c_iflag & IGNCR) != 0) { + if ( c == '\r' && ( tty->termios.c_iflag & IGNCR ) != 0 ) { return RTEMS_TERMIOS_IPROC_CONTINUE; } @@ -1447,27 +1527,28 @@ siprocPoll (unsigned char c, rtems_termios_tty *tty) * devices so we need to perform those actions before processing * the character. */ - c = iprocEarly (c, tty); - return siproc (c, tty); + c = iprocEarly( c, tty ); + return siproc( c, tty ); } /* * Fill the input buffer by polling the device */ -static rtems_termios_iproc_status_code -fillBufferPoll (struct rtems_termios_tty *tty) +static rtems_termios_iproc_status_code fillBufferPoll( + struct rtems_termios_tty *tty +) { int n; rtems_termios_iproc_status_code rc; - if (tty->termios.c_lflag & ICANON) { - for (;;) { - n = (*tty->handler.poll_read)(tty->device_context); - if (n < 0) { - rtems_task_wake_after (1); + if ( tty->termios.c_lflag & ICANON ) { + for ( ;; ) { + n = ( *tty->handler.poll_read )( tty->device_context ); + if ( n < 0 ) { + rtems_task_wake_after( 1 ); } else { - rc = siprocPoll (n, tty); - if (rc != RTEMS_TERMIOS_IPROC_CONTINUE) { + rc = siprocPoll( n, tty ); + if ( rc != RTEMS_TERMIOS_IPROC_CONTINUE ) { return rc; } } @@ -1476,34 +1557,37 @@ fillBufferPoll (struct rtems_termios_tty *tty) rtems_interval then, now; then = rtems_clock_get_ticks_since_boot(); - for (;;) { - n = (*tty->handler.poll_read)(tty->device_context); - if (n < 0) { - if (tty->termios.c_cc[VMIN]) { - if (tty->termios.c_cc[VTIME] && tty->ccount) { + for ( ;; ) { + n = ( *tty->handler.poll_read )( tty->device_context ); + if ( n < 0 ) { + if ( tty->termios.c_cc[ VMIN ] ) { + if ( tty->termios.c_cc[ VTIME ] && tty->ccount ) { now = rtems_clock_get_ticks_since_boot(); - if ((now - then) > tty->vtimeTicks) { + if ( ( now - then ) > tty->vtimeTicks ) { break; } } } else { - if (!tty->termios.c_cc[VTIME]) + if ( !tty->termios.c_cc[ VTIME ] ) { break; + } now = rtems_clock_get_ticks_since_boot(); - if ((now - then) > tty->vtimeTicks) { + if ( ( now - then ) > tty->vtimeTicks ) { break; } } - rtems_task_wake_after (1); + rtems_task_wake_after( 1 ); } else { - rc = siprocPoll (n, tty); - if (rc != RTEMS_TERMIOS_IPROC_CONTINUE) { + rc = siprocPoll( n, tty ); + if ( rc != RTEMS_TERMIOS_IPROC_CONTINUE ) { return rc; } - if (tty->ccount >= tty->termios.c_cc[VMIN]) + if ( tty->ccount >= tty->termios.c_cc[ VMIN ] ) { break; - if (tty->termios.c_cc[VMIN] && tty->termios.c_cc[VTIME]) + } + if ( tty->termios.c_cc[ VMIN ] && tty->termios.c_cc[ VTIME ] ) { then = rtems_clock_get_ticks_since_boot(); + } } } } @@ -1513,12 +1597,13 @@ fillBufferPoll (struct rtems_termios_tty *tty) /* * Fill the input buffer from the raw input queue */ -static rtems_termios_iproc_status_code -fillBufferQueue (struct rtems_termios_tty *tty) +static rtems_termios_iproc_status_code fillBufferQueue( + struct rtems_termios_tty *tty +) { rtems_termios_device_context *ctx = tty->device_context; - rtems_interval timeout = tty->rawInBufSemaphoreFirstTimeout; - bool wait = true; + rtems_interval timeout = tty->rawInBufSemaphoreFirstTimeout; + bool wait = true; while ( wait ) { rtems_interrupt_lock_context lock_context; @@ -1527,81 +1612,91 @@ fillBufferQueue (struct rtems_termios_tty *tty) * Process characters read from raw queue */ - rtems_termios_device_lock_acquire (ctx, &lock_context); + rtems_termios_device_lock_acquire( ctx, &lock_context ); - while ((tty->rawInBuf.Head != tty->rawInBuf.Tail) && - (tty->ccount < (CBUFSIZE-1))) { - unsigned char c; - unsigned int newHead; - rtems_termios_iproc_status_code rc; + while ( + ( tty->rawInBuf.Head != tty->rawInBuf.Tail ) && + ( tty->ccount < ( CBUFSIZE - 1 ) ) + ) { + unsigned char c; + unsigned int newHead; + rtems_termios_iproc_status_code rc; - newHead = (tty->rawInBuf.Head + 1) % tty->rawInBuf.Size; - c = tty->rawInBuf.theBuf[newHead]; + newHead = ( tty->rawInBuf.Head + 1 ) % tty->rawInBuf.Size; + c = tty->rawInBuf.theBuf[ newHead ]; tty->rawInBuf.Head = newHead; - if(((tty->rawInBuf.Tail - newHead) % tty->rawInBuf.Size) - < tty->lowwater) { + if ( + ( ( tty->rawInBuf.Tail - newHead ) % tty->rawInBuf.Size ) < + tty->lowwater + ) { tty->flow_ctrl &= ~FL_IREQXOF; /* if tx stopped and XON should be sent... */ - if (((tty->flow_ctrl & (FL_MDXON | FL_ISNTXOF)) - == (FL_MDXON | FL_ISNTXOF)) - && ((tty->rawOutBufState == rob_idle) - || (tty->flow_ctrl & FL_OSTOP))) { + if ( + ( ( tty->flow_ctrl & ( FL_MDXON | FL_ISNTXOF ) ) == + ( FL_MDXON | FL_ISNTXOF ) ) && + ( ( tty->rawOutBufState == rob_idle ) || + ( tty->flow_ctrl & FL_OSTOP ) ) + ) { /* XON should be sent now... */ - (*tty->handler.write)( - tty->device_context, (void *)&(tty->termios.c_cc[VSTART]), 1); - } else if (tty->flow_ctrl & FL_MDRTS) { + ( *tty->handler.write )( + tty->device_context, + (void *) &( tty->termios.c_cc[ VSTART ] ), + 1 + ); + } else if ( tty->flow_ctrl & FL_MDRTS ) { tty->flow_ctrl &= ~FL_IRTSOFF; /* activate RTS line */ - if (tty->flow.start_remote_tx != NULL) { - tty->flow.start_remote_tx(tty->device_context); + if ( tty->flow.start_remote_tx != NULL ) { + tty->flow.start_remote_tx( tty->device_context ); } } } - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); /* continue processing new character */ - if (tty->termios.c_lflag & ICANON) { - rc = siproc (c, tty); - if (rc != RTEMS_TERMIOS_IPROC_CONTINUE) { + if ( tty->termios.c_lflag & ICANON ) { + rc = siproc( c, tty ); + if ( rc != RTEMS_TERMIOS_IPROC_CONTINUE ) { return rc; } } else { - rc = siproc (c, tty); + rc = siproc( c, tty ); /* in non-canonical mode only stop on interrupt */ - if (rc == RTEMS_TERMIOS_IPROC_INTERRUPT) { + if ( rc == RTEMS_TERMIOS_IPROC_INTERRUPT ) { return rc; } - if (tty->ccount >= tty->termios.c_cc[VMIN]) + if ( tty->ccount >= tty->termios.c_cc[ VMIN ] ) { wait = false; + } } timeout = tty->rawInBufSemaphoreTimeout; - rtems_termios_device_lock_acquire (ctx, &lock_context); + rtems_termios_device_lock_acquire( ctx, &lock_context ); } - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); /* * Wait for characters */ - if (wait) { - if (tty->ccount < CBUFSIZE - 1) { + if ( wait ) { + if ( tty->ccount < CBUFSIZE - 1 ) { rtems_binary_semaphore *sem; - int eno; + int eno; sem = &tty->rawInBuf.Semaphore; - if (tty->rawInBufSemaphoreWait) { - eno = rtems_binary_semaphore_wait_timed_ticks (sem, timeout); + if ( tty->rawInBufSemaphoreWait ) { + eno = rtems_binary_semaphore_wait_timed_ticks( sem, timeout ); } else { - eno = rtems_binary_semaphore_try_wait (sem); + eno = rtems_binary_semaphore_try_wait( sem ); } - if (eno != 0) { + if ( eno != 0 ) { break; } } else { @@ -1612,26 +1707,28 @@ fillBufferQueue (struct rtems_termios_tty *tty) return RTEMS_TERMIOS_IPROC_CONTINUE; } -static rtems_status_code -rtems_termios_read_tty ( +static rtems_status_code rtems_termios_read_tty( struct rtems_termios_tty *tty, char *buffer, uint32_t initial_count, uint32_t *count_read ) { - uint32_t count; - rtems_termios_iproc_status_code rc; + uint32_t count; + rtems_termios_iproc_status_code rc; count = initial_count; - if (tty->cindex == tty->ccount) { + if ( tty->cindex == tty->ccount ) { tty->cindex = tty->ccount = 0; tty->read_start_column = tty->column; - if (tty->handler.poll_read != NULL && tty->handler.mode == TERMIOS_POLLED) - rc = fillBufferPoll (tty); - else - rc = fillBufferQueue (tty); + if ( + tty->handler.poll_read != NULL && tty->handler.mode == TERMIOS_POLLED + ) { + rc = fillBufferPoll( tty ); + } else { + rc = fillBufferQueue( tty ); + } } else { rc = RTEMS_TERMIOS_IPROC_CONTINUE; } @@ -1639,10 +1736,10 @@ rtems_termios_read_tty ( /* * If there are characters in the buffer, then copy them to the caller. */ - while (count && (tty->cindex < tty->ccount)) { - *buffer++ = tty->cbuf[tty->cindex++]; + while ( count && ( tty->cindex < tty->ccount ) ) { + *buffer++ = tty->cbuf[ tty->cindex++ ]; count--; - } + } tty->tty_rcvwakeup = false; *count_read = initial_count - count; @@ -1651,27 +1748,25 @@ rtems_termios_read_tty ( * was interrupted. The isig handler can do nothing, have POSIX behavior * and cause a signal, or a user defined action. */ - if (rc == RTEMS_TERMIOS_IPROC_INTERRUPT) { + if ( rc == RTEMS_TERMIOS_IPROC_INTERRUPT ) { return RTEMS_INTERRUPTED; } return RTEMS_SUCCESSFUL; } -rtems_status_code -rtems_termios_read (void *arg) +rtems_status_code rtems_termios_read( void *arg ) { rtems_libio_rw_args_t *args = arg; struct rtems_termios_tty *tty = args->iop->data1; rtems_status_code sc; - rtems_mutex_lock (&tty->isem); + rtems_mutex_lock( &tty->isem ); - if (rtems_termios_linesw[tty->t_line].l_read != NULL) { - - sc = rtems_termios_linesw[tty->t_line].l_read(tty,args); + if ( rtems_termios_linesw[ tty->t_line ].l_read != NULL ) { + sc = rtems_termios_linesw[ tty->t_line ].l_read( tty, args ); tty->tty_rcvwakeup = false; - rtems_mutex_unlock (&tty->isem); + rtems_mutex_unlock( &tty->isem ); return sc; } @@ -1681,7 +1776,7 @@ rtems_termios_read (void *arg) args->count, &args->bytes_moved ); - rtems_mutex_unlock (&tty->isem); + rtems_mutex_unlock( &tty->isem ); return sc; } @@ -1690,25 +1785,28 @@ rtems_termios_read (void *arg) * NOTE: This routine runs in the context of the * device receive interrupt handler. */ -void rtems_termios_rxirq_occured(struct rtems_termios_tty *tty) +void rtems_termios_rxirq_occured( struct rtems_termios_tty *tty ) { /* * send event to rx daemon task */ - rtems_event_send(tty->rxTaskId,TERMIOS_RX_PROC_EVENT); + rtems_event_send( tty->rxTaskId, TERMIOS_RX_PROC_EVENT ); } -static bool -mustCallReceiveCallback (const rtems_termios_tty *tty, unsigned char c, - unsigned int newTail, unsigned int head) +static bool mustCallReceiveCallback( + const rtems_termios_tty *tty, + unsigned char c, + unsigned int newTail, + unsigned int head +) { - if ((tty->termios.c_lflag & ICANON) != 0) { - return c == '\n' || c == tty->termios.c_cc[VEOF] || - c == tty->termios.c_cc[VEOL] || c == tty->termios.c_cc[VEOL2]; + if ( ( tty->termios.c_lflag & ICANON ) != 0 ) { + return c == '\n' || c == tty->termios.c_cc[ VEOF ] || + c == tty->termios.c_cc[ VEOL ] || c == tty->termios.c_cc[ VEOL2 ]; } else { - unsigned int rawContentSize = (newTail - head) % tty->rawInBuf.Size; + unsigned int rawContentSize = ( newTail - head ) % tty->rawInBuf.Size; - return rawContentSize >= tty->termios.c_cc[VMIN]; + return rawContentSize >= tty->termios.c_cc[ VMIN ]; } } @@ -1718,126 +1816,138 @@ mustCallReceiveCallback (const rtems_termios_tty *tty, unsigned char c, * device receive interrupt handler. * Returns the number of characters dropped because of overflow. */ -int -rtems_termios_enqueue_raw_characters (void *ttyp, const char *buf, int len) +int rtems_termios_enqueue_raw_characters( + void *ttyp, + const char *buf, + int len +) { struct rtems_termios_tty *tty = ttyp; - char c; - int dropped = 0; + char c; + int dropped = 0; bool flow_rcv = false; /* true, if flow control char received */ rtems_termios_device_context *ctx = tty->device_context; - rtems_interrupt_lock_context lock_context; + rtems_interrupt_lock_context lock_context; - if (rtems_termios_linesw[tty->t_line].l_rint != NULL) { - while (len--) { + if ( rtems_termios_linesw[ tty->t_line ].l_rint != NULL ) { + while ( len-- ) { c = *buf++; - rtems_termios_linesw[tty->t_line].l_rint(c,tty); + rtems_termios_linesw[ tty->t_line ].l_rint( c, tty ); } /* * check to see if rcv wakeup callback was set */ - if (tty->tty_rcv.sw_pfn != NULL && !tty->tty_rcvwakeup) { + if ( tty->tty_rcv.sw_pfn != NULL && !tty->tty_rcvwakeup ) { tty->tty_rcvwakeup = true; - (*tty->tty_rcv.sw_pfn)(&tty->termios, tty->tty_rcv.sw_arg); + ( *tty->tty_rcv.sw_pfn )( &tty->termios, tty->tty_rcv.sw_arg ); } return 0; } - while (len--) { + while ( len-- ) { c = *buf++; /* FIXME: implement IXANY: any character restarts output */ /* if incoming XON/XOFF controls outgoing stream: */ - if (tty->flow_ctrl & FL_MDXON) { + if ( tty->flow_ctrl & FL_MDXON ) { /* if received char is V_STOP and V_START (both are equal value) */ - if (c == tty->termios.c_cc[VSTOP]) { - if (c == tty->termios.c_cc[VSTART]) { + if ( c == tty->termios.c_cc[ VSTOP ] ) { + if ( c == tty->termios.c_cc[ VSTART ] ) { /* received VSTOP and VSTART==VSTOP? */ /* then toggle "stop output" status */ tty->flow_ctrl = tty->flow_ctrl ^ FL_ORCVXOF; - } - else { + } else { /* VSTOP received (other code than VSTART) */ /* stop output */ tty->flow_ctrl |= FL_ORCVXOF; } flow_rcv = true; - } - else if (c == tty->termios.c_cc[VSTART]) { + } else if ( c == tty->termios.c_cc[ VSTART ] ) { /* VSTART received */ /* restart output */ tty->flow_ctrl &= ~FL_ORCVXOF; flow_rcv = true; } } - if (flow_rcv) { + if ( flow_rcv ) { /* restart output according to FL_ORCVXOF flag */ - if ((tty->flow_ctrl & (FL_ORCVXOF | FL_OSTOP)) == FL_OSTOP) { + if ( ( tty->flow_ctrl & ( FL_ORCVXOF | FL_OSTOP ) ) == FL_OSTOP ) { /* disable interrupts */ - rtems_termios_device_lock_acquire (ctx, &lock_context); + rtems_termios_device_lock_acquire( ctx, &lock_context ); tty->flow_ctrl &= ~FL_OSTOP; /* check for chars in output buffer (or rob_state?) */ - if (tty->rawOutBufState != rob_idle) { + if ( tty->rawOutBufState != rob_idle ) { /* if chars available, call write function... */ - (*tty->handler.write)( - ctx, &tty->rawOutBuf.theBuf[tty->rawOutBuf.Tail], 1); + ( *tty->handler.write )( + ctx, + &tty->rawOutBuf.theBuf[ tty->rawOutBuf.Tail ], + 1 + ); } /* reenable interrupts */ - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); } } else { unsigned int head; unsigned int oldTail; unsigned int newTail; - bool callReciveCallback; + bool callReciveCallback; - if (c == '\r' && (tty->termios.c_iflag & IGNCR) != 0) { + if ( c == '\r' && ( tty->termios.c_iflag & IGNCR ) != 0 ) { continue; } - c = iprocEarly (c, tty); + c = iprocEarly( c, tty ); - rtems_termios_device_lock_acquire (ctx, &lock_context); + rtems_termios_device_lock_acquire( ctx, &lock_context ); head = tty->rawInBuf.Head; oldTail = tty->rawInBuf.Tail; - newTail = (oldTail + 1) % tty->rawInBuf.Size; + newTail = ( oldTail + 1 ) % tty->rawInBuf.Size; /* if chars_in_buffer > highwater */ - if ((tty->flow_ctrl & FL_IREQXOF) != 0 && (((newTail - head) % - tty->rawInBuf.Size) > tty->highwater)) { + if ( + ( tty->flow_ctrl & FL_IREQXOF ) != 0 && + ( ( ( newTail - head ) % tty->rawInBuf.Size ) > tty->highwater ) + ) { /* incoming data stream should be stopped */ tty->flow_ctrl |= FL_IREQXOF; - if ((tty->flow_ctrl & (FL_MDXOF | FL_ISNTXOF)) - == (FL_MDXOF ) ) { - if ((tty->flow_ctrl & FL_OSTOP) || - (tty->rawOutBufState == rob_idle)) { + if ( ( tty->flow_ctrl & ( FL_MDXOF | FL_ISNTXOF ) ) == ( FL_MDXOF ) ) { + if ( + ( tty->flow_ctrl & FL_OSTOP ) || + ( tty->rawOutBufState == rob_idle ) + ) { /* if tx is stopped due to XOFF or out of data */ /* call write function here */ tty->flow_ctrl |= FL_ISNTXOF; - (*tty->handler.write)(ctx, - (void *)&(tty->termios.c_cc[VSTOP]), 1); + ( *tty->handler.write )( + ctx, + (void *) &( tty->termios.c_cc[ VSTOP ] ), + 1 + ); } - } else if ((tty->flow_ctrl & (FL_MDRTS | FL_IRTSOFF)) == (FL_MDRTS) ) { + } else if ( + ( tty->flow_ctrl & ( FL_MDRTS | FL_IRTSOFF ) ) == ( FL_MDRTS ) + ) { tty->flow_ctrl |= FL_IRTSOFF; /* deactivate RTS line */ - if (tty->flow.stop_remote_tx != NULL) { - tty->flow.stop_remote_tx(ctx); + if ( tty->flow.stop_remote_tx != NULL ) { + tty->flow.stop_remote_tx( ctx ); } } } callReciveCallback = false; - if (newTail != head) { - tty->rawInBuf.theBuf[newTail] = c; + if ( newTail != head ) { + tty->rawInBuf.theBuf[ newTail ] = c; tty->rawInBuf.Tail = newTail; /* * check to see if rcv wakeup callback was set */ - if (tty->tty_rcv.sw_pfn != NULL && !tty->tty_rcvwakeup) { - if (mustCallReceiveCallback (tty, c, newTail, head)) { + if ( tty->tty_rcv.sw_pfn != NULL && !tty->tty_rcvwakeup ) { + if ( mustCallReceiveCallback( tty, c, newTail, head ) ) { tty->tty_rcvwakeup = true; callReciveCallback = true; } @@ -1845,22 +1955,22 @@ rtems_termios_enqueue_raw_characters (void *ttyp, const char *buf, int len) } else { ++dropped; - if (tty->tty_rcv.sw_pfn != NULL && !tty->tty_rcvwakeup) { + if ( tty->tty_rcv.sw_pfn != NULL && !tty->tty_rcvwakeup ) { tty->tty_rcvwakeup = true; callReciveCallback = true; } } - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); - if (callReciveCallback) { - (*tty->tty_rcv.sw_pfn)(&tty->termios, tty->tty_rcv.sw_arg); + if ( callReciveCallback ) { + ( *tty->tty_rcv.sw_pfn )( &tty->termios, tty->tty_rcv.sw_arg ); } } } tty->rawInBufDropped += dropped; - rtems_binary_semaphore_post (&tty->rawInBuf.Semaphore); + rtems_binary_semaphore_post( &tty->rawInBuf.Semaphore ); return dropped; } @@ -1868,30 +1978,37 @@ rtems_termios_enqueue_raw_characters (void *ttyp, const char *buf, int len) * in task-driven mode, this function is called in Tx task context * in interrupt-driven mode, this function is called in TxIRQ context */ -static int -rtems_termios_refill_transmitter (struct rtems_termios_tty *tty) +static int rtems_termios_refill_transmitter( struct rtems_termios_tty *tty ) { - bool wakeUpWriterTask = false; - unsigned int newTail; - int nToSend; + bool wakeUpWriterTask = false; + unsigned int newTail; + int nToSend; rtems_termios_device_context *ctx = tty->device_context; - rtems_interrupt_lock_context lock_context; - int len; + rtems_interrupt_lock_context lock_context; + int len; - rtems_termios_device_lock_acquire (ctx, &lock_context); + rtems_termios_device_lock_acquire( ctx, &lock_context ); /* check for XOF/XON to send */ - if ((tty->flow_ctrl & (FL_MDXOF | FL_IREQXOF | FL_ISNTXOF)) - == (FL_MDXOF | FL_IREQXOF)) { + if ( + ( tty->flow_ctrl & ( FL_MDXOF | FL_IREQXOF | FL_ISNTXOF ) ) == + ( FL_MDXOF | FL_IREQXOF ) + ) { /* XOFF should be sent now... */ - (*tty->handler.write)(ctx, (void *)&(tty->termios.c_cc[VSTOP]), 1); + ( *tty->handler.write )( + ctx, + (void *) &( tty->termios.c_cc[ VSTOP ] ), + 1 + ); tty->t_dqlen--; tty->flow_ctrl |= FL_ISNTXOF; nToSend = 1; - } else if ((tty->flow_ctrl & (FL_IREQXOF | FL_ISNTXOF)) == FL_ISNTXOF) { + } else if ( + ( tty->flow_ctrl & ( FL_IREQXOF | FL_ISNTXOF ) ) == FL_ISNTXOF + ) { /* NOTE: send XON even, if no longer in XON/XOFF mode... */ /* XON should be sent now... */ /* @@ -1900,7 +2017,11 @@ rtems_termios_refill_transmitter (struct rtems_termios_tty *tty) * buffer, although the corresponding data is not yet out! * Therefore the dequeue "length" should be reduced by 1 */ - (*tty->handler.write)(ctx, (void *)&(tty->termios.c_cc[VSTART]), 1); + ( *tty->handler.write )( + ctx, + (void *) &( tty->termios.c_cc[ VSTART ] ), + 1 + ); tty->t_dqlen--; tty->flow_ctrl &= ~FL_ISNTXOF; @@ -1910,54 +2031,54 @@ rtems_termios_refill_transmitter (struct rtems_termios_tty *tty) /* * buffer was empty */ - if (tty->rawOutBufState == rob_wait) { + if ( tty->rawOutBufState == rob_wait ) { /* * this should never happen... */ wakeUpWriterTask = true; } - (*tty->handler.write) (ctx, NULL, 0); + ( *tty->handler.write )( ctx, NULL, 0 ); nToSend = 0; } else { len = tty->t_dqlen; tty->t_dqlen = 0; - newTail = (tty->rawOutBuf.Tail + len) % tty->rawOutBuf.Size; + newTail = ( tty->rawOutBuf.Tail + len ) % tty->rawOutBuf.Size; tty->rawOutBuf.Tail = newTail; - if (tty->rawOutBufState == rob_wait) { + if ( tty->rawOutBufState == rob_wait ) { /* * wake up any pending writer task */ wakeUpWriterTask = true; } - if (newTail == tty->rawOutBuf.Head) { + if ( newTail == tty->rawOutBuf.Head ) { /* * Buffer has become empty */ tty->rawOutBufState = rob_idle; - (*tty->handler.write) (ctx, NULL, 0); + ( *tty->handler.write )( ctx, NULL, 0 ); nToSend = 0; /* * check to see if snd wakeup callback was set */ - if ( tty->tty_snd.sw_pfn != NULL) { - (*tty->tty_snd.sw_pfn)(&tty->termios, tty->tty_snd.sw_arg); + if ( tty->tty_snd.sw_pfn != NULL ) { + ( *tty->tty_snd.sw_pfn )( &tty->termios, tty->tty_snd.sw_arg ); } } else { /* * Buffer not empty, check flow control, start transmitter */ - nToSend = startXmit (tty, newTail, true); + nToSend = startXmit( tty, newTail, true ); } } - rtems_termios_device_lock_release (ctx, &lock_context); + rtems_termios_device_lock_release( ctx, &lock_context ); - if (wakeUpWriterTask) { - rtems_binary_semaphore_post (&tty->rawOutBuf.Semaphore); + if ( wakeUpWriterTask ) { + rtems_binary_semaphore_post( &tty->rawOutBuf.Semaphore ); } return nToSend; @@ -1972,60 +2093,60 @@ rtems_termios_refill_transmitter (struct rtems_termios_tty *tty) * for each transmitted character. * It returns number of characters left to transmit */ -int -rtems_termios_dequeue_characters (void *ttyp, int len) +int rtems_termios_dequeue_characters( void *ttyp, int len ) { struct rtems_termios_tty *tty = ttyp; - rtems_status_code sc; + rtems_status_code sc; /* * sum up character count already sent */ tty->t_dqlen += len; - if (tty->handler.mode == TERMIOS_TASK_DRIVEN) { + if ( tty->handler.mode == TERMIOS_TASK_DRIVEN ) { /* * send wake up to transmitter task */ tty->txTaskCharsDequeued = len; - sc = rtems_event_send(tty->txTaskId, TERMIOS_TX_START_EVENT); - if (sc != RTEMS_SUCCESSFUL) - rtems_fatal_error_occurred (sc); - return 0; /* nothing to output in IRQ... */ - } - - if (tty->t_line == PPPDISC ) { - /* - * call PPP line discipline start function - */ - if (rtems_termios_linesw[tty->t_line].l_start != NULL) { - rtems_termios_linesw[tty->t_line].l_start(tty, len); + sc = rtems_event_send( tty->txTaskId, TERMIOS_TX_START_EVENT ); + if ( sc != RTEMS_SUCCESSFUL ) { + rtems_fatal_error_occurred( sc ); } return 0; /* nothing to output in IRQ... */ } - return rtems_termios_refill_transmitter(tty); + if ( tty->t_line == PPPDISC ) { + /* + * call PPP line discipline start function + */ + if ( rtems_termios_linesw[ tty->t_line ].l_start != NULL ) { + rtems_termios_linesw[ tty->t_line ].l_start( tty, len ); + } + return 0; /* nothing to output in IRQ... */ + } + + return rtems_termios_refill_transmitter( tty ); } /* * this task actually processes any transmit events */ -static rtems_task rtems_termios_txdaemon(rtems_task_argument argument) +static rtems_task rtems_termios_txdaemon( rtems_task_argument argument ) { - struct rtems_termios_tty *tty = (struct rtems_termios_tty *)argument; - rtems_event_set the_event; + struct rtems_termios_tty *tty = (struct rtems_termios_tty *) argument; + rtems_event_set the_event; - while (1) { + while ( 1 ) { /* * wait for rtems event */ rtems_event_receive( - (TERMIOS_TX_START_EVENT | TERMIOS_TX_TERMINATE_EVENT), - RTEMS_EVENT_ANY | RTEMS_WAIT, - RTEMS_NO_TIMEOUT, - &the_event + ( TERMIOS_TX_START_EVENT | TERMIOS_TX_TERMINATE_EVENT ), + RTEMS_EVENT_ANY | RTEMS_WAIT, + RTEMS_NO_TIMEOUT, + &the_event ); - if ((the_event & TERMIOS_TX_TERMINATE_EVENT) != 0) { + if ( ( the_event & TERMIOS_TX_TERMINATE_EVENT ) != 0 ) { tty->txTaskId = 0; rtems_task_exit(); } @@ -2033,10 +2154,13 @@ static rtems_task rtems_termios_txdaemon(rtems_task_argument argument) /* * call any line discipline start function */ - if (rtems_termios_linesw[tty->t_line].l_start != NULL) { - rtems_termios_linesw[tty->t_line].l_start(tty, tty->txTaskCharsDequeued); + if ( rtems_termios_linesw[ tty->t_line ].l_start != NULL ) { + rtems_termios_linesw[ tty->t_line ].l_start( + tty, + tty->txTaskCharsDequeued + ); - if (tty->t_line == PPPDISC) { + if ( tty->t_line == PPPDISC ) { /* * Do not call rtems_termios_refill_transmitter() in this case similar * to rtems_termios_dequeue_characters(). @@ -2048,32 +2172,32 @@ static rtems_task rtems_termios_txdaemon(rtems_task_argument argument) /* * try to push further characters to device */ - rtems_termios_refill_transmitter(tty); + rtems_termios_refill_transmitter( tty ); } } /* * this task actually processes any receive events */ -static rtems_task rtems_termios_rxdaemon(rtems_task_argument argument) +static rtems_task rtems_termios_rxdaemon( rtems_task_argument argument ) { - struct rtems_termios_tty *tty = (struct rtems_termios_tty *)argument; + struct rtems_termios_tty *tty = (struct rtems_termios_tty *) argument; rtems_termios_device_context *ctx = tty->device_context; - rtems_event_set the_event; - int c; - char c_buf; + rtems_event_set the_event; + int c; + char c_buf; - while (1) { + while ( 1 ) { /* * wait for rtems event */ rtems_event_receive( - (TERMIOS_RX_PROC_EVENT | TERMIOS_RX_TERMINATE_EVENT), + ( TERMIOS_RX_PROC_EVENT | TERMIOS_RX_TERMINATE_EVENT ), RTEMS_EVENT_ANY | RTEMS_WAIT, RTEMS_NO_TIMEOUT, &the_event ); - if ((the_event & TERMIOS_RX_TERMINATE_EVENT) != 0) { + if ( ( the_event & TERMIOS_RX_TERMINATE_EVENT ) != 0 ) { tty->rxTaskId = 0; rtems_task_exit(); } @@ -2081,67 +2205,78 @@ static rtems_task rtems_termios_rxdaemon(rtems_task_argument argument) /* * do something */ - c = tty->handler.poll_read(ctx); - if (c != EOF) { + c = tty->handler.poll_read( ctx ); + if ( c != EOF ) { /* * poll_read did call enqueue on its own */ c_buf = c; - rtems_termios_enqueue_raw_characters ( tty,&c_buf,1); + rtems_termios_enqueue_raw_characters( tty, &c_buf, 1 ); } } } -static int -rtems_termios_imfs_open (rtems_libio_t *iop, - const char *path, int oflag, mode_t mode) +static int rtems_termios_imfs_open( + rtems_libio_t *iop, + const char *path, + int oflag, + mode_t mode +) { (void) path; (void) oflag; - rtems_termios_device_node *device_node; + rtems_termios_device_node *device_node; rtems_libio_open_close_args_t args; - struct rtems_termios_tty *tty; + struct rtems_termios_tty *tty; - device_node = IMFS_generic_get_context_by_iop (iop); + device_node = IMFS_generic_get_context_by_iop( iop ); - memset (&args, 0, sizeof (args)); + memset( &args, 0, sizeof( args ) ); args.iop = iop; - args.flags = rtems_libio_iop_flags (iop); + args.flags = rtems_libio_iop_flags( iop ); args.mode = mode; - rtems_termios_obtain (); + rtems_termios_obtain(); - tty = rtems_termios_open_tty (device_node->major, device_node->minor, &args, - device_node->tty, device_node, NULL); - if (tty == NULL) { - rtems_termios_release (); - rtems_set_errno_and_return_minus_one (ENOMEM); + tty = rtems_termios_open_tty( + device_node->major, + device_node->minor, + &args, + device_node->tty, + device_node, + NULL + ); + if ( tty == NULL ) { + rtems_termios_release(); + rtems_set_errno_and_return_minus_one( ENOMEM ); } - rtems_termios_release (); + rtems_termios_release(); return 0; } -static int -rtems_termios_imfs_close (rtems_libio_t *iop) +static int rtems_termios_imfs_close( rtems_libio_t *iop ) { rtems_libio_open_close_args_t args; - struct rtems_termios_tty *tty; + struct rtems_termios_tty *tty; - memset (&args, 0, sizeof (args)); + memset( &args, 0, sizeof( args ) ); args.iop = iop; tty = iop->data1; - rtems_termios_obtain (); - rtems_termios_close_tty (tty, &args); - rtems_termios_release (); + rtems_termios_obtain(); + rtems_termios_close_tty( tty, &args ); + rtems_termios_release(); return 0; } -static ssize_t -rtems_termios_imfs_read (rtems_libio_t *iop, void *buffer, size_t count) +static ssize_t rtems_termios_imfs_read( + rtems_libio_t *iop, + void *buffer, + size_t count +) { struct rtems_termios_tty *tty; uint32_t bytes_moved; @@ -2149,90 +2284,94 @@ rtems_termios_imfs_read (rtems_libio_t *iop, void *buffer, size_t count) tty = iop->data1; - rtems_mutex_lock (&tty->isem); + rtems_mutex_lock( &tty->isem ); - if (rtems_termios_linesw[tty->t_line].l_read != NULL) { + if ( rtems_termios_linesw[ tty->t_line ].l_read != NULL ) { rtems_libio_rw_args_t args; - rtems_status_code sc; + rtems_status_code sc; - memset (&args, 0, sizeof (args)); + memset( &args, 0, sizeof( args ) ); args.iop = iop; args.buffer = buffer; args.count = count; - args.flags = rtems_libio_iop_flags (iop); + args.flags = rtems_libio_iop_flags( iop ); - sc = rtems_termios_linesw[tty->t_line].l_read (tty, &args); + sc = rtems_termios_linesw[ tty->t_line ].l_read( tty, &args ); tty->tty_rcvwakeup = false; - rtems_mutex_unlock (&tty->isem); + rtems_mutex_unlock( &tty->isem ); - if (sc != RTEMS_SUCCESSFUL) { - return rtems_status_code_to_errno (sc); + if ( sc != RTEMS_SUCCESSFUL ) { + return rtems_status_code_to_errno( sc ); } return (ssize_t) args.bytes_moved; } - sc = rtems_termios_read_tty(tty, buffer, count, &bytes_moved); - rtems_mutex_unlock (&tty->isem); - if (sc != RTEMS_SUCCESSFUL) { - return rtems_status_code_to_errno (sc); + sc = rtems_termios_read_tty( tty, buffer, count, &bytes_moved ); + rtems_mutex_unlock( &tty->isem ); + if ( sc != RTEMS_SUCCESSFUL ) { + return rtems_status_code_to_errno( sc ); } return (ssize_t) bytes_moved; - } -static ssize_t -rtems_termios_imfs_write (rtems_libio_t *iop, const void *buffer, size_t count) +static ssize_t rtems_termios_imfs_write( + rtems_libio_t *iop, + const void *buffer, + size_t count +) { struct rtems_termios_tty *tty; - uint32_t bytes_moved; + uint32_t bytes_moved; tty = iop->data1; - rtems_mutex_lock (&tty->osem); + rtems_mutex_lock( &tty->osem ); - if (rtems_termios_linesw[tty->t_line].l_write != NULL) { + if ( rtems_termios_linesw[ tty->t_line ].l_write != NULL ) { rtems_libio_rw_args_t args; - rtems_status_code sc; + rtems_status_code sc; - memset (&args, 0, sizeof (args)); + memset( &args, 0, sizeof( args ) ); args.iop = iop; - args.buffer = RTEMS_DECONST (void *, buffer); + args.buffer = RTEMS_DECONST( void *, buffer ); args.count = count; - args.flags = rtems_libio_iop_flags (iop); + args.flags = rtems_libio_iop_flags( iop ); - sc = rtems_termios_linesw[tty->t_line].l_write (tty, &args); - rtems_mutex_unlock (&tty->osem); + sc = rtems_termios_linesw[ tty->t_line ].l_write( tty, &args ); + rtems_mutex_unlock( &tty->osem ); - if (sc != RTEMS_SUCCESSFUL) { - return rtems_status_code_to_errno (sc); + if ( sc != RTEMS_SUCCESSFUL ) { + return rtems_status_code_to_errno( sc ); } return (ssize_t) args.bytes_moved; } - bytes_moved = rtems_termios_write_tty (iop, tty, buffer, count); - rtems_mutex_unlock (&tty->osem); + bytes_moved = rtems_termios_write_tty( iop, tty, buffer, count ); + rtems_mutex_unlock( &tty->osem ); return (ssize_t) bytes_moved; } -static int -rtems_termios_imfs_ioctl (rtems_libio_t *iop, ioctl_command_t request, - void *buffer) +static int rtems_termios_imfs_ioctl( + rtems_libio_t *iop, + ioctl_command_t request, + void *buffer +) { - rtems_status_code sc; + rtems_status_code sc; rtems_libio_ioctl_args_t args; - memset (&args, 0, sizeof (args)); + memset( &args, 0, sizeof( args ) ); args.iop = iop; args.command = request; args.buffer = buffer; - sc = rtems_termios_ioctl (&args); + sc = rtems_termios_ioctl( &args ); if ( sc == RTEMS_SUCCESSFUL ) { return args.ioctl_return; } else { - return rtems_status_code_to_errno (sc); + return rtems_status_code_to_errno( sc ); } } @@ -2255,33 +2394,34 @@ static const rtems_filesystem_file_handlers_r rtems_termios_imfs_handler = { .writev_h = rtems_filesystem_default_writev }; -static IMFS_jnode_t * -rtems_termios_imfs_node_initialize (IMFS_jnode_t *node, void *arg) +static IMFS_jnode_t *rtems_termios_imfs_node_initialize( + IMFS_jnode_t *node, + void *arg +) { rtems_termios_device_node *device_node; - dev_t dev; + dev_t dev; - node = IMFS_node_initialize_generic (node, arg); - device_node = IMFS_generic_get_context_by_node (node); - dev = IMFS_generic_get_device_identifier_by_node (node); - device_node->major = rtems_filesystem_dev_major_t (dev); - device_node->minor = rtems_filesystem_dev_minor_t (dev); + node = IMFS_node_initialize_generic( node, arg ); + device_node = IMFS_generic_get_context_by_node( node ); + dev = IMFS_generic_get_device_identifier_by_node( node ); + device_node->major = rtems_filesystem_dev_major_t( dev ); + device_node->minor = rtems_filesystem_dev_minor_t( dev ); return node; } -static void -rtems_termios_imfs_node_destroy (IMFS_jnode_t *node) +static void rtems_termios_imfs_node_destroy( IMFS_jnode_t *node ) { rtems_termios_device_node *device_node; - device_node = IMFS_generic_get_context_by_node (node); - free (device_node); - IMFS_node_destroy_default (node); + device_node = IMFS_generic_get_context_by_node( node ); + free( device_node ); + IMFS_node_destroy_default( node ); } -static const IMFS_node_control rtems_termios_imfs_node_control = - IMFS_GENERIC_INITIALIZER( +static const IMFS_node_control + rtems_termios_imfs_node_control = IMFS_GENERIC_INITIALIZER( &rtems_termios_imfs_handler, rtems_termios_imfs_node_initialize, rtems_termios_imfs_node_destroy diff --git a/cpukit/libcsupport/src/termios_baud2index.c b/cpukit/libcsupport/src/termios_baud2index.c index 17b3c40b29..8a847f294a 100644 --- a/cpukit/libcsupport/src/termios_baud2index.c +++ b/cpukit/libcsupport/src/termios_baud2index.c @@ -40,39 +40,89 @@ #include #include -int rtems_termios_baud_to_index( - rtems_termios_baud_t termios_baud -) +int rtems_termios_baud_to_index( rtems_termios_baud_t termios_baud ) { int baud_index; - switch (termios_baud) { - case B0: baud_index = 0; break; - case B50: baud_index = 1; break; - case B75: baud_index = 2; break; - case B110: baud_index = 3; break; - case B134: baud_index = 4; break; - case B150: baud_index = 5; break; - case B200: baud_index = 6; break; - case B300: baud_index = 7; break; - case B600: baud_index = 8; break; - case B1200: baud_index = 9; break; - case B1800: baud_index = 10; break; - case B2400: baud_index = 11; break; - case B4800: baud_index = 12; break; - case B9600: baud_index = 13; break; - case B19200: baud_index = 14; break; - case B38400: baud_index = 15; break; - case B7200: baud_index = 16; break; - case B14400: baud_index = 17; break; - case B28800: baud_index = 18; break; - case B57600: baud_index = 19; break; - case B76800: baud_index = 20; break; - case B115200: baud_index = 21; break; - case B230400: baud_index = 22; break; - case B460800: baud_index = 23; break; - case B921600: baud_index = 24; break; - default: baud_index = -1; break; + switch ( termios_baud ) { + case B0: + baud_index = 0; + break; + case B50: + baud_index = 1; + break; + case B75: + baud_index = 2; + break; + case B110: + baud_index = 3; + break; + case B134: + baud_index = 4; + break; + case B150: + baud_index = 5; + break; + case B200: + baud_index = 6; + break; + case B300: + baud_index = 7; + break; + case B600: + baud_index = 8; + break; + case B1200: + baud_index = 9; + break; + case B1800: + baud_index = 10; + break; + case B2400: + baud_index = 11; + break; + case B4800: + baud_index = 12; + break; + case B9600: + baud_index = 13; + break; + case B19200: + baud_index = 14; + break; + case B38400: + baud_index = 15; + break; + case B7200: + baud_index = 16; + break; + case B14400: + baud_index = 17; + break; + case B28800: + baud_index = 18; + break; + case B57600: + baud_index = 19; + break; + case B76800: + baud_index = 20; + break; + case B115200: + baud_index = 21; + break; + case B230400: + baud_index = 22; + break; + case B460800: + baud_index = 23; + break; + case B921600: + baud_index = 24; + break; + default: + baud_index = -1; + break; } return baud_index; diff --git a/cpukit/libcsupport/src/termios_baud2num.c b/cpukit/libcsupport/src/termios_baud2num.c index 4a20938ff0..11f7ab3eb5 100644 --- a/cpukit/libcsupport/src/termios_baud2num.c +++ b/cpukit/libcsupport/src/termios_baud2num.c @@ -39,7 +39,7 @@ #include -rtems_termios_baud_t rtems_termios_baud_to_number(speed_t spd) +rtems_termios_baud_t rtems_termios_baud_to_number( speed_t spd ) { - return rtems_assoc_local_by_remote(rtems_termios_baud_table, spd); + return rtems_assoc_local_by_remote( rtems_termios_baud_table, spd ); } diff --git a/cpukit/libcsupport/src/termios_baudtable.c b/cpukit/libcsupport/src/termios_baudtable.c index ea25bf6ed5..14b0f2454a 100644 --- a/cpukit/libcsupport/src/termios_baudtable.c +++ b/cpukit/libcsupport/src/termios_baudtable.c @@ -39,31 +39,31 @@ #include -const rtems_assoc_t rtems_termios_baud_table [] = { - { "B0", 0, B0 }, - { "B50", 50, B50 }, - { "B75", 75, B75 }, - { "B110", 110, B110 }, - { "B134", 134, B134 }, - { "B150", 150, B150 }, - { "B200", 200, B200 }, - { "B300", 300, B300 }, - { "B600", 600, B600 }, - { "B1200", 1200, B1200 }, - { "B1800", 1800, B1800 }, - { "B2400", 2400, B2400 }, - { "B4800", 4800, B4800 }, - { "B7200", 7200, B7200 }, - { "B9600", 9600, B9600 }, - { "B14400", 14400, B14400 }, - { "B19200", 19200, B19200 }, - { "B38400", 38400, B38400 }, - { "B28800", 28800, B28800 }, - { "B57600", 57600, B57600 }, - { "B76800", 76800, B76800 }, +const rtems_assoc_t rtems_termios_baud_table[] = { + { "B0", 0, B0 }, + { "B50", 50, B50 }, + { "B75", 75, B75 }, + { "B110", 110, B110 }, + { "B134", 134, B134 }, + { "B150", 150, B150 }, + { "B200", 200, B200 }, + { "B300", 300, B300 }, + { "B600", 600, B600 }, + { "B1200", 1200, B1200 }, + { "B1800", 1800, B1800 }, + { "B2400", 2400, B2400 }, + { "B4800", 4800, B4800 }, + { "B7200", 7200, B7200 }, + { "B9600", 9600, B9600 }, + { "B14400", 14400, B14400 }, + { "B19200", 19200, B19200 }, + { "B38400", 38400, B38400 }, + { "B28800", 28800, B28800 }, + { "B57600", 57600, B57600 }, + { "B76800", 76800, B76800 }, { "B115200", 115200, B115200 }, { "B230400", 230400, B230400 }, { "B460800", 460800, B460800 }, { "B921600", 921600, B921600 }, - { NULL, 0, 0 } + { NULL, 0, 0 } }; diff --git a/cpukit/libcsupport/src/termios_num2baud.c b/cpukit/libcsupport/src/termios_num2baud.c index c50afd16f9..3d8cc7ddc2 100644 --- a/cpukit/libcsupport/src/termios_num2baud.c +++ b/cpukit/libcsupport/src/termios_num2baud.c @@ -39,14 +39,14 @@ #include -tcflag_t rtems_termios_number_to_baud(rtems_termios_baud_t baud) +tcflag_t rtems_termios_number_to_baud( rtems_termios_baud_t baud ) { uint32_t remote_value = rtems_assoc_remote_by_local( rtems_termios_baud_table, baud ); - if (remote_value == 0) { + if ( remote_value == 0 ) { remote_value = B0; } diff --git a/cpukit/libcsupport/src/termios_setbestbaud.c b/cpukit/libcsupport/src/termios_setbestbaud.c index 56152c3dbd..eb8ceec3d7 100644 --- a/cpukit/libcsupport/src/termios_setbestbaud.c +++ b/cpukit/libcsupport/src/termios_setbestbaud.c @@ -31,14 +31,11 @@ #include -void rtems_termios_set_best_baud( - struct termios *term, - uint32_t baud -) +void rtems_termios_set_best_baud( struct termios *term, uint32_t baud ) { const rtems_assoc_t *current = &rtems_termios_baud_table[ 0 ]; const rtems_assoc_t *last = current; - speed_t spd; + speed_t spd; while ( current->name != NULL && current->local_value < baud ) { last = current; @@ -46,7 +43,8 @@ void rtems_termios_set_best_baud( } if ( current->name != NULL ) { - uint32_t mid = (last->local_value + current->local_value) / UINT32_C( 2 ); + uint32_t mid = ( last->local_value + current->local_value ) / + UINT32_C( 2 ); spd = baud <= mid ? last->remote_value : current->remote_value; } else { diff --git a/cpukit/libcsupport/src/termios_setinitialbaud.c b/cpukit/libcsupport/src/termios_setinitialbaud.c index 9331233927..9d0d7b286f 100644 --- a/cpukit/libcsupport/src/termios_setinitialbaud.c +++ b/cpukit/libcsupport/src/termios_setinitialbaud.c @@ -41,11 +41,11 @@ int rtems_termios_set_initial_baud( struct rtems_termios_tty *tty, - rtems_termios_baud_t baud + rtems_termios_baud_t baud ) { - int rv = 0; - speed_t spd = rtems_termios_number_to_baud(baud); + int rv = 0; + speed_t spd = rtems_termios_number_to_baud( baud ); if ( spd != 0 ) { tty->termios.c_ispeed = spd; diff --git a/cpukit/libcsupport/src/termiosinitialize.c b/cpukit/libcsupport/src/termiosinitialize.c index be35311e45..32e77eb08f 100644 --- a/cpukit/libcsupport/src/termiosinitialize.c +++ b/cpukit/libcsupport/src/termiosinitialize.c @@ -24,24 +24,22 @@ #include -void -rtems_termios_device_lock_acquire_default( +void rtems_termios_device_lock_acquire_default( rtems_termios_device_context *ctx, rtems_interrupt_lock_context *lock_context ) { (void) ctx; - rtems_interrupt_lock_acquire (&ctx->lock.interrupt, lock_context); + rtems_interrupt_lock_acquire( &ctx->lock.interrupt, lock_context ); } -void -rtems_termios_device_lock_release_default( +void rtems_termios_device_lock_release_default( rtems_termios_device_context *ctx, rtems_interrupt_lock_context *lock_context ) { (void) ctx; - rtems_interrupt_lock_release (&ctx->lock.interrupt, lock_context); + rtems_interrupt_lock_release( &ctx->lock.interrupt, lock_context ); } diff --git a/cpukit/libcsupport/src/truncate.c b/cpukit/libcsupport/src/truncate.c index cfb11b1b0e..9039c872da 100644 --- a/cpukit/libcsupport/src/truncate.c +++ b/cpukit/libcsupport/src/truncate.c @@ -46,17 +46,15 @@ * commonly supported on most UNIX and POSIX systems. It is provided * for compatibility. */ -int truncate( - const char *path, - off_t length -) +int truncate( const char *path, off_t length ) { int status; int fd; fd = open( path, O_WRONLY ); - if ( fd == -1 ) + if ( fd == -1 ) { return -1; + } status = ftruncate( fd, length ); diff --git a/cpukit/libcsupport/src/uenvgetgroups.c b/cpukit/libcsupport/src/uenvgetgroups.c index 68521f990f..c1dc56e071 100644 --- a/cpukit/libcsupport/src/uenvgetgroups.c +++ b/cpukit/libcsupport/src/uenvgetgroups.c @@ -36,10 +36,10 @@ #include #include -void rtems_current_user_env_getgroups(void) +void rtems_current_user_env_getgroups( void ) { rtems_user_env_t *uenv = rtems_current_user_env_get(); - int ngroups = (int) RTEMS_ARRAY_SIZE( uenv->groups ); + int ngroups = (int) RTEMS_ARRAY_SIZE( uenv->groups ); ngroups = getgroups( ngroups, &uenv->groups[ 0 ] ); if ( ngroups > 0 ) { diff --git a/cpukit/libcsupport/src/umask.c b/cpukit/libcsupport/src/umask.c index 5403834771..5bb611074c 100644 --- a/cpukit/libcsupport/src/umask.c +++ b/cpukit/libcsupport/src/umask.c @@ -50,7 +50,7 @@ mode_t umask( mode_t cmask ) rtems_libio_lock(); old_mask = rtems_filesystem_umask; - rtems_filesystem_umask = cmask & (S_IRWXU | S_IRWXG | S_IRWXO); + rtems_filesystem_umask = cmask & ( S_IRWXU | S_IRWXG | S_IRWXO ); rtems_libio_unlock(); return old_mask; diff --git a/cpukit/libcsupport/src/unlink.c b/cpukit/libcsupport/src/unlink.c index ee767f223f..14ccfe6833 100644 --- a/cpukit/libcsupport/src/unlink.c +++ b/cpukit/libcsupport/src/unlink.c @@ -46,15 +46,14 @@ */ int unlink( const char *path ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_REJECT_TERMINAL_DOT; + int eval_flags = RTEMS_FS_REJECT_TERMINAL_DOT; rtems_filesystem_location_info_t parentloc; - int parent_eval_flags = RTEMS_FS_PERMS_WRITE - | RTEMS_FS_PERMS_EXEC - | RTEMS_FS_FOLLOW_LINK; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start_with_parent( + int parent_eval_flags = RTEMS_FS_PERMS_WRITE | RTEMS_FS_PERMS_EXEC | + RTEMS_FS_FOLLOW_LINK; + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start_with_parent( &ctx, path, eval_flags, @@ -65,7 +64,7 @@ int unlink( const char *path ) if ( !rtems_filesystem_location_is_instance_root( currentloc ) ) { const rtems_filesystem_operations_table *ops = currentloc->mt_entry->ops; - rv = (*ops->rmnod_h)( &parentloc, currentloc ); + rv = ( *ops->rmnod_h )( &parentloc, currentloc ); } else { rtems_filesystem_eval_path_error( &ctx, EBUSY ); rv = -1; @@ -76,17 +75,14 @@ int unlink( const char *path ) return rv; } -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include /** * This is the Newlib dependent reentrant version of unlink(). */ -int _unlink_r( - struct _reent *ptr RTEMS_UNUSED, - const char *path -) +int _unlink_r( struct _reent *ptr RTEMS_UNUSED, const char *path ) { return unlink( path ); } diff --git a/cpukit/libcsupport/src/unmount.c b/cpukit/libcsupport/src/unmount.c index 65836a0a0f..21ccf7097f 100644 --- a/cpukit/libcsupport/src/unmount.c +++ b/cpukit/libcsupport/src/unmount.c @@ -45,10 +45,10 @@ static bool contains_root_or_current_directory( const rtems_filesystem_mount_table_entry_t *mt_entry ) { - const rtems_filesystem_location_info_t *root = - &rtems_filesystem_root->location; - const rtems_filesystem_location_info_t *current = - &rtems_filesystem_current->location; + const rtems_filesystem_location_info_t + *root = &rtems_filesystem_root->location; + const rtems_filesystem_location_info_t + *current = &rtems_filesystem_current->location; return mt_entry == root->mt_entry || mt_entry == current->mt_entry; } @@ -61,19 +61,19 @@ static bool contains_root_or_current_directory( */ int unmount( const char *path ) { - int rv = 0; + int rv = 0; rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_FOLLOW_LINK; - const rtems_filesystem_location_info_t *currentloc = - rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); + int eval_flags = RTEMS_FS_FOLLOW_LINK; + const rtems_filesystem_location_info_t + *currentloc = rtems_filesystem_eval_path_start( &ctx, path, eval_flags ); rtems_filesystem_mount_table_entry_t *mt_entry = currentloc->mt_entry; if ( rtems_filesystem_location_is_instance_root( currentloc ) ) { if ( !contains_root_or_current_directory( mt_entry ) ) { - const rtems_filesystem_operations_table *mt_point_ops = - mt_entry->mt_point_node->location.mt_entry->ops; + const rtems_filesystem_operations_table + *mt_point_ops = mt_entry->mt_point_node->location.mt_entry->ops; - rv = (*mt_point_ops->unmount_h)( mt_entry ); + rv = ( *mt_point_ops->unmount_h )( mt_entry ); if ( rv == 0 ) { rtems_id self_task_id = rtems_task_self(); rtems_filesystem_mt_entry_declare_lock_context( lock_context ); diff --git a/cpukit/libcsupport/src/utime.c b/cpukit/libcsupport/src/utime.c index b5b70348fa..2494571df1 100644 --- a/cpukit/libcsupport/src/utime.c +++ b/cpukit/libcsupport/src/utime.c @@ -47,19 +47,16 @@ * * Set file access and modification times */ -int utime( - const char *path, - const struct utimbuf *times -) +int utime( const char *path, const struct utimbuf *times ) { - struct timespec new_times[2]; + struct timespec new_times[ 2 ]; if ( times == NULL ) { - return utimensat(AT_FDCWD, path, NULL, 0); + return utimensat( AT_FDCWD, path, NULL, 0 ); } - _Timespec_Set(&new_times[0], times->actime, 0); - _Timespec_Set(&new_times[1], times->modtime, 0); + _Timespec_Set( &new_times[ 0 ], times->actime, 0 ); + _Timespec_Set( &new_times[ 1 ], times->modtime, 0 ); - return utimensat(AT_FDCWD, path, new_times, 0); + return utimensat( AT_FDCWD, path, new_times, 0 ); } diff --git a/cpukit/libcsupport/src/utimensat.c b/cpukit/libcsupport/src/utimensat.c index c053218ad0..d1ce77b67f 100644 --- a/cpukit/libcsupport/src/utimensat.c +++ b/cpukit/libcsupport/src/utimensat.c @@ -50,7 +50,7 @@ * These guidelines come from the description of the EINVAL errors on * https://pubs.opengroup.org/onlinepubs/9699919799/functions/futimens.html */ -bool rtems_filesystem_utime_tv_nsec_valid(struct timespec time) +bool rtems_filesystem_utime_tv_nsec_valid( struct timespec time ) { if ( time.tv_nsec == UTIME_NOW ) { return true; @@ -73,15 +73,15 @@ bool rtems_filesystem_utime_tv_nsec_valid(struct timespec time) /* Determine whether the access and modified timestamps can be updated */ int rtems_filesystem_utime_check_permissions( - const rtems_filesystem_location_info_t * currentloc, - const struct timespec times[2] + const rtems_filesystem_location_info_t *currentloc, + const struct timespec times[ 2 ] ) { struct stat st = {}; - int rv; - bool write_access; + int rv; + bool write_access; - rv = (*currentloc->handlers->fstat_h)( currentloc, &st ); + rv = ( *currentloc->handlers->fstat_h )( currentloc, &st ); if ( rv != 0 ) { rtems_set_errno_and_return_minus_one( ENOENT ); } @@ -97,13 +97,17 @@ int rtems_filesystem_utime_check_permissions( * The logic for the EACCES error is an inverted subset of the EPERM * conditional according to the POSIX standard. */ - if ( (times == NULL) || - ( (times[0].tv_nsec == UTIME_NOW) && (times[1].tv_nsec == UTIME_NOW) )) { - if ( !write_access ) { - rtems_set_errno_and_return_minus_one( EACCES ); - } + if ( + ( times == NULL ) || ( ( times[ 0 ].tv_nsec == UTIME_NOW ) && + ( times[ 1 ].tv_nsec == UTIME_NOW ) ) + ) { + if ( !write_access ) { + rtems_set_errno_and_return_minus_one( EACCES ); + } } else { - if ( times[0].tv_nsec != UTIME_OMIT || times[1].tv_nsec != UTIME_OMIT ) { + if ( + times[ 0 ].tv_nsec != UTIME_OMIT || times[ 1 ].tv_nsec != UTIME_OMIT + ) { if ( !write_access ) { rtems_set_errno_and_return_minus_one( EPERM ); } @@ -118,11 +122,11 @@ int rtems_filesystem_utime_check_permissions( * whether the values in times are valid. */ int rtems_filesystem_utime_update( - const struct timespec times[2], - struct timespec new_times[2] + const struct timespec times[ 2 ], + struct timespec new_times[ 2 ] ) { - bool got_time = false; + bool got_time = false; struct timespec now; /* @@ -130,39 +134,39 @@ int rtems_filesystem_utime_update( * elements */ if ( times == NULL ) { - _Timespec_Set( &new_times[0], 0, UTIME_NOW ); - _Timespec_Set( &new_times[1], 0, UTIME_NOW ); + _Timespec_Set( &new_times[ 0 ], 0, UTIME_NOW ); + _Timespec_Set( &new_times[ 1 ], 0, UTIME_NOW ); } else { - new_times[0] = times[0]; - new_times[1] = times[1]; + new_times[ 0 ] = times[ 0 ]; + new_times[ 1 ] = times[ 1 ]; } - if ( new_times[0].tv_nsec == UTIME_NOW ) { + if ( new_times[ 0 ].tv_nsec == UTIME_NOW ) { clock_gettime( CLOCK_REALTIME, &now ); - new_times[0] = now; + new_times[ 0 ] = now; got_time = true; } - if ( new_times[1].tv_nsec == UTIME_NOW ) { + if ( new_times[ 1 ].tv_nsec == UTIME_NOW ) { if ( !got_time ) { clock_gettime( CLOCK_REALTIME, &now ); } - new_times[1] = now; + new_times[ 1 ] = now; } - if ( !_Timespec_Is_non_negative( &new_times[0] ) ) { + if ( !_Timespec_Is_non_negative( &new_times[ 0 ] ) ) { rtems_set_errno_and_return_minus_one( EINVAL ); } - if ( !_Timespec_Is_non_negative( &new_times[1] ) ) { + if ( !_Timespec_Is_non_negative( &new_times[ 1 ] ) ) { rtems_set_errno_and_return_minus_one( EINVAL ); } - if ( !rtems_filesystem_utime_tv_nsec_valid( new_times[0] ) ) { + if ( !rtems_filesystem_utime_tv_nsec_valid( new_times[ 0 ] ) ) { rtems_set_errno_and_return_minus_one( EINVAL ); } - if ( !rtems_filesystem_utime_tv_nsec_valid( new_times[1] ) ) { + if ( !rtems_filesystem_utime_tv_nsec_valid( new_times[ 1 ] ) ) { rtems_set_errno_and_return_minus_one( EINVAL ); } @@ -175,17 +179,17 @@ int rtems_filesystem_utime_update( * Set file access and modification times */ int utimensat( - int fd, - const char *path, - const struct timespec times[2], - int flag + int fd, + const char *path, + const struct timespec times[ 2 ], + int flag ) { - int rv = 0; - rtems_filesystem_eval_path_context_t ctx; - int eval_flags = RTEMS_FS_FOLLOW_LINK; + int rv = 0; + rtems_filesystem_eval_path_context_t ctx; + int eval_flags = RTEMS_FS_FOLLOW_LINK; const rtems_filesystem_location_info_t *currentloc = NULL; - struct timespec new_times[2]; + struct timespec new_times[ 2 ]; /* * RTEMS does not currently support operating on a real file descriptor @@ -214,10 +218,7 @@ int utimensat( return rv; } - rv = (*currentloc->mt_entry->ops->utimens_h)( - currentloc, - new_times - ); + rv = ( *currentloc->mt_entry->ops->utimens_h )( currentloc, new_times ); rtems_filesystem_eval_path_cleanup( &ctx ); diff --git a/cpukit/libcsupport/src/utimes.c b/cpukit/libcsupport/src/utimes.c index 9748abb5fd..2dff0849ec 100644 --- a/cpukit/libcsupport/src/utimes.c +++ b/cpukit/libcsupport/src/utimes.c @@ -47,26 +47,23 @@ * * Set file access and modification times */ -int utimes( - const char *path, - const struct timeval times[2] -) +int utimes( const char *path, const struct timeval times[ 2 ] ) { - struct timespec new_times[2]; + struct timespec new_times[ 2 ]; if ( times == NULL ) { - return utimensat( AT_FDCWD, path, NULL , 0 ); + return utimensat( AT_FDCWD, path, NULL, 0 ); } _Timespec_Set( - &new_times[0], - times[0].tv_sec, - times[0].tv_usec * TOD_NANOSECONDS_PER_MICROSECOND + &new_times[ 0 ], + times[ 0 ].tv_sec, + times[ 0 ].tv_usec * TOD_NANOSECONDS_PER_MICROSECOND ); _Timespec_Set( - &new_times[1], - times[1].tv_sec, - times[1].tv_usec * TOD_NANOSECONDS_PER_MICROSECOND + &new_times[ 1 ], + times[ 1 ].tv_sec, + times[ 1 ].tv_usec * TOD_NANOSECONDS_PER_MICROSECOND ); return utimensat( AT_FDCWD, path, new_times, 0 ); diff --git a/cpukit/libcsupport/src/utsname.c b/cpukit/libcsupport/src/utsname.c index 8089222127..c1c2bc6be1 100644 --- a/cpukit/libcsupport/src/utsname.c +++ b/cpukit/libcsupport/src/utsname.c @@ -50,9 +50,7 @@ * 4.4.1 Get System Name, P1003.1b-1993, p. 90 */ -int uname( - struct utsname *name -) +int uname( struct utsname *name ) { /* XXX: Here is what Solaris returns... sysname = SunOS @@ -62,22 +60,30 @@ int uname( machine = sun4m */ - if ( !name ) + if ( !name ) { rtems_set_errno_and_return_minus_one( EFAULT ); + } - strncpy( name->sysname, "RTEMS", sizeof(name->sysname) ); + strncpy( name->sysname, "RTEMS", sizeof( name->sysname ) ); snprintf( name->nodename, - sizeof(name->nodename), - "Node %" PRId16, rtems_object_get_local_node() + sizeof( name->nodename ), + "Node %" PRId16, + rtems_object_get_local_node() ); - strncpy( name->release, RTEMS_VERSION, sizeof(name->release) ); + strncpy( name->release, RTEMS_VERSION, sizeof( name->release ) ); - strncpy( name->version, "", sizeof(name->version) ); + strncpy( name->version, "", sizeof( name->version ) ); - snprintf( name->machine, sizeof(name->machine), "%s/%s", CPU_NAME, CPU_MODEL_NAME ); + snprintf( + name->machine, + sizeof( name->machine ), + "%s/%s", + CPU_NAME, + CPU_MODEL_NAME + ); return 0; } diff --git a/cpukit/libcsupport/src/write.c b/cpukit/libcsupport/src/write.c index a4a24d932c..a8be180ab7 100644 --- a/cpukit/libcsupport/src/write.c +++ b/cpukit/libcsupport/src/write.c @@ -46,11 +46,7 @@ * This routine writes count bytes from from buffer pointed to by buffer * to the file associated with the open file descriptor, fildes. */ -ssize_t write( - int fd, - const void *buffer, - size_t count -) +ssize_t write( int fd, const void *buffer, size_t count ) { rtems_libio_t *iop; ssize_t n; @@ -63,7 +59,7 @@ ssize_t write( /* * Now process the write() request. */ - n = (*iop->pathinfo.handlers->write_h)( iop, buffer, count ); + n = ( *iop->pathinfo.handlers->write_h )( iop, buffer, count ); rtems_libio_iop_drop( iop ); return n; } diff --git a/cpukit/libcsupport/src/write_r.c b/cpukit/libcsupport/src/write_r.c index f82c5c3a5e..29469fd25c 100644 --- a/cpukit/libcsupport/src/write_r.c +++ b/cpukit/libcsupport/src/write_r.c @@ -47,15 +47,15 @@ * This is the Newlib dependent reentrant version of write(). */ -#if defined(RTEMS_NEWLIB) +#if defined( RTEMS_NEWLIB ) #include _ssize_t _write_r( struct _reent *ptr RTEMS_UNUSED, - int fd, - const void *buf, - size_t nbytes + int fd, + const void *buf, + size_t nbytes ) { return write( fd, buf, nbytes ); diff --git a/cpukit/libcsupport/src/writev.c b/cpukit/libcsupport/src/writev.c index a43b6fc0d8..b78f041a9a 100644 --- a/cpukit/libcsupport/src/writev.c +++ b/cpukit/libcsupport/src/writev.c @@ -53,11 +53,7 @@ static ssize_t writev_adapter( return ( *iop->pathinfo.handlers->writev_h )( iop, iov, iovcnt, total ); } -ssize_t writev( - int fd, - const struct iovec *iov, - int iovcnt -) +ssize_t writev( int fd, const struct iovec *iov, int iovcnt ) { return rtems_libio_iovec_eval( fd,