source: rtems/cpukit/libmisc/shell/main_sleep.c @ 35d09ba

4.104.115
Last change on this file since 35d09ba was 35d09ba, checked in by Joel Sherrill <joel.sherrill@…>, on 07/22/09 at 15:17:37

2009-07-22 Joel Sherrill <joel.sherrill@…>

  • 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.
  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 *  Sleep Shell Command Implmentation
3 *
4 *  COPYRIGHT (c) 1989-2008.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <stdio.h>
19#include <time.h>
20
21#include <rtems.h>
22#include <rtems/shell.h>
23#include <rtems/stringto.h>
24#include "internal.h"
25
26int rtems_shell_main_sleep(
27  int   argc,
28  char *argv[]
29)
30{
31  struct timespec delay;
32  unsigned long   tmp;
33
34  if ((argc != 2) && (argc != 3)) {
35    fprintf( stderr, "%s: Usage seconds [nanoseconds]\n", argv[0] );
36    return -1;
37  }
38
39  /*
40   *  Convert the seconds argument to a number
41   */
42  if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
43    printf( "Seconds argument (%s) is not a number\n", argv[1] );
44    return -1;
45  }
46  delay.tv_sec = (time_t) tmp;
47
48  /*
49   *  If the user specified a nanoseconds argument, convert it
50   */
51  delay.tv_nsec = 0;
52  if (argc == 3) {
53    if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
54      printf( "Seconds argument (%s) is not a number\n", argv[1] );
55      return -1;
56    }
57    delay.tv_nsec = tmp;
58  }
59
60  /*
61   *  Now sleep as requested.
62   */
63  nanosleep( &delay, NULL );
64  return 0;
65}
66
67rtems_shell_cmd_t rtems_shell_SLEEP_Command = {
68  "sleep",                       /* name */
69  "sleep seconds [nanoseconds]", /* usage */
70  "misc",                        /* topic */
71  rtems_shell_main_sleep,        /* command */
72  NULL,                          /* alias */
73  NULL                           /* next */
74};
Note: See TracBrowser for help on using the repository browser.