In message <
[email protected]>
LibraryUser said:
This problem is why your query is off-topic on c.l.c. Sockets,
particular compilers and operating systems are not mentioned in
the C standard, and thus such things are inherently non-portable.
For God's sake, his query wasn't in the slightest off-topic. His original
question didn't involve sockets, compilers or operating systems. What's wrong
with you people? Have you just programmed some sort of automated script
to say every single query is off-topic if certain keywords occur in a thread?
Is it a sin to explain WHY he wants to do something, and what the background
to the query is? If he didn't people would just ask why anyway.
His original query was "how can I treat an array as a file". Last time I
checked, C was advanced enough to include both of those two hip new computing
concepts, so it shouldn't be too much of a heinous crime to ask in
comp.lang.c whether they can be interworked.
The answer is, unfortunately, there is no portable way of doing this in ISO C
(so by merely asking whether there was, you are automatically off-topic, and
I'm probably off-topic by telling you there isn't).
This is odd, as most implementations of the stdio library probably do this
internally to implement sprintf(); it's natural and easy given the buffering
requirements of stdio. It would make sense to expose this internal working
portably via some sort of
FILE *fmemopen(void *ptr, size_t len, const char *mode);
sprintf() could then be implemented as
int sprintf(char *buf, const char *fmt, ...)
{
FILE *f = fmemopen(buf, SIZE_MAX, "w");
va_list ap = va_start(ap, fmt);
int result = vfprintf(f, fmt, ap);
va_end(ap);
fclose(f);
}
Maybe the original poster would like to propose this as an addition to
<stdio.h> in comp.std.c.
As ISO C doesn't (yet) provide what you're looking for, your next port of
call should probably be a POSIX newsgroup to see if you can find a
POSIX-standard method, maybe involving connecting to the s*cket directly, and
then beyond that platform-specific newsgroups.
Chuck Falconer, on vacation.
Some vacation, sitting in a library telling poor innocents asking sensible
questions that they're off-topic. I suggest you take a vacation from your
vacation. Seriously.