Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: snprintf alternatives in iso9899 Date: Wed, 09 Dec 2015 14:49:03 -0800 Organization: None to speak of Lines: 54 Message-ID: References: <87lh956li9.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="10480"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+R794piMXhnucREXJw80nh" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:j59sqawfp33mQGOzf7jZ+EgaloU= sha1:ZI7edt/bW58PEJJl0xpEeNbrFI8= Xref: csiph.com comp.lang.c:78308 Eric Sosman writes: > On 12/9/2015 4:14 PM, Tim Rentsch wrote: >> supercat@casperkitty.com writes: >> >>> On Tuesday, December 8, 2015 at 8:52:31 AM UTC-6, Ben Bacarisse wrote: >>>> snprintf was implemented "in the wild" before standardisation, so some >>>> pre-C99 systems had it. You could just assume C90+snprintf. >>> >>> It's too bad there's no standard for a general-purpose printf >>> which takes a pointer to a structure with one or two function >>> pointers and a void*, and uses one of the passed-in functions for >>> output (passing the void* to the function, which can then use it >>> as it sees fit). [...] >> >> If the lack bothers you, why don't you write one? I did. > > It seems to me that a more flexible and powerful approach would > be to implement such things at the FILE* level. It's easy to imagine > things along the lines of > > FILE *stream = fopen("http://www.c-faq.com/", "r"); The string "http://www.c-faq.com/" could *also* be a valid local file name. On a POSIX system, there could be a directory named "http:" with a subdirectory name "www.c-faq.com". The trailing "/" means that the whole thing refers to a directory, but "http://www.c-faq.com/index.html" could be an ordinary file. You could set up a "/url" directory, for example, so a file name like "/url/http://www.c-faq.com/" would unambiguously refer to that URL. I haven't heard of anyone actually doing that. The POSIX popen() function, along with a command like "curl", can do pretty much the same thing. One issue is that the things URLs refer to only partially act like files. > ... and it wouldn't be a huge departure to offer something like > > FILE *funcopen(int (*)reader(void*), int (*)writer(void*), > void *userarg); > FILE *stream = funcopen(NULL, mywriter, buffptr); > > Something in this vein would be, I think, superior to running around > endlessly adding capabilities to printf(), scanf(), fseek(), ... There's the GNU-specific fopencookie(). -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"