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