xref: /dflybsd-src/contrib/cvs-1.12/lib/getndelim2.h (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters,
286d7f5d3SJohn Marino    with bounded memory allocation.
386d7f5d3SJohn Marino 
486d7f5d3SJohn Marino    Copyright (C) 2003, 2004 Free Software Foundation, Inc.
586d7f5d3SJohn Marino 
686d7f5d3SJohn Marino    This program is free software; you can redistribute it and/or modify
786d7f5d3SJohn Marino    it under the terms of the GNU General Public License as published by
886d7f5d3SJohn Marino    the Free Software Foundation; either version 2, or (at your option)
986d7f5d3SJohn Marino    any later version.
1086d7f5d3SJohn Marino 
1186d7f5d3SJohn Marino    This program is distributed in the hope that it will be useful,
1286d7f5d3SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
1386d7f5d3SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1486d7f5d3SJohn Marino    GNU General Public License for more details.
1586d7f5d3SJohn Marino 
1686d7f5d3SJohn Marino    You should have received a copy of the GNU General Public License
1786d7f5d3SJohn Marino    along with this program; if not, write to the Free Software Foundation,
1886d7f5d3SJohn Marino    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
1986d7f5d3SJohn Marino 
2086d7f5d3SJohn Marino #ifndef GETNDELIM2_H
2186d7f5d3SJohn Marino #define GETNDELIM2_H 1
2286d7f5d3SJohn Marino 
2386d7f5d3SJohn Marino #include <stdio.h>
2486d7f5d3SJohn Marino #include <sys/types.h>
2586d7f5d3SJohn Marino 
2686d7f5d3SJohn Marino #define GETNLINE_NO_LIMIT ((size_t) -1)
2786d7f5d3SJohn Marino 
2886d7f5d3SJohn Marino /* Read into a buffer *LINEPTR returned from malloc (or NULL),
2986d7f5d3SJohn Marino    pointing to *LINESIZE bytes of space.  Store the input bytes
3086d7f5d3SJohn Marino    starting at *LINEPTR + OFFSET, and null-terminate them.  Reallocate
3186d7f5d3SJohn Marino    the buffer as necessary, but if NMAX is not GETNLINE_NO_LIMIT
3286d7f5d3SJohn Marino    then do not allocate more than NMAX bytes; if the line is longer
3386d7f5d3SJohn Marino    than that, read and discard the extra bytes.  Stop reading after
3486d7f5d3SJohn Marino    after the first occurrence of DELIM1 or DELIM2, whichever comes
3586d7f5d3SJohn Marino    first; a delimiter equal to EOF stands for no delimiter.  Read the
3686d7f5d3SJohn Marino    input bytes from STREAM.
3786d7f5d3SJohn Marino    Return the number of bytes read and stored at *LINEPTR + OFFSET (not
3886d7f5d3SJohn Marino    including the NUL terminator), or -1 on error or EOF.  */
3986d7f5d3SJohn Marino extern ssize_t getndelim2 (char **lineptr, size_t *linesize, size_t offset,
4086d7f5d3SJohn Marino                            size_t nmax, int delim1, int delim2,
4186d7f5d3SJohn Marino                            FILE *stream);
4286d7f5d3SJohn Marino 
4386d7f5d3SJohn Marino #endif /* GETNDELIM2_H */
44