Changeset 670
- Timestamp:
- Dec 3, 2011, 4:23:50 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/source3/utils/net_time.c
r414 r670 20 20 #include "utils/net.h" 21 21 22 #ifdef __OS2__ 23 #define INCL_DOSNLS /* National Language Support values */ 24 #define INCL_DOSERRORS /* DOS error values */ 25 #include <os2.h> 26 #endif 27 22 28 /* 23 29 return the time on a server. This does not require any authentication … … 91 97 tm->tm_min, tm->tm_year + 1900, tm->tm_sec); 92 98 } 99 #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) 102 { 103 struct tm *tm; 104 105 tm = localtime(&t); 106 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 131 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 */ 158 } 159 #endif 93 160 94 161 int net_time_usage(struct net_context *c, int argc, const char **argv) … … 113 180 if (t == 0) return -1; 114 181 182 #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)); 200 #else 115 201 /* yes, I know this is cheesy. Use "net time system" if you want to 116 202 roll your own. I'm putting this in as it works on a large number … … 123 209 d_fprintf(stderr, _("%s failed. Error was (%s)\n"), 124 210 cmd, strerror(errno)); 211 #endif 125 212 free(cmd); 126 213
Note:
See TracChangeset
for help on using the changeset viewer.