New module 'getndelim2'.
authorBruno Haible <bruno@clisp.org>
Fri, 18 Jul 2003 16:58:06 +0000 (16:58 +0000)
committerBruno Haible <bruno@clisp.org>
Fri, 18 Jul 2003 16:58:06 +0000 (16:58 +0000)
15 files changed:
ChangeLog
MODULES.html.sh
lib/ChangeLog
lib/getline.c
lib/getline.h
lib/getndelim2.c
lib/getndelim2.h [new file with mode: 0644]
lib/getnline.c
m4/ChangeLog
m4/getline.m4
m4/getndelim2.m4 [new file with mode: 0644]
m4/getnline.m4
modules/getline
modules/getndelim2 [new file with mode: 0644]
modules/getnline

index f51440e..8e43287 100644 (file)
--- 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.
index 9d6eef3..4fcc1d7 100755 (executable)
@@ -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
index 0fdc20e..f416ba5 100644 (file)
@@ -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.
index ccc3b4a..6cd9503 100644 (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
index 88c5023..0bf8a25 100644 (file)
@@ -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
 
index bceb70f..fb75a3f 100644 (file)
@@ -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.
    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 (file)
index 0000000..d9bafe3
--- /dev/null
@@ -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 */
index 311bb1d..7b858e3 100644 (file)
@@ -23,6 +23,8 @@
 /* Specification.  */
 #include "getnline.h"
 
+#include "getndelim2.h"
+
 ssize_t
 getnline (char **lineptr, size_t *linesize, size_t nmax, FILE *stream)
 {
index eaf430b..d8f62b3 100644 (file)
@@ -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.
index b594391..606a989 100644 (file)
@@ -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 (file)
index 0000000..db48328
--- /dev/null
@@ -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])
+])
index c83ab36..0ee18c8 100644 (file)
@@ -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])
+  :
 ])
index e7f6f56..af67fa8 100644 (file)
@@ -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 (file)
index 0000000..8f6f517
--- /dev/null
@@ -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
+
index e578954..eddf2e5 100644 (file)
@@ -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"