source: freewrt/tools/paxmirabilis/fgetln.c@ 3784d08

freewrt_1_0 freewrt_2_0
Last change on this file since 3784d08 was 08c8e8e, checked in by Thorsten Glaser <tg@…>, 16 years ago

sync with upstream (MirBSD), which gives us

  • improvements to fgetln(3) such as memory leak fixes and better congruence with other implementations even where not mandated by the API (manual page)
  • support for Mac OSX 10.6 Snow Leopard which removed the tape functions <sys/mtio.h> *even in a server operating system*
  • gcc warning fixes

git-svn-id: svn://www.freewrt.org/branches/freewrt_1_0@3882 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 1.7 KB
Line 
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)
35char *fgetln(FILE *, size_t *);
36#endif
37
38char *
39fgetln(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
Note: See TracBrowser for help on using the repository browser.