4.104.115
Line | |
---|
1 | /* |
---|
2 | * DATE Shell Command Implmentation |
---|
3 | * |
---|
4 | * OAuthor: Fernando RUIZ CASAS |
---|
5 | * Work: fernando.ruiz@ctv.es |
---|
6 | * Home: correo@fernando-ruiz.com |
---|
7 | * |
---|
8 | * Significantly rewritten by Joel Sherrill <joel.sherrill@oarcorp.com>. |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | * |
---|
14 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #ifdef HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <stdio.h> |
---|
22 | #include <unistd.h> |
---|
23 | #include <string.h> |
---|
24 | #include <errno.h> |
---|
25 | |
---|
26 | #include <rtems.h> |
---|
27 | #include <rtems/shell.h> |
---|
28 | #include "internal.h" |
---|
29 | |
---|
30 | int rtems_shell_main_date( |
---|
31 | int argc, |
---|
32 | char *argv[] |
---|
33 | ) |
---|
34 | { |
---|
35 | /* |
---|
36 | * Print the current date and time in default format. |
---|
37 | */ |
---|
38 | if ( argc == 1 ) { |
---|
39 | time_t t; |
---|
40 | |
---|
41 | time(&t); |
---|
42 | printf("%s", ctime(&t)); |
---|
43 | return 0; |
---|
44 | } |
---|
45 | |
---|
46 | /* |
---|
47 | * Set the current date and time |
---|
48 | */ |
---|
49 | if ( argc == 3 ) { |
---|
50 | char buf[128]; |
---|
51 | struct tm TOD; |
---|
52 | struct timespec timesp; |
---|
53 | char *result; |
---|
54 | |
---|
55 | sprintf( buf, "%s %s", argv[1], argv[2] ); |
---|
56 | result = strptime( |
---|
57 | buf, |
---|
58 | "%Y-%m-%d %T", |
---|
59 | &TOD |
---|
60 | ); |
---|
61 | if ( result && !*result ) { |
---|
62 | timesp.tv_sec = mktime( &TOD ); |
---|
63 | timesp.tv_nsec = 0; |
---|
64 | clock_settime( CLOCK_REALTIME, ×p ); |
---|
65 | return 0; |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | fprintf( stderr, "%s: Usage: [YYYY-MM-DD HH:MM:SS]\n", argv[0] ); |
---|
70 | return -1; |
---|
71 | } |
---|
72 | |
---|
73 | rtems_shell_cmd_t rtems_shell_DATE_Command = { |
---|
74 | "date", /* name */ |
---|
75 | "date [YYYY-MM-DD HH:MM:SS]", /* usage */ |
---|
76 | "misc", /* topic */ |
---|
77 | rtems_shell_main_date, /* command */ |
---|
78 | NULL, /* alias */ |
---|
79 | NULL /* next */ |
---|
80 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.