DOCUMENT:Q145996 30-JUL-2001 [visualc] TITLE :FIX: _setmaxstdio Causes Access Violation PRODUCT :Microsoft C Compiler PROD/VER:winnt: OPER/SYS: KEYWORDS:kbCRT kbVC kbVC410fix ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - The C Run-Time (CRT), used with: - *EDITOR Please do not choose this product*Microsoft Visual C++ 32-bit Edition* use 241, 265, 225, versions 4.0, 4.1, 4.2 ------------------------------------------------------------------------------- SYMPTOMS ======== The CRT function _setmaxstdio does not work properly. The function sets the maximum number of files an application can open with the stream I/O functions, like fopen. It is documented in the README book in the online documentation, and in the Vcread.wri file. Using _setmaxstdio results in the following error when you exit the program or call the fopen function: Unhandled exception in .exe: 0xC0000005: Access Violation RESOLUTION ========== Do not use the _setmaxstdio function. Here are two workarounds: - Keep track of the number of files opened with fopen, and do not open more than 512. -or- - If the application needs to open more than 512 files, use the low-level I/O functions: _open, _read, and _write. These allow up to 2048 files to be opened. STATUS ====== Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ 4.1. MORE INFORMATION ================ Sample Code to Reproduce Problem -------------------------------- /* Compile options needed: none */ #include void main() { _setmaxstdio(511); FILE *text = fopen("textfile.txt","w"); fclose(text); } Additional query words: kbVC400bug 4.00 4.10 ====================================================================== Keywords : kbCRT kbVC kbVC410fix Technology : kbVCsearch kbAudDeveloper kbCRT Version : winnt: Issue type : kbbug Solution Type : kbfix ============================================================================= 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. Copyright Microsoft Corporation 2001.