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.)
This commit is contained in:
parent
ff5de51147
commit
db594c6591
@ -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
|
||||
|
@ -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 @@ __RCSID("$NetBSD: fgetln.c,v 1.13 2004/04/21 00:01:57 christos Exp $");
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "reentrant.h"
|
||||
#include "local.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(fgetln,_fgetln)
|
||||
#endif
|
||||
@ -61,5 +64,10 @@ fgetln(fp, lenp)
|
||||
FILE *fp;
|
||||
size_t *lenp;
|
||||
{
|
||||
return fgetstr(fp, lenp, '\n');
|
||||
char *cp;
|
||||
|
||||
FLOCKFILE(fp);
|
||||
cp = __fgetstr(fp, lenp, '\n');
|
||||
FUNLOCKFILE(fp);
|
||||
return cp;
|
||||
}
|
||||
|
@ -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 @@ __RCSID("$NetBSD: fgetstr.c,v 1.1 2004/04/21 00:01:57 christos Exp $");
|
||||
#include "reentrant.h"
|
||||
#include "local.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(fgetstr,_fgetstr)
|
||||
#endif
|
||||
|
||||
int __slbexpand __P((FILE *, size_t));
|
||||
|
||||
/*
|
||||
@ -92,7 +88,7 @@ __slbexpand(fp, newsize)
|
||||
* 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 @@ fgetstr(fp, lenp, sep)
|
||||
_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 @@ fgetstr(fp, lenp, sep)
|
||||
fp->_flags |= __SMOD;
|
||||
fp->_r -= len;
|
||||
fp->_p = p;
|
||||
FUNLOCKFILE(fp);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
@ -176,11 +168,9 @@ fgetstr(fp, lenp, sep)
|
||||
#ifdef notdef
|
||||
fp->_lb._base[len] = 0;
|
||||
#endif
|
||||
FUNLOCKFILE(fp);
|
||||
return ((char *)fp->_lb._base);
|
||||
|
||||
error:
|
||||
*lenp = 0; /* ??? */
|
||||
FUNLOCKFILE(fp);
|
||||
return (NULL); /* ??? */
|
||||
}
|
||||
|
@ -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 int __gettemp __P((char *, int *, int));
|
||||
|
||||
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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user