Path: utzoo!attcan!uunet!husc6!mailrus!ames!oliveb!pyramid!prls!mips!hitz From: hitz@mips.COM (David Hitz) Newsgroups: comp.unix.questions Subject: Re: Guessing buffer size needed for sprintf beforehand Summary: RBFM -- Read Both Fucking Manuals. Message-ID: <2190@quacky.mips.COM> Date: 16 May 88 05:53:55 GMT References: <136@insyte.uucp> <7768@ncoast.UUCP> Reply-To: hitz@mips.COM (David Hitz) Organization: MIPS Computer Systems, Sunnyvale, CA Lines: 20 In article <7768@ncoast.UUCP> allbery@ncoast.UUCP (Brandon Allbery) writes: >As quoted from <136@insyte.uucp> by jad@insyte.uucp (Jill Diewald): >+--------------- >| One solution is to fprintf into a file opened to be /dev/null. [...] >Close. fprintf() to a newly-created temporary file, then rewind() it (this >is a stdio function) and getc() out of it and send it wherever. If you need >the size, get the file size using the OS's current-file-position call before >the rewind(). This is perhaps a bit slower than an in-core buffer, but it's >clean and is limited only by free space on the disk! Oops: SYSV vs. BSD. In SYSV printf() returns the number of characters printed, so Jill's solution works fine without Brandon's gyrations. In BSD printf() returns the first argument. -- Dave Hitz home: 408-739-7116 UUCP: {decvax,ucbvax,ihnp4}!decwrl!mips!hitz play: 408-991-0345