Microsoft KB Archive/145996

= FIX: _setmaxstdio Causes Access Violation =

Article ID: 145996

Article Last Modified on 12/9/2003

-

APPLIES TO

 The C Run-Time (CRT), when used with:  Microsoft Visual C++ 4.0 Professional Edition

 Microsoft Visual C++ 4.1 Subscription

 Microsoft Visual C++ 4.2 Professional Edition

 Microsoft Visual C++ 4.2 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Learning Edition</li></ul>

 Microsoft Visual C++ 5.0 Learning Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q145996

<div class="symptoms_section">

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 <Project>.exe: 0xC0000005: Access Violation

<div class="resolution_section">

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.

<div class="status_section">

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.

<div class="moreinformation_section">

Sample Code to Reproduce Problem
/* Compile options needed: none


 * 1) include <stdio.h>

void main {   _setmaxstdio(511); FILE *text = fopen("textfile.txt","w"); fclose(text); }

Additional query words: kbVC400bug 4.00 4.10

Keywords: kbbug kbfix kbcrt kbvc410fix KB145996

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.