summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rwxr-xr-xMODULES.html.sh1
-rw-r--r--lib/ChangeLog10
-rw-r--r--lib/getline.c14
-rw-r--r--lib/getline.h5
-rw-r--r--lib/getndelim2.c24
-rw-r--r--lib/getndelim2.h42
-rw-r--r--lib/getnline.c2
-rw-r--r--m4/ChangeLog10
-rw-r--r--m4/getline.m45
-rw-r--r--m4/getndelim2.m421
-rw-r--r--m4/getnline.m44
-rw-r--r--modules/getline5
-rw-r--r--modules/getndelim225
-rw-r--r--modules/getnline6
15 files changed, 152 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index f51440e749..8e432875f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+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.
diff --git a/MODULES.html.sh b/MODULES.html.sh
index 9d6eef392f..4fcc1d723b 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -1580,6 +1580,7 @@ func_all_modules ()
func_module diacrit
func_module getline
func_module getnline
+ func_module getndelim2
func_module linebuffer
func_module obstack
func_module hash-pjw
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 0fdc20e1e5..f416ba558e 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,13 @@
+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.
diff --git a/lib/getline.c b/lib/getline.c
index ccc3b4a395..6cd9503277 100644
--- a/lib/getline.c
+++ b/lib/getline.c
@@ -38,24 +38,24 @@
#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
diff --git a/lib/getline.h b/lib/getline.h
index 88c502382f..0bf8a2552b 100644
--- a/lib/getline.h
+++ b/lib/getline.h
@@ -26,9 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* 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
diff --git a/lib/getndelim2.c b/lib/getndelim2.c
index bceb70fbe7..fb75a3f276 100644
--- a/lib/getndelim2.c
+++ b/lib/getndelim2.c
@@ -1,4 +1,5 @@
-/* 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.
@@ -17,6 +18,15 @@
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
@@ -28,17 +38,7 @@ char *malloc (), *realloc ();
/* 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)
{
diff --git a/lib/getndelim2.h b/lib/getndelim2.h
new file mode 100644
index 0000000000..d9bafe3b42
--- /dev/null
+++ b/lib/getndelim2.h
@@ -0,0 +1,42 @@
+/* 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 */
diff --git a/lib/getnline.c b/lib/getnline.c
index 311bb1d7bf..7b858e37fa 100644
--- a/lib/getnline.c
+++ b/lib/getnline.c
@@ -23,6 +23,8 @@
/* Specification. */
#include "getnline.h"
+#include "getndelim2.h"
+
ssize_t
getnline (char **lineptr, size_t *linesize, size_t nmax, FILE *stream)
{
diff --git a/m4/ChangeLog b/m4/ChangeLog
index eaf430bd8f..d8f62b3b8d 100644
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,3 +1,13 @@
+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.
diff --git a/m4/getline.m4 b/m4/getline.m4
index b5943918c7..606a989b95 100644
--- a/m4/getline.m4
+++ b/m4/getline.m4
@@ -1,4 +1,4 @@
-# getline.m4 serial 8
+# getline.m4 serial 9
dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software
dnl Foundation, Inc.
@@ -56,13 +56,14 @@ AC_DEFUN([AM_FUNC_GETLINE],
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)
])
diff --git a/m4/getndelim2.m4 b/m4/getndelim2.m4
new file mode 100644
index 0000000000..db483281e1
--- /dev/null
+++ b/m4/getndelim2.m4
@@ -0,0 +1,21 @@
+# 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])
+])
diff --git a/m4/getnline.m4 b/m4/getnline.m4
index c83ab36c4f..0ee18c83e5 100644
--- a/m4/getnline.m4
+++ b/m4/getnline.m4
@@ -1,4 +1,4 @@
-# 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
@@ -11,5 +11,5 @@ AC_DEFUN([gl_GETNLINE],
dnl Prerequisites of lib/getnline.h.
AC_REQUIRE([gt_TYPE_SSIZE_T])
dnl Prerequisites of lib/getnline.c.
- AC_REQUIRE([AC_HEADER_STDC])
+ :
])
diff --git a/modules/getline b/modules/getline
index e7f6f56fe5..af67fa82de 100644
--- a/modules/getline
+++ b/modules/getline
@@ -4,8 +4,11 @@ Read a line from a stream.
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
@@ -15,7 +18,7 @@ AM_FUNC_GETLINE
Makefile.am:
lib_SOURCES += getline.h
-EXTRA_DIST += getndelim2.c
+EXTRA_DIST += getndelim2.h getndelim2.c
Include:
"getline.h"
diff --git a/modules/getndelim2 b/modules/getndelim2
new file mode 100644
index 0000000000..8f6f51713e
--- /dev/null
+++ b/modules/getndelim2
@@ -0,0 +1,25 @@
+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
+
diff --git a/modules/getnline b/modules/getnline
index e578954833..eddf2e53b9 100644
--- a/modules/getnline
+++ b/modules/getnline
@@ -4,19 +4,17 @@ Read a line from a stream, with bounded memory allocation.
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"