@c ---------------------------------------------------------------------- @node errno, stdio @vindex errno @subheading Syntax @example #include extern int errno; @end example @subheading Description This variable is used to hold the value of the error of the last function call. The value might be one of the following: @table @code @item 0 No Error. Library functions never set @code{errno} to zero, but the startup code does that just before calling @code{main} (this is ANSI C requirement). @item 1 EDOM -- Numerical input to a function is out of range. @item 2 ERANGE -- Numerical output of a function is out of range. @item 3 E2BIG -- Argument list too long. @code{system} and the functions from the @code{spawn} family assign this to @code{errno} when the command line is too long (longer than 126-character limit when invoking non-DJGPP programs, or longer than the transfer buffer size when invoking DJGPP programs). @item 4 EACCES -- Permission denied. Attempt to write to a read-only file, or remove a non-empty directory, or open a directory as if it were a file, etc. In essence, it's a DOS way of saying "You can't do that, but I'm too stupid to know why." @item 5 EAGAIN -- Resource temporarily unavailable, try again later. Almost never used in DJGPP, except when DOS returns error code 3Dh ("network print queue full") 81h (NetWare4 "CWait children still running") or 9Bh (NetWare4 "unable to create another TCB"). @item 6 EBADF -- Bad file descriptor: an invalid file handle passed to a library function. @item 7 EBUSY -- Resource busy. Attempt to remove current directory (including current directory on another drive), or when a networked resource, such as a drive, is in use by another process. @item 8 ECHILD -- No child processes. Returned by @code{wait} and @code{waitpid}, and by NetWare-related calls. @item 9 EDEADLK -- Resource deadlock avoided. Never used in DJGPP. @item 10 EEXIST -- File exists. Returned by @code{open} and @code{mkdir} when a file or directory by that name already exists. @item 11 EFAULT -- Bad address. A function was passed a bad pointer (like a @code{NULL} pointer). @item 12 EFBIG -- File too large. Never used in DJGPP. @item 13 EINTR -- Interrupted system call. @code{system} and the functions of the @code{spawn} family use that when the child program was interrupted by @kbd{Ctrl-@key{C}}. Also, when DOS returns the "fail on INT 24h" error code. @item 14 EINVAL -- Invalid argument. Any case when any argument to a library function is found to be invalid. Examples include invalid drive number, "." or ".." as one of the arguments to @code{rename}, syntax errors in the command line passed to @code{system}, etc. @item 15 EIO -- Input or output error. Low-level error in I/O operation, like bad disk block, damaged FAT, etc. @item 16 EISDIR -- Is a directory: an attempt to do something with a directory which is only allowed with regular files. DOS usually returns @code{EACCES} in these cases, but DJGPP sometimes assigns @code{EISDIR} to @code{errno}, like when @code{rename} is called to move a regular file over a directory, or when @code{system} or one of the @code{spawn*} functions are passed a name of a directory instead of an executable program. @item 17 EMFILE -- Too many open files in system (no more handles available). This usually means that the number specified by the @samp{FILES=} directive in @file{CONFIG.SYS} is too small. @item 18 EMLINK -- Too many links. Not used in DJGPP (as DOS doesn't support hard links). @item 19 ENAMETOOLONG -- File name too long (longer than @code{FILENAME_MAX}, defined in @file{stdio.h}). @item 20 ENFILE -- Too many open files. Never used in DJGPP. @item 21 ENODEV -- No such device. Attempt to access an invalid drive, or an invalid operation for the type of drive. @item 22 ENOENT -- No such file or directory. @item 23 ENOEXEC -- Unable to execute file. Returned by @code{_dxe_load} (when the argument names a file that isn't a valid DXE), and by NetWare-related calls which run programs remotely. @item 24 ENOLCK -- No locks available. Returned when the DOS file-locking functions cannot lock more files (due to overflow of the sharing buffer). @item 25 ENOMEM -- Not enough memory. Note that, unlike your expectations, @code{malloc} does NOT set @code{errno} to @code{ENOMEM}; however, several library functions that use @code{malloc} will do that when it returns a @code{NULL} pointer. @item 26 ENOSPC -- No space left on drive. DOS usually doesn't return this error, but @code{write} and @code{_write} do this for it, when they detect a full disk condition. @item 27 ENOSYS -- Function not implemented. Any system call that isn't supported by the underlying OS, like an LFN function when running on plain DOS. @item 28 ENOTDIR -- Not a directory. DOS never returns this code, but some library functions, like @code{rename} and @code{_truename}, do that if they expect a valid directory pathname, but get either an invalid (e.g. empty) pathname or a file that is not a directory. @item 29 ENOTEMPTY -- Directory not empty. DOS never returns this code, but @code{rename} does, when it is called to move a directory over an existing non-empty directory. @item 30 ENOTTY -- Inappropriate I/O control operation. The @dfn{termios} functions set @code{errno} to this when called on a device that is not a TTY. @item 31 ENXIO -- No such device or address. An operation attempted to reference a device (not a disk drive) that is invalid, or non-existent, or access a disk drive that exists but is empty. @item 32 EPERM -- Operation not permitted. Examples include: sharing or file lock violations; denial of access to networked resources; expired password or illegal login attempts via a network; too many or duplicate network redirections; etc. @item 33 EPIPE -- Broken pipe: attempt to write to a pipe with nobody to read it. This never happens in DJGPP. @item 34 EROFS -- Read-only file system: attempt to write to a read-only disk. Unfortunately, DOS almost never returns this code. @item 35 ESPIPE -- Invalid seek: attempt to seek on a pipe. Never happens in DJGPP, except for NetWare-related operations, since pipes are simulated with regular files in MS-DOS, and therefore are always seekable. @item 36 ESRCH -- No such process. Not used in DJGPP. @item 37 EXDEV -- Improper link. An attempt to rename a file across drives or create a cross-device hardlink. @item 38 ENMFILE -- No more files. @code{findfirst} and @code{findnext} assign this to @code{errno} when they exhaust the files in the directory. @code{readdir} does that as well. @item 39 ELOOP -- Too many levels of symbolic links. Can be set virtually by any file handling function in library. Usually means encountered link loop (link1 -> link2, link2 -> link1). @item 40 EOVERFLOW -- Value too large. @code{filelength} can assign this to @code{errno} when a file's length is larger than @math{2^31-2} (@pxref{filelength}). @code{lfilelength} can assign this to @code{errno} when a file's length is larger than @math{2^63-1} (@pxref{lfilelength}). @item 41 EILSEQ -- Invalid or incomplete multibyte or wide character. @end table @xref{perror}. @subheading Portability @portability ansi, posix