Mercurial > cpython-lru_cache-weakref
annotate Modules/timemodule.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | f6976b9a85a4 |
| children | 33a8e65eef23 |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
143
diff
changeset
|
1 /*********************************************************** |
|
2061
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
172ba04a5191
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
3 The Netherlands. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
143
diff
changeset
|
4 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
143
diff
changeset
|
5 All Rights Reserved |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
143
diff
changeset
|
6 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
143
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
143
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
15 permission. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
143
diff
changeset
|
16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4373
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
143
diff
changeset
|
29 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
143
diff
changeset
|
30 ******************************************************************/ |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
143
diff
changeset
|
31 |
| 6 | 32 /* Time module */ |
| 33 | |
| 86 | 34 #include "allobjects.h" |
| 35 #include "modsupport.h" | |
| 926 | 36 #include "ceval.h" |
| 86 | 37 |
|
3979
87e53c62cac8
Include "mymath.h" instead of manually declaring math functions.
Guido van Rossum <guido@python.org>
parents:
3592
diff
changeset
|
38 #ifdef HAVE_SELECT |
|
87e53c62cac8
Include "mymath.h" instead of manually declaring math functions.
Guido van Rossum <guido@python.org>
parents:
3592
diff
changeset
|
39 #include "mymath.h" |
|
87e53c62cac8
Include "mymath.h" instead of manually declaring math functions.
Guido van Rossum <guido@python.org>
parents:
3592
diff
changeset
|
40 #endif |
|
87e53c62cac8
Include "mymath.h" instead of manually declaring math functions.
Guido van Rossum <guido@python.org>
parents:
3592
diff
changeset
|
41 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
42 #ifdef macintosh |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
43 #include <time.h> |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
44 #else |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
45 #include <sys/types.h> |
|
1177
533e36de1e4d
* Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents:
956
diff
changeset
|
46 #endif |
|
533e36de1e4d
* Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents:
956
diff
changeset
|
47 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
48 #ifdef QUICKWIN |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
49 #include <io.h> |
|
956
a60cb5321211
* macmodule.c: include allobjects.h, not .c
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
50 #endif |
|
a60cb5321211
* macmodule.c: include allobjects.h, not .c
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
51 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
52 #ifdef HAVE_UNISTD_H |
|
730
c81952d97ebe
Initialized sigsave to shut lint up
Guido van Rossum <guido@python.org>
parents:
701
diff
changeset
|
53 #include <unistd.h> |
|
c81952d97ebe
Initialized sigsave to shut lint up
Guido van Rossum <guido@python.org>
parents:
701
diff
changeset
|
54 #endif |
|
c81952d97ebe
Initialized sigsave to shut lint up
Guido van Rossum <guido@python.org>
parents:
701
diff
changeset
|
55 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
56 #ifdef HAVE_SELECT |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
57 #include "myselect.h" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
58 #else |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
59 #include "mytime.h" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
60 #endif |
|
209
e486c849c50c
New hacks for include files to get time_t in the most portable way.
Guido van Rossum <guido@python.org>
parents:
181
diff
changeset
|
61 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
62 #ifdef HAVE_FTIME |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
63 #include <sys/timeb.h> |
|
1413
c914b10bf2ed
* timemodule.c: Add hack for Solaris 2.
Guido van Rossum <guido@python.org>
parents:
1322
diff
changeset
|
64 #endif |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
65 |
| 3592 | 66 #ifdef __WATCOMC__ |
| 67 #include <i86.h> | |
| 68 #else | |
|
4216
0a5f01d4701c
Some changes for better Windows portability.
Guido van Rossum <guido@python.org>
parents:
3979
diff
changeset
|
69 #ifdef MS_WINDOWS |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
70 #include <windows.h> |
|
4232
886c0f775c97
Sleep() turns out to be win32 specific.
Guido van Rossum <guido@python.org>
parents:
4216
diff
changeset
|
71 #ifdef MS_WIN16 |
|
886c0f775c97
Sleep() turns out to be win32 specific.
Guido van Rossum <guido@python.org>
parents:
4216
diff
changeset
|
72 /* These overrides not needed for Win32 */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
73 #define timezone _timezone |
|
2533
e506ec4fb2b1
tiny additions for Windows 3.1
Guido van Rossum <guido@python.org>
parents:
2506
diff
changeset
|
74 #define tzname _tzname |
|
e506ec4fb2b1
tiny additions for Windows 3.1
Guido van Rossum <guido@python.org>
parents:
2506
diff
changeset
|
75 #define daylight _daylight |
|
e506ec4fb2b1
tiny additions for Windows 3.1
Guido van Rossum <guido@python.org>
parents:
2506
diff
changeset
|
76 #define altzone _altzone |
|
4232
886c0f775c97
Sleep() turns out to be win32 specific.
Guido van Rossum <guido@python.org>
parents:
4216
diff
changeset
|
77 #endif /* MS_WIN16 */ |
|
4216
0a5f01d4701c
Some changes for better Windows portability.
Guido van Rossum <guido@python.org>
parents:
3979
diff
changeset
|
78 #endif /* MS_WINDOWS */ |
|
0a5f01d4701c
Some changes for better Windows portability.
Guido van Rossum <guido@python.org>
parents:
3979
diff
changeset
|
79 #endif /* !__WATCOMC__ */ |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
80 |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
81 /* Forward declarations */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
82 static int floatsleep PROTO((double)); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
83 static double floattime PROTO(()); |
| 6 | 84 |
| 85 static object * | |
| 86 time_time(self, args) | |
| 87 object *self; | |
| 88 object *args; | |
| 89 { | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
90 double secs; |
|
1177
533e36de1e4d
* Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents:
956
diff
changeset
|
91 if (!getnoarg(args)) |
|
533e36de1e4d
* Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents:
956
diff
changeset
|
92 return NULL; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
93 secs = floattime(); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
94 if (secs == 0.0) { |
|
1177
533e36de1e4d
* Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents:
956
diff
changeset
|
95 err_errno(IOError); |
|
533e36de1e4d
* Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents:
956
diff
changeset
|
96 return NULL; |
|
533e36de1e4d
* Configure.py: use #!/usr/local/bin/python
Guido van Rossum <guido@python.org>
parents:
956
diff
changeset
|
97 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
98 return newfloatobject(secs); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
99 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
100 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
101 #ifdef HAVE_CLOCK |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
102 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
103 #ifndef CLOCKS_PER_SEC |
|
3419
e045f9132b07
default CLOCKS_PER_SEC to CLK_TCK if it exists
Guido van Rossum <guido@python.org>
parents:
3388
diff
changeset
|
104 #ifdef CLK_TCK |
|
e045f9132b07
default CLOCKS_PER_SEC to CLK_TCK if it exists
Guido van Rossum <guido@python.org>
parents:
3388
diff
changeset
|
105 #define CLOCKS_PER_SEC CLK_TCK |
|
e045f9132b07
default CLOCKS_PER_SEC to CLK_TCK if it exists
Guido van Rossum <guido@python.org>
parents:
3388
diff
changeset
|
106 #else |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
107 #define CLOCKS_PER_SEC 1000000 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
108 #endif |
|
3419
e045f9132b07
default CLOCKS_PER_SEC to CLK_TCK if it exists
Guido van Rossum <guido@python.org>
parents:
3388
diff
changeset
|
109 #endif |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
110 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
111 static object * |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
112 time_clock(self, args) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
113 object *self; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
114 object *args; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
115 { |
| 6 | 116 if (!getnoarg(args)) |
| 117 return NULL; | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
118 return newfloatobject(((double)clock()) / CLOCKS_PER_SEC); |
| 6 | 119 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
120 #endif /* HAVE_CLOCK */ |
| 6 | 121 |
| 122 static object * | |
| 123 time_sleep(self, args) | |
| 124 object *self; | |
| 125 object *args; | |
| 126 { | |
|
1181
950cd37fcddc
* Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents:
1177
diff
changeset
|
127 double secs; |
|
950cd37fcddc
* Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents:
1177
diff
changeset
|
128 if (!getargs(args, "d", &secs)) |
| 6 | 129 return NULL; |
| 926 | 130 BGN_SAVE |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
131 if (floatsleep(secs) != 0) { |
| 926 | 132 RET_SAVE |
| 6 | 133 return NULL; |
| 134 } | |
| 926 | 135 END_SAVE |
| 6 | 136 INCREF(None); |
| 137 return None; | |
| 138 } | |
| 139 | |
| 140 static object * | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
141 time_convert(when, function) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
142 time_t when; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
143 struct tm * (*function) PROTO((const time_t *)); |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
144 { |
|
4373
98ea80051dbc
Check for NULL pointer returned from localtime()/gmtime().
Guido van Rossum <guido@python.org>
parents:
4232
diff
changeset
|
145 struct tm *p; |
|
98ea80051dbc
Check for NULL pointer returned from localtime()/gmtime().
Guido van Rossum <guido@python.org>
parents:
4232
diff
changeset
|
146 errno = 0; |
|
98ea80051dbc
Check for NULL pointer returned from localtime()/gmtime().
Guido van Rossum <guido@python.org>
parents:
4232
diff
changeset
|
147 p = function(&when); |
|
98ea80051dbc
Check for NULL pointer returned from localtime()/gmtime().
Guido van Rossum <guido@python.org>
parents:
4232
diff
changeset
|
148 if (p == NULL) { |
|
98ea80051dbc
Check for NULL pointer returned from localtime()/gmtime().
Guido van Rossum <guido@python.org>
parents:
4232
diff
changeset
|
149 #ifdef EINVAL |
|
4514
f6976b9a85a4
Should compare errno to 0, not NULL
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
150 if (errno == 0) |
|
4373
98ea80051dbc
Check for NULL pointer returned from localtime()/gmtime().
Guido van Rossum <guido@python.org>
parents:
4232
diff
changeset
|
151 errno = EINVAL; |
|
98ea80051dbc
Check for NULL pointer returned from localtime()/gmtime().
Guido van Rossum <guido@python.org>
parents:
4232
diff
changeset
|
152 #endif |
|
98ea80051dbc
Check for NULL pointer returned from localtime()/gmtime().
Guido van Rossum <guido@python.org>
parents:
4232
diff
changeset
|
153 return err_errno(IOError); |
|
98ea80051dbc
Check for NULL pointer returned from localtime()/gmtime().
Guido van Rossum <guido@python.org>
parents:
4232
diff
changeset
|
154 } |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
155 return mkvalue("(iiiiiiiii)", |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
156 p->tm_year + 1900, |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
157 p->tm_mon + 1, /* Want January == 1 */ |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
158 p->tm_mday, |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
159 p->tm_hour, |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
160 p->tm_min, |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
161 p->tm_sec, |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
162 (p->tm_wday + 6) % 7, /* Want Monday == 0 */ |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
163 p->tm_yday + 1, /* Want January, 1 == 1 */ |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
164 p->tm_isdst); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
165 } |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
166 |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
167 static object * |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
168 time_gmtime(self, args) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
169 object *self; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
170 object *args; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
171 { |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
172 double when; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
173 if (!getargs(args, "d", &when)) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
174 return NULL; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
175 return time_convert((time_t)when, gmtime); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
176 } |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
177 |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
178 static object * |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
179 time_localtime(self, args) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
180 object *self; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
181 object *args; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
182 { |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
183 double when; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
184 if (!getargs(args, "d", &when)) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
185 return NULL; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
186 return time_convert((time_t)when, localtime); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
187 } |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
188 |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
189 static int |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
190 gettmarg(args, p) |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
191 object *args; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
192 struct tm *p; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
193 { |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
194 if (!getargs(args, "(iiiiiiiii)", |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
195 &p->tm_year, |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
196 &p->tm_mon, |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
197 &p->tm_mday, |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
198 &p->tm_hour, |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
199 &p->tm_min, |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
200 &p->tm_sec, |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
201 &p->tm_wday, |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
202 &p->tm_yday, |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
203 &p->tm_isdst)) |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
204 return 0; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
205 if (p->tm_year >= 1900) |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
206 p->tm_year -= 1900; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
207 p->tm_mon--; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
208 p->tm_wday = (p->tm_wday + 1) % 7; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
209 p->tm_yday--; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
210 return 1; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
211 } |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
212 |
| 3086 | 213 #ifdef HAVE_STRFTIME |
| 214 static object * | |
| 215 time_strftime(self, args) | |
| 216 object *self; | |
| 217 object *args; | |
| 218 { | |
| 219 struct tm buf; | |
| 220 const char *fmt; | |
| 221 char *outbuf = 0; | |
| 222 int i; | |
| 223 | |
| 224 if (!PyArg_ParseTuple(args, "s(iiiiiiiii)", | |
| 225 &fmt, | |
| 226 &(buf.tm_year), | |
| 227 &(buf.tm_mon), | |
| 228 &(buf.tm_mday), | |
| 229 &(buf.tm_hour), | |
| 230 &(buf.tm_min), | |
| 231 &(buf.tm_sec), | |
| 232 &(buf.tm_wday), | |
| 233 &(buf.tm_yday), | |
| 234 &(buf.tm_isdst))) | |
| 235 return NULL; | |
| 236 if (buf.tm_year >= 1900) | |
| 237 buf.tm_year -= 1900; | |
| 238 buf.tm_mon--; | |
| 239 buf.tm_wday = (buf.tm_wday + 1) % 7; | |
| 240 buf.tm_yday--; | |
| 241 /* I hate these functions that presume you know how big the output */ | |
| 242 /* will be ahead of time... */ | |
| 243 for (i = 1024 ; i < 8192 ; i += 1024) { | |
| 244 outbuf = malloc(i); | |
| 245 if (outbuf == NULL) { | |
| 246 return err_nomem(); | |
| 247 } | |
| 248 if (strftime(outbuf, i-1, fmt, &buf) != 0) { | |
| 249 object *ret; | |
| 250 ret = newstringobject(outbuf); | |
| 251 free(outbuf); | |
| 252 return ret; | |
| 253 } | |
| 254 free(outbuf); | |
| 255 } | |
| 256 return err_nomem(); | |
| 257 } | |
| 258 #endif /* HAVE_STRFTIME */ | |
| 259 | |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
260 static object * |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
261 time_asctime(self, args) |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
262 object *self; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
263 object *args; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
264 { |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
265 struct tm buf; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
266 char *p; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
267 if (!gettmarg(args, &buf)) |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
268 return NULL; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
269 p = asctime(&buf); |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
270 if (p[24] == '\n') |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
271 p[24] = '\0'; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
272 return newstringobject(p); |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
273 } |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
274 |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
275 static object * |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
276 time_ctime(self, args) |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
277 object *self; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
278 object *args; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
279 { |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
280 double dt; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
281 time_t tt; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
282 char *p; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
283 if (!getargs(args, "d", &dt)) |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
284 return NULL; |
|
4216
0a5f01d4701c
Some changes for better Windows portability.
Guido van Rossum <guido@python.org>
parents:
3979
diff
changeset
|
285 tt = (time_t)dt; |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
286 p = ctime(&tt); |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
287 if (p[24] == '\n') |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
288 p[24] = '\0'; |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
289 return newstringobject(p); |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
290 } |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
291 |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
292 static object * |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
293 time_mktime(self, args) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
294 object *self; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
295 object *args; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
296 { |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
297 struct tm buf; |
| 3592 | 298 time_t tt; |
| 299 tt = time(&tt); | |
| 300 buf = *localtime(&tt); | |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
301 if (!gettmarg(args, &buf)) |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
302 return NULL; |
| 3592 | 303 tt = mktime(&buf); |
| 304 if (tt == (time_t)(-1)) { | |
| 305 err_setstr(OverflowError, "mktime argument out of range"); | |
| 306 return NULL; | |
| 307 } | |
| 308 return newfloatobject((double)tt); | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
309 } |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
310 |
| 6 | 311 static struct methodlist time_methods[] = { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
312 {"time", time_time}, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
313 #ifdef HAVE_CLOCK |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
314 {"clock", time_clock}, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
315 #endif |
| 6 | 316 {"sleep", time_sleep}, |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
317 {"gmtime", time_gmtime}, |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
318 {"localtime", time_localtime}, |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
319 {"asctime", time_asctime}, |
|
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
320 {"ctime", time_ctime}, |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
321 {"mktime", time_mktime}, |
| 3086 | 322 #ifdef HAVE_STRFTIME |
|
3388
1696fbf302b6
mark strftime as varargs
Guido van Rossum <guido@python.org>
parents:
3140
diff
changeset
|
323 {"strftime", time_strftime, 1}, |
| 3086 | 324 #endif |
| 6 | 325 {NULL, NULL} /* sentinel */ |
| 326 }; | |
| 327 | |
| 2215 | 328 static void |
| 329 ins(d, name, v) | |
| 330 object *d; | |
| 331 char *name; | |
| 332 object *v; | |
| 333 { | |
| 334 if (v == NULL) | |
| 335 fatal("Can't initialize time module -- NULL value"); | |
| 336 if (dictinsert(d, name, v) != 0) | |
| 337 fatal("Can't initialize time module -- dictinsert failed"); | |
| 338 DECREF(v); | |
| 339 } | |
| 340 | |
| 6 | 341 void |
| 342 inittime() | |
| 343 { | |
| 3140 | 344 object *m, *d; |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
345 m = initmodule("time", time_methods); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
346 d = getmoduledict(m); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
347 #ifdef HAVE_TZNAME |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
348 tzset(); |
| 2215 | 349 ins(d, "timezone", newintobject((long)timezone)); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
350 #ifdef HAVE_ALTZONE |
| 2215 | 351 ins(d, "altzone", newintobject((long)altzone)); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
352 #else |
| 2215 | 353 ins(d, "altzone", newintobject((long)timezone-3600)); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
354 #endif |
| 2215 | 355 ins(d, "daylight", newintobject((long)daylight)); |
| 356 ins(d, "tzname", mkvalue("(zz)", tzname[0], tzname[1])); | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
357 #else /* !HAVE_TZNAME */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
358 #if HAVE_TM_ZONE |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
359 { |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
360 #define YEAR ((time_t)((365 * 24 + 6) * 3600)) |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
361 time_t t; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
362 struct tm *p; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
363 long winterzone, summerzone; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
364 char wintername[10], summername[10]; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
365 /* XXX This won't work on the southern hemisphere. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
366 XXX Anybody got a better idea? */ |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
367 t = (time((time_t *)0) / YEAR) * YEAR; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
368 p = localtime(&t); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
369 winterzone = -p->tm_gmtoff; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
370 strncpy(wintername, p->tm_zone ? p->tm_zone : " ", 9); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
371 wintername[9] = '\0'; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
372 t += YEAR/2; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
373 p = localtime(&t); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
374 summerzone = -p->tm_gmtoff; |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
375 strncpy(summername, p->tm_zone ? p->tm_zone : " ", 9); |
|
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
376 summername[9] = '\0'; |
| 2215 | 377 ins(d, "timezone", newintobject(winterzone)); |
| 378 ins(d, "altzone", newintobject(summerzone)); | |
| 379 ins(d, "daylight", newintobject((long)(winterzone != summerzone))); | |
| 380 ins(d, "tzname", mkvalue("(zz)", wintername, summername)); | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
381 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
382 #endif /* HAVE_TM_ZONE */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
383 #endif /* !HAVE_TZNAME */ |
| 6 | 384 } |
| 385 | |
| 386 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
387 /* Implement floattime() for various platforms */ |
| 6 | 388 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
389 static double |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
390 floattime() |
| 6 | 391 { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
392 /* There are three ways to get the time: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
393 (1) gettimeofday() -- resolution in microseconds |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
394 (2) ftime() -- resolution in milliseconds |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
395 (3) time() -- resolution in seconds |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
396 In all cases the return value is a float in seconds. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
397 Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
398 fail, so we fall back on ftime() or time(). |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
399 Note: clock resolution does not imply clock accuracy! */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
400 #ifdef HAVE_GETTIMEOFDAY |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
401 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
402 struct timeval t; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
403 #ifdef GETTIMEOFDAY_NO_TZ |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
404 if (gettimeofday(&t) == 0) |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
405 return (double)t.tv_sec + t.tv_usec*0.000001; |
|
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
406 #else /* !GETTIMEOFDAY_NO_TZ */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
407 if (gettimeofday(&t, (struct timezone *)NULL) == 0) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
408 return (double)t.tv_sec + t.tv_usec*0.000001; |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1827
diff
changeset
|
409 #endif /* !GETTIMEOFDAY_NO_TZ */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
410 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
411 #endif /* !HAVE_GETTIMEOFDAY */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
412 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
413 #ifdef HAVE_FTIME |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
414 struct timeb t; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
415 ftime(&t); |
|
1827
f5f3ddfec3c7
Makefile.pre.in: add $(OPT) to link command
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
416 return (double)t.time + (double)t.millitm * (double)0.001; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
417 #else /* !HAVE_FTIME */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
418 time_t secs; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
419 time(&secs); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
420 return (double)secs; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
421 #endif /* !HAVE_FTIME */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
422 } |
| 6 | 423 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
424 |
| 6 | 425 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
426 /* Implement floatsleep() for various platforms. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
427 When interrupted (or when another error occurs), return -1 and |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
428 set an exception; else return 0. */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
429 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
430 static int |
| 2506 | 431 #ifdef MPW |
| 432 floatsleep(double secs) | |
| 433 #else | |
|
1181
950cd37fcddc
* Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents:
1177
diff
changeset
|
434 floatsleep(secs) |
|
950cd37fcddc
* Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents:
1177
diff
changeset
|
435 double secs; |
| 2506 | 436 #endif /* MPW */ |
| 6 | 437 { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
438 #ifdef HAVE_SELECT |
|
143
1870d82de069
Added BSD implementations of millisleep.
Guido van Rossum <guido@python.org>
parents:
86
diff
changeset
|
439 struct timeval t; |
|
1181
950cd37fcddc
* Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents:
1177
diff
changeset
|
440 double frac; |
|
950cd37fcddc
* Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents:
1177
diff
changeset
|
441 frac = fmod(secs, 1.0); |
|
950cd37fcddc
* Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents:
1177
diff
changeset
|
442 secs = floor(secs); |
|
950cd37fcddc
* Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents:
1177
diff
changeset
|
443 t.tv_sec = (long)secs; |
|
950cd37fcddc
* Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents:
1177
diff
changeset
|
444 t.tv_usec = (long)(frac*1000000.0); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
445 if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
446 err_errno(IOError); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
447 return -1; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
448 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
449 #else /* !HAVE_SELECT */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
450 #ifdef macintosh |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
451 #define MacTicks (* (long *)0x16A) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
452 long deadline; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
453 deadline = MacTicks + (long)(secs * 60.0); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
454 while (MacTicks < deadline) { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
455 if (sigcheck()) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
456 return -1; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
457 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
458 #else /* !macintosh */ |
| 3592 | 459 #ifdef __WATCOMC__ |
| 460 /* XXX Can't interrupt this sleep */ | |
| 461 delay((int)(secs * 1000 + 0.5)); /* delay() uses milliseconds */ | |
| 462 #else /* !__WATCOMC__ */ | |
|
1322
f3c907efe5d7
* config.c: different default PYTHONPATH for MS-DOS
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
463 #ifdef MSDOS |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
464 struct timeb t1, t2; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
465 double frac; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
466 extern double fmod PROTO((double, double)); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
467 extern double floor PROTO((double)); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
468 if (secs <= 0.0) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
469 return; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
470 frac = fmod(secs, 1.0); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
471 secs = floor(secs); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
472 ftime(&t1); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
473 t2.time = t1.time + (int)secs; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
474 t2.millitm = t1.millitm + (int)(frac*1000.0); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
475 while (t2.millitm >= 1000) { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
476 t2.time++; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
477 t2.millitm -= 1000; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
478 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
479 for (;;) { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
480 #ifdef QUICKWIN |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
481 _wyield(); |
|
209
e486c849c50c
New hacks for include files to get time_t in the most portable way.
Guido van Rossum <guido@python.org>
parents:
181
diff
changeset
|
482 #endif |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
483 if (sigcheck()) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
484 return -1; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
485 ftime(&t1); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
486 if (t1.time > t2.time || |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
487 t1.time == t2.time && t1.millitm >= t2.millitm) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
488 break; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
489 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
490 #else /* !MSDOS */ |
|
4232
886c0f775c97
Sleep() turns out to be win32 specific.
Guido van Rossum <guido@python.org>
parents:
4216
diff
changeset
|
491 #ifdef MS_WIN32 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
492 /* XXX Can't interrupt this sleep */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
493 Sleep((int)(secs*1000)); |
|
4232
886c0f775c97
Sleep() turns out to be win32 specific.
Guido van Rossum <guido@python.org>
parents:
4216
diff
changeset
|
494 #else /* !MS_WIN32 */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
495 /* XXX Can't interrupt this sleep */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
496 sleep((int)secs); |
|
4232
886c0f775c97
Sleep() turns out to be win32 specific.
Guido van Rossum <guido@python.org>
parents:
4216
diff
changeset
|
497 #endif /* !MS_WIN32 */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
498 #endif /* !MSDOS */ |
| 3592 | 499 #endif /* !__WATCOMC__ */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
500 #endif /* !macintosh */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
501 #endif /* !HAVE_SELECT */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
502 return 0; |
|
209
e486c849c50c
New hacks for include files to get time_t in the most portable way.
Guido van Rossum <guido@python.org>
parents:
181
diff
changeset
|
503 } |
