blob: 4c856fcb5158ee3bccadf41ba0d8019f4ba63c98 [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 */
Guido van Rossum56934121995-02-13 16:19:04 +000070#if defined(__MWERKS__) && defined(__powerc)
Jack Jansen7cbf4801995-01-22 16:52:38 +000071#define MALLOC_DEBUG
72#endif
Jack Jansenb6971731996-02-20 16:24:37 +000073#if defined(USE_GUSI) || !defined(__MWERKS__)
74#define WEHAVE_FDOPEN
75#endif
76#if defined(MPW) || defined(USE_GUSI)
77#define WEHAVE_DUP
78#endif
Jack Jansen7cbf4801995-01-22 16:52:38 +000079
Guido van Rossumd4d77281994-08-19 10:51:31 +000080#include "macdefs.h"
Jack Jansenc743c8d1996-02-14 16:02:30 +000081#ifdef USE_GUSI
82#include <dirent.h>
83#else
Guido van Rossumd4d77281994-08-19 10:51:31 +000084#include "dirent.h"
Jack Jansenc743c8d1996-02-14 16:02:30 +000085#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +000086
87#ifndef MAXPATHLEN
88#define MAXPATHLEN 1024
89#endif
90
91/* Prototypes for Unix simulation on Mac */
92
Jack Jansenb6971731996-02-20 16:24:37 +000093#ifndef USE_GUSI
94
Guido van Rossum921a08f1994-05-06 15:56:22 +000095int chdir PROTO((const char *path));
Guido van Rossum921a08f1994-05-06 15:56:22 +000096int mkdir PROTO((const char *path, int mode));
97DIR * opendir PROTO((char *));
Guido van Rossum87f223c1994-05-06 15:54:15 +000098void closedir PROTO((DIR *));
Guido van Rossumd4d77281994-08-19 10:51:31 +000099struct dirent * readdir PROTO((DIR *));
Guido van Rossum921a08f1994-05-06 15:56:22 +0000100int rmdir PROTO((const char *path));
Guido van Rossum87f223c1994-05-06 15:54:15 +0000101int sync PROTO((void));
Jack Jansenb6971731996-02-20 16:24:37 +0000102
103#if defined(THINK_C) || defined(__SC__)
Guido van Rossum739267b1994-08-29 08:42:37 +0000104int unlink PROTO((char *));
105#else
Guido van Rossum921a08f1994-05-06 15:56:22 +0000106int unlink PROTO((const char *));
Guido van Rossum739267b1994-08-29 08:42:37 +0000107#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000108
Jack Jansenb6971731996-02-20 16:24:37 +0000109#endif /* USE_GUSI */
110
111char *getwd PROTO((char *));
112char *getbootvol PROTO((void));
Guido van Rossum87f223c1994-05-06 15:54:15 +0000113
114
115static object *MacError; /* Exception mac.error */
116
117/* Set a MAC-specific error from errno, and return NULL */
118
119static object *
120mac_error()
121{
Guido van Rossum921a08f1994-05-06 15:56:22 +0000122 return err_errno(MacError);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000123}
124
125/* MAC generic methods */
126
127static object *
128mac_1str(args, func)
129 object *args;
130 int (*func) FPROTO((const char *));
131{
132 char *path1;
133 int res;
134 if (!getargs(args, "s", &path1))
135 return NULL;
136 BGN_SAVE
137 res = (*func)(path1);
138 END_SAVE
139 if (res < 0)
140 return mac_error();
141 INCREF(None);
142 return None;
143}
144
145static object *
146mac_2str(args, func)
147 object *args;
148 int (*func) FPROTO((const char *, const char *));
149{
150 char *path1, *path2;
151 int res;
152 if (!getargs(args, "(ss)", &path1, &path2))
153 return NULL;
154 BGN_SAVE
155 res = (*func)(path1, path2);
156 END_SAVE
157 if (res < 0)
158 return mac_error();
159 INCREF(None);
160 return None;
161}
162
163static object *
164mac_strint(args, func)
165 object *args;
166 int (*func) FPROTO((const char *, int));
167{
168 char *path;
169 int i;
170 int res;
171 if (!getargs(args, "(si)", &path, &i))
172 return NULL;
173 BGN_SAVE
174 res = (*func)(path, i);
175 END_SAVE
176 if (res < 0)
177 return mac_error();
178 INCREF(None);
179 return None;
180}
181
182static object *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000183mac_chdir(self, args)
184 object *self;
185 object *args;
186{
Jack Jansen378815c1996-03-06 16:21:34 +0000187#ifdef USE_GUSI
188 object *rv;
189
190 /* Change MacOS's idea of wd too */
191 rv = mac_1str(args, chdir);
192 PyMac_FixGUSIcd();
193 return rv;
194#else
Guido van Rossum87f223c1994-05-06 15:54:15 +0000195 return mac_1str(args, chdir);
Jack Jansen378815c1996-03-06 16:21:34 +0000196#endif
197
Guido van Rossum87f223c1994-05-06 15:54:15 +0000198}
199
200static object *
201mac_close(self, args)
202 object *self;
203 object *args;
204{
205 int fd, res;
206 if (!getargs(args, "i", &fd))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000207 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000208 BGN_SAVE
209 res = close(fd);
210 END_SAVE
Jack Jansenb6971731996-02-20 16:24:37 +0000211#ifndef USE_GUSI
212 /* GUSI gives surious errors here? */
Guido van Rossum87f223c1994-05-06 15:54:15 +0000213 if (res < 0)
214 return mac_error();
Jack Jansenb6971731996-02-20 16:24:37 +0000215#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000216 INCREF(None);
217 return None;
218}
219
Jack Jansenb6971731996-02-20 16:24:37 +0000220#ifdef WEHAVE_DUP
Guido van Rossum921a08f1994-05-06 15:56:22 +0000221
Guido van Rossum87f223c1994-05-06 15:54:15 +0000222static object *
223mac_dup(self, args)
224 object *self;
225 object *args;
226{
227 int fd;
228 if (!getargs(args, "i", &fd))
229 return NULL;
230 BGN_SAVE
231 fd = dup(fd);
232 END_SAVE
233 if (fd < 0)
234 return mac_error();
235 return newintobject((long)fd);
236}
237
Jack Jansenb6971731996-02-20 16:24:37 +0000238#endif
Guido van Rossume7834441994-08-26 09:09:48 +0000239
Jack Jansenb6971731996-02-20 16:24:37 +0000240#ifdef WEHAVE_FDOPEN
Guido van Rossum87f223c1994-05-06 15:54:15 +0000241static object *
242mac_fdopen(self, args)
243 object *self;
244 object *args;
245{
246 extern int fclose PROTO((FILE *));
247 int fd;
248 char *mode;
249 FILE *fp;
250 if (!getargs(args, "(is)", &fd, &mode))
251 return NULL;
252 BGN_SAVE
253 fp = fdopen(fd, mode);
254 END_SAVE
255 if (fp == NULL)
256 return mac_error();
257 return newopenfileobject(fp, "(fdopen)", mode, fclose);
258}
Jack Jansen0c097ea1994-12-14 13:48:38 +0000259#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000260
261static object *
262mac_getbootvol(self, args)
263 object *self;
264 object *args;
265{
266 char *res;
267 if (!getnoarg(args))
268 return NULL;
269 BGN_SAVE
270 res = getbootvol();
271 END_SAVE
272 if (res == NULL)
273 return mac_error();
274 return newstringobject(res);
275}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000276
277static object *
278mac_getcwd(self, args)
279 object *self;
280 object *args;
281{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000282 char path[MAXPATHLEN];
283 char *res;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000284 if (!getnoarg(args))
285 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000286 BGN_SAVE
Jack Jansenb6971731996-02-20 16:24:37 +0000287#ifdef USE_GUSI
288 res = getcwd(path, sizeof path);
289#else
Guido van Rossum87f223c1994-05-06 15:54:15 +0000290 res = getwd(path);
Jack Jansenb6971731996-02-20 16:24:37 +0000291#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000292 END_SAVE
293 if (res == NULL) {
294 err_setstr(MacError, path);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000295 return NULL;
296 }
Guido van Rossum87f223c1994-05-06 15:54:15 +0000297 return newstringobject(res);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000298}
299
Guido van Rossumce9739b1994-01-05 16:17:15 +0000300static object *
301mac_listdir(self, args)
302 object *self;
303 object *args;
304{
Guido van Rossumce9739b1994-01-05 16:17:15 +0000305 char *name;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000306 object *d, *v;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000307 DIR *dirp;
Guido van Rossumd4d77281994-08-19 10:51:31 +0000308 struct dirent *ep;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000309 if (!getargs(args, "s", &name))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000310 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000311 BGN_SAVE
312 if ((dirp = opendir(name)) == NULL) {
313 RET_SAVE
314 return mac_error();
315 }
Guido van Rossumce9739b1994-01-05 16:17:15 +0000316 if ((d = newlistobject(0)) == NULL) {
317 closedir(dirp);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000318 RET_SAVE
Guido van Rossumce9739b1994-01-05 16:17:15 +0000319 return NULL;
320 }
321 while ((ep = readdir(dirp)) != NULL) {
322 v = newstringobject(ep->d_name);
323 if (v == NULL) {
324 DECREF(d);
325 d = NULL;
326 break;
327 }
328 if (addlistitem(d, v) != 0) {
329 DECREF(v);
330 DECREF(d);
331 d = NULL;
332 break;
333 }
334 DECREF(v);
335 }
336 closedir(dirp);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000337 END_SAVE
338
Guido van Rossumce9739b1994-01-05 16:17:15 +0000339 return d;
340}
341
Guido van Rossum87f223c1994-05-06 15:54:15 +0000342static object *
343mac_lseek(self, args)
344 object *self;
345 object *args;
346{
347 int fd;
348 int where;
349 int how;
350 long res;
351 if (!getargs(args, "(iii)", &fd, &where, &how))
352 return NULL;
353 BGN_SAVE
354 res = lseek(fd, (long)where, how);
355 END_SAVE
356 if (res < 0)
357 return mac_error();
358 return newintobject(res);
359}
Jack Jansenc743c8d1996-02-14 16:02:30 +0000360
Guido van Rossumce9739b1994-01-05 16:17:15 +0000361static object *
362mac_mkdir(self, args)
363 object *self;
364 object *args;
365{
Jack Jansen243b29b1996-02-21 12:33:50 +0000366 int res;
367 char *path;
368 int mode = 0777; /* Unused */
369 if (!newgetargs(args, "s|i", &path, &mode))
370 return NULL;
371 BGN_SAVE
Jack Jansen3ca6edd1996-08-06 16:06:31 +0000372#ifdef USE_GUSI
373 res = mkdir(path);
374#else
Jack Jansen243b29b1996-02-21 12:33:50 +0000375 res = mkdir(path, mode);
Jack Jansen3ca6edd1996-08-06 16:06:31 +0000376#endif
Jack Jansen243b29b1996-02-21 12:33:50 +0000377 END_SAVE
378 if (res < 0)
379 return mac_error();
380 INCREF(None);
381 return None;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000382}
383
Guido van Rossum87f223c1994-05-06 15:54:15 +0000384static object *
385mac_open(self, args)
386 object *self;
387 object *args;
388{
389 char *path;
390 int mode;
391 int fd;
392 if (!getargs(args, "(si)", &path, &mode))
393 return NULL;
394 BGN_SAVE
395 fd = open(path, mode);
396 END_SAVE
397 if (fd < 0)
398 return mac_error();
399 return newintobject((long)fd);
400}
401
402static object *
403mac_read(self, args)
404 object *self;
405 object *args;
406{
407 int fd, size;
408 object *buffer;
409 if (!getargs(args, "(ii)", &fd, &size))
410 return NULL;
411 buffer = newsizedstringobject((char *)NULL, size);
412 if (buffer == NULL)
413 return NULL;
414 BGN_SAVE
415 size = read(fd, getstringvalue(buffer), size);
416 END_SAVE
417 if (size < 0) {
418 DECREF(buffer);
419 return mac_error();
420 }
421 resizestring(&buffer, size);
422 return buffer;
423}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000424
425static object *
426mac_rename(self, args)
427 object *self;
428 object *args;
429{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000430 return mac_2str(args, rename);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000431}
432
Guido van Rossumce9739b1994-01-05 16:17:15 +0000433static object *
434mac_rmdir(self, args)
435 object *self;
436 object *args;
437{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000438 return mac_1str(args, rmdir);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000439}
440
Guido van Rossumce9739b1994-01-05 16:17:15 +0000441static object *
442mac_stat(self, args)
443 object *self;
444 object *args;
445{
Jack Jansen59b912a1996-10-15 16:13:33 +0000446 struct stat st;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000447 char *path;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000448 int res;
449 if (!getargs(args, "s", &path))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000450 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000451 BGN_SAVE
Jack Jansen59b912a1996-10-15 16:13:33 +0000452 res = stat(path, &st);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000453 END_SAVE
454 if (res != 0)
455 return mac_error();
Jack Jansen59b912a1996-10-15 16:13:33 +0000456#if 1
457 return mkvalue("(lllllllddd)",
458 (long)st.st_mode,
459 (long)st.st_ino,
460 (long)st.st_dev,
461 (long)st.st_nlink,
462 (long)st.st_uid,
463 (long)st.st_gid,
464 (long)st.st_size,
465 (double)st.st_atime,
466 (double)st.st_mtime,
467 (double)st.st_ctime);
468#else
Guido van Rossumd4d77281994-08-19 10:51:31 +0000469 return mkvalue("(llllllllll)",
Guido van Rossum87f223c1994-05-06 15:54:15 +0000470 (long)st.st_mode,
Guido van Rossume7834441994-08-26 09:09:48 +0000471 (long)st.st_ino,
Guido van Rossumd4d77281994-08-19 10:51:31 +0000472 (long)st.st_dev,
473 (long)st.st_nlink,
474 (long)st.st_uid,
475 (long)st.st_gid,
Guido van Rossum87f223c1994-05-06 15:54:15 +0000476 (long)st.st_size,
Guido van Rossumd4d77281994-08-19 10:51:31 +0000477 (long)st.st_atime,
478 (long)st.st_mtime,
479 (long)st.st_ctime);
Jack Jansen59b912a1996-10-15 16:13:33 +0000480#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000481}
482
Guido van Rossumce9739b1994-01-05 16:17:15 +0000483static object *
Guido van Rossum222c8921995-08-08 14:10:22 +0000484mac_xstat(self, args)
485 object *self;
486 object *args;
487{
Jack Jansen59b912a1996-10-15 16:13:33 +0000488 struct macstat mst;
489 struct stat st;
Guido van Rossum222c8921995-08-08 14:10:22 +0000490 char *path;
491 int res;
492 if (!getargs(args, "s", &path))
493 return NULL;
Jack Jansen59b912a1996-10-15 16:13:33 +0000494 /*
495 ** Convoluted: we want stat() and xstat() to agree, so we call both
496 ** stat and macstat, and use the latter only for values not provided by
497 ** the former.
498 */
Guido van Rossum222c8921995-08-08 14:10:22 +0000499 BGN_SAVE
Jack Jansen59b912a1996-10-15 16:13:33 +0000500 res = macstat(path, &mst);
Guido van Rossum222c8921995-08-08 14:10:22 +0000501 END_SAVE
502 if (res != 0)
503 return mac_error();
Jack Jansen59b912a1996-10-15 16:13:33 +0000504 BGN_SAVE
505 res = stat(path, &st);
506 END_SAVE
507 if (res != 0)
508 return mac_error();
509#if 1
510 return mkvalue("(llllllldddls#s#)",
Jack Jansenc743c8d1996-02-14 16:02:30 +0000511 (long)st.st_mode,
512 (long)st.st_ino,
513 (long)st.st_dev,
514 (long)st.st_nlink,
515 (long)st.st_uid,
516 (long)st.st_gid,
517 (long)st.st_size,
Jack Jansen59b912a1996-10-15 16:13:33 +0000518 (double)st.st_atime,
519 (double)st.st_mtime,
520 (double)st.st_ctime,
521 (long)mst.st_rsize,
522 mst.st_creator, 4,
523 mst.st_type, 4);
Jack Jansenc743c8d1996-02-14 16:02:30 +0000524#else
Guido van Rossum222c8921995-08-08 14:10:22 +0000525 return mkvalue("(llllllllllls#s#)",
526 (long)st.st_mode,
527 (long)st.st_ino,
528 (long)st.st_dev,
529 (long)st.st_nlink,
530 (long)st.st_uid,
531 (long)st.st_gid,
532 (long)st.st_size,
533 (long)st.st_atime,
534 (long)st.st_mtime,
535 (long)st.st_ctime,
Jack Jansen59b912a1996-10-15 16:13:33 +0000536 (long)mst.st_rsize,
537 mst.st_creator, 4,
538 mst.st_type, 4);
Jack Jansenc743c8d1996-02-14 16:02:30 +0000539#endif
Guido van Rossum222c8921995-08-08 14:10:22 +0000540}
541
542static object *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000543mac_sync(self, args)
544 object *self;
545 object *args;
546{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000547 int res;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000548 if (!getnoarg(args))
549 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000550 BGN_SAVE
551 res = sync();
552 END_SAVE
553 if (res != 0)
554 return mac_error();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000555 INCREF(None);
556 return None;
557}
558
Guido van Rossumce9739b1994-01-05 16:17:15 +0000559static object *
560mac_unlink(self, args)
561 object *self;
562 object *args;
563{
Guido van Rossum739267b1994-08-29 08:42:37 +0000564 return mac_1str(args, (int (*)(const char *))unlink);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000565}
566
Guido van Rossum87f223c1994-05-06 15:54:15 +0000567static object *
568mac_write(self, args)
569 object *self;
570 object *args;
571{
572 int fd, size;
573 char *buffer;
574 if (!getargs(args, "(is#)", &fd, &buffer, &size))
575 return NULL;
576 BGN_SAVE
577 size = write(fd, buffer, size);
578 END_SAVE
579 if (size < 0)
580 return mac_error();
581 return newintobject((long)size);
582}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000583
Jack Jansend50e4e11995-01-18 13:58:04 +0000584#ifdef MALLOC_DEBUG
585static object *
586mac_mstats(self, args)
587 object*self;
588 object *args;
589{
590 mstats("python");
591 INCREF(None);
592 return None;
593}
594#endif MALLOC_DEBUG
595
Guido van Rossumce9739b1994-01-05 16:17:15 +0000596static struct methodlist mac_methods[] = {
597 {"chdir", mac_chdir},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000598 {"close", mac_close},
Jack Jansenb6971731996-02-20 16:24:37 +0000599#ifdef WEHAVE_DUP
Guido van Rossum87f223c1994-05-06 15:54:15 +0000600 {"dup", mac_dup},
Guido van Rossum921a08f1994-05-06 15:56:22 +0000601#endif
Jack Jansenb6971731996-02-20 16:24:37 +0000602#ifdef WEHAVE_FDOPEN
Guido van Rossume7834441994-08-26 09:09:48 +0000603 {"fdopen", mac_fdopen},
Jack Jansen0c097ea1994-12-14 13:48:38 +0000604#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000605 {"getbootvol", mac_getbootvol}, /* non-standard */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000606 {"getcwd", mac_getcwd},
Guido van Rossumd1ef5961995-02-19 15:50:35 +0000607 {"listdir", mac_listdir, 0},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000608 {"lseek", mac_lseek},
Jack Jansen243b29b1996-02-21 12:33:50 +0000609 {"mkdir", mac_mkdir, 1},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000610 {"open", mac_open},
611 {"read", mac_read},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000612 {"rename", mac_rename},
613 {"rmdir", mac_rmdir},
614 {"stat", mac_stat},
Guido van Rossum222c8921995-08-08 14:10:22 +0000615 {"xstat", mac_xstat},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000616 {"sync", mac_sync},
Jack Jansen243b29b1996-02-21 12:33:50 +0000617 {"remove", mac_unlink},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000618 {"unlink", mac_unlink},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000619 {"write", mac_write},
Jack Jansend50e4e11995-01-18 13:58:04 +0000620#ifdef MALLOC_DEBUG
621 {"mstats", mac_mstats},
622#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000623
Guido van Rossumce9739b1994-01-05 16:17:15 +0000624 {NULL, NULL} /* Sentinel */
625};
626
627
628void
629initmac()
630{
Jack Jansend50e4e11995-01-18 13:58:04 +0000631 object *m, *d;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000632
633 m = initmodule("mac", mac_methods);
634 d = getmoduledict(m);
635
636 /* Initialize mac.error exception */
637 MacError = newstringobject("mac.error");
638 if (MacError == NULL || dictinsert(d, "error", MacError) != 0)
639 fatal("can't define mac.error");
640}