Source-Changes-HG archive

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

[src/trunk]: src/lib/libc After discussion with christos, turn fgetstr() into...



details:   https://anonhg.NetBSD.org/src/rev/e110f08a47de
branches:  trunk
changeset: 566477:e110f08a47de
user:      drochner <drochner%NetBSD.org@localhost>
date:      Mon May 10 16:47:11 2004 +0000

description:
After discussion with christos, turn fgetstr() into an internal function.
Its API in inherently non-threadsafe (and it depends on certain properties
of the underlying stdio implementation), so it shouldn't be a first-class
function for general use, polluting the application namespace.
Also remove the FLOCKFILE() code from it - this is under control of the
calling function now.
(XXX I'm not sure whether the FLOCKFILE() should be kept in fgetln(),
this function cannot be used in multiple threads anyway. It doesn't
hurt much, and it might prevent corruption of internal FILE structures.)

diffstat:

 lib/libc/include/namespace.h |   3 +--
 lib/libc/stdio/fgetln.c      |  14 +++++++++++---
 lib/libc/stdio/fgetstr.c     |  16 +++-------------
 lib/libc/stdio/local.h       |   5 ++++-
 4 files changed, 19 insertions(+), 19 deletions(-)

diffs (147 lines):

diff -r aa58c2fed011 -r e110f08a47de lib/libc/include/namespace.h
--- a/lib/libc/include/namespace.h      Mon May 10 15:25:57 2004 +0000
+++ b/lib/libc/include/namespace.h      Mon May 10 16:47:11 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: namespace.h,v 1.88 2004/05/09 17:27:53 kleink Exp $    */
+/*     $NetBSD: namespace.h,v 1.89 2004/05/10 16:47:11 drochner Exp $  */
 
 /*-
  * Copyright (c) 1997-2002 The NetBSD Foundation, Inc.
@@ -188,7 +188,6 @@
 #define execvp                 _execvp
 #define fdopen                 _fdopen
 #define fgetln                 _fgetln
-#define fgetstr                        _fgetstr
 #define flockfile              _flockfile
 #define ftrylockfile           _ftrylockfile
 #define funlockfile            _funlockfile
diff -r aa58c2fed011 -r e110f08a47de lib/libc/stdio/fgetln.c
--- a/lib/libc/stdio/fgetln.c   Mon May 10 15:25:57 2004 +0000
+++ b/lib/libc/stdio/fgetln.c   Mon May 10 16:47:11 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fgetln.c,v 1.13 2004/04/21 00:01:57 christos Exp $     */
+/*     $NetBSD: fgetln.c,v 1.14 2004/05/10 16:47:11 drochner Exp $     */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)fgetline.c 8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: fgetln.c,v 1.13 2004/04/21 00:01:57 christos Exp $");
+__RCSID("$NetBSD: fgetln.c,v 1.14 2004/05/10 16:47:11 drochner Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -45,6 +45,9 @@
 
 #include <stdio.h>
 
+#include "reentrant.h"
+#include "local.h"
+
 #ifdef __weak_alias
 __weak_alias(fgetln,_fgetln)
 #endif
@@ -61,5 +64,10 @@
        FILE *fp;
        size_t *lenp;
 {
-       return fgetstr(fp, lenp, '\n');
+       char *cp;
+
+       FLOCKFILE(fp);
+       cp = __fgetstr(fp, lenp, '\n');
+       FUNLOCKFILE(fp);
+       return cp;
 }
diff -r aa58c2fed011 -r e110f08a47de lib/libc/stdio/fgetstr.c
--- a/lib/libc/stdio/fgetstr.c  Mon May 10 15:25:57 2004 +0000
+++ b/lib/libc/stdio/fgetstr.c  Mon May 10 16:47:11 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fgetstr.c,v 1.1 2004/04/21 00:01:57 christos Exp $     */
+/*     $NetBSD: fgetstr.c,v 1.2 2004/05/10 16:47:11 drochner Exp $     */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)fgetline.c 8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: fgetstr.c,v 1.1 2004/04/21 00:01:57 christos Exp $");
+__RCSID("$NetBSD: fgetstr.c,v 1.2 2004/05/10 16:47:11 drochner Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -50,10 +50,6 @@
 #include "reentrant.h"
 #include "local.h"
 
-#ifdef __weak_alias
-__weak_alias(fgetstr,_fgetstr)
-#endif
-
 int __slbexpand __P((FILE *, size_t));
 
 /*
@@ -92,7 +88,7 @@
  * it if they wish.  Thus, we set __SMOD in case the caller does.
  */
 char *
-fgetstr(fp, lenp, sep)
+__fgetstr(fp, lenp, sep)
        FILE *fp;
        size_t *lenp;
        int sep;
@@ -104,12 +100,9 @@
        _DIAGASSERT(fp != NULL);
        _DIAGASSERT(lenp != NULL);
 
-       FLOCKFILE(fp);
-
        /* make sure there is input */
        if (fp->_r <= 0 && __srefill(fp)) {
                *lenp = 0;
-               FUNLOCKFILE(fp);
                return (NULL);
        }
 
@@ -128,7 +121,6 @@
                fp->_flags |= __SMOD;
                fp->_r -= len;
                fp->_p = p;
-               FUNLOCKFILE(fp);
                return (ret);
        }
 
@@ -176,11 +168,9 @@
 #ifdef notdef
        fp->_lb._base[len] = 0;
 #endif
-       FUNLOCKFILE(fp);
        return ((char *)fp->_lb._base);
 
 error:
        *lenp = 0;              /* ??? */
-       FUNLOCKFILE(fp);
        return (NULL);          /* ??? */
 }
diff -r aa58c2fed011 -r e110f08a47de lib/libc/stdio/local.h
--- a/lib/libc/stdio/local.h    Mon May 10 15:25:57 2004 +0000
+++ b/lib/libc/stdio/local.h    Mon May 10 16:47:11 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: local.h,v 1.17 2003/08/07 16:43:27 agc Exp $   */
+/*     $NetBSD: local.h,v 1.18 2004/05/10 16:47:11 drochner Exp $      */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -71,6 +71,9 @@
 
 extern wint_t  __fgetwc_unlock __P((FILE *));
 extern wint_t  __fputwc_unlock __P((wchar_t, FILE *));
+
+extern char    *__fgetstr __P((FILE * __restrict, size_t * __restrict, int));
+
 /*
  * Return true iff the given FILE cannot be written now.
  */



Home | Main Index | Thread Index | Old Index