File: fgetln.c

package info (click to toggle)
mg 20070918-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 664 kB
  • ctags: 892
  • sloc: ansic: 12,205; sh: 148; makefile: 81; modula3: 7
file content (42 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* $FreeWRT$ */

/*-
 * Copyright (c) 2007
 *	Thorsten Glaser <tg@mirbsd.de>
 *
 * Provided that these terms and disclaimer and all copyright notices
 * are retained or reproduced in an accompanying document, permission
 * is granted to deal in this work without restriction, including un-
 * limited rights to use, publicly perform, distribute, sell, modify,
 * merge, give away, or sublicence.
 *
 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
 * the utmost extent permitted by applicable law, neither express nor
 * implied; without malicious intent or gross negligence. In no event
 * may a licensor, author or contributor be held liable for indirect,
 * direct, other damage, loss, or other issues arising in any way out
 * of dealing in the work, even if advised of the possibility of such
 * damage or existence of a defect, except proven that it results out
 * of said person's immediate fault when using the work as intended.
 *-
 * fgetln() wrapper for operating systems with getline()
 */

#define _GNU_SOURCE		/* for getline() */
#include <sys/types.h>
#include <stdio.h>
#include <string.h>

#ifdef __GLIBC__		/* FreeWRT: only build this where needed */
char *fgetln(FILE *, size_t *);

char *
fgetln(FILE *stream, size_t *len)
{
	char *lb = NULL;
	size_t lbsz = 0;

	*len = getline(&lb, &lbsz, stream);
	return ((*len == (size_t)-1) ? NULL : lb);
}
#endif