Node:Usual file name errors, Next:Opening files at a low level, Previous:Low-level file routines, Up:Low-level file routines
Usual file name errors
Most low-level file functions return some kind of error flag if they
cannot perform the action you request, for example, if they cannot parse
the file name or find the file. However, to discover which error
or what kind of error has occurred, you must frequently refer to the
system variable errno
. This is an integer specifying the most recent
error that has occurred. Macros for values of errno
are listed below.
They are all defined in the GNU C Library.
The word component below refers to part of a full file name. For
example, in the file name /home/fred/snozzberry.txt
, fred
is a component that designates a subdirectory of the directory
/home
, and snozzberry.txt
is the name of the file proper.
Most functions that accept file name arguments can detect the following
error conditions. These are known as the usual file name errors.
The names of the errors, such as EACCES
, are compounded of
E
for "error" and a term indicating the type of error, such as
ACCES
for "access".
EACCES
- The program is not permitted to search within one of the directories in
the file name.
ENAMETOOLONG
- Either the full file name is too long, or some component is too long.
GNU does not limit the overall length of file names, but depending on
which file system you are using, the length of component names may be
limited. (For example, you may be running GNU/Linux but accessing a
Macintosh HFS disk; the names of Macintosh files cannot be longer than
31 characters.)
ENOENT
- Either some component of the file name does not exist, or some component is
a symbolic link whose target file does not exist.
ENOTDIR
- One of the file name components that is supposed to be a directory is
not a directory.
ELOOP
- Too many symbolic links had to be followed to find the file. (GNU has a limit on how many symbolic links can be followed at once, as a basic way to detect recursive (looping) links.)
You can display English text for each of these errors with the m
conversion specifier of the printf
function, as in the following
short example.
errno = EACCES; printf ("errno string (EACCES): %m\n");
This example prints the following string:
errno string (EACCES): Permission denied
See Formatted output conversion specifiers, for more information
on the m
conversion specifier.