| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | /***********************************************************
 | 
					
						
							| 
									
										
										
										
											1997-01-31 16:15:11 +00:00
										 |  |  | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, | 
					
						
							| 
									
										
										
										
											1995-01-08 14:33:34 +00:00
										 |  |  | The Netherlands. | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00: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 15:54:15 +00:00
										 |  |  | /* Mac module implementation */ | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | #include "Python.h"
 | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  | #include "structseq.h"
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | #include "ceval.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											1994-08-29 08:42:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-02-14 16:02:30 +00:00
										 |  |  | #ifdef USE_GUSI
 | 
					
						
							| 
									
										
										
										
											1996-10-15 16:13:33 +00:00
										 |  |  | /* Remove defines from macstat.h */ | 
					
						
							|  |  |  | #undef S_IFMT
 | 
					
						
							|  |  |  | #undef S_IFDIR
 | 
					
						
							|  |  |  | #undef S_IFREG
 | 
					
						
							|  |  |  | #undef S_IREAD
 | 
					
						
							|  |  |  | #undef S_IWRITE
 | 
					
						
							|  |  |  | #undef S_IEXEC
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-02-14 16:02:30 +00:00
										 |  |  | #include <sys/types.h>
 | 
					
						
							| 
									
										
										
										
											2000-04-07 09:25:06 +00:00
										 |  |  | #include <sys/stat.h>
 | 
					
						
							|  |  |  | #else /* USE_GUSI */
 | 
					
						
							|  |  |  | #endif /* USE_GUSI */
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-07 09:25:06 +00:00
										 |  |  | #ifdef USE_GUSI2
 | 
					
						
							|  |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | #include <fcntl.h>
 | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2000-05-12 21:36:29 +00:00
										 |  |  | #define mode_t int
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | #include <fcntl.h>
 | 
					
						
							| 
									
										
										
										
											2000-06-02 21:35:07 +00:00
										 |  |  | #ifdef _POSIX
 | 
					
						
							|  |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | #include <stat.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1994-12-14 13:48:38 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00: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 15:56:19 +00:00
										 |  |  | #if defined(USE_GUSI)
 | 
					
						
							|  |  |  | #define WEHAVE_FSTAT
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1995-01-22 16:52:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-08-19 10:51:31 +00:00
										 |  |  | #include "macdefs.h"
 | 
					
						
							| 
									
										
										
										
											1996-02-14 16:02:30 +00:00
										 |  |  | #ifdef USE_GUSI
 | 
					
						
							|  |  |  | #include <dirent.h>
 | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											1994-08-19 10:51:31 +00:00
										 |  |  | #include "dirent.h"
 | 
					
						
							| 
									
										
										
										
											1996-02-14 16:02:30 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifndef MAXPATHLEN
 | 
					
						
							|  |  |  | #define MAXPATHLEN 1024
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Prototypes for Unix simulation on Mac */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00:00
										 |  |  | #ifndef USE_GUSI
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-11 19:51:05 +00:00
										 |  |  | 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); | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-11 19:51:05 +00:00
										 |  |  | int unlink(const char *); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00:00
										 |  |  | #endif /* USE_GUSI */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-11 19:51:05 +00:00
										 |  |  | char *getwd(char *); | 
					
						
							|  |  |  | char *getbootvol(void); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | /* Set a MAC-specific error from errno, and return NULL */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject *  | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_error()  | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2001-11-30 14:16:36 +00:00
										 |  |  | 	return PyErr_SetFromErrno(PyExc_OSError); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* MAC generic methods */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_1str(args, func) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											2000-07-11 19:51:05 +00:00
										 |  |  | 	int (*func)(const char *); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *path1; | 
					
						
							|  |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "s", &path1)) | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	res = (*func)(path1); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (res < 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_2str(args, func) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											2000-07-11 19:51:05 +00:00
										 |  |  | 	int (*func)(const char *, const char *); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *path1, *path2; | 
					
						
							|  |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "ss", &path1, &path2)) | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	res = (*func)(path1, path2); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (res < 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_strint(args, func) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											2000-07-11 19:51:05 +00:00
										 |  |  | 	int (*func)(const char *, int); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *path; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "si", &path, &i)) | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	res = (*func)(path, i); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (res < 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | mac_chdir(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	return mac_1str(args, chdir); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_close(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int fd, res; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "i", &fd)) | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	res = close(fd); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (res < 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00:00
										 |  |  | #ifdef WEHAVE_DUP
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:56:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_dup(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int fd; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "i", &fd)) | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	fd = dup(fd); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (fd < 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return PyInt_FromLong((long)fd); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1994-08-26 09:09:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00:00
										 |  |  | #ifdef WEHAVE_FDOPEN
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_fdopen(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2000-07-11 19:51:05 +00:00
										 |  |  | 	extern int fclose(FILE *); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	int fd; | 
					
						
							| 
									
										
										
										
											2003-01-08 16:27:44 +00:00
										 |  |  | 	char *mode = "r"; | 
					
						
							|  |  |  | 	int bufsize = -1; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	FILE *fp; | 
					
						
							| 
									
										
										
										
											2003-01-08 16:27:44 +00:00
										 |  |  | 	PyObject *f; | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "i|si", &fd, &mode, &bufsize)) | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	fp = fdopen(fd, mode); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (fp == NULL) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											2003-01-08 16:27:44 +00:00
										 |  |  | 	f = PyFile_FromFile(fp, "<fdopen>", mode, fclose); | 
					
						
							|  |  |  | 	if (f != NULL) | 
					
						
							|  |  |  | 		PyFile_SetBufSize(f, bufsize); | 
					
						
							|  |  |  | 	return f; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1994-12-14 13:48:38 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | mac_getcwd(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	char path[MAXPATHLEN]; | 
					
						
							|  |  |  | 	char *res; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00:00
										 |  |  | #ifdef USE_GUSI
 | 
					
						
							|  |  |  | 	res = getcwd(path, sizeof path); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	res = getwd(path); | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (res == NULL) { | 
					
						
							| 
									
										
										
										
											2001-11-30 14:16:36 +00:00
										 |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return PyString_FromString(res); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | mac_listdir(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *name; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *d, *v; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 	DIR *dirp; | 
					
						
							| 
									
										
										
										
											1994-08-19 10:51:31 +00:00
										 |  |  | 	struct dirent *ep; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "s", &name)) | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2001-08-11 23:18:55 +00:00
										 |  |  | #ifdef USE_GUSI
 | 
					
						
							|  |  |  | 	/* Work around a bug in GUSI: if you opendir() a file it will
 | 
					
						
							|  |  |  | 	** actually opendir() the parent directory. | 
					
						
							|  |  |  | 	*/ | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		struct stat stb; | 
					
						
							|  |  |  | 		int res; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		res = stat(name, &stb); | 
					
						
							|  |  |  | 		if ( res < 0 ) | 
					
						
							|  |  |  | 			return mac_error(); | 
					
						
							|  |  |  | 		if (!S_ISDIR(stb.st_mode) ) { | 
					
						
							|  |  |  | 			errno = ENOTDIR; | 
					
						
							|  |  |  | 			return mac_error(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if ((dirp = opendir(name)) == NULL) { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 		Py_BLOCK_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 		return mac_error(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if ((d = PyList_New(0)) == NULL) { | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 		closedir(dirp); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 		Py_BLOCK_THREADS | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	while ((ep = readdir(dirp)) != NULL) { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 		v = PyString_FromString(ep->d_name); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 		if (v == NULL) { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 			Py_DECREF(d); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 			d = NULL; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 		if (PyList_Append(d, v) != 0) { | 
					
						
							|  |  |  | 			Py_DECREF(v); | 
					
						
							|  |  |  | 			Py_DECREF(d); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 			d = NULL; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 		Py_DECREF(v); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	closedir(dirp); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 	return d; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_lseek(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int fd; | 
					
						
							|  |  |  | 	int where; | 
					
						
							|  |  |  | 	int how; | 
					
						
							|  |  |  | 	long res; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "iii", &fd, &where, &how)) | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	res = lseek(fd, (long)where, how); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (res < 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return PyInt_FromLong(res); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1996-02-14 16:02:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | mac_mkdir(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1996-02-21 12:33:50 +00:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 	char *path; | 
					
						
							|  |  |  | 	int mode = 0777; /* Unused */ | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "s|i", &path, &mode)) | 
					
						
							| 
									
										
										
										
											1996-02-21 12:33:50 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1996-02-21 12:33:50 +00:00
										 |  |  | 	res = mkdir(path, mode); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1996-02-21 12:33:50 +00:00
										 |  |  | 	if (res < 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_open(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *path; | 
					
						
							|  |  |  | 	int mode; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	int perm; /* Accepted but ignored */ | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	int fd; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "si|i", &path, &mode, &perm)) | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	fd = open(path, mode); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (fd < 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return PyInt_FromLong((long)fd); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_read(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	int fd, size; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *buffer; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "ii", &fd, &size)) | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	buffer = PyString_FromStringAndSize((char *)NULL, size); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (buffer == NULL) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							|  |  |  | 	size = read(fd, PyString_AsString(buffer), size); | 
					
						
							|  |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (size < 0) { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 		Py_DECREF(buffer); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 		return mac_error(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	_PyString_Resize(&buffer, size); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	return buffer; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_rename(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return mac_2str(args, rename); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | mac_rmdir(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	return mac_1str(args, rmdir); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  | static char stat_result__doc__[] =  | 
					
						
							|  |  |  | "stat_result: Result from stat or lstat.\n\n\
 | 
					
						
							|  |  |  | This object may be accessed either as a tuple of\n\ | 
					
						
							|  |  |  |   (mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime)\n\ | 
					
						
							|  |  |  | or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\ | 
					
						
							|  |  |  | \n\ | 
					
						
							|  |  |  | See os.stat for more information.\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define COMMON_STAT_RESULT_FIELDS \
 | 
					
						
							|  |  |  |         { "st_mode",  "protection bits" }, \ | 
					
						
							|  |  |  |         { "st_ino",   "inode" }, \ | 
					
						
							| 
									
										
										
										
											2001-10-23 22:28:23 +00:00
										 |  |  |         { "st_dev",   "device" }, \ | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  |         { "st_nlink", "number of hard links" }, \ | 
					
						
							| 
									
										
										
										
											2001-10-23 22:28:23 +00:00
										 |  |  |         { "st_uid",   "user ID of owner" }, \ | 
					
						
							|  |  |  |         { "st_gid",   "group ID of owner" }, \ | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  |         { "st_size",  "total size, in bytes" }, \ | 
					
						
							|  |  |  |         { "st_atime", "time of last access" }, \ | 
					
						
							|  |  |  |         { "st_mtime", "time of last modification" }, \ | 
					
						
							|  |  |  |         { "st_ctime", "time of last change" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyStructSequence_Field stat_result_fields[] = { | 
					
						
							|  |  |  | 	COMMON_STAT_RESULT_FIELDS | 
					
						
							|  |  |  | 	{0} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyStructSequence_Desc stat_result_desc = { | 
					
						
							| 
									
										
										
										
											2001-12-08 18:02:58 +00:00
										 |  |  | 	"mac.stat_result", | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  | 	stat_result__doc__, | 
					
						
							|  |  |  | 	stat_result_fields, | 
					
						
							|  |  |  | 	10 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyTypeObject StatResultType; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | _pystat_from_struct_stat(struct stat st, void* _mst)  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *v; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-12 10:31:54 +00:00
										 |  |  | 	v = PyStructSequence_New(&StatResultType); | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  | 	PyStructSequence_SET_ITEM(v, 0, PyInt_FromLong((long)st.st_mode)); | 
					
						
							|  |  |  | 	PyStructSequence_SET_ITEM(v, 1, PyInt_FromLong((long)st.st_ino)); | 
					
						
							|  |  |  | 	PyStructSequence_SET_ITEM(v, 2, PyInt_FromLong((long)st.st_dev)); | 
					
						
							|  |  |  | 	PyStructSequence_SET_ITEM(v, 3, PyInt_FromLong((long)st.st_nlink)); | 
					
						
							|  |  |  | 	PyStructSequence_SET_ITEM(v, 4, PyInt_FromLong((long)st.st_uid)); | 
					
						
							|  |  |  | 	PyStructSequence_SET_ITEM(v, 5, PyInt_FromLong((long)st.st_gid)); | 
					
						
							|  |  |  | 	PyStructSequence_SET_ITEM(v, 6, PyInt_FromLong((long)st.st_size)); | 
					
						
							|  |  |  | 	PyStructSequence_SET_ITEM(v, 7,  | 
					
						
							|  |  |  | 				  PyFloat_FromDouble((double)st.st_atime)); | 
					
						
							|  |  |  | 	PyStructSequence_SET_ITEM(v, 8,  | 
					
						
							|  |  |  | 				  PyFloat_FromDouble((double)st.st_mtime)); | 
					
						
							|  |  |  | 	PyStructSequence_SET_ITEM(v, 9,  | 
					
						
							|  |  |  | 				  PyFloat_FromDouble((double)st.st_ctime)); | 
					
						
							| 
									
										
										
										
											2002-12-12 10:31:54 +00:00
										 |  |  | 	if (PyErr_Occurred()) { | 
					
						
							|  |  |  | 			Py_DECREF(v); | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-12 10:31:54 +00:00
										 |  |  | 	return v; | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | mac_stat(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1996-10-15 16:13:33 +00:00
										 |  |  | 	struct stat st; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 	char *path; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "s", &path)) | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1996-10-15 16:13:33 +00:00
										 |  |  | 	res = stat(path, &st); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (res != 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return _pystat_from_struct_stat(st, NULL); | 
					
						
							| 
									
										
										
										
											1998-02-20 15:56:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef WEHAVE_FSTAT
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | mac_fstat(self, args) | 
					
						
							|  |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct stat st; | 
					
						
							|  |  |  | 	long fd; | 
					
						
							|  |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "l", &fd)) | 
					
						
							| 
									
										
										
										
											1998-02-20 15:56:19 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							|  |  |  | 	res = fstat((int)fd, &st); | 
					
						
							|  |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							|  |  |  | 	if (res != 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return _pystat_from_struct_stat(st, NULL); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1998-02-20 15:56:19 +00:00
										 |  |  | #endif /* WEHAVE_FSTAT */
 | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | mac_sync(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "")) | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											2002-03-21 21:09:36 +00:00
										 |  |  | #ifdef USE_GUSI2
 | 
					
						
							|  |  |  | 	sync(); | 
					
						
							|  |  |  | 	res = 0; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	res = sync(); | 
					
						
							| 
									
										
										
										
											2002-03-21 21:09:36 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (res != 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | mac_unlink(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											1994-08-29 08:42:37 +00:00
										 |  |  | 	return mac_1str(args, (int (*)(const char *))unlink); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | mac_write(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int fd, size; | 
					
						
							|  |  |  | 	char *buffer; | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "is#", &fd, &buffer, &size)) | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_BEGIN_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	size = write(fd, buffer, size); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_END_ALLOW_THREADS | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 	if (size < 0) | 
					
						
							|  |  |  | 		return mac_error(); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	return PyInt_FromLong((long)size); | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-10-23 15:46:57 +00:00
										 |  |  | #ifdef USE_MALLOC_DEBUG
 | 
					
						
							| 
									
										
										
										
											2000-08-25 22:18:20 +00:00
										 |  |  | void *mstats(char *); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											1995-01-18 13:58:04 +00:00
										 |  |  | mac_mstats(self, args) | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject*self; | 
					
						
							|  |  |  | 	PyObject *args; | 
					
						
							| 
									
										
										
										
											1995-01-18 13:58:04 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	mstats("python"); | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											1995-01-18 13:58:04 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											1997-02-20 15:22:17 +00:00
										 |  |  | #endif /* USE_MALLOC_DEBUG */
 | 
					
						
							| 
									
										
										
										
											1995-01-18 13:58:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | static struct PyMethodDef mac_methods[] = { | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	{"chdir",	mac_chdir, 1}, | 
					
						
							|  |  |  | 	{"close",	mac_close, 1}, | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00:00
										 |  |  | #ifdef WEHAVE_DUP
 | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	{"dup",		mac_dup, 1}, | 
					
						
							| 
									
										
										
										
											1994-05-06 15:56:22 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1996-02-20 16:24:37 +00:00
										 |  |  | #ifdef WEHAVE_FDOPEN
 | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	{"fdopen",	mac_fdopen, 1}, | 
					
						
							| 
									
										
										
										
											1998-02-20 15:56:19 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | #ifdef WEHAVE_FSTAT
 | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	{"fstat",	mac_fstat, 1}, | 
					
						
							| 
									
										
										
										
											2000-06-02 21:35:07 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	{"getcwd",	mac_getcwd, 1}, | 
					
						
							|  |  |  | 	{"listdir",	mac_listdir, 1}, | 
					
						
							|  |  |  | 	{"lseek",	mac_lseek, 1}, | 
					
						
							| 
									
										
										
										
											1996-02-21 12:33:50 +00:00
										 |  |  | 	{"mkdir",	mac_mkdir, 1}, | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	{"open",	mac_open, 1}, | 
					
						
							|  |  |  | 	{"read",	mac_read, 1}, | 
					
						
							|  |  |  | 	{"rename",	mac_rename, 1}, | 
					
						
							|  |  |  | 	{"rmdir",	mac_rmdir, 1}, | 
					
						
							|  |  |  | 	{"stat",	mac_stat, 1}, | 
					
						
							|  |  |  | 	{"sync",	mac_sync, 1}, | 
					
						
							|  |  |  | 	{"remove",	mac_unlink, 1}, | 
					
						
							|  |  |  | 	{"unlink",	mac_unlink, 1}, | 
					
						
							|  |  |  | 	{"write",	mac_write, 1}, | 
					
						
							| 
									
										
										
										
											1996-10-23 15:46:57 +00:00
										 |  |  | #ifdef USE_MALLOC_DEBUG
 | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 	{"mstats",	mac_mstats, 1}, | 
					
						
							| 
									
										
										
										
											1995-01-18 13:58:04 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1994-05-06 15:54:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 	{NULL,		NULL}		 /* Sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  | 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 16:17:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | initmac() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	PyObject *m, *d; | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											1997-01-30 15:48:07 +00:00
										 |  |  | 	m = Py_InitModule("mac", mac_methods); | 
					
						
							|  |  |  | 	d = PyModule_GetDict(m); | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2001-08-03 13:07:19 +00:00
										 |  |  |         if (all_ins(d)) | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | 	/* Initialize mac.error exception */ | 
					
						
							| 
									
										
										
										
											2001-11-30 14:16:36 +00:00
										 |  |  | 	PyDict_SetItemString(d, "error", PyExc_OSError); | 
					
						
							| 
									
										
										
											
												SF patch #462296: Add attributes to os.stat results; by Nick Mathewson.
This is a big one, touching lots of files.  Some of the platforms
aren't tested yet.  Briefly, this changes the return value of the
os/posix functions stat(), fstat(), statvfs(), fstatvfs(), and the
time functions localtime(), gmtime(), and strptime() from tuples into
pseudo-sequences.  When accessed as a sequence, they behave exactly as
before.  But they also have attributes like st_mtime or tm_year.  The
stat return value, moreover, has a few platform-specific attributes
that are not available through the sequence interface (because
everybody expects the sequence to have a fixed length, these couldn't
be added there).  If your platform's struct stat doesn't define
st_blksize, st_blocks or st_rdev, they won't be accessible from Python
either.
(Still missing is a documentation update.)
											
										 
											2001-10-18 20:34:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	PyStructSequence_InitType(&StatResultType, &stat_result_desc); | 
					
						
							|  |  |  | 	PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-01-05 16:17:15 +00:00
										 |  |  | } |