Changes in / [8595b954:ce1df04] in mainline
- File:
-
- 1 edited
-
uspace/app/date/date.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/date/date.c
r8595b954 rce1df04 41 41 static int read_date_from_arg(char *wdate, struct tm *t); 42 42 static int read_time_from_arg(char *wdate, struct tm *t); 43 static int read_num_from_str(char *str, size_t len, int *n); 43 44 static int tm_sanity_check(struct tm *t); 44 45 static bool is_leap_year(int year); … … 201 202 { 202 203 int rc; 203 uint32_t tmp;204 204 205 205 if (str_size(wdate) != 10) /* str_size("DD/MM/YYYY") == 10 */ … … 211 211 } 212 212 213 rc = str_uint32_t(&wdate[0], NULL, 10, false, &tmp);213 rc = read_num_from_str(&wdate[0], 2, &t->tm_mday); 214 214 if (rc != EOK) 215 215 return rc; 216 216 217 t->tm_mday = tmp; 218 219 rc = str_uint32_t(&wdate[3], NULL, 10, false, &tmp); 217 rc = read_num_from_str(&wdate[3], 2, &t->tm_mon); 220 218 if (rc != EOK) 221 219 return rc; 222 223 t->tm_mon = tmp - 1; 224 225 rc = str_uint32_t(&wdate[6], NULL, 10, false, &tmp); 226 t->tm_year = tmp - 1900; 227 220 t->tm_mon--; 221 222 rc = read_num_from_str(&wdate[6], 4, &t->tm_year); 223 t->tm_year -= 1900; 228 224 return rc; 229 225 } … … 238 234 size_t len = str_size(wtime); 239 235 bool sec_present = len == 8; 240 uint32_t tmp;241 236 242 237 /* str_size("HH:MM") == 5 */ … … 251 246 return EINVAL; 252 247 253 rc = str_uint32_t(&wtime[0], NULL, 10, false, &tmp);248 rc = read_num_from_str(&wtime[0], 2, &t->tm_hour); 254 249 if (rc != EOK) 255 250 return rc; 256 251 257 t->tm_hour = tmp; 258 259 rc = str_uint32_t(&wtime[3], NULL, 10, false, &tmp); 252 rc = read_num_from_str(&wtime[3], 2, &t->tm_min); 260 253 if (rc != EOK) 261 254 return rc; 262 255 263 t->tm_min = tmp; 264 265 if (sec_present) { 266 rc = str_uint32_t(&wtime[6], NULL, 10, false, &tmp); 267 t->tm_sec = tmp; 268 } else 256 if (sec_present) 257 rc = read_num_from_str(&wtime[6], 2, &t->tm_sec); 258 else 269 259 t->tm_sec = 0; 270 260 271 261 return rc; 262 } 263 264 static int 265 read_num_from_str(char *str, size_t len, int *n) 266 { 267 size_t i; 268 269 *n = 0; 270 271 for (i = 0; i < len; ++i, ++str) { 272 if (!isdigit(*str)) 273 return EINVAL; 274 *n *= 10; 275 *n += *str - '0'; 276 } 277 278 return EOK; 272 279 } 273 280
Note:
See TracChangeset
for help on using the changeset viewer.
