blob: 766722ff016cd42e4363008e8968d3a53a56bcfe [file] [log] [blame]
Guido van Rossumce9739b1994-01-05 16:17:15 +00001/***********************************************************
Jack Jansen42218ce1997-01-31 16:15:11 +00002Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
Guido van Rossum99546991995-01-08 14:33:34 +00003The Netherlands.
Guido van Rossumce9739b1994-01-05 16:17:15 +00004
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum87f223c1994-05-06 15:54:15 +000025/* Mac module implementation */
Guido van Rossumce9739b1994-01-05 16:17:15 +000026
Jack Jansenf5c20571997-01-30 15:48:07 +000027#include "Python.h"
Guido van Rossum87f223c1994-05-06 15:54:15 +000028#include "ceval.h"
Guido van Rossumce9739b1994-01-05 16:17:15 +000029
Guido van Rossum87f223c1994-05-06 15:54:15 +000030#include <stdio.h>
31#include <string.h>
32#include <errno.h>
Guido van Rossum739267b1994-08-29 08:42:37 +000033
Jack Jansen6e68a7e2001-05-12 21:31:34 +000034#if TARGET_API_MAC_OS8
Jack Jansend9d0b5f2001-01-12 23:37:14 +000035/* Skip for Carbon */
Jack Jansen59b912a1996-10-15 16:13:33 +000036#include "macstat.h"
Jack Jansene79dc762000-06-02 21:35:07 +000037#endif
38
Jack Jansenc743c8d1996-02-14 16:02:30 +000039#ifdef USE_GUSI
Jack Jansen59b912a1996-10-15 16:13:33 +000040/* 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 Jansen37d21e12000-04-07 09:25:06 +000048#ifdef USE_GUSI1
Jack Jansenb6971731996-02-20 16:24:37 +000049#include <GUSI.h>
Jack Jansen37d21e12000-04-07 09:25:06 +000050#endif /* USE_GUSI1 */
Jack Jansenc743c8d1996-02-14 16:02:30 +000051#include <sys/types.h>
Jack Jansen37d21e12000-04-07 09:25:06 +000052#include <sys/stat.h>
53#else /* USE_GUSI */
Jack Jansen6e68a7e2001-05-12 21:31:34 +000054#if TARGET_API_MAC_OS8
Jack Jansen59b912a1996-10-15 16:13:33 +000055#define stat macstat
Jack Jansene79dc762000-06-02 21:35:07 +000056#endif
Jack Jansen37d21e12000-04-07 09:25:06 +000057#endif /* USE_GUSI */
Guido van Rossumce9739b1994-01-05 16:17:15 +000058
Jack Jansen37d21e12000-04-07 09:25:06 +000059#ifdef USE_GUSI2
60#define sync bad_sync
61#include <unistd.h>
62#include <fcntl.h>
63#undef sync
64int sync(void);
65#else
Jack Jansen12e89e42000-05-12 21:36:29 +000066#define mode_t int
Guido van Rossum87f223c1994-05-06 15:54:15 +000067#include <fcntl.h>
Jack Jansene79dc762000-06-02 21:35:07 +000068#ifdef _POSIX
69#include <unistd.h>
70#include <stat.h>
71#endif
Jack Jansen0c097ea1994-12-14 13:48:38 +000072#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +000073
Jack Jansenb6971731996-02-20 16:24:37 +000074/* Optional routines, for some compiler/runtime combinations */
Jack Jansenb6971731996-02-20 16:24:37 +000075#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 Jansen40bd7701998-02-20 15:56:19 +000081#if defined(USE_GUSI)
82#define WEHAVE_FSTAT
83#endif
Jack Jansen7cbf4801995-01-22 16:52:38 +000084
Guido van Rossumd4d77281994-08-19 10:51:31 +000085#include "macdefs.h"
Jack Jansenc743c8d1996-02-14 16:02:30 +000086#ifdef USE_GUSI
87#include <dirent.h>
88#else
Guido van Rossumd4d77281994-08-19 10:51:31 +000089#include "dirent.h"
Jack Jansenc743c8d1996-02-14 16:02:30 +000090#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +000091
92#ifndef MAXPATHLEN
93#define MAXPATHLEN 1024
94#endif
95
96/* Prototypes for Unix simulation on Mac */
97
Jack Jansenb6971731996-02-20 16:24:37 +000098#ifndef USE_GUSI
99
Jack Jansend88296d2000-07-11 19:51:05 +0000100int chdir(const char *path);
101int mkdir(const char *path, int mode);
102DIR * opendir(char *);
103void closedir(DIR *);
104struct dirent * readdir(DIR *);
105int rmdir(const char *path);
106int sync(void);
Jack Jansenb6971731996-02-20 16:24:37 +0000107
Jack Jansend88296d2000-07-11 19:51:05 +0000108int unlink(const char *);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000109
Jack Jansenb6971731996-02-20 16:24:37 +0000110#endif /* USE_GUSI */
111
Jack Jansend88296d2000-07-11 19:51:05 +0000112char *getwd(char *);
113char *getbootvol(void);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000114
115
Jack Jansenf5c20571997-01-30 15:48:07 +0000116static PyObject *MacError; /* Exception mac.error */
Guido van Rossum87f223c1994-05-06 15:54:15 +0000117
118/* Set a MAC-specific error from errno, and return NULL */
119
Jack Jansenf5c20571997-01-30 15:48:07 +0000120static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000121mac_error()
122{
Jack Jansenf5c20571997-01-30 15:48:07 +0000123 return PyErr_SetFromErrno(MacError);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000124}
125
126/* MAC generic methods */
127
Jack Jansenf5c20571997-01-30 15:48:07 +0000128static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000129mac_1str(args, func)
Jack Jansenf5c20571997-01-30 15:48:07 +0000130 PyObject *args;
Jack Jansend88296d2000-07-11 19:51:05 +0000131 int (*func)(const char *);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000132{
133 char *path1;
134 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000135 if (!PyArg_ParseTuple(args, "s", &path1))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000136 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000137 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000138 res = (*func)(path1);
Jack Jansenf5c20571997-01-30 15:48:07 +0000139 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000140 if (res < 0)
141 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000142 Py_INCREF(Py_None);
143 return Py_None;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000144}
145
Jack Jansenf5c20571997-01-30 15:48:07 +0000146static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000147mac_2str(args, func)
Jack Jansenf5c20571997-01-30 15:48:07 +0000148 PyObject *args;
Jack Jansend88296d2000-07-11 19:51:05 +0000149 int (*func)(const char *, const char *);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000150{
151 char *path1, *path2;
152 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000153 if (!PyArg_ParseTuple(args, "ss", &path1, &path2))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000154 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000155 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000156 res = (*func)(path1, path2);
Jack Jansenf5c20571997-01-30 15:48:07 +0000157 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000158 if (res < 0)
159 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000160 Py_INCREF(Py_None);
161 return Py_None;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000162}
163
Jack Jansenf5c20571997-01-30 15:48:07 +0000164static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000165mac_strint(args, func)
Jack Jansenf5c20571997-01-30 15:48:07 +0000166 PyObject *args;
Jack Jansend88296d2000-07-11 19:51:05 +0000167 int (*func)(const char *, int);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000168{
169 char *path;
170 int i;
171 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000172 if (!PyArg_ParseTuple(args, "si", &path, &i))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000173 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000174 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000175 res = (*func)(path, i);
Jack Jansenf5c20571997-01-30 15:48:07 +0000176 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000177 if (res < 0)
178 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000179 Py_INCREF(Py_None);
180 return Py_None;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000181}
182
Jack Jansenf5c20571997-01-30 15:48:07 +0000183static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000184mac_chdir(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000185 PyObject *self;
186 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000187{
Jack Jansen37d21e12000-04-07 09:25:06 +0000188#ifdef USE_GUSI1
Jack Jansenf5c20571997-01-30 15:48:07 +0000189 PyObject *rv;
Jack Jansen378815c1996-03-06 16:21:34 +0000190
191 /* Change MacOS's idea of wd too */
192 rv = mac_1str(args, chdir);
193 PyMac_FixGUSIcd();
194 return rv;
195#else
Guido van Rossum87f223c1994-05-06 15:54:15 +0000196 return mac_1str(args, chdir);
Jack Jansen378815c1996-03-06 16:21:34 +0000197#endif
198
Guido van Rossum87f223c1994-05-06 15:54:15 +0000199}
200
Jack Jansenf5c20571997-01-30 15:48:07 +0000201static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000202mac_close(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000203 PyObject *self;
204 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000205{
206 int fd, res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000207 if (!PyArg_ParseTuple(args, "i", &fd))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000208 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000209 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000210 res = close(fd);
Jack Jansenf5c20571997-01-30 15:48:07 +0000211 Py_END_ALLOW_THREADS
Jack Jansen37d21e12000-04-07 09:25:06 +0000212#ifndef USE_GUSI1
Jack Jansenb6971731996-02-20 16:24:37 +0000213 /* GUSI gives surious errors here? */
Guido van Rossum87f223c1994-05-06 15:54:15 +0000214 if (res < 0)
215 return mac_error();
Jack Jansenb6971731996-02-20 16:24:37 +0000216#endif
Jack Jansenf5c20571997-01-30 15:48:07 +0000217 Py_INCREF(Py_None);
218 return Py_None;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000219}
220
Jack Jansenb6971731996-02-20 16:24:37 +0000221#ifdef WEHAVE_DUP
Guido van Rossum921a08f1994-05-06 15:56:22 +0000222
Jack Jansenf5c20571997-01-30 15:48:07 +0000223static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000224mac_dup(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000225 PyObject *self;
226 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000227{
228 int fd;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000229 if (!PyArg_ParseTuple(args, "i", &fd))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000230 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000231 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000232 fd = dup(fd);
Jack Jansenf5c20571997-01-30 15:48:07 +0000233 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000234 if (fd < 0)
235 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000236 return PyInt_FromLong((long)fd);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000237}
238
Jack Jansenb6971731996-02-20 16:24:37 +0000239#endif
Guido van Rossume7834441994-08-26 09:09:48 +0000240
Jack Jansenb6971731996-02-20 16:24:37 +0000241#ifdef WEHAVE_FDOPEN
Jack Jansenf5c20571997-01-30 15:48:07 +0000242static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000243mac_fdopen(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000244 PyObject *self;
245 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000246{
Jack Jansend88296d2000-07-11 19:51:05 +0000247 extern int fclose(FILE *);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000248 int fd;
249 char *mode;
250 FILE *fp;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000251 if (!PyArg_ParseTuple(args, "is", &fd, &mode))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000252 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000253 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000254 fp = fdopen(fd, mode);
Jack Jansenf5c20571997-01-30 15:48:07 +0000255 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000256 if (fp == NULL)
257 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000258 return PyFile_FromFile(fp, "(fdopen)", mode, fclose);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000259}
Jack Jansen0c097ea1994-12-14 13:48:38 +0000260#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000261
Jack Jansen6e68a7e2001-05-12 21:31:34 +0000262#if TARGET_API_MAC_OS8
Jack Jansenf5c20571997-01-30 15:48:07 +0000263static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000264mac_getbootvol(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000265 PyObject *self;
266 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000267{
268 char *res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000269 if (!PyArg_ParseTuple(args, ""))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000270 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000271 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000272 res = getbootvol();
Jack Jansenf5c20571997-01-30 15:48:07 +0000273 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000274 if (res == NULL)
275 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000276 return PyString_FromString(res);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000277}
Jack Jansene79dc762000-06-02 21:35:07 +0000278#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000279
Jack Jansenf5c20571997-01-30 15:48:07 +0000280static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000281mac_getcwd(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000282 PyObject *self;
283 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000284{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000285 char path[MAXPATHLEN];
286 char *res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000287 if (!PyArg_ParseTuple(args, ""))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000288 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000289 Py_BEGIN_ALLOW_THREADS
Jack Jansenb6971731996-02-20 16:24:37 +0000290#ifdef USE_GUSI
291 res = getcwd(path, sizeof path);
292#else
Guido van Rossum87f223c1994-05-06 15:54:15 +0000293 res = getwd(path);
Jack Jansenb6971731996-02-20 16:24:37 +0000294#endif
Jack Jansenf5c20571997-01-30 15:48:07 +0000295 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000296 if (res == NULL) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000297 PyErr_SetString(MacError, path);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000298 return NULL;
299 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000300 return PyString_FromString(res);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000301}
302
Jack Jansenf5c20571997-01-30 15:48:07 +0000303static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000304mac_listdir(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000305 PyObject *self;
306 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000307{
Guido van Rossumce9739b1994-01-05 16:17:15 +0000308 char *name;
Jack Jansenf5c20571997-01-30 15:48:07 +0000309 PyObject *d, *v;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000310 DIR *dirp;
Guido van Rossumd4d77281994-08-19 10:51:31 +0000311 struct dirent *ep;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000312 if (!PyArg_ParseTuple(args, "s", &name))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000313 return NULL;
Jack Jansend7b568a2001-08-11 23:18:55 +0000314#ifdef USE_GUSI
315 /* Work around a bug in GUSI: if you opendir() a file it will
316 ** actually opendir() the parent directory.
317 */
318 {
319 struct stat stb;
320 int res;
321
322 res = stat(name, &stb);
323 if ( res < 0 )
324 return mac_error();
325 if (!S_ISDIR(stb.st_mode) ) {
326 errno = ENOTDIR;
327 return mac_error();
328 }
329 }
330#endif
331
Jack Jansenf5c20571997-01-30 15:48:07 +0000332 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000333 if ((dirp = opendir(name)) == NULL) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000334 Py_BLOCK_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000335 return mac_error();
336 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000337 if ((d = PyList_New(0)) == NULL) {
Guido van Rossumce9739b1994-01-05 16:17:15 +0000338 closedir(dirp);
Jack Jansenf5c20571997-01-30 15:48:07 +0000339 Py_BLOCK_THREADS
Guido van Rossumce9739b1994-01-05 16:17:15 +0000340 return NULL;
341 }
342 while ((ep = readdir(dirp)) != NULL) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000343 v = PyString_FromString(ep->d_name);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000344 if (v == NULL) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000345 Py_DECREF(d);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000346 d = NULL;
347 break;
348 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000349 if (PyList_Append(d, v) != 0) {
350 Py_DECREF(v);
351 Py_DECREF(d);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000352 d = NULL;
353 break;
354 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000355 Py_DECREF(v);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000356 }
357 closedir(dirp);
Jack Jansenf5c20571997-01-30 15:48:07 +0000358 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000359
Guido van Rossumce9739b1994-01-05 16:17:15 +0000360 return d;
361}
362
Jack Jansenf5c20571997-01-30 15:48:07 +0000363static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000364mac_lseek(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000365 PyObject *self;
366 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000367{
368 int fd;
369 int where;
370 int how;
371 long res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000372 if (!PyArg_ParseTuple(args, "iii", &fd, &where, &how))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000373 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000374 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000375 res = lseek(fd, (long)where, how);
Jack Jansenf5c20571997-01-30 15:48:07 +0000376 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000377 if (res < 0)
378 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000379 return PyInt_FromLong(res);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000380}
Jack Jansenc743c8d1996-02-14 16:02:30 +0000381
Jack Jansenf5c20571997-01-30 15:48:07 +0000382static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000383mac_mkdir(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000384 PyObject *self;
385 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000386{
Jack Jansen243b29b1996-02-21 12:33:50 +0000387 int res;
388 char *path;
389 int mode = 0777; /* Unused */
Jack Jansenf5c20571997-01-30 15:48:07 +0000390 if (!PyArg_ParseTuple(args, "s|i", &path, &mode))
Jack Jansen243b29b1996-02-21 12:33:50 +0000391 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000392 Py_BEGIN_ALLOW_THREADS
Jack Jansen37d21e12000-04-07 09:25:06 +0000393#ifdef USE_GUSI1
Jack Jansen3ca6edd1996-08-06 16:06:31 +0000394 res = mkdir(path);
395#else
Jack Jansen243b29b1996-02-21 12:33:50 +0000396 res = mkdir(path, mode);
Jack Jansen3ca6edd1996-08-06 16:06:31 +0000397#endif
Jack Jansenf5c20571997-01-30 15:48:07 +0000398 Py_END_ALLOW_THREADS
Jack Jansen243b29b1996-02-21 12:33:50 +0000399 if (res < 0)
400 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000401 Py_INCREF(Py_None);
402 return Py_None;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000403}
404
Jack Jansenf5c20571997-01-30 15:48:07 +0000405static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000406mac_open(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000407 PyObject *self;
408 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000409{
410 char *path;
411 int mode;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000412 int perm; /* Accepted but ignored */
Guido van Rossum87f223c1994-05-06 15:54:15 +0000413 int fd;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000414 if (!PyArg_ParseTuple(args, "si|i", &path, &mode, &perm))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000415 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000416 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000417 fd = open(path, mode);
Jack Jansenf5c20571997-01-30 15:48:07 +0000418 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000419 if (fd < 0)
420 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000421 return PyInt_FromLong((long)fd);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000422}
423
Jack Jansenf5c20571997-01-30 15:48:07 +0000424static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000425mac_read(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000426 PyObject *self;
427 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000428{
429 int fd, size;
Jack Jansenf5c20571997-01-30 15:48:07 +0000430 PyObject *buffer;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000431 if (!PyArg_ParseTuple(args, "ii", &fd, &size))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000432 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000433 buffer = PyString_FromStringAndSize((char *)NULL, size);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000434 if (buffer == NULL)
435 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000436 Py_BEGIN_ALLOW_THREADS
437 size = read(fd, PyString_AsString(buffer), size);
438 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000439 if (size < 0) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000440 Py_DECREF(buffer);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000441 return mac_error();
442 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000443 _PyString_Resize(&buffer, size);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000444 return buffer;
445}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000446
Jack Jansenf5c20571997-01-30 15:48:07 +0000447static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000448mac_rename(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000449 PyObject *self;
450 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000451{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000452 return mac_2str(args, rename);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000453}
454
Jack Jansenf5c20571997-01-30 15:48:07 +0000455static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000456mac_rmdir(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000457 PyObject *self;
458 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000459{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000460 return mac_1str(args, rmdir);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000461}
462
Jack Jansenf5c20571997-01-30 15:48:07 +0000463static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000464mac_stat(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000465 PyObject *self;
466 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000467{
Jack Jansen59b912a1996-10-15 16:13:33 +0000468 struct stat st;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000469 char *path;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000470 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000471 if (!PyArg_ParseTuple(args, "s", &path))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000472 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000473 Py_BEGIN_ALLOW_THREADS
Jack Jansen59b912a1996-10-15 16:13:33 +0000474 res = stat(path, &st);
Jack Jansenf5c20571997-01-30 15:48:07 +0000475 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000476 if (res != 0)
477 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000478 return Py_BuildValue("(lllllllddd)",
Jack Jansen59b912a1996-10-15 16:13:33 +0000479 (long)st.st_mode,
480 (long)st.st_ino,
481 (long)st.st_dev,
482 (long)st.st_nlink,
483 (long)st.st_uid,
484 (long)st.st_gid,
485 (long)st.st_size,
486 (double)st.st_atime,
487 (double)st.st_mtime,
488 (double)st.st_ctime);
Jack Jansen40bd7701998-02-20 15:56:19 +0000489}
490
491#ifdef WEHAVE_FSTAT
492static PyObject *
493mac_fstat(self, args)
494 PyObject *self;
495 PyObject *args;
496{
497 struct stat st;
498 long fd;
499 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000500 if (!PyArg_ParseTuple(args, "l", &fd))
Jack Jansen40bd7701998-02-20 15:56:19 +0000501 return NULL;
502 Py_BEGIN_ALLOW_THREADS
503 res = fstat((int)fd, &st);
504 Py_END_ALLOW_THREADS
505 if (res != 0)
506 return mac_error();
507 return Py_BuildValue("(lllllllddd)",
Guido van Rossum87f223c1994-05-06 15:54:15 +0000508 (long)st.st_mode,
Guido van Rossume7834441994-08-26 09:09:48 +0000509 (long)st.st_ino,
Guido van Rossumd4d77281994-08-19 10:51:31 +0000510 (long)st.st_dev,
511 (long)st.st_nlink,
512 (long)st.st_uid,
513 (long)st.st_gid,
Guido van Rossum87f223c1994-05-06 15:54:15 +0000514 (long)st.st_size,
Jack Jansen40bd7701998-02-20 15:56:19 +0000515 (double)st.st_atime,
516 (double)st.st_mtime,
517 (double)st.st_ctime);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000518}
Jack Jansen40bd7701998-02-20 15:56:19 +0000519#endif /* WEHAVE_FSTAT */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000520
Jack Jansen6e68a7e2001-05-12 21:31:34 +0000521#if TARGET_API_MAC_OS8
Jack Jansenf5c20571997-01-30 15:48:07 +0000522static PyObject *
Guido van Rossum222c8921995-08-08 14:10:22 +0000523mac_xstat(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000524 PyObject *self;
525 PyObject *args;
Guido van Rossum222c8921995-08-08 14:10:22 +0000526{
Jack Jansen59b912a1996-10-15 16:13:33 +0000527 struct macstat mst;
528 struct stat st;
Guido van Rossum222c8921995-08-08 14:10:22 +0000529 char *path;
530 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000531 if (!PyArg_ParseTuple(args, "s", &path))
Guido van Rossum222c8921995-08-08 14:10:22 +0000532 return NULL;
Jack Jansen59b912a1996-10-15 16:13:33 +0000533 /*
534 ** Convoluted: we want stat() and xstat() to agree, so we call both
535 ** stat and macstat, and use the latter only for values not provided by
536 ** the former.
537 */
Jack Jansenf5c20571997-01-30 15:48:07 +0000538 Py_BEGIN_ALLOW_THREADS
Jack Jansen59b912a1996-10-15 16:13:33 +0000539 res = macstat(path, &mst);
Jack Jansenf5c20571997-01-30 15:48:07 +0000540 Py_END_ALLOW_THREADS
Guido van Rossum222c8921995-08-08 14:10:22 +0000541 if (res != 0)
542 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000543 Py_BEGIN_ALLOW_THREADS
Jack Jansen59b912a1996-10-15 16:13:33 +0000544 res = stat(path, &st);
Jack Jansenf5c20571997-01-30 15:48:07 +0000545 Py_END_ALLOW_THREADS
Jack Jansen59b912a1996-10-15 16:13:33 +0000546 if (res != 0)
547 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000548 return Py_BuildValue("(llllllldddls#s#)",
Jack Jansenc743c8d1996-02-14 16:02:30 +0000549 (long)st.st_mode,
550 (long)st.st_ino,
551 (long)st.st_dev,
552 (long)st.st_nlink,
553 (long)st.st_uid,
554 (long)st.st_gid,
555 (long)st.st_size,
Jack Jansen59b912a1996-10-15 16:13:33 +0000556 (double)st.st_atime,
557 (double)st.st_mtime,
558 (double)st.st_ctime,
559 (long)mst.st_rsize,
560 mst.st_creator, 4,
561 mst.st_type, 4);
Guido van Rossum222c8921995-08-08 14:10:22 +0000562}
Jack Jansene79dc762000-06-02 21:35:07 +0000563#endif
Guido van Rossum222c8921995-08-08 14:10:22 +0000564
Jack Jansenf5c20571997-01-30 15:48:07 +0000565static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000566mac_sync(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000567 PyObject *self;
568 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000569{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000570 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000571 if (!PyArg_ParseTuple(args, ""))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000572 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000573 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000574 res = sync();
Jack Jansenf5c20571997-01-30 15:48:07 +0000575 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000576 if (res != 0)
577 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000578 Py_INCREF(Py_None);
579 return Py_None;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000580}
581
Jack Jansenf5c20571997-01-30 15:48:07 +0000582static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000583mac_unlink(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000584 PyObject *self;
585 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000586{
Guido van Rossum739267b1994-08-29 08:42:37 +0000587 return mac_1str(args, (int (*)(const char *))unlink);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000588}
589
Jack Jansenf5c20571997-01-30 15:48:07 +0000590static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000591mac_write(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000592 PyObject *self;
593 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000594{
595 int fd, size;
596 char *buffer;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000597 if (!PyArg_ParseTuple(args, "is#", &fd, &buffer, &size))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000598 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000599 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000600 size = write(fd, buffer, size);
Jack Jansenf5c20571997-01-30 15:48:07 +0000601 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000602 if (size < 0)
603 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000604 return PyInt_FromLong((long)size);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000605}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000606
Jack Jansen46ed2761996-10-23 15:46:57 +0000607#ifdef USE_MALLOC_DEBUG
Jack Jansen8748a0b2000-08-25 22:18:20 +0000608void *mstats(char *);
609
Jack Jansenf5c20571997-01-30 15:48:07 +0000610static PyObject *
Jack Jansend50e4e11995-01-18 13:58:04 +0000611mac_mstats(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000612 PyObject*self;
613 PyObject *args;
Jack Jansend50e4e11995-01-18 13:58:04 +0000614{
615 mstats("python");
Jack Jansenf5c20571997-01-30 15:48:07 +0000616 Py_INCREF(Py_None);
617 return Py_None;
Jack Jansend50e4e11995-01-18 13:58:04 +0000618}
Jack Jansen4f27a551997-02-20 15:22:17 +0000619#endif /* USE_MALLOC_DEBUG */
Jack Jansend50e4e11995-01-18 13:58:04 +0000620
Jack Jansenf5c20571997-01-30 15:48:07 +0000621static struct PyMethodDef mac_methods[] = {
Jack Jansenddafd2b2001-08-03 13:07:19 +0000622 {"chdir", mac_chdir, 1},
623 {"close", mac_close, 1},
Jack Jansenb6971731996-02-20 16:24:37 +0000624#ifdef WEHAVE_DUP
Jack Jansenddafd2b2001-08-03 13:07:19 +0000625 {"dup", mac_dup, 1},
Guido van Rossum921a08f1994-05-06 15:56:22 +0000626#endif
Jack Jansenb6971731996-02-20 16:24:37 +0000627#ifdef WEHAVE_FDOPEN
Jack Jansenddafd2b2001-08-03 13:07:19 +0000628 {"fdopen", mac_fdopen, 1},
Jack Jansen0c097ea1994-12-14 13:48:38 +0000629#endif
Jack Jansen40bd7701998-02-20 15:56:19 +0000630#ifdef WEHAVE_FSTAT
Jack Jansenddafd2b2001-08-03 13:07:19 +0000631 {"fstat", mac_fstat, 1},
Jack Jansen40bd7701998-02-20 15:56:19 +0000632#endif
Jack Jansen6e68a7e2001-05-12 21:31:34 +0000633#if TARGET_API_MAC_OS8
Jack Jansenddafd2b2001-08-03 13:07:19 +0000634 {"getbootvol", mac_getbootvol, 1}, /* non-standard */
Jack Jansene79dc762000-06-02 21:35:07 +0000635#endif
Jack Jansenddafd2b2001-08-03 13:07:19 +0000636 {"getcwd", mac_getcwd, 1},
637 {"listdir", mac_listdir, 1},
638 {"lseek", mac_lseek, 1},
Jack Jansen243b29b1996-02-21 12:33:50 +0000639 {"mkdir", mac_mkdir, 1},
Jack Jansenddafd2b2001-08-03 13:07:19 +0000640 {"open", mac_open, 1},
641 {"read", mac_read, 1},
642 {"rename", mac_rename, 1},
643 {"rmdir", mac_rmdir, 1},
644 {"stat", mac_stat, 1},
Jack Jansen6e68a7e2001-05-12 21:31:34 +0000645#if TARGET_API_MAC_OS8
Jack Jansenddafd2b2001-08-03 13:07:19 +0000646 {"xstat", mac_xstat, 1},
Jack Jansene79dc762000-06-02 21:35:07 +0000647#endif
Jack Jansenddafd2b2001-08-03 13:07:19 +0000648 {"sync", mac_sync, 1},
649 {"remove", mac_unlink, 1},
650 {"unlink", mac_unlink, 1},
651 {"write", mac_write, 1},
Jack Jansen46ed2761996-10-23 15:46:57 +0000652#ifdef USE_MALLOC_DEBUG
Jack Jansenddafd2b2001-08-03 13:07:19 +0000653 {"mstats", mac_mstats, 1},
Jack Jansend50e4e11995-01-18 13:58:04 +0000654#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000655
Guido van Rossumce9739b1994-01-05 16:17:15 +0000656 {NULL, NULL} /* Sentinel */
657};
658
Jack Jansenddafd2b2001-08-03 13:07:19 +0000659static int
660ins(PyObject *d, char *symbol, long value)
661{
662 PyObject* v = PyInt_FromLong(value);
663 if (!v || PyDict_SetItemString(d, symbol, v) < 0)
664 return -1; /* triggers fatal error */
665
666 Py_DECREF(v);
667 return 0;
668}
669
670static int
671all_ins(PyObject *d)
672{
673#ifdef F_OK
674 if (ins(d, "F_OK", (long)F_OK)) return -1;
675#endif
676#ifdef R_OK
677 if (ins(d, "R_OK", (long)R_OK)) return -1;
678#endif
679#ifdef W_OK
680 if (ins(d, "W_OK", (long)W_OK)) return -1;
681#endif
682#ifdef X_OK
683 if (ins(d, "X_OK", (long)X_OK)) return -1;
684#endif
685#ifdef NGROUPS_MAX
686 if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1;
687#endif
688#ifdef TMP_MAX
689 if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1;
690#endif
691#ifdef WNOHANG
692 if (ins(d, "WNOHANG", (long)WNOHANG)) return -1;
693#endif
694#ifdef O_RDONLY
695 if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1;
696#endif
697#ifdef O_WRONLY
698 if (ins(d, "O_WRONLY", (long)O_WRONLY)) return -1;
699#endif
700#ifdef O_RDWR
701 if (ins(d, "O_RDWR", (long)O_RDWR)) return -1;
702#endif
703#ifdef O_NDELAY
704 if (ins(d, "O_NDELAY", (long)O_NDELAY)) return -1;
705#endif
706#ifdef O_NONBLOCK
707 if (ins(d, "O_NONBLOCK", (long)O_NONBLOCK)) return -1;
708#endif
709#ifdef O_APPEND
710 if (ins(d, "O_APPEND", (long)O_APPEND)) return -1;
711#endif
712#ifdef O_DSYNC
713 if (ins(d, "O_DSYNC", (long)O_DSYNC)) return -1;
714#endif
715#ifdef O_RSYNC
716 if (ins(d, "O_RSYNC", (long)O_RSYNC)) return -1;
717#endif
718#ifdef O_SYNC
719 if (ins(d, "O_SYNC", (long)O_SYNC)) return -1;
720#endif
721#ifdef O_NOCTTY
722 if (ins(d, "O_NOCTTY", (long)O_NOCTTY)) return -1;
723#endif
724#ifdef O_CREAT
725 if (ins(d, "O_CREAT", (long)O_CREAT)) return -1;
726#endif
727#ifdef O_EXCL
728 if (ins(d, "O_EXCL", (long)O_EXCL)) return -1;
729#endif
730#ifdef O_TRUNC
731 if (ins(d, "O_TRUNC", (long)O_TRUNC)) return -1;
732#endif
733#ifdef O_BINARY
734 if (ins(d, "O_BINARY", (long)O_BINARY)) return -1;
735#endif
736#ifdef O_TEXT
737 if (ins(d, "O_TEXT", (long)O_TEXT)) return -1;
738#endif
739
740#ifdef HAVE_SPAWNV
741 if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1;
742 if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1;
743 if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1;
744 if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1;
745 if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1;
746#endif
747
748#if defined(PYOS_OS2)
749 if (insertvalues(d)) return -1;
750#endif
751 return 0;
752}
753
Guido van Rossumce9739b1994-01-05 16:17:15 +0000754
755void
756initmac()
757{
Jack Jansenf5c20571997-01-30 15:48:07 +0000758 PyObject *m, *d;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000759
Jack Jansenf5c20571997-01-30 15:48:07 +0000760 m = Py_InitModule("mac", mac_methods);
761 d = PyModule_GetDict(m);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000762
Jack Jansenddafd2b2001-08-03 13:07:19 +0000763 if (all_ins(d))
764 return;
765
Guido van Rossumce9739b1994-01-05 16:17:15 +0000766 /* Initialize mac.error exception */
Jack Jansen55e39271997-10-07 21:47:25 +0000767 MacError = PyErr_NewException("mac.error", NULL, NULL);
768 PyDict_SetItemString(d, "error", MacError);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000769}