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