blob: 75716db66d96db7aa5f4db1325f6f8aef2b3ee58 [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
364 res = mkdir(path, mode);
365 END_SAVE
366 if (res < 0)
367 return mac_error();
368 INCREF(None);
369 return None;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000370}
371
Guido van Rossum87f223c1994-05-06 15:54:15 +0000372static object *
373mac_open(self, args)
374 object *self;
375 object *args;
376{
377 char *path;
378 int mode;
379 int fd;
380 if (!getargs(args, "(si)", &path, &mode))
381 return NULL;
382 BGN_SAVE
383 fd = open(path, mode);
384 END_SAVE
385 if (fd < 0)
386 return mac_error();
387 return newintobject((long)fd);
388}
389
390static object *
391mac_read(self, args)
392 object *self;
393 object *args;
394{
395 int fd, size;
396 object *buffer;
397 if (!getargs(args, "(ii)", &fd, &size))
398 return NULL;
399 buffer = newsizedstringobject((char *)NULL, size);
400 if (buffer == NULL)
401 return NULL;
402 BGN_SAVE
403 size = read(fd, getstringvalue(buffer), size);
404 END_SAVE
405 if (size < 0) {
406 DECREF(buffer);
407 return mac_error();
408 }
409 resizestring(&buffer, size);
410 return buffer;
411}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000412
413static object *
414mac_rename(self, args)
415 object *self;
416 object *args;
417{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000418 return mac_2str(args, rename);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000419}
420
Guido van Rossumce9739b1994-01-05 16:17:15 +0000421static object *
422mac_rmdir(self, args)
423 object *self;
424 object *args;
425{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000426 return mac_1str(args, rmdir);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000427}
428
Guido van Rossumce9739b1994-01-05 16:17:15 +0000429static object *
430mac_stat(self, args)
431 object *self;
432 object *args;
433{
Guido van Rossum739267b1994-08-29 08:42:37 +0000434 struct macstat st;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000435 char *path;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000436 int res;
437 if (!getargs(args, "s", &path))
Guido van Rossumce9739b1994-01-05 16:17:15 +0000438 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000439 BGN_SAVE
Guido van Rossum739267b1994-08-29 08:42:37 +0000440 res = macstat(path, &st);
Guido van Rossum87f223c1994-05-06 15:54:15 +0000441 END_SAVE
442 if (res != 0)
443 return mac_error();
Guido van Rossumd4d77281994-08-19 10:51:31 +0000444 return mkvalue("(llllllllll)",
Guido van Rossum87f223c1994-05-06 15:54:15 +0000445 (long)st.st_mode,
Guido van Rossume7834441994-08-26 09:09:48 +0000446 (long)st.st_ino,
Guido van Rossumd4d77281994-08-19 10:51:31 +0000447 (long)st.st_dev,
448 (long)st.st_nlink,
449 (long)st.st_uid,
450 (long)st.st_gid,
Guido van Rossum87f223c1994-05-06 15:54:15 +0000451 (long)st.st_size,
Guido van Rossumd4d77281994-08-19 10:51:31 +0000452 (long)st.st_atime,
453 (long)st.st_mtime,
454 (long)st.st_ctime);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000455}
456
Guido van Rossumce9739b1994-01-05 16:17:15 +0000457static object *
Guido van Rossum222c8921995-08-08 14:10:22 +0000458mac_xstat(self, args)
459 object *self;
460 object *args;
461{
462 struct macstat st;
463 char *path;
464 int res;
465 if (!getargs(args, "s", &path))
466 return NULL;
467 BGN_SAVE
468 res = macstat(path, &st);
469 END_SAVE
470 if (res != 0)
471 return mac_error();
Jack Jansenc743c8d1996-02-14 16:02:30 +0000472#ifdef USE_GUSI
473 return mkvalue("(llllllllll)",
474 (long)st.st_mode,
475 (long)st.st_ino,
476 (long)st.st_dev,
477 (long)st.st_nlink,
478 (long)st.st_uid,
479 (long)st.st_gid,
480 (long)st.st_size,
481 (long)st.st_atime,
482 (long)st.st_mtime,
483 (long)st.st_ctime);
484#else
Guido van Rossum222c8921995-08-08 14:10:22 +0000485 return mkvalue("(llllllllllls#s#)",
486 (long)st.st_mode,
487 (long)st.st_ino,
488 (long)st.st_dev,
489 (long)st.st_nlink,
490 (long)st.st_uid,
491 (long)st.st_gid,
492 (long)st.st_size,
493 (long)st.st_atime,
494 (long)st.st_mtime,
495 (long)st.st_ctime,
496 (long)st.st_rsize,
497 st.st_creator, 4,
498 st.st_type, 4);
Jack Jansenc743c8d1996-02-14 16:02:30 +0000499#endif
Guido van Rossum222c8921995-08-08 14:10:22 +0000500}
501
502static object *
Guido van Rossumce9739b1994-01-05 16:17:15 +0000503mac_sync(self, args)
504 object *self;
505 object *args;
506{
Guido van Rossum87f223c1994-05-06 15:54:15 +0000507 int res;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000508 if (!getnoarg(args))
509 return NULL;
Guido van Rossum87f223c1994-05-06 15:54:15 +0000510 BGN_SAVE
511 res = sync();
512 END_SAVE
513 if (res != 0)
514 return mac_error();
Guido van Rossumce9739b1994-01-05 16:17:15 +0000515 INCREF(None);
516 return None;
517}
518
Guido van Rossumce9739b1994-01-05 16:17:15 +0000519static object *
520mac_unlink(self, args)
521 object *self;
522 object *args;
523{
Guido van Rossum739267b1994-08-29 08:42:37 +0000524 return mac_1str(args, (int (*)(const char *))unlink);
Guido van Rossumce9739b1994-01-05 16:17:15 +0000525}
526
Guido van Rossum87f223c1994-05-06 15:54:15 +0000527static object *
528mac_write(self, args)
529 object *self;
530 object *args;
531{
532 int fd, size;
533 char *buffer;
534 if (!getargs(args, "(is#)", &fd, &buffer, &size))
535 return NULL;
536 BGN_SAVE
537 size = write(fd, buffer, size);
538 END_SAVE
539 if (size < 0)
540 return mac_error();
541 return newintobject((long)size);
542}
Guido van Rossumce9739b1994-01-05 16:17:15 +0000543
Jack Jansend50e4e11995-01-18 13:58:04 +0000544#ifdef MALLOC_DEBUG
545static object *
546mac_mstats(self, args)
547 object*self;
548 object *args;
549{
550 mstats("python");
551 INCREF(None);
552 return None;
553}
554#endif MALLOC_DEBUG
555
Guido van Rossumce9739b1994-01-05 16:17:15 +0000556static struct methodlist mac_methods[] = {
557 {"chdir", mac_chdir},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000558 {"close", mac_close},
Jack Jansenb6971731996-02-20 16:24:37 +0000559#ifdef WEHAVE_DUP
Guido van Rossum87f223c1994-05-06 15:54:15 +0000560 {"dup", mac_dup},
Guido van Rossum921a08f1994-05-06 15:56:22 +0000561#endif
Jack Jansenb6971731996-02-20 16:24:37 +0000562#ifdef WEHAVE_FDOPEN
Guido van Rossume7834441994-08-26 09:09:48 +0000563 {"fdopen", mac_fdopen},
Jack Jansen0c097ea1994-12-14 13:48:38 +0000564#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000565 {"getbootvol", mac_getbootvol}, /* non-standard */
Guido van Rossumce9739b1994-01-05 16:17:15 +0000566 {"getcwd", mac_getcwd},
Guido van Rossumd1ef5961995-02-19 15:50:35 +0000567 {"listdir", mac_listdir, 0},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000568 {"lseek", mac_lseek},
Jack Jansen243b29b1996-02-21 12:33:50 +0000569 {"mkdir", mac_mkdir, 1},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000570 {"open", mac_open},
571 {"read", mac_read},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000572 {"rename", mac_rename},
573 {"rmdir", mac_rmdir},
574 {"stat", mac_stat},
Guido van Rossum222c8921995-08-08 14:10:22 +0000575 {"xstat", mac_xstat},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000576 {"sync", mac_sync},
Jack Jansen243b29b1996-02-21 12:33:50 +0000577 {"remove", mac_unlink},
Guido van Rossumce9739b1994-01-05 16:17:15 +0000578 {"unlink", mac_unlink},
Guido van Rossum87f223c1994-05-06 15:54:15 +0000579 {"write", mac_write},
Jack Jansend50e4e11995-01-18 13:58:04 +0000580#ifdef MALLOC_DEBUG
581 {"mstats", mac_mstats},
582#endif
Guido van Rossum87f223c1994-05-06 15:54:15 +0000583
Guido van Rossumce9739b1994-01-05 16:17:15 +0000584 {NULL, NULL} /* Sentinel */
585};
586
587
588void
589initmac()
590{
Jack Jansend50e4e11995-01-18 13:58:04 +0000591 object *m, *d;
Guido van Rossumce9739b1994-01-05 16:17:15 +0000592
593 m = initmodule("mac", mac_methods);
594 d = getmoduledict(m);
595
596 /* Initialize mac.error exception */
597 MacError = newstringobject("mac.error");
598 if (MacError == NULL || dictinsert(d, "error", MacError) != 0)
599 fatal("can't define mac.error");
600}