mirror of
git://sourceware.org/git/glibc.git
synced 2024-12-09 04:11:27 +08:00
acd7f096d7
This patch completes the headers cleanup consequent on removal of _BSD_SOURCE and _SVID_SOURCE (apart from any subsequent deprecations): * #endif conditionals that referred to BSD or SVID are updated. * Redundant __USE_* tests in cases involving __USE_MISC are removed. This includes cases such as __USE_MISC || __USE_ISOC99, where __USE_MISC is redundant (because __USE_MISC is only ever defined in the default / _DEFAULT_SOURCE / _GNU_SOURCE case, when __USE_ISOC99 is also defined; the same applies to the non-XSI-extended POSIX versions), and cases involving __USE_GNU, where __USE_GNU is redundant (because if __USE_GNU is defined, so are the other __USE_* macros). There may well be other cases of __USE_FOO || __USE_BAR tests that could be simplified because one macro implies the other; this patch only addresses cases involving __USE_MISC. Tested x86_64. * bits/fcntl.h [__USE_MISC]: Remove redundant conditionals. * bits/sigaction.h [__USE_MISC]: Likewise. * bits/waitstatus.h: Update #endif comments. * ctype/ctype.h: Likewise. * dirent/dirent.h: Likewise. [__USE_MISC]: Remove redundant conditionals. * grp/grp.h: Update #endif comments. [__USE_GNU]: Remove redundant conditionals. [__USE_MISC]: Likewise. * inet/netinet/in.h [__USE_GNU]: Likewise. * io/sys/stat.h [__USE_MISC]: Likewise. * libio/bits/stdio-ldbl.h [__USE_MISC]: Likewise. * libio/bits/stdio.h: Update #endif comments. [__USE_MISC]: Remove redundant conditionals. * libio/bits/stdio2.h [__USE_MISC]: Likewise. * libio/stdio.h: Update #endif comments. [__USE_MISC]: Remove redundant conditionals. * math/bits/math-finite.h [__USE_MISC]: Likewise. * math/bits/mathcalls.h [__USE_MISC]: Likewise. * math/math.h: Update #else and #endif comments. [__USE_MISC]: Remove redundant conditionals. * misc/sys/uio.h: Update #endif comments. * posix/bits/unistd.h [__USE_MISC]: Remove redundant conditionals. * posix/glob.h [__USE_MISC]: Likewise. * posix/sys/types.h: Update #endif comments. [__USE_MISC]: Remove redundant conditionals. * posix/sys/wait.h: Update #endif comments. [__USE_MISC]: Remove redundant conditionals. * posix/unistd.h: Update #endif comments. [__USE_MISC]: Remove redundant conditionals. * pwd/pwd.h [__USE_GNU]: Likewise. [__USE_MISC]: Likewise. * resolv/netdb.h [__USE_GNU]: Likewise. * signal/signal.h: Update #endif comments. [__USE_MISC]: Remove redundant conditionals. * stdlib/stdlib.h: Update #else and #endif comments. [__USE_MISC]: Remove redundant conditionals. [__USE_GNU]: Likewise. * string/bits/string2.h [__USE_MISC]: Likewise. * string/string.h: Update #endif comments. [__USE_MISC]: Remove redundant conditionals. * sysdeps/m68k/m680x0/fpu/bits/mathinline.h [__USE_MISC]: Likewise. * sysdeps/mach/hurd/bits/fcntl.h [__USE_MISC]: Likewise. * sysdeps/mach/hurd/bits/stat.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/alpha/bits/sigaction.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/alpha/bits/stat.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/bits/fcntl-linux.h: Update #endif comments. [__USE_MISC]: Remove redundant conditionals. * sysdeps/unix/sysv/linux/bits/in.h [__USE_GNU]: Likewise. * sysdeps/unix/sysv/linux/bits/sigaction.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/bits/socket.h [__USE_GNU]: Likewise. * sysdeps/unix/sysv/linux/bits/stat.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/ia64/bits/sigaction.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/m68k/bits/stat.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/mips/bits/sigaction.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/mips/bits/stat.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/powerpc/bits/stat.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/s390/bits/sigaction.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/s390/bits/stat.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/sparc/bits/sigaction.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/sparc/bits/stat.h [__USE_MISC]: Likewise. * sysdeps/unix/sysv/linux/x86/bits/stat.h [__USE_MISC]: Likewise. * sysdeps/x86/bits/string.h: Update #endif comments. * sysdeps/x86/fpu/bits/mathinline.h [__USE_MISC]: Remove redundant conditionals. * time/sys/time.h: Update #endif comments. * time/time.h: Likewise. [__USE_MISC]: Remove redundant conditionals.
386 lines
13 KiB
C
386 lines
13 KiB
C
/* Checking macros for unistd functions.
|
|
Copyright (C) 2005-2014 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library 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.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library 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 the GNU C Library; if not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef _UNISTD_H
|
|
# error "Never include <bits/unistd.h> directly; use <unistd.h> instead."
|
|
#endif
|
|
|
|
extern ssize_t __read_chk (int __fd, void *__buf, size_t __nbytes,
|
|
size_t __buflen) __wur;
|
|
extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf,
|
|
size_t __nbytes), read) __wur;
|
|
extern ssize_t __REDIRECT (__read_chk_warn,
|
|
(int __fd, void *__buf, size_t __nbytes,
|
|
size_t __buflen), __read_chk)
|
|
__wur __warnattr ("read called with bigger length than size of "
|
|
"the destination buffer");
|
|
|
|
__fortify_function __wur ssize_t
|
|
read (int __fd, void *__buf, size_t __nbytes)
|
|
{
|
|
if (__bos0 (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__nbytes))
|
|
return __read_chk (__fd, __buf, __nbytes, __bos0 (__buf));
|
|
|
|
if (__nbytes > __bos0 (__buf))
|
|
return __read_chk_warn (__fd, __buf, __nbytes, __bos0 (__buf));
|
|
}
|
|
return __read_alias (__fd, __buf, __nbytes);
|
|
}
|
|
|
|
#ifdef __USE_UNIX98
|
|
extern ssize_t __pread_chk (int __fd, void *__buf, size_t __nbytes,
|
|
__off_t __offset, size_t __bufsize) __wur;
|
|
extern ssize_t __pread64_chk (int __fd, void *__buf, size_t __nbytes,
|
|
__off64_t __offset, size_t __bufsize) __wur;
|
|
extern ssize_t __REDIRECT (__pread_alias,
|
|
(int __fd, void *__buf, size_t __nbytes,
|
|
__off_t __offset), pread) __wur;
|
|
extern ssize_t __REDIRECT (__pread64_alias,
|
|
(int __fd, void *__buf, size_t __nbytes,
|
|
__off64_t __offset), pread64) __wur;
|
|
extern ssize_t __REDIRECT (__pread_chk_warn,
|
|
(int __fd, void *__buf, size_t __nbytes,
|
|
__off_t __offset, size_t __bufsize), __pread_chk)
|
|
__wur __warnattr ("pread called with bigger length than size of "
|
|
"the destination buffer");
|
|
extern ssize_t __REDIRECT (__pread64_chk_warn,
|
|
(int __fd, void *__buf, size_t __nbytes,
|
|
__off64_t __offset, size_t __bufsize),
|
|
__pread64_chk)
|
|
__wur __warnattr ("pread64 called with bigger length than size of "
|
|
"the destination buffer");
|
|
|
|
# ifndef __USE_FILE_OFFSET64
|
|
__fortify_function __wur ssize_t
|
|
pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset)
|
|
{
|
|
if (__bos0 (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__nbytes))
|
|
return __pread_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
|
|
|
|
if ( __nbytes > __bos0 (__buf))
|
|
return __pread_chk_warn (__fd, __buf, __nbytes, __offset,
|
|
__bos0 (__buf));
|
|
}
|
|
return __pread_alias (__fd, __buf, __nbytes, __offset);
|
|
}
|
|
# else
|
|
__fortify_function __wur ssize_t
|
|
pread (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
|
|
{
|
|
if (__bos0 (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__nbytes))
|
|
return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
|
|
|
|
if ( __nbytes > __bos0 (__buf))
|
|
return __pread64_chk_warn (__fd, __buf, __nbytes, __offset,
|
|
__bos0 (__buf));
|
|
}
|
|
|
|
return __pread64_alias (__fd, __buf, __nbytes, __offset);
|
|
}
|
|
# endif
|
|
|
|
# ifdef __USE_LARGEFILE64
|
|
__fortify_function __wur ssize_t
|
|
pread64 (int __fd, void *__buf, size_t __nbytes, __off64_t __offset)
|
|
{
|
|
if (__bos0 (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__nbytes))
|
|
return __pread64_chk (__fd, __buf, __nbytes, __offset, __bos0 (__buf));
|
|
|
|
if ( __nbytes > __bos0 (__buf))
|
|
return __pread64_chk_warn (__fd, __buf, __nbytes, __offset,
|
|
__bos0 (__buf));
|
|
}
|
|
|
|
return __pread64_alias (__fd, __buf, __nbytes, __offset);
|
|
}
|
|
# endif
|
|
#endif
|
|
|
|
#if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K
|
|
extern ssize_t __readlink_chk (const char *__restrict __path,
|
|
char *__restrict __buf, size_t __len,
|
|
size_t __buflen)
|
|
__THROW __nonnull ((1, 2)) __wur;
|
|
extern ssize_t __REDIRECT_NTH (__readlink_alias,
|
|
(const char *__restrict __path,
|
|
char *__restrict __buf, size_t __len), readlink)
|
|
__nonnull ((1, 2)) __wur;
|
|
extern ssize_t __REDIRECT_NTH (__readlink_chk_warn,
|
|
(const char *__restrict __path,
|
|
char *__restrict __buf, size_t __len,
|
|
size_t __buflen), __readlink_chk)
|
|
__nonnull ((1, 2)) __wur __warnattr ("readlink called with bigger length "
|
|
"than size of destination buffer");
|
|
|
|
__fortify_function __nonnull ((1, 2)) __wur ssize_t
|
|
__NTH (readlink (const char *__restrict __path, char *__restrict __buf,
|
|
size_t __len))
|
|
{
|
|
if (__bos (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__len))
|
|
return __readlink_chk (__path, __buf, __len, __bos (__buf));
|
|
|
|
if ( __len > __bos (__buf))
|
|
return __readlink_chk_warn (__path, __buf, __len, __bos (__buf));
|
|
}
|
|
return __readlink_alias (__path, __buf, __len);
|
|
}
|
|
#endif
|
|
|
|
#ifdef __USE_ATFILE
|
|
extern ssize_t __readlinkat_chk (int __fd, const char *__restrict __path,
|
|
char *__restrict __buf, size_t __len,
|
|
size_t __buflen)
|
|
__THROW __nonnull ((2, 3)) __wur;
|
|
extern ssize_t __REDIRECT_NTH (__readlinkat_alias,
|
|
(int __fd, const char *__restrict __path,
|
|
char *__restrict __buf, size_t __len),
|
|
readlinkat)
|
|
__nonnull ((2, 3)) __wur;
|
|
extern ssize_t __REDIRECT_NTH (__readlinkat_chk_warn,
|
|
(int __fd, const char *__restrict __path,
|
|
char *__restrict __buf, size_t __len,
|
|
size_t __buflen), __readlinkat_chk)
|
|
__nonnull ((2, 3)) __wur __warnattr ("readlinkat called with bigger "
|
|
"length than size of destination "
|
|
"buffer");
|
|
|
|
__fortify_function __nonnull ((2, 3)) __wur ssize_t
|
|
__NTH (readlinkat (int __fd, const char *__restrict __path,
|
|
char *__restrict __buf, size_t __len))
|
|
{
|
|
if (__bos (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__len))
|
|
return __readlinkat_chk (__fd, __path, __buf, __len, __bos (__buf));
|
|
|
|
if (__len > __bos (__buf))
|
|
return __readlinkat_chk_warn (__fd, __path, __buf, __len,
|
|
__bos (__buf));
|
|
}
|
|
return __readlinkat_alias (__fd, __path, __buf, __len);
|
|
}
|
|
#endif
|
|
|
|
extern char *__getcwd_chk (char *__buf, size_t __size, size_t __buflen)
|
|
__THROW __wur;
|
|
extern char *__REDIRECT_NTH (__getcwd_alias,
|
|
(char *__buf, size_t __size), getcwd) __wur;
|
|
extern char *__REDIRECT_NTH (__getcwd_chk_warn,
|
|
(char *__buf, size_t __size, size_t __buflen),
|
|
__getcwd_chk)
|
|
__wur __warnattr ("getcwd caller with bigger length than size of "
|
|
"destination buffer");
|
|
|
|
__fortify_function __wur char *
|
|
__NTH (getcwd (char *__buf, size_t __size))
|
|
{
|
|
if (__bos (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__size))
|
|
return __getcwd_chk (__buf, __size, __bos (__buf));
|
|
|
|
if (__size > __bos (__buf))
|
|
return __getcwd_chk_warn (__buf, __size, __bos (__buf));
|
|
}
|
|
return __getcwd_alias (__buf, __size);
|
|
}
|
|
|
|
#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
|
|
extern char *__getwd_chk (char *__buf, size_t buflen)
|
|
__THROW __nonnull ((1)) __wur;
|
|
extern char *__REDIRECT_NTH (__getwd_warn, (char *__buf), getwd)
|
|
__nonnull ((1)) __wur __warnattr ("please use getcwd instead, as getwd "
|
|
"doesn't specify buffer size");
|
|
|
|
__fortify_function __nonnull ((1)) __attribute_deprecated__ __wur char *
|
|
__NTH (getwd (char *__buf))
|
|
{
|
|
if (__bos (__buf) != (size_t) -1)
|
|
return __getwd_chk (__buf, __bos (__buf));
|
|
return __getwd_warn (__buf);
|
|
}
|
|
#endif
|
|
|
|
extern size_t __confstr_chk (int __name, char *__buf, size_t __len,
|
|
size_t __buflen) __THROW;
|
|
extern size_t __REDIRECT_NTH (__confstr_alias, (int __name, char *__buf,
|
|
size_t __len), confstr);
|
|
extern size_t __REDIRECT_NTH (__confstr_chk_warn,
|
|
(int __name, char *__buf, size_t __len,
|
|
size_t __buflen), __confstr_chk)
|
|
__warnattr ("confstr called with bigger length than size of destination "
|
|
"buffer");
|
|
|
|
__fortify_function size_t
|
|
__NTH (confstr (int __name, char *__buf, size_t __len))
|
|
{
|
|
if (__bos (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__len))
|
|
return __confstr_chk (__name, __buf, __len, __bos (__buf));
|
|
|
|
if (__bos (__buf) < __len)
|
|
return __confstr_chk_warn (__name, __buf, __len, __bos (__buf));
|
|
}
|
|
return __confstr_alias (__name, __buf, __len);
|
|
}
|
|
|
|
|
|
extern int __getgroups_chk (int __size, __gid_t __list[], size_t __listlen)
|
|
__THROW __wur;
|
|
extern int __REDIRECT_NTH (__getgroups_alias, (int __size, __gid_t __list[]),
|
|
getgroups) __wur;
|
|
extern int __REDIRECT_NTH (__getgroups_chk_warn,
|
|
(int __size, __gid_t __list[], size_t __listlen),
|
|
__getgroups_chk)
|
|
__wur __warnattr ("getgroups called with bigger group count than what "
|
|
"can fit into destination buffer");
|
|
|
|
__fortify_function int
|
|
__NTH (getgroups (int __size, __gid_t __list[]))
|
|
{
|
|
if (__bos (__list) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__size) || __size < 0)
|
|
return __getgroups_chk (__size, __list, __bos (__list));
|
|
|
|
if (__size * sizeof (__gid_t) > __bos (__list))
|
|
return __getgroups_chk_warn (__size, __list, __bos (__list));
|
|
}
|
|
return __getgroups_alias (__size, __list);
|
|
}
|
|
|
|
|
|
extern int __ttyname_r_chk (int __fd, char *__buf, size_t __buflen,
|
|
size_t __nreal) __THROW __nonnull ((2));
|
|
extern int __REDIRECT_NTH (__ttyname_r_alias, (int __fd, char *__buf,
|
|
size_t __buflen), ttyname_r)
|
|
__nonnull ((2));
|
|
extern int __REDIRECT_NTH (__ttyname_r_chk_warn,
|
|
(int __fd, char *__buf, size_t __buflen,
|
|
size_t __nreal), __ttyname_r_chk)
|
|
__nonnull ((2)) __warnattr ("ttyname_r called with bigger buflen than "
|
|
"size of destination buffer");
|
|
|
|
__fortify_function int
|
|
__NTH (ttyname_r (int __fd, char *__buf, size_t __buflen))
|
|
{
|
|
if (__bos (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__buflen))
|
|
return __ttyname_r_chk (__fd, __buf, __buflen, __bos (__buf));
|
|
|
|
if (__buflen > __bos (__buf))
|
|
return __ttyname_r_chk_warn (__fd, __buf, __buflen, __bos (__buf));
|
|
}
|
|
return __ttyname_r_alias (__fd, __buf, __buflen);
|
|
}
|
|
|
|
|
|
#if defined __USE_REENTRANT || defined __USE_POSIX199506
|
|
extern int __getlogin_r_chk (char *__buf, size_t __buflen, size_t __nreal)
|
|
__nonnull ((1));
|
|
extern int __REDIRECT (__getlogin_r_alias, (char *__buf, size_t __buflen),
|
|
getlogin_r) __nonnull ((1));
|
|
extern int __REDIRECT (__getlogin_r_chk_warn,
|
|
(char *__buf, size_t __buflen, size_t __nreal),
|
|
__getlogin_r_chk)
|
|
__nonnull ((1)) __warnattr ("getlogin_r called with bigger buflen than "
|
|
"size of destination buffer");
|
|
|
|
__fortify_function int
|
|
getlogin_r (char *__buf, size_t __buflen)
|
|
{
|
|
if (__bos (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__buflen))
|
|
return __getlogin_r_chk (__buf, __buflen, __bos (__buf));
|
|
|
|
if (__buflen > __bos (__buf))
|
|
return __getlogin_r_chk_warn (__buf, __buflen, __bos (__buf));
|
|
}
|
|
return __getlogin_r_alias (__buf, __buflen);
|
|
}
|
|
#endif
|
|
|
|
|
|
#if defined __USE_MISC || defined __USE_UNIX98
|
|
extern int __gethostname_chk (char *__buf, size_t __buflen, size_t __nreal)
|
|
__THROW __nonnull ((1));
|
|
extern int __REDIRECT_NTH (__gethostname_alias, (char *__buf, size_t __buflen),
|
|
gethostname) __nonnull ((1));
|
|
extern int __REDIRECT_NTH (__gethostname_chk_warn,
|
|
(char *__buf, size_t __buflen, size_t __nreal),
|
|
__gethostname_chk)
|
|
__nonnull ((1)) __warnattr ("gethostname called with bigger buflen than "
|
|
"size of destination buffer");
|
|
|
|
__fortify_function int
|
|
__NTH (gethostname (char *__buf, size_t __buflen))
|
|
{
|
|
if (__bos (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__buflen))
|
|
return __gethostname_chk (__buf, __buflen, __bos (__buf));
|
|
|
|
if (__buflen > __bos (__buf))
|
|
return __gethostname_chk_warn (__buf, __buflen, __bos (__buf));
|
|
}
|
|
return __gethostname_alias (__buf, __buflen);
|
|
}
|
|
#endif
|
|
|
|
|
|
#if defined __USE_MISC || (defined __USE_XOPEN && !defined __USE_UNIX98)
|
|
extern int __getdomainname_chk (char *__buf, size_t __buflen, size_t __nreal)
|
|
__THROW __nonnull ((1)) __wur;
|
|
extern int __REDIRECT_NTH (__getdomainname_alias, (char *__buf,
|
|
size_t __buflen),
|
|
getdomainname) __nonnull ((1)) __wur;
|
|
extern int __REDIRECT_NTH (__getdomainname_chk_warn,
|
|
(char *__buf, size_t __buflen, size_t __nreal),
|
|
__getdomainname_chk)
|
|
__nonnull ((1)) __wur __warnattr ("getdomainname called with bigger "
|
|
"buflen than size of destination "
|
|
"buffer");
|
|
|
|
__fortify_function int
|
|
__NTH (getdomainname (char *__buf, size_t __buflen))
|
|
{
|
|
if (__bos (__buf) != (size_t) -1)
|
|
{
|
|
if (!__builtin_constant_p (__buflen))
|
|
return __getdomainname_chk (__buf, __buflen, __bos (__buf));
|
|
|
|
if (__buflen > __bos (__buf))
|
|
return __getdomainname_chk_warn (__buf, __buflen, __bos (__buf));
|
|
}
|
|
return __getdomainname_alias (__buf, __buflen);
|
|
}
|
|
#endif
|