Changeset 671
- Timestamp:
- Dec 3, 2011, 4:41:18 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/source3/utils/net_time.c
r670 r671 21 21 22 22 #ifdef __OS2__ 23 #define INCL_DOS NLS /* National Language Supportvalues */23 #define INCL_DOSDATETIME /* Date and time values */ 24 24 #define INCL_DOSERRORS /* DOS error values */ 25 25 #include <os2.h> … … 97 97 tm->tm_min, tm->tm_year + 1900, tm->tm_sec); 98 98 } 99 99 100 #ifdef __OS2__ 100 /* return time as a string ready to be passed to cmd time command*/101 static const char *os2_systime(time_t t)101 /* set date/time on OS/2 */ 102 static int os2_setdatetime(time_t t) 102 103 { 103 104 struct tm *tm; … … 105 106 tm = localtime(&t); 106 107 if (!tm) { 107 return "unknown"; 108 } 109 110 return talloc_asprintf(talloc_tos(), "%02d:%02d:%02d", 111 tm->tm_hour, tm->tm_min, tm->tm_sec); 112 } 113 114 /* return a date as a string ready to be passed to cmd date command */ 115 static const char *os2_sysdate(time_t t) 116 { 117 struct tm *tm; 118 119 tm = localtime(&t); 120 if (!tm) { 121 return "unknown"; 122 } 123 124 COUNTRYCODE Country = {0}; /* Country code info (0 = current country) */ 125 COUNTRYINFO CtryInfo = {0}; /* Buffer for country-specific information */ 126 ULONG ulInfoLen = 0; 127 APIRET rc = NO_ERROR; /* Return code */ 128 129 rc = DosQueryCtryInfo(sizeof(CtryInfo), &Country, &CtryInfo, &ulInfoLen); 130 108 return -1; 109 } 110 111 DATETIME DateTime = {0}; /* Structure to hold date/time info. */ 112 APIRET rc = NO_ERROR; /* Return code */ 113 114 rc = DosGetDateTime(&DateTime); /* Get current date/time to fill structure */ 131 115 if (rc != NO_ERROR) { 132 printf("DosQueryCtryInfo error: return code = %u\n",rc); 133 return talloc_asprintf(talloc_tos(), "%02d.%02d.%04d", 134 tm->tm_mon+1, tm->tm_mday, tm->tm_year + 1900); 135 } 136 switch (CtryInfo.fsDateFmt) { 137 case(1): /* dd/mm/yy */ 138 return talloc_asprintf(talloc_tos(), "%02d%s%02d%s%04d", 139 tm->tm_mday, CtryInfo.szDateSeparator, 140 tm->tm_mon+1, CtryInfo.szDateSeparator, 141 tm->tm_year + 1900); 142 break; 143 144 case(2): /* yy/mm/dd */ 145 return talloc_asprintf(talloc_tos(), "%04d%s%02d%s%02d", 146 tm->tm_year + 1900, CtryInfo.szDateSeparator, 147 tm->tm_mon+1, CtryInfo.szDateSeparator, 148 tm->tm_mday); 149 break; 150 151 default: /* mm/dd/yy */ 152 return talloc_asprintf(talloc_tos(), "%02d%s%02d%s%04d", 153 tm->tm_mday, CtryInfo.szDateSeparator, 154 tm->tm_mon+1, CtryInfo.szDateSeparator, 155 tm->tm_year + 1900); 156 break; 157 } /* endswitch */ 116 return rc; 117 } 118 119 DateTime.year = (USHORT) ((BYTE) tm->tm_year+1900); 120 DateTime.month = (UCHAR) ((BYTE) tm->tm_mon+1); 121 DateTime.day = (UCHAR) ((BYTE) tm->tm_mday); 122 DateTime.hours = (UCHAR) ((BYTE) tm->tm_hour); 123 DateTime.minutes = (UCHAR) ((BYTE) tm->tm_min); 124 DateTime.seconds = (UCHAR) ((BYTE) tm->tm_sec); 125 126 rc = DosSetDateTime(&DateTime); /* Update the date and time */ 127 128 if (rc!= NO_ERROR) { 129 printf ("DosSetDateTime error : return code = %u\n", rc); 130 } 131 return rc; 158 132 } 159 133 #endif … … 181 155 182 156 #ifdef __OS2__ 183 /* eCS (OS/2) "net time set" routine */ 184 /* First we set the time using cmd internal time command */ 185 if (asprintf(&cmd, "time %s", os2_systime(t)) == -1) { 186 return -1; 187 } 188 result = system(cmd); 189 if (result) 190 d_fprintf(stderr, _("eCS (OS/2) time set: %s failed. Error was (%s)\n"), 191 cmd, strerror(errno)); 192 /* Then we set the date using cmd internal date command */ 193 if (asprintf(&cmd, "date %s", os2_sysdate(t)) == -1) { 194 return -1; 195 } 196 result = system(cmd); 197 if (result) 198 d_fprintf(stderr, _("eCS (OS/2) date set: %s failed. Error was (%s)\n"), 199 cmd, strerror(errno)); 157 /* eCS (OS/2) native "net time set" routine */ 158 result = os2_setdatetime(t); 200 159 #else 201 160 /* yes, I know this is cheesy. Use "net time system" if you want to … … 206 165 } 207 166 result = system(cmd); 167 #endif 208 168 if (result) 209 169 d_fprintf(stderr, _("%s failed. Error was (%s)\n"), 210 170 cmd, strerror(errno)); 211 #endif212 171 free(cmd); 213 172
Note:
See TracChangeset
for help on using the changeset viewer.