1994-01-05 12:17:15 -04:00
|
|
|
/***********************************************************
|
1997-01-31 12:15:11 -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.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
1994-05-06 12:54:15 -03:00
|
|
|
/* Mac module implementation */
|
1994-01-05 12:17:15 -04:00
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
#include "Python.h"
|
1994-05-06 12:54:15 -03:00
|
|
|
#include "ceval.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
1994-08-29 05:42:37 -03:00
|
|
|
|
|
|
|
#ifdef THINK_C
|
|
|
|
#include "unix.h"
|
|
|
|
#undef S_IFMT
|
|
|
|
#undef S_IFDIR
|
|
|
|
#undef S_IFCHR
|
|
|
|
#undef S_IFBLK
|
|
|
|
#undef S_IFREG
|
|
|
|
#undef S_ISDIR
|
|
|
|
#undef S_ISREG
|
2000-04-07 06:25:06 -03:00
|
|
|
#endif /* THINK_C */
|
1994-08-29 05:42:37 -03:00
|
|
|
|
2000-06-02 18:35:07 -03:00
|
|
|
#ifndef TARGET_API_MAC_CARBON_NOTYET
|
|
|
|
/* XXXX Skip for Carbon, for now */
|
1996-10-15 13:13:33 -03:00
|
|
|
#include "macstat.h"
|
2000-06-02 18:35:07 -03:00
|
|
|
#endif
|
|
|
|
|
1996-02-14 12:02:30 -04:00
|
|
|
#ifdef USE_GUSI
|
1996-10-15 13:13:33 -03:00
|
|
|
/* Remove defines from macstat.h */
|
|
|
|
#undef S_IFMT
|
|
|
|
#undef S_IFDIR
|
|
|
|
#undef S_IFREG
|
|
|
|
#undef S_IREAD
|
|
|
|
#undef S_IWRITE
|
|
|
|
#undef S_IEXEC
|
|
|
|
|
2000-04-07 06:25:06 -03:00
|
|
|
#ifdef USE_GUSI1
|
1996-02-20 12:24:37 -04:00
|
|
|
#include <GUSI.h>
|
2000-04-07 06:25:06 -03:00
|
|
|
#endif /* USE_GUSI1 */
|
1996-02-14 12:02:30 -04:00
|
|
|
#include <sys/types.h>
|
2000-04-07 06:25:06 -03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#else /* USE_GUSI */
|
2000-06-02 18:35:07 -03:00
|
|
|
#ifndef TARGET_API_MAC_CARBON_NOTYET
|
1996-10-15 13:13:33 -03:00
|
|
|
#define stat macstat
|
2000-06-02 18:35:07 -03:00
|
|
|
#endif
|
2000-04-07 06:25:06 -03:00
|
|
|
#endif /* USE_GUSI */
|
1994-05-06 12:54:15 -03:00
|
|
|
|
2000-04-07 06:25:06 -03:00
|
|
|
#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
|
1994-05-06 12:54:15 -03:00
|
|
|
#include <fcntl.h>
|
2000-06-02 18:35:07 -03:00
|
|
|
#ifdef _POSIX
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stat.h>
|
|
|
|
#endif
|
1994-12-14 09:48:38 -04:00
|
|
|
#endif
|
1994-05-06 12:54:15 -03:00
|
|
|
|
1996-02-20 12:24:37 -04:00
|
|
|
/* 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
|
1995-01-22 12:52:38 -04:00
|
|
|
|
1994-08-19 07:51:31 -03:00
|
|
|
#include "macdefs.h"
|
1996-02-14 12:02:30 -04:00
|
|
|
#ifdef USE_GUSI
|
|
|
|
#include <dirent.h>
|
|
|
|
#else
|
1994-08-19 07:51:31 -03:00
|
|
|
#include "dirent.h"
|
1996-02-14 12:02:30 -04:00
|
|
|
#endif
|
1994-05-06 12:54:15 -03:00
|
|
|
|
|
|
|
#ifndef MAXPATHLEN
|
|
|
|
#define MAXPATHLEN 1024
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Prototypes for Unix simulation on Mac */
|
|
|
|
|
1996-02-20 12:24:37 -04:00
|
|
|
#ifndef USE_GUSI
|
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
int chdir Py_PROTO((const char *path));
|
|
|
|
int mkdir Py_PROTO((const char *path, int mode));
|
|
|
|
DIR * opendir Py_PROTO((char *));
|
|
|
|
void closedir Py_PROTO((DIR *));
|
|
|
|
struct dirent * readdir Py_PROTO((DIR *));
|
|
|
|
int rmdir Py_PROTO((const char *path));
|
|
|
|
int sync Py_PROTO((void));
|
1996-02-20 12:24:37 -04:00
|
|
|
|
|
|
|
#if defined(THINK_C) || defined(__SC__)
|
1997-01-30 11:48:07 -04:00
|
|
|
int unlink Py_PROTO((char *));
|
1994-08-29 05:42:37 -03:00
|
|
|
#else
|
1997-01-30 11:48:07 -04:00
|
|
|
int unlink Py_PROTO((const char *));
|
1994-08-29 05:42:37 -03:00
|
|
|
#endif
|
1994-05-06 12:54:15 -03:00
|
|
|
|
1996-02-20 12:24:37 -04:00
|
|
|
#endif /* USE_GUSI */
|
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
char *getwd Py_PROTO((char *));
|
|
|
|
char *getbootvol Py_PROTO((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
|
|
|
|
1994-05-06 12:54:15 -03:00
|
|
|
/* Set a MAC-specific error from errno, and return NULL */
|
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_error()
|
|
|
|
{
|
1997-01-30 11:48:07 -04:00
|
|
|
return PyErr_SetFromErrno(MacError);
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* MAC generic methods */
|
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_1str(args, func)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *args;
|
|
|
|
int (*func) Py_FPROTO((const char *));
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
|
|
|
char *path1;
|
|
|
|
int res;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(args, "s", &path1))
|
1994-05-06 12:54:15 -03:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
res = (*func)(path1);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
if (res < 0)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_2str(args, func)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *args;
|
|
|
|
int (*func) Py_FPROTO((const char *, const char *));
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
|
|
|
char *path1, *path2;
|
|
|
|
int res;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(args, "(ss)", &path1, &path2))
|
1994-05-06 12:54:15 -03:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
res = (*func)(path1, path2);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
if (res < 0)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_strint(args, func)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *args;
|
|
|
|
int (*func) Py_FPROTO((const char *, int));
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
int i;
|
|
|
|
int res;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(args, "(si)", &path, &i))
|
1994-05-06 12:54:15 -03:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
res = (*func)(path, i);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
if (res < 0)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2000-04-07 06:25:06 -03:00
|
|
|
#ifdef USE_GUSI1
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *rv;
|
1996-03-06 12:21:34 -04:00
|
|
|
|
|
|
|
/* Change MacOS's idea of wd too */
|
|
|
|
rv = mac_1str(args, chdir);
|
|
|
|
PyMac_FixGUSIcd();
|
|
|
|
return rv;
|
|
|
|
#else
|
1994-05-06 12:54:15 -03:00
|
|
|
return mac_1str(args, chdir);
|
1996-03-06 12:21:34 -04:00
|
|
|
#endif
|
|
|
|
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_close(self, args)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
|
|
|
int fd, res;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(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
|
1994-05-06 12:54:15 -03:00
|
|
|
res = close(fd);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
2000-04-07 06:25:06 -03:00
|
|
|
#ifndef USE_GUSI1
|
1996-02-20 12:24:37 -04:00
|
|
|
/* GUSI gives surious errors here? */
|
1994-05-06 12:54:15 -03:00
|
|
|
if (res < 0)
|
|
|
|
return mac_error();
|
1996-02-20 12:24:37 -04:00
|
|
|
#endif
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-01-05 12:17:15 -04:00
|
|
|
}
|
|
|
|
|
1996-02-20 12:24:37 -04:00
|
|
|
#ifdef WEHAVE_DUP
|
1994-05-06 12:56:22 -03:00
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_dup(self, args)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
|
|
|
int fd;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(args, "i", &fd))
|
1994-05-06 12:54:15 -03:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
fd = dup(fd);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
if (fd < 0)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
return PyInt_FromLong((long)fd);
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
|
|
|
|
1996-02-20 12:24:37 -04:00
|
|
|
#endif
|
1994-08-26 06:09:48 -03:00
|
|
|
|
1996-02-20 12:24:37 -04:00
|
|
|
#ifdef WEHAVE_FDOPEN
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_fdopen(self, args)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
1997-01-30 11:48:07 -04:00
|
|
|
extern int fclose Py_PROTO((FILE *));
|
1994-05-06 12:54:15 -03:00
|
|
|
int fd;
|
|
|
|
char *mode;
|
|
|
|
FILE *fp;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(args, "(is)", &fd, &mode))
|
1994-05-06 12:54:15 -03:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
fp = fdopen(fd, mode);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
if (fp == NULL)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
return PyFile_FromFile(fp, "(fdopen)", mode, fclose);
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
1994-12-14 09:48:38 -04:00
|
|
|
#endif
|
1994-05-06 12:54:15 -03:00
|
|
|
|
2000-06-02 18:35:07 -03:00
|
|
|
#ifndef TARGET_API_MAC_CARBON
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_getbootvol(self, args)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
|
|
|
char *res;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_NoArgs(args))
|
1994-05-06 12:54:15 -03:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
res = getbootvol();
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
if (res == NULL)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
return PyString_FromString(res);
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
2000-06-02 18:35:07 -03:00
|
|
|
#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
|
|
|
{
|
1994-05-06 12:54:15 -03:00
|
|
|
char path[MAXPATHLEN];
|
|
|
|
char *res;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_NoArgs(args))
|
1994-01-05 12:17:15 -04:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1996-02-20 12:24:37 -04:00
|
|
|
#ifdef USE_GUSI
|
|
|
|
res = getcwd(path, sizeof path);
|
|
|
|
#else
|
1994-05-06 12:54:15 -03:00
|
|
|
res = getwd(path);
|
1996-02-20 12:24:37 -04:00
|
|
|
#endif
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
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;
|
1994-08-19 07:51:31 -03:00
|
|
|
struct dirent *ep;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(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
|
1994-05-06 12:54:15 -03:00
|
|
|
if ((dirp = opendir(name)) == NULL) {
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BLOCK_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
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-05-06 12:54:15 -03:00
|
|
|
|
1994-01-05 12:17:15 -04:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_lseek(self, args)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int where;
|
|
|
|
int how;
|
|
|
|
long res;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(args, "(iii)", &fd, &where, &how))
|
1994-05-06 12:54:15 -03:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
res = lseek(fd, (long)where, how);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
if (res < 0)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
return PyInt_FromLong(res);
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
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;
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
1996-02-21 08:33:50 -04:00
|
|
|
int res;
|
|
|
|
char *path;
|
|
|
|
int mode = 0777; /* Unused */
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "s|i", &path, &mode))
|
1996-02-21 08:33:50 -04:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
2000-04-07 06:25:06 -03:00
|
|
|
#ifdef USE_GUSI1
|
1996-08-06 13:06:31 -03:00
|
|
|
res = mkdir(path);
|
|
|
|
#else
|
1996-02-21 08:33:50 -04:00
|
|
|
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
|
1996-02-21 08:33:50 -04:00
|
|
|
if (res < 0)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
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;
|
1994-05-06 12:54:15 -03:00
|
|
|
int fd;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(args, "(si)", &path, &mode))
|
1994-01-05 12:17:15 -04:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
fd = open(path, mode);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
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 *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_read(self, args)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1994-01-05 12:17:15 -04:00
|
|
|
{
|
1994-05-06 12:54:15 -03:00
|
|
|
int fd, size;
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *buffer;
|
|
|
|
if (!PyArg_Parse(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);
|
1994-05-06 12:54:15 -03:00
|
|
|
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
|
1994-05-06 12:54:15 -03:00
|
|
|
if (size < 0) {
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_DECREF(buffer);
|
1994-05-06 12:54:15 -03:00
|
|
|
return mac_error();
|
|
|
|
}
|
1997-01-30 11:48:07 -04:00
|
|
|
_PyString_Resize(&buffer, size);
|
1994-05-06 12:54:15 -03:00
|
|
|
return buffer;
|
1994-01-05 12:17:15 -04:00
|
|
|
}
|
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_rename(self, args)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
1994-05-06 12:54:15 -03: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
|
|
|
{
|
1996-10-15 13:13:33 -03:00
|
|
|
struct stat st;
|
1994-01-05 12:17:15 -04:00
|
|
|
char *path;
|
1994-05-06 12:54:15 -03:00
|
|
|
int res;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(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
|
1996-10-15 13:13:33 -03:00
|
|
|
res = stat(path, &st);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
if (res != 0)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
return Py_BuildValue("(lllllllddd)",
|
1996-10-15 13:13:33 -03: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);
|
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_Parse(args, "l", &fd))
|
|
|
|
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)",
|
1994-05-06 12:54:15 -03:00
|
|
|
(long)st.st_mode,
|
1994-08-26 06:09:48 -03:00
|
|
|
(long)st.st_ino,
|
1994-08-19 07:51:31 -03:00
|
|
|
(long)st.st_dev,
|
|
|
|
(long)st.st_nlink,
|
|
|
|
(long)st.st_uid,
|
|
|
|
(long)st.st_gid,
|
1994-05-06 12:54:15 -03:00
|
|
|
(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
|
|
|
|
2000-06-02 18:35:07 -03:00
|
|
|
#ifndef TARGET_API_MAC_CARBON_NOTYET
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1995-08-08 11:10:22 -03:00
|
|
|
mac_xstat(self, args)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1995-08-08 11:10:22 -03:00
|
|
|
{
|
1996-10-15 13:13:33 -03:00
|
|
|
struct macstat mst;
|
|
|
|
struct stat st;
|
1995-08-08 11:10:22 -03:00
|
|
|
char *path;
|
|
|
|
int res;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_Parse(args, "s", &path))
|
1995-08-08 11:10:22 -03:00
|
|
|
return NULL;
|
1996-10-15 13:13:33 -03:00
|
|
|
/*
|
|
|
|
** 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
|
1996-10-15 13:13:33 -03:00
|
|
|
res = macstat(path, &mst);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1995-08-08 11:10:22 -03:00
|
|
|
if (res != 0)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1996-10-15 13:13:33 -03:00
|
|
|
res = stat(path, &st);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1996-10-15 13:13:33 -03:00
|
|
|
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,
|
1996-10-15 13:13:33 -03:00
|
|
|
(double)st.st_atime,
|
|
|
|
(double)st.st_mtime,
|
|
|
|
(double)st.st_ctime,
|
|
|
|
(long)mst.st_rsize,
|
|
|
|
mst.st_creator, 4,
|
|
|
|
mst.st_type, 4);
|
1995-08-08 11:10:22 -03:00
|
|
|
}
|
2000-06-02 18:35:07 -03:00
|
|
|
#endif
|
1995-08-08 11:10:22 -03:00
|
|
|
|
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
|
|
|
{
|
1994-05-06 12:54:15 -03:00
|
|
|
int res;
|
1997-01-30 11:48:07 -04:00
|
|
|
if (!PyArg_NoArgs(args))
|
1994-01-05 12:17:15 -04:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
res = sync();
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
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
|
|
|
{
|
1994-08-29 05:42:37 -03: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 *
|
1994-05-06 12:54:15 -03:00
|
|
|
mac_write(self, args)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
1994-05-06 12:54:15 -03:00
|
|
|
{
|
|
|
|
int fd, size;
|
|
|
|
char *buffer;
|
1997-05-07 12:46:31 -03:00
|
|
|
if (!PyArg_Parse(args, "(is#)", &fd, &buffer, &size))
|
1994-05-06 12:54:15 -03:00
|
|
|
return NULL;
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_BEGIN_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
size = write(fd, buffer, size);
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_END_ALLOW_THREADS
|
1994-05-06 12:54:15 -03:00
|
|
|
if (size < 0)
|
|
|
|
return mac_error();
|
1997-01-30 11:48:07 -04:00
|
|
|
return PyInt_FromLong((long)size);
|
1994-05-06 12:54:15 -03:00
|
|
|
}
|
1994-01-05 12:17:15 -04:00
|
|
|
|
1996-10-23 12:46:57 -03:00
|
|
|
#ifdef USE_MALLOC_DEBUG
|
1997-01-30 11:48:07 -04:00
|
|
|
static PyObject *
|
1995-01-18 09:58:04 -04:00
|
|
|
mac_mstats(self, args)
|
1997-01-30 11:48:07 -04:00
|
|
|
PyObject*self;
|
|
|
|
PyObject *args;
|
1995-01-18 09:58:04 -04:00
|
|
|
{
|
|
|
|
mstats("python");
|
1997-01-30 11:48:07 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
1995-01-18 09:58:04 -04:00
|
|
|
}
|
1997-02-20 11:22:17 -04:00
|
|
|
#endif /* USE_MALLOC_DEBUG */
|
1995-01-18 09:58:04 -04:00
|
|
|
|
1997-01-30 11:48:07 -04:00
|
|
|
static struct PyMethodDef mac_methods[] = {
|
1994-01-05 12:17:15 -04:00
|
|
|
{"chdir", mac_chdir},
|
1994-05-06 12:54:15 -03:00
|
|
|
{"close", mac_close},
|
1996-02-20 12:24:37 -04:00
|
|
|
#ifdef WEHAVE_DUP
|
1994-05-06 12:54:15 -03:00
|
|
|
{"dup", mac_dup},
|
1994-05-06 12:56:22 -03:00
|
|
|
#endif
|
1996-02-20 12:24:37 -04:00
|
|
|
#ifdef WEHAVE_FDOPEN
|
1994-08-26 06:09:48 -03:00
|
|
|
{"fdopen", mac_fdopen},
|
1998-02-20 11:56:19 -04:00
|
|
|
#endif
|
|
|
|
#ifdef WEHAVE_FSTAT
|
|
|
|
{"fstat", mac_fstat},
|
1994-12-14 09:48:38 -04:00
|
|
|
#endif
|
2000-06-02 18:35:07 -03:00
|
|
|
#ifndef TARGET_API_MAC_CARBON
|
1994-05-06 12:54:15 -03:00
|
|
|
{"getbootvol", mac_getbootvol}, /* non-standard */
|
2000-06-02 18:35:07 -03:00
|
|
|
#endif
|
1994-01-05 12:17:15 -04:00
|
|
|
{"getcwd", mac_getcwd},
|
1995-02-19 11:50:35 -04:00
|
|
|
{"listdir", mac_listdir, 0},
|
1994-05-06 12:54:15 -03:00
|
|
|
{"lseek", mac_lseek},
|
1996-02-21 08:33:50 -04:00
|
|
|
{"mkdir", mac_mkdir, 1},
|
1994-05-06 12:54:15 -03:00
|
|
|
{"open", mac_open},
|
|
|
|
{"read", mac_read},
|
1994-01-05 12:17:15 -04:00
|
|
|
{"rename", mac_rename},
|
|
|
|
{"rmdir", mac_rmdir},
|
|
|
|
{"stat", mac_stat},
|
2000-06-02 18:35:07 -03:00
|
|
|
#ifndef TARGET_API_MAC_CARBON_NOTYET
|
1995-08-08 11:10:22 -03:00
|
|
|
{"xstat", mac_xstat},
|
2000-06-02 18:35:07 -03:00
|
|
|
#endif
|
1994-01-05 12:17:15 -04:00
|
|
|
{"sync", mac_sync},
|
1996-02-21 08:33:50 -04:00
|
|
|
{"remove", mac_unlink},
|
1994-01-05 12:17:15 -04:00
|
|
|
{"unlink", mac_unlink},
|
1994-05-06 12:54:15 -03:00
|
|
|
{"write", mac_write},
|
1996-10-23 12:46:57 -03:00
|
|
|
#ifdef USE_MALLOC_DEBUG
|
1995-01-18 09:58:04 -04:00
|
|
|
{"mstats", mac_mstats},
|
|
|
|
#endif
|
1994-05-06 12:54:15 -03:00
|
|
|
|
1994-01-05 12:17:15 -04:00
|
|
|
{NULL, NULL} /* Sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/* 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
|
|
|
}
|