Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Jack Jansen | 42218ce | 1997-01-31 16:15:11 +0000 | [diff] [blame] | 2 | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
Guido van Rossum | 9954699 | 1995-01-08 14:33:34 +0000 | [diff] [blame] | 3 | The Netherlands. |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 25 | /* Mac module implementation */ |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 26 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 27 | #include "Python.h" |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 28 | #include "ceval.h" |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 29 | |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 30 | #include <stdio.h> |
| 31 | #include <string.h> |
| 32 | #include <errno.h> |
Guido van Rossum | 739267b | 1994-08-29 08:42:37 +0000 | [diff] [blame] | 33 | |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 34 | #if TARGET_API_MAC_OS8 |
Jack Jansen | d9d0b5f | 2001-01-12 23:37:14 +0000 | [diff] [blame] | 35 | /* Skip for Carbon */ |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 36 | #include "macstat.h" |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 39 | #ifdef USE_GUSI |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 40 | /* Remove defines from macstat.h */ |
| 41 | #undef S_IFMT |
| 42 | #undef S_IFDIR |
| 43 | #undef S_IFREG |
| 44 | #undef S_IREAD |
| 45 | #undef S_IWRITE |
| 46 | #undef S_IEXEC |
| 47 | |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 48 | #ifdef USE_GUSI1 |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 49 | #include <GUSI.h> |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 50 | #endif /* USE_GUSI1 */ |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 51 | #include <sys/types.h> |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 52 | #include <sys/stat.h> |
| 53 | #else /* USE_GUSI */ |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 54 | #if TARGET_API_MAC_OS8 |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 55 | #define stat macstat |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 56 | #endif |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 57 | #endif /* USE_GUSI */ |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 58 | |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 59 | #ifdef USE_GUSI2 |
| 60 | #define sync bad_sync |
| 61 | #include <unistd.h> |
| 62 | #include <fcntl.h> |
| 63 | #undef sync |
| 64 | int sync(void); |
| 65 | #else |
Jack Jansen | 12e89e4 | 2000-05-12 21:36:29 +0000 | [diff] [blame] | 66 | #define mode_t int |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 67 | #include <fcntl.h> |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 68 | #ifdef _POSIX |
| 69 | #include <unistd.h> |
| 70 | #include <stat.h> |
| 71 | #endif |
Jack Jansen | 0c097ea | 1994-12-14 13:48:38 +0000 | [diff] [blame] | 72 | #endif |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 73 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 74 | /* Optional routines, for some compiler/runtime combinations */ |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 75 | #if defined(USE_GUSI) || !defined(__MWERKS__) |
| 76 | #define WEHAVE_FDOPEN |
| 77 | #endif |
| 78 | #if defined(MPW) || defined(USE_GUSI) |
| 79 | #define WEHAVE_DUP |
| 80 | #endif |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 81 | #if defined(USE_GUSI) |
| 82 | #define WEHAVE_FSTAT |
| 83 | #endif |
Jack Jansen | 7cbf480 | 1995-01-22 16:52:38 +0000 | [diff] [blame] | 84 | |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 85 | #include "macdefs.h" |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 86 | #ifdef USE_GUSI |
| 87 | #include <dirent.h> |
| 88 | #else |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 89 | #include "dirent.h" |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 90 | #endif |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 91 | |
| 92 | #ifndef MAXPATHLEN |
| 93 | #define MAXPATHLEN 1024 |
| 94 | #endif |
| 95 | |
| 96 | /* Prototypes for Unix simulation on Mac */ |
| 97 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 98 | #ifndef USE_GUSI |
| 99 | |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 100 | int chdir(const char *path); |
| 101 | int mkdir(const char *path, int mode); |
| 102 | DIR * opendir(char *); |
| 103 | void closedir(DIR *); |
| 104 | struct dirent * readdir(DIR *); |
| 105 | int rmdir(const char *path); |
| 106 | int sync(void); |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 107 | |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 108 | int unlink(const char *); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 109 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 110 | #endif /* USE_GUSI */ |
| 111 | |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 112 | char *getwd(char *); |
| 113 | char *getbootvol(void); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 114 | |
| 115 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 116 | static PyObject *MacError; /* Exception mac.error */ |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 117 | |
| 118 | /* Set a MAC-specific error from errno, and return NULL */ |
| 119 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 120 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 121 | mac_error() |
| 122 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 123 | return PyErr_SetFromErrno(MacError); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /* MAC generic methods */ |
| 127 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 128 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 129 | mac_1str(args, func) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 130 | PyObject *args; |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 131 | int (*func)(const char *); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 132 | { |
| 133 | char *path1; |
| 134 | int res; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 135 | if (!PyArg_Parse(args, "s", &path1)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 136 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 137 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 138 | res = (*func)(path1); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 139 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 140 | if (res < 0) |
| 141 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 142 | Py_INCREF(Py_None); |
| 143 | return Py_None; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 146 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 147 | mac_2str(args, func) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 148 | PyObject *args; |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 149 | int (*func)(const char *, const char *); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 150 | { |
| 151 | char *path1, *path2; |
| 152 | int res; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 153 | if (!PyArg_Parse(args, "(ss)", &path1, &path2)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 154 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 155 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 156 | res = (*func)(path1, path2); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 157 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 158 | if (res < 0) |
| 159 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 160 | Py_INCREF(Py_None); |
| 161 | return Py_None; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 164 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 165 | mac_strint(args, func) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 166 | PyObject *args; |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 167 | int (*func)(const char *, int); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 168 | { |
| 169 | char *path; |
| 170 | int i; |
| 171 | int res; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 172 | if (!PyArg_Parse(args, "(si)", &path, &i)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 173 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 174 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 175 | res = (*func)(path, i); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 176 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 177 | if (res < 0) |
| 178 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 179 | Py_INCREF(Py_None); |
| 180 | return Py_None; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 183 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 184 | mac_chdir(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 185 | PyObject *self; |
| 186 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 187 | { |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 188 | #ifdef USE_GUSI1 |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 189 | PyObject *rv; |
Jack Jansen | 378815c | 1996-03-06 16:21:34 +0000 | [diff] [blame] | 190 | |
| 191 | /* Change MacOS's idea of wd too */ |
| 192 | rv = mac_1str(args, chdir); |
| 193 | PyMac_FixGUSIcd(); |
| 194 | return rv; |
| 195 | #else |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 196 | return mac_1str(args, chdir); |
Jack Jansen | 378815c | 1996-03-06 16:21:34 +0000 | [diff] [blame] | 197 | #endif |
| 198 | |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 201 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 202 | mac_close(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 203 | PyObject *self; |
| 204 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 205 | { |
| 206 | int fd, res; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 207 | if (!PyArg_Parse(args, "i", &fd)) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 208 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 209 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 210 | res = close(fd); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 211 | Py_END_ALLOW_THREADS |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 212 | #ifndef USE_GUSI1 |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 213 | /* GUSI gives surious errors here? */ |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 214 | if (res < 0) |
| 215 | return mac_error(); |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 216 | #endif |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 217 | Py_INCREF(Py_None); |
| 218 | return Py_None; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 221 | #ifdef WEHAVE_DUP |
Guido van Rossum | 921a08f | 1994-05-06 15:56:22 +0000 | [diff] [blame] | 222 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 223 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 224 | mac_dup(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 225 | PyObject *self; |
| 226 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 227 | { |
| 228 | int fd; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 229 | if (!PyArg_Parse(args, "i", &fd)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 230 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 231 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 232 | fd = dup(fd); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 233 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 234 | if (fd < 0) |
| 235 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 236 | return PyInt_FromLong((long)fd); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 239 | #endif |
Guido van Rossum | e783444 | 1994-08-26 09:09:48 +0000 | [diff] [blame] | 240 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 241 | #ifdef WEHAVE_FDOPEN |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 242 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 243 | mac_fdopen(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 244 | PyObject *self; |
| 245 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 246 | { |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 247 | extern int fclose(FILE *); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 248 | int fd; |
| 249 | char *mode; |
| 250 | FILE *fp; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 251 | if (!PyArg_Parse(args, "(is)", &fd, &mode)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 252 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 253 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 254 | fp = fdopen(fd, mode); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 255 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 256 | if (fp == NULL) |
| 257 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 258 | return PyFile_FromFile(fp, "(fdopen)", mode, fclose); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 259 | } |
Jack Jansen | 0c097ea | 1994-12-14 13:48:38 +0000 | [diff] [blame] | 260 | #endif |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 261 | |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 262 | #if TARGET_API_MAC_OS8 |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 263 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 264 | mac_getbootvol(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 265 | PyObject *self; |
| 266 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 267 | { |
| 268 | char *res; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 269 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 270 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 271 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 272 | res = getbootvol(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 273 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 274 | if (res == NULL) |
| 275 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 276 | return PyString_FromString(res); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 277 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 278 | #endif |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 279 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 280 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 281 | mac_getcwd(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 282 | PyObject *self; |
| 283 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 284 | { |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 285 | char path[MAXPATHLEN]; |
| 286 | char *res; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 287 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 288 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 289 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 290 | #ifdef USE_GUSI |
| 291 | res = getcwd(path, sizeof path); |
| 292 | #else |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 293 | res = getwd(path); |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 294 | #endif |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 295 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 296 | if (res == NULL) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 297 | PyErr_SetString(MacError, path); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 298 | return NULL; |
| 299 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 300 | return PyString_FromString(res); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 303 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 304 | mac_listdir(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 305 | PyObject *self; |
| 306 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 307 | { |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 308 | char *name; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 309 | PyObject *d, *v; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 310 | DIR *dirp; |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 311 | struct dirent *ep; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 312 | if (!PyArg_Parse(args, "s", &name)) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 313 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 314 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 315 | if ((dirp = opendir(name)) == NULL) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 316 | Py_BLOCK_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 317 | return mac_error(); |
| 318 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 319 | if ((d = PyList_New(0)) == NULL) { |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 320 | closedir(dirp); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 321 | Py_BLOCK_THREADS |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 322 | return NULL; |
| 323 | } |
| 324 | while ((ep = readdir(dirp)) != NULL) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 325 | v = PyString_FromString(ep->d_name); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 326 | if (v == NULL) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 327 | Py_DECREF(d); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 328 | d = NULL; |
| 329 | break; |
| 330 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 331 | if (PyList_Append(d, v) != 0) { |
| 332 | Py_DECREF(v); |
| 333 | Py_DECREF(d); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 334 | d = NULL; |
| 335 | break; |
| 336 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 337 | Py_DECREF(v); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 338 | } |
| 339 | closedir(dirp); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 340 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 341 | |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 342 | return d; |
| 343 | } |
| 344 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 345 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 346 | mac_lseek(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 347 | PyObject *self; |
| 348 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 349 | { |
| 350 | int fd; |
| 351 | int where; |
| 352 | int how; |
| 353 | long res; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 354 | if (!PyArg_Parse(args, "(iii)", &fd, &where, &how)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 355 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 356 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 357 | res = lseek(fd, (long)where, how); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 358 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 359 | if (res < 0) |
| 360 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 361 | return PyInt_FromLong(res); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 362 | } |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 363 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 364 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 365 | mac_mkdir(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 366 | PyObject *self; |
| 367 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 368 | { |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 369 | int res; |
| 370 | char *path; |
| 371 | int mode = 0777; /* Unused */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 372 | if (!PyArg_ParseTuple(args, "s|i", &path, &mode)) |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 373 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 374 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 375 | #ifdef USE_GUSI1 |
Jack Jansen | 3ca6edd | 1996-08-06 16:06:31 +0000 | [diff] [blame] | 376 | res = mkdir(path); |
| 377 | #else |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 378 | res = mkdir(path, mode); |
Jack Jansen | 3ca6edd | 1996-08-06 16:06:31 +0000 | [diff] [blame] | 379 | #endif |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 380 | Py_END_ALLOW_THREADS |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 381 | if (res < 0) |
| 382 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 383 | Py_INCREF(Py_None); |
| 384 | return Py_None; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 387 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 388 | mac_open(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 389 | PyObject *self; |
| 390 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 391 | { |
| 392 | char *path; |
| 393 | int mode; |
| 394 | int fd; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 395 | if (!PyArg_Parse(args, "(si)", &path, &mode)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 396 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 397 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 398 | fd = open(path, mode); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 399 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 400 | if (fd < 0) |
| 401 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 402 | return PyInt_FromLong((long)fd); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 405 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 406 | mac_read(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 407 | PyObject *self; |
| 408 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 409 | { |
| 410 | int fd, size; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 411 | PyObject *buffer; |
| 412 | if (!PyArg_Parse(args, "(ii)", &fd, &size)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 413 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 414 | buffer = PyString_FromStringAndSize((char *)NULL, size); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 415 | if (buffer == NULL) |
| 416 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 417 | Py_BEGIN_ALLOW_THREADS |
| 418 | size = read(fd, PyString_AsString(buffer), size); |
| 419 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 420 | if (size < 0) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 421 | Py_DECREF(buffer); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 422 | return mac_error(); |
| 423 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 424 | _PyString_Resize(&buffer, size); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 425 | return buffer; |
| 426 | } |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 427 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 428 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 429 | mac_rename(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 430 | PyObject *self; |
| 431 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 432 | { |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 433 | return mac_2str(args, rename); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 436 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 437 | mac_rmdir(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 438 | PyObject *self; |
| 439 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 440 | { |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 441 | return mac_1str(args, rmdir); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 444 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 445 | mac_stat(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 446 | PyObject *self; |
| 447 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 448 | { |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 449 | struct stat st; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 450 | char *path; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 451 | int res; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 452 | if (!PyArg_Parse(args, "s", &path)) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 453 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 454 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 455 | res = stat(path, &st); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 456 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 457 | if (res != 0) |
| 458 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 459 | return Py_BuildValue("(lllllllddd)", |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 460 | (long)st.st_mode, |
| 461 | (long)st.st_ino, |
| 462 | (long)st.st_dev, |
| 463 | (long)st.st_nlink, |
| 464 | (long)st.st_uid, |
| 465 | (long)st.st_gid, |
| 466 | (long)st.st_size, |
| 467 | (double)st.st_atime, |
| 468 | (double)st.st_mtime, |
| 469 | (double)st.st_ctime); |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | #ifdef WEHAVE_FSTAT |
| 473 | static PyObject * |
| 474 | mac_fstat(self, args) |
| 475 | PyObject *self; |
| 476 | PyObject *args; |
| 477 | { |
| 478 | struct stat st; |
| 479 | long fd; |
| 480 | int res; |
| 481 | if (!PyArg_Parse(args, "l", &fd)) |
| 482 | return NULL; |
| 483 | Py_BEGIN_ALLOW_THREADS |
| 484 | res = fstat((int)fd, &st); |
| 485 | Py_END_ALLOW_THREADS |
| 486 | if (res != 0) |
| 487 | return mac_error(); |
| 488 | return Py_BuildValue("(lllllllddd)", |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 489 | (long)st.st_mode, |
Guido van Rossum | e783444 | 1994-08-26 09:09:48 +0000 | [diff] [blame] | 490 | (long)st.st_ino, |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 491 | (long)st.st_dev, |
| 492 | (long)st.st_nlink, |
| 493 | (long)st.st_uid, |
| 494 | (long)st.st_gid, |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 495 | (long)st.st_size, |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 496 | (double)st.st_atime, |
| 497 | (double)st.st_mtime, |
| 498 | (double)st.st_ctime); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 499 | } |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 500 | #endif /* WEHAVE_FSTAT */ |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 501 | |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 502 | #if TARGET_API_MAC_OS8 |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 503 | static PyObject * |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 504 | mac_xstat(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 505 | PyObject *self; |
| 506 | PyObject *args; |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 507 | { |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 508 | struct macstat mst; |
| 509 | struct stat st; |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 510 | char *path; |
| 511 | int res; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 512 | if (!PyArg_Parse(args, "s", &path)) |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 513 | return NULL; |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 514 | /* |
| 515 | ** Convoluted: we want stat() and xstat() to agree, so we call both |
| 516 | ** stat and macstat, and use the latter only for values not provided by |
| 517 | ** the former. |
| 518 | */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 519 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 520 | res = macstat(path, &mst); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 521 | Py_END_ALLOW_THREADS |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 522 | if (res != 0) |
| 523 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 524 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 525 | res = stat(path, &st); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 526 | Py_END_ALLOW_THREADS |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 527 | if (res != 0) |
| 528 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 529 | return Py_BuildValue("(llllllldddls#s#)", |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 530 | (long)st.st_mode, |
| 531 | (long)st.st_ino, |
| 532 | (long)st.st_dev, |
| 533 | (long)st.st_nlink, |
| 534 | (long)st.st_uid, |
| 535 | (long)st.st_gid, |
| 536 | (long)st.st_size, |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 537 | (double)st.st_atime, |
| 538 | (double)st.st_mtime, |
| 539 | (double)st.st_ctime, |
| 540 | (long)mst.st_rsize, |
| 541 | mst.st_creator, 4, |
| 542 | mst.st_type, 4); |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 543 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 544 | #endif |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 545 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 546 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 547 | mac_sync(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 548 | PyObject *self; |
| 549 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 550 | { |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 551 | int res; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 552 | if (!PyArg_NoArgs(args)) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 553 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 554 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 555 | res = sync(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 556 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 557 | if (res != 0) |
| 558 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 559 | Py_INCREF(Py_None); |
| 560 | return Py_None; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 563 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 564 | mac_unlink(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 565 | PyObject *self; |
| 566 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 567 | { |
Guido van Rossum | 739267b | 1994-08-29 08:42:37 +0000 | [diff] [blame] | 568 | return mac_1str(args, (int (*)(const char *))unlink); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 571 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 572 | mac_write(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 573 | PyObject *self; |
| 574 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 575 | { |
| 576 | int fd, size; |
| 577 | char *buffer; |
Jack Jansen | eeccca9 | 1997-05-07 15:46:31 +0000 | [diff] [blame] | 578 | if (!PyArg_Parse(args, "(is#)", &fd, &buffer, &size)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 579 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 580 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 581 | size = write(fd, buffer, size); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 582 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 583 | if (size < 0) |
| 584 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 585 | return PyInt_FromLong((long)size); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 586 | } |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 587 | |
Jack Jansen | 46ed276 | 1996-10-23 15:46:57 +0000 | [diff] [blame] | 588 | #ifdef USE_MALLOC_DEBUG |
Jack Jansen | 8748a0b | 2000-08-25 22:18:20 +0000 | [diff] [blame] | 589 | void *mstats(char *); |
| 590 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 591 | static PyObject * |
Jack Jansen | d50e4e1 | 1995-01-18 13:58:04 +0000 | [diff] [blame] | 592 | mac_mstats(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 593 | PyObject*self; |
| 594 | PyObject *args; |
Jack Jansen | d50e4e1 | 1995-01-18 13:58:04 +0000 | [diff] [blame] | 595 | { |
| 596 | mstats("python"); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 597 | Py_INCREF(Py_None); |
| 598 | return Py_None; |
Jack Jansen | d50e4e1 | 1995-01-18 13:58:04 +0000 | [diff] [blame] | 599 | } |
Jack Jansen | 4f27a55 | 1997-02-20 15:22:17 +0000 | [diff] [blame] | 600 | #endif /* USE_MALLOC_DEBUG */ |
Jack Jansen | d50e4e1 | 1995-01-18 13:58:04 +0000 | [diff] [blame] | 601 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 602 | static struct PyMethodDef mac_methods[] = { |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 603 | {"chdir", mac_chdir}, |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 604 | {"close", mac_close}, |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 605 | #ifdef WEHAVE_DUP |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 606 | {"dup", mac_dup}, |
Guido van Rossum | 921a08f | 1994-05-06 15:56:22 +0000 | [diff] [blame] | 607 | #endif |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 608 | #ifdef WEHAVE_FDOPEN |
Guido van Rossum | e783444 | 1994-08-26 09:09:48 +0000 | [diff] [blame] | 609 | {"fdopen", mac_fdopen}, |
Jack Jansen | 0c097ea | 1994-12-14 13:48:38 +0000 | [diff] [blame] | 610 | #endif |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 611 | #ifdef WEHAVE_FSTAT |
| 612 | {"fstat", mac_fstat}, |
| 613 | #endif |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 614 | #if TARGET_API_MAC_OS8 |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 615 | {"getbootvol", mac_getbootvol}, /* non-standard */ |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 616 | #endif |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 617 | {"getcwd", mac_getcwd}, |
Guido van Rossum | d1ef596 | 1995-02-19 15:50:35 +0000 | [diff] [blame] | 618 | {"listdir", mac_listdir, 0}, |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 619 | {"lseek", mac_lseek}, |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 620 | {"mkdir", mac_mkdir, 1}, |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 621 | {"open", mac_open}, |
| 622 | {"read", mac_read}, |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 623 | {"rename", mac_rename}, |
| 624 | {"rmdir", mac_rmdir}, |
| 625 | {"stat", mac_stat}, |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 626 | #if TARGET_API_MAC_OS8 |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 627 | {"xstat", mac_xstat}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 628 | #endif |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 629 | {"sync", mac_sync}, |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 630 | {"remove", mac_unlink}, |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 631 | {"unlink", mac_unlink}, |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 632 | {"write", mac_write}, |
Jack Jansen | 46ed276 | 1996-10-23 15:46:57 +0000 | [diff] [blame] | 633 | #ifdef USE_MALLOC_DEBUG |
Jack Jansen | d50e4e1 | 1995-01-18 13:58:04 +0000 | [diff] [blame] | 634 | {"mstats", mac_mstats}, |
| 635 | #endif |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 636 | |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 637 | {NULL, NULL} /* Sentinel */ |
| 638 | }; |
| 639 | |
| 640 | |
| 641 | void |
| 642 | initmac() |
| 643 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 644 | PyObject *m, *d; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 645 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 646 | m = Py_InitModule("mac", mac_methods); |
| 647 | d = PyModule_GetDict(m); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 648 | |
| 649 | /* Initialize mac.error exception */ |
Jack Jansen | 55e3927 | 1997-10-07 21:47:25 +0000 | [diff] [blame] | 650 | MacError = PyErr_NewException("mac.error", NULL, NULL); |
| 651 | PyDict_SetItemString(d, "error", MacError); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 652 | } |