blob: 7735ab34cd20d5132fc0ee37914cf19dc21c2db8 [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 Jansenf5c20571997-01-30 15:48:07 +0000314 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000315 if ((dirp = opendir(name)) == NULL) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000316 Py_BLOCK_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000317 return mac_error();
318 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000319 if ((d = PyList_New(0)) == NULL) {
Guido van Rossumce9739b1994-01-05 16:17:15 +0000320 closedir(dirp);
Jack Jansenf5c20571997-01-30 15:48:07 +0000321 Py_BLOCK_THREADS
Guido van Rossumce9739b1994-01-05 16:17:15 +0000322 return NULL;
323 }
324 while ((ep = readdir(dirp)) != NULL) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000325 v = PyString_FromString(ep->d_name);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000326 if (v == NULL) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000327 Py_DECREF(d);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000328 d = NULL;
329 break;
330 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000331 if (PyList_Append(d, v) != 0) {
332 Py_DECREF(v);
333 Py_DECREF(d);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000334 d = NULL;
335 break;
336 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000337 Py_DECREF(v);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000338 }
339 closedir(dirp);
Jack Jansenf5c20571997-01-30 15:48:07 +0000340 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000341
Guido van Rossumce9739b1994-01-05 16:17:15 +0000342 return d;
343}
344
Jack Jansenf5c20571997-01-30 15:48:07 +0000345static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000346mac_lseek(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000347 PyObject *self;
348 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000349{
350 int fd;
351 int where;
352 int how;
353 long res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000354 if (!PyArg_ParseTuple(args, "iii", &fd, &where, &how))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000355 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000356 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000357 res = lseek(fd, (long)where, how);
Jack Jansenf5c20571997-01-30 15:48:07 +0000358 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000359 if (res < 0)
360 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000361 return PyInt_FromLong(res);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000362}
Jack Jansenc743c8d1996-02-14 16:02:30 +0000363
Jack Jansenf5c20571997-01-30 15:48:07 +0000364static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000365mac_mkdir(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000366 PyObject *self;
367 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000368{
Jack Jansen243b29b1996-02-21 12:33:50 +0000369 int res;
370 char *path;
371 int mode = 0777; /* Unused */
Jack Jansenf5c20571997-01-30 15:48:07 +0000372 if (!PyArg_ParseTuple(args, "s|i", &path, &mode))
Jack Jansen243b29b1996-02-21 12:33:50 +0000373 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000374 Py_BEGIN_ALLOW_THREADS
Jack Jansen37d21e12000-04-07 09:25:06 +0000375#ifdef USE_GUSI1
Jack Jansen3ca6edd1996-08-06 16:06:31 +0000376 res = mkdir(path);
377#else
Jack Jansen243b29b1996-02-21 12:33:50 +0000378 res = mkdir(path, mode);
Jack Jansen3ca6edd1996-08-06 16:06:31 +0000379#endif
Jack Jansenf5c20571997-01-30 15:48:07 +0000380 Py_END_ALLOW_THREADS
Jack Jansen243b29b1996-02-21 12:33:50 +0000381 if (res < 0)
382 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000383 Py_INCREF(Py_None);
384 return Py_None;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000385}
386
Jack Jansenf5c20571997-01-30 15:48:07 +0000387static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000388mac_open(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000389 PyObject *self;
390 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000391{
392 char *path;
393 int mode;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000394 int perm; /* Accepted but ignored */
Guido van Rossum87f223c1994-05-06 15:54:15 +0000395 int fd;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000396 if (!PyArg_ParseTuple(args, "si|i", &path, &mode, &perm))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000397 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000398 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000399 fd = open(path, mode);
Jack Jansenf5c20571997-01-30 15:48:07 +0000400 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000401 if (fd < 0)
402 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000403 return PyInt_FromLong((long)fd);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000404}
405
Jack Jansenf5c20571997-01-30 15:48:07 +0000406static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000407mac_read(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000408 PyObject *self;
409 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000410{
411 int fd, size;
Jack Jansenf5c20571997-01-30 15:48:07 +0000412 PyObject *buffer;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000413 if (!PyArg_ParseTuple(args, "ii", &fd, &size))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000414 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000415 buffer = PyString_FromStringAndSize((char *)NULL, size);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000416 if (buffer == NULL)
417 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000418 Py_BEGIN_ALLOW_THREADS
419 size = read(fd, PyString_AsString(buffer), size);
420 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000421 if (size < 0) {
Jack Jansenf5c20571997-01-30 15:48:07 +0000422 Py_DECREF(buffer);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000423 return mac_error();
424 }
Jack Jansenf5c20571997-01-30 15:48:07 +0000425 _PyString_Resize(&buffer, size);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000426 return buffer;
427}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000428
Jack Jansenf5c20571997-01-30 15:48:07 +0000429static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000430mac_rename(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000431 PyObject *self;
432 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000433{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000434 return mac_2str(args, rename);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000435}
436
Jack Jansenf5c20571997-01-30 15:48:07 +0000437static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000438mac_rmdir(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000439 PyObject *self;
440 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000441{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000442 return mac_1str(args, rmdir);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000443}
444
Jack Jansenf5c20571997-01-30 15:48:07 +0000445static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000446mac_stat(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000447 PyObject *self;
448 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000449{
Jack Jansen59b912a1996-10-15 16:13:33 +0000450 struct stat st;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000451 char *path;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000452 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000453 if (!PyArg_ParseTuple(args, "s", &path))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000454 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000455 Py_BEGIN_ALLOW_THREADS
Jack Jansen59b912a1996-10-15 16:13:33 +0000456 res = stat(path, &st);
Jack Jansenf5c20571997-01-30 15:48:07 +0000457 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000458 if (res != 0)
459 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000460 return Py_BuildValue("(lllllllddd)",
Jack Jansen59b912a1996-10-15 16:13:33 +0000461 (long)st.st_mode,
462 (long)st.st_ino,
463 (long)st.st_dev,
464 (long)st.st_nlink,
465 (long)st.st_uid,
466 (long)st.st_gid,
467 (long)st.st_size,
468 (double)st.st_atime,
469 (double)st.st_mtime,
470 (double)st.st_ctime);
Jack Jansen40bd7701998-02-20 15:56:19 +0000471}
472
473#ifdef WEHAVE_FSTAT
474static PyObject *
475mac_fstat(self, args)
476 PyObject *self;
477 PyObject *args;
478{
479 struct stat st;
480 long fd;
481 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000482 if (!PyArg_ParseTuple(args, "l", &fd))
Jack Jansen40bd7701998-02-20 15:56:19 +0000483 return NULL;
484 Py_BEGIN_ALLOW_THREADS
485 res = fstat((int)fd, &st);
486 Py_END_ALLOW_THREADS
487 if (res != 0)
488 return mac_error();
489 return Py_BuildValue("(lllllllddd)",
Guido van Rossum87f223c1994-05-06 15:54:15 +0000490 (long)st.st_mode,
Guido van Rossume7834441994-08-26 09:09:48 +0000491 (long)st.st_ino,
Guido van Rossumd4d77281994-08-19 10:51:31 +0000492 (long)st.st_dev,
493 (long)st.st_nlink,
494 (long)st.st_uid,
495 (long)st.st_gid,
Guido van Rossum87f223c1994-05-06 15:54:15 +0000496 (long)st.st_size,
Jack Jansen40bd7701998-02-20 15:56:19 +0000497 (double)st.st_atime,
498 (double)st.st_mtime,
499 (double)st.st_ctime);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000500}
Jack Jansen40bd7701998-02-20 15:56:19 +0000501#endif /* WEHAVE_FSTAT */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000502
Jack Jansen6e68a7e2001-05-12 21:31:34 +0000503#if TARGET_API_MAC_OS8
Jack Jansenf5c20571997-01-30 15:48:07 +0000504static PyObject *
Guido van Rossum222c8921995-08-08 14:10:22 +0000505mac_xstat(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000506 PyObject *self;
507 PyObject *args;
Guido van Rossum222c8921995-08-08 14:10:22 +0000508{
Jack Jansen59b912a1996-10-15 16:13:33 +0000509 struct macstat mst;
510 struct stat st;
Guido van Rossum222c8921995-08-08 14:10:22 +0000511 char *path;
512 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000513 if (!PyArg_ParseTuple(args, "s", &path))
Guido van Rossum222c8921995-08-08 14:10:22 +0000514 return NULL;
Jack Jansen59b912a1996-10-15 16:13:33 +0000515 /*
516 ** Convoluted: we want stat() and xstat() to agree, so we call both
517 ** stat and macstat, and use the latter only for values not provided by
518 ** the former.
519 */
Jack Jansenf5c20571997-01-30 15:48:07 +0000520 Py_BEGIN_ALLOW_THREADS
Jack Jansen59b912a1996-10-15 16:13:33 +0000521 res = macstat(path, &mst);
Jack Jansenf5c20571997-01-30 15:48:07 +0000522 Py_END_ALLOW_THREADS
Guido van Rossum222c8921995-08-08 14:10:22 +0000523 if (res != 0)
524 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000525 Py_BEGIN_ALLOW_THREADS
Jack Jansen59b912a1996-10-15 16:13:33 +0000526 res = stat(path, &st);
Jack Jansenf5c20571997-01-30 15:48:07 +0000527 Py_END_ALLOW_THREADS
Jack Jansen59b912a1996-10-15 16:13:33 +0000528 if (res != 0)
529 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000530 return Py_BuildValue("(llllllldddls#s#)",
Jack Jansenc743c8d1996-02-14 16:02:30 +0000531 (long)st.st_mode,
532 (long)st.st_ino,
533 (long)st.st_dev,
534 (long)st.st_nlink,
535 (long)st.st_uid,
536 (long)st.st_gid,
537 (long)st.st_size,
Jack Jansen59b912a1996-10-15 16:13:33 +0000538 (double)st.st_atime,
539 (double)st.st_mtime,
540 (double)st.st_ctime,
541 (long)mst.st_rsize,
542 mst.st_creator, 4,
543 mst.st_type, 4);
Guido van Rossum222c8921995-08-08 14:10:22 +0000544}
Jack Jansene79dc762000-06-02 21:35:07 +0000545#endif
Guido van Rossum222c8921995-08-08 14:10:22 +0000546
Jack Jansenf5c20571997-01-30 15:48:07 +0000547static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000548mac_sync(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000549 PyObject *self;
550 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000551{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000552 int res;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000553 if (!PyArg_ParseTuple(args, ""))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000554 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000555 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000556 res = sync();
Jack Jansenf5c20571997-01-30 15:48:07 +0000557 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000558 if (res != 0)
559 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000560 Py_INCREF(Py_None);
561 return Py_None;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000562}
563
Jack Jansenf5c20571997-01-30 15:48:07 +0000564static PyObject *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000565mac_unlink(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000566 PyObject *self;
567 PyObject *args;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000568{
Guido van Rossum739267b1994-08-29 08:42:37 +0000569 return mac_1str(args, (int (*)(const char *))unlink);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000570}
571
Jack Jansenf5c20571997-01-30 15:48:07 +0000572static PyObject *
Guido van Rossum87f223c1994-05-06 15:54:15 +0000573mac_write(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000574 PyObject *self;
575 PyObject *args;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000576{
577 int fd, size;
578 char *buffer;
Jack Jansenddafd2b2001-08-03 13:07:19 +0000579 if (!PyArg_ParseTuple(args, "is#", &fd, &buffer, &size))
Guido van Rossum87f223c1994-05-06 15:54:15 +0000580 return NULL;
Jack Jansenf5c20571997-01-30 15:48:07 +0000581 Py_BEGIN_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000582 size = write(fd, buffer, size);
Jack Jansenf5c20571997-01-30 15:48:07 +0000583 Py_END_ALLOW_THREADS
Guido van Rossum87f223c1994-05-06 15:54:15 +0000584 if (size < 0)
585 return mac_error();
Jack Jansenf5c20571997-01-30 15:48:07 +0000586 return PyInt_FromLong((long)size);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000587}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000588
Jack Jansen46ed2761996-10-23 15:46:57 +0000589#ifdef USE_MALLOC_DEBUG
Jack Jansen8748a0b2000-08-25 22:18:20 +0000590void *mstats(char *);
591
Jack Jansenf5c20571997-01-30 15:48:07 +0000592static PyObject *
Jack Jansend50e4e11995-01-18 13:58:04 +0000593mac_mstats(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +0000594 PyObject*self;
595 PyObject *args;
Jack Jansend50e4e11995-01-18 13:58:04 +0000596{
597 mstats("python");
Jack Jansenf5c20571997-01-30 15:48:07 +0000598 Py_INCREF(Py_None);
599 return Py_None;
Jack Jansend50e4e11995-01-18 13:58:04 +0000600}
Jack Jansen4f27a551997-02-20 15:22:17 +0000601#endif /* USE_MALLOC_DEBUG */
Jack Jansend50e4e11995-01-18 13:58:04 +0000602
Jack Jansenf5c20571997-01-30 15:48:07 +0000603static struct PyMethodDef mac_methods[] = {
Jack Jansenddafd2b2001-08-03 13:07:19 +0000604 {"chdir", mac_chdir, 1},
605 {"close", mac_close, 1},
Jack Jansenb6971731996-02-20 16:24:37 +0000606#ifdef WEHAVE_DUP
Jack Jansenddafd2b2001-08-03 13:07:19 +0000607 {"dup", mac_dup, 1},
Guido van Rossum921a08f1994-05-06 15:56:22 +0000608#endif
Jack Jansenb6971731996-02-20 16:24:37 +0000609#ifdef WEHAVE_FDOPEN
Jack Jansenddafd2b2001-08-03 13:07:19 +0000610 {"fdopen", mac_fdopen, 1},
Jack Jansen0c097ea1994-12-14 13:48:38 +0000611#endif
Jack Jansen40bd7701998-02-20 15:56:19 +0000612#ifdef WEHAVE_FSTAT
Jack Jansenddafd2b2001-08-03 13:07:19 +0000613 {"fstat", mac_fstat, 1},
Jack Jansen40bd7701998-02-20 15:56:19 +0000614#endif
Jack Jansen6e68a7e2001-05-12 21:31:34 +0000615#if TARGET_API_MAC_OS8
Jack Jansenddafd2b2001-08-03 13:07:19 +0000616 {"getbootvol", mac_getbootvol, 1}, /* non-standard */
Jack Jansene79dc762000-06-02 21:35:07 +0000617#endif
Jack Jansenddafd2b2001-08-03 13:07:19 +0000618 {"getcwd", mac_getcwd, 1},
619 {"listdir", mac_listdir, 1},
620 {"lseek", mac_lseek, 1},
Jack Jansen243b29b1996-02-21 12:33:50 +0000621 {"mkdir", mac_mkdir, 1},
Jack Jansenddafd2b2001-08-03 13:07:19 +0000622 {"open", mac_open, 1},
623 {"read", mac_read, 1},
624 {"rename", mac_rename, 1},
625 {"rmdir", mac_rmdir, 1},
626 {"stat", mac_stat, 1},
Jack Jansen6e68a7e2001-05-12 21:31:34 +0000627#if TARGET_API_MAC_OS8
Jack Jansenddafd2b2001-08-03 13:07:19 +0000628 {"xstat", mac_xstat, 1},
Jack Jansene79dc762000-06-02 21:35:07 +0000629#endif
Jack Jansenddafd2b2001-08-03 13:07:19 +0000630 {"sync", mac_sync, 1},
631 {"remove", mac_unlink, 1},
632 {"unlink", mac_unlink, 1},
633 {"write", mac_write, 1},
Jack Jansen46ed2761996-10-23 15:46:57 +0000634#ifdef USE_MALLOC_DEBUG
Jack Jansenddafd2b2001-08-03 13:07:19 +0000635 {"mstats", mac_mstats, 1},
Jack Jansend50e4e11995-01-18 13:58:04 +0000636#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000637
Guido van Rossumce9739b1994-01-05 16:17:15 +0000638 {NULL, NULL} /* Sentinel */
639};
640
Jack Jansenddafd2b2001-08-03 13:07:19 +0000641static int
642ins(PyObject *d, char *symbol, long value)
643{
644 PyObject* v = PyInt_FromLong(value);
645 if (!v || PyDict_SetItemString(d, symbol, v) < 0)
646 return -1; /* triggers fatal error */
647
648 Py_DECREF(v);
649 return 0;
650}
651
652static int
653all_ins(PyObject *d)
654{
655#ifdef F_OK
656 if (ins(d, "F_OK", (long)F_OK)) return -1;
657#endif
658#ifdef R_OK
659 if (ins(d, "R_OK", (long)R_OK)) return -1;
660#endif
661#ifdef W_OK
662 if (ins(d, "W_OK", (long)W_OK)) return -1;
663#endif
664#ifdef X_OK
665 if (ins(d, "X_OK", (long)X_OK)) return -1;
666#endif
667#ifdef NGROUPS_MAX
668 if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1;
669#endif
670#ifdef TMP_MAX
671 if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1;
672#endif
673#ifdef WNOHANG
674 if (ins(d, "WNOHANG", (long)WNOHANG)) return -1;
675#endif
676#ifdef O_RDONLY
677 if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1;
678#endif
679#ifdef O_WRONLY
680 if (ins(d, "O_WRONLY", (long)O_WRONLY)) return -1;
681#endif
682#ifdef O_RDWR
683 if (ins(d, "O_RDWR", (long)O_RDWR)) return -1;
684#endif
685#ifdef O_NDELAY
686 if (ins(d, "O_NDELAY", (long)O_NDELAY)) return -1;
687#endif
688#ifdef O_NONBLOCK
689 if (ins(d, "O_NONBLOCK", (long)O_NONBLOCK)) return -1;
690#endif
691#ifdef O_APPEND
692 if (ins(d, "O_APPEND", (long)O_APPEND)) return -1;
693#endif
694#ifdef O_DSYNC
695 if (ins(d, "O_DSYNC", (long)O_DSYNC)) return -1;
696#endif
697#ifdef O_RSYNC
698 if (ins(d, "O_RSYNC", (long)O_RSYNC)) return -1;
699#endif
700#ifdef O_SYNC
701 if (ins(d, "O_SYNC", (long)O_SYNC)) return -1;
702#endif
703#ifdef O_NOCTTY
704 if (ins(d, "O_NOCTTY", (long)O_NOCTTY)) return -1;
705#endif
706#ifdef O_CREAT
707 if (ins(d, "O_CREAT", (long)O_CREAT)) return -1;
708#endif
709#ifdef O_EXCL
710 if (ins(d, "O_EXCL", (long)O_EXCL)) return -1;
711#endif
712#ifdef O_TRUNC
713 if (ins(d, "O_TRUNC", (long)O_TRUNC)) return -1;
714#endif
715#ifdef O_BINARY
716 if (ins(d, "O_BINARY", (long)O_BINARY)) return -1;
717#endif
718#ifdef O_TEXT
719 if (ins(d, "O_TEXT", (long)O_TEXT)) return -1;
720#endif
721
722#ifdef HAVE_SPAWNV
723 if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1;
724 if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1;
725 if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1;
726 if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1;
727 if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1;
728#endif
729
730#if defined(PYOS_OS2)
731 if (insertvalues(d)) return -1;
732#endif
733 return 0;
734}
735
Guido van Rossumce9739b1994-01-05 16:17:15 +0000736
737void
738initmac()
739{
Jack Jansenf5c20571997-01-30 15:48:07 +0000740 PyObject *m, *d;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000741
Jack Jansenf5c20571997-01-30 15:48:07 +0000742 m = Py_InitModule("mac", mac_methods);
743 d = PyModule_GetDict(m);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000744
Jack Jansenddafd2b2001-08-03 13:07:19 +0000745 if (all_ins(d))
746 return;
747
Guido van Rossumce9739b1994-01-05 16:17:15 +0000748 /* Initialize mac.error exception */
Jack Jansen55e39271997-10-07 21:47:25 +0000749 MacError = PyErr_NewException("mac.error", NULL, NULL);
750 PyDict_SetItemString(d, "error", MacError);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000751}