• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1:mod:`!posix` --- The most common POSIX system calls
2====================================================
3
4.. module:: posix
5   :platform: Unix
6   :synopsis: The most common POSIX system calls (normally used via module os).
7
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.. availability:: Unix.
15
16.. index:: pair: module; os
17
18**Do not import this module directly.**  Instead, import the module :mod:`os`,
19which provides a *portable* version of this interface.  On Unix, the :mod:`os`
20module provides a superset of the :mod:`posix` interface.  On non-Unix operating
21systems the :mod:`posix` module is not available, but a subset is always
22available through the :mod:`os` interface.  Once :mod:`os` is imported, there is
23*no* performance penalty in using it instead of :mod:`posix`.  In addition,
24:mod:`os` provides some additional functionality, such as automatically calling
25:func:`~os.putenv` when an entry in ``os.environ`` is changed.
26
27Errors are reported as exceptions; the usual exceptions are given for type
28errors, while errors reported by the system calls raise :exc:`OSError`.
29
30
31.. _posix-large-files:
32
33Large File Support
34------------------
35
36.. index::
37   single: large files
38   single: file; large files
39
40.. sectionauthor:: Steve Clift <clift@mail.anacapa.net>
41
42Several operating systems (including AIX and Solaris) provide
43support for files that are larger than 2 GiB from a C programming model where
44:c:expr:`int` and :c:expr:`long` are 32-bit values. This is typically accomplished
45by defining the relevant size and offset types as 64-bit values. Such files are
46sometimes referred to as :dfn:`large files`.
47
48Large file support is enabled in Python when the size of an :c:type:`off_t` is
49larger than a :c:expr:`long` and the :c:expr:`long long` is at least as large
50as an :c:type:`off_t`.
51It may be necessary to configure and compile Python with certain compiler flags
52to enable this mode. For example, with Solaris 2.6 and 2.7 you need to do
53something like::
54
55   CFLAGS="`getconf LFS_CFLAGS`" OPT="-g -O2 $CFLAGS" \
56           ./configure
57
58On large-file-capable Linux systems, this might work::
59
60   CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" \
61           ./configure
62
63
64.. _posix-contents:
65
66Notable Module Contents
67-----------------------
68
69In addition to many functions described in the :mod:`os` module documentation,
70:mod:`posix` defines the following data item:
71
72.. data:: environ
73
74   A dictionary representing the string environment at the time the interpreter
75   was started. Keys and values are bytes on Unix and str on Windows. For
76   example, ``environ[b'HOME']`` (``environ['HOME']`` on Windows) is the
77   pathname of your home directory, equivalent to ``getenv("HOME")`` in C.
78
79   Modifying this dictionary does not affect the string environment passed on by
80   :func:`~os.execv`, :func:`~os.popen` or :func:`~os.system`; if you need to
81   change the environment, pass ``environ`` to :func:`~os.execve` or add
82   variable assignments and export statements to the command string for
83   :func:`~os.system` or :func:`~os.popen`.
84
85   .. versionchanged:: 3.2
86      On Unix, keys and values are bytes.
87
88   .. note::
89
90      The :mod:`os` module provides an alternate implementation of ``environ``
91      which updates the environment on modification. Note also that updating
92      :data:`os.environ` will render this dictionary obsolete. Use of the
93      :mod:`os` module version of this is recommended over direct access to the
94      :mod:`posix` module.
95