Secure 'C' library - string I/O (Re: retiring gets(3))

Chris Torek chris at mimsy.UUCP
Fri Nov 11 12:26:57 AEST 1988


In article <2185 at ficc.uu.net> peter at ficc.uu.net (Peter da Silva) writes:
>In general, sprintf should have an argument describing the size of the
>output buffer. A better solution still would be to can sprintf and replace
>it with something like:
>
>	FILE *stropen(buffer, length, mode);

[mimsy73] grep fmemopen /usr/include/stdio.h
FILE	*fmemopen _PROTO_((char *addr, unsigned int len, const char *mode));
[mimsy74]

(The `_PROTO_(x)' macro expands to `x' if __STDC__, else to `'.)  [The
prototypes in our <stdio.h> wreak minor havoc with GCC.  GCC needs more
type-correctness internally.]

Something similar should appear in 4.4BSD.

>	Any of the normal I/O functions will operate on this internal file.
>	A null will be written at the high water mark when the file pointer
>	is fclosed. fseek operates within the string.

fseek does not currently work on my `fmem' function (for no good
reason); it also does not append a NUL (you can do that yourself
directly with putc() and by using sizeof(str)-1 and setting
str[sizeof(str)-1]=0).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list