Subversion Repositories Kolibri OS

Rev

Rev 9765 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "stddef.h"
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. const char* wday_str[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
  8. const char* mon_str[12] = { "Jan", "Feb", "Mar", "Ap", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  9.  
  10. #define TIME_STR_MAX 27
  11.  
  12. char* asctime(const struct tm* tm)
  13. {
  14.     if (!tm) {
  15.         __errno = EINVAL;
  16.         return NULL;
  17.     }
  18.     if (tm->tm_wday > 6 || tm->tm_wday < 0 || tm->tm_mon < 0 || tm->tm_mon > 11) {
  19.         errno = EINVAL;
  20.         return NULL;
  21.     }
  22.     static char time_str[TIME_STR_MAX];
  23.     snprintf(time_str, TIME_STR_MAX - 1, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
  24.         wday_str[tm->tm_wday],
  25.         mon_str[tm->tm_mon],
  26.         tm->tm_mday, tm->tm_hour,
  27.         tm->tm_min, tm->tm_sec,
  28.         1900 + tm->tm_year);
  29.     return time_str;
  30. }