annotate Modules/posixmodule.c @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents 4c85de247eed
children 86d8384d8810
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: 117
diff changeset
1
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* POSIX module implementation */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
4 /* This file is also used for Windows NT/MS-Win and OS/2. In that case the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
5 module actually calls itself 'nt' or 'os2', not 'posix', and a few
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
6 functions are either unimplemented or implemented differently. The source
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
7 assumes that for Windows NT, the macro 'MS_WINDOWS' is defined independent
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
8 of the compiler used. Different compilers define their own feature
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
9 test macro, e.g. '__BORLANDC__' or '_MSC_VER'. For OS/2, the compiler
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
10 independent macro PYOS_OS2 should be defined. On OS/2 the default
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
11 compiler is assumed to be IBM's VisualAge C++ (VACPP). PYCC_GCC is used
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
12 as the compiler specific macro for the EMX port of gcc to OS/2. */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
13
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
14 /* See also ../Dos/dosmodule.c */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
15
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
16 #include "Python.h"
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
17 #include "structseq.h"
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
18
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
19 #if defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
20 # include <ctype.h> /* tolower() */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
21 # include <descrip.h> /* string descriptors */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
22 # include <dvidef.h> /* DVI$_name */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
23 # include <file.h> /* -> O_RDWR */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
24 # include <jpidef.h> /* JPI$_name */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
25 # include <lib$routines.h> /* LIB$name */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
26 # include <ots$routines.h> /* OTS$name */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
27 # include <ssdef.h> /* SS$_name */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
28 # include <unixio.h>
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
29 # include <unixlib.h>
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
30 # include <stat.h>
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
31 /* ----- */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
32 /* DECC on Alpha does redefine these already */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
33 # ifndef shell$from_vms
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
34 # define shell$from_vms(_p1_,_p2_,_p3_) decc$from_vms(_p1_,_p2_,_p3_)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
35 # endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
36 # ifndef shell$translate_vms
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
37 # define shell$translate_vms(_p1_) decc$translate_vms(_p1_)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
38 # endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
39 # ifndef shell$to_vms
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
40 # define shell$to_vms(_p1_,_p2_,_p3_,_p4_,_p5_) \
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
41 decc$to_vms(_p1_,_p2_,_p3_,_p4_,_p5_)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
42 # endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
43 # include <wait.h> /* define wait() */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
44 #endif /* defined(__VMS) */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
45
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
46 PyDoc_STRVAR(posix__doc__,
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
47 "This module provides access to operating system functionality that is\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
48 standardized by the C Standard and the POSIX standard (a thinly\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
49 disguised Unix interface). Refer to the library manual and\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
50 corresponding Unix manual entries for more information on calls.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
51
26330
3086e111783a Fix --disable-unicode compilation problems.
Martin v. Löwis <martin@v.loewis.de>
parents: 26320
diff changeset
52 #ifndef Py_USING_UNICODE
3086e111783a Fix --disable-unicode compilation problems.
Martin v. Löwis <martin@v.loewis.de>
parents: 26320
diff changeset
53 /* This is used in signatures of functions. */
3086e111783a Fix --disable-unicode compilation problems.
Martin v. Löwis <martin@v.loewis.de>
parents: 26320
diff changeset
54 #define Py_UNICODE void
3086e111783a Fix --disable-unicode compilation problems.
Martin v. Löwis <martin@v.loewis.de>
parents: 26320
diff changeset
55 #endif
3086e111783a Fix --disable-unicode compilation problems.
Martin v. Löwis <martin@v.loewis.de>
parents: 26320
diff changeset
56
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
57 #if defined(PYOS_OS2)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
58 #define INCL_DOS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
59 #define INCL_DOSERRORS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
60 #define INCL_DOSPROCESS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
61 #define INCL_NOPMAPI
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
62 #include <os2.h>
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
63 #if defined(PYCC_GCC)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
64 #include <ctype.h>
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
65 #include <io.h>
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
66 #include <stdio.h>
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
67 #include <process.h>
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
68 #include "osdefs.h"
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
69 #endif
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
70 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
71
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
72 #include <sys/types.h>
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
73 #include <sys/stat.h>
20537
01af91aeccd4 Shut up warnings for setgroups() on Linux -- you have to #include
Guido van Rossum <guido@python.org>
parents: 20508
diff changeset
74
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
75 #ifdef HAVE_SYS_WAIT_H
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
76 #include <sys/wait.h> /* For WNOHANG */
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
77 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
78
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
79 #ifdef HAVE_SIGNAL_H
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
80 #include <signal.h>
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
81 #endif
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
82
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
83 #ifdef HAVE_FCNTL_H
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
84 #include <fcntl.h>
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
85 #endif /* HAVE_FCNTL_H */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
86
20537
01af91aeccd4 Shut up warnings for setgroups() on Linux -- you have to #include
Guido van Rossum <guido@python.org>
parents: 20508
diff changeset
87 #ifdef HAVE_GRP_H
01af91aeccd4 Shut up warnings for setgroups() on Linux -- you have to #include
Guido van Rossum <guido@python.org>
parents: 20508
diff changeset
88 #include <grp.h>
01af91aeccd4 Shut up warnings for setgroups() on Linux -- you have to #include
Guido van Rossum <guido@python.org>
parents: 20508
diff changeset
89 #endif
01af91aeccd4 Shut up warnings for setgroups() on Linux -- you have to #include
Guido van Rossum <guido@python.org>
parents: 20508
diff changeset
90
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
91 #ifdef HAVE_SYSEXITS_H
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
92 #include <sysexits.h>
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
93 #endif /* HAVE_SYSEXITS_H */
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
94
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
95 /* Various compilers have only certain posix functions */
18835
2dea40e40d9d Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774.
Martin v. Löwis <martin@v.loewis.de>
parents: 18749
diff changeset
96 /* XXX Gosh I wish these were all moved into pyconfig.h */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
97 #if defined(PYCC_VACPP) && defined(PYOS_OS2)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
98 #include <process.h>
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
99 #else
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
100 #if defined(__WATCOMC__) && !defined(__QNX__) /* Watcom compiler */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
101 #define HAVE_GETCWD 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
102 #define HAVE_OPENDIR 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
103 #define HAVE_SYSTEM 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
104 #if defined(__OS2__)
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
105 #define HAVE_EXECV 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
106 #define HAVE_WAIT 1
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
107 #endif
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
108 #include <process.h>
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
109 #else
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
110 #ifdef __BORLANDC__ /* Borland compiler */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
111 #define HAVE_EXECV 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
112 #define HAVE_GETCWD 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
113 #define HAVE_OPENDIR 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
114 #define HAVE_PIPE 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
115 #define HAVE_POPEN 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
116 #define HAVE_SYSTEM 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
117 #define HAVE_WAIT 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
118 #else
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
119 #ifdef _MSC_VER /* Microsoft compiler */
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
120 #define HAVE_GETCWD 1
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
121 #define HAVE_SPAWNV 1
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
122 #define HAVE_EXECV 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
123 #define HAVE_PIPE 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
124 #define HAVE_POPEN 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
125 #define HAVE_SYSTEM 1
21857
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
126 #define HAVE_CWAIT 1
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
127 #else
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
128 #if defined(PYOS_OS2) && defined(PYCC_GCC) || defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
129 /* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
130 #else /* all other compilers */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
131 /* Unix functions that the configure script doesn't check for */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
132 #define HAVE_EXECV 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
133 #define HAVE_FORK 1
17419
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
134 #if defined(__USLC__) && defined(__SCO_VERSION__) /* SCO UDK Compiler */
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
135 #define HAVE_FORK1 1
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
136 #endif
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
137 #define HAVE_GETCWD 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
138 #define HAVE_GETEGID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
139 #define HAVE_GETEUID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
140 #define HAVE_GETGID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
141 #define HAVE_GETPPID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
142 #define HAVE_GETUID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
143 #define HAVE_KILL 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
144 #define HAVE_OPENDIR 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
145 #define HAVE_PIPE 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
146 #define HAVE_POPEN 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
147 #define HAVE_SYSTEM 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
148 #define HAVE_WAIT 1
9939
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
149 #define HAVE_TTYNAME 1
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
150 #endif /* PYOS_OS2 && PYCC_GCC */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
151 #endif /* _MSC_VER */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
152 #endif /* __BORLANDC__ */
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
153 #endif /* ! __WATCOMC__ || __QNX__ */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
154 #endif /* ! __IBMC__ */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
155
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
156 #ifndef _MSC_VER
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
157
14837
b7787a9052e3 Add missing prototypes for the benefit of SunOS 4.1.4 */
Guido van Rossum <guido@python.org>
parents: 14767
diff changeset
158 #if defined(sun) && !defined(__SVR4)
b7787a9052e3 Add missing prototypes for the benefit of SunOS 4.1.4 */
Guido van Rossum <guido@python.org>
parents: 14767
diff changeset
159 /* SunOS 4.1.4 doesn't have prototypes for these: */
b7787a9052e3 Add missing prototypes for the benefit of SunOS 4.1.4 */
Guido van Rossum <guido@python.org>
parents: 14767
diff changeset
160 extern int rename(const char *, const char *);
b7787a9052e3 Add missing prototypes for the benefit of SunOS 4.1.4 */
Guido van Rossum <guido@python.org>
parents: 14767
diff changeset
161 extern int pclose(FILE *);
b7787a9052e3 Add missing prototypes for the benefit of SunOS 4.1.4 */
Guido van Rossum <guido@python.org>
parents: 14767
diff changeset
162 extern int fclose(FILE *);
16607
941a76f38747 Add a few more missing prototypes to the SunOS 4.1.4 section (no SF
Thomas Wouters <thomas@python.org>
parents: 16367
diff changeset
163 extern int fsync(int);
941a76f38747 Add a few more missing prototypes to the SunOS 4.1.4 section (no SF
Thomas Wouters <thomas@python.org>
parents: 16367
diff changeset
164 extern int lstat(const char *, struct stat *);
941a76f38747 Add a few more missing prototypes to the SunOS 4.1.4 section (no SF
Thomas Wouters <thomas@python.org>
parents: 16367
diff changeset
165 extern int symlink(const char *, const char *);
14837
b7787a9052e3 Add missing prototypes for the benefit of SunOS 4.1.4 */
Guido van Rossum <guido@python.org>
parents: 14767
diff changeset
166 #endif
b7787a9052e3 Add missing prototypes for the benefit of SunOS 4.1.4 */
Guido van Rossum <guido@python.org>
parents: 14767
diff changeset
167
25327
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25277
diff changeset
168 #if defined(__sgi)&&_COMPILER_VERSION>=700
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25277
diff changeset
169 /* declare ctermid_r if compiling with MIPSPro 7.x in ANSI C mode
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25277
diff changeset
170 (default) */
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25277
diff changeset
171 extern char *ctermid_r(char *);
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25277
diff changeset
172 #endif
337fcc24985b Patch #608999: Fix portability problems with MIPSPro 7.x
Martin v. Löwis <martin@v.loewis.de>
parents: 25277
diff changeset
173
13694
b54f11ada91e Create a new section of pyport.h to hold all external function declarations
Thomas Wouters <thomas@python.org>
parents: 13675
diff changeset
174 #ifndef HAVE_UNISTD_H
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
175 #if defined(PYCC_VACPP)
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
176 extern int mkdir(char *);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
177 #else
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
178 #if ( defined(__WATCOMC__) || defined(_MSC_VER) ) && !defined(__QNX__)
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
179 extern int mkdir(const char *);
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
180 #else
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
181 extern int mkdir(const char *, mode_t);
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
182 #endif
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
183 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
184 #if defined(__IBMC__) || defined(__IBMCPP__)
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
185 extern int chdir(char *);
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
186 extern int rmdir(char *);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
187 #else
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
188 extern int chdir(const char *);
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
189 extern int rmdir(const char *);
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
190 #endif
17831
5c06a9596fbf SF patch #418147 Fixes to allow compiling w/ Borland, from Stephen Hansen.
Tim Peters <tim.peters@gmail.com>
parents: 17822
diff changeset
191 #ifdef __BORLANDC__
5c06a9596fbf SF patch #418147 Fixes to allow compiling w/ Borland, from Stephen Hansen.
Tim Peters <tim.peters@gmail.com>
parents: 17822
diff changeset
192 extern int chmod(const char *, int);
5c06a9596fbf SF patch #418147 Fixes to allow compiling w/ Borland, from Stephen Hansen.
Tim Peters <tim.peters@gmail.com>
parents: 17822
diff changeset
193 #else
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
194 extern int chmod(const char *, mode_t);
17831
5c06a9596fbf SF patch #418147 Fixes to allow compiling w/ Borland, from Stephen Hansen.
Tim Peters <tim.peters@gmail.com>
parents: 17822
diff changeset
195 #endif
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
196 extern int chown(const char *, uid_t, gid_t);
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
197 extern char *getcwd(char *, int);
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
198 extern char *strerror(int);
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
199 extern int link(const char *, const char *);
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
200 extern int rename(const char *, const char *);
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
201 extern int stat(const char *, struct stat *);
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
202 extern int unlink(const char *);
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
203 extern int pclose(FILE *);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
204 #ifdef HAVE_SYMLINK
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
205 extern int symlink(const char *, const char *);
2370
e386035f897d fix comment opener after #endif
Guido van Rossum <guido@python.org>
parents: 2298
diff changeset
206 #endif /* HAVE_SYMLINK */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
207 #ifdef HAVE_LSTAT
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
208 extern int lstat(const char *, struct stat *);
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
209 #endif /* HAVE_LSTAT */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
210 #endif /* !HAVE_UNISTD_H */
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
211
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
212 #endif /* !_MSC_VER */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
213
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
214 #ifdef HAVE_UTIME_H
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
215 #include <utime.h>
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
216 #endif /* HAVE_UTIME_H */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
217
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
218 #ifdef HAVE_SYS_UTIME_H
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
219 #include <sys/utime.h>
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
220 #define HAVE_UTIME_H /* pretend we do for the rest of this file */
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
221 #endif /* HAVE_SYS_UTIME_H */
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
222
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
223 #ifdef HAVE_SYS_TIMES_H
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
224 #include <sys/times.h>
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
225 #endif /* HAVE_SYS_TIMES_H */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
226
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
227 #ifdef HAVE_SYS_PARAM_H
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
228 #include <sys/param.h>
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
229 #endif /* HAVE_SYS_PARAM_H */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
230
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
231 #ifdef HAVE_SYS_UTSNAME_H
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
232 #include <sys/utsname.h>
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
233 #endif /* HAVE_SYS_UTSNAME_H */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
234
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
235 #ifdef HAVE_DIRENT_H
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
236 #include <dirent.h>
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
237 #define NAMLEN(dirent) strlen((dirent)->d_name)
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
238 #else
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
239 #if defined(__WATCOMC__) && !defined(__QNX__)
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
240 #include <direct.h>
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
241 #define NAMLEN(dirent) strlen((dirent)->d_name)
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
242 #else
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
243 #define dirent direct
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
244 #define NAMLEN(dirent) (dirent)->d_namlen
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
245 #endif
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
246 #ifdef HAVE_SYS_NDIR_H
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
247 #include <sys/ndir.h>
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
248 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
249 #ifdef HAVE_SYS_DIR_H
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
250 #include <sys/dir.h>
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
251 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
252 #ifdef HAVE_NDIR_H
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
253 #include <ndir.h>
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
254 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
255 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
256
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
257 #ifdef _MSC_VER
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
258 #include <direct.h>
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
259 #include <io.h>
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
260 #include <process.h>
22123
3a06e19df46b Python no longer compiled on Windows, due to #include file confusion
Tim Peters <tim.peters@gmail.com>
parents: 22116
diff changeset
261 #include "osdefs.h"
24239
51cda6e8764a /F revealed that ShellExecute() only requires shellapi.h, not the
Tim Peters <tim.peters@gmail.com>
parents: 24235
diff changeset
262 #define WIN32_LEAN_AND_MEAN
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
263 #include <windows.h>
24239
51cda6e8764a /F revealed that ShellExecute() only requires shellapi.h, not the
Tim Peters <tim.peters@gmail.com>
parents: 24235
diff changeset
264 #include <shellapi.h> /* for ShellExecute() */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
265 #define popen _popen
1815
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
266 #define pclose _pclose
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
267 #endif /* _MSC_VER */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
268
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
269 #if defined(PYCC_VACPP) && defined(PYOS_OS2)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
270 #include <io.h>
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
271 #endif /* OS2 */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
272
22123
3a06e19df46b Python no longer compiled on Windows, due to #include file confusion
Tim Peters <tim.peters@gmail.com>
parents: 22116
diff changeset
273 #ifndef MAXPATHLEN
3a06e19df46b Python no longer compiled on Windows, due to #include file confusion
Tim Peters <tim.peters@gmail.com>
parents: 22116
diff changeset
274 #define MAXPATHLEN 1024
3a06e19df46b Python no longer compiled on Windows, due to #include file confusion
Tim Peters <tim.peters@gmail.com>
parents: 22116
diff changeset
275 #endif /* MAXPATHLEN */
3a06e19df46b Python no longer compiled on Windows, due to #include file confusion
Tim Peters <tim.peters@gmail.com>
parents: 22116
diff changeset
276
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
277 #ifdef UNION_WAIT
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
278 /* Emulate some macros on systems that have a union instead of macros */
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
279
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
280 #ifndef WIFEXITED
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
281 #define WIFEXITED(u_wait) (!(u_wait).w_termsig && !(u_wait).w_coredump)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
282 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
283
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
284 #ifndef WEXITSTATUS
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
285 #define WEXITSTATUS(u_wait) (WIFEXITED(u_wait)?((u_wait).w_retcode):-1)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
286 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
287
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
288 #ifndef WTERMSIG
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
289 #define WTERMSIG(u_wait) ((u_wait).w_termsig)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
290 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
291
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
292 #endif /* UNION_WAIT */
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
293
11893
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
294 /* Don't use the "_r" form if we don't need it (also, won't have a
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
295 prototype for it, at least on Solaris -- maybe others as well?). */
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
296 #if defined(HAVE_CTERMID_R) && defined(WITH_THREAD)
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
297 #define USE_CTERMID_R
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
298 #endif
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
299
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
300 #if defined(HAVE_TMPNAM_R) && defined(WITH_THREAD)
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
301 #define USE_TMPNAM_R
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
302 #endif
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
303
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
304 /* choose the appropriate stat and fstat functions and return structs */
13251
86177fb0edd8 Crude way to fix a problem on AIX: #undef STAT before defining it.
Guido van Rossum <guido@python.org>
parents: 13153
diff changeset
305 #undef STAT
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
306 #if defined(MS_WIN64) || defined(MS_WINDOWS)
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
307 # define STAT _stati64
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
308 # define FSTAT _fstati64
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
309 # define STRUCT_STAT struct _stati64
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
310 #else
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
311 # define STAT stat
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
312 # define FSTAT fstat
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
313 # define STRUCT_STAT struct stat
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
314 #endif
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
315
25694
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
316 #if defined(MAJOR_IN_MKDEV)
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
317 #include <sys/mkdev.h>
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
318 #else
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
319 #if defined(MAJOR_IN_SYSMACROS)
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
320 #include <sys/sysmacros.h>
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
321 #endif
23193
508fd952c9e9 #546163, fix link problem on Solaris 8 for makedev when using mknod
Neal Norwitz <nnorwitz@gmail.com>
parents: 23170
diff changeset
322 #if defined(HAVE_MKNOD) && defined(HAVE_SYS_MKDEV_H)
508fd952c9e9 #546163, fix link problem on Solaris 8 for makedev when using mknod
Neal Norwitz <nnorwitz@gmail.com>
parents: 23170
diff changeset
323 #include <sys/mkdev.h>
508fd952c9e9 #546163, fix link problem on Solaris 8 for makedev when using mknod
Neal Norwitz <nnorwitz@gmail.com>
parents: 23170
diff changeset
324 #endif
25694
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
325 #endif
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
326
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 /* Return a dictionary corresponding to the POSIX environment table */
24469
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
328 #ifdef WITH_NEXT_FRAMEWORK
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
329 /* On Darwin/MacOSX a shared library or framework has no access to
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
330 ** environ directly, we must obtain it with _NSGetEnviron().
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
331 */
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
332 #include <crt_externs.h>
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
333 static char **environ;
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
334 #elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) )
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 extern char **environ;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
336 #endif /* !_MSC_VER */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
337
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
338 #if defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
339 static char psxmod_gt_psxpath[1026];
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
340
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
341 static int
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
342 psxmod_from_vms_action (char *spec)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
343 {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
344 (void)strcpy(psxmod_gt_psxpath, spec);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
345 return 1;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
346 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
347
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
348 /* Return a dictionary corresponding to the VMS 'environment table' */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
349 static char* at_home = "HOME";
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
350 static char* at_path = "PATH";
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
351
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
352 static char psxmod_t_command [] = "SYS$COMMAND";
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
353 /* add some values to provide a similar environment like POSIX */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
354 void
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
355 psmmod_add_posix_env(PyObject *d)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
356 {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
357 /* -------------------- */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
358 struct dsc$descriptor_s r_device_name;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
359 long l_devbufsiz;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
360 long l_tt_page;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
361 long l_item_code;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
362 long l_status;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
363 PyObject *o;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
364 struct dsc$descriptor_s r_resultant_string;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
365 char t_resultant_string[13]; /* enough space for username (12)+ '\0' */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
366 char *at_resultant_string;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
367 short int w_resultant_length;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
368
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
369 /* set up string descriptor */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
370 r_device_name.dsc$w_length = strlen(psxmod_t_command);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
371 r_device_name.dsc$b_dtype = DSC$K_DTYPE_T;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
372 r_device_name.dsc$b_class = DSC$K_CLASS_S;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
373 r_device_name.dsc$a_pointer = &psxmod_t_command[0];
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
374
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
375 /* -------------------- */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
376 /* COLUMNS = $getdvi("SYS$COMMAND","DEVBUFSIZ") */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
377 l_item_code = DVI$_DEVBUFSIZ;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
378 l_status = lib$getdvi(&l_item_code,
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
379 0, /* [channel] */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
380 &r_device_name,
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
381 &l_devbufsiz, /* integer-value */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
382 0, /* resultant_string */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
383 0); /* resultant_length */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
384 if (l_status == SS$_NORMAL) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
385 /* create a string object here to comply with POSIX */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
386
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
387 /* set up string descriptor */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
388 r_resultant_string.dsc$w_length =
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
389 (sizeof(t_resultant_string) - 1); /* ommit '\0' at end */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
390 r_resultant_string.dsc$b_dtype = DSC$K_DTYPE_T;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
391 r_resultant_string.dsc$b_class = DSC$K_CLASS_S;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
392 r_resultant_string.dsc$a_pointer = &t_resultant_string[0];
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
393
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
394 /* Convert Signed Integer to Decimal Text */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
395 l_status = ots$cvt_l_ti(&l_devbufsiz, &r_resultant_string, 1,
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
396 4, 0);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
397 if (l_status == SS$_NORMAL) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
398 /* terminate string for 'C'-style */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
399 t_resultant_string[sizeof(t_resultant_string)-1] = '\0';
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
400 /* string appears as: ' value' -- skip ' ' */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
401 at_resultant_string = &t_resultant_string[0];
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
402 while ((*at_resultant_string == ' ' ) &&
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
403 (*at_resultant_string != '\0')) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
404 at_resultant_string++; /* skip prefix spaces */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
405 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
406
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
407 o = Py_BuildValue("s", at_resultant_string);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
408 if (o != NULL) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
409 (void) PyDict_SetItemString(d, "COLUMNS", o);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
410 Py_DECREF(o);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
411 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
412 } /* (l_status = ots$cvt_l_ti() == SS$_NORMAL) */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
413 } /* (l_status = lib$getdvi(DVI$_DEVBUFSIZ) == SS$_NORMAL) */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
414 /* LINES = $getdvi("SYS$COMMAND","TT_PAGE") */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
415 l_item_code = DVI$_TT_PAGE;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
416 l_status = lib$getdvi(&l_item_code,
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
417 0, /* [channel] */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
418 &r_device_name,
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
419 &l_tt_page, /* integer-value */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
420 0, /* resultant_string */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
421 0); /* resultant_length */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
422 if (l_status == SS$_NORMAL) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
423 /* create a string object here to comply with POSIX */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
424
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
425 /* set up string descriptor */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
426 r_resultant_string.dsc$w_length =
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
427 (sizeof(t_resultant_string) - 1); /* ommit '\0' at end */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
428 r_resultant_string.dsc$b_dtype = DSC$K_DTYPE_T;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
429 r_resultant_string.dsc$b_class = DSC$K_CLASS_S;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
430 r_resultant_string.dsc$a_pointer = &t_resultant_string[0];
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
431
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
432 /* Convert Signed Integer to Decimal Text */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
433 l_status = ots$cvt_l_ti(&l_tt_page, &r_resultant_string,
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
434 1, 4, 0);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
435 if (l_status == SS$_NORMAL) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
436 /* terminate string for 'C'-style */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
437 t_resultant_string[sizeof(t_resultant_string)-1] = '\0';
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
438 /* string appears as: ' value' -- skip ' ' */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
439 at_resultant_string = &t_resultant_string[0];
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
440 while ((*at_resultant_string == ' ' ) &&
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
441 (*at_resultant_string != '\0')) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
442 at_resultant_string++; /* skip prefix spaces */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
443 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
444
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
445 o = Py_BuildValue("s", at_resultant_string);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
446 if (o != NULL) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
447 (void)PyDict_SetItemString(d, "LINES", o);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
448 Py_DECREF(o);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
449 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
450 } /* (l_status = ots$cvt_l_ti() == SS$_NORMAL) */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
451 } /* (l_status = lib$getdvi(DVI$_TT_PAGE) == SS$_NORMAL) */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
452 /* else -- ignore error */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
453
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
454 /* LOGNAME = $getjpi(0,"USERNAME") */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
455 l_item_code = JPI$_USERNAME;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
456
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
457 /* set up string descriptor */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
458 r_resultant_string.dsc$w_length =
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
459 (sizeof(t_resultant_string) - 1); /* ommit '\0' at end */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
460 r_resultant_string.dsc$b_dtype = DSC$K_DTYPE_T;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
461 r_resultant_string.dsc$b_class = DSC$K_CLASS_S;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
462 r_resultant_string.dsc$a_pointer = &t_resultant_string[0];
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
463
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
464 l_status = lib$getjpi(&l_item_code, 0, 0, 0,
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
465 &r_resultant_string, &w_resultant_length);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
466 if (l_status == SS$_NORMAL){
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
467 t_resultant_string[w_resultant_length] = '\0';
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
468
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
469 /* remove any trailing spaces by replacing 1st one with '\0' */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
470 at_resultant_string = &t_resultant_string[0];
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
471 while ((*at_resultant_string != ' ' ) &&
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
472 (*at_resultant_string != '\0')) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
473 /* lowercase for compatibility with POSIX */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
474 *at_resultant_string = tolower(*at_resultant_string);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
475 at_resultant_string++; /* skip non-blank */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
476 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
477 *at_resultant_string = '\0'; /* terminate */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
478
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
479 o = Py_BuildValue("s", &t_resultant_string[0]);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
480 if (o != NULL) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
481 (void) PyDict_SetItemString(d, "LOGNAME", o);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
482 (void) PyDict_SetItemString(d, "USERNAME", o);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
483 Py_DECREF(o);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
484 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
485 } /* (l_status == SS$_NORMAL) */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
486
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
487 /* OS = "OpenVMS" */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
488 o = PyString_FromString ("OpenVMS");
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
489 if (o != NULL) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
490 (void)PyDict_SetItemString(d, "OS", o);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
491 Py_DECREF(o);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
492 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
493 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
494
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
495 /* @@ posix env:
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
496 COLUMNS=80 $ write sys$output f$getdvi("SYS$COMMAND","DEVBUFSIZ")
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
497 LINES=47 $ write sys$output f$getdvi("SYS$COMMAND","TT_PAGE")
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
498 LOGNAME=zessin $ write sys$output f$edit(f$getjpi(0,"username"), -
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
499 "collapse,lowercase")
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
500 OS=OpenVMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
501 PS1=HERE $
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
502
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
503 TZ=CET-1:00CET DST,M3.5.0/2:00,M10.5.0/3:00
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
504 $ write sys$output f$trnlnm("POSIX$DEFAULT_TZ")
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
505 "CET-1:00CET DST-2:00,M3.5.0/2:00,M10.5.0/3:00"
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
506 $ write sys$output f$trnlnm("UCX$TZ")
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
507 "MET-1MET_DST-2,M3.5.0/2,M10.5.0/3"
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
508 PAGER=more
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
509 TERM=vt300_series
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
510 SHELL=/bin/sh
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
511 HOME=/dka100/user/zessin
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
512 _=/bin/env
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
513
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
514 >>> for v in os.environ.items():
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
515 ... print v
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
516 ...
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
517 ('HOME', '/user_here/zessin')
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
518 ('COLUMNS', '80')
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
519 ('LINES', '24')
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
520 ('PATH', '/python_disk/python/python-1_5_2/vms')
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
521 ('OS', 'OpenVMS')
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
522 ('USER', 'ZESSIN')
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
523 ('LOGNAME', 'zessin')
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
524 ('TERM', 'vt300-80')
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
525 ('USERNAME', 'zessin')
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
526 >>>
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
527 */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
528 #endif /* __VMS */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
529
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
530 static PyObject *
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13642
diff changeset
531 convertenviron(void)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
532 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
533 PyObject *d;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
534 char **e;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
535 d = PyDict_New();
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
536 if (d == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
537 return NULL;
24469
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
538 #ifdef WITH_NEXT_FRAMEWORK
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
539 if (environ == NULL)
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
540 environ = *_NSGetEnviron();
79f129b073de - Get _environ through the NSEnviron call in a MacOSX framework. This allows
Jack Jansen <jack.jansen@cwi.nl>
parents: 24436
diff changeset
541 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
542 if (environ == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
543 return d;
11172
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
544 /* This part ignores errors */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
545 for (e = environ; *e != NULL; e++) {
11172
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
546 PyObject *k;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
547 PyObject *v;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
548 char *p = strchr(*e, '=');
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
549 if (p == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
550 continue;
11172
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
551 k = PyString_FromStringAndSize(*e, (int)(p-*e));
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
552 if (k == NULL) {
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
553 PyErr_Clear();
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
554 continue;
11172
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
555 }
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
556 #if defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
557 if ((strncmp(at_home, *e, sizeof(at_home)) == 0) ||
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
558 (strncmp(at_path, *e, sizeof(at_path)) == 0)) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
559 (void)shell$from_vms(p+1, psxmod_from_vms_action, 0);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
560 /* 0 = no wildcard expansion */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
561 v = PyString_FromString(psxmod_gt_psxpath);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
562 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
563 else {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
564 v = PyString_FromString(p+1);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
565 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
566 #else
11172
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
567 v = PyString_FromString(p+1);
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
568 #endif
11172
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
569 if (v == NULL) {
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
570 PyErr_Clear();
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
571 Py_DECREF(k);
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
572 continue;
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
573 }
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
574 if (PyDict_GetItem(d, k) == NULL) {
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
575 if (PyDict_SetItem(d, k, v) != 0)
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
576 PyErr_Clear();
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
577 }
8e74ed154f60 It turns out that modifying the environment strings is not safe.
Guido van Rossum <guido@python.org>
parents: 11095
diff changeset
578 Py_DECREF(k);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
579 Py_DECREF(v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
580 }
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
581 #if defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
582 psmmod_add_posix_env(d);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
583 #endif /* defined(__VMS) */
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
584 #if defined(PYOS_OS2)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
585 {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
586 APIRET rc;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
587 char buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
588
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
589 rc = DosQueryExtLIBPATH(buffer, BEGIN_LIBPATH);
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
590 if (rc == NO_ERROR) { /* (not a type, envname is NOT 'BEGIN_LIBPATH') */
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
591 PyObject *v = PyString_FromString(buffer);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
592 PyDict_SetItemString(d, "BEGINLIBPATH", v);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
593 Py_DECREF(v);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
594 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
595 rc = DosQueryExtLIBPATH(buffer, END_LIBPATH);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
596 if (rc == NO_ERROR) { /* (not a typo, envname is NOT 'END_LIBPATH') */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
597 PyObject *v = PyString_FromString(buffer);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
598 PyDict_SetItemString(d, "ENDLIBPATH", v);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
599 Py_DECREF(v);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
600 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
601 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
602 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
603 return d;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
604 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
605
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
606
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 /* Set a POSIX-specific error from errno, and return NULL */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
608
8708
acf49c9def7d Several changes to support inclusion of filename in relevent
Barry Warsaw <barry@python.org>
parents: 8497
diff changeset
609 static PyObject *
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13642
diff changeset
610 posix_error(void)
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
611 {
10133
5718e83020ae Got rid of the file-global PosixError. This was redundant since it
Barry Warsaw <barry@python.org>
parents: 10092
diff changeset
612 return PyErr_SetFromErrno(PyExc_OSError);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
613 }
8708
acf49c9def7d Several changes to support inclusion of filename in relevent
Barry Warsaw <barry@python.org>
parents: 8497
diff changeset
614 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
615 posix_error_with_filename(char* name)
8708
acf49c9def7d Several changes to support inclusion of filename in relevent
Barry Warsaw <barry@python.org>
parents: 8497
diff changeset
616 {
10133
5718e83020ae Got rid of the file-global PosixError. This was redundant since it
Barry Warsaw <barry@python.org>
parents: 10092
diff changeset
617 return PyErr_SetFromErrnoWithFilename(PyExc_OSError, name);
8708
acf49c9def7d Several changes to support inclusion of filename in relevent
Barry Warsaw <barry@python.org>
parents: 8497
diff changeset
618 }
acf49c9def7d Several changes to support inclusion of filename in relevent
Barry Warsaw <barry@python.org>
parents: 8497
diff changeset
619
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
620 #ifdef Py_WIN_WIDE_FILENAMES
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
621 static PyObject *
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
622 posix_error_with_unicode_filename(Py_UNICODE* name)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
623 {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
624 return PyErr_SetFromErrnoWithUnicodeFilename(PyExc_OSError, name);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
625 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
626 #endif /* Py_WIN_WIDE_FILENAMES */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
627
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
628
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
629 static PyObject *
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
630 posix_error_with_allocated_filename(char* name)
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
631 {
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
632 PyObject *rc = PyErr_SetFromErrnoWithFilename(PyExc_OSError, name);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
633 PyMem_Free(name);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
634 return rc;
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
635 }
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
636
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
637 #ifdef MS_WINDOWS
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
638 static PyObject *
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
639 win32_error(char* function, char* filename)
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
640 {
13974
3e6e3d05d00b Fix for bug #110670 - Win32 os.listdir raises confusing errors:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13960
diff changeset
641 /* XXX We should pass the function name along in the future.
3e6e3d05d00b Fix for bug #110670 - Win32 os.listdir raises confusing errors:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13960
diff changeset
642 (_winreg.c also wants to pass the function name.)
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
643 This would however require an additional param to the
13974
3e6e3d05d00b Fix for bug #110670 - Win32 os.listdir raises confusing errors:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13960
diff changeset
644 Windows error object, which is non-trivial.
3e6e3d05d00b Fix for bug #110670 - Win32 os.listdir raises confusing errors:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13960
diff changeset
645 */
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
646 errno = GetLastError();
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
647 if (filename)
13974
3e6e3d05d00b Fix for bug #110670 - Win32 os.listdir raises confusing errors:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13960
diff changeset
648 return PyErr_SetFromWindowsErrWithFilename(errno, filename);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
649 else
13974
3e6e3d05d00b Fix for bug #110670 - Win32 os.listdir raises confusing errors:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13960
diff changeset
650 return PyErr_SetFromWindowsErr(errno);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
651 }
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
652
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
653 #ifdef Py_WIN_WIDE_FILENAMES
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
654 static PyObject *
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
655 win32_error_unicode(char* function, Py_UNICODE* filename)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
656 {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
657 /* XXX - see win32_error for comments on 'function' */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
658 errno = GetLastError();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
659 if (filename)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
660 return PyErr_SetFromWindowsErrWithUnicodeFilename(errno, filename);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
661 else
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
662 return PyErr_SetFromWindowsErr(errno);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
663 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
664
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
665 static PyObject *_PyUnicode_FromFileSystemEncodedObject(register PyObject *obj)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
666 {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
667 /* XXX Perhaps we should make this API an alias of
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
668 PyObject_Unicode() instead ?! */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
669 if (PyUnicode_CheckExact(obj)) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
670 Py_INCREF(obj);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
671 return obj;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
672 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
673 if (PyUnicode_Check(obj)) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
674 /* For a Unicode subtype that's not a Unicode object,
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
675 return a true Unicode object with the same data. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
676 return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(obj),
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
677 PyUnicode_GET_SIZE(obj));
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
678 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
679 return PyUnicode_FromEncodedObject(obj,
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
680 Py_FileSystemDefaultEncoding,
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
681 "strict");
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
682 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
683
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
684 #endif /* Py_WIN_WIDE_FILENAMES */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
685
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
686 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
687
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
688 #if defined(PYOS_OS2)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
689 /**********************************************************************
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
690 * Helper Function to Trim and Format OS/2 Messages
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
691 **********************************************************************/
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
692 static void
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
693 os2_formatmsg(char *msgbuf, int msglen, char *reason)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
694 {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
695 msgbuf[msglen] = '\0'; /* OS/2 Doesn't Guarantee a Terminator */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
696
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
697 if (strlen(msgbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
698 char *lastc = &msgbuf[ strlen(msgbuf)-1 ];
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
699
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
700 while (lastc > msgbuf && isspace(*lastc))
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
701 *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
702 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
703
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
704 /* Add Optional Reason Text */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
705 if (reason) {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
706 strcat(msgbuf, " : ");
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
707 strcat(msgbuf, reason);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
708 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
709 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
710
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
711 /**********************************************************************
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
712 * Decode an OS/2 Operating System Error Code
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
713 *
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
714 * A convenience function to lookup an OS/2 error code and return a
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
715 * text message we can use to raise a Python exception.
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
716 *
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
717 * Notes:
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
718 * The messages for errors returned from the OS/2 kernel reside in
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
719 * the file OSO001.MSG in the \OS2 directory hierarchy.
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
720 *
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
721 **********************************************************************/
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
722 static char *
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
723 os2_strerror(char *msgbuf, int msgbuflen, int errorcode, char *reason)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
724 {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
725 APIRET rc;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
726 ULONG msglen;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
727
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
728 /* Retrieve Kernel-Related Error Message from OSO001.MSG File */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
729 Py_BEGIN_ALLOW_THREADS
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
730 rc = DosGetMessage(NULL, 0, msgbuf, msgbuflen,
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
731 errorcode, "oso001.msg", &msglen);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
732 Py_END_ALLOW_THREADS
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
733
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
734 if (rc == NO_ERROR)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
735 os2_formatmsg(msgbuf, msglen, reason);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
736 else
21075
dc641e1256f9 Repair a botched PyOS_snprintf conversion.
Tim Peters <tim.peters@gmail.com>
parents: 21073
diff changeset
737 PyOS_snprintf(msgbuf, msgbuflen,
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 21066
diff changeset
738 "unknown OS error #%d", errorcode);
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
739
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
740 return msgbuf;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
741 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
742
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
743 /* Set an OS/2-specific error and return NULL. OS/2 kernel
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
744 errors are not in a global variable e.g. 'errno' nor are
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
745 they congruent with posix error numbers. */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
746
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
747 static PyObject * os2_error(int code)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
748 {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
749 char text[1024];
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
750 PyObject *v;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
751
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
752 os2_strerror(text, sizeof(text), code, "");
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
753
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
754 v = Py_BuildValue("(is)", code, text);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
755 if (v != NULL) {
10133
5718e83020ae Got rid of the file-global PosixError. This was redundant since it
Barry Warsaw <barry@python.org>
parents: 10092
diff changeset
756 PyErr_SetObject(PyExc_OSError, v);
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
757 Py_DECREF(v);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
758 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
759 return NULL; /* Signal to Python that an Exception is Pending */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
760 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
761
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
762 #endif /* OS2 */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
763
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
764 /* POSIX generic methods */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
765
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
766 static PyObject *
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
767 posix_fildes(PyObject *fdobj, int (*func)(int))
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
768 {
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
769 int fd;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
770 int res;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
771 fd = PyObject_AsFileDescriptor(fdobj);
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
772 if (fd < 0)
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
773 return NULL;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
774 Py_BEGIN_ALLOW_THREADS
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
775 res = (*func)(fd);
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
776 Py_END_ALLOW_THREADS
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
777 if (res < 0)
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
778 return posix_error();
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
779 Py_INCREF(Py_None);
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
780 return Py_None;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
781 }
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
782
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
783 #ifdef Py_WIN_WIDE_FILENAMES
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
784 static int
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
785 unicode_file_names(void)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
786 {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
787 static int canusewide = -1;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
788 if (canusewide == -1) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
789 /* As per doc for ::GetVersion(), this is the correct test for
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
790 the Windows NT family. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
791 canusewide = (GetVersion() < 0x80000000) ? 1 : 0;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
792 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
793 return canusewide;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
794 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
795 #endif
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
796
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
797 static PyObject *
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
798 posix_1str(PyObject *args, char *format, int (*func)(const char*),
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
799 char *wformat, int (*wfunc)(const Py_UNICODE*))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
800 {
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
801 char *path1 = NULL;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
802 int res;
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
803 #ifdef Py_WIN_WIDE_FILENAMES
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
804 if (unicode_file_names()) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
805 PyUnicodeObject *po;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
806 if (PyArg_ParseTuple(args, wformat, &po)) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
807 Py_BEGIN_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
808 /* PyUnicode_AS_UNICODE OK without thread
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
809 lock as it is a simple dereference. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
810 res = (*wfunc)(PyUnicode_AS_UNICODE(po));
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
811 Py_END_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
812 if (res < 0)
25536
93ef745555d7 Trivial fix to the pep277 checkin: ensure that exceptions always have a filename attribute (previously did only when string filenames were passed, but not when unicode)
Mark Hammond <mhammond@skippinet.com.au>
parents: 25535
diff changeset
813 return posix_error_with_unicode_filename(PyUnicode_AS_UNICODE(po));
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
814 Py_INCREF(Py_None);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
815 return Py_None;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
816 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
817 /* Drop the argument parsing error as narrow
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
818 strings are also valid. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
819 PyErr_Clear();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
820 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
821 #else
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
822 /* Platforms that don't support Unicode filenames
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
823 shouldn't be passing these extra params */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
824 assert(wformat==NULL && wfunc == NULL);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
825 #endif
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
826
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
827 if (!PyArg_ParseTuple(args, format,
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
828 Py_FileSystemDefaultEncoding, &path1))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
829 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
830 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
831 res = (*func)(path1);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
832 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
833 if (res < 0)
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
834 return posix_error_with_allocated_filename(path1);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
835 PyMem_Free(path1);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
836 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
837 return Py_None;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
838 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
839
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
840 static PyObject *
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
841 posix_2str(PyObject *args,
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
842 char *format,
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
843 int (*func)(const char *, const char *),
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
844 char *wformat,
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
845 int (*wfunc)(const Py_UNICODE *, const Py_UNICODE *))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
846 {
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
847 char *path1 = NULL, *path2 = NULL;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
848 int res;
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
849 #ifdef Py_WIN_WIDE_FILENAMES
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
850 if (unicode_file_names()) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
851 PyObject *po1;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
852 PyObject *po2;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
853 if (PyArg_ParseTuple(args, wformat, &po1, &po2)) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
854 if (PyUnicode_Check(po1) || PyUnicode_Check(po2)) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
855 PyObject *wpath1;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
856 PyObject *wpath2;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
857 wpath1 = _PyUnicode_FromFileSystemEncodedObject(po1);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
858 wpath2 = _PyUnicode_FromFileSystemEncodedObject(po2);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
859 if (!wpath1 || !wpath2) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
860 Py_XDECREF(wpath1);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
861 Py_XDECREF(wpath2);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
862 return NULL;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
863 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
864 Py_BEGIN_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
865 /* PyUnicode_AS_UNICODE OK without thread
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
866 lock as it is a simple dereference. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
867 res = (*wfunc)(PyUnicode_AS_UNICODE(wpath1),
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
868 PyUnicode_AS_UNICODE(wpath2));
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
869 Py_END_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
870 Py_XDECREF(wpath1);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
871 Py_XDECREF(wpath2);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
872 if (res != 0)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
873 return posix_error();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
874 Py_INCREF(Py_None);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
875 return Py_None;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
876 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
877 /* Else flow through as neither is Unicode. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
878 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
879 /* Drop the argument parsing error as narrow
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
880 strings are also valid. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
881 PyErr_Clear();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
882 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
883 #else
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
884 /* Platforms that don't support Unicode filenames
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
885 shouldn't be passing these extra params */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
886 assert(wformat==NULL && wfunc == NULL);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
887 #endif
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
888
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
889 if (!PyArg_ParseTuple(args, format,
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
890 Py_FileSystemDefaultEncoding, &path1,
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
891 Py_FileSystemDefaultEncoding, &path2))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
892 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
893 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
894 res = (*func)(path1, path2);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
895 Py_END_ALLOW_THREADS
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
896 PyMem_Free(path1);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
897 PyMem_Free(path2);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
898 if (res != 0)
8708
acf49c9def7d Several changes to support inclusion of filename in relevent
Barry Warsaw <barry@python.org>
parents: 8497
diff changeset
899 /* XXX how to report both path1 and path2??? */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
900 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
901 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
902 return Py_None;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
903 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
904
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
905 PyDoc_STRVAR(stat_result__doc__,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
906 "stat_result: Result from stat or lstat.\n\n\
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
907 This object may be accessed either as a tuple of\n\
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
908 (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)\n\
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
909 or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
910 \n\
20543
a8995a6de8d0 Don't leave bare newlines in long strings -- VC doesn't like that.
Guido van Rossum <guido@python.org>
parents: 20539
diff changeset
911 Posix/windows: If your platform supports st_blksize, st_blocks, or st_rdev,\n\
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
912 they are available as attributes only.\n\
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
913 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
914 See os.stat for more information.");
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
915
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
916 static PyStructSequence_Field stat_result_fields[] = {
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
917 {"st_mode", "protection bits"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
918 {"st_ino", "inode"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
919 {"st_dev", "device"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
920 {"st_nlink", "number of hard links"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
921 {"st_uid", "user ID of owner"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
922 {"st_gid", "group ID of owner"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
923 {"st_size", "total size, in bytes"},
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
924 /* The NULL is replaced with PyStructSequence_UnnamedField later. */
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
925 {NULL, "integer time of last access"},
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
926 {NULL, "integer time of last modification"},
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
927 {NULL, "integer time of last change"},
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
928 {"st_atime", "time of last access"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
929 {"st_mtime", "time of last modification"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
930 {"st_ctime", "time of last change"},
25810
915112671152 Patch #623780: Replace obsolete struct macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
931 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
932 {"st_blksize", "blocksize for filesystem I/O"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
933 #endif
25810
915112671152 Patch #623780: Replace obsolete struct macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
934 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
935 {"st_blocks", "number of blocks allocated"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
936 #endif
25810
915112671152 Patch #623780: Replace obsolete struct macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
937 #ifdef HAVE_STRUCT_STAT_ST_RDEV
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
938 {"st_rdev", "device type (if inode device)"},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
939 #endif
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
940 {0}
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
941 };
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
942
25810
915112671152 Patch #623780: Replace obsolete struct macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
943 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
944 #define ST_BLKSIZE_IDX 13
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
945 #else
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
946 #define ST_BLKSIZE_IDX 12
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
947 #endif
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
948
25810
915112671152 Patch #623780: Replace obsolete struct macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
949 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
950 #define ST_BLOCKS_IDX (ST_BLKSIZE_IDX+1)
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
951 #else
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
952 #define ST_BLOCKS_IDX ST_BLKSIZE_IDX
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
953 #endif
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
954
25810
915112671152 Patch #623780: Replace obsolete struct macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
955 #ifdef HAVE_STRUCT_STAT_ST_RDEV
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
956 #define ST_RDEV_IDX (ST_BLOCKS_IDX+1)
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
957 #else
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
958 #define ST_RDEV_IDX ST_BLOCKS_IDX
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
959 #endif
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
960
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
961 static PyStructSequence_Desc stat_result_desc = {
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
962 "stat_result", /* name */
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
963 stat_result__doc__, /* doc */
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
964 stat_result_fields,
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
965 10
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
966 };
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
967
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
968 PyDoc_STRVAR(statvfs_result__doc__,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
969 "statvfs_result: Result from statvfs or fstatvfs.\n\n\
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
970 This object may be accessed either as a tuple of\n\
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
971 (bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax),\n\
20543
a8995a6de8d0 Don't leave bare newlines in long strings -- VC doesn't like that.
Guido van Rossum <guido@python.org>
parents: 20539
diff changeset
972 or via the attributes f_bsize, f_frsize, f_blocks, f_bfree, and so on.\n\
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
973 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
974 See os.statvfs for more information.");
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
975
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
976 static PyStructSequence_Field statvfs_result_fields[] = {
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
977 {"f_bsize", },
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
978 {"f_frsize", },
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
979 {"f_blocks", },
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
980 {"f_bfree", },
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
981 {"f_bavail", },
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
982 {"f_files", },
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
983 {"f_ffree", },
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
984 {"f_favail", },
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
985 {"f_flag", },
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
986 {"f_namemax",},
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
987 {0}
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
988 };
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
989
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
990 static PyStructSequence_Desc statvfs_result_desc = {
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
991 "statvfs_result", /* name */
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
992 statvfs_result__doc__, /* doc */
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
993 statvfs_result_fields,
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
994 10
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
995 };
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
996
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
997 static PyTypeObject StatResultType;
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
998 static PyTypeObject StatVFSResultType;
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
999 static newfunc structseq_new;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1000
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1001 static PyObject *
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1002 statresult_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1003 {
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1004 PyStructSequence *result;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1005 int i;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1006
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1007 result = (PyStructSequence*)structseq_new(type, args, kwds);
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1008 if (!result)
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1009 return NULL;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1010 /* If we have been initialized from a tuple,
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1011 st_?time might be set to None. Initialize it
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1012 from the int slots. */
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1013 for (i = 7; i <= 9; i++) {
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1014 if (result->ob_item[i+3] == Py_None) {
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1015 Py_DECREF(Py_None);
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1016 Py_INCREF(result->ob_item[i]);
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1017 result->ob_item[i+3] = result->ob_item[i];
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1018 }
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1019 }
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1020 return (PyObject*)result;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1021 }
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1022
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1023
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1024
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1025 /* If true, st_?time is float. */
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1026 static int _stat_float_times = 0;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1027
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1028 PyDoc_STRVAR(stat_float_times__doc__,
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1029 "stat_float_times([newval]) -> oldval\n\n\
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1030 Determine whether os.[lf]stat represents time stamps as float objects.\n\
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1031 If newval is True, future calls to stat() return floats, if it is False,\n\
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1032 future calls return ints. \n\
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1033 If newval is omitted, return the current setting.\n");
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1034
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1035 static PyObject*
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1036 stat_float_times(PyObject* self, PyObject *args)
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1037 {
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1038 int newval = -1;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1039 if (!PyArg_ParseTuple(args, "|i:stat_float_times", &newval))
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1040 return NULL;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1041 if (newval == -1)
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1042 /* Return old value */
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1043 return PyBool_FromLong(_stat_float_times);
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1044 _stat_float_times = newval;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1045 Py_INCREF(Py_None);
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1046 return Py_None;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1047 }
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1048
25176
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1049 static void
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1050 fill_time(PyObject *v, int index, time_t sec, unsigned long nsec)
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1051 {
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1052 PyObject *fval,*ival;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1053 #if SIZEOF_TIME_T > SIZEOF_LONG
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1054 ival = PyLong_FromLongLong((LONG_LONG)sec);
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1055 #else
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1056 ival = PyInt_FromLong((long)sec);
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1057 #endif
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1058 if (_stat_float_times) {
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1059 fval = PyFloat_FromDouble(sec + 1e-9*nsec);
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1060 } else {
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1061 fval = ival;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1062 Py_INCREF(fval);
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1063 }
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1064 PyStructSequence_SET_ITEM(v, index, ival);
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
1065 PyStructSequence_SET_ITEM(v, index+3, fval);
25176
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1066 }
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1067
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1068 /* pack a system stat C structure into the Python stat tuple
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1069 (used by posix_stat() and posix_fstat()) */
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1070 static PyObject*
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1071 _pystat_fromstructstat(STRUCT_STAT st)
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1072 {
25176
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1073 unsigned long ansec, mnsec, cnsec;
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1074 PyObject *v = PyStructSequence_New(&StatResultType);
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1075 if (v == NULL)
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1076 return NULL;
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1077
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1078 PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long)st.st_mode));
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1079 #ifdef HAVE_LARGEFILE_SUPPORT
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1080 PyStructSequence_SET_ITEM(v, 1,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1081 PyLong_FromLongLong((LONG_LONG)st.st_ino));
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1082 #else
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1083 PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long)st.st_ino));
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1084 #endif
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1085 #if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS)
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1086 PyStructSequence_SET_ITEM(v, 2,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1087 PyLong_FromLongLong((LONG_LONG)st.st_dev));
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1088 #else
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1089 PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long)st.st_dev));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1090 #endif
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1091 PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long)st.st_nlink));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1092 PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long)st.st_uid));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1093 PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long)st.st_gid));
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1094 #ifdef HAVE_LARGEFILE_SUPPORT
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1095 PyStructSequence_SET_ITEM(v, 6,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1096 PyLong_FromLongLong((LONG_LONG)st.st_size));
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1097 #else
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1098 PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong(st.st_size));
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1099 #endif
25176
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1100
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1101 #ifdef HAVE_STAT_TV_NSEC
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1102 ansec = st.st_atim.tv_nsec;
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1103 mnsec = st.st_mtim.tv_nsec;
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1104 cnsec = st.st_ctim.tv_nsec;
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1105 #else
25176
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1106 ansec = mnsec = cnsec = 0;
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1107 #endif
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1108 fill_time(v, 7, st.st_atime, ansec);
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1109 fill_time(v, 8, st.st_mtime, mnsec);
038711ae13e0 Patch #606592: Subsecond timestamps in stat_result.
Martin v. Löwis <martin@v.loewis.de>
parents: 25087
diff changeset
1110 fill_time(v, 9, st.st_ctime, cnsec);
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1111
25810
915112671152 Patch #623780: Replace obsolete struct macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
1112 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1113 PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1114 PyInt_FromLong((long)st.st_blksize));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1115 #endif
25810
915112671152 Patch #623780: Replace obsolete struct macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
1116 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1117 PyStructSequence_SET_ITEM(v, ST_BLOCKS_IDX,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1118 PyInt_FromLong((long)st.st_blocks));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1119 #endif
25810
915112671152 Patch #623780: Replace obsolete struct macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
1120 #ifdef HAVE_STRUCT_STAT_ST_RDEV
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1121 PyStructSequence_SET_ITEM(v, ST_RDEV_IDX,
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
1122 PyInt_FromLong((long)st.st_rdev));
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1123 #endif
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1124
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1125 if (PyErr_Occurred()) {
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1126 Py_DECREF(v);
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1127 return NULL;
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1128 }
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1129
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1130 return v;
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1131 }
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1132
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1133 static PyObject *
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1134 posix_do_stat(PyObject *self, PyObject *args,
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1135 char *format,
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1136 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1137 int (*statfunc)(const char *, STRUCT_STAT *, ...),
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1138 #else
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1139 int (*statfunc)(const char *, STRUCT_STAT *),
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1140 #endif
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1141 char *wformat,
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1142 int (*wstatfunc)(const Py_UNICODE *, STRUCT_STAT *))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1143 {
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1144 STRUCT_STAT st;
21489
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1145 char *path = NULL; /* pass this to stat; do not free() it */
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1146 char *pathfree = NULL; /* this memory must be free'd */
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
1147 int res;
12435
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1148
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
1149 #ifdef MS_WINDOWS
21489
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1150 int pathlen;
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1151 char pathcopy[MAX_PATH];
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
1152 #endif /* MS_WINDOWS */
12435
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1153
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1154
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1155 #ifdef Py_WIN_WIDE_FILENAMES
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1156 /* If on wide-character-capable OS see if argument
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1157 is Unicode and if so use wide API. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1158 if (unicode_file_names()) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1159 PyUnicodeObject *po;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1160 if (PyArg_ParseTuple(args, wformat, &po)) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1161 Py_UNICODE wpath[MAX_PATH+1];
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1162 pathlen = wcslen(PyUnicode_AS_UNICODE(po));
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1163 /* the library call can blow up if the file name is too long! */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1164 if (pathlen > MAX_PATH) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1165 errno = ENAMETOOLONG;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1166 return posix_error();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1167 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1168 wcscpy(wpath, PyUnicode_AS_UNICODE(po));
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1169 /* Remove trailing slash or backslash, unless it's the current
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1170 drive root (/ or \) or a specific drive's root (like c:\ or c:/).
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1171 */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1172 if (pathlen > 0 &&
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1173 (wpath[pathlen-1]== L'\\' || wpath[pathlen-1] == L'/')) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1174 /* It does end with a slash -- exempt the root drive cases. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1175 /* XXX UNC root drives should also be exempted? */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1176 if (pathlen == 1 || (pathlen == 3 && wpath[1] == L':'))
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1177 /* leave it alone */;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1178 else {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1179 /* nuke the trailing backslash */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1180 wpath[pathlen-1] = L'\0';
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1181 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1182 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1183 Py_BEGIN_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1184 /* PyUnicode_AS_UNICODE result OK without
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1185 thread lock as it is a simple dereference. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1186 res = wstatfunc(wpath, &st);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1187 Py_END_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1188 if (res != 0)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1189 return posix_error_with_unicode_filename(wpath);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1190 return _pystat_fromstructstat(st);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1191 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1192 /* Drop the argument parsing error as narrow strings
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1193 are also valid. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1194 PyErr_Clear();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1195 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1196 #endif
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1197
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1198 if (!PyArg_ParseTuple(args, format,
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1199 Py_FileSystemDefaultEncoding, &path))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1200 return NULL;
21489
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1201 pathfree = path;
12435
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1202
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
1203 #ifdef MS_WINDOWS
12435
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1204 pathlen = strlen(path);
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1205 /* the library call can blow up if the file name is too long! */
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1206 if (pathlen > MAX_PATH) {
21489
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1207 PyMem_Free(pathfree);
12435
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1208 errno = ENAMETOOLONG;
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1209 return posix_error();
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1210 }
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1211
21489
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1212 /* Remove trailing slash or backslash, unless it's the current
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1213 drive root (/ or \) or a specific drive's root (like c:\ or c:/).
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1214 */
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1215 if (pathlen > 0 &&
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1216 (path[pathlen-1]== '\\' || path[pathlen-1] == '/')) {
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1217 /* It does end with a slash -- exempt the root drive cases. */
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1218 /* XXX UNC root drives should also be exempted? */
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1219 if (pathlen == 1 || (pathlen == 3 && path[1] == ':'))
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1220 /* leave it alone */;
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1221 else {
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1222 /* nuke the trailing backslash */
12435
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1223 strncpy(pathcopy, path, pathlen);
21489
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1224 pathcopy[pathlen-1] = '\0';
12435
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1225 path = pathcopy;
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1226 }
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1227 }
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
1228 #endif /* MS_WINDOWS */
12435
ca7b99d27a40 Patch by Brian Hooper, somewhat augmented by GvR, to strip a trailing
Guido van Rossum <guido@python.org>
parents: 12393
diff changeset
1229
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1230 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
1231 res = (*statfunc)(path, &st);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1232 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
1233 if (res != 0)
21489
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1234 return posix_error_with_allocated_filename(pathfree);
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1235
1d1c46824fc3 SF bug #495021: Crash calling os.stat with a trailing backslash
Tim Peters <tim.peters@gmail.com>
parents: 21313
diff changeset
1236 PyMem_Free(pathfree);
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
1237 return _pystat_fromstructstat(st);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1238 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1239
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1240
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1241 /* POSIX methods */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1242
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1243 PyDoc_STRVAR(posix_access__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1244 "access(path, mode) -> 1 if granted, 0 otherwise\n\n\
23900
0899409a0cb6 Corect speling and add \n\ to line ends in new docstring for access().
Guido van Rossum <guido@python.org>
parents: 23897
diff changeset
1245 Use the real uid/gid to test for access to a path. Note that most\n\
0899409a0cb6 Corect speling and add \n\ to line ends in new docstring for access().
Guido van Rossum <guido@python.org>
parents: 23897
diff changeset
1246 operations will use the effective uid/gid, therefore this routine can\n\
0899409a0cb6 Corect speling and add \n\ to line ends in new docstring for access().
Guido van Rossum <guido@python.org>
parents: 23897
diff changeset
1247 be used in a suid/sgid environment to test if the invoking user has the\n\
0899409a0cb6 Corect speling and add \n\ to line ends in new docstring for access().
Guido van Rossum <guido@python.org>
parents: 23897
diff changeset
1248 specified access to the path. The mode argument can be F_OK to test\n\
0899409a0cb6 Corect speling and add \n\ to line ends in new docstring for access().
Guido van Rossum <guido@python.org>
parents: 23897
diff changeset
1249 existence, or the inclusive-OR of R_OK, W_OK, and X_OK.");
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1250
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1251 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1252 posix_access(PyObject *self, PyObject *args)
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1253 {
9795
836f9408c956 Change the access() code to return 1 if granted, 0 if not granted.
Guido van Rossum <guido@python.org>
parents: 9785
diff changeset
1254 char *path;
836f9408c956 Change the access() code to return 1 if granted, 0 if not granted.
Guido van Rossum <guido@python.org>
parents: 9785
diff changeset
1255 int mode;
836f9408c956 Change the access() code to return 1 if granted, 0 if not granted.
Guido van Rossum <guido@python.org>
parents: 9785
diff changeset
1256 int res;
836f9408c956 Change the access() code to return 1 if granted, 0 if not granted.
Guido van Rossum <guido@python.org>
parents: 9785
diff changeset
1257
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1258 if (!PyArg_ParseTuple(args, "si:access", &path, &mode))
9795
836f9408c956 Change the access() code to return 1 if granted, 0 if not granted.
Guido van Rossum <guido@python.org>
parents: 9785
diff changeset
1259 return NULL;
836f9408c956 Change the access() code to return 1 if granted, 0 if not granted.
Guido van Rossum <guido@python.org>
parents: 9785
diff changeset
1260 Py_BEGIN_ALLOW_THREADS
836f9408c956 Change the access() code to return 1 if granted, 0 if not granted.
Guido van Rossum <guido@python.org>
parents: 9785
diff changeset
1261 res = access(path, mode);
836f9408c956 Change the access() code to return 1 if granted, 0 if not granted.
Guido van Rossum <guido@python.org>
parents: 9785
diff changeset
1262 Py_END_ALLOW_THREADS
25087
9a178adb4e2d SF bug 601775 - some int results that should be bool.
Guido van Rossum <guido@python.org>
parents: 24884
diff changeset
1263 return(PyBool_FromLong(res == 0));
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1264 }
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1265
9939
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1266 #ifndef F_OK
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1267 #define F_OK 0
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1268 #endif
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1269 #ifndef R_OK
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1270 #define R_OK 4
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1271 #endif
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1272 #ifndef W_OK
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1273 #define W_OK 2
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1274 #endif
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1275 #ifndef X_OK
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1276 #define X_OK 1
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1277 #endif
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1278
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1279 #ifdef HAVE_TTYNAME
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1280 PyDoc_STRVAR(posix_ttyname__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1281 "ttyname(fd) -> string\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1282 Return the name of the terminal device connected to 'fd'.");
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1283
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1284 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1285 posix_ttyname(PyObject *self, PyObject *args)
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1286 {
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1287 int id;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1288 char *ret;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1289
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1290 if (!PyArg_ParseTuple(args, "i:ttyname", &id))
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1291 return NULL;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1292
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1293 #if defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1294 /* DECC V5.0 - only about FD= 0 @@ try getname()+$getdvi(dvi$_devnam) */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1295 if (id == 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1296 ret = ttyname();
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1297 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1298 else {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1299 ret = NULL;
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1300 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1301 #else
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1302 ret = ttyname(id);
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1303 #endif
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1304 if (ret == NULL)
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1305 return(posix_error());
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1306 return(PyString_FromString(ret));
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1307 }
9939
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
1308 #endif
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
1309
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1310 #ifdef HAVE_CTERMID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1311 PyDoc_STRVAR(posix_ctermid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1312 "ctermid() -> string\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1313 Return the name of the controlling terminal for this process.");
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1314
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1315 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
1316 posix_ctermid(PyObject *self, PyObject *noargs)
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1317 {
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1318 char *ret;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1319 char buffer[L_ctermid];
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1320
11893
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
1321 #ifdef USE_CTERMID_R
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1322 ret = ctermid_r(buffer);
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1323 #else
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1324 ret = ctermid(buffer);
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1325 #endif
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1326 if (ret == NULL)
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1327 return(posix_error());
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1328 return(PyString_FromString(buffer));
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1329 }
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1330 #endif
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1331
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1332 PyDoc_STRVAR(posix_chdir__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1333 "chdir(path)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1334 Change the current working directory to the specified path.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1335
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1336 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1337 posix_chdir(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1338 {
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1339 #ifdef MS_WINDOWS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1340 return posix_1str(args, "et:chdir", chdir, "U:chdir", _wchdir);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1341 #elif defined(PYOS_OS2) && defined(PYCC_GCC)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1342 return posix_1str(args, "et:chdir", _chdir2, NULL, NULL);
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1343 #else
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1344 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1345 return posix_1str(args, "et:chdir", (int (*)(const char *))chdir,
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1346 NULL, NULL);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1347 #else
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1348 return posix_1str(args, "et:chdir", chdir, NULL, NULL);
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1349 #endif
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1350 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1351 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1352
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1353 #ifdef HAVE_FCHDIR
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1354 PyDoc_STRVAR(posix_fchdir__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1355 "fchdir(fildes)\n\n\
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1356 Change to the directory of the given file descriptor. fildes must be\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1357 opened on a directory, not a file.");
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1358
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1359 static PyObject *
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1360 posix_fchdir(PyObject *self, PyObject *fdobj)
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1361 {
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1362 return posix_fildes(fdobj, fchdir);
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1363 }
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1364 #endif /* HAVE_FCHDIR */
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1365
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1366
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1367 PyDoc_STRVAR(posix_chmod__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1368 "chmod(path, mode)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1369 Change the access permissions of a file.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1370
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1371 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1372 posix_chmod(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1373 {
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1374 char *path = NULL;
12139
338e055b7cc0 Two robustness patches:
Guido van Rossum <guido@python.org>
parents: 11893
diff changeset
1375 int i;
338e055b7cc0 Two robustness patches:
Guido van Rossum <guido@python.org>
parents: 11893
diff changeset
1376 int res;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1377 if (!PyArg_ParseTuple(args, "eti", Py_FileSystemDefaultEncoding,
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1378 &path, &i))
12139
338e055b7cc0 Two robustness patches:
Guido van Rossum <guido@python.org>
parents: 11893
diff changeset
1379 return NULL;
338e055b7cc0 Two robustness patches:
Guido van Rossum <guido@python.org>
parents: 11893
diff changeset
1380 Py_BEGIN_ALLOW_THREADS
12150
81e5f8000094 Sigh. On Windows, (mode_t)i fails. Assume that there's a prototype
Guido van Rossum <guido@python.org>
parents: 12140
diff changeset
1381 res = chmod(path, i);
12139
338e055b7cc0 Two robustness patches:
Guido van Rossum <guido@python.org>
parents: 11893
diff changeset
1382 Py_END_ALLOW_THREADS
338e055b7cc0 Two robustness patches:
Guido van Rossum <guido@python.org>
parents: 11893
diff changeset
1383 if (res < 0)
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1384 return posix_error_with_allocated_filename(path);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1385 PyMem_Free(path);
12139
338e055b7cc0 Two robustness patches:
Guido van Rossum <guido@python.org>
parents: 11893
diff changeset
1386 Py_INCREF(Py_None);
338e055b7cc0 Two robustness patches:
Guido van Rossum <guido@python.org>
parents: 11893
diff changeset
1387 return Py_None;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1388 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1389
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1390
20264
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
1391 #ifdef HAVE_CHROOT
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1392 PyDoc_STRVAR(posix_chroot__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1393 "chroot(path)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1394 Change root directory to path.");
20264
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
1395
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
1396 static PyObject *
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
1397 posix_chroot(PyObject *self, PyObject *args)
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
1398 {
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1399 return posix_1str(args, "et:chroot", chroot, NULL, NULL);
20264
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
1400 }
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
1401 #endif
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
1402
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1403 #ifdef HAVE_FSYNC
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1404 PyDoc_STRVAR(posix_fsync__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1405 "fsync(fildes)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1406 force write of file with filedescriptor to disk.");
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1407
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1408 static PyObject *
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1409 posix_fsync(PyObject *self, PyObject *fdobj)
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1410 {
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1411 return posix_fildes(fdobj, fsync);
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1412 }
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1413 #endif /* HAVE_FSYNC */
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1414
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1415 #ifdef HAVE_FDATASYNC
14762
5f638a299888 Hopefully fix the problem with undeclared fdatasync() on HP-UX that
Guido van Rossum <guido@python.org>
parents: 14752
diff changeset
1416
14767
60ce37f066d8 It's better to test for __hpux rather than __hppa, and hpux or hppa is
Guido van Rossum <guido@python.org>
parents: 14762
diff changeset
1417 #ifdef __hpux
14762
5f638a299888 Hopefully fix the problem with undeclared fdatasync() on HP-UX that
Guido van Rossum <guido@python.org>
parents: 14752
diff changeset
1418 extern int fdatasync(int); /* On HP-UX, in libc but not in unistd.h */
5f638a299888 Hopefully fix the problem with undeclared fdatasync() on HP-UX that
Guido van Rossum <guido@python.org>
parents: 14752
diff changeset
1419 #endif
5f638a299888 Hopefully fix the problem with undeclared fdatasync() on HP-UX that
Guido van Rossum <guido@python.org>
parents: 14752
diff changeset
1420
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1421 PyDoc_STRVAR(posix_fdatasync__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1422 "fdatasync(fildes)\n\n\
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1423 force write of file with filedescriptor to disk.\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1424 does not force update of metadata.");
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1425
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1426 static PyObject *
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1427 posix_fdatasync(PyObject *self, PyObject *fdobj)
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1428 {
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
1429 return posix_fildes(fdobj, fdatasync);
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1430 }
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1431 #endif /* HAVE_FDATASYNC */
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1432
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
1433
13513
6057f44b0b7a - stupid typo.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13511
diff changeset
1434 #ifdef HAVE_CHOWN
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1435 PyDoc_STRVAR(posix_chown__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1436 "chown(path, uid, gid)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1437 Change the owner and group id of path to the numeric uid and gid.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1438
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1439 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1440 posix_chown(PyObject *self, PyObject *args)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1441 {
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1442 char *path = NULL;
13511
18395ca5c30e -- get rid of a compiler warning on unix. (as reported
Fredrik Lundh <fredrik@pythonware.com>
parents: 13486
diff changeset
1443 int uid, gid;
18395ca5c30e -- get rid of a compiler warning on unix. (as reported
Fredrik Lundh <fredrik@pythonware.com>
parents: 13486
diff changeset
1444 int res;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1445 if (!PyArg_ParseTuple(args, "etii:chown",
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1446 Py_FileSystemDefaultEncoding, &path,
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1447 &uid, &gid))
13511
18395ca5c30e -- get rid of a compiler warning on unix. (as reported
Fredrik Lundh <fredrik@pythonware.com>
parents: 13486
diff changeset
1448 return NULL;
18395ca5c30e -- get rid of a compiler warning on unix. (as reported
Fredrik Lundh <fredrik@pythonware.com>
parents: 13486
diff changeset
1449 Py_BEGIN_ALLOW_THREADS
18395ca5c30e -- get rid of a compiler warning on unix. (as reported
Fredrik Lundh <fredrik@pythonware.com>
parents: 13486
diff changeset
1450 res = chown(path, (uid_t) uid, (gid_t) gid);
18395ca5c30e -- get rid of a compiler warning on unix. (as reported
Fredrik Lundh <fredrik@pythonware.com>
parents: 13486
diff changeset
1451 Py_END_ALLOW_THREADS
18395ca5c30e -- get rid of a compiler warning on unix. (as reported
Fredrik Lundh <fredrik@pythonware.com>
parents: 13486
diff changeset
1452 if (res < 0)
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1453 return posix_error_with_allocated_filename(path);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1454 PyMem_Free(path);
13511
18395ca5c30e -- get rid of a compiler warning on unix. (as reported
Fredrik Lundh <fredrik@pythonware.com>
parents: 13486
diff changeset
1455 Py_INCREF(Py_None);
18395ca5c30e -- get rid of a compiler warning on unix. (as reported
Fredrik Lundh <fredrik@pythonware.com>
parents: 13486
diff changeset
1456 return Py_None;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1457 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
1458 #endif /* HAVE_CHOWN */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1459
24413
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1460 #ifdef HAVE_LCHOWN
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1461 PyDoc_STRVAR(posix_lchown__doc__,
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1462 "lchown(path, uid, gid)\n\n\
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1463 Change the owner and group id of path to the numeric uid and gid.\n\
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1464 This function will not follow symbolic links.");
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1465
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1466 static PyObject *
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1467 posix_lchown(PyObject *self, PyObject *args)
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1468 {
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1469 char *path = NULL;
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1470 int uid, gid;
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1471 int res;
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1472 if (!PyArg_ParseTuple(args, "etii:lchown",
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1473 Py_FileSystemDefaultEncoding, &path,
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1474 &uid, &gid))
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1475 return NULL;
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1476 Py_BEGIN_ALLOW_THREADS
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1477 res = lchown(path, (uid_t) uid, (gid_t) gid);
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1478 Py_END_ALLOW_THREADS
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
1479 if (res < 0)
24413
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1480 return posix_error_with_allocated_filename(path);
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1481 PyMem_Free(path);
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1482 Py_INCREF(Py_None);
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1483 return Py_None;
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1484 }
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1485 #endif /* HAVE_LCHOWN */
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
1486
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1487
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
1488 #ifdef HAVE_GETCWD
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1489 PyDoc_STRVAR(posix_getcwd__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1490 "getcwd() -> path\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1491 Return a string representing the current working directory.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1492
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1493 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
1494 posix_getcwd(PyObject *self, PyObject *noargs)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1495 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1496 char buf[1026];
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
1497 char *res;
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
1498
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1499 Py_BEGIN_ALLOW_THREADS
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1500 #if defined(PYOS_OS2) && defined(PYCC_GCC)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1501 res = _getcwd2(buf, sizeof buf);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1502 #else
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1503 #if defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1504 /* 0 = force Unix-style path if in the VMS DCL environment! */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1505 res = getcwd(buf, sizeof buf, 0);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1506 #else
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
1507 res = getcwd(buf, sizeof buf);
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1508 #endif
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
1509 #endif
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1510 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
1511 if (res == NULL)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1512 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1513 return PyString_FromString(buf);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1514 }
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1515
26320
d41c4b95e714 Comment out the getcwdu implementation for --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents: 26092
diff changeset
1516 #ifdef Py_USING_UNICODE
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1517 PyDoc_STRVAR(posix_getcwdu__doc__,
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1518 "getcwdu() -> path\n\n\
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1519 Return a unicode string representing the current working directory.");
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1520
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1521 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
1522 posix_getcwdu(PyObject *self, PyObject *noargs)
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1523 {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1524 char buf[1026];
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1525 char *res;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1526
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1527 #ifdef Py_WIN_WIDE_FILENAMES
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1528 if (unicode_file_names()) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1529 wchar_t *wres;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1530 wchar_t wbuf[1026];
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1531 Py_BEGIN_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1532 wres = _wgetcwd(wbuf, sizeof wbuf/ sizeof wbuf[0]);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1533 Py_END_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1534 if (wres == NULL)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1535 return posix_error();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1536 return PyUnicode_FromWideChar(wbuf, wcslen(wbuf));
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1537 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1538 #endif
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1539
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1540 Py_BEGIN_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1541 #if defined(PYOS_OS2) && defined(PYCC_GCC)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1542 res = _getcwd2(buf, sizeof buf);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1543 #else
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1544 res = getcwd(buf, sizeof buf);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1545 #endif
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1546 Py_END_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1547 if (res == NULL)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1548 return posix_error();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1549 return PyUnicode_Decode(buf, strlen(buf), Py_FileSystemDefaultEncoding,"strict");
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1550 }
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
1551 #endif
26320
d41c4b95e714 Comment out the getcwdu implementation for --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents: 26092
diff changeset
1552 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1553
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1554
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1555 #ifdef HAVE_LINK
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1556 PyDoc_STRVAR(posix_link__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1557 "link(src, dst)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1558 Create a hard link to a file.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1559
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1560 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1561 posix_link(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1562 {
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1563 return posix_2str(args, "etet:link", link, NULL, NULL);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1564 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
1565 #endif /* HAVE_LINK */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1566
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1567
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1568 PyDoc_STRVAR(posix_listdir__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1569 "listdir(path) -> list_of_strings\n\n\
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1570 Return a list containing the names of the entries in the directory.\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1571 \n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1572 path: path of directory to list\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1573 \n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1574 The list is in arbitrary order. It does not include the special\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1575 entries '.' and '..' even if they are present in the directory.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1576
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1577 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1578 posix_listdir(PyObject *self, PyObject *args)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1579 {
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1580 /* XXX Should redo this putting the (now four) versions of opendir
6027
494e550cb18d Added a bunch of XXX comments about things I'd like to see changed...
Guido van Rossum <guido@python.org>
parents: 5967
diff changeset
1581 in separate files instead of having them all here... */
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
1582 #if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR)
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
1583
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1584 PyObject *d, *v;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1585 HANDLE hFindFile;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1586 WIN32_FIND_DATA FileData;
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1587 /* MAX_PATH characters could mean a bigger encoded string */
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1588 char namebuf[MAX_PATH*2+5];
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1589 char *bufptr = namebuf;
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1590 int len = sizeof(namebuf)/sizeof(namebuf[0]);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1591
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1592 #ifdef Py_WIN_WIDE_FILENAMES
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1593 /* If on wide-character-capable OS see if argument
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1594 is Unicode and if so use wide API. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1595 if (unicode_file_names()) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1596 PyUnicodeObject *po;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1597 if (PyArg_ParseTuple(args, "U:listdir", &po)) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1598 WIN32_FIND_DATAW wFileData;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1599 Py_UNICODE wnamebuf[MAX_PATH*2+5];
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1600 Py_UNICODE wch;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1601 wcsncpy(wnamebuf, PyUnicode_AS_UNICODE(po), MAX_PATH);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1602 wnamebuf[MAX_PATH] = L'\0';
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1603 len = wcslen(wnamebuf);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1604 wch = (len > 0) ? wnamebuf[len-1] : L'\0';
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1605 if (wch != L'/' && wch != L'\\' && wch != L':')
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1606 wnamebuf[len++] = L'/';
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1607 wcscpy(wnamebuf + len, L"*.*");
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1608 if ((d = PyList_New(0)) == NULL)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1609 return NULL;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1610 hFindFile = FindFirstFileW(wnamebuf, &wFileData);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1611 if (hFindFile == INVALID_HANDLE_VALUE) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1612 errno = GetLastError();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1613 if (errno == ERROR_FILE_NOT_FOUND) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1614 return d;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1615 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1616 Py_DECREF(d);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1617 return win32_error_unicode("FindFirstFileW", wnamebuf);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1618 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1619 do {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1620 if (wFileData.cFileName[0] == L'.' &&
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1621 (wFileData.cFileName[1] == L'\0' ||
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1622 wFileData.cFileName[1] == L'.' &&
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1623 wFileData.cFileName[2] == L'\0'))
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1624 continue;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1625 v = PyUnicode_FromUnicode(wFileData.cFileName, wcslen(wFileData.cFileName));
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1626 if (v == NULL) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1627 Py_DECREF(d);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1628 d = NULL;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1629 break;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1630 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1631 if (PyList_Append(d, v) != 0) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1632 Py_DECREF(v);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1633 Py_DECREF(d);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1634 d = NULL;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1635 break;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1636 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1637 Py_DECREF(v);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1638 } while (FindNextFileW(hFindFile, &wFileData) == TRUE);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1639
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1640 if (FindClose(hFindFile) == FALSE) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1641 Py_DECREF(d);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1642 return win32_error_unicode("FindClose", wnamebuf);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1643 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1644 return d;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1645 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1646 /* Drop the argument parsing error as narrow strings
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1647 are also valid. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1648 PyErr_Clear();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1649 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1650 #endif
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1651
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1652 if (!PyArg_ParseTuple(args, "et#:listdir",
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1653 Py_FileSystemDefaultEncoding, &bufptr, &len))
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1654 return NULL;
22462
85bd534cbd19 Handle os.listdir("") case correctly on Windows. Closes bug 500705.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22256
diff changeset
1655 if (len > 0) {
85bd534cbd19 Handle os.listdir("") case correctly on Windows. Closes bug 500705.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22256
diff changeset
1656 char ch = namebuf[len-1];
85bd534cbd19 Handle os.listdir("") case correctly on Windows. Closes bug 500705.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22256
diff changeset
1657 if (ch != SEP && ch != ALTSEP && ch != ':')
85bd534cbd19 Handle os.listdir("") case correctly on Windows. Closes bug 500705.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22256
diff changeset
1658 namebuf[len++] = '/';
85bd534cbd19 Handle os.listdir("") case correctly on Windows. Closes bug 500705.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22256
diff changeset
1659 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1660 strcpy(namebuf + len, "*.*");
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1661
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1662 if ((d = PyList_New(0)) == NULL)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1663 return NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1664
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1665 hFindFile = FindFirstFile(namebuf, &FileData);
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1666 if (hFindFile == INVALID_HANDLE_VALUE) {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1667 errno = GetLastError();
8839
c2f9e505f75a In Win32 version of listdir(), when FindFirstFile() returns
Guido van Rossum <guido@python.org>
parents: 8823
diff changeset
1668 if (errno == ERROR_FILE_NOT_FOUND)
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1669 return d;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1670 Py_DECREF(d);
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1671 return win32_error("FindFirstFile", namebuf);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1672 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1673 do {
2845
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
1674 if (FileData.cFileName[0] == '.' &&
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
1675 (FileData.cFileName[1] == '\0' ||
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
1676 FileData.cFileName[1] == '.' &&
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
1677 FileData.cFileName[2] == '\0'))
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
1678 continue;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1679 v = PyString_FromString(FileData.cFileName);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1680 if (v == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1681 Py_DECREF(d);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1682 d = NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1683 break;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1684 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1685 if (PyList_Append(d, v) != 0) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1686 Py_DECREF(v);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1687 Py_DECREF(d);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1688 d = NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1689 break;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1690 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1691 Py_DECREF(v);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1692 } while (FindNextFile(hFindFile, &FileData) == TRUE);
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1693
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1694 if (FindClose(hFindFile) == FALSE) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1695 Py_DECREF(d);
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1696 return win32_error("FindClose", namebuf);
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1697 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1698
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1699 return d;
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
1700
14586
cd1b9d8d045d Closes SF bug 113894: on Windows, things like os.listdir("k:") and
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
1701 #elif defined(PYOS_OS2)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1702
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1703 #ifndef MAX_PATH
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1704 #define MAX_PATH CCHMAXPATH
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1705 #endif
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1706 char *name, *pt;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1707 int len;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1708 PyObject *d, *v;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1709 char namebuf[MAX_PATH+5];
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1710 HDIR hdir = 1;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1711 ULONG srchcnt = 1;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1712 FILEFINDBUF3 ep;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1713 APIRET rc;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1714
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1715 if (!PyArg_ParseTuple(args, "t#:listdir", &name, &len))
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1716 return NULL;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1717 if (len >= MAX_PATH) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1718 PyErr_SetString(PyExc_ValueError, "path too long");
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1719 return NULL;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1720 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1721 strcpy(namebuf, name);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1722 for (pt = namebuf; *pt; pt++)
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1723 if (*pt == ALTSEP)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1724 *pt = SEP;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1725 if (namebuf[len-1] != SEP)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1726 namebuf[len++] = SEP;
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1727 strcpy(namebuf + len, "*.*");
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1728
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1729 if ((d = PyList_New(0)) == NULL)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1730 return NULL;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1731
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1732 rc = DosFindFirst(namebuf, /* Wildcard Pattern to Match */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1733 &hdir, /* Handle to Use While Search Directory */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1734 FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY,
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1735 &ep, sizeof(ep), /* Structure to Receive Directory Entry */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1736 &srchcnt, /* Max and Actual Count of Entries Per Iteration */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1737 FIL_STANDARD); /* Format of Entry (EAs or Not) */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1738
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1739 if (rc != NO_ERROR) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1740 errno = ENOENT;
10887
af07389c8517 posix_listdir(): When an error occurs, call
Barry Warsaw <barry@python.org>
parents: 10526
diff changeset
1741 return posix_error_with_filename(name);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1742 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1743
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1744 if (srchcnt > 0) { /* If Directory is NOT Totally Empty, */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1745 do {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1746 if (ep.achName[0] == '.'
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
1747 && (ep.achName[1] == '\0' || (ep.achName[1] == '.' && ep.achName[2] == '\0')))
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1748 continue; /* Skip Over "." and ".." Names */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1749
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1750 strcpy(namebuf, ep.achName);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1751
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1752 /* Leave Case of Name Alone -- In Native Form */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1753 /* (Removed Forced Lowercasing Code) */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1754
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1755 v = PyString_FromString(namebuf);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1756 if (v == NULL) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1757 Py_DECREF(d);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1758 d = NULL;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1759 break;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1760 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1761 if (PyList_Append(d, v) != 0) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1762 Py_DECREF(v);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1763 Py_DECREF(d);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1764 d = NULL;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1765 break;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1766 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1767 Py_DECREF(v);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1768 } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && srchcnt > 0);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1769 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1770
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1771 return d;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
1772 #else
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
1773
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
1774 char *name;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1775 PyObject *d, *v;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1776 DIR *dirp;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1777 struct dirent *ep;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1778 if (!PyArg_ParseTuple(args, "s:listdir", &name))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1779 return NULL;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
1780 if ((dirp = opendir(name)) == NULL) {
10887
af07389c8517 posix_listdir(): When an error occurs, call
Barry Warsaw <barry@python.org>
parents: 10526
diff changeset
1781 return posix_error_with_filename(name);
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
1782 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1783 if ((d = PyList_New(0)) == NULL) {
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1784 closedir(dirp);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1785 return NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1786 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1787 while ((ep = readdir(dirp)) != NULL) {
2845
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
1788 if (ep->d_name[0] == '.' &&
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
1789 (NAMLEN(ep) == 1 ||
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
1790 (ep->d_name[1] == '.' && NAMLEN(ep) == 2)))
2845
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
1791 continue;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1792 v = PyString_FromStringAndSize(ep->d_name, NAMLEN(ep));
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1793 if (v == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1794 Py_DECREF(d);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1795 d = NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1796 break;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1797 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1798 if (PyList_Append(d, v) != 0) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1799 Py_DECREF(v);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1800 Py_DECREF(d);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1801 d = NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1802 break;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1803 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1804 Py_DECREF(v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1805 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1806 closedir(dirp);
200
9d01965f4f48 Incorporated MSDOS changes (untested).
Guido van Rossum <guido@python.org>
parents: 199
diff changeset
1807
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1808 return d;
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
1809
14586
cd1b9d8d045d Closes SF bug 113894: on Windows, things like os.listdir("k:") and
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
1810 #endif /* which OS */
cd1b9d8d045d Closes SF bug 113894: on Windows, things like os.listdir("k:") and
Tim Peters <tim.peters@gmail.com>
parents: 14375
diff changeset
1811 } /* end of posix_listdir */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1812
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
1813 #ifdef MS_WINDOWS
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1814 /* A helper function for abspath on win32 */
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1815 static PyObject *
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1816 posix__getfullpathname(PyObject *self, PyObject *args)
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1817 {
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1818 /* assume encoded strings wont more than double no of chars */
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1819 char inbuf[MAX_PATH*2];
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1820 char *inbufp = inbuf;
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1821 int insize = sizeof(inbuf)/sizeof(inbuf[0]);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1822 char outbuf[MAX_PATH*2];
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1823 char *temp;
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1824 #ifdef Py_WIN_WIDE_FILENAMES
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1825 if (unicode_file_names()) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1826 PyUnicodeObject *po;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1827 if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1828 Py_UNICODE woutbuf[MAX_PATH*2];
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1829 Py_UNICODE *wtemp;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1830 if (!GetFullPathNameW(PyUnicode_AS_UNICODE(po),
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1831 sizeof(woutbuf)/sizeof(woutbuf[0]),
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1832 woutbuf, &wtemp))
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1833 return win32_error("GetFullPathName", "");
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1834 return PyUnicode_FromUnicode(woutbuf, wcslen(woutbuf));
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1835 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1836 /* Drop the argument parsing error as narrow strings
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1837 are also valid. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1838 PyErr_Clear();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1839 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1840 #endif
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1841 if (!PyArg_ParseTuple (args, "et#:_getfullpathname",
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1842 Py_FileSystemDefaultEncoding, &inbufp,
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1843 &insize))
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1844 return NULL;
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1845 if (!GetFullPathName(inbuf, sizeof(outbuf)/sizeof(outbuf[0]),
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1846 outbuf, &temp))
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1847 return win32_error("GetFullPathName", inbuf);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1848 return PyString_FromString(outbuf);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1849 } /* end of posix__getfullpathname */
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
1850 #endif /* MS_WINDOWS */
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1851
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1852 PyDoc_STRVAR(posix_mkdir__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1853 "mkdir(path [, mode=0777])\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1854 Create a directory.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1855
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1856 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1857 posix_mkdir(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1858 {
3418
0ac5fbaf8aef Made 2nd arg to mkdir optional
Guido van Rossum <guido@python.org>
parents: 3387
diff changeset
1859 int res;
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1860 char *path = NULL;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1861 int mode = 0777;
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1862
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1863 #ifdef Py_WIN_WIDE_FILENAMES
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1864 if (unicode_file_names()) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1865 PyUnicodeObject *po;
27969
4c85de247eed os.mkdir() would crash with a Unicode filename and mode param.
Mark Hammond <mhammond@skippinet.com.au>
parents: 27916
diff changeset
1866 if (PyArg_ParseTuple(args, "U|i:mkdir", &po, &mode)) {
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1867 Py_BEGIN_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1868 /* PyUnicode_AS_UNICODE OK without thread lock as
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1869 it is a simple dereference. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1870 res = _wmkdir(PyUnicode_AS_UNICODE(po));
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1871 Py_END_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1872 if (res < 0)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1873 return posix_error();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1874 Py_INCREF(Py_None);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1875 return Py_None;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1876 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1877 /* Drop the argument parsing error as narrow strings
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1878 are also valid. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1879 PyErr_Clear();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1880 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1881 #endif
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1882
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1883 if (!PyArg_ParseTuple(args, "et|i:mkdir",
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1884 Py_FileSystemDefaultEncoding, &path, &mode))
3418
0ac5fbaf8aef Made 2nd arg to mkdir optional
Guido van Rossum <guido@python.org>
parents: 3387
diff changeset
1885 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1886 Py_BEGIN_ALLOW_THREADS
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
1887 #if ( defined(__WATCOMC__) || defined(_MSC_VER) || defined(PYCC_VACPP) ) && !defined(__QNX__)
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1888 res = mkdir(path);
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1889 #else
3418
0ac5fbaf8aef Made 2nd arg to mkdir optional
Guido van Rossum <guido@python.org>
parents: 3387
diff changeset
1890 res = mkdir(path, mode);
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1891 #endif
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1892 Py_END_ALLOW_THREADS
3418
0ac5fbaf8aef Made 2nd arg to mkdir optional
Guido van Rossum <guido@python.org>
parents: 3387
diff changeset
1893 if (res < 0)
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1894 return posix_error_with_allocated_filename(path);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
1895 PyMem_Free(path);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1896 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1897 return Py_None;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1898 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1899
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1900
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1901 #ifdef HAVE_NICE
18486
26fc905ddc12 Re-do the broken-nice() patch to break less platforms. Hopefully none :P
Thomas Wouters <thomas@python.org>
parents: 18476
diff changeset
1902 #if defined(HAVE_BROKEN_NICE) && defined(HAVE_SYS_RESOURCE_H)
26fc905ddc12 Re-do the broken-nice() patch to break less platforms. Hopefully none :P
Thomas Wouters <thomas@python.org>
parents: 18476
diff changeset
1903 #if defined(HAVE_GETPRIORITY) && !defined(PRIO_PROCESS)
26fc905ddc12 Re-do the broken-nice() patch to break less platforms. Hopefully none :P
Thomas Wouters <thomas@python.org>
parents: 18476
diff changeset
1904 #include <sys/resource.h>
26fc905ddc12 Re-do the broken-nice() patch to break less platforms. Hopefully none :P
Thomas Wouters <thomas@python.org>
parents: 18476
diff changeset
1905 #endif
26fc905ddc12 Re-do the broken-nice() patch to break less platforms. Hopefully none :P
Thomas Wouters <thomas@python.org>
parents: 18476
diff changeset
1906 #endif
26fc905ddc12 Re-do the broken-nice() patch to break less platforms. Hopefully none :P
Thomas Wouters <thomas@python.org>
parents: 18476
diff changeset
1907
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1908 PyDoc_STRVAR(posix_nice__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1909 "nice(inc) -> new_priority\n\n\
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1910 Decrease the priority of process by inc and return the new priority.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1911
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1912 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1913 posix_nice(PyObject *self, PyObject *args)
1181
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
1914 {
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
1915 int increment, value;
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
1916
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1917 if (!PyArg_ParseTuple(args, "i:nice", &increment))
1181
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
1918 return NULL;
18476
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1919
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1920 /* There are two flavours of 'nice': one that returns the new
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1921 priority (as required by almost all standards out there) and the
18486
26fc905ddc12 Re-do the broken-nice() patch to break less platforms. Hopefully none :P
Thomas Wouters <thomas@python.org>
parents: 18476
diff changeset
1922 Linux/FreeBSD/BSDI one, which returns '0' on success and advices
26fc905ddc12 Re-do the broken-nice() patch to break less platforms. Hopefully none :P
Thomas Wouters <thomas@python.org>
parents: 18476
diff changeset
1923 the use of getpriority() to get the new priority.
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
1924
18476
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1925 If we are of the nice family that returns the new priority, we
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1926 need to clear errno before the call, and check if errno is filled
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1927 before calling posix_error() on a returnvalue of -1, because the
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1928 -1 may be the actual new priority! */
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1929
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1930 errno = 0;
1181
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
1931 value = nice(increment);
18486
26fc905ddc12 Re-do the broken-nice() patch to break less platforms. Hopefully none :P
Thomas Wouters <thomas@python.org>
parents: 18476
diff changeset
1932 #if defined(HAVE_BROKEN_NICE) && defined(HAVE_GETPRIORITY)
18476
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1933 if (value == 0)
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1934 value = getpriority(PRIO_PROCESS, 0);
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1935 #endif
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1936 if (value == -1 && errno != 0)
04e25c01849b Patch #439995 (slightly modified from the uploaded version):
Thomas Wouters <thomas@python.org>
parents: 17831
diff changeset
1937 /* either nice() or getpriority() returned an error */
1181
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
1938 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1939 return PyInt_FromLong((long) value);
1181
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
1940 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1941 #endif /* HAVE_NICE */
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
1942
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1943
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1944 PyDoc_STRVAR(posix_rename__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1945 "rename(old, new)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1946 Rename a file or directory.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1947
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1948 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1949 posix_rename(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1950 {
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1951 #ifdef MS_WINDOWS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1952 return posix_2str(args, "etet:rename", rename, "OO:rename", _wrename);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1953 #else
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1954 return posix_2str(args, "etet:rename", rename, NULL, NULL);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1955 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1956 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1957
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1958
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1959 PyDoc_STRVAR(posix_rmdir__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1960 "rmdir(path)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1961 Remove a directory.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1962
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1963 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1964 posix_rmdir(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1965 {
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1966 #ifdef MS_WINDOWS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1967 return posix_1str(args, "et:rmdir", rmdir, "U:rmdir", _wrmdir);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1968 #else
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1969 return posix_1str(args, "et:rmdir", rmdir, NULL, NULL);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1970 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1971 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1972
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1973
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1974 PyDoc_STRVAR(posix_stat__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1975 "stat(path) -> stat result\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1976 Perform a stat system call on the given path.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1977
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1978 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1979 posix_stat(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1980 {
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1981 #ifdef MS_WINDOWS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1982 return posix_do_stat(self, args, "et:stat", STAT, "U:stat", _wstati64);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1983 #else
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1984 return posix_do_stat(self, args, "et:stat", STAT, NULL, NULL);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
1985 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1986 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1987
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1988
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1989 #ifdef HAVE_SYSTEM
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1990 PyDoc_STRVAR(posix_system__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
1991 "system(command) -> exit_status\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
1992 Execute the command (a string) in a subshell.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1993
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1994 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
1995 posix_system(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1996 {
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
1997 char *command;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
1998 long sts;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
1999 if (!PyArg_ParseTuple(args, "s:system", &command))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2000 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2001 Py_BEGIN_ALLOW_THREADS
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
2002 sts = system(command);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2003 Py_END_ALLOW_THREADS
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2004 return PyInt_FromLong(sts);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2005 }
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2006 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2007
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2008
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2009 PyDoc_STRVAR(posix_umask__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2010 "umask(new_mask) -> old_mask\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2011 Set the current numeric umask and return the previous umask.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2012
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2013 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2014 posix_umask(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2015 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2016 int i;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
2017 if (!PyArg_ParseTuple(args, "i:umask", &i))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2018 return NULL;
18749
c6ef71e943dd Remove warnings from the SGI compiler.
Fred Drake <fdrake@acm.org>
parents: 18674
diff changeset
2019 i = (int)umask(i);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2020 if (i < 0)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2021 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2022 return PyInt_FromLong((long)i);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2023 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2024
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2025
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2026 PyDoc_STRVAR(posix_unlink__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2027 "unlink(path)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2028 Remove a file (same as remove(path)).");
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2029
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2030 PyDoc_STRVAR(posix_remove__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2031 "remove(path)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2032 Remove a file (same as unlink(path)).");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2033
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2034 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2035 posix_unlink(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2036 {
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
2037 #ifdef MS_WINDOWS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
2038 return posix_1str(args, "et:remove", unlink, "U:remove", _wunlink);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
2039 #else
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
2040 return posix_1str(args, "et:remove", unlink, NULL, NULL);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
2041 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2042 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2043
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2044
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2045 #ifdef HAVE_UNAME
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2046 PyDoc_STRVAR(posix_uname__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2047 "uname() -> (sysname, nodename, release, version, machine)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2048 Return a tuple identifying the current operating system.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2049
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2050 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2051 posix_uname(PyObject *self, PyObject *noargs)
658
5b521fe4d1f6 Added uname. Made lstat/readlink/symlink unconditional (the latter
Guido van Rossum <guido@python.org>
parents: 643
diff changeset
2052 {
5b521fe4d1f6 Added uname. Made lstat/readlink/symlink unconditional (the latter
Guido van Rossum <guido@python.org>
parents: 643
diff changeset
2053 struct utsname u;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
2054 int res;
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2055
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2056 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
2057 res = uname(&u);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2058 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
2059 if (res < 0)
658
5b521fe4d1f6 Added uname. Made lstat/readlink/symlink unconditional (the latter
Guido van Rossum <guido@python.org>
parents: 643
diff changeset
2060 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2061 return Py_BuildValue("(sssss)",
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
2062 u.sysname,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
2063 u.nodename,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
2064 u.release,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
2065 u.version,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
2066 u.machine);
658
5b521fe4d1f6 Added uname. Made lstat/readlink/symlink unconditional (the latter
Guido van Rossum <guido@python.org>
parents: 643
diff changeset
2067 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2068 #endif /* HAVE_UNAME */
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2069
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2070 static int
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2071 extract_time(PyObject *t, long* sec, long* usec)
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2072 {
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2073 long intval;
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2074 if (PyFloat_Check(t)) {
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2075 double tval = PyFloat_AsDouble(t);
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2076 PyObject *intobj = t->ob_type->tp_as_number->nb_int(t);
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2077 if (!intobj)
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2078 return -1;
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2079 intval = PyInt_AsLong(intobj);
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2080 Py_DECREF(intobj);
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2081 *sec = intval;
25184
a0be182631cc extract_time(): Squash compiler warning about possibly information-
Tim Peters <tim.peters@gmail.com>
parents: 25183
diff changeset
2082 *usec = (long)((tval - intval) * 1e6); /* can't exceed 1000000 */
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2083 if (*usec < 0)
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2084 /* If rounding gave us a negative number,
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2085 truncate. */
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2086 *usec = 0;
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2087 return 0;
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2088 }
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2089 intval = PyInt_AsLong(t);
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2090 if (intval == -1 && PyErr_Occurred())
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2091 return -1;
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2092 *sec = intval;
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2093 *usec = 0;
25183
18160cb63650 Add missing return statement.
Martin v. Löwis <martin@v.loewis.de>
parents: 25178
diff changeset
2094 return 0;
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2095 }
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2096
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2097 PyDoc_STRVAR(posix_utime__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2098 "utime(path, (atime, utime))\n\
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2099 utime(path, None)\n\n\
12533
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2100 Set the access and modified time of the file to the given values. If the\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2101 second form is used, set the access and modified times to the current time.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2102
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2103 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2104 posix_utime(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2105 {
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
2106 char *path;
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2107 long atime, mtime, ausec, musec;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
2108 int res;
12533
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2109 PyObject* arg;
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2110
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2111 #if defined(HAVE_UTIMES)
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2112 struct timeval buf[2];
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2113 #define ATIME buf[0].tv_sec
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2114 #define MTIME buf[1].tv_sec
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2115 #elif defined(HAVE_UTIME_H)
6027
494e550cb18d Added a bunch of XXX comments about things I'd like to see changed...
Guido van Rossum <guido@python.org>
parents: 5967
diff changeset
2116 /* XXX should define struct utimbuf instead, above */
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2117 struct utimbuf buf;
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2118 #define ATIME buf.actime
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2119 #define MTIME buf.modtime
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2120 #define UTIME_ARG &buf
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2121 #else /* HAVE_UTIMES */
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2122 time_t buf[2];
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2123 #define ATIME buf[0]
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2124 #define MTIME buf[1]
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2125 #define UTIME_ARG buf
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2126 #endif /* HAVE_UTIMES */
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2127
12533
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2128 if (!PyArg_ParseTuple(args, "sO:utime", &path, &arg))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2129 return NULL;
12533
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2130 if (arg == Py_None) {
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2131 /* optional time values not given */
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2132 Py_BEGIN_ALLOW_THREADS
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2133 res = utime(path, NULL);
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2134 Py_END_ALLOW_THREADS
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2135 }
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2136 else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
12533
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2137 PyErr_SetString(PyExc_TypeError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
2138 "utime() arg 2 must be a tuple (atime, mtime)");
12533
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2139 return NULL;
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2140 }
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2141 else {
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2142 if (extract_time(PyTuple_GET_ITEM(arg, 0),
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2143 &atime, &ausec) == -1)
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2144 return NULL;
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2145 if (extract_time(PyTuple_GET_ITEM(arg, 1),
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2146 &mtime, &musec) == -1)
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2147 return NULL;
12533
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2148 ATIME = atime;
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2149 MTIME = mtime;
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2150 #ifdef HAVE_UTIMES
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2151 buf[0].tv_usec = ausec;
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2152 buf[1].tv_usec = musec;
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2153 Py_BEGIN_ALLOW_THREADS
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2154 res = utimes(path, buf);
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2155 Py_END_ALLOW_THREADS
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2156 #else
12533
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2157 Py_BEGIN_ALLOW_THREADS
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2158 res = utime(path, UTIME_ARG);
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2159 Py_END_ALLOW_THREADS
25178
3efbd1943b8c Use utimes(2) where available to support microsecond timestamps.
Martin v. Löwis <martin@v.loewis.de>
parents: 25177
diff changeset
2160 #endif
12533
5235656f9d0f posix_utime(): Allow the second argument to be None, which invokes the
Barry Warsaw <barry@python.org>
parents: 12503
diff changeset
2161 }
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
2162 if (res < 0)
8708
acf49c9def7d Several changes to support inclusion of filename in relevent
Barry Warsaw <barry@python.org>
parents: 8497
diff changeset
2163 return posix_error_with_filename(path);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2164 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2165 return Py_None;
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2166 #undef UTIME_ARG
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2167 #undef ATIME
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
2168 #undef MTIME
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2169 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2170
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2171
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
2172 /* Process operations */
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2173
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2174 PyDoc_STRVAR(posix__exit__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2175 "_exit(status)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2176 Exit to the system with specified status, without normal exit processing.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2177
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2178 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2179 posix__exit(PyObject *self, PyObject *args)
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2180 {
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2181 int sts;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
2182 if (!PyArg_ParseTuple(args, "i:_exit", &sts))
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2183 return NULL;
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2184 _exit(sts);
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
2185 return NULL; /* Make gcc -Wall happy */
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2186 }
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2187
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2188 #if defined(HAVE_EXECV) || defined(HAVE_SPAWNV)
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2189 static void
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2190 free_string_array(char **array, int count)
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2191 {
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2192 int i;
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2193 for (i = 0; i < count; i++)
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2194 PyMem_Free(array[i]);
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2195 PyMem_DEL(array);
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2196 }
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2197 #endif
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2198
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2199
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2200 #ifdef HAVE_EXECV
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2201 PyDoc_STRVAR(posix_execv__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2202 "execv(path, args)\n\n\
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2203 Execute an executable path with arguments, replacing current process.\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2204 \n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2205 path: path of executable file\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2206 args: tuple or list of strings");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2207
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2208 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2209 posix_execv(PyObject *self, PyObject *args)
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2210 {
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
2211 char *path;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2212 PyObject *argv;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2213 char **argvlist;
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2214 int i, argc;
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2215 PyObject *(*getitem)(PyObject *, int);
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2216
1360
1808ca5d8883 * import.c (MAGIC): Changed magic word to avoid confusion about exec
Guido van Rossum <guido@python.org>
parents: 1329
diff changeset
2217 /* execv has two arguments: (path, argv), where
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2218 argv is a list or tuple of strings. */
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2219
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2220 if (!PyArg_ParseTuple(args, "etO:execv",
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2221 Py_FileSystemDefaultEncoding,
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2222 &path, &argv))
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2223 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2224 if (PyList_Check(argv)) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2225 argc = PyList_Size(argv);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2226 getitem = PyList_GetItem;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2227 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2228 else if (PyTuple_Check(argv)) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2229 argc = PyTuple_Size(argv);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2230 getitem = PyTuple_GetItem;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2231 }
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
2232 else {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
2233 PyErr_SetString(PyExc_TypeError, "execv() arg 2 must be a tuple or list");
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2234 PyMem_Free(path);
12503
211483bd0a51 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12435
diff changeset
2235 return NULL;
211483bd0a51 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12435
diff changeset
2236 }
211483bd0a51 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12435
diff changeset
2237
211483bd0a51 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12435
diff changeset
2238 if (argc == 0) {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
2239 PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty");
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2240 PyMem_Free(path);
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
2241 return NULL;
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
2242 }
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2243
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2244 argvlist = PyMem_NEW(char *, argc+1);
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2245 if (argvlist == NULL) {
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2246 PyMem_Free(path);
27826
7dffcc498c45 Add more missing PyErr_NoMemory() after failled memory allocs
Neal Norwitz <nnorwitz@gmail.com>
parents: 27780
diff changeset
2247 return PyErr_NoMemory();
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2248 }
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2249 for (i = 0; i < argc; i++) {
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2250 if (!PyArg_Parse((*getitem)(argv, i), "et",
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2251 Py_FileSystemDefaultEncoding,
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2252 &argvlist[i])) {
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2253 free_string_array(argvlist, i);
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2254 PyErr_SetString(PyExc_TypeError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
2255 "execv() arg 2 must contain only strings");
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2256 PyMem_Free(path);
12503
211483bd0a51 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12435
diff changeset
2257 return NULL;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2258
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2259 }
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2260 }
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2261 argvlist[argc] = NULL;
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2262
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2263 #ifdef BAD_EXEC_PROTOTYPES
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2264 execv(path, (const char **) argvlist);
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
2265 #else /* BAD_EXEC_PROTOTYPES */
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
2266 execv(path, argvlist);
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
2267 #endif /* BAD_EXEC_PROTOTYPES */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2268
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2269 /* If we get here it's definitely an error */
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2270
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2271 free_string_array(argvlist, argc);
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2272 PyMem_Free(path);
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2273 return posix_error();
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2274 }
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2275
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2276
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2277 PyDoc_STRVAR(posix_execve__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2278 "execve(path, args, env)\n\n\
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2279 Execute a path with arguments and environment, replacing current process.\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2280 \n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2281 path: path of executable file\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2282 args: tuple or list of arguments\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2283 env: dictionary of strings mapping to strings");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2284
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2285 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2286 posix_execve(PyObject *self, PyObject *args)
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2287 {
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2288 char *path;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2289 PyObject *argv, *env;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2290 char **argvlist;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2291 char **envlist;
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2292 PyObject *key, *val, *keys=NULL, *vals=NULL;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2293 int i, pos, argc, envc;
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2294 PyObject *(*getitem)(PyObject *, int);
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2295 int lastarg = 0;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2296
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2297 /* execve has three arguments: (path, argv, env), where
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2298 argv is a list or tuple of strings and env is a dictionary
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2299 like posix.environ. */
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2300
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2301 if (!PyArg_ParseTuple(args, "etOO:execve",
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2302 Py_FileSystemDefaultEncoding,
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2303 &path, &argv, &env))
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2304 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2305 if (PyList_Check(argv)) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2306 argc = PyList_Size(argv);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2307 getitem = PyList_GetItem;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2308 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2309 else if (PyTuple_Check(argv)) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2310 argc = PyTuple_Size(argv);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2311 getitem = PyTuple_GetItem;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2312 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2313 else {
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2314 PyErr_SetString(PyExc_TypeError,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2315 "execve() arg 2 must be a tuple or list");
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2316 goto fail_0;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2317 }
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2318 if (!PyMapping_Check(env)) {
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2319 PyErr_SetString(PyExc_TypeError,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2320 "execve() arg 3 must be a mapping object");
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2321 goto fail_0;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2322 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2323
12503
211483bd0a51 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12435
diff changeset
2324 if (argc == 0) {
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2325 PyErr_SetString(PyExc_ValueError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
2326 "execve() arg 2 must not be empty");
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2327 goto fail_0;
12503
211483bd0a51 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12435
diff changeset
2328 }
211483bd0a51 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12435
diff changeset
2329
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2330 argvlist = PyMem_NEW(char *, argc+1);
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2331 if (argvlist == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2332 PyErr_NoMemory();
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2333 goto fail_0;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2334 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2335 for (i = 0; i < argc; i++) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2336 if (!PyArg_Parse((*getitem)(argv, i),
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2337 "et;execve() arg 2 must contain only strings",
25804
6001265ec686 posix_execve(): add missing argument for "et" format in PyArg_Parse()
Guido van Rossum <guido@python.org>
parents: 25747
diff changeset
2338 Py_FileSystemDefaultEncoding,
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
2339 &argvlist[i]))
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
2340 {
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2341 lastarg = i;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2342 goto fail_1;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2343 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2344 }
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2345 lastarg = argc;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2346 argvlist[argc] = NULL;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2347
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13513
diff changeset
2348 i = PyMapping_Size(env);
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2349 if (i < 0)
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2350 goto fail_1;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2351 envlist = PyMem_NEW(char *, i + 1);
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2352 if (envlist == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2353 PyErr_NoMemory();
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2354 goto fail_1;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2355 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2356 envc = 0;
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2357 keys = PyMapping_Keys(env);
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2358 vals = PyMapping_Values(env);
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2359 if (!keys || !vals)
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2360 goto fail_2;
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2361 if (!PyList_Check(keys) || !PyList_Check(vals)) {
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2362 PyErr_SetString(PyExc_TypeError,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2363 "execve(): env.keys() or env.values() is not a list");
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2364 goto fail_2;
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2365 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2366
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2367 for (pos = 0; pos < i; pos++) {
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2368 char *p, *k, *v;
21172
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
2369 size_t len;
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2370
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2371 key = PyList_GetItem(keys, pos);
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2372 val = PyList_GetItem(vals, pos);
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2373 if (!key || !val)
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2374 goto fail_2;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2375
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2376 if (!PyArg_Parse(
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2377 key,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2378 "s;execve() arg 3 contains a non-string key",
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2379 &k) ||
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2380 !PyArg_Parse(
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2381 val,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2382 "s;execve() arg 3 contains a non-string value",
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2383 &v))
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
2384 {
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2385 goto fail_2;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2386 }
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
2387
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
2388 #if defined(PYOS_OS2)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
2389 /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
2390 if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
2391 #endif
21172
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
2392 len = PyString_Size(key) + PyString_Size(val) + 2;
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
2393 p = PyMem_NEW(char, len);
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2394 if (p == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2395 PyErr_NoMemory();
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2396 goto fail_2;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2397 }
21172
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
2398 PyOS_snprintf(p, len, "%s=%s", k, v);
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2399 envlist[envc++] = p;
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
2400 #if defined(PYOS_OS2)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
2401 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
2402 #endif
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2403 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2404 envlist[envc] = 0;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2405
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2406
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2407 #ifdef BAD_EXEC_PROTOTYPES
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2408 execve(path, (const char **)argvlist, envlist);
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
2409 #else /* BAD_EXEC_PROTOTYPES */
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2410 execve(path, argvlist, envlist);
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
2411 #endif /* BAD_EXEC_PROTOTYPES */
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2412
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2413 /* If we get here it's definitely an error */
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2414
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2415 (void) posix_error();
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2416
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2417 fail_2:
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2418 while (--envc >= 0)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2419 PyMem_DEL(envlist[envc]);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2420 PyMem_DEL(envlist);
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2421 fail_1:
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2422 free_string_array(argvlist, lastarg);
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2423 Py_XDECREF(vals);
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
2424 Py_XDECREF(keys);
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2425 fail_0:
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2426 PyMem_Free(path);
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2427 return NULL;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2428 }
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2429 #endif /* HAVE_EXECV */
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
2430
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2431
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2432 #ifdef HAVE_SPAWNV
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2433 PyDoc_STRVAR(posix_spawnv__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2434 "spawnv(mode, path, args)\n\n\
21295
59894496b5c7 SF patch #489173: Make os.spawnv not block the interpreter, from
Tim Peters <tim.peters@gmail.com>
parents: 21172
diff changeset
2435 Execute the program 'path' in a new process.\n\
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2436 \n\
10066
d7f434d784bf spawnv, spawnve docstrings: added mode parameter; this is required!
Fred Drake <fdrake@acm.org>
parents: 10056
diff changeset
2437 mode: mode of process creation\n\
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2438 path: path of executable file\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2439 args: tuple or list of strings");
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2440
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2441 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2442 posix_spawnv(PyObject *self, PyObject *args)
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2443 {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2444 char *path;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2445 PyObject *argv;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2446 char **argvlist;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2447 int mode, i, argc;
19568
b0f5278a2ab4 SF bug [#456252] Python should never stomp on [u]intptr_t.
Tim Peters <tim.peters@gmail.com>
parents: 19490
diff changeset
2448 Py_intptr_t spawnval;
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2449 PyObject *(*getitem)(PyObject *, int);
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2450
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2451 /* spawnv has three arguments: (mode, path, argv), where
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2452 argv is a list or tuple of strings. */
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2453
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2454 if (!PyArg_ParseTuple(args, "ietO:spawnv", &mode,
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2455 Py_FileSystemDefaultEncoding,
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2456 &path, &argv))
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2457 return NULL;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2458 if (PyList_Check(argv)) {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2459 argc = PyList_Size(argv);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2460 getitem = PyList_GetItem;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2461 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2462 else if (PyTuple_Check(argv)) {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2463 argc = PyTuple_Size(argv);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2464 getitem = PyTuple_GetItem;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2465 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2466 else {
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2467 PyErr_SetString(PyExc_TypeError,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2468 "spawnv() arg 2 must be a tuple or list");
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2469 PyMem_Free(path);
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2470 return NULL;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2471 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2472
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2473 argvlist = PyMem_NEW(char *, argc+1);
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2474 if (argvlist == NULL) {
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2475 PyMem_Free(path);
27826
7dffcc498c45 Add more missing PyErr_NoMemory() after failled memory allocs
Neal Norwitz <nnorwitz@gmail.com>
parents: 27780
diff changeset
2476 return PyErr_NoMemory();
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2477 }
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2478 for (i = 0; i < argc; i++) {
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2479 if (!PyArg_Parse((*getitem)(argv, i), "et",
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2480 Py_FileSystemDefaultEncoding,
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2481 &argvlist[i])) {
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2482 free_string_array(argvlist, i);
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2483 PyErr_SetString(
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2484 PyExc_TypeError,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2485 "spawnv() arg 2 must contain only strings");
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2486 PyMem_Free(path);
12814
b1b260a2de98 Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12564
diff changeset
2487 return NULL;
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2488 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2489 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2490 argvlist[argc] = NULL;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2491
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2492 #if defined(PYOS_OS2) && defined(PYCC_GCC)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2493 Py_BEGIN_ALLOW_THREADS
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2494 spawnval = spawnv(mode, path, argvlist);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2495 Py_END_ALLOW_THREADS
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2496 #else
10069
5e01645ee41b Add _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 10066
diff changeset
2497 if (mode == _OLD_P_OVERLAY)
5e01645ee41b Add _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 10066
diff changeset
2498 mode = _P_OVERLAY;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2499
21295
59894496b5c7 SF patch #489173: Make os.spawnv not block the interpreter, from
Tim Peters <tim.peters@gmail.com>
parents: 21172
diff changeset
2500 Py_BEGIN_ALLOW_THREADS
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
2501 spawnval = _spawnv(mode, path, argvlist);
21295
59894496b5c7 SF patch #489173: Make os.spawnv not block the interpreter, from
Tim Peters <tim.peters@gmail.com>
parents: 21172
diff changeset
2502 Py_END_ALLOW_THREADS
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2503 #endif
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2504
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2505 free_string_array(argvlist, argc);
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2506 PyMem_Free(path);
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2507
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
2508 if (spawnval == -1)
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2509 return posix_error();
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2510 else
13462
4cf0de29c08c - fixed pointer size test in spawn functions. also added
Fredrik Lundh <fredrik@pythonware.com>
parents: 13442
diff changeset
2511 #if SIZEOF_LONG == SIZEOF_VOID_P
4cf0de29c08c - fixed pointer size test in spawn functions. also added
Fredrik Lundh <fredrik@pythonware.com>
parents: 13442
diff changeset
2512 return Py_BuildValue("l", (long) spawnval);
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
2513 #else
13462
4cf0de29c08c - fixed pointer size test in spawn functions. also added
Fredrik Lundh <fredrik@pythonware.com>
parents: 13442
diff changeset
2514 return Py_BuildValue("L", (LONG_LONG) spawnval);
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
2515 #endif
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2516 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2517
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2518
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2519 PyDoc_STRVAR(posix_spawnve__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2520 "spawnve(mode, path, args, env)\n\n\
21295
59894496b5c7 SF patch #489173: Make os.spawnv not block the interpreter, from
Tim Peters <tim.peters@gmail.com>
parents: 21172
diff changeset
2521 Execute the program 'path' in a new process.\n\
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2522 \n\
10066
d7f434d784bf spawnv, spawnve docstrings: added mode parameter; this is required!
Fred Drake <fdrake@acm.org>
parents: 10056
diff changeset
2523 mode: mode of process creation\n\
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2524 path: path of executable file\n\
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2525 args: tuple or list of arguments\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2526 env: dictionary of strings mapping to strings");
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2527
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2528 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2529 posix_spawnve(PyObject *self, PyObject *args)
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2530 {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2531 char *path;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2532 PyObject *argv, *env;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2533 char **argvlist;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2534 char **envlist;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2535 PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2536 int mode, i, pos, argc, envc;
19568
b0f5278a2ab4 SF bug [#456252] Python should never stomp on [u]intptr_t.
Tim Peters <tim.peters@gmail.com>
parents: 19490
diff changeset
2537 Py_intptr_t spawnval;
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
2538 PyObject *(*getitem)(PyObject *, int);
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2539 int lastarg = 0;
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2540
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2541 /* spawnve has four arguments: (mode, path, argv, env), where
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2542 argv is a list or tuple of strings and env is a dictionary
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2543 like posix.environ. */
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2544
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2545 if (!PyArg_ParseTuple(args, "ietOO:spawnve", &mode,
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2546 Py_FileSystemDefaultEncoding,
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2547 &path, &argv, &env))
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2548 return NULL;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2549 if (PyList_Check(argv)) {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2550 argc = PyList_Size(argv);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2551 getitem = PyList_GetItem;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2552 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2553 else if (PyTuple_Check(argv)) {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2554 argc = PyTuple_Size(argv);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2555 getitem = PyTuple_GetItem;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2556 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2557 else {
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2558 PyErr_SetString(PyExc_TypeError,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2559 "spawnve() arg 2 must be a tuple or list");
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2560 goto fail_0;
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2561 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2562 if (!PyMapping_Check(env)) {
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2563 PyErr_SetString(PyExc_TypeError,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2564 "spawnve() arg 3 must be a mapping object");
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2565 goto fail_0;
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2566 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2567
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2568 argvlist = PyMem_NEW(char *, argc+1);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2569 if (argvlist == NULL) {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2570 PyErr_NoMemory();
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2571 goto fail_0;
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2572 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2573 for (i = 0; i < argc; i++) {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2574 if (!PyArg_Parse((*getitem)(argv, i),
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2575 "et;spawnve() arg 2 must contain only strings",
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2576 Py_FileSystemDefaultEncoding,
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2577 &argvlist[i]))
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2578 {
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2579 lastarg = i;
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2580 goto fail_1;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2581 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2582 }
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2583 lastarg = argc;
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2584 argvlist[argc] = NULL;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2585
13576
61e4c29d53d8 replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 13513
diff changeset
2586 i = PyMapping_Size(env);
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2587 if (i < 0)
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2588 goto fail_1;
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2589 envlist = PyMem_NEW(char *, i + 1);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2590 if (envlist == NULL) {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2591 PyErr_NoMemory();
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2592 goto fail_1;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2593 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2594 envc = 0;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2595 keys = PyMapping_Keys(env);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2596 vals = PyMapping_Values(env);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2597 if (!keys || !vals)
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2598 goto fail_2;
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2599 if (!PyList_Check(keys) || !PyList_Check(vals)) {
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2600 PyErr_SetString(PyExc_TypeError,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2601 "spawnve(): env.keys() or env.values() is not a list");
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2602 goto fail_2;
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2603 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2604
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2605 for (pos = 0; pos < i; pos++) {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2606 char *p, *k, *v;
21172
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
2607 size_t len;
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2608
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2609 key = PyList_GetItem(keys, pos);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2610 val = PyList_GetItem(vals, pos);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2611 if (!key || !val)
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2612 goto fail_2;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2613
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2614 if (!PyArg_Parse(
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2615 key,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2616 "s;spawnve() arg 3 contains a non-string key",
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2617 &k) ||
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2618 !PyArg_Parse(
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2619 val,
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2620 "s;spawnve() arg 3 contains a non-string value",
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2621 &v))
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2622 {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2623 goto fail_2;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2624 }
21172
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
2625 len = PyString_Size(key) + PyString_Size(val) + 2;
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
2626 p = PyMem_NEW(char, len);
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2627 if (p == NULL) {
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2628 PyErr_NoMemory();
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2629 goto fail_2;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2630 }
21172
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
2631 PyOS_snprintf(p, len, "%s=%s", k, v);
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2632 envlist[envc++] = p;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2633 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2634 envlist[envc] = 0;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2635
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2636 #if defined(PYOS_OS2) && defined(PYCC_GCC)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2637 Py_BEGIN_ALLOW_THREADS
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2638 spawnval = spawnve(mode, path, argvlist, envlist);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2639 Py_END_ALLOW_THREADS
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2640 #else
10069
5e01645ee41b Add _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 10066
diff changeset
2641 if (mode == _OLD_P_OVERLAY)
5e01645ee41b Add _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 10066
diff changeset
2642 mode = _P_OVERLAY;
21295
59894496b5c7 SF patch #489173: Make os.spawnv not block the interpreter, from
Tim Peters <tim.peters@gmail.com>
parents: 21172
diff changeset
2643
59894496b5c7 SF patch #489173: Make os.spawnv not block the interpreter, from
Tim Peters <tim.peters@gmail.com>
parents: 21172
diff changeset
2644 Py_BEGIN_ALLOW_THREADS
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
2645 spawnval = _spawnve(mode, path, argvlist, envlist);
21295
59894496b5c7 SF patch #489173: Make os.spawnv not block the interpreter, from
Tim Peters <tim.peters@gmail.com>
parents: 21172
diff changeset
2646 Py_END_ALLOW_THREADS
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
2647 #endif
21295
59894496b5c7 SF patch #489173: Make os.spawnv not block the interpreter, from
Tim Peters <tim.peters@gmail.com>
parents: 21172
diff changeset
2648
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
2649 if (spawnval == -1)
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2650 (void) posix_error();
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2651 else
13462
4cf0de29c08c - fixed pointer size test in spawn functions. also added
Fredrik Lundh <fredrik@pythonware.com>
parents: 13442
diff changeset
2652 #if SIZEOF_LONG == SIZEOF_VOID_P
4cf0de29c08c - fixed pointer size test in spawn functions. also added
Fredrik Lundh <fredrik@pythonware.com>
parents: 13442
diff changeset
2653 res = Py_BuildValue("l", (long) spawnval);
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
2654 #else
13462
4cf0de29c08c - fixed pointer size test in spawn functions. also added
Fredrik Lundh <fredrik@pythonware.com>
parents: 13442
diff changeset
2655 res = Py_BuildValue("L", (LONG_LONG) spawnval);
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
2656 #endif
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2657
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2658 fail_2:
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2659 while (--envc >= 0)
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2660 PyMem_DEL(envlist[envc]);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2661 PyMem_DEL(envlist);
26646
9267dffff32d execve(), spawnve(): add some extra sanity checking to env;
Guido van Rossum <guido@python.org>
parents: 26550
diff changeset
2662 fail_1:
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2663 free_string_array(argvlist, lastarg);
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2664 Py_XDECREF(vals);
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2665 Py_XDECREF(keys);
25630
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2666 fail_0:
25d1f4f91487 Apply file system default encoding to exec and spawn path and arguments.
Martin v. Löwis <martin@v.loewis.de>
parents: 25573
diff changeset
2667 PyMem_Free(path);
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2668 return res;
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2669 }
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2670 #endif /* HAVE_SPAWNV */
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2671
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
2672
17419
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2673 #ifdef HAVE_FORK1
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2674 PyDoc_STRVAR(posix_fork1__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2675 "fork1() -> pid\n\n\
17419
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2676 Fork a child process with a single multiplexed (i.e., not bound) thread.\n\
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2677 \n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2678 Return 0 to child process and PID of child to parent process.");
17419
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2679
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2680 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2681 posix_fork1(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2682 {
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2683 int pid = fork1();
17419
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2684 if (pid == -1)
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2685 return posix_error();
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2686 PyOS_AfterFork();
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2687 return PyInt_FromLong((long)pid);
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2688 }
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2689 #endif
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2690
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
2691
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2692 #ifdef HAVE_FORK
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2693 PyDoc_STRVAR(posix_fork__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2694 "fork() -> pid\n\n\
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2695 Fork a child process.\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2696 Return 0 to child process and PID of child to parent process.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2697
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2698 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2699 posix_fork(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2700 {
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2701 int pid = fork();
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2702 if (pid == -1)
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2703 return posix_error();
13389
1c0d35ba16b1 Fix bug #392, reported by Jonathan Giddy <jon@dstc.edu.au>:
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
2704 if (pid == 0)
1c0d35ba16b1 Fix bug #392, reported by Jonathan Giddy <jon@dstc.edu.au>:
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
2705 PyOS_AfterFork();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2706 return PyInt_FromLong((long)pid);
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2707 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2708 #endif
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2709
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2710 #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX)
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2711 #ifdef HAVE_PTY_H
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2712 #include <pty.h>
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2713 #else
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2714 #ifdef HAVE_LIBUTIL_H
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2715 #include <libutil.h>
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2716 #endif /* HAVE_LIBUTIL_H */
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2717 #endif /* HAVE_PTY_H */
26998
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 26960
diff changeset
2718 #ifdef HAVE_STROPTS_H
6ca1c0d3ef19 Expose I_ constants. Auto-detect stropts.h. Properly configure the slave terminal.
Martin v. Löwis <martin@v.loewis.de>
parents: 26960
diff changeset
2719 #include <stropts.h>
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2720 #endif
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2721 #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX */
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2722
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2723 #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2724 PyDoc_STRVAR(posix_openpty__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2725 "openpty() -> (master_fd, slave_fd)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2726 Open a pseudo-terminal, returning open fd's for both master and slave end.\n");
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2727
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2728 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2729 posix_openpty(PyObject *self, PyObject *noargs)
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2730 {
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2731 int master_fd, slave_fd;
13601
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2732 #ifndef HAVE_OPENPTY
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2733 char * slave_name;
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2734 #endif
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2735 #if defined(HAVE_DEV_PTMX) && !defined(HAVE_OPENPTY) && !defined(HAVE__GETPTY)
26952
35fcabefc9d2 Restore signalhandler in case of error. Fix type of signal handler.
Martin v. Löwis <martin@v.loewis.de>
parents: 26945
diff changeset
2736 PyOS_sighandler_t sig_saved;
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2737 #ifdef sun
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2738 extern char *ptsname();
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2739 #endif
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2740 #endif
13601
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2741
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2742 #ifdef HAVE_OPENPTY
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2743 if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0)
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2744 return posix_error();
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2745 #elif HAVE__GETPTY
13601
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2746 slave_name = _getpty(&master_fd, O_RDWR, 0666, 0);
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2747 if (slave_name == NULL)
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2748 return posix_error();
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2749
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2750 slave_fd = open(slave_name, O_RDWR);
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2751 if (slave_fd < 0)
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2752 return posix_error();
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2753 #else
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2754 master_fd = open("/dev/ptmx", O_RDWR | O_NOCTTY); /* open master */
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2755 if (master_fd < 0)
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2756 return posix_error();
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2757 sig_saved = signal(SIGCHLD, SIG_DFL);
26952
35fcabefc9d2 Restore signalhandler in case of error. Fix type of signal handler.
Martin v. Löwis <martin@v.loewis.de>
parents: 26945
diff changeset
2758 /* change permission of slave */
35fcabefc9d2 Restore signalhandler in case of error. Fix type of signal handler.
Martin v. Löwis <martin@v.loewis.de>
parents: 26945
diff changeset
2759 if (grantpt(master_fd) < 0) {
35fcabefc9d2 Restore signalhandler in case of error. Fix type of signal handler.
Martin v. Löwis <martin@v.loewis.de>
parents: 26945
diff changeset
2760 signal(SIGCHLD, sig_saved);
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2761 return posix_error();
26952
35fcabefc9d2 Restore signalhandler in case of error. Fix type of signal handler.
Martin v. Löwis <martin@v.loewis.de>
parents: 26945
diff changeset
2762 }
35fcabefc9d2 Restore signalhandler in case of error. Fix type of signal handler.
Martin v. Löwis <martin@v.loewis.de>
parents: 26945
diff changeset
2763 /* unlock slave */
35fcabefc9d2 Restore signalhandler in case of error. Fix type of signal handler.
Martin v. Löwis <martin@v.loewis.de>
parents: 26945
diff changeset
2764 if (unlockpt(master_fd) < 0) {
35fcabefc9d2 Restore signalhandler in case of error. Fix type of signal handler.
Martin v. Löwis <martin@v.loewis.de>
parents: 26945
diff changeset
2765 signal(SIGCHLD, sig_saved);
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2766 return posix_error();
26952
35fcabefc9d2 Restore signalhandler in case of error. Fix type of signal handler.
Martin v. Löwis <martin@v.loewis.de>
parents: 26945
diff changeset
2767 }
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2768 signal(SIGCHLD, sig_saved);
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2769 slave_name = ptsname(master_fd); /* get name of slave */
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2770 if (slave_name == NULL)
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2771 return posix_error();
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2772 slave_fd = open(slave_name, O_RDWR | O_NOCTTY); /* open slave */
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2773 if (slave_fd < 0)
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2774 return posix_error();
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2775 #ifndef __CYGWIN__
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2776 ioctl(slave_fd, I_PUSH, "ptem"); /* push ptem */
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2777 ioctl(slave_fd, I_PUSH, "ldterm"); /* push ldterm */
26960
1c58fe5c769f Fix compilation errors on HPUX11
Neal Norwitz <nnorwitz@gmail.com>
parents: 26952
diff changeset
2778 #ifndef __hpux
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2779 ioctl(slave_fd, I_PUSH, "ttcompat"); /* push ttcompat */
26960
1c58fe5c769f Fix compilation errors on HPUX11
Neal Norwitz <nnorwitz@gmail.com>
parents: 26952
diff changeset
2780 #endif /* __hpux */
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2781 #endif /* HAVE_CYGWIN */
13694
b54f11ada91e Create a new section of pyport.h to hold all external function declarations
Thomas Wouters <thomas@python.org>
parents: 13675
diff changeset
2782 #endif /* HAVE_OPENPTY */
13601
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2783
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2784 return Py_BuildValue("(ii)", master_fd, slave_fd);
13601
ef8b20b9f6f5 Move (actually copy) support for the sgi._getpty() function into
Thomas Wouters <thomas@python.org>
parents: 13582
diff changeset
2785
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2786 }
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
2787 #endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2788
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2789 #ifdef HAVE_FORKPTY
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2790 PyDoc_STRVAR(posix_forkpty__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2791 "forkpty() -> (pid, master_fd)\n\n\
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2792 Fork a new process with a new pseudo-terminal as controlling tty.\n\n\
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2793 Like fork(), return 0 as pid to child process, and PID of child to parent.\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2794 To both, return fd of newly opened pseudo-terminal.\n");
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2795
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2796 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2797 posix_forkpty(PyObject *self, PyObject *noargs)
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2798 {
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2799 int master_fd, pid;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
2800
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2801 pid = forkpty(&master_fd, NULL, NULL, NULL);
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2802 if (pid == -1)
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2803 return posix_error();
13389
1c0d35ba16b1 Fix bug #392, reported by Jonathan Giddy <jon@dstc.edu.au>:
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
2804 if (pid == 0)
1c0d35ba16b1 Fix bug #392, reported by Jonathan Giddy <jon@dstc.edu.au>:
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
2805 PyOS_AfterFork();
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2806 return Py_BuildValue("(ii)", pid, master_fd);
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2807 }
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
2808 #endif
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2809
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2810 #ifdef HAVE_GETEGID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2811 PyDoc_STRVAR(posix_getegid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2812 "getegid() -> egid\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2813 Return the current process's effective group id.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2814
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2815 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2816 posix_getegid(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2817 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2818 return PyInt_FromLong((long)getegid());
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
2819 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2820 #endif
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
2821
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2822
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2823 #ifdef HAVE_GETEUID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2824 PyDoc_STRVAR(posix_geteuid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2825 "geteuid() -> euid\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2826 Return the current process's effective user id.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2827
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2828 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2829 posix_geteuid(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2830 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2831 return PyInt_FromLong((long)geteuid());
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
2832 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2833 #endif
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
2834
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2835
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2836 #ifdef HAVE_GETGID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2837 PyDoc_STRVAR(posix_getgid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2838 "getgid() -> gid\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2839 Return the current process's group id.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2840
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2841 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2842 posix_getgid(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2843 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2844 return PyInt_FromLong((long)getgid());
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
2845 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2846 #endif
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
2847
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2848
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2849 PyDoc_STRVAR(posix_getpid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2850 "getpid() -> pid\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2851 Return the current process id");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2852
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2853 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2854 posix_getpid(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2855 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2856 return PyInt_FromLong((long)getpid());
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2857 }
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2858
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2859
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2860 #ifdef HAVE_GETGROUPS
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2861 PyDoc_STRVAR(posix_getgroups__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2862 "getgroups() -> list of group IDs\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2863 Return list of supplemental group IDs for the process.");
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2864
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2865 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2866 posix_getgroups(PyObject *self, PyObject *noargs)
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2867 {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2868 PyObject *result = NULL;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2869
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2870 #ifdef NGROUPS_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2871 #define MAX_GROUPS NGROUPS_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2872 #else
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2873 /* defined to be 16 on Solaris7, so this should be a small number */
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2874 #define MAX_GROUPS 64
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2875 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2876 gid_t grouplist[MAX_GROUPS];
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2877 int n;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2878
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2879 n = getgroups(MAX_GROUPS, grouplist);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2880 if (n < 0)
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2881 posix_error();
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2882 else {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2883 result = PyList_New(n);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2884 if (result != NULL) {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2885 int i;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2886 for (i = 0; i < n; ++i) {
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2887 PyObject *o = PyInt_FromLong((long)grouplist[i]);
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2888 if (o == NULL) {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2889 Py_DECREF(result);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2890 result = NULL;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2891 break;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2892 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2893 PyList_SET_ITEM(result, i, o);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2894 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2895 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2896 }
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2897
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2898 return result;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2899 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2900 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
2901
23833
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2902 #ifdef HAVE_GETPGID
23836
065a7f23be2f Use new PyDoc_STRVAR macro
Neal Norwitz <nnorwitz@gmail.com>
parents: 23833
diff changeset
2903 PyDoc_STRVAR(posix_getpgid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2904 "getpgid(pid) -> pgid\n\n\
23836
065a7f23be2f Use new PyDoc_STRVAR macro
Neal Norwitz <nnorwitz@gmail.com>
parents: 23833
diff changeset
2905 Call the system call getpgid().");
23833
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2906
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2907 static PyObject *
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2908 posix_getpgid(PyObject *self, PyObject *args)
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2909 {
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2910 int pid, pgid;
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2911 if (!PyArg_ParseTuple(args, "i:getpgid", &pid))
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2912 return NULL;
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2913 pgid = getpgid(pid);
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2914 if (pgid < 0)
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2915 return posix_error();
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2916 return PyInt_FromLong((long)pgid);
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2917 }
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2918 #endif /* HAVE_GETPGID */
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2919
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
2920
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2921 #ifdef HAVE_GETPGRP
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2922 PyDoc_STRVAR(posix_getpgrp__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2923 "getpgrp() -> pgrp\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2924 Return the current process group id.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2925
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2926 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2927 posix_getpgrp(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2928 {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2929 #ifdef GETPGRP_HAVE_ARG
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2930 return PyInt_FromLong((long)getpgrp(0));
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
2931 #else /* GETPGRP_HAVE_ARG */
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2932 return PyInt_FromLong((long)getpgrp());
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
2933 #endif /* GETPGRP_HAVE_ARG */
273
af1c8f5d0b37 Added getpgrp(); fixed buggy calls to getnoarg().
Guido van Rossum <guido@python.org>
parents: 264
diff changeset
2934 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2935 #endif /* HAVE_GETPGRP */
273
af1c8f5d0b37 Added getpgrp(); fixed buggy calls to getnoarg().
Guido van Rossum <guido@python.org>
parents: 264
diff changeset
2936
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2937
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2938 #ifdef HAVE_SETPGRP
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2939 PyDoc_STRVAR(posix_setpgrp__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2940 "setpgrp()\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2941 Make this process a session leader.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2942
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2943 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2944 posix_setpgrp(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2945 {
1983
80bd7af73201 distinguish between getpgrp and setpgrp arg requirements
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2946 #ifdef SETPGRP_HAVE_ARG
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2947 if (setpgrp(0, 0) < 0)
1983
80bd7af73201 distinguish between getpgrp and setpgrp arg requirements
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2948 #else /* SETPGRP_HAVE_ARG */
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
2949 if (setpgrp() < 0)
1983
80bd7af73201 distinguish between getpgrp and setpgrp arg requirements
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
2950 #endif /* SETPGRP_HAVE_ARG */
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
2951 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2952 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2953 return Py_None;
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
2954 }
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
2955
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2956 #endif /* HAVE_SETPGRP */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2957
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2958 #ifdef HAVE_GETPPID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2959 PyDoc_STRVAR(posix_getppid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2960 "getppid() -> ppid\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2961 Return the parent's process id.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2962
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2963 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2964 posix_getppid(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2965 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2966 return PyInt_FromLong((long)getppid());
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2967 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2968 #endif
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
2969
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2970
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
2971 #ifdef HAVE_GETLOGIN
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2972 PyDoc_STRVAR(posix_getlogin__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
2973 "getlogin() -> string\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
2974 Return the actual login name.");
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
2975
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
2976 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2977 posix_getlogin(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2978 {
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2979 PyObject *result = NULL;
15485
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2980 char *name;
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2981 int old_errno = errno;
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2982
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2983 errno = 0;
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2984 name = getlogin();
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2985 if (name == NULL) {
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2986 if (errno)
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2987 posix_error();
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2988 else
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2989 PyErr_SetString(PyExc_OSError,
15486
b3398c452d95 posix_getlogin(): Be more cautious about interpreting a NULL from
Fred Drake <fdrake@acm.org>
parents: 15485
diff changeset
2990 "unable to determine login name");
15485
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2991 }
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
2992 else
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
2993 result = PyString_FromString(name);
15485
1091ad9a0303 posix_getlogin(): Handle the possibility that getlogin() can return
Fred Drake <fdrake@acm.org>
parents: 15318
diff changeset
2994 errno = old_errno;
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
2995
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
2996 return result;
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
2997 }
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
2998 #endif
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
2999
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
3000 #ifdef HAVE_GETUID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
3001 PyDoc_STRVAR(posix_getuid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
3002 "getuid() -> uid\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
3003 Return the current process's user id.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
3004
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
3005 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
3006 posix_getuid(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
3007 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
3008 return PyInt_FromLong((long)getuid());
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
3009 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
3010 #endif
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
3011
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
3012
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
3013 #ifdef HAVE_KILL
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
3014 PyDoc_STRVAR(posix_kill__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
3015 "kill(pid, sig)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
3016 Kill a process with a signal.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
3017
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
3018 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
3019 posix_kill(PyObject *self, PyObject *args)
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
3020 {
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
3021 int pid, sig;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
3022 if (!PyArg_ParseTuple(args, "ii:kill", &pid, &sig))
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
3023 return NULL;
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3024 #if defined(PYOS_OS2) && !defined(PYCC_GCC)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3025 if (sig == XCPT_SIGNAL_INTR || sig == XCPT_SIGNAL_BREAK) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3026 APIRET rc;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3027 if ((rc = DosSendSignalException(pid, sig)) != NO_ERROR)
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3028 return os2_error(rc);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3029
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3030 } else if (sig == XCPT_SIGNAL_KILLPROC) {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3031 APIRET rc;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3032 if ((rc = DosKillProcess(DKP_PROCESS, pid)) != NO_ERROR)
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3033 return os2_error(rc);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3034
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3035 } else
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3036 return NULL; /* Unrecognized Signal Requested */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3037 #else
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
3038 if (kill(pid, sig) == -1)
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
3039 return posix_error();
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3040 #endif
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
3041 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
3042 return Py_None;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
3043 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
3044 #endif
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
3045
21966
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3046 #ifdef HAVE_KILLPG
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
3047 PyDoc_STRVAR(posix_killpg__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
3048 "killpg(pgid, sig)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
3049 Kill a process group with a signal.");
21966
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3050
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3051 static PyObject *
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3052 posix_killpg(PyObject *self, PyObject *args)
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3053 {
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3054 int pgid, sig;
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3055 if (!PyArg_ParseTuple(args, "ii:killpg", &pgid, &sig))
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3056 return NULL;
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3057 if (killpg(pgid, sig) == -1)
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3058 return posix_error();
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3059 Py_INCREF(Py_None);
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3060 return Py_None;
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3061 }
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3062 #endif
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
3063
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3064 #ifdef HAVE_PLOCK
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3065
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3066 #ifdef HAVE_SYS_LOCK_H
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3067 #include <sys/lock.h>
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3068 #endif
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3069
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
3070 PyDoc_STRVAR(posix_plock__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
3071 "plock(op)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
3072 Lock program segments into memory.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
3073
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
3074 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
3075 posix_plock(PyObject *self, PyObject *args)
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3076 {
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3077 int op;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
3078 if (!PyArg_ParseTuple(args, "i:plock", &op))
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3079 return NULL;
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3080 if (plock(op) == -1)
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3081 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
3082 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
3083 return Py_None;
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3084 }
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3085 #endif
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
3086
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
3087
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
3088 #ifdef HAVE_POPEN
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
3089 PyDoc_STRVAR(posix_popen__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
3090 "popen(command [, mode='r' [, bufsize]]) -> pipe\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
3091 Open a pipe to/from a command returning a file object.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
3092
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3093 #if defined(PYOS_OS2)
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3094 #if defined(PYCC_VACPP)
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3095 static int
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3096 async_system(const char *command)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3097 {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3098 char *p, errormsg[256], args[1024];
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3099 RESULTCODES rcodes;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3100 APIRET rc;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3101 char *shell = getenv("COMSPEC");
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3102 if (!shell)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3103 shell = "cmd";
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3104
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3105 strcpy(args, shell);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3106 p = &args[ strlen(args)+1 ];
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3107 strcpy(p, "/c ");
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3108 strcat(p, command);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3109 p += strlen(p) + 1;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3110 *p = '\0';
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3111
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3112 rc = DosExecPgm(errormsg, sizeof(errormsg),
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3113 EXEC_ASYNC, /* Execute Async w/o Wait for Results */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3114 args,
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3115 NULL, /* Inherit Parent's Environment */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3116 &rcodes, shell);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3117 return rc;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3118 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3119
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3120 static FILE *
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3121 popen(const char *command, const char *mode, int pipesize, int *err)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3122 {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3123 HFILE rhan, whan;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3124 FILE *retfd = NULL;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3125 APIRET rc = DosCreatePipe(&rhan, &whan, pipesize);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3126
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3127 if (rc != NO_ERROR) {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3128 *err = rc;
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3129 return NULL; /* ERROR - Unable to Create Anon Pipe */
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3130 }
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3131
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3132 if (strchr(mode, 'r') != NULL) { /* Treat Command as a Data Source */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3133 int oldfd = dup(1); /* Save STDOUT Handle in Another Handle */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3134
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3135 DosEnterCritSec(); /* Stop Other Threads While Changing Handles */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3136 close(1); /* Make STDOUT Available for Reallocation */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3137
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3138 if (dup2(whan, 1) == 0) { /* Connect STDOUT to Pipe Write Side */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3139 DosClose(whan); /* Close Now-Unused Pipe Write Handle */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3140
20855
6398d1055fcf Patch #474169: Move fdopen calls out of critical section.
Martin v. Löwis <martin@v.loewis.de>
parents: 20551
diff changeset
3141 rc = async_system(command);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3142 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3143
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3144 dup2(oldfd, 1); /* Reconnect STDOUT to Original Handle */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3145 DosExitCritSec(); /* Now Allow Other Threads to Run */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3146
20855
6398d1055fcf Patch #474169: Move fdopen calls out of critical section.
Martin v. Löwis <martin@v.loewis.de>
parents: 20551
diff changeset
3147 if (rc == NO_ERROR)
6398d1055fcf Patch #474169: Move fdopen calls out of critical section.
Martin v. Löwis <martin@v.loewis.de>
parents: 20551
diff changeset
3148 retfd = fdopen(rhan, mode); /* And Return Pipe Read Handle */
6398d1055fcf Patch #474169: Move fdopen calls out of critical section.
Martin v. Löwis <martin@v.loewis.de>
parents: 20551
diff changeset
3149
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3150 close(oldfd); /* And Close Saved STDOUT Handle */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3151 return retfd; /* Return fd of Pipe or NULL if Error */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3152
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3153 } else if (strchr(mode, 'w')) { /* Treat Command as a Data Sink */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3154 int oldfd = dup(0); /* Save STDIN Handle in Another Handle */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3155
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3156 DosEnterCritSec(); /* Stop Other Threads While Changing Handles */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3157 close(0); /* Make STDIN Available for Reallocation */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3158
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3159 if (dup2(rhan, 0) == 0) { /* Connect STDIN to Pipe Read Side */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3160 DosClose(rhan); /* Close Now-Unused Pipe Read Handle */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3161
20855
6398d1055fcf Patch #474169: Move fdopen calls out of critical section.
Martin v. Löwis <martin@v.loewis.de>
parents: 20551
diff changeset
3162 rc = async_system(command);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3163 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3164
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3165 dup2(oldfd, 0); /* Reconnect STDIN to Original Handle */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3166 DosExitCritSec(); /* Now Allow Other Threads to Run */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3167
20855
6398d1055fcf Patch #474169: Move fdopen calls out of critical section.
Martin v. Löwis <martin@v.loewis.de>
parents: 20551
diff changeset
3168 if (rc == NO_ERROR)
6398d1055fcf Patch #474169: Move fdopen calls out of critical section.
Martin v. Löwis <martin@v.loewis.de>
parents: 20551
diff changeset
3169 retfd = fdopen(whan, mode); /* And Return Pipe Write Handle */
6398d1055fcf Patch #474169: Move fdopen calls out of critical section.
Martin v. Löwis <martin@v.loewis.de>
parents: 20551
diff changeset
3170
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3171 close(oldfd); /* And Close Saved STDIN Handle */
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3172 return retfd; /* Return fd of Pipe or NULL if Error */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3173
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3174 } else {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3175 *err = ERROR_INVALID_ACCESS;
6717
64a75211cf72 Patch for QNX, by Chris Herborth. Also left-aligned preprocessor
Guido van Rossum <guido@python.org>
parents: 6626
diff changeset
3176 return NULL; /* ERROR - Invalid Mode (Neither Read nor Write) */
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3177 }
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3178 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3179
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3180 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
3181 posix_popen(PyObject *self, PyObject *args)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3182 {
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3183 char *name;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3184 char *mode = "r";
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3185 int err, bufsize = -1;
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3186 FILE *fp;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3187 PyObject *f;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
3188 if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize))
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3189 return NULL;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3190 Py_BEGIN_ALLOW_THREADS
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3191 fp = popen(name, mode, (bufsize > 0) ? bufsize : 4096, &err);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3192 Py_END_ALLOW_THREADS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3193 if (fp == NULL)
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3194 return os2_error(err);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
3195
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3196 f = PyFile_FromFile(fp, name, mode, fclose);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3197 if (f != NULL)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3198 PyFile_SetBufSize(f, bufsize);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3199 return f;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3200 }
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
3201
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3202 #elif defined(PYCC_GCC)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3203
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3204 /* standard posix version of popen() support */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3205 static PyObject *
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3206 posix_popen(PyObject *self, PyObject *args)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3207 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3208 char *name;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3209 char *mode = "r";
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3210 int bufsize = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3211 FILE *fp;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3212 PyObject *f;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3213 if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize))
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3214 return NULL;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3215 Py_BEGIN_ALLOW_THREADS
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3216 fp = popen(name, mode);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3217 Py_END_ALLOW_THREADS
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3218 if (fp == NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3219 return posix_error();
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3220 f = PyFile_FromFile(fp, name, mode, pclose);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3221 if (f != NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3222 PyFile_SetBufSize(f, bufsize);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3223 return f;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3224 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3225
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3226 /* fork() under OS/2 has lots'o'warts
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3227 * EMX supports pipe() and spawn*() so we can synthesize popen[234]()
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3228 * most of this code is a ripoff of the win32 code, but using the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3229 * capabilities of EMX's C library routines
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3230 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3231
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3232 /* These tell _PyPopen() whether to return 1, 2, or 3 file objects. */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3233 #define POPEN_1 1
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3234 #define POPEN_2 2
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3235 #define POPEN_3 3
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3236 #define POPEN_4 4
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3237
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3238 static PyObject *_PyPopen(char *, int, int, int);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3239 static int _PyPclose(FILE *file);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3240
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3241 /*
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3242 * Internal dictionary mapping popen* file pointers to process handles,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3243 * for use when retrieving the process exit code. See _PyPclose() below
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3244 * for more information on this dictionary's use.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3245 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3246 static PyObject *_PyPopenProcs = NULL;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3247
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3248 /* os2emx version of popen2()
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3249 *
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3250 * The result of this function is a pipe (file) connected to the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3251 * process's stdin, and a pipe connected to the process's stdout.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3252 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3253
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3254 static PyObject *
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3255 os2emx_popen2(PyObject *self, PyObject *args)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3256 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3257 PyObject *f;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3258 int tm=0;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3259
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3260 char *cmdstring;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3261 char *mode = "t";
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3262 int bufsize = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3263 if (!PyArg_ParseTuple(args, "s|si:popen2", &cmdstring, &mode, &bufsize))
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3264 return NULL;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3265
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3266 if (*mode == 't')
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3267 tm = O_TEXT;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3268 else if (*mode != 'b') {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3269 PyErr_SetString(PyExc_ValueError, "mode must be 't' or 'b'");
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3270 return NULL;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3271 } else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3272 tm = O_BINARY;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3273
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3274 f = _PyPopen(cmdstring, tm, POPEN_2, bufsize);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3275
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3276 return f;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3277 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3278
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3279 /*
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3280 * Variation on os2emx.popen2
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3281 *
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3282 * The result of this function is 3 pipes - the process's stdin,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3283 * stdout and stderr
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3284 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3285
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3286 static PyObject *
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3287 os2emx_popen3(PyObject *self, PyObject *args)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3288 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3289 PyObject *f;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3290 int tm = 0;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3291
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3292 char *cmdstring;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3293 char *mode = "t";
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3294 int bufsize = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3295 if (!PyArg_ParseTuple(args, "s|si:popen3", &cmdstring, &mode, &bufsize))
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3296 return NULL;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3297
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3298 if (*mode == 't')
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3299 tm = O_TEXT;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3300 else if (*mode != 'b') {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3301 PyErr_SetString(PyExc_ValueError, "mode must be 't' or 'b'");
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3302 return NULL;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3303 } else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3304 tm = O_BINARY;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3305
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3306 f = _PyPopen(cmdstring, tm, POPEN_3, bufsize);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3307
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3308 return f;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3309 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3310
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3311 /*
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3312 * Variation on os2emx.popen2
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3313 *
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3314 * The result of this function is 2 pipes - the processes stdin,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3315 * and stdout+stderr combined as a single pipe.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3316 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3317
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3318 static PyObject *
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3319 os2emx_popen4(PyObject *self, PyObject *args)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3320 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3321 PyObject *f;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3322 int tm = 0;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3323
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3324 char *cmdstring;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3325 char *mode = "t";
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3326 int bufsize = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3327 if (!PyArg_ParseTuple(args, "s|si:popen4", &cmdstring, &mode, &bufsize))
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3328 return NULL;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3329
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3330 if (*mode == 't')
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3331 tm = O_TEXT;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3332 else if (*mode != 'b') {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3333 PyErr_SetString(PyExc_ValueError, "mode must be 't' or 'b'");
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3334 return NULL;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3335 } else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3336 tm = O_BINARY;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3337
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3338 f = _PyPopen(cmdstring, tm, POPEN_4, bufsize);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3339
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3340 return f;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3341 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3342
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3343 /* a couple of structures for convenient handling of multiple
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3344 * file handles and pipes
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3345 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3346 struct file_ref
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3347 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3348 int handle;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3349 int flags;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3350 };
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3351
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3352 struct pipe_ref
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3353 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3354 int rd;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3355 int wr;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3356 };
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3357
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3358 /* The following code is derived from the win32 code */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3359
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3360 static PyObject *
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3361 _PyPopen(char *cmdstring, int mode, int n, int bufsize)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3362 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3363 struct file_ref stdio[3];
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3364 struct pipe_ref p_fd[3];
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3365 FILE *p_s[3];
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3366 int file_count, i, pipe_err, pipe_pid;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3367 char *shell, *sh_name, *opt, *rd_mode, *wr_mode;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3368 PyObject *f, *p_f[3];
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3369
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3370 /* file modes for subsequent fdopen's on pipe handles */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3371 if (mode == O_TEXT)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3372 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3373 rd_mode = "rt";
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3374 wr_mode = "wt";
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3375 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3376 else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3377 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3378 rd_mode = "rb";
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3379 wr_mode = "wb";
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3380 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3381
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3382 /* prepare shell references */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3383 if ((shell = getenv("EMXSHELL")) == NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3384 if ((shell = getenv("COMSPEC")) == NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3385 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3386 errno = ENOENT;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3387 return posix_error();
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3388 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3389
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3390 sh_name = _getname(shell);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3391 if (stricmp(sh_name, "cmd.exe") == 0 || stricmp(sh_name, "4os2.exe") == 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3392 opt = "/c";
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3393 else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3394 opt = "-c";
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3395
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3396 /* save current stdio fds + their flags, and set not inheritable */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3397 i = pipe_err = 0;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3398 while (pipe_err >= 0 && i < 3)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3399 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3400 pipe_err = stdio[i].handle = dup(i);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3401 stdio[i].flags = fcntl(i, F_GETFD, 0);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3402 fcntl(stdio[i].handle, F_SETFD, stdio[i].flags | FD_CLOEXEC);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3403 i++;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3404 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3405 if (pipe_err < 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3406 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3407 /* didn't get them all saved - clean up and bail out */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3408 int saved_err = errno;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3409 while (i-- > 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3410 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3411 close(stdio[i].handle);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3412 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3413 errno = saved_err;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3414 return posix_error();
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3415 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3416
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3417 /* create pipe ends */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3418 file_count = 2;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3419 if (n == POPEN_3)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3420 file_count = 3;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3421 i = pipe_err = 0;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3422 while ((pipe_err == 0) && (i < file_count))
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3423 pipe_err = pipe((int *)&p_fd[i++]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3424 if (pipe_err < 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3425 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3426 /* didn't get them all made - clean up and bail out */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3427 while (i-- > 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3428 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3429 close(p_fd[i].wr);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3430 close(p_fd[i].rd);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3431 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3432 errno = EPIPE;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3433 return posix_error();
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3434 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3435
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3436 /* change the actual standard IO streams over temporarily,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3437 * making the retained pipe ends non-inheritable
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3438 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3439 pipe_err = 0;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3440
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3441 /* - stdin */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3442 if (dup2(p_fd[0].rd, 0) == 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3443 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3444 close(p_fd[0].rd);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3445 i = fcntl(p_fd[0].wr, F_GETFD, 0);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3446 fcntl(p_fd[0].wr, F_SETFD, i | FD_CLOEXEC);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3447 if ((p_s[0] = fdopen(p_fd[0].wr, wr_mode)) == NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3448 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3449 close(p_fd[0].wr);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3450 pipe_err = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3451 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3452 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3453 else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3454 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3455 pipe_err = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3456 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3457
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3458 /* - stdout */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3459 if (pipe_err == 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3460 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3461 if (dup2(p_fd[1].wr, 1) == 1)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3462 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3463 close(p_fd[1].wr);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3464 i = fcntl(p_fd[1].rd, F_GETFD, 0);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3465 fcntl(p_fd[1].rd, F_SETFD, i | FD_CLOEXEC);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3466 if ((p_s[1] = fdopen(p_fd[1].rd, rd_mode)) == NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3467 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3468 close(p_fd[1].rd);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3469 pipe_err = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3470 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3471 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3472 else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3473 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3474 pipe_err = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3475 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3476 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3477
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3478 /* - stderr, as required */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3479 if (pipe_err == 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3480 switch (n)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3481 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3482 case POPEN_3:
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3483 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3484 if (dup2(p_fd[2].wr, 2) == 2)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3485 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3486 close(p_fd[2].wr);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3487 i = fcntl(p_fd[2].rd, F_GETFD, 0);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3488 fcntl(p_fd[2].rd, F_SETFD, i | FD_CLOEXEC);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3489 if ((p_s[2] = fdopen(p_fd[2].rd, rd_mode)) == NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3490 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3491 close(p_fd[2].rd);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3492 pipe_err = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3493 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3494 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3495 else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3496 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3497 pipe_err = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3498 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3499 break;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3500 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3501
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3502 case POPEN_4:
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3503 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3504 if (dup2(1, 2) != 2)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3505 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3506 pipe_err = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3507 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3508 break;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3509 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3510 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3511
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3512 /* spawn the child process */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3513 if (pipe_err == 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3514 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3515 pipe_pid = spawnlp(P_NOWAIT, shell, shell, opt, cmdstring, (char *)0);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3516 if (pipe_pid == -1)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3517 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3518 pipe_err = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3519 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3520 else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3521 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3522 /* save the PID into the FILE structure
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3523 * NOTE: this implementation doesn't actually
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3524 * take advantage of this, but do it for
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3525 * completeness - AIM Apr01
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3526 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3527 for (i = 0; i < file_count; i++)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3528 p_s[i]->_pid = pipe_pid;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3529 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3530 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3531
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3532 /* reset standard IO to normal */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3533 for (i = 0; i < 3; i++)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3534 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3535 dup2(stdio[i].handle, i);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3536 fcntl(i, F_SETFD, stdio[i].flags);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3537 close(stdio[i].handle);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3538 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3539
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3540 /* if any remnant problems, clean up and bail out */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3541 if (pipe_err < 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3542 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3543 for (i = 0; i < 3; i++)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3544 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3545 close(p_fd[i].rd);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3546 close(p_fd[i].wr);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3547 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3548 errno = EPIPE;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3549 return posix_error_with_filename(cmdstring);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3550 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3551
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3552 /* build tuple of file objects to return */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3553 if ((p_f[0] = PyFile_FromFile(p_s[0], cmdstring, wr_mode, _PyPclose)) != NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3554 PyFile_SetBufSize(p_f[0], bufsize);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3555 if ((p_f[1] = PyFile_FromFile(p_s[1], cmdstring, rd_mode, _PyPclose)) != NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3556 PyFile_SetBufSize(p_f[1], bufsize);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3557 if (n == POPEN_3)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3558 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3559 if ((p_f[2] = PyFile_FromFile(p_s[2], cmdstring, rd_mode, _PyPclose)) != NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3560 PyFile_SetBufSize(p_f[0], bufsize);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3561 f = Py_BuildValue("OOO", p_f[0], p_f[1], p_f[2]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3562 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3563 else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3564 f = Py_BuildValue("OO", p_f[0], p_f[1]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3565
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3566 /*
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3567 * Insert the files we've created into the process dictionary
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3568 * all referencing the list with the process handle and the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3569 * initial number of files (see description below in _PyPclose).
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3570 * Since if _PyPclose later tried to wait on a process when all
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3571 * handles weren't closed, it could create a deadlock with the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3572 * child, we spend some energy here to try to ensure that we
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3573 * either insert all file handles into the dictionary or none
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3574 * at all. It's a little clumsy with the various popen modes
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3575 * and variable number of files involved.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3576 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3577 if (!_PyPopenProcs)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3578 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3579 _PyPopenProcs = PyDict_New();
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3580 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3581
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3582 if (_PyPopenProcs)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3583 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3584 PyObject *procObj, *pidObj, *intObj, *fileObj[3];
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3585 int ins_rc[3];
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3586
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3587 fileObj[0] = fileObj[1] = fileObj[2] = NULL;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3588 ins_rc[0] = ins_rc[1] = ins_rc[2] = 0;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3589
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3590 procObj = PyList_New(2);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3591 pidObj = PyInt_FromLong((long) pipe_pid);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3592 intObj = PyInt_FromLong((long) file_count);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3593
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3594 if (procObj && pidObj && intObj)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3595 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3596 PyList_SetItem(procObj, 0, pidObj);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3597 PyList_SetItem(procObj, 1, intObj);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3598
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3599 fileObj[0] = PyLong_FromVoidPtr(p_s[0]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3600 if (fileObj[0])
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3601 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3602 ins_rc[0] = PyDict_SetItem(_PyPopenProcs,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3603 fileObj[0],
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3604 procObj);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3605 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3606 fileObj[1] = PyLong_FromVoidPtr(p_s[1]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3607 if (fileObj[1])
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3608 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3609 ins_rc[1] = PyDict_SetItem(_PyPopenProcs,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3610 fileObj[1],
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3611 procObj);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3612 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3613 if (file_count >= 3)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3614 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3615 fileObj[2] = PyLong_FromVoidPtr(p_s[2]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3616 if (fileObj[2])
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3617 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3618 ins_rc[2] = PyDict_SetItem(_PyPopenProcs,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3619 fileObj[2],
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3620 procObj);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3621 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3622 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3623
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3624 if (ins_rc[0] < 0 || !fileObj[0] ||
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3625 ins_rc[1] < 0 || (file_count > 1 && !fileObj[1]) ||
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3626 ins_rc[2] < 0 || (file_count > 2 && !fileObj[2]))
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3627 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3628 /* Something failed - remove any dictionary
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3629 * entries that did make it.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3630 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3631 if (!ins_rc[0] && fileObj[0])
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3632 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3633 PyDict_DelItem(_PyPopenProcs,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3634 fileObj[0]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3635 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3636 if (!ins_rc[1] && fileObj[1])
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3637 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3638 PyDict_DelItem(_PyPopenProcs,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3639 fileObj[1]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3640 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3641 if (!ins_rc[2] && fileObj[2])
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3642 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3643 PyDict_DelItem(_PyPopenProcs,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3644 fileObj[2]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3645 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3646 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3647 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3648
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3649 /*
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3650 * Clean up our localized references for the dictionary keys
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3651 * and value since PyDict_SetItem will Py_INCREF any copies
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3652 * that got placed in the dictionary.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3653 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3654 Py_XDECREF(procObj);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3655 Py_XDECREF(fileObj[0]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3656 Py_XDECREF(fileObj[1]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3657 Py_XDECREF(fileObj[2]);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3658 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3659
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3660 /* Child is launched. */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3661 return f;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3662 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3663
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3664 /*
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3665 * Wrapper for fclose() to use for popen* files, so we can retrieve the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3666 * exit code for the child process and return as a result of the close.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3667 *
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3668 * This function uses the _PyPopenProcs dictionary in order to map the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3669 * input file pointer to information about the process that was
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3670 * originally created by the popen* call that created the file pointer.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3671 * The dictionary uses the file pointer as a key (with one entry
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3672 * inserted for each file returned by the original popen* call) and a
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3673 * single list object as the value for all files from a single call.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3674 * The list object contains the Win32 process handle at [0], and a file
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3675 * count at [1], which is initialized to the total number of file
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3676 * handles using that list.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3677 *
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3678 * This function closes whichever handle it is passed, and decrements
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3679 * the file count in the dictionary for the process handle pointed to
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3680 * by this file. On the last close (when the file count reaches zero),
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3681 * this function will wait for the child process and then return its
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3682 * exit code as the result of the close() operation. This permits the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3683 * files to be closed in any order - it is always the close() of the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3684 * final handle that will return the exit code.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3685 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3686
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3687 /* RED_FLAG 31-Aug-2000 Tim
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3688 * This is always called (today!) between a pair of
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3689 * Py_BEGIN_ALLOW_THREADS/ Py_END_ALLOW_THREADS
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3690 * macros. So the thread running this has no valid thread state, as
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3691 * far as Python is concerned. However, this calls some Python API
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3692 * functions that cannot be called safely without a valid thread
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3693 * state, in particular PyDict_GetItem.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3694 * As a temporary hack (although it may last for years ...), we
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3695 * *rely* on not having a valid thread state in this function, in
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3696 * order to create our own "from scratch".
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3697 * This will deadlock if _PyPclose is ever called by a thread
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3698 * holding the global lock.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3699 * (The OS/2 EMX thread support appears to cover the case where the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3700 * lock is already held - AIM Apr01)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3701 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3702
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3703 static int _PyPclose(FILE *file)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3704 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3705 int result;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3706 int exit_code;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3707 int pipe_pid;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3708 PyObject *procObj, *pidObj, *intObj, *fileObj;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3709 int file_count;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3710 #ifdef WITH_THREAD
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3711 PyInterpreterState* pInterpreterState;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3712 PyThreadState* pThreadState;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3713 #endif
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3714
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3715 /* Close the file handle first, to ensure it can't block the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3716 * child from exiting if it's the last handle.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3717 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3718 result = fclose(file);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3719
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3720 #ifdef WITH_THREAD
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3721 /* Bootstrap a valid thread state into existence. */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3722 pInterpreterState = PyInterpreterState_New();
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3723 if (!pInterpreterState) {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3724 /* Well, we're hosed now! We don't have a thread
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3725 * state, so can't call a nice error routine, or raise
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3726 * an exception. Just die.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3727 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3728 Py_FatalError("unable to allocate interpreter state "
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3729 "when closing popen object.");
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3730 return -1; /* unreachable */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3731 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3732 pThreadState = PyThreadState_New(pInterpreterState);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3733 if (!pThreadState) {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3734 Py_FatalError("unable to allocate thread state "
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3735 "when closing popen object.");
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3736 return -1; /* unreachable */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3737 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3738 /* Grab the global lock. Note that this will deadlock if the
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3739 * current thread already has the lock! (see RED_FLAG comments
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3740 * before this function)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3741 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3742 PyEval_RestoreThread(pThreadState);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3743 #endif
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3744
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3745 if (_PyPopenProcs)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3746 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3747 if ((fileObj = PyLong_FromVoidPtr(file)) != NULL &&
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3748 (procObj = PyDict_GetItem(_PyPopenProcs,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3749 fileObj)) != NULL &&
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3750 (pidObj = PyList_GetItem(procObj,0)) != NULL &&
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3751 (intObj = PyList_GetItem(procObj,1)) != NULL)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3752 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3753 pipe_pid = (int) PyInt_AsLong(pidObj);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3754 file_count = (int) PyInt_AsLong(intObj);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3755
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3756 if (file_count > 1)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3757 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3758 /* Still other files referencing process */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3759 file_count--;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3760 PyList_SetItem(procObj,1,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3761 PyInt_FromLong((long) file_count));
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3762 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3763 else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3764 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3765 /* Last file for this process */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3766 if (result != EOF &&
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3767 waitpid(pipe_pid, &exit_code, 0) == pipe_pid)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3768 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3769 /* extract exit status */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3770 if (WIFEXITED(exit_code))
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3771 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3772 result = WEXITSTATUS(exit_code);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3773 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3774 else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3775 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3776 errno = EPIPE;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3777 result = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3778 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3779 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3780 else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3781 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3782 /* Indicate failure - this will cause the file object
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3783 * to raise an I/O error and translate the last
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3784 * error code from errno. We do have a problem with
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3785 * last errors that overlap the normal errno table,
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3786 * but that's a consistent problem with the file object.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3787 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3788 result = -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3789 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3790 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3791
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3792 /* Remove this file pointer from dictionary */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3793 PyDict_DelItem(_PyPopenProcs, fileObj);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3794
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3795 if (PyDict_Size(_PyPopenProcs) == 0)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3796 {
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3797 Py_DECREF(_PyPopenProcs);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3798 _PyPopenProcs = NULL;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3799 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3800
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3801 } /* if object retrieval ok */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3802
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3803 Py_XDECREF(fileObj);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3804 } /* if _PyPopenProcs */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3805
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3806 #ifdef WITH_THREAD
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3807 /* Tear down the thread & interpreter states.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3808 * Note that interpreter state clear & delete functions automatically
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3809 * call the thread clear & delete functions, and indeed insist on
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3810 * doing that themselves. The lock must be held during the clear, but
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3811 * need not be held during the delete.
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3812 */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3813 PyInterpreterState_Clear(pInterpreterState);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3814 PyEval_ReleaseThread(pThreadState);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3815 PyInterpreterState_Delete(pInterpreterState);
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3816 #endif
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3817
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3818 return result;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3819 }
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3820
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3821 #endif /* PYCC_??? */
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
3822
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
3823 #elif defined(MS_WINDOWS)
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3824
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3825 /*
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3826 * Portable 'popen' replacement for Win32.
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3827 *
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3828 * Written by Bill Tutt <billtut@microsoft.com>. Minor tweaks
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3829 * and 2.0 integration by Fredrik Lundh <fredrik@pythonware.com>
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
3830 * Return code handling by David Bolen <db3l@fitlinxx.com>.
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3831 */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3832
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3833 #include <malloc.h>
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3834 #include <io.h>
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3835 #include <fcntl.h>
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3836
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3837 /* These tell _PyPopen() wether to return 1, 2, or 3 file objects. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3838 #define POPEN_1 1
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3839 #define POPEN_2 2
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3840 #define POPEN_3 3
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3841 #define POPEN_4 4
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3842
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3843 static PyObject *_PyPopen(char *, int, int);
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
3844 static int _PyPclose(FILE *file);
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
3845
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
3846 /*
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
3847 * Internal dictionary mapping popen* file pointers to process handles,
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
3848 * for use when retrieving the process exit code. See _PyPclose() below
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
3849 * for more information on this dictionary's use.
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
3850 */
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
3851 static PyObject *_PyPopenProcs = NULL;
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
3852
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3853
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3854 /* popen that works from a GUI.
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3855 *
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3856 * The result of this function is a pipe (file) connected to the
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3857 * processes stdin or stdout, depending on the requested mode.
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3858 */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3859
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3860 static PyObject *
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3861 posix_popen(PyObject *self, PyObject *args)
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3862 {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3863 PyObject *f, *s;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3864 int tm = 0;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3865
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3866 char *cmdstring;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3867 char *mode = "r";
13479
93ae34aa20ab - added popen.popen2/popen3/popen4 support for
Fredrik Lundh <fredrik@pythonware.com>
parents: 13478
diff changeset
3868 int bufsize = -1;
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3869 if (!PyArg_ParseTuple(args, "s|si:popen", &cmdstring, &mode, &bufsize))
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3870 return NULL;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3871
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3872 s = PyTuple_New(0);
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3873
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3874 if (*mode == 'r')
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3875 tm = _O_RDONLY;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3876 else if (*mode != 'w') {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
3877 PyErr_SetString(PyExc_ValueError, "popen() arg 2 must be 'r' or 'w'");
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3878 return NULL;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3879 } else
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3880 tm = _O_WRONLY;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3881
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3882 if (bufsize != -1) {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
3883 PyErr_SetString(PyExc_ValueError, "popen() arg 3 must be -1");
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3884 return NULL;
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3885 }
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3886
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3887 if (*(mode+1) == 't')
13479
93ae34aa20ab - added popen.popen2/popen3/popen4 support for
Fredrik Lundh <fredrik@pythonware.com>
parents: 13478
diff changeset
3888 f = _PyPopen(cmdstring, tm | _O_TEXT, POPEN_1);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3889 else if (*(mode+1) == 'b')
13479
93ae34aa20ab - added popen.popen2/popen3/popen4 support for
Fredrik Lundh <fredrik@pythonware.com>
parents: 13478
diff changeset
3890 f = _PyPopen(cmdstring, tm | _O_BINARY, POPEN_1);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3891 else
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3892 f = _PyPopen(cmdstring, tm | _O_TEXT, POPEN_1);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3893
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3894 return f;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3895 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3896
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3897 /* Variation on win32pipe.popen
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3898 *
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3899 * The result of this function is a pipe (file) connected to the
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3900 * process's stdin, and a pipe connected to the process's stdout.
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3901 */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3902
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3903 static PyObject *
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3904 win32_popen2(PyObject *self, PyObject *args)
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3905 {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3906 PyObject *f;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3907 int tm=0;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3908
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3909 char *cmdstring;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3910 char *mode = "t";
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3911 int bufsize = -1;
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3912 if (!PyArg_ParseTuple(args, "s|si:popen2", &cmdstring, &mode, &bufsize))
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3913 return NULL;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3914
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3915 if (*mode == 't')
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3916 tm = _O_TEXT;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3917 else if (*mode != 'b') {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
3918 PyErr_SetString(PyExc_ValueError, "popen2() arg 2 must be 't' or 'b'");
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3919 return NULL;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3920 } else
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3921 tm = _O_BINARY;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3922
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3923 if (bufsize != -1) {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
3924 PyErr_SetString(PyExc_ValueError, "popen2() arg 3 must be -1");
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3925 return NULL;
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3926 }
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3927
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3928 f = _PyPopen(cmdstring, tm, POPEN_2);
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3929
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3930 return f;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3931 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3932
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3933 /*
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3934 * Variation on <om win32pipe.popen>
13479
93ae34aa20ab - added popen.popen2/popen3/popen4 support for
Fredrik Lundh <fredrik@pythonware.com>
parents: 13478
diff changeset
3935 *
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3936 * The result of this function is 3 pipes - the process's stdin,
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3937 * stdout and stderr
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3938 */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3939
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3940 static PyObject *
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3941 win32_popen3(PyObject *self, PyObject *args)
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3942 {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3943 PyObject *f;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3944 int tm = 0;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3945
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3946 char *cmdstring;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3947 char *mode = "t";
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3948 int bufsize = -1;
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3949 if (!PyArg_ParseTuple(args, "s|si:popen3", &cmdstring, &mode, &bufsize))
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3950 return NULL;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3951
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3952 if (*mode == 't')
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3953 tm = _O_TEXT;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3954 else if (*mode != 'b') {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
3955 PyErr_SetString(PyExc_ValueError, "popen3() arg 2 must be 't' or 'b'");
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3956 return NULL;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3957 } else
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3958 tm = _O_BINARY;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3959
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3960 if (bufsize != -1) {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
3961 PyErr_SetString(PyExc_ValueError, "popen3() arg 3 must be -1");
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3962 return NULL;
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3963 }
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3964
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3965 f = _PyPopen(cmdstring, tm, POPEN_3);
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3966
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3967 return f;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3968 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3969
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3970 /*
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3971 * Variation on win32pipe.popen
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3972 *
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3973 * The result of this function is 2 pipes - the processes stdin,
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3974 * and stdout+stderr combined as a single pipe.
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3975 */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3976
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3977 static PyObject *
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3978 win32_popen4(PyObject *self, PyObject *args)
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3979 {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3980 PyObject *f;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3981 int tm = 0;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3982
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3983 char *cmdstring;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3984 char *mode = "t";
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3985 int bufsize = -1;
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3986 if (!PyArg_ParseTuple(args, "s|si:popen4", &cmdstring, &mode, &bufsize))
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3987 return NULL;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
3988
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3989 if (*mode == 't')
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3990 tm = _O_TEXT;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3991 else if (*mode != 'b') {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
3992 PyErr_SetString(PyExc_ValueError, "popen4() arg 2 must be 't' or 'b'");
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3993 return NULL;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3994 } else
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
3995 tm = _O_BINARY;
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3996
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3997 if (bufsize != -1) {
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
3998 PyErr_SetString(PyExc_ValueError, "popen4() arg 3 must be -1");
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
3999 return NULL;
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
4000 }
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
4001
13479
93ae34aa20ab - added popen.popen2/popen3/popen4 support for
Fredrik Lundh <fredrik@pythonware.com>
parents: 13478
diff changeset
4002 f = _PyPopen(cmdstring, tm, POPEN_4);
13478
70d351fcb8d5 - added optional bufsize argument to new popen methods.
Fredrik Lundh <fredrik@pythonware.com>
parents: 13468
diff changeset
4003
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4004 return f;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4005 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4006
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4007 static BOOL
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4008 _PyPopenCreateProcess(char *cmdstring,
13486
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4009 HANDLE hStdin,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4010 HANDLE hStdout,
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4011 HANDLE hStderr,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4012 HANDLE *hProcess)
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4013 {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4014 PROCESS_INFORMATION piProcInfo;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4015 STARTUPINFO siStartInfo;
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4016 DWORD dwProcessFlags = 0; /* no NEW_CONSOLE by default for Ctrl+C handling */
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4017 char *s1,*s2, *s3 = " /c ";
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4018 const char *szConsoleSpawn = "w9xpopen.exe";
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4019 int i;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4020 int x;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4021
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4022 if (i = GetEnvironmentVariable("COMSPEC",NULL,0)) {
19490
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4023 char *comshell;
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4024
25573
0231cc54f87e s/_alloca/alloca/g; Windows doesn't need the former, at least not unless
Tim Peters <tim.peters@gmail.com>
parents: 25536
diff changeset
4025 s1 = (char *)alloca(i);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4026 if (!(x = GetEnvironmentVariable("COMSPEC", s1, i)))
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4027 return x;
19490
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4028
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4029 /* Explicitly check if we are using COMMAND.COM. If we are
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4030 * then use the w9xpopen hack.
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4031 */
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4032 comshell = s1 + x;
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4033 while (comshell >= s1 && *comshell != '\\')
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4034 --comshell;
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4035 ++comshell;
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4036
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4037 if (GetVersion() < 0x80000000 &&
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4038 _stricmp(comshell, "command.com") != 0) {
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4039 /* NT/2000 and not using command.com. */
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4040 x = i + strlen(s3) + strlen(cmdstring) + 1;
25573
0231cc54f87e s/_alloca/alloca/g; Windows doesn't need the former, at least not unless
Tim Peters <tim.peters@gmail.com>
parents: 25536
diff changeset
4041 s2 = (char *)alloca(x);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4042 ZeroMemory(s2, x);
21094
c2150313d9d1 More sprintf -> PyOS_snprintf.
Tim Peters <tim.peters@gmail.com>
parents: 21075
diff changeset
4043 PyOS_snprintf(s2, x, "%s%s%s", s1, s3, cmdstring);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4044 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4045 else {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4046 /*
19490
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4047 * Oh gag, we're on Win9x or using COMMAND.COM. Use
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4048 * the workaround listed in KB: Q150956
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4049 */
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4050 char modulepath[_MAX_PATH];
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4051 struct stat statinfo;
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4052 GetModuleFileName(NULL, modulepath, sizeof(modulepath));
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4053 for (i = x = 0; modulepath[i]; i++)
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
4054 if (modulepath[i] == SEP)
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4055 x = i+1;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4056 modulepath[x] = '\0';
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4057 /* Create the full-name to w9xpopen, so we can test it exists */
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4058 strncat(modulepath,
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4059 szConsoleSpawn,
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4060 (sizeof(modulepath)/sizeof(modulepath[0]))
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4061 -strlen(modulepath));
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4062 if (stat(modulepath, &statinfo) != 0) {
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4063 /* Eeek - file-not-found - possibly an embedding
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4064 situation - see if we can locate it in sys.prefix
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4065 */
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4066 strncpy(modulepath,
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4067 Py_GetExecPrefix(),
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4068 sizeof(modulepath)/sizeof(modulepath[0]));
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4069 if (modulepath[strlen(modulepath)-1] != '\\')
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4070 strcat(modulepath, "\\");
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4071 strncat(modulepath,
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4072 szConsoleSpawn,
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4073 (sizeof(modulepath)/sizeof(modulepath[0]))
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4074 -strlen(modulepath));
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4075 /* No where else to look - raise an easily identifiable
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4076 error, rather than leaving Windows to report
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4077 "file not found" - as the user is probably blissfully
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4078 unaware this shim EXE is used, and it will confuse them.
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4079 (well, it confused me for a while ;-)
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4080 */
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4081 if (stat(modulepath, &statinfo) != 0) {
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4082 PyErr_Format(PyExc_RuntimeError,
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4083 "Can not locate '%s' which is needed "
19490
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4084 "for popen to work with your shell "
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4085 "or platform.",
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4086 szConsoleSpawn);
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4087 return FALSE;
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4088 }
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4089 }
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4090 x = i + strlen(s3) + strlen(cmdstring) + 1 +
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4091 strlen(modulepath) +
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4092 strlen(szConsoleSpawn) + 1;
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4093
25573
0231cc54f87e s/_alloca/alloca/g; Windows doesn't need the former, at least not unless
Tim Peters <tim.peters@gmail.com>
parents: 25536
diff changeset
4094 s2 = (char *)alloca(x);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4095 ZeroMemory(s2, x);
22773
a6f8e1286b15 Fix bugs:
Mark Hammond <mhammond@skippinet.com.au>
parents: 22462
diff changeset
4096 /* To maintain correct argument passing semantics,
a6f8e1286b15 Fix bugs:
Mark Hammond <mhammond@skippinet.com.au>
parents: 22462
diff changeset
4097 we pass the command-line as it stands, and allow
a6f8e1286b15 Fix bugs:
Mark Hammond <mhammond@skippinet.com.au>
parents: 22462
diff changeset
4098 quoting to be applied. w9xpopen.exe will then
a6f8e1286b15 Fix bugs:
Mark Hammond <mhammond@skippinet.com.au>
parents: 22462
diff changeset
4099 use its argv vector, and re-quote the necessary
a6f8e1286b15 Fix bugs:
Mark Hammond <mhammond@skippinet.com.au>
parents: 22462
diff changeset
4100 args for the ultimate child process.
a6f8e1286b15 Fix bugs:
Mark Hammond <mhammond@skippinet.com.au>
parents: 22462
diff changeset
4101 */
21094
c2150313d9d1 More sprintf -> PyOS_snprintf.
Tim Peters <tim.peters@gmail.com>
parents: 21075
diff changeset
4102 PyOS_snprintf(
c2150313d9d1 More sprintf -> PyOS_snprintf.
Tim Peters <tim.peters@gmail.com>
parents: 21075
diff changeset
4103 s2, x,
22773
a6f8e1286b15 Fix bugs:
Mark Hammond <mhammond@skippinet.com.au>
parents: 22462
diff changeset
4104 "\"%s\" %s%s%s",
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4105 modulepath,
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4106 s1,
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4107 s3,
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4108 cmdstring);
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4109 /* Not passing CREATE_NEW_CONSOLE has been known to
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4110 cause random failures on win9x. Specifically a
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4111 dialog:
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4112 "Your program accessed mem currently in use at xxx"
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4113 and a hopeful warning about the stability of your
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4114 system.
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4115 Cost is Ctrl+C wont kill children, but anyone
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4116 who cares can have a go!
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4117 */
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4118 dwProcessFlags |= CREATE_NEW_CONSOLE;
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4119 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4120 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4121
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4122 /* Could be an else here to try cmd.exe / command.com in the path
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4123 Now we'll just error out.. */
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4124 else {
19490
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4125 PyErr_SetString(PyExc_RuntimeError,
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4126 "Cannot locate a COMSPEC environment variable to "
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4127 "use as the shell");
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4128 return FALSE;
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4129 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4130
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4131 ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4132 siStartInfo.cb = sizeof(STARTUPINFO);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4133 siStartInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4134 siStartInfo.hStdInput = hStdin;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4135 siStartInfo.hStdOutput = hStdout;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4136 siStartInfo.hStdError = hStderr;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4137 siStartInfo.wShowWindow = SW_HIDE;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4138
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4139 if (CreateProcess(NULL,
13486
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4140 s2,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4141 NULL,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4142 NULL,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4143 TRUE,
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
4144 dwProcessFlags,
13486
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4145 NULL,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4146 NULL,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4147 &siStartInfo,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4148 &piProcInfo) ) {
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4149 /* Close the handles now so anyone waiting is woken. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4150 CloseHandle(piProcInfo.hThread);
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4151
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4152 /* Return process handle */
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4153 *hProcess = piProcInfo.hProcess;
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4154 return TRUE;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4155 }
19490
c6385038de39 SF patch [ #455137 ] Makes popen work with COMMAND.COM on WNT, from
Tim Peters <tim.peters@gmail.com>
parents: 19370
diff changeset
4156 win32_error("CreateProcess", s2);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4157 return FALSE;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4158 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4159
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4160 /* The following code is based off of KB: Q190351 */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4161
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4162 static PyObject *
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4163 _PyPopen(char *cmdstring, int mode, int n)
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4164 {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4165 HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr,
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4166 hChildStderrRd, hChildStderrWr, hChildStdinWrDup, hChildStdoutRdDup,
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4167 hChildStderrRdDup, hProcess; /* hChildStdoutWrDup; */
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4168
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4169 SECURITY_ATTRIBUTES saAttr;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4170 BOOL fSuccess;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4171 int fd1, fd2, fd3;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4172 FILE *f1, *f2, *f3;
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4173 long file_count;
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4174 PyObject *f;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4175
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4176 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4177 saAttr.bInheritHandle = TRUE;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4178 saAttr.lpSecurityDescriptor = NULL;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4179
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4180 if (!CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0))
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4181 return win32_error("CreatePipe", NULL);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4182
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4183 /* Create new output read handle and the input write handle. Set
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4184 * the inheritance properties to FALSE. Otherwise, the child inherits
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4185 * the these handles; resulting in non-closeable handles to the pipes
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4186 * being created. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4187 fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr,
13486
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4188 GetCurrentProcess(), &hChildStdinWrDup, 0,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4189 FALSE,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4190 DUPLICATE_SAME_ACCESS);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4191 if (!fSuccess)
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4192 return win32_error("DuplicateHandle", NULL);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4193
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4194 /* Close the inheritable version of ChildStdin
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4195 that we're using. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4196 CloseHandle(hChildStdinWr);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4197
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4198 if (!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0))
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4199 return win32_error("CreatePipe", NULL);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4200
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4201 fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
13486
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4202 GetCurrentProcess(), &hChildStdoutRdDup, 0,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4203 FALSE, DUPLICATE_SAME_ACCESS);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4204 if (!fSuccess)
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4205 return win32_error("DuplicateHandle", NULL);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4206
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4207 /* Close the inheritable version of ChildStdout
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4208 that we're using. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4209 CloseHandle(hChildStdoutRd);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4210
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4211 if (n != POPEN_4) {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4212 if (!CreatePipe(&hChildStderrRd, &hChildStderrWr, &saAttr, 0))
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4213 return win32_error("CreatePipe", NULL);
13486
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4214 fSuccess = DuplicateHandle(GetCurrentProcess(),
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4215 hChildStderrRd,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4216 GetCurrentProcess(),
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4217 &hChildStderrRdDup, 0,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4218 FALSE, DUPLICATE_SAME_ACCESS);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4219 if (!fSuccess)
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4220 return win32_error("DuplicateHandle", NULL);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4221 /* Close the inheritable version of ChildStdErr that we're using. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4222 CloseHandle(hChildStderrRd);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4223 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4224
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4225 switch (n) {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4226 case POPEN_1:
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4227 switch (mode & (_O_RDONLY | _O_TEXT | _O_BINARY | _O_WRONLY)) {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4228 case _O_WRONLY | _O_TEXT:
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4229 /* Case for writing to child Stdin in text mode. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4230 fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4231 f1 = _fdopen(fd1, "w");
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4232 f = PyFile_FromFile(f1, cmdstring, "w", _PyPclose);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4233 PyFile_SetBufSize(f, 0);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4234 /* We don't care about these pipes anymore, so close them. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4235 CloseHandle(hChildStdoutRdDup);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4236 CloseHandle(hChildStderrRdDup);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4237 break;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4238
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4239 case _O_RDONLY | _O_TEXT:
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4240 /* Case for reading from child Stdout in text mode. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4241 fd1 = _open_osfhandle((long)hChildStdoutRdDup, mode);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4242 f1 = _fdopen(fd1, "r");
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4243 f = PyFile_FromFile(f1, cmdstring, "r", _PyPclose);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4244 PyFile_SetBufSize(f, 0);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4245 /* We don't care about these pipes anymore, so close them. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4246 CloseHandle(hChildStdinWrDup);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4247 CloseHandle(hChildStderrRdDup);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4248 break;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4249
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4250 case _O_RDONLY | _O_BINARY:
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4251 /* Case for readinig from child Stdout in binary mode. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4252 fd1 = _open_osfhandle((long)hChildStdoutRdDup, mode);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4253 f1 = _fdopen(fd1, "rb");
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4254 f = PyFile_FromFile(f1, cmdstring, "rb", _PyPclose);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4255 PyFile_SetBufSize(f, 0);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4256 /* We don't care about these pipes anymore, so close them. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4257 CloseHandle(hChildStdinWrDup);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4258 CloseHandle(hChildStderrRdDup);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4259 break;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4260
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4261 case _O_WRONLY | _O_BINARY:
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4262 /* Case for writing to child Stdin in binary mode. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4263 fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4264 f1 = _fdopen(fd1, "wb");
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4265 f = PyFile_FromFile(f1, cmdstring, "wb", _PyPclose);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4266 PyFile_SetBufSize(f, 0);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4267 /* We don't care about these pipes anymore, so close them. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4268 CloseHandle(hChildStdoutRdDup);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4269 CloseHandle(hChildStderrRdDup);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4270 break;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4271 }
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4272 file_count = 1;
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4273 break;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4274
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4275 case POPEN_2:
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4276 case POPEN_4:
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4277 {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4278 char *m1, *m2;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4279 PyObject *p1, *p2;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4280
24884
c4e550702a29 SF bug 595919: popenN return only text mode pipes
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
4281 if (mode & _O_TEXT) {
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4282 m1 = "r";
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4283 m2 = "w";
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4284 } else {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4285 m1 = "rb";
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4286 m2 = "wb";
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4287 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4288
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4289 fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4290 f1 = _fdopen(fd1, m2);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4291 fd2 = _open_osfhandle((long)hChildStdoutRdDup, mode);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4292 f2 = _fdopen(fd2, m1);
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4293 p1 = PyFile_FromFile(f1, cmdstring, m2, _PyPclose);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4294 PyFile_SetBufSize(p1, 0);
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4295 p2 = PyFile_FromFile(f2, cmdstring, m1, _PyPclose);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4296 PyFile_SetBufSize(p2, 0);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4297
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4298 if (n != 4)
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4299 CloseHandle(hChildStderrRdDup);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4300
13486
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4301 f = Py_BuildValue("OO",p1,p2);
16366
38ca9cc9fc48 Fix Bug #125891 - os.popen2,3 and 4 leaked file objects on Windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 15904
diff changeset
4302 Py_XDECREF(p1);
38ca9cc9fc48 Fix Bug #125891 - os.popen2,3 and 4 leaked file objects on Windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 15904
diff changeset
4303 Py_XDECREF(p2);
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4304 file_count = 2;
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4305 break;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4306 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4307
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4308 case POPEN_3:
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4309 {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4310 char *m1, *m2;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4311 PyObject *p1, *p2, *p3;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4312
24884
c4e550702a29 SF bug 595919: popenN return only text mode pipes
Tim Peters <tim.peters@gmail.com>
parents: 24471
diff changeset
4313 if (mode & _O_TEXT) {
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4314 m1 = "r";
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4315 m2 = "w";
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4316 } else {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4317 m1 = "rb";
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4318 m2 = "wb";
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4319 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4320
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4321 fd1 = _open_osfhandle((long)hChildStdinWrDup, mode);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4322 f1 = _fdopen(fd1, m2);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4323 fd2 = _open_osfhandle((long)hChildStdoutRdDup, mode);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4324 f2 = _fdopen(fd2, m1);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4325 fd3 = _open_osfhandle((long)hChildStderrRdDup, mode);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4326 f3 = _fdopen(fd3, m1);
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4327 p1 = PyFile_FromFile(f1, cmdstring, m2, _PyPclose);
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4328 p2 = PyFile_FromFile(f2, cmdstring, m1, _PyPclose);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4329 p3 = PyFile_FromFile(f3, cmdstring, m1, _PyPclose);
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4330 PyFile_SetBufSize(p1, 0);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4331 PyFile_SetBufSize(p2, 0);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4332 PyFile_SetBufSize(p3, 0);
13486
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4333 f = Py_BuildValue("OOO",p1,p2,p3);
16366
38ca9cc9fc48 Fix Bug #125891 - os.popen2,3 and 4 leaked file objects on Windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 15904
diff changeset
4334 Py_XDECREF(p1);
38ca9cc9fc48 Fix Bug #125891 - os.popen2,3 and 4 leaked file objects on Windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 15904
diff changeset
4335 Py_XDECREF(p2);
38ca9cc9fc48 Fix Bug #125891 - os.popen2,3 and 4 leaked file objects on Windows.
Mark Hammond <mhammond@skippinet.com.au>
parents: 15904
diff changeset
4336 Py_XDECREF(p3);
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4337 file_count = 3;
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4338 break;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4339 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4340 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4341
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4342 if (n == POPEN_4) {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4343 if (!_PyPopenCreateProcess(cmdstring,
13486
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4344 hChildStdinRd,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4345 hChildStdoutWr,
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4346 hChildStdoutWr,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4347 &hProcess))
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4348 return NULL;
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4349 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4350 else {
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4351 if (!_PyPopenCreateProcess(cmdstring,
13486
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4352 hChildStdinRd,
32b686da3e51 - changed the nt.popen2 return values back to
Fredrik Lundh <fredrik@pythonware.com>
parents: 13479
diff changeset
4353 hChildStdoutWr,
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4354 hChildStderrWr,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4355 &hProcess))
16367
3c1b426b3ff4 Partial fix to [ Bug #128685 ] popen on Win9x isnt smart enough about finding w9xpopen.exe.
Mark Hammond <mhammond@skippinet.com.au>
parents: 16366
diff changeset
4356 return NULL;
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4357 }
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4358
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4359 /*
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4360 * Insert the files we've created into the process dictionary
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4361 * all referencing the list with the process handle and the
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4362 * initial number of files (see description below in _PyPclose).
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4363 * Since if _PyPclose later tried to wait on a process when all
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4364 * handles weren't closed, it could create a deadlock with the
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4365 * child, we spend some energy here to try to ensure that we
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4366 * either insert all file handles into the dictionary or none
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4367 * at all. It's a little clumsy with the various popen modes
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4368 * and variable number of files involved.
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4369 */
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4370 if (!_PyPopenProcs) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4371 _PyPopenProcs = PyDict_New();
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4372 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4373
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4374 if (_PyPopenProcs) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4375 PyObject *procObj, *hProcessObj, *intObj, *fileObj[3];
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4376 int ins_rc[3];
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4377
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4378 fileObj[0] = fileObj[1] = fileObj[2] = NULL;
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4379 ins_rc[0] = ins_rc[1] = ins_rc[2] = 0;
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4380
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4381 procObj = PyList_New(2);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4382 hProcessObj = PyLong_FromVoidPtr(hProcess);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4383 intObj = PyInt_FromLong(file_count);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4384
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4385 if (procObj && hProcessObj && intObj) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4386 PyList_SetItem(procObj,0,hProcessObj);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4387 PyList_SetItem(procObj,1,intObj);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4388
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4389 fileObj[0] = PyLong_FromVoidPtr(f1);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4390 if (fileObj[0]) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4391 ins_rc[0] = PyDict_SetItem(_PyPopenProcs,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4392 fileObj[0],
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4393 procObj);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4394 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4395 if (file_count >= 2) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4396 fileObj[1] = PyLong_FromVoidPtr(f2);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4397 if (fileObj[1]) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4398 ins_rc[1] = PyDict_SetItem(_PyPopenProcs,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4399 fileObj[1],
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4400 procObj);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4401 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4402 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4403 if (file_count >= 3) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4404 fileObj[2] = PyLong_FromVoidPtr(f3);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4405 if (fileObj[2]) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4406 ins_rc[2] = PyDict_SetItem(_PyPopenProcs,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4407 fileObj[2],
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4408 procObj);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4409 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4410 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4411
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4412 if (ins_rc[0] < 0 || !fileObj[0] ||
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4413 ins_rc[1] < 0 || (file_count > 1 && !fileObj[1]) ||
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4414 ins_rc[2] < 0 || (file_count > 2 && !fileObj[2])) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4415 /* Something failed - remove any dictionary
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4416 * entries that did make it.
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4417 */
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4418 if (!ins_rc[0] && fileObj[0]) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4419 PyDict_DelItem(_PyPopenProcs,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4420 fileObj[0]);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4421 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4422 if (!ins_rc[1] && fileObj[1]) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4423 PyDict_DelItem(_PyPopenProcs,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4424 fileObj[1]);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4425 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4426 if (!ins_rc[2] && fileObj[2]) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4427 PyDict_DelItem(_PyPopenProcs,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4428 fileObj[2]);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4429 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4430 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4431 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4432
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4433 /*
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4434 * Clean up our localized references for the dictionary keys
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4435 * and value since PyDict_SetItem will Py_INCREF any copies
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4436 * that got placed in the dictionary.
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4437 */
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4438 Py_XDECREF(procObj);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4439 Py_XDECREF(fileObj[0]);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4440 Py_XDECREF(fileObj[1]);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4441 Py_XDECREF(fileObj[2]);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4442 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4443
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4444 /* Child is launched. Close the parents copy of those pipe
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4445 * handles that only the child should have open. You need to
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4446 * make sure that no handles to the write end of the output pipe
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4447 * are maintained in this process or else the pipe will not close
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4448 * when the child process exits and the ReadFile will hang. */
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4449
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4450 if (!CloseHandle(hChildStdinRd))
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4451 return win32_error("CloseHandle", NULL);
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4452
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4453 if (!CloseHandle(hChildStdoutWr))
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4454 return win32_error("CloseHandle", NULL);
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4455
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4456 if ((n != 4) && (!CloseHandle(hChildStderrWr)))
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4457 return win32_error("CloseHandle", NULL);
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4458
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4459 return f;
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
4460 }
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4461
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4462 /*
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4463 * Wrapper for fclose() to use for popen* files, so we can retrieve the
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4464 * exit code for the child process and return as a result of the close.
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4465 *
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4466 * This function uses the _PyPopenProcs dictionary in order to map the
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4467 * input file pointer to information about the process that was
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4468 * originally created by the popen* call that created the file pointer.
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4469 * The dictionary uses the file pointer as a key (with one entry
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4470 * inserted for each file returned by the original popen* call) and a
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4471 * single list object as the value for all files from a single call.
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4472 * The list object contains the Win32 process handle at [0], and a file
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4473 * count at [1], which is initialized to the total number of file
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4474 * handles using that list.
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4475 *
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4476 * This function closes whichever handle it is passed, and decrements
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4477 * the file count in the dictionary for the process handle pointed to
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4478 * by this file. On the last close (when the file count reaches zero),
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4479 * this function will wait for the child process and then return its
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4480 * exit code as the result of the close() operation. This permits the
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4481 * files to be closed in any order - it is always the close() of the
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4482 * final handle that will return the exit code.
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4483 */
14341
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4484
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4485 /* RED_FLAG 31-Aug-2000 Tim
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4486 * This is always called (today!) between a pair of
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4487 * Py_BEGIN_ALLOW_THREADS/ Py_END_ALLOW_THREADS
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4488 * macros. So the thread running this has no valid thread state, as
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4489 * far as Python is concerned. However, this calls some Python API
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4490 * functions that cannot be called safely without a valid thread
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4491 * state, in particular PyDict_GetItem.
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4492 * As a temporary hack (although it may last for years ...), we
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4493 * *rely* on not having a valid thread state in this function, in
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4494 * order to create our own "from scratch".
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4495 * This will deadlock if _PyPclose is ever called by a thread
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4496 * holding the global lock.
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4497 */
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4498
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4499 static int _PyPclose(FILE *file)
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4500 {
13720
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4501 int result;
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4502 DWORD exit_code;
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4503 HANDLE hProcess;
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4504 PyObject *procObj, *hProcessObj, *intObj, *fileObj;
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4505 long file_count;
14341
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4506 #ifdef WITH_THREAD
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4507 PyInterpreterState* pInterpreterState;
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4508 PyThreadState* pThreadState;
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4509 #endif
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4510
13720
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4511 /* Close the file handle first, to ensure it can't block the
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4512 * child from exiting if it's the last handle.
13720
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4513 */
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4514 result = fclose(file);
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4515
14341
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4516 #ifdef WITH_THREAD
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4517 /* Bootstrap a valid thread state into existence. */
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4518 pInterpreterState = PyInterpreterState_New();
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4519 if (!pInterpreterState) {
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4520 /* Well, we're hosed now! We don't have a thread
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4521 * state, so can't call a nice error routine, or raise
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4522 * an exception. Just die.
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4523 */
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4524 Py_FatalError("unable to allocate interpreter state "
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
4525 "when closing popen object");
14341
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4526 return -1; /* unreachable */
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4527 }
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4528 pThreadState = PyThreadState_New(pInterpreterState);
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4529 if (!pThreadState) {
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4530 Py_FatalError("unable to allocate thread state "
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
4531 "when closing popen object");
14341
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4532 return -1; /* unreachable */
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4533 }
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4534 /* Grab the global lock. Note that this will deadlock if the
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4535 * current thread already has the lock! (see RED_FLAG comments
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4536 * before this function)
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4537 */
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4538 PyEval_RestoreThread(pThreadState);
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4539 #endif
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4540
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4541 if (_PyPopenProcs) {
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4542 if ((fileObj = PyLong_FromVoidPtr(file)) != NULL &&
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4543 (procObj = PyDict_GetItem(_PyPopenProcs,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4544 fileObj)) != NULL &&
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4545 (hProcessObj = PyList_GetItem(procObj,0)) != NULL &&
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4546 (intObj = PyList_GetItem(procObj,1)) != NULL) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4547
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4548 hProcess = PyLong_AsVoidPtr(hProcessObj);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4549 file_count = PyInt_AsLong(intObj);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4550
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4551 if (file_count > 1) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4552 /* Still other files referencing process */
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4553 file_count--;
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4554 PyList_SetItem(procObj,1,
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4555 PyInt_FromLong(file_count));
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4556 } else {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4557 /* Last file for this process */
13720
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4558 if (result != EOF &&
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4559 WaitForSingleObject(hProcess, INFINITE) != WAIT_FAILED &&
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4560 GetExitCodeProcess(hProcess, &exit_code)) {
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4561 /* Possible truncation here in 16-bit environments, but
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4562 * real exit codes are just the lower byte in any event.
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4563 */
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4564 result = exit_code;
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4565 } else {
13720
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4566 /* Indicate failure - this will cause the file object
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4567 * to raise an I/O error and translate the last Win32
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4568 * error code from errno. We do have a problem with
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4569 * last errors that overlap the normal errno table,
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4570 * but that's a consistent problem with the file object.
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4571 */
13720
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4572 if (result != EOF) {
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4573 /* If the error wasn't from the fclose(), then
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4574 * set errno for the file object error handling.
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4575 */
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4576 errno = GetLastError();
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4577 }
d3f694023642 - changed windows pclose to make sure we don't return before the
Fredrik Lundh <fredrik@pythonware.com>
parents: 13694
diff changeset
4578 result = -1;
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4579 }
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4580
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4581 /* Free up the native handle at this point */
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4582 CloseHandle(hProcess);
13960
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4583 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4584
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4585 /* Remove this file pointer from dictionary */
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4586 PyDict_DelItem(_PyPopenProcs, fileObj);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4587
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4588 if (PyDict_Size(_PyPopenProcs) == 0) {
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4589 Py_DECREF(_PyPopenProcs);
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4590 _PyPopenProcs = NULL;
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4591 }
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4592
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4593 } /* if object retrieval ok */
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4594
7dde74c1ebbe Patch #101032, from David Bolen:
Mark Hammond <mhammond@skippinet.com.au>
parents: 13761
diff changeset
4595 Py_XDECREF(fileObj);
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4596 } /* if _PyPopenProcs */
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4597
14341
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4598 #ifdef WITH_THREAD
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4599 /* Tear down the thread & interpreter states.
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4600 * Note that interpreter state clear & delete functions automatically
14354
0f6809eba50a Repaired damaged comments, and extra spaces in fatal error msgs we'd better
Tim Peters <tim.peters@gmail.com>
parents: 14341
diff changeset
4601 * call the thread clear & delete functions, and indeed insist on
0f6809eba50a Repaired damaged comments, and extra spaces in fatal error msgs we'd better
Tim Peters <tim.peters@gmail.com>
parents: 14341
diff changeset
4602 * doing that themselves. The lock must be held during the clear, but
0f6809eba50a Repaired damaged comments, and extra spaces in fatal error msgs we'd better
Tim Peters <tim.peters@gmail.com>
parents: 14341
diff changeset
4603 * need not be held during the delete.
14341
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4604 */
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4605 PyInterpreterState_Clear(pInterpreterState);
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4606 PyEval_ReleaseThread(pThreadState);
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4607 PyInterpreterState_Delete(pInterpreterState);
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4608 #endif
ab61c335a04d Fix test_popen2 on Windows, recently broken by changes to the dict(!)
Tim Peters <tim.peters@gmail.com>
parents: 14001
diff changeset
4609
13675
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4610 return result;
b1959f006566 -- added code to the new Windows popen functions to make close
Fredrik Lundh <fredrik@pythonware.com>
parents: 13667
diff changeset
4611 }
14354
0f6809eba50a Repaired damaged comments, and extra spaces in fatal error msgs we'd better
Tim Peters <tim.peters@gmail.com>
parents: 14341
diff changeset
4612
0f6809eba50a Repaired damaged comments, and extra spaces in fatal error msgs we'd better
Tim Peters <tim.peters@gmail.com>
parents: 14341
diff changeset
4613 #else /* which OS? */
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4614 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
4615 posix_popen(PyObject *self, PyObject *args)
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
4616 {
2114
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
4617 char *name;
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
4618 char *mode = "r";
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
4619 int bufsize = -1;
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
4620 FILE *fp;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4621 PyObject *f;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
4622 if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize))
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
4623 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4624 Py_BEGIN_ALLOW_THREADS
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
4625 fp = popen(name, mode);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4626 Py_END_ALLOW_THREADS
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
4627 if (fp == NULL)
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
4628 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4629 f = PyFile_FromFile(fp, name, mode, pclose);
2114
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
4630 if (f != NULL)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4631 PyFile_SetBufSize(f, bufsize);
2114
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
4632 return f;
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
4633 }
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
4634
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
4635 #endif /* PYOS_??? */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
4636 #endif /* HAVE_POPEN */
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
4637
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4638
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4639 #ifdef HAVE_SETUID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4640 PyDoc_STRVAR(posix_setuid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4641 "setuid(uid)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4642 Set the current process's user id.");
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4643
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4644 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
4645 posix_setuid(PyObject *self, PyObject *args)
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4646 {
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4647 int uid;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
4648 if (!PyArg_ParseTuple(args, "i:setuid", &uid))
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4649 return NULL;
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4650 if (setuid(uid) < 0)
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4651 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4652 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4653 return Py_None;
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4654 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
4655 #endif /* HAVE_SETUID */
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4656
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4657
13582
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4658 #ifdef HAVE_SETEUID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4659 PyDoc_STRVAR(posix_seteuid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4660 "seteuid(uid)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4661 Set the current process's effective user id.");
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4662
13582
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4663 static PyObject *
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4664 posix_seteuid (PyObject *self, PyObject *args)
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4665 {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4666 int euid;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4667 if (!PyArg_ParseTuple(args, "i", &euid)) {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4668 return NULL;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4669 } else if (seteuid(euid) < 0) {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4670 return posix_error();
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4671 } else {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4672 Py_INCREF(Py_None);
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4673 return Py_None;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4674 }
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4675 }
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4676 #endif /* HAVE_SETEUID */
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4677
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4678 #ifdef HAVE_SETEGID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4679 PyDoc_STRVAR(posix_setegid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4680 "setegid(gid)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4681 Set the current process's effective group id.");
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4682
13582
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4683 static PyObject *
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4684 posix_setegid (PyObject *self, PyObject *args)
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4685 {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4686 int egid;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4687 if (!PyArg_ParseTuple(args, "i", &egid)) {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4688 return NULL;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4689 } else if (setegid(egid) < 0) {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4690 return posix_error();
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4691 } else {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4692 Py_INCREF(Py_None);
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4693 return Py_None;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4694 }
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4695 }
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4696 #endif /* HAVE_SETEGID */
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4697
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4698 #ifdef HAVE_SETREUID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4699 PyDoc_STRVAR(posix_setreuid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4700 "seteuid(ruid, euid)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4701 Set the current process's real and effective user ids.");
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4702
13582
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4703 static PyObject *
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4704 posix_setreuid (PyObject *self, PyObject *args)
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4705 {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4706 int ruid, euid;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4707 if (!PyArg_ParseTuple(args, "ii", &ruid, &euid)) {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4708 return NULL;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4709 } else if (setreuid(ruid, euid) < 0) {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4710 return posix_error();
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4711 } else {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4712 Py_INCREF(Py_None);
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4713 return Py_None;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4714 }
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4715 }
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4716 #endif /* HAVE_SETREUID */
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4717
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4718 #ifdef HAVE_SETREGID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4719 PyDoc_STRVAR(posix_setregid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4720 "setegid(rgid, egid)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4721 Set the current process's real and effective group ids.");
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4722
13582
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4723 static PyObject *
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4724 posix_setregid (PyObject *self, PyObject *args)
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4725 {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4726 int rgid, egid;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4727 if (!PyArg_ParseTuple(args, "ii", &rgid, &egid)) {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4728 return NULL;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4729 } else if (setregid(rgid, egid) < 0) {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4730 return posix_error();
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4731 } else {
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4732 Py_INCREF(Py_None);
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4733 return Py_None;
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4734 }
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4735 }
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4736 #endif /* HAVE_SETREGID */
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
4737
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4738 #ifdef HAVE_SETGID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4739 PyDoc_STRVAR(posix_setgid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4740 "setgid(gid)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4741 Set the current process's group id.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4742
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4743 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
4744 posix_setgid(PyObject *self, PyObject *args)
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4745 {
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4746 int gid;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
4747 if (!PyArg_ParseTuple(args, "i:setgid", &gid))
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4748 return NULL;
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4749 if (setgid(gid) < 0)
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4750 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4751 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4752 return Py_None;
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4753 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
4754 #endif /* HAVE_SETGID */
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
4755
20508
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4756 #ifdef HAVE_SETGROUPS
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4757 PyDoc_STRVAR(posix_setgroups__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4758 "setgroups(list)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4759 Set the groups of the current process to list.");
20508
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4760
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4761 static PyObject *
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4762 posix_setgroups(PyObject *self, PyObject *args)
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4763 {
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4764 PyObject *groups;
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4765 int i, len;
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4766 gid_t grouplist[MAX_GROUPS];
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4767
20508
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4768 if (!PyArg_ParseTuple(args, "O:setgid", &groups))
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4769 return NULL;
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4770 if (!PySequence_Check(groups)) {
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4771 PyErr_SetString(PyExc_TypeError, "setgroups argument must be a sequence");
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4772 return NULL;
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4773 }
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4774 len = PySequence_Size(groups);
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4775 if (len > MAX_GROUPS) {
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4776 PyErr_SetString(PyExc_ValueError, "too many groups");
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4777 return NULL;
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4778 }
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4779 for(i = 0; i < len; i++) {
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4780 PyObject *elem;
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4781 elem = PySequence_GetItem(groups, i);
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4782 if (!elem)
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4783 return NULL;
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4784 if (!PyInt_Check(elem)) {
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4785 PyErr_SetString(PyExc_TypeError,
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4786 "groups must be integers");
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4787 Py_DECREF(elem);
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4788 return NULL;
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4789 }
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4790 /* XXX: check that value fits into gid_t. */
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4791 grouplist[i] = PyInt_AsLong(elem);
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4792 Py_DECREF(elem);
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4793 }
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4794
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4795 if (setgroups(len, grouplist) < 0)
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4796 return posix_error();
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4797 Py_INCREF(Py_None);
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4798 return Py_None;
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4799 }
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
4800 #endif /* HAVE_SETGROUPS */
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4801
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4802 #ifdef HAVE_WAITPID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4803 PyDoc_STRVAR(posix_waitpid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4804 "waitpid(pid, options) -> (pid, status)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4805 Wait for completion of a given child process.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4806
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4807 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
4808 posix_waitpid(PyObject *self, PyObject *args)
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
4809 {
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4810 int pid, options;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4811 #ifdef UNION_WAIT
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4812 union wait status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4813 #define status_i (status.w_status)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4814 #else
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4815 int status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4816 #define status_i status
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4817 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4818 status_i = 0;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4819
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
4820 if (!PyArg_ParseTuple(args, "ii:waitpid", &pid, &options))
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
4821 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4822 Py_BEGIN_ALLOW_THREADS
10056
b82a61a884cf Oops, the patch for NeXT always replaced waitpid() with wait4() --
Guido van Rossum <guido@python.org>
parents: 9970
diff changeset
4823 pid = waitpid(pid, &status, options);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4824 Py_END_ALLOW_THREADS
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
4825 if (pid == -1)
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
4826 return posix_error();
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
4827 else
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4828 return Py_BuildValue("ii", pid, status_i);
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
4829 }
21857
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4830
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4831 #elif defined(HAVE_CWAIT)
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4832
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4833 /* MS C has a variant of waitpid() that's usable for most purposes. */
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4834 PyDoc_STRVAR(posix_waitpid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4835 "waitpid(pid, options) -> (pid, status << 8)\n\n"
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4836 "Wait for completion of a given process. options is ignored on Windows.");
21857
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4837
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4838 static PyObject *
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4839 posix_waitpid(PyObject *self, PyObject *args)
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4840 {
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4841 int pid, options;
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4842 int status;
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4843
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4844 if (!PyArg_ParseTuple(args, "ii:waitpid", &pid, &options))
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4845 return NULL;
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4846 Py_BEGIN_ALLOW_THREADS
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4847 pid = _cwait(&status, pid, options);
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4848 Py_END_ALLOW_THREADS
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4849 if (pid == -1)
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4850 return posix_error();
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4851 else
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4852 /* shift the status left a byte so this is more like the
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4853 POSIX waitpid */
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4854 return Py_BuildValue("ii", pid, status << 8);
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4855 }
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
4856 #endif /* HAVE_WAITPID || HAVE_CWAIT */
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4857
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
4858 #ifdef HAVE_WAIT
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4859 PyDoc_STRVAR(posix_wait__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4860 "wait() -> (pid, status)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4861 Wait for completion of a child process.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4862
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4863 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
4864 posix_wait(PyObject *self, PyObject *noargs)
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
4865 {
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
4866 int pid;
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4867 #ifdef UNION_WAIT
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4868 union wait status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4869 #define status_i (status.w_status)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4870 #else
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4871 int status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4872 #define status_i status
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4873 #endif
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
4874
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4875 status_i = 0;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4876 Py_BEGIN_ALLOW_THREADS
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4877 pid = wait(&status);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4878 Py_END_ALLOW_THREADS
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
4879 if (pid == -1)
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
4880 return posix_error();
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
4881 else
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
4882 return Py_BuildValue("ii", pid, status_i);
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
4883 #undef status_i
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
4884 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
4885 #endif
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
4886
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4887
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4888 PyDoc_STRVAR(posix_lstat__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4889 "lstat(path) -> stat result\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4890 Like stat(path), but do not follow symbolic links.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4891
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4892 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
4893 posix_lstat(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4894 {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4895 #ifdef HAVE_LSTAT
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
4896 return posix_do_stat(self, args, "et:lstat", lstat, NULL, NULL);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4897 #else /* !HAVE_LSTAT */
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
4898 #ifdef MS_WINDOWS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
4899 return posix_do_stat(self, args, "et:lstat", STAT, "u:lstat", _wstati64);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
4900 #else
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
4901 return posix_do_stat(self, args, "et:lstat", STAT, NULL, NULL);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
4902 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4903 #endif /* !HAVE_LSTAT */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4904 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4905
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4906
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4907 #ifdef HAVE_READLINK
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4908 PyDoc_STRVAR(posix_readlink__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4909 "readlink(path) -> path\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4910 Return a string representing the path to which the symbolic link points.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4911
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4912 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
4913 posix_readlink(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4914 {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4915 char buf[MAXPATHLEN];
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
4916 char *path;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4917 int n;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
4918 if (!PyArg_ParseTuple(args, "s:readlink", &path))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4919 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4920 Py_BEGIN_ALLOW_THREADS
731
c65fc172f16d Check empty argument lists.
Guido van Rossum <guido@python.org>
parents: 658
diff changeset
4921 n = readlink(path, buf, (int) sizeof buf);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4922 Py_END_ALLOW_THREADS
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4923 if (n < 0)
8708
acf49c9def7d Several changes to support inclusion of filename in relevent
Barry Warsaw <barry@python.org>
parents: 8497
diff changeset
4924 return posix_error_with_filename(path);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4925 return PyString_FromStringAndSize(buf, n);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4926 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4927 #endif /* HAVE_READLINK */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4928
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4929
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4930 #ifdef HAVE_SYMLINK
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4931 PyDoc_STRVAR(posix_symlink__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
4932 "symlink(src, dst)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
4933 Create a symbolic link.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
4934
6971
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4935 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
4936 posix_symlink(PyObject *self, PyObject *args)
6971
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4937 {
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
4938 return posix_2str(args, "etet:symlink", symlink, NULL, NULL);
6971
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4939 }
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4940 #endif /* HAVE_SYMLINK */
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4941
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4942
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4943 #ifdef HAVE_TIMES
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4944 #ifndef HZ
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4945 #define HZ 60 /* Universal constant :-) */
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4946 #endif /* HZ */
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
4947
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4948 #if defined(PYCC_VACPP) && defined(PYOS_OS2)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4949 static long
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13642
diff changeset
4950 system_uptime(void)
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4951 {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4952 ULONG value = 0;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4953
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4954 Py_BEGIN_ALLOW_THREADS
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4955 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &value, sizeof(value));
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4956 Py_END_ALLOW_THREADS
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4957
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4958 return value;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4959 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4960
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4961 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
4962 posix_times(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
4963 {
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4964 /* Currently Only Uptime is Provided -- Others Later */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4965 return Py_BuildValue("ddddd",
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4966 (double)0 /* t.tms_utime / HZ */,
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4967 (double)0 /* t.tms_stime / HZ */,
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4968 (double)0 /* t.tms_cutime / HZ */,
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4969 (double)0 /* t.tms_cstime / HZ */,
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4970 (double)system_uptime() / 1000);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
4971 }
6971
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4972 #else /* not OS2 */
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4973 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
4974 posix_times(PyObject *self, PyObject *noargs)
793
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
4975 {
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
4976 struct tms t;
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
4977 clock_t c;
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
4978 errno = 0;
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
4979 c = times(&t);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
4980 if (c == (clock_t) -1)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
4981 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4982 return Py_BuildValue("ddddd",
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
4983 (double)t.tms_utime / HZ,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
4984 (double)t.tms_stime / HZ,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
4985 (double)t.tms_cutime / HZ,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
4986 (double)t.tms_cstime / HZ,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
4987 (double)c / HZ);
793
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
4988 }
6971
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4989 #endif /* not OS2 */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
4990 #endif /* HAVE_TIMES */
6971
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4991
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
4992
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
4993 #ifdef MS_WINDOWS
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
4994 #define HAVE_TIMES /* so the method table will pick it up */
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
4995 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
4996 posix_times(PyObject *self, PyObject *noargs)
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
4997 {
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
4998 FILETIME create, exit, kernel, user;
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
4999 HANDLE hProc;
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
5000 hProc = GetCurrentProcess();
10178
f0a57ccf233c Fixed totally bogus conversion factors used in the Win32 version of
Guido van Rossum <guido@python.org>
parents: 10133
diff changeset
5001 GetProcessTimes(hProc, &create, &exit, &kernel, &user);
f0a57ccf233c Fixed totally bogus conversion factors used in the Win32 version of
Guido van Rossum <guido@python.org>
parents: 10133
diff changeset
5002 /* The fields of a FILETIME structure are the hi and lo part
f0a57ccf233c Fixed totally bogus conversion factors used in the Win32 version of
Guido van Rossum <guido@python.org>
parents: 10133
diff changeset
5003 of a 64-bit value expressed in 100 nanosecond units.
f0a57ccf233c Fixed totally bogus conversion factors used in the Win32 version of
Guido van Rossum <guido@python.org>
parents: 10133
diff changeset
5004 1e7 is one second in such units; 1e-7 the inverse.
f0a57ccf233c Fixed totally bogus conversion factors used in the Win32 version of
Guido van Rossum <guido@python.org>
parents: 10133
diff changeset
5005 429.4967296 is 2**32 / 1e7 or 2**32 * 1e-7.
f0a57ccf233c Fixed totally bogus conversion factors used in the Win32 version of
Guido van Rossum <guido@python.org>
parents: 10133
diff changeset
5006 */
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5007 return Py_BuildValue(
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5008 "ddddd",
10178
f0a57ccf233c Fixed totally bogus conversion factors used in the Win32 version of
Guido van Rossum <guido@python.org>
parents: 10133
diff changeset
5009 (double)(kernel.dwHighDateTime*429.4967296 +
f0a57ccf233c Fixed totally bogus conversion factors used in the Win32 version of
Guido van Rossum <guido@python.org>
parents: 10133
diff changeset
5010 kernel.dwLowDateTime*1e-7),
f0a57ccf233c Fixed totally bogus conversion factors used in the Win32 version of
Guido van Rossum <guido@python.org>
parents: 10133
diff changeset
5011 (double)(user.dwHighDateTime*429.4967296 +
f0a57ccf233c Fixed totally bogus conversion factors used in the Win32 version of
Guido van Rossum <guido@python.org>
parents: 10133
diff changeset
5012 user.dwLowDateTime*1e-7),
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5013 (double)0,
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5014 (double)0,
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5015 (double)0);
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
5016 }
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
5017 #endif /* MS_WINDOWS */
6971
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
5018
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
5019 #ifdef HAVE_TIMES
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5020 PyDoc_STRVAR(posix_times__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5021 "times() -> (utime, stime, cutime, cstime, elapsed_time)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5022 Return a tuple of floating point numbers indicating process times.");
6971
bc125f0d2c5d Moved some #ifdefs around that got put in the wrong place by the
Guido van Rossum <guido@python.org>
parents: 6766
diff changeset
5023 #endif
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
5024
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5025
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
5026 #ifdef HAVE_SETSID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5027 PyDoc_STRVAR(posix_setsid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5028 "setsid()\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5029 Call the system call setsid().");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5030
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5031 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
5032 posix_setsid(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
5033 {
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5034 if (setsid() < 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5035 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5036 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5037 return Py_None;
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
5038 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
5039 #endif /* HAVE_SETSID */
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
5040
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
5041 #ifdef HAVE_SETPGID
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5042 PyDoc_STRVAR(posix_setpgid__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5043 "setpgid(pid, pgrp)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5044 Call the system call setpgid().");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5045
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5046 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5047 posix_setpgid(PyObject *self, PyObject *args)
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
5048 {
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
5049 int pid, pgrp;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5050 if (!PyArg_ParseTuple(args, "ii:setpgid", &pid, &pgrp))
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
5051 return NULL;
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5052 if (setpgid(pid, pgrp) < 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5053 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5054 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5055 return Py_None;
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5056 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
5057 #endif /* HAVE_SETPGID */
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5058
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5059
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
5060 #ifdef HAVE_TCGETPGRP
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5061 PyDoc_STRVAR(posix_tcgetpgrp__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5062 "tcgetpgrp(fd) -> pgid\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5063 Return the process group associated with the terminal given by a fd.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5064
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5065 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5066 posix_tcgetpgrp(PyObject *self, PyObject *args)
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5067 {
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5068 int fd, pgid;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5069 if (!PyArg_ParseTuple(args, "i:tcgetpgrp", &fd))
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5070 return NULL;
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5071 pgid = tcgetpgrp(fd);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5072 if (pgid < 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5073 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5074 return PyInt_FromLong((long)pgid);
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5075 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
5076 #endif /* HAVE_TCGETPGRP */
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5077
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5078
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
5079 #ifdef HAVE_TCSETPGRP
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5080 PyDoc_STRVAR(posix_tcsetpgrp__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5081 "tcsetpgrp(fd, pgid)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5082 Set the process group associated with the terminal given by a fd.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5083
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5084 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5085 posix_tcsetpgrp(PyObject *self, PyObject *args)
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5086 {
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5087 int fd, pgid;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5088 if (!PyArg_ParseTuple(args, "ii:tcsetpgrp", &fd, &pgid))
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
5089 return NULL;
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5090 if (tcsetpgrp(fd, pgid) < 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5091 return posix_error();
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
5092 Py_INCREF(Py_None);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5093 return Py_None;
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
5094 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
5095 #endif /* HAVE_TCSETPGRP */
793
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
5096
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5097 /* Functions acting on file descriptors */
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5098
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5099 PyDoc_STRVAR(posix_open__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5100 "open(filename, flag [, mode=0777]) -> fd\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5101 Open a file (for low level IO).");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5102
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5103 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5104 posix_open(PyObject *self, PyObject *args)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5105 {
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
5106 char *file = NULL;
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5107 int flag;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5108 int mode = 0777;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5109 int fd;
25535
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5110
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5111 #ifdef MS_WINDOWS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5112 if (unicode_file_names()) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5113 PyUnicodeObject *po;
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5114 if (PyArg_ParseTuple(args, "Ui|i:mkdir", &po, &flag, &mode)) {
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5115 Py_BEGIN_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5116 /* PyUnicode_AS_UNICODE OK without thread
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5117 lock as it is a simple dereference. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5118 fd = _wopen(PyUnicode_AS_UNICODE(po), flag, mode);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5119 Py_END_ALLOW_THREADS
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5120 if (fd < 0)
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5121 return posix_error();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5122 return PyInt_FromLong((long)fd);
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5123 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5124 /* Drop the argument parsing error as narrow strings
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5125 are also valid. */
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5126 PyErr_Clear();
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5127 }
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5128 #endif
861065256487 Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Mark Hammond <mhammond@skippinet.com.au>
parents: 25327
diff changeset
5129
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5130 if (!PyArg_ParseTuple(args, "eti|i",
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
5131 Py_FileSystemDefaultEncoding, &file,
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
5132 &flag, &mode))
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
5133 return NULL;
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
5134
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5135 Py_BEGIN_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5136 fd = open(file, flag, mode);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5137 Py_END_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5138 if (fd < 0)
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
5139 return posix_error_with_allocated_filename(file);
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
5140 PyMem_Free(file);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5141 return PyInt_FromLong((long)fd);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5142 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5143
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5144
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5145 PyDoc_STRVAR(posix_close__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5146 "close(fd)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5147 Close a file descriptor (for low level IO).");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5148
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5149 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5150 posix_close(PyObject *self, PyObject *args)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5151 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5152 int fd, res;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5153 if (!PyArg_ParseTuple(args, "i:close", &fd))
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5154 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5155 Py_BEGIN_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5156 res = close(fd);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5157 Py_END_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5158 if (res < 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5159 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5160 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5161 return Py_None;
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5162 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5163
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5164
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5165 PyDoc_STRVAR(posix_dup__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5166 "dup(fd) -> fd2\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5167 Return a duplicate of a file descriptor.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5168
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5169 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5170 posix_dup(PyObject *self, PyObject *args)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5171 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5172 int fd;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5173 if (!PyArg_ParseTuple(args, "i:dup", &fd))
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5174 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5175 Py_BEGIN_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5176 fd = dup(fd);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5177 Py_END_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5178 if (fd < 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5179 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5180 return PyInt_FromLong((long)fd);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5181 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5182
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5183
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5184 PyDoc_STRVAR(posix_dup2__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5185 "dup2(fd, fd2)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5186 Duplicate file descriptor.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5187
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5188 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5189 posix_dup2(PyObject *self, PyObject *args)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5190 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5191 int fd, fd2, res;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5192 if (!PyArg_ParseTuple(args, "ii:dup2", &fd, &fd2))
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5193 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5194 Py_BEGIN_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5195 res = dup2(fd, fd2);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5196 Py_END_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5197 if (res < 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5198 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5199 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5200 return Py_None;
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5201 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5202
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5203
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5204 PyDoc_STRVAR(posix_lseek__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5205 "lseek(fd, pos, how) -> newpos\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5206 Set the current position of a file descriptor.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5207
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5208 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5209 posix_lseek(PyObject *self, PyObject *args)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5210 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5211 int fd, how;
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
5212 #if defined(MS_WIN64) || defined(MS_WINDOWS)
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
5213 LONG_LONG pos, res;
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
5214 #else
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5215 off_t pos, res;
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
5216 #endif
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5217 PyObject *posobj;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5218 if (!PyArg_ParseTuple(args, "iOi:lseek", &fd, &posobj, &how))
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5219 return NULL;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5220 #ifdef SEEK_SET
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5221 /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5222 switch (how) {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5223 case 0: how = SEEK_SET; break;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5224 case 1: how = SEEK_CUR; break;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5225 case 2: how = SEEK_END; break;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5226 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
5227 #endif /* SEEK_END */
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5228
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5229 #if !defined(HAVE_LARGEFILE_SUPPORT)
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5230 pos = PyInt_AsLong(posobj);
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5231 #else
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5232 pos = PyLong_Check(posobj) ?
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5233 PyLong_AsLongLong(posobj) : PyInt_AsLong(posobj);
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5234 #endif
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5235 if (PyErr_Occurred())
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5236 return NULL;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5237
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5238 Py_BEGIN_ALLOW_THREADS
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
5239 #if defined(MS_WIN64) || defined(MS_WINDOWS)
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
5240 res = _lseeki64(fd, pos, how);
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
5241 #else
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5242 res = lseek(fd, pos, how);
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
5243 #endif
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5244 Py_END_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5245 if (res < 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5246 return posix_error();
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5247
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5248 #if !defined(HAVE_LARGEFILE_SUPPORT)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5249 return PyInt_FromLong(res);
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5250 #else
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5251 return PyLong_FromLongLong(res);
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5252 #endif
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5253 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5254
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5255
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5256 PyDoc_STRVAR(posix_read__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5257 "read(fd, buffersize) -> string\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5258 Read a file descriptor.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5259
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5260 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5261 posix_read(PyObject *self, PyObject *args)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5262 {
3667
eabbb3c1818f Avoid core dump in resizestring() on read() with 0 bytes.
Guido van Rossum <guido@python.org>
parents: 3622
diff changeset
5263 int fd, size, n;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5264 PyObject *buffer;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5265 if (!PyArg_ParseTuple(args, "ii:read", &fd, &size))
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5266 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5267 buffer = PyString_FromStringAndSize((char *)NULL, size);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5268 if (buffer == NULL)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5269 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5270 Py_BEGIN_ALLOW_THREADS
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5271 n = read(fd, PyString_AsString(buffer), size);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5272 Py_END_ALLOW_THREADS
3667
eabbb3c1818f Avoid core dump in resizestring() on read() with 0 bytes.
Guido van Rossum <guido@python.org>
parents: 3622
diff changeset
5273 if (n < 0) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5274 Py_DECREF(buffer);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5275 return posix_error();
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5276 }
3667
eabbb3c1818f Avoid core dump in resizestring() on read() with 0 bytes.
Guido van Rossum <guido@python.org>
parents: 3622
diff changeset
5277 if (n != size)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5278 _PyString_Resize(&buffer, n);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5279 return buffer;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5280 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5281
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5282
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5283 PyDoc_STRVAR(posix_write__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5284 "write(fd, string) -> byteswritten\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5285 Write a string to a file descriptor.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5286
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5287 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5288 posix_write(PyObject *self, PyObject *args)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5289 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5290 int fd, size;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5291 char *buffer;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5292 if (!PyArg_ParseTuple(args, "is#:write", &fd, &buffer, &size))
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5293 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5294 Py_BEGIN_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5295 size = write(fd, buffer, size);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5296 Py_END_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5297 if (size < 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5298 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5299 return PyInt_FromLong((long)size);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5300 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5301
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5302
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5303 PyDoc_STRVAR(posix_fstat__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5304 "fstat(fd) -> stat result\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5305 Like stat(), but for an open file descriptor.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5306
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5307 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5308 posix_fstat(PyObject *self, PyObject *args)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5309 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5310 int fd;
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
5311 STRUCT_STAT st;
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5312 int res;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5313 if (!PyArg_ParseTuple(args, "i:fstat", &fd))
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5314 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5315 Py_BEGIN_ALLOW_THREADS
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
5316 res = FSTAT(fd, &st);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5317 Py_END_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5318 if (res != 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5319 return posix_error();
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5320
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
5321 return _pystat_fromstructstat(st);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5322 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5323
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5324
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5325 PyDoc_STRVAR(posix_fdopen__doc__,
25747
4890f1bdeaa6 Fix a few docstrings, remove extra commas
Neal Norwitz <nnorwitz@gmail.com>
parents: 25694
diff changeset
5326 "fdopen(fd [, mode='r' [, bufsize]]) -> file_object\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5327 Return an open file object connected to a file descriptor.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5328
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5329 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5330 posix_fdopen(PyObject *self, PyObject *args)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5331 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5332 int fd;
2114
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
5333 char *mode = "r";
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
5334 int bufsize = -1;
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5335 FILE *fp;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5336 PyObject *f;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5337 if (!PyArg_ParseTuple(args, "i|si", &fd, &mode, &bufsize))
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5338 return NULL;
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
5339
26092
52652fb8649d Enforce valid filemode. Fixes SF Bug #623464.
Thomas Heller <theller@ctypes.org>
parents: 25991
diff changeset
5340 if (mode[0] != 'r' && mode[0] != 'w' && mode[0] != 'a') {
52652fb8649d Enforce valid filemode. Fixes SF Bug #623464.
Thomas Heller <theller@ctypes.org>
parents: 25991
diff changeset
5341 PyErr_Format(PyExc_ValueError,
52652fb8649d Enforce valid filemode. Fixes SF Bug #623464.
Thomas Heller <theller@ctypes.org>
parents: 25991
diff changeset
5342 "invalid file mode '%s'", mode);
52652fb8649d Enforce valid filemode. Fixes SF Bug #623464.
Thomas Heller <theller@ctypes.org>
parents: 25991
diff changeset
5343 return NULL;
52652fb8649d Enforce valid filemode. Fixes SF Bug #623464.
Thomas Heller <theller@ctypes.org>
parents: 25991
diff changeset
5344 }
52652fb8649d Enforce valid filemode. Fixes SF Bug #623464.
Thomas Heller <theller@ctypes.org>
parents: 25991
diff changeset
5345
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5346 Py_BEGIN_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5347 fp = fdopen(fd, mode);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5348 Py_END_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5349 if (fp == NULL)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5350 return posix_error();
25277
9b8924bd5b5c I think it makes more sense that the pseudo filename used by fdopen()
Guido van Rossum <guido@python.org>
parents: 25184
diff changeset
5351 f = PyFile_FromFile(fp, "<fdopen>", mode, fclose);
2114
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
5352 if (f != NULL)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5353 PyFile_SetBufSize(f, bufsize);
2114
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
5354 return f;
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5355 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5356
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5357 PyDoc_STRVAR(posix_isatty__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5358 "isatty(fd) -> bool\n\n\
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5359 Return True if the file descriptor 'fd' is an open file descriptor\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5360 connected to the slave end of a terminal.");
13641
38ea27455cbb new method isatty from Thomas Wouters
Skip Montanaro <skip@pobox.com>
parents: 13620
diff changeset
5361
38ea27455cbb new method isatty from Thomas Wouters
Skip Montanaro <skip@pobox.com>
parents: 13620
diff changeset
5362 static PyObject *
13642
dacc9f167e95 ANSIfy the just-checked-in isatty() wrapper.
Thomas Wouters <thomas@python.org>
parents: 13641
diff changeset
5363 posix_isatty(PyObject *self, PyObject *args)
13641
38ea27455cbb new method isatty from Thomas Wouters
Skip Montanaro <skip@pobox.com>
parents: 13620
diff changeset
5364 {
38ea27455cbb new method isatty from Thomas Wouters
Skip Montanaro <skip@pobox.com>
parents: 13620
diff changeset
5365 int fd;
38ea27455cbb new method isatty from Thomas Wouters
Skip Montanaro <skip@pobox.com>
parents: 13620
diff changeset
5366 if (!PyArg_ParseTuple(args, "i:isatty", &fd))
38ea27455cbb new method isatty from Thomas Wouters
Skip Montanaro <skip@pobox.com>
parents: 13620
diff changeset
5367 return NULL;
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5368 return PyBool_FromLong(isatty(fd));
13641
38ea27455cbb new method isatty from Thomas Wouters
Skip Montanaro <skip@pobox.com>
parents: 13620
diff changeset
5369 }
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5370
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5371 #ifdef HAVE_PIPE
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5372 PyDoc_STRVAR(posix_pipe__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5373 "pipe() -> (read_end, write_end)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5374 Create a pipe.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5375
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5376 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
5377 posix_pipe(PyObject *self, PyObject *noargs)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5378 {
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5379 #if defined(PYOS_OS2)
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5380 HFILE read, write;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5381 APIRET rc;
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5382
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5383 Py_BEGIN_ALLOW_THREADS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5384 rc = DosCreatePipe( &read, &write, 4096);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5385 Py_END_ALLOW_THREADS
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5386 if (rc != NO_ERROR)
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5387 return os2_error(rc);
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5388
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5389 return Py_BuildValue("(ii)", read, write);
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5390 #else
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
5391 #if !defined(MS_WINDOWS)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5392 int fds[2];
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5393 int res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5394 Py_BEGIN_ALLOW_THREADS
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
5395 #if defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
5396 res = pipe(fds,0,2100); /* bigger mailbox quota than 512 */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
5397 #else
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5398 res = pipe(fds);
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 26330
diff changeset
5399 #endif
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5400 Py_END_ALLOW_THREADS
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5401 if (res != 0)
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5402 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5403 return Py_BuildValue("(ii)", fds[0], fds[1]);
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
5404 #else /* MS_WINDOWS */
1815
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
5405 HANDLE read, write;
8497
0f91c0bbacc5 On Windows, make the pipe() call return Unix file descriptors instead
Guido van Rossum <guido@python.org>
parents: 6971
diff changeset
5406 int read_fd, write_fd;
1815
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
5407 BOOL ok;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5408 Py_BEGIN_ALLOW_THREADS
8497
0f91c0bbacc5 On Windows, make the pipe() call return Unix file descriptors instead
Guido van Rossum <guido@python.org>
parents: 6971
diff changeset
5409 ok = CreatePipe(&read, &write, NULL, 0);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5410 Py_END_ALLOW_THREADS
1815
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
5411 if (!ok)
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
5412 return win32_error("CreatePipe", NULL);
19568
b0f5278a2ab4 SF bug [#456252] Python should never stomp on [u]intptr_t.
Tim Peters <tim.peters@gmail.com>
parents: 19490
diff changeset
5413 read_fd = _open_osfhandle((Py_intptr_t)read, 0);
b0f5278a2ab4 SF bug [#456252] Python should never stomp on [u]intptr_t.
Tim Peters <tim.peters@gmail.com>
parents: 19490
diff changeset
5414 write_fd = _open_osfhandle((Py_intptr_t)write, 1);
8497
0f91c0bbacc5 On Windows, make the pipe() call return Unix file descriptors instead
Guido van Rossum <guido@python.org>
parents: 6971
diff changeset
5415 return Py_BuildValue("(ii)", read_fd, write_fd);
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
5416 #endif /* MS_WINDOWS */
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
5417 #endif
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
5418 }
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5419 #endif /* HAVE_PIPE */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5420
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5421
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5422 #ifdef HAVE_MKFIFO
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5423 PyDoc_STRVAR(posix_mkfifo__doc__,
25747
4890f1bdeaa6 Fix a few docstrings, remove extra commas
Neal Norwitz <nnorwitz@gmail.com>
parents: 25694
diff changeset
5424 "mkfifo(filename [, mode=0666])\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5425 Create a FIFO (a POSIX named pipe).");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5426
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5427 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5428 posix_mkfifo(PyObject *self, PyObject *args)
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5429 {
23026
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5430 char *filename;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5431 int mode = 0666;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5432 int res;
23026
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5433 if (!PyArg_ParseTuple(args, "s|i:mkfifo", &filename, &mode))
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5434 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5435 Py_BEGIN_ALLOW_THREADS
23026
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5436 res = mkfifo(filename, mode);
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5437 Py_END_ALLOW_THREADS
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5438 if (res < 0)
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5439 return posix_error();
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5440 Py_INCREF(Py_None);
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5441 return Py_None;
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5442 }
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5443 #endif
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5444
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5445
24429
f55d58ee4ea3 SF patch #584245, get python to link on OSF1 (Dec Unix)
Neal Norwitz <nnorwitz@gmail.com>
parents: 24413
diff changeset
5446 #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5447 PyDoc_STRVAR(posix_mknod__doc__,
25747
4890f1bdeaa6 Fix a few docstrings, remove extra commas
Neal Norwitz <nnorwitz@gmail.com>
parents: 25694
diff changeset
5448 "mknod(filename [, mode=0600, device])\n\n\
23026
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5449 Create a filesystem node (file, device special file or named pipe)\n\
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5450 named filename. mode specifies both the permissions to use and the\n\
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5451 type of node to be created, being combined (bitwise OR) with one of\n\
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5452 S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,\n\
25694
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5453 device defines the newly created device special file (probably using\n\
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5454 os.makedev()), otherwise it is ignored.");
23026
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5455
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5456
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5457 static PyObject *
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5458 posix_mknod(PyObject *self, PyObject *args)
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5459 {
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5460 char *filename;
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5461 int mode = 0600;
25694
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5462 int device = 0;
23026
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5463 int res;
25991
19762a4936fc Remove extra argument in mknod. Fixes #632628.
Martin v. Löwis <martin@v.loewis.de>
parents: 25810
diff changeset
5464 if (!PyArg_ParseTuple(args, "s|ii:mknod", &filename, &mode, &device))
23026
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5465 return NULL;
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
5466 Py_BEGIN_ALLOW_THREADS
25694
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5467 res = mknod(filename, mode, device);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5468 Py_END_ALLOW_THREADS
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5469 if (res < 0)
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5470 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5471 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5472 return Py_None;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5473 }
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5474 #endif
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5475
25694
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5476 #ifdef HAVE_DEVICE_MACROS
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5477 PyDoc_STRVAR(posix_major__doc__,
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5478 "major(device) -> major number\n\
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5479 Extracts a device major number from a raw device number.");
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5480
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5481 static PyObject *
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5482 posix_major(PyObject *self, PyObject *args)
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5483 {
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5484 int device;
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5485 if (!PyArg_ParseTuple(args, "i:major", &device))
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5486 return NULL;
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5487 return PyInt_FromLong((long)major(device));
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5488 }
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5489
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5490 PyDoc_STRVAR(posix_minor__doc__,
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5491 "minor(device) -> minor number\n\
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5492 Extracts a device minor number from a raw device number.");
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5493
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5494 static PyObject *
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5495 posix_minor(PyObject *self, PyObject *args)
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5496 {
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5497 int device;
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5498 if (!PyArg_ParseTuple(args, "i:minor", &device))
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5499 return NULL;
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5500 return PyInt_FromLong((long)minor(device));
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5501 }
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5502
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5503 PyDoc_STRVAR(posix_makedev__doc__,
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5504 "makedev(major, minor) -> device number\n\
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5505 Composes a raw device number from the major and minor device numbers.");
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5506
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5507 static PyObject *
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5508 posix_makedev(PyObject *self, PyObject *args)
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5509 {
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5510 int major, minor;
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5511 if (!PyArg_ParseTuple(args, "ii:makedev", &major, &minor))
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5512 return NULL;
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5513 return PyInt_FromLong((long)makedev(major, minor));
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5514 }
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5515 #endif /* device macros */
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
5516
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5517
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5518 #ifdef HAVE_FTRUNCATE
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5519 PyDoc_STRVAR(posix_ftruncate__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5520 "ftruncate(fd, length)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5521 Truncate a file to a specified length.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5522
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5523 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5524 posix_ftruncate(PyObject *self, PyObject *args)
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5525 {
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5526 int fd;
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5527 off_t length;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5528 int res;
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5529 PyObject *lenobj;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5530
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5531 if (!PyArg_ParseTuple(args, "iO:ftruncate", &fd, &lenobj))
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5532 return NULL;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5533
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5534 #if !defined(HAVE_LARGEFILE_SUPPORT)
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5535 length = PyInt_AsLong(lenobj);
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5536 #else
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5537 length = PyLong_Check(lenobj) ?
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5538 PyLong_AsLongLong(lenobj) : PyInt_AsLong(lenobj);
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5539 #endif
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5540 if (PyErr_Occurred())
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5541 return NULL;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5542
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5543 Py_BEGIN_ALLOW_THREADS
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5544 res = ftruncate(fd, length);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5545 Py_END_ALLOW_THREADS
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5546 if (res < 0) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5547 PyErr_SetFromErrno(PyExc_IOError);
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5548 return NULL;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5549 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5550 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5551 return Py_None;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5552 }
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
5553 #endif
793
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
5554
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5555 #ifdef HAVE_PUTENV
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5556 PyDoc_STRVAR(posix_putenv__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5557 "putenv(key, value)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5558 Change or add an environment variable.");
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
5559
11230
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5560 /* Save putenv() parameters as values here, so we can collect them when they
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5561 * get re-set with another call for the same key. */
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5562 static PyObject *posix_putenv_garbage;
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5563
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5564 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5565 posix_putenv(PyObject *self, PyObject *args)
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5566 {
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5567 char *s1, *s2;
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5568 char *new;
11230
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5569 PyObject *newstr;
21172
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
5570 size_t len;
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5571
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5572 if (!PyArg_ParseTuple(args, "ss:putenv", &s1, &s2))
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5573 return NULL;
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5574
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5575 #if defined(PYOS_OS2)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5576 if (stricmp(s1, "BEGINLIBPATH") == 0) {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5577 APIRET rc;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5578
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5579 if (strlen(s2) == 0) /* If New Value is an Empty String */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5580 s2 = NULL; /* Then OS/2 API Wants a NULL to Undefine It */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5581
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5582 rc = DosSetExtLIBPATH(s2, BEGIN_LIBPATH);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5583 if (rc != NO_ERROR)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5584 return os2_error(rc);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5585
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5586 } else if (stricmp(s1, "ENDLIBPATH") == 0) {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5587 APIRET rc;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5588
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5589 if (strlen(s2) == 0) /* If New Value is an Empty String */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5590 s2 = NULL; /* Then OS/2 API Wants a NULL to Undefine It */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5591
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5592 rc = DosSetExtLIBPATH(s2, END_LIBPATH);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5593 if (rc != NO_ERROR)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5594 return os2_error(rc);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5595 } else {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5596 #endif
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5597
11230
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5598 /* XXX This can leak memory -- not easy to fix :-( */
21172
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
5599 len = strlen(s1) + strlen(s2) + 2;
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
5600 /* len includes space for a trailing \0; the size arg to
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
5601 PyString_FromStringAndSize does not count that */
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
5602 newstr = PyString_FromStringAndSize(NULL, (int)len - 1);
11230
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5603 if (newstr == NULL)
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5604 return PyErr_NoMemory();
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5605 new = PyString_AS_STRING(newstr);
21172
df2ffb0cd6bb posix_execve(), posix_spawnve(), posix_putenv():
Tim Peters <tim.peters@gmail.com>
parents: 21094
diff changeset
5606 PyOS_snprintf(new, len, "%s=%s", s1, s2);
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5607 if (putenv(new)) {
27780
dd1130253f10 Fix memory leak of newstr when putenv() fails
Neal Norwitz <nnorwitz@gmail.com>
parents: 27199
diff changeset
5608 Py_DECREF(newstr);
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5609 posix_error();
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5610 return NULL;
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5611 }
11230
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5612 /* Install the first arg and newstr in posix_putenv_garbage;
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5613 * this will cause previous value to be collected. This has to
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5614 * happen after the real putenv() call because the old value
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5615 * was still accessible until then. */
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5616 if (PyDict_SetItem(posix_putenv_garbage,
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5617 PyTuple_GET_ITEM(args, 0), newstr)) {
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5618 /* really not much we can do; just leak */
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5619 PyErr_Clear();
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5620 }
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5621 else {
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5622 Py_DECREF(newstr);
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
5623 }
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5624
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5625 #if defined(PYOS_OS2)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5626 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
5627 #endif
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5628 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
5629 return Py_None;
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5630 }
6315
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5631 #endif /* putenv */
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5632
20551
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5633 #ifdef HAVE_UNSETENV
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5634 PyDoc_STRVAR(posix_unsetenv__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5635 "unsetenv(key)\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5636 Delete an environment variable.");
20551
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5637
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5638 static PyObject *
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5639 posix_unsetenv(PyObject *self, PyObject *args)
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5640 {
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5641 char *s1;
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5642
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5643 if (!PyArg_ParseTuple(args, "s:unsetenv", &s1))
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5644 return NULL;
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5645
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5646 unsetenv(s1);
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5647
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5648 /* Remove the key from posix_putenv_garbage;
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5649 * this will cause it to be collected. This has to
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5650 * happen after the real unsetenv() call because the
20551
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5651 * old value was still accessible until then.
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5652 */
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5653 if (PyDict_DelItem(posix_putenv_garbage,
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5654 PyTuple_GET_ITEM(args, 0))) {
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5655 /* really not much we can do; just leak */
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5656 PyErr_Clear();
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5657 }
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5658
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5659 Py_INCREF(Py_None);
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5660 return Py_None;
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5661 }
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5662 #endif /* unsetenv */
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
5663
6315
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5664 #ifdef HAVE_STRERROR
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5665 PyDoc_STRVAR(posix_strerror__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5666 "strerror(code) -> string\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5667 Translate an error code to a message string.");
6315
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5668
17518
f939ce52a734 Make some private symbols static.
Guido van Rossum <guido@python.org>
parents: 17419
diff changeset
5669 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5670 posix_strerror(PyObject *self, PyObject *args)
6315
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5671 {
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5672 int code;
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5673 char *message;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5674 if (!PyArg_ParseTuple(args, "i:strerror", &code))
6315
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5675 return NULL;
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5676 message = strerror(code);
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5677 if (message == NULL) {
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5678 PyErr_SetString(PyExc_ValueError,
15318
8aa947e1eee8 Ka-Ping Yee <ping@lfw.org>:
Fred Drake <fdrake@acm.org>
parents: 14995
diff changeset
5679 "strerror() argument out of range");
6315
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5680 return NULL;
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5681 }
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5682 return PyString_FromString(message);
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5683 }
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5684 #endif /* strerror */
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
5685
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
5686
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5687 #ifdef HAVE_SYS_WAIT_H
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5688
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5689 #ifdef WCOREDUMP
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5690 PyDoc_STRVAR(posix_WCOREDUMP__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5691 "WCOREDUMP(status) -> bool\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5692 Return True if the process returning 'status' was dumped to a core file.");
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5693
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5694 static PyObject *
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5695 posix_WCOREDUMP(PyObject *self, PyObject *args)
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5696 {
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5697 #ifdef UNION_WAIT
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5698 union wait status;
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5699 #define status_i (status.w_status)
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5700 #else
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5701 int status;
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5702 #define status_i status
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5703 #endif
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5704 status_i = 0;
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5705
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5706 if (!PyArg_ParseTuple(args, "i:WCOREDUMP", &status_i))
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5707 {
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5708 return NULL;
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5709 }
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5710
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5711 return PyBool_FromLong(WCOREDUMP(status));
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5712 #undef status_i
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5713 }
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5714 #endif /* WCOREDUMP */
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5715
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5716 #ifdef WIFCONTINUED
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5717 PyDoc_STRVAR(posix_WIFCONTINUED__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5718 "WIFCONTINUED(status) -> bool\n\n\
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5719 Return True if the process returning 'status' was continued from a\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5720 job control stop.");
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5721
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5722 static PyObject *
23379
e5df086ed455 Rename posix_WCONTINUED to posix_WIFCONTINUED, call WIFCONTINUED inside,
Martin v. Löwis <martin@v.loewis.de>
parents: 23242
diff changeset
5723 posix_WIFCONTINUED(PyObject *self, PyObject *args)
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5724 {
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5725 #ifdef UNION_WAIT
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5726 union wait status;
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5727 #define status_i (status.w_status)
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5728 #else
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5729 int status;
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5730 #define status_i status
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5731 #endif
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5732 status_i = 0;
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5733
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5734 if (!PyArg_ParseTuple(args, "i:WCONTINUED", &status_i))
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5735 {
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5736 return NULL;
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5737 }
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5738
23379
e5df086ed455 Rename posix_WCONTINUED to posix_WIFCONTINUED, call WIFCONTINUED inside,
Martin v. Löwis <martin@v.loewis.de>
parents: 23242
diff changeset
5739 return PyBool_FromLong(WIFCONTINUED(status));
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5740 #undef status_i
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5741 }
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5742 #endif /* WIFCONTINUED */
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5743
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5744 #ifdef WIFSTOPPED
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5745 PyDoc_STRVAR(posix_WIFSTOPPED__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5746 "WIFSTOPPED(status) -> bool\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5747 Return True if the process returning 'status' was stopped.");
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5748
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5749 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5750 posix_WIFSTOPPED(PyObject *self, PyObject *args)
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5751 {
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5752 #ifdef UNION_WAIT
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5753 union wait status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5754 #define status_i (status.w_status)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5755 #else
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5756 int status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5757 #define status_i status
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5758 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5759 status_i = 0;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5760
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5761 if (!PyArg_ParseTuple(args, "i:WIFSTOPPED", &status_i))
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5762 {
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5763 return NULL;
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5764 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5765
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5766 return PyBool_FromLong(WIFSTOPPED(status));
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5767 #undef status_i
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5768 }
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5769 #endif /* WIFSTOPPED */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5770
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5771 #ifdef WIFSIGNALED
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5772 PyDoc_STRVAR(posix_WIFSIGNALED__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5773 "WIFSIGNALED(status) -> bool\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5774 Return True if the process returning 'status' was terminated by a signal.");
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5775
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5776 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5777 posix_WIFSIGNALED(PyObject *self, PyObject *args)
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5778 {
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5779 #ifdef UNION_WAIT
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5780 union wait status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5781 #define status_i (status.w_status)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5782 #else
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5783 int status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5784 #define status_i status
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5785 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5786 status_i = 0;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5787
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5788 if (!PyArg_ParseTuple(args, "i:WIFSIGNALED", &status_i))
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5789 {
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5790 return NULL;
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5791 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5792
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5793 return PyBool_FromLong(WIFSIGNALED(status));
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5794 #undef status_i
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5795 }
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5796 #endif /* WIFSIGNALED */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5797
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5798 #ifdef WIFEXITED
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5799 PyDoc_STRVAR(posix_WIFEXITED__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5800 "WIFEXITED(status) -> bool\n\n\
10073
1e21e22453dc Added documentation to the docstrings for the W*() functions that take
Fred Drake <fdrake@acm.org>
parents: 10069
diff changeset
5801 Return true if the process returning 'status' exited using the exit()\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5802 system call.");
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5803
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5804 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5805 posix_WIFEXITED(PyObject *self, PyObject *args)
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5806 {
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5807 #ifdef UNION_WAIT
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5808 union wait status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5809 #define status_i (status.w_status)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5810 #else
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5811 int status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5812 #define status_i status
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5813 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5814 status_i = 0;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5815
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5816 if (!PyArg_ParseTuple(args, "i:WIFEXITED", &status_i))
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5817 {
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5818 return NULL;
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5819 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5820
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
5821 return PyBool_FromLong(WIFEXITED(status));
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5822 #undef status_i
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5823 }
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5824 #endif /* WIFEXITED */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5825
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5826 #ifdef WEXITSTATUS
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5827 PyDoc_STRVAR(posix_WEXITSTATUS__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5828 "WEXITSTATUS(status) -> integer\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5829 Return the process return code from 'status'.");
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5830
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5831 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5832 posix_WEXITSTATUS(PyObject *self, PyObject *args)
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5833 {
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5834 #ifdef UNION_WAIT
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5835 union wait status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5836 #define status_i (status.w_status)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5837 #else
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5838 int status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5839 #define status_i status
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5840 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5841 status_i = 0;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5842
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5843 if (!PyArg_ParseTuple(args, "i:WEXITSTATUS", &status_i))
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5844 {
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5845 return NULL;
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5846 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5847
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5848 return Py_BuildValue("i", WEXITSTATUS(status));
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5849 #undef status_i
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5850 }
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5851 #endif /* WEXITSTATUS */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5852
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5853 #ifdef WTERMSIG
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5854 PyDoc_STRVAR(posix_WTERMSIG__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5855 "WTERMSIG(status) -> integer\n\n\
10073
1e21e22453dc Added documentation to the docstrings for the W*() functions that take
Fred Drake <fdrake@acm.org>
parents: 10069
diff changeset
5856 Return the signal that terminated the process that provided the 'status'\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5857 value.");
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5858
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5859 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5860 posix_WTERMSIG(PyObject *self, PyObject *args)
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5861 {
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5862 #ifdef UNION_WAIT
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5863 union wait status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5864 #define status_i (status.w_status)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5865 #else
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5866 int status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5867 #define status_i status
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5868 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5869 status_i = 0;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5870
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5871 if (!PyArg_ParseTuple(args, "i:WTERMSIG", &status_i))
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5872 {
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5873 return NULL;
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5874 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5875
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5876 return Py_BuildValue("i", WTERMSIG(status));
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5877 #undef status_i
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5878 }
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5879 #endif /* WTERMSIG */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5880
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5881 #ifdef WSTOPSIG
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5882 PyDoc_STRVAR(posix_WSTOPSIG__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5883 "WSTOPSIG(status) -> integer\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5884 Return the signal that stopped the process that provided\n\
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5885 the 'status' value.");
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5886
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5887 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5888 posix_WSTOPSIG(PyObject *self, PyObject *args)
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5889 {
9970
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5890 #ifdef UNION_WAIT
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5891 union wait status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5892 #define status_i (status.w_status)
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5893 #else
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5894 int status;
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5895 #define status_i status
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5896 #endif
8efa37a770c6 Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents: 9954
diff changeset
5897 status_i = 0;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5898
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5899 if (!PyArg_ParseTuple(args, "i:WSTOPSIG", &status_i))
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5900 {
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5901 return NULL;
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5902 }
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5903
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5904 return Py_BuildValue("i", WSTOPSIG(status));
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5905 #undef status_i
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5906 }
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5907 #endif /* WSTOPSIG */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5908
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5909 #endif /* HAVE_SYS_WAIT_H */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5910
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
5911
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5912 #if defined(HAVE_FSTATVFS)
11391
5486dcf13d77 John DuBois tells us that SCO OpenServer 5.0 and later requires _SVID3
Guido van Rossum <guido@python.org>
parents: 11230
diff changeset
5913 #ifdef _SCO_DS
5486dcf13d77 John DuBois tells us that SCO OpenServer 5.0 and later requires _SVID3
Guido van Rossum <guido@python.org>
parents: 11230
diff changeset
5914 /* SCO OpenServer 5.0 and later requires _SVID3 before it reveals the
5486dcf13d77 John DuBois tells us that SCO OpenServer 5.0 and later requires _SVID3
Guido van Rossum <guido@python.org>
parents: 11230
diff changeset
5915 needed definitions in sys/statvfs.h */
5486dcf13d77 John DuBois tells us that SCO OpenServer 5.0 and later requires _SVID3
Guido van Rossum <guido@python.org>
parents: 11230
diff changeset
5916 #define _SVID3
5486dcf13d77 John DuBois tells us that SCO OpenServer 5.0 and later requires _SVID3
Guido van Rossum <guido@python.org>
parents: 11230
diff changeset
5917 #endif
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5918 #include <sys/statvfs.h>
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5919
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5920 static PyObject*
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5921 _pystatvfs_fromstructstatvfs(struct statvfs st) {
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5922 PyObject *v = PyStructSequence_New(&StatVFSResultType);
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5923 if (v == NULL)
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5924 return NULL;
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5925
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5926 #if !defined(HAVE_LARGEFILE_SUPPORT)
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5927 PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5928 PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5929 PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long) st.f_blocks));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5930 PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long) st.f_bfree));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5931 PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long) st.f_bavail));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5932 PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long) st.f_files));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5933 PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong((long) st.f_ffree));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5934 PyStructSequence_SET_ITEM(v, 7, PyInt_FromLong((long) st.f_favail));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5935 PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5936 PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5937 #else
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5938 PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long) st.f_bsize));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5939 PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long) st.f_frsize));
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5940 PyStructSequence_SET_ITEM(v, 2,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5941 PyLong_FromLongLong((LONG_LONG) st.f_blocks));
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5942 PyStructSequence_SET_ITEM(v, 3,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5943 PyLong_FromLongLong((LONG_LONG) st.f_bfree));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5944 PyStructSequence_SET_ITEM(v, 4,
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5945 PyLong_FromLongLong((LONG_LONG) st.f_bavail));
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5946 PyStructSequence_SET_ITEM(v, 5,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5947 PyLong_FromLongLong((LONG_LONG) st.f_files));
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5948 PyStructSequence_SET_ITEM(v, 6,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5949 PyLong_FromLongLong((LONG_LONG) st.f_ffree));
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
5950 PyStructSequence_SET_ITEM(v, 7,
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5951 PyLong_FromLongLong((LONG_LONG) st.f_favail));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5952 PyStructSequence_SET_ITEM(v, 8, PyInt_FromLong((long) st.f_flag));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5953 PyStructSequence_SET_ITEM(v, 9, PyInt_FromLong((long) st.f_namemax));
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5954 #endif
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5955
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5956 return v;
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5957 }
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5958
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5959 PyDoc_STRVAR(posix_fstatvfs__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5960 "fstatvfs(fd) -> statvfs result\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5961 Perform an fstatvfs system call on the given fd.");
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5962
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5963 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5964 posix_fstatvfs(PyObject *self, PyObject *args)
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5965 {
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5966 int fd, res;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5967 struct statvfs st;
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5968
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5969 if (!PyArg_ParseTuple(args, "i:fstatvfs", &fd))
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5970 return NULL;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5971 Py_BEGIN_ALLOW_THREADS
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5972 res = fstatvfs(fd, &st);
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5973 Py_END_ALLOW_THREADS
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5974 if (res != 0)
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5975 return posix_error();
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5976
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
5977 return _pystatvfs_fromstructstatvfs(st);
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5978 }
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5979 #endif /* HAVE_FSTATVFS */
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5980
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5981
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5982 #if defined(HAVE_STATVFS)
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5983 #include <sys/statvfs.h>
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5984
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5985 PyDoc_STRVAR(posix_statvfs__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
5986 "statvfs(path) -> statvfs result\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
5987 Perform a statvfs system call on the given path.");
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5988
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5989 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
5990 posix_statvfs(PyObject *self, PyObject *args)
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5991 {
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5992 char *path;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5993 int res;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5994 struct statvfs st;
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
5995 if (!PyArg_ParseTuple(args, "s:statvfs", &path))
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5996 return NULL;
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5997 Py_BEGIN_ALLOW_THREADS
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5998 res = statvfs(path, &st);
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
5999 Py_END_ALLOW_THREADS
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
6000 if (res != 0)
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
6001 return posix_error_with_filename(path);
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
6002
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
6003 return _pystatvfs_fromstructstatvfs(st);
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
6004 }
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
6005 #endif /* HAVE_STATVFS */
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
6006
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
6007
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6008 #ifdef HAVE_TEMPNAM
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6009 PyDoc_STRVAR(posix_tempnam__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
6010 "tempnam([dir[, prefix]]) -> string\n\n\
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6011 Return a unique name for a temporary file.\n\
24430
14bd5ab0cdb6 Fix docstring to be consistent with parameter name (prefix)
Neal Norwitz <nnorwitz@gmail.com>
parents: 24429
diff changeset
6012 The directory and a prefix may be specified as strings; they may be omitted\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6013 or None if not needed.");
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6014
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6015 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
6016 posix_tempnam(PyObject *self, PyObject *args)
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6017 {
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6018 PyObject *result = NULL;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6019 char *dir = NULL;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6020 char *pfx = NULL;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6021 char *name;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6022
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6023 if (!PyArg_ParseTuple(args, "|zz:tempnam", &dir, &pfx))
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6024 return NULL;
19370
bafbe5cc941f added warnings about security risk of using tmpnam and tempnam
Skip Montanaro <skip@pobox.com>
parents: 18835
diff changeset
6025
bafbe5cc941f added warnings about security risk of using tmpnam and tempnam
Skip Montanaro <skip@pobox.com>
parents: 18835
diff changeset
6026 if (PyErr_Warn(PyExc_RuntimeWarning,
bafbe5cc941f added warnings about security risk of using tmpnam and tempnam
Skip Montanaro <skip@pobox.com>
parents: 18835
diff changeset
6027 "tempnam is a potential security risk to your program") < 0)
bafbe5cc941f added warnings about security risk of using tmpnam and tempnam
Skip Montanaro <skip@pobox.com>
parents: 18835
diff changeset
6028 return NULL;
bafbe5cc941f added warnings about security risk of using tmpnam and tempnam
Skip Montanaro <skip@pobox.com>
parents: 18835
diff changeset
6029
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
6030 #ifdef MS_WINDOWS
18674
9ee8f16b0e27 On Windows, tempnam() is spelled with a leading underscore.
Fred Drake <fdrake@acm.org>
parents: 18486
diff changeset
6031 name = _tempnam(dir, pfx);
9ee8f16b0e27 On Windows, tempnam() is spelled with a leading underscore.
Fred Drake <fdrake@acm.org>
parents: 18486
diff changeset
6032 #else
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6033 name = tempnam(dir, pfx);
18674
9ee8f16b0e27 On Windows, tempnam() is spelled with a leading underscore.
Fred Drake <fdrake@acm.org>
parents: 18486
diff changeset
6034 #endif
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6035 if (name == NULL)
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6036 return PyErr_NoMemory();
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6037 result = PyString_FromString(name);
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6038 free(name);
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6039 return result;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6040 }
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6041 #endif
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6042
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6043
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6044 #ifdef HAVE_TMPFILE
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6045 PyDoc_STRVAR(posix_tmpfile__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
6046 "tmpfile() -> file object\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6047 Create a temporary file with no directory entries.");
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6048
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6049 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
6050 posix_tmpfile(PyObject *self, PyObject *noargs)
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6051 {
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6052 FILE *fp;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6053
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6054 fp = tmpfile();
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6055 if (fp == NULL)
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6056 return posix_error();
23761
94d0dc9d6e44 SF bug 563750 (Alex Martelli): posix_tmpfile():
Guido van Rossum <guido@python.org>
parents: 23379
diff changeset
6057 return PyFile_FromFile(fp, "<tmpfile>", "w+b", fclose);
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6058 }
9939
faf351e31571 Only do ttyname() when HAVE_TTYNAME is defined.
Guido van Rossum <guido@python.org>
parents: 9824
diff changeset
6059 #endif
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6060
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6061
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6062 #ifdef HAVE_TMPNAM
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6063 PyDoc_STRVAR(posix_tmpnam__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
6064 "tmpnam() -> string\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6065 Return a unique name for a temporary file.");
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6066
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6067 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
6068 posix_tmpnam(PyObject *self, PyObject *noargs)
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6069 {
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6070 char buffer[L_tmpnam];
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6071 char *name;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6072
19370
bafbe5cc941f added warnings about security risk of using tmpnam and tempnam
Skip Montanaro <skip@pobox.com>
parents: 18835
diff changeset
6073 if (PyErr_Warn(PyExc_RuntimeWarning,
bafbe5cc941f added warnings about security risk of using tmpnam and tempnam
Skip Montanaro <skip@pobox.com>
parents: 18835
diff changeset
6074 "tmpnam is a potential security risk to your program") < 0)
bafbe5cc941f added warnings about security risk of using tmpnam and tempnam
Skip Montanaro <skip@pobox.com>
parents: 18835
diff changeset
6075 return NULL;
bafbe5cc941f added warnings about security risk of using tmpnam and tempnam
Skip Montanaro <skip@pobox.com>
parents: 18835
diff changeset
6076
11893
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
6077 #ifdef USE_TMPNAM_R
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6078 name = tmpnam_r(buffer);
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6079 #else
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6080 name = tmpnam(buffer);
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6081 #endif
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6082 if (name == NULL) {
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6083 PyErr_SetObject(PyExc_OSError,
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6084 Py_BuildValue("is", 0,
11893
610d7d642917 Second attempt to fix the ctermid_r/tmpnam_r warnings: define USE_CTERMID_R
Greg Ward <gward@python.net>
parents: 11892
diff changeset
6085 #ifdef USE_TMPNAM_R
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6086 "unexpected NULL from tmpnam_r"
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6087 #else
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6088 "unexpected NULL from tmpnam"
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6089 #endif
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6090 ));
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6091 return NULL;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6092 }
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6093 return PyString_FromString(buffer);
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6094 }
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6095 #endif
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6096
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
6097
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6098 /* This is used for fpathconf(), pathconf(), confstr() and sysconf().
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6099 * It maps strings representing configuration variable names to
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6100 * integer values, allowing those functions to be called with the
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 13601
diff changeset
6101 * magic names instead of polluting the module's namespace with tons of
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6102 * rarely-used constants. There are three separate tables that use
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6103 * these definitions.
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
6104 *
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
6105 * This code is always included, even if none of the interfaces that
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
6106 * need it are included. The #if hackery needed to avoid it would be
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
6107 * sufficiently pervasive that it's not worth the loss of readability.
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6108 */
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6109 struct constdef {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6110 char *name;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6111 long value;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6112 };
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6113
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6114 static int
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
6115 conv_confname(PyObject *arg, int *valuep, struct constdef *table,
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
6116 size_t tablesize)
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6117 {
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6118 if (PyInt_Check(arg)) {
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6119 *valuep = PyInt_AS_LONG(arg);
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6120 return 1;
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6121 }
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6122 if (PyString_Check(arg)) {
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6123 /* look up the value in the table using a binary search */
13153
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
6124 size_t lo = 0;
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
6125 size_t mid;
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
6126 size_t hi = tablesize;
32816ce60a49 Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents: 13058
diff changeset
6127 int cmp;
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6128 char *confname = PyString_AS_STRING(arg);
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6129 while (lo < hi) {
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6130 mid = (lo + hi) / 2;
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6131 cmp = strcmp(confname, table[mid].name);
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6132 if (cmp < 0)
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6133 hi = mid;
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6134 else if (cmp > 0)
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6135 lo = mid + 1;
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6136 else {
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6137 *valuep = table[mid].value;
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6138 return 1;
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6139 }
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6140 }
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6141 PyErr_SetString(PyExc_ValueError, "unrecognized configuration name");
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6142 }
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6143 else
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6144 PyErr_SetString(PyExc_TypeError,
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6145 "configuration names must be strings or integers");
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6146 return 0;
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6147 }
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6148
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6149
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6150 #if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6151 static struct constdef posix_constants_pathconf[] = {
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6152 #ifdef _PC_ABI_AIO_XFER_MAX
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6153 {"PC_ABI_AIO_XFER_MAX", _PC_ABI_AIO_XFER_MAX},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6154 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6155 #ifdef _PC_ABI_ASYNC_IO
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6156 {"PC_ABI_ASYNC_IO", _PC_ABI_ASYNC_IO},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6157 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6158 #ifdef _PC_ASYNC_IO
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6159 {"PC_ASYNC_IO", _PC_ASYNC_IO},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6160 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6161 #ifdef _PC_CHOWN_RESTRICTED
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6162 {"PC_CHOWN_RESTRICTED", _PC_CHOWN_RESTRICTED},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6163 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6164 #ifdef _PC_FILESIZEBITS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6165 {"PC_FILESIZEBITS", _PC_FILESIZEBITS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6166 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6167 #ifdef _PC_LAST
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6168 {"PC_LAST", _PC_LAST},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6169 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6170 #ifdef _PC_LINK_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6171 {"PC_LINK_MAX", _PC_LINK_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6172 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6173 #ifdef _PC_MAX_CANON
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6174 {"PC_MAX_CANON", _PC_MAX_CANON},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6175 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6176 #ifdef _PC_MAX_INPUT
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6177 {"PC_MAX_INPUT", _PC_MAX_INPUT},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6178 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6179 #ifdef _PC_NAME_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6180 {"PC_NAME_MAX", _PC_NAME_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6181 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6182 #ifdef _PC_NO_TRUNC
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6183 {"PC_NO_TRUNC", _PC_NO_TRUNC},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6184 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6185 #ifdef _PC_PATH_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6186 {"PC_PATH_MAX", _PC_PATH_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6187 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6188 #ifdef _PC_PIPE_BUF
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6189 {"PC_PIPE_BUF", _PC_PIPE_BUF},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6190 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6191 #ifdef _PC_PRIO_IO
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6192 {"PC_PRIO_IO", _PC_PRIO_IO},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6193 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6194 #ifdef _PC_SOCK_MAXBUF
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6195 {"PC_SOCK_MAXBUF", _PC_SOCK_MAXBUF},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6196 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6197 #ifdef _PC_SYNC_IO
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6198 {"PC_SYNC_IO", _PC_SYNC_IO},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6199 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6200 #ifdef _PC_VDISABLE
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6201 {"PC_VDISABLE", _PC_VDISABLE},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6202 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6203 };
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6204
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6205 static int
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
6206 conv_path_confname(PyObject *arg, int *valuep)
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6207 {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6208 return conv_confname(arg, valuep, posix_constants_pathconf,
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6209 sizeof(posix_constants_pathconf)
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6210 / sizeof(struct constdef));
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6211 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6212 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6213
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6214 #ifdef HAVE_FPATHCONF
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6215 PyDoc_STRVAR(posix_fpathconf__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
6216 "fpathconf(fd, name) -> integer\n\n\
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6217 Return the configuration limit name for the file descriptor fd.\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6218 If there is no limit, return -1.");
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6219
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6220 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
6221 posix_fpathconf(PyObject *self, PyObject *args)
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6222 {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6223 PyObject *result = NULL;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6224 int name, fd;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6225
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6226 if (PyArg_ParseTuple(args, "iO&:fpathconf", &fd,
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6227 conv_path_confname, &name)) {
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6228 long limit;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6229
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6230 errno = 0;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6231 limit = fpathconf(fd, name);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6232 if (limit == -1 && errno != 0)
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6233 posix_error();
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6234 else
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6235 result = PyInt_FromLong(limit);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6236 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6237 return result;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6238 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6239 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6240
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6241
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6242 #ifdef HAVE_PATHCONF
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6243 PyDoc_STRVAR(posix_pathconf__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
6244 "pathconf(path, name) -> integer\n\n\
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6245 Return the configuration limit name for the file or directory path.\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6246 If there is no limit, return -1.");
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6247
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6248 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
6249 posix_pathconf(PyObject *self, PyObject *args)
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6250 {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6251 PyObject *result = NULL;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6252 int name;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6253 char *path;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6254
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6255 if (PyArg_ParseTuple(args, "sO&:pathconf", &path,
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6256 conv_path_confname, &name)) {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6257 long limit;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6258
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6259 errno = 0;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6260 limit = pathconf(path, name);
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6261 if (limit == -1 && errno != 0) {
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6262 if (errno == EINVAL)
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6263 /* could be a path or name problem */
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6264 posix_error();
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6265 else
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6266 posix_error_with_filename(path);
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
6267 }
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6268 else
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6269 result = PyInt_FromLong(limit);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6270 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6271 return result;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6272 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6273 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6274
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6275 #ifdef HAVE_CONFSTR
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6276 static struct constdef posix_constants_confstr[] = {
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6277 #ifdef _CS_ARCHITECTURE
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6278 {"CS_ARCHITECTURE", _CS_ARCHITECTURE},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6279 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6280 #ifdef _CS_HOSTNAME
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6281 {"CS_HOSTNAME", _CS_HOSTNAME},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6282 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6283 #ifdef _CS_HW_PROVIDER
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6284 {"CS_HW_PROVIDER", _CS_HW_PROVIDER},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6285 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6286 #ifdef _CS_HW_SERIAL
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6287 {"CS_HW_SERIAL", _CS_HW_SERIAL},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6288 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6289 #ifdef _CS_INITTAB_NAME
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6290 {"CS_INITTAB_NAME", _CS_INITTAB_NAME},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6291 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6292 #ifdef _CS_LFS64_CFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6293 {"CS_LFS64_CFLAGS", _CS_LFS64_CFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6294 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6295 #ifdef _CS_LFS64_LDFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6296 {"CS_LFS64_LDFLAGS", _CS_LFS64_LDFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6297 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6298 #ifdef _CS_LFS64_LIBS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6299 {"CS_LFS64_LIBS", _CS_LFS64_LIBS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6300 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6301 #ifdef _CS_LFS64_LINTFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6302 {"CS_LFS64_LINTFLAGS", _CS_LFS64_LINTFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6303 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6304 #ifdef _CS_LFS_CFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6305 {"CS_LFS_CFLAGS", _CS_LFS_CFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6306 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6307 #ifdef _CS_LFS_LDFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6308 {"CS_LFS_LDFLAGS", _CS_LFS_LDFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6309 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6310 #ifdef _CS_LFS_LIBS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6311 {"CS_LFS_LIBS", _CS_LFS_LIBS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6312 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6313 #ifdef _CS_LFS_LINTFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6314 {"CS_LFS_LINTFLAGS", _CS_LFS_LINTFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6315 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6316 #ifdef _CS_MACHINE
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6317 {"CS_MACHINE", _CS_MACHINE},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6318 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6319 #ifdef _CS_PATH
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6320 {"CS_PATH", _CS_PATH},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6321 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6322 #ifdef _CS_RELEASE
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6323 {"CS_RELEASE", _CS_RELEASE},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6324 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6325 #ifdef _CS_SRPC_DOMAIN
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6326 {"CS_SRPC_DOMAIN", _CS_SRPC_DOMAIN},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6327 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6328 #ifdef _CS_SYSNAME
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6329 {"CS_SYSNAME", _CS_SYSNAME},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6330 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6331 #ifdef _CS_VERSION
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6332 {"CS_VERSION", _CS_VERSION},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6333 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6334 #ifdef _CS_XBS5_ILP32_OFF32_CFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6335 {"CS_XBS5_ILP32_OFF32_CFLAGS", _CS_XBS5_ILP32_OFF32_CFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6336 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6337 #ifdef _CS_XBS5_ILP32_OFF32_LDFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6338 {"CS_XBS5_ILP32_OFF32_LDFLAGS", _CS_XBS5_ILP32_OFF32_LDFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6339 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6340 #ifdef _CS_XBS5_ILP32_OFF32_LIBS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6341 {"CS_XBS5_ILP32_OFF32_LIBS", _CS_XBS5_ILP32_OFF32_LIBS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6342 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6343 #ifdef _CS_XBS5_ILP32_OFF32_LINTFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6344 {"CS_XBS5_ILP32_OFF32_LINTFLAGS", _CS_XBS5_ILP32_OFF32_LINTFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6345 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6346 #ifdef _CS_XBS5_ILP32_OFFBIG_CFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6347 {"CS_XBS5_ILP32_OFFBIG_CFLAGS", _CS_XBS5_ILP32_OFFBIG_CFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6348 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6349 #ifdef _CS_XBS5_ILP32_OFFBIG_LDFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6350 {"CS_XBS5_ILP32_OFFBIG_LDFLAGS", _CS_XBS5_ILP32_OFFBIG_LDFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6351 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6352 #ifdef _CS_XBS5_ILP32_OFFBIG_LIBS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6353 {"CS_XBS5_ILP32_OFFBIG_LIBS", _CS_XBS5_ILP32_OFFBIG_LIBS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6354 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6355 #ifdef _CS_XBS5_ILP32_OFFBIG_LINTFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6356 {"CS_XBS5_ILP32_OFFBIG_LINTFLAGS", _CS_XBS5_ILP32_OFFBIG_LINTFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6357 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6358 #ifdef _CS_XBS5_LP64_OFF64_CFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6359 {"CS_XBS5_LP64_OFF64_CFLAGS", _CS_XBS5_LP64_OFF64_CFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6360 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6361 #ifdef _CS_XBS5_LP64_OFF64_LDFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6362 {"CS_XBS5_LP64_OFF64_LDFLAGS", _CS_XBS5_LP64_OFF64_LDFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6363 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6364 #ifdef _CS_XBS5_LP64_OFF64_LIBS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6365 {"CS_XBS5_LP64_OFF64_LIBS", _CS_XBS5_LP64_OFF64_LIBS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6366 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6367 #ifdef _CS_XBS5_LP64_OFF64_LINTFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6368 {"CS_XBS5_LP64_OFF64_LINTFLAGS", _CS_XBS5_LP64_OFF64_LINTFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6369 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6370 #ifdef _CS_XBS5_LPBIG_OFFBIG_CFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6371 {"CS_XBS5_LPBIG_OFFBIG_CFLAGS", _CS_XBS5_LPBIG_OFFBIG_CFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6372 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6373 #ifdef _CS_XBS5_LPBIG_OFFBIG_LDFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6374 {"CS_XBS5_LPBIG_OFFBIG_LDFLAGS", _CS_XBS5_LPBIG_OFFBIG_LDFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6375 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6376 #ifdef _CS_XBS5_LPBIG_OFFBIG_LIBS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6377 {"CS_XBS5_LPBIG_OFFBIG_LIBS", _CS_XBS5_LPBIG_OFFBIG_LIBS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6378 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6379 #ifdef _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6380 {"CS_XBS5_LPBIG_OFFBIG_LINTFLAGS", _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6381 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6382 #ifdef _MIPS_CS_AVAIL_PROCESSORS
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6383 {"MIPS_CS_AVAIL_PROCESSORS", _MIPS_CS_AVAIL_PROCESSORS},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6384 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6385 #ifdef _MIPS_CS_BASE
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6386 {"MIPS_CS_BASE", _MIPS_CS_BASE},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6387 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6388 #ifdef _MIPS_CS_HOSTID
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6389 {"MIPS_CS_HOSTID", _MIPS_CS_HOSTID},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6390 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6391 #ifdef _MIPS_CS_HW_NAME
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6392 {"MIPS_CS_HW_NAME", _MIPS_CS_HW_NAME},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6393 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6394 #ifdef _MIPS_CS_NUM_PROCESSORS
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6395 {"MIPS_CS_NUM_PROCESSORS", _MIPS_CS_NUM_PROCESSORS},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6396 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6397 #ifdef _MIPS_CS_OSREL_MAJ
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6398 {"MIPS_CS_OSREL_MAJ", _MIPS_CS_OSREL_MAJ},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6399 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6400 #ifdef _MIPS_CS_OSREL_MIN
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6401 {"MIPS_CS_OSREL_MIN", _MIPS_CS_OSREL_MIN},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6402 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6403 #ifdef _MIPS_CS_OSREL_PATCH
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6404 {"MIPS_CS_OSREL_PATCH", _MIPS_CS_OSREL_PATCH},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6405 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6406 #ifdef _MIPS_CS_OS_NAME
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6407 {"MIPS_CS_OS_NAME", _MIPS_CS_OS_NAME},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6408 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6409 #ifdef _MIPS_CS_OS_PROVIDER
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6410 {"MIPS_CS_OS_PROVIDER", _MIPS_CS_OS_PROVIDER},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6411 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6412 #ifdef _MIPS_CS_PROCESSORS
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6413 {"MIPS_CS_PROCESSORS", _MIPS_CS_PROCESSORS},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6414 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6415 #ifdef _MIPS_CS_SERIAL
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6416 {"MIPS_CS_SERIAL", _MIPS_CS_SERIAL},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6417 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6418 #ifdef _MIPS_CS_VENDOR
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6419 {"MIPS_CS_VENDOR", _MIPS_CS_VENDOR},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6420 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6421 };
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6422
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6423 static int
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
6424 conv_confstr_confname(PyObject *arg, int *valuep)
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6425 {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6426 return conv_confname(arg, valuep, posix_constants_confstr,
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6427 sizeof(posix_constants_confstr)
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6428 / sizeof(struct constdef));
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6429 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6430
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6431 PyDoc_STRVAR(posix_confstr__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
6432 "confstr(name) -> string\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6433 Return a string-valued system configuration variable.");
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6434
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6435 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
6436 posix_confstr(PyObject *self, PyObject *args)
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6437 {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6438 PyObject *result = NULL;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6439 int name;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6440 char buffer[64];
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6441
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6442 if (PyArg_ParseTuple(args, "O&:confstr", conv_confstr_confname, &name)) {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6443 int len = confstr(name, buffer, sizeof(buffer));
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6444
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6445 errno = 0;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6446 if (len == 0) {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6447 if (errno != 0)
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6448 posix_error();
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6449 else
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6450 result = PyString_FromString("");
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6451 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6452 else {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6453 if (len >= sizeof(buffer)) {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6454 result = PyString_FromStringAndSize(NULL, len);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6455 if (result != NULL)
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6456 confstr(name, PyString_AS_STRING(result), len+1);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6457 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6458 else
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6459 result = PyString_FromString(buffer);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6460 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6461 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6462 return result;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6463 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6464 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6465
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6466
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6467 #ifdef HAVE_SYSCONF
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6468 static struct constdef posix_constants_sysconf[] = {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6469 #ifdef _SC_2_CHAR_TERM
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6470 {"SC_2_CHAR_TERM", _SC_2_CHAR_TERM},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6471 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6472 #ifdef _SC_2_C_BIND
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6473 {"SC_2_C_BIND", _SC_2_C_BIND},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6474 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6475 #ifdef _SC_2_C_DEV
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6476 {"SC_2_C_DEV", _SC_2_C_DEV},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6477 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6478 #ifdef _SC_2_C_VERSION
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6479 {"SC_2_C_VERSION", _SC_2_C_VERSION},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6480 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6481 #ifdef _SC_2_FORT_DEV
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6482 {"SC_2_FORT_DEV", _SC_2_FORT_DEV},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6483 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6484 #ifdef _SC_2_FORT_RUN
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6485 {"SC_2_FORT_RUN", _SC_2_FORT_RUN},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6486 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6487 #ifdef _SC_2_LOCALEDEF
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6488 {"SC_2_LOCALEDEF", _SC_2_LOCALEDEF},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6489 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6490 #ifdef _SC_2_SW_DEV
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6491 {"SC_2_SW_DEV", _SC_2_SW_DEV},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6492 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6493 #ifdef _SC_2_UPE
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6494 {"SC_2_UPE", _SC_2_UPE},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6495 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6496 #ifdef _SC_2_VERSION
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6497 {"SC_2_VERSION", _SC_2_VERSION},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6498 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6499 #ifdef _SC_ABI_ASYNCHRONOUS_IO
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6500 {"SC_ABI_ASYNCHRONOUS_IO", _SC_ABI_ASYNCHRONOUS_IO},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6501 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6502 #ifdef _SC_ACL
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6503 {"SC_ACL", _SC_ACL},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6504 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6505 #ifdef _SC_AIO_LISTIO_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6506 {"SC_AIO_LISTIO_MAX", _SC_AIO_LISTIO_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6507 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6508 #ifdef _SC_AIO_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6509 {"SC_AIO_MAX", _SC_AIO_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6510 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6511 #ifdef _SC_AIO_PRIO_DELTA_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6512 {"SC_AIO_PRIO_DELTA_MAX", _SC_AIO_PRIO_DELTA_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6513 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6514 #ifdef _SC_ARG_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6515 {"SC_ARG_MAX", _SC_ARG_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6516 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6517 #ifdef _SC_ASYNCHRONOUS_IO
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6518 {"SC_ASYNCHRONOUS_IO", _SC_ASYNCHRONOUS_IO},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6519 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6520 #ifdef _SC_ATEXIT_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6521 {"SC_ATEXIT_MAX", _SC_ATEXIT_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6522 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6523 #ifdef _SC_AUDIT
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6524 {"SC_AUDIT", _SC_AUDIT},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6525 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6526 #ifdef _SC_AVPHYS_PAGES
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6527 {"SC_AVPHYS_PAGES", _SC_AVPHYS_PAGES},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6528 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6529 #ifdef _SC_BC_BASE_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6530 {"SC_BC_BASE_MAX", _SC_BC_BASE_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6531 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6532 #ifdef _SC_BC_DIM_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6533 {"SC_BC_DIM_MAX", _SC_BC_DIM_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6534 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6535 #ifdef _SC_BC_SCALE_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6536 {"SC_BC_SCALE_MAX", _SC_BC_SCALE_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6537 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6538 #ifdef _SC_BC_STRING_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6539 {"SC_BC_STRING_MAX", _SC_BC_STRING_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6540 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6541 #ifdef _SC_CAP
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6542 {"SC_CAP", _SC_CAP},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6543 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6544 #ifdef _SC_CHARCLASS_NAME_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6545 {"SC_CHARCLASS_NAME_MAX", _SC_CHARCLASS_NAME_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6546 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6547 #ifdef _SC_CHAR_BIT
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6548 {"SC_CHAR_BIT", _SC_CHAR_BIT},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6549 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6550 #ifdef _SC_CHAR_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6551 {"SC_CHAR_MAX", _SC_CHAR_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6552 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6553 #ifdef _SC_CHAR_MIN
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6554 {"SC_CHAR_MIN", _SC_CHAR_MIN},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6555 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6556 #ifdef _SC_CHILD_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6557 {"SC_CHILD_MAX", _SC_CHILD_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6558 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6559 #ifdef _SC_CLK_TCK
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6560 {"SC_CLK_TCK", _SC_CLK_TCK},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6561 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6562 #ifdef _SC_COHER_BLKSZ
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6563 {"SC_COHER_BLKSZ", _SC_COHER_BLKSZ},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6564 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6565 #ifdef _SC_COLL_WEIGHTS_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6566 {"SC_COLL_WEIGHTS_MAX", _SC_COLL_WEIGHTS_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6567 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6568 #ifdef _SC_DCACHE_ASSOC
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6569 {"SC_DCACHE_ASSOC", _SC_DCACHE_ASSOC},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6570 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6571 #ifdef _SC_DCACHE_BLKSZ
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6572 {"SC_DCACHE_BLKSZ", _SC_DCACHE_BLKSZ},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6573 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6574 #ifdef _SC_DCACHE_LINESZ
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6575 {"SC_DCACHE_LINESZ", _SC_DCACHE_LINESZ},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6576 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6577 #ifdef _SC_DCACHE_SZ
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6578 {"SC_DCACHE_SZ", _SC_DCACHE_SZ},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6579 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6580 #ifdef _SC_DCACHE_TBLKSZ
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6581 {"SC_DCACHE_TBLKSZ", _SC_DCACHE_TBLKSZ},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6582 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6583 #ifdef _SC_DELAYTIMER_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6584 {"SC_DELAYTIMER_MAX", _SC_DELAYTIMER_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6585 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6586 #ifdef _SC_EQUIV_CLASS_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6587 {"SC_EQUIV_CLASS_MAX", _SC_EQUIV_CLASS_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6588 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6589 #ifdef _SC_EXPR_NEST_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6590 {"SC_EXPR_NEST_MAX", _SC_EXPR_NEST_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6591 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6592 #ifdef _SC_FSYNC
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6593 {"SC_FSYNC", _SC_FSYNC},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6594 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6595 #ifdef _SC_GETGR_R_SIZE_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6596 {"SC_GETGR_R_SIZE_MAX", _SC_GETGR_R_SIZE_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6597 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6598 #ifdef _SC_GETPW_R_SIZE_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6599 {"SC_GETPW_R_SIZE_MAX", _SC_GETPW_R_SIZE_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6600 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6601 #ifdef _SC_ICACHE_ASSOC
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6602 {"SC_ICACHE_ASSOC", _SC_ICACHE_ASSOC},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6603 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6604 #ifdef _SC_ICACHE_BLKSZ
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6605 {"SC_ICACHE_BLKSZ", _SC_ICACHE_BLKSZ},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6606 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6607 #ifdef _SC_ICACHE_LINESZ
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6608 {"SC_ICACHE_LINESZ", _SC_ICACHE_LINESZ},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6609 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6610 #ifdef _SC_ICACHE_SZ
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6611 {"SC_ICACHE_SZ", _SC_ICACHE_SZ},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6612 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6613 #ifdef _SC_INF
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6614 {"SC_INF", _SC_INF},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6615 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6616 #ifdef _SC_INT_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6617 {"SC_INT_MAX", _SC_INT_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6618 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6619 #ifdef _SC_INT_MIN
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6620 {"SC_INT_MIN", _SC_INT_MIN},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6621 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6622 #ifdef _SC_IOV_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6623 {"SC_IOV_MAX", _SC_IOV_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6624 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6625 #ifdef _SC_IP_SECOPTS
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6626 {"SC_IP_SECOPTS", _SC_IP_SECOPTS},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6627 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6628 #ifdef _SC_JOB_CONTROL
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6629 {"SC_JOB_CONTROL", _SC_JOB_CONTROL},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6630 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6631 #ifdef _SC_KERN_POINTERS
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6632 {"SC_KERN_POINTERS", _SC_KERN_POINTERS},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6633 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6634 #ifdef _SC_KERN_SIM
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6635 {"SC_KERN_SIM", _SC_KERN_SIM},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6636 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6637 #ifdef _SC_LINE_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6638 {"SC_LINE_MAX", _SC_LINE_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6639 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6640 #ifdef _SC_LOGIN_NAME_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6641 {"SC_LOGIN_NAME_MAX", _SC_LOGIN_NAME_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6642 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6643 #ifdef _SC_LOGNAME_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6644 {"SC_LOGNAME_MAX", _SC_LOGNAME_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6645 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6646 #ifdef _SC_LONG_BIT
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6647 {"SC_LONG_BIT", _SC_LONG_BIT},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6648 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6649 #ifdef _SC_MAC
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6650 {"SC_MAC", _SC_MAC},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6651 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6652 #ifdef _SC_MAPPED_FILES
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6653 {"SC_MAPPED_FILES", _SC_MAPPED_FILES},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6654 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6655 #ifdef _SC_MAXPID
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6656 {"SC_MAXPID", _SC_MAXPID},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6657 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6658 #ifdef _SC_MB_LEN_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6659 {"SC_MB_LEN_MAX", _SC_MB_LEN_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6660 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6661 #ifdef _SC_MEMLOCK
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6662 {"SC_MEMLOCK", _SC_MEMLOCK},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6663 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6664 #ifdef _SC_MEMLOCK_RANGE
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6665 {"SC_MEMLOCK_RANGE", _SC_MEMLOCK_RANGE},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6666 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6667 #ifdef _SC_MEMORY_PROTECTION
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6668 {"SC_MEMORY_PROTECTION", _SC_MEMORY_PROTECTION},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6669 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6670 #ifdef _SC_MESSAGE_PASSING
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6671 {"SC_MESSAGE_PASSING", _SC_MESSAGE_PASSING},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6672 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6673 #ifdef _SC_MMAP_FIXED_ALIGNMENT
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6674 {"SC_MMAP_FIXED_ALIGNMENT", _SC_MMAP_FIXED_ALIGNMENT},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6675 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6676 #ifdef _SC_MQ_OPEN_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6677 {"SC_MQ_OPEN_MAX", _SC_MQ_OPEN_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6678 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6679 #ifdef _SC_MQ_PRIO_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6680 {"SC_MQ_PRIO_MAX", _SC_MQ_PRIO_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6681 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6682 #ifdef _SC_NACLS_MAX
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6683 {"SC_NACLS_MAX", _SC_NACLS_MAX},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6684 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6685 #ifdef _SC_NGROUPS_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6686 {"SC_NGROUPS_MAX", _SC_NGROUPS_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6687 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6688 #ifdef _SC_NL_ARGMAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6689 {"SC_NL_ARGMAX", _SC_NL_ARGMAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6690 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6691 #ifdef _SC_NL_LANGMAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6692 {"SC_NL_LANGMAX", _SC_NL_LANGMAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6693 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6694 #ifdef _SC_NL_MSGMAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6695 {"SC_NL_MSGMAX", _SC_NL_MSGMAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6696 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6697 #ifdef _SC_NL_NMAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6698 {"SC_NL_NMAX", _SC_NL_NMAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6699 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6700 #ifdef _SC_NL_SETMAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6701 {"SC_NL_SETMAX", _SC_NL_SETMAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6702 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6703 #ifdef _SC_NL_TEXTMAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6704 {"SC_NL_TEXTMAX", _SC_NL_TEXTMAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6705 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6706 #ifdef _SC_NPROCESSORS_CONF
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6707 {"SC_NPROCESSORS_CONF", _SC_NPROCESSORS_CONF},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6708 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6709 #ifdef _SC_NPROCESSORS_ONLN
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6710 {"SC_NPROCESSORS_ONLN", _SC_NPROCESSORS_ONLN},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6711 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6712 #ifdef _SC_NPROC_CONF
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6713 {"SC_NPROC_CONF", _SC_NPROC_CONF},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6714 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6715 #ifdef _SC_NPROC_ONLN
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6716 {"SC_NPROC_ONLN", _SC_NPROC_ONLN},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6717 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6718 #ifdef _SC_NZERO
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6719 {"SC_NZERO", _SC_NZERO},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6720 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6721 #ifdef _SC_OPEN_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6722 {"SC_OPEN_MAX", _SC_OPEN_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6723 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6724 #ifdef _SC_PAGESIZE
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6725 {"SC_PAGESIZE", _SC_PAGESIZE},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6726 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6727 #ifdef _SC_PAGE_SIZE
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6728 {"SC_PAGE_SIZE", _SC_PAGE_SIZE},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6729 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6730 #ifdef _SC_PASS_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6731 {"SC_PASS_MAX", _SC_PASS_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6732 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6733 #ifdef _SC_PHYS_PAGES
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6734 {"SC_PHYS_PAGES", _SC_PHYS_PAGES},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6735 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6736 #ifdef _SC_PII
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6737 {"SC_PII", _SC_PII},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6738 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6739 #ifdef _SC_PII_INTERNET
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6740 {"SC_PII_INTERNET", _SC_PII_INTERNET},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6741 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6742 #ifdef _SC_PII_INTERNET_DGRAM
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6743 {"SC_PII_INTERNET_DGRAM", _SC_PII_INTERNET_DGRAM},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6744 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6745 #ifdef _SC_PII_INTERNET_STREAM
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6746 {"SC_PII_INTERNET_STREAM", _SC_PII_INTERNET_STREAM},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6747 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6748 #ifdef _SC_PII_OSI
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6749 {"SC_PII_OSI", _SC_PII_OSI},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6750 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6751 #ifdef _SC_PII_OSI_CLTS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6752 {"SC_PII_OSI_CLTS", _SC_PII_OSI_CLTS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6753 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6754 #ifdef _SC_PII_OSI_COTS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6755 {"SC_PII_OSI_COTS", _SC_PII_OSI_COTS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6756 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6757 #ifdef _SC_PII_OSI_M
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6758 {"SC_PII_OSI_M", _SC_PII_OSI_M},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6759 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6760 #ifdef _SC_PII_SOCKET
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6761 {"SC_PII_SOCKET", _SC_PII_SOCKET},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6762 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6763 #ifdef _SC_PII_XTI
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6764 {"SC_PII_XTI", _SC_PII_XTI},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6765 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6766 #ifdef _SC_POLL
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6767 {"SC_POLL", _SC_POLL},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6768 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6769 #ifdef _SC_PRIORITIZED_IO
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6770 {"SC_PRIORITIZED_IO", _SC_PRIORITIZED_IO},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6771 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6772 #ifdef _SC_PRIORITY_SCHEDULING
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6773 {"SC_PRIORITY_SCHEDULING", _SC_PRIORITY_SCHEDULING},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6774 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6775 #ifdef _SC_REALTIME_SIGNALS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6776 {"SC_REALTIME_SIGNALS", _SC_REALTIME_SIGNALS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6777 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6778 #ifdef _SC_RE_DUP_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6779 {"SC_RE_DUP_MAX", _SC_RE_DUP_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6780 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6781 #ifdef _SC_RTSIG_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6782 {"SC_RTSIG_MAX", _SC_RTSIG_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6783 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6784 #ifdef _SC_SAVED_IDS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6785 {"SC_SAVED_IDS", _SC_SAVED_IDS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6786 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6787 #ifdef _SC_SCHAR_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6788 {"SC_SCHAR_MAX", _SC_SCHAR_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6789 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6790 #ifdef _SC_SCHAR_MIN
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6791 {"SC_SCHAR_MIN", _SC_SCHAR_MIN},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6792 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6793 #ifdef _SC_SELECT
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6794 {"SC_SELECT", _SC_SELECT},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6795 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6796 #ifdef _SC_SEMAPHORES
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6797 {"SC_SEMAPHORES", _SC_SEMAPHORES},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6798 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6799 #ifdef _SC_SEM_NSEMS_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6800 {"SC_SEM_NSEMS_MAX", _SC_SEM_NSEMS_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6801 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6802 #ifdef _SC_SEM_VALUE_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6803 {"SC_SEM_VALUE_MAX", _SC_SEM_VALUE_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6804 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6805 #ifdef _SC_SHARED_MEMORY_OBJECTS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6806 {"SC_SHARED_MEMORY_OBJECTS", _SC_SHARED_MEMORY_OBJECTS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6807 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6808 #ifdef _SC_SHRT_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6809 {"SC_SHRT_MAX", _SC_SHRT_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6810 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6811 #ifdef _SC_SHRT_MIN
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6812 {"SC_SHRT_MIN", _SC_SHRT_MIN},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6813 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6814 #ifdef _SC_SIGQUEUE_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6815 {"SC_SIGQUEUE_MAX", _SC_SIGQUEUE_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6816 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6817 #ifdef _SC_SIGRT_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6818 {"SC_SIGRT_MAX", _SC_SIGRT_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6819 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6820 #ifdef _SC_SIGRT_MIN
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6821 {"SC_SIGRT_MIN", _SC_SIGRT_MIN},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6822 #endif
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6823 #ifdef _SC_SOFTPOWER
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6824 {"SC_SOFTPOWER", _SC_SOFTPOWER},
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
6825 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6826 #ifdef _SC_SPLIT_CACHE
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6827 {"SC_SPLIT_CACHE", _SC_SPLIT_CACHE},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6828 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6829 #ifdef _SC_SSIZE_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6830 {"SC_SSIZE_MAX", _SC_SSIZE_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6831 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6832 #ifdef _SC_STACK_PROT
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6833 {"SC_STACK_PROT", _SC_STACK_PROT},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6834 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6835 #ifdef _SC_STREAM_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6836 {"SC_STREAM_MAX", _SC_STREAM_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6837 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6838 #ifdef _SC_SYNCHRONIZED_IO
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6839 {"SC_SYNCHRONIZED_IO", _SC_SYNCHRONIZED_IO},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6840 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6841 #ifdef _SC_THREADS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6842 {"SC_THREADS", _SC_THREADS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6843 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6844 #ifdef _SC_THREAD_ATTR_STACKADDR
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6845 {"SC_THREAD_ATTR_STACKADDR", _SC_THREAD_ATTR_STACKADDR},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6846 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6847 #ifdef _SC_THREAD_ATTR_STACKSIZE
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6848 {"SC_THREAD_ATTR_STACKSIZE", _SC_THREAD_ATTR_STACKSIZE},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6849 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6850 #ifdef _SC_THREAD_DESTRUCTOR_ITERATIONS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6851 {"SC_THREAD_DESTRUCTOR_ITERATIONS", _SC_THREAD_DESTRUCTOR_ITERATIONS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6852 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6853 #ifdef _SC_THREAD_KEYS_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6854 {"SC_THREAD_KEYS_MAX", _SC_THREAD_KEYS_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6855 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6856 #ifdef _SC_THREAD_PRIORITY_SCHEDULING
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6857 {"SC_THREAD_PRIORITY_SCHEDULING", _SC_THREAD_PRIORITY_SCHEDULING},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6858 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6859 #ifdef _SC_THREAD_PRIO_INHERIT
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6860 {"SC_THREAD_PRIO_INHERIT", _SC_THREAD_PRIO_INHERIT},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6861 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6862 #ifdef _SC_THREAD_PRIO_PROTECT
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6863 {"SC_THREAD_PRIO_PROTECT", _SC_THREAD_PRIO_PROTECT},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6864 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6865 #ifdef _SC_THREAD_PROCESS_SHARED
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6866 {"SC_THREAD_PROCESS_SHARED", _SC_THREAD_PROCESS_SHARED},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6867 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6868 #ifdef _SC_THREAD_SAFE_FUNCTIONS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6869 {"SC_THREAD_SAFE_FUNCTIONS", _SC_THREAD_SAFE_FUNCTIONS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6870 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6871 #ifdef _SC_THREAD_STACK_MIN
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6872 {"SC_THREAD_STACK_MIN", _SC_THREAD_STACK_MIN},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6873 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6874 #ifdef _SC_THREAD_THREADS_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6875 {"SC_THREAD_THREADS_MAX", _SC_THREAD_THREADS_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6876 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6877 #ifdef _SC_TIMERS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6878 {"SC_TIMERS", _SC_TIMERS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6879 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6880 #ifdef _SC_TIMER_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6881 {"SC_TIMER_MAX", _SC_TIMER_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6882 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6883 #ifdef _SC_TTY_NAME_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6884 {"SC_TTY_NAME_MAX", _SC_TTY_NAME_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6885 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6886 #ifdef _SC_TZNAME_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6887 {"SC_TZNAME_MAX", _SC_TZNAME_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6888 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6889 #ifdef _SC_T_IOV_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6890 {"SC_T_IOV_MAX", _SC_T_IOV_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6891 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6892 #ifdef _SC_UCHAR_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6893 {"SC_UCHAR_MAX", _SC_UCHAR_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6894 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6895 #ifdef _SC_UINT_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6896 {"SC_UINT_MAX", _SC_UINT_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6897 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6898 #ifdef _SC_UIO_MAXIOV
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6899 {"SC_UIO_MAXIOV", _SC_UIO_MAXIOV},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6900 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6901 #ifdef _SC_ULONG_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6902 {"SC_ULONG_MAX", _SC_ULONG_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6903 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6904 #ifdef _SC_USHRT_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6905 {"SC_USHRT_MAX", _SC_USHRT_MAX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6906 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6907 #ifdef _SC_VERSION
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6908 {"SC_VERSION", _SC_VERSION},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6909 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6910 #ifdef _SC_WORD_BIT
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6911 {"SC_WORD_BIT", _SC_WORD_BIT},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6912 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6913 #ifdef _SC_XBS5_ILP32_OFF32
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6914 {"SC_XBS5_ILP32_OFF32", _SC_XBS5_ILP32_OFF32},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6915 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6916 #ifdef _SC_XBS5_ILP32_OFFBIG
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6917 {"SC_XBS5_ILP32_OFFBIG", _SC_XBS5_ILP32_OFFBIG},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6918 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6919 #ifdef _SC_XBS5_LP64_OFF64
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6920 {"SC_XBS5_LP64_OFF64", _SC_XBS5_LP64_OFF64},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6921 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6922 #ifdef _SC_XBS5_LPBIG_OFFBIG
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6923 {"SC_XBS5_LPBIG_OFFBIG", _SC_XBS5_LPBIG_OFFBIG},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6924 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6925 #ifdef _SC_XOPEN_CRYPT
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6926 {"SC_XOPEN_CRYPT", _SC_XOPEN_CRYPT},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6927 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6928 #ifdef _SC_XOPEN_ENH_I18N
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6929 {"SC_XOPEN_ENH_I18N", _SC_XOPEN_ENH_I18N},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6930 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6931 #ifdef _SC_XOPEN_LEGACY
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6932 {"SC_XOPEN_LEGACY", _SC_XOPEN_LEGACY},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6933 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6934 #ifdef _SC_XOPEN_REALTIME
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6935 {"SC_XOPEN_REALTIME", _SC_XOPEN_REALTIME},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6936 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6937 #ifdef _SC_XOPEN_REALTIME_THREADS
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6938 {"SC_XOPEN_REALTIME_THREADS", _SC_XOPEN_REALTIME_THREADS},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6939 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6940 #ifdef _SC_XOPEN_SHM
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6941 {"SC_XOPEN_SHM", _SC_XOPEN_SHM},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6942 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6943 #ifdef _SC_XOPEN_UNIX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6944 {"SC_XOPEN_UNIX", _SC_XOPEN_UNIX},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6945 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6946 #ifdef _SC_XOPEN_VERSION
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6947 {"SC_XOPEN_VERSION", _SC_XOPEN_VERSION},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6948 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6949 #ifdef _SC_XOPEN_XCU_VERSION
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6950 {"SC_XOPEN_XCU_VERSION", _SC_XOPEN_XCU_VERSION},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6951 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6952 #ifdef _SC_XOPEN_XPG2
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6953 {"SC_XOPEN_XPG2", _SC_XOPEN_XPG2},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6954 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6955 #ifdef _SC_XOPEN_XPG3
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6956 {"SC_XOPEN_XPG3", _SC_XOPEN_XPG3},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6957 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6958 #ifdef _SC_XOPEN_XPG4
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6959 {"SC_XOPEN_XPG4", _SC_XOPEN_XPG4},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6960 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6961 };
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6962
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6963 static int
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
6964 conv_sysconf_confname(PyObject *arg, int *valuep)
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6965 {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6966 return conv_confname(arg, valuep, posix_constants_sysconf,
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6967 sizeof(posix_constants_sysconf)
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6968 / sizeof(struct constdef));
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6969 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6970
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6971 PyDoc_STRVAR(posix_sysconf__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
6972 "sysconf(name) -> integer\n\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
6973 Return an integer-valued system configuration variable.");
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6974
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6975 static PyObject *
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
6976 posix_sysconf(PyObject *self, PyObject *args)
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6977 {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6978 PyObject *result = NULL;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6979 int name;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6980
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6981 if (PyArg_ParseTuple(args, "O&:sysconf", conv_sysconf_confname, &name)) {
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6982 int value;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6983
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6984 errno = 0;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6985 value = sysconf(name);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6986 if (value == -1 && errno != 0)
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6987 posix_error();
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6988 else
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6989 result = PyInt_FromLong(value);
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6990 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6991 return result;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6992 }
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6993 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6994
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
6995
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
6996 /* This code is used to ensure that the tables of configuration value names
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
6997 * are in sorted order as required by conv_confname(), and also to build the
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
6998 * the exported dictionaries that are used to publish information about the
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
6999 * names available on the host platform.
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7000 *
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7001 * Sorting the table at runtime ensures that the table is properly ordered
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7002 * when used, even for platforms we're not able to test on. It also makes
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7003 * it easier to add additional entries to the tables.
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7004 */
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7005
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7006 static int
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
7007 cmp_constdefs(const void *v1, const void *v2)
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7008 {
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7009 const struct constdef *c1 =
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7010 (const struct constdef *) v1;
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7011 const struct constdef *c2 =
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7012 (const struct constdef *) v2;
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7013
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7014 return strcmp(c1->name, c2->name);
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7015 }
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7016
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7017 static int
13442
ed72067aac03 this one's a bit risky, but I've spent some considerable time
Fredrik Lundh <fredrik@pythonware.com>
parents: 13389
diff changeset
7018 setup_confname_table(struct constdef *table, size_t tablesize,
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7019 char *tablename, PyObject *module)
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7020 {
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7021 PyObject *d = NULL;
12393
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7022 size_t i;
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7023
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7024 qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs);
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7025 d = PyDict_New();
12393
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7026 if (d == NULL)
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7027 return -1;
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7028
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7029 for (i=0; i < tablesize; ++i) {
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7030 PyObject *o = PyInt_FromLong(table[i].value);
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7031 if (o == NULL || PyDict_SetItemString(d, table[i].name, o) == -1) {
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7032 Py_XDECREF(o);
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7033 Py_DECREF(d);
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7034 return -1;
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7035 }
12393
a0498b15244c setup_confname_table(): Close memory leak caused by not decref'ing the
Barry Warsaw <barry@python.org>
parents: 12150
diff changeset
7036 Py_DECREF(o);
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7037 }
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7038 return PyModule_AddObject(module, tablename, d);
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7039 }
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7040
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7041 /* Return -1 on failure, 0 on success. */
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7042 static int
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7043 setup_confname_tables(PyObject *module)
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7044 {
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7045 #if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7046 if (setup_confname_table(posix_constants_pathconf,
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7047 sizeof(posix_constants_pathconf)
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7048 / sizeof(struct constdef),
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7049 "pathconf_names", module))
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7050 return -1;
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7051 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7052 #ifdef HAVE_CONFSTR
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7053 if (setup_confname_table(posix_constants_confstr,
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7054 sizeof(posix_constants_confstr)
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7055 / sizeof(struct constdef),
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7056 "confstr_names", module))
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7057 return -1;
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7058 #endif
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7059 #ifdef HAVE_SYSCONF
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7060 if (setup_confname_table(posix_constants_sysconf,
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7061 sizeof(posix_constants_sysconf)
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7062 / sizeof(struct constdef),
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7063 "sysconf_names", module))
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7064 return -1;
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7065 #endif
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7066 return 0;
11574
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7067 }
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7068
fd0d31c346b2 Added table entries for Irix 6.5 names for confstr()/sysconf()/
Fred Drake <fdrake@acm.org>
parents: 11570
diff changeset
7069
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
7070 PyDoc_STRVAR(posix_abort__doc__,
23937
3500da666c0c Clean up docstrings:
Fred Drake <fdrake@acm.org>
parents: 23900
diff changeset
7071 "abort() -> does not return!\n\n\
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7072 Abort the interpreter immediately. This 'dumps core' or otherwise fails\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
7073 in the hardest way possible on the hosting operating system.");
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7074
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7075 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7076 posix_abort(PyObject *self, PyObject *noargs)
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7077 {
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7078 abort();
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7079 /*NOTREACHED*/
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7080 Py_FatalError("abort() called from Python code didn't abort!");
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7081 return NULL;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7082 }
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7083
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
7084 #ifdef MS_WINDOWS
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
7085 PyDoc_STRVAR(win32_startfile__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
7086 "startfile(filepath) - Start a file with its associated application.\n\
14752
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7087 \n\
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7088 This acts like double-clicking the file in Explorer, or giving the file\n\
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7089 name as an argument to the DOS \"start\" command: the file is opened\n\
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7090 with whatever application (if any) its extension is associated.\n\
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7091 \n\
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7092 startfile returns as soon as the associated application is launched.\n\
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7093 There is no option to wait for the application to close, and no way\n\
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7094 to retrieve the application's exit status.\n\
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7095 \n\
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7096 The filepath is relative to the current directory. If you want to use\n\
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7097 an absolute path, make sure the first character is not a slash (\"/\");\n\
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23761
diff changeset
7098 the underlying Win32 ShellExecute function doesn't work if it is.");
14752
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7099
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7100 static PyObject *
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7101 win32_startfile(PyObject *self, PyObject *args)
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7102 {
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7103 char *filepath;
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7104 HINSTANCE rc;
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7105 if (!PyArg_ParseTuple(args, "s:startfile", &filepath))
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7106 return NULL;
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7107 Py_BEGIN_ALLOW_THREADS
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7108 rc = ShellExecute((HWND)0, NULL, filepath, NULL, NULL, SW_SHOWNORMAL);
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7109 Py_END_ALLOW_THREADS
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7110 if (rc <= (HINSTANCE)32)
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7111 return win32_error("startfile", filepath);
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7112 Py_INCREF(Py_None);
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7113 return Py_None;
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7114 }
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7115 #endif
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7116
26810
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7117 #ifdef HAVE_GETLOADAVG
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7118 PyDoc_STRVAR(posix_getloadavg__doc__,
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7119 "getloadavg() -> (float, float, float)\n\n\
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7120 Return the number of processes in the system run queue averaged over\n\
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7121 the last 1, 5, and 15 minutes or raises OSError if the load average\n\
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7122 was unobtainable");
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7123
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7124 static PyObject *
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7125 posix_getloadavg(PyObject *self, PyObject *noargs)
26810
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7126 {
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7127 double loadavg[3];
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7128 if (getloadavg(loadavg, 3)!=3) {
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7129 PyErr_SetString(PyExc_OSError, "Load averages are unobtainable");
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7130 return NULL;
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7131 } else
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7132 return Py_BuildValue("ddd", loadavg[0], loadavg[1], loadavg[2]);
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7133 }
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7134 #endif
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7135
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7136
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7137 static PyMethodDef posix_methods[] = {
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7138 {"access", posix_access, METH_VARARGS, posix_access__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7139 #ifdef HAVE_TTYNAME
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7140 {"ttyname", posix_ttyname, METH_VARARGS, posix_ttyname__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7141 #endif
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7142 {"chdir", posix_chdir, METH_VARARGS, posix_chdir__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7143 {"chmod", posix_chmod, METH_VARARGS, posix_chmod__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7144 #ifdef HAVE_CHOWN
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7145 {"chown", posix_chown, METH_VARARGS, posix_chown__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7146 #endif /* HAVE_CHOWN */
24413
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
7147 #ifdef HAVE_LCHOWN
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
7148 {"lchown", posix_lchown, METH_VARARGS, posix_lchown__doc__},
08926cc5f2af Patch #573770: Implement lchown.
Martin v. Löwis <martin@v.loewis.de>
parents: 24239
diff changeset
7149 #endif /* HAVE_LCHOWN */
20264
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
7150 #ifdef HAVE_CHROOT
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
7151 {"chroot", posix_chroot, METH_VARARGS, posix_chroot__doc__},
d092abcf9c4b Add chroot call. Implements feature #459267.
Martin v. Löwis <martin@v.loewis.de>
parents: 19754
diff changeset
7152 #endif
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7153 #ifdef HAVE_CTERMID
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7154 {"ctermid", posix_ctermid, METH_NOARGS, posix_ctermid__doc__},
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7155 #endif
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
7156 #ifdef HAVE_GETCWD
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7157 {"getcwd", posix_getcwd, METH_NOARGS, posix_getcwd__doc__},
26320
d41c4b95e714 Comment out the getcwdu implementation for --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents: 26092
diff changeset
7158 #ifdef Py_USING_UNICODE
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7159 {"getcwdu", posix_getcwdu, METH_NOARGS, posix_getcwdu__doc__},
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
7160 #endif
26320
d41c4b95e714 Comment out the getcwdu implementation for --disable-unicode builds
Walter Dörwald <walter@livinglogic.de>
parents: 26092
diff changeset
7161 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7162 #ifdef HAVE_LINK
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7163 {"link", posix_link, METH_VARARGS, posix_link__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7164 #endif /* HAVE_LINK */
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7165 {"listdir", posix_listdir, METH_VARARGS, posix_listdir__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7166 {"lstat", posix_lstat, METH_VARARGS, posix_lstat__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7167 {"mkdir", posix_mkdir, METH_VARARGS, posix_mkdir__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7168 #ifdef HAVE_NICE
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7169 {"nice", posix_nice, METH_VARARGS, posix_nice__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7170 #endif /* HAVE_NICE */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7171 #ifdef HAVE_READLINK
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7172 {"readlink", posix_readlink, METH_VARARGS, posix_readlink__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7173 #endif /* HAVE_READLINK */
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7174 {"rename", posix_rename, METH_VARARGS, posix_rename__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7175 {"rmdir", posix_rmdir, METH_VARARGS, posix_rmdir__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7176 {"stat", posix_stat, METH_VARARGS, posix_stat__doc__},
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
7177 {"stat_float_times", stat_float_times, METH_VARARGS, stat_float_times__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7178 #ifdef HAVE_SYMLINK
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7179 {"symlink", posix_symlink, METH_VARARGS, posix_symlink__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7180 #endif /* HAVE_SYMLINK */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7181 #ifdef HAVE_SYSTEM
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7182 {"system", posix_system, METH_VARARGS, posix_system__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7183 #endif
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7184 {"umask", posix_umask, METH_VARARGS, posix_umask__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7185 #ifdef HAVE_UNAME
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7186 {"uname", posix_uname, METH_NOARGS, posix_uname__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7187 #endif /* HAVE_UNAME */
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7188 {"unlink", posix_unlink, METH_VARARGS, posix_unlink__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7189 {"remove", posix_unlink, METH_VARARGS, posix_remove__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7190 {"utime", posix_utime, METH_VARARGS, posix_utime__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7191 #ifdef HAVE_TIMES
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7192 {"times", posix_times, METH_NOARGS, posix_times__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7193 #endif /* HAVE_TIMES */
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7194 {"_exit", posix__exit, METH_VARARGS, posix__exit__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7195 #ifdef HAVE_EXECV
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7196 {"execv", posix_execv, METH_VARARGS, posix_execv__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7197 {"execve", posix_execve, METH_VARARGS, posix_execve__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7198 #endif /* HAVE_EXECV */
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
7199 #ifdef HAVE_SPAWNV
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7200 {"spawnv", posix_spawnv, METH_VARARGS, posix_spawnv__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7201 {"spawnve", posix_spawnve, METH_VARARGS, posix_spawnve__doc__},
9954
c404a6b0cdb1 Add spawnv and spawnve functions for Win32 platforms.
Guido van Rossum <guido@python.org>
parents: 9939
diff changeset
7202 #endif /* HAVE_SPAWNV */
17419
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
7203 #ifdef HAVE_FORK1
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7204 {"fork1", posix_fork1, METH_NOARGS, posix_fork1__doc__},
17419
3fadc37cfa92 Unixware 7 support by Billy G. Allie (SF patch 413011)
Guido van Rossum <guido@python.org>
parents: 16792
diff changeset
7205 #endif /* HAVE_FORK1 */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7206 #ifdef HAVE_FORK
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7207 {"fork", posix_fork, METH_NOARGS, posix_fork__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7208 #endif /* HAVE_FORK */
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
7209 #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7210 {"openpty", posix_openpty, METH_NOARGS, posix_openpty__doc__},
26945
526742a74d06 Patch #656590: /dev/ptmx support for ptys.
Martin v. Löwis <martin@v.loewis.de>
parents: 26810
diff changeset
7211 #endif /* HAVE_OPENPTY || HAVE__GETPTY || HAVE_DEV_PTMX */
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
7212 #ifdef HAVE_FORKPTY
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7213 {"forkpty", posix_forkpty, METH_NOARGS, posix_forkpty__doc__},
13058
53f4022c0cd5 Thomas Wouters <thomas@xs4all.net>:
Fred Drake <fdrake@acm.org>
parents: 12865
diff changeset
7214 #endif /* HAVE_FORKPTY */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7215 #ifdef HAVE_GETEGID
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7216 {"getegid", posix_getegid, METH_NOARGS, posix_getegid__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7217 #endif /* HAVE_GETEGID */
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7218 #ifdef HAVE_GETEUID
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7219 {"geteuid", posix_geteuid, METH_NOARGS, posix_geteuid__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7220 #endif /* HAVE_GETEUID */
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7221 #ifdef HAVE_GETGID
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7222 {"getgid", posix_getgid, METH_NOARGS, posix_getgid__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7223 #endif /* HAVE_GETGID */
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7224 #ifdef HAVE_GETGROUPS
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7225 {"getgroups", posix_getgroups, METH_NOARGS, posix_getgroups__doc__},
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7226 #endif
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7227 {"getpid", posix_getpid, METH_NOARGS, posix_getpid__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7228 #ifdef HAVE_GETPGRP
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7229 {"getpgrp", posix_getpgrp, METH_NOARGS, posix_getpgrp__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7230 #endif /* HAVE_GETPGRP */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7231 #ifdef HAVE_GETPPID
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7232 {"getppid", posix_getppid, METH_NOARGS, posix_getppid__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7233 #endif /* HAVE_GETPPID */
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7234 #ifdef HAVE_GETUID
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7235 {"getuid", posix_getuid, METH_NOARGS, posix_getuid__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7236 #endif /* HAVE_GETUID */
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
7237 #ifdef HAVE_GETLOGIN
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7238 {"getlogin", posix_getlogin, METH_NOARGS, posix_getlogin__doc__},
11570
885820fa7e31 Added support for getlogin(); does *not* use getlogin_r() where
Fred Drake <fdrake@acm.org>
parents: 11560
diff changeset
7239 #endif
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7240 #ifdef HAVE_KILL
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7241 {"kill", posix_kill, METH_VARARGS, posix_kill__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7242 #endif /* HAVE_KILL */
21966
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
7243 #ifdef HAVE_KILLPG
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
7244 {"killpg", posix_killpg, METH_VARARGS, posix_killpg__doc__},
9c402523f8f5 Patch #511193: Implement killpg in posixmodule.
Martin v. Löwis <martin@v.loewis.de>
parents: 21859
diff changeset
7245 #endif /* HAVE_KILLPG */
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
7246 #ifdef HAVE_PLOCK
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7247 {"plock", posix_plock, METH_VARARGS, posix_plock__doc__},
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
7248 #endif /* HAVE_PLOCK */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7249 #ifdef HAVE_POPEN
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7250 {"popen", posix_popen, METH_VARARGS, posix_popen__doc__},
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
7251 #ifdef MS_WINDOWS
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
7252 {"popen2", win32_popen2, METH_VARARGS},
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
7253 {"popen3", win32_popen3, METH_VARARGS},
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
7254 {"popen4", win32_popen4, METH_VARARGS},
14752
46a6990769d1 Implemented new os.startfile function, unique to Windows, exposing a
Tim Peters <tim.peters@gmail.com>
parents: 14586
diff changeset
7255 {"startfile", win32_startfile, METH_VARARGS, win32_startfile__doc__},
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7256 #else
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7257 #if defined(PYOS_OS2) && defined(PYCC_GCC)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7258 {"popen2", os2emx_popen2, METH_VARARGS},
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7259 {"popen3", os2emx_popen3, METH_VARARGS},
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7260 {"popen4", os2emx_popen4, METH_VARARGS},
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7261 #endif
13468
b907ebf3b052 - improved os.popen support for windows, based on win32pipe
Fredrik Lundh <fredrik@pythonware.com>
parents: 13462
diff changeset
7262 #endif
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7263 #endif /* HAVE_POPEN */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7264 #ifdef HAVE_SETUID
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7265 {"setuid", posix_setuid, METH_VARARGS, posix_setuid__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7266 #endif /* HAVE_SETUID */
13582
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7267 #ifdef HAVE_SETEUID
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7268 {"seteuid", posix_seteuid, METH_VARARGS, posix_seteuid__doc__},
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7269 #endif /* HAVE_SETEUID */
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7270 #ifdef HAVE_SETEGID
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7271 {"setegid", posix_setegid, METH_VARARGS, posix_setegid__doc__},
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7272 #endif /* HAVE_SETEGID */
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7273 #ifdef HAVE_SETREUID
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7274 {"setreuid", posix_setreuid, METH_VARARGS, posix_setreuid__doc__},
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7275 #endif /* HAVE_SETREUID */
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7276 #ifdef HAVE_SETREGID
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7277 {"setregid", posix_setregid, METH_VARARGS, posix_setregid__doc__},
084a758051e0 From Sam Rushing's Medusa, via SF patch #100858: add & document
Andrew M. Kuchling <amk@amk.ca>
parents: 13576
diff changeset
7278 #endif /* HAVE_SETREGID */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7279 #ifdef HAVE_SETGID
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7280 {"setgid", posix_setgid, METH_VARARGS, posix_setgid__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7281 #endif /* HAVE_SETGID */
20508
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
7282 #ifdef HAVE_SETGROUPS
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
7283 {"setgroups", posix_setgroups, METH_VARARGS, posix_setgroups__doc__},
8e0c31849c64 Expose setgroups. Fixes feature request #468116.
Martin v. Löwis <martin@v.loewis.de>
parents: 20264
diff changeset
7284 #endif /* HAVE_SETGROUPS */
23833
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
7285 #ifdef HAVE_GETPGID
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
7286 {"getpgid", posix_getpgid, METH_VARARGS, posix_getpgid__doc__},
9f0ad0eb61f0 Patch #568235: Add posix.setpgid.
Martin v. Löwis <martin@v.loewis.de>
parents: 23832
diff changeset
7287 #endif /* HAVE_GETPGID */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7288 #ifdef HAVE_SETPGRP
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7289 {"setpgrp", posix_setpgrp, METH_NOARGS, posix_setpgrp__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7290 #endif /* HAVE_SETPGRP */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7291 #ifdef HAVE_WAIT
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7292 {"wait", posix_wait, METH_NOARGS, posix_wait__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
7293 #endif /* HAVE_WAIT */
21857
9cff890b4fb0 Implement os.waitpid() for Windows, in a way that's compatible with Linux
Tim Peters <tim.peters@gmail.com>
parents: 21839
diff changeset
7294 #if defined(HAVE_WAITPID) || defined(HAVE_CWAIT)
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7295 {"waitpid", posix_waitpid, METH_VARARGS, posix_waitpid__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7296 #endif /* HAVE_WAITPID */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7297 #ifdef HAVE_SETSID
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7298 {"setsid", posix_setsid, METH_NOARGS, posix_setsid__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7299 #endif /* HAVE_SETSID */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7300 #ifdef HAVE_SETPGID
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7301 {"setpgid", posix_setpgid, METH_VARARGS, posix_setpgid__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7302 #endif /* HAVE_SETPGID */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7303 #ifdef HAVE_TCGETPGRP
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7304 {"tcgetpgrp", posix_tcgetpgrp, METH_VARARGS, posix_tcgetpgrp__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7305 #endif /* HAVE_TCGETPGRP */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7306 #ifdef HAVE_TCSETPGRP
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7307 {"tcsetpgrp", posix_tcsetpgrp, METH_VARARGS, posix_tcsetpgrp__doc__},
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
7308 #endif /* HAVE_TCSETPGRP */
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7309 {"open", posix_open, METH_VARARGS, posix_open__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7310 {"close", posix_close, METH_VARARGS, posix_close__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7311 {"dup", posix_dup, METH_VARARGS, posix_dup__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7312 {"dup2", posix_dup2, METH_VARARGS, posix_dup2__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7313 {"lseek", posix_lseek, METH_VARARGS, posix_lseek__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7314 {"read", posix_read, METH_VARARGS, posix_read__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7315 {"write", posix_write, METH_VARARGS, posix_write__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7316 {"fstat", posix_fstat, METH_VARARGS, posix_fstat__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7317 {"fdopen", posix_fdopen, METH_VARARGS, posix_fdopen__doc__},
13641
38ea27455cbb new method isatty from Thomas Wouters
Skip Montanaro <skip@pobox.com>
parents: 13620
diff changeset
7318 {"isatty", posix_isatty, METH_VARARGS, posix_isatty__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7319 #ifdef HAVE_PIPE
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7320 {"pipe", posix_pipe, METH_NOARGS, posix_pipe__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7321 #endif
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7322 #ifdef HAVE_MKFIFO
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7323 {"mkfifo", posix_mkfifo, METH_VARARGS, posix_mkfifo__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7324 #endif
24429
f55d58ee4ea3 SF patch #584245, get python to link on OSF1 (Dec Unix)
Neal Norwitz <nnorwitz@gmail.com>
parents: 24413
diff changeset
7325 #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
23026
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
7326 {"mknod", posix_mknod, METH_VARARGS, posix_mknod__doc__},
f3fc97da68a9 Patch #543447: Add posix.mknod.
Martin v. Löwis <martin@v.loewis.de>
parents: 22773
diff changeset
7327 #endif
25694
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
7328 #ifdef HAVE_DEVICE_MACROS
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
7329 {"major", posix_major, METH_VARARGS, posix_major__doc__},
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
7330 {"minor", posix_minor, METH_VARARGS, posix_minor__doc__},
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
7331 {"makedev", posix_makedev, METH_VARARGS, posix_makedev__doc__},
e9e7f160aac9 Patch #569139: Implementation of major, minor and makedev.
Martin v. Löwis <martin@v.loewis.de>
parents: 25630
diff changeset
7332 #endif
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7333 #ifdef HAVE_FTRUNCATE
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7334 {"ftruncate", posix_ftruncate, METH_VARARGS, posix_ftruncate__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
7335 #endif
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
7336 #ifdef HAVE_PUTENV
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7337 {"putenv", posix_putenv, METH_VARARGS, posix_putenv__doc__},
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
7338 #endif
20551
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
7339 #ifdef HAVE_UNSETENV
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
7340 {"unsetenv", posix_unsetenv, METH_VARARGS, posix_unsetenv__doc__},
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 20548
diff changeset
7341 #endif
6315
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
7342 #ifdef HAVE_STRERROR
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7343 {"strerror", posix_strerror, METH_VARARGS, posix_strerror__doc__},
6315
d25489c5a22f Add strerror() interface.
Guido van Rossum <guido@python.org>
parents: 6130
diff changeset
7344 #endif
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7345 #ifdef HAVE_FCHDIR
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7346 {"fchdir", posix_fchdir, METH_O, posix_fchdir__doc__},
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7347 #endif
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
7348 #ifdef HAVE_FSYNC
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7349 {"fsync", posix_fsync, METH_O, posix_fsync__doc__},
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
7350 #endif
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
7351 #ifdef HAVE_FDATASYNC
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7352 {"fdatasync", posix_fdatasync, METH_O, posix_fdatasync__doc__},
9822
17e4d81949b9 Added fsync() and fdatasync(). Patches by Scott Cotton. Requires
Guido van Rossum <guido@python.org>
parents: 9795
diff changeset
7353 #endif
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7354 #ifdef HAVE_SYS_WAIT_H
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
7355 #ifdef WCOREDUMP
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
7356 {"WCOREDUMP", posix_WCOREDUMP, METH_VARARGS, posix_WCOREDUMP__doc__},
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
7357 #endif /* WCOREDUMP */
23379
e5df086ed455 Rename posix_WCONTINUED to posix_WIFCONTINUED, call WIFCONTINUED inside,
Martin v. Löwis <martin@v.loewis.de>
parents: 23242
diff changeset
7358 #ifdef WIFCONTINUED
e5df086ed455 Rename posix_WCONTINUED to posix_WIFCONTINUED, call WIFCONTINUED inside,
Martin v. Löwis <martin@v.loewis.de>
parents: 23242
diff changeset
7359 {"WIFCONTINUED",posix_WIFCONTINUED, METH_VARARGS, posix_WIFCONTINUED__doc__},
e5df086ed455 Rename posix_WCONTINUED to posix_WIFCONTINUED, call WIFCONTINUED inside,
Martin v. Löwis <martin@v.loewis.de>
parents: 23242
diff changeset
7360 #endif /* WIFCONTINUED */
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7361 #ifdef WIFSTOPPED
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7362 {"WIFSTOPPED", posix_WIFSTOPPED, METH_VARARGS, posix_WIFSTOPPED__doc__},
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7363 #endif /* WIFSTOPPED */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7364 #ifdef WIFSIGNALED
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7365 {"WIFSIGNALED", posix_WIFSIGNALED, METH_VARARGS, posix_WIFSIGNALED__doc__},
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7366 #endif /* WIFSIGNALED */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7367 #ifdef WIFEXITED
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7368 {"WIFEXITED", posix_WIFEXITED, METH_VARARGS, posix_WIFEXITED__doc__},
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7369 #endif /* WIFEXITED */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7370 #ifdef WEXITSTATUS
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7371 {"WEXITSTATUS", posix_WEXITSTATUS, METH_VARARGS, posix_WEXITSTATUS__doc__},
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7372 #endif /* WEXITSTATUS */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7373 #ifdef WTERMSIG
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7374 {"WTERMSIG", posix_WTERMSIG, METH_VARARGS, posix_WTERMSIG__doc__},
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7375 #endif /* WTERMSIG */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7376 #ifdef WSTOPSIG
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7377 {"WSTOPSIG", posix_WSTOPSIG, METH_VARARGS, posix_WSTOPSIG__doc__},
8810
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7378 #endif /* WSTOPSIG */
4aa76480d812 Patch by Jody Winston (with my changes) to add some of the "wait
Guido van Rossum <guido@python.org>
parents: 8708
diff changeset
7379 #endif /* HAVE_SYS_WAIT_H */
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7380 #ifdef HAVE_FSTATVFS
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7381 {"fstatvfs", posix_fstatvfs, METH_VARARGS, posix_fstatvfs__doc__},
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7382 #endif
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7383 #ifdef HAVE_STATVFS
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7384 {"statvfs", posix_statvfs, METH_VARARGS, posix_statvfs__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7385 #endif
15765
6d8f7e1242c0 Anonymous SF bug report #128053 point out that the #ifdef for
Guido van Rossum <guido@python.org>
parents: 15511
diff changeset
7386 #ifdef HAVE_TMPFILE
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7387 {"tmpfile", posix_tmpfile, METH_NOARGS, posix_tmpfile__doc__},
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7388 #endif
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7389 #ifdef HAVE_TEMPNAM
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7390 {"tempnam", posix_tempnam, METH_VARARGS, posix_tempnam__doc__},
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7391 #endif
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7392 #ifdef HAVE_TMPNAM
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7393 {"tmpnam", posix_tmpnam, METH_NOARGS, posix_tmpnam__doc__},
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7394 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7395 #ifdef HAVE_CONFSTR
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7396 {"confstr", posix_confstr, METH_VARARGS, posix_confstr__doc__},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7397 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7398 #ifdef HAVE_SYSCONF
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7399 {"sysconf", posix_sysconf, METH_VARARGS, posix_sysconf__doc__},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7400 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7401 #ifdef HAVE_FPATHCONF
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7402 {"fpathconf", posix_fpathconf, METH_VARARGS, posix_fpathconf__doc__},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7403 #endif
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7404 #ifdef HAVE_PATHCONF
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7405 {"pathconf", posix_pathconf, METH_VARARGS, posix_pathconf__doc__},
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7406 #endif
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7407 {"abort", posix_abort, METH_NOARGS, posix_abort__doc__},
24071
8142f8d668a0 Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents: 23937
diff changeset
7408 #ifdef MS_WINDOWS
17817
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
7409 {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL},
f7c385226f65 Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465.
Mark Hammond <mhammond@skippinet.com.au>
parents: 17518
diff changeset
7410 #endif
26810
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7411 #ifdef HAVE_GETLOADAVG
27916
93d44870e8b5 Added test_posix (hopefully it works on Windows).
Neal Norwitz <nnorwitz@gmail.com>
parents: 27826
diff changeset
7412 {"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__},
26810
9d0e62c9a128 Patch #657889: Implement posix.getloadavg.
Martin v. Löwis <martin@v.loewis.de>
parents: 26646
diff changeset
7413 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7414 {NULL, NULL} /* Sentinel */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7415 };
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7416
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7417
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7418 static int
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7419 ins(PyObject *module, char *symbol, long value)
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7420 {
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7421 return PyModule_AddIntConstant(module, symbol, value);
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7422 }
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7423
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7424 #if defined(PYOS_OS2)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7425 /* Insert Platform-Specific Constant Values (Strings & Numbers) of Common Use */
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7426 static int insertvalues(PyObject *module)
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7427 {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7428 APIRET rc;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7429 ULONG values[QSV_MAX+1];
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7430 PyObject *v;
21066
225c7dd17e37 Fixes for possible buffer overflows in sprintf() usages.
Marc-André Lemburg <mal@egenix.com>
parents: 21040
diff changeset
7431 char *ver, tmp[50];
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7432
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7433 Py_BEGIN_ALLOW_THREADS
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7434 rc = DosQuerySysInfo(1, QSV_MAX, &values[1], sizeof(values));
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7435 Py_END_ALLOW_THREADS
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7436
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7437 if (rc != NO_ERROR) {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7438 os2_error(rc);
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7439 return -1;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7440 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7441
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7442 if (ins(module, "meminstalled", values[QSV_TOTPHYSMEM])) return -1;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7443 if (ins(module, "memkernel", values[QSV_TOTRESMEM])) return -1;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7444 if (ins(module, "memvirtual", values[QSV_TOTAVAILMEM])) return -1;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7445 if (ins(module, "maxpathlen", values[QSV_MAX_PATH_LENGTH])) return -1;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7446 if (ins(module, "maxnamelen", values[QSV_MAX_COMP_LENGTH])) return -1;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7447 if (ins(module, "revision", values[QSV_VERSION_REVISION])) return -1;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7448 if (ins(module, "timeslice", values[QSV_MIN_SLICE])) return -1;
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7449
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7450 switch (values[QSV_VERSION_MINOR]) {
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7451 case 0: ver = "2.00"; break;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7452 case 10: ver = "2.10"; break;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7453 case 11: ver = "2.11"; break;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7454 case 30: ver = "3.00"; break;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7455 case 40: ver = "4.00"; break;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7456 case 50: ver = "5.00"; break;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7457 default:
21073
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 21066
diff changeset
7458 PyOS_snprintf(tmp, sizeof(tmp),
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 21066
diff changeset
7459 "%d-%d", values[QSV_VERSION_MAJOR],
304b34023876 sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents: 21066
diff changeset
7460 values[QSV_VERSION_MINOR]);
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7461 ver = &tmp[0];
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7462 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7463
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7464 /* Add Indicator of the Version of the Operating System */
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7465 if (PyModule_AddStringConstant(module, "version", tmp) < 0)
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7466 return -1;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7467
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7468 /* Add Indicator of Which Drive was Used to Boot the System */
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7469 tmp[0] = 'A' + values[QSV_BOOT_DRIVE] - 1;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7470 tmp[1] = ':';
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7471 tmp[2] = '\0';
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7472
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7473 return PyModule_AddStringConstant(module, "bootdrive", tmp);
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7474 }
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7475 #endif
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7476
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7477 static int
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13642
diff changeset
7478 all_ins(PyObject *d)
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7479 {
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7480 #ifdef F_OK
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7481 if (ins(d, "F_OK", (long)F_OK)) return -1;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7482 #endif
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7483 #ifdef R_OK
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7484 if (ins(d, "R_OK", (long)R_OK)) return -1;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7485 #endif
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7486 #ifdef W_OK
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7487 if (ins(d, "W_OK", (long)W_OK)) return -1;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7488 #endif
9785
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7489 #ifdef X_OK
facb457b4d32 Changes for long file support by Steve Clift.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
7490 if (ins(d, "X_OK", (long)X_OK)) return -1;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7491 #endif
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7492 #ifdef NGROUPS_MAX
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7493 if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1;
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7494 #endif
11532
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7495 #ifdef TMP_MAX
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7496 if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1;
2951e2d27852 Added support for abort(), ctermid(), tmpfile(), tempnam(), tmpnam(),
Fred Drake <fdrake@acm.org>
parents: 11391
diff changeset
7497 #endif
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
7498 #ifdef WCONTINUED
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
7499 if (ins(d, "WCONTINUED", (long)WCONTINUED)) return -1;
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
7500 #endif
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7501 #ifdef WNOHANG
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7502 if (ins(d, "WNOHANG", (long)WNOHANG)) return -1;
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7503 #endif
23242
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
7504 #ifdef WUNTRACED
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
7505 if (ins(d, "WUNTRACED", (long)WUNTRACED)) return -1;
4e234b87170b WCOREDUMP(), WIFCONTINUED(), WCONTINUED, WUNTRACED: New.
Fred Drake <fdrake@acm.org>
parents: 23193
diff changeset
7506 #endif
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7507 #ifdef O_RDONLY
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7508 if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7509 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7510 #ifdef O_WRONLY
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7511 if (ins(d, "O_WRONLY", (long)O_WRONLY)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7512 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7513 #ifdef O_RDWR
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7514 if (ins(d, "O_RDWR", (long)O_RDWR)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7515 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7516 #ifdef O_NDELAY
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7517 if (ins(d, "O_NDELAY", (long)O_NDELAY)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7518 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7519 #ifdef O_NONBLOCK
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7520 if (ins(d, "O_NONBLOCK", (long)O_NONBLOCK)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7521 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7522 #ifdef O_APPEND
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7523 if (ins(d, "O_APPEND", (long)O_APPEND)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7524 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7525 #ifdef O_DSYNC
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7526 if (ins(d, "O_DSYNC", (long)O_DSYNC)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7527 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7528 #ifdef O_RSYNC
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7529 if (ins(d, "O_RSYNC", (long)O_RSYNC)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7530 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7531 #ifdef O_SYNC
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7532 if (ins(d, "O_SYNC", (long)O_SYNC)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7533 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7534 #ifdef O_NOCTTY
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7535 if (ins(d, "O_NOCTTY", (long)O_NOCTTY)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7536 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7537 #ifdef O_CREAT
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7538 if (ins(d, "O_CREAT", (long)O_CREAT)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7539 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7540 #ifdef O_EXCL
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7541 if (ins(d, "O_EXCL", (long)O_EXCL)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7542 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7543 #ifdef O_TRUNC
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7544 if (ins(d, "O_TRUNC", (long)O_TRUNC)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7545 #endif
5967
9e4ddb459b10 Added O_BINARY and O_TEXT (for Windows).
Guido van Rossum <guido@python.org>
parents: 5725
diff changeset
7546 #ifdef O_BINARY
9e4ddb459b10 Added O_BINARY and O_TEXT (for Windows).
Guido van Rossum <guido@python.org>
parents: 5725
diff changeset
7547 if (ins(d, "O_BINARY", (long)O_BINARY)) return -1;
9e4ddb459b10 Added O_BINARY and O_TEXT (for Windows).
Guido van Rossum <guido@python.org>
parents: 5725
diff changeset
7548 #endif
9e4ddb459b10 Added O_BINARY and O_TEXT (for Windows).
Guido van Rossum <guido@python.org>
parents: 5725
diff changeset
7549 #ifdef O_TEXT
9e4ddb459b10 Added O_BINARY and O_TEXT (for Windows).
Guido van Rossum <guido@python.org>
parents: 5725
diff changeset
7550 if (ins(d, "O_TEXT", (long)O_TEXT)) return -1;
9e4ddb459b10 Added O_BINARY and O_TEXT (for Windows).
Guido van Rossum <guido@python.org>
parents: 5725
diff changeset
7551 #endif
20548
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7552 #ifdef O_LARGEFILE
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7553 if (ins(d, "O_LARGEFILE", (long)O_LARGEFILE)) return -1;
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7554 #endif
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7555
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7556 /* MS Windows */
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7557 #ifdef O_NOINHERIT
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7558 /* Don't inherit in child processes. */
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7559 if (ins(d, "O_NOINHERIT", (long)O_NOINHERIT)) return -1;
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7560 #endif
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7561 #ifdef _O_SHORT_LIVED
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7562 /* Optimize for short life (keep in memory). */
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7563 /* MS forgot to define this one with a non-underscore form too. */
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7564 if (ins(d, "O_SHORT_LIVED", (long)_O_SHORT_LIVED)) return -1;
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7565 #endif
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7566 #ifdef O_TEMPORARY
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7567 /* Automatically delete when last handle is closed. */
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7568 if (ins(d, "O_TEMPORARY", (long)O_TEMPORARY)) return -1;
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7569 #endif
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7570 #ifdef O_RANDOM
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7571 /* Optimize for random access. */
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7572 if (ins(d, "O_RANDOM", (long)O_RANDOM)) return -1;
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7573 #endif
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7574 #ifdef O_SEQUENTIAL
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7575 /* Optimize for sequential access. */
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7576 if (ins(d, "O_SEQUENTIAL", (long)O_SEQUENTIAL)) return -1;
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7577 #endif
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7578
20548
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7579 /* GNU extensions. */
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7580 #ifdef O_DIRECT
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7581 /* Direct disk access. */
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7582 if (ins(d, "O_DIRECT", (long)O_DIRECT)) return -1;
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7583 #endif
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7584 #ifdef O_DIRECTORY
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7585 /* Must be a directory. */
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7586 if (ins(d, "O_DIRECTORY", (long)O_DIRECTORY)) return -1;
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7587 #endif
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7588 #ifdef O_NOFOLLOW
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7589 /* Do not follow links. */
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7590 if (ins(d, "O_NOFOLLOW", (long)O_NOFOLLOW)) return -1;
a56427e5c5e1 Expose O_LARGEFILE, O_DIRECT, O_DIRECTORY, and O_NOFOLLOW.
Martin v. Löwis <martin@v.loewis.de>
parents: 20543
diff changeset
7591 #endif
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7592
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7593 /* These come from sysexits.h */
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7594 #ifdef EX_OK
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7595 if (ins(d, "EX_OK", (long)EX_OK)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7596 #endif /* EX_OK */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7597 #ifdef EX_USAGE
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7598 if (ins(d, "EX_USAGE", (long)EX_USAGE)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7599 #endif /* EX_USAGE */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7600 #ifdef EX_DATAERR
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7601 if (ins(d, "EX_DATAERR", (long)EX_DATAERR)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7602 #endif /* EX_DATAERR */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7603 #ifdef EX_NOINPUT
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7604 if (ins(d, "EX_NOINPUT", (long)EX_NOINPUT)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7605 #endif /* EX_NOINPUT */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7606 #ifdef EX_NOUSER
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7607 if (ins(d, "EX_NOUSER", (long)EX_NOUSER)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7608 #endif /* EX_NOUSER */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7609 #ifdef EX_NOHOST
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7610 if (ins(d, "EX_NOHOST", (long)EX_NOHOST)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7611 #endif /* EX_NOHOST */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7612 #ifdef EX_UNAVAILABLE
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7613 if (ins(d, "EX_UNAVAILABLE", (long)EX_UNAVAILABLE)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7614 #endif /* EX_UNAVAILABLE */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7615 #ifdef EX_SOFTWARE
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7616 if (ins(d, "EX_SOFTWARE", (long)EX_SOFTWARE)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7617 #endif /* EX_SOFTWARE */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7618 #ifdef EX_OSERR
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7619 if (ins(d, "EX_OSERR", (long)EX_OSERR)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7620 #endif /* EX_OSERR */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7621 #ifdef EX_OSFILE
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7622 if (ins(d, "EX_OSFILE", (long)EX_OSFILE)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7623 #endif /* EX_OSFILE */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7624 #ifdef EX_CANTCREAT
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7625 if (ins(d, "EX_CANTCREAT", (long)EX_CANTCREAT)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7626 #endif /* EX_CANTCREAT */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7627 #ifdef EX_IOERR
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7628 if (ins(d, "EX_IOERR", (long)EX_IOERR)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7629 #endif /* EX_IOERR */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7630 #ifdef EX_TEMPFAIL
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7631 if (ins(d, "EX_TEMPFAIL", (long)EX_TEMPFAIL)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7632 #endif /* EX_TEMPFAIL */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7633 #ifdef EX_PROTOCOL
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7634 if (ins(d, "EX_PROTOCOL", (long)EX_PROTOCOL)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7635 #endif /* EX_PROTOCOL */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7636 #ifdef EX_NOPERM
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7637 if (ins(d, "EX_NOPERM", (long)EX_NOPERM)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7638 #endif /* EX_NOPERM */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7639 #ifdef EX_CONFIG
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7640 if (ins(d, "EX_CONFIG", (long)EX_CONFIG)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7641 #endif /* EX_CONFIG */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7642 #ifdef EX_NOTFOUND
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7643 if (ins(d, "EX_NOTFOUND", (long)EX_NOTFOUND)) return -1;
27199
77b70a8884cb Get rid of compiler warnings
Neal Norwitz <nnorwitz@gmail.com>
parents: 27139
diff changeset
7644 #endif /* EX_NOTFOUND */
27139
7bbb0dd8d230 all_ins(): EX_OK and friends, constants from sysexits.h
Barry Warsaw <barry@python.org>
parents: 26998
diff changeset
7645
10069
5e01645ee41b Add _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 10066
diff changeset
7646 #ifdef HAVE_SPAWNV
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7647 #if defined(PYOS_OS2) && defined(PYCC_GCC)
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7648 if (ins(d, "P_WAIT", (long)P_WAIT)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7649 if (ins(d, "P_NOWAIT", (long)P_NOWAIT)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7650 if (ins(d, "P_OVERLAY", (long)P_OVERLAY)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7651 if (ins(d, "P_DEBUG", (long)P_DEBUG)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7652 if (ins(d, "P_SESSION", (long)P_SESSION)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7653 if (ins(d, "P_DETACH", (long)P_DETACH)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7654 if (ins(d, "P_PM", (long)P_PM)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7655 if (ins(d, "P_DEFAULT", (long)P_DEFAULT)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7656 if (ins(d, "P_MINIMIZE", (long)P_MINIMIZE)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7657 if (ins(d, "P_MAXIMIZE", (long)P_MAXIMIZE)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7658 if (ins(d, "P_FULLSCREEN", (long)P_FULLSCREEN)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7659 if (ins(d, "P_WINDOWED", (long)P_WINDOWED)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7660 if (ins(d, "P_FOREGROUND", (long)P_FOREGROUND)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7661 if (ins(d, "P_BACKGROUND", (long)P_BACKGROUND)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7662 if (ins(d, "P_NOCLOSE", (long)P_NOCLOSE)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7663 if (ins(d, "P_NOSESSION", (long)P_NOSESSION)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7664 if (ins(d, "P_QUOTE", (long)P_QUOTE)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7665 if (ins(d, "P_TILDE", (long)P_TILDE)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7666 if (ins(d, "P_UNRELATED", (long)P_UNRELATED)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7667 if (ins(d, "P_DEBUGDESC", (long)P_DEBUGDESC)) return -1;
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7668 #else
10188
6633c3fca626 The symbols P_* (for spawn*(), MS specific) should not have a leading
Guido van Rossum <guido@python.org>
parents: 10178
diff changeset
7669 if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1;
6633c3fca626 The symbols P_* (for spawn*(), MS specific) should not have a leading
Guido van Rossum <guido@python.org>
parents: 10178
diff changeset
7670 if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1;
6633c3fca626 The symbols P_* (for spawn*(), MS specific) should not have a leading
Guido van Rossum <guido@python.org>
parents: 10178
diff changeset
7671 if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1;
6633c3fca626 The symbols P_* (for spawn*(), MS specific) should not have a leading
Guido van Rossum <guido@python.org>
parents: 10178
diff changeset
7672 if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1;
6633c3fca626 The symbols P_* (for spawn*(), MS specific) should not have a leading
Guido van Rossum <guido@python.org>
parents: 10178
diff changeset
7673 if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1;
10069
5e01645ee41b Add _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 10066
diff changeset
7674 #endif
22116
0c4230269ed3 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21966
diff changeset
7675 #endif
10069
5e01645ee41b Add _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 10066
diff changeset
7676
6766
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7677 #if defined(PYOS_OS2)
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7678 if (insertvalues(d)) return -1;
89092ad1e660 Another large batch of patches from Jeff Rush for OS/2.
Guido van Rossum <guido@python.org>
parents: 6717
diff changeset
7679 #endif
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7680 return 0;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7681 }
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7682
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7683
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7684 #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__)
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 6315
diff changeset
7685 #define INITFUNC initnt
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 6315
diff changeset
7686 #define MODNAME "nt"
17831
5c06a9596fbf SF patch #418147 Fixes to allow compiling w/ Borland, from Stephen Hansen.
Tim Peters <tim.peters@gmail.com>
parents: 17822
diff changeset
7687
5c06a9596fbf SF patch #418147 Fixes to allow compiling w/ Borland, from Stephen Hansen.
Tim Peters <tim.peters@gmail.com>
parents: 17822
diff changeset
7688 #elif defined(PYOS_OS2)
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
7689 #define INITFUNC initos2
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
7690 #define MODNAME "os2"
17831
5c06a9596fbf SF patch #418147 Fixes to allow compiling w/ Borland, from Stephen Hansen.
Tim Peters <tim.peters@gmail.com>
parents: 17822
diff changeset
7691
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6578
diff changeset
7692 #else
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 6315
diff changeset
7693 #define INITFUNC initposix
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 6315
diff changeset
7694 #define MODNAME "posix"
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 6315
diff changeset
7695 #endif
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7696
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24469
diff changeset
7697 PyMODINIT_FUNC
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13642
diff changeset
7698 INITFUNC(void)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7699 {
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7700 PyObject *m, *v;
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7701
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7702 m = Py_InitModule3(MODNAME,
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
7703 posix_methods,
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7704 posix__doc__);
21839
5e67ad76c72f Expose more MS WIndows constants usable w/ low-level os.open().
Tim Peters <tim.peters@gmail.com>
parents: 21712
diff changeset
7705
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 6315
diff changeset
7706 /* Initialize environ dictionary */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7707 v = convertenviron();
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7708 Py_XINCREF(v);
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7709 if (v == NULL || PyModule_AddObject(m, "environ", v) != 0)
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 6315
diff changeset
7710 return;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
7711 Py_DECREF(v);
11559
22f4cf16b5a3 Added bindings for getgroups(), fpathconf(), pathconf(), confstr(),
Fred Drake <fdrake@acm.org>
parents: 11532
diff changeset
7712
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7713 if (all_ins(m))
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7714 return;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
7715
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7716 if (setup_confname_tables(m))
11577
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7717 return;
57c1685acb16 Rip out the code to check the ordering of the tables used to map
Fred Drake <fdrake@acm.org>
parents: 11574
diff changeset
7718
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7719 Py_INCREF(PyExc_OSError);
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7720 PyModule_AddObject(m, "error", PyExc_OSError);
11230
b69859b69763 posix_putenv(): Constrain memory leakage when setting the same
Fred Drake <fdrake@acm.org>
parents: 11172
diff changeset
7721
11686
93bed60355e4 The initialization of posix_putenv_garbage should only be done when it
Guido van Rossum <guido@python.org>
parents: 11639
diff changeset
7722 #ifdef HAVE_PUTENV
15904
149458a5740a Plug memory leak.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15765
diff changeset
7723 if (posix_putenv_garbage == NULL)
149458a5740a Plug memory leak.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 15765
diff changeset
7724 posix_putenv_garbage = PyDict_New();
11686
93bed60355e4 The initialization of posix_putenv_garbage should only be done when it
Guido van Rossum <guido@python.org>
parents: 11639
diff changeset
7725 #endif
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
7726
21313
91dd223829c6 Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents: 21295
diff changeset
7727 stat_result_desc.name = MODNAME ".stat_result";
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
7728 stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
7729 stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
7730 stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
7731 PyStructSequence_InitType(&StatResultType, &stat_result_desc);
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
7732 structseq_new = StatResultType.tp_new;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 25804
diff changeset
7733 StatResultType.tp_new = statresult_new;
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7734 Py_INCREF((PyObject*) &StatResultType);
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7735 PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
7736
21313
91dd223829c6 Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents: 21295
diff changeset
7737 statvfs_result_desc.name = MODNAME ".statvfs_result";
20539
2d599a36b67a SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents: 20537
diff changeset
7738 PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);
23056
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7739 Py_INCREF((PyObject*) &StatVFSResultType);
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7740 PyModule_AddObject(m, "statvfs_result",
a135980dd4e9 posix_fildes(): New helper: run a function that takes a file descriptor
Fred Drake <fdrake@acm.org>
parents: 23026
diff changeset
7741 (PyObject*) &StatVFSResultType);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
7742 }