Changeset 8219eb9 in mainline


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

libc: move asctime() from libposix to libc

Location:
uspace/lib
Files:
4 edited

Legend:

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

    r5b3394c r8219eb9  
    4848#include <stdio.h>
    4949#include <ctype.h>
     50
     51#define ASCTIME_BUF_LEN 26
    5052
    5153/** Pointer to kernel shared variables with time */
     
    799801}
    800802
     803/**
     804 * Converts broken-down time to a string in format
     805 * "Sun Jan 1 00:00:00 1970\n". (Obsolete)
     806 *
     807 * @param timeptr Broken-down time structure.
     808 * @return Pointer to a statically allocated string.
     809 */
     810char *asctime(const struct tm *timeptr)
     811{
     812        static char buf[ASCTIME_BUF_LEN];
     813
     814        assert(timeptr != NULL);
     815
     816        static const char *wday[] = {
     817                "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
     818        };
     819        static const char *mon[] = {
     820                "Jan", "Feb", "Mar", "Apr", "May", "Jun",
     821                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
     822        };
     823
     824        snprintf(buf, ASCTIME_BUF_LEN, "%s %s %2d %02d:%02d:%02d %d\n",
     825            wday[timeptr->tm_wday],
     826            mon[timeptr->tm_mon],
     827            timeptr->tm_mday, timeptr->tm_hour,
     828            timeptr->tm_min, timeptr->tm_sec,
     829            1900 + timeptr->tm_year);
     830
     831        return buf;
     832
     833}
     834
    801835
    802836/** @}
  • uspace/lib/c/include/sys/time.h

    r5b3394c r8219eb9  
    4141
    4242#define DST_NONE 0
     43#define ASCTIME_BUF_LEN 26
    4344
    4445typedef long time_t;
     
    8081extern time_t mktime(struct tm *tm);
    8182extern struct tm *gmtime(const time_t *timer);
     83extern char *asctime(const struct tm *timeptr);
    8284extern size_t strftime(char *restrict s, size_t maxsize,
    8385    const char *restrict format, const struct tm *restrict tm);
  • uspace/lib/posix/time.c

    r5b3394c r8219eb9  
    383383 *
    384384 * @param timeptr Broken-down time structure.
    385  * @return Pointer to a statically allocated string.
    386  */
    387 char *posix_asctime(const struct tm *timeptr)
    388 {
    389         static char buf[ASCTIME_BUF_LEN];
    390         return posix_asctime_r(timeptr, buf);
    391 }
    392 
    393 /**
    394  * Converts broken-down time to a string in format
    395  * "Sun Jan 1 00:00:00 1970\n". (Obsolete)
    396  *
    397  * @param timeptr Broken-down time structure.
    398385 * @param buf Buffer to store string to, must be at least ASCTIME_BUF_LEN
    399386 *     bytes long.
     
    436423                return NULL;
    437424        }
    438         return posix_asctime(loctime);
     425        return asctime(loctime);
    439426}
    440427
  • uspace/lib/posix/time.h

    r5b3394c r8219eb9  
    6363#endif
    6464
    65 #undef ASCTIME_BUF_LEN
    66 #define ASCTIME_BUF_LEN 26
    67 
    6865#undef CLOCK_REALTIME
    6966#define CLOCK_REALTIME ((posix_clockid_t) 0)
     
    9895
    9996/* Formatting Calendar Time */
    100 extern char *posix_asctime(const struct tm *timeptr);
    10197extern char *posix_asctime_r(const struct tm *restrict timeptr,
    10298    char *restrict buf);
     
    133129        #define localtime_r posix_localtime_r
    134130
    135         #define asctime posix_asctime
    136131        #define asctime_r posix_asctime_r
    137132        #define ctime posix_ctime
Note: See TracChangeset for help on using the changeset viewer.