Missing stdio features.

karl at haddock karl at haddock
Thu Sep 4 04:55:00 AEST 1986


sun!guy (Guy Harris) writes:
> >FILE *fopenstr(char *str, int len, char *mode)
>It looks straightforward to implement IF you have the 4BSD version of
>standard I/O, where there's a "this is a string" flag for each FILE
>structure.  The S5 version, unfortunately, has only a "char" for the flags,
>not a "short", so it says that the "last" FILE entry, and only that entry,
>is a stream.

Making the last FILE special was indeed a botch, but it isn't necessary to
expand the _flag field to fix it.  Just use (iop->_file == -1) on string
files.

>Given "fopenstr" you can actually provide a version of "sprintf" that
>performs *bounds checking* on the string it's printing into.  (Wow, what a
>unique concept, software that doesn't scribble its data space when a user
>types in a string longer than it expected!)

And given "fopenfxn", you could provide a version of "sprintf" that not only
detects the overflow, but *fixes* it with a realloc()!

Karl W. Z. Heuer (ima!haddock!karl; karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list