source: trunk/minix/lib/ansi/asctime.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.2 KB
Line 
1/*
2 * asctime - print a date
3 */
4/* $Header: /cvsup/minix/src/lib/ansi/asctime.c,v 1.1.1.1 2005/04/21 14:56:04 beng Exp $ */
5
6#include <string.h>
7#include <time.h>
8#include "loc_time.h"
9
10#define DATE_STR "??? ??? ?? ??:??:?? ????\n"
11
12static char *
13two_digits(register char *pb, int i, int nospace)
14{
15 *pb = (i / 10) % 10 + '0';
16 if (!nospace && *pb == '0') *pb = ' ';
17 pb++;
18 *pb++ = (i % 10) + '0';
19 return ++pb;
20}
21
22static char *
23four_digits(register char *pb, int i)
24{
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;
33}
34
35char *asctime(const struct tm *timeptr)
36{
37 static char buf[26];
38 register char *pb = buf;
39 register const char *ps;
40 register int n;
41
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);
57
58 four_digits(pb, timeptr->tm_year + 1900);
59 return buf;
60}
Note: See TracBrowser for help on using the repository browser.