Commit 69482508 authored by Bruno Haible's avatar Bruno Haible

New module 'arg-nonnull'. Declare which arguments expect non-NULL values.

parent 441aa304
2009-12-10 Bruno Haible <bruno@clisp.org>
Declare which arguments expect non-NULL values, for GCC and clang.
* build-aux/arg-nonnull.h: New file.
* modules/arg-nonnull: New file.
* lib/arpa_inet.in.h (_GL_ARG_NONNULL): New placeholder.
(inet_ntop, inet_pton): Use it.
* lib/dirent.in.h (_GL_ARG_NONNULL): New placeholder.
(closedir, dirfd, opendir, scandir, alphasort): Use it.
* lib/fcntl.in.h (_GL_ARG_NONNULL): New placeholder.
(open, openat): Use it.
* lib/fnmatch.in.h (_GL_ARG_NONNULL): New placeholder.
(fnmatch): Use it.
* lib/getopt.in.h (_GL_ARG_NONNULL): New placeholder.
(getopt, getopt_long, getopt_long_only): Use it.
* lib/glob.in.h (_GL_ARG_NONNULL): New placeholder.
* lib/glob-libc.h (glob, globfree, glob64, globfree64, glob_pattern_p):
Use it.
* lib/iconv.in.h (_GL_ARG_NONNULL): New placeholder.
(iconv_open): Use it.
* lib/inttypes.in.h (_GL_ARG_NONNULL): New placeholder.
(strtoimax, strtoumax): Use it.
* lib/locale.in.h (_GL_ARG_NONNULL): New placeholder.
(duplocale): Use it.
* lib/math.in.h (_GL_ARG_NONNULL): New placeholder.
(frexp, frexpl): Use it.
* lib/netdb.in.h (_GL_ARG_NONNULL): New placeholder.
(getaddrinfo, freeaddrinfo, getnameinfo): Use it.
* lib/search.in.h (_GL_ARG_NONNULL): New placeholder.
(tsearch, tfind, tdelete, twalk): Use it.
* lib/signal.in.h (_GL_ARG_NONNULL): New placeholder.
(sigismember, sigemptyset, sigaddset, sigdelset, sigfillset,
sigpending): Use it.
* lib/spawn.in.h (_GL_ARG_NONNULL): New placeholder.
(posix_spawn, posix_spawnp, posix_spawnattr_init,
posix_spawnattr_destroy, posix_spawnattr_getsigdefault,
posix_spawnattr_setsigdefault, posix_spawnattr_getsigmask,
posix_spawnattr_setsigmask, posix_spawnattr_getflags,
posix_spawnattr_setflags, posix_spawnattr_getpgroup,
posix_spawnattr_setpgroup, posix_spawnattr_getschedpolicy,
posix_spawnattr_setschedpolicy, posix_spawnattr_getschedparam,
posix_spawnattr_setschedparam, posix_spawn_file_actions_init,
posix_spawn_file_actions_destroy, posix_spawn_file_actions_addopen,
posix_spawn_file_actions_addclose, posix_spawn_file_actions_adddup2):
Use it.
* lib/stdio.in.h (_GL_ARG_NONNULL): New placeholder.
(dprintf, fclose, fopen, fprintf, fpurge, fputc, fputs, freopen,
rpl_fseek, fseeko, rpl_ftell, ftello, fwrite, getdelim, getline,
obstack_printf, obstack_vprintf, popen, printf, putc, puts, remove,
rename, renameat, snprintf, sprintf, asprintf, vasprintf, vdprintf,
vfprintf, vprintf, vsnprintf, vsprintf): Use it.
* lib/stdlib.in.h (_GL_ARG_NONNULL): New placeholder.
(atoll, canonicalize_file_name, getloadavg, getsubopt, mkdtemp,
mkostemp, mkostemps, mkstemp, mkstemps, putenv, srandom_r, initstate_r,
setstate_r, random_r, realpath, rpmatch, setenv, strtod, strtoll,
strtoull, unsetenv): Use it.
* lib/string.in.h (_GL_ARG_NONNULL): New placeholder.
(memchr, memmem, mempcpy, memrchr, rawmemchr, stpcpy, stpncpy,
strchrnul, strdup, strndup, strnlen, strpbrk, strsep, strstr,
strcasestr, strtok_r, mbslen, mbsnlen, mbschr, mbsrchr, mbsstr,
mbscasecmp, mbsncasecmp, mbspcasecmp, mbscasestr, mbscspn, mbspbrk,
mbsspn, mbssep, mbstok_r, strverscmp): Use it.
* lib/strings.in.h (_GL_ARG_NONNULL): New placeholder.
(strcasecmp, strncasecmp): Use it.
* lib/sys_socket.in.h (_GL_ARG_NONNULL): New placeholder.
(rpl_connect, rpl_bind, rpl_getpeername, rpl_getsockname,
rpl_getsockopt, rpl_recv, rpl_send, rpl_recvfrom, rpl_sendto,
rpl_setsockopt): Use it.
* lib/sys_stat.in.h (_GL_ARG_NONNULL): New placeholder.
(fchmodat, fstat, fstatat, lchmod, rpl_lstat, mkdir, mkdirat, mkfifo,
mkfifoat, mknod, mknodat, stat, utimensat): Use it.
* lib/sys_time.in.h (_GL_ARG_NONNULL): New placeholder.
(gettimeofday): Use it.
* lib/sys_times.in.h (_GL_ARG_NONNULL): New placeholder.
(times): Use it.
* lib/sys_utsname.in.h (_GL_ARG_NONNULL): New placeholder.
(uname): Use it.
* lib/time.in.h (_GL_ARG_NONNULL): New placeholder.
(nanosleep, mktime, localtime_r, gmtime_r, strptime, timegm): Use it.
* lib/unistd.in.h (_GL_ARG_NONNULL): New placeholder.
(chown, euidaccess, faccessat, _gl_register_fd, fchownat,
getdomainname, gethostname, getlogin_r, lchown, link, linkat, pipe2,
pread, readlink, readlinkat, rmdir, symlink, symlinkat, unlink,
unlinkat, write): Use it.
* lib/wchar.in.h (_GL_ARG_NONNULL): New placeholder.
(mbsrtowcs, mbsnrtowcs, wcsrtombs, wcsnrtombs): Use it.
* lib/argv-iter.h: Include arg-nonnull.h.
(_ATTRIBUTE_NONNULL_): Remove macro.
(argv_iter_init_argv, argv_iter_init_stream, argv_iter,
argv_iter_n_args, argv_iter_free): Use _GL_ARG_NONNULL.
* lib/canonicalize-lgpl.c (_GL_ARG_NONNULL): Define, to defeat gcc
optimization.
* lib/getaddrinfo.c (_GL_ARG_NONNULL): Likewise.
* lib/getdelim.c (_GL_ARG_NONNULL): Likewise.
* lib/glob.c (_GL_ARG_NONNULL): Likewise.
* lib/random_r.c (_GL_ARG_NONNULL): Likewise.
* lib/setenv.c (_GL_ARG_NONNULL): Likewise.
* lib/strtod.c (_GL_ARG_NONNULL): Likewise.
* lib/tsearch.c (_GL_ARG_NONNULL): Likewise.
* lib/unsetenv.c (_GL_ARG_NONNULL): Likewise.
* modules/arpa_inet (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into arpa/inet.h.
* modules/dirent (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into dirent.h.
* modules/fcntl-h (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into fcntl.h.
* modules/fnmatch (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into fnmatch.h.
* modules/getopt-posix (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into getopt.h.
* modules/glob (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into glob.h.
* modules/iconv_open (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into iconv.h.
* modules/inttypes (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into inttypes.h.
* modules/locale (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into locale.h.
* modules/math (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into math.h.
* modules/netdb (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into netdb.h.
* modules/search (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into search.h.
* modules/signal (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into signal.h.
* modules/spawn (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into spawn.h.
* modules/stdio (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into stdio.h.
* modules/stdlib (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into stdlib.h.
* modules/string (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into string.h.
* modules/strings (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into strings.h.
* modules/sys_socket (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into sys/socket.h.
* modules/sys_stat (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into sys/stat.h.
* modules/sys_time (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into sys/time.h.
* modules/sys_times (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into sys/times.h.
* modules/sys_utsname (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into sys/utsname.h.
* modules/time (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into time.h.
* modules/unistd (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into unistd.h.
* modules/wchar (Depends-on): Add arg-nonnull.
(Makefile.am): Insert arg-nonnull.h into wchar.h.
* modules/argv-iter (Depends-on): Add arg-nonnull.
* tests/test-canonicalize.c (null_ptr): New function.
(main): Use it.
* tests/test-canonicalize-lgpl.c (null_ptr): New function.
(main): Use it.
* tests/test-memmem.c (null_ptr): New function.
(main): Use it.
Reported by Jim Meyering.
2009-12-10 Bruno Haible <bruno@clisp.org>
Use spaces for indentation, not tabs.
/* A C macro for declaring that specific arguments must not be NULL.
Copyright (C) 2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser 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 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
that the values passed as arguments n, ..., m must be non-NULL pointers.
n = 1 stands for the first argument, n = 2 for the second argument etc. */
#ifndef _GL_ARG_NONNULL
# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
# else
# define _GL_ARG_NONNULL(params)
# endif
#endif
......@@ -17,16 +17,12 @@
#include <stdio.h>
#include <stdbool.h>
/* Definition of _GL_ARG_NONNULL. */
#include "arg-nonnull.h"
struct argv_iterator;
enum argv_iter_err;
#undef _ATTRIBUTE_NONNULL_
#if __GNUC__ == 3 && __GNUC_MINOR__ >= 3 || 3 < __GNUC__
# define _ATTRIBUTE_NONNULL_(m) __attribute__ ((__nonnull__ (m)))
#else
# define _ATTRIBUTE_NONNULL_(m)
#endif
enum argv_iter_err
{
AI_ERR_OK = 1,
......@@ -36,12 +32,12 @@ enum argv_iter_err
};
struct argv_iterator *argv_iter_init_argv (char **argv)
_ATTRIBUTE_NONNULL_ (1);
_GL_ARG_NONNULL ((1));
struct argv_iterator *argv_iter_init_stream (FILE *fp)
_ATTRIBUTE_NONNULL_ (1);
_GL_ARG_NONNULL ((1));
char *argv_iter (struct argv_iterator *, enum argv_iter_err *)
_ATTRIBUTE_NONNULL_ (1) _ATTRIBUTE_NONNULL_ (2);
_GL_ARG_NONNULL ((1, 2));
size_t argv_iter_n_args (struct argv_iterator const *)
_ATTRIBUTE_NONNULL_ (1);
_GL_ARG_NONNULL ((1));
void argv_iter_free (struct argv_iterator *)
_ATTRIBUTE_NONNULL_ (1);
_GL_ARG_NONNULL ((1));
/* A GNU-like <arpa/inet.h>.
Copyright (C) 2005-2006, 2008 Free Software Foundation, Inc.
Copyright (C) 2005-2006, 2008-2009 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
......@@ -38,6 +38,8 @@
/* The definition of GL_LINK_WARNING is copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
#ifdef __cplusplus
extern "C" {
#endif
......@@ -60,7 +62,8 @@ extern "C" {
For more details, see the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/inet_ntop.html>. */
extern const char *inet_ntop (int af, const void *restrict src,
char *restrict dst, socklen_t cnt);
char *restrict dst, socklen_t cnt)
_GL_ARG_NONNULL ((2, 3));
# endif
#elif defined GNULIB_POSIXCHECK
# undef inet_ntop
......@@ -72,7 +75,8 @@ extern const char *inet_ntop (int af, const void *restrict src,
#if @GNULIB_INET_PTON@
# if !@HAVE_DECL_INET_PTON@
extern int inet_pton (int af, const char *restrict src, void *restrict dst);
extern int inet_pton (int af, const char *restrict src, void *restrict dst)
_GL_ARG_NONNULL ((2, 3));
# endif
#elif defined GNULIB_POSIXCHECK
# undef inet_pton
......
......@@ -21,6 +21,10 @@
#if !HAVE_CANONICALIZE_FILE_NAME || !FUNC_REALPATH_WORKS || defined _LIBC
/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
optimizes away the name == NULL test below. */
#define _GL_ARG_NONNULL(params)
/* Specification. */
#include <stdlib.h>
......
......@@ -28,6 +28,8 @@
/* The definition of GL_LINK_WARNING is copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
#ifdef __cplusplus
extern "C" {
......@@ -37,14 +39,14 @@ extern "C" {
#if @REPLACE_CLOSEDIR@
# define closedir rpl_closedir
extern int closedir (DIR *);
extern int closedir (DIR *) _GL_ARG_NONNULL ((1));
#endif
#if @GNULIB_DIRFD@
# if !@HAVE_DECL_DIRFD@ && !defined dirfd
/* Return the file descriptor associated with the given directory stream,
or -1 if none exists. */
extern int dirfd (DIR const *dir);
extern int dirfd (DIR const *dir) _GL_ARG_NONNULL ((1));
# endif
#elif defined GNULIB_POSIXCHECK
# undef dirfd
......@@ -77,7 +79,7 @@ extern DIR *fdopendir (int fd);
#if @REPLACE_OPENDIR@
# define opendir rpl_opendir
extern DIR * opendir (const char *);
extern DIR * opendir (const char *) _GL_ARG_NONNULL ((1));
#endif
#if @GNULIB_SCANDIR@
......@@ -88,7 +90,8 @@ extern DIR * opendir (const char *);
# if !@HAVE_SCANDIR@
extern int scandir (const char *dir, struct dirent ***namelist,
int (*filter) (const struct dirent *),
int (*cmp) (const struct dirent **, const struct dirent **));
int (*cmp) (const struct dirent **, const struct dirent **))
_GL_ARG_NONNULL ((1, 2, 4));
# endif
#elif defined GNULIB_POSIXCHECK
# undef scandir
......@@ -101,7 +104,8 @@ extern int scandir (const char *dir, struct dirent ***namelist,
#if @GNULIB_ALPHASORT@
/* Compare two 'struct dirent' entries alphabetically. */
# if !@HAVE_ALPHASORT@
extern int alphasort (const struct dirent **, const struct dirent **);
extern int alphasort (const struct dirent **, const struct dirent **)
_GL_ARG_NONNULL ((1, 2));
# endif
#elif defined GNULIB_POSIXCHECK
# undef alphasort
......
......@@ -46,6 +46,8 @@
/* The definition of GL_LINK_WARNING is copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
/* Declare overridden functions. */
......@@ -57,7 +59,7 @@ extern "C" {
# if @REPLACE_OPEN@
# undef open
# define open rpl_open
extern int open (const char *filename, int flags, ...);
extern int open (const char *filename, int flags, ...) _GL_ARG_NONNULL ((1));
# endif
#endif
......@@ -67,7 +69,8 @@ extern int open (const char *filename, int flags, ...);
# define openat rpl_openat
# endif
# if !@HAVE_OPENAT@ || @REPLACE_OPENAT@
int openat (int fd, char const *file, int flags, /* mode_t mode */ ...);
int openat (int fd, char const *file, int flags, /* mode_t mode */ ...)
_GL_ARG_NONNULL ((2));
# endif
#elif defined GNULIB_POSIXCHECK
# undef openat
......
/* Copyright (C) 1991, 1992, 1993, 1996, 1997, 1998, 1999, 2001, 2002, 2003,
2005, 2007 Free Software Foundation, Inc.
2005, 2007, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
......@@ -20,6 +20,8 @@
#ifndef _FNMATCH_H
#define _FNMATCH_H 1
/* The definition of _GL_ARG_NONNULL is copied here. */
#ifdef __cplusplus
extern "C" {
#endif
......@@ -56,7 +58,8 @@ extern "C" {
/* Match NAME against the file name pattern PATTERN,
returning zero if it matches, FNM_NOMATCH if not. */
extern int fnmatch (const char *__pattern, const char *__name,
int __flags);
int __flags)
_GL_ARG_NONNULL ((1, 2));
#ifdef __cplusplus
}
......
/* Get address information (partial implementation).
Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2007, 2008 Free Software
Foundation, Inc.
Copyright (C) 1997, 2001-2002, 2004-2009 Free Software Foundation, Inc.
Contributed by Simon Josefsson <simon@josefsson.org>.
This program is free software; you can redistribute it and/or modify
......@@ -19,6 +18,10 @@
#include <config.h>
/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
optimizes away the sa == NULL test below. */
#define _GL_ARG_NONNULL(params)
#include <netdb.h>
#if HAVE_NETINET_IN_H
......
......@@ -21,6 +21,10 @@
#include <config.h>
/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
optimizes away the lineptr == NULL || n == NULL || fp == NULL tests below. */
#define _GL_ARG_NONNULL(params)
#include <stdio.h>
#include <limits.h>
......
......@@ -121,6 +121,8 @@
# endif
#endif
/* The definition of _GL_ARG_NONNULL is copied here. */
#ifdef __cplusplus
extern "C" {
#endif
......@@ -222,17 +224,17 @@ struct option
the environment, then do not permute arguments. */
extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
__THROW;
__THROW _GL_ARG_NONNULL ((2, 3));
#ifndef __need_getopt
extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind)
__THROW;
__THROW _GL_ARG_NONNULL ((2, 3));
extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind)
__THROW;
__THROW _GL_ARG_NONNULL ((2, 3));
#endif
......
/* Copyright (C) 1991,92,95-98,2000,2001,2004-2007 Free Software Foundation, Inc.
/* Copyright (C) 1991,92,95-98,2000,2001,2004-2007, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
......@@ -173,10 +173,10 @@ typedef struct
#if !defined __USE_FILE_OFFSET64 || __GNUC__ < 2 || defined __GLOB_GNULIB
extern int glob (const char *_Restrict_ __pattern, int __flags,
int (*__errfunc) (const char *, int),
glob_t *_Restrict_ __pglob) __THROW;
glob_t *_Restrict_ __pglob) __THROW _GL_ARG_NONNULL ((1, 4));
/* Free storage allocated in PGLOB by a previous `glob' call. */
extern void globfree (glob_t *__pglob) __THROW;
extern void globfree (glob_t *__pglob) __THROW _GL_ARG_NONNULL ((1));
#else
extern int __REDIRECT_NTH (glob, (const char *_Restrict_ __pattern,
int __flags,
......@@ -189,9 +189,10 @@ extern void __REDIRECT_NTH (globfree, (glob_t *__pglob), globfree64);
#if defined __USE_LARGEFILE64 && !defined __GLOB_GNULIB
extern int glob64 (const char *_Restrict_ __pattern, int __flags,
int (*__errfunc) (const char *, int),
glob64_t *_Restrict_ __pglob) __THROW;
glob64_t *_Restrict_ __pglob)
__THROW _GL_ARG_NONNULL ((1, 4));
extern void globfree64 (glob64_t *__pglob) __THROW;
extern void globfree64 (glob64_t *__pglob) __THROW _GL_ARG_NONNULL ((1));
#endif
......@@ -201,7 +202,8 @@ extern void globfree64 (glob64_t *__pglob) __THROW;
This function is not part of the interface specified by POSIX.2
but several programs want to use it. */
extern int glob_pattern_p (const char *__pattern, int __quote) __THROW;
extern int glob_pattern_p (const char *__pattern, int __quote)
__THROW _GL_ARG_NONNULL ((1));
#endif
__END_DECLS
......
......@@ -19,6 +19,10 @@
# include <config.h>
#endif
/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
optimizes away the pattern == NULL || pglob == NULL tests below. */
#define _GL_ARG_NONNULL(params)
#include <glob.h>
#include <errno.h>
......
/* glob.h -- Find a path matching a pattern.
Copyright (C) 2005-2007 Free Software Foundation, Inc.
Copyright (C) 2005-2007, 2009 Free Software Foundation, Inc.
Written by Derek Price <derek@ximbiot.com> & Paul Eggert <eggert@CS.UCLA.EDU>
......@@ -40,6 +40,8 @@
# define __THROW
#endif
/* The definition of _GL_ARG_NONNULL is copied here. */
#ifndef __size_t
# define __size_t size_t
#endif
......
/* A GNU-like <iconv.h>.
Copyright (C) 2007-2008 Free Software Foundation, Inc.
Copyright (C) 2007-2009 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
......@@ -28,6 +28,8 @@
#ifndef _GL_ICONV_H
#define _GL_ICONV_H
/* The definition of _GL_ARG_NONNULL is copied here. */
#ifdef __cplusplus
extern "C" {
#endif
......@@ -37,7 +39,8 @@ extern "C" {
/* An iconv_open wrapper that supports the IANA standardized encoding names
("ISO-8859-1" etc.) as far as possible. */
# define iconv_open rpl_iconv_open
extern iconv_t iconv_open (const char *tocode, const char *fromcode);
extern iconv_t iconv_open (const char *tocode, const char *fromcode)
_GL_ARG_NONNULL ((1, 2));
#endif
#if @REPLACE_ICONV_UTF@
......
......@@ -47,6 +47,8 @@
/* The definition of GL_LINK_WARNING is copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
/* 7.8.1 Macros for format specifiers */
#if ! defined __cplusplus || defined __STDC_FORMAT_MACROS
......@@ -1066,7 +1068,7 @@ extern imaxdiv_t imaxdiv (intmax_t, intmax_t);
#if @GNULIB_STRTOIMAX@
# if !@HAVE_DECL_STRTOIMAX@
extern intmax_t strtoimax (const char *, char **, int);
extern intmax_t strtoimax (const char *, char **, int) _GL_ARG_NONNULL ((1));
# endif
#elif defined GNULIB_POSIXCHECK
# undef strtoimax
......@@ -1078,7 +1080,7 @@ extern intmax_t strtoimax (const char *, char **, int);
#if @GNULIB_STRTOUMAX@
# if !@HAVE_DECL_STRTOUMAX@
extern uintmax_t strtoumax (const char *, char **, int);
extern uintmax_t strtoumax (const char *, char **, int) _GL_ARG_NONNULL ((1));
# endif
#elif defined GNULIB_POSIXCHECK
# undef strtoumax
......
......@@ -34,6 +34,8 @@
# include <xlocale.h>
#endif
/* The definition of _GL_ARG_NONNULL is copied here. */
/* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C.
On systems that don't define it, use the same value as GNU libintl. */
#if !defined LC_MESSAGES
......@@ -44,7 +46,7 @@
# if @REPLACE_DUPLOCALE@
# undef duplocale
# define duplocale rpl_duplocale
extern locale_t duplocale (locale_t locale);
extern locale_t duplocale (locale_t locale) _GL_ARG_NONNULL ((1));
# endif
#elif defined GNULIB_POSIXCHECK
# undef duplocale
......
......@@ -30,6 +30,8 @@
/* The definition of GL_LINK_WARNING is copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
#ifdef __cplusplus
extern "C" {
......@@ -74,7 +76,7 @@ _NaN ()
#if @GNULIB_FREXP@
# if @REPLACE_FREXP@
# define frexp rpl_frexp
extern double frexp (double x, int *expptr);
extern double frexp (double x, int *expptr) _GL_ARG_NONNULL ((2));
# endif
#elif defined GNULIB_POSIXCHECK
# undef frexp
......@@ -211,7 +213,7 @@ extern long double floorl (long double x);
# define frexpl rpl_frexpl
#endif
#if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
extern long double frexpl (long double x, int *expptr);
extern long double frexpl (long double x, int *expptr) _GL_ARG_NONNULL ((2));
#endif
#if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
# undef frexpl
......
/* Provide a netdb.h header file for systems lacking it (read: MinGW).
Copyright (C) 2008 Free Software Foundation, Inc.
Copyright (C) 2008-2009 Free Software Foundation, Inc.
Written by Simon Josefsson.
This program is free software; you can redistribute it and/or modify
......@@ -39,6 +39,8 @@
/* Get netdb.h definitions such as struct hostent for MinGW. */
#include <sys/socket.h>
/* The definition of _GL_ARG_NONNULL is copied here. */
/* Declarations for a platform that lacks <netdb.h>, or where it is
incomplete. */
......@@ -141,14 +143,15 @@ struct addrinfo
extern int getaddrinfo (const char *restrict nodename,
const char *restrict servname,
const struct addrinfo *restrict hints,
struct addrinfo **restrict res);
struct addrinfo **restrict res)
_GL_ARG_NONNULL ((4));
# endif
# if !@HAVE_DECL_FREEADDRINFO@
/* Free `addrinfo' structure AI including associated storage.
For more details, see the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
extern void freeaddrinfo (struct addrinfo *ai);
extern void freeaddrinfo (struct addrinfo *ai) _GL_ARG_NONNULL ((1));
# endif
# if !@HAVE_DECL_GAI_STRERROR@
......@@ -165,7 +168,8 @@ extern const char *gai_strerror (int ecode);
extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
char *restrict node, socklen_t nodelen,
char *restrict service, socklen_t servicelen,
int flags);
int flags)
_GL_ARG_NONNULL ((1));
# endif
/* Possible flags for getnameinfo. */
......
/*
Copyright (C) 1995, 2005, 2008 Free Software Foundation, Inc.
Copyright (C) 1995, 2005, 2008-2009 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
......@@ -52,6 +52,11 @@
#include <config.h>
/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
optimizes away the buf == NULL, arg_state == NULL, result == NULL tests
below. */
#define _GL_ARG_NONNULL(params)
#include <errno.h>
#include <limits.h>
#include <stddef.h>
......
/* A GNU-like <search.h>.
Copyright (C) 2007-2008 Free Software Foundation, Inc.
Copyright (C) 2007-2009 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
......@@ -31,6 +31,8 @@
/* The definition of GL_LINK_WARNING is copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
#ifdef __cplusplus
extern "C" {
......@@ -65,18 +67,21 @@ VISIT;
If one is found, it is returned. Otherwise, a new element equal to KEY
is inserted in the tree and is returned. */
extern void * tsearch (const void *key, void **vrootp,
int (*compar) (const void *, const void *));
int (*compar) (const void *, const void *))
_GL_ARG_NONNULL ((1, 2, 3));
/* Searches an element in the tree *VROOTP that compares equal to KEY.
If one is found, it is returned. Otherwise, NULL is returned. */
extern void * tfind (const void *key, void *const *vrootp,
int (*compar) (const void *, const void *));
int (*compar) (const void *, const void *))
_GL_ARG_NONNULL ((1, 2, 3));
/* Searches an element in the tree *VROOTP that compares equal to KEY.
If one is found, it is removed from the tree, and its parent node is
returned. Otherwise, NULL is returned. */
extern void * tdelete (const void *key, void **vrootp,
int (*compar) (const void *, const void *));
int (*compar) (const void *, const void *))
_GL_ARG_NONNULL ((1, 2, 3));
/* Perform a depth-first, left-to-right traversal of the tree VROOT.
The ACTION function is called:
......@@ -90,7 +95,8 @@ extern void * tdelete (const void *key, void **vrootp,
2. an indicator which visit of the node this is,
3. the level of the node in the tree (0 for the root). */
extern void twalk (const void *vroot,
void (*action) (const void *, VISIT, int));
void (*action) (const void *, VISIT, int))
_GL_ARG_NONNULL ((2));
# endif
#elif defined GNULIB_POSIXCHECK
......
......@@ -17,6 +17,11 @@
#if !_LIBC
# include <config.h>
#endif
/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
optimizes away the name == NULL test below. */
#define _GL_ARG_NONNULL(params)
#include <alloca.h>
/* Specification. */
......
......@@ -37,6 +37,8 @@
/* The definition of GL_LINK_WARNING is copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
/* Define pid_t, uid_t.
Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>. */
#include <sys/types.h>
......@@ -82,22 +84,22 @@ typedef unsigned int sigset_t;
# endif
/* Test whether a given signal is contained in a signal set. */
extern int sigismember (const sigset_t *set, int sig);
extern int sigismember (const sigset_t *set, int sig) _GL_ARG_NONNULL ((1));
/* Initialize a signal set to the empty set. */