Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/stdio/findfp.c,v retrieving revision 1.13.6.1 retrieving revision 1.13.6.2 diff -u -p -r1.13.6.1 -r1.13.6.2 --- src/lib/libc/stdio/findfp.c 2001/08/08 16:27:44 1.13.6.1 +++ src/lib/libc/stdio/findfp.c 2002/01/28 20:50:55 1.13.6.2 @@ -1,4 +1,4 @@ -/* $NetBSD: findfp.c,v 1.13.6.1 2001/08/08 16:27:44 nathanw Exp $ */ +/* $NetBSD: findfp.c,v 1.13.6.2 2002/01/28 20:50:55 nathanw Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)findfp.c 8.2 (Berkeley) 1/4/94"; #else -__RCSID("$NetBSD: findfp.c,v 1.13.6.1 2001/08/08 16:27:44 nathanw Exp $"); +__RCSID("$NetBSD: findfp.c,v 1.13.6.2 2002/01/28 20:50:55 nathanw Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -61,13 +61,18 @@ int __sdidinit; #define NDYNAMIC 10 /* add ten more whenever necessary */ #define std(flags, file) \ - {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite} -/* p r w flags file _bf z cookie close read seek write */ + {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite, \ + {(void*)(__sFext+file)}} +/* p r w flags file _bf z cookie close read seek write, + _ext */ /* the usual - (stdin + stdout + stderr) */ static FILE usual[FOPEN_MAX - 3]; +static struct __sfileext usualext[FOPEN_MAX - 3]; static struct glue uglue = { 0, FOPEN_MAX - 3, usual }; +struct __sfileext __sFext[3]; + FILE __sF[3] = { std(__SRD, STDIN_FILENO), /* stdin */ std(__SWR, STDOUT_FILENO), /* stdout */ @@ -88,17 +93,24 @@ moreglue(n) { struct glue *g; FILE *p; + struct __sfileext *pext; static FILE empty; - g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)); + g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE) + + n * sizeof(struct __sfileext)); if (g == NULL) return (NULL); p = (FILE *)ALIGN((u_long)(g + 1)); g->next = NULL; g->niobs = n; g->iobs = p; - while (--n >= 0) - *p++ = empty; + pext = (void *)(p + n); + while (--n >= 0) { + *p = empty; + _FILEEXT_SETUP(p, pext); + p++; + pext++; + } return (g); } @@ -135,10 +147,11 @@ found: fp->_lbfsize = 0; /* not line buffered */ fp->_file = -1; /* no file */ /* fp->_cookie = ; */ /* caller sets cookie, _read/_write etc */ - fp->_ub._base = NULL; /* no ungetc buffer */ - fp->_ub._size = 0; + _UB(fp)._base = NULL; /* no ungetc buffer */ + _UB(fp)._size = 0; fp->_lb._base = NULL; /* no line buffer */ fp->_lb._size = 0; + memset(WCIO_GET(fp), 0, sizeof(struct wchar_io_data)); rwlock_unlock(&__sfp_lock); return (fp); } @@ -180,6 +193,11 @@ _cleanup() void __sinit() { + int i; + + for (i = 0; i < FOPEN_MAX - 3; i++) + _FILEEXT_SETUP(&usual[i], &usualext[i]); + /* make sure we clean up on exit */ __cleanup = _cleanup; /* conservative */ __sdidinit = 1;