diff options
Diffstat (limited to 'pkgtools/libnbcompat/files/fgetln.c')
-rw-r--r-- | pkgtools/libnbcompat/files/fgetln.c | 43 |
1 files changed, 8 insertions, 35 deletions
diff --git a/pkgtools/libnbcompat/files/fgetln.c b/pkgtools/libnbcompat/files/fgetln.c index df829dd46ac..d5a465f1208 100644 --- a/pkgtools/libnbcompat/files/fgetln.c +++ b/pkgtools/libnbcompat/files/fgetln.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgetln.c,v 1.2 2004/08/23 03:32:12 jlam Exp $ */ +/* $NetBSD: fgetln.c,v 1.3 2004/09/11 19:01:40 jlam Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -37,39 +37,9 @@ */ #include <nbcompat.h> -#include <nbcompat/cdefs.h> -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fgetline.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: fgetln.c,v 1.2 2004/08/23 03:32:12 jlam Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#if 0 -#include "namespace.h" -#endif - #include <nbcompat/stdio.h> +#include <nbcompat/stdlib.h> -#if 0 -#include "reentrant.h" -#include "local.h" -#endif - -#if 0 -#ifdef __weak_alias -__weak_alias(fgetln,_fgetln) -#endif -#endif - -/* - * Get an input line. The returned pointer often (but not always) - * points into a stdio buffer. Fgetline does not alter the text of - * the returned line (which is thus not a C string because it will - * not necessarily end with '\0'), but does allow callers to modify - * it if they wish. Thus, we set __SMOD in case the caller does. - */ char * fgetln(fp, len) FILE *fp; @@ -79,7 +49,6 @@ fgetln(fp, len) static size_t bufsiz = 0; char *ptr; - if (buf == NULL) { bufsiz = BUFSIZ; if ((buf = malloc(bufsiz)) == NULL) @@ -103,8 +72,12 @@ fgetln(fp, len) } else buf = nbuf; - *len = bufsiz; - if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) + /* + * We need to overwrite the '\0' written by the last call + * to fgets(). + */ + *len = bufsiz - 1; + if (fgets(&buf[bufsiz - 1], BUFSIZ + 1, fp) == NULL) return buf; bufsiz = nbufsiz; |