diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-07-22 15:17:37 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-07-22 15:17:37 +0000 |
commit | 35d09baa84f3e029646e3a2f2f0e9b348de57517 (patch) | |
tree | 9e108a9d304ab73d8e596b65dae1b83f82b6d095 /cpukit/libmisc/shell/main_sleep.c | |
parent | 2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-35d09baa84f3e029646e3a2f2f0e9b348de57517.tar.bz2 |
2009-07-22 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/Makefile.am, libmisc/shell/main_chmod.c,
libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c,
libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c,
libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c,
libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c,
libmisc/shell/shell.h, libmisc/shell/shell_script.c,
libmisc/stringto/stringto_template.h: Convert all shell code to use
stringto.h mehods with better error checking.
* libmisc/shell/str2int.c: Removed.
Diffstat (limited to 'cpukit/libmisc/shell/main_sleep.c')
-rw-r--r-- | cpukit/libmisc/shell/main_sleep.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/cpukit/libmisc/shell/main_sleep.c b/cpukit/libmisc/shell/main_sleep.c index 6ee4cef614..b153f62d37 100644 --- a/cpukit/libmisc/shell/main_sleep.c +++ b/cpukit/libmisc/shell/main_sleep.c @@ -20,6 +20,7 @@ #include <rtems.h> #include <rtems/shell.h> +#include <rtems/stringto.h> #include "internal.h" int rtems_shell_main_sleep( @@ -28,23 +29,39 @@ int rtems_shell_main_sleep( ) { struct timespec delay; + unsigned long tmp; - if (argc == 2) { - delay.tv_sec = rtems_shell_str2int(argv[1]); - delay.tv_nsec = 0; - nanosleep( &delay, NULL ); - return 0; + if ((argc != 2) && (argc != 3)) { + fprintf( stderr, "%s: Usage seconds [nanoseconds]\n", argv[0] ); + return -1; } - + + /* + * Convert the seconds argument to a number + */ + if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) { + printf( "Seconds argument (%s) is not a number\n", argv[1] ); + return -1; + } + delay.tv_sec = (time_t) tmp; + + /* + * If the user specified a nanoseconds argument, convert it + */ + delay.tv_nsec = 0; if (argc == 3) { - delay.tv_sec = rtems_shell_str2int(argv[1]); - delay.tv_nsec = rtems_shell_str2int(argv[2]); - nanosleep( &delay, NULL ); - return 0; + if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) { + printf( "Seconds argument (%s) is not a number\n", argv[1] ); + return -1; + } + delay.tv_nsec = tmp; } - - fprintf( stderr, "%s: Usage seconds [nanoseconds]\n", argv[0] ); - return -1; + + /* + * Now sleep as requested. + */ + nanosleep( &delay, NULL ); + return 0; } rtems_shell_cmd_t rtems_shell_SLEEP_Command = { |