(scm_strptime): Add comment about glibc strptime %s and
[bpt/guile.git] / libguile / stime.c
1 /* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003 Free Software Foundation, Inc.
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18
19 \f
20
21 #if HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <stdio.h>
26 #include <errno.h>
27
28 #include "libguile/_scm.h"
29 #include "libguile/feature.h"
30 #include "libguile/strings.h"
31 #include "libguile/vectors.h"
32
33 #include "libguile/validate.h"
34 #include "libguile/stime.h"
35
36 #ifdef HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39
40 \f
41 # ifdef HAVE_SYS_TYPES_H
42 # include <sys/types.h>
43 # endif
44
45 #ifdef HAVE_STRING_H
46 #include <string.h>
47 #endif
48
49 #ifdef HAVE_SYS_TIMES_H
50 # include <sys/times.h>
51 #endif
52
53 #ifdef HAVE_SYS_TIMEB_H
54 # include <sys/timeb.h>
55 #endif
56
57 #ifndef tzname /* For SGI. */
58 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
59 #endif
60 #if defined (__MINGW32__)
61 # define tzname _tzname
62 #endif
63
64 #ifdef MISSING_STRPTIME_DECL
65 extern char *strptime ();
66 #endif
67
68 #ifdef __STDC__
69 # define timet time_t
70 #else
71 # define timet long
72 #endif
73
74 #ifdef HAVE_TIMES
75 static
76 timet mytime()
77 {
78 struct tms time_buffer;
79 times(&time_buffer);
80 return time_buffer.tms_utime + time_buffer.tms_stime;
81 }
82 #else
83 # ifdef LACK_CLOCK
84 # define mytime() ((time((timet*)0) - scm_your_base) * SCM_TIME_UNITS_PER_SECOND)
85 # else
86 # define mytime clock
87 # endif
88 #endif
89
90 #ifdef HAVE_FTIME
91 struct timeb scm_your_base = {0};
92 #else
93 timet scm_your_base = 0;
94 #endif
95
96 SCM_DEFINE (scm_get_internal_real_time, "get-internal-real-time", 0, 0, 0,
97 (),
98 "Return the number of time units since the interpreter was\n"
99 "started.")
100 #define FUNC_NAME s_scm_get_internal_real_time
101 {
102 #ifdef HAVE_FTIME
103 struct timeb time_buffer;
104
105 SCM tmp;
106 ftime (&time_buffer);
107 time_buffer.time -= scm_your_base.time;
108 tmp = scm_long2num (time_buffer.millitm - scm_your_base.millitm);
109 tmp = scm_sum (tmp,
110 scm_product (SCM_MAKINUM (1000),
111 SCM_MAKINUM (time_buffer.time)));
112 return scm_quotient (scm_product (tmp, SCM_MAKINUM (SCM_TIME_UNITS_PER_SECOND)),
113 SCM_MAKINUM (1000));
114 #else
115 return scm_long2num((time((timet*)0) - scm_your_base) * (int)SCM_TIME_UNITS_PER_SECOND);
116 #endif /* HAVE_FTIME */
117 }
118 #undef FUNC_NAME
119
120
121 #ifdef HAVE_TIMES
122 SCM_DEFINE (scm_times, "times", 0, 0, 0,
123 (void),
124 "Return an object with information about real and processor\n"
125 "time. The following procedures accept such an object as an\n"
126 "argument and return a selected component:\n"
127 "\n"
128 "@table @code\n"
129 "@item tms:clock\n"
130 "The current real time, expressed as time units relative to an\n"
131 "arbitrary base.\n"
132 "@item tms:utime\n"
133 "The CPU time units used by the calling process.\n"
134 "@item tms:stime\n"
135 "The CPU time units used by the system on behalf of the calling\n"
136 "process.\n"
137 "@item tms:cutime\n"
138 "The CPU time units used by terminated child processes of the\n"
139 "calling process, whose status has been collected (e.g., using\n"
140 "@code{waitpid}).\n"
141 "@item tms:cstime\n"
142 "Similarly, the CPU times units used by the system on behalf of\n"
143 "terminated child processes.\n"
144 "@end table")
145 #define FUNC_NAME s_scm_times
146 {
147 struct tms t;
148 clock_t rv;
149
150 SCM result = scm_c_make_vector (5, SCM_UNDEFINED);
151 rv = times (&t);
152 if (rv == -1)
153 SCM_SYSERROR;
154 SCM_VECTOR_SET (result, 0, scm_long2num (rv));
155 SCM_VECTOR_SET (result, 1, scm_long2num (t.tms_utime));
156 SCM_VECTOR_SET (result, 2, scm_long2num (t.tms_stime));
157 SCM_VECTOR_SET (result ,3, scm_long2num (t.tms_cutime));
158 SCM_VECTOR_SET (result, 4, scm_long2num (t.tms_cstime));
159 return result;
160 }
161 #undef FUNC_NAME
162 #endif /* HAVE_TIMES */
163
164 static long scm_my_base = 0;
165
166 long
167 scm_c_get_internal_run_time ()
168 {
169 return mytime () - scm_my_base;
170 }
171
172 SCM_DEFINE (scm_get_internal_run_time, "get-internal-run-time", 0, 0, 0,
173 (void),
174 "Return the number of time units of processor time used by the\n"
175 "interpreter. Both @emph{system} and @emph{user} time are\n"
176 "included but subprocesses are not.")
177 #define FUNC_NAME s_scm_get_internal_run_time
178 {
179 return scm_long2num (scm_c_get_internal_run_time ());
180 }
181 #undef FUNC_NAME
182
183 SCM_DEFINE (scm_current_time, "current-time", 0, 0, 0,
184 (void),
185 "Return the number of seconds since 1970-01-01 00:00:00 UTC,\n"
186 "excluding leap seconds.")
187 #define FUNC_NAME s_scm_current_time
188 {
189 timet timv;
190
191 SCM_DEFER_INTS;
192 if ((timv = time (0)) == -1)
193 SCM_SYSERROR;
194 SCM_ALLOW_INTS;
195 return scm_long2num((long) timv);
196 }
197 #undef FUNC_NAME
198
199 SCM_DEFINE (scm_gettimeofday, "gettimeofday", 0, 0, 0,
200 (void),
201 "Return a pair containing the number of seconds and microseconds\n"
202 "since 1970-01-01 00:00:00 UTC, excluding leap seconds. Note:\n"
203 "whether true microsecond resolution is available depends on the\n"
204 "operating system.")
205 #define FUNC_NAME s_scm_gettimeofday
206 {
207 #ifdef HAVE_GETTIMEOFDAY
208 struct timeval time;
209
210 SCM_DEFER_INTS;
211 if (gettimeofday (&time, NULL) == -1)
212 SCM_SYSERROR;
213 SCM_ALLOW_INTS;
214 return scm_cons (scm_long2num ((long) time.tv_sec),
215 scm_long2num ((long) time.tv_usec));
216 #else
217 # ifdef HAVE_FTIME
218 struct timeb time;
219
220 ftime(&time);
221 return scm_cons (scm_long2num ((long) time.time),
222 SCM_MAKINUM (time.millitm * 1000));
223 # else
224 timet timv;
225
226 SCM_DEFER_INTS;
227 if ((timv = time (0)) == -1)
228 SCM_SYSERROR;
229 SCM_ALLOW_INTS;
230 return scm_cons (scm_long2num (timv), SCM_MAKINUM (0));
231 # endif
232 #endif
233 }
234 #undef FUNC_NAME
235
236 static SCM
237 filltime (struct tm *bd_time, int zoff, char *zname)
238 {
239 SCM result = scm_c_make_vector (11, SCM_UNDEFINED);
240
241 SCM_VECTOR_SET (result,0, SCM_MAKINUM (bd_time->tm_sec));
242 SCM_VECTOR_SET (result,1, SCM_MAKINUM (bd_time->tm_min));
243 SCM_VECTOR_SET (result,2, SCM_MAKINUM (bd_time->tm_hour));
244 SCM_VECTOR_SET (result,3, SCM_MAKINUM (bd_time->tm_mday));
245 SCM_VECTOR_SET (result,4, SCM_MAKINUM (bd_time->tm_mon));
246 SCM_VECTOR_SET (result,5, SCM_MAKINUM (bd_time->tm_year));
247 SCM_VECTOR_SET (result,6, SCM_MAKINUM (bd_time->tm_wday));
248 SCM_VECTOR_SET (result,7, SCM_MAKINUM (bd_time->tm_yday));
249 SCM_VECTOR_SET (result,8, SCM_MAKINUM (bd_time->tm_isdst));
250 SCM_VECTOR_SET (result,9, SCM_MAKINUM (zoff));
251 SCM_VECTOR_SET (result,10, zname ? scm_makfrom0str (zname) : SCM_BOOL_F);
252 return result;
253 }
254
255 static char tzvar[3] = "TZ";
256 extern char ** environ;
257
258 /* if zone is set, create a temporary environment with only a TZ
259 string. other threads or interrupt handlers shouldn't be allowed
260 to run until the corresponding restorezone is called. hence the use
261 of a static variable for tmpenv is no big deal. */
262 static char **
263 setzone (SCM zone, int pos, const char *subr)
264 {
265 char **oldenv = 0;
266
267 if (!SCM_UNBNDP (zone))
268 {
269 static char *tmpenv[2];
270 char *buf;
271
272 SCM_ASSERT (SCM_STRINGP (zone), zone, pos, subr);
273 buf = scm_malloc (SCM_STRING_LENGTH (zone) + sizeof (tzvar) + 1);
274 sprintf (buf, "%s=%s", tzvar, SCM_STRING_CHARS (zone));
275 oldenv = environ;
276 tmpenv[0] = buf;
277 tmpenv[1] = 0;
278 environ = tmpenv;
279 }
280 return oldenv;
281 }
282
283 static void
284 restorezone (SCM zone, char **oldenv, const char *subr SCM_UNUSED)
285 {
286 if (!SCM_UNBNDP (zone))
287 {
288 free (environ[0]);
289 environ = oldenv;
290 #ifdef HAVE_TZSET
291 /* for the possible benefit of user code linked with libguile. */
292 tzset();
293 #endif
294 }
295 }
296
297 SCM_DEFINE (scm_localtime, "localtime", 1, 1, 0,
298 (SCM time, SCM zone),
299 "Return an object representing the broken down components of\n"
300 "@var{time}, an integer like the one returned by\n"
301 "@code{current-time}. The time zone for the calculation is\n"
302 "optionally specified by @var{zone} (a string), otherwise the\n"
303 "@code{TZ} environment variable or the system default is used.")
304 #define FUNC_NAME s_scm_localtime
305 {
306 timet itime;
307 struct tm *ltptr, lt, *utc;
308 SCM result;
309 int zoff;
310 char *zname = 0;
311 char **oldenv;
312 int err;
313
314 itime = SCM_NUM2LONG (1, time);
315
316 /* deferring interupts is essential since a) setzone may install a temporary
317 environment b) localtime uses a static buffer. */
318 SCM_DEFER_INTS;
319 oldenv = setzone (zone, SCM_ARG2, FUNC_NAME);
320 #ifdef LOCALTIME_CACHE
321 tzset ();
322 #endif
323 ltptr = localtime (&itime);
324 err = errno;
325 if (ltptr)
326 {
327 const char *ptr;
328
329 /* copy zone name before calling gmtime or restoring zone. */
330 #if defined (HAVE_TM_ZONE)
331 ptr = ltptr->tm_zone;
332 #elif defined (HAVE_TZNAME)
333 ptr = tzname[ (ltptr->tm_isdst == 1) ? 1 : 0 ];
334 #else
335 ptr = "";
336 #endif
337 zname = scm_malloc (strlen (ptr) + 1);
338 strcpy (zname, ptr);
339 }
340 /* the struct is copied in case localtime and gmtime share a buffer. */
341 if (ltptr)
342 lt = *ltptr;
343 utc = gmtime (&itime);
344 if (utc == NULL)
345 err = errno;
346 restorezone (zone, oldenv, FUNC_NAME);
347 /* delayed until zone has been restored. */
348 errno = err;
349 if (utc == NULL || ltptr == NULL)
350 SCM_SYSERROR;
351
352 /* calculate timezone offset in seconds west of UTC. */
353 zoff = (utc->tm_hour - lt.tm_hour) * 3600 + (utc->tm_min - lt.tm_min) * 60
354 + utc->tm_sec - lt.tm_sec;
355 if (utc->tm_year < lt.tm_year)
356 zoff -= 24 * 60 * 60;
357 else if (utc->tm_year > lt.tm_year)
358 zoff += 24 * 60 * 60;
359 else if (utc->tm_yday < lt.tm_yday)
360 zoff -= 24 * 60 * 60;
361 else if (utc->tm_yday > lt.tm_yday)
362 zoff += 24 * 60 * 60;
363
364 result = filltime (&lt, zoff, zname);
365 SCM_ALLOW_INTS;
366 if (zname)
367 free (zname);
368 return result;
369 }
370 #undef FUNC_NAME
371
372 SCM_DEFINE (scm_gmtime, "gmtime", 1, 0, 0,
373 (SCM time),
374 "Return an object representing the broken down components of\n"
375 "@var{time}, an integer like the one returned by\n"
376 "@code{current-time}. The values are calculated for UTC.")
377 #define FUNC_NAME s_scm_gmtime
378 {
379 timet itime;
380 struct tm *bd_time;
381 SCM result;
382
383 itime = SCM_NUM2LONG (1, time);
384 SCM_DEFER_INTS;
385 bd_time = gmtime (&itime);
386 if (bd_time == NULL)
387 SCM_SYSERROR;
388 result = filltime (bd_time, 0, "GMT");
389 SCM_ALLOW_INTS;
390 return result;
391 }
392 #undef FUNC_NAME
393
394 /* copy time components from a Scheme object to a struct tm. */
395 static void
396 bdtime2c (SCM sbd_time, struct tm *lt, int pos, const char *subr)
397 {
398 SCM const *velts;
399 int i;
400
401 SCM_ASSERT (SCM_VECTORP (sbd_time)
402 && SCM_VECTOR_LENGTH (sbd_time) == 11,
403 sbd_time, pos, subr);
404 velts = SCM_VELTS (sbd_time);
405 for (i = 0; i < 10; i++)
406 {
407 SCM_ASSERT (SCM_INUMP (velts[i]), sbd_time, pos, subr);
408 }
409 SCM_ASSERT (SCM_FALSEP (velts[10]) || SCM_STRINGP (velts[10]),
410 sbd_time, pos, subr);
411
412 lt->tm_sec = SCM_INUM (velts[0]);
413 lt->tm_min = SCM_INUM (velts[1]);
414 lt->tm_hour = SCM_INUM (velts[2]);
415 lt->tm_mday = SCM_INUM (velts[3]);
416 lt->tm_mon = SCM_INUM (velts[4]);
417 lt->tm_year = SCM_INUM (velts[5]);
418 lt->tm_wday = SCM_INUM (velts[6]);
419 lt->tm_yday = SCM_INUM (velts[7]);
420 lt->tm_isdst = SCM_INUM (velts[8]);
421 #ifdef HAVE_TM_ZONE
422 lt->tm_gmtoff = SCM_INUM (velts[9]);
423 if (SCM_FALSEP (velts[10]))
424 lt->tm_zone = NULL;
425 else
426 lt->tm_zone = SCM_STRING_CHARS (velts[10]);
427 #endif
428 }
429
430 SCM_DEFINE (scm_mktime, "mktime", 1, 1, 0,
431 (SCM sbd_time, SCM zone),
432 "@var{bd-time} is an object representing broken down time and @code{zone}\n"
433 "is an optional time zone specifier (otherwise the TZ environment variable\n"
434 "or the system default is used).\n\n"
435 "Returns a pair: the car is a corresponding\n"
436 "integer time value like that returned\n"
437 "by @code{current-time}; the cdr is a broken down time object, similar to\n"
438 "as @var{bd-time} but with normalized values.")
439 #define FUNC_NAME s_scm_mktime
440 {
441 timet itime;
442 struct tm lt, *utc;
443 SCM result;
444 int zoff;
445 char *zname = 0;
446 char **oldenv;
447 int err;
448
449 bdtime2c (sbd_time, &lt, SCM_ARG1, FUNC_NAME);
450
451 SCM_DEFER_INTS;
452 oldenv = setzone (zone, SCM_ARG2, FUNC_NAME);
453 #ifdef LOCALTIME_CACHE
454 tzset ();
455 #endif
456 itime = mktime (&lt);
457 err = errno;
458
459 if (itime != -1)
460 {
461 const char *ptr;
462
463 /* copy zone name before calling gmtime or restoring the zone. */
464 #if defined (HAVE_TM_ZONE)
465 ptr = lt.tm_zone;
466 #elif defined (HAVE_TZNAME)
467 ptr = tzname[ (lt.tm_isdst == 1) ? 1 : 0 ];
468 #else
469 ptr = "";
470 #endif
471 zname = scm_malloc (strlen (ptr) + 1);
472 strcpy (zname, ptr);
473 }
474
475 /* get timezone offset in seconds west of UTC. */
476 utc = gmtime (&itime);
477 if (utc == NULL)
478 err = errno;
479
480 restorezone (zone, oldenv, FUNC_NAME);
481 /* delayed until zone has been restored. */
482 errno = err;
483 if (utc == NULL || itime == -1)
484 SCM_SYSERROR;
485
486 zoff = (utc->tm_hour - lt.tm_hour) * 3600 + (utc->tm_min - lt.tm_min) * 60
487 + utc->tm_sec - lt.tm_sec;
488 if (utc->tm_year < lt.tm_year)
489 zoff -= 24 * 60 * 60;
490 else if (utc->tm_year > lt.tm_year)
491 zoff += 24 * 60 * 60;
492 else if (utc->tm_yday < lt.tm_yday)
493 zoff -= 24 * 60 * 60;
494 else if (utc->tm_yday > lt.tm_yday)
495 zoff += 24 * 60 * 60;
496
497 result = scm_cons (scm_long2num ((long) itime),
498 filltime (&lt, zoff, zname));
499 SCM_ALLOW_INTS;
500 if (zname)
501 free (zname);
502 return result;
503 }
504 #undef FUNC_NAME
505
506 #ifdef HAVE_TZSET
507 SCM_DEFINE (scm_tzset, "tzset", 0, 0, 0,
508 (void),
509 "Initialize the timezone from the TZ environment variable\n"
510 "or the system default. It's not usually necessary to call this procedure\n"
511 "since it's done automatically by other procedures that depend on the\n"
512 "timezone.")
513 #define FUNC_NAME s_scm_tzset
514 {
515 tzset();
516 return SCM_UNSPECIFIED;
517 }
518 #undef FUNC_NAME
519 #endif /* HAVE_TZSET */
520
521 SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0,
522 (SCM format, SCM stime),
523 "Formats a time specification @var{time} using @var{template}. @var{time}\n"
524 "is an object with time components in the form returned by @code{localtime}\n"
525 "or @code{gmtime}. @var{template} is a string which can include formatting\n"
526 "specifications introduced by a @code{%} character. The formatting of\n"
527 "month and day names is dependent on the current locale. The value returned\n"
528 "is the formatted string.\n"
529 "@xref{Formatting Date and Time, , , libc, The GNU C Library Reference Manual}.)")
530 #define FUNC_NAME s_scm_strftime
531 {
532 struct tm t;
533
534 char *tbuf;
535 int size = 50;
536 char *fmt, *myfmt;
537 int len;
538 SCM result;
539
540 SCM_VALIDATE_STRING (1, format);
541 bdtime2c (stime, &t, SCM_ARG2, FUNC_NAME);
542
543 fmt = SCM_STRING_CHARS (format);
544 len = SCM_STRING_LENGTH (format);
545
546 /* Ugly hack: strftime can return 0 if its buffer is too small,
547 but some valid time strings (e.g. "%p") can sometimes produce
548 a zero-byte output string! Workaround is to prepend a junk
549 character to the format string, so that valid returns are always
550 nonzero. */
551 myfmt = scm_malloc (len+2);
552 *myfmt = 'x';
553 strncpy(myfmt+1, fmt, len);
554 myfmt[len+1] = 0;
555
556 tbuf = scm_malloc (size);
557 {
558 #if !defined (HAVE_TM_ZONE)
559 /* it seems the only way to tell non-GNU versions of strftime what
560 zone to use (for the %Z format) is to set TZ in the
561 environment. interrupts and thread switching must be deferred
562 until TZ is restored. */
563 char **oldenv = NULL;
564 SCM *velts = (SCM *) SCM_VELTS (stime);
565 int have_zone = 0;
566
567 if (!SCM_FALSEP (velts[10]) && *SCM_STRING_CHARS (velts[10]) != 0)
568 {
569 /* it's not required that the TZ setting be correct, just that
570 it has the right name. so try something like TZ=EST0.
571 using only TZ=EST would be simpler but it doesn't work on
572 some OSs, e.g., Solaris. */
573 SCM zone =
574 scm_string_append (scm_cons (velts[10],
575 scm_cons (scm_makfrom0str ("0"),
576 SCM_EOL)));
577
578 have_zone = 1;
579 SCM_DEFER_INTS;
580 oldenv = setzone (zone, SCM_ARG2, FUNC_NAME);
581 }
582 #endif
583
584 #ifdef LOCALTIME_CACHE
585 tzset ();
586 #endif
587
588 /* POSIX says strftime returns 0 on buffer overrun, but old
589 systems (i.e. libc 4 on GNU/Linux) might return `size' in that
590 case. */
591 while ((len = strftime (tbuf, size, myfmt, &t)) == 0 || len == size)
592 {
593 free (tbuf);
594 size *= 2;
595 tbuf = scm_malloc (size);
596 }
597
598 #if !defined (HAVE_TM_ZONE)
599 if (have_zone)
600 {
601 restorezone (velts[10], oldenv, FUNC_NAME);
602 SCM_ALLOW_INTS;
603 }
604 #endif
605 }
606
607 result = scm_mem2string (tbuf + 1, len - 1);
608 free (tbuf);
609 free (myfmt);
610 return result;
611 }
612 #undef FUNC_NAME
613
614 #ifdef HAVE_STRPTIME
615 SCM_DEFINE (scm_strptime, "strptime", 2, 0, 0,
616 (SCM format, SCM string),
617 "Performs the reverse action to @code{strftime}, parsing\n"
618 "@var{string} according to the specification supplied in\n"
619 "@var{template}. The interpretation of month and day names is\n"
620 "dependent on the current locale. The value returned is a pair.\n"
621 "The car has an object with time components\n"
622 "in the form returned by @code{localtime} or @code{gmtime},\n"
623 "but the time zone components\n"
624 "are not usefully set.\n"
625 "The cdr reports the number of characters from @var{string}\n"
626 "which were used for the conversion.")
627 #define FUNC_NAME s_scm_strptime
628 {
629 struct tm t;
630 char *fmt, *str, *rest;
631
632 SCM_VALIDATE_STRING (1, format);
633 SCM_VALIDATE_STRING (2, string);
634
635 fmt = SCM_STRING_CHARS (format);
636 str = SCM_STRING_CHARS (string);
637
638 /* initialize the struct tm */
639 #define tm_init(field) t.field = 0
640 tm_init (tm_sec);
641 tm_init (tm_min);
642 tm_init (tm_hour);
643 tm_init (tm_mday);
644 tm_init (tm_mon);
645 tm_init (tm_year);
646 tm_init (tm_wday);
647 tm_init (tm_yday);
648 #undef tm_init
649
650 /* GNU glibc strptime() "%s" is affected by the current timezone, since it
651 reads a UTC time_t value and converts with localtime_r() to set the tm
652 fields, hence the use of SCM_DEFER_INTS. */
653 t.tm_isdst = -1;
654 SCM_DEFER_INTS;
655 if ((rest = strptime (str, fmt, &t)) == NULL)
656 SCM_SYSERROR;
657
658 SCM_ALLOW_INTS;
659 return scm_cons (filltime (&t, 0, NULL), SCM_MAKINUM (rest - str));
660 }
661 #undef FUNC_NAME
662 #endif /* HAVE_STRPTIME */
663
664 void
665 scm_init_stime()
666 {
667 scm_c_define ("internal-time-units-per-second",
668 scm_long2num((long) SCM_TIME_UNITS_PER_SECOND));
669
670 #ifdef HAVE_FTIME
671 if (!scm_your_base.time) ftime(&scm_your_base);
672 #else
673 if (!scm_your_base) time(&scm_your_base);
674 #endif
675
676 if (!scm_my_base) scm_my_base = mytime();
677
678 scm_add_feature ("current-time");
679 #include "libguile/stime.x"
680 }
681
682
683 /*
684 Local Variables:
685 c-file-style: "gnu"
686 End:
687 */