Changeset f6cb995 in mainline


Ignore:
Timestamp:
2012-04-23T22:23:05Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
56b308e
Parents:
8219eb9
Message:

libc: move localtime() from libposix to libc

Location:
uspace/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/time.c

    r8219eb9 rf6cb995  
    798798
    799799        return &result;
    800 
    801800}
    802801
     
    833832}
    834833
     834/**
     835 * Converts a time value to a broken-down local time.
     836 *
     837 * @param timer Time to convert.
     838 * @return Normalized broken-down time in local timezone, NULL on overflow.
     839 */
     840struct tm *localtime(const time_t *timer)
     841{
     842        // TODO: deal with timezone
     843        // currently assumes system and all times are in GMT
     844
     845        static struct tm result;
     846
     847        /* Set result to epoch. */
     848        result.tm_sec = 0;
     849        result.tm_min = 0;
     850        result.tm_hour = 0;
     851        result.tm_mday = 1;
     852        result.tm_mon = 0;
     853        result.tm_year = 70; /* 1970 */
     854
     855        if (_normalize_time(&result, *timer) == -1) {
     856                errno = EOVERFLOW;
     857                return NULL;
     858        }
     859
     860        return &result;
     861}
    835862
    836863/** @}
  • uspace/lib/c/include/sys/time.h

    r8219eb9 rf6cb995  
    8282extern struct tm *gmtime(const time_t *timer);
    8383extern char *asctime(const struct tm *timeptr);
     84extern struct tm *localtime(const time_t *timer);
    8485extern size_t strftime(char *restrict s, size_t maxsize,
    8586    const char *restrict format, const struct tm *restrict tm);
  • uspace/lib/posix/time.c

    r8219eb9 rf6cb995  
    353353/**
    354354 * Converts a time value to a broken-down local time.
    355  *
    356  * @param timer Time to convert.
    357  * @return Normalized broken-down time in local timezone, NULL on overflow.
    358  */
    359 struct tm *posix_localtime(const time_t *timer)
    360 {
    361         static struct tm result;
    362         return posix_localtime_r(timer, &result);
    363 }
    364 
    365 /**
    366  * Converts a time value to a broken-down local time.
    367355 *
    368356 * @param timer Time to convert.
     
    419407char *posix_ctime(const time_t *timer)
    420408{
    421         struct tm *loctime = posix_localtime(timer);
     409        struct tm *loctime = localtime(timer);
    422410        if (loctime == NULL) {
    423411                return NULL;
  • uspace/lib/posix/time.h

    r8219eb9 rf6cb995  
    9090extern struct tm *posix_gmtime_r(const time_t *restrict timer,
    9191    struct tm *restrict result);
    92 extern struct tm *posix_localtime(const time_t *timer);
    9392extern struct tm *posix_localtime_r(const time_t *restrict timer,
    9493    struct tm *restrict result);
     
    126125
    127126        #define gmtime_r posix_gmtime_r
    128         #define localtime posix_localtime
    129127        #define localtime_r posix_localtime_r
    130128
Note: See TracChangeset for help on using the changeset viewer.