blob: 843159971ef3a4d8292e30ffb334725da494088c [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{posix} ---
2 The most common \POSIX{} system calls.}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{builtin}{posix}
4
Fred Drakebb3b0021999-01-11 18:36:23 +00005\modulesynopsis{The most common \POSIX{} system calls (normally used
6via module \module{os}).}
Fred Drakeb91e9341998-07-23 17:59:49 +00007
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008
9This module provides access to operating system functionality that is
Fred Drake68a8c691999-02-01 20:23:02 +000010standardized by the C Standard and the \POSIX{} standard (a thinly
Fred Drake75aae9a1998-03-11 05:29:58 +000011disguised \UNIX{} interface).
Guido van Rossum470be141995-03-17 16:07:09 +000012
13\strong{Do not import this module directly.} Instead, import the
Fred Drake75aae9a1998-03-11 05:29:58 +000014module \module{os}, which provides a \emph{portable} version of this
15interface. On \UNIX{}, the \module{os} module provides a superset of
16the \module{posix} interface. On non-\UNIX{} operating systems the
17\module{posix} module is not available, but a subset is always
18available through the \module{os} interface. Once \module{os} is
19imported, there is \emph{no} performance penalty in using it instead
Fred Drakebb3b0021999-01-11 18:36:23 +000020of \module{posix}. In addition, \module{os}\refstmodindex{os}
21provides some additional functionality, such as automatically calling
22\function{putenv()} when an entry in \code{os.environ} is changed.
Guido van Rossum470be141995-03-17 16:07:09 +000023
Guido van Rossum282290f1997-08-27 14:54:25 +000024The descriptions below are very terse; refer to the corresponding
Fred Drake65b32f71998-02-09 20:27:12 +000025\UNIX{} manual (or \POSIX{} documentation) entry for more information.
Guido van Rossum282290f1997-08-27 14:54:25 +000026Arguments called \var{path} refer to a pathname given as a string.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000027
Barry Warsaweef2cd11998-07-23 19:50:09 +000028Errors are reported as exceptions; the usual exceptions are given for
29type errors, while errors reported by the system calls raise
30\exception{error} (a synonym for the standard exception
Fred Drakebb3b0021999-01-11 18:36:23 +000031\exception{OSError}), described below.
32
33\subsection{Large File Support \label{posix-large-files}}
34\index{large files}
35\index{file!large files}
36
37\sectionauthor{Steve Clift}{clift@mail.anacapa.net}
38
39Several operating systems (including AIX, HPUX, Irix and Solaris)
Fred Drake68a8c691999-02-01 20:23:02 +000040provide support for files that are larger than 2 Gb from a C
Fred Drakebb3b0021999-01-11 18:36:23 +000041programming model where \ctype{int} and \ctype{long} are 32-bit
42values. This is typically accomplished by defining the relevant size
43and offset types as 64-bit values. Such files are sometimes referred
44to as \dfn{large files}.
45
46Large file support is enabled in Python when the size of an
47\ctype{off_t} is larger than a \ctype{long} and the \ctype{long long}
48type is available and is at least as large as an \ctype{off_t}. Python
49longs are then used to represent file sizes, offsets and other values
50that can exceed the range of a Python int. It may be necessary to
51configure and compile Python with certain compiler flags to enable
52this mode. For example, it is enabled by default with recent versions
53of Irix, but with Solaris 2.6 and 2.7 you need to do something like:
54
55\begin{verbatim}
56CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" OPT="-g -O2 $CFLAGS" \
57 configure
58\end{verbatim} % $ <-- bow to font-lock
59
60
61\subsection{\module{posix} Module Contents \label{posix-contents}}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000062
Fred Drake68a8c691999-02-01 20:23:02 +000063Module \module{posix} defines the following data item:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000064
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000065\begin{datadesc}{environ}
Fred Drake68a8c691999-02-01 20:23:02 +000066A dictionary representing the string environment at the time the
67interpreter was started. For example, \code{environ['HOME']} is the
68pathname of your home directory, equivalent to \code{getenv("HOME")}
69in C.
Guido van Rossum9c43c591997-08-08 21:05:09 +000070
Guido van Rossum470be141995-03-17 16:07:09 +000071Modifying this dictionary does not affect the string environment
Fred Drake75aae9a1998-03-11 05:29:58 +000072passed on by \function{execv()}, \function{popen()} or
73\function{system()}; if you need to change the environment, pass
74\code{environ} to \function{execve()} or add variable assignments and
75export statements to the command string for \function{system()} or
76\function{popen()}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000077
Fred Drake68a8c691999-02-01 20:23:02 +000078\strong{Note:} The \module{os} module provides an alternate
79implementation of \code{environ} which updates the environment on
80modification. Note also that updating \code{os.environ} will render
81this dictionary obsolete. Use of the \module{os} for this is
82recommended over direct access to the \module{posix} module.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000083\end{datadesc}
84
Fred Drake68a8c691999-02-01 20:23:02 +000085Additional contents of this module should only be accessed via the
86\module{os} module; refer to the documentation for that module for
87further information.