| 1 | \section{\module{posix} ---
|
|---|
| 2 | The most common \POSIX{} system calls}
|
|---|
| 3 |
|
|---|
| 4 | \declaremodule{builtin}{posix}
|
|---|
| 5 | \platform{Unix}
|
|---|
| 6 | \modulesynopsis{The most common \POSIX\ system calls (normally used
|
|---|
| 7 | via module \refmodule{os}).}
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | This module provides access to operating system functionality that is
|
|---|
| 11 | standardized by the C Standard and the \POSIX{} standard (a thinly
|
|---|
| 12 | disguised \UNIX{} interface).
|
|---|
| 13 |
|
|---|
| 14 | \strong{Do not import this module directly.} Instead, import the
|
|---|
| 15 | module \refmodule{os}, which provides a \emph{portable} version of this
|
|---|
| 16 | interface. On \UNIX, the \refmodule{os} module provides a superset of
|
|---|
| 17 | the \module{posix} interface. On non-\UNIX{} operating systems the
|
|---|
| 18 | \module{posix} module is not available, but a subset is always
|
|---|
| 19 | available through the \refmodule{os} interface. Once \refmodule{os} is
|
|---|
| 20 | imported, there is \emph{no} performance penalty in using it instead
|
|---|
| 21 | of \module{posix}. In addition, \refmodule{os}\refstmodindex{os}
|
|---|
| 22 | provides some additional functionality, such as automatically calling
|
|---|
| 23 | \function{putenv()} when an entry in \code{os.environ} is changed.
|
|---|
| 24 |
|
|---|
| 25 | The descriptions below are very terse; refer to the corresponding
|
|---|
| 26 | \UNIX{} manual (or \POSIX{} documentation) entry for more information.
|
|---|
| 27 | Arguments called \var{path} refer to a pathname given as a string.
|
|---|
| 28 |
|
|---|
| 29 | Errors are reported as exceptions; the usual exceptions are given for
|
|---|
| 30 | type errors, while errors reported by the system calls raise
|
|---|
| 31 | \exception{error} (a synonym for the standard exception
|
|---|
| 32 | \exception{OSError}), described below.
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | \subsection{Large File Support \label{posix-large-files}}
|
|---|
| 36 | \sectionauthor{Steve Clift}{[email protected]}
|
|---|
| 37 | \index{large files}
|
|---|
| 38 | \index{file!large files}
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | Several operating systems (including AIX, HPUX, Irix and Solaris)
|
|---|
| 42 | provide support for files that are larger than 2 Gb from a C
|
|---|
| 43 | programming model where \ctype{int} and \ctype{long} are 32-bit
|
|---|
| 44 | values. This is typically accomplished by defining the relevant size
|
|---|
| 45 | and offset types as 64-bit values. Such files are sometimes referred
|
|---|
| 46 | to as \dfn{large files}.
|
|---|
| 47 |
|
|---|
| 48 | Large file support is enabled in Python when the size of an
|
|---|
| 49 | \ctype{off_t} is larger than a \ctype{long} and the \ctype{long long}
|
|---|
| 50 | type is available and is at least as large as an \ctype{off_t}. Python
|
|---|
| 51 | longs are then used to represent file sizes, offsets and other values
|
|---|
| 52 | that can exceed the range of a Python int. It may be necessary to
|
|---|
| 53 | configure and compile Python with certain compiler flags to enable
|
|---|
| 54 | this mode. For example, it is enabled by default with recent versions
|
|---|
| 55 | of Irix, but with Solaris 2.6 and 2.7 you need to do something like:
|
|---|
| 56 |
|
|---|
| 57 | \begin{verbatim}
|
|---|
| 58 | CFLAGS="`getconf LFS_CFLAGS`" OPT="-g -O2 $CFLAGS" \
|
|---|
| 59 | ./configure
|
|---|
| 60 | \end{verbatim} % $ <-- bow to font-lock
|
|---|
| 61 |
|
|---|
| 62 | On large-file-capable Linux systems, this might work:
|
|---|
| 63 |
|
|---|
| 64 | \begin{verbatim}
|
|---|
| 65 | CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" \
|
|---|
| 66 | ./configure
|
|---|
| 67 | \end{verbatim} % $ <-- bow to font-lock
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | \subsection{Module Contents \label{posix-contents}}
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | Module \module{posix} defines the following data item:
|
|---|
| 74 |
|
|---|
| 75 | \begin{datadesc}{environ}
|
|---|
| 76 | A dictionary representing the string environment at the time the
|
|---|
| 77 | interpreter was started. For example, \code{environ['HOME']} is the
|
|---|
| 78 | pathname of your home directory, equivalent to
|
|---|
| 79 | \code{getenv("HOME")} in C.
|
|---|
| 80 |
|
|---|
| 81 | Modifying this dictionary does not affect the string environment
|
|---|
| 82 | passed on by \function{execv()}, \function{popen()} or
|
|---|
| 83 | \function{system()}; if you need to change the environment, pass
|
|---|
| 84 | \code{environ} to \function{execve()} or add variable assignments and
|
|---|
| 85 | export statements to the command string for \function{system()} or
|
|---|
| 86 | \function{popen()}.
|
|---|
| 87 |
|
|---|
| 88 | \note{The \refmodule{os} module provides an alternate
|
|---|
| 89 | implementation of \code{environ} which updates the environment on
|
|---|
| 90 | modification. Note also that updating \code{os.environ} will render
|
|---|
| 91 | this dictionary obsolete. Use of the \refmodule{os} module version of
|
|---|
| 92 | this is recommended over direct access to the \module{posix} module.}
|
|---|
| 93 | \end{datadesc}
|
|---|
| 94 |
|
|---|
| 95 | Additional contents of this module should only be accessed via the
|
|---|
| 96 | \refmodule{os} module; refer to the documentation for that module for
|
|---|
| 97 | further information.
|
|---|