File indexing completed on 2025-05-11 08:24:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #define _XOPEN_SOURCE
0017
0018 #ifdef HAVE_CONFIG_H
0019 #include "config.h"
0020 #endif
0021
0022 #include <stdio.h>
0023 #include <unistd.h>
0024 #include <string.h>
0025 #include <errno.h>
0026 #include <time.h>
0027
0028 #include <rtems.h>
0029 #include <rtems/shell.h>
0030 #include "internal.h"
0031
0032 static int rtems_shell_main_date(
0033 int argc,
0034 char *argv[]
0035 )
0036 {
0037
0038
0039
0040 if ( argc == 1 ) {
0041 time_t t;
0042
0043 time(&t);
0044 printf("%s", ctime(&t));
0045 return 0;
0046 }
0047
0048
0049
0050
0051 if ( argc == 3 ) {
0052 char buf[128];
0053 struct tm TOD;
0054 struct timespec timesp;
0055 char *result;
0056
0057 snprintf( buf, sizeof(buf), "%s %s", argv[1], argv[2] );
0058 result = strptime(
0059 buf,
0060 "%Y-%m-%d %T",
0061 &TOD
0062 );
0063 if ( result && !*result ) {
0064 timesp.tv_sec = mktime( &TOD );
0065 timesp.tv_nsec = 0;
0066 clock_settime( CLOCK_REALTIME, ×p );
0067 return 0;
0068 }
0069 }
0070
0071 fprintf( stderr, "%s: Usage: [YYYY-MM-DD HH:MM:SS]\n", argv[0] );
0072 return -1;
0073 }
0074
0075 rtems_shell_cmd_t rtems_shell_DATE_Command = {
0076 "date",
0077 "date [YYYY-MM-DD HH:MM:SS]",
0078 "misc",
0079 rtems_shell_main_date,
0080 NULL,
0081 NULL
0082 };