blob: 3d5c0ccd5f7810ac71f0607b43fffdfb4f9127fb [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 Jansenc743c8d1996-02-14 16:02:30 +000046#ifdef USE_GUSI
Jack Jansenb6971731996-02-20 16:24:37 +000047#include <GUSI.h>
Jack Jansenc743c8d1996-02-14 16:02:30 +000048#include <sys/types.h>
49#include <stat.h>
50#define macstat stat
51#else
Guido van Rossum739267b1994-08-29 08:42:37 +000052#include "macstat.h"
Jack Jansenc743c8d1996-02-14 16:02:30 +000053#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +000054
Jack Jansen9eeb82d1995-01-26 16:34:53 +000055#ifdef __MWERKS__
Jack Jansen9eeb82d1995-01-26 16:34:53 +000056#include <unix.h>
57#else
Guido van Rossum87f223c1994-05-06 15:54:15 +000058#include <fcntl.h>
Jack Jansen0c097ea1994-12-14 13:48:38 +000059#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +000060
Jack Jansenb6971731996-02-20 16:24:37 +000061/* Optional routines, for some compiler/runtime combinations */
Guido van Rossum56934121995-02-13 16:19:04 +000062#if defined(__MWERKS__) && defined(__powerc)
Jack Jansen7cbf4801995-01-22 16:52:38 +000063#define MALLOC_DEBUG
64#endif
Jack Jansenb6971731996-02-20 16:24:37 +000065#if defined(USE_GUSI) || !defined(__MWERKS__)
66#define WEHAVE_FDOPEN
67#endif
68#if defined(MPW) || defined(USE_GUSI)
69#define WEHAVE_DUP
70#endif
Jack Jansen7cbf4801995-01-22 16:52:38 +000071
Guido van Rossumd4d77281994-08-19 10:51:31 +000072#include "macdefs.h"
Jack Jansenc743c8d1996-02-14 16:02:30 +000073#ifdef USE_GUSI
74#include <dirent.h>
75#else
Guido van Rossumd4d77281994-08-19 10:51:31 +000076#include "dirent.h"
Jack Jansenc743c8d1996-02-14 16:02:30 +000077#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +000078
79#ifndef MAXPATHLEN
80#define MAXPATHLEN 1024
81#endif
82
83/* Prototypes for Unix simulation on Mac */
84
Jack Jansenb6971731996-02-20 16:24:37 +000085#ifndef USE_GUSI
86
Guido van Rossum921a08f1994-05-06 15:56:22 +000087int chdir PROTO((const char *path));
Guido van Rossum921a08f1994-05-06 15:56:22 +000088int mkdir PROTO((const char *path, int mode));
89DIR * opendir PROTO((char *));
Guido van Rossum87f223c1994-05-06 15:54:15 +000090void closedir PROTO((DIR *));
Guido van Rossumd4d77281994-08-19 10:51:31 +000091struct dirent * readdir PROTO((DIR *));
Guido van Rossum921a08f1994-05-06 15:56:22 +000092int rmdir PROTO((const char *path));
Guido van Rossum87f223c1994-05-06 15:54:15 +000093int sync PROTO((void));
Jack Jansenb6971731996-02-20 16:24:37 +000094
95#if defined(THINK_C) || defined(__SC__)
Guido van Rossum739267b1994-08-29 08:42:37 +000096int unlink PROTO((char *));
97#else
Guido van Rossum921a08f1994-05-06 15:56:22 +000098int unlink PROTO((const char *));
Guido van Rossum739267b1994-08-29 08:42:37 +000099#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000100
Jack Jansenb6971731996-02-20 16:24:37 +0000101#endif /* USE_GUSI */
102
103char *getwd PROTO((char *));
104char *getbootvol PROTO((void));
Guido van Rossum87f223c1994-05-06 15:54:15 +0000105
106
107static object *MacError; /* Exception mac.error */
108
109/* Set a MAC-specific error from errno, and return NULL */
110
111static object *
112mac_error()
113{
Guido van Rossum921a08f1994-05-06 15:56:22 +0000114 return err_errno(MacError);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000115}
116
117/* MAC generic methods */
118
119static object *
120mac_1str(args, func)
121 object *args;
122 int (*func) FPROTO((const char *));
123{
124 char *path1;
125 int res;
126 if (!getargs(args, "s", &path1))
127 return NULL;
128 BGN_SAVE
129 res = (*func)(path1);
130 END_SAVE
131 if (res < 0)
132 return mac_error();
133 INCREF(None);
134 return None;
135}
136
137static object *
138mac_2str(args, func)
139 object *args;
140 int (*func) FPROTO((const char *, const char *));
141{
142 char *path1, *path2;
143 int res;
144 if (!getargs(args, "(ss)", &path1, &path2))
145 return NULL;
146 BGN_SAVE
147 res = (*func)(path1, path2);
148 END_SAVE
149 if (res < 0)
150 return mac_error();
151 INCREF(None);
152 return None;
153}
154
155static object *
156mac_strint(args, func)
157 object *args;
158 int (*func) FPROTO((const char *, int));
159{
160 char *path;
161 int i;
162 int res;
163 if (!getargs(args, "(si)", &path, &i))
164 return NULL;
165 BGN_SAVE
166 res = (*func)(path, i);
167 END_SAVE
168 if (res < 0)
169 return mac_error();
170 INCREF(None);
171 return None;
172}
173
174static object *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000175mac_chdir(self, args)
176 object *self;
177 object *args;
178{
Jack Jansen378815c1996-03-06 16:21:34 +0000179#ifdef USE_GUSI
180 object *rv;
181
182 /* Change MacOS's idea of wd too */
183 rv = mac_1str(args, chdir);
184 PyMac_FixGUSIcd();
185 return rv;
186#else
Guido van Rossum87f223c1994-05-06 15:54:15 +0000187 return mac_1str(args, chdir);
Jack Jansen378815c1996-03-06 16:21:34 +0000188#endif
189
Guido van Rossum87f223c1994-05-06 15:54:15 +0000190}
191
192static object *
193mac_close(self, args)
194 object *self;
195 object *args;
196{
197 int fd, res;
198 if (!getargs(args, "i", &fd))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000199 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000200 BGN_SAVE
201 res = close(fd);
202 END_SAVE
Jack Jansenb6971731996-02-20 16:24:37 +0000203#ifndef USE_GUSI
204 /* GUSI gives surious errors here? */
Guido van Rossum87f223c1994-05-06 15:54:15 +0000205 if (res < 0)
206 return mac_error();
Jack Jansenb6971731996-02-20 16:24:37 +0000207#endif
Guido van Rossumce9739b1994-01-05 16:17:15 +0000208 INCREF(None);
209 return None;
210}
211
Jack Jansenb6971731996-02-20 16:24:37 +0000212#ifdef WEHAVE_DUP
Guido van Rossum921a08f1994-05-06 15:56:22 +0000213
Guido van Rossum87f223c1994-05-06 15:54:15 +0000214static object *
215mac_dup(self, args)
216 object *self;
217 object *args;
218{
219 int fd;
220 if (!getargs(args, "i", &fd))
221 return NULL;
222 BGN_SAVE
223 fd = dup(fd);
224 END_SAVE
225 if (fd < 0)
226 return mac_error();
227 return newintobject((long)fd);
228}
229
Jack Jansenb6971731996-02-20 16:24:37 +0000230#endif
Guido van Rossume7834441994-08-26 09:09:48 +0000231
Jack Jansenb6971731996-02-20 16:24:37 +0000232#ifdef WEHAVE_FDOPEN
Guido van Rossum87f223c1994-05-06 15:54:15 +0000233static object *
234mac_fdopen(self, args)
235 object *self;
236 object *args;
237{
238 extern int fclose PROTO((FILE *));
239 int fd;
240 char *mode;
241 FILE *fp;
242 if (!getargs(args, "(is)", &fd, &mode))
243 return NULL;
244 BGN_SAVE
245 fp = fdopen(fd, mode);
246 END_SAVE
247 if (fp == NULL)
248 return mac_error();
249 return newopenfileobject(fp, "(fdopen)", mode, fclose);
250}
Jack Jansen0c097ea1994-12-14 13:48:38 +0000251#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000252
253static object *
254mac_getbootvol(self, args)
255 object *self;
256 object *args;
257{
258 char *res;
259 if (!getnoarg(args))
260 return NULL;
261 BGN_SAVE
262 res = getbootvol();
263 END_SAVE
264 if (res == NULL)
265 return mac_error();
266 return newstringobject(res);
267}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000268
269static object *
270mac_getcwd(self, args)
271 object *self;
272 object *args;
273{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000274 char path[MAXPATHLEN];
275 char *res;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000276 if (!getnoarg(args))
277 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000278 BGN_SAVE
Jack Jansenb6971731996-02-20 16:24:37 +0000279#ifdef USE_GUSI
280 res = getcwd(path, sizeof path);
281#else
Guido van Rossum87f223c1994-05-06 15:54:15 +0000282 res = getwd(path);
Jack Jansenb6971731996-02-20 16:24:37 +0000283#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000284 END_SAVE
285 if (res == NULL) {
286 err_setstr(MacError, path);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000287 return NULL;
288 }
Guido van Rossum87f223c1994-05-06 15:54:15 +0000289 return newstringobject(res);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000290}
291
Guido van Rossumce9739b1994-01-05 16:17:15 +0000292static object *
293mac_listdir(self, args)
294 object *self;
295 object *args;
296{
Guido van Rossumce9739b1994-01-05 16:17:15 +0000297 char *name;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000298 object *d, *v;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000299 DIR *dirp;
Guido van Rossumd4d77281994-08-19 10:51:31 +0000300 struct dirent *ep;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000301 if (!getargs(args, "s", &name))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000302 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000303 BGN_SAVE
304 if ((dirp = opendir(name)) == NULL) {
305 RET_SAVE
306 return mac_error();
307 }
Guido van Rossumce9739b1994-01-05 16:17:15 +0000308 if ((d = newlistobject(0)) == NULL) {
309 closedir(dirp);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000310 RET_SAVE
Guido van Rossumce9739b1994-01-05 16:17:15 +0000311 return NULL;
312 }
313 while ((ep = readdir(dirp)) != NULL) {
314 v = newstringobject(ep->d_name);
315 if (v == NULL) {
316 DECREF(d);
317 d = NULL;
318 break;
319 }
320 if (addlistitem(d, v) != 0) {
321 DECREF(v);
322 DECREF(d);
323 d = NULL;
324 break;
325 }
326 DECREF(v);
327 }
328 closedir(dirp);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000329 END_SAVE
330
Guido van Rossumce9739b1994-01-05 16:17:15 +0000331 return d;
332}
333
Guido van Rossum87f223c1994-05-06 15:54:15 +0000334static object *
335mac_lseek(self, args)
336 object *self;
337 object *args;
338{
339 int fd;
340 int where;
341 int how;
342 long res;
343 if (!getargs(args, "(iii)", &fd, &where, &how))
344 return NULL;
345 BGN_SAVE
346 res = lseek(fd, (long)where, how);
347 END_SAVE
348 if (res < 0)
349 return mac_error();
350 return newintobject(res);
351}
Jack Jansenc743c8d1996-02-14 16:02:30 +0000352
Guido van Rossumce9739b1994-01-05 16:17:15 +0000353static object *
354mac_mkdir(self, args)
355 object *self;
356 object *args;
357{
Jack Jansen243b29b1996-02-21 12:33:50 +0000358 int res;
359 char *path;
360 int mode = 0777; /* Unused */
361 if (!newgetargs(args, "s|i", &path, &mode))
362 return NULL;
363 BGN_SAVE
Jack Jansen3ca6edd1996-08-06 16:06:31 +0000364#ifdef USE_GUSI
365 res = mkdir(path);
366#else
Jack Jansen243b29b1996-02-21 12:33:50 +0000367 res = mkdir(path, mode);
Jack Jansen3ca6edd1996-08-06 16:06:31 +0000368#endif
Jack Jansen243b29b1996-02-21 12:33:50 +0000369 END_SAVE
370 if (res < 0)
371 return mac_error();
372 INCREF(None);
373 return None;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000374}
375
Guido van Rossum87f223c1994-05-06 15:54:15 +0000376static object *
377mac_open(self, args)
378 object *self;
379 object *args;
380{
381 char *path;
382 int mode;
383 int fd;
384 if (!getargs(args, "(si)", &path, &mode))
385 return NULL;
386 BGN_SAVE
387 fd = open(path, mode);
388 END_SAVE
389 if (fd < 0)
390 return mac_error();
391 return newintobject((long)fd);
392}
393
394static object *
395mac_read(self, args)
396 object *self;
397 object *args;
398{
399 int fd, size;
400 object *buffer;
401 if (!getargs(args, "(ii)", &fd, &size))
402 return NULL;
403 buffer = newsizedstringobject((char *)NULL, size);
404 if (buffer == NULL)
405 return NULL;
406 BGN_SAVE
407 size = read(fd, getstringvalue(buffer), size);
408 END_SAVE
409 if (size < 0) {
410 DECREF(buffer);
411 return mac_error();
412 }
413 resizestring(&buffer, size);
414 return buffer;
415}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000416
417static object *
418mac_rename(self, args)
419 object *self;
420 object *args;
421{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000422 return mac_2str(args, rename);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000423}
424
Guido van Rossumce9739b1994-01-05 16:17:15 +0000425static object *
426mac_rmdir(self, args)
427 object *self;
428 object *args;
429{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000430 return mac_1str(args, rmdir);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000431}
432
Guido van Rossumce9739b1994-01-05 16:17:15 +0000433static object *
434mac_stat(self, args)
435 object *self;
436 object *args;
437{
Guido van Rossum739267b1994-08-29 08:42:37 +0000438 struct macstat st;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000439 char *path;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000440 int res;
441 if (!getargs(args, "s", &path))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000442 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000443 BGN_SAVE
Guido van Rossum739267b1994-08-29 08:42:37 +0000444 res = macstat(path, &st);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000445 END_SAVE
446 if (res != 0)
447 return mac_error();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000448 return mkvalue("(llllllllll)",
Guido van Rossum87f223c1994-05-06 15:54:15 +0000449 (long)st.st_mode,
Guido van Rossume7834441994-08-26 09:09:48 +0000450 (long)st.st_ino,
Guido van Rossumd4d77281994-08-19 10:51:31 +0000451 (long)st.st_dev,
452 (long)st.st_nlink,
453 (long)st.st_uid,
454 (long)st.st_gid,
Guido van Rossum87f223c1994-05-06 15:54:15 +0000455 (long)st.st_size,
Guido van Rossumd4d77281994-08-19 10:51:31 +0000456 (long)st.st_atime,
457 (long)st.st_mtime,
458 (long)st.st_ctime);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000459}
460
Guido van Rossumce9739b1994-01-05 16:17:15 +0000461static object *
Guido van Rossum222c8921995-08-08 14:10:22 +0000462mac_xstat(self, args)
463 object *self;
464 object *args;
465{
466 struct macstat st;
467 char *path;
468 int res;
469 if (!getargs(args, "s", &path))
470 return NULL;
471 BGN_SAVE
472 res = macstat(path, &st);
473 END_SAVE
474 if (res != 0)
475 return mac_error();
Jack Jansenc743c8d1996-02-14 16:02:30 +0000476#ifdef USE_GUSI
477 return mkvalue("(llllllllll)",
478 (long)st.st_mode,
479 (long)st.st_ino,
480 (long)st.st_dev,
481 (long)st.st_nlink,
482 (long)st.st_uid,
483 (long)st.st_gid,
484 (long)st.st_size,
485 (long)st.st_atime,
486 (long)st.st_mtime,
487 (long)st.st_ctime);
488#else
Guido van Rossum222c8921995-08-08 14:10:22 +0000489 return mkvalue("(llllllllllls#s#)",
490 (long)st.st_mode,
491 (long)st.st_ino,
492 (long)st.st_dev,
493 (long)st.st_nlink,
494 (long)st.st_uid,
495 (long)st.st_gid,
496 (long)st.st_size,
497 (long)st.st_atime,
498 (long)st.st_mtime,
499 (long)st.st_ctime,
500 (long)st.st_rsize,
501 st.st_creator, 4,
502 st.st_type, 4);
Jack Jansenc743c8d1996-02-14 16:02:30 +0000503#endif
Guido van Rossum222c8921995-08-08 14:10:22 +0000504}
505
506static object *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000507mac_sync(self, args)
508 object *self;
509 object *args;
510{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000511 int res;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000512 if (!getnoarg(args))
513 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000514 BGN_SAVE
515 res = sync();
516 END_SAVE
517 if (res != 0)
518 return mac_error();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000519 INCREF(None);
520 return None;
521}
522
Guido van Rossumce9739b1994-01-05 16:17:15 +0000523static object *
524mac_unlink(self, args)
525 object *self;
526 object *args;
527{
Guido van Rossum739267b1994-08-29 08:42:37 +0000528 return mac_1str(args, (int (*)(const char *))unlink);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000529}
530
Guido van Rossum87f223c1994-05-06 15:54:15 +0000531static object *
532mac_write(self, args)
533 object *self;
534 object *args;
535{
536 int fd, size;
537 char *buffer;
538 if (!getargs(args, "(is#)", &fd, &buffer, &size))
539 return NULL;
540 BGN_SAVE
541 size = write(fd, buffer, size);
542 END_SAVE
543 if (size < 0)
544 return mac_error();
545 return newintobject((long)size);
546}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000547
Jack Jansend50e4e11995-01-18 13:58:04 +0000548#ifdef MALLOC_DEBUG
549static object *
550mac_mstats(self, args)
551 object*self;
552 object *args;
553{
554 mstats("python");
555 INCREF(None);
556 return None;
557}
558#endif MALLOC_DEBUG
559
Guido van Rossumce9739b1994-01-05 16:17:15 +0000560static struct methodlist mac_methods[] = {
561 {"chdir", mac_chdir},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000562 {"close", mac_close},
Jack Jansenb6971731996-02-20 16:24:37 +0000563#ifdef WEHAVE_DUP
Guido van Rossum87f223c1994-05-06 15:54:15 +0000564 {"dup", mac_dup},
Guido van Rossum921a08f1994-05-06 15:56:22 +0000565#endif
Jack Jansenb6971731996-02-20 16:24:37 +0000566#ifdef WEHAVE_FDOPEN
Guido van Rossume7834441994-08-26 09:09:48 +0000567 {"fdopen", mac_fdopen},
Jack Jansen0c097ea1994-12-14 13:48:38 +0000568#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000569 {"getbootvol", mac_getbootvol}, /* non-standard */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000570 {"getcwd", mac_getcwd},
Guido van Rossumd1ef5961995-02-19 15:50:35 +0000571 {"listdir", mac_listdir, 0},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000572 {"lseek", mac_lseek},
Jack Jansen243b29b1996-02-21 12:33:50 +0000573 {"mkdir", mac_mkdir, 1},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000574 {"open", mac_open},
575 {"read", mac_read},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000576 {"rename", mac_rename},
577 {"rmdir", mac_rmdir},
578 {"stat", mac_stat},
Guido van Rossum222c8921995-08-08 14:10:22 +0000579 {"xstat", mac_xstat},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000580 {"sync", mac_sync},
Jack Jansen243b29b1996-02-21 12:33:50 +0000581 {"remove", mac_unlink},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000582 {"unlink", mac_unlink},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000583 {"write", mac_write},
Jack Jansend50e4e11995-01-18 13:58:04 +0000584#ifdef MALLOC_DEBUG
585 {"mstats", mac_mstats},
586#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000587
Guido van Rossumce9739b1994-01-05 16:17:15 +0000588 {NULL, NULL} /* Sentinel */
589};
590
591
592void
593initmac()
594{
Jack Jansend50e4e11995-01-18 13:58:04 +0000595 object *m, *d;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000596
597 m = initmodule("mac", mac_methods);
598 d = getmoduledict(m);
599
600 /* Initialize mac.error exception */
601 MacError = newstringobject("mac.error");
602 if (MacError == NULL || dictinsert(d, "error", MacError) != 0)
603 fatal("can't define mac.error");
604}