Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src - make FILE structure extensible without breaking binary-com...



details:   https://anonhg.NetBSD.org/src/rev/cadb922c8a21
branches:  trunk
changeset: 518890:cadb922c8a21
user:      yamt <yamt%NetBSD.org@localhost>
date:      Fri Dec 07 11:47:40 2001 +0000

description:
- make FILE structure extensible without breaking binary-compatibility.
- add fputwc, fgetwc, fwide and related functions.
- add hooks needed to maintain the orientation of file stream.

diffstat:

 include/stdio.h             |    6 +-
 include/wchar.h             |   19 ++++++-
 lib/libc/stdio/Makefile.inc |   11 +++-
 lib/libc/stdio/asprintf.c   |    7 +-
 lib/libc/stdio/fclose.c     |    6 +-
 lib/libc/stdio/fgets.c      |    5 +-
 lib/libc/stdio/fgetwc.c     |   89 ++++++++++++++++++++++++++++++++++
 lib/libc/stdio/findfp.c     |   36 ++++++++++---
 lib/libc/stdio/fpurge.c     |    6 +-
 lib/libc/stdio/fputs.c      |    6 +-
 lib/libc/stdio/fputwc.c     |   87 +++++++++++++++++++++++++++++++++
 lib/libc/stdio/freopen.c    |    8 +-
 lib/libc/stdio/fwide.3      |   84 ++++++++++++++++++++++++++++++++
 lib/libc/stdio/fwide.c      |   67 +++++++++++++++++++++++++
 lib/libc/stdio/getwc.3      |  115 ++++++++++++++++++++++++++++++++++++++++++++
 lib/libc/stdio/getwc.c      |   44 ++++++++++++++++
 lib/libc/stdio/getwchar.c   |   44 ++++++++++++++++
 lib/libc/stdio/local.h      |   14 +++-
 lib/libc/stdio/putwc.3      |  104 +++++++++++++++++++++++++++++++++++++++
 lib/libc/stdio/putwc.c      |   44 ++++++++++++++++
 lib/libc/stdio/putwchar.c   |   44 ++++++++++++++++
 lib/libc/stdio/rget.c       |    5 +-
 lib/libc/stdio/setvbuf.c    |    6 +-
 lib/libc/stdio/snprintf.c   |    7 +-
 lib/libc/stdio/sprintf.c    |    6 +-
 lib/libc/stdio/sscanf.c     |    8 +-
 lib/libc/stdio/stdio.3      |   10 +++-
 lib/libc/stdio/ungetc.c     |   25 ++++----
 lib/libc/stdio/ungetwc.3    |  101 ++++++++++++++++++++++++++++++++++++++
 lib/libc/stdio/ungetwc.c    |   73 +++++++++++++++++++++++++++
 lib/libc/stdio/vasprintf.c  |    7 +-
 lib/libc/stdio/vfprintf.c   |    8 ++-
 lib/libc/stdio/vfscanf.c    |    5 +-
 lib/libc/stdio/vsnprintf.c  |    7 +-
 lib/libc/stdio/vsprintf.c   |    7 +-
 lib/libc/stdio/vsscanf.c    |    9 ++-
 lib/libc/stdio/wbuf.c       |    6 +-
 37 files changed, 1064 insertions(+), 72 deletions(-)

diffs (truncated from 1955 to 300 lines):

diff -r 556c7b5f2e98 -r cadb922c8a21 include/stdio.h
--- a/include/stdio.h   Fri Dec 07 11:26:30 2001 +0000
+++ b/include/stdio.h   Fri Dec 07 11:47:40 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stdio.h,v 1.41 2000/12/29 15:22:48 kleink Exp $        */
+/*     $NetBSD: stdio.h,v 1.42 2001/12/07 11:47:40 yamt Exp $  */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -123,8 +123,10 @@
        fpos_t  (*_seek)  __P((void *, fpos_t, int));
        int     (*_write) __P((void *, const char *, int));
 
+       /* file extension */
+       struct  __sbuf _ext;
+
        /* separate buffer for long sequences of ungetc() */
-       struct  __sbuf _ub;     /* ungetc buffer */
        unsigned char *_up;     /* saved _p when _p is doing ungetc data */
        int     _ur;            /* saved _r when _r is counting ungetc data */
 
diff -r 556c7b5f2e98 -r cadb922c8a21 include/wchar.h
--- a/include/wchar.h   Fri Dec 07 11:26:30 2001 +0000
+++ b/include/wchar.h   Fri Dec 07 11:47:40 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wchar.h,v 1.10 2001/09/27 16:30:35 yamt Exp $  */
+/*     $NetBSD: wchar.h,v 1.11 2001/12/07 11:47:40 yamt Exp $  */
 
 /*-
  * Copyright (c)1999 Citrus Project,
@@ -69,6 +69,8 @@
 #include <machine/ansi.h>
 #include <sys/null.h>
 
+#include <stdio.h> /* for FILE* */
+
 #ifdef _BSD_WCHAR_T_
 typedef        _BSD_WCHAR_T_   wchar_t;
 #undef _BSD_WCHAR_T_
@@ -93,6 +95,11 @@
 #define        WEOF    ((wint_t)-1)
 #endif
 
+#define getwc(f) fgetwc(f)
+#define getwchar() getwc(stdin)
+#define putwc(wc, f) fputwc((wc), (f))
+#define putwchar(wc) putwc((wc), stdout)
+
 __BEGIN_DECLS
 size_t mbrlen __P((const char * __restrict, size_t, mbstate_t * __restrict));
 size_t mbrtowc __P((wchar_t * __restrict, const char * __restrict, size_t,
@@ -134,6 +141,16 @@
                int base));
 long int wcstol __P((const wchar_t * __restrict, wchar_t ** __restrict, int base));
 double wcstod __P((const wchar_t * __restrict, wchar_t ** __restrict));
+
+wint_t ungetwc __P((wint_t, FILE *));
+wint_t fgetwc __P((FILE *));
+wint_t getwc __P((FILE *));
+wint_t getwchar __P((void));
+wint_t fputwc __P((wint_t, FILE *));
+wint_t putwc __P((wint_t, FILE *));
+wint_t putwchar __P((wint_t));
+
+int fwide __P((FILE *, int));
 __END_DECLS
 
 #endif /* !_WCHAR_H_ */
diff -r 556c7b5f2e98 -r cadb922c8a21 lib/libc/stdio/Makefile.inc
--- a/lib/libc/stdio/Makefile.inc       Fri Dec 07 11:26:30 2001 +0000
+++ b/lib/libc/stdio/Makefile.inc       Fri Dec 07 11:47:40 2001 +0000
@@ -1,5 +1,5 @@
 #      from: @(#)Makefile.inc  5.7 (Berkeley) 6/27/91
-#      $NetBSD: Makefile.inc,v 1.20 2001/04/25 22:06:53 kleink Exp $
+#      $NetBSD: Makefile.inc,v 1.21 2001/12/07 11:47:41 yamt Exp $
 
 # stdio sources
 .PATH: ${.CURDIR}/stdio
@@ -15,7 +15,9 @@
        puts.c putw.c refill.c remove.c rewind.c rget.c scanf.c setbuf.c \
        setbuffer.c setvbuf.c snprintf.c sscanf.c stdio.c tmpfile.c \
        ungetc.c vasprintf.c vfprintf.c vfscanf.c vprintf.c vscanf.c \
-       vsnprintf.c vsscanf.c wbuf.c wsetup.c
+       vsnprintf.c vsscanf.c wbuf.c wsetup.c fputwc.c \
+       fgetwc.c ungetwc.c putwc.c putwchar.c getwc.c getwchar.c \
+       fwide.c
 
 .if !defined(AUDIT)
 SRCS+= gets.c sprintf.c vsprintf.c tempnam.c tmpnam.c mktemp.c
@@ -26,7 +28,8 @@
 
 MAN+=  fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fopen.3 fputs.3 \
        fread.3 fseek.3 funopen.3 getc.3 mktemp.3 perror.3 printf.3 putc.3 \
-       remove.3 scanf.3 setbuf.3 stdio.3 tmpnam.3 ungetc.3
+       remove.3 scanf.3 setbuf.3 stdio.3 tmpnam.3 ungetc.3 putwc.3 getwc.3 \
+       ungetwc.3 fwide.3
 
 MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
 MLINKS+=fflush.3 fpurge.3
@@ -49,3 +52,5 @@
        scanf.3 vsscanf.3
 MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3
 MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3
+MLINKS+=putwc.3 fputwc.3 putwc.3 putwchar.3
+MLINKS+=getwc.3 fgetwc.3 getwc.3 getwchar.3
diff -r 556c7b5f2e98 -r cadb922c8a21 lib/libc/stdio/asprintf.c
--- a/lib/libc/stdio/asprintf.c Fri Dec 07 11:26:30 2001 +0000
+++ b/lib/libc/stdio/asprintf.c Fri Dec 07 11:47:40 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: asprintf.c,v 1.9 2001/09/24 13:22:30 wiz Exp $ */
+/*     $NetBSD: asprintf.c,v 1.10 2001/12/07 11:47:41 yamt Exp $       */
 
 /*
  * Copyright (c) 1997 Todd C. Miller <Todd.Miller%courtesan.com@localhost>
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: asprintf.c,v 1.9 2001/09/24 13:22:30 wiz Exp $");
+__RCSID("$NetBSD: asprintf.c,v 1.10 2001/12/07 11:47:41 yamt Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -42,6 +42,7 @@
 #else
 #include <varargs.h>
 #endif
+#include "local.h"
 
 #ifdef __weak_alias
 __weak_alias(asprintf, _asprintf)
@@ -60,10 +61,12 @@
        int ret;
        va_list ap;
        FILE f;
+       struct __sfileext fext;
        unsigned char *_base;
 
        _DIAGASSERT(str != NULL);
 
+       _FILEEXT_SETUP(&f, &fext);
        f._file = -1;
        f._flags = __SWR | __SSTR | __SALC;
        f._bf._base = f._p = (unsigned char *)malloc(128);
diff -r 556c7b5f2e98 -r cadb922c8a21 lib/libc/stdio/fclose.c
--- a/lib/libc/stdio/fclose.c   Fri Dec 07 11:26:30 2001 +0000
+++ b/lib/libc/stdio/fclose.c   Fri Dec 07 11:47:40 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fclose.c,v 1.13 2000/01/21 19:53:02 mycroft Exp $      */
+/*     $NetBSD: fclose.c,v 1.14 2001/12/07 11:47:41 yamt Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -41,13 +41,14 @@
 #if 0
 static char sccsid[] = "@(#)fclose.c   8.1 (Berkeley) 6/4/93";
 #endif
-__RCSID("$NetBSD: fclose.c,v 1.13 2000/01/21 19:53:02 mycroft Exp $");
+__RCSID("$NetBSD: fclose.c,v 1.14 2001/12/07 11:47:41 yamt Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include <assert.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <wchar.h>
 #include "local.h"
 #include "reentrant.h"
 
@@ -64,6 +65,7 @@
                return (EOF);
        }
        FLOCKFILE(fp);
+       WCIO_FREE(fp);
        r = fp->_flags & __SWR ? __sflush(fp) : 0;
        if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0)
                r = EOF;
diff -r 556c7b5f2e98 -r cadb922c8a21 lib/libc/stdio/fgets.c
--- a/lib/libc/stdio/fgets.c    Fri Dec 07 11:26:30 2001 +0000
+++ b/lib/libc/stdio/fgets.c    Fri Dec 07 11:47:40 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fgets.c,v 1.13 1999/11/14 18:19:57 explorer Exp $      */
+/*     $NetBSD: fgets.c,v 1.14 2001/12/07 11:47:41 yamt Exp $  */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)fgets.c    8.2 (Berkeley) 12/22/93";
 #else
-__RCSID("$NetBSD: fgets.c,v 1.13 1999/11/14 18:19:57 explorer Exp $");
+__RCSID("$NetBSD: fgets.c,v 1.14 2001/12/07 11:47:41 yamt Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -72,6 +72,7 @@
                return (NULL);
 
        FLOCKFILE(fp);
+       _SET_ORIENTATION(fp, -1);
        s = buf;
        n--;                    /* leave space for NUL */
        while (n != 0) {
diff -r 556c7b5f2e98 -r cadb922c8a21 lib/libc/stdio/fgetwc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/stdio/fgetwc.c   Fri Dec 07 11:47:40 2001 +0000
@@ -0,0 +1,89 @@
+/* $NetBSD: fgetwc.c,v 1.1 2001/12/07 11:47:41 yamt Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <wchar.h>
+#include "local.h"
+#include "reentrant.h"
+
+wint_t
+fgetwc(FILE *fp)
+{
+       struct wchar_io_data *wcio;
+       mbstate_t *st;
+       wchar_t wc;
+       size_t size;
+
+       _DIAGASSERT(fp != NULL);
+
+       FLOCKFILE(fp);
+       _SET_ORIENTATION(fp, 1);
+       wcio = WCIO_GET(fp);
+       if (wcio == 0) {
+               FUNLOCKFILE(fp);
+               errno = ENOMEM;
+               return WEOF;
+       }
+
+       /* if there're ungetwc'ed wchars, use them */
+       if (wcio->wcio_ungetwc_inbuf) {
+               wc = wcio->wcio_ungetwc_buf[--wcio->wcio_ungetwc_inbuf];
+               FUNLOCKFILE(fp);
+
+               return wc;
+       }
+
+       st = &wcio->wcio_mbstate_in;
+
+       do {
+               char c;
+               int ch = __sgetc(fp);
+
+               if (ch == EOF) {
+                       FUNLOCKFILE(fp);
+                       return WEOF;
+               }
+
+               c = ch;
+               size = mbrtowc(&wc, &c, 1, st);
+               if (size == (size_t)-1) {
+                       FUNLOCKFILE(fp);
+                       errno = EILSEQ;
+                       return WEOF;
+               }
+       } while (size == (size_t)-2);
+       FUNLOCKFILE(fp);
+
+       _DIAGASSERT(size == 1);
+
+       return wc;
+}
diff -r 556c7b5f2e98 -r cadb922c8a21 lib/libc/stdio/findfp.c
--- a/lib/libc/stdio/findfp.c   Fri Dec 07 11:26:30 2001 +0000
+++ b/lib/libc/stdio/findfp.c   Fri Dec 07 11:47:40 2001 +0000
@@ -1,4 +1,4 @@



Home | Main Index | Thread Index | Old Index