-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasctime.c
60 lines (45 loc) · 1008 Bytes
/
asctime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// asctime.c - adapted from Microsoft C Runtime
//
// Time-stamp: <12/02/01 15:58:09 keuchel@keuchelnt>
#include "celib.h"
#include <time.h>
#define _ASCBUFSIZE 26
static char *store_dt(char *, int);
static char *
store_dt (char *p, int val)
{
*p++ = '0' + val / 10;
*p++ = '0' + val % 10;
return p;
}
char *
xceasctime (const struct tm *tb)
{
static char buf[_ASCBUFSIZE];
char *p = buf;
int day, mon;
int i;
p = buf;
day = tb->tm_wday * 3;
mon = tb->tm_mon * 3;
for (i=0; i < 3; i++,p++) {
*p = *(__dnames + day + i);
*(p+4) = *(__mnames + mon + i);
}
*p = ' ';
p += 4;
*p++ = ' ';
p = store_dt(p, tb->tm_mday);
*p++ = ' ';
p = store_dt(p, tb->tm_hour);
*p++ = ':';
p = store_dt(p, tb->tm_min);
*p++ = ':';
p = store_dt(p, tb->tm_sec);
*p++ = ' ';
p = store_dt(p, 19 + (tb->tm_year/100));
p = store_dt(p, tb->tm_year%100);
*p++ = '\n';
*p = '\0';
return buf;
}