1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997, 1998 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 /* Reads a DELIMITER-separated field of any length from file STREAM.
27 *LINEPTR is a malloc'd string of size N; if *LINEPTR is NULL, it is
28 allocated. *LINEPTR is allocated/enlarged as necessary. Returns
29 -1 if at eof when entered; otherwise eof causes return of string
30 without a terminating DELIMITER. Normally DELIMITER is the last
31 character in *LINEPTR on return (besides the null character which
32 is always present). Returns number of characters read, including
33 terminating field delimiter if present. */
35 getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream)
37 /* Number of characters stored in *lineptr so far. */
40 /* Last character read. */
43 if (*lineptr == NULL || *n < 2)
45 *lineptr = xrealloc (*lineptr, 128);
59 *lineptr = xrealloc (*lineptr, *n);
61 (*lineptr)[len++] = c;
70 (*lineptr)[len] = '\0';