From: Bruno Haible Date: Sat, 23 Aug 2003 15:30:40 +0000 (+0000) Subject: Update from gnulib. X-Git-Tag: v0.13~341 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17b13af857dff5601a26be0fc9f9dd798a222353;p=thirdparty%2Fgettext.git Update from gnulib. --- diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index 55506c606..529016007 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,3 +1,11 @@ +2003-08-23 Bruno Haible + + * 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 * fnmatch_.h: Renamed from pfnmatch.h. diff --git a/gettext-tools/lib/Makefile.am b/gettext-tools/lib/Makefile.am index 4bee8ae5c..de81701fe 100644 --- a/gettext-tools/lib/Makefile.am +++ b/gettext-tools/lib/Makefile.am @@ -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 \ diff --git a/gettext-tools/lib/getline.c b/gettext-tools/lib/getline.c index 29efa2742..896b6bbd8 100644 --- a/gettext-tools/lib/getline.c +++ b/gettext-tools/lib/getline.c @@ -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 #include + +/* Get ssize_t. */ #include #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 - -# if HAVE_STDLIB_H -# include -# 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 . */ - -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 diff --git a/gettext-tools/lib/getline.h b/gettext-tools/lib/getline.h index e0fe87ea3..ee9fc052c 100644 --- a/gettext-tools/lib/getline.h +++ b/gettext-tools/lib/getline.h @@ -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 # include +/* Get ssize_t. */ +# include + /* glibc2 has these functions declared in . 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 diff --git a/gettext-tools/m4/getline.m4 b/gettext-tools/m4/getline.m4 index 9798db400..606a989b9 100644 --- a/gettext-tools/m4/getline.m4 +++ b/gettext-tools/m4/getline.m4 @@ -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 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) +])