blob: 4231346e401671fe9b7e8b7a03c546472862d204 [file] [log] [blame]
Guido van Rossumce9739b1994-01-05 16:17:15 +00001/***********************************************************
Guido van Rossum99546991995-01-08 14:33:34 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The 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
27#include "allobjects.h"
Guido van Rossumce9739b1994-01-05 16:17:15 +000028#include "modsupport.h"
Guido van Rossum87f223c1994-05-06 15:54:15 +000029#include "ceval.h"
Guido van Rossumce9739b1994-01-05 16:17:15 +000030
Guido van Rossum87f223c1994-05-06 15:54:15 +000031#include <stdio.h>
32#include <string.h>
33#include <errno.h>
Guido van Rossum739267b1994-08-29 08:42:37 +000034
35#ifdef THINK_C
36#include "unix.h"
37#undef S_IFMT
38#undef S_IFDIR
39#undef S_IFCHR
40#undef S_IFBLK
41#undef S_IFREG
42#undef S_ISDIR
43#undef S_ISREG
44#endif
45
Jack Jansen59b912a1996-10-15 16:13:33 +000046#include "macstat.h"
Jack Jansenc743c8d1996-02-14 16:02:30 +000047#ifdef USE_GUSI
Jack Jansen59b912a1996-10-15 16:13:33 +000048/* Remove defines from macstat.h */
49#undef S_IFMT
50#undef S_IFDIR
51#undef S_IFREG
52#undef S_IREAD
53#undef S_IWRITE
54#undef S_IEXEC
55
Jack Jansenb6971731996-02-20 16:24:37 +000056#include <GUSI.h>
Jack Jansenc743c8d1996-02-14 16:02:30 +000057#include <sys/types.h>
58#include <stat.h>
Jack Jansenc743c8d1996-02-14 16:02:30 +000059#else
Jack Jansen59b912a1996-10-15 16:13:33 +000060#define stat macstat
Jack Jansenc743c8d1996-02-14 16:02:30 +000061#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +000062
Jack Jansen9eeb82d1995-01-26 16:34:53 +000063#ifdef __MWERKS__
Jack Jansen9eeb82d1995-01-26 16:34:53 +000064#include <unix.h>
65#else
Guido van Rossum87f223c1994-05-06 15:54:15 +000066#include <fcntl.h>
Jack Jansen0c097ea1994-12-14 13:48:38 +000067#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +000068
Jack Jansenb6971731996-02-20 16:24:37 +000069/* Optional routines, for some compiler/runtime combinations */
Jack Jansenb6971731996-02-20 16:24:37 +000070#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 Jansen7cbf4801995-01-22 16:52:38 +000076
Guido van Rossumd4d77281994-08-19 10:51:31 +000077#include "macdefs.h"
Jack Jansenc743c8d1996-02-14 16:02:30 +000078#ifdef USE_GUSI
79#include <dirent.h>
80#else
Guido van Rossumd4d77281994-08-19 10:51:31 +000081#include "dirent.h"
Jack Jansenc743c8d1996-02-14 16:02:30 +000082#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +000083
84#ifndef MAXPATHLEN
85#define MAXPATHLEN 1024
86#endif
87
88/* Prototypes for Unix simulation on Mac */
89
Jack Jansenb6971731996-02-20 16:24:37 +000090#ifndef USE_GUSI
91
Guido van Rossum921a08f1994-05-06 15:56:22 +000092int chdir PROTO((const char *path));
Guido van Rossum921a08f1994-05-06 15:56:22 +000093int mkdir PROTO((const char *path, int mode));
94DIR * opendir PROTO((char *));
Guido van Rossum87f223c1994-05-06 15:54:15 +000095void closedir PROTO((DIR *));
Guido van Rossumd4d77281994-08-19 10:51:31 +000096struct dirent * readdir PROTO((DIR *));
Guido van Rossum921a08f1994-05-06 15:56:22 +000097int rmdir PROTO((const char *path));
Guido van Rossum87f223c1994-05-06 15:54:15 +000098int sync PROTO((void));
Jack Jansenb6971731996-02-20 16:24:37 +000099
100#if defined(THINK_C) || defined(__SC__)
Guido van Rossum739267b1994-08-29 08:42:37 +0000101int unlink PROTO((char *));
102#else
Guido van Rossum921a08f1994-05-06 15:56:22 +0000103int unlink PROTO((const char *));
Guido van Rossum739267b1994-08-29 08:42:37 +0000104#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000105
Jack Jansenb6971731996-02-20 16:24:37 +0000106#endif /* USE_GUSI */
107
108char *getwd PROTO((char *));
109char *getbootvol PROTO((void));
Guido van Rossum87f223c1994-05-06 15:54:15 +0000110
111
112static object *MacError; /* Exception mac.error */
113
114/* Set a MAC-specific error from errno, and return NULL */
115
116static object *
117mac_error()
118{
Guido van Rossum921a08f1994-05-06 15:56:22 +0000119 return err_errno(MacError);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000120}
121
122/* MAC generic methods */
123
124static object *
125mac_1str(args, func)
126 object *args;
127 int (*func) FPROTO((const char *));
128{
129 char *path1;
130 int res;
131 if (!getargs(args, "s", &path1))
132 return NULL;
133 BGN_SAVE
134 res = (*func)(path1);
135 END_SAVE
136 if (res < 0)
137 return mac_error();
138 INCREF(None);
139 return None;
140}
141
142static object *
143mac_2str(args, func)
144 object *args;
145 int (*func) FPROTO((const char *, const char *));
146{
147 char *path1, *path2;
148 int res;
149 if (!getargs(args, "(ss)", &path1, &path2))
150 return NULL;
151 BGN_SAVE
152 res = (*func)(path1, path2);
153 END_SAVE
154 if (res < 0)
155 return mac_error();
156 INCREF(None);
157 return None;
158}
159
160static object *
161mac_strint(args, func)
162 object *args;
163 int (*func) FPROTO((const char *, int));
164{
165 char *path;
166 int i;
167 int res;
168 if (!getargs(args, "(si)", &path, &i))
169 return NULL;
170 BGN_SAVE
171 res = (*func)(path, i);
172 END_SAVE
173 if (res < 0)
174 return mac_error();
175 INCREF(None);
176 return None;
177}
178
179static object *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000180mac_chdir(self, args)
181 object *self;
182 object *args;
183{
Jack Jansen378815c1996-03-06 16:21:34 +0000184#ifdef USE_GUSI
185 object *rv;
186
187 /* Change MacOS's idea of wd too */
188 rv = mac_1str(args, chdir);
189 PyMac_FixGUSIcd();
190 return rv;
191#else
Guido van Rossum87f223c1994-05-06 15:54:15 +0000192 return mac_1str(args, chdir);
Jack Jansen378815c1996-03-06 16:21:34 +0000193#endif
194
Guido van Rossum87f223c1994-05-06 15:54:15 +0000195}
196
197static object *
198mac_close(self, args)
199 object *self;
200 object *args;
201{
202 int fd, res;
203 if (!getargs(args, "i", &fd))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000204 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000205 BGN_SAVE
206 res = close(fd);
207 END_SAVE
Jack Jansenb6971731996-02-20 16:24:37 +0000208#ifndef USE_GUSI
209 /* GUSI gives surious errors here? */
Guido van Rossum87f223c1994-05-06 15:54:15 +0000210 if (res < 0)
211 return mac_error();
Jack Jansenb6971731996-02-20 16:24:37 +0000212#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000213 INCREF(None);
214 return None;
215}
216
Jack Jansenb6971731996-02-20 16:24:37 +0000217#ifdef WEHAVE_DUP
Guido van Rossum921a08f1994-05-06 15:56:22 +0000218
Guido van Rossum87f223c1994-05-06 15:54:15 +0000219static object *
220mac_dup(self, args)
221 object *self;
222 object *args;
223{
224 int fd;
225 if (!getargs(args, "i", &fd))
226 return NULL;
227 BGN_SAVE
228 fd = dup(fd);
229 END_SAVE
230 if (fd < 0)
231 return mac_error();
232 return newintobject((long)fd);
233}
234
Jack Jansenb6971731996-02-20 16:24:37 +0000235#endif
Guido van Rossume7834441994-08-26 09:09:48 +0000236
Jack Jansenb6971731996-02-20 16:24:37 +0000237#ifdef WEHAVE_FDOPEN
Guido van Rossum87f223c1994-05-06 15:54:15 +0000238static object *
239mac_fdopen(self, args)
240 object *self;
241 object *args;
242{
243 extern int fclose PROTO((FILE *));
244 int fd;
245 char *mode;
246 FILE *fp;
247 if (!getargs(args, "(is)", &fd, &mode))
248 return NULL;
249 BGN_SAVE
250 fp = fdopen(fd, mode);
251 END_SAVE
252 if (fp == NULL)
253 return mac_error();
254 return newopenfileobject(fp, "(fdopen)", mode, fclose);
255}
Jack Jansen0c097ea1994-12-14 13:48:38 +0000256#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000257
258static object *
259mac_getbootvol(self, args)
260 object *self;
261 object *args;
262{
263 char *res;
264 if (!getnoarg(args))
265 return NULL;
266 BGN_SAVE
267 res = getbootvol();
268 END_SAVE
269 if (res == NULL)
270 return mac_error();
271 return newstringobject(res);
272}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000273
274static object *
275mac_getcwd(self, args)
276 object *self;
277 object *args;
278{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000279 char path[MAXPATHLEN];
280 char *res;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000281 if (!getnoarg(args))
282 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000283 BGN_SAVE
Jack Jansenb6971731996-02-20 16:24:37 +0000284#ifdef USE_GUSI
285 res = getcwd(path, sizeof path);
286#else
Guido van Rossum87f223c1994-05-06 15:54:15 +0000287 res = getwd(path);
Jack Jansenb6971731996-02-20 16:24:37 +0000288#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000289 END_SAVE
290 if (res == NULL) {
291 err_setstr(MacError, path);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000292 return NULL;
293 }
Guido van Rossum87f223c1994-05-06 15:54:15 +0000294 return newstringobject(res);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000295}
296
Guido van Rossumce9739b1994-01-05 16:17:15 +0000297static object *
298mac_listdir(self, args)
299 object *self;
300 object *args;
301{
Guido van Rossumce9739b1994-01-05 16:17:15 +0000302 char *name;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000303 object *d, *v;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000304 DIR *dirp;
Guido van Rossumd4d77281994-08-19 10:51:31 +0000305 struct dirent *ep;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000306 if (!getargs(args, "s", &name))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000307 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000308 BGN_SAVE
309 if ((dirp = opendir(name)) == NULL) {
310 RET_SAVE
311 return mac_error();
312 }
Guido van Rossumce9739b1994-01-05 16:17:15 +0000313 if ((d = newlistobject(0)) == NULL) {
314 closedir(dirp);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000315 RET_SAVE
Guido van Rossumce9739b1994-01-05 16:17:15 +0000316 return NULL;
317 }
318 while ((ep = readdir(dirp)) != NULL) {
319 v = newstringobject(ep->d_name);
320 if (v == NULL) {
321 DECREF(d);
322 d = NULL;
323 break;
324 }
325 if (addlistitem(d, v) != 0) {
326 DECREF(v);
327 DECREF(d);
328 d = NULL;
329 break;
330 }
331 DECREF(v);
332 }
333 closedir(dirp);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000334 END_SAVE
335
Guido van Rossumce9739b1994-01-05 16:17:15 +0000336 return d;
337}
338
Guido van Rossum87f223c1994-05-06 15:54:15 +0000339static object *
340mac_lseek(self, args)
341 object *self;
342 object *args;
343{
344 int fd;
345 int where;
346 int how;
347 long res;
348 if (!getargs(args, "(iii)", &fd, &where, &how))
349 return NULL;
350 BGN_SAVE
351 res = lseek(fd, (long)where, how);
352 END_SAVE
353 if (res < 0)
354 return mac_error();
355 return newintobject(res);
356}
Jack Jansenc743c8d1996-02-14 16:02:30 +0000357
Guido van Rossumce9739b1994-01-05 16:17:15 +0000358static object *
359mac_mkdir(self, args)
360 object *self;
361 object *args;
362{
Jack Jansen243b29b1996-02-21 12:33:50 +0000363 int res;
364 char *path;
365 int mode = 0777; /* Unused */
366 if (!newgetargs(args, "s|i", &path, &mode))
367 return NULL;
368 BGN_SAVE
Jack Jansen3ca6edd1996-08-06 16:06:31 +0000369#ifdef USE_GUSI
370 res = mkdir(path);
371#else
Jack Jansen243b29b1996-02-21 12:33:50 +0000372 res = mkdir(path, mode);
Jack Jansen3ca6edd1996-08-06 16:06:31 +0000373#endif
Jack Jansen243b29b1996-02-21 12:33:50 +0000374 END_SAVE
375 if (res < 0)
376 return mac_error();
377 INCREF(None);
378 return None;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000379}
380
Guido van Rossum87f223c1994-05-06 15:54:15 +0000381static object *
382mac_open(self, args)
383 object *self;
384 object *args;
385{
386 char *path;
387 int mode;
388 int fd;
389 if (!getargs(args, "(si)", &path, &mode))
390 return NULL;
391 BGN_SAVE
392 fd = open(path, mode);
393 END_SAVE
394 if (fd < 0)
395 return mac_error();
396 return newintobject((long)fd);
397}
398
399static object *
400mac_read(self, args)
401 object *self;
402 object *args;
403{
404 int fd, size;
405 object *buffer;
406 if (!getargs(args, "(ii)", &fd, &size))
407 return NULL;
408 buffer = newsizedstringobject((char *)NULL, size);
409 if (buffer == NULL)
410 return NULL;
411 BGN_SAVE
412 size = read(fd, getstringvalue(buffer), size);
413 END_SAVE
414 if (size < 0) {
415 DECREF(buffer);
416 return mac_error();
417 }
418 resizestring(&buffer, size);
419 return buffer;
420}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000421
422static object *
423mac_rename(self, args)
424 object *self;
425 object *args;
426{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000427 return mac_2str(args, rename);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000428}
429
Guido van Rossumce9739b1994-01-05 16:17:15 +0000430static object *
431mac_rmdir(self, args)
432 object *self;
433 object *args;
434{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000435 return mac_1str(args, rmdir);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000436}
437
Guido van Rossumce9739b1994-01-05 16:17:15 +0000438static object *
439mac_stat(self, args)
440 object *self;
441 object *args;
442{
Jack Jansen59b912a1996-10-15 16:13:33 +0000443 struct stat st;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000444 char *path;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000445 int res;
446 if (!getargs(args, "s", &path))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000447 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000448 BGN_SAVE
Jack Jansen59b912a1996-10-15 16:13:33 +0000449 res = stat(path, &st);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000450 END_SAVE
451 if (res != 0)
452 return mac_error();
Jack Jansen59b912a1996-10-15 16:13:33 +0000453#if 1
454 return mkvalue("(lllllllddd)",
455 (long)st.st_mode,
456 (long)st.st_ino,
457 (long)st.st_dev,
458 (long)st.st_nlink,
459 (long)st.st_uid,
460 (long)st.st_gid,
461 (long)st.st_size,
462 (double)st.st_atime,
463 (double)st.st_mtime,
464 (double)st.st_ctime);
465#else
Guido van Rossumd4d77281994-08-19 10:51:31 +0000466 return mkvalue("(llllllllll)",
Guido van Rossum87f223c1994-05-06 15:54:15 +0000467 (long)st.st_mode,
Guido van Rossume7834441994-08-26 09:09:48 +0000468 (long)st.st_ino,
Guido van Rossumd4d77281994-08-19 10:51:31 +0000469 (long)st.st_dev,
470 (long)st.st_nlink,
471 (long)st.st_uid,
472 (long)st.st_gid,
Guido van Rossum87f223c1994-05-06 15:54:15 +0000473 (long)st.st_size,
Guido van Rossumd4d77281994-08-19 10:51:31 +0000474 (long)st.st_atime,
475 (long)st.st_mtime,
476 (long)st.st_ctime);
Jack Jansen59b912a1996-10-15 16:13:33 +0000477#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000478}
479
Guido van Rossumce9739b1994-01-05 16:17:15 +0000480static object *
Guido van Rossum222c8921995-08-08 14:10:22 +0000481mac_xstat(self, args)
482 object *self;
483 object *args;
484{
Jack Jansen59b912a1996-10-15 16:13:33 +0000485 struct macstat mst;
486 struct stat st;
Guido van Rossum222c8921995-08-08 14:10:22 +0000487 char *path;
488 int res;
489 if (!getargs(args, "s", &path))
490 return NULL;
Jack Jansen59b912a1996-10-15 16:13:33 +0000491 /*
492 ** Convoluted: we want stat() and xstat() to agree, so we call both
493 ** stat and macstat, and use the latter only for values not provided by
494 ** the former.
495 */
Guido van Rossum222c8921995-08-08 14:10:22 +0000496 BGN_SAVE
Jack Jansen59b912a1996-10-15 16:13:33 +0000497 res = macstat(path, &mst);
Guido van Rossum222c8921995-08-08 14:10:22 +0000498 END_SAVE
499 if (res != 0)
500 return mac_error();
Jack Jansen59b912a1996-10-15 16:13:33 +0000501 BGN_SAVE
502 res = stat(path, &st);
503 END_SAVE
504 if (res != 0)
505 return mac_error();
506#if 1
507 return mkvalue("(llllllldddls#s#)",
Jack Jansenc743c8d1996-02-14 16:02:30 +0000508 (long)st.st_mode,
509 (long)st.st_ino,
510 (long)st.st_dev,
511 (long)st.st_nlink,
512 (long)st.st_uid,
513 (long)st.st_gid,
514 (long)st.st_size,
Jack Jansen59b912a1996-10-15 16:13:33 +0000515 (double)st.st_atime,
516 (double)st.st_mtime,
517 (double)st.st_ctime,
518 (long)mst.st_rsize,
519 mst.st_creator, 4,
520 mst.st_type, 4);
Jack Jansenc743c8d1996-02-14 16:02:30 +0000521#else
Guido van Rossum222c8921995-08-08 14:10:22 +0000522 return mkvalue("(llllllllllls#s#)",
523 (long)st.st_mode,
524 (long)st.st_ino,
525 (long)st.st_dev,
526 (long)st.st_nlink,
527 (long)st.st_uid,
528 (long)st.st_gid,
529 (long)st.st_size,
530 (long)st.st_atime,
531 (long)st.st_mtime,
532 (long)st.st_ctime,
Jack Jansen59b912a1996-10-15 16:13:33 +0000533 (long)mst.st_rsize,
534 mst.st_creator, 4,
535 mst.st_type, 4);
Jack Jansenc743c8d1996-02-14 16:02:30 +0000536#endif
Guido van Rossum222c8921995-08-08 14:10:22 +0000537}
538
539static object *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000540mac_sync(self, args)
541 object *self;
542 object *args;
543{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000544 int res;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000545 if (!getnoarg(args))
546 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000547 BGN_SAVE
548 res = sync();
549 END_SAVE
550 if (res != 0)
551 return mac_error();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000552 INCREF(None);
553 return None;
554}
555
Guido van Rossumce9739b1994-01-05 16:17:15 +0000556static object *
557mac_unlink(self, args)
558 object *self;
559 object *args;
560{
Guido van Rossum739267b1994-08-29 08:42:37 +0000561 return mac_1str(args, (int (*)(const char *))unlink);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000562}
563
Guido van Rossum87f223c1994-05-06 15:54:15 +0000564static object *
565mac_write(self, args)
566 object *self;
567 object *args;
568{
569 int fd, size;
570 char *buffer;
571 if (!getargs(args, "(is#)", &fd, &buffer, &size))
572 return NULL;
573 BGN_SAVE
574 size = write(fd, buffer, size);
575 END_SAVE
576 if (size < 0)
577 return mac_error();
578 return newintobject((long)size);
579}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000580
Jack Jansen46ed2761996-10-23 15:46:57 +0000581#ifdef USE_MALLOC_DEBUG
Jack Jansend50e4e11995-01-18 13:58:04 +0000582static object *
583mac_mstats(self, args)
584 object*self;
585 object *args;
586{
587 mstats("python");
588 INCREF(None);
589 return None;
590}
Jack Jansen46ed2761996-10-23 15:46:57 +0000591#endif USE_MALLOC_DEBUG
Jack Jansend50e4e11995-01-18 13:58:04 +0000592
Guido van Rossumce9739b1994-01-05 16:17:15 +0000593static struct methodlist mac_methods[] = {
594 {"chdir", mac_chdir},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000595 {"close", mac_close},
Jack Jansenb6971731996-02-20 16:24:37 +0000596#ifdef WEHAVE_DUP
Guido van Rossum87f223c1994-05-06 15:54:15 +0000597 {"dup", mac_dup},
Guido van Rossum921a08f1994-05-06 15:56:22 +0000598#endif
Jack Jansenb6971731996-02-20 16:24:37 +0000599#ifdef WEHAVE_FDOPEN
Guido van Rossume7834441994-08-26 09:09:48 +0000600 {"fdopen", mac_fdopen},
Jack Jansen0c097ea1994-12-14 13:48:38 +0000601#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000602 {"getbootvol", mac_getbootvol}, /* non-standard */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000603 {"getcwd", mac_getcwd},
Guido van Rossumd1ef5961995-02-19 15:50:35 +0000604 {"listdir", mac_listdir, 0},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000605 {"lseek", mac_lseek},
Jack Jansen243b29b1996-02-21 12:33:50 +0000606 {"mkdir", mac_mkdir, 1},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000607 {"open", mac_open},
608 {"read", mac_read},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000609 {"rename", mac_rename},
610 {"rmdir", mac_rmdir},
611 {"stat", mac_stat},
Guido van Rossum222c8921995-08-08 14:10:22 +0000612 {"xstat", mac_xstat},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000613 {"sync", mac_sync},
Jack Jansen243b29b1996-02-21 12:33:50 +0000614 {"remove", mac_unlink},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000615 {"unlink", mac_unlink},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000616 {"write", mac_write},
Jack Jansen46ed2761996-10-23 15:46:57 +0000617#ifdef USE_MALLOC_DEBUG
Jack Jansend50e4e11995-01-18 13:58:04 +0000618 {"mstats", mac_mstats},
619#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000620
Guido van Rossumce9739b1994-01-05 16:17:15 +0000621 {NULL, NULL} /* Sentinel */
622};
623
624
625void
626initmac()
627{
Jack Jansend50e4e11995-01-18 13:58:04 +0000628 object *m, *d;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000629
630 m = initmodule("mac", mac_methods);
631 d = getmoduledict(m);
632
633 /* Initialize mac.error exception */
634 MacError = newstringobject("mac.error");
635 if (MacError == NULL || dictinsert(d, "error", MacError) != 0)
636 fatal("can't define mac.error");
637}