PRB: Errno Set to -1 After Call to Run-Time Library Function

ID: Q138293

The information in this article applies to:

SYMPTOMS

In a program built using Visual C++, the global variable errno is set to -1 after calling a C/C++ run-time function.

CAUSE

This occurs because the run-time library made an MS-DOS system call that failed, and the MS-DOS error code could not be mapped to one of the predefined errno values in Errno.h.

RESOLUTION

To determine what the real error is, check the value of the global variable _doserrno, and call the _dosexterr function to get extended error information from MS-DOS. For more information on MS-DOS error codes and extended error information, please consult the MS-DOS books listed in the "References" section of this article.

MORE INFORMATION

Usually, errno is set to one of the predefined values in Errno.h when an error occurs. For example, if your program calls the _open function to open a file, and it fails and sets errno to the constant EMFILE (defined as 24), it means the program is out of file handles and cannot open any more files. There is no constant for -1 in Errno.h; it is an undocumented value for errno.

REFERENCES

Visual C++ Run-Time Library Reference. MS-DOS Programmer's Reference. Advanced MS-DOS Programming.

Keywords          : kb16bitonly kbCRT kbVC 
Version           : 1.0 1.5 1.51 1.52
Issue type        : kbprb

Last Reviewed: August 11, 1997