.TH "libc" "" "" Library
.PC "Standard C library"
.B /lib/libc.a
.PP
.II "standard C library"
.II "library^standard C"
.B libc
is the library that contains most functions linked into C programs.
It contains many general-purpose functions, as well as stubs for
\*(CO system calls.
The following summarizes these functions.
.SH "Binary Data"
The following functions manipulate binary data types, that is,
integers and floating-point numbers.
.LB
\fBabs()\fR	Return the absolute value of an integer
\fBdecvax_d()\fR	Convert a \fBdouble\fR from IEEE to DECVAX format
\fBdecvax_f()\fR	Convert a \fBfloat\fR from IEEE to DECVAX format
\fBdiv()\fR	Perform integer division
\fBfrexp()\fR	Separate fraction and exponent
\fBieee_d()\fR	Convert a \fBdouble\fR from DECVAX to IEEE format
\fBieee_f()\fR	Convert a \fBfloat\fR from DECVAX to IEEE format
\fBldexp()\fR	Combine fraction and exponent
\fBldiv()\fR	Perform long integer division
\fBmodf()\fR	Separate integral part and fraction
.SH "Binary Data and Strings"
The following functions convert binary data forms to strings, or
strings to binary forms.
.LB
\fBatof()\fR	Convert ASCII strings to floating point
\fBatoi()\fR	Convert ASCII strings to integers
\fBatol()\fR	Convert ASCII strings to long integers
\fBecvt()\fR	Convert floating-point numbers to strings
\fBfcvt()\fR	Convert floating-point numbers to strings
\fBgcvt()\fR	Convert floating-point numbers to strings
\fBstrtod()\fR	Convert string to floating-point number
\fBstrtol()\fR	Convert string to long integer
\fBstrtoul()\fR	Convert string to unsigned long integer
.\".SH Canonization
.\"The following functions convert binary data into the canonical
.\"\*(CO form.
.\"Note that these functions are slated to be removed from a future release
.\"of \*(CO; we strongly discourage their use, and code that uses them should
.\"be modified.
.\".LB
.\"\fBcandaddr()\fR	Convert a \fBdaddr_t\fR to canonical format
.\"\fBcandev()\fR	Convert a \fBdev_t\fR to canonical format
.\"\fBcanino()\fR	Convert a \fBino_t\fR to canonical format
.\"\fBcanint()\fR	Convert a \fBint\fR to canonical format
.\"\fBcanlong()\fR	Convert a \fBlong\fR to canonical format
.\"\fBcanshort()\fR	Convert a \fBshort\fR to canonical format
.\"\fBcansize()\fR	Convert an \fBfsize_t\fR to canonical format
.\"\fBcantime()\fR	Convert a \fBtime_t\fR to canonical format
.\"\fBcanvaddr()\fR	Convert a \fBvaddr_t\fR to canonical format
.SH "ctype Functions"
The
.B ctype
functions test a character's \fItype\fR.
Some can transform some characters into others.
``ctype'' is an abbreviation for ``character type'';
all are declared or defined in the header file
.BR <ctype.h> .
They are as follows:
.LB
\fB_tolower()\fR	Convert an upper-case character to lower case
\fB_toupper()\fR	Convert a lower-case character to upper case
\fBisalnum()\fR	Test if alphanumeric character
\fBisalpha()\fR	Test if alphabetic character
\fBisascii()\fR	Test if ASCII character
\fBiscntrl()\fR	Test if a control character
\fBisdigit()\fR	Test if a numeric digit
\fBisgraph()\fR	Test if a graphics character
\fBislower()\fR	Test if lower-case character
\fBisprint()\fR	Test if printable character
\fBispunct()\fR	Test if punctuation mark
\fBisspace()\fR	Test if a tab, space, or return
\fBisupper()\fR	Test if upper-case character
\fBisxdigit()\fR	Test if hexadecimal numeral
\fBtoascii()\fR	Convert a character to ASCII
\fBtolower()\fR	Convert an upper-case character to lower case
\fBtoupper()\fR	Convert a lower-case character to upper case
.SH "Files and Directories"
The following functions are used to manipulate files and directories,
and their names.
.LB
\fB_getwd()\fR	Get current working directory name
\fBclosedir()\fR	Close a directory stream
\fBdup2()\fR	Duplicate a file descriptor
\fBgetcwd()\fR	Get current working directory
\fBmktemp()\fR	Generate a temporary file name
\fBopendir()\fR	Open a directory stream
\fBpath()\fR	Build a path name for a file
\fBreaddir()\fR	Read a directory stream
\fBremove()\fR	Remove a file
\fBrewinddir()\fR	Rewind a directory stream
\fBseekdir()\fR	Reset the position within a directory stream
\fBtelldir()\fR	Return position within a directory stream
.SH "Interprocess Communication"
The following functions perform interprocess communcation.
.LB
\fBftok()\fR	Generate keys for interprocess communication
\fBmsgctl()\fR	Control message operation
\fBmsgget()\fR	Get a message queue
\fBmsgrcv()\fR	Receive a message
\fBmsgsnd()\fR	Send a message
\fBsemctl()\fR	Control semaphore operations
\fBsemget()\fR	Get a set of semaphores
\fBsemop()\fR	Perform semaphore operations
\fBshmat()\fR	Attach a shared-memory segment to a process
\fBshmctl()\fR	Manipulate shared memory
\fBshmdt()\fR	Detach a shared-memory segment from a process
\fBshmget()\fR	Get the shared-memory segment
.SH "Memory Management"
The following functions help to manage memory.
.LB
\fBalloca()\fR	Dynamically allocate space on the stack
\fBcalloc()\fR	Allocate dynamic memory
\fBfree()\fR	Return dynamic memory to free memory pool
\fBmalloc()\fR	Allocate dynamic memory
\fBrealloc()\fR	Reallocate dynamic memory
\fBsbrk()\fR	Increase a program's data space
.SH "Passwords and Groups"
The following functions manipulate the system files
.BR /etc/group ,
.BR /etc/password ,
and
.BR /etc/shadow ,
and uses the information found therein.
.LB
\fBendgrent()\fR	Close group file
\fBendpwent()\fR	Close password file
\fBendspent()\fR	Close the shadow-password file
\fBgetgrent()\fR	Get group file information
\fBgetgrgid()\fR	Get group file information, by group id
\fBgetgrnam()\fR	Get group file information, by group name
\fBgetlogin()\fR	Get login name
\fBgetpass()\fR	Get password with prompting
\fBgetpw()\fR	Search password file
\fBgetpwent()\fR	Get password file information
\fBgetpwnam()\fR	Get password file information, by name
\fBgetpwuid()\fR	Get password file information, by identifier
\fBgetspent()\fR	Get a shadow-password record
\fBgetspnam()\fR	Get a shadow-password record, by user name
\fBinitgroups()\fR	Initialize the supplementary group-access list
\fBsetgrent()\fR	Rewind group file
\fBsetpwent()\fR	Rewind password file
\fBsetspent()\fR	Rewind the shadow-password file
.SH Processes
The following functions execute and terminate.
For information on how the \fBexec()\fR functions differ, see the Lexicon entry
.BR execution .
.LB
\fB_exit()\fR	Terminate a process
\fBabort()\fR	End program immediately
\fBatexit()\fR	Register a function to be called when the program exits
\fBctermid()\fR	Name the terminal device that controls the current process
\fBexecl()\fR	Execute a load module
\fBexecle()\fR	Execute a load module
\fBexeclp()\fR	Execute a load module
\fBexeclpe()\fR	Execute a load module
\fBexecv()\fR	Execute a load module
\fBexecvp()\fR	Execute a load module
\fBexecvpe()\fR	Execute a load module
\fBraise()\fR	Let a process send a signal to itself
\fBsleep()\fR	Suspend execution
.SH "Random Number"
.II "random numbers"
.B libc
contains the following functions for generating pseudo-random numbers:
.LB
\fBdrand48()\fR	Return 48-bit pseudo-random number as double
\fBerand48()\fR	Return 48-bit pseudo-random number as double
\fBjrand48()\fR	Return 48-bit pseudo-random number as long integer
\fBlcong48()\fR	Initialize values from which 48-bit random numbers are computed
\fBlrand48()\fR	Return 48-bit pseudo-random number as non-negative long integer
\fBmrand48()\fR	Return 48-bit pseudo-random number as long integer
\fBnrand48()\fR	Return 48-bit pseudo-random number as non-negative long integer
\fBrand()\fR	Generate pseudo-random numbers
\fBseed48()\fR	Initialize values from which 48-bit random numbers are computed
\fBsrand()\fR	Seed random number generator
\fBsrand48()\fR	Seed 48-bit pseudo-random number routines
.SH "Regular Expressions"
.II "regular expressions"
.II "expression, regular"
The following functions read and interpret \*(UN-style regular expressions:
.LB
\fBregcomp()\fR	Compile a regular expression into a structure
\fBregerror()\fR	Return an error message from a regular-expression function
\fBregexec()\fR	Compare a string with a regular expression
\fBregsub()\fR	Use regular expression to build a string
.SH STDIO
.I STDIO
is an abbreviation for \fIstandard input and output\fR.
It refers to a set of standard library functions that accompany
all C compilers and that govern input and output with peripheral
devices.
\*(CO includes the following STDIO routines:
.LB
\fBclearerr()\fR	Present status stream
\fBfclose()\fR	Close a file stream
\fBfdopen()\fR	Open a file stream for I/O
\fBfeof()\fR	Discover a file stream's status
\fBferror()\fR	Discover a file stream's status
\fBfflush()\fR	Flush an output buffer
\fBfgetc()\fR	Get a character
\fBfgetpos()\fR	Read the file-position indicator
\fBfgets()\fR	Get a string
\fBfgetw()\fR	Get a word
\fBfileno()\fR	Get a file descriptor from a \fBFILE\fR structure
\fBfopen()\fR	Open a file stream
\fBfprintf()\fR	Format and print to a file stream
\fBfputc()\fR	Output a character
\fBfputs()\fR	Output a string
\fBfputw()\fR	Output a word
\fBfread()\fR	Read a file stream
\fBfreopen()\fR	Open a file stream
\fBfscanf()\fR	Format and read from a file stream
\fBfseek()\fR	Seek in a file stream
\fBfsetpos()\fR	Set the file-position indicator
\fBftell()\fR	Return file pointer position
\fBfwrite()\fR	Write to a file stream
\fBgetc()\fR	Get a character
\fBgetchar()\fR	Get a character
\fBgets()\fR	Get a string
\fBgetw()\fR	Get a word
\fBpclose()\fR	Close a pipe
\fBpopen()\fR	Open a pipe
\fBprintf()\fR	Print a formatted string
\fBputc()\fR	Output a character
\fBputchar()\fR	Output a character
\fBputs()\fR	Output a string
\fBputw()\fR	Output a word
\fBrewind()\fR	Reset a file pointer
\fBscanf()\fR	Format and input from standard input
\fBsetbuf()\fR	Set alternative file-stream buffer
\fBsetvbuf()\fR	Set alternative file-stream buffer
\fBsprintf()\fR	Format and print to a string
\fBsscanf()\fR	Format and read from a string
\fBtmpfile()\fR	Create a temporary file
\fBtmpnam()\fR	Generate a unique name for a temporary file
\fBungetc()\fR	Return character to file stream
\fBvfprintf()\fR	Format and print to a file stream
\fBvprintf()\fR	Print a formatted string
\fBvsprintf()\fR	Format and print to a string
.SH "String Functions"
The character string is a common formation in C programs.
The runtime representation of a string is an array of ASCII characters
that is terminated by a null character (\*(Ql\e0\*(Qr).
\*(CO uses this representation when a program contains a
string constant; for example:
.DM
	"I am a string constant"
.DE
.PP
The address of the first character in the string is used
as the starting point of the string.
A pointer to a string holds only this address.
Note, too, that an array of 20 characters can hold
a string of 19 (\fInot\fR 20) non-null
characters; the 20th character is the null character that terminates
the string.
.PP
The following routines are available to help manipulate
strings.
The prototypes for most are declared in the header file
.BR string.h :
.LB
\fBbcmp()\fR	Berkeley function to compare two chunks of memory
\fBbcopy()\fR	Berkeley function to copy memory
\fBbzero()\fR	Berkeley function to initialize memory to NUL
\fBfnmatch()\fR	Match a string with a normal expression
\fBindex()\fR	Search string for a character; use \fBstrchr()\fR instead
\fBmemccpy()\fR	Copy a region of memory up to a set character
\fBmemchr()\fR	Search a region of memory for a character
\fBmemcmp()\fR	Compare two regions of memory
\fBmemcpy()\fR	Copy one region of memory into another
\fBmemmove()\fR	Copy one region of memory into another with which it overlaps
\fBmemset()\fR	Fill a region of memory with a character
\fBpnmatch()\fR	Match string pattern
\fBrindex()\fR	Find rightmost occurrence of a character in a string
\fBstrcat()\fR	Concatenate two strings
\fBstrcmp()\fR	Compare two strings
\fBstrncat()\fR	Append one string onto another
\fBstrncmp()\fR	Compare two lengths for a set number of bytes
\fBstrcpy()\fR	Copy a string
\fBstrncpy()\fR	Copy a portion of a string
\fBstrcoll()\fR	Compare two strings, using locale information
\fBstrcspn()\fR	Return length one string excludes characters in another
\fBstrdup()\fR	Duplicate a string
\fBstrerror()\fR	Translate an error number into a string
\fBstrlen()\fR	Measure a string
\fBstrpbrk()\fR	Find first occurrence in string of character from another string
\fBstrchr()\fR	Find leftmost occurrence of character in a string
\fBstrrchr()\fR	Find rightmost occurrence of character in a string
\fBstrspn()\fR	Return length one string includes character in another
\fBstrstr()\fR	Find one string within another string
\fBstrtok()\fR	Break a string into tokens
\fBstrxfrm()\fR	Transform a string, using locale information
.SH "System Logs"
The following functions manipulate the files
.B /etc/utmp
and
.BR /usr/adm/wtmp ,
which record login events on your system.
The former file records every login that is still executing (i.e., the user
has logged in and has not yet logged), and every past login.
.LB
\fBendutent()\fR	Close the logging file.
\fBgetutent()\fR	Read the next entry from \fB/etc/utmp\fR.
\fBgetutid()\fR	Find an entry in \fB/etc/utmp\fR by login identifier.
\fBgetutline()\fR	Find an entry in \fB/etc/utmp\fR by login device.
\fBpututline()\fR	Write a record into \fB/etc/utmp\fR.
\fBsetutent()\fR	Rewind the input stream that is reading \fB/etc/utmp\fR
\fButmpname()\fR	Manipulate a file other than \fB/etc/utmp\fR.
.SH Terminals
The following functions help you cope with terminals.
.LB
\fBisatty()\fR	Check if a device is a terminal
\fBttyname()\fR	Identify a terminal
\fBttyslot()\fR	Return a terminal's line number
.SH "Standard Time Functions"
.B libc
includes the following functions to manipulate time:
.LB
\fBasctime()\fR	Convert time structure to ASCII string
\fBclock()\fR	Get processor time
\fBctime()\fR	Convert system time to an ASCII string
\fBdifftime()\fR	Return difference between two times
\fBgmtime()\fR	Convert system time to calendar structure
\fBlocaltime()\fR	Convert system time to calendar structure
\fBmktime()\fR	Turn broken-down time into calendar time
\fBstrftime()\fR	Format locale-specific time
\fBtzset()\fR	Set local time zone
.SH "System Calls"
.II "system calls"
The \*(CO kernel makes many services available to the C programmer.
A programmer can use a \*(CO service through a system call.
.B libc
includes intefaces to the following system calls:
.LB
\fBaccess()\fR	Check if file can be accessed in given mode
\fBacct()\fR	Enable/disable process accounting
\fBalarm()\fR	Set an alarm
\fBbrk()\fR	Change size of data area
\fBchdir()\fR	Change working directory
\fBchmod()\fR	Change file protection modes
\fBchown()\fR	Change ownership of a file
\fBchroot()\fR	Change process's root directory
\fBchsize()\fR	Change the size of a file
\fBclose()\fR	Close a file
\fBcreat()\fR	Create/truncate a file
\fBdup()\fR	Duplicate a file descriptor
\fBexecve()\fR	Execute a load module
\fBexit()\fR	Terminate a program gracefully
\fBfcntl()\fR	Manipulate an open file
\fBfork()\fR	Create a new process
\fBfpathconf()\fR	Get a file variable by file descriptor
\fBfstat()\fR	Get information about a file system
\fBfstatfs()\fR	Get information about a file system
\fBftime()\fR	Get current system time
\fBgetdents()\fR	Read directory entries
\fBgetegid()\fR	Get effective group id
\fBgeteuid()\fR	Get effective user id
\fBgetgid()\fR	Get real group id
\fBgetgroups()\fR	Read the supplemental group-access list
\fBgetmsg()\fR	Get the next message from a stream
\fBgetpgrp()\fR	Get process-group identifier
\fBgetpid()\fR	Get process id
\fBgetppid()\fR	Get process id of parent process
\fBgetuid()\fR	Get real user id
\fBgtty()\fR	Get terminal modes
\fBioctl()\fR	Device-dependent control
\fBkill()\fR	Send a signal to a process
\fBlink()\fR	Create a link
.\" \fBlock()\fR	Prevent process from swapping
\fBlseek()\fR	Set read/write position
\fBmkdir()\fR	Create a directory
\fBmkfifo()\fR	Create a FIFO
\fBmknod()\fR	Create a special file
\fBmount()\fR	Mount a file system
\fBnap()\fR	Sleep briefly
\fBopen()\fR	Open a file
\fBpathconf()\fR	Get a file variable by path name
\fBpause()\fR	Wait for signal
\fBpipe()\fR	Create a pipe
.\" \fBprofil()\fR	Profile process execution
\fBpoll()\fR	Query several I/O devices
\fBptrace()\fR	Trace process execution
\fBputmsg()\fR	Place a message onto a stream
\fBread()\fR	Read from a file
\fBrename()\fR	Rename a file
\fBrmdir()\fR	Remove a directory
\fBsetgid()\fR	Set group id and user id
\fBsetgroups()\fR	Set the supplemental group-access list
\fBsetpgid()\fR	Set the process-group identifier
\fBsetpgrp()\fR	Make a process a process-group leader
\fBsetsid()\fR	Set session identifier
\fBsetuid()\fR	Set user id
\fBsigaction()\fR	Perform detailed signal management
\fBsigaddset()\fR	Add a signal to a set of signals
\fBsigdelset()\fR	Delete a signal from a set
\fBsigemptyset()\fR	Initialize a set of signals
\fBsigfillset()\fR	Initialize a set of signals
\fBsighold()\fR	Place a signal on hold
\fBsigignore()\fR	Tell the system to ignore a signal
\fBsigismember()\fR	Check if a signal is a member of a set
\fBsignal()\fR	Specify action to take upon receipt of a given signal
\fBsigpause()\fR	Pause until a given signal is received
\fBsigpending()\fR	Examine signals that are blocked and pending
\fBsigprocmask()\fR	Examine or change the signal mask
\fBsigrelse()\fR	Release a signal for processing
\fBsigset()\fR	Specify action to take upon receipt of a given signal
\fBsigsuspend()\fR	Install a signal mask and suspend process
\fBstat()\fR	Find file attributes
\fBstatfs()\fR	Get information about a file system
\fBstime()\fR	Set the time
\fBstty()\fR	Set terminal modes
\fBsync()\fR	Flush system buffers
\fBsysconf()\fR	Get configurable system variables
\fBsysi86()\fR	Identify parts within Intel-based machines
\fBtime()\fR	Get current system time
\fBtimes()\fR	Obtain process execution times
\fBulimit()\fR	Get/set limits for a process
\fBumask()\fR	Set file creation mask
\fBumount()\fR	Unmount a file system
\fBuname()\fR	Get name and version of \*(CO
\fBunlink()\fR	Remove a file
\fBustat()\fR	Get statistics on a file system
\fButime()\fR	Change file access and modification times
\fBwait()\fR	Await completion of child process
\fBwaitpid()\fR	Wait for a process to terminate
\fBwrite()\fR	Write to a file
.SH Miscellaneous
The following functions do not fit neatly into any of the above
categories.
.LB
\fBbsearch()\fR	Search an array
\fBcoffnlist()\fR	Symbol table lookup
\fBcrypt()\fR	Encryption using rotor algorithm
\fBgetenv()\fR	Read environmental variable
\fBgetopt()\fR	Get a command-line option
\fBl3tol()\fR	Convert file system block number to long integer
\fBlockf()\fR	Lock a file or a section of a file
\fBlongjmp()\fR	Perform a non-local goto
\fBltol3()\fR	Convert long integer to file system block number
\fBmtype()\fR	Return symbolic machine type
\fBperror()\fR	System call error messages
\fBputenv()\fR	Add a string to the environment
\fBqsort()\fR	Sort arrays in memory
\fBsetjmp()\fR	Save machine state for non-local goto
\fBsiglongjmp()\fR	Perform a non-local goto and restore signal mask
\fBsigsetjmp()\fR	Save machine state and signal mask for non-local jump
\fBshellsort()\fR	Sort arrays in memory
\fBswab()\fR	Swap a pair of bytes
\fBsystem()\fR	Pass a command to the shell for execution
\fBtempnam()\fR	Generate a unique name for a temporary file
.SH "See Also"
.Xr "libraries" libraries
.SH Notes
You do not need to link
.B libc
explicitly into your programs.
The command
.B cc
always includes it by default.
.PP
The macro
.B offsetof()
is not described above because it does not ``live'' in
.BR libc ;
however, it is a useful, general-purpose entity.
For details, see its Lexicon entry.
