X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f Message-ID: <3FF9F187.5010201@phekda.gotadsl.co.uk> Date: Mon, 05 Jan 2004 23:21:43 +0000 From: Richard Dawe User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031031 X-Accept-Language: en, de, fr MIME-Version: 1.0 To: djgpp-workers AT delorie DOT com Subject: Re: Use of FILE in sprintf/sscanf References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Hello. Esa A E Peuha wrote: > The sprintf and sscanf funcion families use FILE objects to point to > strings. However, there is no reason why these functions should know > what is inside FILE; the act of "opening" a string as file can be > abstracted as follows: [snip] > Index: src/libc/ansi/stdio/sprintf.c > =================================================================== > RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/sprintf.c,v > retrieving revision 1.4 > diff -c -r1.4 sprintf.c > *** src/libc/ansi/stdio/sprintf.c 8 Jun 2002 10:14:23 -0000 1.4 > --- src/libc/ansi/stdio/sprintf.c 5 Jan 2004 11:34:05 -0000 > *************** > *** 13,26 **** > FILE _strbuf; > int len; > > ! _strbuf._flag = _IOWRT|_IOSTRG|_IONTERM; > ! _strbuf._ptr = str; > ! _strbuf._cnt = INT_MAX; > ! > va_start(args, fmt); > len = _doprnt(fmt, args, &_strbuf); > va_end(args); > ! > ! *_strbuf._ptr = 0; > return len; > } > --- 13,22 ---- > FILE _strbuf; > int len; > > ! __sopenw(&_strbuf, str, INT_MAX); > va_start(args, fmt); > len = _doprnt(fmt, args, &_strbuf); > va_end(args); > ! str[len] = '\0'; What happens if _doprnt returns a negative number? > return len; > } [snip] Other than that, it looks fine to me. I'd prefer a slightly less cryptic name than "sopen", though - "stropen", "strbufopen"? Bye, Rich =] -- Richard Dawe [ http://homepages.nildram.co.uk/~phekda/richdawe/ ] "You can't evaluate a man by logic alone." -- McCoy, "I, Mudd", Star Trek