Article View: net.lang.c
Article #9272Re: Missing stdio features.
From: karl
Date: Mon, 08 Sep 1986 18:54
Date: Mon, 08 Sep 1986 18:54
40 lines
2110 bytes
2110 bytes
umcp-cs!chris (Chris Torek) writes:
>In article <86900034@haddock> karl@haddock writes:
>>>>FILE *fopenfxn(int (*fxn)(), char *mode)
>>Actually, the function argument should probably be analogous to read/write
>>rather than getc/putc. But there should be one more argument to fopenfxn(),
>>viz. a (void *) argument to be passed to fxn() to distinguish streams.
>
>Indeed, there would be a certain symmetry to the whole thing if one
>could write
> reader(f, buf, len) FILE *f; { return (read(fileno(f), buf, len)); }
> FILE *f = fopenrf(reader, "r");
> fileno(f) = fd;
>instead of
> FILE *f = fdopen(fd, "r");
As I mentioned, I think it has to be (void *) in general, thus
reader(void *v, char *buf, int len) {
return (read(*(int *)v, buf, len));
}
FILE *f = fopenrf(&fd, reader, "r");
so that the more general cases could be supported, e.g. read from string:
typedef struct { char *t_start, *t_end; } tbuf;
reader(void *v, char *buf, int len) {
register tbuf *t = (tbuf *)v;
len = min(len, t->t_end - t->t_start);
memcpy(buf, t->t_start, len);
t->start += len;
return (len);
}
FILE *f = fopenrf(&t, reader, "r");
You could get away with having the first arg to reader() be "FILE *", but in
any case "void *_id" needs to replace or supplement the existing "int _file"
in the FILE structure.
If there are separate functions fopenrf() and fopenwf(), is there any need
for the third argument?
Karl W. Z. Heuer (ima!haddock!karl; karl@haddock.isc.com), The Walking Lint
Technical Details
Message-ID:
<86900044@haddock>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!think!ima!haddock!karlReferences:
<3438@robin.cs.nott.ac.uk>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!think!ima!haddock!karl From: karl@haddock Newsgroups: net.lang.c Subject: Re: Missing stdio features. Message-ID: <86900044@haddock> Date: Mon, 8-Sep-86 14:54:00 EDT Article-I.D.: haddock.86900044 Posted: Mon Sep 8 14:54:00 1986 Date-Received: Mon, 8-Sep-86 20:51:57 EDT References: <3438@robin.cs.nott.ac.uk> Lines: 40 Nf-ID: #R:robin.cs.nott.ac.uk:3438:haddock:86900044:000:1545 Nf-From: haddock!karl Sep 8 14:54:00 1986