Changeset 8219eb9 in mainline for uspace/lib/c/generic/time.c


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

File:
1 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/** @}
Note: See TracChangeset for help on using the changeset viewer.