Topic : An introduction to C
Author : Tom Torfs
Page : << Previous 22  Next >>
Go to page :


                    /* illegal instruction */
SIGINT                        /* interactive attention signal */
SIGSEGV                       /* invalid access to storage */
SIGTERM                       /* termination request received */


These are integer constants representing the signal numbers corresponding to the specified error conditions. Your implementation need not generate any of these signals (unless explicitly raised), and additional signals starting with SIG followed by an uppercase letter may be defined.

SIG_DFL                       /* default handling */
SIG_IGN                       /* ignore signal */


These macros can be used as the second parameter of the signal() function. Your implementation may define more of these macros starting with SIG_ followed by an uppercase letter.

SIG_ERR

This macro corresponds to the return value of signal() in case an error occurs.
Functions

void (*signal(int sig, void (*func)(int)))(int);

Determines how the specified signal number sig (one of the above listed SIG macros) is handled. The second parameter, func, may be either SIG_DFL, which means default handling for that signal, SIG_IGN, which means that signal will be ignored, or a pointer to a function that is called when the signal occurs, a so-called signal handler. Before this handler is called, the signal will be reset to the default handler.
The signal handler must be a function returning void and taking one parameter of type int, the signal number. It may terminate by means of a return statement (unless the signal occurring was SIGFPE or another form of exception) or a call to abort(), exit() or longjmp(). Unless the signal was invoked by the raise() or abort() function, the signal handler may not use any other standard library functions or access any static data other than assigning a value to a static variable of type volatile sig_atomic_t.
If the request is successful, the signal() function will return the address of the previous signal handler for this signal. Otherwise it will return SIG_ERR and set errno.

int raise(int sig);

Causes the specified signal number to occur. Returns 0 if successful, nonzero otherwise.16.11. stdarg.h (variable arguments)
See also 14. Variable argument functions.
Types

va_list

This type is used by the va_start(), va_arg() and va_end() macros to hold information about the variable argument list.
Macros

void va_start(va_list ap,  parmN);

The va_start() macro initializes the va_list variable for use by the va_arg() and va_end() macros; parmN is the name of the parameter right before the ellipsis (...).

type va_arg(va_list ap,  type);

Returns the next variable argument of the specified type. This type must correspond to the type of the parameter actually passed after the default promotions of short to int, float to double, etc. The va_list variable must have been initialized by the va_start macro before.

void va_end(va_list ap);

The va_end() macro must be applied to the va_list variable before the function returns.16.12. stddef.h (standard type/macro definitions)
Types

ptrdiff_t

Signed integral type which is the result of substracting two pointers.

size_t

Unsigned integral type used for holding the size of an object (also the type of the result of the sizeof operator).

wchar_t

Wide character type; in any extended character set the value 0 is reserved for the null character.
Macros

NULL

Pointer constant used for a pointer that points nowhere.

offsetof(type,  member-designator)

Returns the offset (of type size_t) in bytes from the beginning of the structure type to its member variable specified by member-designator.16.13. stdio.h (input/output)
Types

FILE

A type used for interfacing with streams (files). See also 11. Using files.

fpos_t

A type capable of holding every possible file position. Used by fgetpos() and fsetpos().

size_t

Explained in 16.12. stddef.h.
Macros

BUFSIZ

Integer constant; the size of the buffer used by the setbuf() function. Minimum 256.

EOF

Negative integer constant which several file I/O functions (e.g. fgetc()) return to indicate end-of-file condition.

FOPEN_MAX

Integer constant; the minimum number of files that can be open at the same time. This is at least 8 (of which 3 are reserved for the standard I/O streams; your compiler may even reserve more for other non-standard pre-opened I/O streams).

FILENAME_MAX

Integer constant; the maximum length for a filename (includes path etc.) that is guaranteed to be usable. This doesn't mean that longer filenames may not work as well.

_IOFBF                        /* full buffering */
_IOLBF                        /* line buffering */
_IONBF                        /* no buffering */


Integer constants used by the setvbuf() function.

L_tmpnam

Integer constant; the maximum length of the temporary filename generated by the tmpnam() function.

NULL

Explained in 16.12. stddef.h.

SEEK_CUR                      /* seek from current position */
SEEK_END                      /* seek from end of file */
SEEK_SET                      /* seek from beginning of file */


Integer constants used by the fseek() function.

stderr
stdin
stdout


Pointers to FILE representing the standard input, output and error streams. See also 11.4. Using the standard I/O streams.

TMP_MAX

Integer constant; minimum number of unique temporary filenames the tmpnam() function can generate. At least 25.
Functions

void clearerr(FILE *stream);

Clears the end-of-file and error indicators for the specified stream.

int fclose(FILE *stream);

Closes the file associated with the stream; all buffered data will be written. The stream may not be used afterwards except for assigning a new value to it. Returns 0 if successful, EOF otherwise.

int feof(FILE *stream);

Returns nonzero if an attempt has been made to read past the end of the file of the specified stream [*], returns 0 otherwise.
[*] This is different from the way EOF works in some other languages, where it can be used to check if end-of-file has been reached.

int ferror(FILE *stream);

Returns nonzero if the error indicator is set for the specified stream, returns 0 otherwise.

int fflush(FILE *stream);

Writes all buffered data from the stream to the file. The stream must be an output stream or an update stream which was last written to. If stream is null all buffered data for all such streams will be written to the file. Returns 0 if successful, EOF otherwise.

int fgetc(FILE *stream);

Returns the next character from the specified stream as an unsigned char converted to int, or EOF on error.

int fgetpos(FILE *stream, fpos_t *pos);

Stores the current file position for the specified stream into the fpos_t variable pointed to by pos. This variable can later be used by the fsetpos() function to reposition the stream to its current position. Returns 0 if successful or nonzero otherwise.

char *fgets(char *s, int n, FILE *stream);

Reads upto n-1 characters or a newline (whichever comes first) from the specified stream and stores it in the array pointed to by s. A 0 terminator character is appended. Any newline character is not removed. Returns s if successful, or NULL otherwise.
See also 11.2. Using disk files.

FILE *fopen(const char *filename, const char *mode);

The fopen() function is discussed in 11.2. Using disk files.

int fprintf(FILE *stream, const char *format, ...);

The fprintf() function is analogous to the printf() function, except that it writes its output to the specified stream.

int fputc(int c, FILE *stream);

Writes the character specified by c (converted to unsigned char) to the specified stream at the current file position, and adjusts this position appropriately. In append mode, the character is always appended to the end of the file. Returns the character written if successful or EOF otherwise.

int fputs(const char *s, FILE *stream);

Writes the string pointed to by s to the specified stream (not including the terminating 0 character). Returns a nonnegative value if successful, or EOF otherwise.

size_t fread(void *ptr, size_t size, size_t nmemb,
             FILE *stream);


Reads upto nmemb elements of the specified size [*] from the specified stream into the array pointed to by ptr. The file

Page : << Previous 22  Next >>