1 /* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters, 2 with bounded memory allocation. 3 4 Copyright (C) 2003, 2004 Free Software Foundation, Inc. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software Foundation, 18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 19 20 #ifndef GETNDELIM2_H 21 #define GETNDELIM2_H 1 22 23 #include <stdio.h> 24 #include <sys/types.h> 25 26 #define GETNLINE_NO_LIMIT ((size_t) -1) 27 28 /* Read into a buffer *LINEPTR returned from malloc (or NULL), 29 pointing to *LINESIZE bytes of space. Store the input bytes 30 starting at *LINEPTR + OFFSET, and null-terminate them. Reallocate 31 the buffer as necessary, but if NMAX is not GETNLINE_NO_LIMIT 32 then do not allocate more than NMAX bytes; if the line is longer 33 than that, read and discard the extra bytes. Stop reading after 34 after the first occurrence of DELIM1 or DELIM2, whichever comes 35 first; a delimiter equal to EOF stands for no delimiter. Read the 36 input bytes from STREAM. 37 Return the number of bytes read and stored at *LINEPTR + OFFSET (not 38 including the NUL terminator), or -1 on error or EOF. */ 39 extern ssize_t getndelim2 (char **lineptr, size_t *linesize, size_t offset, 40 size_t nmax, int delim1, int delim2, 41 FILE *stream); 42 43 #endif /* GETNDELIM2_H */ 44