annotate Modules/posixmodule.c @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 9a3b115aa491
children 9e4ddb459b10
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 /***********************************************************
2061
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 2055
diff changeset
3 The Netherlands.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 117
diff changeset
4
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 117
diff changeset
5 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 117
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
8 documentation for any purpose and without fee is hereby granted,
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 117
diff changeset
9 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
10 both that copyright notice and this permission notice appear in
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 117
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
15 permission.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 117
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
17 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
18 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4233
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 117
diff changeset
29
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 117
diff changeset
30 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 117
diff changeset
31
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 /* POSIX module implementation */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
34 /* This file is also used for Windows NT and MS-Win. In that case the module
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
35 actually calls itself 'nt', not 'posix', and a few functions are
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
36 either unimplemented or implemented differently. The source
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
37 assumes that for Windows NT, the macro 'MS_WIN32' is defined independent
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
38 of the compiler used. Different compilers define their own feature
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
39 test macro, e.g. '__BORLANDC__' or '_MSC_VER'. */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
40
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
41 /* See also ../Dos/dosmodule.c */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
42
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
43 static char posix__doc__ [] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
44 "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
45 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
46 disguised Unix interface). Refer to the library manual and\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
47 corresponding Unix manual entries for more information on calls.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
48
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
49
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
50
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
51 #include "Python.h"
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
53 #include <sys/types.h>
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
54 #include <sys/stat.h>
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
55 #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
56 #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
57 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
58
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
59 #ifdef HAVE_SIGNAL_H
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
60 #include <signal.h>
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
61 #endif
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
62
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
63 #include "mytime.h" /* For clock_t on some systems */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
64
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
65 #ifdef HAVE_FCNTL_H
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
66 #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
67 #endif /* HAVE_FCNTL_H */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
68
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
69 /* Various compilers have only certain posix functions */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
70 #ifdef __WATCOMC__ /* Watcom compiler */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
71 #define HAVE_GETCWD 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
72 #define HAVE_OPENDIR 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
73 #define HAVE_SYSTEM 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
74 #if defined(__OS2__)
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
75 #define HAVE_EXECV 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
76 #define HAVE_WAIT 1
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
77 #endif
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
78 #include <process.h>
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
79 #else
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
80 #ifdef __BORLANDC__ /* Borland compiler */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
81 #define HAVE_EXECV 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
82 #define HAVE_GETCWD 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
83 #define HAVE_GETEGID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
84 #define HAVE_GETEUID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
85 #define HAVE_GETGID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
86 #define HAVE_GETPPID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
87 #define HAVE_GETUID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
88 #define HAVE_KILL 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
89 #define HAVE_OPENDIR 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
90 #define HAVE_PIPE 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
91 #define HAVE_POPEN 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
92 #define HAVE_SYSTEM 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
93 #define HAVE_WAIT 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
94 #else
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
95 #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
96 #define HAVE_GETCWD 1
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
97 #ifdef MS_WIN32
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
98 #define HAVE_EXECV 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
99 #define HAVE_PIPE 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
100 #define HAVE_POPEN 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
101 #define HAVE_SYSTEM 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
102 #else /* 16-bit Windows */
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
103 #endif /* !MS_WIN32 */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
104 #else /* all other compilers */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
105 /* 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
106 #define HAVE_EXECV 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
107 #define HAVE_FORK 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
108 #define HAVE_GETCWD 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
109 #define HAVE_GETEGID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
110 #define HAVE_GETEUID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
111 #define HAVE_GETGID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
112 #define HAVE_GETPPID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
113 #define HAVE_GETUID 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
114 #define HAVE_KILL 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
115 #define HAVE_OPENDIR 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
116 #define HAVE_PIPE 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
117 #define HAVE_POPEN 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
118 #define HAVE_SYSTEM 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
119 #define HAVE_WAIT 1
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
120 #endif /* _MSC_VER */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
121 #endif /* __BORLANDC__ */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
122 #endif /* ! __WATCOMC__ */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
123
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
124 #ifndef _MSC_VER
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
125
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
126 #ifdef HAVE_UNISTD_H
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 1181
diff changeset
127 #include <unistd.h>
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
128 #endif
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
129
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
130 #ifdef NeXT
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
131 /* NeXT's <unistd.h> and <utime.h> aren't worth much */
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
132 #undef HAVE_UNISTD_H
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
133 #undef HAVE_UTIME_H
5584
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
134 #define HAVE_WAITPID
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
135 /* #undef HAVE_GETCWD */
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
136 #endif
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
137
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
138 #ifdef HAVE_UNISTD_H
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
139 /* XXX These are for SunOS4.1.3 but shouldn't hurt elsewhere */
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
140 extern int rename();
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
141 extern int pclose();
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
142 extern int lstat();
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
143 extern int symlink();
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
144 #else /* !HAVE_UNISTD_H */
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
145 #if defined(__WATCOMC__) || defined(_MSC_VER)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
146 extern int mkdir Py_PROTO((const char *));
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
147 #else
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
148 extern int mkdir Py_PROTO((const char *, mode_t));
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
149 #endif
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
150 extern int chdir Py_PROTO((const char *));
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
151 extern int rmdir Py_PROTO((const char *));
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
152 extern int chmod Py_PROTO((const char *, mode_t));
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
153 extern int chown Py_PROTO((const char *, uid_t, gid_t));
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
154 extern char *getcwd Py_PROTO((char *, int));
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
155 extern char *strerror Py_PROTO((int));
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
156 extern int link Py_PROTO((const char *, const char *));
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
157 extern int rename Py_PROTO((const char *, const char *));
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
158 extern int stat Py_PROTO((const char *, struct stat *));
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
159 extern int unlink Py_PROTO((const char *));
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
160 extern int pclose Py_PROTO((FILE *));
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
161 #ifdef HAVE_SYMLINK
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
162 extern int symlink Py_PROTO((const char *, const char *));
2370
e386035f897d fix comment opener after #endif
Guido van Rossum <guido@python.org>
parents: 2298
diff changeset
163 #endif /* HAVE_SYMLINK */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
164 #ifdef HAVE_LSTAT
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
165 extern int lstat Py_PROTO((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
166 #endif /* HAVE_LSTAT */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
167 #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
168
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
169 #endif /* !_MSC_VER */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
170
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
171 #ifdef HAVE_UTIME_H
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
172 #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
173 #endif /* HAVE_UTIME_H */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
174
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
175 #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
176 #include <sys/utime.h>
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
177 #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
178 #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
179
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
180 #ifdef HAVE_SYS_TIMES_H
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
181 #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
182 #endif /* HAVE_SYS_TIMES_H */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
183
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
184 #ifdef HAVE_SYS_PARAM_H
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
185 #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
186 #endif /* HAVE_SYS_PARAM_H */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
187
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
188 #ifdef HAVE_SYS_UTSNAME_H
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
189 #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
190 #endif /* HAVE_SYS_UTSNAME_H */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
191
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
192 #ifndef MAXPATHLEN
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
193 #define MAXPATHLEN 1024
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
194 #endif /* MAXPATHLEN */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
195
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
196 #ifdef HAVE_DIRENT_H
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
197 #include <dirent.h>
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
198 #define NAMLEN(dirent) strlen((dirent)->d_name)
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
199 #else
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
200 #ifdef __WATCOMC__
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
201 #include <direct.h>
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
202 #define NAMLEN(dirent) strlen((dirent)->d_name)
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
203 #else
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
204 #define dirent direct
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
205 #define NAMLEN(dirent) (dirent)->d_namlen
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
206 #endif
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
207 #ifdef HAVE_SYS_NDIR_H
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
208 #include <sys/ndir.h>
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
209 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
210 #ifdef HAVE_SYS_DIR_H
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
211 #include <sys/dir.h>
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
212 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
213 #ifdef HAVE_NDIR_H
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
214 #include <ndir.h>
2055
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
215 #endif
cf31eab6ab5a Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents: 1983
diff changeset
216 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
217
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
218 #ifdef _MSC_VER
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
219 #include <direct.h>
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
220 #include <io.h>
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
221 #include <process.h>
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
222 #include <windows.h>
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
223 #ifdef MS_WIN32
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
224 #define popen _popen
1815
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
225 #define pclose _pclose
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
226 #else /* 16-bit Windows */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
227 #include <dos.h>
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
228 #include <ctype.h>
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
229 #endif /* MS_WIN32 */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
230 #endif /* _MSC_VER */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
231
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
232 #ifdef OS2
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
233 #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
234 #endif /* OS2 */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
235
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 /* Return a dictionary corresponding to the POSIX environment table */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
237
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
238 #if !defined(_MSC_VER) && !defined(__WATCOMC__)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 extern char **environ;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
240 #endif /* !_MSC_VER */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
241
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
242 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 convertenviron()
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
245 PyObject *d;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 char **e;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
247 d = PyDict_New();
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 if (d == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 return NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 if (environ == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 return d;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 /* XXX This part ignores errors */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 for (e = environ; *e != NULL; e++) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
254 PyObject *v;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 char *p = strchr(*e, '=');
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 if (p == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 continue;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
258 v = PyString_FromString(p+1);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 if (v == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 continue;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 *p = '\0';
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
262 (void) PyDict_SetItemString(d, *e, v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 *p = '=';
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
264 Py_DECREF(v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 return d;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
268
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
269
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
270 static PyObject *PosixError; /* Exception posix.error */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
271
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 /* Set a POSIX-specific error from errno, and return NULL */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
273
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
274 static PyObject * posix_error()
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
275 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
276 return PyErr_SetFromErrno(PosixError);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
278
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
279
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 /* POSIX generic methods */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
281
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
282 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 posix_1str(args, func)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
284 PyObject *args;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
285 int (*func) Py_FPROTO((const char *));
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 {
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
287 char *path1;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
288 int res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
289 if (!PyArg_Parse(args, "s", &path1))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
291 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
292 res = (*func)(path1);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
293 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
294 if (res < 0)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
296 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
297 return Py_None;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
299
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
300 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 posix_2str(args, func)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
302 PyObject *args;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
303 int (*func) Py_FPROTO((const char *, const char *));
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 {
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
305 char *path1, *path2;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
306 int res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
307 if (!PyArg_Parse(args, "(ss)", &path1, &path2))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
309 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
310 res = (*func)(path1, path2);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
311 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
312 if (res < 0)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
314 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
315 return Py_None;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
317
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
318 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 posix_strint(args, func)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
320 PyObject *args;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
321 int (*func) Py_FPROTO((const char *, int));
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 {
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
323 char *path;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 int i;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
325 int res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
326 if (!PyArg_Parse(args, "(si)", &path, &i))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
328 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
329 res = (*func)(path, i);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
330 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
331 if (res < 0)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
333 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
334 return Py_None;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
336
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
337 static PyObject *
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
338 posix_strintint(args, func)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
339 PyObject *args;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
340 int (*func) Py_FPROTO((const char *, int, int));
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
341 {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
342 char *path;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
343 int i,i2;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
344 int res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
345 if (!PyArg_Parse(args, "(sii)", &path, &i, &i2))
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
346 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
347 Py_BEGIN_ALLOW_THREADS
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
348 res = (*func)(path, i, i2);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
349 Py_END_ALLOW_THREADS
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
350 if (res < 0)
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
351 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
352 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
353 return Py_None;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
354 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
355
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
356 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 posix_do_stat(self, args, statfunc)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
358 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
359 PyObject *args;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
360 int (*statfunc) Py_FPROTO((const char *, struct stat *));
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 struct stat st;
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
363 char *path;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
364 int res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
365 if (!PyArg_Parse(args, "s", &path))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
367 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
368 res = (*statfunc)(path, &st);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
369 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
370 if (res != 0)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
372 return Py_BuildValue("(llllllllll)",
1252
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
373 (long)st.st_mode,
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
374 (long)st.st_ino,
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
375 (long)st.st_dev,
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
376 (long)st.st_nlink,
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
377 (long)st.st_uid,
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
378 (long)st.st_gid,
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
379 (long)st.st_size,
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
380 (long)st.st_atime,
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
381 (long)st.st_mtime,
c4cd0d9d8281 * Changed many files to use mkvalue() instead of newtupleobject().
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
382 (long)st.st_ctime);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
384
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
385
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 /* POSIX methods */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
387
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
388 static char posix_chdir__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
389 "chdir(path) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
390 Change the current working directory to the specified path.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
391
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
392 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 posix_chdir(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
394 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
395 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 return posix_1str(args, chdir);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
399
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
400
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
401 static char posix_chmod__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
402 "chmod(path, mode) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
403 Change the access permissions of a file.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
404
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
405 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 posix_chmod(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
407 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
408 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 return posix_strint(args, chmod);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
412
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
413
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
414 #ifdef HAVE_CHOWN
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
415 static char posix_chown__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
416 "chown(path, uid, gid) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
417 Change the owner and group id of path to the numeric uid and gid.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
418
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
419 static PyObject *
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
420 posix_chown(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
421 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
422 PyObject *args;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
423 {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
424 return posix_strintint(args, chown);
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
425 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
426 #endif /* HAVE_CHOWN */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
427
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
428
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
429 #ifdef HAVE_GETCWD
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
430 static char posix_getcwd__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
431 "getcwd() -> path\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
432 Return a string representing the current working directory.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
433
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
434 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 posix_getcwd(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
436 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
437 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 char buf[1026];
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
440 char *res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
441 if (!PyArg_NoArgs(args))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
443 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
444 res = getcwd(buf, sizeof buf);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
445 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
446 if (res == NULL)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
448 return PyString_FromString(buf);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 }
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
450 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
451
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
452
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
453 #ifdef HAVE_LINK
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
454 static char posix_link__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
455 "link(src, dst) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
456 Create a hard link to a file.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
457
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
458 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 posix_link(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
460 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
461 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
462 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
463 return posix_2str(args, link);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
464 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
465 #endif /* HAVE_LINK */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
466
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
467
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
468 static char posix_listdir__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
469 "listdir(path) -> list_of_strings\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
470 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
471 \n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
472 path: path of directory to list\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
473 \n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
474 The list is in arbitrary order. It does not include the special\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
475 entries '.' and '..' even if they are present in the directory.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
476
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
477 static PyObject *
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
478 posix_listdir(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
479 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
480 PyObject *args;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
481 {
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
482 #if defined(MS_WIN32) && !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
483
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
484 char *name;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
485 int len;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
486 PyObject *d, *v;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
487 HANDLE hFindFile;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
488 WIN32_FIND_DATA FileData;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
489 char namebuf[MAX_PATH+5];
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
490
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
491 if (!PyArg_Parse(args, "s#", &name, &len))
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
492 return NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
493 if (len >= MAX_PATH) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
494 PyErr_SetString(PyExc_ValueError, "path too long");
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
495 return NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
496 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
497 strcpy(namebuf, name);
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
498 if (namebuf[len-1] != '/' && namebuf[len-1] != '\\')
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
499 namebuf[len++] = '/';
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
500 strcpy(namebuf + len, "*.*");
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
501
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
502 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
503 return NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
504
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
505 hFindFile = FindFirstFile(namebuf, &FileData);
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
506 if (hFindFile == INVALID_HANDLE_VALUE) {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
507 errno = GetLastError();
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
508 return posix_error();
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
509 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
510 do {
2845
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
511 if (FileData.cFileName[0] == '.' &&
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
512 (FileData.cFileName[1] == '\0' ||
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
513 FileData.cFileName[1] == '.' &&
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
514 FileData.cFileName[2] == '\0'))
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
515 continue;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
516 v = PyString_FromString(FileData.cFileName);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
517 if (v == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
518 Py_DECREF(d);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
519 d = NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
520 break;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
521 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
522 if (PyList_Append(d, v) != 0) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
523 Py_DECREF(v);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
524 Py_DECREF(d);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
525 d = NULL;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
526 break;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
527 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
528 Py_DECREF(v);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
529 } while (FindNextFile(hFindFile, &FileData) == TRUE);
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
530
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
531 if (FindClose(hFindFile) == FALSE) {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
532 errno = GetLastError();
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
533 return posix_error();
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
534 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
535
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
536 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
537
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
538 #else /* !MS_WIN32 */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
539 #ifdef _MSC_VER /* 16-bit Windows */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
540
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
541 #ifndef MAX_PATH
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
542 #define MAX_PATH 250
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
543 #endif
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
544 char *name, *pt;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
545 int len;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
546 PyObject *d, *v;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
547 char namebuf[MAX_PATH+5];
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
548 struct _find_t ep;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
549
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
550 if (!PyArg_Parse(args, "s#", &name, &len))
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
551 return NULL;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
552 if (len >= MAX_PATH) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
553 PyErr_SetString(PyExc_ValueError, "path too long");
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
554 return NULL;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
555 }
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
556 strcpy(namebuf, name);
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
557 for (pt = namebuf; *pt; pt++)
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
558 if (*pt == '/')
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
559 *pt = '\\';
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
560 if (namebuf[len-1] != '\\')
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
561 namebuf[len++] = '\\';
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
562 strcpy(namebuf + len, "*.*");
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
563
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
564 if ((d = PyList_New(0)) == NULL)
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
565 return NULL;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
566
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
567 if (_dos_findfirst(namebuf, _A_RDONLY |
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
568 _A_HIDDEN | _A_SYSTEM | _A_SUBDIR, &ep) != 0)
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
569 {
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
570 errno = ENOENT;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
571 return posix_error();
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
572 }
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
573 do {
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
574 if (ep.name[0] == '.' &&
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
575 (ep.name[1] == '\0' ||
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
576 ep.name[1] == '.' &&
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
577 ep.name[2] == '\0'))
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
578 continue;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
579 strcpy(namebuf, ep.name);
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
580 for (pt = namebuf; *pt; pt++)
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
581 if (isupper(*pt))
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
582 *pt = tolower(*pt);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
583 v = PyString_FromString(namebuf);
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
584 if (v == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
585 Py_DECREF(d);
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
586 d = NULL;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
587 break;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
588 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
589 if (PyList_Append(d, v) != 0) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
590 Py_DECREF(v);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
591 Py_DECREF(d);
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
592 d = NULL;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
593 break;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
594 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
595 Py_DECREF(v);
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
596 } while (_dos_findnext(&ep) == 0);
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
597
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
598 return d;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
599
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
600 #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
601
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
602 char *name;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
603 PyObject *d, *v;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
604 DIR *dirp;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
605 struct dirent *ep;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
606 if (!PyArg_Parse(args, "s", &name))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
607 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
608 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
609 if ((dirp = opendir(name)) == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
610 Py_BLOCK_THREADS
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
611 return posix_error();
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
612 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
613 if ((d = PyList_New(0)) == NULL) {
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
614 closedir(dirp);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
615 Py_BLOCK_THREADS
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
616 return NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
617 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
618 while ((ep = readdir(dirp)) != NULL) {
2845
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
619 if (ep->d_name[0] == '.' &&
051bacab59af suppress . and .. in listdir return value
Guido van Rossum <guido@python.org>
parents: 2740
diff changeset
620 (NAMLEN(ep) == 1 ||
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
621 (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
622 continue;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
623 v = PyString_FromStringAndSize(ep->d_name, NAMLEN(ep));
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
624 if (v == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
625 Py_DECREF(d);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
626 d = NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 break;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
628 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
629 if (PyList_Append(d, v) != 0) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
630 Py_DECREF(v);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
631 Py_DECREF(d);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
632 d = NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
633 break;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
634 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
635 Py_DECREF(v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
636 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
637 closedir(dirp);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
638 Py_END_ALLOW_THREADS
200
9d01965f4f48 Incorporated MSDOS changes (untested).
Guido van Rossum <guido@python.org>
parents: 199
diff changeset
639
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
640 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
641
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
642 #endif /* !_MSC_VER */
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
643 #endif /* !MS_WIN32 */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
644 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
645
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
646 static char posix_mkdir__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
647 "mkdir(path [, mode=0777]) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
648 Create a directory.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
649
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
650 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
651 posix_mkdir(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
652 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
653 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
654 {
3418
0ac5fbaf8aef Made 2nd arg to mkdir optional
Guido van Rossum <guido@python.org>
parents: 3387
diff changeset
655 int res;
0ac5fbaf8aef Made 2nd arg to mkdir optional
Guido van Rossum <guido@python.org>
parents: 3387
diff changeset
656 char *path;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
657 int mode = 0777;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
658 if (!PyArg_ParseTuple(args, "s|i", &path, &mode))
3418
0ac5fbaf8aef Made 2nd arg to mkdir optional
Guido van Rossum <guido@python.org>
parents: 3387
diff changeset
659 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
660 Py_BEGIN_ALLOW_THREADS
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
661 #if defined(__WATCOMC__) || defined(_MSC_VER)
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
662 res = mkdir(path);
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
663 #else
3418
0ac5fbaf8aef Made 2nd arg to mkdir optional
Guido van Rossum <guido@python.org>
parents: 3387
diff changeset
664 res = mkdir(path, mode);
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
665 #endif
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
666 Py_END_ALLOW_THREADS
3418
0ac5fbaf8aef Made 2nd arg to mkdir optional
Guido van Rossum <guido@python.org>
parents: 3387
diff changeset
667 if (res < 0)
0ac5fbaf8aef Made 2nd arg to mkdir optional
Guido van Rossum <guido@python.org>
parents: 3387
diff changeset
668 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
669 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
670 return Py_None;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
671 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
672
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
673
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
674 #ifdef HAVE_NICE
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
675 static char posix_nice__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
676 "nice(inc) -> new_priority\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
677 Decrease the priority of process and return new priority.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
678
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
679 static PyObject *
1181
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
680 posix_nice(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
681 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
682 PyObject *args;
1181
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
683 {
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
684 int increment, value;
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
685
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
686 if (!PyArg_Parse(args, "i", &increment))
1181
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
687 return NULL;
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
688 value = nice(increment);
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
689 if (value == -1)
950cd37fcddc * Makefile: use cp -r to install the library
Guido van Rossum <guido@python.org>
parents: 1177
diff changeset
690 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
691 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
692 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
693 #endif /* HAVE_NICE */
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
694
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
695
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
696 static char posix_rename__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
697 "rename(old, new) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
698 Rename a file or directory.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
699
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
700 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
701 posix_rename(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
702 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
703 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
704 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
705 return posix_2str(args, rename);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
706 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
707
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
708
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
709 static char posix_rmdir__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
710 "rmdir(path) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
711 Remove a directory.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
712
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
713 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
714 posix_rmdir(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
715 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
716 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
717 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
718 return posix_1str(args, rmdir);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
719 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
720
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
721
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
722 static char posix_stat__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
723 "stat(path) -> (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
724 Perform a stat system call on the given path.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
725
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
726 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
727 posix_stat(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
728 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
729 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
730 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
731 return posix_do_stat(self, args, stat);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
732 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
733
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
734
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
735 #ifdef HAVE_SYSTEM
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
736 static char posix_system__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
737 "system(command) -> exit_status\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
738 Execute the command (a string) in a subshell.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
739
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
740 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
741 posix_system(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
742 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
743 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
744 {
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
745 char *command;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
746 long sts;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
747 if (!PyArg_Parse(args, "s", &command))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
748 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
749 Py_BEGIN_ALLOW_THREADS
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
750 sts = system(command);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
751 Py_END_ALLOW_THREADS
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
752 return PyInt_FromLong(sts);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
753 }
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
754 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
755
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
756
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
757 static char posix_umask__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
758 "umask(new_mask) -> old_mask\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
759 Set the current numeric umask and return the previous umask.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
760
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
761 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
762 posix_umask(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
763 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
764 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
765 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
766 int i;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
767 if (!PyArg_Parse(args, "i", &i))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
768 return NULL;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
769 i = umask(i);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
770 if (i < 0)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
771 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
772 return PyInt_FromLong((long)i);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
773 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
774
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
775
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
776 static char posix_unlink__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
777 "unlink(path) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
778 Remove a file (same as remove(path)).";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
779
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
780 static char posix_remove__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
781 "remove(path) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
782 Remove a file (same as unlink(path)).";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
783
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
784 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
785 posix_unlink(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
786 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
787 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
788 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
789 return posix_1str(args, unlink);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
790 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
791
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
792
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
793 #ifdef HAVE_UNAME
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
794 static char posix_uname__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
795 "uname() -> (sysname, nodename, release, version, machine)\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
796 Return a tuple identifying the current operating system.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
797
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
798 static PyObject *
658
5b521fe4d1f6 Added uname. Made lstat/readlink/symlink unconditional (the latter
Guido van Rossum <guido@python.org>
parents: 643
diff changeset
799 posix_uname(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
800 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
801 PyObject *args;
658
5b521fe4d1f6 Added uname. Made lstat/readlink/symlink unconditional (the latter
Guido van Rossum <guido@python.org>
parents: 643
diff changeset
802 {
5b521fe4d1f6 Added uname. Made lstat/readlink/symlink unconditional (the latter
Guido van Rossum <guido@python.org>
parents: 643
diff changeset
803 struct utsname u;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
804 int res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
805 if (!PyArg_NoArgs(args))
731
c65fc172f16d Check empty argument lists.
Guido van Rossum <guido@python.org>
parents: 658
diff changeset
806 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
807 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
808 res = uname(&u);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
809 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
810 if (res < 0)
658
5b521fe4d1f6 Added uname. Made lstat/readlink/symlink unconditional (the latter
Guido van Rossum <guido@python.org>
parents: 643
diff changeset
811 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
812 return Py_BuildValue("(sssss)",
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
813 u.sysname,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
814 u.nodename,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
815 u.release,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
816 u.version,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
817 u.machine);
658
5b521fe4d1f6 Added uname. Made lstat/readlink/symlink unconditional (the latter
Guido van Rossum <guido@python.org>
parents: 643
diff changeset
818 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
819 #endif /* HAVE_UNAME */
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
820
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
821
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
822 static char posix_utime__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
823 "utime(path, (atime, utime)) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
824 Set the access and modified time of the file to the given values.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
825
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
826 static PyObject *
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
827 posix_utime(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
828 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
829 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
830 {
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
831 char *path;
2236
1b662497426b uname 64-bit fix
Guido van Rossum <guido@python.org>
parents: 2114
diff changeset
832 long atime, mtime;
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
833 int res;
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
834
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
835 #ifdef HAVE_UTIME_H
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
836 struct utimbuf buf;
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
837 #define ATIME buf.actime
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
838 #define MTIME buf.modtime
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
839 #define UTIME_ARG &buf
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
840 #else /* HAVE_UTIME_H */
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
841 time_t buf[2];
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
842 #define ATIME buf[0]
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
843 #define MTIME buf[1]
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
844 #define UTIME_ARG buf
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
845 #endif /* HAVE_UTIME_H */
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
846
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
847 if (!PyArg_Parse(args, "(s(ll))", &path, &atime, &mtime))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
848 return NULL;
2236
1b662497426b uname 64-bit fix
Guido van Rossum <guido@python.org>
parents: 2114
diff changeset
849 ATIME = atime;
2298
fe8db78f311c correct typo in utime stub
Guido van Rossum <guido@python.org>
parents: 2236
diff changeset
850 MTIME = mtime;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
851 Py_BEGIN_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
852 res = utime(path, UTIME_ARG);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
853 Py_END_ALLOW_THREADS
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 861
diff changeset
854 if (res < 0)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
855 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
856 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
857 return Py_None;
199
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
858 #undef UTIME_ARG
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
859 #undef ATIME
0a3e33cfd4a9 Made utime use much more portable.
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
860 #undef MTIME
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
861 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
862
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
863
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
864 /* Process operations */
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
865
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
866 static char posix__exit__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
867 "_exit(status)\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
868 Exit to the system with specified status, without normal exit processing.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
869
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
870 static PyObject *
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
871 posix__exit(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
872 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
873 PyObject *args;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
874 {
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
875 int sts;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
876 if (!PyArg_Parse(args, "i", &sts))
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
877 return NULL;
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
878 _exit(sts);
4600
d36250aefb82 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
879 return NULL; /* Make gcc -Wall happy */
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
880 }
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
881
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
882
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
883 #ifdef HAVE_EXECV
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
884 static char posix_execv__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
885 "execv(path, args)\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
886 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
887 \n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
888 path: path of executable file\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
889 args: tuple or list of strings";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
890
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
891 static PyObject *
1360
1808ca5d8883 * import.c (MAGIC): Changed magic word to avoid confusion about exec
Guido van Rossum <guido@python.org>
parents: 1329
diff changeset
892 posix_execv(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
893 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
894 PyObject *args;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
895 {
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
896 char *path;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
897 PyObject *argv;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
898 char **argvlist;
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
899 int i, argc;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
900 PyObject *(*getitem) Py_PROTO((PyObject *, int));
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
901
1360
1808ca5d8883 * import.c (MAGIC): Changed magic word to avoid confusion about exec
Guido van Rossum <guido@python.org>
parents: 1329
diff changeset
902 /* execv has two arguments: (path, argv), where
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
903 argv is a list or tuple of strings. */
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
904
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
905 if (!PyArg_Parse(args, "(sO)", &path, &argv))
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
906 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
907 if (PyList_Check(argv)) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
908 argc = PyList_Size(argv);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
909 getitem = PyList_GetItem;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
910 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
911 else if (PyTuple_Check(argv)) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
912 argc = PyTuple_Size(argv);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
913 getitem = PyTuple_GetItem;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
914 }
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
915 else {
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
916 badarg:
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
917 PyErr_BadArgument();
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
918 return NULL;
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
919 }
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
920
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
921 argvlist = PyMem_NEW(char *, argc+1);
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
922 if (argvlist == NULL)
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
923 return NULL;
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
924 for (i = 0; i < argc; i++) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
925 if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
926 PyMem_DEL(argvlist);
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
927 goto badarg;
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
928 }
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
929 }
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
930 argvlist[argc] = NULL;
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
931
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
932 #ifdef BAD_EXEC_PROTOTYPES
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
933 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
934 #else /* BAD_EXEC_PROTOTYPES */
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
935 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
936 #endif /* BAD_EXEC_PROTOTYPES */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
937
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
938 /* If we get here it's definitely an error */
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
939
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
940 PyMem_DEL(argvlist);
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
941 return posix_error();
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
942 }
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
943
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
944
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
945 static char posix_execve__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
946 "execve(path, args, env)\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
947 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
948 \n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
949 path: path of executable file\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
950 args: tuple or list of arguments\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
951 env: dictonary of strings mapping to strings";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
952
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
953 static PyObject *
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
954 posix_execve(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
955 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
956 PyObject *args;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
957 {
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
958 char *path;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
959 PyObject *argv, *env;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
960 char **argvlist;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
961 char **envlist;
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
962 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
963 int i, pos, argc, envc;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
964 PyObject *(*getitem) Py_PROTO((PyObject *, int));
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
965
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
966 /* 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
967 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
968 like posix.environ. */
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
969
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
970 if (!PyArg_Parse(args, "(sOO)", &path, &argv, &env))
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
971 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
972 if (PyList_Check(argv)) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
973 argc = PyList_Size(argv);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
974 getitem = PyList_GetItem;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
975 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
976 else if (PyTuple_Check(argv)) {
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
977 argc = PyTuple_Size(argv);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
978 getitem = PyTuple_GetItem;
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
979 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
980 else {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
981 PyErr_SetString(PyExc_TypeError, "argv must be tuple or list");
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
982 return NULL;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
983 }
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
984 if (!PyMapping_Check(env)) {
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
985 PyErr_SetString(PyExc_TypeError, "env must be mapping object");
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
986 return NULL;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
987 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
988
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
989 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
990 if (argvlist == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
991 PyErr_NoMemory();
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
992 return NULL;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
993 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
994 for (i = 0; i < argc; i++) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
995 if (!PyArg_Parse((*getitem)(argv, i),
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
996 "s;argv must be list of strings",
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
997 &argvlist[i]))
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
998 {
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
999 goto fail_1;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1000 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1001 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1002 argvlist[argc] = NULL;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1003
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1004 i = PyMapping_Length(env);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1005 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
1006 if (envlist == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1007 PyErr_NoMemory();
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1008 goto fail_1;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1009 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1010 envc = 0;
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1011 keys = PyMapping_Keys(env);
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1012 vals = PyMapping_Values(env);
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1013 if (!keys || !vals)
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1014 goto fail_2;
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1015
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1016 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
1017 char *p, *k, *v;
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1018
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1019 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
1020 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
1021 if (!key || !val)
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1022 goto fail_2;
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1023
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1024 if (!PyArg_Parse(key, "s;non-string key in env", &k) ||
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1025 !PyArg_Parse(val, "s;non-string value in env", &v))
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1026 {
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1027 goto fail_2;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1028 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1029 p = PyMem_NEW(char, PyString_Size(key)+PyString_Size(val) + 2);
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1030 if (p == NULL) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1031 PyErr_NoMemory();
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1032 goto fail_2;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1033 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1034 sprintf(p, "%s=%s", k, v);
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1035 envlist[envc++] = p;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1036 }
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1037 envlist[envc] = 0;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1038
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1039
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1040 #ifdef BAD_EXEC_PROTOTYPES
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1041 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
1042 #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
1043 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
1044 #endif /* BAD_EXEC_PROTOTYPES */
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1045
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1046 /* 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
1047
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1048 (void) posix_error();
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1049
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1050 fail_2:
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1051 while (--envc >= 0)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1052 PyMem_DEL(envlist[envc]);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1053 PyMem_DEL(envlist);
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1054 fail_1:
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1055 PyMem_DEL(argvlist);
5058
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1056 Py_XDECREF(vals);
371464f6666b posix_execve(): Accept any mapping protocol object for the env
Barry Warsaw <barry@python.org>
parents: 4789
diff changeset
1057 Py_XDECREF(keys);
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1058 return NULL;
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1059 }
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1060 #endif /* HAVE_EXECV */
1395
be61e072a505 Added execve; change getstrarg into getargs with "s" format
Guido van Rossum <guido@python.org>
parents: 1388
diff changeset
1061
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1062
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1063 #ifdef HAVE_FORK
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1064 static char posix_fork__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1065 "fork() -> pid\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1066 Fork a child process.\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1067 \n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1068 Return 0 to child process and PID of child to parent process.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1069
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1070 static PyObject *
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1071 posix_fork(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1072 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1073 PyObject *args;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1074 {
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1075 int pid;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1076 if (!PyArg_NoArgs(args))
731
c65fc172f16d Check empty argument lists.
Guido van Rossum <guido@python.org>
parents: 658
diff changeset
1077 return NULL;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1078 pid = fork();
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1079 if (pid == -1)
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1080 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1081 return PyInt_FromLong((long)pid);
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1082 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1083 #endif
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1084
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1085
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1086 #ifdef HAVE_GETEGID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1087 static char posix_getegid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1088 "getegid() -> egid\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1089 Return the current process's effective group id.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1090
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1091 static PyObject *
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1092 posix_getegid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1093 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1094 PyObject *args;
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1095 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1096 if (!PyArg_NoArgs(args))
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1097 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1098 return PyInt_FromLong((long)getegid());
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1099 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1100 #endif
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1101
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1102
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1103 #ifdef HAVE_GETEUID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1104 static char posix_geteuid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1105 "geteuid() -> euid\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1106 Return the current process's effective user id.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1107
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1108 static PyObject *
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1109 posix_geteuid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1110 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1111 PyObject *args;
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1112 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1113 if (!PyArg_NoArgs(args))
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1114 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1115 return PyInt_FromLong((long)geteuid());
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1116 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1117 #endif
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1118
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1119
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1120 #ifdef HAVE_GETGID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1121 static char posix_getgid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1122 "getgid() -> gid\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1123 Return the current process's group id.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1124
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1125 static PyObject *
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1126 posix_getgid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1127 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1128 PyObject *args;
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1129 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1130 if (!PyArg_NoArgs(args))
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1131 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1132 return PyInt_FromLong((long)getgid());
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1133 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1134 #endif
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1135
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1136
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1137 static char posix_getpid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1138 "getpid() -> pid\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1139 Return the current process id";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1140
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1141 static PyObject *
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1142 posix_getpid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1143 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1144 PyObject *args;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1145 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1146 if (!PyArg_NoArgs(args))
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1147 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1148 return PyInt_FromLong((long)getpid());
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1149 }
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1150
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1151
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1152 #ifdef HAVE_GETPGRP
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1153 static char posix_getpgrp__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1154 "getpgrp() -> pgrp\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1155 Return the current process group id.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1156
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1157 static PyObject *
273
af1c8f5d0b37 Added getpgrp(); fixed buggy calls to getnoarg().
Guido van Rossum <guido@python.org>
parents: 264
diff changeset
1158 posix_getpgrp(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1159 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1160 PyObject *args;
273
af1c8f5d0b37 Added getpgrp(); fixed buggy calls to getnoarg().
Guido van Rossum <guido@python.org>
parents: 264
diff changeset
1161 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1162 if (!PyArg_NoArgs(args))
273
af1c8f5d0b37 Added getpgrp(); fixed buggy calls to getnoarg().
Guido van Rossum <guido@python.org>
parents: 264
diff changeset
1163 return NULL;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1164 #ifdef GETPGRP_HAVE_ARG
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1165 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
1166 #else /* GETPGRP_HAVE_ARG */
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1167 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
1168 #endif /* GETPGRP_HAVE_ARG */
273
af1c8f5d0b37 Added getpgrp(); fixed buggy calls to getnoarg().
Guido van Rossum <guido@python.org>
parents: 264
diff changeset
1169 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1170 #endif /* HAVE_GETPGRP */
273
af1c8f5d0b37 Added getpgrp(); fixed buggy calls to getnoarg().
Guido van Rossum <guido@python.org>
parents: 264
diff changeset
1171
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1172
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1173 #ifdef HAVE_SETPGRP
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1174 static char posix_setpgrp__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1175 "setpgrp() -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1176 Make this process a session leader.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1177
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1178 static PyObject *
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
1179 posix_setpgrp(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1180 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1181 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
1182 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1183 if (!PyArg_NoArgs(args))
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
1184 return NULL;
1983
80bd7af73201 distinguish between getpgrp and setpgrp arg requirements
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1185 #ifdef SETPGRP_HAVE_ARG
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1186 if (setpgrp(0, 0) < 0)
1983
80bd7af73201 distinguish between getpgrp and setpgrp arg requirements
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1187 #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
1188 if (setpgrp() < 0)
1983
80bd7af73201 distinguish between getpgrp and setpgrp arg requirements
Guido van Rossum <guido@python.org>
parents: 1915
diff changeset
1189 #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
1190 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1191 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1192 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
1193 }
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
1194
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1195 #endif /* HAVE_SETPGRP */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1196
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1197 #ifdef HAVE_GETPPID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1198 static char posix_getppid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1199 "getppid() -> ppid\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1200 Return the parent's process id.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1201
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1202 static PyObject *
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1203 posix_getppid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1204 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1205 PyObject *args;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1206 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1207 if (!PyArg_NoArgs(args))
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1208 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1209 return PyInt_FromLong((long)getppid());
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1210 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1211 #endif
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1212
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1213
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1214 #ifdef HAVE_GETUID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1215 static char posix_getuid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1216 "getuid() -> uid\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1217 Return the current process's user id.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1218
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1219 static PyObject *
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1220 posix_getuid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1221 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1222 PyObject *args;
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1223 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1224 if (!PyArg_NoArgs(args))
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1225 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1226 return PyInt_FromLong((long)getuid());
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1227 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1228 #endif
861
76095a8b96ca Added gete?[gu]id functions
Guido van Rossum <guido@python.org>
parents: 793
diff changeset
1229
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1230
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1231 #ifdef HAVE_KILL
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1232 static char posix_kill__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1233 "kill(pid, sig) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1234 Kill a process with a signal.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1235
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1236 static PyObject *
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1237 posix_kill(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1238 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1239 PyObject *args;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1240 {
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1241 int pid, sig;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1242 if (!PyArg_Parse(args, "(ii)", &pid, &sig))
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1243 return NULL;
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1244 if (kill(pid, sig) == -1)
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1245 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1246 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1247 return Py_None;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1248 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1249 #endif
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1250
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1251 #ifdef HAVE_PLOCK
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1252
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1253 #ifdef HAVE_SYS_LOCK_H
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1254 #include <sys/lock.h>
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1255 #endif
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1256
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1257 static char posix_plock__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1258 "plock(op) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1259 Lock program segments into memory.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1260
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1261 static PyObject *
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1262 posix_plock(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1263 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1264 PyObject *args;
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1265 {
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1266 int op;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1267 if (!PyArg_Parse(args, "i", &op))
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1268 return NULL;
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1269 if (plock(op) == -1)
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1270 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1271 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1272 return Py_None;
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1273 }
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1274 #endif
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
1275
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1276
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1277 #ifdef HAVE_POPEN
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1278 static char posix_popen__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1279 "popen(command [, mode='r' [, bufsize]]) -> pipe\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1280 Open a pipe to/from a command returning a file object.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1281
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1282 static PyObject *
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
1283 posix_popen(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1284 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1285 PyObject *args;
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
1286 {
2114
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
1287 char *name;
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
1288 char *mode = "r";
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
1289 int bufsize = -1;
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
1290 FILE *fp;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1291 PyObject *f;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1292 if (!PyArg_ParseTuple(args, "s|si", &name, &mode, &bufsize))
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
1293 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1294 Py_BEGIN_ALLOW_THREADS
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
1295 fp = popen(name, mode);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1296 Py_END_ALLOW_THREADS
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
1297 if (fp == NULL)
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
1298 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1299 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
1300 if (f != NULL)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1301 PyFile_SetBufSize(f, bufsize);
2114
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
1302 return f;
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
1303 }
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1304 #endif /* HAVE_POPEN */
264
72d1b89be35a Added popen().
Guido van Rossum <guido@python.org>
parents: 257
diff changeset
1305
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1306
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1307 #ifdef HAVE_SETUID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1308 static char posix_setuid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1309 "setuid(uid) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1310 Set the current process's user id.";
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1311 static PyObject *
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1312 posix_setuid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1313 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1314 PyObject *args;
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1315 {
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1316 int uid;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1317 if (!PyArg_Parse(args, "i", &uid))
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1318 return NULL;
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1319 if (setuid(uid) < 0)
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1320 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1321 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1322 return Py_None;
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1323 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
1324 #endif /* HAVE_SETUID */
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1325
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1326
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1327 #ifdef HAVE_SETGID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1328 static char posix_setgid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1329 "setgid(gid) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1330 Set the current process's group id.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1331
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1332 static PyObject *
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1333 posix_setgid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1334 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1335 PyObject *args;
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1336 {
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1337 int gid;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1338 if (!PyArg_Parse(args, "i", &gid))
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1339 return NULL;
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1340 if (setgid(gid) < 0)
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1341 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1342 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1343 return Py_None;
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1344 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
1345 #endif /* HAVE_SETGID */
1405
90c5e2bb4da5 * posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents: 1395
diff changeset
1346
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1347
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1348 #ifdef HAVE_WAITPID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1349 static char posix_waitpid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1350 "waitpid(pid, options) -> (pid, status)\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1351 Wait for completion of a give child process.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1352
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1353 static PyObject *
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1354 posix_waitpid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1355 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1356 PyObject *args;
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1357 {
3695
1454138c6f2d Clear waitpid() status arg in case there's no process to report with
Guido van Rossum <guido@python.org>
parents: 3667
diff changeset
1358 int pid, options, sts = 0;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1359 if (!PyArg_Parse(args, "(ii)", &pid, &options))
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1360 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1361 Py_BEGIN_ALLOW_THREADS
5584
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1362 #ifdef NeXT
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1363 pid = wait4(pid, (union wait *)&sts, options, NULL);
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1364 #else
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1365 pid = waitpid(pid, &sts, options);
5584
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1366 #endif
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1367 Py_END_ALLOW_THREADS
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1368 if (pid == -1)
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1369 return posix_error();
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1370 else
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1371 return Py_BuildValue("ii", pid, sts);
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1372 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1373 #endif /* HAVE_WAITPID */
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1374
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1375
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1376 #ifdef HAVE_WAIT
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1377 static char posix_wait__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1378 "wait() -> (pid, status)\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1379 Wait for completion of a child process.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1380
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1381 static PyObject *
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1382 posix_wait(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1383 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1384 PyObject *args;
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1385 {
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1386 int pid, sts;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1387 Py_BEGIN_ALLOW_THREADS
5584
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1388 #ifdef NeXT
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1389 pid = wait((union wait *)&sts);
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1390 #else
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1391 pid = wait(&sts);
5584
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1392 #endif
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1393 Py_END_ALLOW_THREADS
931
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1394 if (pid == -1)
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1395 return posix_error();
d8608ed1cc3b Makefile, Configure.py: ##ask --> ##[el]if[yes|no]
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
1396 else
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1397 return Py_BuildValue("ii", pid, sts);
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1398 }
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
1399 #endif
257
a46558ad0bed Removed utimes() compatibility hack.
Guido van Rossum <guido@python.org>
parents: 200
diff changeset
1400
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1401
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1402 static char posix_lstat__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1403 "lstat(path) -> (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1404 Like stat(path), but do not follow symbolic links.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1405
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1406 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1407 posix_lstat(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1408 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1409 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1410 {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1411 #ifdef HAVE_LSTAT
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1412 return posix_do_stat(self, args, lstat);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1413 #else /* !HAVE_LSTAT */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1414 return posix_do_stat(self, args, stat);
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1415 #endif /* !HAVE_LSTAT */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1416 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1417
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1418
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1419 #ifdef HAVE_READLINK
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1420 static char posix_readlink__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1421 "readlink(path) -> path\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1422 Return a string representing the path to which the symbolic link points.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1423
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1424 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1425 posix_readlink(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1426 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1427 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1428 {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1429 char buf[MAXPATHLEN];
643
02d3f161b7f5 Use getargs() function.
Guido van Rossum <guido@python.org>
parents: 373
diff changeset
1430 char *path;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1431 int n;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1432 if (!PyArg_Parse(args, "s", &path))
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1433 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1434 Py_BEGIN_ALLOW_THREADS
731
c65fc172f16d Check empty argument lists.
Guido van Rossum <guido@python.org>
parents: 658
diff changeset
1435 n = readlink(path, buf, (int) sizeof buf);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1436 Py_END_ALLOW_THREADS
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1437 if (n < 0)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1438 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1439 return PyString_FromStringAndSize(buf, n);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1440 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1441 #endif /* HAVE_READLINK */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1442
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1443
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1444 #ifdef HAVE_SYMLINK
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1445 static char posix_symlink__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1446 "symlink(src, dst) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1447 Create a symbolic link.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1448
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1449 static PyObject *
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1450 posix_symlink(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1451 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1452 PyObject *args;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1453 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1454 return posix_2str(args, symlink);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1455 }
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1456 #endif /* HAVE_SYMLINK */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1457
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1458 #ifdef HAVE_TIMES
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1459 #ifndef HZ
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1460 #define HZ 60 /* Universal constant :-) */
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
1461 #endif /* HZ */
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1462
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1463 static PyObject *
793
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
1464 posix_times(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1465 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1466 PyObject *args;
793
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
1467 {
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
1468 struct tms t;
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
1469 clock_t c;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1470 if (!PyArg_NoArgs(args))
793
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
1471 return NULL;
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
1472 errno = 0;
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
1473 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
1474 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
1475 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1476 return Py_BuildValue("ddddd",
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1477 (double)t.tms_utime / HZ,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1478 (double)t.tms_stime / HZ,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1479 (double)t.tms_cutime / HZ,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1480 (double)t.tms_cstime / HZ,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1481 (double)c / HZ);
793
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
1482 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1483 #endif /* HAVE_TIMES */
4233
1099159ec821 Use #ifdef MS_WIN32 instead of _MSC_VER > 850.
Guido van Rossum <guido@python.org>
parents: 3801
diff changeset
1484 #ifdef MS_WIN32
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
1485 #define HAVE_TIMES /* so the method table will pick it up */
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1486 static PyObject *
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
1487 posix_times(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1488 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1489 PyObject *args;
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
1490 {
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
1491 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
1492 HANDLE hProc;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1493 if (!PyArg_NoArgs(args))
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
1494 return NULL;
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
1495 hProc = GetCurrentProcess();
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
1496 GetProcessTimes(hProc,&create, &exit, &kernel, &user);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1497 return Py_BuildValue(
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1498 "ddddd",
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1499 (double)(kernel.dwHighDateTime*2E32+kernel.dwLowDateTime)/2E6,
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1500 (double)(user.dwHighDateTime*2E32+user.dwLowDateTime) / 2E6,
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1501 (double)0,
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1502 (double)0,
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1503 (double)0);
1915
80818c106e3e * Modules/xxmodule.c: integrated with xxobject.c by Jack
Guido van Rossum <guido@python.org>
parents: 1845
diff changeset
1504 }
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
1505 #endif /* MS_WIN32 */
5725
9a3b115aa491 Moved the definition of posix_times__doc__ to outside of #ifdef HAVE_TIMES
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 5699
diff changeset
1506 static char posix_times__doc__[] =
9a3b115aa491 Moved the definition of posix_times__doc__ to outside of #ifdef HAVE_TIMES
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 5699
diff changeset
1507 "times() -> (utime, stime, cutime, cstime, elapsed_time)\n\
9a3b115aa491 Moved the definition of posix_times__doc__ to outside of #ifdef HAVE_TIMES
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents: 5699
diff changeset
1508 Return a tuple of floating point numbers indicating process times.";
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
1509
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1510
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1511 #ifdef HAVE_SETSID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1512 static char posix_setsid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1513 "setsid() -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1514 Call the system call setsid().";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1515
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1516 static PyObject *
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
1517 posix_setsid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1518 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1519 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
1520 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1521 if (!PyArg_NoArgs(args))
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
1522 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
1523 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
1524 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1525 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1526 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
1527 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1528 #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
1529
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1530 #ifdef HAVE_SETPGID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1531 static char posix_setpgid__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1532 "setpgid(pid, pgrp) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1533 Call the system call setpgid().";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1534
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1535 static PyObject *
1050
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
1536 posix_setpgid(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1537 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1538 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
1539 {
f49d2311776b posix: added setpgrp() and, if sgi, setsid() and setpgid(pid, pgid)
Guido van Rossum <guido@python.org>
parents: 943
diff changeset
1540 int pid, pgrp;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1541 if (!PyArg_Parse(args, "(ii)", &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
1542 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
1543 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
1544 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1545 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1546 return Py_None;
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1547 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1548 #endif /* HAVE_SETPGID */
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1549
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1550
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1551 #ifdef HAVE_TCGETPGRP
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1552 static char posix_tcgetpgrp__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1553 "tcgetpgrp(fd) -> pgid\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1554 Return the process group associated with the terminal given by a fd.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1555
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1556 static PyObject *
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1557 posix_tcgetpgrp(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1558 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1559 PyObject *args;
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1560 {
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1561 int fd, pgid;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1562 if (!PyArg_Parse(args, "i", &fd))
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1563 return NULL;
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1564 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
1565 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
1566 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1567 return PyInt_FromLong((long)pgid);
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1568 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1569 #endif /* HAVE_TCGETPGRP */
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1570
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1571
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1572 #ifdef HAVE_TCSETPGRP
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1573 static char posix_tcsetpgrp__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1574 "tcsetpgrp(fd, pgid) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1575 Set the process group associated with the terminal given by a fd.";
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 *
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1578 posix_tcsetpgrp(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1579 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1580 PyObject *args;
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1581 {
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1582 int fd, pgid;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1583 if (!PyArg_Parse(args, "(ii)", &fd, &pgid))
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1050
diff changeset
1584 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
1585 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
1586 return posix_error();
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1587 Py_INCREF(Py_None);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1588 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
1589 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
1590 #endif /* HAVE_TCSETPGRP */
793
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
1591
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1592 /* 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
1593
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1594 static char posix_open__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1595 "open(filename, flag [, mode=0777]) -> fd\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1596 Open a file (for low level IO).";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1597
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1598 static PyObject *
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1599 posix_open(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1600 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1601 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
1602 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1603 char *file;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1604 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
1605 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
1606 int fd;
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1607 if (!PyArg_ParseTuple(args, "si|i", &file, &flag, &mode))
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1608 return NULL;
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1609
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1610 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
1611 fd = open(file, flag, mode);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1612 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
1613 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
1614 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1615 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
1616 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1617
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1618
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1619 static char posix_close__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1620 "close(fd) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1621 Close a file descriptor (for low level IO).";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1622
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1623 static PyObject *
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1624 posix_close(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1625 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1626 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
1627 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1628 int fd, res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1629 if (!PyArg_Parse(args, "i", &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
1630 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1631 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
1632 res = close(fd);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1633 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
1634 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
1635 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1636 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1637 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
1638 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1639
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1640
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1641 static char posix_dup__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1642 "dup(fd) -> fd2\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1643 Return a duplicate of a file descriptor.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1644
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1645 static PyObject *
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1646 posix_dup(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1647 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1648 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
1649 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1650 int fd;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1651 if (!PyArg_Parse(args, "i", &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
1652 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1653 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
1654 fd = dup(fd);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1655 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
1656 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
1657 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1658 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
1659 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1660
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1661
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1662 static char posix_dup2__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1663 "dup2(fd, fd2) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1664 Duplicate file descriptor.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1665
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1666 static PyObject *
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1667 posix_dup2(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1668 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1669 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
1670 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1671 int fd, fd2, res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1672 if (!PyArg_Parse(args, "(ii)", &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
1673 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1674 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
1675 res = dup2(fd, fd2);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1676 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
1677 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
1678 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1679 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1680 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
1681 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1682
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1683
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1684 static char posix_lseek__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1685 "lseek(fd, pos, how) -> newpos\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1686 Set the current position of a file descriptor.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1687
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1688 static PyObject *
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1689 posix_lseek(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1690 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1691 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
1692 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1693 int fd, how;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1694 long pos, res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1695 if (!PyArg_Parse(args, "(ili)", &fd, &pos, &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
1696 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
1697 #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
1698 /* 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
1699 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
1700 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
1701 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
1702 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
1703 }
1792
a584b4bbbc59 Changes to make it work and compile on NT, by Mark Hammond.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
1704 #endif /* SEEK_END */
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1705 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
1706 res = lseek(fd, pos, how);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1707 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
1708 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
1709 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1710 return PyInt_FromLong(res);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1711 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1712
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1713
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1714 static char posix_read__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1715 "read(fd, buffersize) -> string\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1716 Read a file descriptor.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1717
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1718 static PyObject *
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1719 posix_read(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1720 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1721 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
1722 {
3667
eabbb3c1818f Avoid core dump in resizestring() on read() with 0 bytes.
Guido van Rossum <guido@python.org>
parents: 3622
diff changeset
1723 int fd, size, n;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1724 PyObject *buffer;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1725 if (!PyArg_Parse(args, "(ii)", &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
1726 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1727 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
1728 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
1729 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1730 Py_BEGIN_ALLOW_THREADS
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1731 n = read(fd, PyString_AsString(buffer), size);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1732 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
1733 if (n < 0) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1734 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
1735 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
1736 }
3667
eabbb3c1818f Avoid core dump in resizestring() on read() with 0 bytes.
Guido van Rossum <guido@python.org>
parents: 3622
diff changeset
1737 if (n != size)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1738 _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
1739 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
1740 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1741
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1742
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1743 static char posix_write__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1744 "write(fd, string) -> byteswritten\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1745 Write a string to a file descriptor.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1746
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1747 static PyObject *
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1748 posix_write(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1749 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1750 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
1751 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1752 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
1753 char *buffer;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1754 if (!PyArg_Parse(args, "(is#)", &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
1755 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1756 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
1757 size = write(fd, buffer, size);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1758 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
1759 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
1760 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1761 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
1762 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1763
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1764
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1765 static char posix_fstat__doc__[]=
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1766 "fstat(fd) -> (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1767 Like stat(), but for an open file descriptor.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1768
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1769 static PyObject *
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1770 posix_fstat(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1771 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1772 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
1773 {
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1774 int fd;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1775 struct stat st;
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1776 int res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1777 if (!PyArg_Parse(args, "i", &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
1778 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1779 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
1780 res = fstat(fd, &st);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1781 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
1782 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
1783 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1784 return Py_BuildValue("(llllllllll)",
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1785 (long)st.st_mode,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1786 (long)st.st_ino,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1787 (long)st.st_dev,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1788 (long)st.st_nlink,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1789 (long)st.st_uid,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1790 (long)st.st_gid,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1791 (long)st.st_size,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1792 (long)st.st_atime,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1793 (long)st.st_mtime,
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1794 (long)st.st_ctime);
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1795 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1796
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1797
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1798 static char posix_fdopen__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1799 "fdopen(fd, [, mode='r' [, bufsize]]) -> file_object\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1800 Return an open file object connected to a file descriptor.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1801
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1802 static PyObject *
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1803 posix_fdopen(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1804 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1805 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
1806 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1807 extern int fclose Py_PROTO((FILE *));
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1808 int fd;
2114
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
1809 char *mode = "r";
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
1810 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
1811 FILE *fp;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1812 PyObject *f;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1813 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
1814 return NULL;
4785
9fc380b1a445 Minor formatting changes.
Barry Warsaw <barry@python.org>
parents: 4672
diff changeset
1815
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1816 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
1817 fp = fdopen(fd, mode);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1818 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
1819 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
1820 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1821 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
1822 if (f != NULL)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1823 PyFile_SetBufSize(f, bufsize);
2114
7947c0d16ca0 added bufsize parameter to fdopen and popen
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
1824 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
1825 }
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1826
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1827
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1828 #ifdef HAVE_PIPE
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1829 static char posix_pipe__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1830 "pipe() -> (read_end, write_end)\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1831 Create a pipe.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1832
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1833 static PyObject *
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1834 posix_pipe(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1835 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1836 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
1837 {
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
1838 #if !defined(MS_WIN32)
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1839 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
1840 int res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1841 if (!PyArg_Parse(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
1842 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1843 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
1844 res = pipe(fds);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1845 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
1846 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
1847 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1848 return Py_BuildValue("(ii)", fds[0], fds[1]);
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
1849 #else /* MS_WIN32 */
1815
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1850 HANDLE read, write;
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1851 BOOL ok;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1852 if (!PyArg_Parse(args, ""))
1815
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1853 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1854 Py_BEGIN_ALLOW_THREADS
1815
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1855 ok = CreatePipe( &read, &write, NULL, 0);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1856 Py_END_ALLOW_THREADS
1815
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1857 if (!ok)
6353fe25cdce * Modules/posixmodule.c: some more NT changes
Guido van Rossum <guido@python.org>
parents: 1792
diff changeset
1858 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1859 return Py_BuildValue("(ii)", read, write);
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
1860 #endif /* MS_WIN32 */
1287
673dd9bbdbf1 New posix functions open, close, dup, dup2, lseek, read, write, fstat, pipe.
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
1861 }
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1862 #endif /* HAVE_PIPE */
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1863
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1864
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1865 #ifdef HAVE_MKFIFO
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1866 static char posix_mkfifo__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1867 "mkfifo(file, [, mode=0666]) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1868 Create a FIFO (a POSIX named pipe).";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1869
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1870 static PyObject *
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1871 posix_mkfifo(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1872 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1873 PyObject *args;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1874 {
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1875 char *file;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1876 int mode = 0666;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1877 int res;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1878 if (!PyArg_ParseTuple(args, "s|i", &file, &mode))
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1879 return NULL;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1880 Py_BEGIN_ALLOW_THREADS
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1881 res = mkfifo(file, mode);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1882 Py_END_ALLOW_THREADS
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1883 if (res < 0)
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1884 return posix_error();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1885 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1886 return Py_None;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1887 }
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1888 #endif
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1889
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1890
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1891 #ifdef HAVE_FTRUNCATE
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1892 static char posix_ftruncate__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1893 "ftruncate(fd, length) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1894 Truncate a file to a specified length.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1895
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1896 static PyObject *
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1897 posix_ftruncate(self, args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1898 PyObject *self; /* Not used */
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1899 PyObject *args;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1900 {
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1901 int fd;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1902 long length;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1903 int res;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1904
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1905 if (!PyArg_Parse(args, "(il)", &fd, &length))
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1906 return NULL;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1907
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1908 Py_BEGIN_ALLOW_THREADS
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1909 res = ftruncate(fd, length);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1910 Py_END_ALLOW_THREADS
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1911 if (res < 0) {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1912 PyErr_SetFromErrno(PyExc_IOError);
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1913 return NULL;
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1914 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1915 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
1916 return Py_None;
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1917 }
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
1918 #endif
793
cbf0ef998a4a Added times() (from time)
Guido van Rossum <guido@python.org>
parents: 731
diff changeset
1919
5584
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1920 #ifdef NeXT
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1921 #define HAVE_PUTENV
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1922 /* Steve Spicklemire got this putenv from NeXTAnswers */
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1923 static int
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1924 putenv(char *newval)
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1925 {
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1926 extern char **environ;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1927
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1928 static int firstTime = 1;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1929 char **ep;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1930 char *cp;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1931 int esiz;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1932 char *np;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1933
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1934 if (!(np = strchr(newval, '=')))
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1935 return 1;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1936 *np = '\0';
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1937
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1938 /* look it up */
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1939 for (ep=environ ; *ep ; ep++)
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1940 {
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1941 /* this should always be true... */
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1942 if (cp = strchr(*ep, '='))
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1943 {
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1944 *cp = '\0';
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1945 if (!strcmp(*ep, newval))
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1946 {
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1947 /* got it! */
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1948 *cp = '=';
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1949 break;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1950 }
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1951 *cp = '=';
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1952 }
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1953 else
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1954 {
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1955 *np = '=';
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1956 return 1;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1957 }
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1958 }
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1959
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1960 *np = '=';
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1961 if (*ep)
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1962 {
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1963 /* the string was already there:
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1964 just replace it with the new one */
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1965 *ep = newval;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1966 return 0;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1967 }
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1968
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1969 /* expand environ by one */
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1970 for (esiz=2, ep=environ ; *ep ; ep++)
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1971 esiz++;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1972 if (firstTime)
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1973 {
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1974 char **epp;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1975 char **newenv;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1976 if (!(newenv = malloc(esiz * sizeof(char *))))
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1977 return 1;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1978
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1979 for (ep=environ, epp=newenv ; *ep ;)
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1980 *epp++ = *ep++;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1981 *epp++ = newval;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1982 *epp = (char *) 0;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1983 environ = newenv;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1984 }
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1985 else
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1986 {
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1987 if (!(environ = realloc(environ, esiz * sizeof(char *))))
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1988 return 1;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1989 environ[esiz - 2] = newval;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1990 environ[esiz - 1] = (char *) 0;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1991 firstTime = 0;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1992 }
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1993
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1994 return 0;
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1995 }
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1996 #endif NeXT
85c5043c9316 Enable putenv and waitpid (== wait4) for NeXT.
Guido van Rossum <guido@python.org>
parents: 5361
diff changeset
1997
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
1998
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
1999 #ifdef HAVE_PUTENV
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2000 static char posix_putenv__doc__[] =
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2001 "putenv(key, value) -> None\n\
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2002 Change or add an environment variable.";
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2003
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2004 static PyObject *
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
2005 posix_putenv(self,args)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2006 PyObject *self;
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2007 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
2008 {
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
2009 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
2010 char *new;
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
2011
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2012 if (!PyArg_ParseTuple(args, "ss", &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
2013 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
2014 /* XXX This leaks memory -- not easy to fix :-( */
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
2015 if ((new = malloc(strlen(s1) + strlen(s2) + 2)) == NULL)
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2016 return PyErr_NoMemory();
3801
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
2017 (void) sprintf(new, "%s=%s", 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
2018 if (putenv(new)) {
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
2019 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
2020 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
2021 }
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2022 Py_INCREF(Py_None);
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2023 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
2024 }
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
2025 #endif
843121a226ca Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Guido van Rossum <guido@python.org>
parents: 3735
diff changeset
2026
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2027 static PyMethodDef posix_methods[] = {
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2028 {"chdir", posix_chdir, 0, posix_chdir__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2029 {"chmod", posix_chmod, 0, posix_chmod__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2030 #ifdef HAVE_CHOWN
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2031 {"chown", posix_chown, 0, 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
2032 #endif /* HAVE_CHOWN */
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
2033 #ifdef HAVE_GETCWD
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2034 {"getcwd", posix_getcwd, 0, posix_getcwd__doc__},
2740
3e370a4b103b sys/wait.h; NeXT changes (no unistd, utime; getcwd?)
Guido van Rossum <guido@python.org>
parents: 2615
diff changeset
2035 #endif
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2036 #ifdef HAVE_LINK
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2037 {"link", posix_link, 0, 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
2038 #endif /* HAVE_LINK */
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2039 {"listdir", posix_listdir, 0, posix_listdir__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2040 {"lstat", posix_lstat, 0, posix_lstat__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2041 {"mkdir", posix_mkdir, 1, posix_mkdir__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2042 #ifdef HAVE_NICE
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2043 {"nice", posix_nice, 0, 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
2044 #endif /* HAVE_NICE */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2045 #ifdef HAVE_READLINK
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2046 {"readlink", posix_readlink, 0, 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
2047 #endif /* HAVE_READLINK */
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2048 {"rename", posix_rename, 0, posix_rename__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2049 {"rmdir", posix_rmdir, 0, posix_rmdir__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2050 {"stat", posix_stat, 0, posix_stat__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2051 #ifdef HAVE_SYMLINK
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2052 {"symlink", posix_symlink, 0, 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
2053 #endif /* HAVE_SYMLINK */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2054 #ifdef HAVE_SYSTEM
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2055 {"system", posix_system, 0, posix_system__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2056 #endif
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2057 {"umask", posix_umask, 0, posix_umask__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2058 #ifdef HAVE_UNAME
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2059 {"uname", posix_uname, 0, 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
2060 #endif /* HAVE_UNAME */
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2061 {"unlink", posix_unlink, 0, posix_unlink__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2062 {"remove", posix_unlink, 0, posix_remove__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2063 {"utime", posix_utime, 0, posix_utime__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2064 #ifdef HAVE_TIMES
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2065 {"times", posix_times, 0, 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
2066 #endif /* HAVE_TIMES */
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2067 {"_exit", posix__exit, 0, posix__exit__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2068 #ifdef HAVE_EXECV
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2069 {"execv", posix_execv, 0, posix_execv__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2070 {"execve", posix_execve, 0, posix_execve__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2071 #endif /* HAVE_EXECV */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2072 #ifdef HAVE_FORK
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2073 {"fork", posix_fork, 0, posix_fork__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2074 #endif /* HAVE_FORK */
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2075 #ifdef HAVE_GETEGID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2076 {"getegid", posix_getegid, 0, posix_getegid__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2077 #endif /* HAVE_GETEGID */
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2078 #ifdef HAVE_GETEUID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2079 {"geteuid", posix_geteuid, 0, posix_geteuid__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2080 #endif /* HAVE_GETEUID */
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2081 #ifdef HAVE_GETGID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2082 {"getgid", posix_getgid, 0, posix_getgid__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2083 #endif /* HAVE_GETGID */
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2084 {"getpid", posix_getpid, 0, posix_getpid__doc__},
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2085 #ifdef HAVE_GETPGRP
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2086 {"getpgrp", posix_getpgrp, 0, 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
2087 #endif /* HAVE_GETPGRP */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2088 #ifdef HAVE_GETPPID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2089 {"getppid", posix_getppid, 0, posix_getppid__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2090 #endif /* HAVE_GETPPID */
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2091 #ifdef HAVE_GETUID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2092 {"getuid", posix_getuid, 0, posix_getuid__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2093 #endif /* HAVE_GETUID */
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2094 #ifdef HAVE_KILL
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2095 {"kill", posix_kill, 0, posix_kill__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2096 #endif /* HAVE_KILL */
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
2097 #ifdef HAVE_PLOCK
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2098 {"plock", posix_plock, 0, posix_plock__doc__},
3735
4692cb46008e Added plock() system call.
Guido van Rossum <guido@python.org>
parents: 3702
diff changeset
2099 #endif /* HAVE_PLOCK */
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2100 #ifdef HAVE_POPEN
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2101 {"popen", posix_popen, 1, posix_popen__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2102 #endif /* HAVE_POPEN */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2103 #ifdef HAVE_SETUID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2104 {"setuid", posix_setuid, 0, 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
2105 #endif /* HAVE_SETUID */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2106 #ifdef HAVE_SETGID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2107 {"setgid", posix_setgid, 0, 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
2108 #endif /* HAVE_SETGID */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2109 #ifdef HAVE_SETPGRP
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2110 {"setpgrp", posix_setpgrp, 0, 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
2111 #endif /* HAVE_SETPGRP */
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2112 #ifdef HAVE_WAIT
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2113 {"wait", posix_wait, 0, posix_wait__doc__},
2456
bc03225a4493 changes for NT/Borland C
Guido van Rossum <guido@python.org>
parents: 2370
diff changeset
2114 #endif /* HAVE_WAIT */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2115 #ifdef HAVE_WAITPID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2116 {"waitpid", posix_waitpid, 0, 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
2117 #endif /* HAVE_WAITPID */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2118 #ifdef HAVE_SETSID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2119 {"setsid", posix_setsid, 0, 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
2120 #endif /* HAVE_SETSID */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2121 #ifdef HAVE_SETPGID
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2122 {"setpgid", posix_setpgid, 0, 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
2123 #endif /* HAVE_SETPGID */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2124 #ifdef HAVE_TCGETPGRP
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2125 {"tcgetpgrp", posix_tcgetpgrp, 0, 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
2126 #endif /* HAVE_TCGETPGRP */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2127 #ifdef HAVE_TCSETPGRP
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2128 {"tcsetpgrp", posix_tcsetpgrp, 0, 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
2129 #endif /* HAVE_TCSETPGRP */
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2130 {"open", posix_open, 1, posix_open__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2131 {"close", posix_close, 0, posix_close__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2132 {"dup", posix_dup, 0, posix_dup__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2133 {"dup2", posix_dup2, 0, posix_dup2__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2134 {"lseek", posix_lseek, 0, posix_lseek__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2135 {"read", posix_read, 0, posix_read__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2136 {"write", posix_write, 0, posix_write__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2137 {"fstat", posix_fstat, 0, posix_fstat__doc__},
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2138 {"fdopen", posix_fdopen, 1, posix_fdopen__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2139 #ifdef HAVE_PIPE
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2140 {"pipe", posix_pipe, 0, posix_pipe__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2141 #endif
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2142 #ifdef HAVE_MKFIFO
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2143 {"mkfifo", posix_mkfifo, 1, posix_mkfifo__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2144 #endif
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2145 #ifdef HAVE_FTRUNCATE
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2146 {"ftruncate", posix_ftruncate, 1, posix_ftruncate__doc__},
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2147 #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
2148 #ifdef HAVE_PUTENV
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2149 {"putenv", posix_putenv, 1, 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
2150 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2151 {NULL, NULL} /* Sentinel */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2152 };
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2153
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2154
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2155 static int
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2156 ins(d, symbol, value)
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2157 PyObject* d;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2158 char* symbol;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2159 long value;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2160 {
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2161 PyObject* v = PyInt_FromLong(value);
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2162 if (!v || PyDict_SetItemString(d, symbol, v) < 0)
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2163 return -1; /* triggers fatal error */
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2164
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2165 Py_DECREF(v);
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2166 return 0;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2167 }
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2168
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2169 static int
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2170 all_ins(d)
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2171 PyObject* d;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2172 {
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2173 #ifdef WNOHANG
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2174 if (ins(d, "WNOHANG", (long)WNOHANG)) return -1;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2175 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2176 #ifdef O_RDONLY
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2177 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
2178 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2179 #ifdef O_WRONLY
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2180 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
2181 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2182 #ifdef O_RDWR
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2183 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
2184 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2185 #ifdef O_NDELAY
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2186 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
2187 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2188 #ifdef O_NONBLOCK
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2189 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
2190 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2191 #ifdef O_APPEND
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2192 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
2193 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2194 #ifdef O_DSYNC
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2195 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
2196 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2197 #ifdef O_RSYNC
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2198 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
2199 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2200 #ifdef O_SYNC
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2201 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
2202 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2203 #ifdef O_NOCTTY
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2204 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
2205 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2206 #ifdef O_CREAT
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2207 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
2208 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2209 #ifdef O_EXCL
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2210 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
2211 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2212 #ifdef O_TRUNC
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2213 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
2214 #endif
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2215 return 0;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2216 }
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2217
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2218
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2219
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2220
3622
b75edc0e6333 Changed NT -> MSC or WATCOM
Guido van Rossum <guido@python.org>
parents: 3601
diff changeset
2221 #if defined(_MSC_VER) || defined(__WATCOMC__)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2222 void
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2223 initnt()
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2224 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2225 PyObject *m, *d, *v;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2226
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2227 m = Py_InitModule4("nt",
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2228 posix_methods,
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2229 posix__doc__,
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2230 (PyObject *)NULL,
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2231 PYTHON_API_VERSION);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2232 d = PyModule_GetDict(m);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2233
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2234 /* Initialize nt.environ dictionary */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2235 v = convertenviron();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2236 if (v == NULL || PyDict_SetItemString(d, "environ", v) != 0)
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2237 goto finally;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2238 Py_DECREF(v);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2239
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2240 if (all_ins(d))
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2241 goto finally;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2242
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2243 /* Initialize nt.error exception */
5361
b1c2b79aa51f Change the exception objects to have the string value "os.error"
Guido van Rossum <guido@python.org>
parents: 5058
diff changeset
2244 PosixError = PyString_FromString("os.error");
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2245 PyDict_SetItemString(d, "error", PosixError);
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2246
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2247 if (!PyErr_Occurred())
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2248 return;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2249
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2250 finally:
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2251 Py_FatalError("can't initialize NT posixmodule");
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1441
diff changeset
2252 }
3702
3408756ec601 changed windows test symbols; removed debug printf from sockets
Guido van Rossum <guido@python.org>
parents: 3695
diff changeset
2253 #else /* not a PC port */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2254 void
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2255 initposix()
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2256 {
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2257 PyObject *m, *d, *v;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2258
5699
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2259 m = Py_InitModule4("posix",
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2260 posix_methods,
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2261 posix__doc__,
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2262 (PyObject *)NULL,
76fd5281f98a Added doc strings (Neil Schemenauer).
Guido van Rossum <guido@python.org>
parents: 5584
diff changeset
2263 PYTHON_API_VERSION);
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2264 d = PyModule_GetDict(m);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2265
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2266 /* Initialize posix.environ dictionary */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2267 v = convertenviron();
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2268 if (v == NULL || PyDict_SetItemString(d, "environ", v) != 0)
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2269 goto finally;
4672
5b53268f547a Renamed.
Barry Warsaw <barry@python.org>
parents: 4600
diff changeset
2270 Py_DECREF(v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2271
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2272 if (all_ins(d))
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2273 goto finally;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2274
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2275 /* Initialize posix.error exception */
5361
b1c2b79aa51f Change the exception objects to have the string value "os.error"
Guido van Rossum <guido@python.org>
parents: 5058
diff changeset
2276 PosixError = PyString_FromString("os.error");
4789
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2277 PyDict_SetItemString(d, "error", PosixError);
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2278
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2279 if (!PyErr_Occurred())
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2280 return;
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2281
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2282 finally:
d45ba64b82fd 1. Export open(2) flag constants for every defined constant
Barry Warsaw <barry@python.org>
parents: 4785
diff changeset
2283 Py_FatalError("can't initialize posix module");
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2284 }
3601
5a7a76166e7e Added mkfifo, ftruncate. Windows/PC changes.
Guido van Rossum <guido@python.org>
parents: 3418
diff changeset
2285 #endif /* !_MSC_VER */