xref: /netbsd-src/lib/libc/stdio/fgetln.c (revision 555c77845c87d9da003293ebef8f491375415b21)
1*555c7784Suwe /*	$NetBSD: fgetln.c,v 1.17 2017/06/08 15:59:45 uwe Exp $	*/
2255db7b2Sjtc 
3a18790e6Scgd /*-
4a18790e6Scgd  * Copyright (c) 1990, 1993
5a18790e6Scgd  *	The Regents of the University of California.  All rights reserved.
6a18790e6Scgd  *
7a18790e6Scgd  * This code is derived from software contributed to Berkeley by
8a18790e6Scgd  * Chris Torek.
9a18790e6Scgd  *
10a18790e6Scgd  * Redistribution and use in source and binary forms, with or without
11a18790e6Scgd  * modification, are permitted provided that the following conditions
12a18790e6Scgd  * are met:
13a18790e6Scgd  * 1. Redistributions of source code must retain the above copyright
14a18790e6Scgd  *    notice, this list of conditions and the following disclaimer.
15a18790e6Scgd  * 2. Redistributions in binary form must reproduce the above copyright
16a18790e6Scgd  *    notice, this list of conditions and the following disclaimer in the
17a18790e6Scgd  *    documentation and/or other materials provided with the distribution.
18eb7c1594Sagc  * 3. Neither the name of the University nor the names of its contributors
19a18790e6Scgd  *    may be used to endorse or promote products derived from this software
20a18790e6Scgd  *    without specific prior written permission.
21a18790e6Scgd  *
22a18790e6Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23a18790e6Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24a18790e6Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25a18790e6Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26a18790e6Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27a18790e6Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28a18790e6Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29a18790e6Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30a18790e6Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31a18790e6Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32a18790e6Scgd  * SUCH DAMAGE.
33a18790e6Scgd  */
34a18790e6Scgd 
3523312f88Schristos #include <sys/cdefs.h>
36*555c7784Suwe __RCSID("$NetBSD: fgetln.c,v 1.17 2017/06/08 15:59:45 uwe Exp $");
37a18790e6Scgd 
3873ef151bSkleink #include "namespace.h"
39b48252f3Slukem 
40a18790e6Scgd #include <stdio.h>
41a18790e6Scgd 
42db594c65Sdrochner #include "reentrant.h"
43db594c65Sdrochner #include "local.h"
44db594c65Sdrochner 
4573ef151bSkleink #ifdef __weak_alias
__weak_alias(fgetln,_fgetln)4660549036Smycroft __weak_alias(fgetln,_fgetln)
4773ef151bSkleink #endif
4873ef151bSkleink 
49a18790e6Scgd /*
507cfa0468Sroy  * Get an input line.
517cfa0468Sroy  * This now uses getdelim(3) for a code reduction.
52*555c7784Suwe  * The upside is that strings are now always null-terminated, but relying
537cfa0468Sroy  * on this is non portable - better to use the POSIX getdelim(3) function.
54a18790e6Scgd  */
55a18790e6Scgd char *
567cfa0468Sroy fgetln(FILE *fp, size_t *lenp)
57a18790e6Scgd {
587cfa0468Sroy 	char *p;
59db594c65Sdrochner 
607cfa0468Sroy 	FLOCKFILE(fp);
617cfa0468Sroy 	p = __fgetstr(fp, lenp, '\n');
627cfa0468Sroy 	FUNLOCKFILE(fp);
637cfa0468Sroy 	return p;
64a18790e6Scgd }
65