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

Last reviewed: August 8, 1997
Article ID: Q138293
The information in this article applies to:
  • The C Run-time (CRT) included with: - Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, 1.52

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          : CRTIss kb16bitonly
Version           : 1.0 1.5 1.51 1.52
Issue type        : kbprb


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.