Path: utzoo!attcan!uunet!husc6!mailrus!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Secure 'C' library - string I/O (Re: retiring gets(3)) Message-ID: <14486@mimsy.UUCP> Date: 11 Nov 88 02:26:57 GMT References: <1988Nov8.054845.23998@utstat.uucp> <1031@cps3xx.UUCP> <2185@ficc.uu.net> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 28 In article <2185@ficc.uu.net> peter@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 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@mimsy.umd.edu Path: uunet!mimsy!chris