home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / static / asctime.c < prev    next >
C/C++ Source or Header  |  1996-10-01  |  2KB  |  62 lines

  1. /*
  2. ** This file is in the public domain, so clarified as of
  3. ** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
  4. */
  5.  
  6. #ifndef lint
  7. #ifndef NOID
  8. static char    elsieid[] = "@(#)asctime.c    7.7";
  9. #endif /* !defined NOID */
  10. #endif /* !defined lint */
  11.  
  12. /*LINTLIBRARY*/
  13.  
  14. #include "private.h"
  15. #include "tzfile.h"
  16.  
  17. /*
  18. ** A la X3J11, with core dump avoidance.
  19. */
  20.  
  21. char *
  22. asctime(timeptr)
  23. register const struct tm *    timeptr;
  24. {
  25.     static const char    wday_name[][3] = {
  26.         "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  27.     };
  28.     static const char    mon_name[][3] = {
  29.         "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  30.         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  31.     };
  32.     /*
  33.     ** Big enough for something such as
  34.     ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
  35.     ** (two three-character abbreviations, five strings denoting integers,
  36.     ** three explicit spaces, two explicit colons, a newline,
  37.     ** and a trailing ASCII nul).
  38.     */
  39.     static char        result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) +
  40.                     3 + 2 + 1 + 1];
  41.     register const char *    wn;
  42.     register const char *    mn;
  43.  
  44.     if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
  45.         wn = "???";
  46.     else    wn = wday_name[timeptr->tm_wday];
  47.     if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
  48.         mn = "???";
  49.     else    mn = mon_name[timeptr->tm_mon];
  50.     /*
  51.     ** The X3J11-suggested format is
  52.     **    "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
  53.     ** Since the .2 in 02.2d is ignored, we drop it.
  54.     */
  55.     (void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n",
  56.         wn, mn,
  57.         timeptr->tm_mday, timeptr->tm_hour,
  58.         timeptr->tm_min, timeptr->tm_sec,
  59.         TM_YEAR_BASE + timeptr->tm_year);
  60.     return result;
  61. }
  62.