Blame manual/intro.texi

Packit Service 82fcde
@node Introduction, Error Reporting, Top, Top
Packit Service 82fcde
@chapter Introduction
Packit Service 82fcde
@c %MENU% Purpose of the GNU C Library
Packit Service 82fcde
Packit Service 82fcde
The C language provides no built-in facilities for performing such
Packit Service 82fcde
common operations as input/output, memory management, string
Packit Service 82fcde
manipulation, and the like.  Instead, these facilities are defined
Packit Service 82fcde
in a standard @dfn{library}, which you compile and link with your
Packit Service 82fcde
programs.
Packit Service 82fcde
@cindex library
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{}, described in this document, defines all of the
Packit Service 82fcde
library functions that are specified by the @w{ISO C} standard, as well as
Packit Service 82fcde
additional features specific to POSIX and other derivatives of the Unix
Packit Service 82fcde
operating system, and extensions specific to @gnusystems{}.
Packit Service 82fcde
Packit Service 82fcde
The purpose of this manual is to tell you how to use the facilities
Packit Service 82fcde
of @theglibc{}.  We have mentioned which features belong to which
Packit Service 82fcde
standards to help you identify things that are potentially non-portable
Packit Service 82fcde
to other systems.  But the emphasis in this manual is not on strict
Packit Service 82fcde
portability.
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Getting Started::             What this manual is for and how to use it.
Packit Service 82fcde
* Standards and Portability::   Standards and sources upon which the GNU
Packit Service 82fcde
                                 C library is based.
Packit Service 82fcde
* Using the Library::           Some practical uses for the library.
Packit Service 82fcde
* Roadmap to the Manual::       Overview of the remaining chapters in
Packit Service 82fcde
                                 this manual.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Getting Started, Standards and Portability,  , Introduction
Packit Service 82fcde
@section Getting Started
Packit Service 82fcde
Packit Service 82fcde
This manual is written with the assumption that you are at least
Packit Service 82fcde
somewhat familiar with the C programming language and basic programming
Packit Service 82fcde
concepts.  Specifically, familiarity with ISO standard C
Packit Service 82fcde
(@pxref{ISO C}), rather than ``traditional'' pre-ISO C dialects, is
Packit Service 82fcde
assumed.
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} includes several @dfn{header files}, each of which
Packit Service 82fcde
provides definitions and declarations for a group of related facilities;
Packit Service 82fcde
this information is used by the C compiler when processing your program.
Packit Service 82fcde
For example, the header file @file{stdio.h} declares facilities for
Packit Service 82fcde
performing input and output, and the header file @file{string.h}
Packit Service 82fcde
declares string processing utilities.  The organization of this manual
Packit Service 82fcde
generally follows the same division as the header files.
Packit Service 82fcde
Packit Service 82fcde
If you are reading this manual for the first time, you should read all
Packit Service 82fcde
of the introductory material and skim the remaining chapters.  There are
Packit Service 82fcde
a @emph{lot} of functions in @theglibc{} and it's not realistic to
Packit Service 82fcde
expect that you will be able to remember exactly @emph{how} to use each
Packit Service 82fcde
and every one of them.  It's more important to become generally familiar
Packit Service 82fcde
with the kinds of facilities that the library provides, so that when you
Packit Service 82fcde
are writing your programs you can recognize @emph{when} to make use of
Packit Service 82fcde
library functions, and @emph{where} in this manual you can find more
Packit Service 82fcde
specific information about them.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Standards and Portability, Using the Library, Getting Started, Introduction
Packit Service 82fcde
@section Standards and Portability
Packit Service 82fcde
@cindex standards
Packit Service 82fcde
Packit Service 82fcde
This section discusses the various standards and other sources that @theglibc{}
Packit Service 82fcde
is based upon.  These sources include the @w{ISO C} and
Packit Service 82fcde
POSIX standards, and the System V and Berkeley Unix implementations.
Packit Service 82fcde
Packit Service 82fcde
The primary focus of this manual is to tell you how to make effective
Packit Service 82fcde
use of the @glibcadj{} facilities.  But if you are concerned about
Packit Service 82fcde
making your programs compatible with these standards, or portable to
Packit Service 82fcde
operating systems other than GNU, this can affect how you use the
Packit Service 82fcde
library.  This section gives you an overview of these standards, so that
Packit Service 82fcde
you will know what they are when they are mentioned in other parts of
Packit Service 82fcde
the manual.
Packit Service 82fcde
Packit Service 82fcde
@xref{Library Summary}, for an alphabetical list of the functions and
Packit Service 82fcde
other symbols provided by the library.  This list also states which
Packit Service 82fcde
standards each function or symbol comes from.
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* ISO C::                       The international standard for the C
Packit Service 82fcde
                                 programming language.
Packit Service 82fcde
* POSIX::                       The ISO/IEC 9945 (aka IEEE 1003) standards
Packit Service 82fcde
                                 for operating systems.
Packit Service 82fcde
* Berkeley Unix::               BSD and SunOS.
Packit Service 82fcde
* SVID::                        The System V Interface Description.
Packit Service 82fcde
* XPG::                         The X/Open Portability Guide.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node ISO C, POSIX,  , Standards and Portability
Packit Service 82fcde
@subsection ISO C
Packit Service 82fcde
@cindex ISO C
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} is compatible with the C standard adopted by the
Packit Service 82fcde
American National Standards Institute (ANSI):
Packit Service 82fcde
@cite{American National Standard X3.159-1989---``ANSI C''} and later
Packit Service 82fcde
by the International Standardization Organization (ISO):
Packit Service 82fcde
@cite{ISO/IEC 9899:1990, ``Programming languages---C''}.
Packit Service 82fcde
We here refer to the standard as @w{ISO C} since this is the more
Packit Service 82fcde
general standard in respect of ratification.
Packit Service 82fcde
The header files and library facilities that make up @theglibc{} are
Packit Service 82fcde
a superset of those specified by the @w{ISO C} standard.@refill
Packit Service 82fcde
Packit Service 82fcde
@pindex gcc
Packit Service 82fcde
If you are concerned about strict adherence to the @w{ISO C} standard, you
Packit Service 82fcde
should use the @samp{-ansi} option when you compile your programs with
Packit Service 82fcde
the GNU C compiler.  This tells the compiler to define @emph{only} ISO
Packit Service 82fcde
standard features from the library header files, unless you explicitly
Packit Service 82fcde
ask for additional features.  @xref{Feature Test Macros}, for
Packit Service 82fcde
information on how to do this.
Packit Service 82fcde
Packit Service 82fcde
Being able to restrict the library to include only @w{ISO C} features is
Packit Service 82fcde
important because @w{ISO C} puts limitations on what names can be defined
Packit Service 82fcde
by the library implementation, and the GNU extensions don't fit these
Packit Service 82fcde
limitations.  @xref{Reserved Names}, for more information about these
Packit Service 82fcde
restrictions.
Packit Service 82fcde
Packit Service 82fcde
This manual does not attempt to give you complete details on the
Packit Service 82fcde
differences between @w{ISO C} and older dialects.  It gives advice on how
Packit Service 82fcde
to write programs to work portably under multiple C dialects, but does
Packit Service 82fcde
not aim for completeness.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node POSIX, Berkeley Unix, ISO C, Standards and Portability
Packit Service 82fcde
@subsection POSIX (The Portable Operating System Interface)
Packit Service 82fcde
@cindex POSIX
Packit Service 82fcde
@cindex POSIX.1
Packit Service 82fcde
@cindex IEEE Std 1003.1
Packit Service 82fcde
@cindex ISO/IEC 9945-1
Packit Service 82fcde
@cindex POSIX.2
Packit Service 82fcde
@cindex IEEE Std 1003.2
Packit Service 82fcde
@cindex ISO/IEC 9945-2
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} is also compatible with the ISO @dfn{POSIX} family of
Packit Service 82fcde
standards, known more formally as the @dfn{Portable Operating System
Packit Service 82fcde
Interface for Computer Environments} (ISO/IEC 9945).  They were also
Packit Service 82fcde
published as ANSI/IEEE Std 1003.  POSIX is derived mostly from various
Packit Service 82fcde
versions of the Unix operating system.
Packit Service 82fcde
Packit Service 82fcde
The library facilities specified by the POSIX standards are a superset
Packit Service 82fcde
of those required by @w{ISO C}; POSIX specifies additional features for
Packit Service 82fcde
@w{ISO C} functions, as well as specifying new additional functions.  In
Packit Service 82fcde
general, the additional requirements and functionality defined by the
Packit Service 82fcde
POSIX standards are aimed at providing lower-level support for a
Packit Service 82fcde
particular kind of operating system environment, rather than general
Packit Service 82fcde
programming language support which can run in many diverse operating
Packit Service 82fcde
system environments.@refill
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} implements all of the functions specified in
Packit Service 82fcde
@cite{ISO/IEC 9945-1:1996, the POSIX System Application Program
Packit Service 82fcde
Interface}, commonly referred to as POSIX.1.  The primary extensions to
Packit Service 82fcde
the @w{ISO C} facilities specified by this standard include file system
Packit Service 82fcde
interface primitives (@pxref{File System Interface}), device-specific
Packit Service 82fcde
terminal control functions (@pxref{Low-Level Terminal Interface}), and
Packit Service 82fcde
process control functions (@pxref{Processes}).
Packit Service 82fcde
Packit Service 82fcde
Some facilities from @cite{ISO/IEC 9945-2:1993, the POSIX Shell and
Packit Service 82fcde
Utilities standard} (POSIX.2) are also implemented in @theglibc{}.
Packit Service 82fcde
These include utilities for dealing with regular expressions and other
Packit Service 82fcde
pattern matching facilities (@pxref{Pattern Matching}).
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* POSIX Safety Concepts::       Safety concepts from POSIX.
Packit Service 82fcde
* Unsafe Features::             Features that make functions unsafe.
Packit Service 82fcde
* Conditionally Safe Features:: Features that make functions unsafe
Packit Service 82fcde
                                 in the absence of workarounds.
Packit Service 82fcde
* Other Safety Remarks::        Additional safety features and remarks.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@comment Roland sez:
Packit Service 82fcde
@comment The GNU C library as it stands conforms to 1003.2 draft 11, which
Packit Service 82fcde
@comment specifies:
Packit Service 82fcde
@comment
Packit Service 82fcde
@comment Several new macros in <limits.h>.
Packit Service 82fcde
@comment popen, pclose
Packit Service 82fcde
@comment <regex.h> (which is not yet fully implemented--wait on this)
Packit Service 82fcde
@comment fnmatch
Packit Service 82fcde
@comment getopt
Packit Service 82fcde
@comment <glob.h>
Packit Service 82fcde
@comment <wordexp.h> (not yet implemented)
Packit Service 82fcde
@comment confstr
Packit Service 82fcde
Packit Service 82fcde
@node POSIX Safety Concepts, Unsafe Features, , POSIX
Packit Service 82fcde
@subsubsection POSIX Safety Concepts
Packit Service 82fcde
@cindex POSIX Safety Concepts
Packit Service 82fcde
Packit Service 82fcde
This manual documents various safety properties of @glibcadj{}
Packit Service 82fcde
functions, in lines that follow their prototypes and look like:
Packit Service 82fcde
Packit Service 82fcde
@sampsafety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
Packit Service 82fcde
Packit Service 82fcde
The properties are assessed according to the criteria set forth in the
Packit Service 82fcde
POSIX standard for such safety contexts as Thread-, Async-Signal- and
Packit Service 82fcde
Async-Cancel- -Safety.  Intuitive definitions of these properties,
Packit Service 82fcde
attempting to capture the meaning of the standard definitions, follow.
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@cindex MT-Safe
Packit Service 82fcde
@cindex Thread-Safe
Packit Service 82fcde
@code{MT-Safe} or Thread-Safe functions are safe to call in the presence
Packit Service 82fcde
of other threads.  MT, in MT-Safe, stands for Multi Thread.
Packit Service 82fcde
Packit Service 82fcde
Being MT-Safe does not imply a function is atomic, nor that it uses any
Packit Service 82fcde
of the memory synchronization mechanisms POSIX exposes to users.  It is
Packit Service 82fcde
even possible that calling MT-Safe functions in sequence does not yield
Packit Service 82fcde
an MT-Safe combination.  For example, having a thread call two MT-Safe
Packit Service 82fcde
functions one right after the other does not guarantee behavior
Packit Service 82fcde
equivalent to atomic execution of a combination of both functions, since
Packit Service 82fcde
concurrent calls in other threads may interfere in a destructive way.
Packit Service 82fcde
Packit Service 82fcde
Whole-program optimizations that could inline functions across library
Packit Service 82fcde
interfaces may expose unsafe reordering, and so performing inlining
Packit Service 82fcde
across the @glibcadj{} interface is not recommended.  The documented
Packit Service 82fcde
MT-Safety status is not guaranteed under whole-program optimization.
Packit Service 82fcde
However, functions defined in user-visible headers are designed to be
Packit Service 82fcde
safe for inlining.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@cindex AS-Safe
Packit Service 82fcde
@cindex Async-Signal-Safe
Packit Service 82fcde
@code{AS-Safe} or Async-Signal-Safe functions are safe to call from
Packit Service 82fcde
asynchronous signal handlers.  AS, in AS-Safe, stands for Asynchronous
Packit Service 82fcde
Signal.
Packit Service 82fcde
Packit Service 82fcde
Many functions that are AS-Safe may set @code{errno}, or modify the
Packit Service 82fcde
floating-point environment, because their doing so does not make them
Packit Service 82fcde
unsuitable for use in signal handlers.  However, programs could
Packit Service 82fcde
misbehave should asynchronous signal handlers modify this thread-local
Packit Service 82fcde
state, and the signal handling machinery cannot be counted on to
Packit Service 82fcde
preserve it.  Therefore, signal handlers that call functions that may
Packit Service 82fcde
set @code{errno} or modify the floating-point environment @emph{must}
Packit Service 82fcde
save their original values, and restore them before returning.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@cindex AC-Safe
Packit Service 82fcde
@cindex Async-Cancel-Safe
Packit Service 82fcde
@code{AC-Safe} or Async-Cancel-Safe functions are safe to call when
Packit Service 82fcde
asynchronous cancellation is enabled.  AC in AC-Safe stands for
Packit Service 82fcde
Asynchronous Cancellation.
Packit Service 82fcde
Packit Service 82fcde
The POSIX standard defines only three functions to be AC-Safe, namely
Packit Service 82fcde
@code{pthread_cancel}, @code{pthread_setcancelstate}, and
Packit Service 82fcde
@code{pthread_setcanceltype}.  At present @theglibc{} provides no
Packit Service 82fcde
guarantees beyond these three functions, but does document which
Packit Service 82fcde
functions are presently AC-Safe.  This documentation is provided for use
Packit Service 82fcde
by @theglibc{} developers.
Packit Service 82fcde
Packit Service 82fcde
Just like signal handlers, cancellation cleanup routines must configure
Packit Service 82fcde
the floating point environment they require.  The routines cannot assume
Packit Service 82fcde
a floating point environment, particularly when asynchronous
Packit Service 82fcde
cancellation is enabled.  If the configuration of the floating point
Packit Service 82fcde
environment cannot be performed atomically then it is also possible that
Packit Service 82fcde
the environment encountered is internally inconsistent.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@cindex MT-Unsafe
Packit Service 82fcde
@cindex Thread-Unsafe
Packit Service 82fcde
@cindex AS-Unsafe
Packit Service 82fcde
@cindex Async-Signal-Unsafe
Packit Service 82fcde
@cindex AC-Unsafe
Packit Service 82fcde
@cindex Async-Cancel-Unsafe
Packit Service 82fcde
@code{MT-Unsafe}, @code{AS-Unsafe}, @code{AC-Unsafe} functions are not
Packit Service 82fcde
safe to call within the safety contexts described above.  Calling them
Packit Service 82fcde
within such contexts invokes undefined behavior.
Packit Service 82fcde
Packit Service 82fcde
Functions not explicitly documented as safe in a safety context should
Packit Service 82fcde
be regarded as Unsafe.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@cindex Preliminary
Packit Service 82fcde
@code{Preliminary} safety properties are documented, indicating these
Packit Service 82fcde
properties may @emph{not} be counted on in future releases of
Packit Service 82fcde
@theglibc{}.
Packit Service 82fcde
Packit Service 82fcde
Such preliminary properties are the result of an assessment of the
Packit Service 82fcde
properties of our current implementation, rather than of what is
Packit Service 82fcde
mandated and permitted by current and future standards.
Packit Service 82fcde
Packit Service 82fcde
Although we strive to abide by the standards, in some cases our
Packit Service 82fcde
implementation is safe even when the standard does not demand safety,
Packit Service 82fcde
and in other cases our implementation does not meet the standard safety
Packit Service 82fcde
requirements.  The latter are most likely bugs; the former, when marked
Packit Service 82fcde
as @code{Preliminary}, should not be counted on: future standards may
Packit Service 82fcde
require changes that are not compatible with the additional safety
Packit Service 82fcde
properties afforded by the current implementation.
Packit Service 82fcde
Packit Service 82fcde
Furthermore, the POSIX standard does not offer a detailed definition of
Packit Service 82fcde
safety.  We assume that, by ``safe to call'', POSIX means that, as long
Packit Service 82fcde
as the program does not invoke undefined behavior, the ``safe to call''
Packit Service 82fcde
function behaves as specified, and does not cause other functions to
Packit Service 82fcde
deviate from their specified behavior.  We have chosen to use its loose
Packit Service 82fcde
definitions of safety, not because they are the best definitions to use,
Packit Service 82fcde
but because choosing them harmonizes this manual with POSIX.
Packit Service 82fcde
Packit Service 82fcde
Please keep in mind that these are preliminary definitions and
Packit Service 82fcde
annotations, and certain aspects of the definitions are still under
Packit Service 82fcde
discussion and might be subject to clarification or change.
Packit Service 82fcde
Packit Service 82fcde
Over time, we envision evolving the preliminary safety notes into stable
Packit Service 82fcde
commitments, as stable as those of our interfaces.  As we do, we will
Packit Service 82fcde
remove the @code{Preliminary} keyword from safety notes.  As long as the
Packit Service 82fcde
keyword remains, however, they are not to be regarded as a promise of
Packit Service 82fcde
future behavior.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
Other keywords that appear in safety notes are defined in subsequent
Packit Service 82fcde
sections.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Unsafe Features, Conditionally Safe Features, POSIX Safety Concepts, POSIX
Packit Service 82fcde
@subsubsection Unsafe Features
Packit Service 82fcde
@cindex Unsafe Features
Packit Service 82fcde
Packit Service 82fcde
Functions that are unsafe to call in certain contexts are annotated with
Packit Service 82fcde
keywords that document their features that make them unsafe to call.
Packit Service 82fcde
AS-Unsafe features in this section indicate the functions are never safe
Packit Service 82fcde
to call when asynchronous signals are enabled.  AC-Unsafe features
Packit Service 82fcde
indicate they are never safe to call when asynchronous cancellation is
Packit Service 82fcde
enabled.  There are no MT-Unsafe marks in this section.
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
Packit Service 82fcde
@item @code{lock}
Packit Service 82fcde
@cindex lock
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{lock} as an AS-Unsafe feature may be
Packit Service 82fcde
interrupted by a signal while holding a non-recursive lock.  If the
Packit Service 82fcde
signal handler calls another such function that takes the same lock, the
Packit Service 82fcde
result is a deadlock.
Packit Service 82fcde
Packit Service 82fcde
Functions annotated with @code{lock} as an AC-Unsafe feature may, if
Packit Service 82fcde
cancelled asynchronously, fail to release a lock that would have been
Packit Service 82fcde
released if their execution had not been interrupted by asynchronous
Packit Service 82fcde
thread cancellation.  Once a lock is left taken, attempts to take that
Packit Service 82fcde
lock will block indefinitely.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{corrupt}
Packit Service 82fcde
@cindex corrupt
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{corrupt} as an AS-Unsafe feature may corrupt
Packit Service 82fcde
data structures and misbehave when they interrupt, or are interrupted
Packit Service 82fcde
by, another such function.  Unlike functions marked with @code{lock},
Packit Service 82fcde
these take recursive locks to avoid MT-Safety problems, but this is not
Packit Service 82fcde
enough to stop a signal handler from observing a partially-updated data
Packit Service 82fcde
structure.  Further corruption may arise from the interrupted function's
Packit Service 82fcde
failure to notice updates made by signal handlers.
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{corrupt} as an AC-Unsafe feature may leave
Packit Service 82fcde
data structures in a corrupt, partially updated state.  Subsequent uses
Packit Service 82fcde
of the data structure may misbehave.
Packit Service 82fcde
Packit Service 82fcde
@c A special case, probably not worth documenting separately, involves
Packit Service 82fcde
@c reallocing, or even freeing pointers.  Any case involving free could
Packit Service 82fcde
@c be easily turned into an ac-safe leak by resetting the pointer before
Packit Service 82fcde
@c releasing it; I don't think we have any case that calls for this sort
Packit Service 82fcde
@c of fixing.  Fixing the realloc cases would require a new interface:
Packit Service 82fcde
@c instead of @code{ptr=realloc(ptr,size)} we'd have to introduce
Packit Service 82fcde
@c @code{acsafe_realloc(&ptr,size)} that would modify ptr before
Packit Service 82fcde
@c releasing the old memory.  The ac-unsafe realloc could be implemented
Packit Service 82fcde
@c in terms of an internal interface with this semantics (say
Packit Service 82fcde
@c __acsafe_realloc), but since realloc can be overridden, the function
Packit Service 82fcde
@c we call to implement realloc should not be this internal interface,
Packit Service 82fcde
@c but another internal interface that calls __acsafe_realloc if realloc
Packit Service 82fcde
@c was not overridden, and calls the overridden realloc with async
Packit Service 82fcde
@c cancel disabled.  --lxoliva
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{heap}
Packit Service 82fcde
@cindex heap
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{heap} may call heap memory management
Packit Service 82fcde
functions from the @code{malloc}/@code{free} family of functions and are
Packit Service 82fcde
only as safe as those functions.  This note is thus equivalent to:
Packit Service 82fcde
Packit Service 82fcde
@sampsafety{@asunsafe{@asulock{}}@acunsafe{@aculock{} @acsfd{} @acsmem{}}}
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@c Check for cases that should have used plugin instead of or in
Packit Service 82fcde
@c addition to this.  Then, after rechecking gettext, adjust i18n if
Packit Service 82fcde
@c needed.
Packit Service 82fcde
@item @code{dlopen}
Packit Service 82fcde
@cindex dlopen
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{dlopen} use the dynamic loader to load
Packit Service 82fcde
shared libraries into the current execution image.  This involves
Packit Service 82fcde
opening files, mapping them into memory, allocating additional memory,
Packit Service 82fcde
resolving symbols, applying relocations and more, all of this while
Packit Service 82fcde
holding internal dynamic loader locks.
Packit Service 82fcde
Packit Service 82fcde
The locks are enough for these functions to be AS- and AC-Unsafe, but
Packit Service 82fcde
other issues may arise.  At present this is a placeholder for all
Packit Service 82fcde
potential safety issues raised by @code{dlopen}.
Packit Service 82fcde
Packit Service 82fcde
@c dlopen runs init and fini sections of the module; does this mean
Packit Service 82fcde
@c dlopen always implies plugin?
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{plugin}
Packit Service 82fcde
@cindex plugin
Packit Service 82fcde
Packit Service 82fcde
Functions annotated with @code{plugin} may run code from plugins that
Packit Service 82fcde
may be external to @theglibc{}.  Such plugin functions are assumed to be
Packit Service 82fcde
MT-Safe, AS-Unsafe and AC-Unsafe.  Examples of such plugins are stack
Packit Service 82fcde
@cindex NSS
Packit Service 82fcde
unwinding libraries, name service switch (NSS) and character set
Packit Service 82fcde
@cindex iconv
Packit Service 82fcde
conversion (iconv) back-ends.
Packit Service 82fcde
Packit Service 82fcde
Although the plugins mentioned as examples are all brought in by means
Packit Service 82fcde
of dlopen, the @code{plugin} keyword does not imply any direct
Packit Service 82fcde
involvement of the dynamic loader or the @code{libdl} interfaces, those
Packit Service 82fcde
are covered by @code{dlopen}.  For example, if one function loads a
Packit Service 82fcde
module and finds the addresses of some of its functions, while another
Packit Service 82fcde
just calls those already-resolved functions, the former will be marked
Packit Service 82fcde
with @code{dlopen}, whereas the latter will get the @code{plugin}.  When
Packit Service 82fcde
a single function takes all of these actions, then it gets both marks.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{i18n}
Packit Service 82fcde
@cindex i18n
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{i18n} may call internationalization
Packit Service 82fcde
functions of the @code{gettext} family and will be only as safe as those
Packit Service 82fcde
functions.  This note is thus equivalent to:
Packit Service 82fcde
Packit Service 82fcde
@sampsafety{@mtsafe{@mtsenv{}}@asunsafe{@asucorrupt{} @ascuheap{} @ascudlopen{}}@acunsafe{@acucorrupt{}}}
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{timer}
Packit Service 82fcde
@cindex timer
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{timer} use the @code{alarm} function or
Packit Service 82fcde
similar to set a time-out for a system call or a long-running operation.
Packit Service 82fcde
In a multi-threaded program, there is a risk that the time-out signal
Packit Service 82fcde
will be delivered to a different thread, thus failing to interrupt the
Packit Service 82fcde
intended thread.  Besides being MT-Unsafe, such functions are always
Packit Service 82fcde
AS-Unsafe, because calling them in signal handlers may interfere with
Packit Service 82fcde
timers set in the interrupted code, and AC-Unsafe, because there is no
Packit Service 82fcde
safe way to guarantee an earlier timer will be reset in case of
Packit Service 82fcde
asynchronous cancellation.
Packit Service 82fcde
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Conditionally Safe Features, Other Safety Remarks, Unsafe Features, POSIX
Packit Service 82fcde
@subsubsection Conditionally Safe Features
Packit Service 82fcde
@cindex Conditionally Safe Features
Packit Service 82fcde
Packit Service 82fcde
For some features that make functions unsafe to call in certain
Packit Service 82fcde
contexts, there are known ways to avoid the safety problem other than
Packit Service 82fcde
refraining from calling the function altogether.  The keywords that
Packit Service 82fcde
follow refer to such features, and each of their definitions indicate
Packit Service 82fcde
how the whole program needs to be constrained in order to remove the
Packit Service 82fcde
safety problem indicated by the keyword.  Only when all the reasons that
Packit Service 82fcde
make a function unsafe are observed and addressed, by applying the
Packit Service 82fcde
documented constraints, does the function become safe to call in a
Packit Service 82fcde
context.
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
Packit Service 82fcde
@item @code{init}
Packit Service 82fcde
@cindex init
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{init} as an MT-Unsafe feature perform
Packit Service 82fcde
MT-Unsafe initialization when they are first called.
Packit Service 82fcde
Packit Service 82fcde
Calling such a function at least once in single-threaded mode removes
Packit Service 82fcde
this specific cause for the function to be regarded as MT-Unsafe.  If no
Packit Service 82fcde
other cause for that remains, the function can then be safely called
Packit Service 82fcde
after other threads are started.
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{init} as an AS- or AC-Unsafe feature use the
Packit Service 82fcde
internal @code{libc_once} machinery or similar to initialize internal
Packit Service 82fcde
data structures.
Packit Service 82fcde
Packit Service 82fcde
If a signal handler interrupts such an initializer, and calls any
Packit Service 82fcde
function that also performs @code{libc_once} initialization, it will
Packit Service 82fcde
deadlock if the thread library has been loaded.
Packit Service 82fcde
Packit Service 82fcde
Furthermore, if an initializer is partially complete before it is
Packit Service 82fcde
canceled or interrupted by a signal whose handler requires the same
Packit Service 82fcde
initialization, some or all of the initialization may be performed more
Packit Service 82fcde
than once, leaking resources or even resulting in corrupt internal data.
Packit Service 82fcde
Packit Service 82fcde
Applications that need to call functions marked with @code{init} as an
Packit Service 82fcde
AS- or AC-Unsafe feature should ensure the initialization is performed
Packit Service 82fcde
before configuring signal handlers or enabling cancellation, so that the
Packit Service 82fcde
AS- and AC-Safety issues related with @code{libc_once} do not arise.
Packit Service 82fcde
Packit Service 82fcde
@c We may have to extend the annotations to cover conditions in which
Packit Service 82fcde
@c initialization may or may not occur, since an initial call in a safe
Packit Service 82fcde
@c context is no use if the initialization doesn't take place at that
Packit Service 82fcde
@c time: it doesn't remove the risk for later calls.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{race}
Packit Service 82fcde
@cindex race
Packit Service 82fcde
Packit Service 82fcde
Functions annotated with @code{race} as an MT-Safety issue operate on
Packit Service 82fcde
objects in ways that may cause data races or similar forms of
Packit Service 82fcde
destructive interference out of concurrent execution.  In some cases,
Packit Service 82fcde
the objects are passed to the functions by users; in others, they are
Packit Service 82fcde
used by the functions to return values to users; in others, they are not
Packit Service 82fcde
even exposed to users.
Packit Service 82fcde
Packit Service 82fcde
We consider access to objects passed as (indirect) arguments to
Packit Service 82fcde
functions to be data race free.  The assurance of data race free objects
Packit Service 82fcde
is the caller's responsibility.  We will not mark a function as
Packit Service 82fcde
MT-Unsafe or AS-Unsafe if it misbehaves when users fail to take the
Packit Service 82fcde
measures required by POSIX to avoid data races when dealing with such
Packit Service 82fcde
objects.  As a general rule, if a function is documented as reading from
Packit Service 82fcde
an object passed (by reference) to it, or modifying it, users ought to
Packit Service 82fcde
use memory synchronization primitives to avoid data races just as they
Packit Service 82fcde
would should they perform the accesses themselves rather than by calling
Packit Service 82fcde
the library function.  @code{FILE} streams are the exception to the
Packit Service 82fcde
general rule, in that POSIX mandates the library to guard against data
Packit Service 82fcde
races in many functions that manipulate objects of this specific opaque
Packit Service 82fcde
type.  We regard this as a convenience provided to users, rather than as
Packit Service 82fcde
a general requirement whose expectations should extend to other types.
Packit Service 82fcde
Packit Service 82fcde
In order to remind users that guarding certain arguments is their
Packit Service 82fcde
responsibility, we will annotate functions that take objects of certain
Packit Service 82fcde
types as arguments.  We draw the line for objects passed by users as
Packit Service 82fcde
follows: objects whose types are exposed to users, and that users are
Packit Service 82fcde
expected to access directly, such as memory buffers, strings, and
Packit Service 82fcde
various user-visible @code{struct} types, do @emph{not} give reason for
Packit Service 82fcde
functions to be annotated with @code{race}.  It would be noisy and
Packit Service 82fcde
redundant with the general requirement, and not many would be surprised
Packit Service 82fcde
by the library's lack of internal guards when accessing objects that can
Packit Service 82fcde
be accessed directly by users.
Packit Service 82fcde
Packit Service 82fcde
As for objects that are opaque or opaque-like, in that they are to be
Packit Service 82fcde
manipulated only by passing them to library functions (e.g.,
Packit Service 82fcde
@code{FILE}, @code{DIR}, @code{obstack}, @code{iconv_t}), there might be
Packit Service 82fcde
additional expectations as to internal coordination of access by the
Packit Service 82fcde
library.  We will annotate, with @code{race} followed by a colon and the
Packit Service 82fcde
argument name, functions that take such objects but that do not take
Packit Service 82fcde
care of synchronizing access to them by default.  For example,
Packit Service 82fcde
@code{FILE} stream @code{unlocked} functions will be annotated, but
Packit Service 82fcde
those that perform implicit locking on @code{FILE} streams by default
Packit Service 82fcde
will not, even though the implicit locking may be disabled on a
Packit Service 82fcde
per-stream basis.
Packit Service 82fcde
Packit Service 82fcde
In either case, we will not regard as MT-Unsafe functions that may
Packit Service 82fcde
access user-supplied objects in unsafe ways should users fail to ensure
Packit Service 82fcde
the accesses are well defined.  The notion prevails that users are
Packit Service 82fcde
expected to safeguard against data races any user-supplied objects that
Packit Service 82fcde
the library accesses on their behalf.
Packit Service 82fcde
Packit Service 82fcde
@c The above describes @mtsrace; @mtasurace is described below.
Packit Service 82fcde
Packit Service 82fcde
This user responsibility does not apply, however, to objects controlled
Packit Service 82fcde
by the library itself, such as internal objects and static buffers used
Packit Service 82fcde
to return values from certain calls.  When the library doesn't guard
Packit Service 82fcde
them against concurrent uses, these cases are regarded as MT-Unsafe and
Packit Service 82fcde
AS-Unsafe (although the @code{race} mark under AS-Unsafe will be omitted
Packit Service 82fcde
as redundant with the one under MT-Unsafe).  As in the case of
Packit Service 82fcde
user-exposed objects, the mark may be followed by a colon and an
Packit Service 82fcde
identifier.  The identifier groups all functions that operate on a
Packit Service 82fcde
certain unguarded object; users may avoid the MT-Safety issues related
Packit Service 82fcde
with unguarded concurrent access to such internal objects by creating a
Packit Service 82fcde
non-recursive mutex related with the identifier, and always holding the
Packit Service 82fcde
mutex when calling any function marked as racy on that identifier, as
Packit Service 82fcde
they would have to should the identifier be an object under user
Packit Service 82fcde
control.  The non-recursive mutex avoids the MT-Safety issue, but it
Packit Service 82fcde
trades one AS-Safety issue for another, so use in asynchronous signals
Packit Service 82fcde
remains undefined.
Packit Service 82fcde
Packit Service 82fcde
When the identifier relates to a static buffer used to hold return
Packit Service 82fcde
values, the mutex must be held for as long as the buffer remains in use
Packit Service 82fcde
by the caller.  Many functions that return pointers to static buffers
Packit Service 82fcde
offer reentrant variants that store return values in caller-supplied
Packit Service 82fcde
buffers instead.  In some cases, such as @code{tmpname}, the variant is
Packit Service 82fcde
chosen not by calling an alternate entry point, but by passing a
Packit Service 82fcde
non-@code{NULL} pointer to the buffer in which the returned values are
Packit Service 82fcde
to be stored.  These variants are generally preferable in multi-threaded
Packit Service 82fcde
programs, although some of them are not MT-Safe because of other
Packit Service 82fcde
internal buffers, also documented with @code{race} notes.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{const}
Packit Service 82fcde
@cindex const
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{const} as an MT-Safety issue non-atomically
Packit Service 82fcde
modify internal objects that are better regarded as constant, because a
Packit Service 82fcde
substantial portion of @theglibc{} accesses them without
Packit Service 82fcde
synchronization.  Unlike @code{race}, that causes both readers and
Packit Service 82fcde
writers of internal objects to be regarded as MT-Unsafe and AS-Unsafe,
Packit Service 82fcde
this mark is applied to writers only.  Writers remain equally MT- and
Packit Service 82fcde
AS-Unsafe to call, but the then-mandatory constness of objects they
Packit Service 82fcde
modify enables readers to be regarded as MT-Safe and AS-Safe (as long as
Packit Service 82fcde
no other reasons for them to be unsafe remain), since the lack of
Packit Service 82fcde
synchronization is not a problem when the objects are effectively
Packit Service 82fcde
constant.
Packit Service 82fcde
Packit Service 82fcde
The identifier that follows the @code{const} mark will appear by itself
Packit Service 82fcde
as a safety note in readers.  Programs that wish to work around this
Packit Service 82fcde
safety issue, so as to call writers, may use a non-recursve
Packit Service 82fcde
@code{rwlock} associated with the identifier, and guard @emph{all} calls
Packit Service 82fcde
to functions marked with @code{const} followed by the identifier with a
Packit Service 82fcde
write lock, and @emph{all} calls to functions marked with the identifier
Packit Service 82fcde
by itself with a read lock.  The non-recursive locking removes the
Packit Service 82fcde
MT-Safety problem, but it trades one AS-Safety problem for another, so
Packit Service 82fcde
use in asynchronous signals remains undefined.
Packit Service 82fcde
Packit Service 82fcde
@c But what if, instead of marking modifiers with const:id and readers
Packit Service 82fcde
@c with just id, we marked writers with race:id and readers with ro:id?
Packit Service 82fcde
@c Instead of having to define each instance of “id”, we'd have a
Packit Service 82fcde
@c general pattern governing all such “id”s, wherein race:id would
Packit Service 82fcde
@c suggest the need for an exclusive/write lock to make the function
Packit Service 82fcde
@c safe, whereas ro:id would indicate “id” is expected to be read-only,
Packit Service 82fcde
@c but if any modifiers are called (while holding an exclusive lock),
Packit Service 82fcde
@c then ro:id-marked functions ought to be guarded with a read lock for
Packit Service 82fcde
@c safe operation.  ro:env or ro:locale, for example, seems to convey
Packit Service 82fcde
@c more clearly the expectations and the meaning, than just env or
Packit Service 82fcde
@c locale.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{sig}
Packit Service 82fcde
@cindex sig
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{sig} as a MT-Safety issue (that implies an
Packit Service 82fcde
identical AS-Safety issue, omitted for brevity) may temporarily install
Packit Service 82fcde
a signal handler for internal purposes, which may interfere with other
Packit Service 82fcde
uses of the signal, identified after a colon.
Packit Service 82fcde
Packit Service 82fcde
This safety problem can be worked around by ensuring that no other uses
Packit Service 82fcde
of the signal will take place for the duration of the call.  Holding a
Packit Service 82fcde
non-recursive mutex while calling all functions that use the same
Packit Service 82fcde
temporary signal; blocking that signal before the call and resetting its
Packit Service 82fcde
handler afterwards is recommended.
Packit Service 82fcde
Packit Service 82fcde
There is no safe way to guarantee the original signal handler is
Packit Service 82fcde
restored in case of asynchronous cancellation, therefore so-marked
Packit Service 82fcde
functions are also AC-Unsafe.
Packit Service 82fcde
Packit Service 82fcde
@c fixme: at least deferred cancellation should get it right, and would
Packit Service 82fcde
@c obviate the restoring bit below, and the qualifier above.
Packit Service 82fcde
Packit Service 82fcde
Besides the measures recommended to work around the MT- and AS-Safety
Packit Service 82fcde
problem, in order to avert the cancellation problem, disabling
Packit Service 82fcde
asynchronous cancellation @emph{and} installing a cleanup handler to
Packit Service 82fcde
restore the signal to the desired state and to release the mutex are
Packit Service 82fcde
recommended.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{term}
Packit Service 82fcde
@cindex term
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{term} as an MT-Safety issue may change the
Packit Service 82fcde
terminal settings in the recommended way, namely: call @code{tcgetattr},
Packit Service 82fcde
modify some flags, and then call @code{tcsetattr}; this creates a window
Packit Service 82fcde
in which changes made by other threads are lost.  Thus, functions marked
Packit Service 82fcde
with @code{term} are MT-Unsafe.  The same window enables changes made by
Packit Service 82fcde
asynchronous signals to be lost.  These functions are also AS-Unsafe,
Packit Service 82fcde
but the corresponding mark is omitted as redundant.
Packit Service 82fcde
Packit Service 82fcde
It is thus advisable for applications using the terminal to avoid
Packit Service 82fcde
concurrent and reentrant interactions with it, by not using it in signal
Packit Service 82fcde
handlers or blocking signals that might use it, and holding a lock while
Packit Service 82fcde
calling these functions and interacting with the terminal.  This lock
Packit Service 82fcde
should also be used for mutual exclusion with functions marked with
Packit Service 82fcde
@code{@mtasurace{:tcattr(fd)}}, where @var{fd} is a file descriptor for
Packit Service 82fcde
the controlling terminal.  The caller may use a single mutex for
Packit Service 82fcde
simplicity, or use one mutex per terminal, even if referenced by
Packit Service 82fcde
different file descriptors.
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{term} as an AC-Safety issue are supposed to
Packit Service 82fcde
restore terminal settings to their original state, after temporarily
Packit Service 82fcde
changing them, but they may fail to do so if cancelled.
Packit Service 82fcde
Packit Service 82fcde
@c fixme: at least deferred cancellation should get it right, and would
Packit Service 82fcde
@c obviate the restoring bit below, and the qualifier above.
Packit Service 82fcde
Packit Service 82fcde
Besides the measures recommended to work around the MT- and AS-Safety
Packit Service 82fcde
problem, in order to avert the cancellation problem, disabling
Packit Service 82fcde
asynchronous cancellation @emph{and} installing a cleanup handler to
Packit Service 82fcde
restore the terminal settings to the original state and to release the
Packit Service 82fcde
mutex are recommended.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Other Safety Remarks, , Conditionally Safe Features, POSIX
Packit Service 82fcde
@subsubsection Other Safety Remarks
Packit Service 82fcde
@cindex Other Safety Remarks
Packit Service 82fcde
Packit Service 82fcde
Additional keywords may be attached to functions, indicating features
Packit Service 82fcde
that do not make a function unsafe to call, but that may need to be
Packit Service 82fcde
taken into account in certain classes of programs:
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
Packit Service 82fcde
@item @code{locale}
Packit Service 82fcde
@cindex locale
Packit Service 82fcde
Packit Service 82fcde
Functions annotated with @code{locale} as an MT-Safety issue read from
Packit Service 82fcde
the locale object without any form of synchronization.  Functions
Packit Service 82fcde
annotated with @code{locale} called concurrently with locale changes may
Packit Service 82fcde
behave in ways that do not correspond to any of the locales active
Packit Service 82fcde
during their execution, but an unpredictable mix thereof.
Packit Service 82fcde
Packit Service 82fcde
We do not mark these functions as MT- or AS-Unsafe, however, because
Packit Service 82fcde
functions that modify the locale object are marked with
Packit Service 82fcde
@code{const:locale} and regarded as unsafe.  Being unsafe, the latter
Packit Service 82fcde
are not to be called when multiple threads are running or asynchronous
Packit Service 82fcde
signals are enabled, and so the locale can be considered effectively
Packit Service 82fcde
constant in these contexts, which makes the former safe.
Packit Service 82fcde
Packit Service 82fcde
@c Should the locking strategy suggested under @code{const} be used,
Packit Service 82fcde
@c failure to guard locale uses is not as fatal as data races in
Packit Service 82fcde
@c general: unguarded uses will @emph{not} follow dangling pointers or
Packit Service 82fcde
@c access uninitialized, unmapped or recycled memory.  Each access will
Packit Service 82fcde
@c read from a consistent locale object that is or was active at some
Packit Service 82fcde
@c point during its execution.  Without synchronization, however, it
Packit Service 82fcde
@c cannot even be assumed that, after a change in locale, earlier
Packit Service 82fcde
@c locales will no longer be used, even after the newly-chosen one is
Packit Service 82fcde
@c used in the thread.  Nevertheless, even though unguarded reads from
Packit Service 82fcde
@c the locale will not violate type safety, functions that access the
Packit Service 82fcde
@c locale multiple times may invoke all sorts of undefined behavior
Packit Service 82fcde
@c because of the unexpected locale changes.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{env}
Packit Service 82fcde
@cindex env
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{env} as an MT-Safety issue access the
Packit Service 82fcde
environment with @code{getenv} or similar, without any guards to ensure
Packit Service 82fcde
safety in the presence of concurrent modifications.
Packit Service 82fcde
Packit Service 82fcde
We do not mark these functions as MT- or AS-Unsafe, however, because
Packit Service 82fcde
functions that modify the environment are all marked with
Packit Service 82fcde
@code{const:env} and regarded as unsafe.  Being unsafe, the latter are
Packit Service 82fcde
not to be called when multiple threads are running or asynchronous
Packit Service 82fcde
signals are enabled, and so the environment can be considered
Packit Service 82fcde
effectively constant in these contexts, which makes the former safe.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{hostid}
Packit Service 82fcde
@cindex hostid
Packit Service 82fcde
Packit Service 82fcde
The function marked with @code{hostid} as an MT-Safety issue reads from
Packit Service 82fcde
the system-wide data structures that hold the ``host ID'' of the
Packit Service 82fcde
machine.  These data structures cannot generally be modified atomically.
Packit Service 82fcde
Since it is expected that the ``host ID'' will not normally change, the
Packit Service 82fcde
function that reads from it (@code{gethostid}) is regarded as safe,
Packit Service 82fcde
whereas the function that modifies it (@code{sethostid}) is marked with
Packit Service 82fcde
@code{@mtasuconst{:@mtshostid{}}}, indicating it may require special
Packit Service 82fcde
care if it is to be called.  In this specific case, the special care
Packit Service 82fcde
amounts to system-wide (not merely intra-process) coordination.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{sigintr}
Packit Service 82fcde
@cindex sigintr
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{sigintr} as an MT-Safety issue access the
Packit Service 82fcde
@code{_sigintr} internal data structure without any guards to ensure
Packit Service 82fcde
safety in the presence of concurrent modifications.
Packit Service 82fcde
Packit Service 82fcde
We do not mark these functions as MT- or AS-Unsafe, however, because
Packit Service 82fcde
functions that modify the this data structure are all marked with
Packit Service 82fcde
@code{const:sigintr} and regarded as unsafe.  Being unsafe, the latter
Packit Service 82fcde
are not to be called when multiple threads are running or asynchronous
Packit Service 82fcde
signals are enabled, and so the data structure can be considered
Packit Service 82fcde
effectively constant in these contexts, which makes the former safe.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{fd}
Packit Service 82fcde
@cindex fd
Packit Service 82fcde
Packit Service 82fcde
Functions annotated with @code{fd} as an AC-Safety issue may leak file
Packit Service 82fcde
descriptors if asynchronous thread cancellation interrupts their
Packit Service 82fcde
execution.
Packit Service 82fcde
Packit Service 82fcde
Functions that allocate or deallocate file descriptors will generally be
Packit Service 82fcde
marked as such.  Even if they attempted to protect the file descriptor
Packit Service 82fcde
allocation and deallocation with cleanup regions, allocating a new
Packit Service 82fcde
descriptor and storing its number where the cleanup region could release
Packit Service 82fcde
it cannot be performed as a single atomic operation.  Similarly,
Packit Service 82fcde
releasing the descriptor and taking it out of the data structure
Packit Service 82fcde
normally responsible for releasing it cannot be performed atomically.
Packit Service 82fcde
There will always be a window in which the descriptor cannot be released
Packit Service 82fcde
because it was not stored in the cleanup handler argument yet, or it was
Packit Service 82fcde
already taken out before releasing it.  It cannot be taken out after
Packit Service 82fcde
release: an open descriptor could mean either that the descriptor still
Packit Service 82fcde
has to be closed, or that it already did so but the descriptor was
Packit Service 82fcde
reallocated by another thread or signal handler.
Packit Service 82fcde
Packit Service 82fcde
Such leaks could be internally avoided, with some performance penalty,
Packit Service 82fcde
by temporarily disabling asynchronous thread cancellation.  However,
Packit Service 82fcde
since callers of allocation or deallocation functions would have to do
Packit Service 82fcde
this themselves, to avoid the same sort of leak in their own layer, it
Packit Service 82fcde
makes more sense for the library to assume they are taking care of it
Packit Service 82fcde
than to impose a performance penalty that is redundant when the problem
Packit Service 82fcde
is solved in upper layers, and insufficient when it is not.
Packit Service 82fcde
Packit Service 82fcde
This remark by itself does not cause a function to be regarded as
Packit Service 82fcde
AC-Unsafe.  However, cumulative effects of such leaks may pose a
Packit Service 82fcde
problem for some programs.  If this is the case, suspending asynchronous
Packit Service 82fcde
cancellation for the duration of calls to such functions is recommended.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{mem}
Packit Service 82fcde
@cindex mem
Packit Service 82fcde
Packit Service 82fcde
Functions annotated with @code{mem} as an AC-Safety issue may leak
Packit Service 82fcde
memory if asynchronous thread cancellation interrupts their execution.
Packit Service 82fcde
Packit Service 82fcde
The problem is similar to that of file descriptors: there is no atomic
Packit Service 82fcde
interface to allocate memory and store its address in the argument to a
Packit Service 82fcde
cleanup handler, or to release it and remove its address from that
Packit Service 82fcde
argument, without at least temporarily disabling asynchronous
Packit Service 82fcde
cancellation, which these functions do not do.
Packit Service 82fcde
Packit Service 82fcde
This remark does not by itself cause a function to be regarded as
Packit Service 82fcde
generally AC-Unsafe.  However, cumulative effects of such leaks may be
Packit Service 82fcde
severe enough for some programs that disabling asynchronous cancellation
Packit Service 82fcde
for the duration of calls to such functions may be required.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{cwd}
Packit Service 82fcde
@cindex cwd
Packit Service 82fcde
Packit Service 82fcde
Functions marked with @code{cwd} as an MT-Safety issue may temporarily
Packit Service 82fcde
change the current working directory during their execution, which may
Packit Service 82fcde
cause relative pathnames to be resolved in unexpected ways in other
Packit Service 82fcde
threads or within asynchronous signal or cancellation handlers.
Packit Service 82fcde
Packit Service 82fcde
This is not enough of a reason to mark so-marked functions as MT- or
Packit Service 82fcde
AS-Unsafe, but when this behavior is optional (e.g., @code{nftw} with
Packit Service 82fcde
@code{FTW_CHDIR}), avoiding the option may be a good alternative to
Packit Service 82fcde
using full pathnames or file descriptor-relative (e.g. @code{openat})
Packit Service 82fcde
system calls.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{!posix}
Packit Service 82fcde
@cindex !posix
Packit Service 82fcde
Packit Service 82fcde
This remark, as an MT-, AS- or AC-Safety note to a function, indicates
Packit Service 82fcde
the safety status of the function is known to differ from the specified
Packit Service 82fcde
status in the POSIX standard.  For example, POSIX does not require a
Packit Service 82fcde
function to be Safe, but our implementation is, or vice-versa.
Packit Service 82fcde
Packit Service 82fcde
For the time being, the absence of this remark does not imply the safety
Packit Service 82fcde
properties we documented are identical to those mandated by POSIX for
Packit Service 82fcde
the corresponding functions.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{:identifier}
Packit Service 82fcde
@cindex :identifier
Packit Service 82fcde
Packit Service 82fcde
Annotations may sometimes be followed by identifiers, intended to group
Packit Service 82fcde
several functions that e.g. access the data structures in an unsafe way,
Packit Service 82fcde
as in @code{race} and @code{const}, or to provide more specific
Packit Service 82fcde
information, such as naming a signal in a function marked with
Packit Service 82fcde
@code{sig}.  It is envisioned that it may be applied to @code{lock} and
Packit Service 82fcde
@code{corrupt} as well in the future.
Packit Service 82fcde
Packit Service 82fcde
In most cases, the identifier will name a set of functions, but it may
Packit Service 82fcde
name global objects or function arguments, or identifiable properties or
Packit Service 82fcde
logical components associated with them, with a notation such as
Packit Service 82fcde
e.g. @code{:buf(arg)} to denote a buffer associated with the argument
Packit Service 82fcde
@var{arg}, or @code{:tcattr(fd)} to denote the terminal attributes of a
Packit Service 82fcde
file descriptor @var{fd}.
Packit Service 82fcde
Packit Service 82fcde
The most common use for identifiers is to provide logical groups of
Packit Service 82fcde
functions and arguments that need to be protected by the same
Packit Service 82fcde
synchronization primitive in order to ensure safe operation in a given
Packit Service 82fcde
context.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item @code{/condition}
Packit Service 82fcde
@cindex /condition
Packit Service 82fcde
Packit Service 82fcde
Some safety annotations may be conditional, in that they only apply if a
Packit Service 82fcde
boolean expression involving arguments, global variables or even the
Packit Service 82fcde
underlying kernel evaluates to true.  Such conditions as
Packit Service 82fcde
@code{/hurd} or @code{/!linux!bsd} indicate the preceding marker only
Packit Service 82fcde
applies when the underlying kernel is the HURD, or when it is neither
Packit Service 82fcde
Linux nor a BSD kernel, respectively.  @code{/!ps} and
Packit Service 82fcde
@code{/one_per_line} indicate the preceding marker only applies when
Packit Service 82fcde
argument @var{ps} is NULL, or global variable @var{one_per_line} is
Packit Service 82fcde
nonzero.
Packit Service 82fcde
Packit Service 82fcde
When all marks that render a function unsafe are adorned with such
Packit Service 82fcde
conditions, and none of the named conditions hold, then the function can
Packit Service 82fcde
be regarded as safe.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Berkeley Unix, SVID, POSIX, Standards and Portability
Packit Service 82fcde
@subsection Berkeley Unix
Packit Service 82fcde
@cindex BSD Unix
Packit Service 82fcde
@cindex 4.@var{n} BSD Unix
Packit Service 82fcde
@cindex Berkeley Unix
Packit Service 82fcde
@cindex SunOS
Packit Service 82fcde
@cindex Unix, Berkeley
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} defines facilities from some versions of Unix which
Packit Service 82fcde
are not formally standardized, specifically from the 4.2 BSD, 4.3 BSD,
Packit Service 82fcde
and 4.4 BSD Unix systems (also known as @dfn{Berkeley Unix}) and from
Packit Service 82fcde
@dfn{SunOS} (a popular 4.2 BSD derivative that includes some Unix System
Packit Service 82fcde
V functionality).  These systems support most of the @w{ISO C} and POSIX
Packit Service 82fcde
facilities, and 4.4 BSD and newer releases of SunOS in fact support them all.
Packit Service 82fcde
Packit Service 82fcde
The BSD facilities include symbolic links (@pxref{Symbolic Links}), the
Packit Service 82fcde
@code{select} function (@pxref{Waiting for I/O}), the BSD signal
Packit Service 82fcde
functions (@pxref{BSD Signal Handling}), and sockets (@pxref{Sockets}).
Packit Service 82fcde
Packit Service 82fcde
@node SVID, XPG, Berkeley Unix, Standards and Portability
Packit Service 82fcde
@subsection SVID (The System V Interface Description)
Packit Service 82fcde
@cindex SVID
Packit Service 82fcde
@cindex System V Unix
Packit Service 82fcde
@cindex Unix, System V
Packit Service 82fcde
Packit Service 82fcde
The @dfn{System V Interface Description} (SVID) is a document describing
Packit Service 82fcde
the AT&T Unix System V operating system.  It is to some extent a
Packit Service 82fcde
superset of the POSIX standard (@pxref{POSIX}).
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} defines most of the facilities required by the SVID
Packit Service 82fcde
that are not also required by the @w{ISO C} or POSIX standards, for
Packit Service 82fcde
compatibility with  System V Unix and other Unix systems (such as
Packit Service 82fcde
SunOS) which include these facilities.  However, many of the more
Packit Service 82fcde
obscure and less generally useful facilities required by the SVID are
Packit Service 82fcde
not included.  (In fact, Unix System V itself does not provide them all.)
Packit Service 82fcde
Packit Service 82fcde
The supported facilities from System V include the methods for
Packit Service 82fcde
inter-process communication and shared memory, the @code{hsearch} and
Packit Service 82fcde
@code{drand48} families of functions, @code{fmtmsg} and several of the
Packit Service 82fcde
mathematical functions.
Packit Service 82fcde
Packit Service 82fcde
@node XPG, , SVID, Standards and Portability
Packit Service 82fcde
@subsection XPG (The X/Open Portability Guide)
Packit Service 82fcde
Packit Service 82fcde
The X/Open Portability Guide, published by the X/Open Company, Ltd., is
Packit Service 82fcde
a more general standard than POSIX.  X/Open owns the Unix copyright and
Packit Service 82fcde
the XPG specifies the requirements for systems which are intended to be
Packit Service 82fcde
a Unix system.
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} complies to the X/Open Portability Guide, Issue 4.2,
Packit Service 82fcde
with all extensions common to XSI (X/Open System Interface)
Packit Service 82fcde
compliant systems and also all X/Open UNIX extensions.
Packit Service 82fcde
Packit Service 82fcde
The additions on top of POSIX are mainly derived from functionality
Packit Service 82fcde
available in @w{System V} and BSD systems.  Some of the really bad
Packit Service 82fcde
mistakes in @w{System V} systems were corrected, though.  Since
Packit Service 82fcde
fulfilling the XPG standard with the Unix extensions is a
Packit Service 82fcde
precondition for getting the Unix brand chances are good that the
Packit Service 82fcde
functionality is available on commercial systems.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Using the Library, Roadmap to the Manual, Standards and Portability, Introduction
Packit Service 82fcde
@section Using the Library
Packit Service 82fcde
Packit Service 82fcde
This section describes some of the practical issues involved in using
Packit Service 82fcde
@theglibc{}.
Packit Service 82fcde
Packit Service 82fcde
@menu
Packit Service 82fcde
* Header Files::                How to include the header files in your
Packit Service 82fcde
                                 programs.
Packit Service 82fcde
* Macro Definitions::           Some functions in the library may really
Packit Service 82fcde
                                 be implemented as macros.
Packit Service 82fcde
* Reserved Names::              The C standard reserves some names for
Packit Service 82fcde
                                 the library, and some for users.
Packit Service 82fcde
* Feature Test Macros::         How to control what names are defined.
Packit Service 82fcde
@end menu
Packit Service 82fcde
Packit Service 82fcde
@node Header Files, Macro Definitions,  , Using the Library
Packit Service 82fcde
@subsection Header Files
Packit Service 82fcde
@cindex header files
Packit Service 82fcde
Packit Service 82fcde
Libraries for use by C programs really consist of two parts: @dfn{header
Packit Service 82fcde
files} that define types and macros and declare variables and
Packit Service 82fcde
functions; and the actual library or @dfn{archive} that contains the
Packit Service 82fcde
definitions of the variables and functions.
Packit Service 82fcde
Packit Service 82fcde
(Recall that in C, a @dfn{declaration} merely provides information that
Packit Service 82fcde
a function or variable exists and gives its type.  For a function
Packit Service 82fcde
declaration, information about the types of its arguments might be
Packit Service 82fcde
provided as well.  The purpose of declarations is to allow the compiler
Packit Service 82fcde
to correctly process references to the declared variables and functions.
Packit Service 82fcde
A @dfn{definition}, on the other hand, actually allocates storage for a
Packit Service 82fcde
variable or says what a function does.)
Packit Service 82fcde
@cindex definition (compared to declaration)
Packit Service 82fcde
@cindex declaration (compared to definition)
Packit Service 82fcde
Packit Service 82fcde
In order to use the facilities in @theglibc{}, you should be sure
Packit Service 82fcde
that your program source files include the appropriate header files.
Packit Service 82fcde
This is so that the compiler has declarations of these facilities
Packit Service 82fcde
available and can correctly process references to them.  Once your
Packit Service 82fcde
program has been compiled, the linker resolves these references to
Packit Service 82fcde
the actual definitions provided in the archive file.
Packit Service 82fcde
Packit Service 82fcde
Header files are included into a program source file by the
Packit Service 82fcde
@samp{#include} preprocessor directive.  The C language supports two
Packit Service 82fcde
forms of this directive; the first,
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
#include "@var{header}"
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
is typically used to include a header file @var{header} that you write
Packit Service 82fcde
yourself; this would contain definitions and declarations describing the
Packit Service 82fcde
interfaces between the different parts of your particular application.
Packit Service 82fcde
By contrast,
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
#include <file.h>
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
is typically used to include a header file @file{file.h} that contains
Packit Service 82fcde
definitions and declarations for a standard library.  This file would
Packit Service 82fcde
normally be installed in a standard place by your system administrator.
Packit Service 82fcde
You should use this second form for the C library header files.
Packit Service 82fcde
Packit Service 82fcde
Typically, @samp{#include} directives are placed at the top of the C
Packit Service 82fcde
source file, before any other code.  If you begin your source files with
Packit Service 82fcde
some comments explaining what the code in the file does (a good idea),
Packit Service 82fcde
put the @samp{#include} directives immediately afterwards, following the
Packit Service 82fcde
feature test macro definition (@pxref{Feature Test Macros}).
Packit Service 82fcde
Packit Service 82fcde
For more information about the use of header files and @samp{#include}
Packit Service 82fcde
directives, @pxref{Header Files,,, cpp.info, The GNU C Preprocessor
Packit Service 82fcde
Manual}.@refill
Packit Service 82fcde
Packit Service 82fcde
@Theglibc{} provides several header files, each of which contains
Packit Service 82fcde
the type and macro definitions and variable and function declarations
Packit Service 82fcde
for a group of related facilities.  This means that your programs may
Packit Service 82fcde
need to include several header files, depending on exactly which
Packit Service 82fcde
facilities you are using.
Packit Service 82fcde
Packit Service 82fcde
Some library header files include other library header files
Packit Service 82fcde
automatically.  However, as a matter of programming style, you should
Packit Service 82fcde
not rely on this; it is better to explicitly include all the header
Packit Service 82fcde
files required for the library facilities you are using.  The @glibcadj{}
Packit Service 82fcde
header files have been written in such a way that it doesn't
Packit Service 82fcde
matter if a header file is accidentally included more than once;
Packit Service 82fcde
including a header file a second time has no effect.  Likewise, if your
Packit Service 82fcde
program needs to include multiple header files, the order in which they
Packit Service 82fcde
are included doesn't matter.
Packit Service 82fcde
Packit Service 82fcde
@strong{Compatibility Note:} Inclusion of standard header files in any
Packit Service 82fcde
order and any number of times works in any @w{ISO C} implementation.
Packit Service 82fcde
However, this has traditionally not been the case in many older C
Packit Service 82fcde
implementations.
Packit Service 82fcde
Packit Service 82fcde
Strictly speaking, you don't @emph{have to} include a header file to use
Packit Service 82fcde
a function it declares; you could declare the function explicitly
Packit Service 82fcde
yourself, according to the specifications in this manual.  But it is
Packit Service 82fcde
usually better to include the header file because it may define types
Packit Service 82fcde
and macros that are not otherwise available and because it may define
Packit Service 82fcde
more efficient macro replacements for some functions.  It is also a sure
Packit Service 82fcde
way to have the correct declaration.
Packit Service 82fcde
Packit Service 82fcde
@node Macro Definitions, Reserved Names, Header Files, Using the Library
Packit Service 82fcde
@subsection Macro Definitions of Functions
Packit Service 82fcde
@cindex shadowing functions with macros
Packit Service 82fcde
@cindex removing macros that shadow functions
Packit Service 82fcde
@cindex undefining macros that shadow functions
Packit Service 82fcde
Packit Service 82fcde
If we describe something as a function in this manual, it may have a
Packit Service 82fcde
macro definition as well.  This normally has no effect on how your
Packit Service 82fcde
program runs---the macro definition does the same thing as the function
Packit Service 82fcde
would.  In particular, macro equivalents for library functions evaluate
Packit Service 82fcde
arguments exactly once, in the same way that a function call would.  The
Packit Service 82fcde
main reason for these macro definitions is that sometimes they can
Packit Service 82fcde
produce an inline expansion that is considerably faster than an actual
Packit Service 82fcde
function call.
Packit Service 82fcde
Packit Service 82fcde
Taking the address of a library function works even if it is also
Packit Service 82fcde
defined as a macro.  This is because, in this context, the name of the
Packit Service 82fcde
function isn't followed by the left parenthesis that is syntactically
Packit Service 82fcde
necessary to recognize a macro call.
Packit Service 82fcde
Packit Service 82fcde
You might occasionally want to avoid using the macro definition of a
Packit Service 82fcde
function---perhaps to make your program easier to debug.  There are
Packit Service 82fcde
two ways you can do this:
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
@item
Packit Service 82fcde
You can avoid a macro definition in a specific use by enclosing the name
Packit Service 82fcde
of the function in parentheses.  This works because the name of the
Packit Service 82fcde
function doesn't appear in a syntactic context where it is recognizable
Packit Service 82fcde
as a macro call.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
You can suppress any macro definition for a whole source file by using
Packit Service 82fcde
the @samp{#undef} preprocessor directive, unless otherwise stated
Packit Service 82fcde
explicitly in the description of that facility.
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
For example, suppose the header file @file{stdlib.h} declares a function
Packit Service 82fcde
named @code{abs} with
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
extern int abs (int);
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
and also provides a macro definition for @code{abs}.  Then, in:
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
#include <stdlib.h>
Packit Service 82fcde
int f (int *i) @{ return abs (++*i); @}
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
@noindent
Packit Service 82fcde
the reference to @code{abs} might refer to either a macro or a function.
Packit Service 82fcde
On the other hand, in each of the following examples the reference is
Packit Service 82fcde
to a function and not a macro.
Packit Service 82fcde
Packit Service 82fcde
@smallexample
Packit Service 82fcde
#include <stdlib.h>
Packit Service 82fcde
int g (int *i) @{ return (abs) (++*i); @}
Packit Service 82fcde
Packit Service 82fcde
#undef abs
Packit Service 82fcde
int h (int *i) @{ return abs (++*i); @}
Packit Service 82fcde
@end smallexample
Packit Service 82fcde
Packit Service 82fcde
Since macro definitions that double for a function behave in
Packit Service 82fcde
exactly the same way as the actual function version, there is usually no
Packit Service 82fcde
need for any of these methods.  In fact, removing macro definitions usually
Packit Service 82fcde
just makes your program slower.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@node Reserved Names, Feature Test Macros, Macro Definitions, Using the Library
Packit Service 82fcde
@subsection Reserved Names
Packit Service 82fcde
@cindex reserved names
Packit Service 82fcde
@cindex name space
Packit Service 82fcde
Packit Service 82fcde
The names of all library types, macros, variables and functions that
Packit Service 82fcde
come from the @w{ISO C} standard are reserved unconditionally; your program
Packit Service 82fcde
@strong{may not} redefine these names.  All other library names are
Packit Service 82fcde
reserved if your program explicitly includes the header file that
Packit Service 82fcde
defines or declares them.  There are several reasons for these
Packit Service 82fcde
restrictions:
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
@item
Packit Service 82fcde
Other people reading your code could get very confused if you were using
Packit Service 82fcde
a function named @code{exit} to do something completely different from
Packit Service 82fcde
what the standard @code{exit} function does, for example.  Preventing
Packit Service 82fcde
this situation helps to make your programs easier to understand and
Packit Service 82fcde
contributes to modularity and maintainability.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
It avoids the possibility of a user accidentally redefining a library
Packit Service 82fcde
function that is called by other library functions.  If redefinition
Packit Service 82fcde
were allowed, those other functions would not work properly.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
It allows the compiler to do whatever special optimizations it pleases
Packit Service 82fcde
on calls to these functions, without the possibility that they may have
Packit Service 82fcde
been redefined by the user.  Some library facilities, such as those for
Packit Service 82fcde
dealing with variadic arguments (@pxref{Variadic Functions})
Packit Service 82fcde
and non-local exits (@pxref{Non-Local Exits}), actually require a
Packit Service 82fcde
considerable amount of cooperation on the part of the C compiler, and
Packit Service 82fcde
with respect to the implementation, it might be easier for the compiler
Packit Service 82fcde
to treat these as built-in parts of the language.
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
In addition to the names documented in this manual, reserved names
Packit Service 82fcde
include all external identifiers (global functions and variables) that
Packit Service 82fcde
begin with an underscore (@samp{_}) and all identifiers regardless of
Packit Service 82fcde
use that begin with either two underscores or an underscore followed by
Packit Service 82fcde
a capital letter are reserved names.  This is so that the library and
Packit Service 82fcde
header files can define functions, variables, and macros for internal
Packit Service 82fcde
purposes without risk of conflict with names in user programs.
Packit Service 82fcde
Packit Service 82fcde
Some additional classes of identifier names are reserved for future
Packit Service 82fcde
extensions to the C language or the POSIX.1 environment.  While using these
Packit Service 82fcde
names for your own purposes right now might not cause a problem, they do
Packit Service 82fcde
raise the possibility of conflict with future versions of the C
Packit Service 82fcde
or POSIX standards, so you should avoid these names.
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
@item
Packit Service 82fcde
Names beginning with a capital @samp{E} followed a digit or uppercase
Packit Service 82fcde
letter may be used for additional error code names.  @xref{Error
Packit Service 82fcde
Reporting}.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
Names that begin with either @samp{is} or @samp{to} followed by a
Packit Service 82fcde
lowercase letter may be used for additional character testing and
Packit Service 82fcde
conversion functions.  @xref{Character Handling}.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
Names that begin with @samp{LC_} followed by an uppercase letter may be
Packit Service 82fcde
used for additional macros specifying locale attributes.
Packit Service 82fcde
@xref{Locales}.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
Names of all existing mathematics functions (@pxref{Mathematics})
Packit Service 82fcde
suffixed with @samp{f} or @samp{l} are reserved for corresponding
Packit Service 82fcde
functions that operate on @code{float} and @code{long double} arguments,
Packit Service 82fcde
respectively.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
Names that begin with @samp{SIG} followed by an uppercase letter are
Packit Service 82fcde
reserved for additional signal names.  @xref{Standard Signals}.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
Names that begin with @samp{SIG_} followed by an uppercase letter are
Packit Service 82fcde
reserved for additional signal actions.  @xref{Basic Signal Handling}.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
Names beginning with @samp{str}, @samp{mem}, or @samp{wcs} followed by a
Packit Service 82fcde
lowercase letter are reserved for additional string and array functions.
Packit Service 82fcde
@xref{String and Array Utilities}.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
Names that end with @samp{_t} are reserved for additional type names.
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
In addition, some individual header files reserve names beyond
Packit Service 82fcde
those that they actually define.  You only need to worry about these
Packit Service 82fcde
restrictions if your program includes that particular header file.
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
@item
Packit Service 82fcde
The header file @file{dirent.h} reserves names prefixed with
Packit Service 82fcde
@samp{d_}.
Packit Service 82fcde
@pindex dirent.h
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The header file @file{fcntl.h} reserves names prefixed with
Packit Service 82fcde
@samp{l_}, @samp{F_}, @samp{O_}, and @samp{S_}.
Packit Service 82fcde
@pindex fcntl.h
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The header file @file{grp.h} reserves names prefixed with @samp{gr_}.
Packit Service 82fcde
@pindex grp.h
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The header file @file{limits.h} reserves names suffixed with @samp{_MAX}.
Packit Service 82fcde
@pindex limits.h
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The header file @file{pwd.h} reserves names prefixed with @samp{pw_}.
Packit Service 82fcde
@pindex pwd.h
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The header file @file{signal.h} reserves names prefixed with @samp{sa_}
Packit Service 82fcde
and @samp{SA_}.
Packit Service 82fcde
@pindex signal.h
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The header file @file{sys/stat.h} reserves names prefixed with @samp{st_}
Packit Service 82fcde
and @samp{S_}.
Packit Service 82fcde
@pindex sys/stat.h
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The header file @file{sys/times.h} reserves names prefixed with @samp{tms_}.
Packit Service 82fcde
@pindex sys/times.h
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
The header file @file{termios.h} reserves names prefixed with @samp{c_},
Packit Service 82fcde
@samp{V}, @samp{I}, @samp{O}, and @samp{TC}; and names prefixed with
Packit Service 82fcde
@samp{B} followed by a digit.
Packit Service 82fcde
@pindex termios.h
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
@comment Include the section on Creature Nest Macros.
Packit Service 82fcde
@include creature.texi
Packit Service 82fcde
Packit Service 82fcde
@node Roadmap to the Manual,  , Using the Library, Introduction
Packit Service 82fcde
@section Roadmap to the Manual
Packit Service 82fcde
Packit Service 82fcde
Here is an overview of the contents of the remaining chapters of
Packit Service 82fcde
this manual.
Packit Service 82fcde
Packit Service 82fcde
@c The chapter overview ordering is:
Packit Service 82fcde
@c Error Reporting (2)
Packit Service 82fcde
@c Virtual Memory Allocation and Paging (3)
Packit Service 82fcde
@c Character Handling (4)
Packit Service 82fcde
@c Strings and Array Utilities (5)
Packit Service 82fcde
@c Character Set Handling (6)
Packit Service 82fcde
@c Locales and Internationalization (7)
Packit Service 82fcde
@c Searching and Sorting (9)
Packit Service 82fcde
@c Pattern Matching (10)
Packit Service 82fcde
@c Input/Output Overview (11)
Packit Service 82fcde
@c Input/Output on Streams (12)
Packit Service 82fcde
@c Low-level Input/Ooutput (13)
Packit Service 82fcde
@c File System Interface (14)
Packit Service 82fcde
@c Pipes and FIFOs (15)
Packit Service 82fcde
@c Sockets (16)
Packit Service 82fcde
@c Low-Level Terminal Interface (17)
Packit Service 82fcde
@c Syslog (18)
Packit Service 82fcde
@c Mathematics (19)
Packit Service 82fcde
@c Aritmetic Functions (20)
Packit Service 82fcde
@c Date and Time (21)
Packit Service 82fcde
@c Non-Local Exist (23)
Packit Service 82fcde
@c Signal Handling (24)
Packit Service 82fcde
@c The Basic Program/System Interface (25)
Packit Service 82fcde
@c Processes (26)
Packit Service 82fcde
@c Job Control (28)
Packit Service 82fcde
@c System Databases and Name Service Switch (29)
Packit Service 82fcde
@c Users and Groups (30) -- References `User Database' and `Group Database'
Packit Service 82fcde
@c System Management (31)
Packit Service 82fcde
@c System Configuration Parameters (32)
Packit Service 82fcde
@c C Language Facilities in the Library (AA)
Packit Service 82fcde
@c Summary of Library Facilities (AB)
Packit Service 82fcde
@c Installing (AC)
Packit Service 82fcde
@c Library Maintenance (AD)
Packit Service 82fcde
Packit Service 82fcde
@c The following chapters need overview text to be added:
Packit Service 82fcde
@c Message Translation (8)
Packit Service 82fcde
@c Resource Usage And Limitations (22)
Packit Service 82fcde
@c Inter-Process Communication (27)
Packit Service 82fcde
@c Debugging support (34)
Packit Service 82fcde
@c POSIX Threads (35)
Packit Service 82fcde
@c Internal Probes (36)
Packit Service 82fcde
@c Platform-specific facilities (AE)
Packit Service 82fcde
@c Contributors to (AF)
Packit Service 82fcde
@c Free Software Needs Free Documentation (AG)
Packit Service 82fcde
@c GNU Lesser General Public License (AH)
Packit Service 82fcde
@c GNU Free Documentation License (AI)
Packit Service 82fcde
Packit Service 82fcde
@itemize @bullet
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Error Reporting}, describes how errors detected by the library
Packit Service 82fcde
are reported.
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Memory}, describes @theglibc{}'s facilities for managing and
Packit Service 82fcde
using virtual and real memory, including dynamic allocation of virtual
Packit Service 82fcde
memory.  If you do not know in advance how much memory your program
Packit Service 82fcde
needs, you can allocate it dynamically instead, and manipulate it via
Packit Service 82fcde
pointers.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Character Handling}, contains information about character
Packit Service 82fcde
classification functions (such as @code{isspace}) and functions for
Packit Service 82fcde
performing case conversion.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{String and Array Utilities}, has descriptions of functions for
Packit Service 82fcde
manipulating strings (null-terminated character arrays) and general
Packit Service 82fcde
byte arrays, including operations such as copying and comparison.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Character Set Handling}, contains information about manipulating
Packit Service 82fcde
characters and strings using character sets larger than will fit in
Packit Service 82fcde
the usual @code{char} data type.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Locales}, describes how selecting a particular country
Packit Service 82fcde
or language affects the behavior of the library.  For example, the locale
Packit Service 82fcde
affects collation sequences for strings and how monetary values are
Packit Service 82fcde
formatted.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Searching and Sorting}, contains information about functions
Packit Service 82fcde
for searching and sorting arrays.  You can use these functions on any
Packit Service 82fcde
kind of array by providing an appropriate comparison function.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Pattern Matching}, presents functions for matching regular expressions
Packit Service 82fcde
and shell file name patterns, and for expanding words as the shell does.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{I/O Overview}, gives an overall look at the input and output
Packit Service 82fcde
facilities in the library, and contains information about basic concepts
Packit Service 82fcde
such as file names.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{I/O on Streams}, describes I/O operations involving streams (or
Packit Service 82fcde
@w{@code{FILE *}} objects).  These are the normal C library functions
Packit Service 82fcde
from @file{stdio.h}.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Low-Level I/O}, contains information about I/O operations
Packit Service 82fcde
on file descriptors.  File descriptors are a lower-level mechanism
Packit Service 82fcde
specific to the Unix family of operating systems.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{File System Interface}, has descriptions of operations on entire
Packit Service 82fcde
files, such as functions for deleting and renaming them and for creating
Packit Service 82fcde
new directories.  This chapter also contains information about how you
Packit Service 82fcde
can access the attributes of a file, such as its owner and file protection
Packit Service 82fcde
modes.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Pipes and FIFOs}, contains information about simple interprocess
Packit Service 82fcde
communication mechanisms.  Pipes allow communication between two related
Packit Service 82fcde
processes (such as between a parent and child), while FIFOs allow
Packit Service 82fcde
communication between processes sharing a common file system on the same
Packit Service 82fcde
machine.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Sockets}, describes a more complicated interprocess communication
Packit Service 82fcde
mechanism that allows processes running on different machines to
Packit Service 82fcde
communicate over a network.  This chapter also contains information about
Packit Service 82fcde
Internet host addressing and how to use the system network databases.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Low-Level Terminal Interface}, describes how you can change the
Packit Service 82fcde
attributes of a terminal device.  If you want to disable echo of
Packit Service 82fcde
characters typed by the user, for example, read this chapter.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Mathematics}, contains information about the math library
Packit Service 82fcde
functions.  These include things like random-number generators and
Packit Service 82fcde
remainder functions on integers as well as the usual trigonometric and
Packit Service 82fcde
exponential functions on floating-point numbers.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Arithmetic,, Low-Level Arithmetic Functions}, describes functions
Packit Service 82fcde
for simple arithmetic, analysis of floating-point values, and reading
Packit Service 82fcde
numbers from strings.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Date and Time}, describes functions for measuring both calendar time
Packit Service 82fcde
and CPU time, as well as functions for setting alarms and timers.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Non-Local Exits}, contains descriptions of the @code{setjmp} and
Packit Service 82fcde
@code{longjmp} functions.  These functions provide a facility for
Packit Service 82fcde
@code{goto}-like jumps which can jump from one function to another.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Signal Handling}, tells you all about signals---what they are,
Packit Service 82fcde
how to establish a handler that is called when a particular kind of
Packit Service 82fcde
signal is delivered, and how to prevent signals from arriving during
Packit Service 82fcde
critical sections of your program.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Program Basics}, tells how your programs can access their
Packit Service 82fcde
command-line arguments and environment variables.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Processes}, contains information about how to start new processes
Packit Service 82fcde
and run programs.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Job Control}, describes functions for manipulating process groups
Packit Service 82fcde
and the controlling terminal.  This material is probably only of
Packit Service 82fcde
interest if you are writing a shell or other program which handles job
Packit Service 82fcde
control specially.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Name Service Switch}, describes the services which are available
Packit Service 82fcde
for looking up names in the system databases, how to determine which
Packit Service 82fcde
service is used for which database, and how these services are
Packit Service 82fcde
implemented so that contributors can design their own services.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{User Database}, and @ref{Group Database}, tell you how to access
Packit Service 82fcde
the system user and group databases.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{System Management}, describes functions for controlling and getting
Packit Service 82fcde
information about the hardware and software configuration your program
Packit Service 82fcde
is executing under.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{System Configuration}, tells you how you can get information about
Packit Service 82fcde
various operating system limits.  Most of these parameters are provided for
Packit Service 82fcde
compatibility with POSIX.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Language Features}, contains information about library support for
Packit Service 82fcde
standard parts of the C language, including things like the @code{sizeof}
Packit Service 82fcde
operator and the symbolic constant @code{NULL}, how to write functions
Packit Service 82fcde
accepting variable numbers of arguments, and constants describing the
Packit Service 82fcde
ranges and other properties of the numerical types.  There is also a simple
Packit Service 82fcde
debugging mechanism which allows you to put assertions in your code, and
Packit Service 82fcde
have diagnostic messages printed if the tests fail.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Library Summary}, gives a summary of all the functions, variables, and
Packit Service 82fcde
macros in the library, with complete data types and function prototypes,
Packit Service 82fcde
and says what standard or system each is derived from.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Installation}, explains how to build and install @theglibc{} on
Packit Service 82fcde
your system, and how to report any bugs you might find.
Packit Service 82fcde
Packit Service 82fcde
@item
Packit Service 82fcde
@ref{Maintenance}, explains how to add new functions or port the
Packit Service 82fcde
library to a new system.
Packit Service 82fcde
@end itemize
Packit Service 82fcde
Packit Service 82fcde
If you already know the name of the facility you are interested in, you
Packit Service 82fcde
can look it up in @ref{Library Summary}.  This gives you a summary of
Packit Service 82fcde
its syntax and a pointer to where you can find a more detailed
Packit Service 82fcde
description.  This appendix is particularly useful if you just want to
Packit Service 82fcde
verify the order and type of arguments to a function, for example.  It
Packit Service 82fcde
also tells you what standard or system each function, variable, or macro
Packit Service 82fcde
is derived from.