diff options
author | Simon Josefsson <simon@josefsson.org> | 2010-02-17 10:10:47 +0100 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2010-02-17 10:10:47 +0100 |
commit | db3a3b93e599669172d46d81c3db3eb661640996 (patch) | |
tree | e0d9da491762dead0f4f742555a17e32f8f782df /gl | |
parent | 8728945992cce0019e0d286181d81dcd9d280d0d (diff) | |
download | gnutls-db3a3b93e599669172d46d81c3db3eb661640996.tar.gz |
Update gnulib files.
Diffstat (limited to 'gl')
-rw-r--r-- | gl/Makefile.am | 9 | ||||
-rw-r--r-- | gl/m4/getdelim.m4 | 65 | ||||
-rw-r--r-- | gl/m4/getline.m4 | 38 | ||||
-rw-r--r-- | gl/m4/gettimeofday.m4 | 61 | ||||
-rw-r--r-- | gl/m4/gnulib-comp.m4 | 1 | ||||
-rw-r--r-- | gl/m4/stdio_h.m4 | 3 | ||||
-rw-r--r-- | gl/m4/sys_time_h.m4 | 44 | ||||
-rw-r--r-- | gl/netdb.in.h | 28 | ||||
-rw-r--r-- | gl/stdio.in.h | 8 | ||||
-rw-r--r-- | gl/sys_time.in.h | 16 | ||||
-rw-r--r-- | gl/tests/test-getdelim.c | 19 | ||||
-rw-r--r-- | gl/tests/test-getline.c | 19 | ||||
-rw-r--r-- | gl/tests/test-gettimeofday.c | 8 |
13 files changed, 230 insertions, 89 deletions
diff --git a/gl/Makefile.am b/gl/Makefile.am index 203a514a0a..cdcb1cbd7a 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -748,6 +748,7 @@ stdio.h: stdio.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H) -e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \ -e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \ -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \ + -e 's|@''REPLACE_GETDELIM''@|$(REPLACE_GETDELIM)|g' \ -e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \ -e 's|@''REPLACE_OBSTACK_PRINTF''@|$(REPLACE_OBSTACK_PRINTF)|g' \ -e 's|@''REPLACE_PERROR''@|$(REPLACE_PERROR)|g' \ @@ -1078,11 +1079,11 @@ EXTRA_DIST += sys_stat.in.h ## begin gnulib module sys_time -BUILT_SOURCES += $(SYS_TIME_H) +BUILT_SOURCES += sys/time.h # We need the following in order to create <sys/time.h> when the system # doesn't have one that works with the given compiler. -sys/time.h: sys_time.in.h $(ARG_NONNULL_H) +sys/time.h: sys_time.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H) $(AM_V_at)$(MKDIR_P) sys $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ @@ -1090,9 +1091,11 @@ sys/time.h: sys_time.in.h $(ARG_NONNULL_H) -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \ - -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \ + -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \ + -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/sys_time.in.h; \ } > $@-t && \ mv $@-t $@ diff --git a/gl/m4/getdelim.m4 b/gl/m4/getdelim.m4 index 9e5ad5baaf..4beb1501c2 100644 --- a/gl/m4/getdelim.m4 +++ b/gl/m4/getdelim.m4 @@ -1,6 +1,6 @@ -# getdelim.m4 serial 5 +# getdelim.m4 serial 6 -dnl Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. +dnl Copyright (C) 2005-2007, 2009-2010 Free Software Foundation, Inc. dnl dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -15,16 +15,71 @@ AC_DEFUN([gl_FUNC_GETDELIM], dnl Persuade glibc <stdio.h> to declare getdelim(). AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - AC_REPLACE_FUNCS([getdelim]) AC_CHECK_DECLS_ONCE([getdelim]) - if test $ac_cv_func_getdelim = no; then - gl_PREREQ_GETDELIM + AC_CHECK_FUNCS_ONCE([getdelim]) + if test $ac_cv_func_getdelim = yes; then + dnl Found it in some library. Verify that it works. + AC_CACHE_CHECK([for working getdelim function], [gl_cv_func_working_getdelim], + [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data + AC_RUN_IFELSE([AC_LANG_SOURCE([[ +# include <stdio.h> +# include <stdlib.h> +# include <string.h> + int main () + { + FILE *in = fopen ("./conftest.data", "r"); + if (!in) + return 1; + { + /* Test result for a NULL buffer and a zero size. + Based on a test program from Karl Heuer. */ + char *line = NULL; + size_t siz = 0; + int len = getdelim (&line, &siz, '\n', in); + if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) + return 1; + } + { + /* Test result for a NULL buffer and a non-zero size. + This crashes on FreeBSD 8.0. */ + char *line = NULL; + size_t siz = (size_t)(~0) / 4; + if (getdelim (&line, &siz, '\n', in) == -1) + return 1; + } + return 0; + } + ]])], [gl_cv_func_working_getdelim=yes] dnl The library version works. + , [gl_cv_func_working_getdelim=no] dnl The library version does NOT work. + , dnl We're cross compiling. Assume it works on glibc2 systems. + [AC_EGREP_CPP([Lucky GNU user], + [ +#include <features.h> +#ifdef __GNU_LIBRARY__ + #if (__GLIBC__ >= 2) + Lucky GNU user + #endif +#endif + ], + [gl_cv_func_working_getdelim=yes], + [gl_cv_func_working_getdelim=no])] + )]) + else + gl_cv_func_working_getdelim=no fi if test $ac_cv_have_decl_getdelim = no; then HAVE_DECL_GETDELIM=0 fi + + if test $gl_cv_func_working_getdelim = no; then + if test $ac_cv_func_getdelim = yes; then + REPLACE_GETDELIM=1 + fi + AC_LIBOBJ([getdelim]) + gl_PREREQ_GETDELIM + fi ]) # Prerequisites of lib/getdelim.c. diff --git a/gl/m4/getline.m4 b/gl/m4/getline.m4 index 5b8a712fbc..83005600d6 100644 --- a/gl/m4/getline.m4 +++ b/gl/m4/getline.m4 @@ -1,4 +1,4 @@ -# getline.m4 serial 20 +# getline.m4 serial 21 dnl Copyright (C) 1998-2003, 2005-2007, 2009-2010 Free Software Foundation, dnl Inc. @@ -24,26 +24,39 @@ AC_DEFUN([gl_FUNC_GETLINE], gl_getline_needs_run_time_check=no AC_CHECK_FUNC([getline], - dnl Found it in some library. Verify that it works. - gl_getline_needs_run_time_check=yes, - am_cv_func_working_getline=no) + [dnl Found it in some library. Verify that it works. + gl_getline_needs_run_time_check=yes], + [am_cv_func_working_getline=no]) if test $gl_getline_needs_run_time_check = yes; then AC_CACHE_CHECK([for working getline function], [am_cv_func_working_getline], - [echo fooN |tr -d '\012'|tr N '\012' > conftest.data + [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data AC_RUN_IFELSE([AC_LANG_SOURCE([[ # include <stdio.h> # include <stdlib.h> # include <string.h> int main () - { /* Based on a test program from Karl Heuer. */ - char *line = NULL; - size_t siz = 0; - int len; + { FILE *in = fopen ("./conftest.data", "r"); if (!in) return 1; - len = getline (&line, &siz, in); - exit ((len == 4 && line && strcmp (line, "foo\n") == 0) ? 0 : 1); + { + /* Test result for a NULL buffer and a zero size. + Based on a test program from Karl Heuer. */ + char *line = NULL; + size_t siz = 0; + int len = getline (&line, &siz, in); + if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) + return 1; + } + { + /* Test result for a NULL buffer and a non-zero size. + This crashes on FreeBSD 8.0. */ + char *line = NULL; + size_t siz = (size_t)(~0) / 4; + if (getline (&line, &siz, in) == -1) + return 1; + } + return 0; } ]])], [am_cv_func_working_getline=yes] dnl The library version works. , [am_cv_func_working_getline=no] dnl The library version does NOT work. @@ -67,6 +80,9 @@ AC_DEFUN([gl_FUNC_GETLINE], fi if test $am_cv_func_working_getline = no; then + dnl Set REPLACE_GETLINE always: Even if we have not found the broken + dnl getline function among $LIBS, it may exist in libinet and the + dnl executable may be linked with -linet. REPLACE_GETLINE=1 AC_LIBOBJ([getline]) diff --git a/gl/m4/gettimeofday.m4 b/gl/m4/gettimeofday.m4 index 735123e6dc..32e4f29a9f 100644 --- a/gl/m4/gettimeofday.m4 +++ b/gl/m4/gettimeofday.m4 @@ -1,4 +1,4 @@ -# serial 12 +# serial 14 # Copyright (C) 2001-2003, 2005, 2007, 2009-2010 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -11,33 +11,49 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY], [ AC_REQUIRE([AC_C_RESTRICT]) AC_REQUIRE([gl_HEADER_SYS_TIME_H]) + AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) AC_CHECK_FUNCS_ONCE([gettimeofday]) - AC_CACHE_CHECK([for gettimeofday with POSIX signature], - [gl_cv_func_gettimeofday_posix_signature], - [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM( - [[#include <sys/time.h> - struct timeval c; - ]], - [[ - int (*f) (struct timeval *restrict, void *restrict) = gettimeofday; - int x = f (&c, 0); - return !(x | c.tv_sec | c.tv_usec); - ]])], - [gl_cv_func_gettimeofday_posix_signature=yes], - [gl_cv_func_gettimeofday_posix_signature=no])]) - - gl_FUNC_GETTIMEOFDAY_CLOBBER - - if test $gl_cv_func_gettimeofday_posix_signature != yes; then - REPLACE_GETTIMEOFDAY=1 - SYS_TIME_H=sys/time.h - if test $gl_cv_func_gettimeofday_clobber != yes; then + gl_gettimeofday_timezone=void + if test $ac_cv_func_gettimeofday = yes; then + gl_FUNC_GETTIMEOFDAY_CLOBBER + AC_CACHE_CHECK([for gettimeofday with POSIX signature], + [gl_cv_func_gettimeofday_posix_signature], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include <sys/time.h> + struct timeval c; + int gettimeofday (struct timeval *restrict, void *restrict); + ]], + [[/* glibc uses struct timezone * rather than the POSIX void * + if _GNU_SOURCE is defined. However, since the only portable + use of gettimeofday uses NULL as the second parameter, and + since the glibc definition is actually more typesafe, it is + not worth wrapping this to get a compliant signature. */ + int (*f) (struct timeval *restrict, void *restrict) + = gettimeofday; + int x = f (&c, 0); + return !(x | c.tv_sec | c.tv_usec); + ]])], + [gl_cv_func_gettimeofday_posix_signature=yes], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include <sys/time.h> +int gettimeofday (struct timeval *restrict, struct timezone *restrict); + ]])], + [gl_cv_func_gettimeofday_posix_signature=almost], + [gl_cv_func_gettimeofday_posix_signature=no])])]) + if test $gl_cv_func_gettimeofday_posix_signature = almost; then + gl_gettimeofday_timezone='struct timezone' + elif test $gl_cv_func_gettimeofday_posix_signature != yes; then + REPLACE_GETTIMEOFDAY=1 AC_LIBOBJ([gettimeofday]) gl_PREREQ_GETTIMEOFDAY fi fi + AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone], + [Define this to 'void' or 'struct timezone' to match the system's + declaration of the second argument to gettimeofday.]) ]) @@ -78,7 +94,6 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER], if test $gl_cv_func_gettimeofday_clobber = yes; then REPLACE_GETTIMEOFDAY=1 - SYS_TIME_H=sys/time.h gl_GETTIMEOFDAY_REPLACE_LOCALTIME AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1], [Define if gettimeofday clobbers the localtime buffer.]) diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index 9ee2c0a593..4f08319901 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -238,6 +238,7 @@ AC_SUBST([LTALLOCA]) gl_source_base='gl/tests' gl_FUNC_UNGETC_WORKS gl_FUNC_GETTIMEOFDAY + gl_SYS_TIME_MODULE_INDICATOR([gettimeofday]) AC_C_BIGENDIAN AC_C_BIGENDIAN AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4 index 20af579d14..781fa8d388 100644 --- a/gl/m4/stdio_h.m4 +++ b/gl/m4/stdio_h.m4 @@ -1,4 +1,4 @@ -# stdio_h.m4 serial 24 +# stdio_h.m4 serial 25 dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -111,6 +111,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS], REPLACE_FSEEKO=0; AC_SUBST([REPLACE_FSEEKO]) REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL]) REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO]) + REPLACE_GETDELIM=0; AC_SUBST([REPLACE_GETDELIM]) REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE]) REPLACE_OBSTACK_PRINTF=0; AC_SUBST([REPLACE_OBSTACK_PRINTF]) REPLACE_PERROR=0; AC_SUBST([REPLACE_PERROR]) diff --git a/gl/m4/sys_time_h.m4 b/gl/m4/sys_time_h.m4 index 9c16487957..b14bc4ba2b 100644 --- a/gl/m4/sys_time_h.m4 +++ b/gl/m4/sys_time_h.m4 @@ -1,5 +1,5 @@ # Configure a replacement for <sys/time.h>. -# serial 2 +# serial 3 # Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -19,15 +19,13 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H], AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY], [ AC_REQUIRE([AC_C_RESTRICT]) + AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) AC_CHECK_HEADERS_ONCE([sys/time.h]) gl_CHECK_NEXT_HEADERS([sys/time.h]) - if test $ac_cv_header_sys_time_h = yes; then - HAVE_SYS_TIME_H=1 - else + if test $ac_cv_header_sys_time_h != yes; then HAVE_SYS_TIME_H=0 fi - AC_SUBST([HAVE_SYS_TIME_H]) AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval], [AC_COMPILE_IFELSE( @@ -40,20 +38,32 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY], [[static struct timeval x; x.tv_sec = x.tv_usec;]])], [gl_cv_sys_struct_timeval=yes], [gl_cv_sys_struct_timeval=no])]) - if test $gl_cv_sys_struct_timeval = yes; then - HAVE_STRUCT_TIMEVAL=1 - else + if test $gl_cv_sys_struct_timeval != yes; then HAVE_STRUCT_TIMEVAL=0 fi - AC_SUBST([HAVE_STRUCT_TIMEVAL]) + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ +#if HAVE_SYS_TIME_H +# include <sys/time.h> +#endif +#include <time.h> + ]], [gettimeofday]) +]) + +AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS]) + GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 +]) + +AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS], +[ + GNULIB_GETTIMEOFDAY=0; AC_SUBST([GNULIB_GETTIMEOFDAY]) dnl Assume POSIX behavior unless another module says otherwise. - REPLACE_GETTIMEOFDAY=0 - AC_SUBST([REPLACE_GETTIMEOFDAY]) - if test $HAVE_SYS_TIME_H = 0 || test $HAVE_STRUCT_TIMEVAL = 0; then - SYS_TIME_H=sys/time.h - else - SYS_TIME_H= - fi - AC_SUBST([SYS_TIME_H]) + HAVE_STRUCT_TIMEVAL=1; AC_SUBST([HAVE_STRUCT_TIMEVAL]) + HAVE_SYS_TIME_H=1; AC_SUBST([HAVE_SYS_TIME_H]) + REPLACE_GETTIMEOFDAY=0; AC_SUBST([REPLACE_GETTIMEOFDAY]) ]) diff --git a/gl/netdb.in.h b/gl/netdb.in.h index 92daa51386..6e0f966c9a 100644 --- a/gl/netdb.in.h +++ b/gl/netdb.in.h @@ -74,18 +74,24 @@ struct addrinfo # endif # if 0 -/* The commented out definitions below are not yet implemented in the - GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact, - cause conflicts on systems with a getaddrinfo() function which does not - define them. - - If they are restored, be sure to protect the definitions with #ifndef. */ # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */ -# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */ -# define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */ -# define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose - returned address type.. */ -# endif /* 0 */ +# endif + +/* These symbolic constants are required to be present by POSIX, but + our getaddrinfo replacement doesn't use them (yet). Setting them + to 0 on systems that doesn't have them avoids causing problems for + system getaddrinfo implementations that would be confused by + unknown values. */ +# ifndef AI_V4MAPPED +# define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */ +# endif +# ifndef AI_ALL +# define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */ +# endif +# ifndef AI_ADDRCONFIG +# define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose + returned address type.. */ +# endif /* Error values for `getaddrinfo' function. */ # ifndef EAI_BADFLAGS diff --git a/gl/stdio.in.h b/gl/stdio.in.h index 6b72c39cb7..96010d2347 100644 --- a/gl/stdio.in.h +++ b/gl/stdio.in.h @@ -340,7 +340,11 @@ extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream) #endif #if @GNULIB_GETDELIM@ -# if !@HAVE_DECL_GETDELIM@ +# if @REPLACE_GETDELIM@ +# undef getdelim +# define getdelim rpl_getdelim +# endif +# if !@HAVE_DECL_GETDELIM@ || @REPLACE_GETDELIM@ /* Read input, up to (and including) the next occurrence of DELIMITER, from STREAM, store it in *LINEPTR (and NUL-terminate it). *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE @@ -382,7 +386,7 @@ _GL_WARN_ON_USE (getline, "getline is unportable - " # endif #endif -#if @GNULIB_OBSTACK_PRINTF@ +#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ # if @REPLACE_OBSTACK_PRINTF@ # define obstack_printf rpl_osbtack_printf # define obstack_vprintf rpl_obstack_vprintf diff --git a/gl/sys_time.in.h b/gl/sys_time.in.h index 028093c627..e00f85807f 100644 --- a/gl/sys_time.in.h +++ b/gl/sys_time.in.h @@ -41,6 +41,8 @@ /* The definition of _GL_ARG_NONNULL is copied here. */ +/* The definition of _GL_WARN_ON_USE is copied here. */ + #ifdef __cplusplus extern "C" { #endif @@ -53,11 +55,19 @@ struct timeval }; # endif -# if @REPLACE_GETTIMEOFDAY@ -# undef gettimeofday -# define gettimeofday rpl_gettimeofday +# if @GNULIB_GETTIMEOFDAY@ +# if @REPLACE_GETTIMEOFDAY@ +# undef gettimeofday +# define gettimeofday rpl_gettimeofday extern int gettimeofday (struct timeval *restrict, void *restrict) _GL_ARG_NONNULL ((1)); +# endif +# elif defined GNULIB_POSIXCHECK +# undef gettimeofday +# if HAVE_RAW_DECL_GETTIMEOFDAY +_GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - " + "use gnulib module gettimeofday for portability"); +# endif # endif #ifdef __cplusplus diff --git a/gl/tests/test-getdelim.c b/gl/tests/test-getdelim.c index df9966497e..a5df49f1dd 100644 --- a/gl/tests/test-getdelim.c +++ b/gl/tests/test-getdelim.c @@ -33,13 +33,13 @@ int main (void) { FILE *f; - char *line = NULL; - size_t len = 0; + char *line; + size_t len; ssize_t result; /* Create test file. */ f = fopen ("test-getdelim.txt", "wb"); - if (!f || fwrite ("anbcnd\0f", 1, 8, f) != 8 || fclose (f) != 0) + if (!f || fwrite ("anAnbcnd\0f", 1, 10, f) != 10 || fclose (f) != 0) { fputs ("Failed to create sample file.\n", stderr); remove ("test-getdelim.txt"); @@ -54,13 +54,24 @@ main (void) } /* Test initial allocation, which must include trailing NUL. */ + line = NULL; + len = 0; result = getdelim (&line, &len, 'n', f); ASSERT (result == 2); ASSERT (strcmp (line, "an") == 0); ASSERT (2 < len); + free (line); - /* Test growth of buffer. */ + /* Test initial allocation again, with line = NULL and len != 0. */ + line = NULL; + len = (size_t)(~0) / 4; + result = getdelim (&line, &len, 'n', f); + ASSERT (result == 2); + ASSERT (strcmp (line, "An") == 0); + ASSERT (2 < len); free (line); + + /* Test growth of buffer. */ line = malloc (1); len = 1; result = getdelim (&line, &len, 'n', f); diff --git a/gl/tests/test-getline.c b/gl/tests/test-getline.c index 7112b52a4c..6a661ce530 100644 --- a/gl/tests/test-getline.c +++ b/gl/tests/test-getline.c @@ -33,13 +33,13 @@ int main (void) { FILE *f; - char *line = NULL; - size_t len = 0; + char *line; + size_t len; ssize_t result; /* Create test file. */ f = fopen ("test-getline.txt", "wb"); - if (!f || fwrite ("a\nbc\nd\0f", 1, 8, f) != 8 || fclose (f) != 0) + if (!f || fwrite ("a\nA\nbc\nd\0f", 1, 10, f) != 10 || fclose (f) != 0) { fputs ("Failed to create sample file.\n", stderr); remove ("test-getline.txt"); @@ -54,13 +54,24 @@ main (void) } /* Test initial allocation, which must include trailing NUL. */ + line = NULL; + len = 0; result = getline (&line, &len, f); ASSERT (result == 2); ASSERT (strcmp (line, "a\n") == 0); ASSERT (2 < len); + free (line); - /* Test growth of buffer, must not leak. */ + /* Test initial allocation again, with line = NULL and len != 0. */ + line = NULL; + len = (size_t)(~0) / 4; + result = getline (&line, &len, f); + ASSERT (result == 2); + ASSERT (strcmp (line, "A\n") == 0); + ASSERT (2 < len); free (line); + + /* Test growth of buffer, must not leak. */ line = malloc (1); len = 0; result = getline (&line, &len, f); diff --git a/gl/tests/test-gettimeofday.c b/gl/tests/test-gettimeofday.c index 2a07814bb9..ff2bc72b54 100644 --- a/gl/tests/test-gettimeofday.c +++ b/gl/tests/test-gettimeofday.c @@ -20,7 +20,8 @@ #include <sys/time.h> #include "signature.h" -SIGNATURE_CHECK (gettimeofday, int, (struct timeval *, void *)); +SIGNATURE_CHECK (gettimeofday, int, + (struct timeval *, GETTIMEOFDAY_TIMEZONE *)); #include <time.h> @@ -42,8 +43,5 @@ main (void) fprintf (stderr, "gettimeofday still clobbers the localtime buffer!\n"); return 1; } - else - { - return 0; - } + return 0; } |