Mail Archives: djgpp-workers/2004/01/05/18:08:43
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
- Raw text -