diff options
Diffstat (limited to 'lib/libc/stdio/findfp.c')
-rw-r--r-- | lib/libc/stdio/findfp.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c index 48eb5b5..e0f0e29 100644 --- a/lib/libc/stdio/findfp.c +++ b/lib/libc/stdio/findfp.c @@ -59,21 +59,24 @@ int __sdidinit; #define NDYNAMIC 10 /* add ten more whenever necessary */ -#define std(handle, flags, file) \ -FILE handle = {0,0,0,flags,file,{0},0,&handle,__sclose,__sread,__sseek,__swrite} -/* p r w flags file _bf z cookie close read seek write */ - +#define std(flags, file) \ + {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite, \ + {0}, __sFX + file} + /* p r w flags file _bf z cookie close read seek write */ + /* _ub _extra */ /* the usual - (stdin + stdout + stderr) */ static FILE usual[FOPEN_MAX - 3]; static struct glue uglue = { NULL, FOPEN_MAX - 3, usual }; -std(__stdin, __SRD, STDIN_FILENO); -std(__stdout, __SWR, STDOUT_FILENO); -std(__stderr, __SWR|__SNBF, STDERR_FILENO); +static struct __sFILEX __sFX[3]; + +FILE __sF[3] = { + std(__SRD, STDIN_FILENO), + std(__SWR, STDOUT_FILENO), + std(__SWR|__SNBF, STDERR_FILENO) +}; -static struct glue sglue2 = { &uglue, 1, &__stderr }; -static struct glue sglue1 = { &sglue2, 1, &__stdout }; -struct glue __sglue = { &sglue1, 1, &__stdin }; +struct glue __sglue = { &uglue, 3, __sF }; static struct glue *lastglue = &uglue; static struct glue * moreglue __P((int)); @@ -93,18 +96,26 @@ moreglue(n) int n; { struct glue *g; - FILE *p; static FILE empty; + static struct __sFILEX emptyx; + FILE *p; + struct __sFILEX *fx; - g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)); + g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE) + + n * sizeof(struct __sFILEX)); if (g == NULL) return (NULL); p = (FILE *)ALIGN(g + 1); + fx = (struct __sFILEX *)&p[n]; g->next = NULL; g->niobs = n; g->iobs = p; - while (--n >= 0) - *p++ = empty; + while (--n >= 0) { + *p = empty; + p->_extra = fx; + *p->_extra = emptyx; + p++, fx++; + } return (g); } |