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 | |
---|
26 | int 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 | |
---|
67 | rtems_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 | }; |
---|