Changes in / [4cade47:86e81a9] in mainline
- Location:
- uspace/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/sys/time.h
r4cade47 r86e81a9 1 1 /* 2 2 * Copyright (c) 2006 Ondrej Palkovsky 3 * Copyright (c) 2011 Petr Koupy4 * Copyright (c) 2011 Jiri Zarevucky5 3 * All rights reserved. 6 4 * … … 49 47 50 48 struct tm { 51 int tm_sec; /* Seconds [0,60]. */ 52 int tm_min; /* Minutes [0,59]. */ 53 int tm_hour; /* Hour [0,23]. */ 54 int tm_mday; /* Day of month [1,31]. */ 55 int tm_mon; /* Month of year [0,11]. */ 56 int tm_year; /* Years since 1900. */ 57 int tm_wday; /* Day of week [0,6] (Sunday = 0). */ 58 int tm_yday; /* Day of year [0,365]. */ 59 int tm_isdst; /* Daylight Savings flag. */ 49 int tm_sec; /* 0 - 59 */ 50 int tm_min; /* 0 - 59 */ 51 int tm_hour; /* 0 - 23 */ 52 int tm_mday; /* 1 - 31 */ 53 int tm_mon; /* 0 - 11 */ 54 int tm_year; /* years since 1900 */ 60 55 }; 61 56 -
uspace/lib/posix/time.c
r4cade47 r86e81a9 200 200 * @return Number of seconds since the epoch, not counting leap seconds. 201 201 */ 202 static time_t _secs_since_epoch(const struct tm *tm)202 static time_t _secs_since_epoch(const struct posix_tm *tm) 203 203 { 204 204 return _days_since_epoch(tm->tm_year, tm->tm_mon, tm->tm_mday) * … … 229 229 * @return 0 on success, -1 on overflow 230 230 */ 231 static int _normalize_time(struct tm *tm, time_t sec_add)231 static int _normalize_time(struct posix_tm *tm, time_t sec_add) 232 232 { 233 233 // TODO: DST correction … … 324 324 * @return Week-based year. 325 325 */ 326 static int _wbyear(const struct tm *tm)326 static int _wbyear(const struct posix_tm *tm) 327 327 { 328 328 int day = tm->tm_yday - _wbyear_offset(tm->tm_year); … … 347 347 * @return The week number (0 - 53). 348 348 */ 349 static int _sun_week_number(const struct tm *tm)349 static int _sun_week_number(const struct posix_tm *tm) 350 350 { 351 351 int first_day = (7 - _day_of_week(tm->tm_year, 0, 1)) % 7; … … 363 363 * @return The week number (1 - 53). 364 364 */ 365 static int _iso_week_number(const struct tm *tm)365 static int _iso_week_number(const struct posix_tm *tm) 366 366 { 367 367 int day = tm->tm_yday - _wbyear_offset(tm->tm_year); … … 386 386 * @return The week number (0 - 53). 387 387 */ 388 static int _mon_week_number(const struct tm *tm)388 static int _mon_week_number(const struct posix_tm *tm) 389 389 { 390 390 int first_day = (1 - _day_of_week(tm->tm_year, 0, 1)) % 7; … … 430 430 * @return time_t representation of the time, undefined value on overflow. 431 431 */ 432 time_t posix_mktime(struct tm *tm)432 time_t posix_mktime(struct posix_tm *tm) 433 433 { 434 434 // TODO: take DST flag into account … … 445 445 * @return Normalized broken-down time in UTC, NULL on overflow. 446 446 */ 447 struct tm *posix_gmtime(const time_t *timer)447 struct posix_tm *posix_gmtime(const time_t *timer) 448 448 { 449 449 assert(timer != NULL); 450 450 451 static struct tm result;451 static struct posix_tm result; 452 452 return posix_gmtime_r(timer, &result); 453 453 } … … 460 460 * @return Value of result on success, NULL on overflow. 461 461 */ 462 struct tm *posix_gmtime_r(const time_t *restrict timer,463 struct tm *restrict result)462 struct posix_tm *posix_gmtime_r(const time_t *restrict timer, 463 struct posix_tm *restrict result) 464 464 { 465 465 assert(timer != NULL); … … 488 488 * @return Normalized broken-down time in local timezone, NULL on overflow. 489 489 */ 490 struct tm *posix_localtime(const time_t *timer)491 { 492 static struct tm result;490 struct posix_tm *posix_localtime(const time_t *timer) 491 { 492 static struct posix_tm result; 493 493 return posix_localtime_r(timer, &result); 494 494 } … … 501 501 * @return Value of result on success, NULL on overflow. 502 502 */ 503 struct tm *posix_localtime_r(const time_t *restrict timer,504 struct tm *restrict result)503 struct posix_tm *posix_localtime_r(const time_t *restrict timer, 504 struct posix_tm *restrict result) 505 505 { 506 506 // TODO: deal with timezone … … 516 516 * @return Pointer to a statically allocated string. 517 517 */ 518 char *posix_asctime(const struct tm *timeptr)518 char *posix_asctime(const struct posix_tm *timeptr) 519 519 { 520 520 static char buf[ASCTIME_BUF_LEN]; … … 531 531 * @return Value of buf. 532 532 */ 533 char *posix_asctime_r(const struct tm *restrict timeptr,533 char *posix_asctime_r(const struct posix_tm *restrict timeptr, 534 534 char *restrict buf) 535 535 { … … 563 563 char *posix_ctime(const time_t *timer) 564 564 { 565 struct tm *loctime = posix_localtime(timer);565 struct posix_tm *loctime = posix_localtime(timer); 566 566 if (loctime == NULL) { 567 567 return NULL; … … 580 580 char *posix_ctime_r(const time_t *timer, char *buf) 581 581 { 582 struct tm loctime;582 struct posix_tm loctime; 583 583 if (posix_localtime_r(timer, &loctime) == NULL) { 584 584 return NULL; … … 598 598 */ 599 599 size_t posix_strftime(char *restrict s, size_t maxsize, 600 const char *restrict format, const struct tm *restrict tm)600 const char *restrict format, const struct posix_tm *restrict tm) 601 601 { 602 602 assert(s != NULL); -
uspace/lib/posix/time.h
r4cade47 r86e81a9 69 69 #define CLOCK_REALTIME ((posix_clockid_t) 0) 70 70 71 struct posix_tm { 72 int tm_sec; /* Seconds [0,60]. */ 73 int tm_min; /* Minutes [0,59]. */ 74 int tm_hour; /* Hour [0,23]. */ 75 int tm_mday; /* Day of month [1,31]. */ 76 int tm_mon; /* Month of year [0,11]. */ 77 int tm_year; /* Years since 1900. */ 78 int tm_wday; /* Day of week [0,6] (Sunday = 0). */ 79 int tm_yday; /* Day of year [0,365]. */ 80 int tm_isdst; /* Daylight Savings flag. */ 81 }; 82 71 83 struct posix_timespec { 72 84 time_t tv_sec; /* Seconds. */ … … 91 103 92 104 /* Broken-down Time */ 93 extern time_t posix_mktime(struct tm *tm);94 extern struct tm *posix_gmtime(const time_t *timer);95 extern struct tm *posix_gmtime_r(const time_t *restrict timer,96 struct tm *restrict result);97 extern struct tm *posix_localtime(const time_t *timer);98 extern struct tm *posix_localtime_r(const time_t *restrict timer,99 struct tm *restrict result);105 extern time_t posix_mktime(struct posix_tm *tm); 106 extern struct posix_tm *posix_gmtime(const time_t *timer); 107 extern struct posix_tm *posix_gmtime_r(const time_t *restrict timer, 108 struct posix_tm *restrict result); 109 extern struct posix_tm *posix_localtime(const time_t *timer); 110 extern struct posix_tm *posix_localtime_r(const time_t *restrict timer, 111 struct posix_tm *restrict result); 100 112 101 113 /* Formatting Calendar Time */ 102 extern char *posix_asctime(const struct tm *timeptr);103 extern char *posix_asctime_r(const struct tm *restrict timeptr,114 extern char *posix_asctime(const struct posix_tm *timeptr); 115 extern char *posix_asctime_r(const struct posix_tm *restrict timeptr, 104 116 char *restrict buf); 105 117 extern char *posix_ctime(const time_t *timer); 106 118 extern char *posix_ctime_r(const time_t *timer, char *buf); 107 119 extern size_t posix_strftime(char *restrict s, size_t maxsize, 108 const char *restrict format, const struct tm *restrict tm);120 const char *restrict format, const struct posix_tm *restrict tm); 109 121 110 122 /* Clocks */ … … 122 134 123 135 #ifndef LIBPOSIX_INTERNAL 136 #define tm posix_tm 124 137 #define timespec posix_timespec 125 138 #define itimerspec posix_itimerspec
Note:
See TracChangeset
for help on using the changeset viewer.