Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{posix} --- |
| 2 | The most common \POSIX{} system calls.} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | \declaremodule{builtin}{posix} |
| 4 | |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 5 | \modulesynopsis{The most common \POSIX{} system calls (normally used |
| 6 | via module \module{os}).} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 7 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 8 | |
| 9 | This module provides access to operating system functionality that is |
Fred Drake | 68a8c69 | 1999-02-01 20:23:02 +0000 | [diff] [blame] | 10 | standardized by the C Standard and the \POSIX{} standard (a thinly |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 11 | disguised \UNIX{} interface). |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 12 | |
| 13 | \strong{Do not import this module directly.} Instead, import the |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 14 | module \module{os}, which provides a \emph{portable} version of this |
| 15 | interface. On \UNIX{}, the \module{os} module provides a superset of |
| 16 | the \module{posix} interface. On non-\UNIX{} operating systems the |
| 17 | \module{posix} module is not available, but a subset is always |
| 18 | available through the \module{os} interface. Once \module{os} is |
| 19 | imported, there is \emph{no} performance penalty in using it instead |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 20 | of \module{posix}. In addition, \module{os}\refstmodindex{os} |
| 21 | provides some additional functionality, such as automatically calling |
| 22 | \function{putenv()} when an entry in \code{os.environ} is changed. |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 23 | |
Guido van Rossum | 282290f | 1997-08-27 14:54:25 +0000 | [diff] [blame] | 24 | The descriptions below are very terse; refer to the corresponding |
Fred Drake | 65b32f7 | 1998-02-09 20:27:12 +0000 | [diff] [blame] | 25 | \UNIX{} manual (or \POSIX{} documentation) entry for more information. |
Guido van Rossum | 282290f | 1997-08-27 14:54:25 +0000 | [diff] [blame] | 26 | Arguments called \var{path} refer to a pathname given as a string. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 27 | |
Barry Warsaw | eef2cd1 | 1998-07-23 19:50:09 +0000 | [diff] [blame] | 28 | Errors are reported as exceptions; the usual exceptions are given for |
| 29 | type errors, while errors reported by the system calls raise |
| 30 | \exception{error} (a synonym for the standard exception |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 31 | \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 | |
| 39 | Several operating systems (including AIX, HPUX, Irix and Solaris) |
Fred Drake | 68a8c69 | 1999-02-01 20:23:02 +0000 | [diff] [blame] | 40 | provide support for files that are larger than 2 Gb from a C |
Fred Drake | bb3b002 | 1999-01-11 18:36:23 +0000 | [diff] [blame] | 41 | programming model where \ctype{int} and \ctype{long} are 32-bit |
| 42 | values. This is typically accomplished by defining the relevant size |
| 43 | and offset types as 64-bit values. Such files are sometimes referred |
| 44 | to as \dfn{large files}. |
| 45 | |
| 46 | Large 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} |
| 48 | type is available and is at least as large as an \ctype{off_t}. Python |
| 49 | longs are then used to represent file sizes, offsets and other values |
| 50 | that can exceed the range of a Python int. It may be necessary to |
| 51 | configure and compile Python with certain compiler flags to enable |
| 52 | this mode. For example, it is enabled by default with recent versions |
| 53 | of Irix, but with Solaris 2.6 and 2.7 you need to do something like: |
| 54 | |
| 55 | \begin{verbatim} |
| 56 | CFLAGS="-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 Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 62 | |
Fred Drake | 68a8c69 | 1999-02-01 20:23:02 +0000 | [diff] [blame] | 63 | Module \module{posix} defines the following data item: |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 64 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 65 | \begin{datadesc}{environ} |
Fred Drake | 68a8c69 | 1999-02-01 20:23:02 +0000 | [diff] [blame] | 66 | A dictionary representing the string environment at the time the |
| 67 | interpreter was started. For example, \code{environ['HOME']} is the |
| 68 | pathname of your home directory, equivalent to \code{getenv("HOME")} |
| 69 | in C. |
Guido van Rossum | 9c43c59 | 1997-08-08 21:05:09 +0000 | [diff] [blame] | 70 | |
Guido van Rossum | 470be14 | 1995-03-17 16:07:09 +0000 | [diff] [blame] | 71 | Modifying this dictionary does not affect the string environment |
Fred Drake | 75aae9a | 1998-03-11 05:29:58 +0000 | [diff] [blame] | 72 | passed 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 |
| 75 | export statements to the command string for \function{system()} or |
| 76 | \function{popen()}. |
Guido van Rossum | 9c43c59 | 1997-08-08 21:05:09 +0000 | [diff] [blame] | 77 | |
Fred Drake | 68a8c69 | 1999-02-01 20:23:02 +0000 | [diff] [blame] | 78 | \strong{Note:} The \module{os} module provides an alternate |
| 79 | implementation of \code{environ} which updates the environment on |
| 80 | modification. Note also that updating \code{os.environ} will render |
| 81 | this dictionary obsolete. Use of the \module{os} for this is |
| 82 | recommended over direct access to the \module{posix} module. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 83 | \end{datadesc} |
| 84 | |
Fred Drake | 68a8c69 | 1999-02-01 20:23:02 +0000 | [diff] [blame] | 85 | Additional contents of this module should only be accessed via the |
| 86 | \module{os} module; refer to the documentation for that module for |
| 87 | further information. |