@@ -71,13 +71,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
7171#include <time.h>
7272#endif /* !unix */
7373
74- /* XXX This is bogus -- times() is defined in posixmodule.c */
75- #ifdef DO_TIMES
76- #include <sys/times.h>
77- #include <sys/param.h>
78- #include <errno.h>
79- #endif
80-
8174#ifdef SYSV
8275/* Access timezone stuff */
8376#ifdef OLDTZ /* ANSI prepends underscore to these */
@@ -227,32 +220,6 @@ time_millitimer(self, args)
227220
228221#endif /* DO_MILLI */
229222
230- #ifdef DO_TIMES
231-
232- static object *
233- time_times (self , args )
234- object * self ;
235- object * args ;
236- {
237- struct tms t ;
238- clock_t c ;
239- if (!getnoarg (args ))
240- return NULL ;
241- errno = 0 ;
242- c = times (& t );
243- if (c == (clock_t ) - 1 ) {
244- err_errno (IOError );
245- return NULL ;
246- }
247- return mkvalue ("(dddd)" ,
248- (double )t .tms_utime / HZ ,
249- (double )t .tms_stime / HZ ,
250- (double )t .tms_cutime / HZ ,
251- (double )t .tms_cstime / HZ );
252- }
253-
254- #endif
255-
256223
257224static object *
258225time_convert (when , function )
@@ -268,7 +235,7 @@ time_convert(when, function)
268235 p -> tm_min ,
269236 p -> tm_sec ,
270237 (p -> tm_wday + 6 ) % 7 , /* Want Monday == 0 */
271- p -> tm_yday ,
238+ p -> tm_yday + 1 , /* Want January, 1 == 1 */
272239 p -> tm_isdst );
273240}
274241
@@ -294,6 +261,62 @@ time_localtime(self, args)
294261 return time_convert ((time_t )when , localtime );
295262}
296263
264+ static int
265+ gettmarg (args , p )
266+ object * args ;
267+ struct tm * p ;
268+ {
269+ if (!getargs (args , "(iiiiiiiii)" ,
270+ & p -> tm_year ,
271+ & p -> tm_mon ,
272+ & p -> tm_mday ,
273+ & p -> tm_hour ,
274+ & p -> tm_min ,
275+ & p -> tm_sec ,
276+ & p -> tm_wday ,
277+ & p -> tm_yday ,
278+ & p -> tm_isdst ))
279+ return 0 ;
280+ if (p -> tm_year >= 1900 )
281+ p -> tm_year -= 1900 ;
282+ p -> tm_mon -- ;
283+ p -> tm_wday = (p -> tm_wday + 1 ) % 7 ;
284+ p -> tm_yday -- ;
285+ return 1 ;
286+ }
287+
288+ static object *
289+ time_asctime (self , args )
290+ object * self ;
291+ object * args ;
292+ {
293+ struct tm buf ;
294+ char * p ;
295+ if (!gettmarg (args , & buf ))
296+ return NULL ;
297+ p = asctime (& buf );
298+ if (p [24 ] == '\n' )
299+ p [24 ] = '\0' ;
300+ return newstringobject (p );
301+ }
302+
303+ static object *
304+ time_ctime (self , args )
305+ object * self ;
306+ object * args ;
307+ {
308+ double dt ;
309+ time_t tt ;
310+ char * p ;
311+ if (!getargs (args , "d" , & dt ))
312+ return NULL ;
313+ tt = dt ;
314+ p = ctime (& tt );
315+ if (p [24 ] == '\n' )
316+ p [24 ] = '\0' ;
317+ return newstringobject (p );
318+ }
319+
297320/* Some very old systems may not have mktime(). Comment it out then! */
298321
299322static object *
@@ -302,20 +325,8 @@ time_mktime(self, args)
302325 object * args ;
303326{
304327 struct tm buf ;
305- if (!getargs (args , "(iiiiiiiii)" ,
306- & buf .tm_year ,
307- & buf .tm_mon ,
308- & buf .tm_mday ,
309- & buf .tm_hour ,
310- & buf .tm_min ,
311- & buf .tm_sec ,
312- & buf .tm_wday ,
313- & buf .tm_yday ,
314- & buf .tm_isdst ))
328+ if (!gettmarg (args , & buf ))
315329 return NULL ;
316- if (buf .tm_year >= 1900 )
317- buf .tm_year -= 1900 ;
318- buf .tm_mon -- ;
319330 return newintobject ((long )mktime (& buf ));
320331}
321332
@@ -324,13 +335,12 @@ static struct methodlist time_methods[] = {
324335 {"millisleep" , time_millisleep },
325336 {"millitimer" , time_millitimer },
326337#endif /* DO_MILLI */
327- #ifdef DO_TIMES
328- {"times" , time_times },
329- #endif
330338 {"sleep" , time_sleep },
331339 {"time" , time_time },
332340 {"gmtime" , time_gmtime },
333341 {"localtime" , time_localtime },
342+ {"asctime" , time_asctime },
343+ {"ctime" , time_ctime },
334344 {"mktime" , time_mktime },
335345 {NULL , NULL } /* sentinel */
336346};
0 commit comments