Debian Codegraph @

Doc/library/posix.rst

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