[Python-Dev] confstr(), fpathconf(), pathconf(), sysconf()

Fred L. Drake, Jr. fdrake@acm.org
Mon, 13 Dec 1999 12:00:26 -0500 (EST)


  I've just checked in bindings for these POSIX.1 and POSIX.2
functions, and thought I'd explain the interfaces for those who don't
want to read the diffs.  ;)
  These functions expect a "name" parameter (that's how it's described 
in the man pages and the O'Reilly book).  The value for "name" is an
integer that's defined in the system headers.  The constants all have
the form

    _XX_SOME_NAME

where XX is PC for fpathconf()- and pathconf()-related names, SC for
sysconf()-related names, and CS for confstr()-related names.  Some
names are defined by the standards, but additional names are defined
by implementations (there are a *lot* of sysconf() names under
Solaris!).
  We don't want to expose enormous numbers of constants in the
module's interface, however, as there are already a lot of names in
the posix module.  That would also slow down module initialization.
We also don't want to force callers to use magic numbers in code that 
uses these functions, especially since the values may be
system-specific.
  The best way to call these functions, then, is to use a *string*
that corresponds to the name of the C #define sysmbol with the leading 
underscore stripped off.  For example, to get the length of the
arguments to exec(), you could say:

    num_args = os.sysconf("SC_ARG_MAX")

  The string will be mapped to the appropriate numeric value defined
in an internal table.  If the name isn't defined for the platform, a
ValueError will be raised.

    >>> num_args = os.sysconf("FOO_BAR")
    Traceback (innermost last):
      File "<stdin>", line 1, in ?
    ValueError: unrecognized configuration name

  To allow retrieval for platform-dependent configuration information, 
integers can also be passed in.  On Solaris, this is equivalent to
using "SC_ARG_MAX":

    num_args = os.sysconf(1)

(Ignoring the portability and readability issues, ha!)
  There are three separate tables used for this; one for confstr(),
one for sysconf(), and one shared by fpathconf() and pathconf().  The
names used to build the tables come from Linux and Solaris; we can add 
other names as needed.  To add names, I'd need the names to add and
how to test for their existence at compile time (#ifdef, etc.).


  -Fred

--
Fred L. Drake, Jr.	     <fdrake@acm.org>
Corporation for National Research Initiatives