cpython/Mac/Modules/macmodule.c

752 lines
15 KiB
C
Raw Normal View History

1994-01-05 12:17:15 -04:00
/***********************************************************
Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
1995-01-08 10:33:34 -04:00
The Netherlands.
1994-01-05 12:17:15 -04:00
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* Mac module implementation */
1994-01-05 12:17:15 -04:00
1997-01-30 11:48:07 -04:00
#include "Python.h"
#include "ceval.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#if TARGET_API_MAC_OS8
/* Skip for Carbon */
#include "macstat.h"
#endif
1996-02-14 12:02:30 -04:00
#ifdef USE_GUSI
/* Remove defines from macstat.h */
#undef S_IFMT
#undef S_IFDIR
#undef S_IFREG
#undef S_IREAD
#undef S_IWRITE
#undef S_IEXEC
#ifdef USE_GUSI1
#include <GUSI.h>
#endif /* USE_GUSI1 */
1996-02-14 12:02:30 -04:00
#include <sys/types.h>
#include <sys/stat.h>
#else /* USE_GUSI */
#if TARGET_API_MAC_OS8
#define stat macstat
#endif
#endif /* USE_GUSI */
#ifdef USE_GUSI2
#define sync bad_sync
#include <unistd.h>
#include <fcntl.h>
#undef sync
int sync(void);
#else
2000-05-12 18:36:29 -03:00
#define mode_t int
#include <fcntl.h>
#ifdef _POSIX
#include <unistd.h>
#include <stat.h>
#endif
#endif
/* Optional routines, for some compiler/runtime combinations */
#if defined(USE_GUSI) || !defined(__MWERKS__)
#define WEHAVE_FDOPEN
#endif
#if defined(MPW) || defined(USE_GUSI)
#define WEHAVE_DUP
#endif
1998-02-20 11:56:19 -04:00
#if defined(USE_GUSI)
#define WEHAVE_FSTAT
#endif
#include "macdefs.h"
1996-02-14 12:02:30 -04:00
#ifdef USE_GUSI
#include <dirent.h>
#else
#include "dirent.h"
1996-02-14 12:02:30 -04:00
#endif
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
/* Prototypes for Unix simulation on Mac */
#ifndef USE_GUSI
int chdir(const char *path);
int mkdir(const char *path, int mode);
DIR * opendir(char *);
void closedir(DIR *);
struct dirent * readdir(DIR *);
int rmdir(const char *path);
int sync(void);
int unlink(const char *);
#endif /* USE_GUSI */
char *getwd(char *);
char *getbootvol(void);
1994-01-05 12:17:15 -04:00
1997-01-30 11:48:07 -04:00
static PyObject *MacError; /* Exception mac.error */
1994-01-05 12:17:15 -04:00
/* Set a MAC-specific error from errno, and return NULL */
1997-01-30 11:48:07 -04:00
static PyObject *
mac_error()
{
1997-01-30 11:48:07 -04:00
return PyErr_SetFromErrno(MacError);
}
/* MAC generic methods */
1997-01-30 11:48:07 -04:00
static PyObject *
mac_1str(args, func)
1997-01-30 11:48:07 -04:00
PyObject *args;
int (*func)(const char *);
{
char *path1;
int res;
if (!PyArg_ParseTuple(args, "s", &path1))
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
res = (*func)(path1);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res < 0)
return mac_error();
1997-01-30 11:48:07 -04:00
Py_INCREF(Py_None);
return Py_None;
}
1997-01-30 11:48:07 -04:00
static PyObject *
mac_2str(args, func)
1997-01-30 11:48:07 -04:00
PyObject *args;
int (*func)(const char *, const char *);
{
char *path1, *path2;
int res;
if (!PyArg_ParseTuple(args, "ss", &path1, &path2))
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
res = (*func)(path1, path2);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res < 0)
return mac_error();
1997-01-30 11:48:07 -04:00
Py_INCREF(Py_None);
return Py_None;
}
1997-01-30 11:48:07 -04:00
static PyObject *
mac_strint(args, func)
1997-01-30 11:48:07 -04:00
PyObject *args;
int (*func)(const char *, int);
{
char *path;
int i;
int res;
if (!PyArg_ParseTuple(args, "si", &path, &i))
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
res = (*func)(path, i);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res < 0)
return mac_error();
1997-01-30 11:48:07 -04:00
Py_INCREF(Py_None);
return Py_None;
}
1997-01-30 11:48:07 -04:00
static PyObject *
1994-01-05 12:17:15 -04:00
mac_chdir(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
1994-01-05 12:17:15 -04:00
{
#ifdef USE_GUSI1
1997-01-30 11:48:07 -04:00
PyObject *rv;
/* Change MacOS's idea of wd too */
rv = mac_1str(args, chdir);
PyMac_FixGUSIcd();
return rv;
#else
return mac_1str(args, chdir);
#endif
}
1997-01-30 11:48:07 -04:00
static PyObject *
mac_close(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
{
int fd, res;
if (!PyArg_ParseTuple(args, "i", &fd))
1994-01-05 12:17:15 -04:00
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
res = close(fd);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
#ifndef USE_GUSI1
/* GUSI gives surious errors here? */
if (res < 0)
return mac_error();
#endif
1997-01-30 11:48:07 -04:00
Py_INCREF(Py_None);
return Py_None;
1994-01-05 12:17:15 -04:00
}
#ifdef WEHAVE_DUP
1997-01-30 11:48:07 -04:00
static PyObject *
mac_dup(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
{
int fd;
if (!PyArg_ParseTuple(args, "i", &fd))
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
fd = dup(fd);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (fd < 0)
return mac_error();
1997-01-30 11:48:07 -04:00
return PyInt_FromLong((long)fd);
}
#endif
#ifdef WEHAVE_FDOPEN
1997-01-30 11:48:07 -04:00
static PyObject *
mac_fdopen(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
{
extern int fclose(FILE *);
int fd;
char *mode;
FILE *fp;
if (!PyArg_ParseTuple(args, "is", &fd, &mode))
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
fp = fdopen(fd, mode);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (fp == NULL)
return mac_error();
1997-01-30 11:48:07 -04:00
return PyFile_FromFile(fp, "(fdopen)", mode, fclose);
}
#endif
#if TARGET_API_MAC_OS8
1997-01-30 11:48:07 -04:00
static PyObject *
mac_getbootvol(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
{
char *res;
if (!PyArg_ParseTuple(args, ""))
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
res = getbootvol();
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res == NULL)
return mac_error();
1997-01-30 11:48:07 -04:00
return PyString_FromString(res);
}
#endif
1994-01-05 12:17:15 -04:00
1997-01-30 11:48:07 -04:00
static PyObject *
1994-01-05 12:17:15 -04:00
mac_getcwd(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
1994-01-05 12:17:15 -04:00
{
char path[MAXPATHLEN];
char *res;
if (!PyArg_ParseTuple(args, ""))
1994-01-05 12:17:15 -04:00
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
#ifdef USE_GUSI
res = getcwd(path, sizeof path);
#else
res = getwd(path);
#endif
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res == NULL) {
1997-01-30 11:48:07 -04:00
PyErr_SetString(MacError, path);
1994-01-05 12:17:15 -04:00
return NULL;
}
1997-01-30 11:48:07 -04:00
return PyString_FromString(res);
1994-01-05 12:17:15 -04:00
}
1997-01-30 11:48:07 -04:00
static PyObject *
1994-01-05 12:17:15 -04:00
mac_listdir(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
1994-01-05 12:17:15 -04:00
{
char *name;
1997-01-30 11:48:07 -04:00
PyObject *d, *v;
1994-01-05 12:17:15 -04:00
DIR *dirp;
struct dirent *ep;
if (!PyArg_ParseTuple(args, "s", &name))
1994-01-05 12:17:15 -04:00
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
if ((dirp = opendir(name)) == NULL) {
1997-01-30 11:48:07 -04:00
Py_BLOCK_THREADS
return mac_error();
}
1997-01-30 11:48:07 -04:00
if ((d = PyList_New(0)) == NULL) {
1994-01-05 12:17:15 -04:00
closedir(dirp);
1997-01-30 11:48:07 -04:00
Py_BLOCK_THREADS
1994-01-05 12:17:15 -04:00
return NULL;
}
while ((ep = readdir(dirp)) != NULL) {
1997-01-30 11:48:07 -04:00
v = PyString_FromString(ep->d_name);
1994-01-05 12:17:15 -04:00
if (v == NULL) {
1997-01-30 11:48:07 -04:00
Py_DECREF(d);
1994-01-05 12:17:15 -04:00
d = NULL;
break;
}
1997-01-30 11:48:07 -04:00
if (PyList_Append(d, v) != 0) {
Py_DECREF(v);
Py_DECREF(d);
1994-01-05 12:17:15 -04:00
d = NULL;
break;
}
1997-01-30 11:48:07 -04:00
Py_DECREF(v);
1994-01-05 12:17:15 -04:00
}
closedir(dirp);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
1994-01-05 12:17:15 -04:00
return d;
}
1997-01-30 11:48:07 -04:00
static PyObject *
mac_lseek(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
{
int fd;
int where;
int how;
long res;
if (!PyArg_ParseTuple(args, "iii", &fd, &where, &how))
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
res = lseek(fd, (long)where, how);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res < 0)
return mac_error();
1997-01-30 11:48:07 -04:00
return PyInt_FromLong(res);
}
1996-02-14 12:02:30 -04:00
1997-01-30 11:48:07 -04:00
static PyObject *
1994-01-05 12:17:15 -04:00
mac_mkdir(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
{
int res;
char *path;
int mode = 0777; /* Unused */
1997-01-30 11:48:07 -04:00
if (!PyArg_ParseTuple(args, "s|i", &path, &mode))
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
#ifdef USE_GUSI1
1996-08-06 13:06:31 -03:00
res = mkdir(path);
#else
res = mkdir(path, mode);
1996-08-06 13:06:31 -03:00
#endif
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res < 0)
return mac_error();
1997-01-30 11:48:07 -04:00
Py_INCREF(Py_None);
return Py_None;
}
1997-01-30 11:48:07 -04:00
static PyObject *
mac_open(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
1994-01-05 12:17:15 -04:00
{
char *path;
int mode;
int perm; /* Accepted but ignored */
int fd;
if (!PyArg_ParseTuple(args, "si|i", &path, &mode, &perm))
1994-01-05 12:17:15 -04:00
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
fd = open(path, mode);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (fd < 0)
return mac_error();
1997-01-30 11:48:07 -04:00
return PyInt_FromLong((long)fd);
1994-01-05 12:17:15 -04:00
}
1997-01-30 11:48:07 -04:00
static PyObject *
mac_read(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
1994-01-05 12:17:15 -04:00
{
int fd, size;
1997-01-30 11:48:07 -04:00
PyObject *buffer;
if (!PyArg_ParseTuple(args, "ii", &fd, &size))
1994-01-05 12:17:15 -04:00
return NULL;
1997-01-30 11:48:07 -04:00
buffer = PyString_FromStringAndSize((char *)NULL, size);
if (buffer == NULL)
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
size = read(fd, PyString_AsString(buffer), size);
Py_END_ALLOW_THREADS
if (size < 0) {
1997-01-30 11:48:07 -04:00
Py_DECREF(buffer);
return mac_error();
}
1997-01-30 11:48:07 -04:00
_PyString_Resize(&buffer, size);
return buffer;
1994-01-05 12:17:15 -04:00
}
1997-01-30 11:48:07 -04:00
static PyObject *
mac_rename(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
{
return mac_2str(args, rename);
}
1994-01-05 12:17:15 -04:00
1997-01-30 11:48:07 -04:00
static PyObject *
1994-01-05 12:17:15 -04:00
mac_rmdir(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
1994-01-05 12:17:15 -04:00
{
return mac_1str(args, rmdir);
1994-01-05 12:17:15 -04:00
}
1997-01-30 11:48:07 -04:00
static PyObject *
1994-01-05 12:17:15 -04:00
mac_stat(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
1994-01-05 12:17:15 -04:00
{
struct stat st;
1994-01-05 12:17:15 -04:00
char *path;
int res;
if (!PyArg_ParseTuple(args, "s", &path))
1994-01-05 12:17:15 -04:00
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
res = stat(path, &st);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res != 0)
return mac_error();
1997-01-30 11:48:07 -04:00
return Py_BuildValue("(lllllllddd)",
(long)st.st_mode,
(long)st.st_ino,
(long)st.st_dev,
(long)st.st_nlink,
(long)st.st_uid,
(long)st.st_gid,
(long)st.st_size,
(double)st.st_atime,
(double)st.st_mtime,
(double)st.st_ctime);
1998-02-20 11:56:19 -04:00
}
#ifdef WEHAVE_FSTAT
static PyObject *
mac_fstat(self, args)
PyObject *self;
PyObject *args;
{
struct stat st;
long fd;
int res;
if (!PyArg_ParseTuple(args, "l", &fd))
1998-02-20 11:56:19 -04:00
return NULL;
Py_BEGIN_ALLOW_THREADS
res = fstat((int)fd, &st);
Py_END_ALLOW_THREADS
if (res != 0)
return mac_error();
return Py_BuildValue("(lllllllddd)",
(long)st.st_mode,
(long)st.st_ino,
(long)st.st_dev,
(long)st.st_nlink,
(long)st.st_uid,
(long)st.st_gid,
(long)st.st_size,
1998-02-20 11:56:19 -04:00
(double)st.st_atime,
(double)st.st_mtime,
(double)st.st_ctime);
1994-01-05 12:17:15 -04:00
}
1998-02-20 11:56:19 -04:00
#endif /* WEHAVE_FSTAT */
1994-01-05 12:17:15 -04:00
#if TARGET_API_MAC_OS8
1997-01-30 11:48:07 -04:00
static PyObject *
mac_xstat(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
{
struct macstat mst;
struct stat st;
char *path;
int res;
if (!PyArg_ParseTuple(args, "s", &path))
return NULL;
/*
** Convoluted: we want stat() and xstat() to agree, so we call both
** stat and macstat, and use the latter only for values not provided by
** the former.
*/
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
res = macstat(path, &mst);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res != 0)
return mac_error();
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
res = stat(path, &st);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res != 0)
return mac_error();
1997-01-30 11:48:07 -04:00
return Py_BuildValue("(llllllldddls#s#)",
1996-02-14 12:02:30 -04:00
(long)st.st_mode,
(long)st.st_ino,
(long)st.st_dev,
(long)st.st_nlink,
(long)st.st_uid,
(long)st.st_gid,
(long)st.st_size,
(double)st.st_atime,
(double)st.st_mtime,
(double)st.st_ctime,
(long)mst.st_rsize,
mst.st_creator, 4,
mst.st_type, 4);
}
#endif
1997-01-30 11:48:07 -04:00
static PyObject *
1994-01-05 12:17:15 -04:00
mac_sync(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
1994-01-05 12:17:15 -04:00
{
int res;
if (!PyArg_ParseTuple(args, ""))
1994-01-05 12:17:15 -04:00
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
res = sync();
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (res != 0)
return mac_error();
1997-01-30 11:48:07 -04:00
Py_INCREF(Py_None);
return Py_None;
1994-01-05 12:17:15 -04:00
}
1997-01-30 11:48:07 -04:00
static PyObject *
1994-01-05 12:17:15 -04:00
mac_unlink(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
1994-01-05 12:17:15 -04:00
{
return mac_1str(args, (int (*)(const char *))unlink);
1994-01-05 12:17:15 -04:00
}
1997-01-30 11:48:07 -04:00
static PyObject *
mac_write(self, args)
1997-01-30 11:48:07 -04:00
PyObject *self;
PyObject *args;
{
int fd, size;
char *buffer;
if (!PyArg_ParseTuple(args, "is#", &fd, &buffer, &size))
return NULL;
1997-01-30 11:48:07 -04:00
Py_BEGIN_ALLOW_THREADS
size = write(fd, buffer, size);
1997-01-30 11:48:07 -04:00
Py_END_ALLOW_THREADS
if (size < 0)
return mac_error();
1997-01-30 11:48:07 -04:00
return PyInt_FromLong((long)size);
}
1994-01-05 12:17:15 -04:00
#ifdef USE_MALLOC_DEBUG
2000-08-25 19:18:20 -03:00
void *mstats(char *);
1997-01-30 11:48:07 -04:00
static PyObject *
mac_mstats(self, args)
1997-01-30 11:48:07 -04:00
PyObject*self;
PyObject *args;
{
mstats("python");
1997-01-30 11:48:07 -04:00
Py_INCREF(Py_None);
return Py_None;
}
#endif /* USE_MALLOC_DEBUG */
1997-01-30 11:48:07 -04:00
static struct PyMethodDef mac_methods[] = {
{"chdir", mac_chdir, 1},
{"close", mac_close, 1},
#ifdef WEHAVE_DUP
{"dup", mac_dup, 1},
#endif
#ifdef WEHAVE_FDOPEN
{"fdopen", mac_fdopen, 1},
1998-02-20 11:56:19 -04:00
#endif
#ifdef WEHAVE_FSTAT
{"fstat", mac_fstat, 1},
#endif
#if TARGET_API_MAC_OS8
{"getbootvol", mac_getbootvol, 1}, /* non-standard */
#endif
{"getcwd", mac_getcwd, 1},
{"listdir", mac_listdir, 1},
{"lseek", mac_lseek, 1},
{"mkdir", mac_mkdir, 1},
{"open", mac_open, 1},
{"read", mac_read, 1},
{"rename", mac_rename, 1},
{"rmdir", mac_rmdir, 1},
{"stat", mac_stat, 1},
#if TARGET_API_MAC_OS8
{"xstat", mac_xstat, 1},
#endif
{"sync", mac_sync, 1},
{"remove", mac_unlink, 1},
{"unlink", mac_unlink, 1},
{"write", mac_write, 1},
#ifdef USE_MALLOC_DEBUG
{"mstats", mac_mstats, 1},
#endif
1994-01-05 12:17:15 -04:00
{NULL, NULL} /* Sentinel */
};
static int
ins(PyObject *d, char *symbol, long value)
{
PyObject* v = PyInt_FromLong(value);
if (!v || PyDict_SetItemString(d, symbol, v) < 0)
return -1; /* triggers fatal error */
Py_DECREF(v);
return 0;
}
static int
all_ins(PyObject *d)
{
#ifdef F_OK
if (ins(d, "F_OK", (long)F_OK)) return -1;
#endif
#ifdef R_OK
if (ins(d, "R_OK", (long)R_OK)) return -1;
#endif
#ifdef W_OK
if (ins(d, "W_OK", (long)W_OK)) return -1;
#endif
#ifdef X_OK
if (ins(d, "X_OK", (long)X_OK)) return -1;
#endif
#ifdef NGROUPS_MAX
if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1;
#endif
#ifdef TMP_MAX
if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1;
#endif
#ifdef WNOHANG
if (ins(d, "WNOHANG", (long)WNOHANG)) return -1;
#endif
#ifdef O_RDONLY
if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1;
#endif
#ifdef O_WRONLY
if (ins(d, "O_WRONLY", (long)O_WRONLY)) return -1;
#endif
#ifdef O_RDWR
if (ins(d, "O_RDWR", (long)O_RDWR)) return -1;
#endif
#ifdef O_NDELAY
if (ins(d, "O_NDELAY", (long)O_NDELAY)) return -1;
#endif
#ifdef O_NONBLOCK
if (ins(d, "O_NONBLOCK", (long)O_NONBLOCK)) return -1;
#endif
#ifdef O_APPEND
if (ins(d, "O_APPEND", (long)O_APPEND)) return -1;
#endif
#ifdef O_DSYNC
if (ins(d, "O_DSYNC", (long)O_DSYNC)) return -1;
#endif
#ifdef O_RSYNC
if (ins(d, "O_RSYNC", (long)O_RSYNC)) return -1;
#endif
#ifdef O_SYNC
if (ins(d, "O_SYNC", (long)O_SYNC)) return -1;
#endif
#ifdef O_NOCTTY
if (ins(d, "O_NOCTTY", (long)O_NOCTTY)) return -1;
#endif
#ifdef O_CREAT
if (ins(d, "O_CREAT", (long)O_CREAT)) return -1;
#endif
#ifdef O_EXCL
if (ins(d, "O_EXCL", (long)O_EXCL)) return -1;
#endif
#ifdef O_TRUNC
if (ins(d, "O_TRUNC", (long)O_TRUNC)) return -1;
#endif
#ifdef O_BINARY
if (ins(d, "O_BINARY", (long)O_BINARY)) return -1;
#endif
#ifdef O_TEXT
if (ins(d, "O_TEXT", (long)O_TEXT)) return -1;
#endif
#ifdef HAVE_SPAWNV
if (ins(d, "P_WAIT", (long)_P_WAIT)) return -1;
if (ins(d, "P_NOWAIT", (long)_P_NOWAIT)) return -1;
if (ins(d, "P_OVERLAY", (long)_OLD_P_OVERLAY)) return -1;
if (ins(d, "P_NOWAITO", (long)_P_NOWAITO)) return -1;
if (ins(d, "P_DETACH", (long)_P_DETACH)) return -1;
#endif
#if defined(PYOS_OS2)
if (insertvalues(d)) return -1;
#endif
return 0;
}
1994-01-05 12:17:15 -04:00
void
initmac()
{
1997-01-30 11:48:07 -04:00
PyObject *m, *d;
1994-01-05 12:17:15 -04:00
1997-01-30 11:48:07 -04:00
m = Py_InitModule("mac", mac_methods);
d = PyModule_GetDict(m);
1994-01-05 12:17:15 -04:00
if (all_ins(d))
return;
1994-01-05 12:17:15 -04:00
/* Initialize mac.error exception */
1997-10-07 18:47:25 -03:00
MacError = PyErr_NewException("mac.error", NULL, NULL);
PyDict_SetItemString(d, "error", MacError);
1994-01-05 12:17:15 -04:00
}