Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site umcp-cs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!houxz!vax135!cornell!uw-beaver!tektronix!hplabs!hao!seismo!rlgvax!cvl!umcp-cs!chris From: chris@umcp-cs.UUCP Newsgroups: net.unix-wizards Subject: Re: _print/_doprnt Message-ID: <7788@umcp-cs.UUCP> Date: Sat, 7-Jul-84 21:12:42 EDT Article-I.D.: umcp-cs.7788 Posted: Sat Jul 7 21:12:42 1984 Date-Received: Thu, 12-Jul-84 03:20:45 EDT References: <1075@sri-arpa.UUCP> <2048@rlgvax.UUCP> <1472@pegasus.UUCP> Organization: Univ. of Maryland, Computer Science Dept. Lines: 55 As long as we're getting into *printf: Here's a bunch of things I'd like to see in the stdio library: a) sprintfl (or some similar name): like sprintf, but takes a maximum buffer length specification. For example: char buf[N]; . . . sprintfl(buf, N, "%s", foo); Avoiding overrun with plain ol' sprintf() is a pain. b) v*printf versions of everything on Berkeley Unix(tm) c) _IOSTRG flag working properly. At least in BSD, _IOSTRG is *never* checked (not once!) so if you try to write sprintfl as /* sprintfl - vax version */ char * sprintfl(buf, len, fmt, arg) register char *buf; register int len; char *fmt; { struct _iobuf _strbuf; strbuf._flag = _IOWRT | _IOSTRG; strbuf._cnt = len - 1; strbuf._ptr = buf; _doprnt(fmt, &arg, _strbuf); buf[len - 1] = '\0'; return buf; } and call sprintfl with a `len' of (say) 50 and a fmt+arglist that comes out to more than 50 characters, guess what happens? _flsbuf writes the first 49 characters [len-1, remember?] to whatever file descriptor happens to be in _strbuf._file, or other similarly nasty things (the exact behaviour depends on what is in _strbuf._base). This means that if you pass a sufficient amount of stuff to sprintf, it will break, since it sets strbuf._flag as above (but sets strbuf._len to 32767). The (temporary) way around this is to leave out _IOWRT, which makes _flsbuf return an error, which makes _doprnt quit, which is essentially what is desired. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci (301) 454-7690 UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland