Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:19

0001 /*
0002  *  Sleep Shell Command Implmentation
0003  *
0004  *  COPYRIGHT (c) 1989-2008.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  *  The license and distribution terms for this file may be
0008  *  found in the file LICENSE in this distribution or at
0009  *  http://www.rtems.org/license/LICENSE.
0010  */
0011 
0012 #ifdef HAVE_CONFIG_H
0013 #include "config.h"
0014 #endif
0015 
0016 #include <stdio.h>
0017 #include <time.h>
0018 
0019 #include <rtems.h>
0020 #include <rtems/shell.h>
0021 #include <rtems/stringto.h>
0022 #include "internal.h"
0023 
0024 static int rtems_shell_main_sleep(
0025   int   argc,
0026   char *argv[]
0027 )
0028 {
0029   struct timespec delay;
0030   unsigned long   tmp;
0031 
0032   if ((argc != 2) && (argc != 3)) {
0033     fprintf( stderr, "%s: Usage seconds [nanoseconds]\n", argv[0] );
0034     return -1;
0035   }
0036 
0037   /*
0038    *  Convert the seconds argument to a number
0039    */
0040   if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
0041     printf( "Seconds argument (%s) is not a number\n", argv[1] );
0042     return -1;
0043   }
0044   delay.tv_sec = (time_t) tmp;
0045 
0046   /*
0047    *  If the user specified a nanoseconds argument, convert it
0048    */
0049   delay.tv_nsec = 0;
0050   if (argc == 3) {
0051     if ( rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
0052       printf( "Seconds argument (%s) is not a number\n", argv[1] );
0053       return -1;
0054     }
0055     delay.tv_nsec = tmp;
0056   }
0057 
0058   /*
0059    *  Now sleep as requested.
0060    */
0061   nanosleep( &delay, NULL );
0062   return 0;
0063 }
0064 
0065 rtems_shell_cmd_t rtems_shell_SLEEP_Command = {
0066   "sleep",                       /* name */
0067   "sleep seconds [nanoseconds]", /* usage */
0068   "misc",                        /* topic */
0069   rtems_shell_main_sleep,        /* command */
0070   NULL,                          /* alias */
0071   NULL                           /* next */
0072 };