blob: 4bbe6e6c35b0b72712b6f2657bc43cd8e8cb2a83 [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 Drake215fe2f1999-02-02 19:02:35 +000014module \refmodule{os}, which provides a \emph{portable} version of this
Fred Drake75aae9a1998-03-11 05:29:58 +000015interface. 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
Fred Drake215fe2f1999-02-02 19:02:35 +000033
Fred Drakebb3b0021999-01-11 18:36:23 +000034\subsection{Large File Support \label{posix-large-files}}
Fred Drake215fe2f1999-02-02 19:02:35 +000035\sectionauthor{Steve Clift}{clift@mail.anacapa.net}
Fred Drakebb3b0021999-01-11 18:36:23 +000036\index{large files}
37\index{file!large files}
38
Fred Drakebb3b0021999-01-11 18:36:23 +000039
40Several operating systems (including AIX, HPUX, Irix and Solaris)
Fred Drake68a8c691999-02-01 20:23:02 +000041provide support for files that are larger than 2 Gb from a C
Fred Drakebb3b0021999-01-11 18:36:23 +000042programming model where \ctype{int} and \ctype{long} are 32-bit
43values. This is typically accomplished by defining the relevant size
44and offset types as 64-bit values. Such files are sometimes referred
45to as \dfn{large files}.
46
47Large file support is enabled in Python when the size of an
48\ctype{off_t} is larger than a \ctype{long} and the \ctype{long long}
49type is available and is at least as large as an \ctype{off_t}. Python
50longs are then used to represent file sizes, offsets and other values
51that can exceed the range of a Python int. It may be necessary to
52configure and compile Python with certain compiler flags to enable
53this mode. For example, it is enabled by default with recent versions
54of Irix, but with Solaris 2.6 and 2.7 you need to do something like:
55
56\begin{verbatim}
57CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" OPT="-g -O2 $CFLAGS" \
58 configure
59\end{verbatim} % $ <-- bow to font-lock
60
61
Fred Drake215fe2f1999-02-02 19:02:35 +000062\subsection{Module Contents \label{posix-contents}}
63
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000064
Fred Drake68a8c691999-02-01 20:23:02 +000065Module \module{posix} defines the following data item:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000066
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000067\begin{datadesc}{environ}
Fred Drake68a8c691999-02-01 20:23:02 +000068A dictionary representing the string environment at the time the
69interpreter was started. For example, \code{environ['HOME']} is the
70pathname of your home directory, equivalent to \code{getenv("HOME")}
71in C.
Guido van Rossum9c43c591997-08-08 21:05:09 +000072
Guido van Rossum470be141995-03-17 16:07:09 +000073Modifying this dictionary does not affect the string environment
Fred Drake75aae9a1998-03-11 05:29:58 +000074passed on by \function{execv()}, \function{popen()} or
75\function{system()}; if you need to change the environment, pass
76\code{environ} to \function{execve()} or add variable assignments and
77export statements to the command string for \function{system()} or
78\function{popen()}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000079
Fred Drake215fe2f1999-02-02 19:02:35 +000080\strong{Note:} The \refmodule{os} module provides an alternate
Fred Drake68a8c691999-02-01 20:23:02 +000081implementation of \code{environ} which updates the environment on
82modification. Note also that updating \code{os.environ} will render
Fred Drake215fe2f1999-02-02 19:02:35 +000083this dictionary obsolete. Use of the \refmodule{os} for this is
Fred Drake68a8c691999-02-01 20:23:02 +000084recommended over direct access to the \module{posix} module.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000085\end{datadesc}
86
Fred Drake68a8c691999-02-01 20:23:02 +000087Additional contents of this module should only be accessed via the
Fred Drake215fe2f1999-02-02 19:02:35 +000088\refmodule{os} module; refer to the documentation for that module for
Fred Drake68a8c691999-02-01 20:23:02 +000089further information.