2 OS-specific module implementation for EDK II and UEFI.
3 Derived from posixmodule.c in Python 2.7.2.
5 Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials are licensed and made available under
7 the terms and conditions of the BSD License that accompanies this distribution.
8 The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #define PY_SSIZE_T_CLEAN
17 #include "structseq.h"
22 #include <sys/syslimits.h>
28 PyDoc_STRVAR(edk2__doc__
,
29 "This module provides access to UEFI firmware functionality that is\n\
30 standardized by the C Standard and the POSIX standard (a thinly\n\
31 disguised Unix interface). Refer to the library manual and\n\
32 corresponding UEFI Specification entries for more information on calls.");
34 #ifndef Py_USING_UNICODE
35 /* This is used in signatures of functions. */
36 #define Py_UNICODE void
39 #ifdef HAVE_SYS_TYPES_H
40 #include <sys/types.h>
41 #endif /* HAVE_SYS_TYPES_H */
43 #ifdef HAVE_SYS_STAT_H
45 #endif /* HAVE_SYS_STAT_H */
47 #ifdef HAVE_SYS_WAIT_H
48 #include <sys/wait.h> /* For WNOHANG */
57 #endif /* HAVE_FCNTL_H */
63 #ifdef HAVE_SYSEXITS_H
65 #endif /* HAVE_SYSEXITS_H */
67 #ifdef HAVE_SYS_LOADAVG_H
68 #include <sys/loadavg.h>
73 #endif /* HAVE_UTIME_H */
75 #ifdef HAVE_SYS_UTIME_H
76 #include <sys/utime.h>
77 #define HAVE_UTIME_H /* pretend we do for the rest of this file */
78 #endif /* HAVE_SYS_UTIME_H */
80 #ifdef HAVE_SYS_TIMES_H
81 #include <sys/times.h>
82 #endif /* HAVE_SYS_TIMES_H */
84 #ifdef HAVE_SYS_PARAM_H
85 #include <sys/param.h>
86 #endif /* HAVE_SYS_PARAM_H */
88 #ifdef HAVE_SYS_UTSNAME_H
89 #include <sys/utsname.h>
90 #endif /* HAVE_SYS_UTSNAME_H */
94 #define NAMLEN(dirent) wcslen((dirent)->FileName)
97 #define NAMLEN(dirent) (dirent)->d_namlen
98 #ifdef HAVE_SYS_NDIR_H
101 #ifdef HAVE_SYS_DIR_H
110 #if defined(PATH_MAX) && PATH_MAX > 1024
111 #define MAXPATHLEN PATH_MAX
113 #define MAXPATHLEN 1024
115 #endif /* MAXPATHLEN */
117 #define WAIT_TYPE int
118 #define WAIT_STATUS_INT(s) (s)
120 /* Issue #1983: pid_t can be longer than a C long on some systems */
121 #if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT
122 #define PARSE_PID "i"
123 #define PyLong_FromPid PyInt_FromLong
124 #define PyLong_AsPid PyInt_AsLong
125 #elif SIZEOF_PID_T == SIZEOF_LONG
126 #define PARSE_PID "l"
127 #define PyLong_FromPid PyInt_FromLong
128 #define PyLong_AsPid PyInt_AsLong
129 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG
130 #define PARSE_PID "L"
131 #define PyLong_FromPid PyLong_FromLongLong
132 #define PyLong_AsPid PyInt_AsLongLong
134 #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)"
135 #endif /* SIZEOF_PID_T */
137 /* Don't use the "_r" form if we don't need it (also, won't have a
138 prototype for it, at least on Solaris -- maybe others as well?). */
139 #if defined(HAVE_CTERMID_R) && defined(WITH_THREAD)
140 #define USE_CTERMID_R
143 #if defined(HAVE_TMPNAM_R) && defined(WITH_THREAD)
147 /* choose the appropriate stat and fstat functions and return structs */
153 #define STRUCT_STAT struct stat
155 /* dummy version. _PyVerify_fd() is already defined in fileobject.h */
156 #define _PyVerify_fd_dup2(A, B) (1)
158 #ifndef UEFI_C_SOURCE
159 /* Return a dictionary corresponding to the POSIX environment table */
160 extern char **environ
;
172 /* This part ignores errors */
173 for (e
= environ
; *e
!= NULL
; e
++) {
176 char *p
= strchr(*e
, '=');
179 k
= PyString_FromStringAndSize(*e
, (int)(p
-*e
));
184 v
= PyString_FromString(p
+1);
190 if (PyDict_GetItem(d
, k
) == NULL
) {
191 if (PyDict_SetItem(d
, k
, v
) != 0)
199 #endif /* UEFI_C_SOURCE */
201 /* Set a POSIX-specific error from errno, and return NULL */
206 return PyErr_SetFromErrno(PyExc_OSError
);
209 posix_error_with_filename(char* name
)
211 return PyErr_SetFromErrnoWithFilename(PyExc_OSError
, name
);
216 posix_error_with_allocated_filename(char* name
)
218 PyObject
*rc
= PyErr_SetFromErrnoWithFilename(PyExc_OSError
, name
);
223 /* POSIX generic methods */
225 #ifndef UEFI_C_SOURCE
227 posix_fildes(PyObject
*fdobj
, int (*func
)(int))
231 fd
= PyObject_AsFileDescriptor(fdobj
);
234 if (!_PyVerify_fd(fd
))
235 return posix_error();
236 Py_BEGIN_ALLOW_THREADS
240 return posix_error();
244 #endif /* UEFI_C_SOURCE */
247 posix_1str(PyObject
*args
, char *format
, int (*func
)(const char*))
251 if (!PyArg_ParseTuple(args
, format
,
252 Py_FileSystemDefaultEncoding
, &path1
))
254 Py_BEGIN_ALLOW_THREADS
255 res
= (*func
)(path1
);
258 return posix_error_with_allocated_filename(path1
);
265 posix_2str(PyObject
*args
,
267 int (*func
)(const char *, const char *))
269 char *path1
= NULL
, *path2
= NULL
;
271 if (!PyArg_ParseTuple(args
, format
,
272 Py_FileSystemDefaultEncoding
, &path1
,
273 Py_FileSystemDefaultEncoding
, &path2
))
275 Py_BEGIN_ALLOW_THREADS
276 res
= (*func
)(path1
, path2
);
281 /* XXX how to report both path1 and path2??? */
282 return posix_error();
287 PyDoc_STRVAR(stat_result__doc__
,
288 "stat_result: Result from stat or lstat.\n\n\
289 This object may be accessed either as a tuple of\n\
290 (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)\n\
291 or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.\n\
293 Posix/windows: If your platform supports st_blksize, st_blocks, st_rdev,\n\
294 or st_flags, they are available as attributes only.\n\
296 See os.stat for more information.");
298 static PyStructSequence_Field stat_result_fields
[] = {
299 {"st_mode", "protection bits"},
300 //{"st_ino", "inode"},
301 //{"st_dev", "device"},
302 //{"st_nlink", "number of hard links"},
303 //{"st_uid", "user ID of owner"},
304 //{"st_gid", "group ID of owner"},
305 {"st_size", "total size, in bytes"},
306 /* The NULL is replaced with PyStructSequence_UnnamedField later. */
307 {NULL
, "integer time of last access"},
308 {NULL
, "integer time of last modification"},
309 {NULL
, "integer time of last change"},
310 {"st_atime", "time of last access"},
311 {"st_mtime", "time of last modification"},
312 {"st_ctime", "time of last change"},
313 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
314 {"st_blksize", "blocksize for filesystem I/O"},
316 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
317 {"st_blocks", "number of blocks allocated"},
319 #ifdef HAVE_STRUCT_STAT_ST_RDEV
320 {"st_rdev", "device type (if inode device)"},
322 #ifdef HAVE_STRUCT_STAT_ST_FLAGS
323 {"st_flags", "user defined flags for file"},
325 #ifdef HAVE_STRUCT_STAT_ST_GEN
326 {"st_gen", "generation number"},
328 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
329 {"st_birthtime", "time of creation"},
334 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
335 #define ST_BLKSIZE_IDX 8
337 #define ST_BLKSIZE_IDX 12
340 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
341 #define ST_BLOCKS_IDX (ST_BLKSIZE_IDX+1)
343 #define ST_BLOCKS_IDX ST_BLKSIZE_IDX
346 #ifdef HAVE_STRUCT_STAT_ST_RDEV
347 #define ST_RDEV_IDX (ST_BLOCKS_IDX+1)
349 #define ST_RDEV_IDX ST_BLOCKS_IDX
352 #ifdef HAVE_STRUCT_STAT_ST_FLAGS
353 #define ST_FLAGS_IDX (ST_RDEV_IDX+1)
355 #define ST_FLAGS_IDX ST_RDEV_IDX
358 #ifdef HAVE_STRUCT_STAT_ST_GEN
359 #define ST_GEN_IDX (ST_FLAGS_IDX+1)
361 #define ST_GEN_IDX ST_FLAGS_IDX
364 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
365 #define ST_BIRTHTIME_IDX (ST_GEN_IDX+1)
367 #define ST_BIRTHTIME_IDX ST_GEN_IDX
370 static PyStructSequence_Desc stat_result_desc
= {
371 "stat_result", /* name */
372 stat_result__doc__
, /* doc */
377 #ifndef UEFI_C_SOURCE /* Not in UEFI */
378 PyDoc_STRVAR(statvfs_result__doc__
,
379 "statvfs_result: Result from statvfs or fstatvfs.\n\n\
380 This object may be accessed either as a tuple of\n\
381 (bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax),\n\
382 or via the attributes f_bsize, f_frsize, f_blocks, f_bfree, and so on.\n\
384 See os.statvfs for more information.");
386 static PyStructSequence_Field statvfs_result_fields
[] = {
400 static PyStructSequence_Desc statvfs_result_desc
= {
401 "statvfs_result", /* name */
402 statvfs_result__doc__
, /* doc */
403 statvfs_result_fields
,
407 static PyTypeObject StatVFSResultType
;
410 static int initialized
;
411 static PyTypeObject StatResultType
;
412 static newfunc structseq_new
;
415 statresult_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
417 PyStructSequence
*result
;
420 result
= (PyStructSequence
*)structseq_new(type
, args
, kwds
);
423 /* If we have been initialized from a tuple,
424 st_?time might be set to None. Initialize it
425 from the int slots. */
426 for (i
= 7; i
<= 9; i
++) {
427 if (result
->ob_item
[i
+3] == Py_None
) {
429 Py_INCREF(result
->ob_item
[i
]);
430 result
->ob_item
[i
+3] = result
->ob_item
[i
];
433 return (PyObject
*)result
;
438 /* If true, st_?time is float. */
439 #if defined(UEFI_C_SOURCE)
440 static int _stat_float_times
= 0;
442 static int _stat_float_times
= 1;
444 PyDoc_STRVAR(stat_float_times__doc__
,
445 "stat_float_times([newval]) -> oldval\n\n\
446 Determine whether os.[lf]stat represents time stamps as float objects.\n\
447 If newval is True, future calls to stat() return floats, if it is False,\n\
448 future calls return ints. \n\
449 If newval is omitted, return the current setting.\n");
452 stat_float_times(PyObject
* self
, PyObject
*args
)
456 if (!PyArg_ParseTuple(args
, "|i:stat_float_times", &newval
))
459 /* Return old value */
460 return PyBool_FromLong(_stat_float_times
);
461 _stat_float_times
= newval
;
465 #endif /* UEFI_C_SOURCE */
468 fill_time(PyObject
*v
, int index
, time_t sec
, unsigned long nsec
)
470 PyObject
*fval
,*ival
;
471 #if SIZEOF_TIME_T > SIZEOF_LONG
472 ival
= PyLong_FromLongLong((PY_LONG_LONG
)sec
);
474 ival
= PyInt_FromLong((long)sec
);
478 if (_stat_float_times
) {
479 fval
= PyFloat_FromDouble(sec
+ 1e-9*nsec
);
484 PyStructSequence_SET_ITEM(v
, index
, ival
);
485 PyStructSequence_SET_ITEM(v
, index
+3, fval
);
488 /* pack a system stat C structure into the Python stat tuple
489 (used by posix_stat() and posix_fstat()) */
491 _pystat_fromstructstat(STRUCT_STAT
*st
)
493 unsigned long ansec
, mnsec
, cnsec
;
494 PyObject
*v
= PyStructSequence_New(&StatResultType
);
498 PyStructSequence_SET_ITEM(v
, 0, PyInt_FromLong((long)st
->st_mode
));
499 PyStructSequence_SET_ITEM(v
, 1,
500 PyLong_FromLongLong((PY_LONG_LONG
)st
->st_size
));
502 ansec
= mnsec
= cnsec
= 0;
503 /* The index used by fill_time is the index of the integer time.
504 fill_time will add 3 to the index to get the floating time index.
506 fill_time(v
, 2, st
->st_atime
, ansec
);
507 fill_time(v
, 3, st
->st_mtime
, mnsec
);
508 fill_time(v
, 4, st
->st_mtime
, cnsec
);
510 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
511 PyStructSequence_SET_ITEM(v
, ST_BLKSIZE_IDX
,
512 PyInt_FromLong((long)st
->st_blksize
));
514 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
515 PyStructSequence_SET_ITEM(v
, ST_BLOCKS_IDX
,
516 PyInt_FromLong((long)st
->st_blocks
));
518 #ifdef HAVE_STRUCT_STAT_ST_RDEV
519 PyStructSequence_SET_ITEM(v
, ST_RDEV_IDX
,
520 PyInt_FromLong((long)st
->st_rdev
));
522 #ifdef HAVE_STRUCT_STAT_ST_GEN
523 PyStructSequence_SET_ITEM(v
, ST_GEN_IDX
,
524 PyInt_FromLong((long)st
->st_gen
));
526 #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
529 unsigned long bsec
,bnsec
;
530 bsec
= (long)st
->st_birthtime
;
531 #ifdef HAVE_STAT_TV_NSEC2
532 bnsec
= st
->st_birthtimespec
.tv_nsec
;
536 if (_stat_float_times
) {
537 val
= PyFloat_FromDouble(bsec
+ 1e-9*bnsec
);
539 val
= PyInt_FromLong((long)bsec
);
541 PyStructSequence_SET_ITEM(v
, ST_BIRTHTIME_IDX
,
545 #ifdef HAVE_STRUCT_STAT_ST_FLAGS
546 PyStructSequence_SET_ITEM(v
, ST_FLAGS_IDX
,
547 PyInt_FromLong((long)st
->st_flags
));
550 if (PyErr_Occurred()) {
559 posix_do_stat(PyObject
*self
, PyObject
*args
,
561 int (*statfunc
)(const char *, STRUCT_STAT
*),
563 int (*wstatfunc
)(const Py_UNICODE
*, STRUCT_STAT
*))
566 char *path
= NULL
; /* pass this to stat; do not free() it */
567 char *pathfree
= NULL
; /* this memory must be free'd */
571 if (!PyArg_ParseTuple(args
, format
,
572 Py_FileSystemDefaultEncoding
, &path
))
576 Py_BEGIN_ALLOW_THREADS
577 res
= (*statfunc
)(path
, &st
);
581 result
= posix_error_with_filename(pathfree
);
584 result
= _pystat_fromstructstat(&st
);
586 PyMem_Free(pathfree
);
592 PyDoc_STRVAR(posix_access__doc__
,
593 "access(path, mode) -> True if granted, False otherwise\n\n\
594 Use the real uid/gid to test for access to a path. Note that most\n\
595 operations will use the effective uid/gid, therefore this routine can\n\
596 be used in a suid/sgid environment to test if the invoking user has the\n\
597 specified access to the path. The mode argument can be F_OK to test\n\
598 existence, or the inclusive-OR of R_OK, W_OK, and X_OK.");
601 posix_access(PyObject
*self
, PyObject
*args
)
607 if (!PyArg_ParseTuple(args
, "eti:access",
608 Py_FileSystemDefaultEncoding
, &path
, &mode
))
610 Py_BEGIN_ALLOW_THREADS
611 res
= access(path
, mode
);
614 return PyBool_FromLong(res
== 0);
630 PyDoc_STRVAR(posix_chdir__doc__
,
632 Change the current working directory to the specified path.");
635 posix_chdir(PyObject
*self
, PyObject
*args
)
637 return posix_1str(args
, "et:chdir", chdir
);
640 PyDoc_STRVAR(posix_chmod__doc__
,
641 "chmod(path, mode)\n\n\
642 Change the access permissions of a file.");
645 posix_chmod(PyObject
*self
, PyObject
*args
)
650 if (!PyArg_ParseTuple(args
, "eti:chmod", Py_FileSystemDefaultEncoding
,
653 Py_BEGIN_ALLOW_THREADS
654 res
= chmod(path
, i
);
657 return posix_error_with_allocated_filename(path
);
664 PyDoc_STRVAR(posix_fchmod__doc__
,
665 "fchmod(fd, mode)\n\n\
666 Change the access permissions of the file given by file\n\
670 posix_fchmod(PyObject
*self
, PyObject
*args
)
673 if (!PyArg_ParseTuple(args
, "ii:fchmod", &fd
, &mode
))
675 Py_BEGIN_ALLOW_THREADS
676 res
= fchmod(fd
, mode
);
679 return posix_error();
682 #endif /* HAVE_FCHMOD */
685 PyDoc_STRVAR(posix_lchmod__doc__
,
686 "lchmod(path, mode)\n\n\
687 Change the access permissions of a file. If path is a symlink, this\n\
688 affects the link itself rather than the target.");
691 posix_lchmod(PyObject
*self
, PyObject
*args
)
696 if (!PyArg_ParseTuple(args
, "eti:lchmod", Py_FileSystemDefaultEncoding
,
699 Py_BEGIN_ALLOW_THREADS
700 res
= lchmod(path
, i
);
703 return posix_error_with_allocated_filename(path
);
707 #endif /* HAVE_LCHMOD */
711 PyDoc_STRVAR(posix_chflags__doc__
,
712 "chflags(path, flags)\n\n\
716 posix_chflags(PyObject
*self
, PyObject
*args
)
721 if (!PyArg_ParseTuple(args
, "etk:chflags",
722 Py_FileSystemDefaultEncoding
, &path
, &flags
))
724 Py_BEGIN_ALLOW_THREADS
725 res
= chflags(path
, flags
);
728 return posix_error_with_allocated_filename(path
);
733 #endif /* HAVE_CHFLAGS */
736 PyDoc_STRVAR(posix_lchflags__doc__
,
737 "lchflags(path, flags)\n\n\
739 This function will not follow symbolic links.");
742 posix_lchflags(PyObject
*self
, PyObject
*args
)
747 if (!PyArg_ParseTuple(args
, "etk:lchflags",
748 Py_FileSystemDefaultEncoding
, &path
, &flags
))
750 Py_BEGIN_ALLOW_THREADS
751 res
= lchflags(path
, flags
);
754 return posix_error_with_allocated_filename(path
);
759 #endif /* HAVE_LCHFLAGS */
762 PyDoc_STRVAR(posix_chroot__doc__
,
764 Change root directory to path.");
767 posix_chroot(PyObject
*self
, PyObject
*args
)
769 return posix_1str(args
, "et:chroot", chroot
);
774 PyDoc_STRVAR(posix_fsync__doc__
,
776 force write of file with filedescriptor to disk.");
779 posix_fsync(PyObject
*self
, PyObject
*fdobj
)
781 return posix_fildes(fdobj
, fsync
);
783 #endif /* HAVE_FSYNC */
785 #ifdef HAVE_FDATASYNC
788 extern int fdatasync(int); /* On HP-UX, in libc but not in unistd.h */
791 PyDoc_STRVAR(posix_fdatasync__doc__
,
792 "fdatasync(fildes)\n\n\
793 force write of file with filedescriptor to disk.\n\
794 does not force update of metadata.");
797 posix_fdatasync(PyObject
*self
, PyObject
*fdobj
)
799 return posix_fildes(fdobj
, fdatasync
);
801 #endif /* HAVE_FDATASYNC */
805 PyDoc_STRVAR(posix_chown__doc__
,
806 "chown(path, uid, gid)\n\n\
807 Change the owner and group id of path to the numeric uid and gid.");
810 posix_chown(PyObject
*self
, PyObject
*args
)
815 if (!PyArg_ParseTuple(args
, "etll:chown",
816 Py_FileSystemDefaultEncoding
, &path
,
819 Py_BEGIN_ALLOW_THREADS
820 res
= chown(path
, (uid_t
) uid
, (gid_t
) gid
);
823 return posix_error_with_allocated_filename(path
);
828 #endif /* HAVE_CHOWN */
831 PyDoc_STRVAR(posix_fchown__doc__
,
832 "fchown(fd, uid, gid)\n\n\
833 Change the owner and group id of the file given by file descriptor\n\
834 fd to the numeric uid and gid.");
837 posix_fchown(PyObject
*self
, PyObject
*args
)
842 if (!PyArg_ParseTuple(args
, "ill:chown", &fd
, &uid
, &gid
))
844 Py_BEGIN_ALLOW_THREADS
845 res
= fchown(fd
, (uid_t
) uid
, (gid_t
) gid
);
848 return posix_error();
851 #endif /* HAVE_FCHOWN */
854 PyDoc_STRVAR(posix_lchown__doc__
,
855 "lchown(path, uid, gid)\n\n\
856 Change the owner and group id of path to the numeric uid and gid.\n\
857 This function will not follow symbolic links.");
860 posix_lchown(PyObject
*self
, PyObject
*args
)
865 if (!PyArg_ParseTuple(args
, "etll:lchown",
866 Py_FileSystemDefaultEncoding
, &path
,
869 Py_BEGIN_ALLOW_THREADS
870 res
= lchown(path
, (uid_t
) uid
, (gid_t
) gid
);
873 return posix_error_with_allocated_filename(path
);
878 #endif /* HAVE_LCHOWN */
882 PyDoc_STRVAR(posix_getcwd__doc__
,
883 "getcwd() -> path\n\n\
884 Return a string representing the current working directory.");
887 posix_getcwd(PyObject
*self
, PyObject
*noargs
)
889 int bufsize_incr
= 1024;
893 PyObject
*dynamic_return
;
895 Py_BEGIN_ALLOW_THREADS
897 bufsize
= bufsize
+ bufsize_incr
;
898 tmpbuf
= malloc(bufsize
);
899 if (tmpbuf
== NULL
) {
902 res
= getcwd(tmpbuf
, bufsize
);
906 } while ((res
== NULL
) && (errno
== ERANGE
));
910 return posix_error();
912 dynamic_return
= PyString_FromString(tmpbuf
);
915 return dynamic_return
;
918 #ifdef Py_USING_UNICODE
919 PyDoc_STRVAR(posix_getcwdu__doc__
,
920 "getcwdu() -> path\n\n\
921 Return a unicode string representing the current working directory.");
924 posix_getcwdu(PyObject
*self
, PyObject
*noargs
)
929 Py_BEGIN_ALLOW_THREADS
930 res
= getcwd(buf
, sizeof buf
);
933 return posix_error();
934 return PyUnicode_Decode(buf
, strlen(buf
), Py_FileSystemDefaultEncoding
,"strict");
936 #endif /* Py_USING_UNICODE */
937 #endif /* HAVE_GETCWD */
940 PyDoc_STRVAR(posix_listdir__doc__
,
941 "listdir(path) -> list_of_strings\n\n\
942 Return a list containing the names of the entries in the directory.\n\
944 path: path of directory to list\n\
946 The list is in arbitrary order. It does not include the special\n\
947 entries '.' and '..' even if they are present in the directory.");
950 posix_listdir(PyObject
*self
, PyObject
*args
)
952 /* XXX Should redo this putting the (now four) versions of opendir
953 in separate files instead of having them all here... */
960 int arg_is_unicode
= 1;
963 if (!PyArg_ParseTuple(args
, "U:listdir", &v
)) {
967 if (!PyArg_ParseTuple(args
, "et:listdir", Py_FileSystemDefaultEncoding
, &name
))
969 Py_BEGIN_ALLOW_THREADS
970 dirp
= opendir(name
);
973 return posix_error_with_allocated_filename(name
);
975 if ((d
= PyList_New(0)) == NULL
) {
976 Py_BEGIN_ALLOW_THREADS
982 if((MBname
= malloc(NAME_MAX
)) == NULL
) {
983 Py_BEGIN_ALLOW_THREADS
992 Py_BEGIN_ALLOW_THREADS
996 if ((errno
== 0) || (errno
== EISDIR
)) {
999 Py_BEGIN_ALLOW_THREADS
1001 Py_END_ALLOW_THREADS
1003 return posix_error_with_allocated_filename(name
);
1006 if (ep
->FileName
[0] == L
'.' &&
1008 (ep
->FileName
[1] == L
'.' && NAMLEN(ep
) == 2)))
1010 if(wcstombs(MBname
, ep
->FileName
, NAME_MAX
) == -1) {
1012 Py_BEGIN_ALLOW_THREADS
1014 Py_END_ALLOW_THREADS
1019 v
= PyString_FromStringAndSize(MBname
, strlen(MBname
));
1025 #ifdef Py_USING_UNICODE
1026 if (arg_is_unicode
) {
1029 w
= PyUnicode_FromEncodedObject(v
,
1030 Py_FileSystemDefaultEncoding
,
1037 /* fall back to the original byte string, as
1038 discussed in patch #683592 */
1043 if (PyList_Append(d
, v
) != 0) {
1051 Py_BEGIN_ALLOW_THREADS
1053 Py_END_ALLOW_THREADS
1055 if(MBname
!= NULL
) {
1061 } /* end of posix_listdir */
1063 PyDoc_STRVAR(posix_mkdir__doc__
,
1064 "mkdir(path [, mode=0777])\n\n\
1065 Create a directory.");
1068 posix_mkdir(PyObject
*self
, PyObject
*args
)
1074 if (!PyArg_ParseTuple(args
, "et|i:mkdir",
1075 Py_FileSystemDefaultEncoding
, &path
, &mode
))
1077 Py_BEGIN_ALLOW_THREADS
1078 res
= mkdir(path
, mode
);
1079 Py_END_ALLOW_THREADS
1081 return posix_error_with_allocated_filename(path
);
1088 /* sys/resource.h is needed for at least: wait3(), wait4(), broken nice. */
1089 #if defined(HAVE_SYS_RESOURCE_H)
1090 #include <sys/resource.h>
1095 PyDoc_STRVAR(posix_nice__doc__
,
1096 "nice(inc) -> new_priority\n\n\
1097 Decrease the priority of process by inc and return the new priority.");
1100 posix_nice(PyObject
*self
, PyObject
*args
)
1102 int increment
, value
;
1104 if (!PyArg_ParseTuple(args
, "i:nice", &increment
))
1107 /* There are two flavours of 'nice': one that returns the new
1108 priority (as required by almost all standards out there) and the
1109 Linux/FreeBSD/BSDI one, which returns '0' on success and advices
1110 the use of getpriority() to get the new priority.
1112 If we are of the nice family that returns the new priority, we
1113 need to clear errno before the call, and check if errno is filled
1114 before calling posix_error() on a returnvalue of -1, because the
1115 -1 may be the actual new priority! */
1118 value
= nice(increment
);
1119 #if defined(HAVE_BROKEN_NICE) && defined(HAVE_GETPRIORITY)
1121 value
= getpriority(PRIO_PROCESS
, 0);
1123 if (value
== -1 && errno
!= 0)
1124 /* either nice() or getpriority() returned an error */
1125 return posix_error();
1126 return PyInt_FromLong((long) value
);
1128 #endif /* HAVE_NICE */
1130 PyDoc_STRVAR(posix_rename__doc__
,
1131 "rename(old, new)\n\n\
1132 Rename a file or directory.");
1135 posix_rename(PyObject
*self
, PyObject
*args
)
1137 return posix_2str(args
, "etet:rename", rename
);
1141 PyDoc_STRVAR(posix_rmdir__doc__
,
1143 Remove a directory.");
1146 posix_rmdir(PyObject
*self
, PyObject
*args
)
1148 return posix_1str(args
, "et:rmdir", rmdir
);
1152 PyDoc_STRVAR(posix_stat__doc__
,
1153 "stat(path) -> stat result\n\n\
1154 Perform a stat system call on the given path.");
1157 posix_stat(PyObject
*self
, PyObject
*args
)
1159 return posix_do_stat(self
, args
, "et:stat", STAT
, NULL
, NULL
);
1164 PyDoc_STRVAR(posix_system__doc__
,
1165 "system(command) -> exit_status\n\n\
1166 Execute the command (a string) in a subshell.");
1169 posix_system(PyObject
*self
, PyObject
*args
)
1173 if (!PyArg_ParseTuple(args
, "s:system", &command
))
1175 Py_BEGIN_ALLOW_THREADS
1176 sts
= system(command
);
1177 Py_END_ALLOW_THREADS
1178 return PyInt_FromLong(sts
);
1183 PyDoc_STRVAR(posix_umask__doc__
,
1184 "umask(new_mask) -> old_mask\n\n\
1185 Set the current numeric umask and return the previous umask.");
1188 posix_umask(PyObject
*self
, PyObject
*args
)
1191 if (!PyArg_ParseTuple(args
, "i:umask", &i
))
1195 return posix_error();
1196 return PyInt_FromLong((long)i
);
1200 PyDoc_STRVAR(posix_unlink__doc__
,
1202 Remove a file (same as remove(path)).");
1204 PyDoc_STRVAR(posix_remove__doc__
,
1206 Remove a file (same as unlink(path)).");
1209 posix_unlink(PyObject
*self
, PyObject
*args
)
1211 return posix_1str(args
, "et:remove", unlink
);
1216 extract_time(PyObject
*t
, time_t* sec
, long* usec
)
1219 if (PyFloat_Check(t
)) {
1220 double tval
= PyFloat_AsDouble(t
);
1221 PyObject
*intobj
= PyNumber_Long(t
);
1224 #if SIZEOF_TIME_T > SIZEOF_LONG
1225 intval
= PyInt_AsUnsignedLongLongMask(intobj
);
1227 intval
= PyInt_AsLong(intobj
);
1230 if (intval
== -1 && PyErr_Occurred())
1233 *usec
= (long)((tval
- intval
) * 1e6
); /* can't exceed 1000000 */
1235 /* If rounding gave us a negative number,
1240 #if SIZEOF_TIME_T > SIZEOF_LONG
1241 intval
= PyInt_AsUnsignedLongLongMask(t
);
1243 intval
= PyInt_AsLong(t
);
1245 if (intval
== -1 && PyErr_Occurred())
1252 PyDoc_STRVAR(posix_utime__doc__
,
1253 "utime(path, (atime, mtime))\n\
1254 utime(path, None)\n\n\
1255 Set the access and modified time of the file to the given values. If the\n\
1256 second form is used, set the access and modified times to the current time.");
1259 posix_utime(PyObject
*self
, PyObject
*args
)
1262 time_t atime
, mtime
;
1267 #if defined(HAVE_UTIMES)
1268 struct timeval buf
[2];
1269 #define ATIME buf[0].tv_sec
1270 #define MTIME buf[1].tv_sec
1271 #elif defined(HAVE_UTIME_H)
1272 /* XXX should define struct utimbuf instead, above */
1274 #define ATIME buf.actime
1275 #define MTIME buf.modtime
1276 #define UTIME_ARG &buf
1277 #else /* HAVE_UTIMES */
1279 #define ATIME buf[0]
1280 #define MTIME buf[1]
1281 #define UTIME_ARG buf
1282 #endif /* HAVE_UTIMES */
1285 if (!PyArg_ParseTuple(args
, "etO:utime",
1286 Py_FileSystemDefaultEncoding
, &path
, &arg
))
1288 if (arg
== Py_None
) {
1289 /* optional time values not given */
1290 Py_BEGIN_ALLOW_THREADS
1291 res
= utime(path
, NULL
);
1292 Py_END_ALLOW_THREADS
1294 else if (!PyTuple_Check(arg
) || PyTuple_Size(arg
) != 2) {
1295 PyErr_SetString(PyExc_TypeError
,
1296 "utime() arg 2 must be a tuple (atime, mtime)");
1301 if (extract_time(PyTuple_GET_ITEM(arg
, 0),
1302 &atime
, &ausec
) == -1) {
1306 if (extract_time(PyTuple_GET_ITEM(arg
, 1),
1307 &mtime
, &musec
) == -1) {
1314 buf
[0].tv_usec
= ausec
;
1315 buf
[1].tv_usec
= musec
;
1316 Py_BEGIN_ALLOW_THREADS
1317 res
= utimes(path
, buf
);
1318 Py_END_ALLOW_THREADS
1320 Py_BEGIN_ALLOW_THREADS
1321 res
= utime(path
, UTIME_ARG
);
1322 Py_END_ALLOW_THREADS
1323 #endif /* HAVE_UTIMES */
1326 return posix_error_with_allocated_filename(path
);
1337 /* Process operations */
1339 PyDoc_STRVAR(posix__exit__doc__
,
1341 Exit to the system with specified status, without normal exit processing.");
1344 posix__exit(PyObject
*self
, PyObject
*args
)
1347 if (!PyArg_ParseTuple(args
, "i:_exit", &sts
))
1350 return NULL
; /* Make gcc -Wall happy */
1353 #if defined(HAVE_EXECV) || defined(HAVE_SPAWNV)
1355 free_string_array(char **array
, Py_ssize_t count
)
1358 for (i
= 0; i
< count
; i
++)
1359 PyMem_Free(array
[i
]);
1366 PyDoc_STRVAR(posix_execv__doc__
,
1367 "execv(path, args)\n\n\
1368 Execute an executable path with arguments, replacing current process.\n\
1370 path: path of executable file\n\
1371 args: tuple or list of strings");
1374 posix_execv(PyObject
*self
, PyObject
*args
)
1380 PyObject
*(*getitem
)(PyObject
*, Py_ssize_t
);
1382 /* execv has two arguments: (path, argv), where
1383 argv is a list or tuple of strings. */
1385 if (!PyArg_ParseTuple(args
, "etO:execv",
1386 Py_FileSystemDefaultEncoding
,
1389 if (PyList_Check(argv
)) {
1390 argc
= PyList_Size(argv
);
1391 getitem
= PyList_GetItem
;
1393 else if (PyTuple_Check(argv
)) {
1394 argc
= PyTuple_Size(argv
);
1395 getitem
= PyTuple_GetItem
;
1398 PyErr_SetString(PyExc_TypeError
, "execv() arg 2 must be a tuple or list");
1403 PyErr_SetString(PyExc_ValueError
, "execv() arg 2 must not be empty");
1408 argvlist
= PyMem_NEW(char *, argc
+1);
1409 if (argvlist
== NULL
) {
1411 return PyErr_NoMemory();
1413 for (i
= 0; i
< argc
; i
++) {
1414 if (!PyArg_Parse((*getitem
)(argv
, i
), "et",
1415 Py_FileSystemDefaultEncoding
,
1417 free_string_array(argvlist
, i
);
1418 PyErr_SetString(PyExc_TypeError
,
1419 "execv() arg 2 must contain only strings");
1425 argvlist
[argc
] = NULL
;
1427 execv(path
, argvlist
);
1429 /* If we get here it's definitely an error */
1431 free_string_array(argvlist
, argc
);
1433 return posix_error();
1437 PyDoc_STRVAR(posix_execve__doc__
,
1438 "execve(path, args, env)\n\n\
1439 Execute a path with arguments and environment, replacing current process.\n\
1441 path: path of executable file\n\
1442 args: tuple or list of arguments\n\
1443 env: dictionary of strings mapping to strings");
1446 posix_execve(PyObject
*self
, PyObject
*args
)
1449 PyObject
*argv
, *env
;
1452 PyObject
*key
, *val
, *keys
=NULL
, *vals
=NULL
;
1453 Py_ssize_t i
, pos
, argc
, envc
;
1454 PyObject
*(*getitem
)(PyObject
*, Py_ssize_t
);
1455 Py_ssize_t lastarg
= 0;
1457 /* execve has three arguments: (path, argv, env), where
1458 argv is a list or tuple of strings and env is a dictionary
1459 like posix.environ. */
1461 if (!PyArg_ParseTuple(args
, "etOO:execve",
1462 Py_FileSystemDefaultEncoding
,
1463 &path
, &argv
, &env
))
1465 if (PyList_Check(argv
)) {
1466 argc
= PyList_Size(argv
);
1467 getitem
= PyList_GetItem
;
1469 else if (PyTuple_Check(argv
)) {
1470 argc
= PyTuple_Size(argv
);
1471 getitem
= PyTuple_GetItem
;
1474 PyErr_SetString(PyExc_TypeError
,
1475 "execve() arg 2 must be a tuple or list");
1478 if (!PyMapping_Check(env
)) {
1479 PyErr_SetString(PyExc_TypeError
,
1480 "execve() arg 3 must be a mapping object");
1484 argvlist
= PyMem_NEW(char *, argc
+1);
1485 if (argvlist
== NULL
) {
1489 for (i
= 0; i
< argc
; i
++) {
1490 if (!PyArg_Parse((*getitem
)(argv
, i
),
1491 "et;execve() arg 2 must contain only strings",
1492 Py_FileSystemDefaultEncoding
,
1500 argvlist
[argc
] = NULL
;
1502 i
= PyMapping_Size(env
);
1505 envlist
= PyMem_NEW(char *, i
+ 1);
1506 if (envlist
== NULL
) {
1511 keys
= PyMapping_Keys(env
);
1512 vals
= PyMapping_Values(env
);
1515 if (!PyList_Check(keys
) || !PyList_Check(vals
)) {
1516 PyErr_SetString(PyExc_TypeError
,
1517 "execve(): env.keys() or env.values() is not a list");
1521 for (pos
= 0; pos
< i
; pos
++) {
1525 key
= PyList_GetItem(keys
, pos
);
1526 val
= PyList_GetItem(vals
, pos
);
1532 "s;execve() arg 3 contains a non-string key",
1536 "s;execve() arg 3 contains a non-string value",
1542 #if defined(PYOS_OS2)
1543 /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */
1544 if (stricmp(k
, "BEGINLIBPATH") != 0 && stricmp(k
, "ENDLIBPATH") != 0) {
1546 len
= PyString_Size(key
) + PyString_Size(val
) + 2;
1547 p
= PyMem_NEW(char, len
);
1552 PyOS_snprintf(p
, len
, "%s=%s", k
, v
);
1553 envlist
[envc
++] = p
;
1554 #if defined(PYOS_OS2)
1560 execve(path
, argvlist
, envlist
);
1562 /* If we get here it's definitely an error */
1564 (void) posix_error();
1568 PyMem_DEL(envlist
[envc
]);
1571 free_string_array(argvlist
, lastarg
);
1578 #endif /* HAVE_EXECV */
1582 PyDoc_STRVAR(posix_spawnv__doc__
,
1583 "spawnv(mode, path, args)\n\n\
1584 Execute the program 'path' in a new process.\n\
1586 mode: mode of process creation\n\
1587 path: path of executable file\n\
1588 args: tuple or list of strings");
1591 posix_spawnv(PyObject
*self
, PyObject
*args
)
1598 Py_intptr_t spawnval
;
1599 PyObject
*(*getitem
)(PyObject
*, Py_ssize_t
);
1601 /* spawnv has three arguments: (mode, path, argv), where
1602 argv is a list or tuple of strings. */
1604 if (!PyArg_ParseTuple(args
, "ietO:spawnv", &mode
,
1605 Py_FileSystemDefaultEncoding
,
1608 if (PyList_Check(argv
)) {
1609 argc
= PyList_Size(argv
);
1610 getitem
= PyList_GetItem
;
1612 else if (PyTuple_Check(argv
)) {
1613 argc
= PyTuple_Size(argv
);
1614 getitem
= PyTuple_GetItem
;
1617 PyErr_SetString(PyExc_TypeError
,
1618 "spawnv() arg 2 must be a tuple or list");
1623 argvlist
= PyMem_NEW(char *, argc
+1);
1624 if (argvlist
== NULL
) {
1626 return PyErr_NoMemory();
1628 for (i
= 0; i
< argc
; i
++) {
1629 if (!PyArg_Parse((*getitem
)(argv
, i
), "et",
1630 Py_FileSystemDefaultEncoding
,
1632 free_string_array(argvlist
, i
);
1635 "spawnv() arg 2 must contain only strings");
1640 argvlist
[argc
] = NULL
;
1642 #if defined(PYOS_OS2) && defined(PYCC_GCC)
1643 Py_BEGIN_ALLOW_THREADS
1644 spawnval
= spawnv(mode
, path
, argvlist
);
1645 Py_END_ALLOW_THREADS
1647 if (mode
== _OLD_P_OVERLAY
)
1650 Py_BEGIN_ALLOW_THREADS
1651 spawnval
= _spawnv(mode
, path
, argvlist
);
1652 Py_END_ALLOW_THREADS
1655 free_string_array(argvlist
, argc
);
1659 return posix_error();
1661 #if SIZEOF_LONG == SIZEOF_VOID_P
1662 return Py_BuildValue("l", (long) spawnval
);
1664 return Py_BuildValue("L", (PY_LONG_LONG
) spawnval
);
1669 PyDoc_STRVAR(posix_spawnve__doc__
,
1670 "spawnve(mode, path, args, env)\n\n\
1671 Execute the program 'path' in a new process.\n\
1673 mode: mode of process creation\n\
1674 path: path of executable file\n\
1675 args: tuple or list of arguments\n\
1676 env: dictionary of strings mapping to strings");
1679 posix_spawnve(PyObject
*self
, PyObject
*args
)
1682 PyObject
*argv
, *env
;
1685 PyObject
*key
, *val
, *keys
=NULL
, *vals
=NULL
, *res
=NULL
;
1686 int mode
, pos
, envc
;
1688 Py_intptr_t spawnval
;
1689 PyObject
*(*getitem
)(PyObject
*, Py_ssize_t
);
1690 Py_ssize_t lastarg
= 0;
1692 /* spawnve has four arguments: (mode, path, argv, env), where
1693 argv is a list or tuple of strings and env is a dictionary
1694 like posix.environ. */
1696 if (!PyArg_ParseTuple(args
, "ietOO:spawnve", &mode
,
1697 Py_FileSystemDefaultEncoding
,
1698 &path
, &argv
, &env
))
1700 if (PyList_Check(argv
)) {
1701 argc
= PyList_Size(argv
);
1702 getitem
= PyList_GetItem
;
1704 else if (PyTuple_Check(argv
)) {
1705 argc
= PyTuple_Size(argv
);
1706 getitem
= PyTuple_GetItem
;
1709 PyErr_SetString(PyExc_TypeError
,
1710 "spawnve() arg 2 must be a tuple or list");
1713 if (!PyMapping_Check(env
)) {
1714 PyErr_SetString(PyExc_TypeError
,
1715 "spawnve() arg 3 must be a mapping object");
1719 argvlist
= PyMem_NEW(char *, argc
+1);
1720 if (argvlist
== NULL
) {
1724 for (i
= 0; i
< argc
; i
++) {
1725 if (!PyArg_Parse((*getitem
)(argv
, i
),
1726 "et;spawnve() arg 2 must contain only strings",
1727 Py_FileSystemDefaultEncoding
,
1735 argvlist
[argc
] = NULL
;
1737 i
= PyMapping_Size(env
);
1740 envlist
= PyMem_NEW(char *, i
+ 1);
1741 if (envlist
== NULL
) {
1746 keys
= PyMapping_Keys(env
);
1747 vals
= PyMapping_Values(env
);
1750 if (!PyList_Check(keys
) || !PyList_Check(vals
)) {
1751 PyErr_SetString(PyExc_TypeError
,
1752 "spawnve(): env.keys() or env.values() is not a list");
1756 for (pos
= 0; pos
< i
; pos
++) {
1760 key
= PyList_GetItem(keys
, pos
);
1761 val
= PyList_GetItem(vals
, pos
);
1767 "s;spawnve() arg 3 contains a non-string key",
1771 "s;spawnve() arg 3 contains a non-string value",
1776 len
= PyString_Size(key
) + PyString_Size(val
) + 2;
1777 p
= PyMem_NEW(char, len
);
1782 PyOS_snprintf(p
, len
, "%s=%s", k
, v
);
1783 envlist
[envc
++] = p
;
1787 #if defined(PYOS_OS2) && defined(PYCC_GCC)
1788 Py_BEGIN_ALLOW_THREADS
1789 spawnval
= spawnve(mode
, path
, argvlist
, envlist
);
1790 Py_END_ALLOW_THREADS
1792 if (mode
== _OLD_P_OVERLAY
)
1795 Py_BEGIN_ALLOW_THREADS
1796 spawnval
= _spawnve(mode
, path
, argvlist
, envlist
);
1797 Py_END_ALLOW_THREADS
1801 (void) posix_error();
1803 #if SIZEOF_LONG == SIZEOF_VOID_P
1804 res
= Py_BuildValue("l", (long) spawnval
);
1806 res
= Py_BuildValue("L", (PY_LONG_LONG
) spawnval
);
1811 PyMem_DEL(envlist
[envc
]);
1814 free_string_array(argvlist
, lastarg
);
1822 /* OS/2 supports spawnvp & spawnvpe natively */
1823 #if defined(PYOS_OS2)
1824 PyDoc_STRVAR(posix_spawnvp__doc__
,
1825 "spawnvp(mode, file, args)\n\n\
1826 Execute the program 'file' in a new process, using the environment\n\
1827 search path to find the file.\n\
1829 mode: mode of process creation\n\
1830 file: executable file name\n\
1831 args: tuple or list of strings");
1834 posix_spawnvp(PyObject
*self
, PyObject
*args
)
1840 Py_intptr_t spawnval
;
1841 PyObject
*(*getitem
)(PyObject
*, Py_ssize_t
);
1843 /* spawnvp has three arguments: (mode, path, argv), where
1844 argv is a list or tuple of strings. */
1846 if (!PyArg_ParseTuple(args
, "ietO:spawnvp", &mode
,
1847 Py_FileSystemDefaultEncoding
,
1850 if (PyList_Check(argv
)) {
1851 argc
= PyList_Size(argv
);
1852 getitem
= PyList_GetItem
;
1854 else if (PyTuple_Check(argv
)) {
1855 argc
= PyTuple_Size(argv
);
1856 getitem
= PyTuple_GetItem
;
1859 PyErr_SetString(PyExc_TypeError
,
1860 "spawnvp() arg 2 must be a tuple or list");
1865 argvlist
= PyMem_NEW(char *, argc
+1);
1866 if (argvlist
== NULL
) {
1868 return PyErr_NoMemory();
1870 for (i
= 0; i
< argc
; i
++) {
1871 if (!PyArg_Parse((*getitem
)(argv
, i
), "et",
1872 Py_FileSystemDefaultEncoding
,
1874 free_string_array(argvlist
, i
);
1877 "spawnvp() arg 2 must contain only strings");
1882 argvlist
[argc
] = NULL
;
1884 Py_BEGIN_ALLOW_THREADS
1885 #if defined(PYCC_GCC)
1886 spawnval
= spawnvp(mode
, path
, argvlist
);
1888 spawnval
= _spawnvp(mode
, path
, argvlist
);
1890 Py_END_ALLOW_THREADS
1892 free_string_array(argvlist
, argc
);
1896 return posix_error();
1898 return Py_BuildValue("l", (long) spawnval
);
1902 PyDoc_STRVAR(posix_spawnvpe__doc__
,
1903 "spawnvpe(mode, file, args, env)\n\n\
1904 Execute the program 'file' in a new process, using the environment\n\
1905 search path to find the file.\n\
1907 mode: mode of process creation\n\
1908 file: executable file name\n\
1909 args: tuple or list of arguments\n\
1910 env: dictionary of strings mapping to strings");
1913 posix_spawnvpe(PyObject
*self
, PyObject
*args
)
1916 PyObject
*argv
, *env
;
1919 PyObject
*key
, *val
, *keys
=NULL
, *vals
=NULL
, *res
=NULL
;
1920 int mode
, i
, pos
, argc
, envc
;
1921 Py_intptr_t spawnval
;
1922 PyObject
*(*getitem
)(PyObject
*, Py_ssize_t
);
1925 /* spawnvpe has four arguments: (mode, path, argv, env), where
1926 argv is a list or tuple of strings and env is a dictionary
1927 like posix.environ. */
1929 if (!PyArg_ParseTuple(args
, "ietOO:spawnvpe", &mode
,
1930 Py_FileSystemDefaultEncoding
,
1931 &path
, &argv
, &env
))
1933 if (PyList_Check(argv
)) {
1934 argc
= PyList_Size(argv
);
1935 getitem
= PyList_GetItem
;
1937 else if (PyTuple_Check(argv
)) {
1938 argc
= PyTuple_Size(argv
);
1939 getitem
= PyTuple_GetItem
;
1942 PyErr_SetString(PyExc_TypeError
,
1943 "spawnvpe() arg 2 must be a tuple or list");
1946 if (!PyMapping_Check(env
)) {
1947 PyErr_SetString(PyExc_TypeError
,
1948 "spawnvpe() arg 3 must be a mapping object");
1952 argvlist
= PyMem_NEW(char *, argc
+1);
1953 if (argvlist
== NULL
) {
1957 for (i
= 0; i
< argc
; i
++) {
1958 if (!PyArg_Parse((*getitem
)(argv
, i
),
1959 "et;spawnvpe() arg 2 must contain only strings",
1960 Py_FileSystemDefaultEncoding
,
1968 argvlist
[argc
] = NULL
;
1970 i
= PyMapping_Size(env
);
1973 envlist
= PyMem_NEW(char *, i
+ 1);
1974 if (envlist
== NULL
) {
1979 keys
= PyMapping_Keys(env
);
1980 vals
= PyMapping_Values(env
);
1983 if (!PyList_Check(keys
) || !PyList_Check(vals
)) {
1984 PyErr_SetString(PyExc_TypeError
,
1985 "spawnvpe(): env.keys() or env.values() is not a list");
1989 for (pos
= 0; pos
< i
; pos
++) {
1993 key
= PyList_GetItem(keys
, pos
);
1994 val
= PyList_GetItem(vals
, pos
);
2000 "s;spawnvpe() arg 3 contains a non-string key",
2004 "s;spawnvpe() arg 3 contains a non-string value",
2009 len
= PyString_Size(key
) + PyString_Size(val
) + 2;
2010 p
= PyMem_NEW(char, len
);
2015 PyOS_snprintf(p
, len
, "%s=%s", k
, v
);
2016 envlist
[envc
++] = p
;
2020 Py_BEGIN_ALLOW_THREADS
2021 #if defined(PYCC_GCC)
2022 spawnval
= spawnvpe(mode
, path
, argvlist
, envlist
);
2024 spawnval
= _spawnvpe(mode
, path
, argvlist
, envlist
);
2026 Py_END_ALLOW_THREADS
2029 (void) posix_error();
2031 res
= Py_BuildValue("l", (long) spawnval
);
2035 PyMem_DEL(envlist
[envc
]);
2038 free_string_array(argvlist
, lastarg
);
2045 #endif /* PYOS_OS2 */
2046 #endif /* HAVE_SPAWNV */
2050 PyDoc_STRVAR(posix_fork1__doc__
,
2051 "fork1() -> pid\n\n\
2052 Fork a child process with a single multiplexed (i.e., not bound) thread.\n\
2054 Return 0 to child process and PID of child to parent process.");
2057 posix_fork1(PyObject
*self
, PyObject
*noargs
)
2061 _PyImport_AcquireLock();
2064 /* child: this clobbers and resets the import lock. */
2067 /* parent: release the import lock. */
2068 result
= _PyImport_ReleaseLock();
2071 return posix_error();
2073 /* Don't clobber the OSError if the fork failed. */
2074 PyErr_SetString(PyExc_RuntimeError
,
2075 "not holding the import lock");
2078 return PyLong_FromPid(pid
);
2084 PyDoc_STRVAR(posix_fork__doc__
,
2086 Fork a child process.\n\
2087 Return 0 to child process and PID of child to parent process.");
2090 posix_fork(PyObject
*self
, PyObject
*noargs
)
2094 _PyImport_AcquireLock();
2097 /* child: this clobbers and resets the import lock. */
2100 /* parent: release the import lock. */
2101 result
= _PyImport_ReleaseLock();
2104 return posix_error();
2106 /* Don't clobber the OSError if the fork failed. */
2107 PyErr_SetString(PyExc_RuntimeError
,
2108 "not holding the import lock");
2111 return PyLong_FromPid(pid
);
2115 /* AIX uses /dev/ptc but is otherwise the same as /dev/ptmx */
2116 /* IRIX has both /dev/ptc and /dev/ptmx, use ptmx */
2117 #if defined(HAVE_DEV_PTC) && !defined(HAVE_DEV_PTMX)
2118 #define DEV_PTY_FILE "/dev/ptc"
2119 #define HAVE_DEV_PTMX
2121 #define DEV_PTY_FILE "/dev/ptmx"
2124 #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX)
2128 #ifdef HAVE_LIBUTIL_H
2129 #include <libutil.h>
2133 #endif /* HAVE_UTIL_H */
2134 #endif /* HAVE_LIBUTIL_H */
2135 #endif /* HAVE_PTY_H */
2136 #ifdef HAVE_STROPTS_H
2137 #include <stropts.h>
2139 #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX */
2141 #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
2142 PyDoc_STRVAR(posix_openpty__doc__
,
2143 "openpty() -> (master_fd, slave_fd)\n\n\
2144 Open a pseudo-terminal, returning open fd's for both master and slave end.\n");
2147 posix_openpty(PyObject
*self
, PyObject
*noargs
)
2149 int master_fd
, slave_fd
;
2150 #ifndef HAVE_OPENPTY
2153 #if defined(HAVE_DEV_PTMX) && !defined(HAVE_OPENPTY) && !defined(HAVE__GETPTY)
2154 PyOS_sighandler_t sig_saved
;
2156 extern char *ptsname(int fildes
);
2161 if (openpty(&master_fd
, &slave_fd
, NULL
, NULL
, NULL
) != 0)
2162 return posix_error();
2163 #elif defined(HAVE__GETPTY)
2164 slave_name
= _getpty(&master_fd
, O_RDWR
, 0666, 0);
2165 if (slave_name
== NULL
)
2166 return posix_error();
2168 slave_fd
= open(slave_name
, O_RDWR
);
2170 return posix_error();
2172 master_fd
= open(DEV_PTY_FILE
, O_RDWR
| O_NOCTTY
); /* open master */
2174 return posix_error();
2175 sig_saved
= PyOS_setsig(SIGCHLD
, SIG_DFL
);
2176 /* change permission of slave */
2177 if (grantpt(master_fd
) < 0) {
2178 PyOS_setsig(SIGCHLD
, sig_saved
);
2179 return posix_error();
2182 if (unlockpt(master_fd
) < 0) {
2183 PyOS_setsig(SIGCHLD
, sig_saved
);
2184 return posix_error();
2186 PyOS_setsig(SIGCHLD
, sig_saved
);
2187 slave_name
= ptsname(master_fd
); /* get name of slave */
2188 if (slave_name
== NULL
)
2189 return posix_error();
2190 slave_fd
= open(slave_name
, O_RDWR
| O_NOCTTY
); /* open slave */
2192 return posix_error();
2193 #if !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC)
2194 ioctl(slave_fd
, I_PUSH
, "ptem"); /* push ptem */
2195 ioctl(slave_fd
, I_PUSH
, "ldterm"); /* push ldterm */
2197 ioctl(slave_fd
, I_PUSH
, "ttcompat"); /* push ttcompat */
2199 #endif /* HAVE_CYGWIN */
2200 #endif /* HAVE_OPENPTY */
2202 return Py_BuildValue("(ii)", master_fd
, slave_fd
);
2205 #endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */
2208 PyDoc_STRVAR(posix_forkpty__doc__
,
2209 "forkpty() -> (pid, master_fd)\n\n\
2210 Fork a new process with a new pseudo-terminal as controlling tty.\n\n\
2211 Like fork(), return 0 as pid to child process, and PID of child to parent.\n\
2212 To both, return fd of newly opened pseudo-terminal.\n");
2215 posix_forkpty(PyObject
*self
, PyObject
*noargs
)
2217 int master_fd
= -1, result
= 0;
2220 _PyImport_AcquireLock();
2221 pid
= forkpty(&master_fd
, NULL
, NULL
, NULL
);
2223 /* child: this clobbers and resets the import lock. */
2226 /* parent: release the import lock. */
2227 result
= _PyImport_ReleaseLock();
2230 return posix_error();
2232 /* Don't clobber the OSError if the fork failed. */
2233 PyErr_SetString(PyExc_RuntimeError
,
2234 "not holding the import lock");
2237 return Py_BuildValue("(Ni)", PyLong_FromPid(pid
), master_fd
);
2241 PyDoc_STRVAR(posix_getpid__doc__
,
2242 "getpid() -> pid\n\n\
2243 Return the current process id");
2246 posix_getpid(PyObject
*self
, PyObject
*noargs
)
2248 return PyLong_FromPid(getpid());
2251 #ifdef HAVE_GETLOGIN
2252 PyDoc_STRVAR(posix_getlogin__doc__
,
2253 "getlogin() -> string\n\n\
2254 Return the actual login name.");
2257 posix_getlogin(PyObject
*self
, PyObject
*noargs
)
2259 PyObject
*result
= NULL
;
2261 int old_errno
= errno
;
2269 PyErr_SetString(PyExc_OSError
,
2270 "unable to determine login name");
2273 result
= PyString_FromString(name
);
2281 PyDoc_STRVAR(posix_kill__doc__
,
2282 "kill(pid, sig)\n\n\
2283 Kill a process with a signal.");
2286 posix_kill(PyObject
*self
, PyObject
*args
)
2290 if (!PyArg_ParseTuple(args
, PARSE_PID
"i:kill", &pid
, &sig
))
2292 #if defined(PYOS_OS2) && !defined(PYCC_GCC)
2293 if (sig
== XCPT_SIGNAL_INTR
|| sig
== XCPT_SIGNAL_BREAK
) {
2295 if ((rc
= DosSendSignalException(pid
, sig
)) != NO_ERROR
)
2296 return os2_error(rc
);
2298 } else if (sig
== XCPT_SIGNAL_KILLPROC
) {
2300 if ((rc
= DosKillProcess(DKP_PROCESS
, pid
)) != NO_ERROR
)
2301 return os2_error(rc
);
2304 return NULL
; /* Unrecognized Signal Requested */
2306 if (kill(pid
, sig
) == -1)
2307 return posix_error();
2316 #ifdef HAVE_SYS_LOCK_H
2317 #include <sys/lock.h>
2320 PyDoc_STRVAR(posix_plock__doc__
,
2322 Lock program segments into memory.");
2325 posix_plock(PyObject
*self
, PyObject
*args
)
2328 if (!PyArg_ParseTuple(args
, "i:plock", &op
))
2330 if (plock(op
) == -1)
2331 return posix_error();
2339 PyDoc_STRVAR(posix_popen__doc__
,
2340 "popen(command [, mode='r' [, bufsize]]) -> pipe\n\n\
2341 Open a pipe to/from a command returning a file object.");
2343 /* standard posix version of popen() support */
2345 posix_popen(PyObject
*self
, PyObject
*args
)
2352 if (!PyArg_ParseTuple(args
, "s|si:popen", &name
, &mode
, &bufsize
))
2354 /* Strip mode of binary or text modifiers */
2355 if (strcmp(mode
, "rb") == 0 || strcmp(mode
, "rt") == 0)
2357 else if (strcmp(mode
, "wb") == 0 || strcmp(mode
, "wt") == 0)
2359 Py_BEGIN_ALLOW_THREADS
2360 fp
= popen(name
, mode
);
2361 Py_END_ALLOW_THREADS
2363 return posix_error();
2364 f
= PyFile_FromFile(fp
, name
, mode
, pclose
);
2366 PyFile_SetBufSize(f
, bufsize
);
2370 #endif /* HAVE_POPEN */
2372 #if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)
2374 wait_helper(pid_t pid
, int status
, struct rusage
*ru
)
2377 static PyObject
*struct_rusage
;
2380 return posix_error();
2382 if (struct_rusage
== NULL
) {
2383 PyObject
*m
= PyImport_ImportModuleNoBlock("resource");
2386 struct_rusage
= PyObject_GetAttrString(m
, "struct_rusage");
2388 if (struct_rusage
== NULL
)
2392 /* XXX(nnorwitz): Copied (w/mods) from resource.c, there should be only one. */
2393 result
= PyStructSequence_New((PyTypeObject
*) struct_rusage
);
2398 #define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)
2401 PyStructSequence_SET_ITEM(result
, 0,
2402 PyFloat_FromDouble(doubletime(ru
->ru_utime
)));
2403 PyStructSequence_SET_ITEM(result
, 1,
2404 PyFloat_FromDouble(doubletime(ru
->ru_stime
)));
2405 #define SET_INT(result, index, value)\
2406 PyStructSequence_SET_ITEM(result, index, PyInt_FromLong(value))
2407 SET_INT(result
, 2, ru
->ru_maxrss
);
2408 SET_INT(result
, 3, ru
->ru_ixrss
);
2409 SET_INT(result
, 4, ru
->ru_idrss
);
2410 SET_INT(result
, 5, ru
->ru_isrss
);
2411 SET_INT(result
, 6, ru
->ru_minflt
);
2412 SET_INT(result
, 7, ru
->ru_majflt
);
2413 SET_INT(result
, 8, ru
->ru_nswap
);
2414 SET_INT(result
, 9, ru
->ru_inblock
);
2415 SET_INT(result
, 10, ru
->ru_oublock
);
2416 SET_INT(result
, 11, ru
->ru_msgsnd
);
2417 SET_INT(result
, 12, ru
->ru_msgrcv
);
2418 SET_INT(result
, 13, ru
->ru_nsignals
);
2419 SET_INT(result
, 14, ru
->ru_nvcsw
);
2420 SET_INT(result
, 15, ru
->ru_nivcsw
);
2423 if (PyErr_Occurred()) {
2428 return Py_BuildValue("NiN", PyLong_FromPid(pid
), status
, result
);
2430 #endif /* HAVE_WAIT3 || HAVE_WAIT4 */
2433 PyDoc_STRVAR(posix_wait3__doc__
,
2434 "wait3(options) -> (pid, status, rusage)\n\n\
2435 Wait for completion of a child process.");
2438 posix_wait3(PyObject
*self
, PyObject
*args
)
2444 WAIT_STATUS_INT(status
) = 0;
2446 if (!PyArg_ParseTuple(args
, "i:wait3", &options
))
2449 Py_BEGIN_ALLOW_THREADS
2450 pid
= wait3(&status
, options
, &ru
);
2451 Py_END_ALLOW_THREADS
2453 return wait_helper(pid
, WAIT_STATUS_INT(status
), &ru
);
2455 #endif /* HAVE_WAIT3 */
2458 PyDoc_STRVAR(posix_wait4__doc__
,
2459 "wait4(pid, options) -> (pid, status, rusage)\n\n\
2460 Wait for completion of a given child process.");
2463 posix_wait4(PyObject
*self
, PyObject
*args
)
2469 WAIT_STATUS_INT(status
) = 0;
2471 if (!PyArg_ParseTuple(args
, PARSE_PID
"i:wait4", &pid
, &options
))
2474 Py_BEGIN_ALLOW_THREADS
2475 pid
= wait4(pid
, &status
, options
, &ru
);
2476 Py_END_ALLOW_THREADS
2478 return wait_helper(pid
, WAIT_STATUS_INT(status
), &ru
);
2480 #endif /* HAVE_WAIT4 */
2483 PyDoc_STRVAR(posix_waitpid__doc__
,
2484 "waitpid(pid, options) -> (pid, status)\n\n\
2485 Wait for completion of a given child process.");
2488 posix_waitpid(PyObject
*self
, PyObject
*args
)
2493 WAIT_STATUS_INT(status
) = 0;
2495 if (!PyArg_ParseTuple(args
, PARSE_PID
"i:waitpid", &pid
, &options
))
2497 Py_BEGIN_ALLOW_THREADS
2498 pid
= waitpid(pid
, &status
, options
);
2499 Py_END_ALLOW_THREADS
2501 return posix_error();
2503 return Py_BuildValue("Ni", PyLong_FromPid(pid
), WAIT_STATUS_INT(status
));
2506 #elif defined(HAVE_CWAIT)
2508 /* MS C has a variant of waitpid() that's usable for most purposes. */
2509 PyDoc_STRVAR(posix_waitpid__doc__
,
2510 "waitpid(pid, options) -> (pid, status << 8)\n\n"
2511 "Wait for completion of a given process. options is ignored on Windows.");
2514 posix_waitpid(PyObject
*self
, PyObject
*args
)
2517 int status
, options
;
2519 if (!PyArg_ParseTuple(args
, PARSE_PID
"i:waitpid", &pid
, &options
))
2521 Py_BEGIN_ALLOW_THREADS
2522 pid
= _cwait(&status
, pid
, options
);
2523 Py_END_ALLOW_THREADS
2525 return posix_error();
2527 /* shift the status left a byte so this is more like the POSIX waitpid */
2528 return Py_BuildValue("Ni", PyLong_FromPid(pid
), status
<< 8);
2530 #endif /* HAVE_WAITPID || HAVE_CWAIT */
2533 PyDoc_STRVAR(posix_wait__doc__
,
2534 "wait() -> (pid, status)\n\n\
2535 Wait for completion of a child process.");
2538 posix_wait(PyObject
*self
, PyObject
*noargs
)
2542 WAIT_STATUS_INT(status
) = 0;
2544 Py_BEGIN_ALLOW_THREADS
2545 pid
= wait(&status
);
2546 Py_END_ALLOW_THREADS
2548 return posix_error();
2550 return Py_BuildValue("Ni", PyLong_FromPid(pid
), WAIT_STATUS_INT(status
));
2555 PyDoc_STRVAR(posix_lstat__doc__
,
2556 "lstat(path) -> stat result\n\n\
2557 Like stat(path), but do not follow symbolic links.");
2560 posix_lstat(PyObject
*self
, PyObject
*args
)
2563 return posix_do_stat(self
, args
, "et:lstat", lstat
, NULL
, NULL
);
2564 #else /* !HAVE_LSTAT */
2565 return posix_do_stat(self
, args
, "et:lstat", STAT
, NULL
, NULL
);
2566 #endif /* !HAVE_LSTAT */
2570 #ifdef HAVE_READLINK
2571 PyDoc_STRVAR(posix_readlink__doc__
,
2572 "readlink(path) -> path\n\n\
2573 Return a string representing the path to which the symbolic link points.");
2576 posix_readlink(PyObject
*self
, PyObject
*args
)
2579 char buf
[MAXPATHLEN
];
2582 #ifdef Py_USING_UNICODE
2583 int arg_is_unicode
= 0;
2586 if (!PyArg_ParseTuple(args
, "et:readlink",
2587 Py_FileSystemDefaultEncoding
, &path
))
2589 #ifdef Py_USING_UNICODE
2590 v
= PySequence_GetItem(args
, 0);
2596 if (PyUnicode_Check(v
)) {
2602 Py_BEGIN_ALLOW_THREADS
2603 n
= readlink(path
, buf
, (int) sizeof buf
);
2604 Py_END_ALLOW_THREADS
2606 return posix_error_with_allocated_filename(path
);
2609 v
= PyString_FromStringAndSize(buf
, n
);
2610 #ifdef Py_USING_UNICODE
2611 if (arg_is_unicode
) {
2614 w
= PyUnicode_FromEncodedObject(v
,
2615 Py_FileSystemDefaultEncoding
,
2622 /* fall back to the original byte string, as
2623 discussed in patch #683592 */
2630 #endif /* HAVE_READLINK */
2634 PyDoc_STRVAR(posix_symlink__doc__
,
2635 "symlink(src, dst)\n\n\
2636 Create a symbolic link pointing to src named dst.");
2639 posix_symlink(PyObject
*self
, PyObject
*args
)
2641 return posix_2str(args
, "etet:symlink", symlink
);
2643 #endif /* HAVE_SYMLINK */
2647 #define NEED_TICKS_PER_SECOND
2648 static long ticks_per_second
= -1;
2650 posix_times(PyObject
*self
, PyObject
*noargs
)
2656 if (c
== (clock_t) -1)
2657 return posix_error();
2658 return Py_BuildValue("ddddd",
2659 (double)t
.tms_utime
/ ticks_per_second
,
2660 (double)t
.tms_stime
/ ticks_per_second
,
2661 (double)t
.tms_cutime
/ ticks_per_second
,
2662 (double)t
.tms_cstime
/ ticks_per_second
,
2663 (double)c
/ ticks_per_second
);
2665 #endif /* HAVE_TIMES */
2669 PyDoc_STRVAR(posix_times__doc__
,
2670 "times() -> (utime, stime, cutime, cstime, elapsed_time)\n\n\
2671 Return a tuple of floating point numbers indicating process times.");
2676 PyDoc_STRVAR(posix_getsid__doc__
,
2677 "getsid(pid) -> sid\n\n\
2678 Call the system call getsid().");
2681 posix_getsid(PyObject
*self
, PyObject
*args
)
2685 if (!PyArg_ParseTuple(args
, PARSE_PID
":getsid", &pid
))
2689 return posix_error();
2690 return PyInt_FromLong((long)sid
);
2692 #endif /* HAVE_GETSID */
2696 PyDoc_STRVAR(posix_setsid__doc__
,
2698 Call the system call setsid().");
2701 posix_setsid(PyObject
*self
, PyObject
*noargs
)
2704 return posix_error();
2708 #endif /* HAVE_SETSID */
2711 PyDoc_STRVAR(posix_setpgid__doc__
,
2712 "setpgid(pid, pgrp)\n\n\
2713 Call the system call setpgid().");
2716 posix_setpgid(PyObject
*self
, PyObject
*args
)
2720 if (!PyArg_ParseTuple(args
, PARSE_PID
"i:setpgid", &pid
, &pgrp
))
2722 if (setpgid(pid
, pgrp
) < 0)
2723 return posix_error();
2727 #endif /* HAVE_SETPGID */
2730 #ifdef HAVE_TCGETPGRP
2731 PyDoc_STRVAR(posix_tcgetpgrp__doc__
,
2732 "tcgetpgrp(fd) -> pgid\n\n\
2733 Return the process group associated with the terminal given by a fd.");
2736 posix_tcgetpgrp(PyObject
*self
, PyObject
*args
)
2740 if (!PyArg_ParseTuple(args
, "i:tcgetpgrp", &fd
))
2742 pgid
= tcgetpgrp(fd
);
2744 return posix_error();
2745 return PyLong_FromPid(pgid
);
2747 #endif /* HAVE_TCGETPGRP */
2750 #ifdef HAVE_TCSETPGRP
2751 PyDoc_STRVAR(posix_tcsetpgrp__doc__
,
2752 "tcsetpgrp(fd, pgid)\n\n\
2753 Set the process group associated with the terminal given by a fd.");
2756 posix_tcsetpgrp(PyObject
*self
, PyObject
*args
)
2760 if (!PyArg_ParseTuple(args
, "i" PARSE_PID
":tcsetpgrp", &fd
, &pgid
))
2762 if (tcsetpgrp(fd
, pgid
) < 0)
2763 return posix_error();
2767 #endif /* HAVE_TCSETPGRP */
2769 /* Functions acting on file descriptors */
2771 PyDoc_STRVAR(posix_open__doc__
,
2772 "open(filename, flag [, mode=0777]) -> fd\n\n\
2773 Open a file (for low level IO).");
2776 posix_open(PyObject
*self
, PyObject
*args
)
2783 if (!PyArg_ParseTuple(args
, "eti|i",
2784 Py_FileSystemDefaultEncoding
, &file
,
2788 Py_BEGIN_ALLOW_THREADS
2789 fd
= open(file
, flag
, mode
);
2790 Py_END_ALLOW_THREADS
2792 return posix_error_with_allocated_filename(file
);
2794 return PyInt_FromLong((long)fd
);
2798 PyDoc_STRVAR(posix_close__doc__
,
2800 Close a file descriptor (for low level IO).");
2803 posix_close(PyObject
*self
, PyObject
*args
)
2806 if (!PyArg_ParseTuple(args
, "i:close", &fd
))
2808 if (!_PyVerify_fd(fd
))
2809 return posix_error();
2810 Py_BEGIN_ALLOW_THREADS
2812 Py_END_ALLOW_THREADS
2814 return posix_error();
2820 PyDoc_STRVAR(posix_closerange__doc__
,
2821 "closerange(fd_low, fd_high)\n\n\
2822 Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
2825 posix_closerange(PyObject
*self
, PyObject
*args
)
2827 int fd_from
, fd_to
, i
;
2828 if (!PyArg_ParseTuple(args
, "ii:closerange", &fd_from
, &fd_to
))
2830 Py_BEGIN_ALLOW_THREADS
2831 for (i
= fd_from
; i
< fd_to
; i
++)
2832 if (_PyVerify_fd(i
))
2834 Py_END_ALLOW_THREADS
2839 PyDoc_STRVAR(posix_dup__doc__
,
2840 "dup(fd) -> fd2\n\n\
2841 Return a duplicate of a file descriptor.");
2844 posix_dup(PyObject
*self
, PyObject
*args
)
2847 if (!PyArg_ParseTuple(args
, "i:dup", &fd
))
2849 if (!_PyVerify_fd(fd
))
2850 return posix_error();
2851 Py_BEGIN_ALLOW_THREADS
2853 Py_END_ALLOW_THREADS
2855 return posix_error();
2856 return PyInt_FromLong((long)fd
);
2860 PyDoc_STRVAR(posix_dup2__doc__
,
2861 "dup2(old_fd, new_fd)\n\n\
2862 Duplicate file descriptor.");
2865 posix_dup2(PyObject
*self
, PyObject
*args
)
2868 if (!PyArg_ParseTuple(args
, "ii:dup2", &fd
, &fd2
))
2870 if (!_PyVerify_fd_dup2(fd
, fd2
))
2871 return posix_error();
2872 Py_BEGIN_ALLOW_THREADS
2873 res
= dup2(fd
, fd2
);
2874 Py_END_ALLOW_THREADS
2876 return posix_error();
2882 PyDoc_STRVAR(posix_lseek__doc__
,
2883 "lseek(fd, pos, how) -> newpos\n\n\
2884 Set the current position of a file descriptor.");
2887 posix_lseek(PyObject
*self
, PyObject
*args
)
2892 if (!PyArg_ParseTuple(args
, "iOi:lseek", &fd
, &posobj
, &how
))
2895 /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
2897 case 0: how
= SEEK_SET
; break;
2898 case 1: how
= SEEK_CUR
; break;
2899 case 2: how
= SEEK_END
; break;
2901 #endif /* SEEK_END */
2903 #if !defined(HAVE_LARGEFILE_SUPPORT)
2904 pos
= PyInt_AsLong(posobj
);
2906 pos
= PyLong_Check(posobj
) ?
2907 PyLong_AsLongLong(posobj
) : PyInt_AsLong(posobj
);
2909 if (PyErr_Occurred())
2912 if (!_PyVerify_fd(fd
))
2913 return posix_error();
2914 Py_BEGIN_ALLOW_THREADS
2915 res
= lseek(fd
, pos
, how
);
2916 Py_END_ALLOW_THREADS
2918 return posix_error();
2920 #if !defined(HAVE_LARGEFILE_SUPPORT)
2921 return PyInt_FromLong(res
);
2923 return PyLong_FromLongLong(res
);
2928 PyDoc_STRVAR(posix_read__doc__
,
2929 "read(fd, buffersize) -> string\n\n\
2930 Read a file descriptor.");
2933 posix_read(PyObject
*self
, PyObject
*args
)
2937 if (!PyArg_ParseTuple(args
, "ii:read", &fd
, &size
))
2941 return posix_error();
2943 buffer
= PyString_FromStringAndSize((char *)NULL
, size
);
2946 if (!_PyVerify_fd(fd
)) {
2948 return posix_error();
2950 Py_BEGIN_ALLOW_THREADS
2951 n
= read(fd
, PyString_AsString(buffer
), size
);
2952 Py_END_ALLOW_THREADS
2955 return posix_error();
2958 _PyString_Resize(&buffer
, n
);
2963 PyDoc_STRVAR(posix_write__doc__
,
2964 "write(fd, string) -> byteswritten\n\n\
2965 Write a string to a file descriptor.");
2968 posix_write(PyObject
*self
, PyObject
*args
)
2974 if (!PyArg_ParseTuple(args
, "is*:write", &fd
, &pbuf
))
2976 if (!_PyVerify_fd(fd
)) {
2977 PyBuffer_Release(&pbuf
);
2978 return posix_error();
2980 Py_BEGIN_ALLOW_THREADS
2981 size
= write(fd
, pbuf
.buf
, (size_t)pbuf
.len
);
2982 Py_END_ALLOW_THREADS
2983 PyBuffer_Release(&pbuf
);
2985 return posix_error();
2986 return PyInt_FromSsize_t(size
);
2990 PyDoc_STRVAR(posix_fstat__doc__
,
2991 "fstat(fd) -> stat result\n\n\
2992 Like stat(), but for an open file descriptor.");
2995 posix_fstat(PyObject
*self
, PyObject
*args
)
3000 if (!PyArg_ParseTuple(args
, "i:fstat", &fd
))
3002 if (!_PyVerify_fd(fd
))
3003 return posix_error();
3004 Py_BEGIN_ALLOW_THREADS
3005 res
= FSTAT(fd
, &st
);
3006 Py_END_ALLOW_THREADS
3008 return posix_error();
3011 return _pystat_fromstructstat(&st
);
3015 PyDoc_STRVAR(posix_fdopen__doc__
,
3016 "fdopen(fd [, mode='r' [, bufsize]]) -> file_object\n\n\
3017 Return an open file object connected to a file descriptor.");
3020 posix_fdopen(PyObject
*self
, PyObject
*args
)
3023 char *orgmode
= "r";
3028 if (!PyArg_ParseTuple(args
, "i|si", &fd
, &orgmode
, &bufsize
))
3031 /* Sanitize mode. See fileobject.c */
3032 mode
= PyMem_MALLOC(strlen(orgmode
)+3);
3037 strcpy(mode
, orgmode
);
3038 if (_PyFile_SanitizeMode(mode
)) {
3042 if (!_PyVerify_fd(fd
))
3043 return posix_error();
3044 Py_BEGIN_ALLOW_THREADS
3045 #if !defined(MS_WINDOWS) && defined(HAVE_FCNTL_H)
3046 if (mode
[0] == 'a') {
3047 /* try to make sure the O_APPEND flag is set */
3049 flags
= fcntl(fd
, F_GETFL
);
3051 fcntl(fd
, F_SETFL
, flags
| O_APPEND
);
3052 fp
= fdopen(fd
, mode
);
3053 if (fp
== NULL
&& flags
!= -1)
3054 /* restore old mode if fdopen failed */
3055 fcntl(fd
, F_SETFL
, flags
);
3057 fp
= fdopen(fd
, mode
);
3060 fp
= fdopen(fd
, mode
);
3062 Py_END_ALLOW_THREADS
3065 return posix_error();
3066 f
= PyFile_FromFile(fp
, "<fdopen>", orgmode
, fclose
);
3068 PyFile_SetBufSize(f
, bufsize
);
3072 PyDoc_STRVAR(posix_isatty__doc__
,
3073 "isatty(fd) -> bool\n\n\
3074 Return True if the file descriptor 'fd' is an open file descriptor\n\
3075 connected to the slave end of a terminal.");
3078 posix_isatty(PyObject
*self
, PyObject
*args
)
3081 if (!PyArg_ParseTuple(args
, "i:isatty", &fd
))
3083 if (!_PyVerify_fd(fd
))
3084 return PyBool_FromLong(0);
3085 return PyBool_FromLong(isatty(fd
));
3089 PyDoc_STRVAR(posix_pipe__doc__
,
3090 "pipe() -> (read_end, write_end)\n\n\
3094 posix_pipe(PyObject
*self
, PyObject
*noargs
)
3098 Py_BEGIN_ALLOW_THREADS
3100 Py_END_ALLOW_THREADS
3102 return posix_error();
3103 return Py_BuildValue("(ii)", fds
[0], fds
[1]);
3105 #endif /* HAVE_PIPE */
3109 PyDoc_STRVAR(posix_mkfifo__doc__
,
3110 "mkfifo(filename [, mode=0666])\n\n\
3111 Create a FIFO (a POSIX named pipe).");
3114 posix_mkfifo(PyObject
*self
, PyObject
*args
)
3119 if (!PyArg_ParseTuple(args
, "s|i:mkfifo", &filename
, &mode
))
3121 Py_BEGIN_ALLOW_THREADS
3122 res
= mkfifo(filename
, mode
);
3123 Py_END_ALLOW_THREADS
3125 return posix_error();
3132 #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
3133 PyDoc_STRVAR(posix_mknod__doc__
,
3134 "mknod(filename [, mode=0600, device])\n\n\
3135 Create a filesystem node (file, device special file or named pipe)\n\
3136 named filename. mode specifies both the permissions to use and the\n\
3137 type of node to be created, being combined (bitwise OR) with one of\n\
3138 S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,\n\
3139 device defines the newly created device special file (probably using\n\
3140 os.makedev()), otherwise it is ignored.");
3144 posix_mknod(PyObject
*self
, PyObject
*args
)
3150 if (!PyArg_ParseTuple(args
, "s|ii:mknod", &filename
, &mode
, &device
))
3152 Py_BEGIN_ALLOW_THREADS
3153 res
= mknod(filename
, mode
, device
);
3154 Py_END_ALLOW_THREADS
3156 return posix_error();
3162 #ifdef HAVE_DEVICE_MACROS
3163 PyDoc_STRVAR(posix_major__doc__
,
3164 "major(device) -> major number\n\
3165 Extracts a device major number from a raw device number.");
3168 posix_major(PyObject
*self
, PyObject
*args
)
3171 if (!PyArg_ParseTuple(args
, "i:major", &device
))
3173 return PyInt_FromLong((long)major(device
));
3176 PyDoc_STRVAR(posix_minor__doc__
,
3177 "minor(device) -> minor number\n\
3178 Extracts a device minor number from a raw device number.");
3181 posix_minor(PyObject
*self
, PyObject
*args
)
3184 if (!PyArg_ParseTuple(args
, "i:minor", &device
))
3186 return PyInt_FromLong((long)minor(device
));
3189 PyDoc_STRVAR(posix_makedev__doc__
,
3190 "makedev(major, minor) -> device number\n\
3191 Composes a raw device number from the major and minor device numbers.");
3194 posix_makedev(PyObject
*self
, PyObject
*args
)
3197 if (!PyArg_ParseTuple(args
, "ii:makedev", &major
, &minor
))
3199 return PyInt_FromLong((long)makedev(major
, minor
));
3201 #endif /* device macros */
3204 #ifdef HAVE_FTRUNCATE
3205 PyDoc_STRVAR(posix_ftruncate__doc__
,
3206 "ftruncate(fd, length)\n\n\
3207 Truncate a file to a specified length.");
3210 posix_ftruncate(PyObject
*self
, PyObject
*args
)
3217 if (!PyArg_ParseTuple(args
, "iO:ftruncate", &fd
, &lenobj
))
3220 #if !defined(HAVE_LARGEFILE_SUPPORT)
3221 length
= PyInt_AsLong(lenobj
);
3223 length
= PyLong_Check(lenobj
) ?
3224 PyLong_AsLongLong(lenobj
) : PyInt_AsLong(lenobj
);
3226 if (PyErr_Occurred())
3229 Py_BEGIN_ALLOW_THREADS
3230 res
= ftruncate(fd
, length
);
3231 Py_END_ALLOW_THREADS
3233 return posix_error();
3240 PyDoc_STRVAR(posix_putenv__doc__
,
3241 "putenv(key, value)\n\n\
3242 Change or add an environment variable.");
3244 /* Save putenv() parameters as values here, so we can collect them when they
3245 * get re-set with another call for the same key. */
3246 static PyObject
*posix_putenv_garbage
;
3249 posix_putenv(PyObject
*self
, PyObject
*args
)
3256 if (!PyArg_ParseTuple(args
, "ss:putenv", &s1
, &s2
))
3259 /* XXX This can leak memory -- not easy to fix :-( */
3260 len
= strlen(s1
) + strlen(s2
) + 2;
3261 /* len includes space for a trailing \0; the size arg to
3262 PyString_FromStringAndSize does not count that */
3263 newstr
= PyString_FromStringAndSize(NULL
, (int)len
- 1);
3265 return PyErr_NoMemory();
3266 newenv
= PyString_AS_STRING(newstr
);
3267 PyOS_snprintf(newenv
, len
, "%s=%s", s1
, s2
);
3268 if (putenv(newenv
)) {
3273 /* Install the first arg and newstr in posix_putenv_garbage;
3274 * this will cause previous value to be collected. This has to
3275 * happen after the real putenv() call because the old value
3276 * was still accessible until then. */
3277 if (PyDict_SetItem(posix_putenv_garbage
,
3278 PyTuple_GET_ITEM(args
, 0), newstr
)) {
3279 /* really not much we can do; just leak */
3291 #ifdef HAVE_UNSETENV
3292 PyDoc_STRVAR(posix_unsetenv__doc__
,
3294 Delete an environment variable.");
3297 posix_unsetenv(PyObject
*self
, PyObject
*args
)
3301 if (!PyArg_ParseTuple(args
, "s:unsetenv", &s1
))
3306 /* Remove the key from posix_putenv_garbage;
3307 * this will cause it to be collected. This has to
3308 * happen after the real unsetenv() call because the
3309 * old value was still accessible until then.
3311 if (PyDict_DelItem(posix_putenv_garbage
,
3312 PyTuple_GET_ITEM(args
, 0))) {
3313 /* really not much we can do; just leak */
3320 #endif /* unsetenv */
3322 PyDoc_STRVAR(posix_strerror__doc__
,
3323 "strerror(code) -> string\n\n\
3324 Translate an error code to a message string.");
3327 posix_strerror(PyObject
*self
, PyObject
*args
)
3331 if (!PyArg_ParseTuple(args
, "i:strerror", &code
))
3333 message
= strerror(code
);
3334 if (message
== NULL
) {
3335 PyErr_SetString(PyExc_ValueError
,
3336 "strerror() argument out of range");
3339 return PyString_FromString(message
);
3343 #ifdef HAVE_SYS_WAIT_H
3346 PyDoc_STRVAR(posix_WCOREDUMP__doc__
,
3347 "WCOREDUMP(status) -> bool\n\n\
3348 Return True if the process returning 'status' was dumped to a core file.");
3351 posix_WCOREDUMP(PyObject
*self
, PyObject
*args
)
3354 WAIT_STATUS_INT(status
) = 0;
3356 if (!PyArg_ParseTuple(args
, "i:WCOREDUMP", &WAIT_STATUS_INT(status
)))
3359 return PyBool_FromLong(WCOREDUMP(status
));
3361 #endif /* WCOREDUMP */
3364 PyDoc_STRVAR(posix_WIFCONTINUED__doc__
,
3365 "WIFCONTINUED(status) -> bool\n\n\
3366 Return True if the process returning 'status' was continued from a\n\
3367 job control stop.");
3370 posix_WIFCONTINUED(PyObject
*self
, PyObject
*args
)
3373 WAIT_STATUS_INT(status
) = 0;
3375 if (!PyArg_ParseTuple(args
, "i:WCONTINUED", &WAIT_STATUS_INT(status
)))
3378 return PyBool_FromLong(WIFCONTINUED(status
));
3380 #endif /* WIFCONTINUED */
3383 PyDoc_STRVAR(posix_WIFSTOPPED__doc__
,
3384 "WIFSTOPPED(status) -> bool\n\n\
3385 Return True if the process returning 'status' was stopped.");
3388 posix_WIFSTOPPED(PyObject
*self
, PyObject
*args
)
3391 WAIT_STATUS_INT(status
) = 0;
3393 if (!PyArg_ParseTuple(args
, "i:WIFSTOPPED", &WAIT_STATUS_INT(status
)))
3396 return PyBool_FromLong(WIFSTOPPED(status
));
3398 #endif /* WIFSTOPPED */
3401 PyDoc_STRVAR(posix_WIFSIGNALED__doc__
,
3402 "WIFSIGNALED(status) -> bool\n\n\
3403 Return True if the process returning 'status' was terminated by a signal.");
3406 posix_WIFSIGNALED(PyObject
*self
, PyObject
*args
)
3409 WAIT_STATUS_INT(status
) = 0;
3411 if (!PyArg_ParseTuple(args
, "i:WIFSIGNALED", &WAIT_STATUS_INT(status
)))
3414 return PyBool_FromLong(WIFSIGNALED(status
));
3416 #endif /* WIFSIGNALED */
3419 PyDoc_STRVAR(posix_WIFEXITED__doc__
,
3420 "WIFEXITED(status) -> bool\n\n\
3421 Return true if the process returning 'status' exited using the exit()\n\
3425 posix_WIFEXITED(PyObject
*self
, PyObject
*args
)
3428 WAIT_STATUS_INT(status
) = 0;
3430 if (!PyArg_ParseTuple(args
, "i:WIFEXITED", &WAIT_STATUS_INT(status
)))
3433 return PyBool_FromLong(WIFEXITED(status
));
3435 #endif /* WIFEXITED */
3438 PyDoc_STRVAR(posix_WEXITSTATUS__doc__
,
3439 "WEXITSTATUS(status) -> integer\n\n\
3440 Return the process return code from 'status'.");
3443 posix_WEXITSTATUS(PyObject
*self
, PyObject
*args
)
3446 WAIT_STATUS_INT(status
) = 0;
3448 if (!PyArg_ParseTuple(args
, "i:WEXITSTATUS", &WAIT_STATUS_INT(status
)))
3451 return Py_BuildValue("i", WEXITSTATUS(status
));
3453 #endif /* WEXITSTATUS */
3456 PyDoc_STRVAR(posix_WTERMSIG__doc__
,
3457 "WTERMSIG(status) -> integer\n\n\
3458 Return the signal that terminated the process that provided the 'status'\n\
3462 posix_WTERMSIG(PyObject
*self
, PyObject
*args
)
3465 WAIT_STATUS_INT(status
) = 0;
3467 if (!PyArg_ParseTuple(args
, "i:WTERMSIG", &WAIT_STATUS_INT(status
)))
3470 return Py_BuildValue("i", WTERMSIG(status
));
3472 #endif /* WTERMSIG */
3475 PyDoc_STRVAR(posix_WSTOPSIG__doc__
,
3476 "WSTOPSIG(status) -> integer\n\n\
3477 Return the signal that stopped the process that provided\n\
3478 the 'status' value.");
3481 posix_WSTOPSIG(PyObject
*self
, PyObject
*args
)
3484 WAIT_STATUS_INT(status
) = 0;
3486 if (!PyArg_ParseTuple(args
, "i:WSTOPSIG", &WAIT_STATUS_INT(status
)))
3489 return Py_BuildValue("i", WSTOPSIG(status
));
3491 #endif /* WSTOPSIG */
3493 #endif /* HAVE_SYS_WAIT_H */
3496 #if defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)
3497 #include <sys/statvfs.h>
3500 _pystatvfs_fromstructstatvfs(struct statvfs st
) {
3501 PyObject
*v
= PyStructSequence_New(&StatVFSResultType
);
3505 #if !defined(HAVE_LARGEFILE_SUPPORT)
3506 PyStructSequence_SET_ITEM(v
, 0, PyInt_FromLong((long) st
.f_bsize
));
3507 PyStructSequence_SET_ITEM(v
, 1, PyInt_FromLong((long) st
.f_frsize
));
3508 PyStructSequence_SET_ITEM(v
, 2, PyInt_FromLong((long) st
.f_blocks
));
3509 PyStructSequence_SET_ITEM(v
, 3, PyInt_FromLong((long) st
.f_bfree
));
3510 PyStructSequence_SET_ITEM(v
, 4, PyInt_FromLong((long) st
.f_bavail
));
3511 PyStructSequence_SET_ITEM(v
, 5, PyInt_FromLong((long) st
.f_files
));
3512 PyStructSequence_SET_ITEM(v
, 6, PyInt_FromLong((long) st
.f_ffree
));
3513 PyStructSequence_SET_ITEM(v
, 7, PyInt_FromLong((long) st
.f_favail
));
3514 PyStructSequence_SET_ITEM(v
, 8, PyInt_FromLong((long) st
.f_flag
));
3515 PyStructSequence_SET_ITEM(v
, 9, PyInt_FromLong((long) st
.f_namemax
));
3517 PyStructSequence_SET_ITEM(v
, 0, PyInt_FromLong((long) st
.f_bsize
));
3518 PyStructSequence_SET_ITEM(v
, 1, PyInt_FromLong((long) st
.f_frsize
));
3519 PyStructSequence_SET_ITEM(v
, 2,
3520 PyLong_FromLongLong((PY_LONG_LONG
) st
.f_blocks
));
3521 PyStructSequence_SET_ITEM(v
, 3,
3522 PyLong_FromLongLong((PY_LONG_LONG
) st
.f_bfree
));
3523 PyStructSequence_SET_ITEM(v
, 4,
3524 PyLong_FromLongLong((PY_LONG_LONG
) st
.f_bavail
));
3525 PyStructSequence_SET_ITEM(v
, 5,
3526 PyLong_FromLongLong((PY_LONG_LONG
) st
.f_files
));
3527 PyStructSequence_SET_ITEM(v
, 6,
3528 PyLong_FromLongLong((PY_LONG_LONG
) st
.f_ffree
));
3529 PyStructSequence_SET_ITEM(v
, 7,
3530 PyLong_FromLongLong((PY_LONG_LONG
) st
.f_favail
));
3531 PyStructSequence_SET_ITEM(v
, 8, PyInt_FromLong((long) st
.f_flag
));
3532 PyStructSequence_SET_ITEM(v
, 9, PyInt_FromLong((long) st
.f_namemax
));
3538 PyDoc_STRVAR(posix_fstatvfs__doc__
,
3539 "fstatvfs(fd) -> statvfs result\n\n\
3540 Perform an fstatvfs system call on the given fd.");
3543 posix_fstatvfs(PyObject
*self
, PyObject
*args
)
3548 if (!PyArg_ParseTuple(args
, "i:fstatvfs", &fd
))
3550 Py_BEGIN_ALLOW_THREADS
3551 res
= fstatvfs(fd
, &st
);
3552 Py_END_ALLOW_THREADS
3554 return posix_error();
3556 return _pystatvfs_fromstructstatvfs(st
);
3558 #endif /* HAVE_FSTATVFS && HAVE_SYS_STATVFS_H */
3561 #if defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)
3562 #include <sys/statvfs.h>
3564 PyDoc_STRVAR(posix_statvfs__doc__
,
3565 "statvfs(path) -> statvfs result\n\n\
3566 Perform a statvfs system call on the given path.");
3569 posix_statvfs(PyObject
*self
, PyObject
*args
)
3574 if (!PyArg_ParseTuple(args
, "s:statvfs", &path
))
3576 Py_BEGIN_ALLOW_THREADS
3577 res
= statvfs(path
, &st
);
3578 Py_END_ALLOW_THREADS
3580 return posix_error_with_filename(path
);
3582 return _pystatvfs_fromstructstatvfs(st
);
3584 #endif /* HAVE_STATVFS */
3588 PyDoc_STRVAR(posix_tempnam__doc__
,
3589 "tempnam([dir[, prefix]]) -> string\n\n\
3590 Return a unique name for a temporary file.\n\
3591 The directory and a prefix may be specified as strings; they may be omitted\n\
3592 or None if not needed.");
3595 posix_tempnam(PyObject
*self
, PyObject
*args
)
3597 PyObject
*result
= NULL
;
3602 if (!PyArg_ParseTuple(args
, "|zz:tempnam", &dir
, &pfx
))
3605 if (PyErr_Warn(PyExc_RuntimeWarning
,
3606 "tempnam is a potential security risk to your program") < 0)
3609 if (PyErr_WarnPy3k("tempnam has been removed in 3.x; "
3610 "use the tempfile module", 1) < 0)
3613 name
= tempnam(dir
, pfx
);
3615 return PyErr_NoMemory();
3616 result
= PyString_FromString(name
);
3624 PyDoc_STRVAR(posix_tmpfile__doc__
,
3625 "tmpfile() -> file object\n\n\
3626 Create a temporary file with no directory entries.");
3629 posix_tmpfile(PyObject
*self
, PyObject
*noargs
)
3633 if (PyErr_WarnPy3k("tmpfile has been removed in 3.x; "
3634 "use the tempfile module", 1) < 0)
3639 return posix_error();
3640 return PyFile_FromFile(fp
, "<tmpfile>", "w+b", fclose
);
3646 PyDoc_STRVAR(posix_tmpnam__doc__
,
3647 "tmpnam() -> string\n\n\
3648 Return a unique name for a temporary file.");
3651 posix_tmpnam(PyObject
*self
, PyObject
*noargs
)
3653 char buffer
[L_tmpnam
];
3656 if (PyErr_Warn(PyExc_RuntimeWarning
,
3657 "tmpnam is a potential security risk to your program") < 0)
3660 if (PyErr_WarnPy3k("tmpnam has been removed in 3.x; "
3661 "use the tempfile module", 1) < 0)
3665 name
= tmpnam_r(buffer
);
3667 name
= tmpnam(buffer
);
3670 PyObject
*err
= Py_BuildValue("is", 0,
3672 "unexpected NULL from tmpnam_r"
3674 "unexpected NULL from tmpnam"
3677 PyErr_SetObject(PyExc_OSError
, err
);
3681 return PyString_FromString(buffer
);
3685 PyDoc_STRVAR(posix_abort__doc__
,
3686 "abort() -> does not return!\n\n\
3687 Abort the interpreter immediately. This 'dumps core' or otherwise fails\n\
3688 in the hardest way possible on the hosting operating system.");
3691 posix_abort(PyObject
*self
, PyObject
*noargs
)
3695 Py_FatalError("abort() called from Python code didn't abort!");
3699 static PyMethodDef posix_methods
[] = {
3700 {"access", posix_access
, METH_VARARGS
, posix_access__doc__
},
3702 {"ttyname", posix_ttyname
, METH_VARARGS
, posix_ttyname__doc__
},
3704 {"chdir", posix_chdir
, METH_VARARGS
, posix_chdir__doc__
},
3706 {"chflags", posix_chflags
, METH_VARARGS
, posix_chflags__doc__
},
3707 #endif /* HAVE_CHFLAGS */
3708 {"chmod", posix_chmod
, METH_VARARGS
, posix_chmod__doc__
},
3710 {"fchmod", posix_fchmod
, METH_VARARGS
, posix_fchmod__doc__
},
3711 #endif /* HAVE_FCHMOD */
3713 {"chown", posix_chown
, METH_VARARGS
, posix_chown__doc__
},
3714 #endif /* HAVE_CHOWN */
3716 {"lchmod", posix_lchmod
, METH_VARARGS
, posix_lchmod__doc__
},
3717 #endif /* HAVE_LCHMOD */
3719 {"fchown", posix_fchown
, METH_VARARGS
, posix_fchown__doc__
},
3720 #endif /* HAVE_FCHOWN */
3721 #ifdef HAVE_LCHFLAGS
3722 {"lchflags", posix_lchflags
, METH_VARARGS
, posix_lchflags__doc__
},
3723 #endif /* HAVE_LCHFLAGS */
3725 {"lchown", posix_lchown
, METH_VARARGS
, posix_lchown__doc__
},
3726 #endif /* HAVE_LCHOWN */
3728 {"chroot", posix_chroot
, METH_VARARGS
, posix_chroot__doc__
},
3731 {"ctermid", posix_ctermid
, METH_NOARGS
, posix_ctermid__doc__
},
3734 {"getcwd", posix_getcwd
, METH_NOARGS
, posix_getcwd__doc__
},
3735 #ifdef Py_USING_UNICODE
3736 {"getcwdu", posix_getcwdu
, METH_NOARGS
, posix_getcwdu__doc__
},
3740 {"link", posix_link
, METH_VARARGS
, posix_link__doc__
},
3741 #endif /* HAVE_LINK */
3742 {"listdir", posix_listdir
, METH_VARARGS
, posix_listdir__doc__
},
3743 {"lstat", posix_lstat
, METH_VARARGS
, posix_lstat__doc__
},
3744 {"mkdir", posix_mkdir
, METH_VARARGS
, posix_mkdir__doc__
},
3746 {"nice", posix_nice
, METH_VARARGS
, posix_nice__doc__
},
3747 #endif /* HAVE_NICE */
3748 #ifdef HAVE_READLINK
3749 {"readlink", posix_readlink
, METH_VARARGS
, posix_readlink__doc__
},
3750 #endif /* HAVE_READLINK */
3751 {"rename", posix_rename
, METH_VARARGS
, posix_rename__doc__
},
3752 {"rmdir", posix_rmdir
, METH_VARARGS
, posix_rmdir__doc__
},
3753 {"stat", posix_stat
, METH_VARARGS
, posix_stat__doc__
},
3754 //{"stat_float_times", stat_float_times, METH_VARARGS, stat_float_times__doc__},
3756 {"symlink", posix_symlink
, METH_VARARGS
, posix_symlink__doc__
},
3757 #endif /* HAVE_SYMLINK */
3759 {"system", posix_system
, METH_VARARGS
, posix_system__doc__
},
3761 {"umask", posix_umask
, METH_VARARGS
, posix_umask__doc__
},
3763 {"uname", posix_uname
, METH_NOARGS
, posix_uname__doc__
},
3764 #endif /* HAVE_UNAME */
3765 {"unlink", posix_unlink
, METH_VARARGS
, posix_unlink__doc__
},
3766 {"remove", posix_unlink
, METH_VARARGS
, posix_remove__doc__
},
3767 {"utime", posix_utime
, METH_VARARGS
, posix_utime__doc__
},
3769 {"times", posix_times
, METH_NOARGS
, posix_times__doc__
},
3770 #endif /* HAVE_TIMES */
3771 {"_exit", posix__exit
, METH_VARARGS
, posix__exit__doc__
},
3773 {"execv", posix_execv
, METH_VARARGS
, posix_execv__doc__
},
3774 {"execve", posix_execve
, METH_VARARGS
, posix_execve__doc__
},
3775 #endif /* HAVE_EXECV */
3777 {"spawnv", posix_spawnv
, METH_VARARGS
, posix_spawnv__doc__
},
3778 {"spawnve", posix_spawnve
, METH_VARARGS
, posix_spawnve__doc__
},
3779 #if defined(PYOS_OS2)
3780 {"spawnvp", posix_spawnvp
, METH_VARARGS
, posix_spawnvp__doc__
},
3781 {"spawnvpe", posix_spawnvpe
, METH_VARARGS
, posix_spawnvpe__doc__
},
3782 #endif /* PYOS_OS2 */
3783 #endif /* HAVE_SPAWNV */
3785 {"fork1", posix_fork1
, METH_NOARGS
, posix_fork1__doc__
},
3786 #endif /* HAVE_FORK1 */
3788 {"fork", posix_fork
, METH_NOARGS
, posix_fork__doc__
},
3789 #endif /* HAVE_FORK */
3790 #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
3791 {"openpty", posix_openpty
, METH_NOARGS
, posix_openpty__doc__
},
3792 #endif /* HAVE_OPENPTY || HAVE__GETPTY || HAVE_DEV_PTMX */
3794 {"forkpty", posix_forkpty
, METH_NOARGS
, posix_forkpty__doc__
},
3795 #endif /* HAVE_FORKPTY */
3796 {"getpid", posix_getpid
, METH_NOARGS
, posix_getpid__doc__
},
3798 {"getpgrp", posix_getpgrp
, METH_NOARGS
, posix_getpgrp__doc__
},
3799 #endif /* HAVE_GETPGRP */
3801 {"getppid", posix_getppid
, METH_NOARGS
, posix_getppid__doc__
},
3802 #endif /* HAVE_GETPPID */
3803 #ifdef HAVE_GETLOGIN
3804 {"getlogin", posix_getlogin
, METH_NOARGS
, posix_getlogin__doc__
},
3807 {"kill", posix_kill
, METH_VARARGS
, posix_kill__doc__
},
3808 #endif /* HAVE_KILL */
3810 {"killpg", posix_killpg
, METH_VARARGS
, posix_killpg__doc__
},
3811 #endif /* HAVE_KILLPG */
3813 {"plock", posix_plock
, METH_VARARGS
, posix_plock__doc__
},
3814 #endif /* HAVE_PLOCK */
3816 {"popen", posix_popen
, METH_VARARGS
, posix_popen__doc__
},
3817 #endif /* HAVE_POPEN */
3818 #ifdef HAVE_SETGROUPS
3819 {"setgroups", posix_setgroups
, METH_O
, posix_setgroups__doc__
},
3820 #endif /* HAVE_SETGROUPS */
3821 #ifdef HAVE_INITGROUPS
3822 {"initgroups", posix_initgroups
, METH_VARARGS
, posix_initgroups__doc__
},
3823 #endif /* HAVE_INITGROUPS */
3825 {"getpgid", posix_getpgid
, METH_VARARGS
, posix_getpgid__doc__
},
3826 #endif /* HAVE_GETPGID */
3828 {"setpgrp", posix_setpgrp
, METH_NOARGS
, posix_setpgrp__doc__
},
3829 #endif /* HAVE_SETPGRP */
3831 {"wait", posix_wait
, METH_NOARGS
, posix_wait__doc__
},
3832 #endif /* HAVE_WAIT */
3834 {"wait3", posix_wait3
, METH_VARARGS
, posix_wait3__doc__
},
3835 #endif /* HAVE_WAIT3 */
3837 {"wait4", posix_wait4
, METH_VARARGS
, posix_wait4__doc__
},
3838 #endif /* HAVE_WAIT4 */
3839 #if defined(HAVE_WAITPID) || defined(HAVE_CWAIT)
3840 {"waitpid", posix_waitpid
, METH_VARARGS
, posix_waitpid__doc__
},
3841 #endif /* HAVE_WAITPID */
3843 {"getsid", posix_getsid
, METH_VARARGS
, posix_getsid__doc__
},
3844 #endif /* HAVE_GETSID */
3846 {"setsid", posix_setsid
, METH_NOARGS
, posix_setsid__doc__
},
3847 #endif /* HAVE_SETSID */
3849 {"setpgid", posix_setpgid
, METH_VARARGS
, posix_setpgid__doc__
},
3850 #endif /* HAVE_SETPGID */
3851 #ifdef HAVE_TCGETPGRP
3852 {"tcgetpgrp", posix_tcgetpgrp
, METH_VARARGS
, posix_tcgetpgrp__doc__
},
3853 #endif /* HAVE_TCGETPGRP */
3854 #ifdef HAVE_TCSETPGRP
3855 {"tcsetpgrp", posix_tcsetpgrp
, METH_VARARGS
, posix_tcsetpgrp__doc__
},
3856 #endif /* HAVE_TCSETPGRP */
3857 {"open", posix_open
, METH_VARARGS
, posix_open__doc__
},
3858 {"close", posix_close
, METH_VARARGS
, posix_close__doc__
},
3859 {"closerange", posix_closerange
, METH_VARARGS
, posix_closerange__doc__
},
3860 {"dup", posix_dup
, METH_VARARGS
, posix_dup__doc__
},
3861 {"dup2", posix_dup2
, METH_VARARGS
, posix_dup2__doc__
},
3862 {"lseek", posix_lseek
, METH_VARARGS
, posix_lseek__doc__
},
3863 {"read", posix_read
, METH_VARARGS
, posix_read__doc__
},
3864 {"write", posix_write
, METH_VARARGS
, posix_write__doc__
},
3865 {"fstat", posix_fstat
, METH_VARARGS
, posix_fstat__doc__
},
3866 {"fdopen", posix_fdopen
, METH_VARARGS
, posix_fdopen__doc__
},
3867 {"isatty", posix_isatty
, METH_VARARGS
, posix_isatty__doc__
},
3869 {"pipe", posix_pipe
, METH_NOARGS
, posix_pipe__doc__
},
3872 {"mkfifo", posix_mkfifo
, METH_VARARGS
, posix_mkfifo__doc__
},
3874 #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)
3875 {"mknod", posix_mknod
, METH_VARARGS
, posix_mknod__doc__
},
3877 #ifdef HAVE_DEVICE_MACROS
3878 {"major", posix_major
, METH_VARARGS
, posix_major__doc__
},
3879 {"minor", posix_minor
, METH_VARARGS
, posix_minor__doc__
},
3880 {"makedev", posix_makedev
, METH_VARARGS
, posix_makedev__doc__
},
3882 #ifdef HAVE_FTRUNCATE
3883 {"ftruncate", posix_ftruncate
, METH_VARARGS
, posix_ftruncate__doc__
},
3886 {"putenv", posix_putenv
, METH_VARARGS
, posix_putenv__doc__
},
3888 #ifdef HAVE_UNSETENV
3889 {"unsetenv", posix_unsetenv
, METH_VARARGS
, posix_unsetenv__doc__
},
3891 {"strerror", posix_strerror
, METH_VARARGS
, posix_strerror__doc__
},
3893 {"fchdir", posix_fchdir
, METH_O
, posix_fchdir__doc__
},
3896 {"fsync", posix_fsync
, METH_O
, posix_fsync__doc__
},
3898 #ifdef HAVE_FDATASYNC
3899 {"fdatasync", posix_fdatasync
, METH_O
, posix_fdatasync__doc__
},
3901 #ifdef HAVE_SYS_WAIT_H
3903 {"WCOREDUMP", posix_WCOREDUMP
, METH_VARARGS
, posix_WCOREDUMP__doc__
},
3904 #endif /* WCOREDUMP */
3906 {"WIFCONTINUED",posix_WIFCONTINUED
, METH_VARARGS
, posix_WIFCONTINUED__doc__
},
3907 #endif /* WIFCONTINUED */
3909 {"WIFSTOPPED", posix_WIFSTOPPED
, METH_VARARGS
, posix_WIFSTOPPED__doc__
},
3910 #endif /* WIFSTOPPED */
3912 {"WIFSIGNALED", posix_WIFSIGNALED
, METH_VARARGS
, posix_WIFSIGNALED__doc__
},
3913 #endif /* WIFSIGNALED */
3915 {"WIFEXITED", posix_WIFEXITED
, METH_VARARGS
, posix_WIFEXITED__doc__
},
3916 #endif /* WIFEXITED */
3918 {"WEXITSTATUS", posix_WEXITSTATUS
, METH_VARARGS
, posix_WEXITSTATUS__doc__
},
3919 #endif /* WEXITSTATUS */
3921 {"WTERMSIG", posix_WTERMSIG
, METH_VARARGS
, posix_WTERMSIG__doc__
},
3922 #endif /* WTERMSIG */
3924 {"WSTOPSIG", posix_WSTOPSIG
, METH_VARARGS
, posix_WSTOPSIG__doc__
},
3925 #endif /* WSTOPSIG */
3926 #endif /* HAVE_SYS_WAIT_H */
3927 #if defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)
3928 {"fstatvfs", posix_fstatvfs
, METH_VARARGS
, posix_fstatvfs__doc__
},
3930 #if defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)
3931 {"statvfs", posix_statvfs
, METH_VARARGS
, posix_statvfs__doc__
},
3934 {"tmpfile", posix_tmpfile
, METH_NOARGS
, posix_tmpfile__doc__
},
3937 {"tempnam", posix_tempnam
, METH_VARARGS
, posix_tempnam__doc__
},
3940 {"tmpnam", posix_tmpnam
, METH_NOARGS
, posix_tmpnam__doc__
},
3943 {"confstr", posix_confstr
, METH_VARARGS
, posix_confstr__doc__
},
3946 {"sysconf", posix_sysconf
, METH_VARARGS
, posix_sysconf__doc__
},
3948 #ifdef HAVE_FPATHCONF
3949 {"fpathconf", posix_fpathconf
, METH_VARARGS
, posix_fpathconf__doc__
},
3951 #ifdef HAVE_PATHCONF
3952 {"pathconf", posix_pathconf
, METH_VARARGS
, posix_pathconf__doc__
},
3954 {"abort", posix_abort
, METH_NOARGS
, posix_abort__doc__
},
3956 {NULL
, NULL
} /* Sentinel */
3961 ins(PyObject
*module
, char *symbol
, long value
)
3963 return PyModule_AddIntConstant(module
, symbol
, value
);
3967 all_ins(PyObject
*d
)
3970 if (ins(d
, "F_OK", (long)F_OK
)) return -1;
3973 if (ins(d
, "R_OK", (long)R_OK
)) return -1;
3976 if (ins(d
, "W_OK", (long)W_OK
)) return -1;
3979 if (ins(d
, "X_OK", (long)X_OK
)) return -1;
3982 if (ins(d
, "NGROUPS_MAX", (long)NGROUPS_MAX
)) return -1;
3985 if (ins(d
, "TMP_MAX", (long)TMP_MAX
)) return -1;
3988 if (ins(d
, "WCONTINUED", (long)WCONTINUED
)) return -1;
3991 if (ins(d
, "WNOHANG", (long)WNOHANG
)) return -1;
3994 if (ins(d
, "WUNTRACED", (long)WUNTRACED
)) return -1;
3997 if (ins(d
, "O_RDONLY", (long)O_RDONLY
)) return -1;
4000 if (ins(d
, "O_WRONLY", (long)O_WRONLY
)) return -1;
4003 if (ins(d
, "O_RDWR", (long)O_RDWR
)) return -1;
4006 if (ins(d
, "O_NDELAY", (long)O_NDELAY
)) return -1;
4009 if (ins(d
, "O_NONBLOCK", (long)O_NONBLOCK
)) return -1;
4012 if (ins(d
, "O_APPEND", (long)O_APPEND
)) return -1;
4015 if (ins(d
, "O_DSYNC", (long)O_DSYNC
)) return -1;
4018 if (ins(d
, "O_RSYNC", (long)O_RSYNC
)) return -1;
4021 if (ins(d
, "O_SYNC", (long)O_SYNC
)) return -1;
4024 if (ins(d
, "O_NOCTTY", (long)O_NOCTTY
)) return -1;
4027 if (ins(d
, "O_CREAT", (long)O_CREAT
)) return -1;
4030 if (ins(d
, "O_EXCL", (long)O_EXCL
)) return -1;
4033 if (ins(d
, "O_TRUNC", (long)O_TRUNC
)) return -1;
4036 if (ins(d
, "O_BINARY", (long)O_BINARY
)) return -1;
4039 if (ins(d
, "O_TEXT", (long)O_TEXT
)) return -1;
4042 if (ins(d
, "O_LARGEFILE", (long)O_LARGEFILE
)) return -1;
4045 if (ins(d
, "O_SHLOCK", (long)O_SHLOCK
)) return -1;
4048 if (ins(d
, "O_EXLOCK", (long)O_EXLOCK
)) return -1;
4053 /* Don't inherit in child processes. */
4054 if (ins(d
, "O_NOINHERIT", (long)O_NOINHERIT
)) return -1;
4056 #ifdef _O_SHORT_LIVED
4057 /* Optimize for short life (keep in memory). */
4058 /* MS forgot to define this one with a non-underscore form too. */
4059 if (ins(d
, "O_SHORT_LIVED", (long)_O_SHORT_LIVED
)) return -1;
4062 /* Automatically delete when last handle is closed. */
4063 if (ins(d
, "O_TEMPORARY", (long)O_TEMPORARY
)) return -1;
4066 /* Optimize for random access. */
4067 if (ins(d
, "O_RANDOM", (long)O_RANDOM
)) return -1;
4070 /* Optimize for sequential access. */
4071 if (ins(d
, "O_SEQUENTIAL", (long)O_SEQUENTIAL
)) return -1;
4074 /* GNU extensions. */
4076 /* Send a SIGIO signal whenever input or output
4077 becomes available on file descriptor */
4078 if (ins(d
, "O_ASYNC", (long)O_ASYNC
)) return -1;
4081 /* Direct disk access. */
4082 if (ins(d
, "O_DIRECT", (long)O_DIRECT
)) return -1;
4085 /* Must be a directory. */
4086 if (ins(d
, "O_DIRECTORY", (long)O_DIRECTORY
)) return -1;
4089 /* Do not follow links. */
4090 if (ins(d
, "O_NOFOLLOW", (long)O_NOFOLLOW
)) return -1;
4093 /* Do not update the access time. */
4094 if (ins(d
, "O_NOATIME", (long)O_NOATIME
)) return -1;
4097 /* These come from sysexits.h */
4099 if (ins(d
, "EX_OK", (long)EX_OK
)) return -1;
4102 if (ins(d
, "EX_USAGE", (long)EX_USAGE
)) return -1;
4103 #endif /* EX_USAGE */
4105 if (ins(d
, "EX_DATAERR", (long)EX_DATAERR
)) return -1;
4106 #endif /* EX_DATAERR */
4108 if (ins(d
, "EX_NOINPUT", (long)EX_NOINPUT
)) return -1;
4109 #endif /* EX_NOINPUT */
4111 if (ins(d
, "EX_NOUSER", (long)EX_NOUSER
)) return -1;
4112 #endif /* EX_NOUSER */
4114 if (ins(d
, "EX_NOHOST", (long)EX_NOHOST
)) return -1;
4115 #endif /* EX_NOHOST */
4116 #ifdef EX_UNAVAILABLE
4117 if (ins(d
, "EX_UNAVAILABLE", (long)EX_UNAVAILABLE
)) return -1;
4118 #endif /* EX_UNAVAILABLE */
4120 if (ins(d
, "EX_SOFTWARE", (long)EX_SOFTWARE
)) return -1;
4121 #endif /* EX_SOFTWARE */
4123 if (ins(d
, "EX_OSERR", (long)EX_OSERR
)) return -1;
4124 #endif /* EX_OSERR */
4126 if (ins(d
, "EX_OSFILE", (long)EX_OSFILE
)) return -1;
4127 #endif /* EX_OSFILE */
4129 if (ins(d
, "EX_CANTCREAT", (long)EX_CANTCREAT
)) return -1;
4130 #endif /* EX_CANTCREAT */
4132 if (ins(d
, "EX_IOERR", (long)EX_IOERR
)) return -1;
4133 #endif /* EX_IOERR */
4135 if (ins(d
, "EX_TEMPFAIL", (long)EX_TEMPFAIL
)) return -1;
4136 #endif /* EX_TEMPFAIL */
4138 if (ins(d
, "EX_PROTOCOL", (long)EX_PROTOCOL
)) return -1;
4139 #endif /* EX_PROTOCOL */
4141 if (ins(d
, "EX_NOPERM", (long)EX_NOPERM
)) return -1;
4142 #endif /* EX_NOPERM */
4144 if (ins(d
, "EX_CONFIG", (long)EX_CONFIG
)) return -1;
4145 #endif /* EX_CONFIG */
4147 if (ins(d
, "EX_NOTFOUND", (long)EX_NOTFOUND
)) return -1;
4148 #endif /* EX_NOTFOUND */
4151 if (ins(d
, "P_WAIT", (long)_P_WAIT
)) return -1;
4152 if (ins(d
, "P_NOWAIT", (long)_P_NOWAIT
)) return -1;
4153 if (ins(d
, "P_OVERLAY", (long)_OLD_P_OVERLAY
)) return -1;
4154 if (ins(d
, "P_NOWAITO", (long)_P_NOWAITO
)) return -1;
4155 if (ins(d
, "P_DETACH", (long)_P_DETACH
)) return -1;
4160 #define INITFUNC initedk2
4161 #define MODNAME "edk2"
4168 #ifndef UEFI_C_SOURCE
4172 m
= Py_InitModule3(MODNAME
,
4178 #ifndef UEFI_C_SOURCE
4179 /* Initialize environ dictionary */
4180 v
= convertenviron();
4182 if (v
== NULL
|| PyModule_AddObject(m
, "environ", v
) != 0)
4185 #endif /* UEFI_C_SOURCE */
4190 if (setup_confname_tables(m
))
4193 Py_INCREF(PyExc_OSError
);
4194 PyModule_AddObject(m
, "error", PyExc_OSError
);
4197 if (posix_putenv_garbage
== NULL
)
4198 posix_putenv_garbage
= PyDict_New();
4202 stat_result_desc
.name
= MODNAME
".stat_result";
4203 stat_result_desc
.fields
[2].name
= PyStructSequence_UnnamedField
;
4204 stat_result_desc
.fields
[3].name
= PyStructSequence_UnnamedField
;
4205 stat_result_desc
.fields
[4].name
= PyStructSequence_UnnamedField
;
4206 PyStructSequence_InitType(&StatResultType
, &stat_result_desc
);
4207 structseq_new
= StatResultType
.tp_new
;
4208 StatResultType
.tp_new
= statresult_new
;
4210 //statvfs_result_desc.name = MODNAME ".statvfs_result";
4211 //PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);
4212 #ifdef NEED_TICKS_PER_SECOND
4213 # if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
4214 ticks_per_second
= sysconf(_SC_CLK_TCK
);
4216 ticks_per_second
= HZ
;
4218 ticks_per_second
= 60; /* magic fallback value; may be bogus */
4222 Py_INCREF((PyObject
*) &StatResultType
);
4223 PyModule_AddObject(m
, "stat_result", (PyObject
*) &StatResultType
);
4224 //Py_INCREF((PyObject*) &StatVFSResultType);
4225 //PyModule_AddObject(m, "statvfs_result",
4226 // (PyObject*) &StatVFSResultType);