Back to index

python3.2  3.2.2
Classes | Defines | Functions | Variables
posixmodule.c File Reference
#include "Python.h"

Go to the source code of this file.

Classes

struct  constdef

Defines

#define PY_SSIZE_T_CLEAN
#define HAVE_EXECV   1
#define HAVE_FORK   1
#define HAVE_GETCWD   1
#define HAVE_GETEGID   1
#define HAVE_GETEUID   1
#define HAVE_GETGID   1
#define HAVE_GETPPID   1
#define HAVE_GETUID   1
#define HAVE_KILL   1
#define HAVE_OPENDIR   1
#define HAVE_PIPE   1
#define HAVE_SYSTEM   1
#define HAVE_WAIT   1
#define HAVE_TTYNAME   1
#define dirent   direct
#define NAMLEN(dirent)   (dirent)->d_namlen
#define MAXPATHLEN   1024
#define WAIT_TYPE   int
#define WAIT_STATUS_INT(s)   (s)
#define STAT   stat
#define FSTAT   fstat
#define STRUCT_STAT   struct stat
#define _PyVerify_fd_dup2(A, B)   (1)
#define ST_BLKSIZE_IDX   12
#define ST_BLOCKS_IDX   ST_BLKSIZE_IDX
#define ST_RDEV_IDX   ST_BLOCKS_IDX
#define ST_FLAGS_IDX   ST_RDEV_IDX
#define ST_GEN_IDX   ST_FLAGS_IDX
#define ST_BIRTHTIME_IDX   ST_GEN_IDX
#define F_OK   0
#define R_OK   4
#define W_OK   2
#define X_OK   1
#define ATIME   buf[0]
#define MTIME   buf[1]
#define UTIME_ARG   buf
#define DEV_PTY_FILE   "/dev/ptmx"
#define INITFUNC   PyInit_posix
#define MODNAME   "posix"

Functions

 PyDoc_STRVAR (posix__doc__,"This module provides access to operating system functionality that is\n\ standardized by the C Standard and the POSIX standard (a thinly\n\ disguised Unix interface). Refer to the library manual and\n\ corresponding Unix manual entries for more information on calls.")
int mkdir (const char *, mode_t)
int chdir (const char *)
int rmdir (const char *)
int chmod (const char *, mode_t)
int chown (const char *, uid_t, gid_t)
char * getcwd (char *, int)
char * strerror (int)
int link (const char *, const char *)
int rename (const char *, const char *)
int stat (const char *, struct stat *)
int unlink (const char *)
static PyObjectconvertenviron (void)
static PyObjectposix_error (void)
static PyObjectposix_error_with_filename (char *name)
static PyObjectposix_error_with_allocated_filename (PyObject *name)
static PyObjectposix_fildes (PyObject *fdobj, int(*func)(int))
static PyObjectposix_1str (PyObject *args, char *format, int(*func)(const char *))
static PyObjectposix_2str (PyObject *args, char *format, int(*func)(const char *, const char *))
 PyDoc_STRVAR (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\ Posix/windows: If your platform supports st_blksize, st_blocks, st_rdev,\n\ or st_flags, they are available as attributes only.\n\ \n\ See os.stat for more information.")
 PyDoc_STRVAR (statvfs_result__doc__,"statvfs_result: Result from statvfs or fstatvfs.\n\n\ This object may be accessed either as a tuple of\n\ (bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax),\n\ or via the attributes f_bsize, f_frsize, f_blocks, f_bfree, and so on.\n\ \n\ See os.statvfs for more information.")
static PyObjectstatresult_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR (stat_float_times__doc__,"stat_float_times([newval]) -> oldval\n\n\ Determine whether os.[lf]stat represents time stamps as float objects.\n\ If newval is True, future calls to stat() return floats, if it is False,\n\ future calls return ints. \n\ If newval is omitted, return the current setting.\n")
static PyObjectstat_float_times (PyObject *self, PyObject *args)
static void fill_time (PyObject *v, int index, time_t sec, unsigned long nsec)
static PyObject_pystat_fromstructstat (STRUCT_STAT *st)
static PyObjectposix_do_stat (PyObject *self, PyObject *args, char *format, int(*statfunc)(const char *, STRUCT_STAT *), char *wformat, int(*wstatfunc)(const Py_UNICODE *, STRUCT_STAT *))
 PyDoc_STRVAR (posix_access__doc__,"access(path, mode) -> True if granted, False otherwise\n\n\ Use the real uid/gid to test for access to a path. Note that most\n\ operations will use the effective uid/gid, therefore this routine can\n\ be used in a suid/sgid environment to test if the invoking user has the\n\ specified access to the path. The mode argument can be F_OK to test\n\ existence, or the inclusive-OR of R_OK, W_OK, and X_OK.")
static PyObjectposix_access (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_ttyname__doc__,"ttyname(fd) -> string\n\n\ Return the name of the terminal device connected to 'fd'.")
static PyObjectposix_ttyname (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_chdir__doc__,"chdir(path)\n\n\ Change the current working directory to the specified path.")
static PyObjectposix_chdir (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_chmod__doc__,"chmod(path, mode)\n\n\ Change the access permissions of a file.")
static PyObjectposix_chmod (PyObject *self, PyObject *args)
static PyObjectposix_getcwd (int use_bytes)
 PyDoc_STRVAR (posix_getcwd__doc__,"getcwd() -> path\n\n\ Return a unicode string representing the current working directory.")
static PyObjectposix_getcwd_unicode (PyObject *self)
 PyDoc_STRVAR (posix_getcwdb__doc__,"getcwdb() -> path\n\n\ Return a bytes string representing the current working directory.")
static PyObjectposix_getcwd_bytes (PyObject *self)
 PyDoc_STRVAR (posix_listdir__doc__,"listdir([path]) -> list_of_strings\n\n\ Return a list containing the names of the entries in the directory.\n\ \n\ path: path of directory to list (default: '.')\n\ \n\ The list is in arbitrary order. It does not include the special\n\ entries '.' and '..' even if they are present in the directory.")
static PyObjectposix_listdir (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_mkdir__doc__,"mkdir(path [, mode=0777])\n\n\ Create a directory.")
static PyObjectposix_mkdir (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_rename__doc__,"rename(old, new)\n\n\ Rename a file or directory.")
static PyObjectposix_rename (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_rmdir__doc__,"rmdir(path)\n\n\ Remove a directory.")
static PyObjectposix_rmdir (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_stat__doc__,"stat(path) -> stat result\n\n\ Perform a stat system call on the given path.")
static PyObjectposix_stat (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_system__doc__,"system(command) -> exit_status\n\n\ Execute the command (a string) in a subshell.")
static PyObjectposix_system (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_umask__doc__,"umask(new_mask) -> old_mask\n\n\ Set the current numeric umask and return the previous umask.")
static PyObjectposix_umask (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_unlink__doc__,"unlink(path)\n\n\ Remove a file (same as remove(path)).")
 PyDoc_STRVAR (posix_remove__doc__,"remove(path)\n\n\ Remove a file (same as unlink(path)).")
static PyObjectposix_unlink (PyObject *self, PyObject *args)
static int extract_time (PyObject *t, time_t *sec, long *usec)
 PyDoc_STRVAR (posix_utime__doc__,"utime(path, (atime, mtime))\n\ utime(path, None)\n\n\ Set the access and modified time of the file to the given values. If the\n\ second form is used, set the access and modified times to the current time.")
static PyObjectposix_utime (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix__exit__doc__,"_exit(status)\n\n\ Exit to the system with specified status, without normal exit processing.")
static PyObjectposix__exit (PyObject *self, PyObject *args)
static void free_string_array (char **array, Py_ssize_t count)
static int fsconvert_strdup (PyObject *o, char **out)
 PyDoc_STRVAR (posix_execv__doc__,"execv(path, args)\n\n\ Execute an executable path with arguments, replacing current process.\n\ \n\ path: path of executable file\n\ args: tuple or list of strings")
static PyObjectposix_execv (PyObject *self, PyObject *args)
static char ** parse_envlist (PyObject *env, Py_ssize_t *envc_ptr)
 PyDoc_STRVAR (posix_execve__doc__,"execve(path, args, env)\n\n\ Execute a path with arguments and environment, replacing current process.\n\ \n\ path: path of executable file\n\ args: tuple or list of arguments\n\ env: dictionary of strings mapping to strings")
static PyObjectposix_execve (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_fork__doc__,"fork() -> pid\n\n\ Fork a child process.\n\ Return 0 to child process and PID of child to parent process.")
static PyObjectposix_fork (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (posix_getegid__doc__,"getegid() -> egid\n\n\ Return the current process's effective group id.")
static PyObjectposix_getegid (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (posix_geteuid__doc__,"geteuid() -> euid\n\n\ Return the current process's effective user id.")
static PyObjectposix_geteuid (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (posix_getgid__doc__,"getgid() -> gid\n\n\ Return the current process's group id.")
static PyObjectposix_getgid (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (posix_getpid__doc__,"getpid() -> pid\n\n\ Return the current process id")
static PyObjectposix_getpid (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (posix_getppid__doc__,"getppid() -> ppid\n\n\ Return the parent's process id. If the parent process has already exited,\n\ Windows machines will still return its id; others systems will return the id\n\ of the 'init' process (1).")
static PyObjectposix_getppid (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (posix_getuid__doc__,"getuid() -> uid\n\n\ Return the current process's user id.")
static PyObjectposix_getuid (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (posix_kill__doc__,"kill(pid, sig)\n\n\ Kill a process with a signal.")
static PyObjectposix_kill (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_wait__doc__,"wait() -> (pid, status)\n\n\ Wait for completion of a child process.")
static PyObjectposix_wait (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (posix_lstat__doc__,"lstat(path) -> stat result\n\n\ Like stat(path), but do not follow symbolic links.")
static PyObjectposix_lstat (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_open__doc__,"open(filename, flag [, mode=0777]) -> fd\n\n\ Open a file (for low level IO).")
static PyObjectposix_open (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_close__doc__,"close(fd)\n\n\ Close a file descriptor (for low level IO).")
static PyObjectposix_close (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_closerange__doc__,"closerange(fd_low, fd_high)\n\n\ Closes all file descriptors in [fd_low, fd_high), ignoring errors.")
static PyObjectposix_closerange (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_dup__doc__,"dup(fd) -> fd2\n\n\ Return a duplicate of a file descriptor.")
static PyObjectposix_dup (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_dup2__doc__,"dup2(old_fd, new_fd)\n\n\ Duplicate file descriptor.")
static PyObjectposix_dup2 (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_lseek__doc__,"lseek(fd, pos, how) -> newpos\n\n\ Set the current position of a file descriptor.")
static PyObjectposix_lseek (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_read__doc__,"read(fd, buffersize) -> string\n\n\ Read a file descriptor.")
static PyObjectposix_read (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_write__doc__,"write(fd, string) -> byteswritten\n\n\ Write a string to a file descriptor.")
static PyObjectposix_write (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_fstat__doc__,"fstat(fd) -> stat result\n\n\ Like stat(), but for an open file descriptor.")
static PyObjectposix_fstat (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_isatty__doc__,"isatty(fd) -> bool\n\n\ Return True if the file descriptor 'fd' is an open file descriptor\n\ connected to the slave end of a terminal.")
static PyObjectposix_isatty (PyObject *self, PyObject *args)
 PyDoc_STRVAR (posix_pipe__doc__,"pipe() -> (read_end, write_end)\n\n\ Create a pipe.")
static PyObjectposix_pipe (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (posix_strerror__doc__,"strerror(code) -> string\n\n\ Translate an error code to a message string.")
static PyObjectposix_strerror (PyObject *self, PyObject *args)
static int conv_confname (PyObject *arg, int *valuep, struct constdef *table, size_t tablesize)
static int cmp_constdefs (const void *v1, const void *v2)
static int setup_confname_table (struct constdef *table, size_t tablesize, char *tablename, PyObject *module)
static int setup_confname_tables (PyObject *module)
 PyDoc_STRVAR (posix_abort__doc__,"abort() -> does not return!\n\n\ Abort the interpreter immediately. This 'dumps core' or otherwise fails\n\ in the hardest way possible on the hosting operating system.")
static PyObjectposix_abort (PyObject *self, PyObject *noargs)
 PyDoc_STRVAR (device_encoding__doc__,"device_encoding(fd) -> str\n\n\ Return a string describing the encoding of the device\n\ if the output is a terminal; else return None.")
static PyObjectdevice_encoding (PyObject *self, PyObject *args)
static int ins (PyObject *module, char *symbol, long value)
static int all_ins (PyObject *d)
PyMODINIT_FUNC INITFUNC (void)

Variables

char ** environ
static PyStructSequence_Field stat_result_fields []
static PyStructSequence_Desc stat_result_desc
static PyStructSequence_Field statvfs_result_fields []
static PyStructSequence_Desc statvfs_result_desc
static int initialized
static PyTypeObject StatResultType
static PyTypeObject StatVFSResultType
static newfunc structseq_new
static int _stat_float_times = 1
static PyMethodDef posix_methods []
static struct PyModuleDef

Class Documentation

struct constdef

Definition at line 6500 of file posixmodule.c.

Class Members
char * name
long value

Define Documentation

#define _PyVerify_fd_dup2 (   A,
  B 
)    (1)

Definition at line 440 of file posixmodule.c.

#define ATIME   buf[0]
#define DEV_PTY_FILE   "/dev/ptmx"

Definition at line 4162 of file posixmodule.c.

#define dirent   direct

Definition at line 240 of file posixmodule.c.

#define F_OK   0

Definition at line 1844 of file posixmodule.c.

#define FSTAT   fstat

Definition at line 335 of file posixmodule.c.

#define HAVE_EXECV   1

Definition at line 135 of file posixmodule.c.

#define HAVE_FORK   1

Definition at line 136 of file posixmodule.c.

#define HAVE_GETCWD   1

Definition at line 140 of file posixmodule.c.

#define HAVE_GETEGID   1

Definition at line 141 of file posixmodule.c.

#define HAVE_GETEUID   1

Definition at line 142 of file posixmodule.c.

#define HAVE_GETGID   1

Definition at line 143 of file posixmodule.c.

#define HAVE_GETPPID   1

Definition at line 144 of file posixmodule.c.

#define HAVE_GETUID   1

Definition at line 145 of file posixmodule.c.

#define HAVE_KILL   1

Definition at line 146 of file posixmodule.c.

#define HAVE_OPENDIR   1

Definition at line 147 of file posixmodule.c.

#define HAVE_PIPE   1

Definition at line 148 of file posixmodule.c.

#define HAVE_SYSTEM   1

Definition at line 149 of file posixmodule.c.

#define HAVE_TTYNAME   1

Definition at line 151 of file posixmodule.c.

#define HAVE_WAIT   1

Definition at line 150 of file posixmodule.c.

#define INITFUNC   PyInit_posix

Definition at line 8498 of file posixmodule.c.

#define MAXPATHLEN   1024

Definition at line 292 of file posixmodule.c.

#define MODNAME   "posix"

Definition at line 8499 of file posixmodule.c.

#define MTIME   buf[1]
#define NAMLEN (   dirent)    (dirent)->d_namlen

Definition at line 241 of file posixmodule.c.

Definition at line 26 of file posixmodule.c.

#define R_OK   4

Definition at line 1847 of file posixmodule.c.

Definition at line 1508 of file posixmodule.c.

#define ST_BLKSIZE_IDX   12

Definition at line 1478 of file posixmodule.c.

Definition at line 1484 of file posixmodule.c.

#define ST_FLAGS_IDX   ST_RDEV_IDX

Definition at line 1496 of file posixmodule.c.

#define ST_GEN_IDX   ST_FLAGS_IDX

Definition at line 1502 of file posixmodule.c.

#define ST_RDEV_IDX   ST_BLOCKS_IDX

Definition at line 1490 of file posixmodule.c.

#define STAT   stat

Definition at line 334 of file posixmodule.c.

#define STRUCT_STAT   struct stat

Definition at line 336 of file posixmodule.c.

#define UTIME_ARG   buf
#define W_OK   2

Definition at line 1850 of file posixmodule.c.

#define WAIT_STATUS_INT (   s)    (s)

Definition at line 316 of file posixmodule.c.

#define WAIT_TYPE   int

Definition at line 315 of file posixmodule.c.

#define X_OK   1

Definition at line 1853 of file posixmodule.c.


Function Documentation

static PyObject* _pystat_fromstructstat ( STRUCT_STAT st) [static]

Definition at line 1624 of file posixmodule.c.

{
    unsigned long ansec, mnsec, cnsec;
    PyObject *v = PyStructSequence_New(&StatResultType);
    if (v == NULL)
        return NULL;

    PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long)st->st_mode));
#ifdef HAVE_LARGEFILE_SUPPORT
    PyStructSequence_SET_ITEM(v, 1,
                              PyLong_FromLongLong((PY_LONG_LONG)st->st_ino));
#else
    PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long)st->st_ino));
#endif
#if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS)
    PyStructSequence_SET_ITEM(v, 2,
                              PyLong_FromLongLong((PY_LONG_LONG)st->st_dev));
#else
    PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long)st->st_dev));
#endif
    PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long)st->st_nlink));
    PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong((long)st->st_uid));
    PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong((long)st->st_gid));
#ifdef HAVE_LARGEFILE_SUPPORT
    PyStructSequence_SET_ITEM(v, 6,
                              PyLong_FromLongLong((PY_LONG_LONG)st->st_size));
#else
    PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong(st->st_size));
#endif

#if defined(HAVE_STAT_TV_NSEC)
    ansec = st->st_atim.tv_nsec;
    mnsec = st->st_mtim.tv_nsec;
    cnsec = st->st_ctim.tv_nsec;
#elif defined(HAVE_STAT_TV_NSEC2)
    ansec = st->st_atimespec.tv_nsec;
    mnsec = st->st_mtimespec.tv_nsec;
    cnsec = st->st_ctimespec.tv_nsec;
#elif defined(HAVE_STAT_NSEC)
    ansec = st->st_atime_nsec;
    mnsec = st->st_mtime_nsec;
    cnsec = st->st_ctime_nsec;
#else
    ansec = mnsec = cnsec = 0;
#endif
    fill_time(v, 7, st->st_atime, ansec);
    fill_time(v, 8, st->st_mtime, mnsec);
    fill_time(v, 9, st->st_ctime, cnsec);

#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
    PyStructSequence_SET_ITEM(v, ST_BLKSIZE_IDX,
                              PyLong_FromLong((long)st->st_blksize));
#endif
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
    PyStructSequence_SET_ITEM(v, ST_BLOCKS_IDX,
                              PyLong_FromLong((long)st->st_blocks));
#endif
#ifdef HAVE_STRUCT_STAT_ST_RDEV
    PyStructSequence_SET_ITEM(v, ST_RDEV_IDX,
                              PyLong_FromLong((long)st->st_rdev));
#endif
#ifdef HAVE_STRUCT_STAT_ST_GEN
    PyStructSequence_SET_ITEM(v, ST_GEN_IDX,
                              PyLong_FromLong((long)st->st_gen));
#endif
#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME
    {
      PyObject *val;
      unsigned long bsec,bnsec;
      bsec = (long)st->st_birthtime;
#ifdef HAVE_STAT_TV_NSEC2
      bnsec = st->st_birthtimespec.tv_nsec;
#else
      bnsec = 0;
#endif
      if (_stat_float_times) {
        val = PyFloat_FromDouble(bsec + 1e-9*bnsec);
      } else {
        val = PyLong_FromLong((long)bsec);
      }
      PyStructSequence_SET_ITEM(v, ST_BIRTHTIME_IDX,
                                val);
    }
#endif
#ifdef HAVE_STRUCT_STAT_ST_FLAGS
    PyStructSequence_SET_ITEM(v, ST_FLAGS_IDX,
                              PyLong_FromLong((long)st->st_flags));
#endif

    if (PyErr_Occurred()) {
        Py_DECREF(v);
        return NULL;
    }

    return v;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int all_ins ( PyObject d) [static]

Definition at line 8260 of file posixmodule.c.

{
#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 WCONTINUED
    if (ins(d, "WCONTINUED", (long)WCONTINUED)) return -1;
#endif
#ifdef WNOHANG
    if (ins(d, "WNOHANG", (long)WNOHANG)) return -1;
#endif
#ifdef WUNTRACED
    if (ins(d, "WUNTRACED", (long)WUNTRACED)) 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 O_LARGEFILE
    if (ins(d, "O_LARGEFILE", (long)O_LARGEFILE)) return -1;
#endif
#ifdef O_SHLOCK
    if (ins(d, "O_SHLOCK", (long)O_SHLOCK)) return -1;
#endif
#ifdef O_EXLOCK
    if (ins(d, "O_EXLOCK", (long)O_EXLOCK)) return -1;
#endif

/* MS Windows */
#ifdef O_NOINHERIT
    /* Don't inherit in child processes. */
    if (ins(d, "O_NOINHERIT", (long)O_NOINHERIT)) return -1;
#endif
#ifdef _O_SHORT_LIVED
    /* Optimize for short life (keep in memory). */
    /* MS forgot to define this one with a non-underscore form too. */
    if (ins(d, "O_SHORT_LIVED", (long)_O_SHORT_LIVED)) return -1;
#endif
#ifdef O_TEMPORARY
    /* Automatically delete when last handle is closed. */
    if (ins(d, "O_TEMPORARY", (long)O_TEMPORARY)) return -1;
#endif
#ifdef O_RANDOM
    /* Optimize for random access. */
    if (ins(d, "O_RANDOM", (long)O_RANDOM)) return -1;
#endif
#ifdef O_SEQUENTIAL
    /* Optimize for sequential access. */
    if (ins(d, "O_SEQUENTIAL", (long)O_SEQUENTIAL)) return -1;
#endif

/* GNU extensions. */
#ifdef O_ASYNC
    /* Send a SIGIO signal whenever input or output
       becomes available on file descriptor */
    if (ins(d, "O_ASYNC", (long)O_ASYNC)) return -1;
#endif
#ifdef O_DIRECT
    /* Direct disk access. */
    if (ins(d, "O_DIRECT", (long)O_DIRECT)) return -1;
#endif
#ifdef O_DIRECTORY
    /* Must be a directory.      */
    if (ins(d, "O_DIRECTORY", (long)O_DIRECTORY)) return -1;
#endif
#ifdef O_NOFOLLOW
    /* Do not follow links.      */
    if (ins(d, "O_NOFOLLOW", (long)O_NOFOLLOW)) return -1;
#endif
#ifdef O_NOATIME
    /* Do not update the access time. */
    if (ins(d, "O_NOATIME", (long)O_NOATIME)) return -1;
#endif

    /* These come from sysexits.h */
#ifdef EX_OK
    if (ins(d, "EX_OK", (long)EX_OK)) return -1;
#endif /* EX_OK */
#ifdef EX_USAGE
    if (ins(d, "EX_USAGE", (long)EX_USAGE)) return -1;
#endif /* EX_USAGE */
#ifdef EX_DATAERR
    if (ins(d, "EX_DATAERR", (long)EX_DATAERR)) return -1;
#endif /* EX_DATAERR */
#ifdef EX_NOINPUT
    if (ins(d, "EX_NOINPUT", (long)EX_NOINPUT)) return -1;
#endif /* EX_NOINPUT */
#ifdef EX_NOUSER
    if (ins(d, "EX_NOUSER", (long)EX_NOUSER)) return -1;
#endif /* EX_NOUSER */
#ifdef EX_NOHOST
    if (ins(d, "EX_NOHOST", (long)EX_NOHOST)) return -1;
#endif /* EX_NOHOST */
#ifdef EX_UNAVAILABLE
    if (ins(d, "EX_UNAVAILABLE", (long)EX_UNAVAILABLE)) return -1;
#endif /* EX_UNAVAILABLE */
#ifdef EX_SOFTWARE
    if (ins(d, "EX_SOFTWARE", (long)EX_SOFTWARE)) return -1;
#endif /* EX_SOFTWARE */
#ifdef EX_OSERR
    if (ins(d, "EX_OSERR", (long)EX_OSERR)) return -1;
#endif /* EX_OSERR */
#ifdef EX_OSFILE
    if (ins(d, "EX_OSFILE", (long)EX_OSFILE)) return -1;
#endif /* EX_OSFILE */
#ifdef EX_CANTCREAT
    if (ins(d, "EX_CANTCREAT", (long)EX_CANTCREAT)) return -1;
#endif /* EX_CANTCREAT */
#ifdef EX_IOERR
    if (ins(d, "EX_IOERR", (long)EX_IOERR)) return -1;
#endif /* EX_IOERR */
#ifdef EX_TEMPFAIL
    if (ins(d, "EX_TEMPFAIL", (long)EX_TEMPFAIL)) return -1;
#endif /* EX_TEMPFAIL */
#ifdef EX_PROTOCOL
    if (ins(d, "EX_PROTOCOL", (long)EX_PROTOCOL)) return -1;
#endif /* EX_PROTOCOL */
#ifdef EX_NOPERM
    if (ins(d, "EX_NOPERM", (long)EX_NOPERM)) return -1;
#endif /* EX_NOPERM */
#ifdef EX_CONFIG
    if (ins(d, "EX_CONFIG", (long)EX_CONFIG)) return -1;
#endif /* EX_CONFIG */
#ifdef EX_NOTFOUND
    if (ins(d, "EX_NOTFOUND", (long)EX_NOTFOUND)) return -1;
#endif /* EX_NOTFOUND */

    /* statvfs */
#ifdef ST_RDONLY
    if (ins(d, "ST_RDONLY", (long)ST_RDONLY)) return -1;
#endif /* ST_RDONLY */
#ifdef ST_NOSUID
    if (ins(d, "ST_NOSUID", (long)ST_NOSUID)) return -1;
#endif /* ST_NOSUID */

#ifdef HAVE_SPAWNV
#if defined(PYOS_OS2) && defined(PYCC_GCC)
    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)P_OVERLAY)) return -1;
    if (ins(d, "P_DEBUG", (long)P_DEBUG)) return -1;
    if (ins(d, "P_SESSION", (long)P_SESSION)) return -1;
    if (ins(d, "P_DETACH", (long)P_DETACH)) return -1;
    if (ins(d, "P_PM", (long)P_PM)) return -1;
    if (ins(d, "P_DEFAULT", (long)P_DEFAULT)) return -1;
    if (ins(d, "P_MINIMIZE", (long)P_MINIMIZE)) return -1;
    if (ins(d, "P_MAXIMIZE", (long)P_MAXIMIZE)) return -1;
    if (ins(d, "P_FULLSCREEN", (long)P_FULLSCREEN)) return -1;
    if (ins(d, "P_WINDOWED", (long)P_WINDOWED)) return -1;
    if (ins(d, "P_FOREGROUND", (long)P_FOREGROUND)) return -1;
    if (ins(d, "P_BACKGROUND", (long)P_BACKGROUND)) return -1;
    if (ins(d, "P_NOCLOSE", (long)P_NOCLOSE)) return -1;
    if (ins(d, "P_NOSESSION", (long)P_NOSESSION)) return -1;
    if (ins(d, "P_QUOTE", (long)P_QUOTE)) return -1;
    if (ins(d, "P_TILDE", (long)P_TILDE)) return -1;
    if (ins(d, "P_UNRELATED", (long)P_UNRELATED)) return -1;
    if (ins(d, "P_DEBUGDESC", (long)P_DEBUGDESC)) return -1;
#else
    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
#endif

#if defined(PYOS_OS2)
    if (insertvalues(d)) return -1;
#endif
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int chdir ( const char *  )

Here is the caller graph for this function:

int chmod ( const char *  ,
mode_t   
)

Here is the caller graph for this function:

int chown ( const char *  ,
uid_t  ,
gid_t   
)
static int cmp_constdefs ( const void v1,
const void v2 
) [static]

Definition at line 7448 of file posixmodule.c.

{
    const struct constdef *c1 =
    (const struct constdef *) v1;
    const struct constdef *c2 =
    (const struct constdef *) v2;

    return strcmp(c1->name, c2->name);
}

Here is the caller graph for this function:

static int conv_confname ( PyObject arg,
int valuep,
struct constdef table,
size_t  tablesize 
) [static]

Definition at line 6506 of file posixmodule.c.

{
    if (PyLong_Check(arg)) {
        *valuep = PyLong_AS_LONG(arg);
        return 1;
    }
    else {
        /* look up the value in the table using a binary search */
        size_t lo = 0;
        size_t mid;
        size_t hi = tablesize;
        int cmp;
        const char *confname;
        if (!PyUnicode_Check(arg)) {
            PyErr_SetString(PyExc_TypeError,
                "configuration names must be strings or integers");
            return 0;
        }
        confname = _PyUnicode_AsString(arg);
        if (confname == NULL)
            return 0;
        while (lo < hi) {
            mid = (lo + hi) / 2;
            cmp = strcmp(confname, table[mid].name);
            if (cmp < 0)
                hi = mid;
            else if (cmp > 0)
                lo = mid + 1;
            else {
                *valuep = table[mid].value;
                return 1;
            }
        }
        PyErr_SetString(PyExc_ValueError, "unrecognized configuration name");
        return 0;
    }
}

Here is the call graph for this function:

static PyObject* convertenviron ( void  ) [static]

Definition at line 515 of file posixmodule.c.

{
    PyObject *d;
#ifdef MS_WINDOWS
    wchar_t **e;
#else
    char **e;
#endif
#if defined(PYOS_OS2)
    APIRET rc;
    char   buffer[1024]; /* OS/2 Provides a Documented Max of 1024 Chars */
#endif

    d = PyDict_New();
    if (d == NULL)
        return NULL;
#ifdef WITH_NEXT_FRAMEWORK
    if (environ == NULL)
        environ = *_NSGetEnviron();
#endif
#ifdef MS_WINDOWS
    /* _wenviron must be initialized in this way if the program is started
       through main() instead of wmain(). */
    _wgetenv(L"");
    if (_wenviron == NULL)
        return d;
    /* This part ignores errors */
    for (e = _wenviron; *e != NULL; e++) {
        PyObject *k;
        PyObject *v;
        wchar_t *p = wcschr(*e, L'=');
        if (p == NULL)
            continue;
        k = PyUnicode_FromWideChar(*e, (Py_ssize_t)(p-*e));
        if (k == NULL) {
            PyErr_Clear();
            continue;
        }
        v = PyUnicode_FromWideChar(p+1, wcslen(p+1));
        if (v == NULL) {
            PyErr_Clear();
            Py_DECREF(k);
            continue;
        }
        if (PyDict_GetItem(d, k) == NULL) {
            if (PyDict_SetItem(d, k, v) != 0)
                PyErr_Clear();
        }
        Py_DECREF(k);
        Py_DECREF(v);
    }
#else
    if (environ == NULL)
        return d;
    /* This part ignores errors */
    for (e = environ; *e != NULL; e++) {
        PyObject *k;
        PyObject *v;
        char *p = strchr(*e, '=');
        if (p == NULL)
            continue;
        k = PyBytes_FromStringAndSize(*e, (int)(p-*e));
        if (k == NULL) {
            PyErr_Clear();
            continue;
        }
        v = PyBytes_FromStringAndSize(p+1, strlen(p+1));
        if (v == NULL) {
            PyErr_Clear();
            Py_DECREF(k);
            continue;
        }
        if (PyDict_GetItem(d, k) == NULL) {
            if (PyDict_SetItem(d, k, v) != 0)
                PyErr_Clear();
        }
        Py_DECREF(k);
        Py_DECREF(v);
    }
#endif
#if defined(PYOS_OS2)
    rc = DosQueryExtLIBPATH(buffer, BEGIN_LIBPATH);
    if (rc == NO_ERROR) { /* (not a type, envname is NOT 'BEGIN_LIBPATH') */
        PyObject *v = PyBytes_FromString(buffer);
        PyDict_SetItemString(d, "BEGINLIBPATH", v);
        Py_DECREF(v);
    }
    rc = DosQueryExtLIBPATH(buffer, END_LIBPATH);
    if (rc == NO_ERROR) { /* (not a typo, envname is NOT 'END_LIBPATH') */
        PyObject *v = PyBytes_FromString(buffer);
        PyDict_SetItemString(d, "ENDLIBPATH", v);
        Py_DECREF(v);
    }
#endif
    return d;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* device_encoding ( PyObject self,
PyObject args 
) [static]

Definition at line 7707 of file posixmodule.c.

{
    int fd;
    if (!PyArg_ParseTuple(args, "i:device_encoding", &fd))
        return NULL;
    if (!_PyVerify_fd(fd) || !isatty(fd)) {
        Py_INCREF(Py_None);
        return Py_None;
    }
#if defined(MS_WINDOWS) || defined(MS_WIN64)
    if (fd == 0) {
        char buf[100];
        sprintf(buf, "cp%d", GetConsoleCP());
        return PyUnicode_FromString(buf);
    }
    if (fd == 1 || fd == 2) {
        char buf[100];
        sprintf(buf, "cp%d", GetConsoleOutputCP());
        return PyUnicode_FromString(buf);
    }
#elif defined(CODESET)
    {
        char *codeset = nl_langinfo(CODESET);
        if (codeset != NULL && codeset[0] != 0)
            return PyUnicode_FromString(codeset);
    }
#endif
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static int extract_time ( PyObject t,
time_t *  sec,
long usec 
) [static]

Definition at line 3227 of file posixmodule.c.

{
    time_t intval;
    if (PyFloat_Check(t)) {
        double tval = PyFloat_AsDouble(t);
        PyObject *intobj = PyNumber_Long(t);
        if (!intobj)
            return -1;
#if SIZEOF_TIME_T > SIZEOF_LONG
        intval = PyLong_AsUnsignedLongLongMask(intobj);
#else
        intval = PyLong_AsLong(intobj);
#endif
        Py_DECREF(intobj);
        if (intval == -1 && PyErr_Occurred())
            return -1;
        *sec = intval;
        *usec = (long)((tval - intval) * 1e6); /* can't exceed 1000000 */
        if (*usec < 0)
            /* If rounding gave us a negative number,
               truncate.  */
            *usec = 0;
        return 0;
    }
#if SIZEOF_TIME_T > SIZEOF_LONG
    intval = PyLong_AsUnsignedLongLongMask(t);
#else
    intval = PyLong_AsLong(t);
#endif
    if (intval == -1 && PyErr_Occurred())
        return -1;
    *sec = intval;
    *usec = 0;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void fill_time ( PyObject v,
int  index,
time_t  sec,
unsigned long  nsec 
) [static]

Definition at line 1601 of file posixmodule.c.

{
    PyObject *fval,*ival;
#if SIZEOF_TIME_T > SIZEOF_LONG
    ival = PyLong_FromLongLong((PY_LONG_LONG)sec);
#else
    ival = PyLong_FromLong((long)sec);
#endif
    if (!ival)
        return;
    if (_stat_float_times) {
        fval = PyFloat_FromDouble(sec + 1e-9*nsec);
    } else {
        fval = ival;
        Py_INCREF(fval);
    }
    PyStructSequence_SET_ITEM(v, index, ival);
    PyStructSequence_SET_ITEM(v, index+3, fval);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void free_string_array ( char **  array,
Py_ssize_t  count 
) [static]

Definition at line 3452 of file posixmodule.c.

{
    Py_ssize_t i;
    for (i = 0; i < count; i++)
        PyMem_Free(array[i]);
    PyMem_DEL(array);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int fsconvert_strdup ( PyObject o,
char **  out 
) [static]

Definition at line 3461 of file posixmodule.c.

{
    PyObject *bytes;
    Py_ssize_t size;
    if (!PyUnicode_FSConverter(o, &bytes))
        return 0;
    size = PyBytes_GET_SIZE(bytes);
    *out = PyMem_Malloc(size+1);
    if (!*out)
        return 0;
    memcpy(*out, PyBytes_AsString(bytes), size+1);
    Py_DECREF(bytes);
    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* getcwd ( char *  ,
int   
)

Definition at line 58 of file getcwd.c.

{
    FILE *fp;
    char *p;
    int sts;
    if (size <= 0) {
        errno = EINVAL;
        return NULL;
    }
    if ((fp = popen(PWD_CMD, "r")) == NULL)
        return NULL;
    if (fgets(buf, size, fp) == NULL || (sts = pclose(fp)) != 0) {
        errno = EACCES; /* Most likely error */
        return NULL;
    }
    for (p = buf; *p != '\n'; p++) {
        if (*p == '\0') {
            errno = ERANGE;
            return NULL;
        }
    }
    *p = '\0';
    return buf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 8516 of file posixmodule.c.

{
    PyObject *m, *v;

#if defined(HAVE_SYMLINK) && defined(MS_WINDOWS)
    win32_can_symlink = enable_symlink();
#endif

    m = PyModule_Create(&posixmodule);
    if (m == NULL)
        return NULL;

    /* Initialize environ dictionary */
    v = convertenviron();
    Py_XINCREF(v);
    if (v == NULL || PyModule_AddObject(m, "environ", v) != 0)
        return NULL;
    Py_DECREF(v);

    if (all_ins(m))
        return NULL;

    if (setup_confname_tables(m))
        return NULL;

    Py_INCREF(PyExc_OSError);
    PyModule_AddObject(m, "error", PyExc_OSError);

#ifdef HAVE_PUTENV
    if (posix_putenv_garbage == NULL)
        posix_putenv_garbage = PyDict_New();
#endif

    if (!initialized) {
        stat_result_desc.name = MODNAME ".stat_result";
        stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
        stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
        stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
        PyStructSequence_InitType(&StatResultType, &stat_result_desc);
        structseq_new = StatResultType.tp_new;
        StatResultType.tp_new = statresult_new;

        statvfs_result_desc.name = MODNAME ".statvfs_result";
        PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);
#ifdef NEED_TICKS_PER_SECOND
#  if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
        ticks_per_second = sysconf(_SC_CLK_TCK);
#  elif defined(HZ)
        ticks_per_second = HZ;
#  else
        ticks_per_second = 60; /* magic fallback value; may be bogus */
#  endif
#endif
    }
    Py_INCREF((PyObject*) &StatResultType);
    PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);
    Py_INCREF((PyObject*) &StatVFSResultType);
    PyModule_AddObject(m, "statvfs_result",
                       (PyObject*) &StatVFSResultType);
    initialized = 1;

#ifdef __APPLE__
    /*
     * Step 2 of weak-linking support on Mac OS X.
     *
     * The code below removes functions that are not available on the
     * currently active platform.
     *
     * This block allow one to use a python binary that was build on
     * OSX 10.4 on OSX 10.3, without loosing access to new APIs on
     * OSX 10.4.
     */
#ifdef HAVE_FSTATVFS
    if (fstatvfs == NULL) {
        if (PyObject_DelAttrString(m, "fstatvfs") == -1) {
            return NULL;
        }
    }
#endif /* HAVE_FSTATVFS */

#ifdef HAVE_STATVFS
    if (statvfs == NULL) {
        if (PyObject_DelAttrString(m, "statvfs") == -1) {
            return NULL;
        }
    }
#endif /* HAVE_STATVFS */

# ifdef HAVE_LCHOWN
    if (lchown == NULL) {
        if (PyObject_DelAttrString(m, "lchown") == -1) {
            return NULL;
        }
    }
#endif /* HAVE_LCHOWN */


#endif /* __APPLE__ */
    return m;

}

Here is the call graph for this function:

static int ins ( PyObject module,
char *  symbol,
long  value 
) [static]

Definition at line 8172 of file posixmodule.c.

{
    return PyModule_AddIntConstant(module, symbol, value);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int link ( const char *  ,
const char *   
)

Here is the caller graph for this function:

int mkdir ( const char *  ,
mode_t   
)

Here is the caller graph for this function:

static char** parse_envlist ( PyObject env,
Py_ssize_t envc_ptr 
) [static]

Definition at line 3551 of file posixmodule.c.

{
    char **envlist;
    Py_ssize_t i, pos, envc;
    PyObject *keys=NULL, *vals=NULL;
    PyObject *key, *val, *key2, *val2;
    char *p, *k, *v;
    size_t len;

    i = PyMapping_Size(env);
    if (i < 0)
        return NULL;
    envlist = PyMem_NEW(char *, i + 1);
    if (envlist == NULL) {
        PyErr_NoMemory();
        return NULL;
    }
    envc = 0;
    keys = PyMapping_Keys(env);
    vals = PyMapping_Values(env);
    if (!keys || !vals)
        goto error;
    if (!PyList_Check(keys) || !PyList_Check(vals)) {
        PyErr_Format(PyExc_TypeError,
                     "env.keys() or env.values() is not a list");
        goto error;
    }

    for (pos = 0; pos < i; pos++) {
        key = PyList_GetItem(keys, pos);
        val = PyList_GetItem(vals, pos);
        if (!key || !val)
            goto error;

        if (PyUnicode_FSConverter(key, &key2) == 0)
            goto error;
        if (PyUnicode_FSConverter(val, &val2) == 0) {
            Py_DECREF(key2);
            goto error;
        }

#if defined(PYOS_OS2)
        /* Omit Pseudo-Env Vars that Would Confuse Programs if Passed On */
        if (stricmp(k, "BEGINLIBPATH") != 0 && stricmp(k, "ENDLIBPATH") != 0) {
#endif
        k = PyBytes_AsString(key2);
        v = PyBytes_AsString(val2);
        len = PyBytes_GET_SIZE(key2) + PyBytes_GET_SIZE(val2) + 2;

        p = PyMem_NEW(char, len);
        if (p == NULL) {
            PyErr_NoMemory();
            Py_DECREF(key2);
            Py_DECREF(val2);
            goto error;
        }
        PyOS_snprintf(p, len, "%s=%s", k, v);
        envlist[envc++] = p;
        Py_DECREF(key2);
        Py_DECREF(val2);
#if defined(PYOS_OS2)
        }
#endif
    }
    Py_DECREF(vals);
    Py_DECREF(keys);

    envlist[envc] = 0;
    *envc_ptr = envc;
    return envlist;

error:
    Py_XDECREF(keys);
    Py_XDECREF(vals);
    while (--envc >= 0)
        PyMem_DEL(envlist[envc]);
    PyMem_DEL(envlist);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* posix_1str ( PyObject args,
char *  format,
int(*)(const char *)  func 
) [static]

Definition at line 784 of file posixmodule.c.

{
    PyObject *opath1 = NULL;
    char *path1;
    int res;
    if (!PyArg_ParseTuple(args, format,
                          PyUnicode_FSConverter, &opath1))
        return NULL;
    path1 = PyBytes_AsString(opath1);
    Py_BEGIN_ALLOW_THREADS
    res = (*func)(path1);
    Py_END_ALLOW_THREADS
    if (res < 0)
        return posix_error_with_allocated_filename(opath1);
    Py_DECREF(opath1);
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* posix_2str ( PyObject args,
char *  format,
int(*)(const char *, const char *)  func 
) [static]

Definition at line 804 of file posixmodule.c.

{
    PyObject *opath1 = NULL, *opath2 = NULL;
    char *path1, *path2;
    int res;
    if (!PyArg_ParseTuple(args, format,
                          PyUnicode_FSConverter, &opath1,
                          PyUnicode_FSConverter, &opath2)) {
        return NULL;
    }
    path1 = PyBytes_AsString(opath1);
    path2 = PyBytes_AsString(opath2);
    Py_BEGIN_ALLOW_THREADS
    res = (*func)(path1, path2);
    Py_END_ALLOW_THREADS
    Py_DECREF(opath1);
    Py_DECREF(opath2);
    if (res != 0)
        /* XXX how to report both path1 and path2??? */
        return posix_error();
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* posix__exit ( PyObject self,
PyObject args 
) [static]

Definition at line 3441 of file posixmodule.c.

{
    int sts;
    if (!PyArg_ParseTuple(args, "i:_exit", &sts))
        return NULL;
    _exit(sts);
    return NULL; /* Make gcc -Wall happy */
}

Here is the call graph for this function:

static PyObject* posix_abort ( PyObject self,
PyObject noargs 
) [static]

Definition at line 7517 of file posixmodule.c.

{
    abort();
    /*NOTREACHED*/
    Py_FatalError("abort() called from Python code didn't abort!");
    return NULL;
}

Here is the call graph for this function:

static PyObject* posix_access ( PyObject self,
PyObject args 
) [static]

Definition at line 1791 of file posixmodule.c.

{
    PyObject *opath;
    char *path;
    int mode;

#ifdef MS_WINDOWS
    DWORD attr;
    PyUnicodeObject *po;
    if (PyArg_ParseTuple(args, "Ui:access", &po, &mode)) {
        Py_BEGIN_ALLOW_THREADS
        /* PyUnicode_AS_UNICODE OK without thread lock as
           it is a simple dereference. */
        attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po));
        Py_END_ALLOW_THREADS
        goto finish;
    }
    /* Drop the argument parsing error as narrow strings
       are also valid. */
    PyErr_Clear();
    if (!PyArg_ParseTuple(args, "O&i:access",
                          PyUnicode_FSConverter, &opath, &mode))
        return NULL;
    path = PyBytes_AsString(opath);
    Py_BEGIN_ALLOW_THREADS
    attr = GetFileAttributesA(path);
    Py_END_ALLOW_THREADS
    Py_DECREF(opath);
finish:
    if (attr == 0xFFFFFFFF)
        /* File does not exist, or cannot read attributes */
        return PyBool_FromLong(0);
    /* Access is possible if either write access wasn't requested, or
       the file isn't read-only, or if it's a directory, as there are
       no read-only directories on Windows. */
    return PyBool_FromLong(!(mode & 2)
                           || !(attr & FILE_ATTRIBUTE_READONLY)
                           || (attr & FILE_ATTRIBUTE_DIRECTORY));
#else
    int res;
    if (!PyArg_ParseTuple(args, "O&i:access",
                          PyUnicode_FSConverter, &opath, &mode))
        return NULL;
    path = PyBytes_AsString(opath);
    Py_BEGIN_ALLOW_THREADS
    res = access(path, mode);
    Py_END_ALLOW_THREADS
    Py_DECREF(opath);
    return PyBool_FromLong(res == 0);
#endif
}

Here is the call graph for this function:

static PyObject* posix_chdir ( PyObject self,
PyObject args 
) [static]

Definition at line 1914 of file posixmodule.c.

{
#ifdef MS_WINDOWS
    return win32_1str(args, "chdir", "y:chdir", win32_chdir, "U:chdir", win32_wchdir);
#elif defined(PYOS_OS2) && defined(PYCC_GCC)
    return posix_1str(args, "O&:chdir", _chdir2);
#elif defined(__VMS)
    return posix_1str(args, "O&:chdir", (int (*)(const char *))chdir);
#else
    return posix_1str(args, "O&:chdir", chdir);
#endif
}

Here is the call graph for this function:

static PyObject* posix_chmod ( PyObject self,
PyObject args 
) [static]

Definition at line 1946 of file posixmodule.c.

{
    PyObject *opath = NULL;
    char *path = NULL;
    int i;
    int res;
#ifdef MS_WINDOWS
    DWORD attr;
    PyUnicodeObject *po;
    if (PyArg_ParseTuple(args, "Ui|:chmod", &po, &i)) {
        Py_BEGIN_ALLOW_THREADS
        attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po));
        if (attr != 0xFFFFFFFF) {
            if (i & _S_IWRITE)
                attr &= ~FILE_ATTRIBUTE_READONLY;
            else
                attr |= FILE_ATTRIBUTE_READONLY;
            res = SetFileAttributesW(PyUnicode_AS_UNICODE(po), attr);
        }
        else
            res = 0;
        Py_END_ALLOW_THREADS
        if (!res)
            return win32_error_unicode("chmod",
                                       PyUnicode_AS_UNICODE(po));
        Py_INCREF(Py_None);
        return Py_None;
    }
    /* Drop the argument parsing error as narrow strings
       are also valid. */
    PyErr_Clear();

    if (!PyArg_ParseTuple(args, "O&i:chmod", PyUnicode_FSConverter,
                          &opath, &i))
        return NULL;
    path = PyBytes_AsString(opath);
    Py_BEGIN_ALLOW_THREADS
    attr = GetFileAttributesA(path);
    if (attr != 0xFFFFFFFF) {
        if (i & _S_IWRITE)
            attr &= ~FILE_ATTRIBUTE_READONLY;
        else
            attr |= FILE_ATTRIBUTE_READONLY;
        res = SetFileAttributesA(path, attr);
    }
    else
        res = 0;
    Py_END_ALLOW_THREADS
    if (!res) {
        win32_error("chmod", path);
        Py_DECREF(opath);
        return NULL;
    }
    Py_DECREF(opath);
    Py_INCREF(Py_None);
    return Py_None;
#else /* MS_WINDOWS */
    if (!PyArg_ParseTuple(args, "O&i:chmod", PyUnicode_FSConverter,
                          &opath, &i))
        return NULL;
    path = PyBytes_AsString(opath);
    Py_BEGIN_ALLOW_THREADS
    res = chmod(path, i);
    Py_END_ALLOW_THREADS
    if (res < 0)
        return posix_error_with_allocated_filename(opath);
    Py_DECREF(opath);
    Py_INCREF(Py_None);
    return Py_None;
#endif
}

Here is the call graph for this function:

static PyObject* posix_close ( PyObject self,
PyObject args 
) [static]

Definition at line 5609 of file posixmodule.c.

{
    int fd, res;
    if (!PyArg_ParseTuple(args, "i:close", &fd))
        return NULL;
    if (!_PyVerify_fd(fd))
        return posix_error();
    Py_BEGIN_ALLOW_THREADS
    res = close(fd);
    Py_END_ALLOW_THREADS
    if (res < 0)
        return posix_error();
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* posix_closerange ( PyObject self,
PyObject args 
) [static]

Definition at line 5631 of file posixmodule.c.

{
    int fd_from, fd_to, i;
    if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to))
        return NULL;
    Py_BEGIN_ALLOW_THREADS
    for (i = fd_from; i < fd_to; i++)
        if (_PyVerify_fd(i))
            close(i);
    Py_END_ALLOW_THREADS
    Py_RETURN_NONE;
}

Here is the call graph for this function:

static PyObject* posix_do_stat ( PyObject self,
PyObject args,
char *  format,
int(*)(const char *, STRUCT_STAT *)  statfunc,
char *  wformat,
int(*)(const Py_UNICODE *, STRUCT_STAT *)  wstatfunc 
) [static]

Definition at line 1722 of file posixmodule.c.

{
    STRUCT_STAT st;
    PyObject *opath;
    char *path;
    int res;
    PyObject *result;

#ifdef MS_WINDOWS
    PyUnicodeObject *po;
    if (PyArg_ParseTuple(args, wformat, &po)) {
        Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);

        Py_BEGIN_ALLOW_THREADS
            /* PyUnicode_AS_UNICODE result OK without
               thread lock as it is a simple dereference. */
        res = wstatfunc(wpath, &st);
        Py_END_ALLOW_THREADS

        if (res != 0)
            return win32_error_unicode("stat", wpath);
        return _pystat_fromstructstat(&st);
    }
    /* Drop the argument parsing error as narrow strings
       are also valid. */
    PyErr_Clear();
#endif

    if (!PyArg_ParseTuple(args, format,
                          PyUnicode_FSConverter, &opath))
        return NULL;
    path = PyBytes_AsString(opath);
    Py_BEGIN_ALLOW_THREADS
    res = (*statfunc)(path, &st);
    Py_END_ALLOW_THREADS

    if (res != 0) {
#ifdef MS_WINDOWS
        result = win32_error("stat", path);
#else
        result = posix_error_with_filename(path);
#endif
    }
    else
        result = _pystat_fromstructstat(&st);

    Py_DECREF(opath);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* posix_dup ( PyObject self,
PyObject args 
) [static]

Definition at line 5650 of file posixmodule.c.

{
    int fd;
    if (!PyArg_ParseTuple(args, "i:dup", &fd))
        return NULL;
    if (!_PyVerify_fd(fd))
        return posix_error();
    Py_BEGIN_ALLOW_THREADS
    fd = dup(fd);
    Py_END_ALLOW_THREADS
    if (fd < 0)
        return posix_error();
    return PyLong_FromLong((long)fd);
}

Here is the call graph for this function:

static PyObject* posix_dup2 ( PyObject self,
PyObject args 
) [static]

Definition at line 5671 of file posixmodule.c.

{
    int fd, fd2, res;
    if (!PyArg_ParseTuple(args, "ii:dup2", &fd, &fd2))
        return NULL;
    if (!_PyVerify_fd_dup2(fd, fd2))
        return posix_error();
    Py_BEGIN_ALLOW_THREADS
    res = dup2(fd, fd2);
    Py_END_ALLOW_THREADS
    if (res < 0)
        return posix_error();
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* posix_error ( void  ) [static]

Definition at line 615 of file posixmodule.c.

{
    return PyErr_SetFromErrno(PyExc_OSError);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 627 of file posixmodule.c.

{
    PyObject *name_str, *rc;
    name_str = PyUnicode_DecodeFSDefaultAndSize(PyBytes_AsString(name),
                                                PyBytes_GET_SIZE(name));
    Py_DECREF(name);
    rc = PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError,
                                              name_str);
    Py_XDECREF(name_str);
    return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* posix_error_with_filename ( char *  name) [static]

Definition at line 620 of file posixmodule.c.

{
    return PyErr_SetFromErrnoWithFilename(PyExc_OSError, name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* posix_execv ( PyObject self,
PyObject args 
) [static]

Definition at line 3487 of file posixmodule.c.

{
    PyObject *opath;
    char *path;
    PyObject *argv;
    char **argvlist;
    Py_ssize_t i, argc;
    PyObject *(*getitem)(PyObject *, Py_ssize_t);

    /* execv has two arguments: (path, argv), where
       argv is a list or tuple of strings. */

    if (!PyArg_ParseTuple(args, "O&O:execv",
                          PyUnicode_FSConverter,
                          &opath, &argv))
        return NULL;
    path = PyBytes_AsString(opath);
    if (PyList_Check(argv)) {
        argc = PyList_Size(argv);
        getitem = PyList_GetItem;
    }
    else if (PyTuple_Check(argv)) {
        argc = PyTuple_Size(argv);
        getitem = PyTuple_GetItem;
    }
    else {
        PyErr_SetString(PyExc_TypeError, "execv() arg 2 must be a tuple or list");
        Py_DECREF(opath);
        return NULL;
    }
    if (argc < 1) {
        PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty");
        Py_DECREF(opath);
        return NULL;
    }

    argvlist = PyMem_NEW(char *, argc+1);
    if (argvlist == NULL) {
        Py_DECREF(opath);
        return PyErr_NoMemory();
    }
    for (i = 0; i < argc; i++) {
        if (!fsconvert_strdup((*getitem)(argv, i),
                              &argvlist[i])) {
            free_string_array(argvlist, i);
            PyErr_SetString(PyExc_TypeError,
                            "execv() arg 2 must contain only strings");
            Py_DECREF(opath);
            return NULL;

        }
    }
    argvlist[argc] = NULL;

    execv(path, argvlist);

    /* If we get here it's definitely an error */

    free_string_array(argvlist, argc);
    Py_DECREF(opath);
    return posix_error();
}

Here is the call graph for this function:

static PyObject* posix_execve ( PyObject self,
PyObject args 
) [static]

Definition at line 3640 of file posixmodule.c.

{
    PyObject *opath;
    char *path;
    PyObject *argv, *env;
    char **argvlist;
    char **envlist;
    Py_ssize_t i, argc, envc;
    PyObject *(*getitem)(PyObject *, Py_ssize_t);
    Py_ssize_t lastarg = 0;

    /* execve has three arguments: (path, argv, env), where
       argv is a list or tuple of strings and env is a dictionary
       like posix.environ. */

    if (!PyArg_ParseTuple(args, "O&OO:execve",
                          PyUnicode_FSConverter,
                          &opath, &argv, &env))
        return NULL;
    path = PyBytes_AsString(opath);
    if (PyList_Check(argv)) {
        argc = PyList_Size(argv);
        getitem = PyList_GetItem;
    }
    else if (PyTuple_Check(argv)) {
        argc = PyTuple_Size(argv);
        getitem = PyTuple_GetItem;
    }
    else {
        PyErr_SetString(PyExc_TypeError,
                        "execve() arg 2 must be a tuple or list");
        goto fail_0;
    }
    if (!PyMapping_Check(env)) {
        PyErr_SetString(PyExc_TypeError,
                        "execve() arg 3 must be a mapping object");
        goto fail_0;
    }

    argvlist = PyMem_NEW(char *, argc+1);
    if (argvlist == NULL) {
        PyErr_NoMemory();
        goto fail_0;
    }
    for (i = 0; i < argc; i++) {
        if (!fsconvert_strdup((*getitem)(argv, i),
                              &argvlist[i]))
        {
            lastarg = i;
            goto fail_1;
        }
    }
    lastarg = argc;
    argvlist[argc] = NULL;

    envlist = parse_envlist(env, &envc);
    if (envlist == NULL)
        goto fail_1;

    execve(path, argvlist, envlist);

    /* If we get here it's definitely an error */

    (void) posix_error();

    while (--envc >= 0)
        PyMem_DEL(envlist[envc]);
    PyMem_DEL(envlist);
  fail_1:
    free_string_array(argvlist, lastarg);
  fail_0:
    Py_DECREF(opath);
    return NULL;
}

Here is the call graph for this function:

static PyObject* posix_fildes ( PyObject fdobj,
int(*)(int func 
) [static]

Definition at line 765 of file posixmodule.c.

{
    int fd;
    int res;
    fd = PyObject_AsFileDescriptor(fdobj);
    if (fd < 0)
        return NULL;
    if (!_PyVerify_fd(fd))
        return posix_error();
    Py_BEGIN_ALLOW_THREADS
    res = (*func)(fd);
    Py_END_ALLOW_THREADS
    if (res < 0)
        return posix_error();
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* posix_fork ( PyObject self,
PyObject noargs 
) [static]

Definition at line 4131 of file posixmodule.c.

{
    pid_t pid;
    int result = 0;
    _PyImport_AcquireLock();
    pid = fork();
    if (pid == 0) {
        /* child: this clobbers and resets the import lock. */
        PyOS_AfterFork();
    } else {
        /* parent: release the import lock. */
        result = _PyImport_ReleaseLock();
    }
    if (pid == -1)
        return posix_error();
    if (result < 0) {
        /* Don't clobber the OSError if the fork failed. */
        PyErr_SetString(PyExc_RuntimeError,
                        "not holding the import lock");
        return NULL;
    }
    return PyLong_FromPid(pid);
}

Here is the call graph for this function:

static PyObject* posix_fstat ( PyObject self,
PyObject args 
) [static]

Definition at line 5817 of file posixmodule.c.

{
    int fd;
    STRUCT_STAT st;
    int res;
    if (!PyArg_ParseTuple(args, "i:fstat", &fd))
        return NULL;
#ifdef __VMS
    /* on OpenVMS we must ensure that all bytes are written to the file */
    fsync(fd);
#endif
    if (!_PyVerify_fd(fd))
        return posix_error();
    Py_BEGIN_ALLOW_THREADS
    res = FSTAT(fd, &st);
    Py_END_ALLOW_THREADS
    if (res != 0) {
#ifdef MS_WINDOWS
        return win32_error("fstat", NULL);
#else
        return posix_error();
#endif
    }

    return _pystat_fromstructstat(&st);
}

Here is the call graph for this function:

static PyObject* posix_getcwd ( int  use_bytes) [static]

Definition at line 2248 of file posixmodule.c.

{
    char buf[1026];
    char *res;

#ifdef MS_WINDOWS
    if (!use_bytes) {
        wchar_t wbuf[1026];
        wchar_t *wbuf2 = wbuf;
        PyObject *resobj;
        DWORD len;
        Py_BEGIN_ALLOW_THREADS
        len = GetCurrentDirectoryW(sizeof wbuf/ sizeof wbuf[0], wbuf);
        /* If the buffer is large enough, len does not include the
           terminating \0. If the buffer is too small, len includes
           the space needed for the terminator. */
        if (len >= sizeof wbuf/ sizeof wbuf[0]) {
            wbuf2 = malloc(len * sizeof(wchar_t));
            if (wbuf2)
                len = GetCurrentDirectoryW(len, wbuf2);
        }
        Py_END_ALLOW_THREADS
        if (!wbuf2) {
            PyErr_NoMemory();
            return NULL;
        }
        if (!len) {
            if (wbuf2 != wbuf) free(wbuf2);
            return win32_error("getcwdu", NULL);
        }
        resobj = PyUnicode_FromWideChar(wbuf2, len);
        if (wbuf2 != wbuf) free(wbuf2);
        return resobj;
    }
#endif

    Py_BEGIN_ALLOW_THREADS
#if defined(PYOS_OS2) && defined(PYCC_GCC)
    res = _getcwd2(buf, sizeof buf);
#else
    res = getcwd(buf, sizeof buf);
#endif
    Py_END_ALLOW_THREADS
    if (res == NULL)
        return posix_error();
    if (use_bytes)
        return PyBytes_FromStringAndSize(buf, strlen(buf));
    return PyUnicode_DecodeFSDefault(buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* posix_getcwd_bytes ( PyObject self) [static]

Definition at line 2313 of file posixmodule.c.

{
    return posix_getcwd(1);
}

Here is the call graph for this function:

static PyObject* posix_getcwd_unicode ( PyObject self) [static]

Definition at line 2303 of file posixmodule.c.

{
    return posix_getcwd(0);
}

Here is the call graph for this function:

static PyObject* posix_getegid ( PyObject self,
PyObject noargs 
) [static]

Definition at line 4288 of file posixmodule.c.

{
    return PyLong_FromLong((long)getegid());
}

Here is the call graph for this function:

static PyObject* posix_geteuid ( PyObject self,
PyObject noargs 
) [static]

Definition at line 4301 of file posixmodule.c.

{
    return PyLong_FromLong((long)geteuid());
}

Here is the call graph for this function:

static PyObject* posix_getgid ( PyObject self,
PyObject noargs 
) [static]

Definition at line 4314 of file posixmodule.c.

{
    return PyLong_FromLong((long)getgid());
}

Here is the call graph for this function:

static PyObject* posix_getpid ( PyObject self,
PyObject noargs 
) [static]

Definition at line 4326 of file posixmodule.c.

{
    return PyLong_FromPid(getpid());
}
static PyObject* posix_getppid ( PyObject self,
PyObject noargs 
) [static]

Definition at line 4546 of file posixmodule.c.

{
#ifdef MS_WINDOWS
    return win32_getppid();
#else
    return PyLong_FromPid(getppid());
#endif
}
static PyObject* posix_getuid ( PyObject self,
PyObject noargs 
) [static]

Definition at line 4602 of file posixmodule.c.

{
    return PyLong_FromLong((long)getuid());
}

Here is the call graph for this function:

static PyObject* posix_isatty ( PyObject self,
PyObject args 
) [static]

Definition at line 5850 of file posixmodule.c.

{
    int fd;
    if (!PyArg_ParseTuple(args, "i:isatty", &fd))
        return NULL;
    if (!_PyVerify_fd(fd))
        return PyBool_FromLong(0);
    return PyBool_FromLong(isatty(fd));
}

Here is the call graph for this function:

static PyObject* posix_kill ( PyObject self,
PyObject args 
) [static]

Definition at line 4615 of file posixmodule.c.

{
    pid_t pid;
    int sig;
    if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:kill", &pid, &sig))
        return NULL;
#if defined(PYOS_OS2) && !defined(PYCC_GCC)
    if (sig == XCPT_SIGNAL_INTR || sig == XCPT_SIGNAL_BREAK) {
        APIRET rc;
        if ((rc = DosSendSignalException(pid, sig)) != NO_ERROR)
            return os2_error(rc);

    } else if (sig == XCPT_SIGNAL_KILLPROC) {
        APIRET rc;
        if ((rc = DosKillProcess(DKP_PROCESS, pid)) != NO_ERROR)
            return os2_error(rc);

    } else
        return NULL; /* Unrecognized Signal Requested */
#else
    if (kill(pid, sig) == -1)
        return posix_error();
#endif
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* posix_listdir ( PyObject self,
PyObject args 
) [static]

Definition at line 2391 of file posixmodule.c.

{
    /* XXX Should redo this putting the (now four) versions of opendir
       in separate files instead of having them all here... */
#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR)

    PyObject *d, *v;
    HANDLE hFindFile;
    BOOL result;
    WIN32_FIND_DATA FileData;
    PyObject *opath;
    char namebuf[MAX_PATH+5]; /* Overallocate for \\*.*\0 */
    char *bufptr = namebuf;
    Py_ssize_t len = sizeof(namebuf)-5; /* only claim to have space for MAX_PATH */

    PyObject *po = NULL;
    if (PyArg_ParseTuple(args, "|U:listdir", &po)) {
        WIN32_FIND_DATAW wFileData;
        Py_UNICODE *wnamebuf, *po_wchars;

        if (po == NULL) { /* Default arg: "." */
            po_wchars = L".";
            len = 1;
        } else {
            po_wchars = PyUnicode_AS_UNICODE(po);
            len = PyUnicode_GET_SIZE(po);
        }
        /* Overallocate for \\*.*\0 */
        wnamebuf = malloc((len + 5) * sizeof(wchar_t));
        if (!wnamebuf) {
            PyErr_NoMemory();
            return NULL;
        }
        wcscpy(wnamebuf, po_wchars);
        if (len > 0) {
            Py_UNICODE wch = wnamebuf[len-1];
            if (wch != L'/' && wch != L'\\' && wch != L':')
                wnamebuf[len++] = L'\\';
            wcscpy(wnamebuf + len, L"*.*");
        }
        if ((d = PyList_New(0)) == NULL) {
            free(wnamebuf);
            return NULL;
        }
        Py_BEGIN_ALLOW_THREADS
        hFindFile = FindFirstFileW(wnamebuf, &wFileData);
        Py_END_ALLOW_THREADS
        if (hFindFile == INVALID_HANDLE_VALUE) {
            int error = GetLastError();
            if (error == ERROR_FILE_NOT_FOUND) {
                free(wnamebuf);
                return d;
            }
            Py_DECREF(d);
            win32_error_unicode("FindFirstFileW", wnamebuf);
            free(wnamebuf);
            return NULL;
        }
        do {
            /* Skip over . and .. */
            if (wcscmp(wFileData.cFileName, L".") != 0 &&
                wcscmp(wFileData.cFileName, L"..") != 0) {
                v = PyUnicode_FromUnicode(wFileData.cFileName, wcslen(wFileData.cFileName));
                if (v == NULL) {
                    Py_DECREF(d);
                    d = NULL;
                    break;
                }
                if (PyList_Append(d, v) != 0) {
                    Py_DECREF(v);
                    Py_DECREF(d);
                    d = NULL;
                    break;
                }
                Py_DECREF(v);
            }
            Py_BEGIN_ALLOW_THREADS
            result = FindNextFileW(hFindFile, &wFileData);
            Py_END_ALLOW_THREADS
            /* FindNextFile sets error to ERROR_NO_MORE_FILES if
               it got to the end of the directory. */
            if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
                Py_DECREF(d);
                win32_error_unicode("FindNextFileW", wnamebuf);
                FindClose(hFindFile);
                free(wnamebuf);
                return NULL;
            }
        } while (result == TRUE);

        if (FindClose(hFindFile) == FALSE) {
            Py_DECREF(d);
            win32_error_unicode("FindClose", wnamebuf);
            free(wnamebuf);
            return NULL;
        }
        free(wnamebuf);
        return d;
    }
    /* Drop the argument parsing error as narrow strings
       are also valid. */
    PyErr_Clear();

    if (!PyArg_ParseTuple(args, "O&:listdir",
                          PyUnicode_FSConverter, &opath))
        return NULL;
    if (PyBytes_GET_SIZE(opath)+1 > MAX_PATH) {
        PyErr_SetString(PyExc_ValueError, "path too long");
        Py_DECREF(opath);
        return NULL;
    }
    strcpy(namebuf, PyBytes_AsString(opath));
    len = PyObject_Size(opath);
    Py_DECREF(opath);
    if (len > 0) {
        char ch = namebuf[len-1];
        if (ch != SEP && ch != ALTSEP && ch != ':')
            namebuf[len++] = '/';
        strcpy(namebuf + len, "*.*");
    }

    if ((d = PyList_New(0)) == NULL)
        return NULL;

    Py_BEGIN_ALLOW_THREADS
    hFindFile = FindFirstFile(namebuf, &FileData);
    Py_END_ALLOW_THREADS
    if (hFindFile == INVALID_HANDLE_VALUE) {
        int error = GetLastError();
        if (error == ERROR_FILE_NOT_FOUND)
            return d;
        Py_DECREF(d);
        return win32_error("FindFirstFile", namebuf);
    }
    do {
        /* Skip over . and .. */
        if (strcmp(FileData.cFileName, ".") != 0 &&
            strcmp(FileData.cFileName, "..") != 0) {
            v = PyBytes_FromString(FileData.cFileName);
            if (v == NULL) {
                Py_DECREF(d);
                d = NULL;
                break;
            }
            if (PyList_Append(d, v) != 0) {
                Py_DECREF(v);
                Py_DECREF(d);
                d = NULL;
                break;
            }
            Py_DECREF(v);
        }
        Py_BEGIN_ALLOW_THREADS
        result = FindNextFile(hFindFile, &FileData);
        Py_END_ALLOW_THREADS
        /* FindNextFile sets error to ERROR_NO_MORE_FILES if
           it got to the end of the directory. */
        if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
            Py_DECREF(d);
            win32_error("FindNextFile", namebuf);
            FindClose(hFindFile);
            return NULL;
        }
    } while (result == TRUE);

    if (FindClose(hFindFile) == FALSE) {
        Py_DECREF(d);
        return win32_error("FindClose", namebuf);
    }

    return d;

#elif defined(PYOS_OS2)

#ifndef MAX_PATH
#define MAX_PATH    CCHMAXPATH
#endif
    PyObject *oname;
    char *name, *pt;
    Py_ssize_t len;
    PyObject *d, *v;
    char namebuf[MAX_PATH+5];
    HDIR  hdir = 1;
    ULONG srchcnt = 1;
    FILEFINDBUF3   ep;
    APIRET rc;

    if (!PyArg_ParseTuple(args, "O&:listdir",
                          PyUnicode_FSConverter, &oname))
        return NULL;
    name = PyBytes_AsString(oname);
    len = PyBytes_GET_SIZE(oname);
    if (len >= MAX_PATH) {
        Py_DECREF(oname);
        PyErr_SetString(PyExc_ValueError, "path too long");
        return NULL;
    }
    strcpy(namebuf, name);
    for (pt = namebuf; *pt; pt++)
        if (*pt == ALTSEP)
            *pt = SEP;
    if (namebuf[len-1] != SEP)
        namebuf[len++] = SEP;
    strcpy(namebuf + len, "*.*");

    if ((d = PyList_New(0)) == NULL) {
        Py_DECREF(oname);
        return NULL;
    }

    rc = DosFindFirst(namebuf,         /* Wildcard Pattern to Match */
                      &hdir,           /* Handle to Use While Search Directory */
                      FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY,
                      &ep, sizeof(ep), /* Structure to Receive Directory Entry */
                      &srchcnt,        /* Max and Actual Count of Entries Per Iteration */
                      FIL_STANDARD);   /* Format of Entry (EAs or Not) */

    if (rc != NO_ERROR) {
        errno = ENOENT;
        return posix_error_with_allocated_filename(oname);
    }

    if (srchcnt > 0) { /* If Directory is NOT Totally Empty, */
        do {
            if (ep.achName[0] == '.'
            && (ep.achName[1] == '\0' || (ep.achName[1] == '.' && ep.achName[2] == '\0')))
                continue; /* Skip Over "." and ".." Names */

            strcpy(namebuf, ep.achName);

            /* Leave Case of Name Alone -- In Native Form */
            /* (Removed Forced Lowercasing Code) */

            v = PyBytes_FromString(namebuf);
            if (v == NULL) {
                Py_DECREF(d);
                d = NULL;
                break;
            }
            if (PyList_Append(d, v) != 0) {
                Py_DECREF(v);
                Py_DECREF(d);
                d = NULL;
                break;
            }
            Py_DECREF(v);
        } while (DosFindNext(hdir, &ep, sizeof(ep), &srchcnt) == NO_ERROR && srchcnt > 0);
    }

    Py_DECREF(oname);
    return d;
#else
    PyObject *oname;
    char *name;
    PyObject *d, *v;
    DIR *dirp;
    struct dirent *ep;
    int arg_is_unicode = 1;

    errno = 0;
    /* v is never read, so it does not need to be initialized yet. */
    if (!PyArg_ParseTuple(args, "|U:listdir", &v)) {
        arg_is_unicode = 0;
        PyErr_Clear();
    }
    oname = NULL;
    if (!PyArg_ParseTuple(args, "|O&:listdir", PyUnicode_FSConverter, &oname))
        return NULL;
    if (oname == NULL) { /* Default arg: "." */
        oname = PyBytes_FromString(".");
    }
    name = PyBytes_AsString(oname);
    Py_BEGIN_ALLOW_THREADS
    dirp = opendir(name);
    Py_END_ALLOW_THREADS
    if (dirp == NULL) {
        return posix_error_with_allocated_filename(oname);
    }
    if ((d = PyList_New(0)) == NULL) {
        Py_BEGIN_ALLOW_THREADS
        closedir(dirp);
        Py_END_ALLOW_THREADS
        Py_DECREF(oname);
        return NULL;
    }
    for (;;) {
        errno = 0;
        Py_BEGIN_ALLOW_THREADS
        ep = readdir(dirp);
        Py_END_ALLOW_THREADS
        if (ep == NULL) {
            if (errno == 0) {
                break;
            } else {
                Py_BEGIN_ALLOW_THREADS
                closedir(dirp);
                Py_END_ALLOW_THREADS
                Py_DECREF(d);
                return posix_error_with_allocated_filename(oname);
            }
        }
        if (ep->d_name[0] == '.' &&
            (NAMLEN(ep) == 1 ||
             (ep->d_name[1] == '.' && NAMLEN(ep) == 2)))
            continue;
        if (arg_is_unicode)
            v = PyUnicode_DecodeFSDefaultAndSize(ep->d_name, NAMLEN(ep));
        else
            v = PyBytes_FromStringAndSize(ep->d_name, NAMLEN(ep));
        if (v == NULL) {
            Py_CLEAR(d);
            break;
        }
        if (PyList_Append(d, v) != 0) {
            Py_DECREF(v);
            Py_CLEAR(d);
            break;
        }
        Py_DECREF(v);
    }
    Py_BEGIN_ALLOW_THREADS
    closedir(dirp);
    Py_END_ALLOW_THREADS
    Py_DECREF(oname);

    return d;

#endif /* which OS */
}  /* end of posix_listdir */

Here is the call graph for this function:

static PyObject* posix_lseek ( PyObject self,
PyObject args 
) [static]

Definition at line 5693 of file posixmodule.c.

{
    int fd, how;
#if defined(MS_WIN64) || defined(MS_WINDOWS)
    PY_LONG_LONG pos, res;
#else
    off_t pos, res;
#endif
    PyObject *posobj;
    if (!PyArg_ParseTuple(args, "iOi:lseek", &fd, &posobj, &how))
        return NULL;
#ifdef SEEK_SET
    /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */
    switch (how) {
    case 0: how = SEEK_SET; break;
    case 1: how = SEEK_CUR; break;
    case 2: how = SEEK_END; break;
    }
#endif /* SEEK_END */

#if !defined(HAVE_LARGEFILE_SUPPORT)
    pos = PyLong_AsLong(posobj);
#else
    pos = PyLong_Check(posobj) ?
        PyLong_AsLongLong(posobj) : PyLong_AsLong(posobj);
#endif
    if (PyErr_Occurred())
        return NULL;

    if (!_PyVerify_fd(fd))
        return posix_error();
    Py_BEGIN_ALLOW_THREADS
#if defined(MS_WIN64) || defined(MS_WINDOWS)
    res = _lseeki64(fd, pos, how);
#else
    res = lseek(fd, pos, how);
#endif
    Py_END_ALLOW_THREADS
    if (res < 0)
        return posix_error();

#if !defined(HAVE_LARGEFILE_SUPPORT)
    return PyLong_FromLong(res);
#else
    return PyLong_FromLongLong(res);
#endif
}

Here is the call graph for this function:

static PyObject* posix_lstat ( PyObject self,
PyObject args 
) [static]

Definition at line 5150 of file posixmodule.c.

{
#ifdef HAVE_LSTAT
    return posix_do_stat(self, args, "O&:lstat", lstat, NULL, NULL);
#else /* !HAVE_LSTAT */
#ifdef MS_WINDOWS
    return posix_do_stat(self, args, "O&:lstat", win32_lstat, "U:lstat",
                         win32_lstat_w);
#else
    return posix_do_stat(self, args, "O&:lstat", STAT, NULL, NULL);
#endif
#endif /* !HAVE_LSTAT */
}

Here is the call graph for this function:

static PyObject* posix_mkdir ( PyObject self,
PyObject args 
) [static]

Definition at line 2914 of file posixmodule.c.

{
    int res;
    PyObject *opath;
    char *path;
    int mode = 0777;

#ifdef MS_WINDOWS
    PyUnicodeObject *po;
    if (PyArg_ParseTuple(args, "U|i:mkdir", &po, &mode)) {
        Py_BEGIN_ALLOW_THREADS
        /* PyUnicode_AS_UNICODE OK without thread lock as
           it is a simple dereference. */
        res = CreateDirectoryW(PyUnicode_AS_UNICODE(po), NULL);
        Py_END_ALLOW_THREADS
        if (!res)
            return win32_error_unicode("mkdir", PyUnicode_AS_UNICODE(po));
        Py_INCREF(Py_None);
        return Py_None;
    }
    /* Drop the argument parsing error as narrow strings
       are also valid. */
    PyErr_Clear();
    if (!PyArg_ParseTuple(args, "O&|i:mkdir",
                          PyUnicode_FSConverter, &opath, &mode))
        return NULL;
    path = PyBytes_AsString(opath);
    Py_BEGIN_ALLOW_THREADS
    /* PyUnicode_AS_UNICODE OK without thread lock as
       it is a simple dereference. */
    res = CreateDirectoryA(path, NULL);
    Py_END_ALLOW_THREADS
    if (!res) {
        win32_error("mkdir", path);
        Py_DECREF(opath);
        return NULL;
    }
    Py_DECREF(opath);
    Py_INCREF(Py_None);
    return Py_None;
#else

    if (!PyArg_ParseTuple(args, "O&|i:mkdir",
                          PyUnicode_FSConverter, &opath, &mode))
        return NULL;
    path = PyBytes_AsString(opath);
    Py_BEGIN_ALLOW_THREADS
#if ( defined(__WATCOMC__) || defined(PYCC_VACPP) ) && !defined(__QNX__)
    res = mkdir(path);
#else
    res = mkdir(path, mode);
#endif
    Py_END_ALLOW_THREADS
    if (res < 0)
        return posix_error_with_allocated_filename(opath);
    Py_DECREF(opath);
    Py_INCREF(Py_None);
    return Py_None;
#endif
}

Here is the call graph for this function:

static PyObject* posix_open ( PyObject self,
PyObject args 
) [static]

Definition at line 5564 of file posixmodule.c.

{
    PyObject *ofile;
    char *file;
    int flag;
    int mode = 0777;
    int fd;

#ifdef MS_WINDOWS
    PyUnicodeObject *po;
    if (PyArg_ParseTuple(args, "Ui|i:open", &po, &flag, &mode)) {
        Py_BEGIN_ALLOW_THREADS
        /* PyUnicode_AS_UNICODE OK without thread
           lock as it is a simple dereference. */
        fd = _wopen(PyUnicode_AS_UNICODE(po), flag, mode);
        Py_END_ALLOW_THREADS
        if (fd < 0)
            return posix_error();
        return PyLong_FromLong((long)fd);
    }
    /* Drop the argument parsing error as narrow strings
       are also valid. */
    PyErr_Clear();
#endif

    if (!PyArg_ParseTuple(args, "O&i|i:open",
                          PyUnicode_FSConverter, &ofile,
                          &flag, &mode))
        return NULL;
    file = PyBytes_AsString(ofile);
    Py_BEGIN_ALLOW_THREADS
    fd = open(file, flag, mode);
    Py_END_ALLOW_THREADS
    if (fd < 0)
        return posix_error_with_allocated_filename(ofile);
    Py_DECREF(ofile);
    return PyLong_FromLong((long)fd);
}

Here is the call graph for this function:

static PyObject* posix_pipe ( PyObject self,
PyObject noargs 
) [static]

Definition at line 5866 of file posixmodule.c.

{
#if defined(PYOS_OS2)
    HFILE read, write;
    APIRET rc;

    Py_BEGIN_ALLOW_THREADS
    rc = DosCreatePipe( &read, &write, 4096);
    Py_END_ALLOW_THREADS
    if (rc != NO_ERROR)
        return os2_error(rc);

    return Py_BuildValue("(ii)", read, write);
#else
#if !defined(MS_WINDOWS)
    int fds[2];
    int res;
    Py_BEGIN_ALLOW_THREADS
    res = pipe(fds);
    Py_END_ALLOW_THREADS
    if (res != 0)
        return posix_error();
    return Py_BuildValue("(ii)", fds[0], fds[1]);
#else /* MS_WINDOWS */
    HANDLE read, write;
    int read_fd, write_fd;
    BOOL ok;
    Py_BEGIN_ALLOW_THREADS
    ok = CreatePipe(&read, &write, NULL, 0);
    Py_END_ALLOW_THREADS
    if (!ok)
        return win32_error("CreatePipe", NULL);
    read_fd = _open_osfhandle((Py_intptr_t)read, 0);
    write_fd = _open_osfhandle((Py_intptr_t)write, 1);
    return Py_BuildValue("(ii)", read_fd, write_fd);
#endif /* MS_WINDOWS */
#endif
}

Here is the call graph for this function:

static PyObject* posix_read ( PyObject self,
PyObject args 
) [static]

Definition at line 5747 of file posixmodule.c.

{
    int fd, size;
    Py_ssize_t n;
    PyObject *buffer;
    if (!PyArg_ParseTuple(args, "ii:read", &fd, &size))
        return NULL;
    if (size < 0) {
        errno = EINVAL;
        return posix_error();
    }
    buffer = PyBytes_FromStringAndSize((char *)NULL, size);
    if (buffer == NULL)
        return NULL;
    if (!_PyVerify_fd(fd)) {
        Py_DECREF(buffer);
        return posix_error();
    }
    Py_BEGIN_ALLOW_THREADS
    n = read(fd, PyBytes_AS_STRING(buffer), size);
    Py_END_ALLOW_THREADS
    if (n < 0) {
        Py_DECREF(buffer);
        return posix_error();
    }
    if (n != size)
        _PyBytes_Resize(&buffer, n);
    return buffer;
}

Here is the call graph for this function:

static PyObject* posix_rename ( PyObject self,
PyObject args 
) [static]

Definition at line 3023 of file posixmodule.c.

{
#ifdef MS_WINDOWS
    PyObject *o1, *o2;
    char *p1, *p2;
    BOOL result;
    if (!PyArg_ParseTuple(args, "OO:rename", &o1, &o2))
        goto error;
    if (!convert_to_unicode(&o1))
        goto error;
    if (!convert_to_unicode(&o2)) {
        Py_DECREF(o1);
        goto error;
    }
    Py_BEGIN_ALLOW_THREADS
    result = MoveFileW(PyUnicode_AsUnicode(o1),
                       PyUnicode_AsUnicode(o2));
    Py_END_ALLOW_THREADS
    Py_DECREF(o1);
    Py_DECREF(o2);
    if (!result)
        return win32_error("rename", NULL);
    Py_INCREF(Py_None);
    return Py_None;
error:
    PyErr_Clear();
    if (!PyArg_ParseTuple(args, "ss:rename", &p1, &p2))
        return NULL;
    Py_BEGIN_ALLOW_THREADS
    result = MoveFileA(p1, p2);
    Py_END_ALLOW_THREADS
    if (!result)
        return win32_error("rename", NULL);
    Py_INCREF(Py_None);
    return Py_None;
#else
    return posix_2str(args, "O&O&:rename", rename);
#endif
}

Here is the call graph for this function:

static PyObject* posix_rmdir ( PyObject self,
PyObject args 
) [static]

Definition at line 3069 of file posixmodule.c.

{
#ifdef MS_WINDOWS
    return win32_1str(args, "rmdir", "y:rmdir", RemoveDirectoryA, "U:rmdir", RemoveDirectoryW);
#else
    return posix_1str(args, "O&:rmdir", rmdir);
#endif
}

Here is the call graph for this function:

static PyObject* posix_stat ( PyObject self,
PyObject args 
) [static]

Definition at line 3084 of file posixmodule.c.

{
#ifdef MS_WINDOWS
    return posix_do_stat(self, args, "O&:stat", STAT, "U:stat", win32_stat_w);
#else
    return posix_do_stat(self, args, "O&:stat", STAT, NULL, NULL);
#endif
}

Here is the call graph for this function:

static PyObject* posix_strerror ( PyObject self,
PyObject args 
) [static]

Definition at line 6225 of file posixmodule.c.

{
    int code;
    char *message;
    if (!PyArg_ParseTuple(args, "i:strerror", &code))
        return NULL;
    message = strerror(code);
    if (message == NULL) {
        PyErr_SetString(PyExc_ValueError,
                        "strerror() argument out of range");
        return NULL;
    }
    return PyUnicode_FromString(message);
}

Here is the call graph for this function:

static PyObject* posix_system ( PyObject self,
PyObject args 
) [static]

Definition at line 3100 of file posixmodule.c.

{
    long sts;
#ifdef MS_WINDOWS
    wchar_t *command;
    if (!PyArg_ParseTuple(args, "u:system", &command))
        return NULL;

    Py_BEGIN_ALLOW_THREADS
    sts = _wsystem(command);
    Py_END_ALLOW_THREADS
#else
    PyObject *command_obj;
    char *command;
    if (!PyArg_ParseTuple(args, "O&:system",
                          PyUnicode_FSConverter, &command_obj))
        return NULL;

    command = PyBytes_AsString(command_obj);
    Py_BEGIN_ALLOW_THREADS
    sts = system(command);
    Py_END_ALLOW_THREADS
    Py_DECREF(command_obj);
#endif
    return PyLong_FromLong(sts);
}

Here is the call graph for this function:

static PyObject* posix_ttyname ( PyObject self,
PyObject args 
) [static]

Definition at line 1862 of file posixmodule.c.

{
    int id;
    char *ret;

    if (!PyArg_ParseTuple(args, "i:ttyname", &id))
        return NULL;

#if defined(__VMS)
    /* file descriptor 0 only, the default input device (stdin) */
    if (id == 0) {
        ret = ttyname();
    }
    else {
        ret = NULL;
    }
#else
    ret = ttyname(id);
#endif
    if (ret == NULL)
        return posix_error();
    return PyUnicode_DecodeFSDefault(ret);
}

Here is the call graph for this function:

static PyObject* posix_umask ( PyObject self,
PyObject args 
) [static]

Definition at line 3134 of file posixmodule.c.

{
    int i;
    if (!PyArg_ParseTuple(args, "i:umask", &i))
        return NULL;
    i = (int)umask(i);
    if (i < 0)
        return posix_error();
    return PyLong_FromLong((long)i);
}

Here is the call graph for this function:

static PyObject* posix_unlink ( PyObject self,
PyObject args 
) [static]

Definition at line 3190 of file posixmodule.c.

{
#ifdef MS_WINDOWS
    return win32_1str(args, "remove", "y:remove", DeleteFileA,
                      "U:remove", Py_DeleteFileW);
#else
    return posix_1str(args, "O&:remove", unlink);
#endif
}

Here is the call graph for this function:

static PyObject* posix_utime ( PyObject self,
PyObject args 
) [static]

Definition at line 3270 of file posixmodule.c.

{
#ifdef MS_WINDOWS
    PyObject *arg;
    PyUnicodeObject *obwpath;
    wchar_t *wpath = NULL;
    PyObject *oapath;
    char *apath;
    HANDLE hFile;
    time_t atimesec, mtimesec;
    long ausec, musec;
    FILETIME atime, mtime;
    PyObject *result = NULL;

    if (PyArg_ParseTuple(args, "UO|:utime", &obwpath, &arg)) {
        wpath = PyUnicode_AS_UNICODE(obwpath);
        Py_BEGIN_ALLOW_THREADS
        hFile = CreateFileW(wpath, FILE_WRITE_ATTRIBUTES, 0,
                            NULL, OPEN_EXISTING,
                            FILE_FLAG_BACKUP_SEMANTICS, NULL);
        Py_END_ALLOW_THREADS
        if (hFile == INVALID_HANDLE_VALUE)
            return win32_error_unicode("utime", wpath);
    } else
        /* Drop the argument parsing error as narrow strings
           are also valid. */
        PyErr_Clear();

    if (!wpath) {
        if (!PyArg_ParseTuple(args, "O&O:utime",
                        PyUnicode_FSConverter, &oapath, &arg))
            return NULL;
        apath = PyBytes_AsString(oapath);
        Py_BEGIN_ALLOW_THREADS
        hFile = CreateFileA(apath, FILE_WRITE_ATTRIBUTES, 0,
                            NULL, OPEN_EXISTING,
                            FILE_FLAG_BACKUP_SEMANTICS, NULL);
        Py_END_ALLOW_THREADS
        if (hFile == INVALID_HANDLE_VALUE) {
            win32_error("utime", apath);
            Py_DECREF(oapath);
            return NULL;
        }
        Py_DECREF(oapath);
    }

    if (arg == Py_None) {
        SYSTEMTIME now;
        GetSystemTime(&now);
        if (!SystemTimeToFileTime(&now, &mtime) ||
            !SystemTimeToFileTime(&now, &atime)) {
            win32_error("utime", NULL);
            goto done;
        }
    }
    else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
        PyErr_SetString(PyExc_TypeError,
                        "utime() arg 2 must be a tuple (atime, mtime)");
        goto done;
    }
    else {
        if (extract_time(PyTuple_GET_ITEM(arg, 0),
                         &atimesec, &ausec) == -1)
            goto done;
        time_t_to_FILE_TIME(atimesec, 1000*ausec, &atime);
        if (extract_time(PyTuple_GET_ITEM(arg, 1),
                         &mtimesec, &musec) == -1)
            goto done;
        time_t_to_FILE_TIME(mtimesec, 1000*musec, &mtime);
    }
    if (!SetFileTime(hFile, NULL, &atime, &mtime)) {
        /* Avoid putting the file name into the error here,
           as that may confuse the user into believing that
           something is wrong with the file, when it also
           could be the time stamp that gives a problem. */
        win32_error("utime", NULL);
        goto done;
    }
    Py_INCREF(Py_None);
    result = Py_None;
done:
    CloseHandle(hFile);
    return result;
#else /* MS_WINDOWS */

    PyObject *opath;
    char *path;
    time_t atime, mtime;
    long ausec, musec;
    int res;
    PyObject* arg;

#if defined(HAVE_UTIMES)
    struct timeval buf[2];
#define ATIME buf[0].tv_sec
#define MTIME buf[1].tv_sec
#elif defined(HAVE_UTIME_H)
/* XXX should define struct utimbuf instead, above */
    struct utimbuf buf;
#define ATIME buf.actime
#define MTIME buf.modtime
#define UTIME_ARG &buf
#else /* HAVE_UTIMES */
    time_t buf[2];
#define ATIME buf[0]
#define MTIME buf[1]
#define UTIME_ARG buf
#endif /* HAVE_UTIMES */


    if (!PyArg_ParseTuple(args, "O&O:utime",
                          PyUnicode_FSConverter, &opath, &arg))
        return NULL;
    path = PyBytes_AsString(opath);
    if (arg == Py_None) {
        /* optional time values not given */
        Py_BEGIN_ALLOW_THREADS
        res = utime(path, NULL);
        Py_END_ALLOW_THREADS
    }
    else if (!PyTuple_Check(arg) || PyTuple_Size(arg) != 2) {
        PyErr_SetString(PyExc_TypeError,
                        "utime() arg 2 must be a tuple (atime, mtime)");
        Py_DECREF(opath);
        return NULL;
    }
    else {
        if (extract_time(PyTuple_GET_ITEM(arg, 0),
                         &atime, &ausec) == -1) {
            Py_DECREF(opath);
            return NULL;
        }
        if (extract_time(PyTuple_GET_ITEM(arg, 1),
                         &mtime, &musec) == -1) {
            Py_DECREF(opath);
            return NULL;
        }
        ATIME = atime;
        MTIME = mtime;
#ifdef HAVE_UTIMES
        buf[0].tv_usec = ausec;
        buf[1].tv_usec = musec;
        Py_BEGIN_ALLOW_THREADS
        res = utimes(path, buf);
        Py_END_ALLOW_THREADS
#else
        Py_BEGIN_ALLOW_THREADS
        res = utime(path, UTIME_ARG);
        Py_END_ALLOW_THREADS
#endif /* HAVE_UTIMES */
    }
    if (res < 0) {
        return posix_error_with_allocated_filename(opath);
    }
    Py_DECREF(opath);
    Py_INCREF(Py_None);
    return Py_None;
#undef UTIME_ARG
#undef ATIME
#undef MTIME
#endif /* MS_WINDOWS */
}

Here is the call graph for this function:

static PyObject* posix_wait ( PyObject self,
PyObject noargs 
) [static]

Definition at line 5128 of file posixmodule.c.

{
    pid_t pid;
    WAIT_TYPE status;
    WAIT_STATUS_INT(status) = 0;

    Py_BEGIN_ALLOW_THREADS
    pid = wait(&status);
    Py_END_ALLOW_THREADS
    if (pid == -1)
        return posix_error();

    return Py_BuildValue("Ni", PyLong_FromPid(pid), WAIT_STATUS_INT(status));
}

Here is the call graph for this function:

static PyObject* posix_write ( PyObject self,
PyObject args 
) [static]

Definition at line 5783 of file posixmodule.c.

{
    Py_buffer pbuf;
    int fd;
    Py_ssize_t size, len;

    if (!PyArg_ParseTuple(args, "iy*:write", &fd, &pbuf))
        return NULL;
    if (!_PyVerify_fd(fd)) {
        PyBuffer_Release(&pbuf);
        return posix_error();
    }
    len = pbuf.len;
    Py_BEGIN_ALLOW_THREADS
#if defined(MS_WIN64) || defined(MS_WINDOWS)
    if (len > INT_MAX)
        len = INT_MAX;
    size = write(fd, pbuf.buf, (int)len);
#else
    size = write(fd, pbuf.buf, len);
#endif
    Py_END_ALLOW_THREADS
    PyBuffer_Release(&pbuf);
    if (size < 0)
        return posix_error();
    return PyLong_FromSsize_t(size);
}

Here is the call graph for this function:

PyDoc_STRVAR ( posix__doc__  ,
"This module provides access to operating system functionality that is\n\standardized by the C Standard and the POSIX standard (a thinly\n\disguised Unix interface). Refer to the library manual and\n\corresponding Unix manual entries for more information on calls."   
)
PyDoc_STRVAR ( 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\Posix/windows:If your platform supports  st_blksize,
st_blocks  ,
st_rdev  ,
\n\or  st_flags,
they are available as attributes only.\n\\n\See os.stat for more information."   
)
PyDoc_STRVAR ( statvfs_result__doc__  ,
"statvfs_result: Result from statvfs or fstatvfs.\n\n\This object may be accessed either as a tuple of\n\   bsize, frsize, blocks, bfree, bavail, files, ffree, favail, flag, namemax,
\n\or via the attributes  f_bsize,
f_frsize  ,
f_blocks  ,
f_bfree  ,
and so on.\n\\n\See os.statvfs for more information."   
)
PyDoc_STRVAR ( stat_float_times__doc__  ,
"stat_float_times([newval]) -> oldval\n\n\Determine whether os.stat represents time stamps as float objects.\n\If newval is  True[lf],
future calls to stat() return  floats,
if it is  False,
\n\future calls return ints.\n\If newval is  omitted,
return the current setting.\n  
)
PyDoc_STRVAR ( posix_access__doc__  ,
"access(path, mode) -> True if  granted,
False otherwise\n\n\Use the real uid/gid to test for access to a path.Note that most\n\operations will use the effective uid/  gid,
therefore this routine can\n\be used in a suid/sgid environment to test if the invoking user has the\n\specified access to the path.The mode argument can be F_OK to test\n\  existence,
or the inclusive-OR of  R_OK,
W_OK  ,
and X_OK."   
)
PyDoc_STRVAR ( posix_ttyname__doc__  ,
"ttyname(fd) -> string\n\n\Return the name of the terminal device connected to 'fd'."   
)
PyDoc_STRVAR ( posix_chdir__doc__  ,
"chdir(path)\n\n\Change the current working directory to the specified path."   
)
PyDoc_STRVAR ( posix_chmod__doc__  ,
"chmod(path, mode)\n\n\Change the access permissions of a file."   
)
PyDoc_STRVAR ( posix_getcwd__doc__  ,
"getcwd() -> path\n\n\Return a unicode string representing the current working directory."   
)
PyDoc_STRVAR ( posix_getcwdb__doc__  ,
"getcwdb() -> path\n\n\Return a bytes string representing the current working directory."   
)
PyDoc_STRVAR ( posix_listdir__doc__  ,
"listdir([path]) -> list_of_strings\n\n\Return a list containing the names of the entries in the directory.\n\\n\ path: path of directory to list (default: '.')\n\\n\The list is in arbitrary order. It does not include the special\n\entries '.' and '..' even if they are present in the directory."   
)
PyDoc_STRVAR ( posix_mkdir__doc__  ,
"mkdir(path [, mode=0777])\n\n\Create a directory."   
)
PyDoc_STRVAR ( posix_rename__doc__  ,
"rename(old, new)\n\n\Rename a file or directory."   
)
PyDoc_STRVAR ( posix_rmdir__doc__  ,
"rmdir(path)\n\n\Remove a directory."   
)
PyDoc_STRVAR ( posix_stat__doc__  ,
"stat(path) -> stat result\n\n\Perform a stat system call on the given path."   
)
PyDoc_STRVAR ( posix_system__doc__  ,
"system(command) -> exit_status\n\n\Execute the command (a string) in a subshell."   
)
PyDoc_STRVAR ( posix_umask__doc__  ,
"umask(new_mask) -> old_mask\n\n\Set the current numeric umask and return the previous umask."   
)
PyDoc_STRVAR ( posix_unlink__doc__  ,
"unlink(path)\n\n\Remove a file (same as remove(path))."   
)
PyDoc_STRVAR ( posix_remove__doc__  ,
"remove(path)\n\n\Remove a file (same as unlink(path))."   
)
PyDoc_STRVAR ( posix_utime__doc__  ,
"utime(path, (atime, mtime))\n\utime(path, None)\n\n\Set the access and modified time of the file to the given values. If the\n\second form is  used,
set the access and modified times to the current time."   
)
PyDoc_STRVAR ( posix__exit__doc__  ,
"_exit(status)\n\n\Exit to the system with specified  status,
without normal exit processing."   
)
PyDoc_STRVAR ( posix_execv__doc__  ,
"execv(path, args)\n\n\Execute an executable path with  arguments,
replacing current process.\n\\n\path:path of executable file\n\args:tuple or list of strings"   
)
PyDoc_STRVAR ( posix_execve__doc__  ,
"execve(path, args, env)\n\n\Execute a path with arguments and  environment,
replacing current process.\n\\n\path:path of executable file\n\args:tuple or list of arguments\n\env:dictionary of strings mapping to strings"   
)
PyDoc_STRVAR ( posix_fork__doc__  ,
"fork() -> pid\n\n\Fork a child process.\n\Return 0 to child process and PID of child to parent process."   
)
PyDoc_STRVAR ( posix_getegid__doc__  ,
"getegid() -> egid\n\n\Return the current process's effective group id."   
)
PyDoc_STRVAR ( posix_geteuid__doc__  ,
"geteuid() -> euid\n\n\Return the current process's effective user id."   
)
PyDoc_STRVAR ( posix_getgid__doc__  ,
"getgid() -> gid\n\n\Return the current process's group id."   
)
PyDoc_STRVAR ( posix_getpid__doc__  ,
"getpid() -> pid\n\n\Return the current process id"   
)
PyDoc_STRVAR ( posix_getppid__doc__  ,
"getppid() -> ppid\n\n\Return the parent's process id. If the parent process has already  exited,
\n\Windows machines will still return its id;others systems will return the id\n\of the 'init'process(1)."   
)
PyDoc_STRVAR ( posix_getuid__doc__  ,
"getuid() -> uid\n\n\Return the current process's user id."   
)
PyDoc_STRVAR ( posix_kill__doc__  ,
"kill(pid, sig)\n\n\Kill a process with a signal."   
)
PyDoc_STRVAR ( posix_wait__doc__  ,
"wait() -> (pid, status)\n\n\Wait for completion of a child process."   
)
PyDoc_STRVAR ( posix_lstat__doc__  ,
lstatpath) -> stat result\n\n\Like stat(path,
but do not follow symbolic links."   
)
PyDoc_STRVAR ( posix_open__doc__  ,
"open(filename, flag [, mode=0777]) -> fd\n\n\Open a file (for low level IO)."   
)
PyDoc_STRVAR ( posix_close__doc__  ,
"close(fd)\n\n\Close a file descriptor (for low level IO)."   
)
PyDoc_STRVAR ( posix_closerange__doc__  ,
"closerange(fd_low, fd_high)\n\n\Closes all file descriptors in [  fd_low,
fd_high   
)
PyDoc_STRVAR ( posix_dup__doc__  ,
"dup(fd) -> fd2\n\n\Return a duplicate of a file descriptor."   
)
PyDoc_STRVAR ( posix_dup2__doc__  ,
"dup2(old_fd, new_fd)\n\n\Duplicate file descriptor."   
)
PyDoc_STRVAR ( posix_lseek__doc__  ,
"lseek(fd, pos, how) -> newpos\n\n\Set the current position of a file descriptor."   
)
PyDoc_STRVAR ( posix_read__doc__  ,
"read(fd, buffersize) -> string\n\n\Read a file descriptor."   
)
PyDoc_STRVAR ( posix_write__doc__  ,
"write(fd, string) -> byteswritten\n\n\Write a string to a file descriptor."   
)
PyDoc_STRVAR ( posix_fstat__doc__  ,
fstatfd) -> stat result\n\n\Like stat(,
but for an open file descriptor."   
)
PyDoc_STRVAR ( posix_isatty__doc__  ,
"isatty(fd) -> bool\n\n\Return True if the file descriptor 'fd' is an open file descriptor\n\connected to the slave end of a terminal."   
)
PyDoc_STRVAR ( posix_pipe__doc__  ,
"pipe() -> (read_end, write_end)\n\n\Create a pipe."   
)
PyDoc_STRVAR ( posix_strerror__doc__  ,
"strerror(code) -> string\n\n\Translate an error code to a message string."   
)
PyDoc_STRVAR ( posix_abort__doc__  ,
"abort() -> does not return!\n\n\Abort the interpreter immediately. This 'dumps core' or otherwise fails\n\in the hardest way possible on the hosting operating system."   
)
PyDoc_STRVAR ( device_encoding__doc__  ,
"device_encoding(fd) -> str\n\n\Return a string describing the encoding of the device\n\if the output is a terminal; else return None."   
)
int rename ( const char *  ,
const char *   
)

Here is the caller graph for this function:

int rmdir ( const char *  )

Here is the caller graph for this function:

static int setup_confname_table ( struct constdef table,
size_t  tablesize,
char *  tablename,
PyObject module 
) [static]

Definition at line 7459 of file posixmodule.c.

{
    PyObject *d = NULL;
    size_t i;

    qsort(table, tablesize, sizeof(struct constdef), cmp_constdefs);
    d = PyDict_New();
    if (d == NULL)
        return -1;

    for (i=0; i < tablesize; ++i) {
        PyObject *o = PyLong_FromLong(table[i].value);
        if (o == NULL || PyDict_SetItemString(d, table[i].name, o) == -1) {
            Py_XDECREF(o);
            Py_DECREF(d);
            return -1;
        }
        Py_DECREF(o);
    }
    return PyModule_AddObject(module, tablename, d);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int setup_confname_tables ( PyObject module) [static]

Definition at line 7484 of file posixmodule.c.

{
#if defined(HAVE_FPATHCONF) || defined(HAVE_PATHCONF)
    if (setup_confname_table(posix_constants_pathconf,
                             sizeof(posix_constants_pathconf)
                               / sizeof(struct constdef),
                             "pathconf_names", module))
        return -1;
#endif
#ifdef HAVE_CONFSTR
    if (setup_confname_table(posix_constants_confstr,
                             sizeof(posix_constants_confstr)
                               / sizeof(struct constdef),
                             "confstr_names", module))
        return -1;
#endif
#ifdef HAVE_SYSCONF
    if (setup_confname_table(posix_constants_sysconf,
                             sizeof(posix_constants_sysconf)
                               / sizeof(struct constdef),
                             "sysconf_names", module))
        return -1;
#endif
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int stat ( const char *  ,
struct stat  
)

Here is the caller graph for this function:

static PyObject* stat_float_times ( PyObject self,
PyObject args 
) [static]

Definition at line 1587 of file posixmodule.c.

{
    int newval = -1;
    if (!PyArg_ParseTuple(args, "|i:stat_float_times", &newval))
        return NULL;
    if (newval == -1)
        /* Return old value */
        return PyBool_FromLong(_stat_float_times);
    _stat_float_times = newval;
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* statresult_new ( PyTypeObject type,
PyObject args,
PyObject kwds 
) [static]

Definition at line 1553 of file posixmodule.c.

{
    PyStructSequence *result;
    int i;

    result = (PyStructSequence*)structseq_new(type, args, kwds);
    if (!result)
        return NULL;
    /* If we have been initialized from a tuple,
       st_?time might be set to None. Initialize it
       from the int slots.  */
    for (i = 7; i <= 9; i++) {
        if (result->ob_item[i+3] == Py_None) {
            Py_DECREF(Py_None);
            Py_INCREF(result->ob_item[i]);
            result->ob_item[i+3] = result->ob_item[i];
        }
    }
    return (PyObject*)result;
}

Here is the caller graph for this function:

char* strerror ( int  )

Here is the caller graph for this function:

int unlink ( const char *  )

Variable Documentation

int _stat_float_times = 1 [static]

Definition at line 1577 of file posixmodule.c.

char** environ

Definition at line 305 of file os.py.

int initialized [static]

Definition at line 1547 of file posixmodule.c.

Definition at line 7850 of file posixmodule.c.

struct PyModuleDef [static]
Initial value:
 {
    PyModuleDef_HEAD_INIT,
    MODNAME,
    posix__doc__,
    -1,
    posix_methods,
    NULL,
    NULL,
    NULL,
    NULL
}

Definition at line 8502 of file posixmodule.c.

Initial value:
 {
    "stat_result", 
    stat_result__doc__, 
    stat_result_fields,
    10
}

Definition at line 1511 of file posixmodule.c.

Definition at line 1439 of file posixmodule.c.

Definition at line 1548 of file posixmodule.c.

Initial value:
 {
    "statvfs_result", 
    statvfs_result__doc__, 
    statvfs_result_fields,
    10
}

Definition at line 1540 of file posixmodule.c.

Initial value:
 {
    {"f_bsize",  },
    {"f_frsize", },
    {"f_blocks", },
    {"f_bfree",  },
    {"f_bavail", },
    {"f_files",  },
    {"f_ffree",  },
    {"f_favail", },
    {"f_flag",   },
    {"f_namemax",},
    {0}
}

Definition at line 1526 of file posixmodule.c.

Definition at line 1549 of file posixmodule.c.

Definition at line 1550 of file posixmodule.c.