1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* getdelim.c --- Implementation of replacement getdelim function.
4 Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007, 2008 Free
5 Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 3, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 /* Ported from glibc by Simon Josefsson. */
33 # define SIZE_MAX ((size_t) -1)
36 # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
40 # define flockfile(x) ((void) 0)
44 # define funlockfile(x) ((void) 0)
47 /* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
48 NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
49 NULL), pointing to *N characters of space. It is realloc'ed as
50 necessary. Returns the number of characters read (not including
51 the null terminator), or -1 on error or EOF. */
54 getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
59 if (lineptr == NULL || n == NULL || fp == NULL)
67 if (*lineptr == NULL || *n == 0)
71 new_lineptr = (char *) realloc (*lineptr, *n);
72 if (new_lineptr == NULL)
77 *lineptr = new_lineptr;
91 /* Make enough space for len+1 (for final NUL) bytes. */
92 if (cur_len + 1 >= *n)
95 SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
96 size_t needed = 2 * *n + 1; /* Be generous. */
99 if (needed_max < needed)
101 if (cur_len + 1 >= needed)
108 new_lineptr = (char *) realloc (*lineptr, needed);
109 if (new_lineptr == NULL)
115 *lineptr = new_lineptr;
119 (*lineptr)[cur_len] = i;
125 (*lineptr)[cur_len] = '\0';
126 result = cur_len ? cur_len : result;
129 funlockfile (fp); /* doesn't set errno */