Changeset 0ca3729a in freewrt


Ignore:
Timestamp:
Mar 22, 2007, 4:31:51 AM (19 years ago)
Author:
Thorsten Glaser <tg@…>
Children:
1650b64
Parents:
f9d3951
Message:

I originally intended to “just fix” the _GNU_SOURCE vs declaration stuff
when I pointed this file's existence out to Han Boetes, who is currently
porting BSD grep to Crux GNU/Linux, but found out this code is crazy and
can't ever have worked correctly.

This is a re-implementation directly from the specs – getline(3) manpage
from Debian (etch) testing, fgetln(3) manpage from MirOS #10-beta

git-svn-id: svn://www.freewrt.org/trunk/freewrt@2229 afb5a338-a214-0410-bd46-81f09a774fd1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/paxmirabilis/fgetln.c

    rf9d3951 r0ca3729a  
    22
    33/*-
    4  * Copyright Holder:
     4 * Copyright (c) 2007
     5 *      Thorsten Glaser <tg@mirbsd.de>
    56 *
    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.
    712 *
    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()
    2423 */
    2524
     25#define _GNU_SOURCE             /* for getline() */
    2626#include <sys/types.h>
    27 #include <sys/cdefs.h>
    2827#include <stdio.h>
    2928#include <string.h>
    3029
    31 #ifdef __GLIBC__
    32 ssize_t getline(char **, size_t *, FILE *);
     30#ifdef __GLIBC__                /* FreeWRT: only build this where needed */
    3331char *fgetln(FILE *, size_t *);
    3432
     
    3634fgetln(FILE *stream, size_t *len)
    3735{
    38         char *line=NULL;
    39         size_t nread = 0;
     36        char *lb = NULL;
     37        size_t lbsz = 0;
    4038
    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);
    5141}
    5242#endif
Note: See TracChangeset for help on using the changeset viewer.