-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasctime.c.diff
198 lines (176 loc) · 5.07 KB
/
asctime.c.diff
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
*** ./asctime.c.orig Wed Jun 17 00:00:00 1998
--- ./asctime.c Mon Feb 12 15:58:10 2001
***************
*** 1,133 ****
! /***
! *asctime.c - convert date/time structure to ASCII string
! *
! * Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
! *
! *Purpose:
! * Contains asctime() - convert a date/time structure to ASCII string.
! *
! *******************************************************************************/
! #include <cruntime.h>
#include <time.h>
- #include <internal.h>
- #include <mtdll.h>
- #ifdef _MT
- #include <malloc.h>
- #include <stddef.h>
- #endif /* _MT */
- #include <tchar.h>
- #include <dbgint.h>
#define _ASCBUFSIZE 26
- static _TSCHAR buf[_ASCBUFSIZE];
! /*
! ** This prototype must be local to this file since the procedure is static
! */
!
! static _TSCHAR * __cdecl store_dt(_TSCHAR *, int);
!
! static _TSCHAR * __cdecl store_dt (
! REG1 _TSCHAR *p,
! REG2 int val
! )
! {
! *p++ = (_TSCHAR)(_T('0') + val / 10);
! *p++ = (_TSCHAR)(_T('0') + val % 10);
! return(p);
! }
!
! /***
! *char *asctime(time) - convert a structure time to ascii string
! *
! *Purpose:
! * Converts a time stored in a struct tm to a charcater string.
! * The string is always exactly 26 characters of the form
! * Tue May 01 02:34:55 1984\n\0
! *
! *Entry:
! * struct tm *time - ptr to time structure
! *
! *Exit:
! * returns pointer to static string with time string.
! *
! *Exceptions:
! *
! *******************************************************************************/
!
! _TSCHAR * __cdecl _tasctime (
! REG1 const struct tm *tb
! )
{
! #ifdef _MT
!
! _ptiddata ptd = _getptd();
!
! REG2 _TSCHAR *p; /* will point to asctime buffer */
! _TSCHAR *retval; /* holds retval pointer */
!
! #else /* _MT */
!
! REG2 _TSCHAR *p = buf;
!
! #endif /* _MT */
! int day, mon;
! int i;
!
! #ifdef _MT
!
! /* Use per thread buffer area (malloc space, if necessary) */
!
! #ifdef _UNICODE
! if ( (ptd->_wasctimebuf != NULL) || ((ptd->_wasctimebuf =
! (wchar_t *)_malloc_crt(_ASCBUFSIZE * sizeof(wchar_t))) != NULL) )
! p = ptd->_wasctimebuf;
! #else /* _UNICODE */
! if ( (ptd->_asctimebuf != NULL) || ((ptd->_asctimebuf =
! (char *)_malloc_crt(_ASCBUFSIZE * sizeof(char))) != NULL) )
! p = ptd->_asctimebuf;
! #endif /* _UNICODE */
! else
! p = buf; /* error: use static buffer */
!
! retval = p; /* save return value for later */
!
! #endif /* _MT */
!
! /* copy day and month names into the buffer */
! day = tb->tm_wday * 3; /* index to correct day string */
! mon = tb->tm_mon * 3; /* index to correct month string */
! for (i=0; i < 3; i++,p++) {
! *p = *(__dnames + day + i);
! *(p+4) = *(__mnames + mon + i);
! }
! *p = _T(' '); /* blank between day and month */
! p += 4;
! *p++ = _T(' ');
! p = store_dt(p, tb->tm_mday); /* day of the month (1-31) */
! *p++ = _T(' ');
! p = store_dt(p, tb->tm_hour); /* hours (0-23) */
! *p++ = _T(':');
! p = store_dt(p, tb->tm_min); /* minutes (0-59) */
! *p++ = _T(':');
! p = store_dt(p, tb->tm_sec); /* seconds (0-59) */
! *p++ = _T(' ');
! p = store_dt(p, 19 + (tb->tm_year/100)); /* year (after 1900) */
! p = store_dt(p, tb->tm_year%100);
! *p++ = _T('\n');
! *p = _T('\0');
! #ifdef _MT
! return (retval);
! #else /* _MT */
! return ((_TSCHAR *) buf);
! #endif /* _MT */
}
--- 1,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;
}