Changeset df7f9fb5 in mainline
- Timestamp:
- 2012-09-18T19:21:16Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0a586f4c, 8595b954
- Parents:
- 7137fe3f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/date/date.c
r7137fe3f rdf7f9fb5 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);44 43 static int tm_sanity_check(struct tm *t); 45 44 static bool is_leap_year(int year); … … 202 201 { 203 202 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 = read_num_from_str(&wdate[0], 2, &t->tm_mday);213 rc = str_uint32_t(&wdate[0], NULL, 10, false, &tmp); 214 214 if (rc != EOK) 215 215 return rc; 216 216 217 rc = read_num_from_str(&wdate[3], 2, &t->tm_mon); 217 t->tm_mday = tmp; 218 219 rc = str_uint32_t(&wdate[3], NULL, 10, false, &tmp); 218 220 if (rc != EOK) 219 221 return rc; 220 t->tm_mon--; 221 222 rc = read_num_from_str(&wdate[6], 4, &t->tm_year); 223 t->tm_year -= 1900; 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 224 228 return rc; 225 229 } … … 234 238 size_t len = str_size(wtime); 235 239 bool sec_present = len == 8; 240 uint32_t tmp; 236 241 237 242 /* str_size("HH:MM") == 5 */ … … 246 251 return EINVAL; 247 252 248 rc = read_num_from_str(&wtime[0], 2, &t->tm_hour);253 rc = str_uint32_t(&wtime[0], NULL, 10, false, &tmp); 249 254 if (rc != EOK) 250 255 return rc; 251 256 252 rc = read_num_from_str(&wtime[3], 2, &t->tm_min); 257 t->tm_hour = tmp; 258 259 rc = str_uint32_t(&wtime[3], NULL, 10, false, &tmp); 253 260 if (rc != EOK) 254 261 return rc; 255 262 256 if (sec_present) 257 rc = read_num_from_str(&wtime[6], 2, &t->tm_sec); 258 else 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 259 269 t->tm_sec = 0; 260 270 261 271 return rc; 262 }263 264 static int265 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;279 272 } 280 273
Note:
See TracChangeset
for help on using the changeset viewer.