Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 524b588 | 1995-01-04 19:10:35 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 32 | /* POSIX module implementation */ |
| 33 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 34 | /* This file is also used for Windows NT and MS-Win. In that case the module |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 35 | actually calls itself 'nt', not 'posix', and a few functions are |
| 36 | either unimplemented or implemented differently. The source |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 37 | assumes that for Windows NT, the macro 'MS_WIN32' is defined independent |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 38 | of the compiler used. Different compilers define their own feature |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 39 | test macro, e.g. '__BORLANDC__' or '_MSC_VER'. */ |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 40 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 41 | /* See also ../Dos/dosmodule.c */ |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 42 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 43 | static char posix__doc__ [] = |
| 44 | "This module provides access to operating system functionality that is\n\ |
| 45 | standardized by the C Standard and the POSIX standard (a thinly\n\ |
| 46 | disguised Unix interface). Refer to the library manual and\n\ |
| 47 | corresponding Unix manual entries for more information on calls."; |
| 48 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 49 | #include "Python.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 50 | |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 51 | #if defined(PYOS_OS2) |
| 52 | #define INCL_DOS |
| 53 | #define INCL_DOSERRORS |
| 54 | #define INCL_DOSPROCESS |
| 55 | #define INCL_NOPMAPI |
| 56 | #include <os2.h> |
| 57 | #endif |
| 58 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 59 | #include <sys/types.h> |
| 60 | #include <sys/stat.h> |
Guido van Rossum | 36bc680 | 1995-06-14 22:54:23 +0000 | [diff] [blame] | 61 | #ifdef HAVE_SYS_WAIT_H |
| 62 | #include <sys/wait.h> /* For WNOHANG */ |
| 63 | #endif |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 64 | |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 65 | #ifdef HAVE_SIGNAL_H |
| 66 | #include <signal.h> |
| 67 | #endif |
| 68 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 69 | #include "mytime.h" /* For clock_t on some systems */ |
| 70 | |
| 71 | #ifdef HAVE_FCNTL_H |
| 72 | #include <fcntl.h> |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 73 | #endif /* HAVE_FCNTL_H */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 74 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 75 | /* Various compilers have only certain posix functions */ |
Guido van Rossum | 6d8841c | 1997-08-14 19:57:39 +0000 | [diff] [blame] | 76 | /* XXX Gosh I wish these were all moved into config.h */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 77 | #if defined(PYCC_VACPP) && defined(PYOS_OS2) |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 78 | #include <process.h> |
| 79 | #else |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 80 | #if defined(__WATCOMC__) && !defined(__QNX__) /* Watcom compiler */ |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 81 | #define HAVE_GETCWD 1 |
| 82 | #define HAVE_OPENDIR 1 |
| 83 | #define HAVE_SYSTEM 1 |
| 84 | #if defined(__OS2__) |
| 85 | #define HAVE_EXECV 1 |
| 86 | #define HAVE_WAIT 1 |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 87 | #endif |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 88 | #include <process.h> |
| 89 | #else |
| 90 | #ifdef __BORLANDC__ /* Borland compiler */ |
| 91 | #define HAVE_EXECV 1 |
| 92 | #define HAVE_GETCWD 1 |
| 93 | #define HAVE_GETEGID 1 |
| 94 | #define HAVE_GETEUID 1 |
| 95 | #define HAVE_GETGID 1 |
| 96 | #define HAVE_GETPPID 1 |
| 97 | #define HAVE_GETUID 1 |
| 98 | #define HAVE_KILL 1 |
| 99 | #define HAVE_OPENDIR 1 |
| 100 | #define HAVE_PIPE 1 |
| 101 | #define HAVE_POPEN 1 |
| 102 | #define HAVE_SYSTEM 1 |
| 103 | #define HAVE_WAIT 1 |
| 104 | #else |
| 105 | #ifdef _MSC_VER /* Microsoft compiler */ |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 106 | #define HAVE_GETCWD 1 |
| 107 | #ifdef MS_WIN32 |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 108 | #define HAVE_SPAWNV 1 |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 109 | #define HAVE_EXECV 1 |
| 110 | #define HAVE_PIPE 1 |
| 111 | #define HAVE_POPEN 1 |
| 112 | #define HAVE_SYSTEM 1 |
| 113 | #else /* 16-bit Windows */ |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 114 | #endif /* !MS_WIN32 */ |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 115 | #else /* all other compilers */ |
| 116 | /* Unix functions that the configure script doesn't check for */ |
| 117 | #define HAVE_EXECV 1 |
| 118 | #define HAVE_FORK 1 |
| 119 | #define HAVE_GETCWD 1 |
| 120 | #define HAVE_GETEGID 1 |
| 121 | #define HAVE_GETEUID 1 |
| 122 | #define HAVE_GETGID 1 |
| 123 | #define HAVE_GETPPID 1 |
| 124 | #define HAVE_GETUID 1 |
| 125 | #define HAVE_KILL 1 |
| 126 | #define HAVE_OPENDIR 1 |
| 127 | #define HAVE_PIPE 1 |
| 128 | #define HAVE_POPEN 1 |
| 129 | #define HAVE_SYSTEM 1 |
| 130 | #define HAVE_WAIT 1 |
Guido van Rossum | d371ff1 | 1999-01-25 16:12:23 +0000 | [diff] [blame] | 131 | #define HAVE_TTYNAME 1 |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 132 | #endif /* _MSC_VER */ |
| 133 | #endif /* __BORLANDC__ */ |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 134 | #endif /* ! __WATCOMC__ || __QNX__ */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 135 | #endif /* ! __IBMC__ */ |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 136 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 137 | #ifndef _MSC_VER |
Guido van Rossum | 36bc680 | 1995-06-14 22:54:23 +0000 | [diff] [blame] | 138 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 139 | #ifdef HAVE_UNISTD_H |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 140 | #include <unistd.h> |
Guido van Rossum | 36bc680 | 1995-06-14 22:54:23 +0000 | [diff] [blame] | 141 | #endif |
| 142 | |
| 143 | #ifdef NeXT |
| 144 | /* NeXT's <unistd.h> and <utime.h> aren't worth much */ |
| 145 | #undef HAVE_UNISTD_H |
| 146 | #undef HAVE_UTIME_H |
Guido van Rossum | b9f866c | 1997-05-22 15:12:39 +0000 | [diff] [blame] | 147 | #define HAVE_WAITPID |
Guido van Rossum | 36bc680 | 1995-06-14 22:54:23 +0000 | [diff] [blame] | 148 | /* #undef HAVE_GETCWD */ |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 149 | #define UNION_WAIT /* This should really be checked for by autoconf */ |
Guido van Rossum | 36bc680 | 1995-06-14 22:54:23 +0000 | [diff] [blame] | 150 | #endif |
| 151 | |
| 152 | #ifdef HAVE_UNISTD_H |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 153 | /* XXX These are for SunOS4.1.3 but shouldn't hurt elsewhere */ |
| 154 | extern int rename(); |
| 155 | extern int pclose(); |
| 156 | extern int lstat(); |
| 157 | extern int symlink(); |
Guido van Rossum | 8c67e4e | 1999-04-07 15:49:41 +0000 | [diff] [blame] | 158 | extern int fsync(); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 159 | #else /* !HAVE_UNISTD_H */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 160 | #if defined(PYCC_VACPP) |
| 161 | extern int mkdir Py_PROTO((char *)); |
| 162 | #else |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 163 | #if ( defined(__WATCOMC__) || defined(_MSC_VER) ) && !defined(__QNX__) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 164 | extern int mkdir Py_PROTO((const char *)); |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 165 | #else |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 166 | extern int mkdir Py_PROTO((const char *, mode_t)); |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 167 | #endif |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 168 | #endif |
| 169 | #if defined(__IBMC__) || defined(__IBMCPP__) |
| 170 | extern int chdir Py_PROTO((char *)); |
| 171 | extern int rmdir Py_PROTO((char *)); |
| 172 | #else |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 173 | extern int chdir Py_PROTO((const char *)); |
| 174 | extern int rmdir Py_PROTO((const char *)); |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 175 | #endif |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 176 | extern int chmod Py_PROTO((const char *, mode_t)); |
| 177 | extern int chown Py_PROTO((const char *, uid_t, gid_t)); |
| 178 | extern char *getcwd Py_PROTO((char *, int)); |
| 179 | extern char *strerror Py_PROTO((int)); |
| 180 | extern int link Py_PROTO((const char *, const char *)); |
| 181 | extern int rename Py_PROTO((const char *, const char *)); |
| 182 | extern int stat Py_PROTO((const char *, struct stat *)); |
| 183 | extern int unlink Py_PROTO((const char *)); |
| 184 | extern int pclose Py_PROTO((FILE *)); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 185 | #ifdef HAVE_SYMLINK |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 186 | extern int symlink Py_PROTO((const char *, const char *)); |
Guido van Rossum | a38a503 | 1995-02-17 15:11:36 +0000 | [diff] [blame] | 187 | #endif /* HAVE_SYMLINK */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 188 | #ifdef HAVE_LSTAT |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 189 | extern int lstat Py_PROTO((const char *, struct stat *)); |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 190 | #endif /* HAVE_LSTAT */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 191 | #endif /* !HAVE_UNISTD_H */ |
Guido van Rossum | 36bc680 | 1995-06-14 22:54:23 +0000 | [diff] [blame] | 192 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 193 | #endif /* !_MSC_VER */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 194 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 195 | #ifdef HAVE_UTIME_H |
| 196 | #include <utime.h> |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 197 | #endif /* HAVE_UTIME_H */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 198 | |
Guido van Rossum | 14ed0b2 | 1994-09-29 09:50:09 +0000 | [diff] [blame] | 199 | #ifdef HAVE_SYS_UTIME_H |
| 200 | #include <sys/utime.h> |
| 201 | #define HAVE_UTIME_H /* pretend we do for the rest of this file */ |
| 202 | #endif /* HAVE_SYS_UTIME_H */ |
| 203 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 204 | #ifdef HAVE_SYS_TIMES_H |
| 205 | #include <sys/times.h> |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 206 | #endif /* HAVE_SYS_TIMES_H */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 207 | |
| 208 | #ifdef HAVE_SYS_PARAM_H |
| 209 | #include <sys/param.h> |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 210 | #endif /* HAVE_SYS_PARAM_H */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 211 | |
| 212 | #ifdef HAVE_SYS_UTSNAME_H |
| 213 | #include <sys/utsname.h> |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 214 | #endif /* HAVE_SYS_UTSNAME_H */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 215 | |
| 216 | #ifndef MAXPATHLEN |
| 217 | #define MAXPATHLEN 1024 |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 218 | #endif /* MAXPATHLEN */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 219 | |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 220 | #ifdef HAVE_DIRENT_H |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 221 | #include <dirent.h> |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 222 | #define NAMLEN(dirent) strlen((dirent)->d_name) |
| 223 | #else |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 224 | #if defined(__WATCOMC__) && !defined(__QNX__) |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 225 | #include <direct.h> |
| 226 | #define NAMLEN(dirent) strlen((dirent)->d_name) |
| 227 | #else |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 228 | #define dirent direct |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 229 | #define NAMLEN(dirent) (dirent)->d_namlen |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 230 | #endif |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 231 | #ifdef HAVE_SYS_NDIR_H |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 232 | #include <sys/ndir.h> |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 233 | #endif |
| 234 | #ifdef HAVE_SYS_DIR_H |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 235 | #include <sys/dir.h> |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 236 | #endif |
| 237 | #ifdef HAVE_NDIR_H |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 238 | #include <ndir.h> |
Guido van Rossum | 3bbc62e | 1995-01-02 19:30:30 +0000 | [diff] [blame] | 239 | #endif |
| 240 | #endif |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 241 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 242 | #ifdef _MSC_VER |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 243 | #include <direct.h> |
| 244 | #include <io.h> |
| 245 | #include <process.h> |
| 246 | #include <windows.h> |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 247 | #ifdef MS_WIN32 |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 248 | #define popen _popen |
Guido van Rossum | 794d813 | 1994-08-23 13:48:48 +0000 | [diff] [blame] | 249 | #define pclose _pclose |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 250 | #else /* 16-bit Windows */ |
| 251 | #include <dos.h> |
| 252 | #include <ctype.h> |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 253 | #endif /* MS_WIN32 */ |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 254 | #endif /* _MSC_VER */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 255 | |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 256 | #if defined(PYCC_VACPP) && defined(PYOS_OS2) |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 257 | #include <io.h> |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 258 | #endif /* OS2 */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 259 | |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 260 | #ifdef UNION_WAIT |
| 261 | /* Emulate some macros on systems that have a union instead of macros */ |
| 262 | |
| 263 | #ifndef WIFEXITED |
| 264 | #define WIFEXITED(u_wait) (!(u_wait).w_termsig && !(u_wait).w_coredump) |
| 265 | #endif |
| 266 | |
| 267 | #ifndef WEXITSTATUS |
| 268 | #define WEXITSTATUS(u_wait) (WIFEXITED(u_wait)?((u_wait).w_retcode):-1) |
| 269 | #endif |
| 270 | |
| 271 | #ifndef WTERMSIG |
| 272 | #define WTERMSIG(u_wait) ((u_wait).w_termsig) |
| 273 | #endif |
| 274 | |
| 275 | #endif /* UNION_WAIT */ |
| 276 | |
Greg Ward | b48bc17 | 2000-03-01 21:51:56 +0000 | [diff] [blame] | 277 | /* Don't use the "_r" form if we don't need it (also, won't have a |
| 278 | prototype for it, at least on Solaris -- maybe others as well?). */ |
| 279 | #if defined(HAVE_CTERMID_R) && defined(WITH_THREAD) |
| 280 | #define USE_CTERMID_R |
| 281 | #endif |
| 282 | |
| 283 | #if defined(HAVE_TMPNAM_R) && defined(WITH_THREAD) |
| 284 | #define USE_TMPNAM_R |
| 285 | #endif |
| 286 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 287 | /* Return a dictionary corresponding to the POSIX environment table */ |
| 288 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 289 | #if !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) ) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 290 | extern char **environ; |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 291 | #endif /* !_MSC_VER */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 292 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 293 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 294 | convertenviron() |
| 295 | { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 296 | PyObject *d; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 297 | char **e; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 298 | d = PyDict_New(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 299 | if (d == NULL) |
| 300 | return NULL; |
| 301 | if (environ == NULL) |
| 302 | return d; |
Guido van Rossum | 6a619f4 | 1999-08-03 19:41:10 +0000 | [diff] [blame] | 303 | /* This part ignores errors */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 304 | for (e = environ; *e != NULL; e++) { |
Guido van Rossum | 6a619f4 | 1999-08-03 19:41:10 +0000 | [diff] [blame] | 305 | PyObject *k; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 306 | PyObject *v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 307 | char *p = strchr(*e, '='); |
| 308 | if (p == NULL) |
| 309 | continue; |
Guido van Rossum | 6a619f4 | 1999-08-03 19:41:10 +0000 | [diff] [blame] | 310 | k = PyString_FromStringAndSize(*e, (int)(p-*e)); |
| 311 | if (k == NULL) { |
| 312 | PyErr_Clear(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 313 | continue; |
Guido van Rossum | 6a619f4 | 1999-08-03 19:41:10 +0000 | [diff] [blame] | 314 | } |
| 315 | v = PyString_FromString(p+1); |
| 316 | if (v == NULL) { |
| 317 | PyErr_Clear(); |
| 318 | Py_DECREF(k); |
| 319 | continue; |
| 320 | } |
| 321 | if (PyDict_GetItem(d, k) == NULL) { |
| 322 | if (PyDict_SetItem(d, k, v) != 0) |
| 323 | PyErr_Clear(); |
| 324 | } |
| 325 | Py_DECREF(k); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 326 | Py_DECREF(v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 327 | } |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 328 | #if defined(PYOS_OS2) |
| 329 | { |
| 330 | APIRET rc; |
| 331 | char buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars */ |
| 332 | |
| 333 | rc = DosQueryExtLIBPATH(buffer, BEGIN_LIBPATH); |
| 334 | if (rc == NO_ERROR) { /* (not a type, envname is NOT 'BEGIN_LIBPATH') */ |
| 335 | PyObject *v = PyString_FromString(buffer); |
| 336 | PyDict_SetItemString(d, "BEGINLIBPATH", v); |
| 337 | Py_DECREF(v); |
| 338 | } |
| 339 | rc = DosQueryExtLIBPATH(buffer, END_LIBPATH); |
| 340 | if (rc == NO_ERROR) { /* (not a typo, envname is NOT 'END_LIBPATH') */ |
| 341 | PyObject *v = PyString_FromString(buffer); |
| 342 | PyDict_SetItemString(d, "ENDLIBPATH", v); |
| 343 | Py_DECREF(v); |
| 344 | } |
| 345 | } |
| 346 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 347 | return d; |
| 348 | } |
| 349 | |
| 350 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 351 | /* Set a POSIX-specific error from errno, and return NULL */ |
| 352 | |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 353 | static PyObject * |
| 354 | posix_error() |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 355 | { |
Barry Warsaw | ca74da4 | 1999-02-09 19:31:45 +0000 | [diff] [blame] | 356 | return PyErr_SetFromErrno(PyExc_OSError); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 357 | } |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 358 | static PyObject * |
| 359 | posix_error_with_filename(name) |
| 360 | char* name; |
| 361 | { |
Barry Warsaw | ca74da4 | 1999-02-09 19:31:45 +0000 | [diff] [blame] | 362 | return PyErr_SetFromErrnoWithFilename(PyExc_OSError, name); |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 365 | |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 366 | #if defined(PYOS_OS2) |
| 367 | /********************************************************************** |
| 368 | * Helper Function to Trim and Format OS/2 Messages |
| 369 | **********************************************************************/ |
| 370 | static void |
| 371 | os2_formatmsg(char *msgbuf, int msglen, char *reason) |
| 372 | { |
| 373 | msgbuf[msglen] = '\0'; /* OS/2 Doesn't Guarantee a Terminator */ |
| 374 | |
| 375 | if (strlen(msgbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */ |
| 376 | char *lastc = &msgbuf[ strlen(msgbuf)-1 ]; |
| 377 | |
| 378 | while (lastc > msgbuf && isspace(*lastc)) |
| 379 | *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */ |
| 380 | } |
| 381 | |
| 382 | /* Add Optional Reason Text */ |
| 383 | if (reason) { |
| 384 | strcat(msgbuf, " : "); |
| 385 | strcat(msgbuf, reason); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /********************************************************************** |
| 390 | * Decode an OS/2 Operating System Error Code |
| 391 | * |
| 392 | * A convenience function to lookup an OS/2 error code and return a |
| 393 | * text message we can use to raise a Python exception. |
| 394 | * |
| 395 | * Notes: |
| 396 | * The messages for errors returned from the OS/2 kernel reside in |
| 397 | * the file OSO001.MSG in the \OS2 directory hierarchy. |
| 398 | * |
| 399 | **********************************************************************/ |
| 400 | static char * |
| 401 | os2_strerror(char *msgbuf, int msgbuflen, int errorcode, char *reason) |
| 402 | { |
| 403 | APIRET rc; |
| 404 | ULONG msglen; |
| 405 | |
| 406 | /* Retrieve Kernel-Related Error Message from OSO001.MSG File */ |
| 407 | Py_BEGIN_ALLOW_THREADS |
| 408 | rc = DosGetMessage(NULL, 0, msgbuf, msgbuflen, |
| 409 | errorcode, "oso001.msg", &msglen); |
| 410 | Py_END_ALLOW_THREADS |
| 411 | |
| 412 | if (rc == NO_ERROR) |
| 413 | os2_formatmsg(msgbuf, msglen, reason); |
| 414 | else |
| 415 | sprintf(msgbuf, "unknown OS error #%d", errorcode); |
| 416 | |
| 417 | return msgbuf; |
| 418 | } |
| 419 | |
| 420 | /* Set an OS/2-specific error and return NULL. OS/2 kernel |
| 421 | errors are not in a global variable e.g. 'errno' nor are |
| 422 | they congruent with posix error numbers. */ |
| 423 | |
| 424 | static PyObject * os2_error(int code) |
| 425 | { |
| 426 | char text[1024]; |
| 427 | PyObject *v; |
| 428 | |
| 429 | os2_strerror(text, sizeof(text), code, ""); |
| 430 | |
| 431 | v = Py_BuildValue("(is)", code, text); |
| 432 | if (v != NULL) { |
Barry Warsaw | ca74da4 | 1999-02-09 19:31:45 +0000 | [diff] [blame] | 433 | PyErr_SetObject(PyExc_OSError, v); |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 434 | Py_DECREF(v); |
| 435 | } |
| 436 | return NULL; /* Signal to Python that an Exception is Pending */ |
| 437 | } |
| 438 | |
| 439 | #endif /* OS2 */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 440 | |
| 441 | /* POSIX generic methods */ |
| 442 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 443 | static PyObject * |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 444 | posix_int(args, format, func) |
Guido van Rossum | 21142a0 | 1999-01-08 21:05:37 +0000 | [diff] [blame] | 445 | PyObject *args; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 446 | char *format; |
Guido van Rossum | 21142a0 | 1999-01-08 21:05:37 +0000 | [diff] [blame] | 447 | int (*func) Py_FPROTO((int)); |
| 448 | { |
| 449 | int fd; |
| 450 | int res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 451 | if (!PyArg_ParseTuple(args, format, &fd)) |
Guido van Rossum | 21142a0 | 1999-01-08 21:05:37 +0000 | [diff] [blame] | 452 | return NULL; |
| 453 | Py_BEGIN_ALLOW_THREADS |
| 454 | res = (*func)(fd); |
| 455 | Py_END_ALLOW_THREADS |
| 456 | if (res < 0) |
| 457 | return posix_error(); |
| 458 | Py_INCREF(Py_None); |
| 459 | return Py_None; |
| 460 | } |
| 461 | |
| 462 | |
| 463 | static PyObject * |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 464 | posix_1str(args, format, func) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 465 | PyObject *args; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 466 | char *format; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 467 | int (*func) Py_FPROTO((const char *)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 468 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 469 | char *path1; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 470 | int res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 471 | if (!PyArg_ParseTuple(args, format, &path1)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 472 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 473 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 474 | res = (*func)(path1); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 475 | Py_END_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 476 | if (res < 0) |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 477 | return posix_error_with_filename(path1); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 478 | Py_INCREF(Py_None); |
| 479 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 482 | static PyObject * |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 483 | posix_2str(args, format, func) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 484 | PyObject *args; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 485 | char *format; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 486 | int (*func) Py_FPROTO((const char *, const char *)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 487 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 488 | char *path1, *path2; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 489 | int res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 490 | if (!PyArg_ParseTuple(args, format, &path1, &path2)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 491 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 492 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 493 | res = (*func)(path1, path2); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 494 | Py_END_ALLOW_THREADS |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 495 | if (res != 0) |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 496 | /* XXX how to report both path1 and path2??? */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 497 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 498 | Py_INCREF(Py_None); |
| 499 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 502 | static PyObject * |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 503 | posix_strint(args, format, func) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 504 | PyObject *args; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 505 | char *format; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 506 | int (*func) Py_FPROTO((const char *, int)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 507 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 508 | char *path; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 509 | int i; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 510 | int res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 511 | if (!PyArg_ParseTuple(args, format, &path, &i)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 512 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 513 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 514 | res = (*func)(path, i); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 515 | Py_END_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 516 | if (res < 0) |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 517 | return posix_error_with_filename(path); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 518 | Py_INCREF(Py_None); |
| 519 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 522 | static PyObject * |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 523 | posix_strintint(args, format, func) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 524 | PyObject *args; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 525 | char *format; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 526 | int (*func) Py_FPROTO((const char *, int, int)); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 527 | { |
| 528 | char *path; |
| 529 | int i,i2; |
| 530 | int res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 531 | if (!PyArg_ParseTuple(args, format, &path, &i, &i2)) |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 532 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 533 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 534 | res = (*func)(path, i, i2); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 535 | Py_END_ALLOW_THREADS |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 536 | if (res < 0) |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 537 | return posix_error_with_filename(path); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 538 | Py_INCREF(Py_None); |
| 539 | return Py_None; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 542 | static PyObject * |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 543 | posix_do_stat(self, args, format, statfunc) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 544 | PyObject *self; |
| 545 | PyObject *args; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 546 | char *format; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 547 | int (*statfunc) Py_FPROTO((const char *, struct stat *)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 548 | { |
| 549 | struct stat st; |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 550 | char *path; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 551 | int res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 552 | if (!PyArg_ParseTuple(args, format, &path)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 553 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 554 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 555 | res = (*statfunc)(path, &st); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 556 | Py_END_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 557 | if (res != 0) |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 558 | return posix_error_with_filename(path); |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 559 | #if !defined(HAVE_LARGEFILE_SUPPORT) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 560 | return Py_BuildValue("(llllllllll)", |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 561 | (long)st.st_mode, |
| 562 | (long)st.st_ino, |
| 563 | (long)st.st_dev, |
| 564 | (long)st.st_nlink, |
| 565 | (long)st.st_uid, |
| 566 | (long)st.st_gid, |
| 567 | (long)st.st_size, |
| 568 | (long)st.st_atime, |
| 569 | (long)st.st_mtime, |
| 570 | (long)st.st_ctime); |
| 571 | #else |
| 572 | return Py_BuildValue("(lLllllLlll)", |
| 573 | (long)st.st_mode, |
| 574 | (LONG_LONG)st.st_ino, |
| 575 | (long)st.st_dev, |
| 576 | (long)st.st_nlink, |
| 577 | (long)st.st_uid, |
| 578 | (long)st.st_gid, |
| 579 | (LONG_LONG)st.st_size, |
| 580 | (long)st.st_atime, |
| 581 | (long)st.st_mtime, |
| 582 | (long)st.st_ctime); |
| 583 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | |
| 587 | /* POSIX methods */ |
| 588 | |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 589 | static char posix_access__doc__[] = |
Guido van Rossum | 015f22a | 1999-01-06 22:52:38 +0000 | [diff] [blame] | 590 | "access(path, mode) -> 1 if granted, 0 otherwise\n\ |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 591 | Test for access to a file."; |
| 592 | |
| 593 | static PyObject * |
| 594 | posix_access(self, args) |
| 595 | PyObject *self; |
| 596 | PyObject *args; |
| 597 | { |
Guido van Rossum | 015f22a | 1999-01-06 22:52:38 +0000 | [diff] [blame] | 598 | char *path; |
| 599 | int mode; |
| 600 | int res; |
| 601 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 602 | if (!PyArg_ParseTuple(args, "si:access", &path, &mode)) |
Guido van Rossum | 015f22a | 1999-01-06 22:52:38 +0000 | [diff] [blame] | 603 | return NULL; |
| 604 | Py_BEGIN_ALLOW_THREADS |
| 605 | res = access(path, mode); |
| 606 | Py_END_ALLOW_THREADS |
| 607 | return(PyInt_FromLong(res == 0 ? 1L : 0L)); |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 608 | } |
| 609 | |
Guido van Rossum | d371ff1 | 1999-01-25 16:12:23 +0000 | [diff] [blame] | 610 | #ifndef F_OK |
| 611 | #define F_OK 0 |
| 612 | #endif |
| 613 | #ifndef R_OK |
| 614 | #define R_OK 4 |
| 615 | #endif |
| 616 | #ifndef W_OK |
| 617 | #define W_OK 2 |
| 618 | #endif |
| 619 | #ifndef X_OK |
| 620 | #define X_OK 1 |
| 621 | #endif |
| 622 | |
| 623 | #ifdef HAVE_TTYNAME |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 624 | static char posix_ttyname__doc__[] = |
Guido van Rossum | 61eeb04 | 1999-02-22 15:29:15 +0000 | [diff] [blame] | 625 | "ttyname(fd) -> String\n\ |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 626 | Return the name of the terminal device connected to 'fd'."; |
| 627 | |
| 628 | static PyObject * |
| 629 | posix_ttyname(self, args) |
| 630 | PyObject *self; |
| 631 | PyObject *args; |
| 632 | { |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 633 | int id; |
| 634 | char *ret; |
| 635 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 636 | if (!PyArg_ParseTuple(args, "i:ttyname", &id)) |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 637 | return NULL; |
| 638 | |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 639 | ret = ttyname(id); |
| 640 | if (ret == NULL) |
| 641 | return(posix_error()); |
| 642 | return(PyString_FromString(ret)); |
| 643 | } |
Guido van Rossum | d371ff1 | 1999-01-25 16:12:23 +0000 | [diff] [blame] | 644 | #endif |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 645 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 646 | #ifdef HAVE_CTERMID |
| 647 | static char posix_ctermid__doc__[] = |
| 648 | "ctermid() -> String\n\ |
| 649 | Return the name of the controlling terminal for this process."; |
| 650 | |
| 651 | static PyObject * |
| 652 | posix_ctermid(self, args) |
| 653 | PyObject *self; |
| 654 | PyObject *args; |
| 655 | { |
| 656 | char *ret; |
| 657 | char buffer[L_ctermid]; |
| 658 | |
| 659 | if (!PyArg_ParseTuple(args, ":ctermid")) |
| 660 | return NULL; |
| 661 | |
Greg Ward | b48bc17 | 2000-03-01 21:51:56 +0000 | [diff] [blame] | 662 | #ifdef USE_CTERMID_R |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 663 | ret = ctermid_r(buffer); |
| 664 | #else |
| 665 | ret = ctermid(buffer); |
| 666 | #endif |
| 667 | if (ret == NULL) |
| 668 | return(posix_error()); |
| 669 | return(PyString_FromString(buffer)); |
| 670 | } |
| 671 | #endif |
| 672 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 673 | static char posix_chdir__doc__[] = |
| 674 | "chdir(path) -> None\n\ |
| 675 | Change the current working directory to the specified path."; |
| 676 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 677 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 678 | posix_chdir(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 679 | PyObject *self; |
| 680 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 681 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 682 | return posix_1str(args, "s:chdir", chdir); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 685 | |
| 686 | static char posix_chmod__doc__[] = |
| 687 | "chmod(path, mode) -> None\n\ |
| 688 | Change the access permissions of a file."; |
| 689 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 690 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 691 | posix_chmod(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 692 | PyObject *self; |
| 693 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 694 | { |
Guido van Rossum | ffd15f5 | 2000-03-31 00:47:28 +0000 | [diff] [blame] | 695 | char *path; |
| 696 | int i; |
| 697 | int res; |
Guido van Rossum | 49679b4 | 2000-03-31 00:48:21 +0000 | [diff] [blame^] | 698 | if (!PyArg_ParseTuple(args, "si", &path, &i)) |
Guido van Rossum | ffd15f5 | 2000-03-31 00:47:28 +0000 | [diff] [blame] | 699 | return NULL; |
| 700 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 49679b4 | 2000-03-31 00:48:21 +0000 | [diff] [blame^] | 701 | res = chmod(path, (mode_t)i); |
Guido van Rossum | ffd15f5 | 2000-03-31 00:47:28 +0000 | [diff] [blame] | 702 | Py_END_ALLOW_THREADS |
| 703 | if (res < 0) |
| 704 | return posix_error_with_filename(path); |
| 705 | Py_INCREF(Py_None); |
| 706 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 709 | |
Guido van Rossum | 21142a0 | 1999-01-08 21:05:37 +0000 | [diff] [blame] | 710 | #ifdef HAVE_FSYNC |
| 711 | static char posix_fsync__doc__[] = |
| 712 | "fsync(fildes) -> None\n\ |
| 713 | force write of file with filedescriptor to disk."; |
| 714 | |
| 715 | static PyObject * |
| 716 | posix_fsync(self, args) |
| 717 | PyObject *self; |
| 718 | PyObject *args; |
| 719 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 720 | return posix_int(args, "i:fsync", fsync); |
Guido van Rossum | 21142a0 | 1999-01-08 21:05:37 +0000 | [diff] [blame] | 721 | } |
| 722 | #endif /* HAVE_FSYNC */ |
| 723 | |
| 724 | #ifdef HAVE_FDATASYNC |
| 725 | static char posix_fdatasync__doc__[] = |
| 726 | "fdatasync(fildes) -> None\n\ |
| 727 | force write of file with filedescriptor to disk.\n\ |
| 728 | does not force update of metadata."; |
| 729 | |
Guido van Rossum | 5d00b6d | 1999-01-08 21:28:05 +0000 | [diff] [blame] | 730 | extern int fdatasync(int); /* Prototype just in case */ |
| 731 | |
Guido van Rossum | 21142a0 | 1999-01-08 21:05:37 +0000 | [diff] [blame] | 732 | static PyObject * |
| 733 | posix_fdatasync(self, args) |
| 734 | PyObject *self; |
| 735 | PyObject *args; |
| 736 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 737 | return posix_int(args, "i:fdatasync", fdatasync); |
Guido van Rossum | 21142a0 | 1999-01-08 21:05:37 +0000 | [diff] [blame] | 738 | } |
| 739 | #endif /* HAVE_FDATASYNC */ |
| 740 | |
| 741 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 742 | #ifdef HAVE_CHOWN |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 743 | static char posix_chown__doc__[] = |
| 744 | "chown(path, uid, gid) -> None\n\ |
| 745 | Change the owner and group id of path to the numeric uid and gid."; |
| 746 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 747 | static PyObject * |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 748 | posix_chown(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 749 | PyObject *self; |
| 750 | PyObject *args; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 751 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 752 | return posix_strintint(args, "sii:chown", chown); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 753 | } |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 754 | #endif /* HAVE_CHOWN */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 755 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 756 | |
Guido van Rossum | 36bc680 | 1995-06-14 22:54:23 +0000 | [diff] [blame] | 757 | #ifdef HAVE_GETCWD |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 758 | static char posix_getcwd__doc__[] = |
| 759 | "getcwd() -> path\n\ |
| 760 | Return a string representing the current working directory."; |
| 761 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 762 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 763 | posix_getcwd(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 764 | PyObject *self; |
| 765 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 766 | { |
| 767 | char buf[1026]; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 768 | char *res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 769 | if (!PyArg_ParseTuple(args, ":getcwd")) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 770 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 771 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 772 | res = getcwd(buf, sizeof buf); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 773 | Py_END_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 774 | if (res == NULL) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 775 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 776 | return PyString_FromString(buf); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 777 | } |
Guido van Rossum | 36bc680 | 1995-06-14 22:54:23 +0000 | [diff] [blame] | 778 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 779 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 780 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 781 | #ifdef HAVE_LINK |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 782 | static char posix_link__doc__[] = |
| 783 | "link(src, dst) -> None\n\ |
| 784 | Create a hard link to a file."; |
| 785 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 786 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 787 | posix_link(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 788 | PyObject *self; |
| 789 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 790 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 791 | return posix_2str(args, "ss:link", link); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 792 | } |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 793 | #endif /* HAVE_LINK */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 794 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 795 | |
| 796 | static char posix_listdir__doc__[] = |
| 797 | "listdir(path) -> list_of_strings\n\ |
| 798 | Return a list containing the names of the entries in the directory.\n\ |
| 799 | \n\ |
| 800 | path: path of directory to list\n\ |
| 801 | \n\ |
| 802 | The list is in arbitrary order. It does not include the special\n\ |
| 803 | entries '.' and '..' even if they are present in the directory."; |
| 804 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 805 | static PyObject * |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 806 | posix_listdir(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 807 | PyObject *self; |
| 808 | PyObject *args; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 809 | { |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 810 | /* XXX Should redo this putting the (now four) versions of opendir |
Guido van Rossum | 6d8841c | 1997-08-14 19:57:39 +0000 | [diff] [blame] | 811 | in separate files instead of having them all here... */ |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 812 | #if defined(MS_WIN32) && !defined(HAVE_OPENDIR) |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 813 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 814 | char *name; |
| 815 | int len; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 816 | PyObject *d, *v; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 817 | HANDLE hFindFile; |
| 818 | WIN32_FIND_DATA FileData; |
| 819 | char namebuf[MAX_PATH+5]; |
| 820 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 821 | if (!PyArg_ParseTuple(args, "t#:listdir", &name, &len)) |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 822 | return NULL; |
| 823 | if (len >= MAX_PATH) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 824 | PyErr_SetString(PyExc_ValueError, "path too long"); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 825 | return NULL; |
| 826 | } |
| 827 | strcpy(namebuf, name); |
| 828 | if (namebuf[len-1] != '/' && namebuf[len-1] != '\\') |
| 829 | namebuf[len++] = '/'; |
| 830 | strcpy(namebuf + len, "*.*"); |
| 831 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 832 | if ((d = PyList_New(0)) == NULL) |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 833 | return NULL; |
| 834 | |
| 835 | hFindFile = FindFirstFile(namebuf, &FileData); |
| 836 | if (hFindFile == INVALID_HANDLE_VALUE) { |
| 837 | errno = GetLastError(); |
Guido van Rossum | 617bc19 | 1998-08-06 03:23:32 +0000 | [diff] [blame] | 838 | if (errno == ERROR_FILE_NOT_FOUND) |
| 839 | return PyList_New(0); |
Barry Warsaw | f63b8cc | 1999-05-27 23:13:21 +0000 | [diff] [blame] | 840 | return posix_error_with_filename(name); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 841 | } |
| 842 | do { |
Guido van Rossum | 24f42ac | 1995-07-18 18:16:52 +0000 | [diff] [blame] | 843 | if (FileData.cFileName[0] == '.' && |
| 844 | (FileData.cFileName[1] == '\0' || |
| 845 | FileData.cFileName[1] == '.' && |
| 846 | FileData.cFileName[2] == '\0')) |
| 847 | continue; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 848 | v = PyString_FromString(FileData.cFileName); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 849 | if (v == NULL) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 850 | Py_DECREF(d); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 851 | d = NULL; |
| 852 | break; |
| 853 | } |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 854 | if (PyList_Append(d, v) != 0) { |
| 855 | Py_DECREF(v); |
| 856 | Py_DECREF(d); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 857 | d = NULL; |
| 858 | break; |
| 859 | } |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 860 | Py_DECREF(v); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 861 | } while (FindNextFile(hFindFile, &FileData) == TRUE); |
| 862 | |
| 863 | if (FindClose(hFindFile) == FALSE) { |
| 864 | errno = GetLastError(); |
Barry Warsaw | f63b8cc | 1999-05-27 23:13:21 +0000 | [diff] [blame] | 865 | return posix_error_with_filename(&name); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | return d; |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 869 | |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 870 | #else /* !MS_WIN32 */ |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 871 | #ifdef _MSC_VER /* 16-bit Windows */ |
| 872 | |
| 873 | #ifndef MAX_PATH |
| 874 | #define MAX_PATH 250 |
| 875 | #endif |
| 876 | char *name, *pt; |
| 877 | int len; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 878 | PyObject *d, *v; |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 879 | char namebuf[MAX_PATH+5]; |
| 880 | struct _find_t ep; |
| 881 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 882 | if (!PyArg_ParseTuple(args, "t#:listdir", &name, &len)) |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 883 | return NULL; |
| 884 | if (len >= MAX_PATH) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 885 | PyErr_SetString(PyExc_ValueError, "path too long"); |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 886 | return NULL; |
| 887 | } |
| 888 | strcpy(namebuf, name); |
| 889 | for (pt = namebuf; *pt; pt++) |
| 890 | if (*pt == '/') |
| 891 | *pt = '\\'; |
| 892 | if (namebuf[len-1] != '\\') |
| 893 | namebuf[len++] = '\\'; |
| 894 | strcpy(namebuf + len, "*.*"); |
| 895 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 896 | if ((d = PyList_New(0)) == NULL) |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 897 | return NULL; |
| 898 | |
| 899 | if (_dos_findfirst(namebuf, _A_RDONLY | |
Barry Warsaw | 43d68b8 | 1996-12-19 22:10:44 +0000 | [diff] [blame] | 900 | _A_HIDDEN | _A_SYSTEM | _A_SUBDIR, &ep) != 0) |
| 901 | { |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 902 | errno = ENOENT; |
Barry Warsaw | f63b8cc | 1999-05-27 23:13:21 +0000 | [diff] [blame] | 903 | return posix_error_with_filename(name); |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 904 | } |
| 905 | do { |
| 906 | if (ep.name[0] == '.' && |
| 907 | (ep.name[1] == '\0' || |
| 908 | ep.name[1] == '.' && |
| 909 | ep.name[2] == '\0')) |
| 910 | continue; |
| 911 | strcpy(namebuf, ep.name); |
| 912 | for (pt = namebuf; *pt; pt++) |
| 913 | if (isupper(*pt)) |
| 914 | *pt = tolower(*pt); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 915 | v = PyString_FromString(namebuf); |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 916 | if (v == NULL) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 917 | Py_DECREF(d); |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 918 | d = NULL; |
| 919 | break; |
| 920 | } |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 921 | if (PyList_Append(d, v) != 0) { |
| 922 | Py_DECREF(v); |
| 923 | Py_DECREF(d); |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 924 | d = NULL; |
| 925 | break; |
| 926 | } |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 927 | Py_DECREF(v); |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 928 | } while (_dos_findnext(&ep) == 0); |
| 929 | |
| 930 | return d; |
| 931 | |
| 932 | #else |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 933 | #if defined(PYOS_OS2) |
| 934 | |
| 935 | #ifndef MAX_PATH |
| 936 | #define MAX_PATH CCHMAXPATH |
| 937 | #endif |
| 938 | char *name, *pt; |
| 939 | int len; |
| 940 | PyObject *d, *v; |
| 941 | char namebuf[MAX_PATH+5]; |
| 942 | HDIR hdir = 1; |
| 943 | ULONG srchcnt = 1; |
| 944 | FILEFINDBUF3 ep; |
| 945 | APIRET rc; |
| 946 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 947 | if (!PyArg_ParseTuple(args, "t#:listdir", &name, &len)) |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 948 | return NULL; |
| 949 | if (len >= MAX_PATH) { |
| 950 | PyErr_SetString(PyExc_ValueError, "path too long"); |
| 951 | return NULL; |
| 952 | } |
| 953 | strcpy(namebuf, name); |
| 954 | for (pt = namebuf; *pt; pt++) |
| 955 | if (*pt == '/') |
| 956 | *pt = '\\'; |
| 957 | if (namebuf[len-1] != '\\') |
| 958 | namebuf[len++] = '\\'; |
| 959 | strcpy(namebuf + len, "*.*"); |
| 960 | |
| 961 | if ((d = PyList_New(0)) == NULL) |
| 962 | return NULL; |
| 963 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 964 | rc = DosFindFirst(namebuf, /* Wildcard Pattern to Match */ |
| 965 | &hdir, /* Handle to Use While Search Directory */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 966 | FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY, |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 967 | &ep, sizeof(ep), /* Structure to Receive Directory Entry */ |
| 968 | &srchcnt, /* Max and Actual Count of Entries Per Iteration */ |
| 969 | FIL_STANDARD); /* Format of Entry (EAs or Not) */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 970 | |
| 971 | if (rc != NO_ERROR) { |
| 972 | errno = ENOENT; |
Barry Warsaw | f63b8cc | 1999-05-27 23:13:21 +0000 | [diff] [blame] | 973 | return posix_error_with_filename(name); |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 976 | if (srchcnt > 0) { /* If Directory is NOT Totally Empty, */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 977 | do { |
| 978 | if (ep.achName[0] == '.' |
| 979 | && (ep.achName[1] == '\0' || ep.achName[1] == '.' && ep.achName[2] == '\0')) |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 980 | continue; /* Skip Over "." and ".." Names */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 981 | |
| 982 | strcpy(namebuf, ep.achName); |
| 983 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 984 | /* Leave Case of Name Alone -- In Native Form */ |
| 985 | /* (Removed Forced Lowercasing Code) */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 986 | |
| 987 | v = PyString_FromString(namebuf); |
| 988 | if (v == NULL) { |
| 989 | Py_DECREF(d); |
| 990 | d = NULL; |
| 991 | break; |
| 992 | } |
| 993 | if (PyList_Append(d, v) != 0) { |
| 994 | Py_DECREF(v); |
| 995 | Py_DECREF(d); |
| 996 | d = NULL; |
| 997 | break; |
| 998 | } |
| 999 | Py_DECREF(v); |
| 1000 | } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && srchcnt > 0); |
| 1001 | } |
| 1002 | |
| 1003 | return d; |
| 1004 | #else |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 1005 | |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 1006 | char *name; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1007 | PyObject *d, *v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1008 | DIR *dirp; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1009 | struct dirent *ep; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1010 | if (!PyArg_ParseTuple(args, "s:listdir", &name)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1011 | return NULL; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 1012 | if ((dirp = opendir(name)) == NULL) { |
Barry Warsaw | f63b8cc | 1999-05-27 23:13:21 +0000 | [diff] [blame] | 1013 | return posix_error_with_filename(name); |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 1014 | } |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1015 | if ((d = PyList_New(0)) == NULL) { |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1016 | closedir(dirp); |
| 1017 | return NULL; |
| 1018 | } |
| 1019 | while ((ep = readdir(dirp)) != NULL) { |
Guido van Rossum | 24f42ac | 1995-07-18 18:16:52 +0000 | [diff] [blame] | 1020 | if (ep->d_name[0] == '.' && |
| 1021 | (NAMLEN(ep) == 1 || |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 1022 | (ep->d_name[1] == '.' && NAMLEN(ep) == 2))) |
Guido van Rossum | 24f42ac | 1995-07-18 18:16:52 +0000 | [diff] [blame] | 1023 | continue; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1024 | v = PyString_FromStringAndSize(ep->d_name, NAMLEN(ep)); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1025 | if (v == NULL) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1026 | Py_DECREF(d); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1027 | d = NULL; |
| 1028 | break; |
| 1029 | } |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1030 | if (PyList_Append(d, v) != 0) { |
| 1031 | Py_DECREF(v); |
| 1032 | Py_DECREF(d); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1033 | d = NULL; |
| 1034 | break; |
| 1035 | } |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1036 | Py_DECREF(v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1037 | } |
| 1038 | closedir(dirp); |
Guido van Rossum | 0ee42cd | 1991-04-08 21:01:03 +0000 | [diff] [blame] | 1039 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1040 | return d; |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 1041 | |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1042 | #endif /* !PYOS_OS2 */ |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 1043 | #endif /* !_MSC_VER */ |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 1044 | #endif /* !MS_WIN32 */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1047 | static char posix_mkdir__doc__[] = |
| 1048 | "mkdir(path [, mode=0777]) -> None\n\ |
| 1049 | Create a directory."; |
| 1050 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1051 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1052 | posix_mkdir(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1053 | PyObject *self; |
| 1054 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1055 | { |
Guido van Rossum | b0824db | 1996-02-25 04:50:32 +0000 | [diff] [blame] | 1056 | int res; |
| 1057 | char *path; |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 1058 | int mode = 0777; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1059 | if (!PyArg_ParseTuple(args, "s|i:mkdir", &path, &mode)) |
Guido van Rossum | b0824db | 1996-02-25 04:50:32 +0000 | [diff] [blame] | 1060 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1061 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 1062 | #if ( defined(__WATCOMC__) || defined(_MSC_VER) || defined(PYCC_VACPP) ) && !defined(__QNX__) |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 1063 | res = mkdir(path); |
| 1064 | #else |
Guido van Rossum | b0824db | 1996-02-25 04:50:32 +0000 | [diff] [blame] | 1065 | res = mkdir(path, mode); |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 1066 | #endif |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1067 | Py_END_ALLOW_THREADS |
Guido van Rossum | b0824db | 1996-02-25 04:50:32 +0000 | [diff] [blame] | 1068 | if (res < 0) |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 1069 | return posix_error_with_filename(path); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1070 | Py_INCREF(Py_None); |
| 1071 | return Py_None; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1074 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1075 | #ifdef HAVE_NICE |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1076 | static char posix_nice__doc__[] = |
| 1077 | "nice(inc) -> new_priority\n\ |
| 1078 | Decrease the priority of process and return new priority."; |
| 1079 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1080 | static PyObject * |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 1081 | posix_nice(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1082 | PyObject *self; |
| 1083 | PyObject *args; |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 1084 | { |
| 1085 | int increment, value; |
| 1086 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1087 | if (!PyArg_ParseTuple(args, "i:nice", &increment)) |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 1088 | return NULL; |
| 1089 | value = nice(increment); |
| 1090 | if (value == -1) |
| 1091 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1092 | return PyInt_FromLong((long) value); |
Guido van Rossum | 775f4da | 1993-01-09 17:18:52 +0000 | [diff] [blame] | 1093 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1094 | #endif /* HAVE_NICE */ |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 1095 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1096 | |
| 1097 | static char posix_rename__doc__[] = |
| 1098 | "rename(old, new) -> None\n\ |
| 1099 | Rename a file or directory."; |
| 1100 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1101 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1102 | posix_rename(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1103 | PyObject *self; |
| 1104 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1105 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1106 | return posix_2str(args, "ss:rename", rename); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1109 | |
| 1110 | static char posix_rmdir__doc__[] = |
| 1111 | "rmdir(path) -> None\n\ |
| 1112 | Remove a directory."; |
| 1113 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1114 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1115 | posix_rmdir(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1116 | PyObject *self; |
| 1117 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1118 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1119 | return posix_1str(args, "s:rmdir", rmdir); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1122 | |
| 1123 | static char posix_stat__doc__[] = |
| 1124 | "stat(path) -> (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\ |
| 1125 | Perform a stat system call on the given path."; |
| 1126 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1127 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1128 | posix_stat(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1129 | PyObject *self; |
| 1130 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1131 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1132 | return posix_do_stat(self, args, "s:stat", stat); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1135 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 1136 | #ifdef HAVE_SYSTEM |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1137 | static char posix_system__doc__[] = |
| 1138 | "system(command) -> exit_status\n\ |
| 1139 | Execute the command (a string) in a subshell."; |
| 1140 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1141 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1142 | posix_system(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1143 | PyObject *self; |
| 1144 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1145 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 1146 | char *command; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 1147 | long sts; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1148 | if (!PyArg_ParseTuple(args, "s:system", &command)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1149 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1150 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 1151 | sts = system(command); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1152 | Py_END_ALLOW_THREADS |
| 1153 | return PyInt_FromLong(sts); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1154 | } |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 1155 | #endif |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1156 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1157 | |
| 1158 | static char posix_umask__doc__[] = |
| 1159 | "umask(new_mask) -> old_mask\n\ |
| 1160 | Set the current numeric umask and return the previous umask."; |
| 1161 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1162 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1163 | posix_umask(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1164 | PyObject *self; |
| 1165 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1166 | { |
| 1167 | int i; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1168 | if (!PyArg_ParseTuple(args, "i:umask", &i)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1169 | return NULL; |
| 1170 | i = umask(i); |
| 1171 | if (i < 0) |
| 1172 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1173 | return PyInt_FromLong((long)i); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1176 | |
| 1177 | static char posix_unlink__doc__[] = |
| 1178 | "unlink(path) -> None\n\ |
| 1179 | Remove a file (same as remove(path))."; |
| 1180 | |
| 1181 | static char posix_remove__doc__[] = |
| 1182 | "remove(path) -> None\n\ |
| 1183 | Remove a file (same as unlink(path))."; |
| 1184 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1185 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1186 | posix_unlink(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1187 | PyObject *self; |
| 1188 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1189 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1190 | return posix_1str(args, "s:remove", unlink); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1193 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1194 | #ifdef HAVE_UNAME |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1195 | static char posix_uname__doc__[] = |
| 1196 | "uname() -> (sysname, nodename, release, version, machine)\n\ |
| 1197 | Return a tuple identifying the current operating system."; |
| 1198 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1199 | static PyObject * |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1200 | posix_uname(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1201 | PyObject *self; |
| 1202 | PyObject *args; |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1203 | { |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1204 | struct utsname u; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 1205 | int res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1206 | if (!PyArg_ParseTuple(args, ":uname")) |
Guido van Rossum | 50e61dc | 1992-03-27 17:22:31 +0000 | [diff] [blame] | 1207 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1208 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 1209 | res = uname(&u); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1210 | Py_END_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 1211 | if (res < 0) |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1212 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1213 | return Py_BuildValue("(sssss)", |
Barry Warsaw | 43d68b8 | 1996-12-19 22:10:44 +0000 | [diff] [blame] | 1214 | u.sysname, |
| 1215 | u.nodename, |
| 1216 | u.release, |
| 1217 | u.version, |
| 1218 | u.machine); |
Guido van Rossum | c39de5f | 1992-02-05 11:15:54 +0000 | [diff] [blame] | 1219 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1220 | #endif /* HAVE_UNAME */ |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 1221 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1222 | |
| 1223 | static char posix_utime__doc__[] = |
| 1224 | "utime(path, (atime, utime)) -> None\n\ |
| 1225 | Set the access and modified time of the file to the given values."; |
| 1226 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1227 | static PyObject * |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 1228 | posix_utime(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1229 | PyObject *self; |
| 1230 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1231 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 1232 | char *path; |
Guido van Rossum | f8803dd | 1995-01-26 00:37:45 +0000 | [diff] [blame] | 1233 | long atime, mtime; |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 1234 | int res; |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 1235 | |
Guido van Rossum | 6d8841c | 1997-08-14 19:57:39 +0000 | [diff] [blame] | 1236 | /* XXX should define struct utimbuf instead, above */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1237 | #ifdef HAVE_UTIME_H |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 1238 | struct utimbuf buf; |
| 1239 | #define ATIME buf.actime |
| 1240 | #define MTIME buf.modtime |
| 1241 | #define UTIME_ARG &buf |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 1242 | #else /* HAVE_UTIME_H */ |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 1243 | time_t buf[2]; |
| 1244 | #define ATIME buf[0] |
| 1245 | #define MTIME buf[1] |
| 1246 | #define UTIME_ARG buf |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 1247 | #endif /* HAVE_UTIME_H */ |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 1248 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1249 | if (!PyArg_ParseTuple(args, "s(ll):utime", &path, &atime, &mtime)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1250 | return NULL; |
Guido van Rossum | f8803dd | 1995-01-26 00:37:45 +0000 | [diff] [blame] | 1251 | ATIME = atime; |
Guido van Rossum | d1b3481 | 1995-02-07 15:39:29 +0000 | [diff] [blame] | 1252 | MTIME = mtime; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1253 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 1254 | res = utime(path, UTIME_ARG); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1255 | Py_END_ALLOW_THREADS |
Guido van Rossum | ff4949e | 1992-08-05 19:58:53 +0000 | [diff] [blame] | 1256 | if (res < 0) |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 1257 | return posix_error_with_filename(path); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1258 | Py_INCREF(Py_None); |
| 1259 | return Py_None; |
Guido van Rossum | 1ff6cb4 | 1991-04-08 20:59:13 +0000 | [diff] [blame] | 1260 | #undef UTIME_ARG |
| 1261 | #undef ATIME |
| 1262 | #undef MTIME |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1265 | |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 1266 | /* Process operations */ |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1267 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1268 | static char posix__exit__doc__[] = |
| 1269 | "_exit(status)\n\ |
| 1270 | Exit to the system with specified status, without normal exit processing."; |
| 1271 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1272 | static PyObject * |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1273 | posix__exit(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1274 | PyObject *self; |
| 1275 | PyObject *args; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1276 | { |
| 1277 | int sts; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1278 | if (!PyArg_ParseTuple(args, "i:_exit", &sts)) |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1279 | return NULL; |
| 1280 | _exit(sts); |
Guido van Rossum | a376cc5 | 1996-12-05 23:43:35 +0000 | [diff] [blame] | 1281 | return NULL; /* Make gcc -Wall happy */ |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1284 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 1285 | #ifdef HAVE_EXECV |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1286 | static char posix_execv__doc__[] = |
| 1287 | "execv(path, args)\n\ |
| 1288 | Execute an executable path with arguments, replacing current process.\n\ |
| 1289 | \n\ |
| 1290 | path: path of executable file\n\ |
| 1291 | args: tuple or list of strings"; |
| 1292 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1293 | static PyObject * |
Guido van Rossum | 89b3325 | 1993-10-22 14:26:06 +0000 | [diff] [blame] | 1294 | posix_execv(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1295 | PyObject *self; |
| 1296 | PyObject *args; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1297 | { |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 1298 | char *path; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1299 | PyObject *argv; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1300 | char **argvlist; |
| 1301 | int i, argc; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1302 | PyObject *(*getitem) Py_PROTO((PyObject *, int)); |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1303 | |
Guido van Rossum | 89b3325 | 1993-10-22 14:26:06 +0000 | [diff] [blame] | 1304 | /* execv has two arguments: (path, argv), where |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1305 | argv is a list or tuple of strings. */ |
| 1306 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1307 | if (!PyArg_ParseTuple(args, "sO:execv", &path, &argv)) |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1308 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1309 | if (PyList_Check(argv)) { |
| 1310 | argc = PyList_Size(argv); |
| 1311 | getitem = PyList_GetItem; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1312 | } |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1313 | else if (PyTuple_Check(argv)) { |
| 1314 | argc = PyTuple_Size(argv); |
| 1315 | getitem = PyTuple_GetItem; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1316 | } |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 1317 | else { |
| 1318 | badarg: |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1319 | PyErr_BadArgument(); |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 1320 | return NULL; |
| 1321 | } |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1322 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1323 | argvlist = PyMem_NEW(char *, argc+1); |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1324 | if (argvlist == NULL) |
| 1325 | return NULL; |
| 1326 | for (i = 0; i < argc; i++) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1327 | if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) { |
| 1328 | PyMem_DEL(argvlist); |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1329 | goto badarg; |
| 1330 | } |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1331 | } |
| 1332 | argvlist[argc] = NULL; |
| 1333 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1334 | #ifdef BAD_EXEC_PROTOTYPES |
| 1335 | execv(path, (const char **) argvlist); |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 1336 | #else /* BAD_EXEC_PROTOTYPES */ |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 1337 | execv(path, argvlist); |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 1338 | #endif /* BAD_EXEC_PROTOTYPES */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1339 | |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1340 | /* If we get here it's definitely an error */ |
| 1341 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1342 | PyMem_DEL(argvlist); |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1343 | return posix_error(); |
| 1344 | } |
| 1345 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1346 | |
| 1347 | static char posix_execve__doc__[] = |
| 1348 | "execve(path, args, env)\n\ |
| 1349 | Execute a path with arguments and environment, replacing current process.\n\ |
| 1350 | \n\ |
| 1351 | path: path of executable file\n\ |
| 1352 | args: tuple or list of arguments\n\ |
| 1353 | env: dictonary of strings mapping to strings"; |
| 1354 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1355 | static PyObject * |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1356 | posix_execve(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1357 | PyObject *self; |
| 1358 | PyObject *args; |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1359 | { |
| 1360 | char *path; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1361 | PyObject *argv, *env; |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1362 | char **argvlist; |
| 1363 | char **envlist; |
Barry Warsaw | 5ed19dc | 1997-01-29 15:08:24 +0000 | [diff] [blame] | 1364 | PyObject *key, *val, *keys=NULL, *vals=NULL; |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1365 | int i, pos, argc, envc; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1366 | PyObject *(*getitem) Py_PROTO((PyObject *, int)); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1367 | |
| 1368 | /* execve has three arguments: (path, argv, env), where |
| 1369 | argv is a list or tuple of strings and env is a dictionary |
| 1370 | like posix.environ. */ |
| 1371 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1372 | if (!PyArg_ParseTuple(args, "sOO:execve", &path, &argv, &env)) |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1373 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1374 | if (PyList_Check(argv)) { |
| 1375 | argc = PyList_Size(argv); |
| 1376 | getitem = PyList_GetItem; |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1377 | } |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1378 | else if (PyTuple_Check(argv)) { |
| 1379 | argc = PyTuple_Size(argv); |
| 1380 | getitem = PyTuple_GetItem; |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1381 | } |
| 1382 | else { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1383 | PyErr_SetString(PyExc_TypeError, "argv must be tuple or list"); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1384 | return NULL; |
| 1385 | } |
Barry Warsaw | 5ed19dc | 1997-01-29 15:08:24 +0000 | [diff] [blame] | 1386 | if (!PyMapping_Check(env)) { |
| 1387 | PyErr_SetString(PyExc_TypeError, "env must be mapping object"); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1388 | return NULL; |
| 1389 | } |
| 1390 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1391 | argvlist = PyMem_NEW(char *, argc+1); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1392 | if (argvlist == NULL) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1393 | PyErr_NoMemory(); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1394 | return NULL; |
| 1395 | } |
| 1396 | for (i = 0; i < argc; i++) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1397 | if (!PyArg_Parse((*getitem)(argv, i), |
Barry Warsaw | 43d68b8 | 1996-12-19 22:10:44 +0000 | [diff] [blame] | 1398 | "s;argv must be list of strings", |
| 1399 | &argvlist[i])) |
| 1400 | { |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1401 | goto fail_1; |
| 1402 | } |
| 1403 | } |
| 1404 | argvlist[argc] = NULL; |
| 1405 | |
Barry Warsaw | 5ed19dc | 1997-01-29 15:08:24 +0000 | [diff] [blame] | 1406 | i = PyMapping_Length(env); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1407 | envlist = PyMem_NEW(char *, i + 1); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1408 | if (envlist == NULL) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1409 | PyErr_NoMemory(); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1410 | goto fail_1; |
| 1411 | } |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1412 | envc = 0; |
Barry Warsaw | 5ed19dc | 1997-01-29 15:08:24 +0000 | [diff] [blame] | 1413 | keys = PyMapping_Keys(env); |
| 1414 | vals = PyMapping_Values(env); |
| 1415 | if (!keys || !vals) |
| 1416 | goto fail_2; |
| 1417 | |
| 1418 | for (pos = 0; pos < i; pos++) { |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1419 | char *p, *k, *v; |
Barry Warsaw | 5ed19dc | 1997-01-29 15:08:24 +0000 | [diff] [blame] | 1420 | |
| 1421 | key = PyList_GetItem(keys, pos); |
| 1422 | val = PyList_GetItem(vals, pos); |
| 1423 | if (!key || !val) |
| 1424 | goto fail_2; |
| 1425 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1426 | if (!PyArg_Parse(key, "s;non-string key in env", &k) || |
Barry Warsaw | 43d68b8 | 1996-12-19 22:10:44 +0000 | [diff] [blame] | 1427 | !PyArg_Parse(val, "s;non-string value in env", &v)) |
| 1428 | { |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1429 | goto fail_2; |
| 1430 | } |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 1431 | |
| 1432 | #if defined(PYOS_OS2) |
| 1433 | /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */ |
| 1434 | if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) { |
| 1435 | #endif |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1436 | p = PyMem_NEW(char, PyString_Size(key)+PyString_Size(val) + 2); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1437 | if (p == NULL) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1438 | PyErr_NoMemory(); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1439 | goto fail_2; |
| 1440 | } |
| 1441 | sprintf(p, "%s=%s", k, v); |
| 1442 | envlist[envc++] = p; |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 1443 | #if defined(PYOS_OS2) |
| 1444 | } |
| 1445 | #endif |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1446 | } |
| 1447 | envlist[envc] = 0; |
| 1448 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1449 | |
| 1450 | #ifdef BAD_EXEC_PROTOTYPES |
| 1451 | execve(path, (const char **)argvlist, envlist); |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 1452 | #else /* BAD_EXEC_PROTOTYPES */ |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1453 | execve(path, argvlist, envlist); |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 1454 | #endif /* BAD_EXEC_PROTOTYPES */ |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1455 | |
| 1456 | /* If we get here it's definitely an error */ |
| 1457 | |
| 1458 | (void) posix_error(); |
| 1459 | |
| 1460 | fail_2: |
| 1461 | while (--envc >= 0) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1462 | PyMem_DEL(envlist[envc]); |
| 1463 | PyMem_DEL(envlist); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1464 | fail_1: |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1465 | PyMem_DEL(argvlist); |
Barry Warsaw | 5ed19dc | 1997-01-29 15:08:24 +0000 | [diff] [blame] | 1466 | Py_XDECREF(vals); |
| 1467 | Py_XDECREF(keys); |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1468 | return NULL; |
| 1469 | } |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 1470 | #endif /* HAVE_EXECV */ |
Guido van Rossum | c6dcc9f | 1993-11-05 10:15:19 +0000 | [diff] [blame] | 1471 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1472 | |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 1473 | #ifdef HAVE_SPAWNV |
| 1474 | static char posix_spawnv__doc__[] = |
Fred Drake | a6dff3e | 1999-02-01 22:24:40 +0000 | [diff] [blame] | 1475 | "spawnv(mode, path, args)\n\ |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 1476 | Execute an executable path with arguments, replacing current process.\n\ |
| 1477 | \n\ |
Fred Drake | a6dff3e | 1999-02-01 22:24:40 +0000 | [diff] [blame] | 1478 | mode: mode of process creation\n\ |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 1479 | path: path of executable file\n\ |
| 1480 | args: tuple or list of strings"; |
| 1481 | |
| 1482 | static PyObject * |
| 1483 | posix_spawnv(self, args) |
| 1484 | PyObject *self; |
| 1485 | PyObject *args; |
| 1486 | { |
| 1487 | char *path; |
| 1488 | PyObject *argv; |
| 1489 | char **argvlist; |
| 1490 | int mode, i, argc; |
| 1491 | PyObject *(*getitem) Py_PROTO((PyObject *, int)); |
| 1492 | |
| 1493 | /* spawnv has three arguments: (mode, path, argv), where |
| 1494 | argv is a list or tuple of strings. */ |
| 1495 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1496 | if (!PyArg_ParseTuple(args, "isO:spawnv", &mode, &path, &argv)) |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 1497 | return NULL; |
| 1498 | if (PyList_Check(argv)) { |
| 1499 | argc = PyList_Size(argv); |
| 1500 | getitem = PyList_GetItem; |
| 1501 | } |
| 1502 | else if (PyTuple_Check(argv)) { |
| 1503 | argc = PyTuple_Size(argv); |
| 1504 | getitem = PyTuple_GetItem; |
| 1505 | } |
| 1506 | else { |
| 1507 | badarg: |
| 1508 | PyErr_BadArgument(); |
| 1509 | return NULL; |
| 1510 | } |
| 1511 | |
| 1512 | argvlist = PyMem_NEW(char *, argc+1); |
| 1513 | if (argvlist == NULL) |
| 1514 | return NULL; |
| 1515 | for (i = 0; i < argc; i++) { |
| 1516 | if (!PyArg_Parse((*getitem)(argv, i), "s", &argvlist[i])) { |
| 1517 | PyMem_DEL(argvlist); |
| 1518 | goto badarg; |
| 1519 | } |
| 1520 | } |
| 1521 | argvlist[argc] = NULL; |
| 1522 | |
Guido van Rossum | 246bc17 | 1999-02-01 23:54:31 +0000 | [diff] [blame] | 1523 | if (mode == _OLD_P_OVERLAY) |
| 1524 | mode = _P_OVERLAY; |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 1525 | i = _spawnv(mode, path, argvlist); |
| 1526 | |
| 1527 | PyMem_DEL(argvlist); |
| 1528 | |
| 1529 | if (i == -1) |
| 1530 | return posix_error(); |
| 1531 | else |
| 1532 | return Py_BuildValue("i", i); |
| 1533 | } |
| 1534 | |
| 1535 | |
| 1536 | static char posix_spawnve__doc__[] = |
Fred Drake | a6dff3e | 1999-02-01 22:24:40 +0000 | [diff] [blame] | 1537 | "spawnve(mode, path, args, env)\n\ |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 1538 | Execute a path with arguments and environment, replacing current process.\n\ |
| 1539 | \n\ |
Fred Drake | a6dff3e | 1999-02-01 22:24:40 +0000 | [diff] [blame] | 1540 | mode: mode of process creation\n\ |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 1541 | path: path of executable file\n\ |
| 1542 | args: tuple or list of arguments\n\ |
| 1543 | env: dictonary of strings mapping to strings"; |
| 1544 | |
| 1545 | static PyObject * |
| 1546 | posix_spawnve(self, args) |
| 1547 | PyObject *self; |
| 1548 | PyObject *args; |
| 1549 | { |
| 1550 | char *path; |
| 1551 | PyObject *argv, *env; |
| 1552 | char **argvlist; |
| 1553 | char **envlist; |
| 1554 | PyObject *key, *val, *keys=NULL, *vals=NULL, *res=NULL; |
| 1555 | int mode, i, pos, argc, envc; |
| 1556 | PyObject *(*getitem) Py_PROTO((PyObject *, int)); |
| 1557 | |
| 1558 | /* spawnve has four arguments: (mode, path, argv, env), where |
| 1559 | argv is a list or tuple of strings and env is a dictionary |
| 1560 | like posix.environ. */ |
| 1561 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1562 | if (!PyArg_ParseTuple(args, "isOO:spawnve", &mode, &path, &argv, &env)) |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 1563 | return NULL; |
| 1564 | if (PyList_Check(argv)) { |
| 1565 | argc = PyList_Size(argv); |
| 1566 | getitem = PyList_GetItem; |
| 1567 | } |
| 1568 | else if (PyTuple_Check(argv)) { |
| 1569 | argc = PyTuple_Size(argv); |
| 1570 | getitem = PyTuple_GetItem; |
| 1571 | } |
| 1572 | else { |
| 1573 | PyErr_SetString(PyExc_TypeError, "argv must be tuple or list"); |
| 1574 | return NULL; |
| 1575 | } |
| 1576 | if (!PyMapping_Check(env)) { |
| 1577 | PyErr_SetString(PyExc_TypeError, "env must be mapping object"); |
| 1578 | return NULL; |
| 1579 | } |
| 1580 | |
| 1581 | argvlist = PyMem_NEW(char *, argc+1); |
| 1582 | if (argvlist == NULL) { |
| 1583 | PyErr_NoMemory(); |
| 1584 | return NULL; |
| 1585 | } |
| 1586 | for (i = 0; i < argc; i++) { |
| 1587 | if (!PyArg_Parse((*getitem)(argv, i), |
| 1588 | "s;argv must be list of strings", |
| 1589 | &argvlist[i])) |
| 1590 | { |
| 1591 | goto fail_1; |
| 1592 | } |
| 1593 | } |
| 1594 | argvlist[argc] = NULL; |
| 1595 | |
| 1596 | i = PyMapping_Length(env); |
| 1597 | envlist = PyMem_NEW(char *, i + 1); |
| 1598 | if (envlist == NULL) { |
| 1599 | PyErr_NoMemory(); |
| 1600 | goto fail_1; |
| 1601 | } |
| 1602 | envc = 0; |
| 1603 | keys = PyMapping_Keys(env); |
| 1604 | vals = PyMapping_Values(env); |
| 1605 | if (!keys || !vals) |
| 1606 | goto fail_2; |
| 1607 | |
| 1608 | for (pos = 0; pos < i; pos++) { |
| 1609 | char *p, *k, *v; |
| 1610 | |
| 1611 | key = PyList_GetItem(keys, pos); |
| 1612 | val = PyList_GetItem(vals, pos); |
| 1613 | if (!key || !val) |
| 1614 | goto fail_2; |
| 1615 | |
| 1616 | if (!PyArg_Parse(key, "s;non-string key in env", &k) || |
| 1617 | !PyArg_Parse(val, "s;non-string value in env", &v)) |
| 1618 | { |
| 1619 | goto fail_2; |
| 1620 | } |
| 1621 | p = PyMem_NEW(char, PyString_Size(key)+PyString_Size(val) + 2); |
| 1622 | if (p == NULL) { |
| 1623 | PyErr_NoMemory(); |
| 1624 | goto fail_2; |
| 1625 | } |
| 1626 | sprintf(p, "%s=%s", k, v); |
| 1627 | envlist[envc++] = p; |
| 1628 | } |
| 1629 | envlist[envc] = 0; |
| 1630 | |
Guido van Rossum | 246bc17 | 1999-02-01 23:54:31 +0000 | [diff] [blame] | 1631 | if (mode == _OLD_P_OVERLAY) |
| 1632 | mode = _P_OVERLAY; |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 1633 | i = _spawnve(mode, path, argvlist, envlist); |
| 1634 | if (i == -1) |
| 1635 | (void) posix_error(); |
| 1636 | else |
| 1637 | res = Py_BuildValue("i", i); |
| 1638 | |
| 1639 | fail_2: |
| 1640 | while (--envc >= 0) |
| 1641 | PyMem_DEL(envlist[envc]); |
| 1642 | PyMem_DEL(envlist); |
| 1643 | fail_1: |
| 1644 | PyMem_DEL(argvlist); |
| 1645 | Py_XDECREF(vals); |
| 1646 | Py_XDECREF(keys); |
| 1647 | return res; |
| 1648 | } |
| 1649 | #endif /* HAVE_SPAWNV */ |
| 1650 | |
| 1651 | |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1652 | #ifdef HAVE_FORK |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1653 | static char posix_fork__doc__[] = |
| 1654 | "fork() -> pid\n\ |
| 1655 | Fork a child process.\n\ |
| 1656 | \n\ |
| 1657 | Return 0 to child process and PID of child to parent process."; |
| 1658 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1659 | static PyObject * |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1660 | posix_fork(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1661 | PyObject *self; |
| 1662 | PyObject *args; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1663 | { |
| 1664 | int pid; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1665 | if (!PyArg_ParseTuple(args, ":fork")) |
Guido van Rossum | 50e61dc | 1992-03-27 17:22:31 +0000 | [diff] [blame] | 1666 | return NULL; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1667 | pid = fork(); |
| 1668 | if (pid == -1) |
| 1669 | return posix_error(); |
Guido van Rossum | 359bcaa | 1997-11-14 22:24:28 +0000 | [diff] [blame] | 1670 | PyOS_AfterFork(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1671 | return PyInt_FromLong((long)pid); |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1672 | } |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1673 | #endif |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1674 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1675 | |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1676 | #ifdef HAVE_GETEGID |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1677 | static char posix_getegid__doc__[] = |
| 1678 | "getegid() -> egid\n\ |
| 1679 | Return the current process's effective group id."; |
| 1680 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1681 | static PyObject * |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1682 | posix_getegid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1683 | PyObject *self; |
| 1684 | PyObject *args; |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1685 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1686 | if (!PyArg_ParseTuple(args, ":getegid")) |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1687 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1688 | return PyInt_FromLong((long)getegid()); |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1689 | } |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1690 | #endif |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1691 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1692 | |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1693 | #ifdef HAVE_GETEUID |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1694 | static char posix_geteuid__doc__[] = |
| 1695 | "geteuid() -> euid\n\ |
| 1696 | Return the current process's effective user id."; |
| 1697 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1698 | static PyObject * |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1699 | posix_geteuid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1700 | PyObject *self; |
| 1701 | PyObject *args; |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1702 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1703 | if (!PyArg_ParseTuple(args, ":geteuid")) |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1704 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1705 | return PyInt_FromLong((long)geteuid()); |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1706 | } |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1707 | #endif |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1708 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1709 | |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1710 | #ifdef HAVE_GETGID |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1711 | static char posix_getgid__doc__[] = |
| 1712 | "getgid() -> gid\n\ |
| 1713 | Return the current process's group id."; |
| 1714 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1715 | static PyObject * |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1716 | posix_getgid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1717 | PyObject *self; |
| 1718 | PyObject *args; |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1719 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1720 | if (!PyArg_ParseTuple(args, ":getgid")) |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1721 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1722 | return PyInt_FromLong((long)getgid()); |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1723 | } |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1724 | #endif |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1725 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1726 | |
| 1727 | static char posix_getpid__doc__[] = |
| 1728 | "getpid() -> pid\n\ |
| 1729 | Return the current process id"; |
| 1730 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1731 | static PyObject * |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1732 | posix_getpid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1733 | PyObject *self; |
| 1734 | PyObject *args; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1735 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1736 | if (!PyArg_ParseTuple(args, ":getpid")) |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1737 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1738 | return PyInt_FromLong((long)getpid()); |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1741 | |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 1742 | #ifdef HAVE_GETGROUPS |
| 1743 | static char posix_getgroups__doc__[] = "\ |
| 1744 | getgroups() -> list of group IDs\n\ |
| 1745 | Return list of supplemental group IDs for the process."; |
| 1746 | |
| 1747 | static PyObject * |
| 1748 | posix_getgroups(self, args) |
| 1749 | PyObject *self; |
| 1750 | PyObject *args; |
| 1751 | { |
| 1752 | PyObject *result = NULL; |
| 1753 | |
| 1754 | if (PyArg_ParseTuple(args, ":getgroups")) { |
| 1755 | #ifdef NGROUPS_MAX |
| 1756 | #define MAX_GROUPS NGROUPS_MAX |
| 1757 | #else |
| 1758 | /* defined to be 16 on Solaris7, so this should be a small number */ |
| 1759 | #define MAX_GROUPS 64 |
| 1760 | #endif |
| 1761 | gid_t grouplist[MAX_GROUPS]; |
| 1762 | int n; |
| 1763 | |
| 1764 | n = getgroups(MAX_GROUPS, grouplist); |
| 1765 | if (n < 0) |
| 1766 | posix_error(); |
| 1767 | else { |
| 1768 | result = PyList_New(n); |
| 1769 | if (result != NULL) { |
| 1770 | PyObject *o; |
| 1771 | int i; |
| 1772 | for (i = 0; i < n; ++i) { |
| 1773 | o = PyInt_FromLong((long)grouplist[i]); |
| 1774 | if (o == NULL) { |
| 1775 | Py_DECREF(result); |
| 1776 | result = NULL; |
| 1777 | break; |
| 1778 | } |
| 1779 | PyList_SET_ITEM(result, i, o); |
| 1780 | } |
| 1781 | } |
| 1782 | } |
| 1783 | } |
| 1784 | return result; |
| 1785 | } |
| 1786 | #endif |
| 1787 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1788 | #ifdef HAVE_GETPGRP |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1789 | static char posix_getpgrp__doc__[] = |
| 1790 | "getpgrp() -> pgrp\n\ |
| 1791 | Return the current process group id."; |
| 1792 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1793 | static PyObject * |
Guido van Rossum | 0481447 | 1991-06-04 20:23:49 +0000 | [diff] [blame] | 1794 | posix_getpgrp(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1795 | PyObject *self; |
| 1796 | PyObject *args; |
Guido van Rossum | 0481447 | 1991-06-04 20:23:49 +0000 | [diff] [blame] | 1797 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1798 | if (!PyArg_ParseTuple(args, ":getpgrp")) |
Guido van Rossum | 0481447 | 1991-06-04 20:23:49 +0000 | [diff] [blame] | 1799 | return NULL; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1800 | #ifdef GETPGRP_HAVE_ARG |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1801 | return PyInt_FromLong((long)getpgrp(0)); |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 1802 | #else /* GETPGRP_HAVE_ARG */ |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1803 | return PyInt_FromLong((long)getpgrp()); |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 1804 | #endif /* GETPGRP_HAVE_ARG */ |
Guido van Rossum | 0481447 | 1991-06-04 20:23:49 +0000 | [diff] [blame] | 1805 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1806 | #endif /* HAVE_GETPGRP */ |
Guido van Rossum | 0481447 | 1991-06-04 20:23:49 +0000 | [diff] [blame] | 1807 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1808 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1809 | #ifdef HAVE_SETPGRP |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1810 | static char posix_setpgrp__doc__[] = |
| 1811 | "setpgrp() -> None\n\ |
| 1812 | Make this process a session leader."; |
| 1813 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1814 | static PyObject * |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 1815 | posix_setpgrp(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1816 | PyObject *self; |
| 1817 | PyObject *args; |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 1818 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1819 | if (!PyArg_ParseTuple(args, ":setpgrp")) |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 1820 | return NULL; |
Guido van Rossum | 6493389 | 1994-10-20 21:56:42 +0000 | [diff] [blame] | 1821 | #ifdef SETPGRP_HAVE_ARG |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 1822 | if (setpgrp(0, 0) < 0) |
Guido van Rossum | 6493389 | 1994-10-20 21:56:42 +0000 | [diff] [blame] | 1823 | #else /* SETPGRP_HAVE_ARG */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1824 | if (setpgrp() < 0) |
Guido van Rossum | 6493389 | 1994-10-20 21:56:42 +0000 | [diff] [blame] | 1825 | #endif /* SETPGRP_HAVE_ARG */ |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 1826 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1827 | Py_INCREF(Py_None); |
| 1828 | return Py_None; |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1831 | #endif /* HAVE_SETPGRP */ |
| 1832 | |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1833 | #ifdef HAVE_GETPPID |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1834 | static char posix_getppid__doc__[] = |
| 1835 | "getppid() -> ppid\n\ |
| 1836 | Return the parent's process id."; |
| 1837 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1838 | static PyObject * |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1839 | posix_getppid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1840 | PyObject *self; |
| 1841 | PyObject *args; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1842 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1843 | if (!PyArg_ParseTuple(args, ":getppid")) |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1844 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1845 | return PyInt_FromLong((long)getppid()); |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1846 | } |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1847 | #endif |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1848 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1849 | |
Fred Drake | 12c6e2d | 1999-12-14 21:25:03 +0000 | [diff] [blame] | 1850 | #ifdef HAVE_GETLOGIN |
| 1851 | static char posix_getlogin__doc__[] = "\ |
| 1852 | getlogin() -> string\n\ |
| 1853 | Return the actual login name."; |
| 1854 | |
| 1855 | static PyObject * |
| 1856 | posix_getlogin(self, args) |
| 1857 | PyObject *self; |
| 1858 | PyObject *args; |
| 1859 | { |
| 1860 | PyObject *result = NULL; |
| 1861 | |
| 1862 | if (PyArg_ParseTuple(args, ":getlogin")) { |
| 1863 | char *name = getlogin(); |
| 1864 | |
| 1865 | if (name == NULL) |
| 1866 | posix_error(); |
| 1867 | else |
| 1868 | result = PyString_FromString(name); |
| 1869 | } |
| 1870 | return result; |
| 1871 | } |
| 1872 | #endif |
| 1873 | |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1874 | #ifdef HAVE_GETUID |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1875 | static char posix_getuid__doc__[] = |
| 1876 | "getuid() -> uid\n\ |
| 1877 | Return the current process's user id."; |
| 1878 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1879 | static PyObject * |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1880 | posix_getuid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1881 | PyObject *self; |
| 1882 | PyObject *args; |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1883 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1884 | if (!PyArg_ParseTuple(args, ":getuid")) |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1885 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1886 | return PyInt_FromLong((long)getuid()); |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1887 | } |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1888 | #endif |
Guido van Rossum | 46003ff | 1992-05-15 11:05:24 +0000 | [diff] [blame] | 1889 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1890 | |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1891 | #ifdef HAVE_KILL |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1892 | static char posix_kill__doc__[] = |
| 1893 | "kill(pid, sig) -> None\n\ |
| 1894 | Kill a process with a signal."; |
| 1895 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1896 | static PyObject * |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1897 | posix_kill(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1898 | PyObject *self; |
| 1899 | PyObject *args; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1900 | { |
| 1901 | int pid, sig; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1902 | if (!PyArg_ParseTuple(args, "ii:kill", &pid, &sig)) |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1903 | return NULL; |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 1904 | #if defined(PYOS_OS2) |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1905 | if (sig == XCPT_SIGNAL_INTR || sig == XCPT_SIGNAL_BREAK) { |
| 1906 | APIRET rc; |
| 1907 | if ((rc = DosSendSignalException(pid, sig)) != NO_ERROR) |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 1908 | return os2_error(rc); |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1909 | |
| 1910 | } else if (sig == XCPT_SIGNAL_KILLPROC) { |
| 1911 | APIRET rc; |
| 1912 | if ((rc = DosKillProcess(DKP_PROCESS, pid)) != NO_ERROR) |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 1913 | return os2_error(rc); |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1914 | |
| 1915 | } else |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 1916 | return NULL; /* Unrecognized Signal Requested */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1917 | #else |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1918 | if (kill(pid, sig) == -1) |
| 1919 | return posix_error(); |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1920 | #endif |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1921 | Py_INCREF(Py_None); |
| 1922 | return Py_None; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1923 | } |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 1924 | #endif |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 1925 | |
Guido van Rossum | c012547 | 1996-06-28 18:55:32 +0000 | [diff] [blame] | 1926 | #ifdef HAVE_PLOCK |
| 1927 | |
| 1928 | #ifdef HAVE_SYS_LOCK_H |
| 1929 | #include <sys/lock.h> |
| 1930 | #endif |
| 1931 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1932 | static char posix_plock__doc__[] = |
| 1933 | "plock(op) -> None\n\ |
| 1934 | Lock program segments into memory."; |
| 1935 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1936 | static PyObject * |
Guido van Rossum | c012547 | 1996-06-28 18:55:32 +0000 | [diff] [blame] | 1937 | posix_plock(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1938 | PyObject *self; |
| 1939 | PyObject *args; |
Guido van Rossum | c012547 | 1996-06-28 18:55:32 +0000 | [diff] [blame] | 1940 | { |
| 1941 | int op; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 1942 | if (!PyArg_ParseTuple(args, "i:plock", &op)) |
Guido van Rossum | c012547 | 1996-06-28 18:55:32 +0000 | [diff] [blame] | 1943 | return NULL; |
| 1944 | if (plock(op) == -1) |
| 1945 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 1946 | Py_INCREF(Py_None); |
| 1947 | return Py_None; |
Guido van Rossum | c012547 | 1996-06-28 18:55:32 +0000 | [diff] [blame] | 1948 | } |
| 1949 | #endif |
| 1950 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1951 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 1952 | #ifdef HAVE_POPEN |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 1953 | static char posix_popen__doc__[] = |
| 1954 | "popen(command [, mode='r' [, bufsize]]) -> pipe\n\ |
| 1955 | Open a pipe to/from a command returning a file object."; |
| 1956 | |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1957 | #if defined(PYOS_OS2) |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 1958 | static int |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1959 | async_system(const char *command) |
| 1960 | { |
| 1961 | char *p, errormsg[256], args[1024]; |
| 1962 | RESULTCODES rcodes; |
| 1963 | APIRET rc; |
| 1964 | char *shell = getenv("COMSPEC"); |
| 1965 | if (!shell) |
| 1966 | shell = "cmd"; |
| 1967 | |
| 1968 | strcpy(args, shell); |
| 1969 | p = &args[ strlen(args)+1 ]; |
| 1970 | strcpy(p, "/c "); |
| 1971 | strcat(p, command); |
| 1972 | p += strlen(p) + 1; |
| 1973 | *p = '\0'; |
| 1974 | |
| 1975 | rc = DosExecPgm(errormsg, sizeof(errormsg), |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 1976 | EXEC_ASYNC, /* Execute Async w/o Wait for Results */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1977 | args, |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 1978 | NULL, /* Inherit Parent's Environment */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1979 | &rcodes, shell); |
| 1980 | return rc; |
| 1981 | } |
| 1982 | |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 1983 | static FILE * |
| 1984 | popen(const char *command, const char *mode, int pipesize, int *err) |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1985 | { |
| 1986 | HFILE rhan, whan; |
| 1987 | FILE *retfd = NULL; |
| 1988 | APIRET rc = DosCreatePipe(&rhan, &whan, pipesize); |
| 1989 | |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 1990 | if (rc != NO_ERROR) { |
| 1991 | *err = rc; |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 1992 | return NULL; /* ERROR - Unable to Create Anon Pipe */ |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 1993 | } |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1994 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 1995 | if (strchr(mode, 'r') != NULL) { /* Treat Command as a Data Source */ |
| 1996 | int oldfd = dup(1); /* Save STDOUT Handle in Another Handle */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 1997 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 1998 | DosEnterCritSec(); /* Stop Other Threads While Changing Handles */ |
| 1999 | close(1); /* Make STDOUT Available for Reallocation */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2000 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 2001 | if (dup2(whan, 1) == 0) { /* Connect STDOUT to Pipe Write Side */ |
| 2002 | DosClose(whan); /* Close Now-Unused Pipe Write Handle */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2003 | |
| 2004 | if (async_system(command) == NO_ERROR) |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2005 | retfd = fdopen(rhan, mode); /* And Return Pipe Read Handle */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 2008 | dup2(oldfd, 1); /* Reconnect STDOUT to Original Handle */ |
| 2009 | DosExitCritSec(); /* Now Allow Other Threads to Run */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2010 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 2011 | close(oldfd); /* And Close Saved STDOUT Handle */ |
| 2012 | return retfd; /* Return fd of Pipe or NULL if Error */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2013 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 2014 | } else if (strchr(mode, 'w')) { /* Treat Command as a Data Sink */ |
| 2015 | int oldfd = dup(0); /* Save STDIN Handle in Another Handle */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2016 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 2017 | DosEnterCritSec(); /* Stop Other Threads While Changing Handles */ |
| 2018 | close(0); /* Make STDIN Available for Reallocation */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2019 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 2020 | if (dup2(rhan, 0) == 0) { /* Connect STDIN to Pipe Read Side */ |
| 2021 | DosClose(rhan); /* Close Now-Unused Pipe Read Handle */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2022 | |
| 2023 | if (async_system(command) == NO_ERROR) |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2024 | retfd = fdopen(whan, mode); /* And Return Pipe Write Handle */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 2027 | dup2(oldfd, 0); /* Reconnect STDIN to Original Handle */ |
| 2028 | DosExitCritSec(); /* Now Allow Other Threads to Run */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2029 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 2030 | close(oldfd); /* And Close Saved STDIN Handle */ |
| 2031 | return retfd; /* Return fd of Pipe or NULL if Error */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2032 | |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2033 | } else { |
| 2034 | *err = ERROR_INVALID_ACCESS; |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 2035 | return NULL; /* ERROR - Invalid Mode (Neither Read nor Write) */ |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2036 | } |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | static PyObject * |
| 2040 | posix_popen(self, args) |
| 2041 | PyObject *self; |
| 2042 | PyObject *args; |
| 2043 | { |
| 2044 | char *name; |
| 2045 | char *mode = "r"; |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2046 | int err, bufsize = -1; |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2047 | FILE *fp; |
| 2048 | PyObject *f; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2049 | if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize)) |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2050 | return NULL; |
| 2051 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2052 | fp = popen(name, mode, (bufsize > 0) ? bufsize : 4096, &err); |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2053 | Py_END_ALLOW_THREADS |
| 2054 | if (fp == NULL) |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2055 | return os2_error(err); |
| 2056 | |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2057 | f = PyFile_FromFile(fp, name, mode, fclose); |
| 2058 | if (f != NULL) |
| 2059 | PyFile_SetBufSize(f, bufsize); |
| 2060 | return f; |
| 2061 | } |
| 2062 | |
| 2063 | #else |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2064 | static PyObject * |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 2065 | posix_popen(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2066 | PyObject *self; |
| 2067 | PyObject *args; |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 2068 | { |
Guido van Rossum | a6a1e53 | 1995-01-10 15:36:38 +0000 | [diff] [blame] | 2069 | char *name; |
| 2070 | char *mode = "r"; |
| 2071 | int bufsize = -1; |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 2072 | FILE *fp; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2073 | PyObject *f; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2074 | if (!PyArg_ParseTuple(args, "s|si:popen", &name, &mode, &bufsize)) |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 2075 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2076 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 2077 | fp = popen(name, mode); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2078 | Py_END_ALLOW_THREADS |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 2079 | if (fp == NULL) |
| 2080 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2081 | f = PyFile_FromFile(fp, name, mode, pclose); |
Guido van Rossum | a6a1e53 | 1995-01-10 15:36:38 +0000 | [diff] [blame] | 2082 | if (f != NULL) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2083 | PyFile_SetBufSize(f, bufsize); |
Guido van Rossum | a6a1e53 | 1995-01-10 15:36:38 +0000 | [diff] [blame] | 2084 | return f; |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 2085 | } |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2086 | #endif |
| 2087 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2088 | #endif /* HAVE_POPEN */ |
Guido van Rossum | 3b06619 | 1991-06-04 19:40:25 +0000 | [diff] [blame] | 2089 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2090 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2091 | #ifdef HAVE_SETUID |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2092 | static char posix_setuid__doc__[] = |
| 2093 | "setuid(uid) -> None\n\ |
| 2094 | Set the current process's user id."; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2095 | static PyObject * |
Guido van Rossum | a3d78fb | 1993-11-10 09:23:53 +0000 | [diff] [blame] | 2096 | posix_setuid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2097 | PyObject *self; |
| 2098 | PyObject *args; |
Guido van Rossum | a3d78fb | 1993-11-10 09:23:53 +0000 | [diff] [blame] | 2099 | { |
| 2100 | int uid; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2101 | if (!PyArg_ParseTuple(args, "i:setuid", &uid)) |
Guido van Rossum | a3d78fb | 1993-11-10 09:23:53 +0000 | [diff] [blame] | 2102 | return NULL; |
| 2103 | if (setuid(uid) < 0) |
| 2104 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2105 | Py_INCREF(Py_None); |
| 2106 | return Py_None; |
Guido van Rossum | a3d78fb | 1993-11-10 09:23:53 +0000 | [diff] [blame] | 2107 | } |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 2108 | #endif /* HAVE_SETUID */ |
Guido van Rossum | a3d78fb | 1993-11-10 09:23:53 +0000 | [diff] [blame] | 2109 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2110 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2111 | #ifdef HAVE_SETGID |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2112 | static char posix_setgid__doc__[] = |
| 2113 | "setgid(gid) -> None\n\ |
| 2114 | Set the current process's group id."; |
| 2115 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2116 | static PyObject * |
Guido van Rossum | a3d78fb | 1993-11-10 09:23:53 +0000 | [diff] [blame] | 2117 | posix_setgid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2118 | PyObject *self; |
| 2119 | PyObject *args; |
Guido van Rossum | a3d78fb | 1993-11-10 09:23:53 +0000 | [diff] [blame] | 2120 | { |
| 2121 | int gid; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2122 | if (!PyArg_ParseTuple(args, "i:setgid", &gid)) |
Guido van Rossum | a3d78fb | 1993-11-10 09:23:53 +0000 | [diff] [blame] | 2123 | return NULL; |
| 2124 | if (setgid(gid) < 0) |
| 2125 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2126 | Py_INCREF(Py_None); |
| 2127 | return Py_None; |
Guido van Rossum | a3d78fb | 1993-11-10 09:23:53 +0000 | [diff] [blame] | 2128 | } |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 2129 | #endif /* HAVE_SETGID */ |
Guido van Rossum | a3d78fb | 1993-11-10 09:23:53 +0000 | [diff] [blame] | 2130 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2131 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2132 | #ifdef HAVE_WAITPID |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2133 | static char posix_waitpid__doc__[] = |
| 2134 | "waitpid(pid, options) -> (pid, status)\n\ |
| 2135 | Wait for completion of a give child process."; |
| 2136 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2137 | static PyObject * |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 2138 | posix_waitpid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2139 | PyObject *self; |
| 2140 | PyObject *args; |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 2141 | { |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 2142 | int pid, options; |
| 2143 | #ifdef UNION_WAIT |
| 2144 | union wait status; |
| 2145 | #define status_i (status.w_status) |
| 2146 | #else |
| 2147 | int status; |
| 2148 | #define status_i status |
| 2149 | #endif |
| 2150 | status_i = 0; |
| 2151 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2152 | if (!PyArg_ParseTuple(args, "ii:waitpid", &pid, &options)) |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 2153 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2154 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | e6a3aa6 | 1999-02-01 16:15:30 +0000 | [diff] [blame] | 2155 | #ifdef NeXT |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 2156 | pid = wait4(pid, &status, options, NULL); |
Guido van Rossum | e6a3aa6 | 1999-02-01 16:15:30 +0000 | [diff] [blame] | 2157 | #else |
| 2158 | pid = waitpid(pid, &status, options); |
| 2159 | #endif |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2160 | Py_END_ALLOW_THREADS |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 2161 | if (pid == -1) |
| 2162 | return posix_error(); |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 2163 | else |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 2164 | return Py_BuildValue("ii", pid, status_i); |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 2165 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2166 | #endif /* HAVE_WAITPID */ |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 2167 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2168 | |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 2169 | #ifdef HAVE_WAIT |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2170 | static char posix_wait__doc__[] = |
| 2171 | "wait() -> (pid, status)\n\ |
| 2172 | Wait for completion of a child process."; |
| 2173 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2174 | static PyObject * |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 2175 | posix_wait(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2176 | PyObject *self; |
| 2177 | PyObject *args; |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 2178 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2179 | int pid; |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 2180 | #ifdef UNION_WAIT |
| 2181 | union wait status; |
| 2182 | #define status_i (status.w_status) |
Guido van Rossum | b9f866c | 1997-05-22 15:12:39 +0000 | [diff] [blame] | 2183 | #else |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 2184 | int status; |
| 2185 | #define status_i status |
Guido van Rossum | b9f866c | 1997-05-22 15:12:39 +0000 | [diff] [blame] | 2186 | #endif |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2187 | if (!PyArg_ParseTuple(args, ":wait")) |
| 2188 | return NULL; |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 2189 | status_i = 0; |
| 2190 | Py_BEGIN_ALLOW_THREADS |
| 2191 | pid = wait(&status); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2192 | Py_END_ALLOW_THREADS |
Guido van Rossum | 21803b8 | 1992-08-09 12:55:27 +0000 | [diff] [blame] | 2193 | if (pid == -1) |
| 2194 | return posix_error(); |
| 2195 | else |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 2196 | return Py_BuildValue("ii", pid, status_i); |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2197 | #undef status_i |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 2198 | } |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 2199 | #endif |
Guido van Rossum | 85e3b01 | 1991-06-03 12:42:10 +0000 | [diff] [blame] | 2200 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2201 | |
| 2202 | static char posix_lstat__doc__[] = |
| 2203 | "lstat(path) -> (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\ |
| 2204 | Like stat(path), but do not follow symbolic links."; |
| 2205 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2206 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2207 | posix_lstat(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2208 | PyObject *self; |
| 2209 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2210 | { |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2211 | #ifdef HAVE_LSTAT |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2212 | return posix_do_stat(self, args, "s:lstat", lstat); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2213 | #else /* !HAVE_LSTAT */ |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2214 | return posix_do_stat(self, args, "s:lstat", stat); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2215 | #endif /* !HAVE_LSTAT */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2218 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2219 | #ifdef HAVE_READLINK |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2220 | static char posix_readlink__doc__[] = |
| 2221 | "readlink(path) -> path\n\ |
| 2222 | Return a string representing the path to which the symbolic link points."; |
| 2223 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2224 | static PyObject * |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2225 | posix_readlink(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2226 | PyObject *self; |
| 2227 | PyObject *args; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2228 | { |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2229 | char buf[MAXPATHLEN]; |
Guido van Rossum | ef0a00e | 1992-01-27 16:51:30 +0000 | [diff] [blame] | 2230 | char *path; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2231 | int n; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2232 | if (!PyArg_ParseTuple(args, "s:readlink", &path)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2233 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2234 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 50e61dc | 1992-03-27 17:22:31 +0000 | [diff] [blame] | 2235 | n = readlink(path, buf, (int) sizeof buf); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2236 | Py_END_ALLOW_THREADS |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2237 | if (n < 0) |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 2238 | return posix_error_with_filename(path); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2239 | return PyString_FromStringAndSize(buf, n); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2240 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2241 | #endif /* HAVE_READLINK */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2242 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2243 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2244 | #ifdef HAVE_SYMLINK |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2245 | static char posix_symlink__doc__[] = |
| 2246 | "symlink(src, dst) -> None\n\ |
| 2247 | Create a symbolic link."; |
| 2248 | |
Guido van Rossum | bfaf3d6 | 1997-12-29 20:02:27 +0000 | [diff] [blame] | 2249 | static PyObject * |
| 2250 | posix_symlink(self, args) |
| 2251 | PyObject *self; |
| 2252 | PyObject *args; |
| 2253 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2254 | return posix_2str(args, "ss:symlink", symlink); |
Guido van Rossum | bfaf3d6 | 1997-12-29 20:02:27 +0000 | [diff] [blame] | 2255 | } |
| 2256 | #endif /* HAVE_SYMLINK */ |
| 2257 | |
| 2258 | |
| 2259 | #ifdef HAVE_TIMES |
| 2260 | #ifndef HZ |
| 2261 | #define HZ 60 /* Universal constant :-) */ |
| 2262 | #endif /* HZ */ |
| 2263 | |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2264 | #if defined(PYCC_VACPP) && defined(PYOS_OS2) |
| 2265 | static long |
| 2266 | system_uptime() |
| 2267 | { |
| 2268 | ULONG value = 0; |
| 2269 | |
| 2270 | Py_BEGIN_ALLOW_THREADS |
| 2271 | DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &value, sizeof(value)); |
| 2272 | Py_END_ALLOW_THREADS |
| 2273 | |
| 2274 | return value; |
| 2275 | } |
| 2276 | |
| 2277 | static PyObject * |
| 2278 | posix_times(self, args) |
| 2279 | PyObject *self; |
| 2280 | PyObject *args; |
| 2281 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2282 | if (!PyArg_ParseTuple(args, ":times")) |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2283 | return NULL; |
| 2284 | |
| 2285 | /* Currently Only Uptime is Provided -- Others Later */ |
| 2286 | return Py_BuildValue("ddddd", |
| 2287 | (double)0 /* t.tms_utime / HZ */, |
| 2288 | (double)0 /* t.tms_stime / HZ */, |
| 2289 | (double)0 /* t.tms_cutime / HZ */, |
| 2290 | (double)0 /* t.tms_cstime / HZ */, |
| 2291 | (double)system_uptime() / 1000); |
| 2292 | } |
Guido van Rossum | bfaf3d6 | 1997-12-29 20:02:27 +0000 | [diff] [blame] | 2293 | #else /* not OS2 */ |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2294 | static PyObject * |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 2295 | posix_times(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2296 | PyObject *self; |
| 2297 | PyObject *args; |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 2298 | { |
| 2299 | struct tms t; |
| 2300 | clock_t c; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2301 | if (!PyArg_ParseTuple(args, ":times")) |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 2302 | return NULL; |
| 2303 | errno = 0; |
| 2304 | c = times(&t); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2305 | if (c == (clock_t) -1) |
| 2306 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2307 | return Py_BuildValue("ddddd", |
Barry Warsaw | 43d68b8 | 1996-12-19 22:10:44 +0000 | [diff] [blame] | 2308 | (double)t.tms_utime / HZ, |
| 2309 | (double)t.tms_stime / HZ, |
| 2310 | (double)t.tms_cutime / HZ, |
| 2311 | (double)t.tms_cstime / HZ, |
| 2312 | (double)c / HZ); |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 2313 | } |
Guido van Rossum | bfaf3d6 | 1997-12-29 20:02:27 +0000 | [diff] [blame] | 2314 | #endif /* not OS2 */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2315 | #endif /* HAVE_TIMES */ |
Guido van Rossum | bfaf3d6 | 1997-12-29 20:02:27 +0000 | [diff] [blame] | 2316 | |
| 2317 | |
Guido van Rossum | 87755a2 | 1996-09-07 00:59:43 +0000 | [diff] [blame] | 2318 | #ifdef MS_WIN32 |
Guido van Rossum | 14ed0b2 | 1994-09-29 09:50:09 +0000 | [diff] [blame] | 2319 | #define HAVE_TIMES /* so the method table will pick it up */ |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2320 | static PyObject * |
Guido van Rossum | 14ed0b2 | 1994-09-29 09:50:09 +0000 | [diff] [blame] | 2321 | posix_times(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2322 | PyObject *self; |
| 2323 | PyObject *args; |
Guido van Rossum | 14ed0b2 | 1994-09-29 09:50:09 +0000 | [diff] [blame] | 2324 | { |
| 2325 | FILETIME create, exit, kernel, user; |
| 2326 | HANDLE hProc; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2327 | if (!PyArg_ParseTuple(args, ":times")) |
Guido van Rossum | 14ed0b2 | 1994-09-29 09:50:09 +0000 | [diff] [blame] | 2328 | return NULL; |
| 2329 | hProc = GetCurrentProcess(); |
Guido van Rossum | b8c3cbd | 1999-02-16 14:37:28 +0000 | [diff] [blame] | 2330 | GetProcessTimes(hProc, &create, &exit, &kernel, &user); |
| 2331 | /* The fields of a FILETIME structure are the hi and lo part |
| 2332 | of a 64-bit value expressed in 100 nanosecond units. |
| 2333 | 1e7 is one second in such units; 1e-7 the inverse. |
| 2334 | 429.4967296 is 2**32 / 1e7 or 2**32 * 1e-7. |
| 2335 | */ |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2336 | return Py_BuildValue( |
| 2337 | "ddddd", |
Guido van Rossum | b8c3cbd | 1999-02-16 14:37:28 +0000 | [diff] [blame] | 2338 | (double)(kernel.dwHighDateTime*429.4967296 + |
| 2339 | kernel.dwLowDateTime*1e-7), |
| 2340 | (double)(user.dwHighDateTime*429.4967296 + |
| 2341 | user.dwLowDateTime*1e-7), |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2342 | (double)0, |
| 2343 | (double)0, |
| 2344 | (double)0); |
Guido van Rossum | 14ed0b2 | 1994-09-29 09:50:09 +0000 | [diff] [blame] | 2345 | } |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 2346 | #endif /* MS_WIN32 */ |
Guido van Rossum | bfaf3d6 | 1997-12-29 20:02:27 +0000 | [diff] [blame] | 2347 | |
| 2348 | #ifdef HAVE_TIMES |
Roger E. Masse | 0318fd6 | 1997-06-05 22:07:58 +0000 | [diff] [blame] | 2349 | static char posix_times__doc__[] = |
| 2350 | "times() -> (utime, stime, cutime, cstime, elapsed_time)\n\ |
| 2351 | Return a tuple of floating point numbers indicating process times."; |
Guido van Rossum | bfaf3d6 | 1997-12-29 20:02:27 +0000 | [diff] [blame] | 2352 | #endif |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 2353 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2354 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2355 | #ifdef HAVE_SETSID |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2356 | static char posix_setsid__doc__[] = |
| 2357 | "setsid() -> None\n\ |
| 2358 | Call the system call setsid()."; |
| 2359 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2360 | static PyObject * |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 2361 | posix_setsid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2362 | PyObject *self; |
| 2363 | PyObject *args; |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 2364 | { |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2365 | if (!PyArg_ParseTuple(args, ":setsid")) |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 2366 | return NULL; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2367 | if (setsid() < 0) |
| 2368 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2369 | Py_INCREF(Py_None); |
| 2370 | return Py_None; |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 2371 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2372 | #endif /* HAVE_SETSID */ |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 2373 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2374 | #ifdef HAVE_SETPGID |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2375 | static char posix_setpgid__doc__[] = |
| 2376 | "setpgid(pid, pgrp) -> None\n\ |
| 2377 | Call the system call setpgid()."; |
| 2378 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2379 | static PyObject * |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 2380 | posix_setpgid(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2381 | PyObject *self; |
| 2382 | PyObject *args; |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 2383 | { |
| 2384 | int pid, pgrp; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2385 | if (!PyArg_ParseTuple(args, "ii:setpgid", &pid, &pgrp)) |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 2386 | return NULL; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2387 | if (setpgid(pid, pgrp) < 0) |
| 2388 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2389 | Py_INCREF(Py_None); |
| 2390 | return Py_None; |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 2391 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2392 | #endif /* HAVE_SETPGID */ |
Guido van Rossum | c2670a0 | 1992-09-13 20:07:29 +0000 | [diff] [blame] | 2393 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2394 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2395 | #ifdef HAVE_TCGETPGRP |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2396 | static char posix_tcgetpgrp__doc__[] = |
| 2397 | "tcgetpgrp(fd) -> pgid\n\ |
| 2398 | Return the process group associated with the terminal given by a fd."; |
| 2399 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2400 | static PyObject * |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 2401 | posix_tcgetpgrp(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2402 | PyObject *self; |
| 2403 | PyObject *args; |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 2404 | { |
| 2405 | int fd, pgid; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2406 | if (!PyArg_ParseTuple(args, "i:tcgetpgrp", &fd)) |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 2407 | return NULL; |
| 2408 | pgid = tcgetpgrp(fd); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2409 | if (pgid < 0) |
| 2410 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2411 | return PyInt_FromLong((long)pgid); |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 2412 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2413 | #endif /* HAVE_TCGETPGRP */ |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 2414 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2415 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2416 | #ifdef HAVE_TCSETPGRP |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2417 | static char posix_tcsetpgrp__doc__[] = |
| 2418 | "tcsetpgrp(fd, pgid) -> None\n\ |
| 2419 | Set the process group associated with the terminal given by a fd."; |
| 2420 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2421 | static PyObject * |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 2422 | posix_tcsetpgrp(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2423 | PyObject *self; |
| 2424 | PyObject *args; |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 2425 | { |
| 2426 | int fd, pgid; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2427 | if (!PyArg_ParseTuple(args, "ii:tcsetpgrp", &fd, &pgid)) |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 2428 | return NULL; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2429 | if (tcsetpgrp(fd, pgid) < 0) |
| 2430 | return posix_error(); |
Barry Warsaw | 43d68b8 | 1996-12-19 22:10:44 +0000 | [diff] [blame] | 2431 | Py_INCREF(Py_None); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2432 | return Py_None; |
Guido van Rossum | 7066dd7 | 1992-09-17 17:54:56 +0000 | [diff] [blame] | 2433 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 2434 | #endif /* HAVE_TCSETPGRP */ |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 2435 | |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2436 | /* Functions acting on file descriptors */ |
| 2437 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2438 | static char posix_open__doc__[] = |
| 2439 | "open(filename, flag [, mode=0777]) -> fd\n\ |
| 2440 | Open a file (for low level IO)."; |
| 2441 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2442 | static PyObject * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2443 | posix_open(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2444 | PyObject *self; |
| 2445 | PyObject *args; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2446 | { |
| 2447 | char *file; |
| 2448 | int flag; |
| 2449 | int mode = 0777; |
| 2450 | int fd; |
Barry Warsaw | 43d68b8 | 1996-12-19 22:10:44 +0000 | [diff] [blame] | 2451 | if (!PyArg_ParseTuple(args, "si|i", &file, &flag, &mode)) |
| 2452 | return NULL; |
| 2453 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2454 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2455 | fd = open(file, flag, mode); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2456 | Py_END_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2457 | if (fd < 0) |
Barry Warsaw | d58d764 | 1998-07-23 16:14:40 +0000 | [diff] [blame] | 2458 | return posix_error_with_filename(file); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2459 | return PyInt_FromLong((long)fd); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2460 | } |
| 2461 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2462 | |
| 2463 | static char posix_close__doc__[] = |
| 2464 | "close(fd) -> None\n\ |
| 2465 | Close a file descriptor (for low level IO)."; |
| 2466 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2467 | static PyObject * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2468 | posix_close(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2469 | PyObject *self; |
| 2470 | PyObject *args; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2471 | { |
| 2472 | int fd, res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2473 | if (!PyArg_ParseTuple(args, "i:close", &fd)) |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2474 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2475 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2476 | res = close(fd); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2477 | Py_END_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2478 | if (res < 0) |
| 2479 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2480 | Py_INCREF(Py_None); |
| 2481 | return Py_None; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2484 | |
| 2485 | static char posix_dup__doc__[] = |
| 2486 | "dup(fd) -> fd2\n\ |
| 2487 | Return a duplicate of a file descriptor."; |
| 2488 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2489 | static PyObject * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2490 | posix_dup(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2491 | PyObject *self; |
| 2492 | PyObject *args; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2493 | { |
| 2494 | int fd; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2495 | if (!PyArg_ParseTuple(args, "i:dup", &fd)) |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2496 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2497 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2498 | fd = dup(fd); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2499 | Py_END_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2500 | if (fd < 0) |
| 2501 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2502 | return PyInt_FromLong((long)fd); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2505 | |
| 2506 | static char posix_dup2__doc__[] = |
| 2507 | "dup2(fd, fd2) -> None\n\ |
| 2508 | Duplicate file descriptor."; |
| 2509 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2510 | static PyObject * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2511 | posix_dup2(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2512 | PyObject *self; |
| 2513 | PyObject *args; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2514 | { |
| 2515 | int fd, fd2, res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2516 | if (!PyArg_ParseTuple(args, "ii:dup2", &fd, &fd2)) |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2517 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2518 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2519 | res = dup2(fd, fd2); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2520 | Py_END_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2521 | if (res < 0) |
| 2522 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2523 | Py_INCREF(Py_None); |
| 2524 | return Py_None; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2527 | |
| 2528 | static char posix_lseek__doc__[] = |
| 2529 | "lseek(fd, pos, how) -> newpos\n\ |
| 2530 | Set the current position of a file descriptor."; |
| 2531 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2532 | static PyObject * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2533 | posix_lseek(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2534 | PyObject *self; |
| 2535 | PyObject *args; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2536 | { |
| 2537 | int fd, how; |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 2538 | off_t pos, res; |
| 2539 | PyObject *posobj; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2540 | if (!PyArg_ParseTuple(args, "iOi:lseek", &fd, &posobj, &how)) |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2541 | return NULL; |
| 2542 | #ifdef SEEK_SET |
| 2543 | /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */ |
| 2544 | switch (how) { |
| 2545 | case 0: how = SEEK_SET; break; |
| 2546 | case 1: how = SEEK_CUR; break; |
| 2547 | case 2: how = SEEK_END; break; |
| 2548 | } |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 2549 | #endif /* SEEK_END */ |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 2550 | |
| 2551 | #if !defined(HAVE_LARGEFILE_SUPPORT) |
| 2552 | pos = PyInt_AsLong(posobj); |
| 2553 | #else |
| 2554 | pos = PyLong_Check(posobj) ? |
| 2555 | PyLong_AsLongLong(posobj) : PyInt_AsLong(posobj); |
| 2556 | #endif |
| 2557 | if (PyErr_Occurred()) |
| 2558 | return NULL; |
| 2559 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2560 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2561 | res = lseek(fd, pos, how); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2562 | Py_END_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2563 | if (res < 0) |
| 2564 | return posix_error(); |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 2565 | |
| 2566 | #if !defined(HAVE_LARGEFILE_SUPPORT) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2567 | return PyInt_FromLong(res); |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 2568 | #else |
| 2569 | return PyLong_FromLongLong(res); |
| 2570 | #endif |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2571 | } |
| 2572 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2573 | |
| 2574 | static char posix_read__doc__[] = |
| 2575 | "read(fd, buffersize) -> string\n\ |
| 2576 | Read a file descriptor."; |
| 2577 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2578 | static PyObject * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2579 | posix_read(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2580 | PyObject *self; |
| 2581 | PyObject *args; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2582 | { |
Guido van Rossum | 8bac546 | 1996-06-11 18:38:48 +0000 | [diff] [blame] | 2583 | int fd, size, n; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2584 | PyObject *buffer; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2585 | if (!PyArg_ParseTuple(args, "ii:read", &fd, &size)) |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2586 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2587 | buffer = PyString_FromStringAndSize((char *)NULL, size); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2588 | if (buffer == NULL) |
| 2589 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2590 | Py_BEGIN_ALLOW_THREADS |
| 2591 | n = read(fd, PyString_AsString(buffer), size); |
| 2592 | Py_END_ALLOW_THREADS |
Guido van Rossum | 8bac546 | 1996-06-11 18:38:48 +0000 | [diff] [blame] | 2593 | if (n < 0) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2594 | Py_DECREF(buffer); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2595 | return posix_error(); |
| 2596 | } |
Guido van Rossum | 8bac546 | 1996-06-11 18:38:48 +0000 | [diff] [blame] | 2597 | if (n != size) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2598 | _PyString_Resize(&buffer, n); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2599 | return buffer; |
| 2600 | } |
| 2601 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2602 | |
| 2603 | static char posix_write__doc__[] = |
| 2604 | "write(fd, string) -> byteswritten\n\ |
| 2605 | Write a string to a file descriptor."; |
| 2606 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2607 | static PyObject * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2608 | posix_write(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2609 | PyObject *self; |
| 2610 | PyObject *args; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2611 | { |
| 2612 | int fd, size; |
| 2613 | char *buffer; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2614 | if (!PyArg_ParseTuple(args, "is#:write", &fd, &buffer, &size)) |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2615 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2616 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2617 | size = write(fd, buffer, size); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2618 | Py_END_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2619 | if (size < 0) |
| 2620 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2621 | return PyInt_FromLong((long)size); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2624 | |
| 2625 | static char posix_fstat__doc__[]= |
| 2626 | "fstat(fd) -> (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)\n\ |
| 2627 | Like stat(), but for an open file descriptor."; |
| 2628 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2629 | static PyObject * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2630 | posix_fstat(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2631 | PyObject *self; |
| 2632 | PyObject *args; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2633 | { |
| 2634 | int fd; |
| 2635 | struct stat st; |
| 2636 | int res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2637 | if (!PyArg_ParseTuple(args, "i:fstat", &fd)) |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2638 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2639 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2640 | res = fstat(fd, &st); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2641 | Py_END_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2642 | if (res != 0) |
| 2643 | return posix_error(); |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 2644 | #if !defined(HAVE_LARGEFILE_SUPPORT) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2645 | return Py_BuildValue("(llllllllll)", |
Barry Warsaw | 43d68b8 | 1996-12-19 22:10:44 +0000 | [diff] [blame] | 2646 | (long)st.st_mode, |
| 2647 | (long)st.st_ino, |
| 2648 | (long)st.st_dev, |
| 2649 | (long)st.st_nlink, |
| 2650 | (long)st.st_uid, |
| 2651 | (long)st.st_gid, |
| 2652 | (long)st.st_size, |
| 2653 | (long)st.st_atime, |
| 2654 | (long)st.st_mtime, |
| 2655 | (long)st.st_ctime); |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 2656 | #else |
| 2657 | return Py_BuildValue("(lLllllLlll)", |
| 2658 | (long)st.st_mode, |
| 2659 | (LONG_LONG)st.st_ino, |
| 2660 | (long)st.st_dev, |
| 2661 | (long)st.st_nlink, |
| 2662 | (long)st.st_uid, |
| 2663 | (long)st.st_gid, |
| 2664 | (LONG_LONG)st.st_size, |
| 2665 | (long)st.st_atime, |
| 2666 | (long)st.st_mtime, |
| 2667 | (long)st.st_ctime); |
| 2668 | #endif |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2669 | } |
| 2670 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2671 | |
| 2672 | static char posix_fdopen__doc__[] = |
| 2673 | "fdopen(fd, [, mode='r' [, bufsize]]) -> file_object\n\ |
| 2674 | Return an open file object connected to a file descriptor."; |
| 2675 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2676 | static PyObject * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2677 | posix_fdopen(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2678 | PyObject *self; |
| 2679 | PyObject *args; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2680 | { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2681 | extern int fclose Py_PROTO((FILE *)); |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2682 | int fd; |
Guido van Rossum | a6a1e53 | 1995-01-10 15:36:38 +0000 | [diff] [blame] | 2683 | char *mode = "r"; |
| 2684 | int bufsize = -1; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2685 | FILE *fp; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2686 | PyObject *f; |
| 2687 | if (!PyArg_ParseTuple(args, "i|si", &fd, &mode, &bufsize)) |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2688 | return NULL; |
Barry Warsaw | 43d68b8 | 1996-12-19 22:10:44 +0000 | [diff] [blame] | 2689 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2690 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2691 | fp = fdopen(fd, mode); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2692 | Py_END_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2693 | if (fp == NULL) |
| 2694 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2695 | f = PyFile_FromFile(fp, "(fdopen)", mode, fclose); |
Guido van Rossum | a6a1e53 | 1995-01-10 15:36:38 +0000 | [diff] [blame] | 2696 | if (f != NULL) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2697 | PyFile_SetBufSize(f, bufsize); |
Guido van Rossum | a6a1e53 | 1995-01-10 15:36:38 +0000 | [diff] [blame] | 2698 | return f; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2699 | } |
| 2700 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2701 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2702 | #ifdef HAVE_PIPE |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2703 | static char posix_pipe__doc__[] = |
| 2704 | "pipe() -> (read_end, write_end)\n\ |
| 2705 | Create a pipe."; |
| 2706 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2707 | static PyObject * |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2708 | posix_pipe(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2709 | PyObject *self; |
| 2710 | PyObject *args; |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2711 | { |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2712 | #if defined(PYOS_OS2) |
| 2713 | HFILE read, write; |
| 2714 | APIRET rc; |
| 2715 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2716 | if (!PyArg_ParseTuple(args, ":pipe")) |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2717 | return NULL; |
| 2718 | |
| 2719 | Py_BEGIN_ALLOW_THREADS |
| 2720 | rc = DosCreatePipe( &read, &write, 4096); |
| 2721 | Py_END_ALLOW_THREADS |
| 2722 | if (rc != NO_ERROR) |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2723 | return os2_error(rc); |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2724 | |
| 2725 | return Py_BuildValue("(ii)", read, write); |
| 2726 | #else |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 2727 | #if !defined(MS_WIN32) |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2728 | int fds[2]; |
| 2729 | int res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2730 | if (!PyArg_ParseTuple(args, ":pipe")) |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2731 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2732 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2733 | res = pipe(fds); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2734 | Py_END_ALLOW_THREADS |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2735 | if (res != 0) |
| 2736 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2737 | return Py_BuildValue("(ii)", fds[0], fds[1]); |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 2738 | #else /* MS_WIN32 */ |
Guido van Rossum | 794d813 | 1994-08-23 13:48:48 +0000 | [diff] [blame] | 2739 | HANDLE read, write; |
Guido van Rossum | b3f9f4b | 1998-06-12 15:05:15 +0000 | [diff] [blame] | 2740 | int read_fd, write_fd; |
Guido van Rossum | 794d813 | 1994-08-23 13:48:48 +0000 | [diff] [blame] | 2741 | BOOL ok; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2742 | if (!PyArg_ParseTuple(args, ":pipe")) |
Guido van Rossum | 794d813 | 1994-08-23 13:48:48 +0000 | [diff] [blame] | 2743 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2744 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | b3f9f4b | 1998-06-12 15:05:15 +0000 | [diff] [blame] | 2745 | ok = CreatePipe(&read, &write, NULL, 0); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2746 | Py_END_ALLOW_THREADS |
Guido van Rossum | 794d813 | 1994-08-23 13:48:48 +0000 | [diff] [blame] | 2747 | if (!ok) |
| 2748 | return posix_error(); |
Guido van Rossum | b3f9f4b | 1998-06-12 15:05:15 +0000 | [diff] [blame] | 2749 | read_fd = _open_osfhandle((long)read, 0); |
| 2750 | write_fd = _open_osfhandle((long)write, 1); |
| 2751 | return Py_BuildValue("(ii)", read_fd, write_fd); |
Guido van Rossum | 8d665e6 | 1996-06-26 18:22:49 +0000 | [diff] [blame] | 2752 | #endif /* MS_WIN32 */ |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 2753 | #endif |
Guido van Rossum | 687dd13 | 1993-05-17 08:34:16 +0000 | [diff] [blame] | 2754 | } |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2755 | #endif /* HAVE_PIPE */ |
| 2756 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2757 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2758 | #ifdef HAVE_MKFIFO |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2759 | static char posix_mkfifo__doc__[] = |
| 2760 | "mkfifo(file, [, mode=0666]) -> None\n\ |
| 2761 | Create a FIFO (a POSIX named pipe)."; |
| 2762 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2763 | static PyObject * |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2764 | posix_mkfifo(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2765 | PyObject *self; |
| 2766 | PyObject *args; |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2767 | { |
| 2768 | char *file; |
| 2769 | int mode = 0666; |
| 2770 | int res; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2771 | if (!PyArg_ParseTuple(args, "s|i:mkfifo", &file, &mode)) |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2772 | return NULL; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2773 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2774 | res = mkfifo(file, mode); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2775 | Py_END_ALLOW_THREADS |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2776 | if (res < 0) |
| 2777 | return posix_error(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2778 | Py_INCREF(Py_None); |
| 2779 | return Py_None; |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2780 | } |
| 2781 | #endif |
| 2782 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2783 | |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2784 | #ifdef HAVE_FTRUNCATE |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2785 | static char posix_ftruncate__doc__[] = |
| 2786 | "ftruncate(fd, length) -> None\n\ |
| 2787 | Truncate a file to a specified length."; |
| 2788 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2789 | static PyObject * |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2790 | posix_ftruncate(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2791 | PyObject *self; /* Not used */ |
| 2792 | PyObject *args; |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2793 | { |
| 2794 | int fd; |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 2795 | off_t length; |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2796 | int res; |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 2797 | PyObject *lenobj; |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2798 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2799 | if (!PyArg_ParseTuple(args, "iO:ftruncate", &fd, &lenobj)) |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 2800 | return NULL; |
| 2801 | |
| 2802 | #if !defined(HAVE_LARGEFILE_SUPPORT) |
| 2803 | length = PyInt_AsLong(lenobj); |
| 2804 | #else |
| 2805 | length = PyLong_Check(lenobj) ? |
| 2806 | PyLong_AsLongLong(lenobj) : PyInt_AsLong(lenobj); |
| 2807 | #endif |
| 2808 | if (PyErr_Occurred()) |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2809 | return NULL; |
| 2810 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2811 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2812 | res = ftruncate(fd, length); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2813 | Py_END_ALLOW_THREADS |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2814 | if (res < 0) { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2815 | PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2816 | return NULL; |
| 2817 | } |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2818 | Py_INCREF(Py_None); |
| 2819 | return Py_None; |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 2820 | } |
| 2821 | #endif |
Guido van Rossum | 22db57e | 1992-04-05 14:25:30 +0000 | [diff] [blame] | 2822 | |
Guido van Rossum | b9f866c | 1997-05-22 15:12:39 +0000 | [diff] [blame] | 2823 | #ifdef NeXT |
| 2824 | #define HAVE_PUTENV |
| 2825 | /* Steve Spicklemire got this putenv from NeXTAnswers */ |
| 2826 | static int |
| 2827 | putenv(char *newval) |
| 2828 | { |
| 2829 | extern char **environ; |
| 2830 | |
| 2831 | static int firstTime = 1; |
| 2832 | char **ep; |
| 2833 | char *cp; |
| 2834 | int esiz; |
| 2835 | char *np; |
| 2836 | |
| 2837 | if (!(np = strchr(newval, '='))) |
| 2838 | return 1; |
| 2839 | *np = '\0'; |
| 2840 | |
| 2841 | /* look it up */ |
| 2842 | for (ep=environ ; *ep ; ep++) |
| 2843 | { |
| 2844 | /* this should always be true... */ |
| 2845 | if (cp = strchr(*ep, '=')) |
| 2846 | { |
| 2847 | *cp = '\0'; |
| 2848 | if (!strcmp(*ep, newval)) |
| 2849 | { |
| 2850 | /* got it! */ |
| 2851 | *cp = '='; |
| 2852 | break; |
| 2853 | } |
| 2854 | *cp = '='; |
| 2855 | } |
| 2856 | else |
| 2857 | { |
| 2858 | *np = '='; |
| 2859 | return 1; |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | *np = '='; |
| 2864 | if (*ep) |
| 2865 | { |
| 2866 | /* the string was already there: |
| 2867 | just replace it with the new one */ |
| 2868 | *ep = newval; |
| 2869 | return 0; |
| 2870 | } |
| 2871 | |
| 2872 | /* expand environ by one */ |
| 2873 | for (esiz=2, ep=environ ; *ep ; ep++) |
| 2874 | esiz++; |
| 2875 | if (firstTime) |
| 2876 | { |
| 2877 | char **epp; |
| 2878 | char **newenv; |
| 2879 | if (!(newenv = malloc(esiz * sizeof(char *)))) |
| 2880 | return 1; |
| 2881 | |
| 2882 | for (ep=environ, epp=newenv ; *ep ;) |
| 2883 | *epp++ = *ep++; |
| 2884 | *epp++ = newval; |
| 2885 | *epp = (char *) 0; |
| 2886 | environ = newenv; |
| 2887 | } |
| 2888 | else |
| 2889 | { |
| 2890 | if (!(environ = realloc(environ, esiz * sizeof(char *)))) |
| 2891 | return 1; |
| 2892 | environ[esiz - 2] = newval; |
| 2893 | environ[esiz - 1] = (char *) 0; |
| 2894 | firstTime = 0; |
| 2895 | } |
| 2896 | |
| 2897 | return 0; |
| 2898 | } |
Guido van Rossum | c6ef204 | 1997-08-21 02:30:45 +0000 | [diff] [blame] | 2899 | #endif /* NeXT */ |
Guido van Rossum | b9f866c | 1997-05-22 15:12:39 +0000 | [diff] [blame] | 2900 | |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2901 | |
Guido van Rossum | f1af3fe | 1996-07-23 19:18:10 +0000 | [diff] [blame] | 2902 | #ifdef HAVE_PUTENV |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 2903 | static char posix_putenv__doc__[] = |
| 2904 | "putenv(key, value) -> None\n\ |
| 2905 | Change or add an environment variable."; |
| 2906 | |
Guido van Rossum | bcc2074 | 1998-08-04 22:53:56 +0000 | [diff] [blame] | 2907 | #ifdef __BEOS__ |
| 2908 | /* We have putenv(), but not in the headers (as of PR2). - [cjh] */ |
| 2909 | int putenv( const char *str ); |
| 2910 | #endif |
| 2911 | |
Fred Drake | 762e206 | 1999-08-26 17:23:54 +0000 | [diff] [blame] | 2912 | /* Save putenv() parameters as values here, so we can collect them when they |
| 2913 | * get re-set with another call for the same key. */ |
| 2914 | static PyObject *posix_putenv_garbage; |
| 2915 | |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2916 | static PyObject * |
Guido van Rossum | b6a4716 | 1997-09-15 22:54:34 +0000 | [diff] [blame] | 2917 | posix_putenv(self, args) |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2918 | PyObject *self; |
| 2919 | PyObject *args; |
Guido van Rossum | f1af3fe | 1996-07-23 19:18:10 +0000 | [diff] [blame] | 2920 | { |
| 2921 | char *s1, *s2; |
| 2922 | char *new; |
Fred Drake | 762e206 | 1999-08-26 17:23:54 +0000 | [diff] [blame] | 2923 | PyObject *newstr; |
Guido van Rossum | f1af3fe | 1996-07-23 19:18:10 +0000 | [diff] [blame] | 2924 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2925 | if (!PyArg_ParseTuple(args, "ss:putenv", &s1, &s2)) |
Guido van Rossum | f1af3fe | 1996-07-23 19:18:10 +0000 | [diff] [blame] | 2926 | return NULL; |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2927 | |
| 2928 | #if defined(PYOS_OS2) |
| 2929 | if (stricmp(s1, "BEGINLIBPATH") == 0) { |
| 2930 | APIRET rc; |
| 2931 | |
| 2932 | if (strlen(s2) == 0) /* If New Value is an Empty String */ |
| 2933 | s2 = NULL; /* Then OS/2 API Wants a NULL to Undefine It */ |
| 2934 | |
| 2935 | rc = DosSetExtLIBPATH(s2, BEGIN_LIBPATH); |
| 2936 | if (rc != NO_ERROR) |
| 2937 | return os2_error(rc); |
| 2938 | |
| 2939 | } else if (stricmp(s1, "ENDLIBPATH") == 0) { |
| 2940 | APIRET rc; |
| 2941 | |
| 2942 | if (strlen(s2) == 0) /* If New Value is an Empty String */ |
| 2943 | s2 = NULL; /* Then OS/2 API Wants a NULL to Undefine It */ |
| 2944 | |
| 2945 | rc = DosSetExtLIBPATH(s2, END_LIBPATH); |
| 2946 | if (rc != NO_ERROR) |
| 2947 | return os2_error(rc); |
| 2948 | } else { |
| 2949 | #endif |
| 2950 | |
Fred Drake | 762e206 | 1999-08-26 17:23:54 +0000 | [diff] [blame] | 2951 | /* XXX This can leak memory -- not easy to fix :-( */ |
| 2952 | newstr = PyString_FromStringAndSize(NULL, strlen(s1) + strlen(s2) + 2); |
| 2953 | if (newstr == NULL) |
| 2954 | return PyErr_NoMemory(); |
| 2955 | new = PyString_AS_STRING(newstr); |
Guido van Rossum | f1af3fe | 1996-07-23 19:18:10 +0000 | [diff] [blame] | 2956 | (void) sprintf(new, "%s=%s", s1, s2); |
| 2957 | if (putenv(new)) { |
| 2958 | posix_error(); |
| 2959 | return NULL; |
| 2960 | } |
Fred Drake | 762e206 | 1999-08-26 17:23:54 +0000 | [diff] [blame] | 2961 | /* Install the first arg and newstr in posix_putenv_garbage; |
| 2962 | * this will cause previous value to be collected. This has to |
| 2963 | * happen after the real putenv() call because the old value |
| 2964 | * was still accessible until then. */ |
| 2965 | if (PyDict_SetItem(posix_putenv_garbage, |
| 2966 | PyTuple_GET_ITEM(args, 0), newstr)) { |
| 2967 | /* really not much we can do; just leak */ |
| 2968 | PyErr_Clear(); |
| 2969 | } |
| 2970 | else { |
| 2971 | Py_DECREF(newstr); |
| 2972 | } |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 2973 | |
| 2974 | #if defined(PYOS_OS2) |
| 2975 | } |
| 2976 | #endif |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 2977 | Py_INCREF(Py_None); |
| 2978 | return Py_None; |
Guido van Rossum | f1af3fe | 1996-07-23 19:18:10 +0000 | [diff] [blame] | 2979 | } |
Guido van Rossum | b6a4716 | 1997-09-15 22:54:34 +0000 | [diff] [blame] | 2980 | #endif /* putenv */ |
| 2981 | |
| 2982 | #ifdef HAVE_STRERROR |
| 2983 | static char posix_strerror__doc__[] = |
| 2984 | "strerror(code) -> string\n\ |
| 2985 | Translate an error code to a message string."; |
| 2986 | |
| 2987 | PyObject * |
| 2988 | posix_strerror(self, args) |
| 2989 | PyObject *self; |
| 2990 | PyObject *args; |
| 2991 | { |
| 2992 | int code; |
| 2993 | char *message; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 2994 | if (!PyArg_ParseTuple(args, "i:strerror", &code)) |
Guido van Rossum | b6a4716 | 1997-09-15 22:54:34 +0000 | [diff] [blame] | 2995 | return NULL; |
| 2996 | message = strerror(code); |
| 2997 | if (message == NULL) { |
| 2998 | PyErr_SetString(PyExc_ValueError, |
| 2999 | "strerror code out of range"); |
| 3000 | return NULL; |
| 3001 | } |
| 3002 | return PyString_FromString(message); |
| 3003 | } |
| 3004 | #endif /* strerror */ |
| 3005 | |
Guido van Rossum | f1af3fe | 1996-07-23 19:18:10 +0000 | [diff] [blame] | 3006 | |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3007 | #ifdef HAVE_SYS_WAIT_H |
| 3008 | |
| 3009 | #ifdef WIFSTOPPED |
| 3010 | static char posix_WIFSTOPPED__doc__[] = |
| 3011 | "WIFSTOPPED(status) -> Boolean\n\ |
Fred Drake | 7e3535c | 1999-02-02 16:37:11 +0000 | [diff] [blame] | 3012 | Return true if the process returning 'status' was stopped."; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3013 | |
| 3014 | static PyObject * |
| 3015 | posix_WIFSTOPPED(self, args) |
| 3016 | PyObject *self; |
| 3017 | PyObject *args; |
| 3018 | { |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 3019 | #ifdef UNION_WAIT |
| 3020 | union wait status; |
| 3021 | #define status_i (status.w_status) |
| 3022 | #else |
| 3023 | int status; |
| 3024 | #define status_i status |
| 3025 | #endif |
| 3026 | status_i = 0; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3027 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3028 | if (!PyArg_ParseTuple(args, "i:WIFSTOPPED", &status_i)) |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3029 | { |
| 3030 | return NULL; |
| 3031 | } |
| 3032 | |
| 3033 | return Py_BuildValue("i", WIFSTOPPED(status)); |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3034 | #undef status_i |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3035 | } |
| 3036 | #endif /* WIFSTOPPED */ |
| 3037 | |
| 3038 | #ifdef WIFSIGNALED |
| 3039 | static char posix_WIFSIGNALED__doc__[] = |
| 3040 | "WIFSIGNALED(status) -> Boolean\n\ |
Guido van Rossum | 3366d1c | 1999-02-23 18:34:43 +0000 | [diff] [blame] | 3041 | Return true if the process returning 'status' was terminated by a signal."; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3042 | |
| 3043 | static PyObject * |
| 3044 | posix_WIFSIGNALED(self, args) |
| 3045 | PyObject *self; |
| 3046 | PyObject *args; |
| 3047 | { |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 3048 | #ifdef UNION_WAIT |
| 3049 | union wait status; |
| 3050 | #define status_i (status.w_status) |
| 3051 | #else |
| 3052 | int status; |
| 3053 | #define status_i status |
| 3054 | #endif |
| 3055 | status_i = 0; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3056 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3057 | if (!PyArg_ParseTuple(args, "i:WIFSIGNALED", &status_i)) |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3058 | { |
| 3059 | return NULL; |
| 3060 | } |
| 3061 | |
| 3062 | return Py_BuildValue("i", WIFSIGNALED(status)); |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3063 | #undef status_i |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3064 | } |
| 3065 | #endif /* WIFSIGNALED */ |
| 3066 | |
| 3067 | #ifdef WIFEXITED |
| 3068 | static char posix_WIFEXITED__doc__[] = |
| 3069 | "WIFEXITED(status) -> Boolean\n\ |
Fred Drake | 7e3535c | 1999-02-02 16:37:11 +0000 | [diff] [blame] | 3070 | Return true if the process returning 'status' exited using the exit()\n\ |
| 3071 | system call."; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3072 | |
| 3073 | static PyObject * |
| 3074 | posix_WIFEXITED(self, args) |
| 3075 | PyObject *self; |
| 3076 | PyObject *args; |
| 3077 | { |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 3078 | #ifdef UNION_WAIT |
| 3079 | union wait status; |
| 3080 | #define status_i (status.w_status) |
| 3081 | #else |
| 3082 | int status; |
| 3083 | #define status_i status |
| 3084 | #endif |
| 3085 | status_i = 0; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3086 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3087 | if (!PyArg_ParseTuple(args, "i:WIFEXITED", &status_i)) |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3088 | { |
| 3089 | return NULL; |
| 3090 | } |
| 3091 | |
| 3092 | return Py_BuildValue("i", WIFEXITED(status)); |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3093 | #undef status_i |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3094 | } |
| 3095 | #endif /* WIFEXITED */ |
| 3096 | |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 3097 | #ifdef WEXITSTATUS |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3098 | static char posix_WEXITSTATUS__doc__[] = |
| 3099 | "WEXITSTATUS(status) -> integer\n\ |
Fred Drake | 7e3535c | 1999-02-02 16:37:11 +0000 | [diff] [blame] | 3100 | Return the process return code from 'status'."; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3101 | |
| 3102 | static PyObject * |
| 3103 | posix_WEXITSTATUS(self, args) |
| 3104 | PyObject *self; |
| 3105 | PyObject *args; |
| 3106 | { |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 3107 | #ifdef UNION_WAIT |
| 3108 | union wait status; |
| 3109 | #define status_i (status.w_status) |
| 3110 | #else |
| 3111 | int status; |
| 3112 | #define status_i status |
| 3113 | #endif |
| 3114 | status_i = 0; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3115 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3116 | if (!PyArg_ParseTuple(args, "i:WEXITSTATUS", &status_i)) |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3117 | { |
| 3118 | return NULL; |
| 3119 | } |
| 3120 | |
| 3121 | return Py_BuildValue("i", WEXITSTATUS(status)); |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3122 | #undef status_i |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3123 | } |
| 3124 | #endif /* WEXITSTATUS */ |
| 3125 | |
| 3126 | #ifdef WTERMSIG |
| 3127 | static char posix_WTERMSIG__doc__[] = |
| 3128 | "WTERMSIG(status) -> integer\n\ |
Fred Drake | 7e3535c | 1999-02-02 16:37:11 +0000 | [diff] [blame] | 3129 | Return the signal that terminated the process that provided the 'status'\n\ |
| 3130 | value."; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3131 | |
| 3132 | static PyObject * |
| 3133 | posix_WTERMSIG(self, args) |
| 3134 | PyObject *self; |
| 3135 | PyObject *args; |
| 3136 | { |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 3137 | #ifdef UNION_WAIT |
| 3138 | union wait status; |
| 3139 | #define status_i (status.w_status) |
| 3140 | #else |
| 3141 | int status; |
| 3142 | #define status_i status |
| 3143 | #endif |
| 3144 | status_i = 0; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3145 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3146 | if (!PyArg_ParseTuple(args, "i:WTERMSIG", &status_i)) |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3147 | { |
| 3148 | return NULL; |
| 3149 | } |
| 3150 | |
| 3151 | return Py_BuildValue("i", WTERMSIG(status)); |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3152 | #undef status_i |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3153 | } |
| 3154 | #endif /* WTERMSIG */ |
| 3155 | |
| 3156 | #ifdef WSTOPSIG |
| 3157 | static char posix_WSTOPSIG__doc__[] = |
| 3158 | "WSTOPSIG(status) -> integer\n\ |
Fred Drake | 7e3535c | 1999-02-02 16:37:11 +0000 | [diff] [blame] | 3159 | Return the signal that stopped the process that provided the 'status' value."; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3160 | |
| 3161 | static PyObject * |
| 3162 | posix_WSTOPSIG(self, args) |
| 3163 | PyObject *self; |
| 3164 | PyObject *args; |
| 3165 | { |
Guido van Rossum | 54ecc3d | 1999-01-27 17:53:11 +0000 | [diff] [blame] | 3166 | #ifdef UNION_WAIT |
| 3167 | union wait status; |
| 3168 | #define status_i (status.w_status) |
| 3169 | #else |
| 3170 | int status; |
| 3171 | #define status_i status |
| 3172 | #endif |
| 3173 | status_i = 0; |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3174 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3175 | if (!PyArg_ParseTuple(args, "i:WSTOPSIG", &status_i)) |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3176 | { |
| 3177 | return NULL; |
| 3178 | } |
| 3179 | |
| 3180 | return Py_BuildValue("i", WSTOPSIG(status)); |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3181 | #undef status_i |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 3182 | } |
| 3183 | #endif /* WSTOPSIG */ |
| 3184 | |
| 3185 | #endif /* HAVE_SYS_WAIT_H */ |
| 3186 | |
| 3187 | |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3188 | #if defined(HAVE_FSTATVFS) |
Guido van Rossum | d5753e1 | 1999-10-19 13:29:23 +0000 | [diff] [blame] | 3189 | #ifdef _SCO_DS |
| 3190 | /* SCO OpenServer 5.0 and later requires _SVID3 before it reveals the |
| 3191 | needed definitions in sys/statvfs.h */ |
| 3192 | #define _SVID3 |
| 3193 | #endif |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3194 | #include <sys/statvfs.h> |
| 3195 | |
| 3196 | static char posix_fstatvfs__doc__[] = |
Guido van Rossum | 0c9608c | 1999-02-03 16:32:37 +0000 | [diff] [blame] | 3197 | "fstatvfs(fd) -> \n\ |
| 3198 | (bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax)\n\ |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3199 | Perform an fstatvfs system call on the given fd."; |
| 3200 | |
| 3201 | static PyObject * |
| 3202 | posix_fstatvfs(self, args) |
| 3203 | PyObject *self; |
| 3204 | PyObject *args; |
| 3205 | { |
| 3206 | int fd, res; |
| 3207 | struct statvfs st; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3208 | if (!PyArg_ParseTuple(args, "i:fstatvfs", &fd)) |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3209 | return NULL; |
| 3210 | Py_BEGIN_ALLOW_THREADS |
| 3211 | res = fstatvfs(fd, &st); |
| 3212 | Py_END_ALLOW_THREADS |
| 3213 | if (res != 0) |
| 3214 | return posix_error(); |
| 3215 | #if !defined(HAVE_LARGEFILE_SUPPORT) |
Guido van Rossum | 0c9608c | 1999-02-03 16:32:37 +0000 | [diff] [blame] | 3216 | return Py_BuildValue("(llllllllll)", |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3217 | (long) st.f_bsize, |
| 3218 | (long) st.f_frsize, |
| 3219 | (long) st.f_blocks, |
| 3220 | (long) st.f_bfree, |
| 3221 | (long) st.f_bavail, |
| 3222 | (long) st.f_files, |
| 3223 | (long) st.f_ffree, |
| 3224 | (long) st.f_favail, |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3225 | (long) st.f_flag, |
| 3226 | (long) st.f_namemax); |
| 3227 | #else |
Guido van Rossum | 0c9608c | 1999-02-03 16:32:37 +0000 | [diff] [blame] | 3228 | return Py_BuildValue("(llLLLLLLll)", |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3229 | (long) st.f_bsize, |
| 3230 | (long) st.f_frsize, |
| 3231 | (LONG_LONG) st.f_blocks, |
| 3232 | (LONG_LONG) st.f_bfree, |
| 3233 | (LONG_LONG) st.f_bavail, |
| 3234 | (LONG_LONG) st.f_files, |
| 3235 | (LONG_LONG) st.f_ffree, |
| 3236 | (LONG_LONG) st.f_favail, |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3237 | (long) st.f_flag, |
| 3238 | (long) st.f_namemax); |
| 3239 | #endif |
| 3240 | } |
| 3241 | #endif /* HAVE_FSTATVFS */ |
| 3242 | |
| 3243 | |
| 3244 | #if defined(HAVE_STATVFS) |
| 3245 | #include <sys/statvfs.h> |
| 3246 | |
| 3247 | static char posix_statvfs__doc__[] = |
Guido van Rossum | 0c9608c | 1999-02-03 16:32:37 +0000 | [diff] [blame] | 3248 | "statvfs(path) -> \n\ |
| 3249 | (bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax)\n\ |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3250 | Perform a statvfs system call on the given path."; |
| 3251 | |
| 3252 | static PyObject * |
| 3253 | posix_statvfs(self, args) |
| 3254 | PyObject *self; |
| 3255 | PyObject *args; |
| 3256 | { |
| 3257 | char *path; |
| 3258 | int res; |
| 3259 | struct statvfs st; |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3260 | if (!PyArg_ParseTuple(args, "s:statvfs", &path)) |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3261 | return NULL; |
| 3262 | Py_BEGIN_ALLOW_THREADS |
| 3263 | res = statvfs(path, &st); |
| 3264 | Py_END_ALLOW_THREADS |
| 3265 | if (res != 0) |
| 3266 | return posix_error_with_filename(path); |
| 3267 | #if !defined(HAVE_LARGEFILE_SUPPORT) |
Guido van Rossum | 0c9608c | 1999-02-03 16:32:37 +0000 | [diff] [blame] | 3268 | return Py_BuildValue("(llllllllll)", |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3269 | (long) st.f_bsize, |
| 3270 | (long) st.f_frsize, |
| 3271 | (long) st.f_blocks, |
| 3272 | (long) st.f_bfree, |
| 3273 | (long) st.f_bavail, |
| 3274 | (long) st.f_files, |
| 3275 | (long) st.f_ffree, |
| 3276 | (long) st.f_favail, |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3277 | (long) st.f_flag, |
| 3278 | (long) st.f_namemax); |
| 3279 | #else /* HAVE_LARGEFILE_SUPPORT */ |
Guido van Rossum | 0c9608c | 1999-02-03 16:32:37 +0000 | [diff] [blame] | 3280 | return Py_BuildValue("(llLLLLLLll)", |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3281 | (long) st.f_bsize, |
| 3282 | (long) st.f_frsize, |
| 3283 | (LONG_LONG) st.f_blocks, |
| 3284 | (LONG_LONG) st.f_bfree, |
| 3285 | (LONG_LONG) st.f_bavail, |
| 3286 | (LONG_LONG) st.f_files, |
| 3287 | (LONG_LONG) st.f_ffree, |
| 3288 | (LONG_LONG) st.f_favail, |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 3289 | (long) st.f_flag, |
| 3290 | (long) st.f_namemax); |
| 3291 | #endif |
| 3292 | } |
| 3293 | #endif /* HAVE_STATVFS */ |
| 3294 | |
| 3295 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3296 | #ifdef HAVE_TEMPNAM |
| 3297 | static char posix_tempnam__doc__[] = "\ |
| 3298 | tempnam([dir[, prefix]]) -> string\n\ |
| 3299 | Return a unique name for a temporary file.\n\ |
| 3300 | The directory and a short may be specified as strings; they may be omitted\n\ |
| 3301 | or None if not needed."; |
| 3302 | |
| 3303 | static PyObject * |
| 3304 | posix_tempnam(self, args) |
| 3305 | PyObject *self; |
| 3306 | PyObject *args; |
| 3307 | { |
| 3308 | PyObject *result = NULL; |
| 3309 | char *dir = NULL; |
| 3310 | char *pfx = NULL; |
| 3311 | char *name; |
| 3312 | |
| 3313 | if (!PyArg_ParseTuple(args, "|zz:tempnam", &dir, &pfx)) |
| 3314 | return NULL; |
| 3315 | name = tempnam(dir, pfx); |
| 3316 | if (name == NULL) |
| 3317 | return PyErr_NoMemory(); |
| 3318 | result = PyString_FromString(name); |
| 3319 | free(name); |
| 3320 | return result; |
| 3321 | } |
Guido van Rossum | d371ff1 | 1999-01-25 16:12:23 +0000 | [diff] [blame] | 3322 | #endif |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3323 | |
| 3324 | |
| 3325 | #ifdef HAVE_TMPFILE |
| 3326 | static char posix_tmpfile__doc__[] = "\ |
| 3327 | tmpfile() -> file object\n\ |
| 3328 | Create a temporary file with no directory entries."; |
| 3329 | |
| 3330 | static PyObject * |
| 3331 | posix_tmpfile(self, args) |
| 3332 | PyObject *self; |
| 3333 | PyObject *args; |
| 3334 | { |
| 3335 | FILE *fp; |
| 3336 | |
| 3337 | if (!PyArg_ParseTuple(args, ":tmpfile")) |
| 3338 | return NULL; |
| 3339 | fp = tmpfile(); |
| 3340 | if (fp == NULL) |
| 3341 | return posix_error(); |
| 3342 | return PyFile_FromFile(fp, "<tmpfile>", "w+", fclose); |
| 3343 | } |
| 3344 | #endif |
| 3345 | |
| 3346 | |
| 3347 | #ifdef HAVE_TMPNAM |
| 3348 | static char posix_tmpnam__doc__[] = "\ |
| 3349 | tmpnam() -> string\n\ |
| 3350 | Return a unique name for a temporary file."; |
| 3351 | |
| 3352 | static PyObject * |
| 3353 | posix_tmpnam(self, args) |
| 3354 | PyObject *self; |
| 3355 | PyObject *args; |
| 3356 | { |
| 3357 | char buffer[L_tmpnam]; |
| 3358 | char *name; |
| 3359 | |
| 3360 | if (!PyArg_ParseTuple(args, ":tmpnam")) |
| 3361 | return NULL; |
Greg Ward | b48bc17 | 2000-03-01 21:51:56 +0000 | [diff] [blame] | 3362 | #ifdef USE_TMPNAM_R |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3363 | name = tmpnam_r(buffer); |
| 3364 | #else |
| 3365 | name = tmpnam(buffer); |
| 3366 | #endif |
| 3367 | if (name == NULL) { |
| 3368 | PyErr_SetObject(PyExc_OSError, |
| 3369 | Py_BuildValue("is", 0, |
Greg Ward | b48bc17 | 2000-03-01 21:51:56 +0000 | [diff] [blame] | 3370 | #ifdef USE_TMPNAM_R |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 3371 | "unexpected NULL from tmpnam_r" |
| 3372 | #else |
| 3373 | "unexpected NULL from tmpnam" |
| 3374 | #endif |
| 3375 | )); |
| 3376 | return NULL; |
| 3377 | } |
| 3378 | return PyString_FromString(buffer); |
| 3379 | } |
| 3380 | #endif |
| 3381 | |
| 3382 | |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3383 | /* This is used for fpathconf(), pathconf(), confstr() and sysconf(). |
| 3384 | * It maps strings representing configuration variable names to |
| 3385 | * integer values, allowing those functions to be called with the |
| 3386 | * magic names instead of poluting the module's namespace with tons of |
Fred Drake | 12c6e2d | 1999-12-14 21:25:03 +0000 | [diff] [blame] | 3387 | * rarely-used constants. There are three separate tables that use |
| 3388 | * these definitions. |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 3389 | * |
| 3390 | * This code is always included, even if none of the interfaces that |
| 3391 | * need it are included. The #if hackery needed to avoid it would be |
| 3392 | * sufficiently pervasive that it's not worth the loss of readability. |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3393 | */ |
| 3394 | struct constdef { |
| 3395 | char *name; |
| 3396 | long value; |
| 3397 | }; |
| 3398 | |
Fred Drake | 12c6e2d | 1999-12-14 21:25:03 +0000 | [diff] [blame] | 3399 | static int |
| 3400 | conv_confname(arg, valuep, table, tablesize) |
| 3401 | PyObject *arg; |
| 3402 | int *valuep; |
| 3403 | struct constdef *table; |
| 3404 | size_t tablesize; |
| 3405 | { |
| 3406 | if (PyInt_Check(arg)) { |
| 3407 | *valuep = PyInt_AS_LONG(arg); |
| 3408 | return 1; |
| 3409 | } |
| 3410 | if (PyString_Check(arg)) { |
| 3411 | /* look up the value in the table using a binary search */ |
| 3412 | int lo = 0; |
| 3413 | int hi = tablesize; |
| 3414 | int cmp, mid; |
| 3415 | char *confname = PyString_AS_STRING(arg); |
| 3416 | while (lo < hi) { |
| 3417 | mid = (lo + hi) / 2; |
| 3418 | cmp = strcmp(confname, table[mid].name); |
| 3419 | if (cmp < 0) |
| 3420 | hi = mid; |
| 3421 | else if (cmp > 0) |
| 3422 | lo = mid + 1; |
| 3423 | else { |
| 3424 | *valuep = table[mid].value; |
| 3425 | return 1; |
| 3426 | } |
| 3427 | } |
| 3428 | PyErr_SetString(PyExc_ValueError, "unrecognized configuration name"); |
| 3429 | } |
| 3430 | else |
| 3431 | PyErr_SetString(PyExc_TypeError, |
| 3432 | "configuration names must be strings or integers"); |
| 3433 | return 0; |
| 3434 | } |
| 3435 | |
| 3436 | |
| 3437 | #if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF) |
| 3438 | static struct constdef posix_constants_pathconf[] = { |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3439 | #ifdef _PC_ABI_AIO_XFER_MAX |
| 3440 | {"PC_ABI_AIO_XFER_MAX", _PC_ABI_AIO_XFER_MAX}, |
| 3441 | #endif |
| 3442 | #ifdef _PC_ABI_ASYNC_IO |
| 3443 | {"PC_ABI_ASYNC_IO", _PC_ABI_ASYNC_IO}, |
| 3444 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3445 | #ifdef _PC_ASYNC_IO |
| 3446 | {"PC_ASYNC_IO", _PC_ASYNC_IO}, |
| 3447 | #endif |
| 3448 | #ifdef _PC_CHOWN_RESTRICTED |
| 3449 | {"PC_CHOWN_RESTRICTED", _PC_CHOWN_RESTRICTED}, |
| 3450 | #endif |
| 3451 | #ifdef _PC_FILESIZEBITS |
| 3452 | {"PC_FILESIZEBITS", _PC_FILESIZEBITS}, |
| 3453 | #endif |
| 3454 | #ifdef _PC_LAST |
| 3455 | {"PC_LAST", _PC_LAST}, |
| 3456 | #endif |
| 3457 | #ifdef _PC_LINK_MAX |
| 3458 | {"PC_LINK_MAX", _PC_LINK_MAX}, |
| 3459 | #endif |
| 3460 | #ifdef _PC_MAX_CANON |
| 3461 | {"PC_MAX_CANON", _PC_MAX_CANON}, |
| 3462 | #endif |
| 3463 | #ifdef _PC_MAX_INPUT |
| 3464 | {"PC_MAX_INPUT", _PC_MAX_INPUT}, |
| 3465 | #endif |
| 3466 | #ifdef _PC_NAME_MAX |
| 3467 | {"PC_NAME_MAX", _PC_NAME_MAX}, |
| 3468 | #endif |
| 3469 | #ifdef _PC_NO_TRUNC |
| 3470 | {"PC_NO_TRUNC", _PC_NO_TRUNC}, |
| 3471 | #endif |
| 3472 | #ifdef _PC_PATH_MAX |
| 3473 | {"PC_PATH_MAX", _PC_PATH_MAX}, |
| 3474 | #endif |
| 3475 | #ifdef _PC_PIPE_BUF |
| 3476 | {"PC_PIPE_BUF", _PC_PIPE_BUF}, |
| 3477 | #endif |
| 3478 | #ifdef _PC_PRIO_IO |
| 3479 | {"PC_PRIO_IO", _PC_PRIO_IO}, |
| 3480 | #endif |
| 3481 | #ifdef _PC_SOCK_MAXBUF |
| 3482 | {"PC_SOCK_MAXBUF", _PC_SOCK_MAXBUF}, |
| 3483 | #endif |
| 3484 | #ifdef _PC_SYNC_IO |
| 3485 | {"PC_SYNC_IO", _PC_SYNC_IO}, |
| 3486 | #endif |
| 3487 | #ifdef _PC_VDISABLE |
| 3488 | {"PC_VDISABLE", _PC_VDISABLE}, |
| 3489 | #endif |
| 3490 | }; |
| 3491 | |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3492 | static int |
| 3493 | conv_path_confname(arg, valuep) |
| 3494 | PyObject *arg; |
| 3495 | int *valuep; |
| 3496 | { |
| 3497 | return conv_confname(arg, valuep, posix_constants_pathconf, |
| 3498 | sizeof(posix_constants_pathconf) |
| 3499 | / sizeof(struct constdef)); |
| 3500 | } |
| 3501 | #endif |
| 3502 | |
| 3503 | #ifdef HAVE_FPATHCONF |
| 3504 | static char posix_fpathconf__doc__[] = "\ |
| 3505 | fpathconf(fd, name) -> integer\n\ |
| 3506 | Return the configuration limit name for the file descriptor fd.\n\ |
| 3507 | If there is no limit, return -1."; |
| 3508 | |
| 3509 | static PyObject * |
| 3510 | posix_fpathconf(self, args) |
| 3511 | PyObject *self; |
| 3512 | PyObject *args; |
| 3513 | { |
| 3514 | PyObject *result = NULL; |
| 3515 | int name, fd; |
| 3516 | |
Fred Drake | 12c6e2d | 1999-12-14 21:25:03 +0000 | [diff] [blame] | 3517 | if (PyArg_ParseTuple(args, "iO&:fpathconf", &fd, |
| 3518 | conv_path_confname, &name)) { |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3519 | long limit; |
| 3520 | |
| 3521 | errno = 0; |
| 3522 | limit = fpathconf(fd, name); |
| 3523 | if (limit == -1 && errno != 0) |
| 3524 | posix_error(); |
| 3525 | else |
| 3526 | result = PyInt_FromLong(limit); |
| 3527 | } |
| 3528 | return result; |
| 3529 | } |
| 3530 | #endif |
| 3531 | |
| 3532 | |
| 3533 | #ifdef HAVE_PATHCONF |
| 3534 | static char posix_pathconf__doc__[] = "\ |
| 3535 | pathconf(path, name) -> integer\n\ |
| 3536 | Return the configuration limit name for the file or directory path.\n\ |
| 3537 | If there is no limit, return -1."; |
| 3538 | |
| 3539 | static PyObject * |
| 3540 | posix_pathconf(self, args) |
| 3541 | PyObject *self; |
| 3542 | PyObject *args; |
| 3543 | { |
| 3544 | PyObject *result = NULL; |
| 3545 | int name; |
| 3546 | char *path; |
| 3547 | |
| 3548 | if (PyArg_ParseTuple(args, "sO&:pathconf", &path, |
| 3549 | conv_path_confname, &name)) { |
| 3550 | long limit; |
| 3551 | |
| 3552 | errno = 0; |
| 3553 | limit = pathconf(path, name); |
Fred Drake | 12c6e2d | 1999-12-14 21:25:03 +0000 | [diff] [blame] | 3554 | if (limit == -1 && errno != 0) { |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3555 | if (errno == EINVAL) |
| 3556 | /* could be a path or name problem */ |
| 3557 | posix_error(); |
| 3558 | else |
| 3559 | posix_error_with_filename(path); |
Fred Drake | 12c6e2d | 1999-12-14 21:25:03 +0000 | [diff] [blame] | 3560 | } |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3561 | else |
| 3562 | result = PyInt_FromLong(limit); |
| 3563 | } |
| 3564 | return result; |
| 3565 | } |
| 3566 | #endif |
| 3567 | |
| 3568 | #ifdef HAVE_CONFSTR |
| 3569 | static struct constdef posix_constants_confstr[] = { |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3570 | #ifdef _CS_ARCHITECTURE |
| 3571 | {"CS_ARCHITECTURE", _CS_ARCHITECTURE}, |
| 3572 | #endif |
| 3573 | #ifdef _CS_HOSTNAME |
| 3574 | {"CS_HOSTNAME", _CS_HOSTNAME}, |
| 3575 | #endif |
| 3576 | #ifdef _CS_HW_PROVIDER |
| 3577 | {"CS_HW_PROVIDER", _CS_HW_PROVIDER}, |
| 3578 | #endif |
| 3579 | #ifdef _CS_HW_SERIAL |
| 3580 | {"CS_HW_SERIAL", _CS_HW_SERIAL}, |
| 3581 | #endif |
| 3582 | #ifdef _CS_INITTAB_NAME |
| 3583 | {"CS_INITTAB_NAME", _CS_INITTAB_NAME}, |
| 3584 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3585 | #ifdef _CS_LFS64_CFLAGS |
| 3586 | {"CS_LFS64_CFLAGS", _CS_LFS64_CFLAGS}, |
| 3587 | #endif |
| 3588 | #ifdef _CS_LFS64_LDFLAGS |
| 3589 | {"CS_LFS64_LDFLAGS", _CS_LFS64_LDFLAGS}, |
| 3590 | #endif |
| 3591 | #ifdef _CS_LFS64_LIBS |
| 3592 | {"CS_LFS64_LIBS", _CS_LFS64_LIBS}, |
| 3593 | #endif |
| 3594 | #ifdef _CS_LFS64_LINTFLAGS |
| 3595 | {"CS_LFS64_LINTFLAGS", _CS_LFS64_LINTFLAGS}, |
| 3596 | #endif |
| 3597 | #ifdef _CS_LFS_CFLAGS |
| 3598 | {"CS_LFS_CFLAGS", _CS_LFS_CFLAGS}, |
| 3599 | #endif |
| 3600 | #ifdef _CS_LFS_LDFLAGS |
| 3601 | {"CS_LFS_LDFLAGS", _CS_LFS_LDFLAGS}, |
| 3602 | #endif |
| 3603 | #ifdef _CS_LFS_LIBS |
| 3604 | {"CS_LFS_LIBS", _CS_LFS_LIBS}, |
| 3605 | #endif |
| 3606 | #ifdef _CS_LFS_LINTFLAGS |
| 3607 | {"CS_LFS_LINTFLAGS", _CS_LFS_LINTFLAGS}, |
| 3608 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3609 | #ifdef _CS_MACHINE |
| 3610 | {"CS_MACHINE", _CS_MACHINE}, |
| 3611 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3612 | #ifdef _CS_PATH |
| 3613 | {"CS_PATH", _CS_PATH}, |
| 3614 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3615 | #ifdef _CS_RELEASE |
| 3616 | {"CS_RELEASE", _CS_RELEASE}, |
| 3617 | #endif |
| 3618 | #ifdef _CS_SRPC_DOMAIN |
| 3619 | {"CS_SRPC_DOMAIN", _CS_SRPC_DOMAIN}, |
| 3620 | #endif |
| 3621 | #ifdef _CS_SYSNAME |
| 3622 | {"CS_SYSNAME", _CS_SYSNAME}, |
| 3623 | #endif |
| 3624 | #ifdef _CS_VERSION |
| 3625 | {"CS_VERSION", _CS_VERSION}, |
| 3626 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3627 | #ifdef _CS_XBS5_ILP32_OFF32_CFLAGS |
| 3628 | {"CS_XBS5_ILP32_OFF32_CFLAGS", _CS_XBS5_ILP32_OFF32_CFLAGS}, |
| 3629 | #endif |
| 3630 | #ifdef _CS_XBS5_ILP32_OFF32_LDFLAGS |
| 3631 | {"CS_XBS5_ILP32_OFF32_LDFLAGS", _CS_XBS5_ILP32_OFF32_LDFLAGS}, |
| 3632 | #endif |
| 3633 | #ifdef _CS_XBS5_ILP32_OFF32_LIBS |
| 3634 | {"CS_XBS5_ILP32_OFF32_LIBS", _CS_XBS5_ILP32_OFF32_LIBS}, |
| 3635 | #endif |
| 3636 | #ifdef _CS_XBS5_ILP32_OFF32_LINTFLAGS |
| 3637 | {"CS_XBS5_ILP32_OFF32_LINTFLAGS", _CS_XBS5_ILP32_OFF32_LINTFLAGS}, |
| 3638 | #endif |
| 3639 | #ifdef _CS_XBS5_ILP32_OFFBIG_CFLAGS |
| 3640 | {"CS_XBS5_ILP32_OFFBIG_CFLAGS", _CS_XBS5_ILP32_OFFBIG_CFLAGS}, |
| 3641 | #endif |
| 3642 | #ifdef _CS_XBS5_ILP32_OFFBIG_LDFLAGS |
| 3643 | {"CS_XBS5_ILP32_OFFBIG_LDFLAGS", _CS_XBS5_ILP32_OFFBIG_LDFLAGS}, |
| 3644 | #endif |
| 3645 | #ifdef _CS_XBS5_ILP32_OFFBIG_LIBS |
| 3646 | {"CS_XBS5_ILP32_OFFBIG_LIBS", _CS_XBS5_ILP32_OFFBIG_LIBS}, |
| 3647 | #endif |
| 3648 | #ifdef _CS_XBS5_ILP32_OFFBIG_LINTFLAGS |
| 3649 | {"CS_XBS5_ILP32_OFFBIG_LINTFLAGS", _CS_XBS5_ILP32_OFFBIG_LINTFLAGS}, |
| 3650 | #endif |
| 3651 | #ifdef _CS_XBS5_LP64_OFF64_CFLAGS |
| 3652 | {"CS_XBS5_LP64_OFF64_CFLAGS", _CS_XBS5_LP64_OFF64_CFLAGS}, |
| 3653 | #endif |
| 3654 | #ifdef _CS_XBS5_LP64_OFF64_LDFLAGS |
| 3655 | {"CS_XBS5_LP64_OFF64_LDFLAGS", _CS_XBS5_LP64_OFF64_LDFLAGS}, |
| 3656 | #endif |
| 3657 | #ifdef _CS_XBS5_LP64_OFF64_LIBS |
| 3658 | {"CS_XBS5_LP64_OFF64_LIBS", _CS_XBS5_LP64_OFF64_LIBS}, |
| 3659 | #endif |
| 3660 | #ifdef _CS_XBS5_LP64_OFF64_LINTFLAGS |
| 3661 | {"CS_XBS5_LP64_OFF64_LINTFLAGS", _CS_XBS5_LP64_OFF64_LINTFLAGS}, |
| 3662 | #endif |
| 3663 | #ifdef _CS_XBS5_LPBIG_OFFBIG_CFLAGS |
| 3664 | {"CS_XBS5_LPBIG_OFFBIG_CFLAGS", _CS_XBS5_LPBIG_OFFBIG_CFLAGS}, |
| 3665 | #endif |
| 3666 | #ifdef _CS_XBS5_LPBIG_OFFBIG_LDFLAGS |
| 3667 | {"CS_XBS5_LPBIG_OFFBIG_LDFLAGS", _CS_XBS5_LPBIG_OFFBIG_LDFLAGS}, |
| 3668 | #endif |
| 3669 | #ifdef _CS_XBS5_LPBIG_OFFBIG_LIBS |
| 3670 | {"CS_XBS5_LPBIG_OFFBIG_LIBS", _CS_XBS5_LPBIG_OFFBIG_LIBS}, |
| 3671 | #endif |
| 3672 | #ifdef _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS |
| 3673 | {"CS_XBS5_LPBIG_OFFBIG_LINTFLAGS", _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS}, |
| 3674 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3675 | #ifdef _MIPS_CS_AVAIL_PROCESSORS |
| 3676 | {"MIPS_CS_AVAIL_PROCESSORS", _MIPS_CS_AVAIL_PROCESSORS}, |
| 3677 | #endif |
| 3678 | #ifdef _MIPS_CS_BASE |
| 3679 | {"MIPS_CS_BASE", _MIPS_CS_BASE}, |
| 3680 | #endif |
| 3681 | #ifdef _MIPS_CS_HOSTID |
| 3682 | {"MIPS_CS_HOSTID", _MIPS_CS_HOSTID}, |
| 3683 | #endif |
| 3684 | #ifdef _MIPS_CS_HW_NAME |
| 3685 | {"MIPS_CS_HW_NAME", _MIPS_CS_HW_NAME}, |
| 3686 | #endif |
| 3687 | #ifdef _MIPS_CS_NUM_PROCESSORS |
| 3688 | {"MIPS_CS_NUM_PROCESSORS", _MIPS_CS_NUM_PROCESSORS}, |
| 3689 | #endif |
| 3690 | #ifdef _MIPS_CS_OSREL_MAJ |
| 3691 | {"MIPS_CS_OSREL_MAJ", _MIPS_CS_OSREL_MAJ}, |
| 3692 | #endif |
| 3693 | #ifdef _MIPS_CS_OSREL_MIN |
| 3694 | {"MIPS_CS_OSREL_MIN", _MIPS_CS_OSREL_MIN}, |
| 3695 | #endif |
| 3696 | #ifdef _MIPS_CS_OSREL_PATCH |
| 3697 | {"MIPS_CS_OSREL_PATCH", _MIPS_CS_OSREL_PATCH}, |
| 3698 | #endif |
| 3699 | #ifdef _MIPS_CS_OS_NAME |
| 3700 | {"MIPS_CS_OS_NAME", _MIPS_CS_OS_NAME}, |
| 3701 | #endif |
| 3702 | #ifdef _MIPS_CS_OS_PROVIDER |
| 3703 | {"MIPS_CS_OS_PROVIDER", _MIPS_CS_OS_PROVIDER}, |
| 3704 | #endif |
| 3705 | #ifdef _MIPS_CS_PROCESSORS |
| 3706 | {"MIPS_CS_PROCESSORS", _MIPS_CS_PROCESSORS}, |
| 3707 | #endif |
| 3708 | #ifdef _MIPS_CS_SERIAL |
| 3709 | {"MIPS_CS_SERIAL", _MIPS_CS_SERIAL}, |
| 3710 | #endif |
| 3711 | #ifdef _MIPS_CS_VENDOR |
| 3712 | {"MIPS_CS_VENDOR", _MIPS_CS_VENDOR}, |
| 3713 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3714 | }; |
| 3715 | |
| 3716 | static int |
| 3717 | conv_confstr_confname(arg, valuep) |
| 3718 | PyObject *arg; |
| 3719 | int *valuep; |
| 3720 | { |
| 3721 | return conv_confname(arg, valuep, posix_constants_confstr, |
| 3722 | sizeof(posix_constants_confstr) |
| 3723 | / sizeof(struct constdef)); |
| 3724 | } |
| 3725 | |
| 3726 | static char posix_confstr__doc__[] = "\ |
| 3727 | confstr(name) -> string\n\ |
| 3728 | Return a string-valued system configuration variable."; |
| 3729 | |
| 3730 | static PyObject * |
| 3731 | posix_confstr(self, args) |
| 3732 | PyObject *self; |
| 3733 | PyObject *args; |
| 3734 | { |
| 3735 | PyObject *result = NULL; |
| 3736 | int name; |
| 3737 | char buffer[64]; |
| 3738 | |
| 3739 | if (PyArg_ParseTuple(args, "O&:confstr", conv_confstr_confname, &name)) { |
| 3740 | int len = confstr(name, buffer, sizeof(buffer)); |
| 3741 | |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3742 | errno = 0; |
| 3743 | if (len == 0) { |
| 3744 | if (errno != 0) |
| 3745 | posix_error(); |
| 3746 | else |
| 3747 | result = PyString_FromString(""); |
| 3748 | } |
| 3749 | else { |
| 3750 | if (len >= sizeof(buffer)) { |
| 3751 | result = PyString_FromStringAndSize(NULL, len); |
| 3752 | if (result != NULL) |
| 3753 | confstr(name, PyString_AS_STRING(result), len+1); |
| 3754 | } |
| 3755 | else |
| 3756 | result = PyString_FromString(buffer); |
| 3757 | } |
| 3758 | } |
| 3759 | return result; |
| 3760 | } |
| 3761 | #endif |
| 3762 | |
| 3763 | |
| 3764 | #ifdef HAVE_SYSCONF |
| 3765 | static struct constdef posix_constants_sysconf[] = { |
| 3766 | #ifdef _SC_2_CHAR_TERM |
| 3767 | {"SC_2_CHAR_TERM", _SC_2_CHAR_TERM}, |
| 3768 | #endif |
| 3769 | #ifdef _SC_2_C_BIND |
| 3770 | {"SC_2_C_BIND", _SC_2_C_BIND}, |
| 3771 | #endif |
| 3772 | #ifdef _SC_2_C_DEV |
| 3773 | {"SC_2_C_DEV", _SC_2_C_DEV}, |
| 3774 | #endif |
| 3775 | #ifdef _SC_2_C_VERSION |
| 3776 | {"SC_2_C_VERSION", _SC_2_C_VERSION}, |
| 3777 | #endif |
| 3778 | #ifdef _SC_2_FORT_DEV |
| 3779 | {"SC_2_FORT_DEV", _SC_2_FORT_DEV}, |
| 3780 | #endif |
| 3781 | #ifdef _SC_2_FORT_RUN |
| 3782 | {"SC_2_FORT_RUN", _SC_2_FORT_RUN}, |
| 3783 | #endif |
| 3784 | #ifdef _SC_2_LOCALEDEF |
| 3785 | {"SC_2_LOCALEDEF", _SC_2_LOCALEDEF}, |
| 3786 | #endif |
| 3787 | #ifdef _SC_2_SW_DEV |
| 3788 | {"SC_2_SW_DEV", _SC_2_SW_DEV}, |
| 3789 | #endif |
| 3790 | #ifdef _SC_2_UPE |
| 3791 | {"SC_2_UPE", _SC_2_UPE}, |
| 3792 | #endif |
| 3793 | #ifdef _SC_2_VERSION |
| 3794 | {"SC_2_VERSION", _SC_2_VERSION}, |
| 3795 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3796 | #ifdef _SC_ABI_ASYNCHRONOUS_IO |
| 3797 | {"SC_ABI_ASYNCHRONOUS_IO", _SC_ABI_ASYNCHRONOUS_IO}, |
| 3798 | #endif |
| 3799 | #ifdef _SC_ACL |
| 3800 | {"SC_ACL", _SC_ACL}, |
| 3801 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3802 | #ifdef _SC_AIO_LISTIO_MAX |
| 3803 | {"SC_AIO_LISTIO_MAX", _SC_AIO_LISTIO_MAX}, |
| 3804 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3805 | #ifdef _SC_AIO_MAX |
| 3806 | {"SC_AIO_MAX", _SC_AIO_MAX}, |
| 3807 | #endif |
| 3808 | #ifdef _SC_AIO_PRIO_DELTA_MAX |
| 3809 | {"SC_AIO_PRIO_DELTA_MAX", _SC_AIO_PRIO_DELTA_MAX}, |
| 3810 | #endif |
| 3811 | #ifdef _SC_ARG_MAX |
| 3812 | {"SC_ARG_MAX", _SC_ARG_MAX}, |
| 3813 | #endif |
| 3814 | #ifdef _SC_ASYNCHRONOUS_IO |
| 3815 | {"SC_ASYNCHRONOUS_IO", _SC_ASYNCHRONOUS_IO}, |
| 3816 | #endif |
| 3817 | #ifdef _SC_ATEXIT_MAX |
| 3818 | {"SC_ATEXIT_MAX", _SC_ATEXIT_MAX}, |
| 3819 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3820 | #ifdef _SC_AUDIT |
| 3821 | {"SC_AUDIT", _SC_AUDIT}, |
| 3822 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3823 | #ifdef _SC_AVPHYS_PAGES |
| 3824 | {"SC_AVPHYS_PAGES", _SC_AVPHYS_PAGES}, |
| 3825 | #endif |
| 3826 | #ifdef _SC_BC_BASE_MAX |
| 3827 | {"SC_BC_BASE_MAX", _SC_BC_BASE_MAX}, |
| 3828 | #endif |
| 3829 | #ifdef _SC_BC_DIM_MAX |
| 3830 | {"SC_BC_DIM_MAX", _SC_BC_DIM_MAX}, |
| 3831 | #endif |
| 3832 | #ifdef _SC_BC_SCALE_MAX |
| 3833 | {"SC_BC_SCALE_MAX", _SC_BC_SCALE_MAX}, |
| 3834 | #endif |
| 3835 | #ifdef _SC_BC_STRING_MAX |
| 3836 | {"SC_BC_STRING_MAX", _SC_BC_STRING_MAX}, |
| 3837 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3838 | #ifdef _SC_CAP |
| 3839 | {"SC_CAP", _SC_CAP}, |
| 3840 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3841 | #ifdef _SC_CHARCLASS_NAME_MAX |
| 3842 | {"SC_CHARCLASS_NAME_MAX", _SC_CHARCLASS_NAME_MAX}, |
| 3843 | #endif |
| 3844 | #ifdef _SC_CHAR_BIT |
| 3845 | {"SC_CHAR_BIT", _SC_CHAR_BIT}, |
| 3846 | #endif |
| 3847 | #ifdef _SC_CHAR_MAX |
| 3848 | {"SC_CHAR_MAX", _SC_CHAR_MAX}, |
| 3849 | #endif |
| 3850 | #ifdef _SC_CHAR_MIN |
| 3851 | {"SC_CHAR_MIN", _SC_CHAR_MIN}, |
| 3852 | #endif |
| 3853 | #ifdef _SC_CHILD_MAX |
| 3854 | {"SC_CHILD_MAX", _SC_CHILD_MAX}, |
| 3855 | #endif |
| 3856 | #ifdef _SC_CLK_TCK |
| 3857 | {"SC_CLK_TCK", _SC_CLK_TCK}, |
| 3858 | #endif |
| 3859 | #ifdef _SC_COHER_BLKSZ |
| 3860 | {"SC_COHER_BLKSZ", _SC_COHER_BLKSZ}, |
| 3861 | #endif |
| 3862 | #ifdef _SC_COLL_WEIGHTS_MAX |
| 3863 | {"SC_COLL_WEIGHTS_MAX", _SC_COLL_WEIGHTS_MAX}, |
| 3864 | #endif |
| 3865 | #ifdef _SC_DCACHE_ASSOC |
| 3866 | {"SC_DCACHE_ASSOC", _SC_DCACHE_ASSOC}, |
| 3867 | #endif |
| 3868 | #ifdef _SC_DCACHE_BLKSZ |
| 3869 | {"SC_DCACHE_BLKSZ", _SC_DCACHE_BLKSZ}, |
| 3870 | #endif |
| 3871 | #ifdef _SC_DCACHE_LINESZ |
| 3872 | {"SC_DCACHE_LINESZ", _SC_DCACHE_LINESZ}, |
| 3873 | #endif |
| 3874 | #ifdef _SC_DCACHE_SZ |
| 3875 | {"SC_DCACHE_SZ", _SC_DCACHE_SZ}, |
| 3876 | #endif |
| 3877 | #ifdef _SC_DCACHE_TBLKSZ |
| 3878 | {"SC_DCACHE_TBLKSZ", _SC_DCACHE_TBLKSZ}, |
| 3879 | #endif |
| 3880 | #ifdef _SC_DELAYTIMER_MAX |
| 3881 | {"SC_DELAYTIMER_MAX", _SC_DELAYTIMER_MAX}, |
| 3882 | #endif |
| 3883 | #ifdef _SC_EQUIV_CLASS_MAX |
| 3884 | {"SC_EQUIV_CLASS_MAX", _SC_EQUIV_CLASS_MAX}, |
| 3885 | #endif |
| 3886 | #ifdef _SC_EXPR_NEST_MAX |
| 3887 | {"SC_EXPR_NEST_MAX", _SC_EXPR_NEST_MAX}, |
| 3888 | #endif |
| 3889 | #ifdef _SC_FSYNC |
| 3890 | {"SC_FSYNC", _SC_FSYNC}, |
| 3891 | #endif |
| 3892 | #ifdef _SC_GETGR_R_SIZE_MAX |
| 3893 | {"SC_GETGR_R_SIZE_MAX", _SC_GETGR_R_SIZE_MAX}, |
| 3894 | #endif |
| 3895 | #ifdef _SC_GETPW_R_SIZE_MAX |
| 3896 | {"SC_GETPW_R_SIZE_MAX", _SC_GETPW_R_SIZE_MAX}, |
| 3897 | #endif |
| 3898 | #ifdef _SC_ICACHE_ASSOC |
| 3899 | {"SC_ICACHE_ASSOC", _SC_ICACHE_ASSOC}, |
| 3900 | #endif |
| 3901 | #ifdef _SC_ICACHE_BLKSZ |
| 3902 | {"SC_ICACHE_BLKSZ", _SC_ICACHE_BLKSZ}, |
| 3903 | #endif |
| 3904 | #ifdef _SC_ICACHE_LINESZ |
| 3905 | {"SC_ICACHE_LINESZ", _SC_ICACHE_LINESZ}, |
| 3906 | #endif |
| 3907 | #ifdef _SC_ICACHE_SZ |
| 3908 | {"SC_ICACHE_SZ", _SC_ICACHE_SZ}, |
| 3909 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3910 | #ifdef _SC_INF |
| 3911 | {"SC_INF", _SC_INF}, |
| 3912 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3913 | #ifdef _SC_INT_MAX |
| 3914 | {"SC_INT_MAX", _SC_INT_MAX}, |
| 3915 | #endif |
| 3916 | #ifdef _SC_INT_MIN |
| 3917 | {"SC_INT_MIN", _SC_INT_MIN}, |
| 3918 | #endif |
| 3919 | #ifdef _SC_IOV_MAX |
| 3920 | {"SC_IOV_MAX", _SC_IOV_MAX}, |
| 3921 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3922 | #ifdef _SC_IP_SECOPTS |
| 3923 | {"SC_IP_SECOPTS", _SC_IP_SECOPTS}, |
| 3924 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3925 | #ifdef _SC_JOB_CONTROL |
| 3926 | {"SC_JOB_CONTROL", _SC_JOB_CONTROL}, |
| 3927 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3928 | #ifdef _SC_KERN_POINTERS |
| 3929 | {"SC_KERN_POINTERS", _SC_KERN_POINTERS}, |
| 3930 | #endif |
| 3931 | #ifdef _SC_KERN_SIM |
| 3932 | {"SC_KERN_SIM", _SC_KERN_SIM}, |
| 3933 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3934 | #ifdef _SC_LINE_MAX |
| 3935 | {"SC_LINE_MAX", _SC_LINE_MAX}, |
| 3936 | #endif |
| 3937 | #ifdef _SC_LOGIN_NAME_MAX |
| 3938 | {"SC_LOGIN_NAME_MAX", _SC_LOGIN_NAME_MAX}, |
| 3939 | #endif |
| 3940 | #ifdef _SC_LOGNAME_MAX |
| 3941 | {"SC_LOGNAME_MAX", _SC_LOGNAME_MAX}, |
| 3942 | #endif |
| 3943 | #ifdef _SC_LONG_BIT |
| 3944 | {"SC_LONG_BIT", _SC_LONG_BIT}, |
| 3945 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3946 | #ifdef _SC_MAC |
| 3947 | {"SC_MAC", _SC_MAC}, |
| 3948 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3949 | #ifdef _SC_MAPPED_FILES |
| 3950 | {"SC_MAPPED_FILES", _SC_MAPPED_FILES}, |
| 3951 | #endif |
| 3952 | #ifdef _SC_MAXPID |
| 3953 | {"SC_MAXPID", _SC_MAXPID}, |
| 3954 | #endif |
| 3955 | #ifdef _SC_MB_LEN_MAX |
| 3956 | {"SC_MB_LEN_MAX", _SC_MB_LEN_MAX}, |
| 3957 | #endif |
| 3958 | #ifdef _SC_MEMLOCK |
| 3959 | {"SC_MEMLOCK", _SC_MEMLOCK}, |
| 3960 | #endif |
| 3961 | #ifdef _SC_MEMLOCK_RANGE |
| 3962 | {"SC_MEMLOCK_RANGE", _SC_MEMLOCK_RANGE}, |
| 3963 | #endif |
| 3964 | #ifdef _SC_MEMORY_PROTECTION |
| 3965 | {"SC_MEMORY_PROTECTION", _SC_MEMORY_PROTECTION}, |
| 3966 | #endif |
| 3967 | #ifdef _SC_MESSAGE_PASSING |
| 3968 | {"SC_MESSAGE_PASSING", _SC_MESSAGE_PASSING}, |
| 3969 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3970 | #ifdef _SC_MMAP_FIXED_ALIGNMENT |
| 3971 | {"SC_MMAP_FIXED_ALIGNMENT", _SC_MMAP_FIXED_ALIGNMENT}, |
| 3972 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3973 | #ifdef _SC_MQ_OPEN_MAX |
| 3974 | {"SC_MQ_OPEN_MAX", _SC_MQ_OPEN_MAX}, |
| 3975 | #endif |
| 3976 | #ifdef _SC_MQ_PRIO_MAX |
| 3977 | {"SC_MQ_PRIO_MAX", _SC_MQ_PRIO_MAX}, |
| 3978 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 3979 | #ifdef _SC_NACLS_MAX |
| 3980 | {"SC_NACLS_MAX", _SC_NACLS_MAX}, |
| 3981 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 3982 | #ifdef _SC_NGROUPS_MAX |
| 3983 | {"SC_NGROUPS_MAX", _SC_NGROUPS_MAX}, |
| 3984 | #endif |
| 3985 | #ifdef _SC_NL_ARGMAX |
| 3986 | {"SC_NL_ARGMAX", _SC_NL_ARGMAX}, |
| 3987 | #endif |
| 3988 | #ifdef _SC_NL_LANGMAX |
| 3989 | {"SC_NL_LANGMAX", _SC_NL_LANGMAX}, |
| 3990 | #endif |
| 3991 | #ifdef _SC_NL_MSGMAX |
| 3992 | {"SC_NL_MSGMAX", _SC_NL_MSGMAX}, |
| 3993 | #endif |
| 3994 | #ifdef _SC_NL_NMAX |
| 3995 | {"SC_NL_NMAX", _SC_NL_NMAX}, |
| 3996 | #endif |
| 3997 | #ifdef _SC_NL_SETMAX |
| 3998 | {"SC_NL_SETMAX", _SC_NL_SETMAX}, |
| 3999 | #endif |
| 4000 | #ifdef _SC_NL_TEXTMAX |
| 4001 | {"SC_NL_TEXTMAX", _SC_NL_TEXTMAX}, |
| 4002 | #endif |
| 4003 | #ifdef _SC_NPROCESSORS_CONF |
| 4004 | {"SC_NPROCESSORS_CONF", _SC_NPROCESSORS_CONF}, |
| 4005 | #endif |
| 4006 | #ifdef _SC_NPROCESSORS_ONLN |
| 4007 | {"SC_NPROCESSORS_ONLN", _SC_NPROCESSORS_ONLN}, |
| 4008 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4009 | #ifdef _SC_NPROC_CONF |
| 4010 | {"SC_NPROC_CONF", _SC_NPROC_CONF}, |
| 4011 | #endif |
| 4012 | #ifdef _SC_NPROC_ONLN |
| 4013 | {"SC_NPROC_ONLN", _SC_NPROC_ONLN}, |
| 4014 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 4015 | #ifdef _SC_NZERO |
| 4016 | {"SC_NZERO", _SC_NZERO}, |
| 4017 | #endif |
| 4018 | #ifdef _SC_OPEN_MAX |
| 4019 | {"SC_OPEN_MAX", _SC_OPEN_MAX}, |
| 4020 | #endif |
| 4021 | #ifdef _SC_PAGESIZE |
| 4022 | {"SC_PAGESIZE", _SC_PAGESIZE}, |
| 4023 | #endif |
| 4024 | #ifdef _SC_PAGE_SIZE |
| 4025 | {"SC_PAGE_SIZE", _SC_PAGE_SIZE}, |
| 4026 | #endif |
| 4027 | #ifdef _SC_PASS_MAX |
| 4028 | {"SC_PASS_MAX", _SC_PASS_MAX}, |
| 4029 | #endif |
| 4030 | #ifdef _SC_PHYS_PAGES |
| 4031 | {"SC_PHYS_PAGES", _SC_PHYS_PAGES}, |
| 4032 | #endif |
| 4033 | #ifdef _SC_PII |
| 4034 | {"SC_PII", _SC_PII}, |
| 4035 | #endif |
| 4036 | #ifdef _SC_PII_INTERNET |
| 4037 | {"SC_PII_INTERNET", _SC_PII_INTERNET}, |
| 4038 | #endif |
| 4039 | #ifdef _SC_PII_INTERNET_DGRAM |
| 4040 | {"SC_PII_INTERNET_DGRAM", _SC_PII_INTERNET_DGRAM}, |
| 4041 | #endif |
| 4042 | #ifdef _SC_PII_INTERNET_STREAM |
| 4043 | {"SC_PII_INTERNET_STREAM", _SC_PII_INTERNET_STREAM}, |
| 4044 | #endif |
| 4045 | #ifdef _SC_PII_OSI |
| 4046 | {"SC_PII_OSI", _SC_PII_OSI}, |
| 4047 | #endif |
| 4048 | #ifdef _SC_PII_OSI_CLTS |
| 4049 | {"SC_PII_OSI_CLTS", _SC_PII_OSI_CLTS}, |
| 4050 | #endif |
| 4051 | #ifdef _SC_PII_OSI_COTS |
| 4052 | {"SC_PII_OSI_COTS", _SC_PII_OSI_COTS}, |
| 4053 | #endif |
| 4054 | #ifdef _SC_PII_OSI_M |
| 4055 | {"SC_PII_OSI_M", _SC_PII_OSI_M}, |
| 4056 | #endif |
| 4057 | #ifdef _SC_PII_SOCKET |
| 4058 | {"SC_PII_SOCKET", _SC_PII_SOCKET}, |
| 4059 | #endif |
| 4060 | #ifdef _SC_PII_XTI |
| 4061 | {"SC_PII_XTI", _SC_PII_XTI}, |
| 4062 | #endif |
| 4063 | #ifdef _SC_POLL |
| 4064 | {"SC_POLL", _SC_POLL}, |
| 4065 | #endif |
| 4066 | #ifdef _SC_PRIORITIZED_IO |
| 4067 | {"SC_PRIORITIZED_IO", _SC_PRIORITIZED_IO}, |
| 4068 | #endif |
| 4069 | #ifdef _SC_PRIORITY_SCHEDULING |
| 4070 | {"SC_PRIORITY_SCHEDULING", _SC_PRIORITY_SCHEDULING}, |
| 4071 | #endif |
| 4072 | #ifdef _SC_REALTIME_SIGNALS |
| 4073 | {"SC_REALTIME_SIGNALS", _SC_REALTIME_SIGNALS}, |
| 4074 | #endif |
| 4075 | #ifdef _SC_RE_DUP_MAX |
| 4076 | {"SC_RE_DUP_MAX", _SC_RE_DUP_MAX}, |
| 4077 | #endif |
| 4078 | #ifdef _SC_RTSIG_MAX |
| 4079 | {"SC_RTSIG_MAX", _SC_RTSIG_MAX}, |
| 4080 | #endif |
| 4081 | #ifdef _SC_SAVED_IDS |
| 4082 | {"SC_SAVED_IDS", _SC_SAVED_IDS}, |
| 4083 | #endif |
| 4084 | #ifdef _SC_SCHAR_MAX |
| 4085 | {"SC_SCHAR_MAX", _SC_SCHAR_MAX}, |
| 4086 | #endif |
| 4087 | #ifdef _SC_SCHAR_MIN |
| 4088 | {"SC_SCHAR_MIN", _SC_SCHAR_MIN}, |
| 4089 | #endif |
| 4090 | #ifdef _SC_SELECT |
| 4091 | {"SC_SELECT", _SC_SELECT}, |
| 4092 | #endif |
| 4093 | #ifdef _SC_SEMAPHORES |
| 4094 | {"SC_SEMAPHORES", _SC_SEMAPHORES}, |
| 4095 | #endif |
| 4096 | #ifdef _SC_SEM_NSEMS_MAX |
| 4097 | {"SC_SEM_NSEMS_MAX", _SC_SEM_NSEMS_MAX}, |
| 4098 | #endif |
| 4099 | #ifdef _SC_SEM_VALUE_MAX |
| 4100 | {"SC_SEM_VALUE_MAX", _SC_SEM_VALUE_MAX}, |
| 4101 | #endif |
| 4102 | #ifdef _SC_SHARED_MEMORY_OBJECTS |
| 4103 | {"SC_SHARED_MEMORY_OBJECTS", _SC_SHARED_MEMORY_OBJECTS}, |
| 4104 | #endif |
| 4105 | #ifdef _SC_SHRT_MAX |
| 4106 | {"SC_SHRT_MAX", _SC_SHRT_MAX}, |
| 4107 | #endif |
| 4108 | #ifdef _SC_SHRT_MIN |
| 4109 | {"SC_SHRT_MIN", _SC_SHRT_MIN}, |
| 4110 | #endif |
| 4111 | #ifdef _SC_SIGQUEUE_MAX |
| 4112 | {"SC_SIGQUEUE_MAX", _SC_SIGQUEUE_MAX}, |
| 4113 | #endif |
| 4114 | #ifdef _SC_SIGRT_MAX |
| 4115 | {"SC_SIGRT_MAX", _SC_SIGRT_MAX}, |
| 4116 | #endif |
| 4117 | #ifdef _SC_SIGRT_MIN |
| 4118 | {"SC_SIGRT_MIN", _SC_SIGRT_MIN}, |
| 4119 | #endif |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4120 | #ifdef _SC_SOFTPOWER |
| 4121 | {"SC_SOFTPOWER", _SC_SOFTPOWER}, |
| 4122 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 4123 | #ifdef _SC_SPLIT_CACHE |
| 4124 | {"SC_SPLIT_CACHE", _SC_SPLIT_CACHE}, |
| 4125 | #endif |
| 4126 | #ifdef _SC_SSIZE_MAX |
| 4127 | {"SC_SSIZE_MAX", _SC_SSIZE_MAX}, |
| 4128 | #endif |
| 4129 | #ifdef _SC_STACK_PROT |
| 4130 | {"SC_STACK_PROT", _SC_STACK_PROT}, |
| 4131 | #endif |
| 4132 | #ifdef _SC_STREAM_MAX |
| 4133 | {"SC_STREAM_MAX", _SC_STREAM_MAX}, |
| 4134 | #endif |
| 4135 | #ifdef _SC_SYNCHRONIZED_IO |
| 4136 | {"SC_SYNCHRONIZED_IO", _SC_SYNCHRONIZED_IO}, |
| 4137 | #endif |
| 4138 | #ifdef _SC_THREADS |
| 4139 | {"SC_THREADS", _SC_THREADS}, |
| 4140 | #endif |
| 4141 | #ifdef _SC_THREAD_ATTR_STACKADDR |
| 4142 | {"SC_THREAD_ATTR_STACKADDR", _SC_THREAD_ATTR_STACKADDR}, |
| 4143 | #endif |
| 4144 | #ifdef _SC_THREAD_ATTR_STACKSIZE |
| 4145 | {"SC_THREAD_ATTR_STACKSIZE", _SC_THREAD_ATTR_STACKSIZE}, |
| 4146 | #endif |
| 4147 | #ifdef _SC_THREAD_DESTRUCTOR_ITERATIONS |
| 4148 | {"SC_THREAD_DESTRUCTOR_ITERATIONS", _SC_THREAD_DESTRUCTOR_ITERATIONS}, |
| 4149 | #endif |
| 4150 | #ifdef _SC_THREAD_KEYS_MAX |
| 4151 | {"SC_THREAD_KEYS_MAX", _SC_THREAD_KEYS_MAX}, |
| 4152 | #endif |
| 4153 | #ifdef _SC_THREAD_PRIORITY_SCHEDULING |
| 4154 | {"SC_THREAD_PRIORITY_SCHEDULING", _SC_THREAD_PRIORITY_SCHEDULING}, |
| 4155 | #endif |
| 4156 | #ifdef _SC_THREAD_PRIO_INHERIT |
| 4157 | {"SC_THREAD_PRIO_INHERIT", _SC_THREAD_PRIO_INHERIT}, |
| 4158 | #endif |
| 4159 | #ifdef _SC_THREAD_PRIO_PROTECT |
| 4160 | {"SC_THREAD_PRIO_PROTECT", _SC_THREAD_PRIO_PROTECT}, |
| 4161 | #endif |
| 4162 | #ifdef _SC_THREAD_PROCESS_SHARED |
| 4163 | {"SC_THREAD_PROCESS_SHARED", _SC_THREAD_PROCESS_SHARED}, |
| 4164 | #endif |
| 4165 | #ifdef _SC_THREAD_SAFE_FUNCTIONS |
| 4166 | {"SC_THREAD_SAFE_FUNCTIONS", _SC_THREAD_SAFE_FUNCTIONS}, |
| 4167 | #endif |
| 4168 | #ifdef _SC_THREAD_STACK_MIN |
| 4169 | {"SC_THREAD_STACK_MIN", _SC_THREAD_STACK_MIN}, |
| 4170 | #endif |
| 4171 | #ifdef _SC_THREAD_THREADS_MAX |
| 4172 | {"SC_THREAD_THREADS_MAX", _SC_THREAD_THREADS_MAX}, |
| 4173 | #endif |
| 4174 | #ifdef _SC_TIMERS |
| 4175 | {"SC_TIMERS", _SC_TIMERS}, |
| 4176 | #endif |
| 4177 | #ifdef _SC_TIMER_MAX |
| 4178 | {"SC_TIMER_MAX", _SC_TIMER_MAX}, |
| 4179 | #endif |
| 4180 | #ifdef _SC_TTY_NAME_MAX |
| 4181 | {"SC_TTY_NAME_MAX", _SC_TTY_NAME_MAX}, |
| 4182 | #endif |
| 4183 | #ifdef _SC_TZNAME_MAX |
| 4184 | {"SC_TZNAME_MAX", _SC_TZNAME_MAX}, |
| 4185 | #endif |
| 4186 | #ifdef _SC_T_IOV_MAX |
| 4187 | {"SC_T_IOV_MAX", _SC_T_IOV_MAX}, |
| 4188 | #endif |
| 4189 | #ifdef _SC_UCHAR_MAX |
| 4190 | {"SC_UCHAR_MAX", _SC_UCHAR_MAX}, |
| 4191 | #endif |
| 4192 | #ifdef _SC_UINT_MAX |
| 4193 | {"SC_UINT_MAX", _SC_UINT_MAX}, |
| 4194 | #endif |
| 4195 | #ifdef _SC_UIO_MAXIOV |
| 4196 | {"SC_UIO_MAXIOV", _SC_UIO_MAXIOV}, |
| 4197 | #endif |
| 4198 | #ifdef _SC_ULONG_MAX |
| 4199 | {"SC_ULONG_MAX", _SC_ULONG_MAX}, |
| 4200 | #endif |
| 4201 | #ifdef _SC_USHRT_MAX |
| 4202 | {"SC_USHRT_MAX", _SC_USHRT_MAX}, |
| 4203 | #endif |
| 4204 | #ifdef _SC_VERSION |
| 4205 | {"SC_VERSION", _SC_VERSION}, |
| 4206 | #endif |
| 4207 | #ifdef _SC_WORD_BIT |
| 4208 | {"SC_WORD_BIT", _SC_WORD_BIT}, |
| 4209 | #endif |
| 4210 | #ifdef _SC_XBS5_ILP32_OFF32 |
| 4211 | {"SC_XBS5_ILP32_OFF32", _SC_XBS5_ILP32_OFF32}, |
| 4212 | #endif |
| 4213 | #ifdef _SC_XBS5_ILP32_OFFBIG |
| 4214 | {"SC_XBS5_ILP32_OFFBIG", _SC_XBS5_ILP32_OFFBIG}, |
| 4215 | #endif |
| 4216 | #ifdef _SC_XBS5_LP64_OFF64 |
| 4217 | {"SC_XBS5_LP64_OFF64", _SC_XBS5_LP64_OFF64}, |
| 4218 | #endif |
| 4219 | #ifdef _SC_XBS5_LPBIG_OFFBIG |
| 4220 | {"SC_XBS5_LPBIG_OFFBIG", _SC_XBS5_LPBIG_OFFBIG}, |
| 4221 | #endif |
| 4222 | #ifdef _SC_XOPEN_CRYPT |
| 4223 | {"SC_XOPEN_CRYPT", _SC_XOPEN_CRYPT}, |
| 4224 | #endif |
| 4225 | #ifdef _SC_XOPEN_ENH_I18N |
| 4226 | {"SC_XOPEN_ENH_I18N", _SC_XOPEN_ENH_I18N}, |
| 4227 | #endif |
| 4228 | #ifdef _SC_XOPEN_LEGACY |
| 4229 | {"SC_XOPEN_LEGACY", _SC_XOPEN_LEGACY}, |
| 4230 | #endif |
| 4231 | #ifdef _SC_XOPEN_REALTIME |
| 4232 | {"SC_XOPEN_REALTIME", _SC_XOPEN_REALTIME}, |
| 4233 | #endif |
| 4234 | #ifdef _SC_XOPEN_REALTIME_THREADS |
| 4235 | {"SC_XOPEN_REALTIME_THREADS", _SC_XOPEN_REALTIME_THREADS}, |
| 4236 | #endif |
| 4237 | #ifdef _SC_XOPEN_SHM |
| 4238 | {"SC_XOPEN_SHM", _SC_XOPEN_SHM}, |
| 4239 | #endif |
| 4240 | #ifdef _SC_XOPEN_UNIX |
| 4241 | {"SC_XOPEN_UNIX", _SC_XOPEN_UNIX}, |
| 4242 | #endif |
| 4243 | #ifdef _SC_XOPEN_VERSION |
| 4244 | {"SC_XOPEN_VERSION", _SC_XOPEN_VERSION}, |
| 4245 | #endif |
| 4246 | #ifdef _SC_XOPEN_XCU_VERSION |
| 4247 | {"SC_XOPEN_XCU_VERSION", _SC_XOPEN_XCU_VERSION}, |
| 4248 | #endif |
| 4249 | #ifdef _SC_XOPEN_XPG2 |
| 4250 | {"SC_XOPEN_XPG2", _SC_XOPEN_XPG2}, |
| 4251 | #endif |
| 4252 | #ifdef _SC_XOPEN_XPG3 |
| 4253 | {"SC_XOPEN_XPG3", _SC_XOPEN_XPG3}, |
| 4254 | #endif |
| 4255 | #ifdef _SC_XOPEN_XPG4 |
| 4256 | {"SC_XOPEN_XPG4", _SC_XOPEN_XPG4}, |
| 4257 | #endif |
| 4258 | }; |
| 4259 | |
| 4260 | static int |
| 4261 | conv_sysconf_confname(arg, valuep) |
| 4262 | PyObject *arg; |
| 4263 | int *valuep; |
| 4264 | { |
| 4265 | return conv_confname(arg, valuep, posix_constants_sysconf, |
| 4266 | sizeof(posix_constants_sysconf) |
| 4267 | / sizeof(struct constdef)); |
| 4268 | } |
| 4269 | |
| 4270 | static char posix_sysconf__doc__[] = "\ |
| 4271 | sysconf(name) -> integer\n\ |
| 4272 | Return an integer-valued system configuration variable."; |
| 4273 | |
| 4274 | static PyObject * |
| 4275 | posix_sysconf(self, args) |
| 4276 | PyObject *self; |
| 4277 | PyObject *args; |
| 4278 | { |
| 4279 | PyObject *result = NULL; |
| 4280 | int name; |
| 4281 | |
| 4282 | if (PyArg_ParseTuple(args, "O&:sysconf", conv_sysconf_confname, &name)) { |
| 4283 | int value; |
| 4284 | |
| 4285 | errno = 0; |
| 4286 | value = sysconf(name); |
| 4287 | if (value == -1 && errno != 0) |
| 4288 | posix_error(); |
| 4289 | else |
| 4290 | result = PyInt_FromLong(value); |
| 4291 | } |
| 4292 | return result; |
| 4293 | } |
| 4294 | #endif |
| 4295 | |
| 4296 | |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4297 | /* This code is used to ensure that the tables of configuration value names |
| 4298 | * are in sorted order as required by conv_confname(), and also to build the |
| 4299 | * the exported dictionaries that are used to publish information about the |
| 4300 | * names available on the host platform. |
| 4301 | * |
| 4302 | * Sorting the table at runtime ensures that the table is properly ordered |
| 4303 | * when used, even for platforms we're not able to test on. It also makes |
| 4304 | * it easier to add additional entries to the tables. |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4305 | */ |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4306 | |
| 4307 | static int |
| 4308 | cmp_constdefs(v1, v2) |
| 4309 | const void *v1; |
| 4310 | const void *v2; |
| 4311 | { |
| 4312 | const struct constdef *c1 = |
| 4313 | (const struct constdef *) v1; |
| 4314 | const struct constdef *c2 = |
| 4315 | (const struct constdef *) v2; |
| 4316 | |
| 4317 | return strcmp(c1->name, c2->name); |
| 4318 | } |
| 4319 | |
| 4320 | static int |
| 4321 | setup_confname_table(table, tablesize, tablename, moddict) |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4322 | struct constdef *table; |
| 4323 | size_t tablesize; |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4324 | char * tablename; |
| 4325 | PyObject *moddict; |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4326 | { |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4327 | PyObject *d = NULL; |
| 4328 | |
| 4329 | qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs); |
| 4330 | d = PyDict_New(); |
| 4331 | if (d != NULL) { |
| 4332 | PyObject *o; |
Fred Drake | e1a79b9 | 1999-12-30 18:05:43 +0000 | [diff] [blame] | 4333 | size_t i = 0; |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4334 | |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4335 | for (; i < tablesize; ++i) { |
| 4336 | o = PyInt_FromLong(table[i].value); |
| 4337 | if (o == NULL |
| 4338 | || PyDict_SetItemString(d, table[i].name, o) == -1) { |
| 4339 | Py_DECREF(d); |
| 4340 | d = NULL; |
| 4341 | return -1; |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4342 | } |
| 4343 | } |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4344 | if (PyDict_SetItemString(moddict, tablename, d) == -1) |
| 4345 | return -1; |
| 4346 | return 0; |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4347 | } |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4348 | return -1; |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4349 | } |
| 4350 | |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4351 | /* Return -1 on failure, 0 on success. */ |
| 4352 | static int |
| 4353 | setup_confname_tables(moddict) |
| 4354 | PyObject *moddict; |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4355 | { |
| 4356 | #if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF) |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4357 | if (setup_confname_table(posix_constants_pathconf, |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4358 | sizeof(posix_constants_pathconf) |
| 4359 | / sizeof(struct constdef), |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4360 | "pathconf_names", moddict)) |
| 4361 | return -1; |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4362 | #endif |
| 4363 | #ifdef HAVE_CONFSTR |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4364 | if (setup_confname_table(posix_constants_confstr, |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4365 | sizeof(posix_constants_confstr) |
| 4366 | / sizeof(struct constdef), |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4367 | "confstr_names", moddict)) |
| 4368 | return -1; |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4369 | #endif |
| 4370 | #ifdef HAVE_SYSCONF |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4371 | if (setup_confname_table(posix_constants_sysconf, |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4372 | sizeof(posix_constants_sysconf) |
| 4373 | / sizeof(struct constdef), |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4374 | "sysconf_names", moddict)) |
| 4375 | return -1; |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4376 | #endif |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4377 | return 0; |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4378 | } |
Fred Drake | d86ed29 | 1999-12-15 15:34:33 +0000 | [diff] [blame] | 4379 | |
| 4380 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4381 | static char posix_abort__doc__[] = "\ |
| 4382 | abort() -> does not return!\n\ |
| 4383 | Abort the interpreter immediately. This 'dumps core' or otherwise fails\n\ |
| 4384 | in the hardest way possible on the hosting operating system."; |
| 4385 | |
| 4386 | static PyObject * |
| 4387 | posix_abort(self, args) |
| 4388 | PyObject *self; |
| 4389 | PyObject *args; |
| 4390 | { |
| 4391 | if (!PyArg_ParseTuple(args, ":abort")) |
| 4392 | return NULL; |
| 4393 | abort(); |
| 4394 | /*NOTREACHED*/ |
| 4395 | Py_FatalError("abort() called from Python code didn't abort!"); |
| 4396 | return NULL; |
| 4397 | } |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4398 | |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4399 | |
| 4400 | static PyMethodDef posix_methods[] = { |
| 4401 | {"access", posix_access, METH_VARARGS, posix_access__doc__}, |
| 4402 | #ifdef HAVE_TTYNAME |
| 4403 | {"ttyname", posix_ttyname, METH_VARARGS, posix_ttyname__doc__}, |
| 4404 | #endif |
| 4405 | {"chdir", posix_chdir, METH_VARARGS, posix_chdir__doc__}, |
| 4406 | {"chmod", posix_chmod, METH_VARARGS, posix_chmod__doc__}, |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4407 | #ifdef HAVE_CHOWN |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4408 | {"chown", posix_chown, METH_VARARGS, posix_chown__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4409 | #endif /* HAVE_CHOWN */ |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4410 | #ifdef HAVE_CTERMID |
| 4411 | {"ctermid", posix_ctermid, METH_VARARGS, posix_ctermid__doc__}, |
| 4412 | #endif |
Guido van Rossum | 36bc680 | 1995-06-14 22:54:23 +0000 | [diff] [blame] | 4413 | #ifdef HAVE_GETCWD |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4414 | {"getcwd", posix_getcwd, METH_VARARGS, posix_getcwd__doc__}, |
Guido van Rossum | 36bc680 | 1995-06-14 22:54:23 +0000 | [diff] [blame] | 4415 | #endif |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4416 | #ifdef HAVE_LINK |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4417 | {"link", posix_link, METH_VARARGS, posix_link__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4418 | #endif /* HAVE_LINK */ |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4419 | {"listdir", posix_listdir, METH_VARARGS, posix_listdir__doc__}, |
| 4420 | {"lstat", posix_lstat, METH_VARARGS, posix_lstat__doc__}, |
| 4421 | {"mkdir", posix_mkdir, METH_VARARGS, posix_mkdir__doc__}, |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4422 | #ifdef HAVE_NICE |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4423 | {"nice", posix_nice, METH_VARARGS, posix_nice__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4424 | #endif /* HAVE_NICE */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4425 | #ifdef HAVE_READLINK |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4426 | {"readlink", posix_readlink, METH_VARARGS, posix_readlink__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4427 | #endif /* HAVE_READLINK */ |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4428 | {"rename", posix_rename, METH_VARARGS, posix_rename__doc__}, |
| 4429 | {"rmdir", posix_rmdir, METH_VARARGS, posix_rmdir__doc__}, |
| 4430 | {"stat", posix_stat, METH_VARARGS, posix_stat__doc__}, |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4431 | #ifdef HAVE_SYMLINK |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4432 | {"symlink", posix_symlink, METH_VARARGS, posix_symlink__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4433 | #endif /* HAVE_SYMLINK */ |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 4434 | #ifdef HAVE_SYSTEM |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4435 | {"system", posix_system, METH_VARARGS, posix_system__doc__}, |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 4436 | #endif |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4437 | {"umask", posix_umask, METH_VARARGS, posix_umask__doc__}, |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4438 | #ifdef HAVE_UNAME |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4439 | {"uname", posix_uname, METH_VARARGS, posix_uname__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4440 | #endif /* HAVE_UNAME */ |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4441 | {"unlink", posix_unlink, METH_VARARGS, posix_unlink__doc__}, |
| 4442 | {"remove", posix_unlink, METH_VARARGS, posix_remove__doc__}, |
| 4443 | {"utime", posix_utime, METH_VARARGS, posix_utime__doc__}, |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4444 | #ifdef HAVE_TIMES |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4445 | {"times", posix_times, METH_VARARGS, posix_times__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4446 | #endif /* HAVE_TIMES */ |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4447 | {"_exit", posix__exit, METH_VARARGS, posix__exit__doc__}, |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 4448 | #ifdef HAVE_EXECV |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4449 | {"execv", posix_execv, METH_VARARGS, posix_execv__doc__}, |
| 4450 | {"execve", posix_execve, METH_VARARGS, posix_execve__doc__}, |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 4451 | #endif /* HAVE_EXECV */ |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 4452 | #ifdef HAVE_SPAWNV |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4453 | {"spawnv", posix_spawnv, METH_VARARGS, posix_spawnv__doc__}, |
| 4454 | {"spawnve", posix_spawnve, METH_VARARGS, posix_spawnve__doc__}, |
Guido van Rossum | a106568 | 1999-01-25 23:20:23 +0000 | [diff] [blame] | 4455 | #endif /* HAVE_SPAWNV */ |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4456 | #ifdef HAVE_FORK |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4457 | {"fork", posix_fork, METH_VARARGS, posix_fork__doc__}, |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4458 | #endif /* HAVE_FORK */ |
| 4459 | #ifdef HAVE_GETEGID |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4460 | {"getegid", posix_getegid, METH_VARARGS, posix_getegid__doc__}, |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4461 | #endif /* HAVE_GETEGID */ |
| 4462 | #ifdef HAVE_GETEUID |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4463 | {"geteuid", posix_geteuid, METH_VARARGS, posix_geteuid__doc__}, |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4464 | #endif /* HAVE_GETEUID */ |
| 4465 | #ifdef HAVE_GETGID |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4466 | {"getgid", posix_getgid, METH_VARARGS, posix_getgid__doc__}, |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4467 | #endif /* HAVE_GETGID */ |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 4468 | #ifdef HAVE_GETGROUPS |
| 4469 | {"getgroups", posix_getgroups, METH_VARARGS, posix_getgroups__doc__}, |
| 4470 | #endif |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4471 | {"getpid", posix_getpid, METH_VARARGS, posix_getpid__doc__}, |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4472 | #ifdef HAVE_GETPGRP |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4473 | {"getpgrp", posix_getpgrp, METH_VARARGS, posix_getpgrp__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4474 | #endif /* HAVE_GETPGRP */ |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4475 | #ifdef HAVE_GETPPID |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4476 | {"getppid", posix_getppid, METH_VARARGS, posix_getppid__doc__}, |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4477 | #endif /* HAVE_GETPPID */ |
| 4478 | #ifdef HAVE_GETUID |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4479 | {"getuid", posix_getuid, METH_VARARGS, posix_getuid__doc__}, |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4480 | #endif /* HAVE_GETUID */ |
Fred Drake | 12c6e2d | 1999-12-14 21:25:03 +0000 | [diff] [blame] | 4481 | #ifdef HAVE_GETLOGIN |
| 4482 | {"getlogin", posix_getlogin, METH_VARARGS, posix_getlogin__doc__}, |
| 4483 | #endif |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4484 | #ifdef HAVE_KILL |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4485 | {"kill", posix_kill, METH_VARARGS, posix_kill__doc__}, |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4486 | #endif /* HAVE_KILL */ |
Guido van Rossum | c012547 | 1996-06-28 18:55:32 +0000 | [diff] [blame] | 4487 | #ifdef HAVE_PLOCK |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4488 | {"plock", posix_plock, METH_VARARGS, posix_plock__doc__}, |
Guido van Rossum | c012547 | 1996-06-28 18:55:32 +0000 | [diff] [blame] | 4489 | #endif /* HAVE_PLOCK */ |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 4490 | #ifdef HAVE_POPEN |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4491 | {"popen", posix_popen, METH_VARARGS, posix_popen__doc__}, |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 4492 | #endif /* HAVE_POPEN */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4493 | #ifdef HAVE_SETUID |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4494 | {"setuid", posix_setuid, METH_VARARGS, posix_setuid__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4495 | #endif /* HAVE_SETUID */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4496 | #ifdef HAVE_SETGID |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4497 | {"setgid", posix_setgid, METH_VARARGS, posix_setgid__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4498 | #endif /* HAVE_SETGID */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4499 | #ifdef HAVE_SETPGRP |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4500 | {"setpgrp", posix_setpgrp, METH_VARARGS, posix_setpgrp__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4501 | #endif /* HAVE_SETPGRP */ |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4502 | #ifdef HAVE_WAIT |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4503 | {"wait", posix_wait, METH_VARARGS, posix_wait__doc__}, |
Guido van Rossum | ad0ee83 | 1995-03-01 10:34:45 +0000 | [diff] [blame] | 4504 | #endif /* HAVE_WAIT */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4505 | #ifdef HAVE_WAITPID |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4506 | {"waitpid", posix_waitpid, METH_VARARGS, posix_waitpid__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4507 | #endif /* HAVE_WAITPID */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4508 | #ifdef HAVE_SETSID |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4509 | {"setsid", posix_setsid, METH_VARARGS, posix_setsid__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4510 | #endif /* HAVE_SETSID */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4511 | #ifdef HAVE_SETPGID |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4512 | {"setpgid", posix_setpgid, METH_VARARGS, posix_setpgid__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4513 | #endif /* HAVE_SETPGID */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4514 | #ifdef HAVE_TCGETPGRP |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4515 | {"tcgetpgrp", posix_tcgetpgrp, METH_VARARGS, posix_tcgetpgrp__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4516 | #endif /* HAVE_TCGETPGRP */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4517 | #ifdef HAVE_TCSETPGRP |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4518 | {"tcsetpgrp", posix_tcsetpgrp, METH_VARARGS, posix_tcsetpgrp__doc__}, |
Guido van Rossum | 6a3eb5f | 1994-08-18 15:42:46 +0000 | [diff] [blame] | 4519 | #endif /* HAVE_TCSETPGRP */ |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4520 | {"open", posix_open, METH_VARARGS, posix_open__doc__}, |
| 4521 | {"close", posix_close, METH_VARARGS, posix_close__doc__}, |
| 4522 | {"dup", posix_dup, METH_VARARGS, posix_dup__doc__}, |
| 4523 | {"dup2", posix_dup2, METH_VARARGS, posix_dup2__doc__}, |
| 4524 | {"lseek", posix_lseek, METH_VARARGS, posix_lseek__doc__}, |
| 4525 | {"read", posix_read, METH_VARARGS, posix_read__doc__}, |
| 4526 | {"write", posix_write, METH_VARARGS, posix_write__doc__}, |
| 4527 | {"fstat", posix_fstat, METH_VARARGS, posix_fstat__doc__}, |
| 4528 | {"fdopen", posix_fdopen, METH_VARARGS, posix_fdopen__doc__}, |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 4529 | #ifdef HAVE_PIPE |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4530 | {"pipe", posix_pipe, METH_VARARGS, posix_pipe__doc__}, |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 4531 | #endif |
| 4532 | #ifdef HAVE_MKFIFO |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4533 | {"mkfifo", posix_mkfifo, METH_VARARGS, posix_mkfifo__doc__}, |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 4534 | #endif |
| 4535 | #ifdef HAVE_FTRUNCATE |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4536 | {"ftruncate", posix_ftruncate, METH_VARARGS, posix_ftruncate__doc__}, |
Guido van Rossum | a4916fa | 1996-05-23 22:58:55 +0000 | [diff] [blame] | 4537 | #endif |
Guido van Rossum | f1af3fe | 1996-07-23 19:18:10 +0000 | [diff] [blame] | 4538 | #ifdef HAVE_PUTENV |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4539 | {"putenv", posix_putenv, METH_VARARGS, posix_putenv__doc__}, |
Guido van Rossum | f1af3fe | 1996-07-23 19:18:10 +0000 | [diff] [blame] | 4540 | #endif |
Guido van Rossum | b6a4716 | 1997-09-15 22:54:34 +0000 | [diff] [blame] | 4541 | #ifdef HAVE_STRERROR |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4542 | {"strerror", posix_strerror, METH_VARARGS, posix_strerror__doc__}, |
Guido van Rossum | b6a4716 | 1997-09-15 22:54:34 +0000 | [diff] [blame] | 4543 | #endif |
Guido van Rossum | 21142a0 | 1999-01-08 21:05:37 +0000 | [diff] [blame] | 4544 | #ifdef HAVE_FSYNC |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4545 | {"fsync", posix_fsync, METH_VARARGS, posix_fsync__doc__}, |
Guido van Rossum | 21142a0 | 1999-01-08 21:05:37 +0000 | [diff] [blame] | 4546 | #endif |
| 4547 | #ifdef HAVE_FDATASYNC |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4548 | {"fdatasync", posix_fdatasync, METH_VARARGS, posix_fdatasync__doc__}, |
Guido van Rossum | 21142a0 | 1999-01-08 21:05:37 +0000 | [diff] [blame] | 4549 | #endif |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 4550 | #ifdef HAVE_SYS_WAIT_H |
| 4551 | #ifdef WIFSTOPPED |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4552 | {"WIFSTOPPED", posix_WIFSTOPPED, METH_VARARGS, posix_WIFSTOPPED__doc__}, |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 4553 | #endif /* WIFSTOPPED */ |
| 4554 | #ifdef WIFSIGNALED |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4555 | {"WIFSIGNALED", posix_WIFSIGNALED, METH_VARARGS, posix_WIFSIGNALED__doc__}, |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 4556 | #endif /* WIFSIGNALED */ |
| 4557 | #ifdef WIFEXITED |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4558 | {"WIFEXITED", posix_WIFEXITED, METH_VARARGS, posix_WIFEXITED__doc__}, |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 4559 | #endif /* WIFEXITED */ |
| 4560 | #ifdef WEXITSTATUS |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4561 | {"WEXITSTATUS", posix_WEXITSTATUS, METH_VARARGS, posix_WEXITSTATUS__doc__}, |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 4562 | #endif /* WEXITSTATUS */ |
| 4563 | #ifdef WTERMSIG |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4564 | {"WTERMSIG", posix_WTERMSIG, METH_VARARGS, posix_WTERMSIG__doc__}, |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 4565 | #endif /* WTERMSIG */ |
| 4566 | #ifdef WSTOPSIG |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4567 | {"WSTOPSIG", posix_WSTOPSIG, METH_VARARGS, posix_WSTOPSIG__doc__}, |
Guido van Rossum | c964179 | 1998-08-04 15:26:23 +0000 | [diff] [blame] | 4568 | #endif /* WSTOPSIG */ |
| 4569 | #endif /* HAVE_SYS_WAIT_H */ |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 4570 | #ifdef HAVE_FSTATVFS |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4571 | {"fstatvfs", posix_fstatvfs, METH_VARARGS, posix_fstatvfs__doc__}, |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 4572 | #endif |
| 4573 | #ifdef HAVE_STATVFS |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4574 | {"statvfs", posix_statvfs, METH_VARARGS, posix_statvfs__doc__}, |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 4575 | #endif |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4576 | #ifdef HAVE_TMPNAM |
| 4577 | {"tmpfile", posix_tmpfile, METH_VARARGS, posix_tmpfile__doc__}, |
| 4578 | #endif |
| 4579 | #ifdef HAVE_TEMPNAM |
| 4580 | {"tempnam", posix_tempnam, METH_VARARGS, posix_tempnam__doc__}, |
| 4581 | #endif |
| 4582 | #ifdef HAVE_TMPNAM |
| 4583 | {"tmpnam", posix_tmpnam, METH_VARARGS, posix_tmpnam__doc__}, |
| 4584 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 4585 | #ifdef HAVE_CONFSTR |
| 4586 | {"confstr", posix_confstr, METH_VARARGS, posix_confstr__doc__}, |
| 4587 | #endif |
| 4588 | #ifdef HAVE_SYSCONF |
| 4589 | {"sysconf", posix_sysconf, METH_VARARGS, posix_sysconf__doc__}, |
| 4590 | #endif |
| 4591 | #ifdef HAVE_FPATHCONF |
| 4592 | {"fpathconf", posix_fpathconf, METH_VARARGS, posix_fpathconf__doc__}, |
| 4593 | #endif |
| 4594 | #ifdef HAVE_PATHCONF |
| 4595 | {"pathconf", posix_pathconf, METH_VARARGS, posix_pathconf__doc__}, |
| 4596 | #endif |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4597 | {"abort", posix_abort, METH_VARARGS, posix_abort__doc__}, |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 4598 | {NULL, NULL} /* Sentinel */ |
| 4599 | }; |
| 4600 | |
| 4601 | |
Barry Warsaw | 4a34209 | 1996-12-19 23:50:02 +0000 | [diff] [blame] | 4602 | static int |
| 4603 | ins(d, symbol, value) |
| 4604 | PyObject* d; |
| 4605 | char* symbol; |
| 4606 | long value; |
| 4607 | { |
| 4608 | PyObject* v = PyInt_FromLong(value); |
| 4609 | if (!v || PyDict_SetItemString(d, symbol, v) < 0) |
| 4610 | return -1; /* triggers fatal error */ |
| 4611 | |
| 4612 | Py_DECREF(v); |
| 4613 | return 0; |
| 4614 | } |
| 4615 | |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 4616 | #if defined(PYOS_OS2) |
| 4617 | /* Insert Platform-Specific Constant Values (Strings & Numbers) of Common Use */ |
| 4618 | static int insertvalues(PyObject *d) |
| 4619 | { |
| 4620 | APIRET rc; |
| 4621 | ULONG values[QSV_MAX+1]; |
| 4622 | PyObject *v; |
| 4623 | char *ver, tmp[10]; |
| 4624 | |
| 4625 | Py_BEGIN_ALLOW_THREADS |
| 4626 | rc = DosQuerySysInfo(1, QSV_MAX, &values[1], sizeof(values)); |
| 4627 | Py_END_ALLOW_THREADS |
| 4628 | |
| 4629 | if (rc != NO_ERROR) { |
| 4630 | os2_error(rc); |
| 4631 | return -1; |
| 4632 | } |
| 4633 | |
| 4634 | if (ins(d, "meminstalled", values[QSV_TOTPHYSMEM])) return -1; |
| 4635 | if (ins(d, "memkernel", values[QSV_TOTRESMEM])) return -1; |
| 4636 | if (ins(d, "memvirtual", values[QSV_TOTAVAILMEM])) return -1; |
| 4637 | if (ins(d, "maxpathlen", values[QSV_MAX_PATH_LENGTH])) return -1; |
| 4638 | if (ins(d, "maxnamelen", values[QSV_MAX_COMP_LENGTH])) return -1; |
| 4639 | if (ins(d, "revision", values[QSV_VERSION_REVISION])) return -1; |
| 4640 | if (ins(d, "timeslice", values[QSV_MIN_SLICE])) return -1; |
| 4641 | |
| 4642 | switch (values[QSV_VERSION_MINOR]) { |
| 4643 | case 0: ver = "2.00"; break; |
| 4644 | case 10: ver = "2.10"; break; |
| 4645 | case 11: ver = "2.11"; break; |
| 4646 | case 30: ver = "3.00"; break; |
| 4647 | case 40: ver = "4.00"; break; |
| 4648 | case 50: ver = "5.00"; break; |
| 4649 | default: |
| 4650 | sprintf(tmp, "%d-%d", values[QSV_VERSION_MAJOR], |
| 4651 | values[QSV_VERSION_MINOR]); |
| 4652 | ver = &tmp[0]; |
| 4653 | } |
| 4654 | |
| 4655 | /* Add Indicator of the Version of the Operating System */ |
| 4656 | v = PyString_FromString(ver); |
| 4657 | if (!v || PyDict_SetItemString(d, "version", v) < 0) |
| 4658 | return -1; |
| 4659 | Py_DECREF(v); |
| 4660 | |
| 4661 | /* Add Indicator of Which Drive was Used to Boot the System */ |
| 4662 | tmp[0] = 'A' + values[QSV_BOOT_DRIVE] - 1; |
| 4663 | tmp[1] = ':'; |
| 4664 | tmp[2] = '\0'; |
| 4665 | |
| 4666 | v = PyString_FromString(tmp); |
| 4667 | if (!v || PyDict_SetItemString(d, "bootdrive", v) < 0) |
| 4668 | return -1; |
| 4669 | Py_DECREF(v); |
| 4670 | |
| 4671 | return 0; |
| 4672 | } |
| 4673 | #endif |
| 4674 | |
Barry Warsaw | 4a34209 | 1996-12-19 23:50:02 +0000 | [diff] [blame] | 4675 | static int |
| 4676 | all_ins(d) |
| 4677 | PyObject* d; |
| 4678 | { |
Guido van Rossum | 94f6f72 | 1999-01-06 18:42:14 +0000 | [diff] [blame] | 4679 | #ifdef F_OK |
| 4680 | if (ins(d, "F_OK", (long)F_OK)) return -1; |
| 4681 | #endif |
| 4682 | #ifdef R_OK |
| 4683 | if (ins(d, "R_OK", (long)R_OK)) return -1; |
| 4684 | #endif |
| 4685 | #ifdef W_OK |
| 4686 | if (ins(d, "W_OK", (long)W_OK)) return -1; |
| 4687 | #endif |
| 4688 | #ifdef X_OK |
| 4689 | if (ins(d, "X_OK", (long)X_OK)) return -1; |
| 4690 | #endif |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 4691 | #ifdef NGROUPS_MAX |
| 4692 | if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1; |
| 4693 | #endif |
Fred Drake | 5ab8eaf | 1999-12-09 21:13:07 +0000 | [diff] [blame] | 4694 | #ifdef TMP_MAX |
| 4695 | if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1; |
| 4696 | #endif |
Barry Warsaw | 4a34209 | 1996-12-19 23:50:02 +0000 | [diff] [blame] | 4697 | #ifdef WNOHANG |
| 4698 | if (ins(d, "WNOHANG", (long)WNOHANG)) return -1; |
| 4699 | #endif |
| 4700 | #ifdef O_RDONLY |
| 4701 | if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1; |
| 4702 | #endif |
| 4703 | #ifdef O_WRONLY |
| 4704 | if (ins(d, "O_WRONLY", (long)O_WRONLY)) return -1; |
| 4705 | #endif |
| 4706 | #ifdef O_RDWR |
| 4707 | if (ins(d, "O_RDWR", (long)O_RDWR)) return -1; |
| 4708 | #endif |
| 4709 | #ifdef O_NDELAY |
| 4710 | if (ins(d, "O_NDELAY", (long)O_NDELAY)) return -1; |
| 4711 | #endif |
| 4712 | #ifdef O_NONBLOCK |
| 4713 | if (ins(d, "O_NONBLOCK", (long)O_NONBLOCK)) return -1; |
| 4714 | #endif |
| 4715 | #ifdef O_APPEND |
| 4716 | if (ins(d, "O_APPEND", (long)O_APPEND)) return -1; |
| 4717 | #endif |
| 4718 | #ifdef O_DSYNC |
| 4719 | if (ins(d, "O_DSYNC", (long)O_DSYNC)) return -1; |
| 4720 | #endif |
| 4721 | #ifdef O_RSYNC |
| 4722 | if (ins(d, "O_RSYNC", (long)O_RSYNC)) return -1; |
| 4723 | #endif |
| 4724 | #ifdef O_SYNC |
| 4725 | if (ins(d, "O_SYNC", (long)O_SYNC)) return -1; |
| 4726 | #endif |
| 4727 | #ifdef O_NOCTTY |
| 4728 | if (ins(d, "O_NOCTTY", (long)O_NOCTTY)) return -1; |
| 4729 | #endif |
| 4730 | #ifdef O_CREAT |
| 4731 | if (ins(d, "O_CREAT", (long)O_CREAT)) return -1; |
| 4732 | #endif |
| 4733 | #ifdef O_EXCL |
| 4734 | if (ins(d, "O_EXCL", (long)O_EXCL)) return -1; |
| 4735 | #endif |
| 4736 | #ifdef O_TRUNC |
| 4737 | if (ins(d, "O_TRUNC", (long)O_TRUNC)) return -1; |
| 4738 | #endif |
Guido van Rossum | 98d9d09 | 1997-08-08 21:48:51 +0000 | [diff] [blame] | 4739 | #ifdef O_BINARY |
| 4740 | if (ins(d, "O_BINARY", (long)O_BINARY)) return -1; |
| 4741 | #endif |
| 4742 | #ifdef O_TEXT |
| 4743 | if (ins(d, "O_TEXT", (long)O_TEXT)) return -1; |
| 4744 | #endif |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 4745 | |
Guido van Rossum | 246bc17 | 1999-02-01 23:54:31 +0000 | [diff] [blame] | 4746 | #ifdef HAVE_SPAWNV |
Guido van Rossum | 7d38529 | 1999-02-16 19:38:04 +0000 | [diff] [blame] | 4747 | if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1; |
| 4748 | if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1; |
| 4749 | if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1; |
| 4750 | if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1; |
| 4751 | if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1; |
Guido van Rossum | 246bc17 | 1999-02-01 23:54:31 +0000 | [diff] [blame] | 4752 | #endif |
| 4753 | |
Guido van Rossum | d48f252 | 1997-12-05 22:19:34 +0000 | [diff] [blame] | 4754 | #if defined(PYOS_OS2) |
| 4755 | if (insertvalues(d)) return -1; |
| 4756 | #endif |
Barry Warsaw | 4a34209 | 1996-12-19 23:50:02 +0000 | [diff] [blame] | 4757 | return 0; |
| 4758 | } |
| 4759 | |
| 4760 | |
Guido van Rossum | c5a0f53 | 1997-12-02 20:36:02 +0000 | [diff] [blame] | 4761 | #if ( defined(_MSC_VER) || defined(__WATCOMC__) ) && !defined(__QNX__) |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 4762 | #define INITFUNC initnt |
| 4763 | #define MODNAME "nt" |
| 4764 | #else |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 4765 | #if defined(PYOS_OS2) |
| 4766 | #define INITFUNC initos2 |
| 4767 | #define MODNAME "os2" |
| 4768 | #else |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 4769 | #define INITFUNC initposix |
| 4770 | #define MODNAME "posix" |
| 4771 | #endif |
Guido van Rossum | 8e9ebfd | 1997-11-22 21:53:48 +0000 | [diff] [blame] | 4772 | #endif |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 4773 | |
Guido van Rossum | 3886bb6 | 1998-12-04 18:50:17 +0000 | [diff] [blame] | 4774 | DL_EXPORT(void) |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 4775 | INITFUNC() |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4776 | { |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 4777 | PyObject *m, *d, *v; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4778 | |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 4779 | m = Py_InitModule4(MODNAME, |
Guido van Rossum | ec4f4ac | 1997-06-02 22:20:51 +0000 | [diff] [blame] | 4780 | posix_methods, |
| 4781 | posix__doc__, |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 4782 | (PyObject *)NULL, |
| 4783 | PYTHON_API_VERSION); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 4784 | d = PyModule_GetDict(m); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4785 | |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 4786 | /* Initialize environ dictionary */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4787 | v = convertenviron(); |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 4788 | if (v == NULL || PyDict_SetItemString(d, "environ", v) != 0) |
Guido van Rossum | 0cb96de | 1997-10-01 04:29:29 +0000 | [diff] [blame] | 4789 | return; |
Barry Warsaw | 53699e9 | 1996-12-10 23:23:01 +0000 | [diff] [blame] | 4790 | Py_DECREF(v); |
Fred Drake | c968092 | 1999-12-13 16:37:25 +0000 | [diff] [blame] | 4791 | |
Barry Warsaw | 4a34209 | 1996-12-19 23:50:02 +0000 | [diff] [blame] | 4792 | if (all_ins(d)) |
Barry Warsaw | 4a34209 | 1996-12-19 23:50:02 +0000 | [diff] [blame] | 4793 | return; |
| 4794 | |
Fred Drake | bec628d | 1999-12-15 18:31:10 +0000 | [diff] [blame] | 4795 | if (setup_confname_tables(d)) |
| 4796 | return; |
| 4797 | |
Barry Warsaw | ca74da4 | 1999-02-09 19:31:45 +0000 | [diff] [blame] | 4798 | PyDict_SetItemString(d, "error", PyExc_OSError); |
Fred Drake | 762e206 | 1999-08-26 17:23:54 +0000 | [diff] [blame] | 4799 | |
Guido van Rossum | b3d3956 | 2000-01-31 18:41:26 +0000 | [diff] [blame] | 4800 | #ifdef HAVE_PUTENV |
Fred Drake | 762e206 | 1999-08-26 17:23:54 +0000 | [diff] [blame] | 4801 | posix_putenv_garbage = PyDict_New(); |
Guido van Rossum | b3d3956 | 2000-01-31 18:41:26 +0000 | [diff] [blame] | 4802 | #endif |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 4803 | } |