Chapter Contents |
Previous |
Next |
Introduction to the SAS/C Library |
The external
int
variable
errno
contains the number of the most recent
error or warning condition detected by the run-time library. To use this value,
include the header file
<errno.h>
.
If no error or warning condition is detected, the value
of
errno
is 0. After program execution
starts,
errno
is never reset to 0 by the
library. Programs that use
errno
for information
about unusual conditions must set it to 0 before calling a library routine
that may detect such a condition.
The
<errno.h>
file contains declarations of the
errno
variable and definitions of symbolic names for the values that can be assigned.
These names rather than numeric values should be used for
errno
.
SAS/C defines a number of general-use
errno
names. There are also many
errno
names associated with specific sublibraries,
notably the SAS/C socket
library and the SAS/C POSIX support. Socket
errno
names are documented in Chapter 15, "The BSD UNIX Socket Library,"
in
SAS/C Library Reference, Volume 2, and
errno
names related to
USS are documented in Chapter 19, "Introduction to POSIX," in
SAS/C Library Reference, Volume 2. For
a complete listing of all
errno
values,
see
SAS/C Compiler and Library Quick Reference Guide.
The variable
errno
is implemented as a macro. If you use
errno
without including
<errno.h>
, the correct
data may not be accessed.
The only portable values for
errno
are
EDOM
and
ERANGE
. The following example illustrates the use of
errno
:
#include <errno.h> #include <stdio.h> FILE *f; char *filename; if (!(f = fopen(filename, "r"))) { /* See if any file can be opened. */ if (errno == ELIMIT) { printf("Too many open files\n"); return(EOF); } else { printf("%s could not be opened, enter new filename\n", filename); getfname(filename); } }
More Exact Error Information: _msgno Variable |
The
header file
<lcdef.h>
contains the declaration
of a nonstandard external variable,
_msgno
.
This variable contains the message number of the last SAS/C library diagnostic.
For example, if the last message ID were LSCX503,
_msgno
would contain 503.
_msgno
may provide
more information about a failure than
errno
.
For instance, trying to read a file that has not been created sets
errno
to ENFOUND, but you can use
_msgno
to distinguish the cases of an empty sequential file (
_msgno
= 503) and a missing PDS member (
_msgno
= 504).
_msgno
is
not portable,
so programs that must be portable should use only
errno
.
_msgno
is implemented
as a macro, so you should not use the name for any other purpose.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.