Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 524b588 | 1995-01-04 19:10:35 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 32 | /* Time module */ |
| 33 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 34 | #include "Python.h" |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 35 | |
Guido van Rossum | 87ce7bb | 1998-06-09 16:30:31 +0000 | [diff] [blame] | 36 | #include <ctype.h> |
| 37 | |
Guido van Rossum | 99d90c0 | 1996-08-08 19:17:45 +0000 | [diff] [blame] | 38 | #ifdef HAVE_SELECT |
| 39 | #include "mymath.h" |
| 40 | #endif |
| 41 | |
Guido van Rossum | 6d946f9 | 1992-08-14 13:49:30 +0000 | [diff] [blame] | 42 | #ifdef macintosh |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 43 | #include <time.h> |
| 44 | #else |
| 45 | #include <sys/types.h> |
Guido van Rossum | 6d946f9 | 1992-08-14 13:49:30 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 48 | #ifdef QUICKWIN |
| 49 | #include <io.h> |
| 50 | #endif |
| 51 | |
| 52 | #ifdef HAVE_UNISTD_H |
Guido van Rossum | 2762f25 | 1992-03-27 17:22:13 +0000 | [diff] [blame] | 53 | #include <unistd.h> |
| 54 | #endif |
| 55 | |
Guido van Rossum | bcc2074 | 1998-08-04 22:53:56 +0000 | [diff] [blame] | 56 | #if defined(HAVE_SELECT) && !defined(__BEOS__) |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 57 | #include "myselect.h" |
| 58 | #else |
| 59 | #include "mytime.h" |
| 60 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 61 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 62 | #ifdef HAVE_FTIME |
Guido van Rossum | bcc2074 | 1998-08-04 22:53:56 +0000 | [diff] [blame] | 63 | #ifndef __BEOS__ |
| 64 | /* We have ftime(), but not in the headers (PR2). - [cjh] */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 65 | #include <sys/timeb.h> |
Guido van Rossum | bcc2074 | 1998-08-04 22:53:56 +0000 | [diff] [blame] | 66 | #endif |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 67 | #if !defined(MS_WINDOWS) && !defined(PYOS_OS2) |
Guido van Rossum | 1bb126f | 1996-12-06 20:17:44 +0000 | [diff] [blame] | 68 | extern int ftime(); |
Guido van Rossum | 5217457 | 1996-12-09 18:38:52 +0000 | [diff] [blame] | 69 | #endif /* MS_WINDOWS */ |
| 70 | #endif /* HAVE_FTIME */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 71 | |
Guido van Rossum | 7bf22de | 1997-12-02 20:34:19 +0000 | [diff] [blame] | 72 | #if defined(__WATCOMC__) && !defined(__QNX__) |
Guido van Rossum | bceeac8 | 1996-05-23 22:53:47 +0000 | [diff] [blame] | 73 | #include <i86.h> |
| 74 | #else |
Guido van Rossum | cac6c72 | 1996-09-06 13:34:02 +0000 | [diff] [blame] | 75 | #ifdef MS_WINDOWS |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 76 | #include <windows.h> |
Guido van Rossum | b2fb364 | 1996-09-07 00:47:35 +0000 | [diff] [blame] | 77 | #ifdef MS_WIN16 |
| 78 | /* These overrides not needed for Win32 */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 79 | #define timezone _timezone |
Guido van Rossum | cc08112 | 1995-03-14 15:05:41 +0000 | [diff] [blame] | 80 | #define tzname _tzname |
| 81 | #define daylight _daylight |
| 82 | #define altzone _altzone |
Guido van Rossum | b2fb364 | 1996-09-07 00:47:35 +0000 | [diff] [blame] | 83 | #endif /* MS_WIN16 */ |
Guido van Rossum | cac6c72 | 1996-09-06 13:34:02 +0000 | [diff] [blame] | 84 | #endif /* MS_WINDOWS */ |
Guido van Rossum | 7bf22de | 1997-12-02 20:34:19 +0000 | [diff] [blame] | 85 | #endif /* !__WATCOMC__ || __QNX__ */ |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 86 | |
Guido van Rossum | 3917c22 | 1997-04-02 05:35:28 +0000 | [diff] [blame] | 87 | #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 Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 93 | #if defined(PYCC_VACPP) |
Guido van Rossum | 2645241 | 1998-09-28 22:07:11 +0000 | [diff] [blame] | 94 | #include <sys/time.h> |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 95 | #endif |
| 96 | |
Guido van Rossum | bcc2074 | 1998-08-04 22:53:56 +0000 | [diff] [blame] | 97 | #ifdef __BEOS__ |
| 98 | /* For bigtime_t, snooze(). - [cjh] */ |
| 99 | #include <support/SupportDefs.h> |
| 100 | #include <kernel/OS.h> |
| 101 | #endif |
| 102 | |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 103 | /* Forward declarations */ |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 104 | static int floatsleep Py_PROTO((double)); |
| 105 | static double floattime Py_PROTO(()); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 106 | |
Guido van Rossum | cfbaecc | 1998-08-25 14:51:12 +0000 | [diff] [blame] | 107 | /* For Y2K check */ |
| 108 | static PyObject *moddict; |
| 109 | |
Guido van Rossum | e6a4b7b | 1997-10-08 15:27:56 +0000 | [diff] [blame] | 110 | #ifdef macintosh |
| 111 | /* Our own timezone. We have enough information to deduce whether |
| 112 | ** DST is on currently, but unfortunately we cannot put it to good |
| 113 | ** use because we don't know the rules (and that is needed to have |
| 114 | ** localtime() return correct tm_isdst values for times other than |
| 115 | ** the current time. So, we cop out and only tell the user the current |
| 116 | ** timezone. |
| 117 | */ |
| 118 | static long timezone; |
| 119 | |
| 120 | static void |
| 121 | initmactimezone() |
| 122 | { |
| 123 | MachineLocation loc; |
| 124 | long delta; |
| 125 | |
| 126 | ReadLocation(&loc); |
| 127 | |
| 128 | if (loc.latitude == 0 && loc.longitude == 0 && loc.u.gmtDelta == 0) |
| 129 | return; |
| 130 | |
| 131 | delta = loc.u.gmtDelta & 0x00FFFFFF; |
| 132 | |
| 133 | if (delta & 0x00800000) |
| 134 | delta |= 0xFF000000; |
| 135 | |
| 136 | timezone = -delta; |
| 137 | } |
| 138 | #endif /* macintosh */ |
| 139 | |
| 140 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 141 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 142 | time_time(self, args) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 143 | PyObject *self; |
| 144 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 145 | { |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 146 | double secs; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 147 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | a2b7f40 | 1993-01-04 09:09:59 +0000 | [diff] [blame] | 148 | return NULL; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 149 | secs = floattime(); |
| 150 | if (secs == 0.0) { |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 151 | PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | a2b7f40 | 1993-01-04 09:09:59 +0000 | [diff] [blame] | 152 | return NULL; |
| 153 | } |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 154 | return PyFloat_FromDouble(secs); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 157 | static char time_doc[] = |
| 158 | "time() -> floating point number\n\ |
| 159 | \n\ |
| 160 | Return the current time in seconds since the Epoch.\n\ |
| 161 | Fractions of a second may be present if the system clock provides them."; |
| 162 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 163 | #ifdef HAVE_CLOCK |
| 164 | |
| 165 | #ifndef CLOCKS_PER_SEC |
Guido van Rossum | 1b66a4f | 1996-02-25 04:50:33 +0000 | [diff] [blame] | 166 | #ifdef CLK_TCK |
| 167 | #define CLOCKS_PER_SEC CLK_TCK |
| 168 | #else |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 169 | #define CLOCKS_PER_SEC 1000000 |
| 170 | #endif |
Guido van Rossum | 1b66a4f | 1996-02-25 04:50:33 +0000 | [diff] [blame] | 171 | #endif |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 172 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 173 | static PyObject * |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 174 | time_clock(self, args) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 175 | PyObject *self; |
| 176 | PyObject *args; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 177 | { |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 178 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 179 | return NULL; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 180 | return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 181 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 182 | #endif /* HAVE_CLOCK */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 183 | |
Guido van Rossum | 3917c22 | 1997-04-02 05:35:28 +0000 | [diff] [blame] | 184 | #ifdef MS_WIN32 |
| 185 | /* Due to Mark Hammond */ |
| 186 | static PyObject * |
| 187 | time_clock(self, args) |
| 188 | PyObject *self; |
| 189 | PyObject *args; |
| 190 | { |
| 191 | static LARGE_INTEGER ctrStart; |
| 192 | static LARGE_INTEGER divisor = {0,0}; |
| 193 | LARGE_INTEGER now, diff, rem; |
| 194 | |
| 195 | if (!PyArg_NoArgs(args)) |
| 196 | return NULL; |
| 197 | |
| 198 | if (LargeIntegerEqualToZero(divisor)) { |
| 199 | QueryPerformanceCounter(&ctrStart); |
| 200 | if (!QueryPerformanceFrequency(&divisor) || |
| 201 | LargeIntegerEqualToZero(divisor)) { |
| 202 | /* Unlikely to happen - |
| 203 | this works on all intel machines at least! |
| 204 | Revert to clock() */ |
| 205 | return PyFloat_FromDouble(clock()); |
| 206 | } |
| 207 | } |
| 208 | QueryPerformanceCounter(&now); |
| 209 | diff = LargeIntegerSubtract(now, ctrStart); |
| 210 | diff = LargeIntegerDivide(diff, divisor, &rem); |
| 211 | /* XXX - we assume both divide results fit in 32 bits. This is |
| 212 | true on Intels. First person who can afford a machine that |
| 213 | doesnt deserves to fix it :-) |
| 214 | */ |
| 215 | return PyFloat_FromDouble((double)diff.LowPart + |
| 216 | ((double)rem.LowPart / (double)divisor.LowPart)); |
| 217 | } |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 218 | |
Guido van Rossum | 3917c22 | 1997-04-02 05:35:28 +0000 | [diff] [blame] | 219 | #define HAVE_CLOCK /* So it gets included in the methods */ |
| 220 | #endif /* MS_WIN32 */ |
| 221 | |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 222 | #ifdef HAVE_CLOCK |
| 223 | static char clock_doc[] = |
| 224 | "clock() -> floating point number\n\ |
| 225 | \n\ |
| 226 | Return the CPU time or real time since the start of the process or since\n\ |
| 227 | the first call to clock(). This has as much precision as the system records."; |
| 228 | #endif |
| 229 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 230 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 231 | time_sleep(self, args) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 232 | PyObject *self; |
| 233 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 234 | { |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 235 | double secs; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 236 | if (!PyArg_Parse(args, "d", &secs)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 237 | return NULL; |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 238 | if (floatsleep(secs) != 0) |
| 239 | return NULL; |
| 240 | Py_INCREF(Py_None); |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 241 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 244 | static char sleep_doc[] = |
| 245 | "sleep(seconds)\n\ |
| 246 | \n\ |
| 247 | Delay execution for a given number of seconds. The argument may be\n\ |
| 248 | a floating point number for subsecond precision."; |
| 249 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 250 | static PyObject * |
Guido van Rossum | 87ce7bb | 1998-06-09 16:30:31 +0000 | [diff] [blame] | 251 | tmtotuple(p) |
| 252 | struct tm *p; |
| 253 | { |
| 254 | return Py_BuildValue("(iiiiiiiii)", |
| 255 | p->tm_year + 1900, |
| 256 | p->tm_mon + 1, /* Want January == 1 */ |
| 257 | p->tm_mday, |
| 258 | p->tm_hour, |
| 259 | p->tm_min, |
| 260 | p->tm_sec, |
| 261 | (p->tm_wday + 6) % 7, /* Want Monday == 0 */ |
| 262 | p->tm_yday + 1, /* Want January, 1 == 1 */ |
| 263 | p->tm_isdst); |
| 264 | } |
| 265 | |
| 266 | static PyObject * |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 267 | time_convert(when, function) |
| 268 | time_t when; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 269 | struct tm * (*function) Py_PROTO((const time_t *)); |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 270 | { |
Guido van Rossum | 6e8583d | 1996-10-08 14:19:52 +0000 | [diff] [blame] | 271 | struct tm *p; |
| 272 | errno = 0; |
| 273 | p = function(&when); |
| 274 | if (p == NULL) { |
| 275 | #ifdef EINVAL |
Guido van Rossum | 0b1ff66 | 1996-11-02 17:31:22 +0000 | [diff] [blame] | 276 | if (errno == 0) |
Guido van Rossum | 6e8583d | 1996-10-08 14:19:52 +0000 | [diff] [blame] | 277 | errno = EINVAL; |
| 278 | #endif |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 279 | return PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 6e8583d | 1996-10-08 14:19:52 +0000 | [diff] [blame] | 280 | } |
Guido van Rossum | 87ce7bb | 1998-06-09 16:30:31 +0000 | [diff] [blame] | 281 | return tmtotuple(p); |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 284 | static PyObject * |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 285 | time_gmtime(self, args) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 286 | PyObject *self; |
| 287 | PyObject *args; |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 288 | { |
| 289 | double when; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 290 | if (!PyArg_Parse(args, "d", &when)) |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 291 | return NULL; |
| 292 | return time_convert((time_t)when, gmtime); |
| 293 | } |
| 294 | |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 295 | static char gmtime_doc[] = |
| 296 | "gmtime(seconds) -> tuple\n\ |
| 297 | \n\ |
| 298 | Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a. GMT)."; |
| 299 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 300 | static PyObject * |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 301 | time_localtime(self, args) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 302 | PyObject *self; |
| 303 | PyObject *args; |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 304 | { |
| 305 | double when; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 306 | if (!PyArg_Parse(args, "d", &when)) |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 307 | return NULL; |
| 308 | return time_convert((time_t)when, localtime); |
| 309 | } |
| 310 | |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 311 | static char localtime_doc[] = |
| 312 | "localtime(seconds) -> tuple\n\ |
| 313 | Convert seconds since the Epoch to a time tuple expressing local time."; |
| 314 | |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 315 | static int |
| 316 | gettmarg(args, p) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 317 | PyObject *args; |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 318 | struct tm *p; |
| 319 | { |
Guido van Rossum | cfbaecc | 1998-08-25 14:51:12 +0000 | [diff] [blame] | 320 | int y; |
| 321 | memset((ANY *) p, '\0', sizeof(struct tm)); |
| 322 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 323 | if (!PyArg_Parse(args, "(iiiiiiiii)", |
Guido van Rossum | cfbaecc | 1998-08-25 14:51:12 +0000 | [diff] [blame] | 324 | &y, |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 325 | &p->tm_mon, |
| 326 | &p->tm_mday, |
| 327 | &p->tm_hour, |
| 328 | &p->tm_min, |
| 329 | &p->tm_sec, |
| 330 | &p->tm_wday, |
| 331 | &p->tm_yday, |
| 332 | &p->tm_isdst)) |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 333 | return 0; |
Guido van Rossum | cfbaecc | 1998-08-25 14:51:12 +0000 | [diff] [blame] | 334 | if (y < 1900) { |
| 335 | PyObject *accept = PyDict_GetItemString(moddict, |
| 336 | "accept2dyear"); |
| 337 | if (accept == NULL || !PyInt_Check(accept) || |
| 338 | PyInt_AsLong(accept) == 0) { |
| 339 | PyErr_SetString(PyExc_ValueError, |
| 340 | "year >= 1900 required"); |
| 341 | return 0; |
| 342 | } |
| 343 | if (69 <= y && y <= 99) |
| 344 | y += 1900; |
| 345 | else if (0 <= y && y <= 68) |
| 346 | y += 2000; |
| 347 | else { |
| 348 | PyErr_SetString(PyExc_ValueError, |
| 349 | "year out of range (00-99, 1900-*)"); |
| 350 | return 0; |
| 351 | } |
| 352 | } |
| 353 | p->tm_year = y - 1900; |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 354 | p->tm_mon--; |
| 355 | p->tm_wday = (p->tm_wday + 1) % 7; |
| 356 | p->tm_yday--; |
| 357 | return 1; |
| 358 | } |
| 359 | |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 360 | #ifdef HAVE_STRFTIME |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 361 | static PyObject * |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 362 | time_strftime(self, args) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 363 | PyObject *self; |
| 364 | PyObject *args; |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 365 | { |
Guido van Rossum | cfbaecc | 1998-08-25 14:51:12 +0000 | [diff] [blame] | 366 | PyObject *tup; |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 367 | struct tm buf; |
| 368 | const char *fmt; |
| 369 | char *outbuf = 0; |
| 370 | int i; |
| 371 | |
Guido van Rossum | 1f41f84 | 1998-04-27 19:04:26 +0000 | [diff] [blame] | 372 | memset((ANY *) &buf, '\0', sizeof(buf)); |
| 373 | |
Guido van Rossum | cfbaecc | 1998-08-25 14:51:12 +0000 | [diff] [blame] | 374 | if (!PyArg_ParseTuple(args, "sO", &fmt, &tup) || !gettmarg(tup, &buf)) |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 375 | return NULL; |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 376 | /* I hate these functions that presume you know how big the output |
| 377 | * will be ahead of time... |
| 378 | */ |
Guido van Rossum | a78bfe1 | 1997-02-14 16:35:10 +0000 | [diff] [blame] | 379 | for (i = 1024 ; i <= 8192 ; i += 1024) { |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 380 | outbuf = malloc(i); |
| 381 | if (outbuf == NULL) { |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 382 | return PyErr_NoMemory(); |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 383 | } |
| 384 | if (strftime(outbuf, i-1, fmt, &buf) != 0) { |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 385 | PyObject *ret; |
| 386 | ret = PyString_FromString(outbuf); |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 387 | free(outbuf); |
| 388 | return ret; |
| 389 | } |
| 390 | free(outbuf); |
| 391 | } |
Guido van Rossum | a78bfe1 | 1997-02-14 16:35:10 +0000 | [diff] [blame] | 392 | PyErr_SetString(PyExc_ValueError, |
| 393 | "bad strftime format or result too big"); |
| 394 | return NULL; |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 395 | } |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 396 | |
| 397 | static char strftime_doc[] = |
| 398 | "strftime(format, tuple) -> string\n\ |
| 399 | \n\ |
| 400 | Convert a time tuple to a string according to a format specification.\n\ |
| 401 | See the library reference manual for formatting codes."; |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 402 | #endif /* HAVE_STRFTIME */ |
| 403 | |
Guido van Rossum | 87ce7bb | 1998-06-09 16:30:31 +0000 | [diff] [blame] | 404 | #ifdef HAVE_STRPTIME |
Guido van Rossum | 0a6363d | 1999-01-03 13:00:34 +0000 | [diff] [blame] | 405 | /* extern char *strptime(); /* Enable this if it's not declared in <time.h> */ |
Guido van Rossum | c206873 | 1998-10-07 16:35:25 +0000 | [diff] [blame] | 406 | |
Guido van Rossum | 87ce7bb | 1998-06-09 16:30:31 +0000 | [diff] [blame] | 407 | static PyObject * |
| 408 | time_strptime(self, args) |
| 409 | PyObject *self; |
| 410 | PyObject *args; |
| 411 | { |
| 412 | struct tm tm; |
| 413 | char *fmt = "%a %b %d %H:%M:%S %Y"; |
| 414 | char *buf; |
| 415 | char *s; |
| 416 | |
| 417 | if (!PyArg_ParseTuple(args, "s|s", &buf, &fmt)) { |
| 418 | PyErr_SetString(PyExc_ValueError, "invalid argument"); |
| 419 | return NULL; |
| 420 | } |
Guido van Rossum | cfbaecc | 1998-08-25 14:51:12 +0000 | [diff] [blame] | 421 | memset((ANY *) &tm, '\0', sizeof(tm)); |
Guido van Rossum | 87ce7bb | 1998-06-09 16:30:31 +0000 | [diff] [blame] | 422 | s = strptime(buf, fmt, &tm); |
| 423 | if (s == NULL) { |
| 424 | PyErr_SetString(PyExc_ValueError, "format mismatch"); |
| 425 | return NULL; |
| 426 | } |
| 427 | while (*s && isspace(*s)) |
| 428 | s++; |
| 429 | if (*s) { |
| 430 | PyErr_Format(PyExc_ValueError, |
| 431 | "unconverted data remains: '%.400s'", s); |
| 432 | return NULL; |
| 433 | } |
| 434 | return tmtotuple(&tm); |
| 435 | } |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 436 | |
| 437 | static char strptime_doc[] = |
Guido van Rossum | 446ccfe | 1999-01-07 18:29:26 +0000 | [diff] [blame] | 438 | "strptime(string, format) -> tuple\n\ |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 439 | Parse a string to a time tuple according to a format specification.\n\ |
| 440 | See the library reference manual for formatting codes (same as strftime())."; |
Guido van Rossum | 87ce7bb | 1998-06-09 16:30:31 +0000 | [diff] [blame] | 441 | #endif /* HAVE_STRPTIME */ |
| 442 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 443 | static PyObject * |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 444 | time_asctime(self, args) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 445 | PyObject *self; |
| 446 | PyObject *args; |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 447 | { |
| 448 | struct tm buf; |
| 449 | char *p; |
| 450 | if (!gettmarg(args, &buf)) |
| 451 | return NULL; |
| 452 | p = asctime(&buf); |
| 453 | if (p[24] == '\n') |
| 454 | p[24] = '\0'; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 455 | return PyString_FromString(p); |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 458 | static char asctime_doc[] = |
| 459 | "asctime(tuple) -> string\n\ |
| 460 | \n\ |
| 461 | Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'."; |
| 462 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 463 | static PyObject * |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 464 | time_ctime(self, args) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 465 | PyObject *self; |
| 466 | PyObject *args; |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 467 | { |
| 468 | double dt; |
| 469 | time_t tt; |
| 470 | char *p; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 471 | if (!PyArg_Parse(args, "d", &dt)) |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 472 | return NULL; |
Guido van Rossum | cac6c72 | 1996-09-06 13:34:02 +0000 | [diff] [blame] | 473 | tt = (time_t)dt; |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 474 | p = ctime(&tt); |
Guido van Rossum | 7853570 | 1998-03-03 22:19:10 +0000 | [diff] [blame] | 475 | if (p == NULL) { |
| 476 | PyErr_SetString(PyExc_ValueError, "unconvertible time"); |
| 477 | return NULL; |
| 478 | } |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 479 | if (p[24] == '\n') |
| 480 | p[24] = '\0'; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 481 | return PyString_FromString(p); |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 484 | static char ctime_doc[] = |
| 485 | "ctime(seconds) -> string\n\ |
| 486 | \n\ |
| 487 | Convert a time in seconds since the Epoch to a string in local time.\n\ |
| 488 | This is equivalent to asctime(localtime(seconds))."; |
| 489 | |
Guido van Rossum | 60cd813 | 1998-03-06 17:16:21 +0000 | [diff] [blame] | 490 | #ifdef HAVE_MKTIME |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 491 | static PyObject * |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 492 | time_mktime(self, args) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 493 | PyObject *self; |
| 494 | PyObject *args; |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 495 | { |
| 496 | struct tm buf; |
Guido van Rossum | bceeac8 | 1996-05-23 22:53:47 +0000 | [diff] [blame] | 497 | time_t tt; |
| 498 | tt = time(&tt); |
| 499 | buf = *localtime(&tt); |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 500 | if (!gettmarg(args, &buf)) |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 501 | return NULL; |
Guido van Rossum | bceeac8 | 1996-05-23 22:53:47 +0000 | [diff] [blame] | 502 | tt = mktime(&buf); |
| 503 | if (tt == (time_t)(-1)) { |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 504 | PyErr_SetString(PyExc_OverflowError, |
| 505 | "mktime argument out of range"); |
Guido van Rossum | bceeac8 | 1996-05-23 22:53:47 +0000 | [diff] [blame] | 506 | return NULL; |
| 507 | } |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 508 | return PyFloat_FromDouble((double)tt); |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 509 | } |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 510 | |
| 511 | static char mktime_doc[] = |
| 512 | "mktime(tuple) -> floating point number\n\ |
| 513 | \n\ |
| 514 | Convert a time tuple in local time to seconds since the Epoch."; |
Guido van Rossum | 60cd813 | 1998-03-06 17:16:21 +0000 | [diff] [blame] | 515 | #endif /* HAVE_MKTIME */ |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 516 | |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 517 | static PyMethodDef time_methods[] = { |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 518 | {"time", time_time, 0, time_doc}, |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 519 | #ifdef HAVE_CLOCK |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 520 | {"clock", time_clock, 0, clock_doc}, |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 521 | #endif |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 522 | {"sleep", time_sleep, 0, sleep_doc}, |
| 523 | {"gmtime", time_gmtime, 0, gmtime_doc}, |
| 524 | {"localtime", time_localtime, 0, localtime_doc}, |
| 525 | {"asctime", time_asctime, 0, asctime_doc}, |
| 526 | {"ctime", time_ctime, 0, ctime_doc}, |
Guido van Rossum | 60cd813 | 1998-03-06 17:16:21 +0000 | [diff] [blame] | 527 | #ifdef HAVE_MKTIME |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 528 | {"mktime", time_mktime, 0, mktime_doc}, |
Guido van Rossum | 60cd813 | 1998-03-06 17:16:21 +0000 | [diff] [blame] | 529 | #endif |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 530 | #ifdef HAVE_STRFTIME |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 531 | {"strftime", time_strftime, 1, strftime_doc}, |
Guido van Rossum | 8d8c1ee | 1995-09-13 17:38:35 +0000 | [diff] [blame] | 532 | #endif |
Guido van Rossum | 87ce7bb | 1998-06-09 16:30:31 +0000 | [diff] [blame] | 533 | #ifdef HAVE_STRPTIME |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 534 | {"strptime", time_strptime, 1, strptime_doc}, |
Guido van Rossum | 87ce7bb | 1998-06-09 16:30:31 +0000 | [diff] [blame] | 535 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 536 | {NULL, NULL} /* sentinel */ |
| 537 | }; |
| 538 | |
Guido van Rossum | 8239f0f | 1995-01-22 00:49:01 +0000 | [diff] [blame] | 539 | static void |
| 540 | ins(d, name, v) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 541 | PyObject *d; |
Guido van Rossum | 8239f0f | 1995-01-22 00:49:01 +0000 | [diff] [blame] | 542 | char *name; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 543 | PyObject *v; |
Guido van Rossum | 8239f0f | 1995-01-22 00:49:01 +0000 | [diff] [blame] | 544 | { |
| 545 | if (v == NULL) |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 546 | Py_FatalError("Can't initialize time module -- NULL value"); |
| 547 | if (PyDict_SetItemString(d, name, v) != 0) |
| 548 | Py_FatalError( |
Guido van Rossum | 5217457 | 1996-12-09 18:38:52 +0000 | [diff] [blame] | 549 | "Can't initialize time module -- PyDict_SetItemString failed"); |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 550 | Py_DECREF(v); |
Guido van Rossum | 8239f0f | 1995-01-22 00:49:01 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 553 | static char module_doc[] = |
| 554 | "This module provides various functions to manipulate time values.\n\ |
| 555 | \n\ |
| 556 | There are two standard representations of time. One is the number\n\ |
| 557 | of seconds since the Epoch, in UTC (a.k.a. GMT). It may be an integer\n\ |
| 558 | or a floating point number (to represent fractions of seconds).\n\ |
| 559 | The Epoch is system-defined; on Unix, it is generally January 1st, 1970.\n\ |
| 560 | The actual value can be retrieved by calling gmtime(0).\n\ |
| 561 | \n\ |
| 562 | The other representation is a tuple of 9 integers giving local time.\n\ |
| 563 | The tuple items are:\n\ |
| 564 | year (four digits, e.g. 1998)\n\ |
| 565 | month (1-12)\n\ |
| 566 | day (1-31)\n\ |
| 567 | hours (0-23)\n\ |
| 568 | minutes (0-59)\n\ |
Guido van Rossum | 360eb9f | 1999-02-22 16:19:52 +0000 | [diff] [blame^] | 569 | seconds (0-59)\n\ |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 570 | weekday (0-6, Monday is 0)\n\ |
| 571 | Julian day (day in the year, 1-366)\n\ |
| 572 | DST (Daylight Savings Time) flag (-1, 0 or 1)\n\ |
| 573 | If the DST flag is 0, the time is given in the regular time zone;\n\ |
| 574 | if it is 1, the time is given in the DST time zone;\n\ |
| 575 | if it is -1, mktime() should guess based on the date and time.\n\ |
| 576 | \n\ |
| 577 | Variables:\n\ |
| 578 | \n\ |
| 579 | timezone -- difference in seconds between UTC and local standard time\n\ |
| 580 | altzone -- difference in seconds between UTC and local DST time\n\ |
| 581 | daylight -- whether local time should reflect DST\n\ |
| 582 | tzname -- tuple of (standard time zone name, DST time zone name)\n\ |
| 583 | \n\ |
| 584 | Functions:\n\ |
| 585 | \n\ |
| 586 | time() -- return current time in seconds since the Epoch as a float\n\ |
| 587 | clock() -- return CPU time since process start as a float\n\ |
| 588 | sleep() -- delay for a number of seconds given as a float\n\ |
| 589 | gmtime() -- convert seconds since Epoch to UTC tuple\n\ |
| 590 | localtime() -- convert seconds since Epoch to local time tuple\n\ |
| 591 | asctime() -- convert time tuple to string\n\ |
| 592 | ctime() -- convert time in seconds to string\n\ |
| 593 | mktime() -- convert local time tuple to seconds since Epoch\n\ |
| 594 | strftime() -- convert time tuple to string according to format specification\n\ |
| 595 | strptime() -- parse string to time tuple according to format specification\n\ |
| 596 | "; |
| 597 | |
| 598 | |
Guido van Rossum | 3886bb6 | 1998-12-04 18:50:17 +0000 | [diff] [blame] | 599 | DL_EXPORT(void) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 600 | inittime() |
| 601 | { |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 602 | PyObject *m, *d; |
Guido van Rossum | cfbaecc | 1998-08-25 14:51:12 +0000 | [diff] [blame] | 603 | char *p; |
Guido van Rossum | 0ef577b | 1998-06-27 20:38:36 +0000 | [diff] [blame] | 604 | m = Py_InitModule3("time", time_methods, module_doc); |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 605 | d = PyModule_GetDict(m); |
Guido van Rossum | c206873 | 1998-10-07 16:35:25 +0000 | [diff] [blame] | 606 | /* Accept 2-digit dates unless PYTHONY2K is set and non-empty */ |
| 607 | p = getenv("PYTHONY2K"); |
| 608 | ins(d, "accept2dyear", PyInt_FromLong((long) (!p || !*p))); |
| 609 | /* Squirrel away the module's dictionary for the y2k check */ |
| 610 | Py_INCREF(d); |
| 611 | moddict = d; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 612 | #ifdef HAVE_TZNAME |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 613 | tzset(); |
Guido van Rossum | 2645241 | 1998-09-28 22:07:11 +0000 | [diff] [blame] | 614 | #ifdef PYOS_OS2 |
| 615 | ins(d, "timezone", PyInt_FromLong((long)_timezone)); |
| 616 | #else /* !PYOS_OS2 */ |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 617 | ins(d, "timezone", PyInt_FromLong((long)timezone)); |
Guido van Rossum | 2645241 | 1998-09-28 22:07:11 +0000 | [diff] [blame] | 618 | #endif /* PYOS_OS2 */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 619 | #ifdef HAVE_ALTZONE |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 620 | ins(d, "altzone", PyInt_FromLong((long)altzone)); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 621 | #else |
Guido van Rossum | 2645241 | 1998-09-28 22:07:11 +0000 | [diff] [blame] | 622 | #ifdef PYOS_OS2 |
| 623 | ins(d, "altzone", PyInt_FromLong((long)_timezone-3600)); |
| 624 | #else /* !PYOS_OS2 */ |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 625 | ins(d, "altzone", PyInt_FromLong((long)timezone-3600)); |
Guido van Rossum | 2645241 | 1998-09-28 22:07:11 +0000 | [diff] [blame] | 626 | #endif /* PYOS_OS2 */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 627 | #endif |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 628 | ins(d, "daylight", PyInt_FromLong((long)daylight)); |
| 629 | ins(d, "tzname", Py_BuildValue("(zz)", tzname[0], tzname[1])); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 630 | #else /* !HAVE_TZNAME */ |
| 631 | #if HAVE_TM_ZONE |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 632 | { |
| 633 | #define YEAR ((time_t)((365 * 24 + 6) * 3600)) |
| 634 | time_t t; |
| 635 | struct tm *p; |
| 636 | long winterzone, summerzone; |
| 637 | char wintername[10], summername[10]; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 638 | /* XXX This won't work on the southern hemisphere. |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 639 | XXX Anybody got a better idea? */ |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 640 | t = (time((time_t *)0) / YEAR) * YEAR; |
| 641 | p = localtime(&t); |
| 642 | winterzone = -p->tm_gmtoff; |
| 643 | strncpy(wintername, p->tm_zone ? p->tm_zone : " ", 9); |
| 644 | wintername[9] = '\0'; |
| 645 | t += YEAR/2; |
| 646 | p = localtime(&t); |
| 647 | summerzone = -p->tm_gmtoff; |
| 648 | strncpy(summername, p->tm_zone ? p->tm_zone : " ", 9); |
| 649 | summername[9] = '\0'; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 650 | ins(d, "timezone", PyInt_FromLong(winterzone)); |
| 651 | ins(d, "altzone", PyInt_FromLong(summerzone)); |
| 652 | ins(d, "daylight", |
| 653 | PyInt_FromLong((long)(winterzone != summerzone))); |
| 654 | ins(d, "tzname", |
| 655 | Py_BuildValue("(zz)", wintername, summername)); |
Guido van Rossum | 234f942 | 1993-06-17 12:35:49 +0000 | [diff] [blame] | 656 | } |
Guido van Rossum | e6a4b7b | 1997-10-08 15:27:56 +0000 | [diff] [blame] | 657 | #else |
| 658 | #ifdef macintosh |
Guido van Rossum | be1eb0d | 1997-12-08 21:56:43 +0000 | [diff] [blame] | 659 | /* The only thing we can obtain is the current timezone |
| 660 | ** (and whether dst is currently _active_, but that is not what |
| 661 | ** we're looking for:-( ) |
| 662 | */ |
Guido van Rossum | e6a4b7b | 1997-10-08 15:27:56 +0000 | [diff] [blame] | 663 | initmactimezone(); |
| 664 | ins(d, "timezone", PyInt_FromLong(timezone)); |
Guido van Rossum | be1eb0d | 1997-12-08 21:56:43 +0000 | [diff] [blame] | 665 | ins(d, "altzone", PyInt_FromLong(timezone)); |
| 666 | ins(d, "daylight", PyInt_FromLong((long)0)); |
| 667 | ins(d, "tzname", Py_BuildValue("(zz)", "", "")); |
Guido van Rossum | e6a4b7b | 1997-10-08 15:27:56 +0000 | [diff] [blame] | 668 | #endif /* macintosh */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 669 | #endif /* HAVE_TM_ZONE */ |
| 670 | #endif /* !HAVE_TZNAME */ |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 671 | if (PyErr_Occurred()) |
| 672 | Py_FatalError("Can't initialize time module"); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 676 | /* Implement floattime() for various platforms */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 677 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 678 | static double |
| 679 | floattime() |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 680 | { |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 681 | /* There are three ways to get the time: |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 682 | (1) gettimeofday() -- resolution in microseconds |
| 683 | (2) ftime() -- resolution in milliseconds |
| 684 | (3) time() -- resolution in seconds |
| 685 | In all cases the return value is a float in seconds. |
| 686 | Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may |
| 687 | fail, so we fall back on ftime() or time(). |
| 688 | Note: clock resolution does not imply clock accuracy! */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 689 | #ifdef HAVE_GETTIMEOFDAY |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 690 | { |
| 691 | struct timeval t; |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 692 | #ifdef GETTIMEOFDAY_NO_TZ |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 693 | if (gettimeofday(&t) == 0) |
| 694 | return (double)t.tv_sec + t.tv_usec*0.000001; |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 695 | #else /* !GETTIMEOFDAY_NO_TZ */ |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 696 | if (gettimeofday(&t, (struct timezone *)NULL) == 0) |
| 697 | return (double)t.tv_sec + t.tv_usec*0.000001; |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 698 | #endif /* !GETTIMEOFDAY_NO_TZ */ |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 699 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 700 | #endif /* !HAVE_GETTIMEOFDAY */ |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 701 | { |
Guido van Rossum | bcc2074 | 1998-08-04 22:53:56 +0000 | [diff] [blame] | 702 | #if defined(HAVE_FTIME) && !defined(__BEOS__) |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 703 | struct timeb t; |
| 704 | ftime(&t); |
| 705 | return (double)t.time + (double)t.millitm * (double)0.001; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 706 | #else /* !HAVE_FTIME */ |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 707 | time_t secs; |
| 708 | time(&secs); |
| 709 | return (double)secs; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 710 | #endif /* !HAVE_FTIME */ |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 711 | } |
Guido van Rossum | 426035c | 1991-02-19 12:27:35 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 714 | |
| 715 | /* Implement floatsleep() for various platforms. |
| 716 | When interrupted (or when another error occurs), return -1 and |
| 717 | set an exception; else return 0. */ |
| 718 | |
| 719 | static int |
Guido van Rossum | a320fd3 | 1995-03-09 12:14:15 +0000 | [diff] [blame] | 720 | #ifdef MPW |
| 721 | floatsleep(double secs) |
| 722 | #else |
Barry Warsaw | 4a6cf41 | 1997-01-13 22:44:55 +0000 | [diff] [blame] | 723 | floatsleep(secs) |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 724 | double secs; |
Guido van Rossum | a320fd3 | 1995-03-09 12:14:15 +0000 | [diff] [blame] | 725 | #endif /* MPW */ |
Guido van Rossum | 426035c | 1991-02-19 12:27:35 +0000 | [diff] [blame] | 726 | { |
Guido van Rossum | a78bfe1 | 1997-02-14 16:35:10 +0000 | [diff] [blame] | 727 | /* XXX Should test for MS_WIN32 first! */ |
Guido van Rossum | bcc2074 | 1998-08-04 22:53:56 +0000 | [diff] [blame] | 728 | #if defined(HAVE_SELECT) && !defined(__BEOS__) |
Guido van Rossum | 426035c | 1991-02-19 12:27:35 +0000 | [diff] [blame] | 729 | struct timeval t; |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 730 | double frac; |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 731 | frac = fmod(secs, 1.0); |
| 732 | secs = floor(secs); |
| 733 | t.tv_sec = (long)secs; |
| 734 | t.tv_usec = (long)(frac*1000000.0); |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 735 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 736 | if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) { |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 737 | Py_BLOCK_THREADS |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 738 | PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 739 | return -1; |
| 740 | } |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 741 | Py_END_ALLOW_THREADS |
Guido van Rossum | bcc2074 | 1998-08-04 22:53:56 +0000 | [diff] [blame] | 742 | #else /* !HAVE_SELECT || __BEOS__ */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 743 | #ifdef macintosh |
| 744 | #define MacTicks (* (long *)0x16A) |
| 745 | long deadline; |
| 746 | deadline = MacTicks + (long)(secs * 60.0); |
| 747 | while (MacTicks < deadline) { |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 748 | /* XXX Should call some yielding function here */ |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 749 | if (PyErr_CheckSignals()) |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 750 | return -1; |
| 751 | } |
| 752 | #else /* !macintosh */ |
Guido van Rossum | 7bf22de | 1997-12-02 20:34:19 +0000 | [diff] [blame] | 753 | #if defined(__WATCOMC__) && !defined(__QNX__) |
Guido van Rossum | bceeac8 | 1996-05-23 22:53:47 +0000 | [diff] [blame] | 754 | /* XXX Can't interrupt this sleep */ |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 755 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | bceeac8 | 1996-05-23 22:53:47 +0000 | [diff] [blame] | 756 | delay((int)(secs * 1000 + 0.5)); /* delay() uses milliseconds */ |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 757 | Py_END_ALLOW_THREADS |
Guido van Rossum | 7bf22de | 1997-12-02 20:34:19 +0000 | [diff] [blame] | 758 | #else /* !__WATCOMC__ || __QNX__ */ |
Guido van Rossum | e22e644 | 1993-07-09 10:51:31 +0000 | [diff] [blame] | 759 | #ifdef MSDOS |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 760 | struct timeb t1, t2; |
| 761 | double frac; |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 762 | extern double fmod Py_PROTO((double, double)); |
| 763 | extern double floor Py_PROTO((double)); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 764 | if (secs <= 0.0) |
| 765 | return; |
| 766 | frac = fmod(secs, 1.0); |
| 767 | secs = floor(secs); |
| 768 | ftime(&t1); |
| 769 | t2.time = t1.time + (int)secs; |
| 770 | t2.millitm = t1.millitm + (int)(frac*1000.0); |
| 771 | while (t2.millitm >= 1000) { |
| 772 | t2.time++; |
| 773 | t2.millitm -= 1000; |
| 774 | } |
| 775 | for (;;) { |
| 776 | #ifdef QUICKWIN |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 777 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 778 | _wyield(); |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 779 | Py_END_ALLOW_THREADS |
Guido van Rossum | 80c9d88 | 1991-04-16 08:47:51 +0000 | [diff] [blame] | 780 | #endif |
Barry Warsaw | 9a2a8a8 | 1996-12-06 23:32:14 +0000 | [diff] [blame] | 781 | if (PyErr_CheckSignals()) |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 782 | return -1; |
| 783 | ftime(&t1); |
| 784 | if (t1.time > t2.time || |
| 785 | t1.time == t2.time && t1.millitm >= t2.millitm) |
| 786 | break; |
| 787 | } |
| 788 | #else /* !MSDOS */ |
Guido van Rossum | b2fb364 | 1996-09-07 00:47:35 +0000 | [diff] [blame] | 789 | #ifdef MS_WIN32 |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 790 | /* XXX Can't interrupt this sleep */ |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 791 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 792 | Sleep((int)(secs*1000)); |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 793 | Py_END_ALLOW_THREADS |
Guido van Rossum | b2fb364 | 1996-09-07 00:47:35 +0000 | [diff] [blame] | 794 | #else /* !MS_WIN32 */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 795 | #ifdef PYOS_OS2 |
| 796 | /* This Sleep *IS* Interruptable by Exceptions */ |
Guido van Rossum | 1d0d7e4 | 1997-12-29 20:03:10 +0000 | [diff] [blame] | 797 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 798 | if (DosSleep(secs * 1000) != NO_ERROR) { |
Guido van Rossum | 1d0d7e4 | 1997-12-29 20:03:10 +0000 | [diff] [blame] | 799 | Py_BLOCK_THREADS |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 800 | PyErr_SetFromErrno(PyExc_IOError); |
| 801 | return -1; |
| 802 | } |
Guido van Rossum | 1d0d7e4 | 1997-12-29 20:03:10 +0000 | [diff] [blame] | 803 | Py_END_ALLOW_THREADS |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 804 | #else /* !PYOS_OS2 */ |
Guido van Rossum | bcc2074 | 1998-08-04 22:53:56 +0000 | [diff] [blame] | 805 | #ifdef __BEOS__ |
| 806 | /* This sleep *CAN BE* interrupted. */ |
| 807 | { |
| 808 | bigtime_t frac, seconds; |
| 809 | |
| 810 | extern double fmod Py_PROTO((double,double)); |
| 811 | extern double floor Py_PROTO((double)); |
| 812 | |
| 813 | if( secs <= 0.0 ) { |
| 814 | return; |
| 815 | } |
| 816 | |
| 817 | frac = (bigtime_t)fmod( secs, 1.0 ); |
| 818 | seconds = (bigtime_t)floor( secs ); |
| 819 | |
| 820 | Py_BEGIN_ALLOW_THREADS |
| 821 | if( snooze( seconds * (bigtime_t)1000 + frac ) == B_INTERRUPTED ) { |
| 822 | Py_BLOCK_THREADS |
| 823 | PyErr_SetFromErrno( PyExc_IOError ); |
| 824 | return -1; |
| 825 | } |
| 826 | Py_END_ALLOW_THREADS |
| 827 | } |
| 828 | #else /* !__BEOS__ */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 829 | /* XXX Can't interrupt this sleep */ |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 830 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 831 | sleep((int)secs); |
Guido van Rossum | 8607ae2 | 1997-11-03 22:04:46 +0000 | [diff] [blame] | 832 | Py_END_ALLOW_THREADS |
Guido van Rossum | bcc2074 | 1998-08-04 22:53:56 +0000 | [diff] [blame] | 833 | #endif /* !__BEOS__ */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 834 | #endif /* !PYOS_OS2 */ |
Guido van Rossum | b2fb364 | 1996-09-07 00:47:35 +0000 | [diff] [blame] | 835 | #endif /* !MS_WIN32 */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 836 | #endif /* !MSDOS */ |
Guido van Rossum | 7bf22de | 1997-12-02 20:34:19 +0000 | [diff] [blame] | 837 | #endif /* !__WATCOMC__ || __QNX__ */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 838 | #endif /* !macintosh */ |
| 839 | #endif /* !HAVE_SELECT */ |
| 840 | return 0; |
Guido van Rossum | 80c9d88 | 1991-04-16 08:47:51 +0000 | [diff] [blame] | 841 | } |