binutils: allow static linking
[openadk.git] / package / toolbox / src / lib / fgetln.c
blob647cf9faa841ba867da536032b7dc03d09d823b9
1 /*-
2 * Copyright (c) 2007, 2009
3 * Thorsten Glaser <tg@mirbsd.org>
5 * Provided that these terms and disclaimer and all copyright notices
6 * are retained or reproduced in an accompanying document, permission
7 * is granted to deal in this work without restriction, including un-
8 * limited rights to use, publicly perform, distribute, sell, modify,
9 * merge, give away, or sublicence.
11 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
12 * the utmost extent permitted by applicable law, neither express nor
13 * implied; without malicious intent or gross negligence. In no event
14 * may a licensor, author or contributor be held liable for indirect,
15 * direct, other damage, loss, or other issues arising in any way out
16 * of dealing in the work, even if advised of the possibility of such
17 * damage or existence of a defect, except proven that it results out
18 * of said person's immediate fault when using the work as intended.
20 * fgetln() wrapper for operating systems with getline() – glibc
23 #undef _GNU_SOURCE
24 #define _GNU_SOURCE /* for getline() */
25 #include <sys/types.h>
26 #include <stdio.h>
27 #include <string.h>
29 __RCSID("$MirOS: contrib/code/mirmake/dist/contrib/fgetln.c,v 1.7 2014/12/20 22:23:29 tg Exp $");
31 char *fgetln(FILE *, size_t *);
33 char *
34 fgetln(FILE *stream, size_t *len)
36 static char *lb = NULL;
37 static size_t lbsz = 0;
39 if ((*len = getline(&lb, &lbsz, stream)) != (size_t)-1)
40 /* getdelim ensures *len is not 0 here */
41 return (lb);
43 /* not required by manpage, but reference implementation does this */
44 *len = 0;
46 /* not required to zero lb or lbsz: getdelim manages it */
47 return (NULL);