/Doc/library/posix.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 86 lines · 61 code · 25 blank · 0 comment · 0 complexity · 882fb296dbbdf0833f31e1a3990a3691 MD5 · raw file

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