source: rtems/cpukit/libmisc/shell/main_sleep.c

Last change on this file was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • 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.org/license/LICENSE.
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <stdio.h>
17#include <time.h>
18
19#include <rtems.h>
20#include <rtems/shell.h>
21#include <rtems/stringto.h>
22#include "internal.h"
23
24static int rtems_shell_main_sleep(
25  int   argc,
26  char *argv[]
27)
28{
29  struct timespec delay;
30  unsigned long   tmp;
31
32  if ((argc != 2) && (argc != 3)) {
33    fprintf( stderr, "%s: Usage seconds [nanoseconds]\n", argv[0] );
34    return -1;
35  }
36
37  /*
38   *  Convert the seconds argument to a number
39   */
40  if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
41    printf( "Seconds argument (%s) is not a number\n", argv[1] );
42    return -1;
43  }
44  delay.tv_sec = (time_t) tmp;
45
46  /*
47   *  If the user specified a nanoseconds argument, convert it
48   */
49  delay.tv_nsec = 0;
50  if (argc == 3) {
51    if ( rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
52      printf( "Seconds argument (%s) is not a number\n", argv[1] );
53      return -1;
54    }
55    delay.tv_nsec = tmp;
56  }
57
58  /*
59   *  Now sleep as requested.
60   */
61  nanosleep( &delay, NULL );
62  return 0;
63}
64
65rtems_shell_cmd_t rtems_shell_SLEEP_Command = {
66  "sleep",                       /* name */
67  "sleep seconds [nanoseconds]", /* usage */
68  "misc",                        /* topic */
69  rtems_shell_main_sleep,        /* command */
70  NULL,                          /* alias */
71  NULL                           /* next */
72};
Note: See TracBrowser for help on using the repository browser.