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 | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 28 | #include "structseq.h" |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 29 | #include "ceval.h" |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 30 | |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <string.h> |
| 33 | #include <errno.h> |
Guido van Rossum | 739267b | 1994-08-29 08:42:37 +0000 | [diff] [blame] | 34 | |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 35 | #if TARGET_API_MAC_OS8 |
Jack Jansen | d9d0b5f | 2001-01-12 23:37:14 +0000 | [diff] [blame] | 36 | /* Skip for Carbon */ |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 37 | #include "macstat.h" |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 40 | #ifdef USE_GUSI |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 41 | /* Remove defines from macstat.h */ |
| 42 | #undef S_IFMT |
| 43 | #undef S_IFDIR |
| 44 | #undef S_IFREG |
| 45 | #undef S_IREAD |
| 46 | #undef S_IWRITE |
| 47 | #undef S_IEXEC |
| 48 | |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 49 | #include <sys/types.h> |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 50 | #include <sys/stat.h> |
| 51 | #else /* USE_GUSI */ |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 52 | #if TARGET_API_MAC_OS8 |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 53 | #define stat macstat |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 54 | #endif |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 55 | #endif /* USE_GUSI */ |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 56 | |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 57 | #ifdef USE_GUSI2 |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 58 | #include <unistd.h> |
| 59 | #include <fcntl.h> |
Jack Jansen | 37d21e1 | 2000-04-07 09:25:06 +0000 | [diff] [blame] | 60 | #else |
Jack Jansen | 12e89e4 | 2000-05-12 21:36:29 +0000 | [diff] [blame] | 61 | #define mode_t int |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 62 | #include <fcntl.h> |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 63 | #ifdef _POSIX |
| 64 | #include <unistd.h> |
| 65 | #include <stat.h> |
| 66 | #endif |
Jack Jansen | 0c097ea | 1994-12-14 13:48:38 +0000 | [diff] [blame] | 67 | #endif |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 68 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 69 | /* Optional routines, for some compiler/runtime combinations */ |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 70 | #if defined(USE_GUSI) || !defined(__MWERKS__) |
| 71 | #define WEHAVE_FDOPEN |
| 72 | #endif |
| 73 | #if defined(MPW) || defined(USE_GUSI) |
| 74 | #define WEHAVE_DUP |
| 75 | #endif |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 76 | #if defined(USE_GUSI) |
| 77 | #define WEHAVE_FSTAT |
| 78 | #endif |
Jack Jansen | 7cbf480 | 1995-01-22 16:52:38 +0000 | [diff] [blame] | 79 | |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 80 | #include "macdefs.h" |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 81 | #ifdef USE_GUSI |
| 82 | #include <dirent.h> |
| 83 | #else |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 84 | #include "dirent.h" |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 85 | #endif |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 86 | |
| 87 | #ifndef MAXPATHLEN |
| 88 | #define MAXPATHLEN 1024 |
| 89 | #endif |
| 90 | |
| 91 | /* Prototypes for Unix simulation on Mac */ |
| 92 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 93 | #ifndef USE_GUSI |
| 94 | |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 95 | int chdir(const char *path); |
| 96 | int mkdir(const char *path, int mode); |
| 97 | DIR * opendir(char *); |
| 98 | void closedir(DIR *); |
| 99 | struct dirent * readdir(DIR *); |
| 100 | int rmdir(const char *path); |
| 101 | int sync(void); |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 102 | |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 103 | int unlink(const char *); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 104 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 105 | #endif /* USE_GUSI */ |
| 106 | |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 107 | char *getwd(char *); |
| 108 | char *getbootvol(void); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 109 | |
| 110 | |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 111 | /* Set a MAC-specific error from errno, and return NULL */ |
| 112 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 113 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 114 | mac_error() |
| 115 | { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 116 | return PyErr_SetFromErrno(PyExc_OSError); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* MAC generic methods */ |
| 120 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 121 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 122 | mac_1str(args, func) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 123 | PyObject *args; |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 124 | int (*func)(const char *); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 125 | { |
| 126 | char *path1; |
| 127 | int res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 128 | if (!PyArg_ParseTuple(args, "s", &path1)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 129 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 130 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 131 | res = (*func)(path1); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 132 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 133 | if (res < 0) |
| 134 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 135 | Py_INCREF(Py_None); |
| 136 | return Py_None; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 139 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 140 | mac_2str(args, func) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 141 | PyObject *args; |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 142 | int (*func)(const char *, const char *); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 143 | { |
| 144 | char *path1, *path2; |
| 145 | int res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 146 | if (!PyArg_ParseTuple(args, "ss", &path1, &path2)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 147 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 148 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 149 | res = (*func)(path1, path2); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 150 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 151 | if (res < 0) |
| 152 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 153 | Py_INCREF(Py_None); |
| 154 | return Py_None; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 157 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 158 | mac_strint(args, func) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 159 | PyObject *args; |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 160 | int (*func)(const char *, int); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 161 | { |
| 162 | char *path; |
| 163 | int i; |
| 164 | int res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 165 | if (!PyArg_ParseTuple(args, "si", &path, &i)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 166 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 167 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 168 | res = (*func)(path, i); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 169 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 170 | if (res < 0) |
| 171 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 172 | Py_INCREF(Py_None); |
| 173 | return Py_None; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 176 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 177 | mac_chdir(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 178 | PyObject *self; |
| 179 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 180 | { |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 181 | return mac_1str(args, chdir); |
| 182 | } |
| 183 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 184 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 185 | mac_close(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 186 | PyObject *self; |
| 187 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 188 | { |
| 189 | int fd, res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 190 | if (!PyArg_ParseTuple(args, "i", &fd)) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 191 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 192 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 193 | res = close(fd); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 194 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 195 | if (res < 0) |
| 196 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 197 | Py_INCREF(Py_None); |
| 198 | return Py_None; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 201 | #ifdef WEHAVE_DUP |
Guido van Rossum | 921a08f | 1994-05-06 15:56:22 +0000 | [diff] [blame] | 202 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 203 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 204 | mac_dup(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 205 | PyObject *self; |
| 206 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 207 | { |
| 208 | int fd; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 209 | if (!PyArg_ParseTuple(args, "i", &fd)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 210 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 211 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 212 | fd = dup(fd); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 213 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 214 | if (fd < 0) |
| 215 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 216 | return PyInt_FromLong((long)fd); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 219 | #endif |
Guido van Rossum | e783444 | 1994-08-26 09:09:48 +0000 | [diff] [blame] | 220 | |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 221 | #ifdef WEHAVE_FDOPEN |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 222 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 223 | mac_fdopen(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 224 | PyObject *self; |
| 225 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 226 | { |
Jack Jansen | d88296d | 2000-07-11 19:51:05 +0000 | [diff] [blame] | 227 | extern int fclose(FILE *); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 228 | int fd; |
| 229 | char *mode; |
| 230 | FILE *fp; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 231 | if (!PyArg_ParseTuple(args, "is", &fd, &mode)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 232 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 233 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 234 | fp = fdopen(fd, mode); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 235 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 236 | if (fp == NULL) |
| 237 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 238 | return PyFile_FromFile(fp, "(fdopen)", mode, fclose); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 239 | } |
Jack Jansen | 0c097ea | 1994-12-14 13:48:38 +0000 | [diff] [blame] | 240 | #endif |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 241 | |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 242 | #if TARGET_API_MAC_OS8 |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 243 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 244 | mac_getbootvol(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 245 | PyObject *self; |
| 246 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 247 | { |
| 248 | char *res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 249 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 250 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 251 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 252 | res = getbootvol(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 253 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 254 | if (res == NULL) |
| 255 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 256 | return PyString_FromString(res); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 257 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 258 | #endif |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 259 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 260 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 261 | mac_getcwd(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 262 | PyObject *self; |
| 263 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 264 | { |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 265 | char path[MAXPATHLEN]; |
| 266 | char *res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 267 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 268 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 269 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 270 | #ifdef USE_GUSI |
| 271 | res = getcwd(path, sizeof path); |
| 272 | #else |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 273 | res = getwd(path); |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 274 | #endif |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 275 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 276 | if (res == NULL) { |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 277 | return mac_error(); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 278 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 279 | return PyString_FromString(res); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 282 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 283 | mac_listdir(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 284 | PyObject *self; |
| 285 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 286 | { |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 287 | char *name; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 288 | PyObject *d, *v; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 289 | DIR *dirp; |
Guido van Rossum | d4d7728 | 1994-08-19 10:51:31 +0000 | [diff] [blame] | 290 | struct dirent *ep; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 291 | if (!PyArg_ParseTuple(args, "s", &name)) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 292 | return NULL; |
Jack Jansen | d7b568a | 2001-08-11 23:18:55 +0000 | [diff] [blame] | 293 | #ifdef USE_GUSI |
| 294 | /* Work around a bug in GUSI: if you opendir() a file it will |
| 295 | ** actually opendir() the parent directory. |
| 296 | */ |
| 297 | { |
| 298 | struct stat stb; |
| 299 | int res; |
| 300 | |
| 301 | res = stat(name, &stb); |
| 302 | if ( res < 0 ) |
| 303 | return mac_error(); |
| 304 | if (!S_ISDIR(stb.st_mode) ) { |
| 305 | errno = ENOTDIR; |
| 306 | return mac_error(); |
| 307 | } |
| 308 | } |
| 309 | #endif |
| 310 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 311 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 312 | if ((dirp = opendir(name)) == NULL) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 313 | Py_BLOCK_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 314 | return mac_error(); |
| 315 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 316 | if ((d = PyList_New(0)) == NULL) { |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 317 | closedir(dirp); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 318 | Py_BLOCK_THREADS |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 319 | return NULL; |
| 320 | } |
| 321 | while ((ep = readdir(dirp)) != NULL) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 322 | v = PyString_FromString(ep->d_name); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 323 | if (v == NULL) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 324 | Py_DECREF(d); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 325 | d = NULL; |
| 326 | break; |
| 327 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 328 | if (PyList_Append(d, v) != 0) { |
| 329 | Py_DECREF(v); |
| 330 | Py_DECREF(d); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 331 | d = NULL; |
| 332 | break; |
| 333 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 334 | Py_DECREF(v); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 335 | } |
| 336 | closedir(dirp); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 337 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 338 | |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 339 | return d; |
| 340 | } |
| 341 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 342 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 343 | mac_lseek(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 344 | PyObject *self; |
| 345 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 346 | { |
| 347 | int fd; |
| 348 | int where; |
| 349 | int how; |
| 350 | long res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 351 | if (!PyArg_ParseTuple(args, "iii", &fd, &where, &how)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 352 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 353 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 354 | res = lseek(fd, (long)where, how); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 355 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 356 | if (res < 0) |
| 357 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 358 | return PyInt_FromLong(res); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 359 | } |
Jack Jansen | c743c8d | 1996-02-14 16:02:30 +0000 | [diff] [blame] | 360 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 361 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 362 | mac_mkdir(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 363 | PyObject *self; |
| 364 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 365 | { |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 366 | int res; |
| 367 | char *path; |
| 368 | int mode = 0777; /* Unused */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 369 | if (!PyArg_ParseTuple(args, "s|i", &path, &mode)) |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 370 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 371 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 372 | res = mkdir(path, mode); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 373 | Py_END_ALLOW_THREADS |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 374 | if (res < 0) |
| 375 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 376 | Py_INCREF(Py_None); |
| 377 | return Py_None; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 380 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 381 | mac_open(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 382 | PyObject *self; |
| 383 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 384 | { |
| 385 | char *path; |
| 386 | int mode; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 387 | int perm; /* Accepted but ignored */ |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 388 | int fd; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 389 | if (!PyArg_ParseTuple(args, "si|i", &path, &mode, &perm)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 390 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 391 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 392 | fd = open(path, mode); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 393 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 394 | if (fd < 0) |
| 395 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 396 | return PyInt_FromLong((long)fd); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 399 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 400 | mac_read(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 401 | PyObject *self; |
| 402 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 403 | { |
| 404 | int fd, size; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 405 | PyObject *buffer; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 406 | if (!PyArg_ParseTuple(args, "ii", &fd, &size)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 407 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 408 | buffer = PyString_FromStringAndSize((char *)NULL, size); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 409 | if (buffer == NULL) |
| 410 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 411 | Py_BEGIN_ALLOW_THREADS |
| 412 | size = read(fd, PyString_AsString(buffer), size); |
| 413 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 414 | if (size < 0) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 415 | Py_DECREF(buffer); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 416 | return mac_error(); |
| 417 | } |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 418 | _PyString_Resize(&buffer, size); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 419 | return buffer; |
| 420 | } |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 421 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 422 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 423 | mac_rename(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 424 | PyObject *self; |
| 425 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 426 | { |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 427 | return mac_2str(args, rename); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 430 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 431 | mac_rmdir(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 432 | PyObject *self; |
| 433 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 434 | { |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 435 | return mac_1str(args, rmdir); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 438 | static char stat_result__doc__[] = |
| 439 | "stat_result: Result from stat or lstat.\n\n\ |
| 440 | This object may be accessed either as a tuple of\n\ |
| 441 | (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\ |
| 442 | or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\ |
| 443 | \n\ |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 444 | See os.stat for more information.\n"; |
| 445 | |
| 446 | #define COMMON_STAT_RESULT_FIELDS \ |
| 447 | { "st_mode", "protection bits" }, \ |
| 448 | { "st_ino", "inode" }, \ |
Jack Jansen | e54968a | 2001-10-23 22:28:23 +0000 | [diff] [blame] | 449 | { "st_dev", "device" }, \ |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 450 | { "st_nlink", "number of hard links" }, \ |
Jack Jansen | e54968a | 2001-10-23 22:28:23 +0000 | [diff] [blame] | 451 | { "st_uid", "user ID of owner" }, \ |
| 452 | { "st_gid", "group ID of owner" }, \ |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 453 | { "st_size", "total size, in bytes" }, \ |
| 454 | { "st_atime", "time of last access" }, \ |
| 455 | { "st_mtime", "time of last modification" }, \ |
| 456 | { "st_ctime", "time of last change" }, |
| 457 | |
| 458 | |
| 459 | |
| 460 | static PyStructSequence_Field stat_result_fields[] = { |
| 461 | COMMON_STAT_RESULT_FIELDS |
| 462 | {0} |
| 463 | }; |
| 464 | |
| 465 | static PyStructSequence_Desc stat_result_desc = { |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 466 | "mac.stat_result", |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 467 | stat_result__doc__, |
| 468 | stat_result_fields, |
| 469 | 10 |
| 470 | }; |
| 471 | |
| 472 | static PyTypeObject StatResultType; |
| 473 | |
| 474 | #ifdef TARGET_API_MAC_OS8 |
| 475 | static PyStructSequence_Field xstat_result_fields[] = { |
Jack Jansen | e54968a | 2001-10-23 22:28:23 +0000 | [diff] [blame] | 476 | COMMON_STAT_RESULT_FIELDS |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 477 | { "st_rsize" }, |
| 478 | { "st_creator" }, |
| 479 | { "st_type "}, |
| 480 | {0} |
| 481 | }; |
| 482 | |
| 483 | static PyStructSequence_Desc xstat_result_desc = { |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame] | 484 | "mac.xstat_result", |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 485 | stat_result__doc__, |
| 486 | xstat_result_fields, |
| 487 | 13 |
| 488 | }; |
| 489 | |
| 490 | static PyTypeObject XStatResultType; |
| 491 | #endif |
| 492 | |
| 493 | static PyObject * |
| 494 | _pystat_from_struct_stat(struct stat st, void* _mst) |
| 495 | { |
| 496 | PyObject *v; |
| 497 | |
| 498 | #if TARGET_API_MAC_OS8 |
| 499 | struct macstat *mst; |
| 500 | |
| 501 | if (_mst != NULL) |
| 502 | v = PyStructSequence_New(&XStatResultType); |
| 503 | else |
| 504 | #endif |
| 505 | v = PyStructSequence_New(&StatResultType); |
| 506 | PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long)st.st_mode)); |
| 507 | PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long)st.st_ino)); |
| 508 | PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long)st.st_dev)); |
| 509 | PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long)st.st_nlink)); |
| 510 | PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long)st.st_uid)); |
| 511 | PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long)st.st_gid)); |
| 512 | PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong((long)st.st_size)); |
| 513 | PyStructSequence_SET_ITEM(v, 7, |
| 514 | PyFloat_FromDouble((double)st.st_atime)); |
| 515 | PyStructSequence_SET_ITEM(v, 8, |
| 516 | PyFloat_FromDouble((double)st.st_mtime)); |
| 517 | PyStructSequence_SET_ITEM(v, 9, |
| 518 | PyFloat_FromDouble((double)st.st_ctime)); |
| 519 | #if TARGET_API_MAC_OS8 |
| 520 | if (_mst != NULL) { |
| 521 | mst = (struct macstat *) _mst; |
| 522 | PyStructSequence_SET_ITEM(v, 10, |
| 523 | PyInt_FromLong((long)mst->st_rsize)); |
| 524 | PyStructSequence_SET_ITEM(v, 11, |
| 525 | PyString_FromStringAndSize(mst->st_creator, |
| 526 | 4)); |
| 527 | PyStructSequence_SET_ITEM(v, 12, |
| 528 | PyString_FromStringAndSize(mst->st_type, |
| 529 | 4)); |
| 530 | } |
| 531 | #endif |
| 532 | |
| 533 | if (PyErr_Occurred()) { |
| 534 | Py_DECREF(v); |
| 535 | return NULL; |
| 536 | } |
| 537 | |
| 538 | return v; |
| 539 | } |
| 540 | |
| 541 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 542 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 543 | mac_stat(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 544 | PyObject *self; |
| 545 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 546 | { |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 547 | struct stat st; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 548 | char *path; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 549 | int res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 550 | if (!PyArg_ParseTuple(args, "s", &path)) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 551 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 552 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 553 | res = stat(path, &st); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 554 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 555 | if (res != 0) |
| 556 | return mac_error(); |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 557 | |
| 558 | return _pystat_from_struct_stat(st, NULL); |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | #ifdef WEHAVE_FSTAT |
| 562 | static PyObject * |
| 563 | mac_fstat(self, args) |
| 564 | PyObject *self; |
| 565 | PyObject *args; |
| 566 | { |
| 567 | struct stat st; |
| 568 | long fd; |
| 569 | int res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 570 | if (!PyArg_ParseTuple(args, "l", &fd)) |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 571 | return NULL; |
| 572 | Py_BEGIN_ALLOW_THREADS |
| 573 | res = fstat((int)fd, &st); |
| 574 | Py_END_ALLOW_THREADS |
| 575 | if (res != 0) |
| 576 | return mac_error(); |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 577 | |
| 578 | return _pystat_from_struct_stat(st, NULL); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 579 | } |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 580 | #endif /* WEHAVE_FSTAT */ |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 581 | |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 582 | #if TARGET_API_MAC_OS8 |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 583 | static PyObject * |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 584 | mac_xstat(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 585 | PyObject *self; |
| 586 | PyObject *args; |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 587 | { |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 588 | struct macstat mst; |
| 589 | struct stat st; |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 590 | char *path; |
| 591 | int res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 592 | if (!PyArg_ParseTuple(args, "s", &path)) |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 593 | return NULL; |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 594 | /* |
| 595 | ** Convoluted: we want stat() and xstat() to agree, so we call both |
| 596 | ** stat and macstat, and use the latter only for values not provided by |
| 597 | ** the former. |
| 598 | */ |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 599 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 600 | res = macstat(path, &mst); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 601 | Py_END_ALLOW_THREADS |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 602 | if (res != 0) |
| 603 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 604 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 605 | res = stat(path, &st); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 606 | Py_END_ALLOW_THREADS |
Jack Jansen | 59b912a | 1996-10-15 16:13:33 +0000 | [diff] [blame] | 607 | if (res != 0) |
| 608 | return mac_error(); |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 609 | |
| 610 | return _pystat_from_struct_stat(st, (void*) &mst); |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 611 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 612 | #endif |
Guido van Rossum | 222c892 | 1995-08-08 14:10:22 +0000 | [diff] [blame] | 613 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 614 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 615 | mac_sync(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 616 | PyObject *self; |
| 617 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 618 | { |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 619 | int res; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 620 | if (!PyArg_ParseTuple(args, "")) |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 621 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 622 | Py_BEGIN_ALLOW_THREADS |
Jack Jansen | 0e5a733 | 2002-03-21 21:09:36 +0000 | [diff] [blame] | 623 | #ifdef USE_GUSI2 |
| 624 | sync(); |
| 625 | res = 0; |
| 626 | #else |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 627 | res = sync(); |
Jack Jansen | 0e5a733 | 2002-03-21 21:09:36 +0000 | [diff] [blame] | 628 | #endif |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 629 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 630 | if (res != 0) |
| 631 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 632 | Py_INCREF(Py_None); |
| 633 | return Py_None; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 636 | static PyObject * |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 637 | mac_unlink(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 638 | PyObject *self; |
| 639 | PyObject *args; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 640 | { |
Guido van Rossum | 739267b | 1994-08-29 08:42:37 +0000 | [diff] [blame] | 641 | return mac_1str(args, (int (*)(const char *))unlink); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 644 | static PyObject * |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 645 | mac_write(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 646 | PyObject *self; |
| 647 | PyObject *args; |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 648 | { |
| 649 | int fd, size; |
| 650 | char *buffer; |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 651 | if (!PyArg_ParseTuple(args, "is#", &fd, &buffer, &size)) |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 652 | return NULL; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 653 | Py_BEGIN_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 654 | size = write(fd, buffer, size); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 655 | Py_END_ALLOW_THREADS |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 656 | if (size < 0) |
| 657 | return mac_error(); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 658 | return PyInt_FromLong((long)size); |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 659 | } |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 660 | |
Jack Jansen | 46ed276 | 1996-10-23 15:46:57 +0000 | [diff] [blame] | 661 | #ifdef USE_MALLOC_DEBUG |
Jack Jansen | 8748a0b | 2000-08-25 22:18:20 +0000 | [diff] [blame] | 662 | void *mstats(char *); |
| 663 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 664 | static PyObject * |
Jack Jansen | d50e4e1 | 1995-01-18 13:58:04 +0000 | [diff] [blame] | 665 | mac_mstats(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 666 | PyObject*self; |
| 667 | PyObject *args; |
Jack Jansen | d50e4e1 | 1995-01-18 13:58:04 +0000 | [diff] [blame] | 668 | { |
| 669 | mstats("python"); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 670 | Py_INCREF(Py_None); |
| 671 | return Py_None; |
Jack Jansen | d50e4e1 | 1995-01-18 13:58:04 +0000 | [diff] [blame] | 672 | } |
Jack Jansen | 4f27a55 | 1997-02-20 15:22:17 +0000 | [diff] [blame] | 673 | #endif /* USE_MALLOC_DEBUG */ |
Jack Jansen | d50e4e1 | 1995-01-18 13:58:04 +0000 | [diff] [blame] | 674 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 675 | static struct PyMethodDef mac_methods[] = { |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 676 | {"chdir", mac_chdir, 1}, |
| 677 | {"close", mac_close, 1}, |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 678 | #ifdef WEHAVE_DUP |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 679 | {"dup", mac_dup, 1}, |
Guido van Rossum | 921a08f | 1994-05-06 15:56:22 +0000 | [diff] [blame] | 680 | #endif |
Jack Jansen | b697173 | 1996-02-20 16:24:37 +0000 | [diff] [blame] | 681 | #ifdef WEHAVE_FDOPEN |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 682 | {"fdopen", mac_fdopen, 1}, |
Jack Jansen | 0c097ea | 1994-12-14 13:48:38 +0000 | [diff] [blame] | 683 | #endif |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 684 | #ifdef WEHAVE_FSTAT |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 685 | {"fstat", mac_fstat, 1}, |
Jack Jansen | 40bd770 | 1998-02-20 15:56:19 +0000 | [diff] [blame] | 686 | #endif |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 687 | #if TARGET_API_MAC_OS8 |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 688 | {"getbootvol", mac_getbootvol, 1}, /* non-standard */ |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 689 | #endif |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 690 | {"getcwd", mac_getcwd, 1}, |
| 691 | {"listdir", mac_listdir, 1}, |
| 692 | {"lseek", mac_lseek, 1}, |
Jack Jansen | 243b29b | 1996-02-21 12:33:50 +0000 | [diff] [blame] | 693 | {"mkdir", mac_mkdir, 1}, |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 694 | {"open", mac_open, 1}, |
| 695 | {"read", mac_read, 1}, |
| 696 | {"rename", mac_rename, 1}, |
| 697 | {"rmdir", mac_rmdir, 1}, |
| 698 | {"stat", mac_stat, 1}, |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 699 | #if TARGET_API_MAC_OS8 |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 700 | {"xstat", mac_xstat, 1}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 701 | #endif |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 702 | {"sync", mac_sync, 1}, |
| 703 | {"remove", mac_unlink, 1}, |
| 704 | {"unlink", mac_unlink, 1}, |
| 705 | {"write", mac_write, 1}, |
Jack Jansen | 46ed276 | 1996-10-23 15:46:57 +0000 | [diff] [blame] | 706 | #ifdef USE_MALLOC_DEBUG |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 707 | {"mstats", mac_mstats, 1}, |
Jack Jansen | d50e4e1 | 1995-01-18 13:58:04 +0000 | [diff] [blame] | 708 | #endif |
Guido van Rossum | 87f223c | 1994-05-06 15:54:15 +0000 | [diff] [blame] | 709 | |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 710 | {NULL, NULL} /* Sentinel */ |
| 711 | }; |
| 712 | |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 713 | static int |
| 714 | ins(PyObject *d, char *symbol, long value) |
| 715 | { |
| 716 | PyObject* v = PyInt_FromLong(value); |
| 717 | if (!v || PyDict_SetItemString(d, symbol, v) < 0) |
| 718 | return -1; /* triggers fatal error */ |
| 719 | |
| 720 | Py_DECREF(v); |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | static int |
| 725 | all_ins(PyObject *d) |
| 726 | { |
| 727 | #ifdef F_OK |
| 728 | if (ins(d, "F_OK", (long)F_OK)) return -1; |
| 729 | #endif |
| 730 | #ifdef R_OK |
| 731 | if (ins(d, "R_OK", (long)R_OK)) return -1; |
| 732 | #endif |
| 733 | #ifdef W_OK |
| 734 | if (ins(d, "W_OK", (long)W_OK)) return -1; |
| 735 | #endif |
| 736 | #ifdef X_OK |
| 737 | if (ins(d, "X_OK", (long)X_OK)) return -1; |
| 738 | #endif |
| 739 | #ifdef NGROUPS_MAX |
| 740 | if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1; |
| 741 | #endif |
| 742 | #ifdef TMP_MAX |
| 743 | if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1; |
| 744 | #endif |
| 745 | #ifdef WNOHANG |
| 746 | if (ins(d, "WNOHANG", (long)WNOHANG)) return -1; |
| 747 | #endif |
| 748 | #ifdef O_RDONLY |
| 749 | if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1; |
| 750 | #endif |
| 751 | #ifdef O_WRONLY |
| 752 | if (ins(d, "O_WRONLY", (long)O_WRONLY)) return -1; |
| 753 | #endif |
| 754 | #ifdef O_RDWR |
| 755 | if (ins(d, "O_RDWR", (long)O_RDWR)) return -1; |
| 756 | #endif |
| 757 | #ifdef O_NDELAY |
| 758 | if (ins(d, "O_NDELAY", (long)O_NDELAY)) return -1; |
| 759 | #endif |
| 760 | #ifdef O_NONBLOCK |
| 761 | if (ins(d, "O_NONBLOCK", (long)O_NONBLOCK)) return -1; |
| 762 | #endif |
| 763 | #ifdef O_APPEND |
| 764 | if (ins(d, "O_APPEND", (long)O_APPEND)) return -1; |
| 765 | #endif |
| 766 | #ifdef O_DSYNC |
| 767 | if (ins(d, "O_DSYNC", (long)O_DSYNC)) return -1; |
| 768 | #endif |
| 769 | #ifdef O_RSYNC |
| 770 | if (ins(d, "O_RSYNC", (long)O_RSYNC)) return -1; |
| 771 | #endif |
| 772 | #ifdef O_SYNC |
| 773 | if (ins(d, "O_SYNC", (long)O_SYNC)) return -1; |
| 774 | #endif |
| 775 | #ifdef O_NOCTTY |
| 776 | if (ins(d, "O_NOCTTY", (long)O_NOCTTY)) return -1; |
| 777 | #endif |
| 778 | #ifdef O_CREAT |
| 779 | if (ins(d, "O_CREAT", (long)O_CREAT)) return -1; |
| 780 | #endif |
| 781 | #ifdef O_EXCL |
| 782 | if (ins(d, "O_EXCL", (long)O_EXCL)) return -1; |
| 783 | #endif |
| 784 | #ifdef O_TRUNC |
| 785 | if (ins(d, "O_TRUNC", (long)O_TRUNC)) return -1; |
| 786 | #endif |
| 787 | #ifdef O_BINARY |
| 788 | if (ins(d, "O_BINARY", (long)O_BINARY)) return -1; |
| 789 | #endif |
| 790 | #ifdef O_TEXT |
| 791 | if (ins(d, "O_TEXT", (long)O_TEXT)) return -1; |
| 792 | #endif |
| 793 | |
| 794 | #ifdef HAVE_SPAWNV |
| 795 | if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1; |
| 796 | if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1; |
| 797 | if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1; |
| 798 | if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1; |
| 799 | if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1; |
| 800 | #endif |
| 801 | |
| 802 | #if defined(PYOS_OS2) |
| 803 | if (insertvalues(d)) return -1; |
| 804 | #endif |
| 805 | return 0; |
| 806 | } |
| 807 | |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 808 | |
| 809 | void |
| 810 | initmac() |
| 811 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 812 | PyObject *m, *d; |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 813 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 814 | m = Py_InitModule("mac", mac_methods); |
| 815 | d = PyModule_GetDict(m); |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 816 | |
Jack Jansen | ddafd2b | 2001-08-03 13:07:19 +0000 | [diff] [blame] | 817 | if (all_ins(d)) |
| 818 | return; |
| 819 | |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 820 | /* Initialize mac.error exception */ |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 821 | PyDict_SetItemString(d, "error", PyExc_OSError); |
Guido van Rossum | 98bf58f | 2001-10-18 20:34:25 +0000 | [diff] [blame] | 822 | |
| 823 | PyStructSequence_InitType(&StatResultType, &stat_result_desc); |
| 824 | PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType); |
| 825 | |
| 826 | #if TARGET_API_MAC_OS8 |
| 827 | PyStructSequence_InitType(&XStatResultType, &xstat_result_desc); |
| 828 | PyDict_SetItemString(d, "xstat_result", (PyObject*) &XStatResultType); |
| 829 | #endif |
Guido van Rossum | ce9739b | 1994-01-05 16:17:15 +0000 | [diff] [blame] | 830 | } |