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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* Time module */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
34 #include "allobjects.h"
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
35 #include "modsupport.h"
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
36 #include "ceval.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
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
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
66 #ifdef __WATCOMC__
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
67 #include <i86.h>
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 static object *
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 time_time(self, args)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 object *self;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 object *args;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 if (!getnoarg(args))
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 static object *
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 time_sleep(self, args)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 object *self;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 object *args;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 return NULL;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
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
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
132 RET_SAVE
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 return NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 }
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 923
diff changeset
135 END_SAVE
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 INCREF(None);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 return None;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
139
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
213 #ifdef HAVE_STRFTIME
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
214 static object *
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
215 time_strftime(self, args)
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
216 object *self;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
217 object *args;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
218 {
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
219 struct tm buf;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
220 const char *fmt;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
221 char *outbuf = 0;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
222 int i;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
223
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
224 if (!PyArg_ParseTuple(args, "s(iiiiiiiii)",
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
225 &fmt,
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
226 &(buf.tm_year),
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
227 &(buf.tm_mon),
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
228 &(buf.tm_mday),
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
229 &(buf.tm_hour),
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
230 &(buf.tm_min),
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
231 &(buf.tm_sec),
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
232 &(buf.tm_wday),
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
233 &(buf.tm_yday),
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
234 &(buf.tm_isdst)))
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
235 return NULL;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
236 if (buf.tm_year >= 1900)
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
237 buf.tm_year -= 1900;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
238 buf.tm_mon--;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
239 buf.tm_wday = (buf.tm_wday + 1) % 7;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
240 buf.tm_yday--;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
241 /* I hate these functions that presume you know how big the output */
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
242 /* will be ahead of time... */
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
243 for (i = 1024 ; i < 8192 ; i += 1024) {
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
244 outbuf = malloc(i);
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
245 if (outbuf == NULL) {
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
246 return err_nomem();
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
247 }
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
248 if (strftime(outbuf, i-1, fmt, &buf) != 0) {
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
249 object *ret;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
250 ret = newstringobject(outbuf);
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
251 free(outbuf);
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
252 return ret;
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
253 }
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
254 free(outbuf);
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
255 }
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
256 return err_nomem();
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
257 }
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
258 #endif /* HAVE_STRFTIME */
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
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
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
298 time_t tt;
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
299 tt = time(&tt);
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
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
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
303 tt = mktime(&buf);
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
304 if (tt == (time_t)(-1)) {
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
305 err_setstr(OverflowError, "mktime argument out of range");
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
306 return NULL;
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
307 }
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
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
d7eea9013e73 added time.strftime()
Guido van Rossum <guido@python.org>
parents: 2533
diff changeset
324 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 {NULL, NULL} /* sentinel */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 };
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
327
2215
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
328 static void
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
329 ins(d, name, v)
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
330 object *d;
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
331 char *name;
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
332 object *v;
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
333 {
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
334 if (v == NULL)
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
335 fatal("Can't initialize time module -- NULL value");
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
336 if (dictinsert(d, name, v) != 0)
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
337 fatal("Can't initialize time module -- dictinsert failed");
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
338 DECREF(v);
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
339 }
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
340
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 void
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 inittime()
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 {
3140
cd388cc9ba98 Removed unused variable
Jack Jansen <jack.jansen@cwi.nl>
parents: 3086
diff changeset
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
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
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
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
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
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
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
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
355 ins(d, "daylight", newintobject((long)daylight));
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
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
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
377 ins(d, "timezone", newintobject(winterzone));
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
378 ins(d, "altzone", newintobject(summerzone));
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
379 ins(d, "daylight", newintobject((long)(winterzone != summerzone)));
a3bd61632f14 fix leaks
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
385
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1413
diff changeset
424
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
9d6e97d66670 changes for MPW
Guido van Rossum <guido@python.org>
parents: 2215
diff changeset
431 #ifdef MPW
9d6e97d66670 changes for MPW
Guido van Rossum <guido@python.org>
parents: 2215
diff changeset
432 floatsleep(double secs)
9d6e97d66670 changes for MPW
Guido van Rossum <guido@python.org>
parents: 2215
diff changeset
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
9d6e97d66670 changes for MPW
Guido van Rossum <guido@python.org>
parents: 2215
diff changeset
436 #endif /* MPW */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
459 #ifdef __WATCOMC__
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
460 /* XXX Can't interrupt this sleep */
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
461 delay((int)(secs * 1000 + 0.5)); /* delay() uses milliseconds */
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
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
2403620ca931 Watcom changes.
Guido van Rossum <guido@python.org>
parents: 3419
diff changeset
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 }