blob: 7feefbcb26238ab57a5b201b4dd13f37eb6bbb89 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossum524b5881995-01-04 19:10:35 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00004
5 All Rights Reserved
6
Guido van Rossumd266eb41996-10-25 14:44:06 +00007Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
Guido van Rossumf70e43a1991-02-19 12:39:46 +00009provided that the above copyright notice appear in all copies and that
Guido van Rossumd266eb41996-10-25 14:44:06 +000010both that copyright notice and this permission notice appear in
Guido van Rossumf70e43a1991-02-19 12:39:46 +000011supporting documentation, and that the names of Stichting Mathematisch
Guido van Rossumd266eb41996-10-25 14:44:06 +000012Centrum or CWI or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000016
Guido van Rossumd266eb41996-10-25 14:44:06 +000017While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000029
30******************************************************************/
31
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000032/* Time module */
33
Barry Warsaw9a2a8a81996-12-06 23:32:14 +000034#include "Python.h"
Guido van Rossum3f5da241990-12-20 15:06:42 +000035
Guido van Rossum87ce7bb1998-06-09 16:30:31 +000036#include <ctype.h>
37
Guido van Rossum99d90c01996-08-08 19:17:45 +000038#ifdef HAVE_SELECT
39#include "mymath.h"
40#endif
41
Guido van Rossum6d946f91992-08-14 13:49:30 +000042#ifdef macintosh
Guido van Rossumb6775db1994-08-01 11:34:53 +000043#include <time.h>
44#else
45#include <sys/types.h>
Guido van Rossum6d946f91992-08-14 13:49:30 +000046#endif
47
Guido van Rossumb6775db1994-08-01 11:34:53 +000048#ifdef QUICKWIN
49#include <io.h>
50#endif
51
52#ifdef HAVE_UNISTD_H
Guido van Rossum2762f251992-03-27 17:22:13 +000053#include <unistd.h>
54#endif
55
Guido van Rossumbcc20741998-08-04 22:53:56 +000056#if defined(HAVE_SELECT) && !defined(__BEOS__)
Guido van Rossumb6775db1994-08-01 11:34:53 +000057#include "myselect.h"
58#else
59#include "mytime.h"
60#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000061
Guido van Rossumb6775db1994-08-01 11:34:53 +000062#ifdef HAVE_FTIME
Guido van Rossumbcc20741998-08-04 22:53:56 +000063#ifndef __BEOS__
64/* We have ftime(), but not in the headers (PR2). - [cjh] */
Guido van Rossumb6775db1994-08-01 11:34:53 +000065#include <sys/timeb.h>
Guido van Rossumbcc20741998-08-04 22:53:56 +000066#endif
Guido van Rossum8e9ebfd1997-11-22 21:53:48 +000067#if !defined(MS_WINDOWS) && !defined(PYOS_OS2)
Guido van Rossum1bb126f1996-12-06 20:17:44 +000068extern int ftime();
Guido van Rossum52174571996-12-09 18:38:52 +000069#endif /* MS_WINDOWS */
70#endif /* HAVE_FTIME */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000071
Guido van Rossum7bf22de1997-12-02 20:34:19 +000072#if defined(__WATCOMC__) && !defined(__QNX__)
Guido van Rossumbceeac81996-05-23 22:53:47 +000073#include <i86.h>
74#else
Guido van Rossumcac6c721996-09-06 13:34:02 +000075#ifdef MS_WINDOWS
Guido van Rossumb6775db1994-08-01 11:34:53 +000076#include <windows.h>
Guido van Rossumb2fb3641996-09-07 00:47:35 +000077#ifdef MS_WIN16
78/* These overrides not needed for Win32 */
Guido van Rossumb6775db1994-08-01 11:34:53 +000079#define timezone _timezone
Guido van Rossumcc081121995-03-14 15:05:41 +000080#define tzname _tzname
81#define daylight _daylight
82#define altzone _altzone
Guido van Rossumb2fb3641996-09-07 00:47:35 +000083#endif /* MS_WIN16 */
Guido van Rossumcac6c721996-09-06 13:34:02 +000084#endif /* MS_WINDOWS */
Guido van Rossum7bf22de1997-12-02 20:34:19 +000085#endif /* !__WATCOMC__ || __QNX__ */
Guido van Rossum234f9421993-06-17 12:35:49 +000086
Guido van Rossum3917c221997-04-02 05:35:28 +000087#ifdef MS_WIN32
88/* Win32 has better clock replacement */
89#include <largeint.h>
90#undef HAVE_CLOCK /* We have our own version down below */
91#endif /* MS_WIN32 */
92
Guido van Rossum8e9ebfd1997-11-22 21:53:48 +000093#if defined(PYOS_OS2)
94#define INCL_DOS
95#define INCL_DOSERRORS
96#define INCL_NOPMAPI
97#include <os2.h>
98#endif
99
100#if defined(PYCC_VACPP)
101#include <time.h>
102#define timezone _timezone
103#endif
104
Guido van Rossumbcc20741998-08-04 22:53:56 +0000105#ifdef __BEOS__
106/* For bigtime_t, snooze(). - [cjh] */
107#include <support/SupportDefs.h>
108#include <kernel/OS.h>
109#endif
110
Guido van Rossum234f9421993-06-17 12:35:49 +0000111/* Forward declarations */
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000112static int floatsleep Py_PROTO((double));
113static double floattime Py_PROTO(());
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000114
Guido van Rossume6a4b7b1997-10-08 15:27:56 +0000115#ifdef macintosh
116/* Our own timezone. We have enough information to deduce whether
117** DST is on currently, but unfortunately we cannot put it to good
118** use because we don't know the rules (and that is needed to have
119** localtime() return correct tm_isdst values for times other than
120** the current time. So, we cop out and only tell the user the current
121** timezone.
122*/
123static long timezone;
124
125static void
126initmactimezone()
127{
128 MachineLocation loc;
129 long delta;
130
131 ReadLocation(&loc);
132
133 if (loc.latitude == 0 && loc.longitude == 0 && loc.u.gmtDelta == 0)
134 return;
135
136 delta = loc.u.gmtDelta & 0x00FFFFFF;
137
138 if (delta & 0x00800000)
139 delta |= 0xFF000000;
140
141 timezone = -delta;
142}
143#endif /* macintosh */
144
145
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000146static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000147time_time(self, args)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000148 PyObject *self;
149 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000150{
Guido van Rossumb6775db1994-08-01 11:34:53 +0000151 double secs;
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000152 if (!PyArg_NoArgs(args))
Guido van Rossuma2b7f401993-01-04 09:09:59 +0000153 return NULL;
Guido van Rossumb6775db1994-08-01 11:34:53 +0000154 secs = floattime();
155 if (secs == 0.0) {
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000156 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossuma2b7f401993-01-04 09:09:59 +0000157 return NULL;
158 }
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000159 return PyFloat_FromDouble(secs);
Guido van Rossumb6775db1994-08-01 11:34:53 +0000160}
161
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000162static char time_doc[] =
163"time() -> floating point number\n\
164\n\
165Return the current time in seconds since the Epoch.\n\
166Fractions of a second may be present if the system clock provides them.";
167
Guido van Rossumb6775db1994-08-01 11:34:53 +0000168#ifdef HAVE_CLOCK
169
170#ifndef CLOCKS_PER_SEC
Guido van Rossum1b66a4f1996-02-25 04:50:33 +0000171#ifdef CLK_TCK
172#define CLOCKS_PER_SEC CLK_TCK
173#else
Guido van Rossumb6775db1994-08-01 11:34:53 +0000174#define CLOCKS_PER_SEC 1000000
175#endif
Guido van Rossum1b66a4f1996-02-25 04:50:33 +0000176#endif
Guido van Rossumb6775db1994-08-01 11:34:53 +0000177
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000178static PyObject *
Guido van Rossumb6775db1994-08-01 11:34:53 +0000179time_clock(self, args)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000180 PyObject *self;
181 PyObject *args;
Guido van Rossumb6775db1994-08-01 11:34:53 +0000182{
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000183 if (!PyArg_NoArgs(args))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000184 return NULL;
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000185 return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000186}
Guido van Rossumb6775db1994-08-01 11:34:53 +0000187#endif /* HAVE_CLOCK */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000188
Guido van Rossum3917c221997-04-02 05:35:28 +0000189#ifdef MS_WIN32
190/* Due to Mark Hammond */
191static PyObject *
192time_clock(self, args)
193 PyObject *self;
194 PyObject *args;
195{
196 static LARGE_INTEGER ctrStart;
197 static LARGE_INTEGER divisor = {0,0};
198 LARGE_INTEGER now, diff, rem;
199
200 if (!PyArg_NoArgs(args))
201 return NULL;
202
203 if (LargeIntegerEqualToZero(divisor)) {
204 QueryPerformanceCounter(&ctrStart);
205 if (!QueryPerformanceFrequency(&divisor) ||
206 LargeIntegerEqualToZero(divisor)) {
207 /* Unlikely to happen -
208 this works on all intel machines at least!
209 Revert to clock() */
210 return PyFloat_FromDouble(clock());
211 }
212 }
213 QueryPerformanceCounter(&now);
214 diff = LargeIntegerSubtract(now, ctrStart);
215 diff = LargeIntegerDivide(diff, divisor, &rem);
216 /* XXX - we assume both divide results fit in 32 bits. This is
217 true on Intels. First person who can afford a machine that
218 doesnt deserves to fix it :-)
219 */
220 return PyFloat_FromDouble((double)diff.LowPart +
221 ((double)rem.LowPart / (double)divisor.LowPart));
222}
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000223
Guido van Rossum3917c221997-04-02 05:35:28 +0000224#define HAVE_CLOCK /* So it gets included in the methods */
225#endif /* MS_WIN32 */
226
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000227#ifdef HAVE_CLOCK
228static char clock_doc[] =
229"clock() -> floating point number\n\
230\n\
231Return the CPU time or real time since the start of the process or since\n\
232the first call to clock(). This has as much precision as the system records.";
233#endif
234
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000235static PyObject *
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000236time_sleep(self, args)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000237 PyObject *self;
238 PyObject *args;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000239{
Guido van Rossum775f4da1993-01-09 17:18:52 +0000240 double secs;
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000241 if (!PyArg_Parse(args, "d", &secs))
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000242 return NULL;
Guido van Rossum8607ae21997-11-03 22:04:46 +0000243 if (floatsleep(secs) != 0)
244 return NULL;
245 Py_INCREF(Py_None);
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000246 return Py_None;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000247}
248
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000249static char sleep_doc[] =
250"sleep(seconds)\n\
251\n\
252Delay execution for a given number of seconds. The argument may be\n\
253a floating point number for subsecond precision.";
254
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000255static PyObject *
Guido van Rossum87ce7bb1998-06-09 16:30:31 +0000256tmtotuple(p)
257 struct tm *p;
258{
259 return Py_BuildValue("(iiiiiiiii)",
260 p->tm_year + 1900,
261 p->tm_mon + 1, /* Want January == 1 */
262 p->tm_mday,
263 p->tm_hour,
264 p->tm_min,
265 p->tm_sec,
266 (p->tm_wday + 6) % 7, /* Want Monday == 0 */
267 p->tm_yday + 1, /* Want January, 1 == 1 */
268 p->tm_isdst);
269}
270
271static PyObject *
Guido van Rossum234f9421993-06-17 12:35:49 +0000272time_convert(when, function)
273 time_t when;
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000274 struct tm * (*function) Py_PROTO((const time_t *));
Guido van Rossum234f9421993-06-17 12:35:49 +0000275{
Guido van Rossum6e8583d1996-10-08 14:19:52 +0000276 struct tm *p;
277 errno = 0;
278 p = function(&when);
279 if (p == NULL) {
280#ifdef EINVAL
Guido van Rossum0b1ff661996-11-02 17:31:22 +0000281 if (errno == 0)
Guido van Rossum6e8583d1996-10-08 14:19:52 +0000282 errno = EINVAL;
283#endif
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000284 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum6e8583d1996-10-08 14:19:52 +0000285 }
Guido van Rossum87ce7bb1998-06-09 16:30:31 +0000286 return tmtotuple(p);
Guido van Rossum234f9421993-06-17 12:35:49 +0000287}
288
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000289static PyObject *
Guido van Rossum234f9421993-06-17 12:35:49 +0000290time_gmtime(self, args)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000291 PyObject *self;
292 PyObject *args;
Guido van Rossum234f9421993-06-17 12:35:49 +0000293{
294 double when;
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000295 if (!PyArg_Parse(args, "d", &when))
Guido van Rossum234f9421993-06-17 12:35:49 +0000296 return NULL;
297 return time_convert((time_t)when, gmtime);
298}
299
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000300static char gmtime_doc[] =
301"gmtime(seconds) -> tuple\n\
302\n\
303Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a. GMT).";
304
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000305static PyObject *
Guido van Rossum234f9421993-06-17 12:35:49 +0000306time_localtime(self, args)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000307 PyObject *self;
308 PyObject *args;
Guido van Rossum234f9421993-06-17 12:35:49 +0000309{
310 double when;
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000311 if (!PyArg_Parse(args, "d", &when))
Guido van Rossum234f9421993-06-17 12:35:49 +0000312 return NULL;
313 return time_convert((time_t)when, localtime);
314}
315
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000316static char localtime_doc[] =
317"localtime(seconds) -> tuple\n\
318Convert seconds since the Epoch to a time tuple expressing local time.";
319
Guido van Rossum9e90a671993-06-24 11:10:19 +0000320static int
321gettmarg(args, p)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000322 PyObject *args;
Guido van Rossum9e90a671993-06-24 11:10:19 +0000323 struct tm *p;
324{
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000325 if (!PyArg_Parse(args, "(iiiiiiiii)",
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000326 &p->tm_year,
327 &p->tm_mon,
328 &p->tm_mday,
329 &p->tm_hour,
330 &p->tm_min,
331 &p->tm_sec,
332 &p->tm_wday,
333 &p->tm_yday,
334 &p->tm_isdst))
Guido van Rossum9e90a671993-06-24 11:10:19 +0000335 return 0;
336 if (p->tm_year >= 1900)
337 p->tm_year -= 1900;
338 p->tm_mon--;
339 p->tm_wday = (p->tm_wday + 1) % 7;
340 p->tm_yday--;
341 return 1;
342}
343
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000344#ifdef HAVE_STRFTIME
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000345static PyObject *
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000346time_strftime(self, args)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000347 PyObject *self;
348 PyObject *args;
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000349{
350 struct tm buf;
351 const char *fmt;
352 char *outbuf = 0;
353 int i;
354
Guido van Rossum1f41f841998-04-27 19:04:26 +0000355 memset((ANY *) &buf, '\0', sizeof(buf));
356
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000357 if (!PyArg_ParseTuple(args, "s(iiiiiiiii)",
358 &fmt,
359 &(buf.tm_year),
360 &(buf.tm_mon),
361 &(buf.tm_mday),
362 &(buf.tm_hour),
363 &(buf.tm_min),
364 &(buf.tm_sec),
365 &(buf.tm_wday),
366 &(buf.tm_yday),
367 &(buf.tm_isdst)))
368 return NULL;
369 if (buf.tm_year >= 1900)
370 buf.tm_year -= 1900;
371 buf.tm_mon--;
372 buf.tm_wday = (buf.tm_wday + 1) % 7;
373 buf.tm_yday--;
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000374 /* I hate these functions that presume you know how big the output
375 * will be ahead of time...
376 */
Guido van Rossuma78bfe11997-02-14 16:35:10 +0000377 for (i = 1024 ; i <= 8192 ; i += 1024) {
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000378 outbuf = malloc(i);
379 if (outbuf == NULL) {
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000380 return PyErr_NoMemory();
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000381 }
382 if (strftime(outbuf, i-1, fmt, &buf) != 0) {
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000383 PyObject *ret;
384 ret = PyString_FromString(outbuf);
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000385 free(outbuf);
386 return ret;
387 }
388 free(outbuf);
389 }
Guido van Rossuma78bfe11997-02-14 16:35:10 +0000390 PyErr_SetString(PyExc_ValueError,
391 "bad strftime format or result too big");
392 return NULL;
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000393}
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000394
395static char strftime_doc[] =
396"strftime(format, tuple) -> string\n\
397\n\
398Convert a time tuple to a string according to a format specification.\n\
399See the library reference manual for formatting codes.";
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000400#endif /* HAVE_STRFTIME */
401
Guido van Rossum87ce7bb1998-06-09 16:30:31 +0000402#ifdef HAVE_STRPTIME
403static PyObject *
404time_strptime(self, args)
405 PyObject *self;
406 PyObject *args;
407{
408 struct tm tm;
409 char *fmt = "%a %b %d %H:%M:%S %Y";
410 char *buf;
411 char *s;
412
413 if (!PyArg_ParseTuple(args, "s|s", &buf, &fmt)) {
414 PyErr_SetString(PyExc_ValueError, "invalid argument");
415 return NULL;
416 }
417 s = strptime(buf, fmt, &tm);
418 if (s == NULL) {
419 PyErr_SetString(PyExc_ValueError, "format mismatch");
420 return NULL;
421 }
422 while (*s && isspace(*s))
423 s++;
424 if (*s) {
425 PyErr_Format(PyExc_ValueError,
426 "unconverted data remains: '%.400s'", s);
427 return NULL;
428 }
429 return tmtotuple(&tm);
430}
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000431
432static char strptime_doc[] =
433"strptime(format, string) -> tuple\n\
434Parse a string to a time tuple according to a format specification.\n\
435See the library reference manual for formatting codes (same as strftime()).";
Guido van Rossum87ce7bb1998-06-09 16:30:31 +0000436#endif /* HAVE_STRPTIME */
437
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000438static PyObject *
Guido van Rossum9e90a671993-06-24 11:10:19 +0000439time_asctime(self, args)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000440 PyObject *self;
441 PyObject *args;
Guido van Rossum9e90a671993-06-24 11:10:19 +0000442{
443 struct tm buf;
444 char *p;
445 if (!gettmarg(args, &buf))
446 return NULL;
447 p = asctime(&buf);
448 if (p[24] == '\n')
449 p[24] = '\0';
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000450 return PyString_FromString(p);
Guido van Rossum9e90a671993-06-24 11:10:19 +0000451}
452
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000453static char asctime_doc[] =
454"asctime(tuple) -> string\n\
455\n\
456Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.";
457
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000458static PyObject *
Guido van Rossum9e90a671993-06-24 11:10:19 +0000459time_ctime(self, args)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000460 PyObject *self;
461 PyObject *args;
Guido van Rossum9e90a671993-06-24 11:10:19 +0000462{
463 double dt;
464 time_t tt;
465 char *p;
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000466 if (!PyArg_Parse(args, "d", &dt))
Guido van Rossum9e90a671993-06-24 11:10:19 +0000467 return NULL;
Guido van Rossumcac6c721996-09-06 13:34:02 +0000468 tt = (time_t)dt;
Guido van Rossum9e90a671993-06-24 11:10:19 +0000469 p = ctime(&tt);
Guido van Rossum78535701998-03-03 22:19:10 +0000470 if (p == NULL) {
471 PyErr_SetString(PyExc_ValueError, "unconvertible time");
472 return NULL;
473 }
Guido van Rossum9e90a671993-06-24 11:10:19 +0000474 if (p[24] == '\n')
475 p[24] = '\0';
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000476 return PyString_FromString(p);
Guido van Rossum9e90a671993-06-24 11:10:19 +0000477}
478
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000479static char ctime_doc[] =
480"ctime(seconds) -> string\n\
481\n\
482Convert a time in seconds since the Epoch to a string in local time.\n\
483This is equivalent to asctime(localtime(seconds)).";
484
Guido van Rossum60cd8131998-03-06 17:16:21 +0000485#ifdef HAVE_MKTIME
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000486static PyObject *
Guido van Rossum234f9421993-06-17 12:35:49 +0000487time_mktime(self, args)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000488 PyObject *self;
489 PyObject *args;
Guido van Rossum234f9421993-06-17 12:35:49 +0000490{
491 struct tm buf;
Guido van Rossumbceeac81996-05-23 22:53:47 +0000492 time_t tt;
493 tt = time(&tt);
494 buf = *localtime(&tt);
Guido van Rossum9e90a671993-06-24 11:10:19 +0000495 if (!gettmarg(args, &buf))
Guido van Rossum234f9421993-06-17 12:35:49 +0000496 return NULL;
Guido van Rossumbceeac81996-05-23 22:53:47 +0000497 tt = mktime(&buf);
498 if (tt == (time_t)(-1)) {
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000499 PyErr_SetString(PyExc_OverflowError,
500 "mktime argument out of range");
Guido van Rossumbceeac81996-05-23 22:53:47 +0000501 return NULL;
502 }
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000503 return PyFloat_FromDouble((double)tt);
Guido van Rossum234f9421993-06-17 12:35:49 +0000504}
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000505
506static char mktime_doc[] =
507"mktime(tuple) -> floating point number\n\
508\n\
509Convert a time tuple in local time to seconds since the Epoch.";
Guido van Rossum60cd8131998-03-06 17:16:21 +0000510#endif /* HAVE_MKTIME */
Guido van Rossum234f9421993-06-17 12:35:49 +0000511
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000512static PyMethodDef time_methods[] = {
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000513 {"time", time_time, 0, time_doc},
Guido van Rossumb6775db1994-08-01 11:34:53 +0000514#ifdef HAVE_CLOCK
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000515 {"clock", time_clock, 0, clock_doc},
Guido van Rossumb6775db1994-08-01 11:34:53 +0000516#endif
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000517 {"sleep", time_sleep, 0, sleep_doc},
518 {"gmtime", time_gmtime, 0, gmtime_doc},
519 {"localtime", time_localtime, 0, localtime_doc},
520 {"asctime", time_asctime, 0, asctime_doc},
521 {"ctime", time_ctime, 0, ctime_doc},
Guido van Rossum60cd8131998-03-06 17:16:21 +0000522#ifdef HAVE_MKTIME
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000523 {"mktime", time_mktime, 0, mktime_doc},
Guido van Rossum60cd8131998-03-06 17:16:21 +0000524#endif
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000525#ifdef HAVE_STRFTIME
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000526 {"strftime", time_strftime, 1, strftime_doc},
Guido van Rossum8d8c1ee1995-09-13 17:38:35 +0000527#endif
Guido van Rossum87ce7bb1998-06-09 16:30:31 +0000528#ifdef HAVE_STRPTIME
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000529 {"strptime", time_strptime, 1, strptime_doc},
Guido van Rossum87ce7bb1998-06-09 16:30:31 +0000530#endif
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000531 {NULL, NULL} /* sentinel */
532};
533
Guido van Rossum8239f0f1995-01-22 00:49:01 +0000534static void
535ins(d, name, v)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000536 PyObject *d;
Guido van Rossum8239f0f1995-01-22 00:49:01 +0000537 char *name;
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000538 PyObject *v;
Guido van Rossum8239f0f1995-01-22 00:49:01 +0000539{
540 if (v == NULL)
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000541 Py_FatalError("Can't initialize time module -- NULL value");
542 if (PyDict_SetItemString(d, name, v) != 0)
543 Py_FatalError(
Guido van Rossum52174571996-12-09 18:38:52 +0000544 "Can't initialize time module -- PyDict_SetItemString failed");
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000545 Py_DECREF(v);
Guido van Rossum8239f0f1995-01-22 00:49:01 +0000546}
547
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000548static char module_doc[] =
549"This module provides various functions to manipulate time values.\n\
550\n\
551There are two standard representations of time. One is the number\n\
552of seconds since the Epoch, in UTC (a.k.a. GMT). It may be an integer\n\
553or a floating point number (to represent fractions of seconds).\n\
554The Epoch is system-defined; on Unix, it is generally January 1st, 1970.\n\
555The actual value can be retrieved by calling gmtime(0).\n\
556\n\
557The other representation is a tuple of 9 integers giving local time.\n\
558The tuple items are:\n\
559 year (four digits, e.g. 1998)\n\
560 month (1-12)\n\
561 day (1-31)\n\
562 hours (0-23)\n\
563 minutes (0-59)\n\
564 seconds (0-61, to allow for leap seconds)\n\
565 weekday (0-6, Monday is 0)\n\
566 Julian day (day in the year, 1-366)\n\
567 DST (Daylight Savings Time) flag (-1, 0 or 1)\n\
568If the DST flag is 0, the time is given in the regular time zone;\n\
569if it is 1, the time is given in the DST time zone;\n\
570if it is -1, mktime() should guess based on the date and time.\n\
571\n\
572Variables:\n\
573\n\
574timezone -- difference in seconds between UTC and local standard time\n\
575altzone -- difference in seconds between UTC and local DST time\n\
576daylight -- whether local time should reflect DST\n\
577tzname -- tuple of (standard time zone name, DST time zone name)\n\
578\n\
579Functions:\n\
580\n\
581time() -- return current time in seconds since the Epoch as a float\n\
582clock() -- return CPU time since process start as a float\n\
583sleep() -- delay for a number of seconds given as a float\n\
584gmtime() -- convert seconds since Epoch to UTC tuple\n\
585localtime() -- convert seconds since Epoch to local time tuple\n\
586asctime() -- convert time tuple to string\n\
587ctime() -- convert time in seconds to string\n\
588mktime() -- convert local time tuple to seconds since Epoch\n\
589strftime() -- convert time tuple to string according to format specification\n\
590strptime() -- parse string to time tuple according to format specification\n\
591";
592
593
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000594void
595inittime()
596{
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000597 PyObject *m, *d;
Guido van Rossum0ef577b1998-06-27 20:38:36 +0000598 m = Py_InitModule3("time", time_methods, module_doc);
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000599 d = PyModule_GetDict(m);
Guido van Rossumb6775db1994-08-01 11:34:53 +0000600#ifdef HAVE_TZNAME
Guido van Rossum234f9421993-06-17 12:35:49 +0000601 tzset();
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000602 ins(d, "timezone", PyInt_FromLong((long)timezone));
Guido van Rossumb6775db1994-08-01 11:34:53 +0000603#ifdef HAVE_ALTZONE
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000604 ins(d, "altzone", PyInt_FromLong((long)altzone));
Guido van Rossumb6775db1994-08-01 11:34:53 +0000605#else
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000606 ins(d, "altzone", PyInt_FromLong((long)timezone-3600));
Guido van Rossumb6775db1994-08-01 11:34:53 +0000607#endif
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000608 ins(d, "daylight", PyInt_FromLong((long)daylight));
609 ins(d, "tzname", Py_BuildValue("(zz)", tzname[0], tzname[1]));
Guido van Rossumb6775db1994-08-01 11:34:53 +0000610#else /* !HAVE_TZNAME */
611#if HAVE_TM_ZONE
Guido van Rossum234f9421993-06-17 12:35:49 +0000612 {
613#define YEAR ((time_t)((365 * 24 + 6) * 3600))
614 time_t t;
615 struct tm *p;
616 long winterzone, summerzone;
617 char wintername[10], summername[10];
Guido van Rossumb6775db1994-08-01 11:34:53 +0000618 /* XXX This won't work on the southern hemisphere.
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000619 XXX Anybody got a better idea? */
Guido van Rossum234f9421993-06-17 12:35:49 +0000620 t = (time((time_t *)0) / YEAR) * YEAR;
621 p = localtime(&t);
622 winterzone = -p->tm_gmtoff;
623 strncpy(wintername, p->tm_zone ? p->tm_zone : " ", 9);
624 wintername[9] = '\0';
625 t += YEAR/2;
626 p = localtime(&t);
627 summerzone = -p->tm_gmtoff;
628 strncpy(summername, p->tm_zone ? p->tm_zone : " ", 9);
629 summername[9] = '\0';
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000630 ins(d, "timezone", PyInt_FromLong(winterzone));
631 ins(d, "altzone", PyInt_FromLong(summerzone));
632 ins(d, "daylight",
633 PyInt_FromLong((long)(winterzone != summerzone)));
634 ins(d, "tzname",
635 Py_BuildValue("(zz)", wintername, summername));
Guido van Rossum234f9421993-06-17 12:35:49 +0000636 }
Guido van Rossume6a4b7b1997-10-08 15:27:56 +0000637#else
638#ifdef macintosh
Guido van Rossumbe1eb0d1997-12-08 21:56:43 +0000639 /* The only thing we can obtain is the current timezone
640 ** (and whether dst is currently _active_, but that is not what
641 ** we're looking for:-( )
642 */
Guido van Rossume6a4b7b1997-10-08 15:27:56 +0000643 initmactimezone();
644 ins(d, "timezone", PyInt_FromLong(timezone));
Guido van Rossumbe1eb0d1997-12-08 21:56:43 +0000645 ins(d, "altzone", PyInt_FromLong(timezone));
646 ins(d, "daylight", PyInt_FromLong((long)0));
647 ins(d, "tzname", Py_BuildValue("(zz)", "", ""));
Guido van Rossume6a4b7b1997-10-08 15:27:56 +0000648#endif /* macintosh */
Guido van Rossumb6775db1994-08-01 11:34:53 +0000649#endif /* HAVE_TM_ZONE */
650#endif /* !HAVE_TZNAME */
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000651 if (PyErr_Occurred())
652 Py_FatalError("Can't initialize time module");
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000653}
654
655
Guido van Rossumb6775db1994-08-01 11:34:53 +0000656/* Implement floattime() for various platforms */
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000657
Guido van Rossumb6775db1994-08-01 11:34:53 +0000658static double
659floattime()
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000660{
Guido van Rossumb6775db1994-08-01 11:34:53 +0000661 /* There are three ways to get the time:
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000662 (1) gettimeofday() -- resolution in microseconds
663 (2) ftime() -- resolution in milliseconds
664 (3) time() -- resolution in seconds
665 In all cases the return value is a float in seconds.
666 Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may
667 fail, so we fall back on ftime() or time().
668 Note: clock resolution does not imply clock accuracy! */
Guido van Rossumb6775db1994-08-01 11:34:53 +0000669#ifdef HAVE_GETTIMEOFDAY
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000670 {
671 struct timeval t;
Guido van Rossum3bbc62e1995-01-02 19:30:30 +0000672#ifdef GETTIMEOFDAY_NO_TZ
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000673 if (gettimeofday(&t) == 0)
674 return (double)t.tv_sec + t.tv_usec*0.000001;
Guido van Rossum3bbc62e1995-01-02 19:30:30 +0000675#else /* !GETTIMEOFDAY_NO_TZ */
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000676 if (gettimeofday(&t, (struct timezone *)NULL) == 0)
677 return (double)t.tv_sec + t.tv_usec*0.000001;
Guido van Rossum3bbc62e1995-01-02 19:30:30 +0000678#endif /* !GETTIMEOFDAY_NO_TZ */
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000679 }
Guido van Rossumb6775db1994-08-01 11:34:53 +0000680#endif /* !HAVE_GETTIMEOFDAY */
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000681 {
Guido van Rossumbcc20741998-08-04 22:53:56 +0000682#if defined(HAVE_FTIME) && !defined(__BEOS__)
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000683 struct timeb t;
684 ftime(&t);
685 return (double)t.time + (double)t.millitm * (double)0.001;
Guido van Rossumb6775db1994-08-01 11:34:53 +0000686#else /* !HAVE_FTIME */
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000687 time_t secs;
688 time(&secs);
689 return (double)secs;
Guido van Rossumb6775db1994-08-01 11:34:53 +0000690#endif /* !HAVE_FTIME */
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000691 }
Guido van Rossum426035c1991-02-19 12:27:35 +0000692}
693
Guido van Rossumb6775db1994-08-01 11:34:53 +0000694
695/* Implement floatsleep() for various platforms.
696 When interrupted (or when another error occurs), return -1 and
697 set an exception; else return 0. */
698
699static int
Guido van Rossuma320fd31995-03-09 12:14:15 +0000700#ifdef MPW
701floatsleep(double secs)
702#else
Barry Warsaw4a6cf411997-01-13 22:44:55 +0000703 floatsleep(secs)
Guido van Rossum775f4da1993-01-09 17:18:52 +0000704 double secs;
Guido van Rossuma320fd31995-03-09 12:14:15 +0000705#endif /* MPW */
Guido van Rossum426035c1991-02-19 12:27:35 +0000706{
Guido van Rossuma78bfe11997-02-14 16:35:10 +0000707/* XXX Should test for MS_WIN32 first! */
Guido van Rossumbcc20741998-08-04 22:53:56 +0000708#if defined(HAVE_SELECT) && !defined(__BEOS__)
Guido van Rossum426035c1991-02-19 12:27:35 +0000709 struct timeval t;
Guido van Rossum775f4da1993-01-09 17:18:52 +0000710 double frac;
Guido van Rossum775f4da1993-01-09 17:18:52 +0000711 frac = fmod(secs, 1.0);
712 secs = floor(secs);
713 t.tv_sec = (long)secs;
714 t.tv_usec = (long)(frac*1000000.0);
Guido van Rossum8607ae21997-11-03 22:04:46 +0000715 Py_BEGIN_ALLOW_THREADS
Guido van Rossumb6775db1994-08-01 11:34:53 +0000716 if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) {
Guido van Rossum8607ae21997-11-03 22:04:46 +0000717 Py_BLOCK_THREADS
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000718 PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossumb6775db1994-08-01 11:34:53 +0000719 return -1;
720 }
Guido van Rossum8607ae21997-11-03 22:04:46 +0000721 Py_END_ALLOW_THREADS
Guido van Rossumbcc20741998-08-04 22:53:56 +0000722#else /* !HAVE_SELECT || __BEOS__ */
Guido van Rossumb6775db1994-08-01 11:34:53 +0000723#ifdef macintosh
724#define MacTicks (* (long *)0x16A)
725 long deadline;
726 deadline = MacTicks + (long)(secs * 60.0);
727 while (MacTicks < deadline) {
Guido van Rossum8607ae21997-11-03 22:04:46 +0000728 /* XXX Should call some yielding function here */
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000729 if (PyErr_CheckSignals())
Guido van Rossumb6775db1994-08-01 11:34:53 +0000730 return -1;
731 }
732#else /* !macintosh */
Guido van Rossum7bf22de1997-12-02 20:34:19 +0000733#if defined(__WATCOMC__) && !defined(__QNX__)
Guido van Rossumbceeac81996-05-23 22:53:47 +0000734 /* XXX Can't interrupt this sleep */
Guido van Rossum8607ae21997-11-03 22:04:46 +0000735 Py_BEGIN_ALLOW_THREADS
Guido van Rossumbceeac81996-05-23 22:53:47 +0000736 delay((int)(secs * 1000 + 0.5)); /* delay() uses milliseconds */
Guido van Rossum8607ae21997-11-03 22:04:46 +0000737 Py_END_ALLOW_THREADS
Guido van Rossum7bf22de1997-12-02 20:34:19 +0000738#else /* !__WATCOMC__ || __QNX__ */
Guido van Rossume22e6441993-07-09 10:51:31 +0000739#ifdef MSDOS
Guido van Rossumb6775db1994-08-01 11:34:53 +0000740 struct timeb t1, t2;
741 double frac;
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000742 extern double fmod Py_PROTO((double, double));
743 extern double floor Py_PROTO((double));
Guido van Rossumb6775db1994-08-01 11:34:53 +0000744 if (secs <= 0.0)
745 return;
746 frac = fmod(secs, 1.0);
747 secs = floor(secs);
748 ftime(&t1);
749 t2.time = t1.time + (int)secs;
750 t2.millitm = t1.millitm + (int)(frac*1000.0);
751 while (t2.millitm >= 1000) {
752 t2.time++;
753 t2.millitm -= 1000;
754 }
755 for (;;) {
756#ifdef QUICKWIN
Guido van Rossum8607ae21997-11-03 22:04:46 +0000757 Py_BEGIN_ALLOW_THREADS
Guido van Rossumb6775db1994-08-01 11:34:53 +0000758 _wyield();
Guido van Rossum8607ae21997-11-03 22:04:46 +0000759 Py_END_ALLOW_THREADS
Guido van Rossum80c9d881991-04-16 08:47:51 +0000760#endif
Barry Warsaw9a2a8a81996-12-06 23:32:14 +0000761 if (PyErr_CheckSignals())
Guido van Rossumb6775db1994-08-01 11:34:53 +0000762 return -1;
763 ftime(&t1);
764 if (t1.time > t2.time ||
765 t1.time == t2.time && t1.millitm >= t2.millitm)
766 break;
767 }
768#else /* !MSDOS */
Guido van Rossumb2fb3641996-09-07 00:47:35 +0000769#ifdef MS_WIN32
Guido van Rossumb6775db1994-08-01 11:34:53 +0000770 /* XXX Can't interrupt this sleep */
Guido van Rossum8607ae21997-11-03 22:04:46 +0000771 Py_BEGIN_ALLOW_THREADS
Guido van Rossumb6775db1994-08-01 11:34:53 +0000772 Sleep((int)(secs*1000));
Guido van Rossum8607ae21997-11-03 22:04:46 +0000773 Py_END_ALLOW_THREADS
Guido van Rossumb2fb3641996-09-07 00:47:35 +0000774#else /* !MS_WIN32 */
Guido van Rossum8e9ebfd1997-11-22 21:53:48 +0000775#ifdef PYOS_OS2
776 /* This Sleep *IS* Interruptable by Exceptions */
Guido van Rossum1d0d7e41997-12-29 20:03:10 +0000777 Py_BEGIN_ALLOW_THREADS
Guido van Rossum8e9ebfd1997-11-22 21:53:48 +0000778 if (DosSleep(secs * 1000) != NO_ERROR) {
Guido van Rossum1d0d7e41997-12-29 20:03:10 +0000779 Py_BLOCK_THREADS
Guido van Rossum8e9ebfd1997-11-22 21:53:48 +0000780 PyErr_SetFromErrno(PyExc_IOError);
781 return -1;
782 }
Guido van Rossum1d0d7e41997-12-29 20:03:10 +0000783 Py_END_ALLOW_THREADS
Guido van Rossum8e9ebfd1997-11-22 21:53:48 +0000784#else /* !PYOS_OS2 */
Guido van Rossumbcc20741998-08-04 22:53:56 +0000785#ifdef __BEOS__
786 /* This sleep *CAN BE* interrupted. */
787 {
788 bigtime_t frac, seconds;
789
790 extern double fmod Py_PROTO((double,double));
791 extern double floor Py_PROTO((double));
792
793 if( secs <= 0.0 ) {
794 return;
795 }
796
797 frac = (bigtime_t)fmod( secs, 1.0 );
798 seconds = (bigtime_t)floor( secs );
799
800 Py_BEGIN_ALLOW_THREADS
801 if( snooze( seconds * (bigtime_t)1000 + frac ) == B_INTERRUPTED ) {
802 Py_BLOCK_THREADS
803 PyErr_SetFromErrno( PyExc_IOError );
804 return -1;
805 }
806 Py_END_ALLOW_THREADS
807 }
808#else /* !__BEOS__ */
Guido van Rossumb6775db1994-08-01 11:34:53 +0000809 /* XXX Can't interrupt this sleep */
Guido van Rossum8607ae21997-11-03 22:04:46 +0000810 Py_BEGIN_ALLOW_THREADS
Guido van Rossumb6775db1994-08-01 11:34:53 +0000811 sleep((int)secs);
Guido van Rossum8607ae21997-11-03 22:04:46 +0000812 Py_END_ALLOW_THREADS
Guido van Rossumbcc20741998-08-04 22:53:56 +0000813#endif /* !__BEOS__ */
Guido van Rossum8e9ebfd1997-11-22 21:53:48 +0000814#endif /* !PYOS_OS2 */
Guido van Rossumb2fb3641996-09-07 00:47:35 +0000815#endif /* !MS_WIN32 */
Guido van Rossumb6775db1994-08-01 11:34:53 +0000816#endif /* !MSDOS */
Guido van Rossum7bf22de1997-12-02 20:34:19 +0000817#endif /* !__WATCOMC__ || __QNX__ */
Guido van Rossumb6775db1994-08-01 11:34:53 +0000818#endif /* !macintosh */
819#endif /* !HAVE_SELECT */
820 return 0;
Guido van Rossum80c9d881991-04-16 08:47:51 +0000821}