mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-10 07:10:06 +00:00
9dd346ff43
This mostly automatically-generated patch converts 113 function definitions in glibc from old-style K&R to prototype-style. Following my other recent such patches, this one deals with the case of function definitions in files that either contain assertions or where grep suggested they might contain assertions - and thus where it isn't possible to use a simple object code comparison as a sanity check on the correctness of the patch, because line numbers are changed. A few such automatically-generated changes needed to be supplemented by manual changes for the result to compile. openat64 had a prototype declaration with "..." but an old-style definition in sysdeps/unix/sysv/linux/dl-openat64.c, and "..." needed adding to the generated prototype in the definition (I've filed <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68024> for diagnosing such cases in GCC; the old state was undefined behavior not requiring a diagnostic, but one seems a good idea). In addition, as Florian has noted regparm attribute mismatches between declaration and definition are only diagnosed for prototype definitions, and five functions needed internal_function added to their definitions (in the case of __pthread_mutex_cond_lock, via the macro definition of __pthread_mutex_lock) to compile on i386. After this patch is in, remaining old-style definitions are probably most readily fixed manually before we can turn on -Wold-style-definition for all builds. Tested for x86_64 and x86 (testsuite). * crypt/md5-crypt.c (__md5_crypt_r): Convert to prototype-style function definition. * crypt/sha256-crypt.c (__sha256_crypt_r): Likewise. * crypt/sha512-crypt.c (__sha512_crypt_r): Likewise. * debug/backtracesyms.c (__backtrace_symbols): Likewise. * elf/dl-minimal.c (_itoa): Likewise. * hurd/hurdmalloc.c (malloc): Likewise. (free): Likewise. (realloc): Likewise. * inet/inet6_option.c (inet6_option_space): Likewise. (inet6_option_init): Likewise. (inet6_option_append): Likewise. (inet6_option_alloc): Likewise. (inet6_option_next): Likewise. (inet6_option_find): Likewise. * io/ftw.c (FTW_NAME): Likewise. (NFTW_NAME): Likewise. (NFTW_NEW_NAME): Likewise. (NFTW_OLD_NAME): Likewise. * libio/iofwide.c (_IO_fwide): Likewise. * libio/strops.c (_IO_str_init_static_internal): Likewise. (_IO_str_init_static): Likewise. (_IO_str_init_readonly): Likewise. (_IO_str_overflow): Likewise. (_IO_str_underflow): Likewise. (_IO_str_count): Likewise. (_IO_str_seekoff): Likewise. (_IO_str_pbackfail): Likewise. (_IO_str_finish): Likewise. * libio/wstrops.c (_IO_wstr_init_static): Likewise. (_IO_wstr_overflow): Likewise. (_IO_wstr_underflow): Likewise. (_IO_wstr_count): Likewise. (_IO_wstr_seekoff): Likewise. (_IO_wstr_pbackfail): Likewise. (_IO_wstr_finish): Likewise. * locale/programs/localedef.c (normalize_codeset): Likewise. * locale/programs/locarchive.c (add_locale_to_archive): Likewise. (add_locales_to_archive): Likewise. (delete_locales_from_archive): Likewise. * malloc/malloc.c (__libc_mallinfo): Likewise. * math/gen-auto-libm-tests.c (init_fp_formats): Likewise. * misc/tsearch.c (__tfind): Likewise. * nptl/pthread_attr_destroy.c (__pthread_attr_destroy): Likewise. * nptl/pthread_attr_getdetachstate.c (__pthread_attr_getdetachstate): Likewise. * nptl/pthread_attr_getguardsize.c (pthread_attr_getguardsize): Likewise. * nptl/pthread_attr_getinheritsched.c (__pthread_attr_getinheritsched): Likewise. * nptl/pthread_attr_getschedparam.c (__pthread_attr_getschedparam): Likewise. * nptl/pthread_attr_getschedpolicy.c (__pthread_attr_getschedpolicy): Likewise. * nptl/pthread_attr_getscope.c (__pthread_attr_getscope): Likewise. * nptl/pthread_attr_getstack.c (__pthread_attr_getstack): Likewise. * nptl/pthread_attr_getstackaddr.c (__pthread_attr_getstackaddr): Likewise. * nptl/pthread_attr_getstacksize.c (__pthread_attr_getstacksize): Likewise. * nptl/pthread_attr_init.c (__pthread_attr_init_2_1): Likewise. (__pthread_attr_init_2_0): Likewise. * nptl/pthread_attr_setdetachstate.c (__pthread_attr_setdetachstate): Likewise. * nptl/pthread_attr_setguardsize.c (pthread_attr_setguardsize): Likewise. * nptl/pthread_attr_setinheritsched.c (__pthread_attr_setinheritsched): Likewise. * nptl/pthread_attr_setschedparam.c (__pthread_attr_setschedparam): Likewise. * nptl/pthread_attr_setschedpolicy.c (__pthread_attr_setschedpolicy): Likewise. * nptl/pthread_attr_setscope.c (__pthread_attr_setscope): Likewise. * nptl/pthread_attr_setstack.c (__pthread_attr_setstack): Likewise. * nptl/pthread_attr_setstackaddr.c (__pthread_attr_setstackaddr): Likewise. * nptl/pthread_attr_setstacksize.c (__pthread_attr_setstacksize): Likewise. * nptl/pthread_condattr_setclock.c (pthread_condattr_setclock): Likewise. * nptl/pthread_create.c (__find_in_stack_list): Likewise. * nptl/pthread_getattr_np.c (pthread_getattr_np): Likewise. * nptl/pthread_mutex_cond_lock.c (__pthread_mutex_lock): Define to use internal_function. * nptl/pthread_mutex_init.c (__pthread_mutex_init): Convert to prototype-style function definition. * nptl/pthread_mutex_lock.c (__pthread_mutex_lock): Likewise. (__pthread_mutex_cond_lock_adjust): Likewise. Use internal_function. * nptl/pthread_mutex_timedlock.c (pthread_mutex_timedlock): Convert to prototype-style function definition. * nptl/pthread_mutex_trylock.c (__pthread_mutex_trylock): Likewise. * nptl/pthread_mutex_unlock.c (__pthread_mutex_unlock_usercnt): Likewise. (__pthread_mutex_unlock): Likewise. * nptl_db/td_ta_clear_event.c (td_ta_clear_event): Likewise. * nptl_db/td_ta_set_event.c (td_ta_set_event): Likewise. * nptl_db/td_thr_clear_event.c (td_thr_clear_event): Likewise. * nptl_db/td_thr_event_enable.c (td_thr_event_enable): Likewise. * nptl_db/td_thr_set_event.c (td_thr_set_event): Likewise. * nss/makedb.c (process_input): Likewise. * posix/fnmatch.c (__strchrnul): Likewise. (__wcschrnul): Likewise. (fnmatch): Likewise. * posix/fnmatch_loop.c (FCT): Likewise. * posix/glob.c (globfree): Likewise. (__glob_pattern_type): Likewise. (__glob_pattern_p): Likewise. * posix/regcomp.c (re_compile_pattern): Likewise. (re_set_syntax): Likewise. (re_compile_fastmap): Likewise. (regcomp): Likewise. (regerror): Likewise. (regfree): Likewise. * posix/regexec.c (regexec): Likewise. (re_match): Likewise. (re_search): Likewise. (re_match_2): Likewise. (re_search_2): Likewise. (re_search_stub): Likewise. Use internal_function (re_copy_regs): Likewise. (re_set_registers): Convert to prototype-style function definition. (prune_impossible_nodes): Likewise. Use internal_function. * resolv/inet_net_pton.c (inet_net_pton): Convert to prototype-style function definition. (inet_net_pton_ipv4): Likewise. * stdlib/strtod_l.c (____STRTOF_INTERNAL): Likewise. * sysdeps/pthread/aio_cancel.c (aio_cancel): Likewise. * sysdeps/pthread/aio_suspend.c (aio_suspend): Likewise. * sysdeps/pthread/timer_delete.c (timer_delete): Likewise. * sysdeps/unix/sysv/linux/dl-openat64.c (openat64): Likewise. Make variadic. * time/strptime_l.c (localtime_r): Convert to prototype-style function definition. * wcsmbs/mbsnrtowcs.c (__mbsnrtowcs): Likewise. * wcsmbs/mbsrtowcs_l.c (__mbsrtowcs_l): Likewise. * wcsmbs/wcsnrtombs.c (__wcsnrtombs): Likewise. * wcsmbs/wcsrtombs.c (__wcsrtombs): Likewise.
203 lines
5.3 KiB
C
203 lines
5.3 KiB
C
/*
|
|
* Copyright (c) 1996,1999 by Internet Software Consortium.
|
|
*
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
|
static const char rcsid[] = "$BINDId: inet_net_pton.c,v 1.11 1999/01/08 19:23:44 vixie Exp $";
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
|
|
#include <assert.h>
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#ifdef SPRINTF_CHAR
|
|
# define SPRINTF(x) strlen(sprintf/**/x)
|
|
#else
|
|
# define SPRINTF(x) ((size_t)sprintf x)
|
|
#endif
|
|
|
|
static int inet_net_pton_ipv4 (const char *src, u_char *dst,
|
|
size_t size) __THROW;
|
|
|
|
/*
|
|
* static int
|
|
* inet_net_pton(af, src, dst, size)
|
|
* convert network number from presentation to network format.
|
|
* accepts hex octets, hex strings, decimal octets, and /CIDR.
|
|
* "size" is in bytes and describes "dst".
|
|
* return:
|
|
* number of bits, either imputed classfully or specified with /CIDR,
|
|
* or -1 if some failure occurred (check errno). ENOENT means it was
|
|
* not a valid network specification.
|
|
* author:
|
|
* Paul Vixie (ISC), June 1996
|
|
*/
|
|
int
|
|
inet_net_pton (int af, const char *src, void *dst, size_t size)
|
|
{
|
|
switch (af) {
|
|
case AF_INET:
|
|
return (inet_net_pton_ipv4(src, dst, size));
|
|
default:
|
|
__set_errno (EAFNOSUPPORT);
|
|
return (-1);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* static int
|
|
* inet_net_pton_ipv4(src, dst, size)
|
|
* convert IPv4 network number from presentation to network format.
|
|
* accepts hex octets, hex strings, decimal octets, and /CIDR.
|
|
* "size" is in bytes and describes "dst".
|
|
* return:
|
|
* number of bits, either imputed classfully or specified with /CIDR,
|
|
* or -1 if some failure occurred (check errno). ENOENT means it was
|
|
* not an IPv4 network specification.
|
|
* note:
|
|
* network byte order assumed. this means 192.5.5.240/28 has
|
|
* 0b11110000 in its fourth octet.
|
|
* author:
|
|
* Paul Vixie (ISC), June 1996
|
|
*/
|
|
static int
|
|
inet_net_pton_ipv4 (const char *src, u_char *dst, size_t size)
|
|
{
|
|
static const char xdigits[] = "0123456789abcdef";
|
|
int n, ch, tmp, dirty, bits;
|
|
const u_char *odst = dst;
|
|
|
|
ch = *src++;
|
|
if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
|
|
&& isascii(src[1]) && isxdigit(src[1])) {
|
|
/* Hexadecimal: Eat nybble string. */
|
|
if (size <= 0)
|
|
goto emsgsize;
|
|
dirty = 0;
|
|
tmp = 0; /* To calm down gcc. */
|
|
src++; /* skip x or X. */
|
|
while (isxdigit((ch = *src++))) {
|
|
ch = _tolower(ch);
|
|
n = (const char *) __rawmemchr(xdigits, ch) - xdigits;
|
|
assert(n >= 0 && n <= 15);
|
|
if (dirty == 0)
|
|
tmp = n;
|
|
else
|
|
tmp = (tmp << 4) | n;
|
|
if (++dirty == 2) {
|
|
if (size-- <= 0)
|
|
goto emsgsize;
|
|
*dst++ = (u_char) tmp;
|
|
dirty = 0;
|
|
}
|
|
}
|
|
if (dirty) { /* Odd trailing nybble? */
|
|
if (size-- <= 0)
|
|
goto emsgsize;
|
|
*dst++ = (u_char) (tmp << 4);
|
|
}
|
|
} else if (isascii(ch) && isdigit(ch)) {
|
|
/* Decimal: eat dotted digit string. */
|
|
for (;;) {
|
|
tmp = 0;
|
|
do {
|
|
n = ((const char *) __rawmemchr(xdigits, ch)
|
|
- xdigits);
|
|
assert(n >= 0 && n <= 9);
|
|
tmp *= 10;
|
|
tmp += n;
|
|
if (tmp > 255)
|
|
goto enoent;
|
|
} while (isascii((ch = *src++)) && isdigit(ch));
|
|
if (size-- <= 0)
|
|
goto emsgsize;
|
|
*dst++ = (u_char) tmp;
|
|
if (ch == '\0' || ch == '/')
|
|
break;
|
|
if (ch != '.')
|
|
goto enoent;
|
|
ch = *src++;
|
|
if (!isascii(ch) || !isdigit(ch))
|
|
goto enoent;
|
|
}
|
|
} else
|
|
goto enoent;
|
|
|
|
bits = -1;
|
|
if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) {
|
|
/* CIDR width specifier. Nothing can follow it. */
|
|
ch = *src++; /* Skip over the /. */
|
|
bits = 0;
|
|
do {
|
|
n = (const char *) __rawmemchr(xdigits, ch) - xdigits;
|
|
assert(n >= 0 && n <= 9);
|
|
bits *= 10;
|
|
bits += n;
|
|
} while (isascii((ch = *src++)) && isdigit(ch));
|
|
if (ch != '\0')
|
|
goto enoent;
|
|
if (bits > 32)
|
|
goto emsgsize;
|
|
}
|
|
|
|
/* Firey death and destruction unless we prefetched EOS. */
|
|
if (ch != '\0')
|
|
goto enoent;
|
|
|
|
/* If nothing was written to the destination, we found no address. */
|
|
if (dst == odst)
|
|
goto enoent;
|
|
/* If no CIDR spec was given, infer width from net class. */
|
|
if (bits == -1) {
|
|
if (*odst >= 240) /* Class E */
|
|
bits = 32;
|
|
else if (*odst >= 224) /* Class D */
|
|
bits = 4;
|
|
else if (*odst >= 192) /* Class C */
|
|
bits = 24;
|
|
else if (*odst >= 128) /* Class B */
|
|
bits = 16;
|
|
else /* Class A */
|
|
bits = 8;
|
|
/* If imputed mask is narrower than specified octets, widen. */
|
|
if (bits >= 8 && bits < ((dst - odst) * 8))
|
|
bits = (dst - odst) * 8;
|
|
}
|
|
/* Extend network to cover the actual mask. */
|
|
while (bits > ((dst - odst) * 8)) {
|
|
if (size-- <= 0)
|
|
goto emsgsize;
|
|
*dst++ = '\0';
|
|
}
|
|
return (bits);
|
|
|
|
enoent:
|
|
__set_errno (ENOENT);
|
|
return (-1);
|
|
|
|
emsgsize:
|
|
__set_errno (EMSGSIZE);
|
|
return (-1);
|
|
}
|