Uninitialized vector entry?
[minix3.git] / lib / ansi / asctime.c
blobed0757816bec112f1444f471ebe8ec8ef93105c2
1 /*
2 * asctime - print a date
3 */
4 /* $Header$ */
6 #include <string.h>
7 #include <time.h>
8 #include "loc_time.h"
10 #define DATE_STR "??? ??? ?? ??:??:?? ????\n"
12 static char *
13 two_digits(register char *pb, int i, int nospace)
15 *pb = (i / 10) % 10 + '0';
16 if (!nospace && *pb == '0') *pb = ' ';
17 pb++;
18 *pb++ = (i % 10) + '0';
19 return ++pb;
22 static char *
23 four_digits(register char *pb, int i)
25 i %= 10000;
26 *pb++ = (i / 1000) + '0';
27 i %= 1000;
28 *pb++ = (i / 100) + '0';
29 i %= 100;
30 *pb++ = (i / 10) + '0';
31 *pb++ = (i % 10) + '0';
32 return ++pb;
35 char *asctime(const struct tm *timeptr)
37 static char buf[26];
38 register char *pb = buf;
39 register const char *ps;
40 register int n;
42 strcpy(pb, DATE_STR);
43 ps = _days[timeptr->tm_wday];
44 n = ABB_LEN;
45 while(--n >= 0) *pb++ = *ps++;
46 pb++;
47 ps = _months[timeptr->tm_mon];
48 n = ABB_LEN;
49 while(--n >= 0) *pb++ = *ps++;
50 pb++;
51 pb = two_digits(
52 two_digits(
53 two_digits(two_digits(pb, timeptr->tm_mday, 0)
54 , timeptr->tm_hour, 1)
55 , timeptr->tm_min, 1)
56 , timeptr->tm_sec, 1);
58 four_digits(pb, timeptr->tm_year + 1900);
59 return buf;