blob: aee6c0db35fe9f2b89f30ca0c2a143dd188de685 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{posix} ---
Fred Drakef6863c11999-03-02 16:37:17 +00002 The most common \POSIX{} system calls}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakef6863c11999-03-02 16:37:17 +00004\declaremodule{builtin}{posix}
Fred Drakea54a8871999-03-02 17:03:42 +00005 \platform{Unix}
Fred Drakec116b822001-05-09 15:50:17 +00006\modulesynopsis{The most common \POSIX\ system calls (normally used
Fred Drakeb2160601999-07-01 13:53:32 +00007 via module \refmodule{os}).}
Fred Drakeb91e9341998-07-23 17:59:49 +00008
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00009
10This module provides access to operating system functionality that is
Fred Drake68a8c691999-02-01 20:23:02 +000011standardized by the C Standard and the \POSIX{} standard (a thinly
Fred Drake75aae9a1998-03-11 05:29:58 +000012disguised \UNIX{} interface).
Guido van Rossum470be141995-03-17 16:07:09 +000013
14\strong{Do not import this module directly.} Instead, import the
Fred Drake215fe2f1999-02-02 19:02:35 +000015module \refmodule{os}, which provides a \emph{portable} version of this
Fred Drakec37b65e2001-11-28 07:26:15 +000016interface. On \UNIX, the \refmodule{os} module provides a superset of
Fred Drake75aae9a1998-03-11 05:29:58 +000017the \module{posix} interface. On non-\UNIX{} operating systems the
18\module{posix} module is not available, but a subset is always
Fred Drake2799f9d1999-04-21 18:33:47 +000019available through the \refmodule{os} interface. Once \refmodule{os} is
Fred Drake75aae9a1998-03-11 05:29:58 +000020imported, there is \emph{no} performance penalty in using it instead
Fred Drake2799f9d1999-04-21 18:33:47 +000021of \module{posix}. In addition, \refmodule{os}\refstmodindex{os}
Fred Drakebb3b0021999-01-11 18:36:23 +000022provides some additional functionality, such as automatically calling
23\function{putenv()} when an entry in \code{os.environ} is changed.
Guido van Rossum470be141995-03-17 16:07:09 +000024
Guido van Rossum282290f1997-08-27 14:54:25 +000025The descriptions below are very terse; refer to the corresponding
Fred Drake65b32f71998-02-09 20:27:12 +000026\UNIX{} manual (or \POSIX{} documentation) entry for more information.
Guido van Rossum282290f1997-08-27 14:54:25 +000027Arguments called \var{path} refer to a pathname given as a string.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000028
Barry Warsaweef2cd11998-07-23 19:50:09 +000029Errors are reported as exceptions; the usual exceptions are given for
30type errors, while errors reported by the system calls raise
31\exception{error} (a synonym for the standard exception
Fred Drakebb3b0021999-01-11 18:36:23 +000032\exception{OSError}), described below.
33
Fred Drake215fe2f1999-02-02 19:02:35 +000034
Fred Drakebb3b0021999-01-11 18:36:23 +000035\subsection{Large File Support \label{posix-large-files}}
Fred Drake215fe2f1999-02-02 19:02:35 +000036\sectionauthor{Steve Clift}{clift@mail.anacapa.net}
Fred Drakebb3b0021999-01-11 18:36:23 +000037\index{large files}
38\index{file!large files}
39
Fred Drakebb3b0021999-01-11 18:36:23 +000040
41Several operating systems (including AIX, HPUX, Irix and Solaris)
Fred Drake68a8c691999-02-01 20:23:02 +000042provide support for files that are larger than 2 Gb from a C
Fred Drakebb3b0021999-01-11 18:36:23 +000043programming model where \ctype{int} and \ctype{long} are 32-bit
44values. This is typically accomplished by defining the relevant size
45and offset types as 64-bit values. Such files are sometimes referred
46to as \dfn{large files}.
47
48Large 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}
50type is available and is at least as large as an \ctype{off_t}. Python
51longs are then used to represent file sizes, offsets and other values
52that can exceed the range of a Python int. It may be necessary to
53configure and compile Python with certain compiler flags to enable
54this mode. For example, it is enabled by default with recent versions
55of Irix, but with Solaris 2.6 and 2.7 you need to do something like:
56
57\begin{verbatim}
Fred Drake82f355a1999-05-26 13:03:34 +000058CFLAGS="`getconf LFS_CFLAGS`" OPT="-g -O2 $CFLAGS" \
Guido van Rossumf89ad5e2001-03-01 18:29:57 +000059 ./configure
Fred Drakebb3b0021999-01-11 18:36:23 +000060\end{verbatim} % $ <-- bow to font-lock
61
Guido van Rossumf89ad5e2001-03-01 18:29:57 +000062On large-file-capable Linux systems, this might work:
63
64\begin{verbatim}
Fred Drake93438bf2001-06-22 16:01:20 +000065CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" \
66 ./configure
67\end{verbatim} % $ <-- bow to font-lock
Guido van Rossumf89ad5e2001-03-01 18:29:57 +000068
Fred Drakebb3b0021999-01-11 18:36:23 +000069
Fred Drake215fe2f1999-02-02 19:02:35 +000070\subsection{Module Contents \label{posix-contents}}
71
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000072
Fred Drake68a8c691999-02-01 20:23:02 +000073Module \module{posix} defines the following data item:
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000074
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000075\begin{datadesc}{environ}
Fred Drake68a8c691999-02-01 20:23:02 +000076A dictionary representing the string environment at the time the
77interpreter was started. For example, \code{environ['HOME']} is the
Fred Drake2799f9d1999-04-21 18:33:47 +000078pathname of your home directory, equivalent to
79\code{getenv("HOME")} in C.
Guido van Rossum9c43c591997-08-08 21:05:09 +000080
Guido van Rossum470be141995-03-17 16:07:09 +000081Modifying this dictionary does not affect the string environment
Fred Drake75aae9a1998-03-11 05:29:58 +000082passed 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
85export statements to the command string for \function{system()} or
86\function{popen()}.
Guido van Rossum9c43c591997-08-08 21:05:09 +000087
Fred Drake0aa811c2001-10-20 04:24:09 +000088\note{The \refmodule{os} module provides an alternate
Fred Drake68a8c691999-02-01 20:23:02 +000089implementation of \code{environ} which updates the environment on
90modification. Note also that updating \code{os.environ} will render
Fred Drake0559d952001-10-24 21:10:52 +000091this dictionary obsolete. Use of the \refmodule{os} module version of
92this is recommended over direct access to the \module{posix} module.}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000093\end{datadesc}
94
Fred Drake68a8c691999-02-01 20:23:02 +000095Additional contents of this module should only be accessed via the
Fred Drake215fe2f1999-02-02 19:02:35 +000096\refmodule{os} module; refer to the documentation for that module for
Fred Drake68a8c691999-02-01 20:23:02 +000097further information.