fopen() and memory shortage
Larry Reznick
reznick at ribs.UUCP
Fri Feb 9 04:42:51 AEST 1990
> I had to sleep over it before I figured out what's wrong:
> fopen() needs memory for buffering, and there wasn't enough left.
> I replaced fopen() and fclose() with open() and close(),
> and presto! it worked.
Try using the stat() function, which gives directory information for a
pathname without opening the file. Your fexist() function would use
stat() to determine if the file exists.
> I can't help wondering why the author had used buffered calls in the
> first place, since nothing is read from the disk anyway; is there
> some situation where open()/close() wouldn't work (are they less
> portable perhaps)?
The open()/close() functions are not standard; fopen()/fclose() are.
Using open()/close() may impact portability.
> Suggestions, anyone?
>
> (I am using TurboC 2.0 in MS-DOS, if it matters.)
If you're really in a crunch for memory such that there is no room for
the file buffers (have you checked your config.sys FILES variable?),
you might consider fclose()ing one or more of stdin, stdout, stderr,
stdaux, & stdprn. If you're not using them why keep them around?
--
Lawrence S. Reznick, KB6NSI Systems Software Engineer
Alldata Corporation Phone: (916) 684-5200 FAX: (916) 684-5225
9412 Big Horn Blvd, Suite 6 UUCP: {sun!sacto,csusac}!ribs!reznick
Elk Grove, CA 95758 INTERNET: ribs!reznick at sacto.West.Sun.COM
More information about the Comp.lang.c
mailing list