Changeset 0ca3729a in freewrt
- Timestamp:
- Mar 22, 2007, 4:31:51 AM (19 years ago)
- Children:
- 1650b64
- Parents:
- f9d3951
- File:
-
- 1 edited
-
tools/paxmirabilis/fgetln.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tools/paxmirabilis/fgetln.c
rf9d3951 r0ca3729a 2 2 3 3 /*- 4 * Copyright Holder: 4 * Copyright (c) 2007 5 * Thorsten Glaser <tg@mirbsd.de> 5 6 * 6 * The FreeBSD project. 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. 7 12 * 8 * License: 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted under the terms of the BSD License. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS `AS IS'' AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 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() 24 23 */ 25 24 25 #define _GNU_SOURCE /* for getline() */ 26 26 #include <sys/types.h> 27 #include <sys/cdefs.h>28 27 #include <stdio.h> 29 28 #include <string.h> 30 29 31 #ifdef __GLIBC__ 32 ssize_t getline(char **, size_t *, FILE *); 30 #ifdef __GLIBC__ /* FreeWRT: only build this where needed */ 33 31 char *fgetln(FILE *, size_t *); 34 32 … … 36 34 fgetln(FILE *stream, size_t *len) 37 35 { 38 char *l ine=NULL;39 size_t nread= 0;36 char *lb = NULL; 37 size_t lbsz = 0; 40 38 41 while (nread == 1) { 42 nread = getline (&line, len, stream); 43 if (nread == (size_t)-1) 44 return NULL; 45 } 46 47 (*len)--; /* get rid of the trailing \0, fgetln 48 does not have it */ 49 50 return line; 39 *len = getline(&lb, &lbsz, stream); 40 return ((*len == (size_t)-1) ? NULL : lb); 51 41 } 52 42 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
