+2003-07-18 Bruno Haible <bruno@clisp.org>
+
+ * modules/getndelim2: New file.
+ * modules/getline: Share files with module getndelim2.
+ * modules/getnline: Depend on getndelim2 instead of sharing files with
+ it. Add getnline.c to lib_SOURCES.
+ * MODULES.html.sh (func_all_modules): Add getndelim2.
+
2003-07-17 Bruno Haible <bruno@clisp.org>
* modules/getnline: New file.
func_module diacrit
func_module getline
func_module getnline
+ func_module getndelim2
func_module linebuffer
func_module obstack
func_module hash-pjw
+2003-07-18 Bruno Haible <bruno@clisp.org>
+
+ * getndelim2.h: New file.
+ * getndelim2.c: Make into a module of its own. Include config.h,
+ getndelim2.h.
+ (getndelim2): Make non-static. Change return type to ssize_t.
+ * getline.h: Change argument names.
+ * getline.c: Include getndelim2.h instead of getndelim2.c.
+ * getnline.c: Include getndelim2.h.
+
2003-07-17 Bruno Haible <bruno@clisp.org>
* Makefile.am: Remove file.
#if defined __GNU_LIBRARY__ && HAVE_GETDELIM
int
-getline (char **lineptr, size_t *n, FILE *stream)
+getline (char **lineptr, size_t *linesize, FILE *stream)
{
- return getdelim (lineptr, n, '\n', stream);
+ return getdelim (lineptr, linesize, '\n', stream);
}
#else /* ! have getdelim */
-#include "getndelim2.c"
+#include "getndelim2.h"
int
-getline (char **lineptr, size_t *n, FILE *stream)
+getline (char **lineptr, size_t *linesize, FILE *stream)
{
- return getndelim2 (lineptr, n, (size_t)(-1), stream, '\n', 0, 0);
+ return getndelim2 (lineptr, linesize, (size_t)(-1), stream, '\n', 0, 0);
}
int
-getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream)
+getdelim (char **lineptr, size_t *linesize, int delimiter, FILE *stream)
{
- return getndelim2 (lineptr, n, (size_t)(-1), stream, delimiter, 0, 0);
+ return getndelim2 (lineptr, linesize, (size_t)(-1), stream, delimiter, 0, 0);
}
#endif
/* glibc2 has these functions declared in <stdio.h>. Avoid redeclarations. */
# if __GLIBC__ < 2
-int getline (char **_lineptr, size_t *_n, FILE *_stream);
+extern int getline (char **_lineptr, size_t *_linesize, FILE *_stream);
-int getdelim (char **_lineptr, size_t *_n, int _delimiter, FILE *_stream);
+extern int getdelim (char **_lineptr, size_t *_linesize, int _delimiter,
+ FILE *_stream);
# endif
-/* getndelim2 - Core of getline, getdelim, getnline, getndelim.
+/* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters,
+ with bounded memory allocation.
Copyright (C) 1993, 1996, 1997, 1998, 2000, 2003 Free Software
Foundation, Inc.
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+/* Originally written by Jan Brittenson, bson@gnu.ai.mit.edu. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification. */
+#include "getndelim2.h"
+
#if STDC_HEADERS
# include <stdlib.h>
#else
/* Always add at least this many bytes when extending the buffer. */
#define MIN_CHUNK 64
-/* Read up to (and including) a delimiter DELIM1 from STREAM into *LINEPTR
- + OFFSET (and NUL-terminate it). If DELIM2 is non-zero, then read up
- and including the first occurrence of DELIM1 or DELIM2. *LINEPTR is
- a pointer returned from malloc (or NULL), pointing to *LINESIZE bytes of
- space. It is realloc'd as necessary. Reallocation is limited to
- NMAX bytes; if the line is longer than that, the extra bytes are read but
- thrown away.
- Return the number of bytes read and stored at *LINEPTR + OFFSET (not
- including the NUL terminator), or -1 on error or EOF. */
-
-static int
+ssize_t
getndelim2 (char **lineptr, size_t *linesize, size_t nmax,
FILE *stream, int delim1, int delim2, size_t offset)
{
--- /dev/null
+/* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters,
+ with bounded memory allocation.
+
+ Copyright (C) 2003 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef GETNDELIM2_H
+#define GETNDELIM2_H 1
+
+#include <stddef.h>
+#include <stdio.h>
+
+/* Get ssize_t. */
+#include <sys/types.h>
+
+/* Read up to (and including) a delimiter DELIM1 from STREAM into *LINEPTR
+ + OFFSET (and NUL-terminate it). If DELIM2 is non-zero, then read up
+ and including the first occurrence of DELIM1 or DELIM2. *LINEPTR is
+ a pointer returned from malloc (or NULL), pointing to *LINESIZE bytes of
+ space. It is realloc'd as necessary. Reallocation is limited to
+ NMAX bytes; if the line is longer than that, the extra bytes are read but
+ thrown away.
+ Return the number of bytes read and stored at *LINEPTR + OFFSET (not
+ including the NUL terminator), or -1 on error or EOF. */
+extern ssize_t getndelim2 (char **lineptr, size_t *linesize, size_t nmax,
+ FILE *stream, int delim1, int delim2,
+ size_t offset);
+
+#endif /* GETNDELIM2_H */
/* Specification. */
#include "getnline.h"
+#include "getndelim2.h"
+
ssize_t
getnline (char **lineptr, size_t *linesize, size_t nmax, FILE *stream)
{
+2003-07-18 Bruno Haible <bruno@clisp.org>
+
+ * getndelim2.m4: New file.
+ * getline.m4 (AM_FUNC_GETLINE): Add AC_LIBOBJ of getndelim2.c and
+ invoke gl_PREREQ_GETNDELIM2.
+ (gl_PREREQ_GETLINE): Drop AC_HEADER_STDC, now done by
+ gl_PREREQ_GETNDELIM2.
+ * getnline.m4 (gl_GETNLINE): Drop AC_HEADER_STDC, now done by
+ gl_GETNDELIM2.
+
2003-07-17 Bruno Haible <bruno@clisp.org>
* Makefile.am.in: Remove file.
-# getline.m4 serial 8
+# getline.m4 serial 9
dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software
dnl Foundation, Inc.
AC_DEFINE([getline], [gnu_getline],
[Define to a replacement function name for getline().])
AC_LIBOBJ(getline)
+ AC_LIBOBJ(getndelim2)
gl_PREREQ_GETLINE
+ gl_PREREQ_GETNDELIM2
fi
])
# Prerequisites of lib/getline.c.
AC_DEFUN([gl_PREREQ_GETLINE],
[
- AC_REQUIRE([AC_HEADER_STDC])
AC_CHECK_FUNCS(getdelim)
])
--- /dev/null
+# getndelim2.m4 serial 1
+dnl Copyright (C) 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_GETNDELIM2],
+[
+ gl_PREREQ_GETNDELIM2
+])
+
+# Prerequisites of lib/getndelim2.h and lib/getndelim2.c.
+AC_DEFUN([gl_PREREQ_GETNDELIM2],
+[
+ dnl Prerequisites of lib/getndelim2.h.
+ AC_REQUIRE([gt_TYPE_SSIZE_T])
+ dnl Prerequisites of lib/getndelim2.c.
+ AC_REQUIRE([AC_HEADER_STDC])
+])
-# getnline.m4 serial 1
+# getnline.m4 serial 2
dnl Copyright (C) 2003 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Prerequisites of lib/getnline.h.
AC_REQUIRE([gt_TYPE_SSIZE_T])
dnl Prerequisites of lib/getnline.c.
- AC_REQUIRE([AC_HEADER_STDC])
+ :
])
Files:
lib/getline.h
lib/getline.c
+lib/getndelim2.h
lib/getndelim2.c
m4/getline.m4
+m4/getndelim2.m4
+m4/ssize_t.m4
Depends-on:
unlocked-io
Makefile.am:
lib_SOURCES += getline.h
-EXTRA_DIST += getndelim2.c
+EXTRA_DIST += getndelim2.h getndelim2.c
Include:
"getline.h"
--- /dev/null
+Description:
+Read a line from a stream, stopping at one of 2 delimiters, with bounded
+memory allocation.
+
+Files:
+lib/getndelim2.h
+lib/getndelim2.c
+m4/getndelim2.m4
+m4/ssize_t.m4
+
+Depends-on:
+unlocked-io
+
+configure.ac:
+gl_GETNDELIM2
+
+Makefile.am:
+lib_SOURCES += getndelim2.h getndelim2.c
+
+Include:
+"getndelim2.h"
+
+Maintainer:
+all
+
Files:
lib/getnline.h
lib/getnline.c
-lib/getndelim2.c
m4/getnline.m4
m4/ssize_t.m4
Depends-on:
-unlocked-io
+getndelim2
configure.ac:
gl_GETNLINE
Makefile.am:
-lib_SOURCES += getnline.h
-EXTRA_DIST += getndelim2.c
+lib_SOURCES += getnline.h getnline.c
Include:
"getnline.h"