header files" -- Overview" "

A header file is a file of C code that contains definitions, declarations, and structures commonly used in a given situation. By tradition, a header file always has the suffix ``.h''. Header files are invoked within a C program by the command ##iinncclluuddee, which is read by cpp, the C preprocessor; for this reason, they are also called ``include files''.

Header files are one of the most useful tools available to a C programmer. They allow you to put into one place all of the information that the different modules of your program share. Proper use of header files will make your programs easier to maintain and to port to other environments.

COHERENT includes the following header files:

aa..oouutt..hh          Include all COFF header files
aacccctt..hh           Format for process-accounting file
aarr..hh             Format for archive files
aasssseerrtt..hh         Define aasssseerrtt(())
ssyyss//bbuuff..hh        Buffer header
ssyyss//ccddrroomm..hh      Definitions for CD-ROM drives
ccooffff..hh           Format for COHERENT objects
ssyyss//ccoonn..hh        Configure device drivers
ssyyss//ccoorree..hh       Declare structure of a ccoorree file
ccttyyppee..hh          Header file for data tests
ccuurrsseess..hh         Declare/define ccuurrsseess routines
ddbbmm..hh            Header file for DBM routines
ssyyss//ddeeffttttyy..hh     Default tty settings
ddiirreenntt..hh         Define constant ddiirreenntt
eerrrrnnoo..hh          Error numbers used by eerrrrnnoo(())
ffccnnttll..hh          Manifest constants for file-handling functions
ssyyss//ffdd..hh         Declare file-descriptor structure
ssyyss//ffddiiooccttll..hh    Control floppy-disk I/O
ssyyss//ffddiisskk..hh      Fixed-disk constants and structures
ssyyss//ffiillssyyss..hh     Structures and constants for super block
ffllooaatt..hh          Define constants for floating-point numbers
ffnnmmaattcchh..hh        Constants used with function ffnnmmaattcchh(())
ffppeerrrr..hh          Constants used with floating-point exception codes
ggddbbmm..hh           Header file for GDBM routines
ggddbbmmeerrrrnnoo..hh      Define error messages used by GDBM routines
ggrrpp..hh            Declare group structure
ssyyss//hhddiiooccttll..hh    Control hard-disk I/O
ssyyss//iinnoo..hh        Constants and structures for i-nodes
ssyyss//iinnooddee..hh      Constants and structures for memory-resident i-nodes
ssyyss//iioo..hh         Constants and structures used by I/O
ssyyss//iippcc..hh        Declarations for interprocess communication
ssyyss//kkbb..hh         Define keys for loadable keyboard driver
ll..oouutt..hh          Format for COHERENT-286 objects
lliimmiittss..hh         Define numerical limits
ssyyss//llppiiooccttll..hh    Definitions for line-printer I/O control
mmaatthh..hh           Declare mathematics functions
mmnnttttaabb..hh         Structure for mount table
mmoonn..hh            Read profile output files
ssyyss//mmoouunntt..hh      Define the mount table
mmpprreecc..hh          Multiple-precision arithmetic
ssyyss//mmssgg..hh        Definitions for message facility
mmttaabb..hh           Currently mounted file systems
ssyyss//mmttiiooccttll..hh    Magnetic-tape I/O control
mmttyyppee..hh          List processor code numbers
nn..oouutt..hh          Define nn..oouutt file structure
nnddbbmm..hh           Header file for NDBM routines
nneettddbb..hh          Define structures used to describe networks
ppaatthh..hh           Define/declare constants and functions used with ppaatthh
ppoollll..hh           Define structures/constants used with polling devices
ssyyss//pprroocc..hh       Define structures/constants used with processes
ssyyss//ppttrraaccee..hh     Perform process tracing
ppwwdd..hh            Define password structure
rreeggeexxpp..hh         Header file for regular-expression functions
ssyyss//sscchheedd..hh      Define constants used with scheduling
ssyyss//sseegg..hh        Definitions used with segmentation
ssyyss//sseemm..hh        Definitions used by semaphore facility
sseettjjmmpp..hh         Define sseettjjmmpp(()) and lloonnggjjmmpp(())
ssggttttyy..hh          Definitions used to control terminal I/O
sshhaaddooww..hh         Definitions used with shadow passwords
ssyyss//sshhmm..hh        Definitions used with shared memory
ssiiggnnaall..hh         Define signals
ssoocckkeett..hh         Define constants and structures with ssoocckkeettss
ssyyss//ssttaatt..hh       Definitions and declarations used to obtain file status
ssttddaarrgg..hh         Declare/define routines for variable arguments
ssttddddeeff..hh         Declare/define standard definitions
ssttddiioo..hh          Declarations and definitions for I/O
ssttddlliibb..hh         Declare/define general functions
ssyyss//ssttrreeaamm..hh     Definitions for message facility
ssttrriinngg..hh         Declare string functions
ssttrrooppttss..hh        User-level STREAMS routines
tteerrmmiioo..hh         Definitions used with terminal input and output
tteerrmmiiooss..hh        Definitions used with POSIX extended terminal interface
ttiimmee..hh           Give time-description structure
ssyyss//ttiimmeebb..hh      Define ttiimmeebb structure
ssyyss//ttiimmeess..hh      Definitions used with ttiimmeess(()) system call
ssyyss//ttttyy..hh        Define flags used with tty processing
ssyyss//ttyyppeess..hh      Define system-specific data types
uulliimmiitt..hh         Define manifest constants used by system call uulliimmiitt(())
uunnccttrrll..hh         Define macro uunnccttrrll(())
uunniissttdd..hh         Define constants for file-handling routines
ssyyss//uupprroocc..hh      Definitions used with user processes
uuttiimmee..hh          Declare system call uuttiimmee(())
uuttmmpp..hh           Login accounting information
ssyyss//uuttssnnaammee..hh    Define uuttssnnaammee structure
vvaarraarrggss..hh        Declare/define routines for variable arguments
ssyyss//wwaaiitt..hh       Define wait routines

Compilation Environments and Feature Tests

The COHERENT header files are designed to let you invoke any of several ``compilation environments''. Each environment offers its own features; in this way, you can easily import code that conforms to the POSIX or ANSI standards, compile device drivers, or otherwise fine tune how your programs are compiled. To invoke a given compilation environment, you must set a feature test.

As discussed in the Lexicon article name space, the ISO Standard" reserves for the implementation every identifier that begins with a single underscore followed by an upper-case letter. The POSIX Standard"s define several symbols in this name space that the implementation can use as ``feature tests'' -- that is, as symbols that you can use in your source code to determine the presence or absence of a particular feature or combination of features. Note that a feature test applies to an implementation of C, rather than to an operating system. A feature test combines aspects of the host system and the language translator: some tests apply to the operating system, some purely to the C translator.

The operating system's header files can define them (for example, _POSIX_SAVED_IDS) to control compilation of user code or to deal with optional features, or you can define them (e.g., _POSIX_C_SOURCE) to control how the system's header files declare or define constants, types, structures, and macros.

In general, a feature test must either be undefined or have an integer value. It must not be defined as having no expansion text, or expand into a string. For example,

     # CORRECT
     cc -D_POSIX_C_SOURCE=1 foo.c

is correct, as is:

     # CORRECT
     cc -U_POSIX_C_SOURCE foo.c

However,

     # WRONG
     cc -D_POSIX_C_SOURCE foo.c

is incorrect, as is:

     # WRONG
     cc -D_POSIX_C_SOURCE="yes" foo.c

This is to permit the constants to be tested with expressions like

     #if _POSIX_C_SOURCE > 1

where an integer value is required. (If the symbol is used in a #if test and is undefined, cpp replaces it with zero, which is still an integer value). This permits the implementation to use different values of the feature test to invoke different feature sets; and it simplifies testing for complex combinations of feature tests.

Although nearly all feature tests behave as shown above, there are a few exceptions, namely _POSIX_SOURCE and _KERNEL. These symbols are not defined as having a specific value, so many users do not supply a value. To deal with this, the COHERENT header files check whether these constants have expansion text. If they do not, the header files redefine these constants with value 1, so that they can be used like the other feature tests that the COHERENT header files define.

The following describes the feature tests used in the COHERENT header files, and briefly describes the compilation environment each invokes. Because we are continually adding new features to the kernel, this list is not guaranteed to be complete.

__DDDDII__DDKKII
Invoke the environment for compiling device drivers. This environment makes visible all DDI/DKI function prototypes and data definitions, and defines all fundamental data types and structures as mandated by UNIX System V, Release 4.

Please note that this feature test is an COHERENT extension, and is not portable to other operating systems.

__KKEERRNNEELL
Invoke the environment for compiling the kernel or a device driver. This environment gives code full access to system's private header files. Under COHERENT, this option is equivalent to defining _DDI_DKI to value 1, because COHERENT only supports compiling DDI/DKI driver source code from System V, Release 4. This means that the definitions of many fundamental data types such as pid_t are changed to the System V, Release 4 definitions rather than the System V, Release 3 definitions used by user code. (This is a System V convention.)

__PPOOSSIIXX__SSOOUURRCCEE
__PPOOSSIIXX__CC__SSOOUURRCCEE
Select a ``clean'' compilation environment, in which the headers defined in the POSIX.1 or POSIX.2 standards define no symbols other than the ones that those environments require. Defining _POSIX_C_SOURCE with value 1 selects the POSIX.1 environment, as defined in the POSIX.1 standard. Defining _POSIX_C_SOURCE with value 2 selects the POSIX.2 environment, as defined in the POSIX.2 standard. Defining _POSIX_SOURCE has the same effect as defining _POSIX_C_SOURCE with value 1.

__SSTTDDCC__SSOOUURRCCEE
Select a ``clean'' compilation environment. In this environment, the headers that the ANSI C standard defines define no symbols other than those that the standard requires. This feature test is designed to let you compile conforming Standard C programs that themselves define functions or macros that the COHERENT header files defined in addition to those described in the ANSI standard.

Please note that this feature test is an COHERENT extension, and is not portable to other operating systems.

__SSUUPPPPRREESSSS__BBSSDD__DDEEFFIINNIITTIIOONNSS
This feature test invokes a compilation environment that excludes all definitions that are included for compatibility with Berkeley UNIX. As of this writing, this feature test affects only the header file <string.h>, and prevents it from defining the macros bcopy(), bzero(), index(), and rindex(). Note that selecting a POSIX or Standard C environment also suppresses these definitions.

Please note that this feature test is an COHERENT extension, and is not portable to other operating systems.

__SSYYSSVV33
This feature test invokes a compilation environment in which all fundamental types and data structures have the definitions mandated by UNIX System V, Release 3.

__SSYYSSVV44
This feature test invokes a compilation environment in which all fundamental types and data structures have the definitions mandated by UNIX System V, Release 4. As of this writing, this facility is incomplete and used mainly to develop device drivers and extensions to the kernel.

Please note that this feature test is an COHERENT extension, and is not portable to other operating systems.

See Also