DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
C and C++ compilation system

C library (libc)

This topic discusses some of the more important routines in the standard C library. libc contains the system calls described in Section 2 and the C language functions described in Section 3, Subsections 3C and 3S.

Subsection 3S routines

Subsection 3S of the manual pages contains the standard I/O library for C programs. Frequently, one manual page describes several related functions or macros. In ``Standard I/O Functions and Macros'', the left-hand column contains the name that appears at the top of the manual page; the other names in the same row are related functions or macros described on the same manual page. Programs that use these routines should include the header file stdio.h.

fclose fflush     Close or flush a stream.
ferror feof clearerr fileno Stream status inquiries.
fopen freopen fdopen   Open a stream.
fread fwrite     Input/output.
fseek rewind ftell   Reposition a file pointer in a stream.
getc getchar fgetc getw Get a character or word from a stream.
gets fgets     Get a string from a stream.
popen pclose     Begin or end a pipe to/from a process.
printf fprintf sprintf   Print formatted output.
putc putchar fputc putw Put a character or word on a stream.
puts fputs     Put a string on a stream.
scanf fscanf sscanf   Convert formatted input.
setbuf setvbuf     Assign buffering to a stream.
system       Issue a command through the shell.
tmpfile       Create a temporary file.
tmpnam tempnam     Create a name for a temporary file.
ungetc       Push character back into input stream.
vprintf vfprintf vsprintf   Print formatted output of a varargs argument list.

Standard I/O Functions and Macros

Subsection 3C routines

Subsection 3C contains functions and macros that perform a variety of tasks:

Here we'll look at functions and macros that perform the first three tasks.

``String Operations'' lists most of the string-handling functions that appear in string(3C). Programs that use these functions should include the header file string.h.

Most of these string-handling functions have corresponding functions that handle multibyte/wide-character objects. These functions are designated by the prefix wcs in place of the str prefix of the string functions.

strcat Append a copy of one string to the end of another.
strncat Append no more than a given amount of characters from one string to the end of another.
strcmp Compare two strings. Returns an integer less than, greater than, or equal to 0 to show that one is lexicographically less than, greater than, or equal to the other.
strncmp Compare no more than a given amount of characters from the two strings. Results are otherwise identical to strcmp.
strcpy Copy a string.
strncpy Copy a given amount of characters from one string to another. The destination string will be truncated if it is longer than the given amount of characters, or padded with null characters if it is shorter.
strdup Return a pointer to a newly allocated string that is a duplicate of a string pointed to.
strchr Return a pointer to the first occurrence of a character in a string, or a null pointer if the character is not in the string.
strrchr Return a pointer to the last occurrence of a character in a string, or a null pointer if the character is not in the string.
strlen Return the number of characters in a string.
strpbrk Return a pointer to the first occurrence in one string of any character from the second, or a null pointer if no character from the second occurs in the first.
strspn Return the length of the initial segment of one string that consists entirely of characters from the second string.
strcspn Return the length of the initial segment of one string that consists entirely of characters not from the second string.
strstr Return a pointer to the first occurrence of the second string in the first string, or a null pointer if the second string is not found.
strtok Break up the first string into a sequence of tokens, each of which is delimited by one or more characters from the second string. Return a pointer to the token, or a null pointer if no token is found.
strlist Concatenate an indefinite number of null-terminated strings into the array pointed to by its first argument.

String Operations

``Classifying 8-Bit Character-Coded Integer Values'' lists most of the functions and macros that classify 8-bit character-coded integer values. These routines appear in conv(3C) and ctype(3C). Programs that use these routines should include the header file ctype.h.

isalpha Is c a letter?
isupper Is c an uppercase letter?
islower Is c a lowercase letter?
isdigit Is c a digit [0-9]?
isxdigit Is c a hexadecimal digit [0-9], [A-F], or [a-f]?
isalnum Is c alphanumeric (a letter or digit)?
isspace Is c a space, horizontal tab, carriage return, new-line, vertical tab, or form-feed?
ispunct Is c a punctuation character (neither control nor alphanumeric)?
isprint Is c a printing character?
isgraph Same as isprint except false for a space.
iscntrl Is c a control character or a delete character?
isascii Is c an ASCII character?
toupper Change lower case to upper case.
_toupper Macro version of toupper.
tolower Change upper case to lower case.
_tolower Macro version of tolower.
toascii Turn off all bits that are not part of a standard ASCII character; intended for compatibility with other systems.

Classifying 8-Bit Character-Coded Integer Values

``Converting Characters, Integers, or Strings'' lists functions and macros in Subsection 3C that are used to convert characters, integers, or strings from one representation to another. The left-hand column contains the name that appears at the top of the manual page; the other names in the same row are related functions or macros described on the same manual page. Programs that use these routines should include the header file stdlib.h.

a64l l64a   Convert between long integer and base-64 ASCII string.
strtod atof strtold Convert string to double-precision number.
strtol atol atoi Convert string to integer.
strtoul     Convert string to unsigned long.

Converting Characters, Integers, or Strings

System calls

UNIX® operating system calls are the interface between the kernel and the user programs that run on top of it. read(2), write(2), and the other system calls define the UNIX® operating system. Everything else is built on their foundation. Strictly speaking, they are the only way to access such facilities as the file system, interprocess communication primitives, and multitasking mechanisms.

Of course, most programs do not need to invoke system calls directly to gain access to these facilities. If you are performing input/output, for example, you can use the standard I/O functions described earlier. When you use these functions, the details of their implementation on the UNIX® operating system -- for example, that the system call read underlies the fread implementation in the standard C library -- are transparent to the program. Therefore, the program will generally be portable to any system with a conforming C implementation.

In contrast, programs that invoke system calls directly are portable only to other systems similar to the UNIX® operating system. Therefore, you would not use read in a program that performed a simple I/O operation. Other operations, however, including most multitasking mechanisms, do require direct interaction with the UNIX® operating system kernel. These operations are discussed in detail in Programming with system calls and libraries.


Next topic: Math library (libm)
Previous topic: How strcmp() Is Used in a Program

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004