2017-06-08 18:59:45 +03:00
|
|
|
/* $NetBSD: fgetln.c,v 1.17 2017/06/08 15:59:45 uwe Exp $ */
|
1995-02-02 05:09:03 +03:00
|
|
|
|
1994-01-04 08:13:16 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Chris Torek.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 20:42:00 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-01-04 08:13:16 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*/
|
|
|
|
|
1997-07-14 00:14:49 +04:00
|
|
|
#include <sys/cdefs.h>
|
2017-06-08 18:59:45 +03:00
|
|
|
__RCSID("$NetBSD: fgetln.c,v 1.17 2017/06/08 15:59:45 uwe Exp $");
|
1994-01-04 08:13:16 +03:00
|
|
|
|
1998-10-16 16:39:54 +04:00
|
|
|
#include "namespace.h"
|
1999-09-16 15:44:54 +04:00
|
|
|
|
1994-01-04 08:13:16 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-05-10 20:47:11 +04:00
|
|
|
#include "reentrant.h"
|
|
|
|
#include "local.h"
|
|
|
|
|
1998-10-16 16:39:54 +04:00
|
|
|
#ifdef __weak_alias
|
2000-01-23 01:19:07 +03:00
|
|
|
__weak_alias(fgetln,_fgetln)
|
1998-10-16 16:39:54 +04:00
|
|
|
#endif
|
|
|
|
|
1994-01-04 08:13:16 +03:00
|
|
|
/*
|
2009-12-02 12:03:13 +03:00
|
|
|
* Get an input line.
|
|
|
|
* This now uses getdelim(3) for a code reduction.
|
2017-06-08 18:59:45 +03:00
|
|
|
* The upside is that strings are now always null-terminated, but relying
|
2009-12-02 12:03:13 +03:00
|
|
|
* on this is non portable - better to use the POSIX getdelim(3) function.
|
1994-01-04 08:13:16 +03:00
|
|
|
*/
|
|
|
|
char *
|
2009-12-02 12:03:13 +03:00
|
|
|
fgetln(FILE *fp, size_t *lenp)
|
1994-01-04 08:13:16 +03:00
|
|
|
{
|
2009-12-02 12:03:13 +03:00
|
|
|
char *p;
|
2009-09-25 00:38:53 +04:00
|
|
|
|
2009-12-02 12:03:13 +03:00
|
|
|
FLOCKFILE(fp);
|
|
|
|
p = __fgetstr(fp, lenp, '\n');
|
|
|
|
FUNLOCKFILE(fp);
|
|
|
|
return p;
|
1994-01-04 08:13:16 +03:00
|
|
|
}
|