]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Update from gnulib.
authorBruno Haible <bruno@clisp.org>
Sat, 23 Aug 2003 15:30:40 +0000 (15:30 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:10:51 +0000 (12:10 +0200)
gettext-tools/lib/ChangeLog
gettext-tools/lib/Makefile.am
gettext-tools/lib/getline.c
gettext-tools/lib/getline.h
gettext-tools/m4/getline.m4

index 55506c606768ca04858b4a9ba3428d97a697b96b..529016007838dfdaa4add51adeac326a2dd42c23 100644 (file)
@@ -1,3 +1,11 @@
+2003-08-23  Bruno Haible  <bruno@clisp.org>
+
+       * getline.h: Update from gnulib.
+       * getline.c: Update from gnulib.
+       * getndelim2.h: New file, from gnulib.
+       * getndelim2.c: New file, from gnulib.
+       * Makefile.am (LIBADD_SOURCE): Add getndelim2.h, getndelim2.c.
+
 2003-08-23  Bruno Haible  <bruno@clisp.org>
 
        * fnmatch_.h: Renamed from pfnmatch.h.
index 4bee8ae5c21d6fac25dee66cbc7e263a70efef1d..de81701fe25f16f06f6c5e58501e74373c2320bb 100644 (file)
@@ -79,6 +79,7 @@ LIBADD_SOURCE = \
   canonicalize.h canonicalize.c \
   fnmatch.c \
   getline.h getline.c \
+  getndelim2.h getndelim2.c \
   memmove.c \
   memset.c \
   mkdtemp.h mkdtemp.c \
index 29efa2742f57e492e30def3636c36795d4ea6ee6..896b6bbd84cb05326175d98a6f5af8a53c112708 100644 (file)
@@ -1,20 +1,21 @@
 /* getline.c -- Replacement for GNU C library function getline
 
-Copyright (C) 1993, 1996, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1993, 1996, 1997, 1998, 2000, 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 of the
-License, or (at your option) any later version.
+   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.
+   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. */
+   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.  */
 
 /* Written by Jan Brittenson, bson@gnu.ai.mit.edu.  */
 
@@ -25,122 +26,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 /* Specification.  */
 #include "getline.h"
 
-/* The `getdelim' function is only declared if the following symbol
-   is defined.  */
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE   1
-#endif
+#include <stddef.h>
 #include <stdio.h>
+
+/* Get ssize_t.  */
 #include <sys/types.h>
 
 #if defined __GNU_LIBRARY__ && HAVE_GETDELIM
 
-int
-getline (char **lineptr, size_t *n, FILE *stream)
+ssize_t
+getline (char **lineptr, size_t *linesize, FILE *stream)
 {
-  return getdelim (lineptr, n, '\n', stream);
+  return getdelim (lineptr, linesize, '\n', stream);
 }
 
 #else /* ! have getdelim */
 
-# include <assert.h>
-
-# if HAVE_STDLIB_H
-#  include <stdlib.h>
-# else
-extern char *malloc ();
-extern char *realloc ();
-# endif
-
-/* Always add at least this many bytes when extending the buffer.  */
-# define MIN_CHUNK 64
-
-/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR
-   + OFFSET (and null-terminate it). *LINEPTR is a pointer returned from
-   malloc (or NULL), pointing to *N characters of space.  It is realloc'd
-   as necessary.  Return the number of characters read (not including the
-   null terminator), or -1 on error or EOF.
-   NOTE: There is another getstr() function declared in <curses.h>.  */
-
-static int
-getstr (char **lineptr, size_t *n, FILE *stream, char terminator,
-       size_t offset)
-{
-  int nchars_avail;            /* Allocated but unused chars in *LINEPTR.  */
-  char *read_pos;              /* Where we're reading into *LINEPTR. */
-  int ret;
-
-  if (!lineptr || !n || !stream)
-    return -1;
-
-  if (!*lineptr)
-    {
-      *n = MIN_CHUNK;
-      *lineptr = malloc (*n);
-      if (!*lineptr)
-       return -1;
-    }
-
-  nchars_avail = *n - offset;
-  read_pos = *lineptr + offset;
-
-  for (;;)
-    {
-      register int c = getc (stream);
-
-      /* We always want at least one char left in the buffer, since we
-        always (unless we get an error while reading the first char)
-        NUL-terminate the line buffer.  */
-
-      assert(*n - nchars_avail == read_pos - *lineptr);
-      if (nchars_avail < 2)
-       {
-         if (*n > MIN_CHUNK)
-           *n *= 2;
-         else
-           *n += MIN_CHUNK;
-
-         nchars_avail = *n + *lineptr - read_pos;
-         *lineptr = realloc (*lineptr, *n);
-         if (!*lineptr)
-           return -1;
-         read_pos = *n - nchars_avail + *lineptr;
-         assert(*n - nchars_avail == read_pos - *lineptr);
-       }
-
-      if (c == EOF || ferror (stream))
-       {
-         /* Return partial line, if any.  */
-         if (read_pos == *lineptr)
-           return -1;
-         else
-           break;
-       }
-
-      *read_pos++ = c;
-      nchars_avail--;
-
-      if (c == terminator)
-       /* Return the line.  */
-       break;
-    }
-
-  /* Done - NUL terminate and return the number of chars read.  */
-  *read_pos = '\0';
-
-  ret = read_pos - (*lineptr + offset);
-  return ret;
-}
+# include "getndelim2.h"
 
-int
-getline (char **lineptr, size_t *n, FILE *stream)
+ssize_t
+getline (char **lineptr, size_t *linesize, FILE *stream)
 {
-  return getstr (lineptr, n, stream, '\n', 0);
+  return getndelim2 (lineptr, linesize, (size_t)(-1), stream, '\n', 0, 0);
 }
 
-int
-getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream)
+ssize_t
+getdelim (char **lineptr, size_t *linesize, int delimiter, FILE *stream)
 {
-  return getstr (lineptr, n, stream, delimiter, 0);
+  return getndelim2 (lineptr, linesize, (size_t)(-1), stream, delimiter, 0, 0);
 }
 #endif
index e0fe87ea3ce6d478316ee3560fc3ac1cdbffd6cf..ee9fc052c129058525a50c11a2579e03d5add869 100644 (file)
@@ -1,4 +1,7 @@
-/*  Copyright (C) 1995, 2000-2002 Free Software Foundation, Inc.
+/* Replacement for GNU C library function getline
+
+   Copyright (C) 1995, 1997, 1999, 2000, 2001, 2002, 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
@@ -20,14 +23,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 # include <stddef.h>
 # include <stdio.h>
 
+/* Get ssize_t.  */
+# include <sys/types.h>
+
 /* glibc2 has these functions declared in <stdio.h>.  Avoid redeclarations.  */
 # if __GLIBC__ < 2
 
-int
-getline (char **_lineptr, size_t *_n, FILE *_stream);
+extern ssize_t getline (char **_lineptr, size_t *_linesize, FILE *_stream);
 
-int
-getdelim (char **_lineptr, size_t *_n, int _delimiter, FILE *_stream);
+extern ssize_t getdelim (char **_lineptr, size_t *_linesize, int _delimiter,
+                         FILE *_stream);
 
 # endif
 
index 9798db400bf6ec6f2f9c4fc8bdfe73e9056ae9f6..606a989b950872a2623509fed9eaec0669b8e282 100644 (file)
@@ -1,5 +1,8 @@
-# getline.m4 serial 6 (gettext-0.12)
-dnl Copyright (C) 1998-2003 Free Software Foundation, Inc.
+# getline.m4 serial 9
+
+dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software
+dnl 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
@@ -13,7 +16,10 @@ dnl We can't just do AC_REPLACE_FUNCS(getline) because some systems
 dnl have a function by that name in -linet that doesn't have anything
 dnl to do with the function we need.
 AC_DEFUN([AM_FUNC_GETLINE],
-[dnl
+[
+  dnl Persuade glibc <stdio.h> to declare getline() and getdelim().
+  AC_REQUIRE([AC_GNU_SOURCE])
+
   am_getline_needs_run_time_check=no
   AC_CHECK_FUNC(getline,
                dnl Found it in some library.  Verify that it works.
@@ -50,5 +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_CHECK_FUNCS(getdelim)
+])