[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
How you should define the four hook

functions that a custom stream needs.

Formatted Messages

12.22.1 Printing Formatted Messages  The fmtmsg function. 12.22.2 Adding Severity Classes  Add more severity classes. 12.22.3 How to use fmtmsg and addseverity  How to use fmtmsg and addseverity.

Low-Level I/O

13.1 Opening and Closing Files  How to open and close file descriptors. 13.2 Input and Output Primitives  Reading and writing data. 13.3 Setting the File Position of a Descriptor  Setting a descriptor’s file position. 13.4 Descriptors and Streams  Converting descriptor to stream or vice-versa. 13.5 Dangers of Mixing Streams and Descriptors  Precautions needed if you use both descriptors and streams. 13.6 Fast Scatter-Gather I/O  Fast I/O to discontinuous buffers. 13.7 Memory-mapped I/O  Using files like memory. 13.8 Waiting for Input or Output  How to check for input or output on multiple file descriptors. 13.9 Synchronizing I/O operations  Making sure all I/O actions completed. 13.10 Perform I/O Operations in Parallel  Perform I/O in parallel. 13.11 Control Operations on Files  Various other operations on file descriptors. 13.12 Duplicating Descriptors  Fcntl commands for duplicating file descriptors. 13.13 File Descriptor Flags  Fcntl commands for manipulating flags associated with file descriptors. 13.14 File Status Flags  Fcntl commands for manipulating flags associated with open files. 13.15 File Locks  Fcntl commands for implementing file locking. 13.16 Interrupt-Driven Input  Getting an asynchronous signal when input arrives. 13.17 Generic I/O Control operations  Generic I/O Control operations.

Stream/Descriptor Precautions

13.5.1 Linked Channels  Dealing with channels sharing a file position. 13.5.2 Independent Channels  Dealing with separately opened, unlinked channels. 13.5.3 Cleaning Streams  Cleaning a stream makes it safe to use another channel.

Asynchronous I/O

13.10.1 Asynchronous Read and Write Operations  Asynchronous Read and Write Operations. 13.10.2 Getting the Status of AIO Operations  Getting the Status of AIO Operations. 13.10.3 Getting into a Consistent State  Getting into a consistent state. 13.10.4 Cancellation of AIO Operations  Cancellation of AIO Operations. 13.10.5 How to optimize the AIO implementation  How to optimize the AIO implementation.

File Status Flags

13.14.1 File Access Modes  Whether the descriptor can read or write. 13.14.2 Open-time Flags  Details of open. 13.14.3 I/O Operating Modes  Special modes to control I/O operations. 13.14.4 Getting and Setting File Status Flags  Fetching and changing these flags.

File System Interface

14.1 Working Directory  This is used to resolve relative file names. 14.2 Accessing Directories  Finding out what files a directory contains. 14.3 Working with Directory Trees  Apply actions to all files or a selectable subset of a directory hierarchy. 14.4 Hard Links  Adding alternate names to a file. 14.5 Symbolic Links  A file that “points to” a file name. 14.6 Deleting Files  How to delete a file, and what that means. 14.7 Renaming Files  Changing a file’s name. 14.8 Creating Directories  A system call just for creating a directory. 14.9 File Attributes  Attributes of individual files. 14.10 Making Special Files  How to create special files. 14.11 Temporary Files  Naming and creating temporary files.

Accessing Directories

14.2.1 Format of a Directory Entry  Format of one directory entry. 14.2.2 Opening a Directory Stream  How to open a directory stream. 14.2.3 Reading and Closing a Directory Stream  How to read directory entries from the stream. 14.2.4 Simple Program to List a Directory  A very simple directory listing program. 14.2.5 Random Access in a Directory Stream  Rereading part of the directory already read with the same stream. 14.2.6 Scanning the Content of a Directory  Get entries for user selected subset of contents in given directory. 14.2.7 Simple Program to List a Directory, Mark II  Revised version of the program.

File Attributes

14.9.1 The meaning of the File Attributes  The names of the file attributes, and what their values mean. 14.9.2 Reading the Attributes of a File  How to read the attributes of a file. 14.9.3 Testing the Type of a File  Distinguishing ordinary files, directories, links… 14.9.4 File Owner  How ownership for new files is determined, and how to change it. 14.9.5 The Mode Bits for Access Permission  How information about a file’s access mode is stored. 14.9.6 How Your Access to a File is Decided  How the system decides who can access a file. 14.9.7 Assigning File Permissions  How permissions for new files are assigned, and how to change them. 14.9.8 Testing Permission to Access a File  How to find out if your process can access a file. 14.9.9 File Times  About the time attributes of a file. 14.9.10 File Size  Manually changing the size of a file.

Pipes and FIFOs

15.1 Creating a Pipe  Making a pipe with the pipe function. 15.2 Pipe to a Subprocess  Using a pipe to communicate with a child process. 15.3 FIFO Special Files  Making a FIFO special file. 15.4 Atomicity of Pipe I/O  When pipe (or FIFO) I/O is atomic.

Sockets

16.1 Socket Concepts  Basic concepts you need to know about. 16.2 Communication Styles Stream communication, datagrams and other styles. 16.3 Socket Addresses  How socket names (“addresses”) work. 16.4 Interface Naming  Identifying specific network interfaces. 16.5 The Local Namespace  Details about the local namespace. 16.6 The Internet Namespace  Details about the Internet namespace. 16.7 Other Namespaces  Other namespaces not documented fully here. 16.8 Opening and Closing Sockets  Creating sockets and destroying them. 16.9 Using Sockets with Connections  Operations on sockets with connection state. 16.10 Datagram Socket Operations  Operations on datagram sockets. 16.11 The inetd Daemon  Inetd is a daemon that starts servers on request. The most convenient way to write a server is to make it work with Inetd. 16.12 Socket Options  Miscellaneous low-level socket options. 16.13 Networks Database  Accessing the database of network names.

Socket Addresses

16.3.1 Address Formats  About struct sockaddr. 16.3.2 Setting the Address of a Socket  Binding an address to a socket. 16.3.3 Reading the Address of a Socket  Reading the address of a socket.

Local Namespace

16.5.1 Local Namespace Concepts  What you need to understand. 16.5.2 Details of Local Namespace  Address format, symbolic names, etc. 16.5.3 Example of Local-Namespace Sockets  Example of creating a socket.

Internet Namespace

16.6.1 Internet Socket Address Formats  How socket addresses are specified in the Internet namespace. 16.6.2 Host Addresses  All about host addresses of Internet host. 16.6.6 Protocols Database  Referring to protocols by name. 16.6.3 Internet Ports  Internet port numbers. 16.6.4 The Services Database  Ports may have symbolic names. 16.6.5 Byte Order Conversion  Different hosts may use different byte ordering conventions; you need to canonicalize host address and port number. 16.6.7 Internet Socket Example  Putting it all together.

Host Addresses

16.6.2.1 Internet Host Addresses  What a host number consists of. 16.6.2.2 Host Address Data Type  Data type for a host number. 16.6.2.3 Host Address Functions  Functions to operate on them. 16.6.2.4 Host Names  Translating host names to host numbers.

Open/Close Sockets

16.8.1 Creating a Socket  How to open a socket. 16.8.2 Closing a Socket  How to close a socket. 16.8.3 Socket Pairs  These are created like pipes.

Connections

16.9.1 Making a Connection  What the client program must do. 16.9.2 Listening for Connections  How a server program waits for requests. 16.9.3 Accepting Connections  What the server does when it gets a request. 16.9.4 Who is Connected to Me?  Getting the address of the other side of a connection. 16.9.5 Transferring Data  How to send and receive data. 16.9.6 Byte Stream Socket Example  An example program: a client for communicating over a byte stream socket in the Internet namespace. 16.9.7 Byte Stream Connection Server Example  A corresponding server program. 16.9.8 Out-of-Band Data  This is an advanced feature.

Transferring Data

16.9.5.1 Sending Data  Sending data with send. 16.9.5.2 Receiving Data  Reading data with recv. 16.9.5.3 Socket Data Options  Using send and recv.

Datagrams

16.10.1 Sending Datagrams  Sending packets on a datagram socket. 16.10.2 Receiving Datagrams  Receiving packets on a datagram socket. 16.10.3 Datagram Socket Example  An example program: packets sent over a datagram socket in the local namespace. 16.10.4 Example of Reading Datagrams  Another program, that receives those packets.

Inetd

16.11.1 inetd Servers  16.11.2 Configuring inetd 

Socket Options

16.12.1 Socket Option Functions  The basic functions for setting and getting socket options. 16.12.2 Socket-Level Options  Details of the options at the socket level.

Low-Level Terminal Interface

17.1 Identifying Terminals  How to determine if a file is a terminal device, and what its name is. 17.2 I/O Queues  About flow control and typeahead. 17.3 Two Styles of Input: Canonical or Not  Two basic styles of input processing. 17.4 Terminal Modes  How to examine and modify flags controlling details of terminal I/O: echoing, signals, editing. Posix. 17.5 BSD Terminal Modes  BSD compatible terminal mode setting 17.6 Line Control Functions  Sending break sequences, clearing terminal buffers … 17.7 Noncanonical Mode Example  How to read single characters without echo. 17.8 Pseudo-Terminals  How to open a pseudo-terminal.

Terminal Modes

17.4.1 Terminal Mode Data Types  The data type struct termios and related types. 17.4.2 Terminal Mode Functions  Functions to read and set the terminal attributes. 17.4.3 Setting Terminal Modes Properly  The right way to set terminal attributes reliably. 17.4.4 Input Modes  Flags controlling low-level input handling. 17.4.5 Output Modes  Flags controlling low-level output handling. 17.4.6 Control Modes  Flags controlling serial port behavior. 17.4.7 Local Modes  Flags controlling high-level input handling. 17.4.8 Line Speed  How to read and set the terminal line speed. 17.4.9 Special Characters  Characters that have special effects, and how to change them. 17.4.10 Noncanonical Input  Controlling how long to wait for input.

Special Characters

17.4.9.1 Characters for Input Editing  Special characters that terminate lines and delete text, and other editing functions. 17.4.9.2 Characters that Cause Signals  Special characters that send or raise signals to or for certain classes of processes. 17.4.9.3 Special Characters for Flow Control  Special characters that suspend or resume suspended output. 17.4.9.4 Other Special Characters  Other special characters for BSD systems: they can discard output, and print status.

Pseudo-Terminals

17.8.1 Allocating Pseudo-Terminals  Allocating a pseudo terminal. 17.8.2 Opening a Pseudo-Terminal Pair  How to open both sides of a pseudo-terminal in a single operation.

Syslog

18.1 Overview of Syslog  Overview of a system’s Syslog facility 18.2 Submitting Syslog Messages  Functions to submit messages to Syslog

Submitting Syslog Messages

18.2.1 openlog  Open connection to Syslog 18.2.2 syslog, vsyslog  Submit message to Syslog 18.2.3 closelog  Close connection to Syslog 18.2.4 setlogmask  Cause certain messages to be ignored 18.2.5 Syslog Example  Example of all of the above

Mathematics

19.1 Predefined Mathematical Constants  Precise numeric values for often-used constants. 19.2 Trigonometric Functions  Sine, cosine, tangent, and friends. 19.3 Inverse Trigonometric Functions  Arcsine, arccosine, etc. 19.4 Exponentiation and Logarithms  Also pow and sqrt. 19.5 Hyperbolic Functions  sinh, cosh, tanh, etc. 19.6 Special Functions  Bessel, gamma, erf. 19.7 Known Maximum Errors in Math Functions  Known Maximum Errors in Math Functions. 19.8 Pseudo-Random Numbers  Functions for generating pseudo-random numbers. 19.9 Is Fast Code or Small Code preferred?  Fast code or small code.

Pseudo-Random Numbers

19.8.1 ISO C Random Number Functions  rand and friends. 19.8.2 BSD Random Number Functions  random and friends. 19.8.3 SVID Random Number Function  drand48 and friends.

Arithmetic

20.1 Integers  Basic integer types and concepts 20.2 Integer Division  Integer division with guaranteed rounding. 20.3 Floating Point Numbers  Basic concepts. IEEE 754. 20.4 Floating-Point Number Classification Functions  The five kinds of floating-point number. 20.5 Errors in Floating-Point Calculations  When something goes wrong in a calculation. 20.6 Rounding Modes  Controlling how results are rounded. 20.7 Floating-Point Control Functions  Saving and restoring the FPU’s state. 20.8 Arithmetic Functions  Fundamental operations provided by the library. 20.9 Complex Numbers  The types. Writing complex constants. 20.10 Projections, Conjugates, and Decomposing of Complex Numbers  Projection, conjugation, decomposition. 20.11 Parsing of Numbers  Converting strings to numbers. 20.12 Old-fashioned System V number-to-string functions  An archaic way to convert numbers to strings.

Floating Point Errors

20.5.1 FP Exceptions  IEEE 754 math exceptions and how to detect them. 20.5.2 Infinity and NaN  Special values returned by calculations. 20.5.3 Examining the FPU status word  Checking for exceptions after the fact. 20.5.4 Error Reporting by Mathematical Functions  How the math functions report errors.

Arithmetic Functions

20.8.1 Absolute Value  Absolute values of integers and floats. 20.8.2 Normalization Functions  Extracting exponents and putting them back. 20.8.3 Rounding Functions  Rounding floats to integers. 20.8.4 Remainder Functions  Remainders on division, precisely defined. 20.8.5 Setting and modifying single bits of FP values  Sign bit adjustment. Adding epsilon. 20.8.6 Floating-Point Comparison Functions  Comparisons without risk of exceptions. 20.8.7 Miscellaneous FP arithmetic functions  Max, min, positive difference, multiply-add.

Parsing of Numbers

20.11.1 Parsing of Integers  Functions for conversion of integer values. 20.11.2 Parsing of Floats  Functions for conversion of floating-point values.

Date and Time

21.1 Time Basics  Concepts and definitions. 21.2 Elapsed Time  Data types to represent elapsed times 21.3 Processor And CPU Time  Time a program has spent executing. 21.4 Calendar Time  Manipulation of “real” dates and times. 21.5 Setting an Alarm  Sending a signal after a specified time. 21.6 Sleeping  Waiting for a period of time.

Processor And CPU Time

21.3.1 CPU Time Inquiry  The clock function. 21.3.2 Processor Time Inquiry  The times function.

Calendar Time

21.4.1 Simple Calendar Time  Facilities for manipulating calendar time. 21.4.2 High-Resolution Calendar  A time representation with greater precision. 21.4.3 Broken-down Time  Facilities for manipulating local time. 21.4.4 High Accuracy Clock  Maintaining a high accuracy system clock. 21.4.5 Formatting Calendar Time  Converting times to strings. 21.4.6 Convert textual time and date information back  Convert textual time and date information back into broken-down time values. 21.4.7 Specifying the Time Zone with TZ  How users specify the time zone. 21.4.8 Functions and Variables for Time Zones  Functions to examine or specify the time zone. 21.4.9 Time Functions Example  An example program showing use of some of the time functions.

Parsing Date and Time

21.4.6.1 Interpret string according to given format  Interpret string according to given format. 21.4.6.2 A More User-friendly Way to Parse Times and Dates  User-friendly function to parse data and time strings.

Resource Usage And Limitation

22.1 Resource Usage  Measuring various resources used. 22.2 Limiting Resource Usage  Specifying limits on resource usage. 22.3 Process CPU Priority And Scheduling  Reading or setting process run priority. 22.4 Querying memory available resources  Querying memory available resources. 22.5 Learn about the processors available  Learn about the processors available.

Priority

22.3.1 Absolute Priority  The first tier of priority. Posix 22.3.2 Realtime Scheduling  Scheduling among the process nobility 22.3.3 Basic Scheduling Functions  Get/set scheduling policy, priority 22.3.4 Traditional Scheduling  Scheduling among the vulgar masses 22.3.5 Limiting execution to certain CPUs  Limiting execution to certain CPUs

Traditional Scheduling

22.3.4.1 Introduction To Traditional Scheduling  22.3.4.2 Functions For Traditional Scheduling 

Memory Resources

22.4.1 Overview about traditional Unix memory handling  Overview about traditional Unix memory handling. 22.4.2 How to get information about the memory subsystem?  How to get information about the memory subsystem?

Non-Local Exits

23.1 Introduction to Non-Local Exits  When and how to use these facilities. 23.2 Details of Non-Local Exits  Functions for non-local exits. 23.3 Non-Local Exits and Signals  Portability issues. 23.4 Complete Context Control  Complete context control a la System V.

Signal Handling

24.1 Basic Concepts of Signals  Introduction to the signal facilities. 24.2 Standard Signals  Particular kinds of signals with standard names and meanings. 24.3 Specifying Signal Actions  Specifying what happens when a particular signal is delivered. 24.4 Defining Signal Handlers  How to write a signal handler function. 24.5 Primitives Interrupted by Signals  Signal handlers affect use of open, read, write and other functions. 24.6 Generating Signals  How to send a signal to a process. 24.7 Blocking Signals  Making the system hold signals temporarily. 24.8 Waiting for a Signal  Suspending your program until a signal arrives. 24.9 Using a Separate Signal Stack  Using a Separate Signal Stack. 24.10 BSD Signal Handling  Additional functions for backward compatibility with BSD.

Concepts of Signals

24.1.1 Some Kinds of Signals  Some examples of what can cause a signal. 24.1.2 Concepts of Signal Generation  Concepts of why and how signals occur. 24.1.3 How Signals Are Delivered  Concepts of what a signal does to the process.

Standard Signals

24.2.1 Program Error Signals  Used to report serious program errors. 24.2.2 Termination Signals  Used to interrupt and/or terminate the program. 24.2.3 Alarm Signals  Used to indicate expiration of timers. 24.2.4 Asynchronous I/O Signals  Used to indicate input is available. 24.2.5 Job Control Signals  Signals used to support job control. 24.2.6 Operation Error Signals  Used to report operational system errors. 24.2.7 Miscellaneous Signals  Miscellaneous Signals. 24.2.8 Signal Messages  Printing a message describing a signal.

Signal Actions

24.3.1 Basic Signal Handling  The simple signal function. 24.3.2 Advanced Signal Handling  The more powerful sigaction function. 24.3.3 Interaction of signal and sigaction  How those two functions interact. 24.3.4 sigaction Function Example  An example of using the sigaction function. 24.3.5 Flags for sigaction  Specifying options for signal handling. 24.3.6 Initial Signal Actions  How programs inherit signal actions.

Defining Handlers

24.4.1 Signal Handlers that Return  Handlers that return normally, and what this means. 24.4.2 Handlers That Terminate the Process  How handler functions terminate a program. 24.4.3 Nonlocal Control Transfer in Handlers  Nonlocal transfer of control out of a signal handler. 24.4.4 Signals Arriving While a Handler Runs  What happens when signals arrive while the handler is already occupied. 24.4.5 Signals Close Together Merge into One  When a second signal arrives before the first is handled. 24.4.6 Signal Handling and Nonreentrant Functions  Do not call any functions unless you know they are reentrant with respect to signals. 24.4.7 Atomic Data Access and Signal Handling  A single handler can run in the middle of reading or writing a single object.

Atomic Data Access

24.4.7.1 Problems with Non-Atomic Access  A program illustrating interrupted access. 24.4.7.2 Atomic Types  Data types that guarantee no interruption. 24.4.7.3 Atomic Usage Patterns  Proving that interruption is harmless.

Generating Signals

24.6.1 Signaling Yourself  A process can send a signal to itself. 24.6.2 Signaling Another Process  Send a signal to another process. 24.6.3 Permission for using kill  Permission for using kill. 24.6.4 Using kill for Communication  Using kill for Communication.

Blocking Signals

24.7.1 Why Blocking Signals is Useful  The purpose of blocking signals. 24.7.2 Signal Sets  How to specify which signals to block. 24.7.3 Process Signal Mask  Blocking delivery of signals to your process during normal execution. 24.7.4 Blocking to Test for Delivery of a Signal  Blocking to Test for Delivery of a Signal. 24.7.5 Blocking Signals for a Handler  Blocking additional signals while a handler is being run. 24.7.6 Checking for Pending Signals  Checking for Pending Signals 24.7.7 Remembering a Signal to Act On Later  How you can get almost the same effect as blocking a signal, by handling it and setting a flag to be tested later.

Waiting for a Signal

24.8.1 Using pause  The simple way, using pause. 24.8.2 Problems with pause  Why the simple way is often not very good. 24.8.3 Using sigsuspend  Reliably waiting for a specific signal.

BSD Signal Handling

24.10.1 BSD Function to Establish a Handler  BSD Function to Establish a Handler. 24.10.2 BSD Functions for Blocking Signals  BSD Functions for Blocking Signals.

Program Basics

25.1 Program Arguments  Parsing your program’s command-line arguments. 25.4 Environment Variables  Less direct parameters affecting your program 25.5 System Calls  Requesting service from the system 25.6 Program Termination  Telling the system you’re done; return status

Program Arguments

25.1.1 Program Argument Syntax Conventions  By convention, options start with a hyphen. 25.1.2 Parsing Program Arguments  Ways to parse program options and arguments.

Parsing Program Arguments

25.2 Parsing program options using getopt  Parsing program options using getopt. 25.3 Parsing Program Options with Argp  Parsing program options using argp_parse. 25.3.12.1 Parsing of Suboptions  Some programs need more detailed options. 25.3.13 Parsing of Suboptions Example  This shows how it could be done for mount.

Environment Variables

25.4.1 Environment Access  How to get and set the values of environment variables. 25.4.2 Standard Environment Variables  These environment variables have standard interpretations.

Program Termination

25.6.1 Normal Termination  If a program calls exit, a process terminates normally. 25.6.2 Exit Status  The exit status provides information about why the process terminated. 25.6.3 Cleanups on Exit  A process can run its own cleanup functions upon normal termination. 25.6.4 Aborting a Program  The abort function causes abnormal program termination. 25.6.5 Termination Internals  What happens when a process terminates.

Processes

26.1 Running a Command  The easy way to run another program. 26.2 Process Creation Concepts  An overview of the hard way to do it. 26.3 Process Identification  How to get the process ID of a process. 26.4 Creating a Process  How to fork a child process. 26.5 Executing a File  How to make a process execute another program. 26.6 Process Completion  How to tell when a child process has completed. 26.7 Process Completion Status  How to interpret the status value returned from a child process. 26.8 BSD Process Wait Functions  More functions, for backward compatibility. 26.9 Process Creation Example  A complete example program.

Job Control

27.1 Concepts of Job Control  Jobs can be controlled by a shell. 27.2 Job Control is Optional  Not all POSIX systems support job control. 27.3 Controlling Terminal of a Process  How a process gets its controlling terminal. 27.4 Access to the Controlling Terminal  How processes share the controlling terminal. 27.5 Orphaned Process Groups  Jobs left after the user logs out. 27.6 Implementing a Job Control Shell  What a shell must do to implement job control. 27.7 Functions for Job Control  Functions to control process groups.

Implementing a Shell

27.6.1 Data Structures for the Shell  Introduction to the sample shell. 27.6.2 Initializing the Shell  What the shell must do to take responsibility for job control. 27.6.3 Launching Jobs  Creating jobs to execute commands. 27.6.4 Foreground and Background  Putting a job in foreground of background. 27.6.5 Stopped and Terminated Jobs  Reporting job status. 27.6.6 Continuing Stopped Jobs  How to continue a stopped job in the foreground or background. 27.6.7 The Missing Pieces  Other parts of the shell.

Functions for Job Control

27.7.1 Identifying the Controlling Terminal  Determining the controlling terminal’s name. 27.7.2 Process Group Functions  Functions for manipulating process groups. 27.7.3 Functions for Controlling Terminal Access  Functions for controlling terminal access.

Name Service Switch

28.1 NSS Basics  What is this NSS good for. 28.2 The NSS Configuration File  Configuring NSS. 28.3 NSS Module Internals  How does it work internally. 28.4 Extending NSS  What to do to add services or databases.

NSS Configuration File

28.2.1 Services in the NSS configuration File  Service names in the NSS configuration. 28.2.2 Actions in the NSS configuration  React appropriately to the lookup result. 28.2.3 Notes on the NSS Configuration File  Things to take care about while configuring NSS.

NSS Module Internals

28.3.1 The Naming Scheme of the NSS Modules  Construction of the interface function of the NSS modules. 28.3.2 The Interface of the Function in NSS Modules  Programming interface in the NSS module functions.

Extending NSS

28.4.1 Adding another Service to NSS  What is to do to add a new service. 28.4.2 Internals of the NSS Module Functions  Guidelines for writing new NSS service functions.

Users and Groups

29.1 User and Group IDs  Each user has a unique numeric ID; likewise for groups. 29.2 The Persona of a Process  The user IDs and group IDs of a process. 29.3 Why Change the Persona of a Process?  Why a program might need to change its user and/or group IDs. 29.4 How an Application Can Change Persona  Changing the user and group IDs. 29.5 Reading the Persona of a Process  How to examine the user and group IDs. 29.6 Setting the User ID  Functions for setting the user ID. 29.7 Setting the Group IDs  Functions for setting the group IDs. 29.8 Enabling and Disabling Setuid Access  Turning setuid access on and off. 29.9 Setuid Program Example  The pertinent parts of one sample program. 29.10 Tips for Writing Setuid Programs  How to avoid granting unlimited access. 29.11 Identifying Who Logged In  Getting the name of the user who logged in, or of the real user ID of the current process. 29.12 The User Accounting Database  Keeping information about users and various actions in databases. 29.13 User Database  Functions and data structures for accessing the user database. 29.14 Group Database  Functions and data structures for accessing the group database. 29.15 User and Group Database Example  Example program showing the use of database inquiry functions. 29.16 Netgroup Database  Functions for accessing the netgroup database.

User Accounting Database

29.12.1 Manipulating the User Accounting Database  Scanning and modifying the user accounting database. 29.12.2 XPG User Accounting Database Functions  A standardized way for doing the same thing. 29.12.3 Logging In and Out  Functions from BSD that modify the user accounting database.

User Database

29.13.1 The Data Structure that Describes a User  What each user record contains. 29.13.2 Looking Up One User  How to look for a particular user. 29.13.3 Scanning the List of All Users  Scanning the list of all users, one by one. 29.13.4 Writing a User Entry  How a program can rewrite a user’s record.

Group Database

29.14.1 The Data Structure for a Group  What each group record contains. 29.14.2 Looking Up One Group  How to look for a particular group. 29.14.3 Scanning the List of All Groups  Scanning the list of all groups.

Netgroup Database

29.16.1 Netgroup Data  Data in the Netgroup database and where it comes from. 29.16.2 Looking up one Netgroup  How to look for a particular netgroup. 29.16.3 Testing for Netgroup Membership  How to test for netgroup membership.

System Management

30.1 Host Identification  Determining the name of the machine. 30.2 Platform Type Identification  Determining operating system and basic machine type 30.3 Controlling and Querying Mounts  Controlling/querying mounts 30.4 System Parameters  Getting and setting various system parameters

Filesystem Handling

30.3.1 Mount Information  What is or could be mounted? 30.3.2 Mount, Unmount, Remount  Controlling what is mounted and how

Mount Information

30.3.1.1 The ‘fstab’ file  The ‘fstab’ file 30.3.1.2 The ‘mtab’ file  The ‘mtab’ file 30.3.1.3 Other (Non-libc) Sources of Mount Information  Other (non-libc) sources of mount information

System Configuration

31.1 General Capacity Limits  Constants and functions that describe various process-related limits that have one uniform value for any given machine. 31.2 Overall System Options  Optional POSIX features. 31.3 Which Version of POSIX is Supported  Version numbers of POSIX.1 and POSIX.2. 31.4 Using sysconf  Getting specific configuration values of general limits and system options. 31.5 Minimum Values for General Capacity Limits  Minimum values for general limits. 31.6 Limits on File System Capacity  Size limitations that pertain to individual files. These can vary between file systems or even from file to file. 31.7 Optional Features in File Support  Optional features that some files may support. 31.8 Minimum Values for File System Limits  Minimum values for file limits. 31.9 Using pathconf  Getting the limit values for a particular file. 31.10 Utility Program Capacity Limits  Capacity limits of some POSIX.2 utility programs. 31.11 Minimum Values for Utility Limits  Minimum allowable values of those limits. 31.12 String-Valued Parameters  Getting the default search path.

Sysconf

31.4.1 Definition of sysconf  Detailed specifications of sysconf. 31.4.2 Constants for sysconf Parameters  The list of parameters sysconf can read. 31.4.3 Examples of sysconf  How to use sysconf and the parameter macros properly together.

Cryptographic Functions

32.1 Legal Problems  This software can get you locked up, or worse. 32.2 Reading Passwords  Prompting the user for a password. 32.3 Encrypting Passwords  A one-way function for passwords. 32.4 DES Encryption  Routines for DES encryption.

Debugging Support

33.1 Backtraces  Obtaining and printing a back trace of the current stack.

Language Features

A.1 Explicitly Checking Internal Consistency  Using assert to abort if something “impossible” happens. A.2 Variadic Functions  Defining functions with varying numbers of args. A.3 Null Pointer Constant  The macro NULL. A.4 Important Data Types  Data types for object sizes. A.5 Data Type Measurements  Parameters of data type representations.

Variadic Functions

A.2.1 Why Variadic Functions are Used  Reasons for making functions take variable arguments. A.2.2 How Variadic Functions are Defined and Used  How to define and call variadic functions. A.2.3 Example of a Variadic Function  A complete example.

How Variadic

A.2.2.1 Syntax for Variable Arguments  How to make a prototype for a function with variable arguments. A.2.2.2 Receiving the Argument Values  Steps you must follow to access the optional argument values. A.2.2.3 How Many Arguments Were Supplied  How to decide whether there are more arguments. A.2.2.4 Calling Variadic Functions  Things you need to know about calling variable arguments functions. A.2.2.5 Argument Access Macros  Detailed specification of the macros for accessing variable arguments. A.2.3.1 Old-Style Variadic Functions  The pre-ISO way of defining variadic functions.

Data Type Measurements

A.5.1 Computing the Width of an Integer Data Type  How many bits does an integer type hold? A.5.2 Range of an Integer Type  What are the largest and smallest values that an integer type can hold? A.5.3 Floating Type Macros  Parameters that measure the floating point types. A.5.4 Structure Field Offset Measurement  Getting measurements on structure types.

Floating Type Macros

A.5.3.1 Floating Point Representation Concepts  Definitions of terminology. A.5.3.2 Floating Point Parameters  Details of specific macros. A.5.3.3 IEEE Floating Point  The measurements for one common representation.

Installation

C.1 Configuring and compiling GNU Libc  How to compile and test GNU libc. C.2 Installing the C Library  How to install it once you’ve got it compiled. C.3 Recommended Tools for Compilation  You’ll need these first. C.4 Specific advice for GNU/Linux systems  Specific advice for GNU/Linux systems. C.5 Reporting Bugs  So they’ll get fixed.

Maintenance

D.1 Adding New Functions  How to add new functions or header files to the GNU C library. D.2 Porting the GNU C Library  How to port the GNU C library to a new machine or operating system.

Porting

D.2.1 Layout of the ‘sysdeps’ Directory Hierarchy  The layout of the ‘sysdeps’ hierarchy. D.2.2 Porting the GNU C Library to Unix Systems  Porting the library to an average Unix-like system. @end menu

1. Introduction

The C language provides no built-in facilities for performing such common operations as input/output, memory management, string manipulation, and the like. Instead, these facilities are defined in a standard library, which you compile and link with your programs.

The GNU C library, described in this document, defines all of the library functions that are specified by the ISO C standard, as well as additional features specific to POSIX and other derivatives of the Unix operating system, and extensions specific to the GNU system.

The purpose of this manual is to tell you how to use the facilities of the GNU library. We have mentioned which features belong to which standards to help you identify things that are potentially non-portable to other systems. But the emphasis in this manual is not on strict portability.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1 Getting Started

This manual is written with the assumption that you are at least somewhat familiar with the C programming language and basic programming concepts. Specifically, familiarity with ISO standard C (see section ISO C), rather than “traditional” pre-ISO C dialects, is assumed.

The GNU C library includes several header files, each of which provides definitions and declarations for a group of related facilities; this information is used by the C compiler when processing your program. For example, the header file ‘stdio.h’ declares facilities for performing input and output, and the header file ‘string.h’ declares string processing utilities. The organization of this manual generally follows the same division as the header files.

If you are reading this manual for the first time, you should read all of the introductory material and skim the remaining chapters. There are a lot of functions in the GNU C library and it’s not realistic to expect that you will be able to remember exactly how to use each and every one of them. It’s more important to become generally familiar with the kinds of facilities that the library provides, so that when you are writing your programs you can recognize when to make use of library functions, and where in this manual you can find more specific information about them.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 Standards and Portability

This section discusses the various standards and other sources that the GNU C library is based upon. These sources include the ISO C and POSIX standards, and the System V and Berkeley Unix implementations.

The primary focus of this manual is to tell you how to make effective use of the GNU library facilities. But if you are concerned about making your programs compatible with these standards, or portable to operating systems other than GNU, this can affect how you use the library. This section gives you an overview of these standards, so that you will know what they are when they are mentioned in other parts of the manual.

See section Summary of Library Facilities, for an alphabetical list of the functions and other symbols provided by the library. This list also states which standards each function or symbol comes from.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2.1 ISO C

The GNU C library is compatible with the C standard adopted by the American National Standards Institute (ANSI): American National Standard X3.159-1989—“ANSI C” and later by the International Standardization Organization (ISO): ISO/IEC 9899:1990, “Programming languages—C”. We here refer to the standard as ISO C since this is the more general standard in respect of ratification. The header files and library facilities that make up the GNU library are a superset of those specified by the ISO C standard.

If you are concerned about strict adherence to the ISO C standard, you should use the ‘-ansi’ option when you compile your programs with the GNU C compiler. This tells the compiler to define only ISO standard features from the library header files, unless you explicitly ask for additional features. See section Feature Test Macros, for information on how to do this.

Being able to restrict the library to include only ISO C features is important because ISO C puts limitations on what names can be defined by the library implementation, and the GNU extensions don’t fit these limitations. See section Reserved Names, for more information about these restrictions.

This manual does not attempt to give you complete details on the differences between ISO C and older dialects. It gives advice on how to write programs to work portably under multiple C dialects, but does not aim for completeness.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2.2 POSIX (The Portable Operating System Interface)

The GNU library is also compatible with the ISO POSIX family of standards, known more formally as the Portable Operating System Interface for Computer Environments (ISO/IEC 9945). They were also published as ANSI/IEEE Std 1003. POSIX is derived mostly from various versions of the Unix operating system.

The library facilities specified by the POSIX standards are a superset of those required by ISO C; POSIX specifies additional features for ISO C functions, as well as specifying new additional functions. In general, the additional requirements and functionality defined by the POSIX standards are aimed at providing lower-level support for a particular kind of operating system environment, rather than general programming language support which can run in many diverse operating system environments.

The GNU C library implements all of the functions specified in ISO/IEC 9945-1:1996, the POSIX System Application Program Interface, commonly referred to as POSIX.1. The primary extensions to the ISO C facilities specified by this standard include file system interface primitives (see section File System Interface), device-specific terminal control functions (see section Low-Level Terminal Interface), and process control functions (see section Processes).

Some facilities from ISO/IEC 9945-2:1993, the POSIX Shell and Utilities standard (POSIX.2) are also implemented in the GNU library. These include utilities for dealing with regular expressions and other pattern matching facilities (see section Pattern Matching).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2.3 Berkeley Unix

The GNU C library defines facilities from some versions of Unix which are not formally standardized, specifically from the 4.2 BSD, 4.3 BSD, and 4.4 BSD Unix systems (also known as Berkeley Unix) and from SunOS (a popular 4.2 BSD derivative that includes some Unix System V functionality). These systems support most of the ISO C and POSIX facilities, and 4.4 BSD and newer releases of SunOS in fact support them all.

The BSD facilities include symbolic links (see section Symbolic Links), the select function (see section Waiting for Input or Output), the BSD signal functions (see section BSD Signal Handling), and sockets (see section Sockets).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2.4 SVID (The System V Interface Description)

The System V Interface Description (SVID) is a document describing the AT&T Unix System V operating system. It is to some extent a superset of the POSIX standard (see section POSIX (The Portable Operating System Interface)).

The GNU C library defines most of the facilities required by the SVID that are not also required by the ISO C or POSIX standards, for compatibility with System V Unix and other Unix systems (such as SunOS) which include these facilities. However, many of the more obscure and less generally useful facilities required by the SVID are not included. (In fact, Unix System V itself does not provide them all.)

The supported facilities from System V include the methods for inter-process communication and shared memory, the hsearch and drand48 families of functions, fmtmsg and several of the mathematical functions.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2.5 XPG (The X/Open Portability Guide)

The X/Open Portability Guide, published by the X/Open Company, Ltd., is a more general standard than POSIX. X/Open owns the Unix copyright and the XPG specifies the requirements for systems which are intended to be a Unix system.

The GNU C library complies to the X/Open Portability Guide, Issue 4.2, with all extensions common to XSI (X/Open System Interface) compliant systems and also all X/Open UNIX extensions.

The additions on top of POSIX are mainly derived from functionality available in System V and BSD systems. Some of the really bad mistakes in System V systems were corrected, though. Since fulfilling the XPG standard with the Unix extensions is a precondition for getting the Unix brand chances are good that the functionality is available on commercial systems.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3 Using the Library

This section describes some of the practical issues involved in using the GNU C library.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3.1 Header Files

Libraries for use by C programs really consist of two parts: header files that define types and macros and declare variables and functions; and the actual library or archive that contains the definitions of the variables and functions.

(Recall that in C, a declaration merely provides information that a function or variable exists and gives its type. For a function declaration, information about the types of its arguments might be provided as well. The purpose of declarations is to allow the compiler to correctly process references to the declared variables and functions. A definition, on the other hand, actually allocates storage for a variable or says what a function does.)

In order to use the facilities in the GNU C library, you should be sure that your program source files include the appropriate header files. This is so that the compiler has declarations of these facilities available and can correctly process references to them. Once your program has been compiled, the linker resolves these references to the actual definitions provided in the archive file.

Header files are included into a program source file by the ‘#include’ preprocessor directive. The C language supports two forms of this directive; the first,

 
#include "header"

is typically used to include a header file header that you write yourself; this would contain definitions and declarations describing the interfaces between the different parts of your particular application. By contrast,

 
#include <file.h>

is typically used to include a header file ‘file.h’ that contains definitions and declarations for a standard library. This file would normally be installed in a standard place by your system administrator. You should use this second form for the C library header files.

Typically, ‘#include’ directives are placed at the top of the C source file, before any other code. If you begin your source files with some comments explaining what the code in the file does (a good idea), put the ‘#include’ directives immediately afterwards, following the feature test macro definition (see section Feature Test Macros).

For more information about the use of header files and ‘#include’ directives, see (cpp.info)Header Files section ‘Header Files’ in The GNU C Preprocessor Manual.

The GNU C library provides several header files, each of which contains the type and macro definitions and variable and function declarations for a group of related facilities. This means that your programs may need to include several header files, depending on exactly which facilities you are using.

Some library header files include other library header files automatically. However, as a matter of programming style, you should not rely on this; it is better to explicitly include all the header files required for the library facilities you are using. The GNU C library header files have been written in such a way that it doesn’t matter if a header file is accidentally included more than once; including a header file a second time has no effect. Likewise, if your program needs to include multiple header files, the order in which they are included doesn’t matter.

Compatibility Note: Inclusion of standard header files in any order and any number of times works in any ISO C implementation. However, this has traditionally not been the case in many older C implementations.

Strictly speaking, you don’t have to include a header file to use a function it declares; you could declare the function explicitly yourself, according to the specifications in this manual. But it is usually better to include the header file because it may define types and macros that are not otherwise available and because it may define more efficient macro replacements for some functions. It is also a sure way to have the correct declaration.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3.2 Macro Definitions of Functions

If we describe something as a function in this manual, it may have a macro definition as well. This normally has no effect on how your program runs—the macro definition does the same thing as the function would. In particular, macro equivalents for library functions evaluate arguments exactly once, in the same way that a function call would. The main reason for these macro definitions is that sometimes they can produce an inline expansion that is considerably faster than an actual function call.

Taking the address of a library function works even if it is also defined as a macro. This is because, in this context, the name of the function isn’t followed by the left parenthesis that is syntactically necessary to recognize a macro call.

You might occasionally want to avoid using the macro definition of a function—perhaps to make your program easier to debug. There are two ways you can do this:

For example, suppose the header file ‘stdlib.h’ declares a function named abs with

 
extern int abs (int);

and also provides a macro definition for abs. Then, in:

 
#include <stdlib.h>
int f (int *i) { return abs (++*i); }

the reference to abs might refer to either a macro or a function. On the other hand, in each of the following examples the reference is to a function and not a macro.

 
#include <stdlib.h>
int g (int *i) { return (abs) (++*i); }

#undef abs
int h (int *i) { return abs (++*i); }

Since macro definitions that double for a function behave in exactly the same way as the actual function version, there is usually no need for any of these methods. In fact, removing macro definitions usually just makes your program slower.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3.3 Reserved Names

The names of all library types, macros, variables and functions that come from the ISO C standard are reserved unconditionally; your program may not redefine these names. All other library names are reserved if your program explicitly includes the header file that defines or declares them. There are several reasons for these restrictions:

In addition to the names documented in this manual, reserved names include all external identifiers (global functions and variables) that begin with an underscore (‘_’) and all identifiers regardless of use that begin with either two underscores or an underscore followed by a capital letter are reserved names. This is so that the library and header files can define functions, variables, and macros for internal purposes without risk of conflict with names in user programs.

Some additional classes of identifier names are reserved for future extensions to the C language or the POSIX.1 environment. While using these names for your own purposes right now might not cause a problem, they do raise the possibility of conflict with future versions of the C or POSIX standards, so you should avoid these names.

In addition, some individual header files reserve names beyond those that they actually define. You only need to worry about these restrictions if your program includes that particular header file.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3.4 Feature Test Macros

The exact set of features available when you compile a source file is controlled by which feature test macros you define.

If you compile your programs using ‘gcc -ansi’, you get only the ISO C library features, unless you explicitly request additional features by defining one or more of the feature macros. See (gcc.info)Invoking GCC section ‘GNU CC Command Options’ in The GNU CC Manual, for more information about GCC options.

You should define these macros by using ‘#define’ preprocessor directives at the top of your source code files. These directives must come before any #include of a system header file. It is best to make them the very first thing in the file, preceded only by comments. You could also use the ‘-D’ option to GCC, but it’s better if you make the source files indicate their own meaning in a self-contained way.

This system exists to allow the library to conform to multiple standards. Although the different standards are often described as supersets of each other, they are usually incompatible because larger standards require functions with names that smaller ones reserve to the user program. This is not mere pedantry — it has been a problem in practice. For instance, some non-GNU programs define functions named getline that have nothing to do with this library’s getline. They would not be compilable if all features were enabled indiscriminately.

This should not be used to verify that a program conforms to a limited standard. It is insufficient for this purpose, as it will not protect you from including header files outside the standard, or relying on semantics undefined within the standard.

Macro: _POSIX_SOURCE

If you define this macro, then the functionality from the POSIX.1 standard (IEEE Standard 1003.1) is available, as well as all of the ISO C facilities.

The state of _POSIX_SOURCE is irrelevant if you define the macro _POSIX_C_SOURCE to a positive integer.

Macro: _POSIX_C_SOURCE

Define this macro to a positive integer to control which POSIX functionality is made available. The greater the value of this macro, the more functionality is made available.

If you define this macro to a value greater than or equal to 1, then the functionality from the 1990 edition of the POSIX.1 standard (IEEE Standard 1003.1-1990) is made available.

If you define this macro to a value greater than or equal to 2, then the functionality from the 1992 edition of the POSIX.2 standard (IEEE Standard 1003.2-1992) is made available.

If you define this macro to a value greater than or equal to 199309L, then the functionality from the 1993 edition of the POSIX.1b standard (IEEE Standard 1003.1b-1993) is made available.

Greater values for _POSIX_C_SOURCE will enable future extensions. The POSIX standards process will define these values as necessary, and the GNU C Library should support them some time after they become standardized. The 1996 edition of POSIX.1 (ISO/IEC 9945-1: 1996) states that if you define _POSIX_C_SOURCE to a value greater than or equal to 199506L, then the functionality from the 1996 edition is made available.

Macro: _BSD_SOURCE

If you define this macro, functionality derived from 4.3 BSD Unix is included as well as the ISO C, POSIX.1, and POSIX.2 material.

Some of the features derived from 4.3 BSD Unix conflict with the corresponding features specified by the POSIX.1 standard. If this macro is defined, the 4.3 BSD definitions take precedence over the POSIX definitions.

Due to the nature of some of the conflicts between 4.3 BSD and POSIX.1, you need to use a special BSD compatibility library when linking programs compiled for BSD compatibility. This is because some functions must be defined in two different ways, one of them in the normal C library, and one of them in the compatibility library. If your program defines _BSD_SOURCE, you must give the option ‘-lbsd-compat’ to the compiler or linker when linking the program, to tell it to find functions in this special compatibility library before looking for them in the normal C library.

Macro: _SVID_SOURCE

If you define this macro, functionality derived from SVID is included as well as the ISO C, POSIX.1, POSIX.2, and X/Open material.

Macro: _XOPEN_SOURCE
Macro: _XOPEN_SOURCE_EXTENDED

If you define this macro, functionality described in the X/Open Portability Guide is included. This is a superset of the POSIX.1 and POSIX.2 functionality and in fact _POSIX_SOURCE and _POSIX_C_SOURCE are automatically defined.

As the unification of all Unices, functionality only available in BSD and SVID is also included.

If the macro _XOPEN_SOURCE_EXTENDED is also defined, even more functionality is available. The extra functions will make all functions available which are necessary for the X/Open Unix brand.

If the macro _XOPEN_SOURCE has the value 500 this includes all functionality described so far plus some new definitions from the Single Unix Specification, version 2.

Macro: _LARGEFILE_SOURCE

If this macro is defined some extra functions are available which rectify a few shortcomings in all previous standards. Specifically, the functions fseeko and ftello are available. Without these functions the difference between the ISO C interface (fseek, ftell) and the low-level POSIX interface (lseek) would lead to problems.

This macro was introduced as part of the Large File Support extension (LFS).

Macro: _LARGEFILE64_SOURCE

If you define this macro an additional set of functions is made available which enables 32 bit systems to use files of sizes beyond the usual limit of 2GB. This interface is not available if the system does not support files that large. On systems where the natural file size limit is greater than 2GB (i.e., on 64 bit systems) the new functions are identical to the replaced functions.

The new functionality is made available by a new set of types and functions which replace the existing ones. The names of these new objects contain 64 to indicate the intention, e.g., off_t vs. off64_t and fseeko vs. fseeko64.

This macro was introduced as part of the Large File Support extension (LFS). It is a transition interface for the period when 64 bit offsets are not generally used (see _FILE_OFFSET_BITS).

Macro: _FILE_OFFSET_BITS

This macro determines which file system interface shall be used, one replacing the other. Whereas _LARGEFILE64_SOURCE makes the 64 bit interface available as an additional interface, _FILE_OFFSET_BITS allows the 64 bit interface to replace the old interface.

If _FILE_OFFSET_BITS is undefined, or if it is defined to the value 32, nothing changes. The 32 bit interface is used and types like off_t have a size of 32 bits on 32 bit systems.

If the macro is defined to the value 64, the large file interface replaces the old interface. I.e., the functions are not made available under different names (as they are with _LARGEFILE64_SOURCE). Instead the old function names now reference the new functions, e.g., a call to fseeko now indeed calls fseeko64.

This macro should only be selected if the system provides mechanisms for handling large files. On 64 bit systems this macro has no effect since the *64 functions are identical to the normal functions.

This macro was introduced as part of the Large File Support extension (LFS).

Macro: _ISOC99_SOURCE

Until the revised ISO C standard is widely adopted the new features are not automatically enabled. The GNU libc nevertheless has a complete implementation of the new standard and to enable the new features the macro _ISOC99_SOURCE should be defined.

Macro: _GNU_SOURCE

If you define this macro, everything is included: ISO C89, ISO C99, POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU extensions. In the cases where POSIX.1 conflicts with BSD, the POSIX definitions take precedence.

If you want to get the full effect of _GNU_SOURCE but make the BSD definitions take precedence over the POSIX definitions, use this sequence of definitions:

 
#define _GNU_SOURCE
#define _BSD_SOURCE
#define _SVID_SOURCE

Note that if you do this, you must link your program with the BSD compatibility library by passing the ‘-lbsd-compat’ option to the compiler or linker. NB: If you forget to do this, you may get very strange errors at run time.

Macro: _REENTRANT
Macro: _THREAD_SAFE

If you define one of these macros, reentrant versions of several functions get declared. Some of the functions are specified in POSIX.1c but many others are only available on a few other systems or are unique to GNU libc. The problem is the delay in the standardization of the thread safe C library interface.

Unlike on some other systems, no special version of the C library must be used for linking. There is only one version but while compiling this it must have been specified to compile as thread safe.

We recommend you use _GNU_SOURCE in new programs. If you don’t specify the ‘-ansi’ option to GCC and don’t define any of these macros explicitly, the effect is the same as defining _POSIX_C_SOURCE to 2 and _POSIX_SOURCE, _SVID_SOURCE, and _BSD_SOURCE to 1.

When you define a feature test macro to request a larger class of features, it is harmless to define in addition a feature test macro for a subset of those features. For example, if you define _POSIX_C_SOURCE, then defining _POSIX_SOURCE as well has no effect. Likewise, if you define _GNU_SOURCE, then defining either _POSIX_SOURCE or _POSIX_C_SOURCE or _SVID_SOURCE as well has no effect.

Note, however, that the features of _BSD_SOURCE are not a subset of any of the other feature test macros supported. This is because it defines BSD features that take precedence over the POSIX features that are requested by the other macros. For this reason, defining _BSD_SOURCE in addition to the other feature test macros does have an effect: it causes the BSD features to take priority over the conflicting POSIX features.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.4 Roadmap to the Manual

Here is an overview of the contents of the remaining chapters of this manual.

If you already know the name of the facility you are interested in, you can look it up in Summary of Library Facilities. This gives you a summary of its syntax and a pointer to where you can find a more detailed description. This appendix is particularly useful if you just want to verify the order and type of arguments to a function, for example. It also tells you what standard or system each function, variable, or macro is derived from.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by root on September 10, 2010 using texi2html 1.82.