From: Lionel Sambuc Date: Thu, 15 Nov 2012 11:06:41 +0000 (+0100) Subject: Libraries updates and cleanup X-Git-Tag: v3.2.1~114 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/dnssec-dsfromkey.html?a=commitdiff_plain;h=refs%2Fchanges%2F72%2F172%2F2;p=minix.git Libraries updates and cleanup * Updating common/lib * Updating lib/csu * Updating lib/libc * Updating libexec/ld.elf_so * Corrected test on __minix in featuretest to actually follow the meaning of the comment. * Cleaned up _REENTRANT-related defintions. * Disabled -D_REENTRANT for libfetch * Removing some unneeded __NBSD_LIBC defines and tests Change-Id: Ic1394baef74d11b9f86b312f5ff4bbc3cbf72ce2 --- diff --git a/commands/diff/xmalloc.c b/commands/diff/xmalloc.c index d0df526ec..d5a536c3a 100644 --- a/commands/diff/xmalloc.c +++ b/commands/diff/xmalloc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/commands/dosread/dosread.c b/commands/dosread/dosread.c index 4ee1df4cd..1757d7a00 100644 --- a/commands/dosread/dosread.c +++ b/commands/dosread/dosread.c @@ -696,7 +696,7 @@ unsigned short mon_len[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; void fill_date(entry) DIRECTORY *entry; { - register long cur_time = time((long *) 0) - DOS_TIME; + register long cur_time = time(NULL) - DOS_TIME; unsigned short year = 0, month = 1, day, hour, minutes, seconds; int i; long tmp; diff --git a/commands/elvis/config.h b/commands/elvis/config.h index 90307bb9b..38af7e843 100644 --- a/commands/elvis/config.h +++ b/commands/elvis/config.h @@ -251,7 +251,8 @@ extern char *malloc(); #endif /* everybody but Amiga wants lseek declared here */ -#if !AMIGA +/* LSC: MINIX Does not want it either! */ +#if !AMIGA && !defined(__minix) extern long lseek(); #endif diff --git a/commands/partition/partition.c b/commands/partition/partition.c index 095a4af8f..be790d5b1 100644 --- a/commands/partition/partition.c +++ b/commands/partition/partition.c @@ -419,11 +419,11 @@ int main(int argc, char **argv) if (rflag) { if (aflag) usage(); if ((argc - i) != 1) usage(); - fprintf(stderr, "%s: -r is not yet implemented\n"); + fprintf(stderr, "%s: -r is not yet implemented\n", __func__); exit(1); } else { if ((argc - i) < 1) usage(); - if (aflag) fprintf(stderr, "%s: -a is not yet implemented\n"); + if (aflag) fprintf(stderr, "%s: -a is not yet implemented\n", __func__); device= argv[i++]; geometry(); diff --git a/commands/playwave/playwave.c b/commands/playwave/playwave.c index b93c354c4..53b92d8dc 100644 --- a/commands/playwave/playwave.c +++ b/commands/playwave/playwave.c @@ -70,7 +70,7 @@ void usage() int main ( int argc, char *argv[] ) { int i, r, audio, file; - char *buffer, *file_name; + char *buffer, *file_name = NULL; unsigned int sign; unsigned int fragment_size; unsigned int channels; diff --git a/commands/repartition/repartition.c b/commands/repartition/repartition.c index 0e536d937..b3966d5ad 100644 --- a/commands/repartition/repartition.c +++ b/commands/repartition/repartition.c @@ -112,7 +112,6 @@ int diocntl(dev_t device, int request, struct partition *entry) { char *name; int r, f, err; - struct partition geometry; name= finddev(device); if ((f= open(name, O_RDONLY)) < 0) return -1; @@ -164,7 +163,7 @@ int main(int argc, char **argv) struct stat hdst; struct partition whole, entry; struct part_entry table[4], *pe; - int drive, par, device, incr; + int drive, par = 0, device, incr; int partf; char *table_file; int hd_major, hd_minor; diff --git a/common/lib/libc/Makefile.inc b/common/lib/libc/Makefile.inc index 862b6bc0b..94ae1819b 100644 --- a/common/lib/libc/Makefile.inc +++ b/common/lib/libc/Makefile.inc @@ -3,11 +3,10 @@ COMMON_DIR:=${.PARSEDIR} .if defined(__MINIX) COMMON_CODEDIRS=atomic gen inet md net quad stdlib string -COMMON_CODEDIRS+=hash/sha1 hash/sha2 hash/rmd160 .else COMMON_CODEDIRS=atomic gen gmon inet md net quad stdlib string sys -COMMON_CODEDIRS+=hash/sha1 hash/sha2 hash/rmd160 hash/murmurhash .endif +COMMON_CODEDIRS+=hash/sha1 hash/sha2 hash/rmd160 hash/murmurhash .if defined(COMMON_MACHINE_ARCH) && !empty(COMMON_MACHINE_ARCH) && \ exists(${COMMON_DIR}/arch/${COMMON_MACHINE_ARCH}) diff --git a/common/lib/libc/arch/arm/atomic/atomic_add_32.S b/common/lib/libc/arch/arm/atomic/atomic_add_32.S index e03472c79..79eb006ea 100644 --- a/common/lib/libc/arch/arm/atomic/atomic_add_32.S +++ b/common/lib/libc/arch/arm/atomic/atomic_add_32.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_add_32.S,v 1.2 2008/08/16 07:12:39 matt Exp $ */ +/* $NetBSD: atomic_add_32.S,v 1.3 2012/08/31 23:41:52 matt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -40,6 +40,11 @@ ENTRY_NP(_atomic_add_32) strex ip, r2, [r3] /* try to store */ cmp ip, #0 /* succeed? */ bne 1b /* no, try again */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET /* return old value */ END(_atomic_add_32) ATOMIC_OP_ALIAS(atomic_add_32,_atomic_add_32) @@ -57,6 +62,11 @@ ENTRY_NP(_atomic_add_32_nv) strex r2, r0, [r3] /* try to store */ cmp r2, #0 /* succeed? */ bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET /* return new value */ END(_atomic_add_32_nv) ATOMIC_OP_ALIAS(atomic_add_32_nv,_atomic_add_32_nv) diff --git a/common/lib/libc/arch/arm/atomic/atomic_add_64.S b/common/lib/libc/arch/arm/atomic/atomic_add_64.S new file mode 100644 index 000000000..f79e10c34 --- /dev/null +++ b/common/lib/libc/arch/arm/atomic/atomic_add_64.S @@ -0,0 +1,81 @@ +/* $NetBSD: atomic_add_64.S,v 1.3 2012/09/13 00:36:12 matt Exp $ */ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "atomic_op_asm.h" + +#ifdef _ARM_ARCH_6 + +ENTRY_NP(_atomic_add_64) + str r4, [sp, #-4]! /* save temporary */ + mov r4, r0 /* need r0 for return value */ +#ifndef __ARM_EABI__ + mov r3, r2 + mov r2, r1 +#endif +1: ldrexd r0, [r4] /* load old value (to be returned) */ + adds NLO, LO, NLO /* calculate new value */ + adc NHI, HI, NHI /* calculate new value */ + strexd ip, r2, [r4] /* try to store */ + cmp ip, #0 /* succeed? */ + bne 1b /* no, try again */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + ldr r4, [sp], #4 /* restore temporary */ + RET /* return old value */ + END(_atomic_add_64) +ATOMIC_OP_ALIAS(atomic_add_64,_atomic_add_64) + +ENTRY_NP(_atomic_add_64_nv) + str r4, [sp, #-4]! /* save temporary */ + mov r4, r0 /* need r0 for return value */ +#ifndef __ARM_EABI__ + mov r3, r2 + mov r2, r1 +#endif +1: ldrexd r0, [r4] /* load old value */ + adds LO, LO, NLO /* calculate new value lo */ + adc HI, HI, NHI /* calculate new value hi */ + strexd ip, r0, [r4] /* try to store */ + cmp ip, #0 /* succeed? */ + bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + ldr r4, [sp], #4 /* restore temporary */ + RET /* return new value */ + END(_atomic_add_64_nv) +ATOMIC_OP_ALIAS(atomic_add_64_nv,_atomic_add_64_nv) + +#endif /* _ARM_ARCH_6 */ diff --git a/common/lib/libc/arch/arm/atomic/atomic_and_32.S b/common/lib/libc/arch/arm/atomic/atomic_and_32.S index d34bf0d49..d55440cda 100644 --- a/common/lib/libc/arch/arm/atomic/atomic_and_32.S +++ b/common/lib/libc/arch/arm/atomic/atomic_and_32.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_and_32.S,v 1.2 2008/08/16 07:12:39 matt Exp $ */ +/* $NetBSD: atomic_and_32.S,v 1.3 2012/08/31 23:41:52 matt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -40,6 +40,11 @@ ENTRY_NP(_atomic_and_32) strex ip, r2, [r3] /* try to store */ cmp ip, #0 /* succeed? */ bne 1b /* no, try again */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET /* return old value */ END(_atomic_and_32) ATOMIC_OP_ALIAS(atomic_and_32,_atomic_and_32) @@ -55,6 +60,11 @@ ENTRY_NP(_atomic_and_32_nv) strex r2, r0, [r3] /* try to store */ cmp r2, #0 /* succeed? */ bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET /* return new value */ END(_atomic_and_32_nv) ATOMIC_OP_ALIAS(atomic_and_32_nv,_atomic_and_32_nv) diff --git a/common/lib/libc/arch/arm/atomic/atomic_and_64.S b/common/lib/libc/arch/arm/atomic/atomic_and_64.S new file mode 100644 index 000000000..1c2f3f27c --- /dev/null +++ b/common/lib/libc/arch/arm/atomic/atomic_and_64.S @@ -0,0 +1,81 @@ +/* $NetBSD: atomic_and_64.S,v 1.2 2012/09/13 00:36:12 matt Exp $ */ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "atomic_op_asm.h" + +#ifdef _ARM_ARCH_6 + +ENTRY_NP(_atomic_and_64) + str r4, [sp, #-4]! /* save temporary */ +#ifndef __ARM_EABI__ + mov r3, r2 + mov r2, r1 +#endif + mov r4, r0 /* need r0 for return value */ +1: ldrexd r0, [r4] /* load old value (to be returned) */ + and r2, r0, r2 /* calculate new value */ + and r3, r1, r3 /* calculate new value */ + strexd ip, r2, [r4] /* try to store */ + cmp ip, #0 /* succeed? */ + bne 1b /* no, try again */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + ldr r4, [sp], #4 /* restore temporary */ + RET /* return old value */ + END(_atomic_and_64) +ATOMIC_OP_ALIAS(atomic_and_64,_atomic_and_64) + +ENTRY_NP(_atomic_and_64_nv) + str r4, [sp, #-4]! /* save temporary */ +#ifndef __ARM_EABI__ + mov r3, r2 + mov r2, r1 +#endif + mov r4, r0 /* need r0 for return value */ +1: ldrexd r0, [r4] /* load old value */ + and r0, r0, r2 /* calculate new value */ + and r1, r1, r3 /* calculate new value */ + strexd ip, r0, [r4] /* try to store */ + cmp ip, #0 /* succeed? */ + bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + ldr r4, [sp], #4 /* restore temporary */ + RET /* return new value */ + END(_atomic_and_64_nv) +ATOMIC_OP_ALIAS(atomic_and_64_nv,_atomic_and_64_nv) + +#endif /* _ARM_ARCH_6 */ diff --git a/common/lib/libc/arch/arm/atomic/atomic_cas_32.S b/common/lib/libc/arch/arm/atomic/atomic_cas_32.S index a77cfbad9..c4011e7b2 100644 --- a/common/lib/libc/arch/arm/atomic/atomic_cas_32.S +++ b/common/lib/libc/arch/arm/atomic/atomic_cas_32.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_cas_32.S,v 1.2 2008/08/16 07:12:39 matt Exp $ */ +/* $NetBSD: atomic_cas_32.S,v 1.3 2012/08/31 23:41:52 matt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. @@ -44,15 +44,28 @@ ENTRY_NP(_atomic_cas_32) strex ip, r2, [r3] /* store new value */ cmp ip, #0 /* succeed? */ bne 1b /* nope, try again. */ - RET /* yes, return. */ +#ifdef _ARM_ARCH_7 + dsb +#else + mcr p15, 0, ip, c7, c10, 4 /* data synchronization barrier */ +#endif + RET /* return. */ END(_atomic_cas_32) ATOMIC_OP_ALIAS(atomic_cas_32,_atomic_cas_32) ATOMIC_OP_ALIAS(atomic_cas_uint,_atomic_cas_32) ATOMIC_OP_ALIAS(atomic_cas_ulong,_atomic_cas_32) ATOMIC_OP_ALIAS(atomic_cas_ptr,_atomic_cas_32) +ATOMIC_OP_ALIAS(atomic_cas_32_ni,_atomic_cas_32) +ATOMIC_OP_ALIAS(atomic_cas_uint_ni,_atomic_cas_32) +ATOMIC_OP_ALIAS(atomic_cas_ulong_ni,_atomic_cas_32) +ATOMIC_OP_ALIAS(atomic_cas_ptr_ni,_atomic_cas_32) STRONG_ALIAS(_atomic_cas_uint,_atomic_cas_32) STRONG_ALIAS(_atomic_cas_ulong,_atomic_cas_32) +STRONG_ALIAS(_atomic_cas_32_ni,_atomic_cas_32) +STRONG_ALIAS(_atomic_cas_ptr_ni,_atomic_cas_32) +STRONG_ALIAS(_atomic_cas_uint_ni,_atomic_cas_32) +STRONG_ALIAS(_atomic_cas_ulong_ni,_atomic_cas_32) STRONG_ALIAS(_atomic_cas_ptr,_atomic_cas_32) #endif /* _ARCH_ARM_6 */ diff --git a/common/lib/libc/arch/arm/atomic/atomic_cas_64.S b/common/lib/libc/arch/arm/atomic/atomic_cas_64.S new file mode 100644 index 000000000..d5046ebdb --- /dev/null +++ b/common/lib/libc/arch/arm/atomic/atomic_cas_64.S @@ -0,0 +1,69 @@ +/* $NetBSD: atomic_cas_64.S,v 1.1 2012/09/11 20:51:25 matt Exp $ */ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "atomic_op_asm.h" + +#if defined(_ARM_ARCH_6) +/* + * ARMv6 has load-exclusive/store-exclusive which works for both user + * and kernel. + */ +ENTRY_NP(_atomic_cas_64) + stmfd sp!, {r4, r5, r6} /* save temporaries */ + mov r6, r0 /* we need r0 for return value */ +#ifdef __ARM_EABI__ + ldrd r4, [sp] /* fetch new value */ +#else + ldr r5, [sp, #4] /* fetch new value */ + ldr r4, [sp, #0] /* fetch new value */ + mov r3, r2 /* r2 will be overwritten by r1 which ... */ + mov r2, r1 /* r1 will be overwritten by ldrexd */ +#endif +1: + ldrexd r0, [r6] /* load current value */ + teq r0, r2 /* compare to old? 1st half */ + teqeq r1, r3 /* compare to old? 2nd half */ + bne 2f /* jump to return if different */ + strexd ip, r4, [r6] /* store new value */ + cmp ip, #0 /* succeed? */ + bne 1b /* nope, try again. */ +#ifdef _ARM_ARCH_7 + dsb +#else + mcr p15, 0, ip, c7, c10, 4 /* data synchronization barrier */ +#endif +2: + ldmfd sp!, {r4, r5, r6} /* restore temporaries */ + RET /* return. */ + END(_atomic_cas_64) + +ATOMIC_OP_ALIAS(atomic_cas_64,_atomic_cas_64) + +#endif /* _ARCH_ARM_6 */ diff --git a/common/lib/libc/arch/arm/atomic/atomic_cas_8.S b/common/lib/libc/arch/arm/atomic/atomic_cas_8.S index 98ebf2152..fc5ddeefe 100644 --- a/common/lib/libc/arch/arm/atomic/atomic_cas_8.S +++ b/common/lib/libc/arch/arm/atomic/atomic_cas_8.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_cas_8.S,v 1.1 2008/11/18 15:22:56 matt Exp $ */ +/* $NetBSD: atomic_cas_8.S,v 1.3 2012/08/31 23:41:52 matt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. @@ -27,37 +27,33 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include -RCSID("$NetBSD: atomic_cas_8.S,v 1.1 2008/11/18 15:22:56 matt Exp $") +#include "atomic_op_asm.h" -ENTRY(atomic_cas_8) - XPUSH {r4,r5} /* we need some more registers */ - and r3, r0, #3 /* which byte do we replace? */ -#if __ARMEB__ - eor r3, r3, #3 /* bytes are reversed on BE */ +#if defined(_ARM_ARCH_6) +/* + * ARMv6 has load-exclusive/store-exclusive which works for both user + * and kernel. + */ +ENTRY_NP(_atomic_cas_8) + mov r3, r0 /* we need r0 for return value */ +1: + ldrexb r0, [r3] /* load old value */ + teq r0, r1 /* compare? */ + RETc(ne) /* return if different */ + strexb ip, r2, [r3] /* store new value */ + cmp ip, #0 /* succeed? */ + bne 1b /* nope, try again. */ +#ifdef _ARM_ARCH_7 + dsb /* data synchronization barrier */ +#else + mcr p15, 0, ip, c7, c10, 4 /* data synchronization barrier */ #endif - mov r3, r3, lsl #3 /* multiply by 8 */ - mov r1, r1, lsl r3 /* mov old value to correct byte */ - eor r2, r1, r2, lsl r3 /* move new value to correct byte */ -/* eor r2, r2, r1 */ /* new value is now (old ^ new) */ - mov r5, #0xff /* load mask */ - mov r5, r5, lsl r3 /* and move to correct byte */ - mov r3, r0 /* move pointer */ + RET /* return. */ + END(_atomic_cas_8) -1: ldrex r4, [r3] /* load 32bit value */ - and r0, r4, r5 /* clear other bytes */ - teq r0, r1 /* equal old value? */ - bne 2f /* nope, bail. */ - eor r4, r4, r2 /* new == old ^ (old ^ new) */ - strex ip, r4, [r3] /* attempt to store it */ - cmp ip, #0 /* succeed? */ - bne 1b /* nope, try again. */ +ATOMIC_OP_ALIAS(atomic_cas_8,_atomic_cas_8) +STRONG_ALIAS(_atomic_cas_char,_atomic_cas_8) +STRONG_ALIAS(_atomic_cas_uchar,_atomic_cas_8) -2: XPOP {r4,r5} /* don't need these anymore */ - and r1, r3, #3 -#if __ARMEB__ - eor r1, r1, #3 -#endif - mov r0, r0, lsr r1 /* shift it back to lsb byte */ - RET +#endif /* _ARCH_ARM_6 */ diff --git a/common/lib/libc/arch/arm/atomic/atomic_dec_32.S b/common/lib/libc/arch/arm/atomic/atomic_dec_32.S index 68466d2a0..5d8b3d249 100644 --- a/common/lib/libc/arch/arm/atomic/atomic_dec_32.S +++ b/common/lib/libc/arch/arm/atomic/atomic_dec_32.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_dec_32.S,v 1.2 2008/08/16 07:12:39 matt Exp $ */ +/* $NetBSD: atomic_dec_32.S,v 1.3 2012/08/31 23:41:52 matt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. @@ -39,6 +39,11 @@ ENTRY_NP(_atomic_dec_32) strex r3, r1, [r2] /* try to store */ cmp r3, #0 /* succeed? */ bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET /* return new value */ END(_atomic_dec_32) ATOMIC_OP_ALIAS(atomic_dec_32,_atomic_dec_32) @@ -56,6 +61,11 @@ ENTRY_NP(_atomic_dec_32_nv) strex r1, r0, [r2] /* try to store */ cmp r1, #0 /* succeed? */ bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET /* return new value */ END(_atomic_dec_32_nv) ATOMIC_OP_ALIAS(atomic_dec_32_nv,_atomic_dec_32_nv) diff --git a/common/lib/libc/arch/arm/atomic/atomic_dec_64.S b/common/lib/libc/arch/arm/atomic/atomic_dec_64.S new file mode 100644 index 000000000..5315fdda1 --- /dev/null +++ b/common/lib/libc/arch/arm/atomic/atomic_dec_64.S @@ -0,0 +1,73 @@ +/* $NetBSD: atomic_dec_64.S,v 1.2 2012/09/13 00:36:12 matt Exp $ */ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "atomic_op_asm.h" + +#ifdef _ARM_ARCH_6 + +ENTRY_NP(_atomic_dec_64) + mvn r2, #0 + mov r3, r0 /* need r0 for return value */ +1: ldrexd r0, [r3] /* load old value (return value) */ + adds LO, LO, r2 /* calculate new value */ + adc HI, HI, r2 /* calculate new value */ + strexd ip, r0, [r3] /* try to store */ + cmp ip, #0 /* succeed? */ + bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + adds LO, LO, #1 + adc HI, HI, #0 + RET /* return old value */ + END(_atomic_dec_64) +ATOMIC_OP_ALIAS(atomic_dec_64,_atomic_dec_64) + +ENTRY_NP(_atomic_dec_64_nv) + mvn r2, #0 + mov r3, r0 /* need r0 for return value */ +1: ldrexd r0, [r3] /* load old value */ + adds LO, LO, r2 /* calculate new value */ + adc HI, HI, r2 /* calculate new value */ + strexd ip, r0, [r3] /* try to store */ + cmp ip, #0 /* succeed? */ + bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + RET /* return new value */ + END(_atomic_dec_64_nv) +ATOMIC_OP_ALIAS(atomic_dec_64_nv,_atomic_dec_64_nv) + +#endif /* _ARM_ARCH_6 */ diff --git a/common/lib/libc/arch/arm/atomic/atomic_inc_32.S b/common/lib/libc/arch/arm/atomic/atomic_inc_32.S index 01aa13061..cc08ce658 100644 --- a/common/lib/libc/arch/arm/atomic/atomic_inc_32.S +++ b/common/lib/libc/arch/arm/atomic/atomic_inc_32.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_inc_32.S,v 1.2 2008/08/16 07:12:39 matt Exp $ */ +/* $NetBSD: atomic_inc_32.S,v 1.3 2012/08/31 23:41:52 matt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. @@ -39,6 +39,11 @@ ENTRY_NP(_atomic_inc_32) strex r3, r1, [r2] /* try to store */ cmp r3, #0 /* succeed? */ bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET /* return new value */ END(_atomic_inc_32) ATOMIC_OP_ALIAS(atomic_inc_32,_atomic_inc_32) @@ -56,6 +61,11 @@ ENTRY_NP(_atomic_inc_32_nv) strex r1, r0, [r2] /* try to store */ cmp r1, #0 /* succeed? */ bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET /* return new value */ END(_atomic_inc_32_nv) ATOMIC_OP_ALIAS(atomic_inc_32_nv,_atomic_inc_32_nv) diff --git a/common/lib/libc/arch/arm/atomic/atomic_inc_64.S b/common/lib/libc/arch/arm/atomic/atomic_inc_64.S new file mode 100644 index 000000000..c798a9cb7 --- /dev/null +++ b/common/lib/libc/arch/arm/atomic/atomic_inc_64.S @@ -0,0 +1,72 @@ +/* $NetBSD: atomic_inc_64.S,v 1.2 2012/09/13 00:36:12 matt Exp $ */ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "atomic_op_asm.h" + +#ifdef _ARM_ARCH_6 + +ENTRY_NP(_atomic_inc_64) + mov r3, r0 /* need r0 for return value */ +1: ldrexd r0, [r3] /* load old value (return value) */ + adds LO, LO, #1 /* calculate new value */ + adc HI, HI, #0 /* zero means we carried */ + strexd ip, r0, [r3] /* try to store */ + cmp ip, #0 /* succeed? */ + bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + mvn r2, #0 /* r2 = -1 */ + adds LO, LO, r2 /* add it */ + adc HI, HI, r2 /* add with carry */ + RET /* return orig value */ + END(_atomic_inc_64) +ATOMIC_OP_ALIAS(atomic_inc_64,_atomic_inc_64) + +ENTRY_NP(_atomic_inc_64_nv) + mov r3, r0 /* need r0 for return value */ +1: ldrexd r0, [r3] /* load old value */ + add LO, LO, #1 /* calculate new value (return value) */ + adc HI, HI, #0 /* fold carry into high */ + strexd ip, r0, [r3] /* try to store */ + cmp ip, #0 /* succeed? */ + bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + RET /* return new value */ + END(_atomic_inc_64_nv) +ATOMIC_OP_ALIAS(atomic_inc_64_nv,_atomic_inc_64_nv) + +#endif /* _ARCH_ARM_6 */ diff --git a/common/lib/libc/arch/arm/atomic/atomic_op_asm.h b/common/lib/libc/arch/arm/atomic/atomic_op_asm.h index 40548fbb4..05cffe003 100644 --- a/common/lib/libc/arch/arm/atomic/atomic_op_asm.h +++ b/common/lib/libc/arch/arm/atomic/atomic_op_asm.h @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_op_asm.h,v 1.2 2008/08/16 07:12:39 matt Exp $ */ +/* $NetBSD: atomic_op_asm.h,v 1.3 2012/09/11 20:51:25 matt Exp $ */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. @@ -51,4 +51,16 @@ #endif /* _KERNEL */ +#ifdef __ARMEB__ +#define HI r0 +#define LO r1 +#define NHI r2 +#define NLO r3 +#else +#define LO r0 +#define HI r1 +#define NLO r2 +#define NHI r3 +#endif + #endif /* _ATOMIC_OP_ASM_H_ */ diff --git a/common/lib/libc/arch/arm/atomic/atomic_or_32.S b/common/lib/libc/arch/arm/atomic/atomic_or_32.S index 380f6f5ae..9a64a54f6 100644 --- a/common/lib/libc/arch/arm/atomic/atomic_or_32.S +++ b/common/lib/libc/arch/arm/atomic/atomic_or_32.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_or_32.S,v 1.2 2008/08/16 07:12:39 matt Exp $ */ +/* $NetBSD: atomic_or_32.S,v 1.3 2012/08/31 23:41:52 matt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. @@ -39,6 +39,11 @@ ENTRY_NP(_atomic_or_32) strex ip, r2, [r3] /* try to store */ cmp ip, #0 /* succeed? */ bne 1b /* no, try again */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET /* return old value */ END(_atomic_or_32) ATOMIC_OP_ALIAS(atomic_or_32,_atomic_or_32) @@ -54,6 +59,11 @@ ENTRY_NP(_atomic_or_32_nv) strex r2, r0, [r3] /* try to store */ cmp r2, #0 /* succeed? */ bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET /* return new value */ END(_atomic_or_32_nv) ATOMIC_OP_ALIAS(atomic_or_32_nv,_atomic_or_32_nv) diff --git a/common/lib/libc/arch/arm/atomic/atomic_or_64.S b/common/lib/libc/arch/arm/atomic/atomic_or_64.S new file mode 100644 index 000000000..7b73057ed --- /dev/null +++ b/common/lib/libc/arch/arm/atomic/atomic_or_64.S @@ -0,0 +1,81 @@ +/* $NetBSD: atomic_or_64.S,v 1.2 2012/09/13 00:36:12 matt Exp $ */ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "atomic_op_asm.h" + +#ifdef _ARM_ARCH_6 + +ENTRY_NP(_atomic_or_64) + str r4, [sp, #-4]! /* save temporary */ +#ifndef __ARM_EABI__ + mov r3, r2 + mov r2, r1 +#endif + mov r4, r0 /* need r0 for return value */ +1: ldrexd r0, [r4] /* load old value (to be returned) */ + orr r2, r0, r2 /* calculate new value */ + orr r3, r1, r3 /* calculate new value */ + strexd ip, r2, [r4] /* try to store */ + cmp ip, #0 /* succeed? */ + bne 1b /* no, try again */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + ldr r4, [sp], #4 /* restore temporary */ + RET /* return old value */ + END(_atomic_or_64) +ATOMIC_OP_ALIAS(atomic_or_64,_atomic_or_64) + +ENTRY_NP(_atomic_or_64_nv) + str r4, [sp, #-4]! /* save temporary */ +#ifndef __ARM_EABI__ + mov r3, r2 + mov r2, r1 +#endif + mov r4, r0 /* need r0 for return value */ +1: ldrexd r0, [r4] /* load old value */ + orr r0, r0, r2 /* calculate new value (return value) */ + orr r1, r1, r3 /* calculate new value (return value) */ + strexd ip, r0, [r4] /* try to store */ + cmp ip, #0 /* succeed? */ + bne 1b /* no, try again? */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + ldr r4, [sp], #4 /* restore temporary */ + RET /* return new value */ + END(_atomic_or_64_nv) +ATOMIC_OP_ALIAS(atomic_or_64_nv,_atomic_or_64_nv) + +#endif /* _ARM_ARCH_6 */ diff --git a/common/lib/libc/arch/arm/atomic/atomic_swap.S b/common/lib/libc/arch/arm/atomic/atomic_swap.S index 42a789724..b7776c2ec 100644 --- a/common/lib/libc/arch/arm/atomic/atomic_swap.S +++ b/common/lib/libc/arch/arm/atomic/atomic_swap.S @@ -1,7 +1,7 @@ -/* $NetBSD: atomic_swap.S,v 1.2 2008/08/16 07:12:40 matt Exp $ */ +/* $NetBSD: atomic_swap.S,v 1.4 2012/08/31 23:41:52 matt Exp $ */ /*- - * Copyright (c) 2007 The NetBSD Foundation, Inc. + * Copyright (c) 2007,2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -15,13 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -38,8 +31,38 @@ #include "atomic_op_asm.h" +/* + * While SWP{B} is sufficient on its own for pre-ARMv7 CPUs, on MP ARMv7 cores + * SWP{B} is disabled since it's no longer atomic among multiple CPUs. They + * will actually raise an UNDEFINED exception. + * + * So if we use the LDREX/STREX template, but use a SWP instruction followed + * by a MOV instruction (using a temporary register), that gives a handler + * for the SWP UNDEFINED exception enough information to "patch" this instance + * SWP with correct forms of LDREX/STREX. (note that this would happen even + * "read-only" pages. If the page gets tossed, we will get another exception + * and fix yet again). + */ + ENTRY_NP(_atomic_swap_32) - swp r0, r1, [r0] + mov r2, r0 +1: +#ifdef _ARM_ARCH_6 + ldrex r0, [r2] + cmp r0, r1 + strexne ip, r1, [r2] +#else + swp r0, r1, [r2] + cmp r0, r1 + movsne ip, #0 +#endif + cmpne ip, #0 + bne 1b +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET END(_atomic_swap_32) ATOMIC_OP_ALIAS(atomic_swap_32,_atomic_swap_32) @@ -51,11 +74,26 @@ STRONG_ALIAS(_atomic_swap_ulong,_atomic_swap_32) STRONG_ALIAS(_atomic_swap_ptr,_atomic_swap_32) ENTRY_NP(_atomic_swap_8) - swpb r0, r1, [r0] + mov r2, r0 +1: +#ifdef _ARM_ARCH_6 + ldrexb r0, [r2] + strexb r3, r1, [r2] +#else + swpb r0, r1, [r2] + mov r3, #0 +#endif + cmp r3, #0 + bne 1b +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif RET END(_atomic_swap_8) ATOMIC_OP_ALIAS(atomic_swap_8,_atomic_swap_8) ATOMIC_OP_ALIAS(atomic_swap_char,_atomic_swap_8) ATOMIC_OP_ALIAS(atomic_swap_uchar,_atomic_swap_8) -STRONG_ALIAS(_atomic_swap_char,_atomic_swap_32) -STRONG_ALIAS(_atomic_swap_uchar,_atomic_swap_32) +STRONG_ALIAS(_atomic_swap_char,_atomic_swap_8) +STRONG_ALIAS(_atomic_swap_uchar,_atomic_swap_8) diff --git a/common/lib/libc/arch/arm/atomic/atomic_swap_64.S b/common/lib/libc/arch/arm/atomic/atomic_swap_64.S new file mode 100644 index 000000000..f0f110be3 --- /dev/null +++ b/common/lib/libc/arch/arm/atomic/atomic_swap_64.S @@ -0,0 +1,53 @@ +/* $NetBSD: atomic_swap_64.S,v 1.2 2012/09/13 00:36:12 matt Exp $ */ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "atomic_op_asm.h" + +ENTRY_NP(_atomic_swap_64) + str r4, [sp, #-4]! /* save temporary */ + mov r4, r0 /* return value will be in r0 */ +#ifndef __ARM_EABI__ + mov r3, r2 /* r2 will be overwriten by r1 */ + mov r2, r1 /* and r1 will be overwritten by ldrexd */ +#endif +1: + ldrexd r0, [r4] /* load old value */ + strexd ip, r2, [r4] /* store new value */ + cmpne ip, #0 /* succeed? */ + bne 1b /* no, try again */ +#ifdef _ARM_ARCH_7 + dmb +#else + mcr p15, 0, ip, c7, c10, 5 /* data memory barrier */ +#endif + ldr r4, [sp], #4 /* restore temporary */ + RET + END(_atomic_swap_64) +ATOMIC_OP_ALIAS(atomic_swap_64,_atomic_swap_64) diff --git a/common/lib/libc/arch/arm/atomic/membar_ops.S b/common/lib/libc/arch/arm/atomic/membar_ops.S index c8af9f9d7..568ba65d8 100644 --- a/common/lib/libc/arch/arm/atomic/membar_ops.S +++ b/common/lib/libc/arch/arm/atomic/membar_ops.S @@ -1,4 +1,4 @@ -/* $NetBSD: membar_ops.S,v 1.2 2008/08/16 07:12:40 matt Exp $ */ +/* $NetBSD: membar_ops.S,v 1.3 2012/08/16 16:49:10 matt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. @@ -33,7 +33,11 @@ #ifdef _ARM_ARCH_6 ENTRY_NP(_membar_producer) +#ifdef _ARM_ARCH_7 + dsb +#else mcr p15, 0, r0, c7, c10, 4 /* Data Synchronization Barrier */ +#endif RET END(_membar_producer) ATOMIC_OP_ALIAS(membar_producer,_membar_producer) @@ -41,7 +45,11 @@ ATOMIC_OP_ALIAS(membar_write,_membar_producer) STRONG_ALIAS(_membar_write,_membar_producer) ENTRY_NP(_membar_sync) +#ifdef _ARM_ARCH_7 + dmb +#else mcr p15, 0, r0, c7, c10, 5 /* Data Memory Barrier */ +#endif RET END(_membar_sync) ATOMIC_OP_ALIAS(membar_sync,_membar_sync) diff --git a/common/lib/libc/arch/arm/gen/divsi3.S b/common/lib/libc/arch/arm/gen/divsi3.S index 75a927b32..d93db001b 100644 --- a/common/lib/libc/arch/arm/gen/divsi3.S +++ b/common/lib/libc/arch/arm/gen/divsi3.S @@ -1,4 +1,4 @@ -/* $NetBSD: divsi3.S,v 1.1 2005/12/20 19:28:49 christos Exp $ */ +/* $NetBSD: divsi3.S,v 1.3 2012/10/10 02:16:54 christos Exp $ */ /* * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND @@ -21,22 +21,6 @@ * which makes a C call */ -ENTRY(__umodsi3) - stmfd sp!, {lr} - sub sp, sp, #4 /* align stack */ - bl .L_udivide - add sp, sp, #4 /* unalign stack */ - mov r0, r1 - ldmfd sp!, {pc} - -ENTRY(__modsi3) - stmfd sp!, {lr} - sub sp, sp, #4 /* align stack */ - bl .L_divide - add sp, sp, #4 /* unalign stack */ - mov r0, r1 - ldmfd sp!, {pc} - .L_overflow: #if !defined(_KERNEL) && !defined(_STANDALONE) mov r0, #8 /* SIGFPE */ @@ -48,6 +32,8 @@ ENTRY(__modsi3) #endif RET +ENTRY_NP(__aeabi_uidivmod) +ENTRY_NP(__aeabi_uidiv) ENTRY(__udivsi3) .L_udivide: /* r0 = r0 / r1; r1 = r0 % r1 */ eor r0, r1, r0 @@ -70,6 +56,8 @@ ENTRY(__udivsi3) mov r1, #0 RET +ENTRY_NP(__aeabi_idivmod) +ENTRY_NP(__aeabi_idiv) ENTRY(__divsi3) .L_divide: /* r0 = r0 / r1; r1 = r0 % r1 */ eor r0, r1, r0 diff --git a/common/lib/libc/arch/arm/gen/modsi3.S b/common/lib/libc/arch/arm/gen/modsi3.S new file mode 100644 index 000000000..fce26633f --- /dev/null +++ b/common/lib/libc/arch/arm/gen/modsi3.S @@ -0,0 +1,31 @@ +/* $NetBSD: modsi3.S,v 1.1 2012/10/10 02:16:54 christos Exp $ */ + +/* + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +/* + * stack is aligned as there's a possibility of branching to .L_overflow + * which makes a C call + */ + +ENTRY(__modsi3) + stmfd sp!, {lr} + sub sp, sp, #4 /* align stack */ + bl PIC_SYM(__divsi3, PLT) + add sp, sp, #4 /* unalign stack */ + mov r0, r1 + ldmfd sp!, {pc} + diff --git a/common/lib/libc/arch/arm/gen/umodsi3.S b/common/lib/libc/arch/arm/gen/umodsi3.S new file mode 100644 index 000000000..18ec2fffb --- /dev/null +++ b/common/lib/libc/arch/arm/gen/umodsi3.S @@ -0,0 +1,30 @@ +/* $NetBSD: umodsi3.S,v 1.1 2012/10/10 02:16:54 christos Exp $ */ + +/* + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +/* + * stack is aligned as there's a possibility of branching to .L_overflow + * which makes a C call + */ + +ENTRY(__umodsi3) + stmfd sp!, {lr} + sub sp, sp, #4 /* align stack */ + bl PIC_SYM(__udivsi3, PLT) + add sp, sp, #4 /* unalign stack */ + mov r0, r1 + ldmfd sp!, {pc} diff --git a/common/lib/libc/arch/arm/quad/__aeabi_lcmp.c b/common/lib/libc/arch/arm/quad/__aeabi_lcmp.c new file mode 100644 index 000000000..fbbd836f5 --- /dev/null +++ b/common/lib/libc/arch/arm/quad/__aeabi_lcmp.c @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include + +__RCSID("$NetBSD: __aeabi_lcmp.c,v 1.2 2012/08/06 02:15:51 matt Exp $"); + +#include "quad.h" +#include + +/* + * Return -1, 0, 1 (like strcmp) if a [<, =, >] b + */ +int +__aeabi_lcmp(long long a, long long b) +{ + const union uu aa = { .q = a }, bb = { .q = b }; + + if (aa.sl[H] < bb.sl[H]) + return -1; + if (aa.sl[H] > bb.sl[H]) + return 1; + + if (aa.sl[L] < bb.sl[L]) + return -1; + if (aa.sl[L] > bb.sl[L]) + return 1; + + return 0; +} diff --git a/common/lib/libc/arch/arm/quad/__aeabi_ldivmod.S b/common/lib/libc/arch/arm/quad/__aeabi_ldivmod.S new file mode 100644 index 000000000..47de1650a --- /dev/null +++ b/common/lib/libc/arch/arm/quad/__aeabi_ldivmod.S @@ -0,0 +1,128 @@ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: __aeabi_ldivmod.S,v 1.1 2012/08/05 06:33:51 matt Exp $") + +ENTRY(__aeabi_ldivmod) + push {r4-r5, sl, lr} +#define NEG r5 + mov NEG, #0 + +#ifdef __ARMEB__ +#define ALO r1 /* incoming numerator, outgoing quotient */ +#define AHI r0 /* incoming numerator, outgoing quotient */ +#define BLO r3 /* incoming denominator, outgoing remainder */ +#define BHI r2 /* incoming denominator, outgoing remainder */ +#else +#define ALO r0 /* incoming numerator, outgoing quotient */ +#define AHI r1 /* incoming numerator, outgoing quotient */ +#define BLO r2 /* incoming denominator, outgoing remainder */ +#define BHI r3 /* incoming denominator, outgoing remainder */ +#endif + + cmp BHI, #0 + bge 2f + eor NEG, NEG, #1 /* flip quotient sign */ + bl .Lnegate_b + bcs .Lmaxdenom + +2: + cmp AHI, #0 + /* bge 3f */ + eorlt NEG, NEG, #3 /* flip quotient sign, flip remainder sign */ + bllt .Lnegate_a +3: + /* + * Arguments are setup, allocate some stack for the remainder + * and call __qdivrem for the heavy lifting. + */ + sub sp, sp, #8 + mov r4, sp /* pointer to remainder */ + bl PLT_SYM(__qdivrem) + + teq NEG, #0 /* any signs to flip? */ + /* + * The quotient is already in the right place and neither value + * needs its sign flipped. + */ + popeq {r2-r5, sl, lr} + RETc(eq) + + pop {r2, r3} + tst NEG, #2 /* does remainder need to be negative? */ + bleq .Lnegate_b + tst NEG, #1 /* does quotient need to be negative? */ + bleq .Lnegate_a + pop {r4-r5, sl, lr} + RET + +.Lnegate_a: + rsbs ALO, ALO, #0 + rsc AHI, AHI, #0 + RET + +.Lnegate_b: + rsbs BLO, BLO, #0 + rsc BHI, BHI, #0 + RET + +.Lmaxdenom: + /* + * We had a carry so the denominator must have INT64_MIN + * Also BLO and BHI never changed values so we can use + * them to see if the numerator has the same value. We + * don't have to worry about sign. + */ + teq BHI, AHI + teqeq BLO, ALO + bne 1f + + /* + * They were equal, so we return a quotient of 1 and remainder of 0. + */ + mov ALO, #1 + mov AHI, #0 + mov BLO, #0 + mov BHI, #0 + pop {r4-r5, sl, lr} + RET + + /* + * Our remainder must be the numerator and our quotient is 0. + */ +1: mov BLO, ALO + mov BHI, AHI + mov ALO, #0 + mov AHI, #0 + pop {r4-r5, sl, lr} + RET + +END(__aeabi_ldivmod) diff --git a/common/lib/libc/arch/arm/quad/__aeabi_ulcmp.c b/common/lib/libc/arch/arm/quad/__aeabi_ulcmp.c new file mode 100644 index 000000000..1bcf17173 --- /dev/null +++ b/common/lib/libc/arch/arm/quad/__aeabi_ulcmp.c @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include + +__RCSID("$NetBSD: __aeabi_ulcmp.c,v 1.2 2012/08/06 02:15:51 matt Exp $"); + +#include "quad.h" +#include + +/* + * Return -1, 0, 1 (like strcmp) if a [<, =, >] b + */ +int +__aeabi_ulcmp(unsigned long long a, unsigned long long b) +{ + const union uu aa = { .uq = a }, bb = { .uq = b }; + + if (aa.ul[H] < bb.ul[H]) + return -1; + if (aa.ul[H] > bb.ul[H]) + return 1; + + if (aa.ul[L] < bb.ul[L]) + return -1; + if (aa.ul[L] > bb.ul[L]) + return 1; + + return 0; +} diff --git a/common/lib/libc/arch/arm/quad/__aeabi_uldivmod.S b/common/lib/libc/arch/arm/quad/__aeabi_uldivmod.S new file mode 100644 index 000000000..bb352157f --- /dev/null +++ b/common/lib/libc/arch/arm/quad/__aeabi_uldivmod.S @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: __aeabi_uldivmod.S,v 1.2 2012/08/05 06:34:09 matt Exp $") + +/* + * typedef struct { unsigned long long quo, rem } ulldiv_t; + * __value_in_regs ulldiv_t __aeabi_uldivmod(unsigned long long n, + * unsigned long long d); + */ + +ENTRY(__aeabi_uldivmod) + push {r4,lr} + sub sp, sp, #8 + mov r4, sp + bl PLT_SYM(__qdivrem) + /* + * The remainder is already on the stack just waiting to be popped + * into r2/r3. + */ + pop {r2-r4,lr} + RET +END(__aeabi_uldivmod) diff --git a/common/lib/libc/arch/arm/string/ffs.S b/common/lib/libc/arch/arm/string/ffs.S index a1f108e1d..49d7b4cb9 100644 --- a/common/lib/libc/arch/arm/string/ffs.S +++ b/common/lib/libc/arch/arm/string/ffs.S @@ -1,4 +1,4 @@ -/* $NetBSD: ffs.S,v 1.1 2005/12/20 19:28:49 christos Exp $ */ +/* $NetBSD: ffs.S,v 1.2 2011/07/03 07:13:31 matt Exp $ */ /* * Copyright (c) 2001 Christopher Gilbert * All rights reserved. @@ -30,7 +30,7 @@ #include -RCSID("$NetBSD: ffs.S,v 1.1 2005/12/20 19:28:49 christos Exp $") +RCSID("$NetBSD: ffs.S,v 1.2 2011/07/03 07:13:31 matt Exp $") /* * ffs - find first set bit, this algorithm isolates the first set @@ -44,7 +44,7 @@ RCSID("$NetBSD: ffs.S,v 1.1 2005/12/20 19:28:49 christos Exp $") * This is the ffs algorithm devised by d.seal and posted to comp.sys.arm on * 16 Feb 1994. */ - +WEAK_ALIAS(__ffssi2,ffs) ENTRY(ffs) #ifdef _ARM_ARCH_5 /* (X & -X) gives LSB or zero. */ diff --git a/common/lib/libc/arch/i386/string/small/memcmp.S b/common/lib/libc/arch/i386/string/small/memcmp.S new file mode 100644 index 000000000..d18f61763 --- /dev/null +++ b/common/lib/libc/arch/i386/string/small/memcmp.S @@ -0,0 +1,50 @@ +/* $NetBSD: memcmp.S,v 1.1 2011/06/16 16:39:14 joerg Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + RCSID("$NetBSD: memcmp.S,v 1.1 2011/06/16 16:39:14 joerg Exp $") + +ENTRY(memcmp) + pushl %esi + pushl %edi + movl 12(%esp), %edi + movl 16(%esp), %esi + movl 20(%esp), %ecx + xorl %eax, %eax + rep + cmpsb + popl %edi + popl %esi + ja 1f + setnz %al + ret +1: + decl %eax + ret diff --git a/common/lib/libc/arch/i386/string/small/memcpy.S b/common/lib/libc/arch/i386/string/small/memcpy.S new file mode 100644 index 000000000..3e3162df4 --- /dev/null +++ b/common/lib/libc/arch/i386/string/small/memcpy.S @@ -0,0 +1,71 @@ +/* $NetBSD: memcpy.S,v 1.1 2011/06/16 16:39:14 joerg Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + RCSID("$NetBSD: memcpy.S,v 1.1 2011/06/16 16:39:14 joerg Exp $") + +# ifdef BCOPY +ENTRY(bcopy) + pushl %esi + pushl %edi + movl 12(%esp), %esi + movl 16(%esp), %edi + jmp __memmove_start +# endif +# if defined(MEMMOVE) +ENTRY(memcpy) +ENTRY(memmove) + pushl %esi + pushl %edi + movl 12(%esp), %edi + movl 16(%esp), %esi + .globl __memmove_start +__memmove_start: + movl 20(%esp), %ecx + pushl %edi + testl %ecx, %ecx + jz 2f + cmpl %esi, %edi + jb 1f + addl %ecx, %esi + decl %esi + addl %ecx, %edi + decl %edi + std +1: + rep + movsb +2: + cld + popl %eax + popl %edi + popl %esi + ret +# endif /* MEMMOVE */ diff --git a/common/lib/libc/arch/i386/string/small/memmove.S b/common/lib/libc/arch/i386/string/small/memmove.S new file mode 100644 index 000000000..d19f25767 --- /dev/null +++ b/common/lib/libc/arch/i386/string/small/memmove.S @@ -0,0 +1,4 @@ +/* $NetBSD: memmove.S,v 1.1 2011/06/16 16:39:14 joerg Exp $ */ + +#define MEMMOVE +#include "memcpy.S" diff --git a/common/lib/libc/arch/i386/string/small/memset.S b/common/lib/libc/arch/i386/string/small/memset.S new file mode 100644 index 000000000..fd21e7d4e --- /dev/null +++ b/common/lib/libc/arch/i386/string/small/memset.S @@ -0,0 +1,45 @@ +/* $NetBSD: memset.S,v 1.1 2011/06/16 16:39:14 joerg Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + RCSID("$NetBSD: memset.S,v 1.1 2011/06/16 16:39:14 joerg Exp $") + +ENTRY(memset) + pushl %edi + movl 8(%esp), %edi + movl 12(%esp), %eax + movl 16(%esp), %ecx + pushl %edi + rep + stosb + popl %eax + popl %edi + ret diff --git a/common/lib/libc/arch/i386/string/small/strchr.S b/common/lib/libc/arch/i386/string/small/strchr.S new file mode 100644 index 000000000..5b33347bd --- /dev/null +++ b/common/lib/libc/arch/i386/string/small/strchr.S @@ -0,0 +1,51 @@ +/* $NetBSD: strchr.S,v 1.1 2011/06/16 16:39:14 joerg Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + RCSID("$NetBSD: strchr.S,v 1.1 2011/06/16 16:39:14 joerg Exp $") + +ENTRY(strchr) + popl %edx /* Return address */ + popl %eax /* String pointer */ + popl %ecx /* Character to find */ + pushl %ecx + pushl %eax + pushl %edx +1: + cmpb $0, 0(%eax) + je 2f + cmpb %cl, 0(%eax) + je 3f + incl %eax + jmp 1b +2: + xorl %eax, %eax +3: + ret diff --git a/common/lib/libc/arch/i386/string/small/strcmp.S b/common/lib/libc/arch/i386/string/small/strcmp.S new file mode 100644 index 000000000..82e6b9263 --- /dev/null +++ b/common/lib/libc/arch/i386/string/small/strcmp.S @@ -0,0 +1,50 @@ +/* $NetBSD: strcmp.S,v 1.1 2011/06/16 16:39:14 joerg Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + RCSID("$NetBSD: strcmp.S,v 1.1 2011/06/16 16:39:14 joerg Exp $") + +ENTRY(strcmp) + pushl %esi + movl 12(%esp), %ecx + movl 8(%esp), %esi + decl %ecx +1: + incl %ecx + lodsb + cmpb 0(%ecx), %al + jne 2f + testb %al, %al + jne 1b +2: + subb 0(%ecx), %al + movsbl %al, %eax + popl %esi + ret diff --git a/common/lib/libc/arch/i386/string/small/strcpy.S b/common/lib/libc/arch/i386/string/small/strcpy.S new file mode 100644 index 000000000..3121644c9 --- /dev/null +++ b/common/lib/libc/arch/i386/string/small/strcpy.S @@ -0,0 +1,48 @@ +/* $NetBSD: strcpy.S,v 1.1 2011/06/16 16:39:14 joerg Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + RCSID("$NetBSD: strcpy.S,v 1.1 2011/06/16 16:39:14 joerg Exp $") + +ENTRY(strcpy) + pushl %esi + pushl %edi + movl 12(%esp), %edi + movl 16(%esp), %esi + pushl %edi +1: + lodsb + stosb + testb %al, %al + jne 1b + popl %eax + popl %edi + popl %esi + ret diff --git a/common/lib/libc/arch/i386/string/small/strlen.S b/common/lib/libc/arch/i386/string/small/strlen.S new file mode 100644 index 000000000..a222d20e5 --- /dev/null +++ b/common/lib/libc/arch/i386/string/small/strlen.S @@ -0,0 +1,41 @@ +/* $NetBSD: strlen.S,v 1.1 2011/06/16 16:39:14 joerg Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by David Laight. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + RCSID("$NetBSD: strlen.S,v 1.1 2011/06/16 16:39:14 joerg Exp $") +ENTRY(strlen) + movl 8(%esp), %ecx + xorl %eax, %eax + dec %eax +1: + incl %eax + cmpb $0, 0(%ecx,%eax,1) + jnz 1b + ret diff --git a/common/lib/libc/arch/m68k/string/ffs.S b/common/lib/libc/arch/m68k/string/ffs.S index f29ff4776..ead152e71 100644 --- a/common/lib/libc/arch/m68k/string/ffs.S +++ b/common/lib/libc/arch/m68k/string/ffs.S @@ -1,4 +1,4 @@ -/* $NetBSD: ffs.S,v 1.1 2005/12/20 19:28:49 christos Exp $ */ +/* $NetBSD: ffs.S,v 1.2 2011/07/09 14:57:29 mrg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -39,12 +39,14 @@ #if 0 RCSID("from: @(#)ffs.s 5.1 (Berkeley) 5/12/90") #else - RCSID("$NetBSD: ffs.S,v 1.1 2005/12/20 19:28:49 christos Exp $") + RCSID("$NetBSD: ffs.S,v 1.2 2011/07/09 14:57:29 mrg Exp $") #endif #endif /* LIBC_SCCS and not lint */ /* bit = ffs(value) */ +WEAK_ALIAS(__ffssi2,ffs) + #ifndef __mc68010__ ENTRY(ffs) diff --git a/common/lib/libc/arch/mips/atomic/atomic_add.S b/common/lib/libc/arch/mips/atomic/atomic_add.S index 298ad243a..30f418856 100644 --- a/common/lib/libc/arch/mips/atomic/atomic_add.S +++ b/common/lib/libc/arch/mips/atomic/atomic_add.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_add.S,v 1.2 2009/12/14 00:38:59 matt Exp $ */ +/* $NetBSD: atomic_add.S,v 1.4 2012/03/14 16:50:34 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -26,16 +26,24 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "atomic_op_asm.h" -RCSID("$NetBSD: atomic_add.S,v 1.2 2009/12/14 00:38:59 matt Exp $") +RCSID("$NetBSD: atomic_add.S,v 1.4 2012/03/14 16:50:34 christos Exp $") .text - .set noat .set noreorder +#ifdef _KERNEL_OPT +#include "opt_cputype.h" +#ifndef MIPS3_LOONGSON2F + .set noat + .set nomacro +#endif +#else /* _KERNEL_OPT */ + .set noat .set nomacro +#endif /* _KERNEL_OPT */ + LEAF(_atomic_add_32) 1: INT_LL t0, 0(a0) diff --git a/common/lib/libc/arch/mips/atomic/atomic_and.S b/common/lib/libc/arch/mips/atomic/atomic_and.S index 7d233d037..cb1eb4848 100644 --- a/common/lib/libc/arch/mips/atomic/atomic_and.S +++ b/common/lib/libc/arch/mips/atomic/atomic_and.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_and.S,v 1.2 2009/12/14 00:38:59 matt Exp $ */ +/* $NetBSD: atomic_and.S,v 1.4 2012/03/14 16:50:34 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -26,16 +26,24 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "atomic_op_asm.h" -RCSID("$NetBSD: atomic_and.S,v 1.2 2009/12/14 00:38:59 matt Exp $") +RCSID("$NetBSD: atomic_and.S,v 1.4 2012/03/14 16:50:34 christos Exp $") .text - .set noat .set noreorder +#ifdef _KERNEL_OPT +#include "opt_cputype.h" +#ifndef MIPS3_LOONGSON2F + .set noat + .set nomacro +#endif +#else /* _KERNEL_OPT */ + .set noat .set nomacro +#endif /* _KERNEL_OPT */ + LEAF(_atomic_and_32) 1: INT_LL t0, 0(a0) diff --git a/common/lib/libc/arch/mips/atomic/atomic_cas.S b/common/lib/libc/arch/mips/atomic/atomic_cas.S index d1747f882..45aec5cb0 100644 --- a/common/lib/libc/arch/mips/atomic/atomic_cas.S +++ b/common/lib/libc/arch/mips/atomic/atomic_cas.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_cas.S,v 1.2 2009/12/14 00:39:00 matt Exp $ */ +/* $NetBSD: atomic_cas.S,v 1.3 2012/03/14 16:50:34 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -26,11 +26,10 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "atomic_op_asm.h" -RCSID("$NetBSD: atomic_cas.S,v 1.2 2009/12/14 00:39:00 matt Exp $") +RCSID("$NetBSD: atomic_cas.S,v 1.3 2012/03/14 16:50:34 christos Exp $") .text .set noat diff --git a/common/lib/libc/arch/mips/atomic/atomic_dec.S b/common/lib/libc/arch/mips/atomic/atomic_dec.S index f44850f54..fdf7fe183 100644 --- a/common/lib/libc/arch/mips/atomic/atomic_dec.S +++ b/common/lib/libc/arch/mips/atomic/atomic_dec.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_dec.S,v 1.2 2009/12/14 00:39:00 matt Exp $ */ +/* $NetBSD: atomic_dec.S,v 1.4 2012/03/14 16:50:34 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -26,16 +26,23 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "atomic_op_asm.h" -RCSID("$NetBSD: atomic_dec.S,v 1.2 2009/12/14 00:39:00 matt Exp $") +RCSID("$NetBSD: atomic_dec.S,v 1.4 2012/03/14 16:50:34 christos Exp $") .text - .set noat .set noreorder +#ifdef _KERNEL_OPT +#include "opt_cputype.h" +#ifndef MIPS3_LOONGSON2F + .set noat + .set nomacro +#endif +#else /* _KERNEL_OPT */ + .set noat .set nomacro +#endif /* _KERNEL_OPT */ LEAF(_atomic_dec_32) 1: INT_LL t0, 0(a0) diff --git a/common/lib/libc/arch/mips/atomic/atomic_inc.S b/common/lib/libc/arch/mips/atomic/atomic_inc.S index 5ab8e4934..9a86fa142 100644 --- a/common/lib/libc/arch/mips/atomic/atomic_inc.S +++ b/common/lib/libc/arch/mips/atomic/atomic_inc.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_inc.S,v 1.2 2009/12/14 00:39:00 matt Exp $ */ +/* $NetBSD: atomic_inc.S,v 1.4 2012/03/14 16:50:34 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -26,16 +26,24 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "atomic_op_asm.h" -RCSID("$NetBSD: atomic_inc.S,v 1.2 2009/12/14 00:39:00 matt Exp $") +RCSID("$NetBSD: atomic_inc.S,v 1.4 2012/03/14 16:50:34 christos Exp $") .text - .set noat .set noreorder +#ifdef _KERNEL_OPT +#include "opt_cputype.h" +#ifndef MIPS3_LOONGSON2F + .set noat + .set nomacro +#endif +#else /* _KERNEL_OPT */ + .set noat .set nomacro +#endif /* _KERNEL_OPT */ + LEAF(_atomic_inc_32) 1: INT_LL t0, 0(a0) diff --git a/common/lib/libc/arch/mips/atomic/atomic_or.S b/common/lib/libc/arch/mips/atomic/atomic_or.S index bf25d8945..595bc4ec7 100644 --- a/common/lib/libc/arch/mips/atomic/atomic_or.S +++ b/common/lib/libc/arch/mips/atomic/atomic_or.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_or.S,v 1.2 2009/12/14 00:39:00 matt Exp $ */ +/* $NetBSD: atomic_or.S,v 1.4 2012/03/14 16:50:34 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -26,14 +26,21 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "atomic_op_asm.h" .text - .set noat .set noreorder +#ifdef _KERNEL_OPT +#include "opt_cputype.h" +#ifndef MIPS3_LOONGSON2F + .set noat + .set nomacro +#endif +#else /* _KERNEL_OPT */ + .set noat .set nomacro +#endif /* _KERNEL_OPT */ LEAF(_atomic_or_32) 1: INT_LL t0, 0(a0) diff --git a/common/lib/libc/arch/mips/atomic/atomic_swap.S b/common/lib/libc/arch/mips/atomic/atomic_swap.S index b5f94778d..e43ba88bd 100644 --- a/common/lib/libc/arch/mips/atomic/atomic_swap.S +++ b/common/lib/libc/arch/mips/atomic/atomic_swap.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_swap.S,v 1.2 2009/12/14 00:39:00 matt Exp $ */ +/* $NetBSD: atomic_swap.S,v 1.4 2012/03/14 16:50:34 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -26,16 +26,24 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "atomic_op_asm.h" -RCSID("$NetBSD: atomic_swap.S,v 1.2 2009/12/14 00:39:00 matt Exp $") +RCSID("$NetBSD: atomic_swap.S,v 1.4 2012/03/14 16:50:34 christos Exp $") .text - .set noat .set noreorder +#ifdef _KERNEL_OPT +#include "opt_cputype.h" +#ifndef MIPS3_LOONGSON2F + .set noat + .set nomacro +#endif +#else /* _KERNEL_OPT */ + .set noat .set nomacro +#endif /* _KERNEL_OPT */ + LEAF(_atomic_swap_32) 1: INT_LL v0, 0(a0) diff --git a/common/lib/libc/arch/mips/atomic/membar_ops.S b/common/lib/libc/arch/mips/atomic/membar_ops.S index 4d016246d..2f64ba6cb 100644 --- a/common/lib/libc/arch/mips/atomic/membar_ops.S +++ b/common/lib/libc/arch/mips/atomic/membar_ops.S @@ -1,4 +1,4 @@ -/* $NetBSD: membar_ops.S,v 1.4 2009/12/14 00:39:00 matt Exp $ */ +/* $NetBSD: membar_ops.S,v 1.5 2012/08/03 06:06:44 matt Exp $ */ /*- * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc. @@ -50,13 +50,14 @@ #endif .text + .set noreorder LEAF(_membar_sync) j ra #ifdef SYNC - SYNC + SYNC #else - nop + nop #endif END(_membar_sync) diff --git a/common/lib/libc/arch/mips/string/bcopy.S b/common/lib/libc/arch/mips/string/bcopy.S index 05f6777e0..d301185ef 100644 --- a/common/lib/libc/arch/mips/string/bcopy.S +++ b/common/lib/libc/arch/mips/string/bcopy.S @@ -1,4 +1,4 @@ -/* $NetBSD: bcopy.S,v 1.3 2009/12/14 00:39:00 matt Exp $ */ +/* $NetBSD: bcopy.S,v 1.4 2011/08/27 13:23:52 bouyer Exp $ */ /* * Mach Operating System @@ -46,7 +46,7 @@ #if 0 RCSID("from: @(#)mips_bcopy.s 2.2 CMU 18/06/93") #else - RCSID("$NetBSD: bcopy.S,v 1.3 2009/12/14 00:39:00 matt Exp $") + RCSID("$NetBSD: bcopy.S,v 1.4 2011/08/27 13:23:52 bouyer Exp $") #endif #endif /* LIBC_SCCS and not lint */ @@ -170,8 +170,10 @@ LEAF(FUNCTION) PTR_ADDU DSTREG,1 4: # copydone + .set at #-mfix-loongson2f-btb j ra nop + .set noat /* * Copy from unaligned source to aligned dest. @@ -264,8 +266,10 @@ LEAF(FUNCTION) PTR_SUBU DSTREG,1 4: # copydone + .set at #-mfix-loongson2f-btb j ra nop + .set noat /* * Copy from unaligned source to aligned dest. diff --git a/common/lib/libc/arch/mips/string/ffs.S b/common/lib/libc/arch/mips/string/ffs.S index 62f2d0aa6..1fca471a8 100644 --- a/common/lib/libc/arch/mips/string/ffs.S +++ b/common/lib/libc/arch/mips/string/ffs.S @@ -1,11 +1,11 @@ -/* $NetBSD: ffs.S,v 1.2 2009/12/14 00:39:00 matt Exp $ */ +/* $NetBSD: ffs.S,v 1.4 2011/07/04 11:35:26 mrg Exp $ */ /*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. * - * This code is derived from software contributed to Berkeley by - * Ralph Campbell. + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,40 +15,96 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #include -#if defined(LIBC_SCCS) && !defined(lint) - /* RCSID("from: @(#)ffs.s 8.1 (Berkeley) 6/4/93") */ - RCSID("$NetBSD: ffs.S,v 1.2 2009/12/14 00:39:00 matt Exp $") -#endif /* LIBC_SCCS and not lint */ +RCSID("$NetBSD: ffs.S,v 1.4 2011/07/04 11:35:26 mrg Exp $") /* bit = ffs(value) */ + .text + .set noreorder + +WEAK_ALIAS(__ffssi2,ffs) +#if __mips == 64 || __mips == 32 +LEAF(ffs) +#ifndef _LP64 +XLEAF(ffsl) +#endif + .set push + .set mips32 + li v1, 32 +#if __mips == 64 + sll a0, a0, 0 +#endif + negu a1, a0 + and a0, a1 + clz v0, a0 + j ra + subu v0, v1, v0 + .set pop +END(ffs) +#if defined(_LP64) && __mips == 64 +LEAF(ffsl) + li v1, 64 + negu a1, a0 + and a0, a1 + dclz v0, a0 + j ra + subu v0, v1, v0 +END(ffsl) +#endif +#else /* __mips != 64 && __mips != 32 */ + +#ifdef _LP64 +XLEAF(ffsl) + beqz a0, 6f # fast escape if 0 + li v0, 0 + + li v0, 1 + li a3, 0xffffffff # initial mask + b 1f + li a2, 32 # bit count of mask +#endif /* _LP64 */ LEAF(ffs) - move v0, zero - beq a0, zero, done +#ifndef _LP64 +XLEAF(ffsl) +#endif /* !_LP64 */ + beqz a0, 6f + li v0, 0 + + li v0, 1 + li a3, 0xffff # initial mask + li a2, 16 # bit count of mask 1: - and v1, a0, 1 # bit set? - addu v0, v0, 1 - srl a0, a0, 1 - beq v1, zero, 1b # no, continue -done: + and v1, a0, a3 # focus no lower half of bits left + bnez v1, 2f # any of the lower half set? + nop + addu v0, a2 # nope, then bit is in the upper half +#ifdef _LP64 + dsrlv a0, a0, a2 # discard low bits +#else + srlv a0, a0, a2 # discard low bits +#endif +2: + srl a2, 1 # divide bit count by 2 + bnez a2, 1b # still bits left to text? + srlv a3, a3, a2 # shrink mask in half +6: j ra + nop END(ffs) +#endif /* __mips == 64 || __mips == 32 */ diff --git a/common/lib/libc/arch/sh3/string/ffs.S b/common/lib/libc/arch/sh3/string/ffs.S index f7189bea7..d0725338d 100644 --- a/common/lib/libc/arch/sh3/string/ffs.S +++ b/common/lib/libc/arch/sh3/string/ffs.S @@ -1,4 +1,4 @@ -/* $NetBSD: ffs.S,v 1.2 2008/04/28 20:22:52 martin Exp $ */ +/* $NetBSD: ffs.S,v 1.3 2011/07/04 12:18:05 mrg Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: ffs.S,v 1.2 2008/04/28 20:22:52 martin Exp $") + RCSID("$NetBSD: ffs.S,v 1.3 2011/07/04 12:18:05 mrg Exp $") #endif /* @@ -42,6 +42,7 @@ * The remaining 8bit is tested in every 2bit. */ +WEAK_ALIAS(__ffssi2,ffs) ENTRY(ffs) mov r4,r0 ! using r0 specific instructions tst #0xff,r0 diff --git a/common/lib/libc/arch/sparc/atomic/atomic_cas.S b/common/lib/libc/arch/sparc/atomic/atomic_cas.S index ab0f29308..2d1c20949 100644 --- a/common/lib/libc/arch/sparc/atomic/atomic_cas.S +++ b/common/lib/libc/arch/sparc/atomic/atomic_cas.S @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_cas.S,v 1.10 2009/03/13 16:40:22 nakayama Exp $ */ +/* $NetBSD: atomic_cas.S,v 1.11 2011/02/22 18:45:10 pooka Exp $ */ /*- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. @@ -63,15 +63,29 @@ #if defined(MULTIPROCESSOR) .section .bss .align 1024 +#ifdef PIC + .globl _C_LABEL(_atomic_cas_locktab) +#endif OTYPE(_C_LABEL(_atomic_cas_locktab)) _C_LABEL(_atomic_cas_locktab): .space 1024 +#ifdef PIC +/* o4 is not used for PSR in PIC cases, so we can use it here */ +#define GETLOCKTAB \ + PIC_PROLOGUE(%o3,%o4) ;\ + set _C_LABEL(_atomic_cas_locktab), %o4 ;\ + ld [%o3 + %o4], %o3 +#else +#define GETLOCKTAB \ + sethi %hi(_C_LABEL(_atomic_cas_locktab)), %o3 +#endif + #define ACQUIRE_INTERLOCK \ DISABLE_INTERRUPTS ;\ srl %o0, 3, %o5 /* get lock address */ ;\ and %o5, 1023, %o5 ;\ - sethi %hi(_C_LABEL(_atomic_cas_locktab)), %o3 ;\ + GETLOCKTAB ;\ add %o5, %o3, %o5 ;\ ;\ /* %o5 has interlock address */ ;\ diff --git a/common/lib/libc/arch/sparc/string/ffs.S b/common/lib/libc/arch/sparc/string/ffs.S index 104e36263..5e8a2474d 100644 --- a/common/lib/libc/arch/sparc/string/ffs.S +++ b/common/lib/libc/arch/sparc/string/ffs.S @@ -1,4 +1,4 @@ -/* $NetBSD: ffs.S,v 1.2 2009/12/19 19:09:48 pooka Exp $ */ +/* $NetBSD: ffs.S,v 1.3 2011/07/04 11:18:23 mrg Exp $ */ /* * Copyright (c) 1992, 1993 @@ -40,7 +40,7 @@ #if 0 .asciz "@(#)ffs.s 8.1 (Berkeley) 6/4/93" #else - RCSID("$NetBSD: ffs.S,v 1.2 2009/12/19 19:09:48 pooka Exp $") + RCSID("$NetBSD: ffs.S,v 1.3 2011/07/04 11:18:23 mrg Exp $") #endif #endif /* LIBC_SCCS and not lint */ @@ -58,6 +58,7 @@ * one, we just return the table value plus 24. This means * that ffstab[0] must be -24 so that ffs(0) will return 0. */ +WEAK_ALIAS(__ffssi2,ffs) ENTRY(ffs) #ifdef PIC PICCY_SET(ffstab, %o2, %o3) diff --git a/common/lib/libc/arch/vax/gen/bswap16.S b/common/lib/libc/arch/vax/gen/bswap16.S index dc1c5932c..b89c98d99 100644 --- a/common/lib/libc/arch/vax/gen/bswap16.S +++ b/common/lib/libc/arch/vax/gen/bswap16.S @@ -1,4 +1,4 @@ -/* $NetBSD: bswap16.S,v 1.2 2008/04/28 20:22:52 martin Exp $ */ +/* $NetBSD: bswap16.S,v 1.3 2011/01/25 04:45:28 matt Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -31,14 +31,17 @@ #include +RCSID("$NetBSD: bswap16.S,v 1.3 2011/01/25 04:45:28 matt Exp $") + #if defined(_KERNEL) || defined(_STANDALONE) -ENTRY(_C_LABEL(bswap16), 0) +ALTENTRY(_C_LABEL(bswap16)) #else ALTENTRY(_C_LABEL(ntohs)) ALTENTRY(_C_LABEL(htons)) -ENTRY(_C_LABEL(__bswap16), 0) #endif +ENTRY(_C_LABEL(__bswap16), 0) movl 4(%ap), %r1 extzv $8, $8, %r1, %r0 insv %r1, $8, $8, %r0 ret +END(_C_LABEL(__bswap16)) diff --git a/common/lib/libc/arch/vax/gen/bswap32.S b/common/lib/libc/arch/vax/gen/bswap32.S index 91377ee9c..73b818577 100644 --- a/common/lib/libc/arch/vax/gen/bswap32.S +++ b/common/lib/libc/arch/vax/gen/bswap32.S @@ -1,4 +1,4 @@ -/* $NetBSD: bswap32.S,v 1.2 2008/04/28 20:22:52 martin Exp $ */ +/* $NetBSD: bswap32.S,v 1.3 2011/01/25 04:45:28 matt Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,18 +31,18 @@ #include +RCSID("$NetBSD: bswap32.S,v 1.3 2011/01/25 04:45:28 matt Exp $") + #if defined(_KERNEL) || defined(_STANDALONE) -ENTRY(_C_LABEL(bswap32), 0) +ALTENTRY(_C_LABEL(bswap32)) #else -#if BYTE_ORDER == LITTLE_ENDIAN ALTENTRY(_C_LABEL(ntohl)) ALTENTRY(_C_LABEL(htonl)) #endif ENTRY(_C_LABEL(__bswap32), 0) -#endif rotl $-8, 4(%ap), %r0 insv %r0, $16, $8, %r0 rotl $8, 4(%ap), %r1 movb %r1, %r0 ret - +END(_C_LABEL(__bswap32)) diff --git a/common/lib/libc/arch/vax/gen/bswap64.S b/common/lib/libc/arch/vax/gen/bswap64.S index b95bb7441..c94ba3caa 100644 --- a/common/lib/libc/arch/vax/gen/bswap64.S +++ b/common/lib/libc/arch/vax/gen/bswap64.S @@ -1,11 +1,9 @@ /* Written by Anders Magnusson. Public Domain */ -#if defined(LIBC_SCCS) && !defined(lint) - .asciz "$NetBSD: bswap64.S,v 1.2 2005/12/24 08:33:32 matt Exp $" -#endif /* LIBC_SCCS and not lint */ - #include +RCSID("$NetBSD: bswap64.S,v 1.3 2011/01/25 04:45:28 matt Exp $") + ENTRY(bswap64, 0) movq 4(%ap),%r3 rotl $-8,%r3,%r1 @@ -17,3 +15,4 @@ ENTRY(bswap64, 0) rotl $8,%r4,%r2 movb %r2,%r0 ret +END(bswap64) diff --git a/common/lib/libc/arch/vax/gen/udiv.S b/common/lib/libc/arch/vax/gen/udiv.S index e9819c6ce..676b59823 100644 --- a/common/lib/libc/arch/vax/gen/udiv.S +++ b/common/lib/libc/arch/vax/gen/udiv.S @@ -30,10 +30,10 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) +#include + /* .asciz "@(#)udiv.s 8.1 (Berkeley) 6/4/93" */ - .asciz "$NetBSD: udiv.S,v 1.2 2005/12/24 08:33:32 matt Exp $" -#endif /* LIBC_SCCS and not lint */ +RCSID("$NetBSD: udiv.S,v 1.3 2011/01/25 04:45:28 matt Exp $") /* * Unsigned division, PCC flavor. @@ -41,16 +41,10 @@ * audiv() takes a pointer to a dividend and an ordinary divisor. */ -#include - #define DIVIDEND 4(%ap) #define DIVISOR 8(%ap) -#ifdef __ELF__ ASENTRY(__udiv,0) -#else -ASENTRY(udiv,0) -#endif movl DIVISOR,%r2 jlss Leasy # big divisor: settle by comparison movl DIVIDEND,%r0 @@ -69,12 +63,9 @@ Leasy: Lone: movl $1,%r0 ret +END(__udiv) -#ifdef __ELF__ ASENTRY(__audiv,0) -#else -ASENTRY(audiv,0) -#endif movl DIVIDEND,%r3 movl DIVISOR,%r2 jlss La_easy # big divisor: settle by comparison @@ -98,3 +89,4 @@ La_one: movl $1,%r0 movl %r0,(%r3) ret +END(__audiv) diff --git a/common/lib/libc/arch/vax/gen/urem.S b/common/lib/libc/arch/vax/gen/urem.S index ffae00cf1..985747c98 100644 --- a/common/lib/libc/arch/vax/gen/urem.S +++ b/common/lib/libc/arch/vax/gen/urem.S @@ -30,13 +30,11 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) - /* .asciz "@(#)urem.s 8.1 (Berkeley) 6/4/93" */ - .asciz "$NetBSD: urem.S,v 1.2 2005/12/24 08:33:32 matt Exp $" -#endif /* LIBC_SCCS and not lint */ - #include + /* .asciz "@(#)urem.s 8.1 (Berkeley) 6/4/93" */ +RCSID("$NetBSD: urem.S,v 1.3 2011/01/25 04:45:28 matt Exp $") + /* * Unsigned modulus, PCC flavor. * urem() takes an ordinary dividend/divisor pair; @@ -46,11 +44,7 @@ #define DIVIDEND 4(%ap) #define DIVISOR 8(%ap) -#ifdef __ELF__ ASENTRY(__urem,0) -#else -ASENTRY(urem,0) -#endif movl DIVISOR,%r2 jlss Leasy # big divisor: settle by comparison movl DIVIDEND,%r0 @@ -69,12 +63,9 @@ Leasy: movl DIVIDEND,%r0 # if divisor is bigger, return dividend Ldifference: ret +END(__urem) -#ifdef __ELF__ ASENTRY(__aurem,0) -#else -ASENTRY(aurem,0) -#endif movl DIVIDEND,%r3 movl DIVISOR,%r2 jlss La_easy # big divisor: settle by comparison @@ -98,3 +89,4 @@ La_easy: La_dividend: movl (%r3),%r0 ret +END(__aurem) diff --git a/common/lib/libc/arch/vax/string/memcpy.S b/common/lib/libc/arch/vax/string/memcpy.S index 843451c0d..df766cf0c 100644 --- a/common/lib/libc/arch/vax/string/memcpy.S +++ b/common/lib/libc/arch/vax/string/memcpy.S @@ -1,4 +1,4 @@ -/* $NetBSD: memcpy.S,v 1.2 2005/12/24 08:33:32 matt Exp $ */ +/* $NetBSD: memcpy.S,v 1.3 2011/01/25 04:45:28 matt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -28,9 +28,10 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) - .asciz "@(#)memcpy.s 8.1 (Berkeley) 6/4/93" -#endif /* LIBC_SCCS and not lint */ +#include + +/* .asciz "@(#)memcpy.s 8.1 (Berkeley) 6/4/93" */ +RCSID("$NetBSD: memcpy.S,v 1.3 2011/01/25 04:45:28 matt Exp $") /* * void *memcpy(dst, src, size) @@ -40,8 +41,6 @@ * of some extra memory references and branches when count >= 65536. */ -#include - ENTRY(memcpy, 0) movzwl $65535,%r0 /* %r0 = 64K (needed below) */ movq 8(%ap),%r1 /* %r1 = src, %r2 = length */ @@ -88,3 +87,4 @@ ENTRY(memcpy, 0) subl2 %r0,%r1 subl2 %r0,%r3 brb 5b +END(memcpy) diff --git a/common/lib/libc/arch/vax/string/memmove.S b/common/lib/libc/arch/vax/string/memmove.S index 9e6516ae2..b71526fdc 100644 --- a/common/lib/libc/arch/vax/string/memmove.S +++ b/common/lib/libc/arch/vax/string/memmove.S @@ -1,4 +1,4 @@ -/* $NetBSD: memmove.S,v 1.2 2005/12/24 08:33:32 matt Exp $ */ +/* $NetBSD: memmove.S,v 1.3 2011/01/25 04:45:28 matt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -28,9 +28,10 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) - .asciz "@(#)memmove.s 8.1 (Berkeley) 6/4/93" -#endif /* LIBC_SCCS and not lint */ +#include + +/* .asciz "@(#)memmove.s 8.1 (Berkeley) 6/4/93" */ +RCSID("$NetBSD: memmove.S,v 1.3 2011/01/25 04:45:28 matt Exp $") /* * void *memmove(dst, src, size) @@ -40,8 +41,6 @@ * of some extra memory references and branches when count >= 65536. */ -#include - ENTRY(memmove, 0) movzwl $65535,%r0 /* %r0 = 64K (needed below) */ movq 8(%ap),%r1 /* %r1 = src, %r2 = length */ @@ -88,3 +87,4 @@ ENTRY(memmove, 0) subl2 %r0,%r1 subl2 %r0,%r3 brb 5b +END(memmove) diff --git a/common/lib/libc/arch/vax/string/memset.S b/common/lib/libc/arch/vax/string/memset.S index 670957772..3d725c892 100644 --- a/common/lib/libc/arch/vax/string/memset.S +++ b/common/lib/libc/arch/vax/string/memset.S @@ -1,4 +1,4 @@ -/* $NetBSD: memset.S,v 1.1 2010/03/12 09:12:34 uwe Exp $ */ +/* $NetBSD: memset.S,v 1.2 2011/01/25 04:45:28 matt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -28,13 +28,12 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) - .asciz "@(#)memset.s 8.1 (Berkeley) 6/4/93" -#endif /* LIBC_SCCS and not lint */ +#include -/* void *memset(base, c, length) */ +/* .asciz "@(#)memset.s 8.1 (Berkeley) 6/4/93" */ +RCSID("$NetBSD: memset.S,v 1.2 2011/01/25 04:45:28 matt Exp $") -#include +/* void *memset(base, c, length) */ ENTRY(memset, 0) movl 4(%ap),%r3 @@ -50,3 +49,4 @@ ENTRY(memset, 0) subl2 %r0,12(%ap) movc5 $0,(%r3),%r1,%r0,(%r3) jbr 1b +END(memset) diff --git a/common/lib/libc/atomic/atomic_init_testset.c b/common/lib/libc/atomic/atomic_init_testset.c index 74baecf12..f85ddf5b1 100644 --- a/common/lib/libc/atomic/atomic_init_testset.c +++ b/common/lib/libc/atomic/atomic_init_testset.c @@ -1,4 +1,4 @@ -/* $NetBSD: atomic_init_testset.c,v 1.7 2009/12/14 00:39:00 matt Exp $ */ +/* $NetBSD: atomic_init_testset.c,v 1.8 2012/02/28 20:41:19 joerg Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ */ #include -__RCSID("$NetBSD: atomic_init_testset.c,v 1.7 2009/12/14 00:39:00 matt Exp $"); +__RCSID("$NetBSD: atomic_init_testset.c,v 1.8 2012/02/28 20:41:19 joerg Exp $"); #include "atomic_op_namespace.h" @@ -139,6 +139,10 @@ __libc_atomic_init(void) #undef atomic_cas_uint #undef atomic_cas_ulong #undef atomic_cas_ptr +#undef atomic_cas_32_ni +#undef atomic_cas_uint_ni +#undef atomic_cas_ulong_ni +#undef atomic_cas_ptr_ni atomic_op_alias(atomic_cas_32,_atomic_cas_32) atomic_op_alias(atomic_cas_uint,_atomic_cas_32) diff --git a/common/lib/libc/gen/bswap16.c b/common/lib/libc/gen/bswap16.c index 54496fee1..99133f166 100644 --- a/common/lib/libc/gen/bswap16.c +++ b/common/lib/libc/gen/bswap16.c @@ -1,4 +1,4 @@ -/* $NetBSD: bswap16.c,v 1.2 2008/02/16 17:37:13 apb Exp $ */ +/* $NetBSD: bswap16.c,v 1.4 2012/03/17 20:57:35 martin Exp $ */ /* * Written by Manuel Bouyer . @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: bswap16.c,v 1.2 2008/02/16 17:37:13 apb Exp $"); +__RCSID("$NetBSD: bswap16.c,v 1.4 2012/03/17 20:57:35 martin Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -16,8 +16,8 @@ __RCSID("$NetBSD: bswap16.c,v 1.2 2008/02/16 17:37:13 apb Exp $"); #undef bswap16 uint16_t -bswap16(x) - uint16_t x; +bswap16(uint16_t x) { + /*LINTED*/ return ((x << 8) & 0xff00) | ((x >> 8) & 0x00ff); } diff --git a/common/lib/libc/gen/bswap32.c b/common/lib/libc/gen/bswap32.c index ded986636..fee64d61c 100644 --- a/common/lib/libc/gen/bswap32.c +++ b/common/lib/libc/gen/bswap32.c @@ -1,4 +1,4 @@ -/* $NetBSD: bswap32.c,v 1.2 2008/02/16 17:37:13 apb Exp $ */ +/* $NetBSD: bswap32.c,v 1.3 2011/07/04 21:20:27 joerg Exp $ */ /* * Written by Manuel Bouyer . @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: bswap32.c,v 1.2 2008/02/16 17:37:13 apb Exp $"); +__RCSID("$NetBSD: bswap32.c,v 1.3 2011/07/04 21:20:27 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -16,8 +16,7 @@ __RCSID("$NetBSD: bswap32.c,v 1.2 2008/02/16 17:37:13 apb Exp $"); #undef bswap32 uint32_t -bswap32(x) - uint32_t x; +bswap32(uint32_t x) { return ((x << 24) & 0xff000000 ) | ((x << 8) & 0x00ff0000 ) | diff --git a/common/lib/libc/gen/ptree.c b/common/lib/libc/gen/ptree.c index 1a2b9403c..da1895500 100644 --- a/common/lib/libc/gen/ptree.c +++ b/common/lib/libc/gen/ptree.c @@ -1,4 +1,4 @@ -/* $NetBSD: ptree.c,v 1.5 2009/06/07 03:12:40 yamt Exp $ */ +/* $NetBSD: ptree.c,v 1.10 2012/10/06 22:15:09 matt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -40,7 +40,7 @@ #include #include #include -__KERNEL_RCSID(0, "$NetBSD: ptree.c,v 1.5 2009/06/07 03:12:40 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ptree.c,v 1.10 2012/10/06 22:15:09 matt Exp $"); #else #include #include @@ -53,7 +53,7 @@ __KERNEL_RCSID(0, "$NetBSD: ptree.c,v 1.5 2009/06/07 03:12:40 yamt Exp $"); #else #define KASSERT(e) do { } while (/*CONSTCOND*/ 0) #endif -__RCSID("$NetBSD: ptree.c,v 1.5 2009/06/07 03:12:40 yamt Exp $"); +__RCSID("$NetBSD: ptree.c,v 1.10 2012/10/06 22:15:09 matt Exp $"); #endif /* _KERNEL || _STANDALONE */ #ifdef _LIBC @@ -67,7 +67,7 @@ __RCSID("$NetBSD: ptree.c,v 1.5 2009/06/07 03:12:40 yamt Exp $"); #endif /* - * This is an implementation of a radix / PATRICIA tree. As in a traditional + * This is an implementation of a radix / PATRICIA tree. As in a traditional * patricia tree, all the data is at the leaves of the tree. An N-value * tree would have N leaves, N-1 branching nodes, and a root pointer. Each * branching node would have left(0) and right(1) pointers that either point @@ -76,15 +76,15 @@ __RCSID("$NetBSD: ptree.c,v 1.5 2009/06/07 03:12:40 yamt Exp $"); * have no need for pointers. * * However, allocation for these branching nodes is problematic since the - * allocation could fail. This would cause insertions to fail for reasons - * beyond the users control. So to prevent this, in this implementation + * allocation could fail. This would cause insertions to fail for reasons + * beyond the user's control. So to prevent this, in this implementation * each node has two identities: its leaf identity and its branch identity. * Each is separate from the other. Every branch is tagged as to whether * it points to a leaf or a branch. This is not an attribute of the object * but of the pointer to the object. The low bit of the pointer is used as * the tag to determine whether it points to a leaf or branch identity, with * branch identities having the low bit set. - * + * * A node's branch identity has one rule: when traversing the tree from the * root to the node's leaf identity, one of the branches traversed will be via * the node's branch identity. Of course, that has an exception: since to @@ -93,7 +93,7 @@ __RCSID("$NetBSD: ptree.c,v 1.5 2009/06/07 03:12:40 yamt Exp $"); * * Branching nodes also has a bit offset and a bit length which determines * which branch slot is used. The bit length can be zero resulting in a - * one-way branch. This is happens in two special cases: the root and + * one-way branch. This happens in two special cases: the root and * interior mask nodes. * * To support longest match first lookups, when a mask node (one that only @@ -124,8 +124,8 @@ ptree_matchnode(const pt_tree_t *pt, const pt_node_t *target, pt_bitoff_t *bitoff_p, pt_slot_t *slots_p) { return (*pt->pt_ops->ptto_matchnode)(NODETOKEY(pt, target), - (ptn != NULL ? NODETOKEY(pt, ptn) : NULL), max_bitoff, - bitoff_p, slots_p); + (ptn != NULL ? NODETOKEY(pt, ptn) : NULL), + max_bitoff, bitoff_p, slots_p, pt->pt_context); } static inline pt_slot_t @@ -134,10 +134,9 @@ ptree_testnode(const pt_tree_t *pt, const pt_node_t *target, { const pt_bitlen_t bitlen = PTN_BRANCH_BITLEN(ptn); if (bitlen == 0) - return PT_SLOT_ROOT; + return PT_SLOT_ROOT; /* mask or root, doesn't matter */ return (*pt->pt_ops->ptto_testnode)(NODETOKEY(pt, target), - PTN_BRANCH_BITOFF(ptn), - bitlen); + PTN_BRANCH_BITOFF(ptn), bitlen, pt->pt_context); } static inline bool @@ -145,15 +144,17 @@ ptree_matchkey(const pt_tree_t *pt, const void *key, const pt_node_t *ptn, pt_bitoff_t bitoff, pt_bitlen_t bitlen) { return (*pt->pt_ops->ptto_matchkey)(key, NODETOKEY(pt, ptn), - bitoff, bitlen); + bitoff, bitlen, pt->pt_context); } static inline pt_slot_t ptree_testkey(const pt_tree_t *pt, const void *key, const pt_node_t *ptn) { - return (*pt->pt_ops->ptto_testkey)(key, - PTN_BRANCH_BITOFF(ptn), - PTN_BRANCH_BITLEN(ptn)); + const pt_bitlen_t bitlen = PTN_BRANCH_BITLEN(ptn); + if (bitlen == 0) + return PT_SLOT_ROOT; /* mask or root, doesn't matter */ + return (*pt->pt_ops->ptto_testkey)(key, PTN_BRANCH_BITOFF(ptn), + PTN_BRANCH_BITLEN(ptn), pt->pt_context); } static inline void @@ -166,12 +167,13 @@ ptree_set_position(uintptr_t node, pt_slot_t position) } void -ptree_init(pt_tree_t *pt, const pt_tree_ops_t *ops, size_t node_offset, - size_t key_offset) +ptree_init(pt_tree_t *pt, const pt_tree_ops_t *ops, void *context, + size_t node_offset, size_t key_offset) { memset(pt, 0, sizeof(*pt)); pt->pt_node_offset = node_offset; pt->pt_key_offset = key_offset; + pt->pt_context = context; pt->pt_ops = ops; } @@ -456,6 +458,12 @@ ptree_insert_node_common(pt_tree_t *pt, void *item) pt_insertfunc_t insertfunc; pt_insertdata_t id; + /* + * If this node already exists in the tree, return failure. + */ + if (target == PT_NODE(pt->pt_root)) + return false; + /* * We need a leaf so we can match against. Until we get a leaf * we having nothing to test against. @@ -477,6 +485,12 @@ ptree_insert_node_common(pt_tree_t *pt, void *item) pt_node_t * const ptn = PT_NODE(*id.id_insertp); id.id_node = *id.id_insertp; + /* + * If this node already exists in the tree, return failure. + */ + if (target == ptn) + return false; + /* * If we hit a leaf, try to insert target at leaf. We could * have inlined ptree_insert_leaf here but that would have @@ -614,7 +628,7 @@ ptree_insert_mask_node(pt_tree_t *pt, void *item, pt_bitlen_t mask_len) #endif /* !PTNOMASH */ void * -ptree_find_filtered_node(pt_tree_t *pt, void *key, pt_filter_t filter, +ptree_find_filtered_node(pt_tree_t *pt, const void *key, pt_filter_t filter, void *filter_arg) { #ifndef PTNOMASK @@ -1200,3 +1214,17 @@ ptree_check(const pt_tree_t *pt) #endif return ok; } + +bool +ptree_mask_node_p(pt_tree_t *pt, const void *item, pt_bitlen_t *lenp) +{ + const pt_node_t * const mask = ITEMTONODE(pt, item); + + if (!PTN_ISMASK_P(mask)) + return false; + + if (lenp != NULL) + *lenp = PTN_MASK_BITLEN(mask); + + return true; +} diff --git a/common/lib/libc/gen/radixtree.c b/common/lib/libc/gen/radixtree.c new file mode 100644 index 000000000..cd1ec6c32 --- /dev/null +++ b/common/lib/libc/gen/radixtree.c @@ -0,0 +1,1466 @@ +/* $NetBSD: radixtree.c,v 1.17 2011/11/02 13:49:43 yamt Exp $ */ + +/*- + * Copyright (c)2011 YAMAMOTO Takashi, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * radixtree.c + * + * this is an implementation of radix tree, whose keys are uint64_t and leafs + * are user provided pointers. + * + * leaf nodes are just void * and this implementation doesn't care about + * what they actually point to. however, this implementation has an assumption + * about their alignment. specifically, this implementation assumes that their + * 2 LSBs are zero and uses them internally. + * + * intermediate nodes are automatically allocated and freed internally and + * basically users don't need to care about them. only radix_tree_insert_node + * function can allocate memory for intermediate nodes and thus can fail for + * ENOMEM. + * + * efficiency: + * it's designed to work efficiently with dense index distribution. + * the memory consumption (number of necessary intermediate nodes) + * heavily depends on index distribution. basically, more dense index + * distribution consumes less nodes per item. + * approximately, + * the best case: about RADIX_TREE_PTR_PER_NODE items per intermediate node. + * the worst case: RADIX_TREE_MAX_HEIGHT intermediate nodes per item. + * + * gang lookup: + * this implementation provides a way to lookup many nodes quickly via + * radix_tree_gang_lookup_node function and its varients. + * + * tags: + * this implementation provides tagging functionality to allow quick + * scanning of a subset of leaf nodes. leaf nodes are untagged when + * inserted into the tree and can be tagged by radix_tree_set_tag function. + * radix_tree_gang_lookup_tagged_node function and its variants returns + * only leaf nodes with the given tag. to reduce amount of nodes to visit for + * these functions, this implementation keeps tagging information in internal + * intermediate nodes and quickly skips uninterested parts of a tree. + */ + +#include + +#if defined(_KERNEL) || defined(_STANDALONE) +__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.17 2011/11/02 13:49:43 yamt Exp $"); +#include +#include +#include +#include +#include +#if defined(_STANDALONE) +#include +#endif /* defined(_STANDALONE) */ +#else /* defined(_KERNEL) || defined(_STANDALONE) */ +__RCSID("$NetBSD: radixtree.c,v 1.17 2011/11/02 13:49:43 yamt Exp $"); +#include +#include +#include +#include +#include +#if 1 +#define KASSERT assert +#else +#define KASSERT(a) /* nothing */ +#endif +#endif /* defined(_KERNEL) || defined(_STANDALONE) */ + +#include + +#define RADIX_TREE_BITS_PER_HEIGHT 4 /* XXX tune */ +#define RADIX_TREE_PTR_PER_NODE (1 << RADIX_TREE_BITS_PER_HEIGHT) +#define RADIX_TREE_MAX_HEIGHT (64 / RADIX_TREE_BITS_PER_HEIGHT) +#define RADIX_TREE_INVALID_HEIGHT (RADIX_TREE_MAX_HEIGHT + 1) +__CTASSERT((64 % RADIX_TREE_BITS_PER_HEIGHT) == 0); + +__CTASSERT(((1 << RADIX_TREE_TAG_ID_MAX) & (sizeof(int) - 1)) == 0); +#define RADIX_TREE_TAG_MASK ((1 << RADIX_TREE_TAG_ID_MAX) - 1) + +static inline void * +entry_ptr(void *p) +{ + + return (void *)((uintptr_t)p & ~RADIX_TREE_TAG_MASK); +} + +static inline unsigned int +entry_tagmask(void *p) +{ + + return (uintptr_t)p & RADIX_TREE_TAG_MASK; +} + +static inline void * +entry_compose(void *p, unsigned int tagmask) +{ + + return (void *)((uintptr_t)p | tagmask); +} + +static inline bool +entry_match_p(void *p, unsigned int tagmask) +{ + + KASSERT(entry_ptr(p) != NULL || entry_tagmask(p) == 0); + if (p == NULL) { + return false; + } + if (tagmask == 0) { + return true; + } + return (entry_tagmask(p) & tagmask) != 0; +} + +static inline unsigned int +tagid_to_mask(radix_tree_tagid_t id) +{ + + KASSERT(id >= 0); + KASSERT(id < RADIX_TREE_TAG_ID_MAX); + return 1U << id; +} + +/* + * radix_tree_node: an intermediate node + * + * we don't care the type of leaf nodes. they are just void *. + */ + +struct radix_tree_node { + void *n_ptrs[RADIX_TREE_PTR_PER_NODE]; + unsigned int n_nptrs; /* # of non-NULL pointers in n_ptrs */ +}; + +/* + * any_children_tagmask: + * + * return OR'ed tagmask of the given node's children. + */ + +static unsigned int +any_children_tagmask(const struct radix_tree_node *n) +{ + unsigned int mask; + int i; + + mask = 0; + for (i = 0; i < RADIX_TREE_PTR_PER_NODE; i++) { + mask |= (unsigned int)(uintptr_t)n->n_ptrs[i]; + } + return mask & RADIX_TREE_TAG_MASK; +} + +/* + * p_refs[0].pptr == &t->t_root + * : + * p_refs[n].pptr == &(*p_refs[n-1])->n_ptrs[x] + * : + * : + * p_refs[t->t_height].pptr == &leaf_pointer + */ + +struct radix_tree_path { + struct radix_tree_node_ref { + void **pptr; + } p_refs[RADIX_TREE_MAX_HEIGHT + 1]; /* +1 for the root ptr */ + /* + * p_lastidx is either the index of the last valid element of p_refs[] + * or RADIX_TREE_INVALID_HEIGHT. + * RADIX_TREE_INVALID_HEIGHT means that radix_tree_lookup_ptr found + * that the height of the tree is not enough to cover the given index. + */ + unsigned int p_lastidx; +}; + +static inline void ** +path_pptr(const struct radix_tree *t, const struct radix_tree_path *p, + unsigned int height) +{ + + KASSERT(height <= t->t_height); + return p->p_refs[height].pptr; +} + +static inline struct radix_tree_node * +path_node(const struct radix_tree * t, const struct radix_tree_path *p, + unsigned int height) +{ + + KASSERT(height <= t->t_height); + return entry_ptr(*path_pptr(t, p, height)); +} + +/* + * radix_tree_init_tree: + * + * initialize a tree. + */ + +void +radix_tree_init_tree(struct radix_tree *t) +{ + + t->t_height = 0; + t->t_root = NULL; +} + +/* + * radix_tree_init_tree: + * + * clean up a tree. + */ + +void +radix_tree_fini_tree(struct radix_tree *t) +{ + + KASSERT(t->t_root == NULL); + KASSERT(t->t_height == 0); +} + +bool +radix_tree_empty_tree_p(struct radix_tree *t) +{ + + return t->t_root == NULL; +} + +bool +radix_tree_empty_tagged_tree_p(struct radix_tree *t, radix_tree_tagid_t tagid) +{ + const unsigned int tagmask = tagid_to_mask(tagid); + + return (entry_tagmask(t->t_root) & tagmask) == 0; +} + +static void +radix_tree_node_init(struct radix_tree_node *n) +{ + + memset(n, 0, sizeof(*n)); +} + +#if defined(_KERNEL) +pool_cache_t radix_tree_node_cache __read_mostly; + +static int +radix_tree_node_ctor(void *dummy, void *item, int flags) +{ + struct radix_tree_node *n = item; + + KASSERT(dummy == NULL); + radix_tree_node_init(n); + return 0; +} + +/* + * radix_tree_init: + * + * initialize the subsystem. + */ + +void +radix_tree_init(void) +{ + + radix_tree_node_cache = pool_cache_init(sizeof(struct radix_tree_node), + 0, 0, 0, "radix_tree_node", NULL, IPL_NONE, radix_tree_node_ctor, + NULL, NULL); + KASSERT(radix_tree_node_cache != NULL); +} +#endif /* defined(_KERNEL) */ + +static bool __unused +radix_tree_node_clean_p(const struct radix_tree_node *n) +{ + unsigned int i; + + if (n->n_nptrs != 0) { + return false; + } + for (i = 0; i < RADIX_TREE_PTR_PER_NODE; i++) { + if (n->n_ptrs[i] != NULL) { + return false; + } + } + return true; +} + +static struct radix_tree_node * +radix_tree_alloc_node(void) +{ + struct radix_tree_node *n; + +#if defined(_KERNEL) + n = pool_cache_get(radix_tree_node_cache, PR_NOWAIT); +#else /* defined(_KERNEL) */ +#if defined(_STANDALONE) + n = alloc(sizeof(*n)); +#else /* defined(_STANDALONE) */ + n = malloc(sizeof(*n)); +#endif /* defined(_STANDALONE) */ + if (n != NULL) { + radix_tree_node_init(n); + } +#endif /* defined(_KERNEL) */ + KASSERT(n == NULL || radix_tree_node_clean_p(n)); + return n; +} + +static void +radix_tree_free_node(struct radix_tree_node *n) +{ + + KASSERT(radix_tree_node_clean_p(n)); +#if defined(_KERNEL) + pool_cache_put(radix_tree_node_cache, n); +#elif defined(_STANDALONE) + dealloc(n, sizeof(*n)); +#else + free(n); +#endif +} + +static int +radix_tree_grow(struct radix_tree *t, unsigned int newheight) +{ + const unsigned int tagmask = entry_tagmask(t->t_root); + + KASSERT(newheight <= 64 / RADIX_TREE_BITS_PER_HEIGHT); + if (t->t_root == NULL) { + t->t_height = newheight; + return 0; + } + while (t->t_height < newheight) { + struct radix_tree_node *n; + + n = radix_tree_alloc_node(); + if (n == NULL) { + /* + * don't bother to revert our changes. + * the caller will likely retry. + */ + return ENOMEM; + } + n->n_nptrs = 1; + n->n_ptrs[0] = t->t_root; + t->t_root = entry_compose(n, tagmask); + t->t_height++; + } + return 0; +} + +/* + * radix_tree_lookup_ptr: + * + * an internal helper function used for various exported functions. + * + * return the pointer to store the node for the given index. + * + * if alloc is true, try to allocate the storage. (note for _KERNEL: + * in that case, this function can block.) if the allocation failed or + * alloc is false, return NULL. + * + * if path is not NULL, fill it for the caller's investigation. + * + * if tagmask is not zero, search only for nodes with the tag set. + * note that, however, this function doesn't check the tagmask for the leaf + * pointer. it's a caller's responsibility to investigate the value which + * is pointed by the returned pointer if necessary. + * + * while this function is a bit large, as it's called with some constant + * arguments, inlining might have benefits. anyway, a compiler will decide. + */ + +static inline void ** +radix_tree_lookup_ptr(struct radix_tree *t, uint64_t idx, + struct radix_tree_path *path, bool alloc, const unsigned int tagmask) +{ + struct radix_tree_node *n; + int hshift = RADIX_TREE_BITS_PER_HEIGHT * t->t_height; + int shift; + void **vpp; + const uint64_t mask = (UINT64_C(1) << RADIX_TREE_BITS_PER_HEIGHT) - 1; + struct radix_tree_node_ref *refs = NULL; + + /* + * check unsupported combinations + */ + KASSERT(tagmask == 0 || !alloc); + KASSERT(path == NULL || !alloc); + vpp = &t->t_root; + if (path != NULL) { + refs = path->p_refs; + refs->pptr = vpp; + } + n = NULL; + for (shift = 64 - RADIX_TREE_BITS_PER_HEIGHT; shift >= 0;) { + struct radix_tree_node *c; + void *entry; + const uint64_t i = (idx >> shift) & mask; + + if (shift >= hshift) { + unsigned int newheight; + + KASSERT(vpp == &t->t_root); + if (i == 0) { + shift -= RADIX_TREE_BITS_PER_HEIGHT; + continue; + } + if (!alloc) { + if (path != NULL) { + KASSERT((refs - path->p_refs) == 0); + path->p_lastidx = + RADIX_TREE_INVALID_HEIGHT; + } + return NULL; + } + newheight = shift / RADIX_TREE_BITS_PER_HEIGHT + 1; + if (radix_tree_grow(t, newheight)) { + return NULL; + } + hshift = RADIX_TREE_BITS_PER_HEIGHT * t->t_height; + } + entry = *vpp; + c = entry_ptr(entry); + if (c == NULL || + (tagmask != 0 && + (entry_tagmask(entry) & tagmask) == 0)) { + if (!alloc) { + if (path != NULL) { + path->p_lastidx = refs - path->p_refs; + } + return NULL; + } + c = radix_tree_alloc_node(); + if (c == NULL) { + return NULL; + } + *vpp = c; + if (n != NULL) { + KASSERT(n->n_nptrs < RADIX_TREE_PTR_PER_NODE); + n->n_nptrs++; + } + } + n = c; + vpp = &n->n_ptrs[i]; + if (path != NULL) { + refs++; + refs->pptr = vpp; + } + shift -= RADIX_TREE_BITS_PER_HEIGHT; + } + if (alloc) { + KASSERT(*vpp == NULL); + if (n != NULL) { + KASSERT(n->n_nptrs < RADIX_TREE_PTR_PER_NODE); + n->n_nptrs++; + } + } + if (path != NULL) { + path->p_lastidx = refs - path->p_refs; + } + return vpp; +} + +/* + * radix_tree_insert_node: + * + * insert the node at idx. + * it's illegal to insert NULL. + * it's illegal to insert a non-aligned pointer. + * + * this function returns ENOMEM if necessary memory allocation failed. + * otherwise, this function returns 0. + * + * note that inserting a node can involves memory allocation for intermediate + * nodes. if _KERNEL, it's done with no-sleep IPL_NONE memory allocation. + * + * for the newly inserted node, all tags are cleared. + */ + +int +radix_tree_insert_node(struct radix_tree *t, uint64_t idx, void *p) +{ + void **vpp; + + KASSERT(p != NULL); + KASSERT(entry_compose(p, 0) == p); + vpp = radix_tree_lookup_ptr(t, idx, NULL, true, 0); + if (vpp == NULL) { + return ENOMEM; + } + KASSERT(*vpp == NULL); + *vpp = p; + return 0; +} + +/* + * radix_tree_replace_node: + * + * replace a node at the given index with the given node. + * return the old node. + * it's illegal to try to replace a node which has not been inserted. + * + * this function doesn't change tags. + */ + +void * +radix_tree_replace_node(struct radix_tree *t, uint64_t idx, void *p) +{ + void **vpp; + void *oldp; + + KASSERT(p != NULL); + KASSERT(entry_compose(p, 0) == p); + vpp = radix_tree_lookup_ptr(t, idx, NULL, false, 0); + KASSERT(vpp != NULL); + oldp = *vpp; + KASSERT(oldp != NULL); + *vpp = entry_compose(p, entry_tagmask(*vpp)); + return entry_ptr(oldp); +} + +/* + * radix_tree_remove_node: + * + * remove the node at idx. + * it's illegal to try to remove a node which has not been inserted. + */ + +void * +radix_tree_remove_node(struct radix_tree *t, uint64_t idx) +{ + struct radix_tree_path path; + void **vpp; + void *oldp; + int i; + + vpp = radix_tree_lookup_ptr(t, idx, &path, false, 0); + KASSERT(vpp != NULL); + oldp = *vpp; + KASSERT(oldp != NULL); + KASSERT(path.p_lastidx == t->t_height); + KASSERT(vpp == path_pptr(t, &path, path.p_lastidx)); + *vpp = NULL; + for (i = t->t_height - 1; i >= 0; i--) { + void *entry; + struct radix_tree_node ** const pptr = + (struct radix_tree_node **)path_pptr(t, &path, i); + struct radix_tree_node *n; + + KASSERT(pptr != NULL); + entry = *pptr; + n = entry_ptr(entry); + KASSERT(n != NULL); + KASSERT(n->n_nptrs > 0); + n->n_nptrs--; + if (n->n_nptrs > 0) { + break; + } + radix_tree_free_node(n); + *pptr = NULL; + } + /* + * fix up height + */ + if (i < 0) { + KASSERT(t->t_root == NULL); + t->t_height = 0; + } + /* + * update tags + */ + for (; i >= 0; i--) { + void *entry; + struct radix_tree_node ** const pptr = + (struct radix_tree_node **)path_pptr(t, &path, i); + struct radix_tree_node *n; + unsigned int newmask; + + KASSERT(pptr != NULL); + entry = *pptr; + n = entry_ptr(entry); + KASSERT(n != NULL); + KASSERT(n->n_nptrs > 0); + newmask = any_children_tagmask(n); + if (newmask == entry_tagmask(entry)) { + break; + } + *pptr = entry_compose(n, newmask); + } + /* + * XXX is it worth to try to reduce height? + * if we do that, make radix_tree_grow rollback its change as well. + */ + return entry_ptr(oldp); +} + +/* + * radix_tree_lookup_node: + * + * returns the node at idx. + * returns NULL if nothing is found at idx. + */ + +void * +radix_tree_lookup_node(struct radix_tree *t, uint64_t idx) +{ + void **vpp; + + vpp = radix_tree_lookup_ptr(t, idx, NULL, false, 0); + if (vpp == NULL) { + return NULL; + } + return entry_ptr(*vpp); +} + +static inline void +gang_lookup_init(struct radix_tree *t, uint64_t idx, + struct radix_tree_path *path, const unsigned int tagmask) +{ + void **vpp; + + vpp = radix_tree_lookup_ptr(t, idx, path, false, tagmask); + KASSERT(vpp == NULL || + vpp == path_pptr(t, path, path->p_lastidx)); + KASSERT(&t->t_root == path_pptr(t, path, 0)); + KASSERT(path->p_lastidx == RADIX_TREE_INVALID_HEIGHT || + path->p_lastidx == t->t_height || + !entry_match_p(*path_pptr(t, path, path->p_lastidx), tagmask)); +} + +/* + * gang_lookup_scan: + * + * a helper routine for radix_tree_gang_lookup_node and its variants. + */ + +static inline unsigned int +__attribute__((__always_inline__)) +gang_lookup_scan(struct radix_tree *t, struct radix_tree_path *path, + void **results, unsigned int maxresults, const unsigned int tagmask, + bool reverse) +{ + + /* + * we keep the path updated only for lastidx-1. + * vpp is what path_pptr(t, path, lastidx) would be. + */ + void **vpp; + unsigned int nfound; + unsigned int lastidx; + /* + * set up scan direction dependant constants so that we can iterate + * n_ptrs as the following. + * + * for (i = first; i != guard; i += step) + * visit n->n_ptrs[i]; + */ + const int step = reverse ? -1 : 1; + const unsigned int first = reverse ? RADIX_TREE_PTR_PER_NODE - 1 : 0; + const unsigned int last = reverse ? 0 : RADIX_TREE_PTR_PER_NODE - 1; + const unsigned int guard = last + step; + + KASSERT(maxresults > 0); + KASSERT(&t->t_root == path_pptr(t, path, 0)); + lastidx = path->p_lastidx; + KASSERT(lastidx == RADIX_TREE_INVALID_HEIGHT || + lastidx == t->t_height || + !entry_match_p(*path_pptr(t, path, lastidx), tagmask)); + nfound = 0; + if (lastidx == RADIX_TREE_INVALID_HEIGHT) { + if (reverse) { + lastidx = 0; + vpp = path_pptr(t, path, lastidx); + goto descend; + } + return 0; + } + vpp = path_pptr(t, path, lastidx); + while (/*CONSTCOND*/true) { + struct radix_tree_node *n; + unsigned int i; + + if (entry_match_p(*vpp, tagmask)) { + KASSERT(lastidx == t->t_height); + /* + * record the matching non-NULL leaf. + */ + results[nfound] = entry_ptr(*vpp); + nfound++; + if (nfound == maxresults) { + return nfound; + } + } +scan_siblings: + /* + * try to find the next matching non-NULL sibling. + */ + if (lastidx == 0) { + /* + * the root has no siblings. + * we've done. + */ + KASSERT(vpp == &t->t_root); + break; + } + n = path_node(t, path, lastidx - 1); + if (*vpp != NULL && n->n_nptrs == 1) { + /* + * optimization; if the node has only a single pointer + * and we've already visited it, there's no point to + * keep scanning in this node. + */ + goto no_siblings; + } + for (i = vpp - n->n_ptrs + step; i != guard; i += step) { + KASSERT(i < RADIX_TREE_PTR_PER_NODE); + if (entry_match_p(n->n_ptrs[i], tagmask)) { + vpp = &n->n_ptrs[i]; + break; + } + } + if (i == guard) { +no_siblings: + /* + * not found. go to parent. + */ + lastidx--; + vpp = path_pptr(t, path, lastidx); + goto scan_siblings; + } +descend: + /* + * following the left-most (or right-most in the case of + * reverse scan) child node, decend until reaching the leaf or + * an non-matching entry. + */ + while (entry_match_p(*vpp, tagmask) && lastidx < t->t_height) { + /* + * save vpp in the path so that we can come back to this + * node after finishing visiting children. + */ + path->p_refs[lastidx].pptr = vpp; + n = entry_ptr(*vpp); + vpp = &n->n_ptrs[first]; + lastidx++; + } + } + return nfound; +} + +/* + * radix_tree_gang_lookup_node: + * + * search nodes starting from idx in the ascending order. + * results should be an array large enough to hold maxresults pointers. + * returns the number of nodes found, up to maxresults. + * returning less than maxresults means there are no more nodes. + * + * the result of this function is semantically equivalent to what could be + * obtained by repeated calls of radix_tree_lookup_node with increasing index. + * but this function is much faster when node indexes are distributed sparsely. + * + * note that this function doesn't return exact values of node indexes of + * found nodes. if they are important for a caller, it's the caller's + * responsibility to check them, typically by examinining the returned nodes + * using some caller-specific knowledge about them. + */ + +unsigned int +radix_tree_gang_lookup_node(struct radix_tree *t, uint64_t idx, + void **results, unsigned int maxresults) +{ + struct radix_tree_path path; + + gang_lookup_init(t, idx, &path, 0); + return gang_lookup_scan(t, &path, results, maxresults, 0, false); +} + +/* + * radix_tree_gang_lookup_node_reverse: + * + * same as radix_tree_gang_lookup_node except that this one scans the + * tree in the reverse order. ie. descending index values. + */ + +unsigned int +radix_tree_gang_lookup_node_reverse(struct radix_tree *t, uint64_t idx, + void **results, unsigned int maxresults) +{ + struct radix_tree_path path; + + gang_lookup_init(t, idx, &path, 0); + return gang_lookup_scan(t, &path, results, maxresults, 0, true); +} + +/* + * radix_tree_gang_lookup_tagged_node: + * + * same as radix_tree_gang_lookup_node except that this one only returns + * nodes tagged with tagid. + */ + +unsigned int +radix_tree_gang_lookup_tagged_node(struct radix_tree *t, uint64_t idx, + void **results, unsigned int maxresults, radix_tree_tagid_t tagid) +{ + struct radix_tree_path path; + const unsigned int tagmask = tagid_to_mask(tagid); + + gang_lookup_init(t, idx, &path, tagmask); + return gang_lookup_scan(t, &path, results, maxresults, tagmask, false); +} + +/* + * radix_tree_gang_lookup_tagged_node_reverse: + * + * same as radix_tree_gang_lookup_tagged_node except that this one scans the + * tree in the reverse order. ie. descending index values. + */ + +unsigned int +radix_tree_gang_lookup_tagged_node_reverse(struct radix_tree *t, uint64_t idx, + void **results, unsigned int maxresults, radix_tree_tagid_t tagid) +{ + struct radix_tree_path path; + const unsigned int tagmask = tagid_to_mask(tagid); + + gang_lookup_init(t, idx, &path, tagmask); + return gang_lookup_scan(t, &path, results, maxresults, tagmask, true); +} + +/* + * radix_tree_get_tag: + * + * return if the tag is set for the node at the given index. (true if set) + * it's illegal to call this function for a node which has not been inserted. + */ + +bool +radix_tree_get_tag(struct radix_tree *t, uint64_t idx, + radix_tree_tagid_t tagid) +{ +#if 1 + const unsigned int tagmask = tagid_to_mask(tagid); + void **vpp; + + vpp = radix_tree_lookup_ptr(t, idx, NULL, false, tagmask); + if (vpp == NULL) { + return false; + } + KASSERT(*vpp != NULL); + return (entry_tagmask(*vpp) & tagmask) != 0; +#else + const unsigned int tagmask = tagid_to_mask(tagid); + void **vpp; + + vpp = radix_tree_lookup_ptr(t, idx, NULL, false, 0); + KASSERT(vpp != NULL); + return (entry_tagmask(*vpp) & tagmask) != 0; +#endif +} + +/* + * radix_tree_set_tag: + * + * set the tag for the node at the given index. + * it's illegal to call this function for a node which has not been inserted. + */ + +void +radix_tree_set_tag(struct radix_tree *t, uint64_t idx, + radix_tree_tagid_t tagid) +{ + struct radix_tree_path path; + const unsigned int tagmask = tagid_to_mask(tagid); + void **vpp; + int i; + + vpp = radix_tree_lookup_ptr(t, idx, &path, false, 0); + KASSERT(vpp != NULL); + KASSERT(*vpp != NULL); + KASSERT(path.p_lastidx == t->t_height); + KASSERT(vpp == path_pptr(t, &path, path.p_lastidx)); + for (i = t->t_height; i >= 0; i--) { + void ** const pptr = (void **)path_pptr(t, &path, i); + void *entry; + + KASSERT(pptr != NULL); + entry = *pptr; + if ((entry_tagmask(entry) & tagmask) != 0) { + break; + } + *pptr = (void *)((uintptr_t)entry | tagmask); + } +} + +/* + * radix_tree_clear_tag: + * + * clear the tag for the node at the given index. + * it's illegal to call this function for a node which has not been inserted. + */ + +void +radix_tree_clear_tag(struct radix_tree *t, uint64_t idx, + radix_tree_tagid_t tagid) +{ + struct radix_tree_path path; + const unsigned int tagmask = tagid_to_mask(tagid); + void **vpp; + int i; + + vpp = radix_tree_lookup_ptr(t, idx, &path, false, 0); + KASSERT(vpp != NULL); + KASSERT(*vpp != NULL); + KASSERT(path.p_lastidx == t->t_height); + KASSERT(vpp == path_pptr(t, &path, path.p_lastidx)); + /* + * if already cleared, nothing to do + */ + if ((entry_tagmask(*vpp) & tagmask) == 0) { + return; + } + /* + * clear the tag only if no children have the tag. + */ + for (i = t->t_height; i >= 0; i--) { + void ** const pptr = (void **)path_pptr(t, &path, i); + void *entry; + + KASSERT(pptr != NULL); + entry = *pptr; + KASSERT((entry_tagmask(entry) & tagmask) != 0); + *pptr = entry_compose(entry_ptr(entry), + entry_tagmask(entry) & ~tagmask); + /* + * check if we should proceed to process the next level. + */ + if (0 < i) { + struct radix_tree_node *n = path_node(t, &path, i - 1); + + if ((any_children_tagmask(n) & tagmask) != 0) { + break; + } + } + } +} + +#if defined(UNITTEST) + +#include +#include + +static void +radix_tree_dump_node(const struct radix_tree *t, void *vp, + uint64_t offset, unsigned int height) +{ + struct radix_tree_node *n; + unsigned int i; + + for (i = 0; i < t->t_height - height; i++) { + printf(" "); + } + if (entry_tagmask(vp) == 0) { + printf("[%" PRIu64 "] %p", offset, entry_ptr(vp)); + } else { + printf("[%" PRIu64 "] %p (tagmask=0x%x)", offset, entry_ptr(vp), + entry_tagmask(vp)); + } + if (height == 0) { + printf(" (leaf)\n"); + return; + } + n = entry_ptr(vp); + assert(any_children_tagmask(n) == entry_tagmask(vp)); + printf(" (%u children)\n", n->n_nptrs); + for (i = 0; i < __arraycount(n->n_ptrs); i++) { + void *c; + + c = n->n_ptrs[i]; + if (c == NULL) { + continue; + } + radix_tree_dump_node(t, c, + offset + i * (UINT64_C(1) << + (RADIX_TREE_BITS_PER_HEIGHT * (height - 1))), height - 1); + } +} + +void radix_tree_dump(const struct radix_tree *); + +void +radix_tree_dump(const struct radix_tree *t) +{ + + printf("tree %p height=%u\n", t, t->t_height); + radix_tree_dump_node(t, t->t_root, 0, t->t_height); +} + +static void +test1(void) +{ + struct radix_tree s; + struct radix_tree *t = &s; + void *results[3]; + + radix_tree_init_tree(t); + radix_tree_dump(t); + assert(radix_tree_lookup_node(t, 0) == NULL); + assert(radix_tree_lookup_node(t, 1000) == NULL); + assert(radix_tree_gang_lookup_node(t, 0, results, 3) == 0); + assert(radix_tree_gang_lookup_node(t, 1000, results, 3) == 0); + assert(radix_tree_gang_lookup_node_reverse(t, 0, results, 3) == 0); + assert(radix_tree_gang_lookup_node_reverse(t, 1000, results, 3) == 0); + assert(radix_tree_gang_lookup_tagged_node(t, 0, results, 3, 0) == 0); + assert(radix_tree_gang_lookup_tagged_node(t, 1000, results, 3, 0) == 0); + assert(radix_tree_gang_lookup_tagged_node_reverse(t, 0, results, 3, 0) + == 0); + assert(radix_tree_gang_lookup_tagged_node_reverse(t, 1000, results, 3, + 0) == 0); + assert(radix_tree_empty_tree_p(t)); + assert(radix_tree_empty_tagged_tree_p(t, 0)); + assert(radix_tree_empty_tagged_tree_p(t, 1)); + assert(radix_tree_insert_node(t, 0, (void *)0xdeadbea0) == 0); + assert(!radix_tree_empty_tree_p(t)); + assert(radix_tree_empty_tagged_tree_p(t, 0)); + assert(radix_tree_empty_tagged_tree_p(t, 1)); + assert(radix_tree_lookup_node(t, 0) == (void *)0xdeadbea0); + assert(radix_tree_lookup_node(t, 1000) == NULL); + memset(results, 0, sizeof(results)); + assert(radix_tree_gang_lookup_node(t, 0, results, 3) == 1); + assert(results[0] == (void *)0xdeadbea0); + assert(radix_tree_gang_lookup_node(t, 1000, results, 3) == 0); + memset(results, 0, sizeof(results)); + assert(radix_tree_gang_lookup_node_reverse(t, 0, results, 3) == 1); + assert(results[0] == (void *)0xdeadbea0); + memset(results, 0, sizeof(results)); + assert(radix_tree_gang_lookup_node_reverse(t, 1000, results, 3) == 1); + assert(results[0] == (void *)0xdeadbea0); + assert(radix_tree_gang_lookup_tagged_node(t, 0, results, 3, 0) + == 0); + assert(radix_tree_gang_lookup_tagged_node_reverse(t, 0, results, 3, 0) + == 0); + assert(radix_tree_insert_node(t, 1000, (void *)0xdeadbea0) == 0); + assert(radix_tree_remove_node(t, 0) == (void *)0xdeadbea0); + assert(!radix_tree_empty_tree_p(t)); + radix_tree_dump(t); + assert(radix_tree_lookup_node(t, 0) == NULL); + assert(radix_tree_lookup_node(t, 1000) == (void *)0xdeadbea0); + memset(results, 0, sizeof(results)); + assert(radix_tree_gang_lookup_node(t, 0, results, 3) == 1); + assert(results[0] == (void *)0xdeadbea0); + memset(results, 0, sizeof(results)); + assert(radix_tree_gang_lookup_node(t, 1000, results, 3) == 1); + assert(results[0] == (void *)0xdeadbea0); + assert(radix_tree_gang_lookup_node_reverse(t, 0, results, 3) == 0); + memset(results, 0, sizeof(results)); + assert(radix_tree_gang_lookup_node_reverse(t, 1000, results, 3) == 1); + assert(results[0] == (void *)0xdeadbea0); + assert(radix_tree_gang_lookup_tagged_node(t, 0, results, 3, 0) + == 0); + assert(radix_tree_gang_lookup_tagged_node_reverse(t, 0, results, 3, 0) + == 0); + assert(!radix_tree_get_tag(t, 1000, 0)); + assert(!radix_tree_get_tag(t, 1000, 1)); + assert(radix_tree_empty_tagged_tree_p(t, 0)); + assert(radix_tree_empty_tagged_tree_p(t, 1)); + radix_tree_set_tag(t, 1000, 1); + assert(!radix_tree_get_tag(t, 1000, 0)); + assert(radix_tree_get_tag(t, 1000, 1)); + assert(radix_tree_empty_tagged_tree_p(t, 0)); + assert(!radix_tree_empty_tagged_tree_p(t, 1)); + radix_tree_dump(t); + assert(radix_tree_lookup_node(t, 1000) == (void *)0xdeadbea0); + assert(radix_tree_insert_node(t, 0, (void *)0xbea0) == 0); + radix_tree_dump(t); + assert(radix_tree_lookup_node(t, 0) == (void *)0xbea0); + assert(radix_tree_lookup_node(t, 1000) == (void *)0xdeadbea0); + assert(radix_tree_insert_node(t, UINT64_C(10000000000), (void *)0xdea0) + == 0); + radix_tree_dump(t); + assert(radix_tree_lookup_node(t, 0) == (void *)0xbea0); + assert(radix_tree_lookup_node(t, 1000) == (void *)0xdeadbea0); + assert(radix_tree_lookup_node(t, UINT64_C(10000000000)) == + (void *)0xdea0); + radix_tree_dump(t); + assert(!radix_tree_get_tag(t, 0, 1)); + assert(radix_tree_get_tag(t, 1000, 1)); + assert(!radix_tree_get_tag(t, UINT64_C(10000000000), 1)); + radix_tree_set_tag(t, 0, 1);; + radix_tree_set_tag(t, UINT64_C(10000000000), 1); + radix_tree_dump(t); + assert(radix_tree_get_tag(t, 0, 1)); + assert(radix_tree_get_tag(t, 1000, 1)); + assert(radix_tree_get_tag(t, UINT64_C(10000000000), 1)); + radix_tree_clear_tag(t, 0, 1);; + radix_tree_clear_tag(t, UINT64_C(10000000000), 1); + radix_tree_dump(t); + assert(!radix_tree_get_tag(t, 0, 1)); + assert(radix_tree_get_tag(t, 1000, 1)); + assert(!radix_tree_get_tag(t, UINT64_C(10000000000), 1)); + radix_tree_dump(t); + assert(radix_tree_replace_node(t, 1000, (void *)0x12345678) == + (void *)0xdeadbea0); + assert(!radix_tree_get_tag(t, 1000, 0)); + assert(radix_tree_get_tag(t, 1000, 1)); + assert(radix_tree_gang_lookup_node(t, 0, results, 3) == 3); + assert(results[0] == (void *)0xbea0); + assert(results[1] == (void *)0x12345678); + assert(results[2] == (void *)0xdea0); + assert(radix_tree_gang_lookup_node(t, 1, results, 3) == 2); + assert(results[0] == (void *)0x12345678); + assert(results[1] == (void *)0xdea0); + assert(radix_tree_gang_lookup_node(t, 1001, results, 3) == 1); + assert(results[0] == (void *)0xdea0); + assert(radix_tree_gang_lookup_node(t, UINT64_C(10000000001), results, 3) + == 0); + assert(radix_tree_gang_lookup_node(t, UINT64_C(1000000000000), results, + 3) == 0); + assert(radix_tree_gang_lookup_tagged_node(t, 0, results, 100, 1) == 1); + assert(results[0] == (void *)0x12345678); + assert(entry_tagmask(t->t_root) != 0); + assert(radix_tree_remove_node(t, 1000) == (void *)0x12345678); + assert(entry_tagmask(t->t_root) == 0); + radix_tree_dump(t); + assert(radix_tree_remove_node(t, UINT64_C(10000000000)) == + (void *)0xdea0); + radix_tree_dump(t); + assert(radix_tree_remove_node(t, 0) == (void *)0xbea0); + radix_tree_dump(t); + radix_tree_fini_tree(t); +} + +#include + +struct testnode { + uint64_t idx; + bool tagged[RADIX_TREE_TAG_ID_MAX]; +}; + +static void +printops(const char *title, const char *name, int tag, unsigned int n, + const struct timeval *stv, const struct timeval *etv) +{ + uint64_t s = stv->tv_sec * 1000000 + stv->tv_usec; + uint64_t e = etv->tv_sec * 1000000 + etv->tv_usec; + + printf("RESULT %s %s %d %lf op/s\n", title, name, tag, + (double)n / (e - s) * 1000000); +} + +#define TEST2_GANG_LOOKUP_NODES 16 + +static bool +test2_should_tag(unsigned int i, radix_tree_tagid_t tagid) +{ + + if (tagid == 0) { + return (i & 0x3) == 0; /* 25% */ + } else { + return (i % 7) == 0; /* 14% */ + } +} + +static void +test2(const char *title, bool dense) +{ + struct radix_tree s; + struct radix_tree *t = &s; + struct testnode *n; + unsigned int i; + unsigned int nnodes = 100000; + unsigned int removed; + radix_tree_tagid_t tag; + unsigned int ntagged[RADIX_TREE_TAG_ID_MAX]; + struct testnode *nodes; + struct timeval stv; + struct timeval etv; + + nodes = malloc(nnodes * sizeof(*nodes)); + for (tag = 0; tag < RADIX_TREE_TAG_ID_MAX; tag++) { + ntagged[tag] = 0; + } + radix_tree_init_tree(t); + for (i = 0; i < nnodes; i++) { + n = &nodes[i]; + n->idx = random(); + if (sizeof(long) == 4) { + n->idx <<= 32; + n->idx |= (uint32_t)random(); + } + if (dense) { + n->idx %= nnodes * 2; + } + while (radix_tree_lookup_node(t, n->idx) != NULL) { + n->idx++; + } + radix_tree_insert_node(t, n->idx, n); + for (tag = 0; tag < RADIX_TREE_TAG_ID_MAX; tag++) { + n->tagged[tag] = test2_should_tag(i, tag); + if (n->tagged[tag]) { + radix_tree_set_tag(t, n->idx, tag); + ntagged[tag]++; + } + assert(n->tagged[tag] == + radix_tree_get_tag(t, n->idx, tag)); + } + } + + gettimeofday(&stv, NULL); + for (i = 0; i < nnodes; i++) { + n = &nodes[i]; + assert(radix_tree_lookup_node(t, n->idx) == n); + } + gettimeofday(&etv, NULL); + printops(title, "lookup", 0, nnodes, &stv, &etv); + + for (tag = 0; tag < RADIX_TREE_TAG_ID_MAX; tag++) { + unsigned int count = 0; + + gettimeofday(&stv, NULL); + for (i = 0; i < nnodes; i++) { + bool tagged; + + n = &nodes[i]; + tagged = radix_tree_get_tag(t, n->idx, tag); + assert(n->tagged[tag] == tagged); + if (tagged) { + count++; + } + } + gettimeofday(&etv, NULL); + assert(ntagged[tag] == count); + printops(title, "get_tag", tag, nnodes, &stv, &etv); + } + + gettimeofday(&stv, NULL); + for (i = 0; i < nnodes; i++) { + n = &nodes[i]; + radix_tree_remove_node(t, n->idx); + } + gettimeofday(&etv, NULL); + printops(title, "remove", 0, nnodes, &stv, &etv); + + gettimeofday(&stv, NULL); + for (i = 0; i < nnodes; i++) { + n = &nodes[i]; + radix_tree_insert_node(t, n->idx, n); + } + gettimeofday(&etv, NULL); + printops(title, "insert", 0, nnodes, &stv, &etv); + + for (tag = 0; tag < RADIX_TREE_TAG_ID_MAX; tag++) { + ntagged[tag] = 0; + gettimeofday(&stv, NULL); + for (i = 0; i < nnodes; i++) { + n = &nodes[i]; + if (n->tagged[tag]) { + radix_tree_set_tag(t, n->idx, tag); + ntagged[tag]++; + } + } + gettimeofday(&etv, NULL); + printops(title, "set_tag", tag, ntagged[tag], &stv, &etv); + } + + gettimeofday(&stv, NULL); + { + struct testnode *results[TEST2_GANG_LOOKUP_NODES]; + uint64_t nextidx; + unsigned int nfound; + unsigned int total; + + nextidx = 0; + total = 0; + while ((nfound = radix_tree_gang_lookup_node(t, nextidx, + (void *)results, __arraycount(results))) > 0) { + nextidx = results[nfound - 1]->idx + 1; + total += nfound; + if (nextidx == 0) { + break; + } + } + assert(total == nnodes); + } + gettimeofday(&etv, NULL); + printops(title, "ganglookup", 0, nnodes, &stv, &etv); + + gettimeofday(&stv, NULL); + { + struct testnode *results[TEST2_GANG_LOOKUP_NODES]; + uint64_t nextidx; + unsigned int nfound; + unsigned int total; + + nextidx = UINT64_MAX; + total = 0; + while ((nfound = radix_tree_gang_lookup_node_reverse(t, nextidx, + (void *)results, __arraycount(results))) > 0) { + nextidx = results[nfound - 1]->idx - 1; + total += nfound; + if (nextidx == UINT64_MAX) { + break; + } + } + assert(total == nnodes); + } + gettimeofday(&etv, NULL); + printops(title, "ganglookup_reverse", 0, nnodes, &stv, &etv); + + for (tag = 0; tag < RADIX_TREE_TAG_ID_MAX; tag++) { + gettimeofday(&stv, NULL); + { + struct testnode *results[TEST2_GANG_LOOKUP_NODES]; + uint64_t nextidx; + unsigned int nfound; + unsigned int total; + + nextidx = 0; + total = 0; + while ((nfound = radix_tree_gang_lookup_tagged_node(t, + nextidx, (void *)results, __arraycount(results), + tag)) > 0) { + nextidx = results[nfound - 1]->idx + 1; + total += nfound; + } + assert(total == ntagged[tag]); + } + gettimeofday(&etv, NULL); + printops(title, "ganglookup_tag", tag, ntagged[tag], &stv, + &etv); + } + + for (tag = 0; tag < RADIX_TREE_TAG_ID_MAX; tag++) { + gettimeofday(&stv, NULL); + { + struct testnode *results[TEST2_GANG_LOOKUP_NODES]; + uint64_t nextidx; + unsigned int nfound; + unsigned int total; + + nextidx = UINT64_MAX; + total = 0; + while ((nfound = + radix_tree_gang_lookup_tagged_node_reverse(t, + nextidx, (void *)results, __arraycount(results), + tag)) > 0) { + nextidx = results[nfound - 1]->idx - 1; + total += nfound; + if (nextidx == UINT64_MAX) { + break; + } + } + assert(total == ntagged[tag]); + } + gettimeofday(&etv, NULL); + printops(title, "ganglookup_tag_reverse", tag, ntagged[tag], + &stv, &etv); + } + + removed = 0; + for (tag = 0; tag < RADIX_TREE_TAG_ID_MAX; tag++) { + unsigned int total; + + total = 0; + gettimeofday(&stv, NULL); + { + struct testnode *results[TEST2_GANG_LOOKUP_NODES]; + uint64_t nextidx; + unsigned int nfound; + + nextidx = 0; + while ((nfound = radix_tree_gang_lookup_tagged_node(t, + nextidx, (void *)results, __arraycount(results), + tag)) > 0) { + for (i = 0; i < nfound; i++) { + radix_tree_remove_node(t, + results[i]->idx); + } + nextidx = results[nfound - 1]->idx + 1; + total += nfound; + if (nextidx == 0) { + break; + } + } + assert(tag != 0 || total == ntagged[tag]); + assert(total <= ntagged[tag]); + } + gettimeofday(&etv, NULL); + printops(title, "ganglookup_tag+remove", tag, total, &stv, + &etv); + removed += total; + } + + gettimeofday(&stv, NULL); + { + struct testnode *results[TEST2_GANG_LOOKUP_NODES]; + uint64_t nextidx; + unsigned int nfound; + unsigned int total; + + nextidx = 0; + total = 0; + while ((nfound = radix_tree_gang_lookup_node(t, nextidx, + (void *)results, __arraycount(results))) > 0) { + for (i = 0; i < nfound; i++) { + assert(results[i] == radix_tree_remove_node(t, + results[i]->idx)); + } + nextidx = results[nfound - 1]->idx + 1; + total += nfound; + if (nextidx == 0) { + break; + } + } + assert(total == nnodes - removed); + } + gettimeofday(&etv, NULL); + printops(title, "ganglookup+remove", 0, nnodes - removed, &stv, &etv); + + assert(radix_tree_empty_tree_p(t)); + assert(radix_tree_empty_tagged_tree_p(t, 0)); + assert(radix_tree_empty_tagged_tree_p(t, 1)); + radix_tree_fini_tree(t); + free(nodes); +} + +int +main(int argc, char *argv[]) +{ + + test1(); + test2("dense", true); + test2("sparse", false); + return 0; +} + +#endif /* defined(UNITTEST) */ diff --git a/common/lib/libc/gen/rb.c b/common/lib/libc/gen/rb.c index a277c28f2..098ab6cd1 100644 --- a/common/lib/libc/gen/rb.c +++ b/common/lib/libc/gen/rb.c @@ -1,4 +1,4 @@ -/* $NetBSD: rb.c,v 1.9 2010/11/17 13:19:32 tron Exp $ */ +/* $NetBSD: rb.c,v 1.11 2011/06/20 09:11:16 mrg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -39,8 +39,10 @@ #else #define KASSERT(s) do { } while (/*CONSTCOND*/ 0) #endif +__RCSID("$NetBSD: rb.c,v 1.11 2011/06/20 09:11:16 mrg Exp $"); #else #include +__KERNEL_RCSID(0, "$NetBSD: rb.c,v 1.11 2011/06/20 09:11:16 mrg Exp $"); #endif #ifdef _LIBC @@ -89,7 +91,7 @@ rb_tree_init(struct rb_tree *rbt, const rb_tree_ops_t *ops) { rbt->rbt_ops = ops; - *((const struct rb_node **)&rbt->rbt_root) = RB_SENTINEL_NODE; + rbt->rbt_root = RB_SENTINEL_NODE; RB_TAILQ_INIT(&rbt->rbt_nodes); #ifndef RBSMALL rbt->rbt_minmax[RB_DIR_LEFT] = rbt->rbt_root; /* minimum node */ diff --git a/common/lib/libc/gen/rpst.c b/common/lib/libc/gen/rpst.c index 753e9923f..5ab09d086 100644 --- a/common/lib/libc/gen/rpst.c +++ b/common/lib/libc/gen/rpst.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpst.c,v 1.9 2009/05/26 22:39:15 yamt Exp $ */ +/* $NetBSD: rpst.c,v 1.11 2011/04/26 20:53:34 yamt Exp $ */ /*- * Copyright (c)2009 YAMAMOTO Takashi, @@ -42,11 +42,15 @@ #include -#if defined(_KERNEL) -__KERNEL_RCSID(0, "$NetBSD: rpst.c,v 1.9 2009/05/26 22:39:15 yamt Exp $"); +#if defined(_KERNEL) || defined(_STANDALONE) +__KERNEL_RCSID(0, "$NetBSD: rpst.c,v 1.11 2011/04/26 20:53:34 yamt Exp $"); #include -#else /* defined(_KERNEL) */ -__RCSID("$NetBSD: rpst.c,v 1.9 2009/05/26 22:39:15 yamt Exp $"); +#include +#if defined(_STANDALONE) +#include +#endif /* defined(_STANDALONE) */ +#else /* defined(_KERNEL) || defined(_STANDALONE) */ +__RCSID("$NetBSD: rpst.c,v 1.11 2011/04/26 20:53:34 yamt Exp $"); #include #include #include @@ -55,7 +59,7 @@ __RCSID("$NetBSD: rpst.c,v 1.9 2009/05/26 22:39:15 yamt Exp $"); #else #define KASSERT(a) #endif -#endif /* defined(_KERNEL) */ +#endif /* defined(_KERNEL) || defined(_STANDALONE) */ #include diff --git a/common/lib/libc/gmon/mcount.c b/common/lib/libc/gmon/mcount.c index 0a0c71688..128abe6f9 100644 --- a/common/lib/libc/gmon/mcount.c +++ b/common/lib/libc/gmon/mcount.c @@ -1,4 +1,4 @@ -/* $NetBSD: mcount.c,v 1.8 2009/01/05 18:06:57 pooka Exp $ */ +/* $NetBSD: mcount.c,v 1.10 2012/03/20 16:21:41 matt Exp $ */ /* * Copyright (c) 2003, 2004 Wasabi Systems, Inc. @@ -76,7 +76,7 @@ #if 0 static char sccsid[] = "@(#)mcount.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: mcount.c,v 1.8 2009/01/05 18:06:57 pooka Exp $"); +__RCSID("$NetBSD: mcount.c,v 1.10 2012/03/20 16:21:41 matt Exp $"); #endif #endif @@ -93,11 +93,13 @@ extern struct gmonparam _gmondummy; struct gmonparam *_m_gmon_alloc(void); #endif -_MCOUNT_DECL __P((u_long, u_long)) +#ifndef __LINT__ +_MCOUNT_DECL(u_long, u_long) #ifdef _KERNEL __attribute__((__no_instrument_function__)) #endif __used; +#endif /* XXX: make these interfaces */ #ifdef _RUMPKERNEL @@ -124,8 +126,9 @@ _MCOUNT_DECL __P((u_long, u_long)) * both frompcindex and frompc. Any reasonable, modern compiler will * perform this optimization. */ -_MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */ - u_long frompc, selfpc; +#ifndef __LINT__ +/* _mcount; may be static, inline, etc */ +_MCOUNT_DECL(u_long frompc, u_long selfpc) { u_short *frompcindex; struct tostruct *top, *prevtop; @@ -258,6 +261,7 @@ overflow: #endif return; } +#endif #ifdef MCOUNT /* diff --git a/common/lib/libc/hash/murmurhash/murmurhash.c b/common/lib/libc/hash/murmurhash/murmurhash.c new file mode 100644 index 000000000..87915c31e --- /dev/null +++ b/common/lib/libc/hash/murmurhash/murmurhash.c @@ -0,0 +1,90 @@ +/* $NetBSD: murmurhash.c,v 1.4 2012/07/10 17:05:38 christos Exp $ */ + +/* + * MurmurHash2 -- from the original code: + * + * "MurmurHash2 was written by Austin Appleby, and is placed in the public + * domain. The author hereby disclaims copyright to this source code." + * + * References: + * http://code.google.com/p/smhasher/ + * https://sites.google.com/site/murmurhash/ + */ + +#include + +#if defined(_KERNEL) || defined(_STANDALONE) +__KERNEL_RCSID(0, "$NetBSD: murmurhash.c,v 1.4 2012/07/10 17:05:38 christos Exp $"); + +#else + +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: murmurhash.c,v 1.4 2012/07/10 17:05:38 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include "namespace.h" +#endif + +#include +#include + +#ifdef __weak_alias +__weak_alias(murmurhash2,_murmurhash2) +#endif + +uint32_t +murmurhash2(const void *key, size_t len, uint32_t seed) +{ + /* + * Note: 'm' and 'r' are mixing constants generated offline. + * They're not really 'magic', they just happen to work well. + * Initialize the hash to a 'random' value. + */ + const uint32_t m = 0x5bd1e995; + const int r = 24; + + const uint8_t *data = key; + uint32_t h = seed ^ (uint32_t)len; + + while (len >= sizeof(uint32_t)) { + uint32_t k; + + k = data[0]; + k |= data[1] << 8; + k |= data[2] << 16; + k |= data[3] << 24; + + k *= m; + k ^= k >> r; + k *= m; + + h *= m; + h ^= k; + + data += sizeof(uint32_t); + len -= sizeof(uint32_t); + } + + /* Handle the last few bytes of the input array. */ + switch (len) { + case 3: + h ^= data[2] << 16; + /* FALLTHROUGH */ + case 2: + h ^= data[1] << 8; + /* FALLTHROUGH */ + case 1: + h ^= data[0]; + h *= m; + } + + /* + * Do a few final mixes of the hash to ensure the last few + * bytes are well-incorporated. + */ + h ^= h >> 13; + h *= m; + h ^= h >> 15; + + return h; +} diff --git a/common/lib/libc/inet/inet_addr.c b/common/lib/libc/inet/inet_addr.c index 551ba1716..1360ce970 100644 --- a/common/lib/libc/inet/inet_addr.c +++ b/common/lib/libc/inet/inet_addr.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_addr.c,v 1.2 2008/02/16 17:37:13 apb Exp $ */ +/* $NetBSD: inet_addr.c,v 1.3 2012/03/09 15:41:16 christos Exp $ */ /* * Copyright (c) 1983, 1990, 1993 @@ -77,7 +77,7 @@ static const char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; static const char rcsid[] = "Id: inet_addr.c,v 1.2.206.2 2004/03/17 00:29:45 marka Exp"; #else -__RCSID("$NetBSD: inet_addr.c,v 1.2 2008/02/16 17:37:13 apb Exp $"); +__RCSID("$NetBSD: inet_addr.c,v 1.3 2012/03/09 15:41:16 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -125,7 +125,8 @@ inet_addr(const char *cp) { int inet_aton(const char *cp, struct in_addr *addr) { uint32_t val; - int base, n; + int base; + size_t n; char c; uint8_t parts[4]; uint8_t *pp = parts; diff --git a/common/lib/libc/md/md4c.c b/common/lib/libc/md/md4c.c index ee7a69726..d51d95fcb 100644 --- a/common/lib/libc/md/md4c.c +++ b/common/lib/libc/md/md4c.c @@ -1,4 +1,4 @@ -/* $NetBSD: md4c.c,v 1.4 2009/03/16 05:59:21 cegger Exp $ */ +/* $NetBSD: md4c.c,v 1.5 2012/03/20 16:21:41 matt Exp $ */ /* * This file is derived from the RSA Data Security, Inc. MD4 Message-Digest @@ -31,7 +31,7 @@ #if !defined(_KERNEL) && !defined(_STANDALONE) #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: md4c.c,v 1.4 2009/03/16 05:59:21 cegger Exp $"); +__RCSID("$NetBSD: md4c.c,v 1.5 2012/03/20 16:21:41 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -76,10 +76,10 @@ typedef uint32_t UINT4; #define S33 11 #define S34 15 -static void MD4Transform __P((UINT4 [4], const unsigned char [64])); +static void MD4Transform(UINT4 [4], const unsigned char [64]); -static void Encode __P((unsigned char *, UINT4 *, unsigned int)); -static void Decode __P((UINT4 *, const unsigned char *, unsigned int)); +static void Encode(unsigned char *, UINT4 *, unsigned int); +static void Decode(UINT4 *, const unsigned char *, unsigned int); static const unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/common/lib/libc/md/md5c.c b/common/lib/libc/md/md5c.c index e15548dd7..a3703cd73 100644 --- a/common/lib/libc/md/md5c.c +++ b/common/lib/libc/md/md5c.c @@ -1,4 +1,4 @@ -/* $NetBSD: md5c.c,v 1.4 2009/03/16 05:59:21 cegger Exp $ */ +/* $NetBSD: md5c.c,v 1.5 2012/03/20 16:21:41 matt Exp $ */ /* * This file is derived from the RSA Data Security, Inc. MD5 Message-Digest @@ -36,7 +36,7 @@ #else #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: md5c.c,v 1.4 2009/03/16 05:59:21 cegger Exp $"); +__RCSID("$NetBSD: md5c.c,v 1.5 2012/03/20 16:21:41 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include @@ -84,10 +84,10 @@ __weak_alias(MD5Final,_MD5Final) __weak_alias(MD5Transform,_MD5Transform) #endif -static void MD5Transform __P((UINT4 [4], const unsigned char [64])); +static void MD5Transform(UINT4 [4], const unsigned char [64]); -static void Encode __P((unsigned char *, UINT4 *, unsigned int)); -static void Decode __P((UINT4 *, const unsigned char *, unsigned int)); +static void Encode(unsigned char *, UINT4 *, unsigned int); +static void Decode(UINT4 *, const unsigned char *, unsigned int); /* * Encodes input (UINT4) into output (unsigned char). Assumes len is diff --git a/common/lib/libc/net/htonl.c b/common/lib/libc/net/htonl.c index 7edc4f8bb..8fc35967e 100644 --- a/common/lib/libc/net/htonl.c +++ b/common/lib/libc/net/htonl.c @@ -1,4 +1,4 @@ -/* $NetBSD: htonl.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */ +/* $NetBSD: htonl.c,v 1.3 2012/03/21 20:02:56 he Exp $ */ /* * Written by J.T. Conklin . @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: htonl.c,v 1.1 2005/12/20 19:28:51 christos Exp $"); +__RCSID("$NetBSD: htonl.c,v 1.3 2012/03/21 20:02:56 he Exp $"); #endif #include @@ -15,11 +15,10 @@ __RCSID("$NetBSD: htonl.c,v 1.1 2005/12/20 19:28:51 christos Exp $"); #undef htonl uint32_t -htonl(x) - uint32_t x; +htonl(uint32_t x) { #if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *)&x; + u_char *s = (void *)&x; return (uint32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); #else return x; diff --git a/common/lib/libc/net/htons.c b/common/lib/libc/net/htons.c index 830db0f1b..9ac41eee9 100644 --- a/common/lib/libc/net/htons.c +++ b/common/lib/libc/net/htons.c @@ -1,4 +1,4 @@ -/* $NetBSD: htons.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */ +/* $NetBSD: htons.c,v 1.3 2012/03/21 20:02:56 he Exp $ */ /* * Written by J.T. Conklin . @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: htons.c,v 1.1 2005/12/20 19:28:51 christos Exp $"); +__RCSID("$NetBSD: htons.c,v 1.3 2012/03/21 20:02:56 he Exp $"); #endif #include @@ -15,11 +15,10 @@ __RCSID("$NetBSD: htons.c,v 1.1 2005/12/20 19:28:51 christos Exp $"); #undef htons uint16_t -htons(x) - uint16_t x; +htons(uint16_t x) { #if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *) &x; + u_char *s = (void *) &x; return (uint16_t)(s[0] << 8 | s[1]); #else return x; diff --git a/common/lib/libc/net/ntohl.c b/common/lib/libc/net/ntohl.c index dc0ca9a8b..cbd2b770e 100644 --- a/common/lib/libc/net/ntohl.c +++ b/common/lib/libc/net/ntohl.c @@ -1,4 +1,4 @@ -/* $NetBSD: ntohl.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */ +/* $NetBSD: ntohl.c,v 1.3 2012/03/21 20:02:56 he Exp $ */ /* * Written by J.T. Conklin . @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: ntohl.c,v 1.1 2005/12/20 19:28:51 christos Exp $"); +__RCSID("$NetBSD: ntohl.c,v 1.3 2012/03/21 20:02:56 he Exp $"); #endif #include @@ -15,11 +15,10 @@ __RCSID("$NetBSD: ntohl.c,v 1.1 2005/12/20 19:28:51 christos Exp $"); #undef ntohl uint32_t -ntohl(x) - uint32_t x; +ntohl(uint32_t x) { #if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *)&x; + u_char *s = (void *)&x; return (uint32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); #else return x; diff --git a/common/lib/libc/net/ntohs.c b/common/lib/libc/net/ntohs.c index eb4e84147..bea167f54 100644 --- a/common/lib/libc/net/ntohs.c +++ b/common/lib/libc/net/ntohs.c @@ -1,4 +1,4 @@ -/* $NetBSD: ntohs.c,v 1.1 2005/12/20 19:28:51 christos Exp $ */ +/* $NetBSD: ntohs.c,v 1.3 2012/03/21 20:02:56 he Exp $ */ /* * Written by J.T. Conklin . @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: ntohs.c,v 1.1 2005/12/20 19:28:51 christos Exp $"); +__RCSID("$NetBSD: ntohs.c,v 1.3 2012/03/21 20:02:56 he Exp $"); #endif #include @@ -15,11 +15,10 @@ __RCSID("$NetBSD: ntohs.c,v 1.1 2005/12/20 19:28:51 christos Exp $"); #undef ntohs uint16_t -ntohs(x) - uint16_t x; +ntohs(uint16_t x) { #if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *) &x; + u_char *s = (void *) &x; return (uint16_t)(s[0] << 8 | s[1]); #else return x; diff --git a/common/lib/libc/quad/ashldi3.c b/common/lib/libc/quad/ashldi3.c index d242614e9..fab582ca6 100644 --- a/common/lib/libc/quad/ashldi3.c +++ b/common/lib/libc/quad/ashldi3.c @@ -1,4 +1,4 @@ -/* $NetBSD: ashldi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $ */ +/* $NetBSD: ashldi3.c,v 1.3 2012/03/09 15:41:16 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)ashldi3.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: ashldi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $"); +__RCSID("$NetBSD: ashldi3.c,v 1.3 2012/03/09 15:41:16 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -57,7 +57,7 @@ __ashldi3(quad_t a, qshift_t shift) return(a); aa.q = a; if (shift >= INT_BITS) { - aa.ul[H] = aa.ul[L] << (shift - INT_BITS); + aa.ul[H] = aa.ul[L] << (unsigned int)(shift - INT_BITS); aa.ul[L] = 0; } else { aa.ul[H] = (aa.ul[H] << shift) | diff --git a/common/lib/libc/quad/ashrdi3.c b/common/lib/libc/quad/ashrdi3.c index c064b57d5..ee1c1c4c0 100644 --- a/common/lib/libc/quad/ashrdi3.c +++ b/common/lib/libc/quad/ashrdi3.c @@ -1,4 +1,4 @@ -/* $NetBSD: ashrdi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $ */ +/* $NetBSD: ashrdi3.c,v 1.4 2012/08/06 02:31:54 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,12 +38,14 @@ #if 0 static char sccsid[] = "@(#)ashrdi3.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: ashrdi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $"); +__RCSID("$NetBSD: ashrdi3.c,v 1.4 2012/08/06 02:31:54 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include "quad.h" +ARM_EABI_ALIAS(__aeabi_lasr, __ashrdi3) /* no semicolon */ + /* * Shift a (signed) quad value right (arithmetic shift right). */ @@ -72,7 +74,7 @@ __ashrdi3(quad_t a, qshift_t shift) aa.ul[H] = s; } else { aa.ul[L] = (aa.ul[L] >> shift) | - (aa.ul[H] << (INT_BITS - shift)); + (aa.ul[H] << (unsigned int)(INT_BITS - shift)); /* LINTED inherits machine dependency */ aa.sl[H] >>= shift; } diff --git a/common/lib/libc/quad/lshldi3.c b/common/lib/libc/quad/lshldi3.c index 652552488..2c51669e5 100644 --- a/common/lib/libc/quad/lshldi3.c +++ b/common/lib/libc/quad/lshldi3.c @@ -1,4 +1,4 @@ -/* $NetBSD: lshldi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $ */ +/* $NetBSD: lshldi3.c,v 1.3 2012/08/06 02:31:54 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,12 +38,14 @@ #if 0 static char sccsid[] = "@(#)lshldi3.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: lshldi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $"); +__RCSID("$NetBSD: lshldi3.c,v 1.3 2012/08/06 02:31:54 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include "quad.h" +ARM_EABI_ALIAS(__aeabi_llsl, __lshldi3) /* no semicolon */ + /* * Shift an (unsigned) quad value left (logical shift left). * This is the same as arithmetic shift left! diff --git a/common/lib/libc/quad/lshrdi3.c b/common/lib/libc/quad/lshrdi3.c index 80a4b6d76..c40932cb0 100644 --- a/common/lib/libc/quad/lshrdi3.c +++ b/common/lib/libc/quad/lshrdi3.c @@ -1,4 +1,4 @@ -/* $NetBSD: lshrdi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $ */ +/* $NetBSD: lshrdi3.c,v 1.4 2012/08/06 02:31:54 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,12 +38,14 @@ #if 0 static char sccsid[] = "@(#)lshrdi3.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: lshrdi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $"); +__RCSID("$NetBSD: lshrdi3.c,v 1.4 2012/08/06 02:31:54 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include "quad.h" +ARM_EABI_ALIAS(__aeabi_llsr, __lshrdi3) /* no semicolon */ + /* * Shift an (unsigned) quad value right (logical shift right). */ @@ -60,7 +62,7 @@ __lshrdi3(quad_t a, qshift_t shift) aa.ul[H] = 0; } else { aa.ul[L] = (aa.ul[L] >> shift) | - (aa.ul[H] << (INT_BITS - shift)); + (aa.ul[H] << (unsigned int)(INT_BITS - shift)); aa.ul[H] >>= shift; } return (aa.q); diff --git a/common/lib/libc/quad/muldi3.c b/common/lib/libc/quad/muldi3.c index bf3b5bdef..f557c9354 100644 --- a/common/lib/libc/quad/muldi3.c +++ b/common/lib/libc/quad/muldi3.c @@ -1,4 +1,4 @@ -/* $NetBSD: muldi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $ */ +/* $NetBSD: muldi3.c,v 1.3 2012/08/06 02:31:54 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,12 +38,14 @@ #if 0 static char sccsid[] = "@(#)muldi3.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: muldi3.c,v 1.2 2009/03/15 22:31:12 cegger Exp $"); +__RCSID("$NetBSD: muldi3.c,v 1.3 2012/08/06 02:31:54 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include "quad.h" +ARM_EABI_ALIAS(__aeabi_lmul, __muldi3) /* no semicolon */ + /* * Multiply two quads. * diff --git a/common/lib/libc/quad/qdivrem.c b/common/lib/libc/quad/qdivrem.c index 84b77812a..384318d78 100644 --- a/common/lib/libc/quad/qdivrem.c +++ b/common/lib/libc/quad/qdivrem.c @@ -1,4 +1,4 @@ -/* $NetBSD: qdivrem.c,v 1.2 2009/03/15 22:31:12 cegger Exp $ */ +/* $NetBSD: qdivrem.c,v 1.4 2012/03/20 16:21:41 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)qdivrem.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: qdivrem.c,v 1.2 2009/03/15 22:31:12 cegger Exp $"); +__RCSID("$NetBSD: qdivrem.c,v 1.4 2012/03/20 16:21:41 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,10 +49,10 @@ __RCSID("$NetBSD: qdivrem.c,v 1.2 2009/03/15 22:31:12 cegger Exp $"); #include "quad.h" -#define B ((int)1 << HALF_BITS) /* digit base */ +#define B ((int)1 << (unsigned int)HALF_BITS) /* digit base */ /* Combine two `digits' to make a single two-digit number. */ -#define COMBINE(a, b) (((u_int)(a) << HALF_BITS) | (b)) +#define COMBINE(a, b) (((u_int)(a) << (unsigned int)HALF_BITS) | (b)) /* select a type for digits in base B: use unsigned short if they fit */ #if UINT_MAX == 0xffffffffU && USHRT_MAX >= 0xffff @@ -61,7 +61,7 @@ typedef unsigned short digit; typedef u_int digit; #endif -static void shl __P((digit *p, int len, int sh)); +static void shl(digit *p, int len, int sh); /* * __qdivrem(u, v, rem) returns u/v and, optionally, sets *rem to u%v. @@ -173,7 +173,7 @@ __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t *arq) * D1: choose multiplier 1 << d to ensure v[1] >= B/2. */ d = 0; - for (t = v[1]; t < B / 2; t <<= 1) + for (t = v[1]; t < B / 2; t <<= (unsigned int)1) d++; if (d > 0) { shl(&u[0], m + n, d); /* u <<= d */ @@ -254,7 +254,7 @@ __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t *arq) if (d) { for (i = m + n; i > m; --i) u[i] = (digit)(((u_int)u[i] >> d) | - LHALF((u_int)u[i - 1] << (HALF_BITS - d))); + LHALF((u_int)u[i - 1] << (unsigned int)(HALF_BITS - d))); u[i] = 0; } tmp.ul[H] = COMBINE(uspace[1], uspace[2]); diff --git a/common/lib/libc/quad/quad.h b/common/lib/libc/quad/quad.h index c5096405a..cd4ef98e9 100644 --- a/common/lib/libc/quad/quad.h +++ b/common/lib/libc/quad/quad.h @@ -1,4 +1,4 @@ -/* $NetBSD: quad.h,v 1.1 2005/12/20 20:29:40 christos Exp $ */ +/* $NetBSD: quad.h,v 1.7 2012/08/06 02:31:54 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -58,6 +58,12 @@ #include #endif +#if defined(__ARM_EABI__) && !defined(lint) +#define ARM_EABI_ALIAS(alias,sym) __strong_alias(alias,sym); +#else +#define ARM_EABI_ALIAS(alias,sym) /* nothing */ +#endif + /* * Depending on the desired operation, we view a `long long' (aka quad_t) in * one or more of the following formats. @@ -94,8 +100,8 @@ union uu { * (sizeof(int)*CHAR_BIT/2). */ #define HHALF(x) ((u_int)(x) >> HALF_BITS) -#define LHALF(x) ((u_int)(x) & (((int)1 << HALF_BITS) - 1)) -#define LHUP(x) ((u_int)(x) << HALF_BITS) +#define LHALF(x) ((u_int)(x) & (((int)1 << (u_int)HALF_BITS) - 1)) +#define LHUP(x) ((u_int)(x) << (u_int)HALF_BITS) /* * XXX @@ -110,30 +116,35 @@ typedef u_quad_t qshift_t; #endif __BEGIN_DECLS -quad_t __adddi3 __P((quad_t, quad_t)); -quad_t __anddi3 __P((quad_t, quad_t)); -quad_t __ashldi3 __P((quad_t, qshift_t)); -quad_t __ashrdi3 __P((quad_t, qshift_t)); -int __cmpdi2 __P((quad_t, quad_t)); -quad_t __divdi3 __P((quad_t, quad_t)); -quad_t __fixdfdi __P((double)); -quad_t __fixsfdi __P((float)); -u_quad_t __fixunsdfdi __P((double)); -u_quad_t __fixunssfdi __P((float)); -double __floatdidf __P((quad_t)); -float __floatdisf __P((quad_t)); -double __floatunsdidf __P((u_quad_t)); -quad_t __iordi3 __P((quad_t, quad_t)); -quad_t __lshldi3 __P((quad_t, qshift_t)); -quad_t __lshrdi3 __P((quad_t, qshift_t)); -quad_t __moddi3 __P((quad_t, quad_t)); -quad_t __muldi3 __P((quad_t, quad_t)); -quad_t __negdi2 __P((quad_t)); -quad_t __one_cmpldi2 __P((quad_t)); -u_quad_t __qdivrem __P((u_quad_t, u_quad_t, u_quad_t *)); -quad_t __subdi3 __P((quad_t, quad_t)); -int __ucmpdi2 __P((u_quad_t, u_quad_t)); -u_quad_t __udivdi3 __P((u_quad_t, u_quad_t )); -u_quad_t __umoddi3 __P((u_quad_t, u_quad_t )); -quad_t __xordi3 __P((quad_t, quad_t)); +quad_t __adddi3(quad_t, quad_t); +quad_t __anddi3(quad_t, quad_t); +quad_t __ashldi3(quad_t, qshift_t); +quad_t __ashrdi3(quad_t, qshift_t); +int __cmpdi2(quad_t, quad_t); +quad_t __divdi3(quad_t, quad_t); +quad_t __fixtfdi(long double); +quad_t __fixdfdi(double); +quad_t __fixsfdi(float); +u_quad_t __fixunstfdi(long double); +u_quad_t __fixunsdfdi(double); +u_quad_t __fixunssfdi(float); +long double __floatditf(quad_t); +double __floatdidf(quad_t); +float __floatdisf(quad_t); +long double __floatunditf(u_quad_t); +double __floatundidf(u_quad_t); +float __floatundisf(u_quad_t); +quad_t __iordi3(quad_t, quad_t); +quad_t __lshldi3(quad_t, qshift_t); +quad_t __lshrdi3(quad_t, qshift_t); +quad_t __moddi3(quad_t, quad_t); +quad_t __muldi3(quad_t, quad_t); +quad_t __negdi2(quad_t); +quad_t __one_cmpldi2(quad_t); +u_quad_t __qdivrem(u_quad_t, u_quad_t, u_quad_t *); +quad_t __subdi3(quad_t, quad_t); +int __ucmpdi2(u_quad_t, u_quad_t); +u_quad_t __udivdi3(u_quad_t, u_quad_t ); +u_quad_t __umoddi3(u_quad_t, u_quad_t ); +quad_t __xordi3(quad_t, quad_t); __END_DECLS diff --git a/common/lib/libc/stdlib/_strtol.h b/common/lib/libc/stdlib/_strtol.h index 8f7ec4924..e722f0a88 100644 --- a/common/lib/libc/stdlib/_strtol.h +++ b/common/lib/libc/stdlib/_strtol.h @@ -1,4 +1,4 @@ -/* $NetBSD: _strtol.h,v 1.2 2009/05/20 22:03:29 christos Exp $ */ +/* $NetBSD: _strtol.h,v 1.3 2012/03/09 15:41:16 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -109,7 +109,7 @@ _FUNCNAME(const char *nptr, char **endptr, int base) * Set any if any `digits' consumed; make it negative to indicate * overflow. */ - cutoff = (neg ? __INT_MIN : __INT_MAX); + cutoff = (__INT)(neg ? __INT_MIN : __INT_MAX); cutlim = (int)(cutoff % base); cutoff /= base; if (neg) { diff --git a/common/lib/libc/stdlib/_strtoul.h b/common/lib/libc/stdlib/_strtoul.h index a9519f955..8256ffd74 100644 --- a/common/lib/libc/stdlib/_strtoul.h +++ b/common/lib/libc/stdlib/_strtoul.h @@ -1,4 +1,4 @@ -/* $NetBSD: _strtoul.h,v 1.1 2008/08/20 12:42:26 joerg Exp $ */ +/* $NetBSD: _strtoul.h,v 1.3 2012/03/22 15:57:29 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -91,8 +91,8 @@ _FUNCNAME(const char *nptr, char **endptr, int base) /* * See strtol for comments as to the logic used. */ - cutoff = __UINT_MAX / (__UINT)base; - cutlim = (int)(__UINT_MAX % (__UINT)base); + cutoff = ((__UINT)__UINT_MAX / (__UINT)base); + cutlim = (int)((__UINT)__UINT_MAX % (__UINT)base); for (acc = 0, any = 0;; c = *s++) { if (isdigit(c)) i = c - '0'; diff --git a/common/lib/libc/string/bcmp.c b/common/lib/libc/string/bcmp.c index 724658d9d..97bf3977c 100644 --- a/common/lib/libc/string/bcmp.c +++ b/common/lib/libc/string/bcmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: bcmp.c,v 1.6 2009/04/25 12:20:48 skrll Exp $ */ +/* $NetBSD: bcmp.c,v 1.7 2012/03/09 15:41:16 christos Exp $ */ /* * Copyright (c) 1987, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: bcmp.c,v 1.6 2009/04/25 12:20:48 skrll Exp $"); +__RCSID("$NetBSD: bcmp.c,v 1.7 2012/03/09 15:41:16 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -66,5 +66,5 @@ bcmp(const void *b1, const void *b2, size_t length) if (*p1++ != *p2++) break; while (--length); - return(length); + return length != 0; } diff --git a/common/lib/libc/string/consttime_bcmp.c b/common/lib/libc/string/consttime_bcmp.c new file mode 100644 index 000000000..e6c0b31c1 --- /dev/null +++ b/common/lib/libc/string/consttime_bcmp.c @@ -0,0 +1,19 @@ +/* $NetBSD: consttime_bcmp.c,v 1.1 2012/08/30 12:16:49 drochner Exp $ */ + +#if !defined(_KERNEL) && !defined(_STANDALONE) +#include +#define consttime_bcmp __consttime_bcmp +#else +#include +#endif + +int +consttime_bcmp(const void *b1, const void *b2, size_t len) +{ + const char *c1 = b1, *c2 = b2; + int res = 0; + + while (len --) + res |= *c1++ ^ *c2++; + return res; +} diff --git a/common/lib/libc/string/explicit_bzero.c b/common/lib/libc/string/explicit_bzero.c new file mode 100644 index 000000000..c34410cfd --- /dev/null +++ b/common/lib/libc/string/explicit_bzero.c @@ -0,0 +1,22 @@ +/* $NetBSD: explicit_bzero.c,v 1.1 2012/08/30 12:16:49 drochner Exp $ */ + +#if !defined(_KERNEL) && !defined(_STANDALONE) +#include +#define explicit_bzero __explicit_bzero +#define explicit_memset_impl __explicit_memset_impl +#else +#include +#endif + +/* + * The use of a volatile pointer guarantees that the compiler + * will not optimise the call away. + */ +void *(* volatile explicit_memset_impl)(void *, int, size_t) = memset; + +void +explicit_bzero(void *b, size_t len) +{ + + (*explicit_memset_impl)(b, 0, len); +} diff --git a/common/lib/libc/string/ffs.c b/common/lib/libc/string/ffs.c index 0217f5e0f..59969507d 100644 --- a/common/lib/libc/string/ffs.c +++ b/common/lib/libc/string/ffs.c @@ -1,4 +1,4 @@ -/* $NetBSD: ffs.c,v 1.3 2007/11/02 21:05:06 christos Exp $ */ +/* $NetBSD: ffs.c,v 1.4 2011/08/07 01:52:47 mrg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)ffs.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: ffs.c,v 1.3 2007/11/02 21:05:06 christos Exp $"); +__RCSID("$NetBSD: ffs.c,v 1.4 2011/08/07 01:52:47 mrg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,6 +53,7 @@ __RCSID("$NetBSD: ffs.c,v 1.3 2007/11/02 21:05:06 christos Exp $"); /* * ffs -- vax ffs instruction */ +__weak_alias(__ffssi2,ffs) int ffs(int mask) { diff --git a/common/lib/libc/string/memcmp.c b/common/lib/libc/string/memcmp.c index 12880486b..4543bf8ce 100644 --- a/common/lib/libc/string/memcmp.c +++ b/common/lib/libc/string/memcmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: memcmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $ */ +/* $NetBSD: memcmp.c,v 1.3 2011/11/08 16:52:11 joerg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)memcmp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: memcmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $"); +__RCSID("$NetBSD: memcmp.c,v 1.3 2011/11/08 16:52:11 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,6 +48,7 @@ __RCSID("$NetBSD: memcmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $"); #include #endif +#undef memcmp /* * Compare memory regions. */ diff --git a/common/lib/libc/string/memset.c b/common/lib/libc/string/memset.c index ed2ccb416..70be19cef 100644 --- a/common/lib/libc/string/memset.c +++ b/common/lib/libc/string/memset.c @@ -1,4 +1,4 @@ -/* $NetBSD: memset.c,v 1.8 2009/03/18 12:25:06 tsutsui Exp $ */ +/* $NetBSD: memset.c,v 1.9 2011/11/08 16:52:11 joerg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)memset.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: memset.c,v 1.8 2009/03/18 12:25:06 tsutsui Exp $"); +__RCSID("$NetBSD: memset.c,v 1.9 2011/11/08 16:52:11 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -60,8 +60,8 @@ __RCSID("$NetBSD: memset.c,v 1.8 2009/03/18 12:25:06 tsutsui Exp $"); #ifdef _FORTIFY_SOURCE #undef bzero -#undef memset #endif +#undef memset #ifndef __OPTIMIZE_SIZE__ #ifdef BZERO diff --git a/common/lib/libc/string/memset2.c b/common/lib/libc/string/memset2.c index 7009f4805..13a0407d0 100644 --- a/common/lib/libc/string/memset2.c +++ b/common/lib/libc/string/memset2.c @@ -27,6 +27,11 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: memset2.c,v 1.5 2012/03/02 16:22:27 apb Exp $"); +#endif /* LIBC_SCCS and not lint */ + #include #if !defined(_KERNEL) && !defined(_STANDALONE) @@ -49,18 +54,16 @@ #ifdef _FORTIFY_SOURCE #undef bzero -#undef memset #endif - -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: memset2.c,v 1.2 2009/12/14 00:39:01 matt Exp $"); -#endif /* LIBC_SCCS and not lint */ +#undef memset /* * Assume uregister_t is the widest non-synthetic unsigned type. */ typedef uregister_t memword_t; +__CTASSERT((~(memword_t)0U >> 1) != ~(memword_t)0U); + #ifdef BZERO static inline #define memset memset0 @@ -71,10 +74,6 @@ static #define memset test_memset #endif -#ifdef CTASSERT -CTASSERT((~(memword_t)0U >> 1) != ~(memword_t)0U); -#endif - void * memset(void *addr, int c, size_t len) { diff --git a/common/lib/libc/string/popcount32.c b/common/lib/libc/string/popcount32.c index bc5058d54..6913fb8ad 100644 --- a/common/lib/libc/string/popcount32.c +++ b/common/lib/libc/string/popcount32.c @@ -1,4 +1,4 @@ -/* $NetBSD: popcount32.c,v 1.3 2009/07/21 19:56:55 drochner Exp $ */ +/* $NetBSD: popcount32.c,v 1.4 2011/08/21 21:25:04 dholland Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. @@ -32,10 +32,11 @@ */ #include -__RCSID("$NetBSD: popcount32.c,v 1.3 2009/07/21 19:56:55 drochner Exp $"); +__RCSID("$NetBSD: popcount32.c,v 1.4 2011/08/21 21:25:04 dholland Exp $"); #if !defined(_KERNEL) && !defined(_STANDALONE) #include +#include #include #else #include diff --git a/common/lib/libc/string/popcount64.c b/common/lib/libc/string/popcount64.c index 51a1c19be..753fb9bd6 100644 --- a/common/lib/libc/string/popcount64.c +++ b/common/lib/libc/string/popcount64.c @@ -1,4 +1,4 @@ -/* $NetBSD: popcount64.c,v 1.5 2009/08/05 15:04:15 joerg Exp $ */ +/* $NetBSD: popcount64.c,v 1.7 2012/03/09 15:41:16 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. @@ -32,10 +32,11 @@ */ #include -__RCSID("$NetBSD: popcount64.c,v 1.5 2009/08/05 15:04:15 joerg Exp $"); +__RCSID("$NetBSD: popcount64.c,v 1.7 2012/03/09 15:41:16 christos Exp $"); #if !defined(_KERNEL) && !defined(_STANDALONE) #include +#include #include #else #include @@ -63,10 +64,12 @@ popcount64(uint64_t v) { unsigned int c; - v = v - ((v >> 1) & 0x5555555555555555ULL); - v = (v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL); - v = ((v + (v >> 4)) & 0x0f0f0f0f0f0f0f0fULL) * 0x0101010101010101ULL; - c = v >> 56; + v = v - ((v >> 1) & (uint64_t)0x5555555555555555ULL); + v = (v & (uint64_t)0x3333333333333333ULL) + + ((v >> 2) & (uint64_t)0x3333333333333333ULL); + v = ((v + (v >> 4)) & (uint64_t)0x0f0f0f0f0f0f0f0fULL) * + (uint64_t)0x0101010101010101ULL; + c = (unsigned int)(v >> 56); return c; } diff --git a/common/lib/libc/string/strchr.c b/common/lib/libc/string/strchr.c index 01c8946c4..2e01b1b34 100644 --- a/common/lib/libc/string/strchr.c +++ b/common/lib/libc/string/strchr.c @@ -1,4 +1,4 @@ -/* $NetBSD: strchr.c,v 1.4 2009/07/17 19:37:57 dsl Exp $ */ +/* $NetBSD: strchr.c,v 1.5 2011/08/31 15:48:32 plunky Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)index.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: strchr.c,v 1.4 2009/07/17 19:37:57 dsl Exp $"); +__RCSID("$NetBSD: strchr.c,v 1.5 2011/08/31 15:48:32 plunky Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -59,7 +59,7 @@ strchr(const char *p, int ch) return(__UNCONST(p)); } if (!*p) - return((char *)NULL); + return(NULL); } /* NOTREACHED */ } diff --git a/common/lib/libc/string/strcpy.c b/common/lib/libc/string/strcpy.c index f7dfb58fd..3a3d2fb54 100644 --- a/common/lib/libc/string/strcpy.c +++ b/common/lib/libc/string/strcpy.c @@ -1,4 +1,4 @@ -/* $NetBSD: strcpy.c,v 1.2 2007/06/04 18:19:27 christos Exp $ */ +/* $NetBSD: strcpy.c,v 1.3 2011/11/08 16:52:11 joerg Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)strcpy.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: strcpy.c,v 1.2 2007/06/04 18:19:27 christos Exp $"); +__RCSID("$NetBSD: strcpy.c,v 1.3 2011/11/08 16:52:11 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -45,9 +45,7 @@ __RCSID("$NetBSD: strcpy.c,v 1.2 2007/06/04 18:19:27 christos Exp $"); #include #endif -#ifdef _FORTIFY_SOURCE #undef strcpy -#endif char * strcpy(char *to, const char *from) diff --git a/common/lib/libc/string/strnlen.c b/common/lib/libc/string/strnlen.c index 8342828b1..b0fba9afa 100644 --- a/common/lib/libc/string/strnlen.c +++ b/common/lib/libc/string/strnlen.c @@ -1,4 +1,4 @@ -/* $NetBSD: strnlen.c,v 1.1 2009/05/01 17:27:01 perry Exp $ */ +/* $NetBSD: strnlen.c,v 1.1 2011/09/01 22:35:18 jym Exp $ */ /*- * Copyright (c) 2009 David Schultz @@ -28,11 +28,15 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: strnlen.c,v 1.1 2009/05/01 17:27:01 perry Exp $"); +__RCSID("$NetBSD: strnlen.c,v 1.1 2011/09/01 22:35:18 jym Exp $"); #endif /* LIBC_SCCS and not lint */ /* FreeBSD: src/lib/libc/string/strnlen.c,v 1.1 2009/02/28 06:00:58 das Exp */ +#if !defined(_KERNEL) && !defined(_STANDALONE) #include +#else +#include +#endif size_t strnlen(const char *s, size_t maxlen) diff --git a/common/lib/libc/sys/cpuset.c b/common/lib/libc/sys/cpuset.c index 66b332050..c34d48537 100644 --- a/common/lib/libc/sys/cpuset.c +++ b/common/lib/libc/sys/cpuset.c @@ -1,4 +1,4 @@ -/* $NetBSD: cpuset.c,v 1.16 2010/09/21 02:03:29 rmind Exp $ */ +/* $NetBSD: cpuset.c,v 1.18 2012/03/09 15:41:16 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #ifndef _STANDALONE #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: cpuset.c,v 1.16 2010/09/21 02:03:29 rmind Exp $"); +__RCSID("$NetBSD: cpuset.c,v 1.18 2012/03/09 15:41:16 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -64,24 +64,11 @@ struct _cpuset { uint32_t bits[0]; }; -#ifdef _KERNEL -struct _kcpuset { - unsigned int nused; - struct _kcpuset *next; - uint32_t bits[0]; -}; -#define KCPUSET_SIZE(n) (sizeof( \ - struct { \ - unsigned int nused; \ - struct _kcpuset *next; \ - uint32_t bits[0]; \ - }) + sizeof(uint32_t) * (n)) -#endif +#ifndef _KERNEL static size_t cpuset_size = 0; static size_t cpuset_nentries = 0; -#ifndef _KERNEL size_t /*ARGSUSED*/ _cpuset_size(const cpuset_t *c) @@ -106,7 +93,7 @@ _cpuset_isset(cpuid_t i, const cpuset_t *c) errno = EINVAL; return -1; } - return ((1 << (i & CPUSET_MASK)) & c->bits[j]) != 0; + return ((1 << (unsigned int)(i & CPUSET_MASK)) & c->bits[j]) != 0; } int @@ -118,7 +105,7 @@ _cpuset_set(cpuid_t i, cpuset_t *c) errno = EINVAL; return -1; } - c->bits[j] |= 1 << (i & CPUSET_MASK); + c->bits[j] |= 1 << (unsigned int)(i & CPUSET_MASK); return 0; } @@ -131,7 +118,7 @@ _cpuset_clr(cpuid_t i, cpuset_t *c) errno = EINVAL; return -1; } - c->bits[j] &= ~(1 << (i & CPUSET_MASK)); + c->bits[j] &= ~(1 << (unsigned int)(i & CPUSET_MASK)); return 0; } @@ -145,7 +132,8 @@ _cpuset_create(void) u_int nc; len = sizeof(nc); - if (sysctl(mib, __arraycount(mib), &nc, &len, NULL, 0) == -1) + if (sysctl(mib, (unsigned int)__arraycount(mib), &nc, &len, + NULL, 0) == -1) return NULL; cpuset_nentries = CPUSET_NENTRIES(nc); @@ -161,150 +149,5 @@ _cpuset_destroy(cpuset_t *c) free(c); } -#else - -kcpuset_t * -kcpuset_create(void) -{ - kcpuset_t *c; - - if (cpuset_size == 0) { - cpuset_nentries = CPUSET_NENTRIES(MAXCPUS); - cpuset_size = KCPUSET_SIZE(cpuset_nentries); - } - c = kmem_zalloc(cpuset_size, KM_SLEEP); - c->next = NULL; - c->nused = 1; - return c; -} - -void -kcpuset_destroy(kcpuset_t *c) -{ - kcpuset_t *nc; - - while (c) { - KASSERT(c->nused == 0); - nc = c->next; - kmem_free(c, cpuset_size); - c = nc; - } -} - -void -kcpuset_copy(kcpuset_t *d, const kcpuset_t *s) -{ - - KASSERT(d->nused == 1); - memcpy(d->bits, s->bits, cpuset_nentries * sizeof(s->bits[0])); -} - -void -kcpuset_use(kcpuset_t *c) -{ - - atomic_inc_uint(&c->nused); -} - -void -kcpuset_unuse(kcpuset_t *c, kcpuset_t **lst) -{ - - if (atomic_dec_uint_nv(&c->nused) != 0) - return; - KASSERT(c->nused == 0); - KASSERT(c->next == NULL); - if (lst == NULL) { - kcpuset_destroy(c); - return; - } - c->next = *lst; - *lst = c; -} - -int -kcpuset_copyin(const cpuset_t *u, kcpuset_t *k, size_t len) -{ - - KASSERT(k->nused > 0); - KASSERT(k->next == NULL); - if (len != CPUSET_SIZE(cpuset_nentries)) - return EINVAL; - return copyin(u->bits, k->bits, cpuset_nentries * sizeof(k->bits[0])); -} - -int -kcpuset_copyout(const kcpuset_t *k, cpuset_t *u, size_t len) -{ - - KASSERT(k->nused > 0); - KASSERT(k->next == NULL); - if (len != CPUSET_SIZE(cpuset_nentries)) - return EINVAL; - return copyout(k->bits, u->bits, cpuset_nentries * sizeof(u->bits[0])); -} - -void -kcpuset_zero(kcpuset_t *c) -{ - - KASSERT(c->nused > 0); - KASSERT(c->next == NULL); - memset(c->bits, 0, cpuset_nentries * sizeof(c->bits[0])); -} - -void -kcpuset_fill(kcpuset_t *c) -{ - - KASSERT(c->nused > 0); - KASSERT(c->next == NULL); - memset(c->bits, ~0, cpuset_nentries * sizeof(c->bits[0])); -} - -void -kcpuset_set(cpuid_t i, kcpuset_t *c) -{ - const unsigned long j = i >> CPUSET_SHIFT; - - KASSERT(c->next == NULL); - KASSERT(j < cpuset_nentries); - c->bits[j] |= 1 << (i & CPUSET_MASK); -} - -int -kcpuset_isset(cpuid_t i, const kcpuset_t *c) -{ - const unsigned long j = i >> CPUSET_SHIFT; - - KASSERT(c != NULL); - KASSERT(c->nused > 0); - KASSERT(c->next == NULL); - KASSERT(j < cpuset_nentries); - return ((1 << (i & CPUSET_MASK)) & c->bits[j]) != 0; -} - -bool -kcpuset_iszero(const kcpuset_t *c) -{ - unsigned long j; - - for (j = 0; j < cpuset_nentries; j++) - if (c->bits[j] != 0) - return false; - return true; -} - -bool -kcpuset_match(const kcpuset_t *c1, const kcpuset_t *c2) -{ - unsigned long j; - - for (j = 0; j < cpuset_nentries; j++) - if ((c1->bits[j] & c2->bits[j]) != c2->bits[j]) - return false; - return true; -} - #endif #endif diff --git a/common/lib/libprop/prop_array.c b/common/lib/libprop/prop_array.c index ecb6a8689..c73996fb2 100644 --- a/common/lib/libprop/prop_array.c +++ b/common/lib/libprop/prop_array.c @@ -1,4 +1,4 @@ -/* $NetBSD: prop_array.c,v 1.20 2008/08/11 05:54:21 christos Exp $ */ +/* $NetBSD: prop_array.c,v 1.21 2012/07/27 09:10:59 pooka Exp $ */ /*- * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc. @@ -29,8 +29,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include "prop_object_impl.h" +#include #if !defined(_KERNEL) && !defined(_STANDALONE) #include @@ -340,7 +340,7 @@ static prop_object_t _prop_array_iterator_next_object(void *v) { struct _prop_array_iterator *pai = v; - prop_array_t pa __unused = pai->pai_base.pi_obj; + prop_array_t pa _PROP_ARG_UNUSED = pai->pai_base.pi_obj; prop_object_t po; _PROP_ASSERT(prop_object_is_array(pa)); @@ -367,7 +367,7 @@ static void _prop_array_iterator_reset(void *v) { struct _prop_array_iterator *pai = v; - prop_array_t pa __unused = pai->pai_base.pi_obj; + prop_array_t pa _PROP_ARG_UNUSED = pai->pai_base.pi_obj; _PROP_ASSERT(prop_object_is_array(pa)); diff --git a/common/lib/libprop/prop_array_util.c b/common/lib/libprop/prop_array_util.c index 8515bd5d3..52e905b68 100644 --- a/common/lib/libprop/prop_array_util.c +++ b/common/lib/libprop/prop_array_util.c @@ -1,4 +1,4 @@ -/* $NetBSD: prop_array_util.c,v 1.3 2011/03/24 17:05:39 bouyer Exp $ */ +/* $NetBSD: prop_array_util.c,v 1.4 2012/07/27 09:10:59 pooka Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -38,8 +38,8 @@ * exactly what we're doing here. */ -#include #include "prop_object_impl.h" /* hide kernel vs. not-kernel vs. standalone */ +#include bool prop_array_get_bool(prop_array_t array, diff --git a/common/lib/libprop/prop_dictionary.c b/common/lib/libprop/prop_dictionary.c index 8c2dcea9f..6e1435088 100644 --- a/common/lib/libprop/prop_dictionary.c +++ b/common/lib/libprop/prop_dictionary.c @@ -1,4 +1,4 @@ -/* $NetBSD: prop_dictionary.c,v 1.37 2011/04/20 19:40:00 martin Exp $ */ +/* $NetBSD: prop_dictionary.c,v 1.38 2012/07/27 09:10:59 pooka Exp $ */ /*- * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc. @@ -29,10 +29,10 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "prop_object_impl.h" #include #include #include -#include "prop_object_impl.h" #include "prop_rb_impl.h" #if !defined(_KERNEL) && !defined(_STANDALONE) @@ -173,7 +173,7 @@ struct _prop_dictionary_iterator { static int /*ARGSUSED*/ -_prop_dict_keysym_rb_compare_nodes(void *ctx __unused, +_prop_dict_keysym_rb_compare_nodes(void *ctx _PROP_ARG_UNUSED, const void *n1, const void *n2) { const struct _prop_dictionary_keysym *pdk1 = n1; @@ -184,7 +184,7 @@ _prop_dict_keysym_rb_compare_nodes(void *ctx __unused, static int /*ARGSUSED*/ -_prop_dict_keysym_rb_compare_key(void *ctx __unused, +_prop_dict_keysym_rb_compare_key(void *ctx _PROP_ARG_UNUSED, const void *n, const void *v) { const struct _prop_dictionary_keysym *pdk = n; @@ -628,7 +628,7 @@ static prop_object_t _prop_dictionary_iterator_next_object(void *v) { struct _prop_dictionary_iterator *pdi = v; - prop_dictionary_t pd __unused = pdi->pdi_base.pi_obj; + prop_dictionary_t pd _PROP_ARG_UNUSED = pdi->pdi_base.pi_obj; prop_dictionary_keysym_t pdk; _PROP_ASSERT(prop_object_is_dictionary(pd)); @@ -655,7 +655,9 @@ static void _prop_dictionary_iterator_reset(void *v) { struct _prop_dictionary_iterator *pdi = v; - prop_dictionary_t pd __unused = pdi->pdi_base.pi_obj; +#ifdef _REENTRANT + prop_dictionary_t pd _PROP_ARG_UNUSED = pdi->pdi_base.pi_obj; +#endif _PROP_RWLOCK_RDLOCK(pd->pd_rwlock); _prop_dictionary_iterator_reset_locked(pdi); @@ -914,15 +916,19 @@ _prop_dictionary_get(prop_dictionary_t pd, const char *key, bool locked) if (! prop_object_is_dictionary(pd)) return (NULL); +#ifdef _REENTRANT if (!locked) _PROP_RWLOCK_RDLOCK(pd->pd_rwlock); +#endif pde = _prop_dict_lookup(pd, key, NULL); if (pde != NULL) { _PROP_ASSERT(pde->pde_objref != NULL); po = pde->pde_objref; } +#ifdef _REENTRANT if (!locked) _PROP_RWLOCK_UNLOCK(pd->pd_rwlock); +#endif return (po); } /* diff --git a/common/lib/libprop/prop_dictionary_util.c b/common/lib/libprop/prop_dictionary_util.c index 65baf73cc..0b4867268 100644 --- a/common/lib/libprop/prop_dictionary_util.c +++ b/common/lib/libprop/prop_dictionary_util.c @@ -1,4 +1,4 @@ -/* $NetBSD: prop_dictionary_util.c,v 1.4 2011/03/24 17:05:39 bouyer Exp $ */ +/* $NetBSD: prop_dictionary_util.c,v 1.5 2012/07/27 09:10:59 pooka Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -38,8 +38,8 @@ * exactly what we're doing here. */ -#include #include "prop_object_impl.h" /* only to hide kernel vs. not-kernel */ +#include bool prop_dictionary_get_dict(prop_dictionary_t dict, const char *key, prop_dictionary_t *dp) diff --git a/common/lib/libprop/prop_ingest.c b/common/lib/libprop/prop_ingest.c index 823d2c6c7..9d161b579 100644 --- a/common/lib/libprop/prop_ingest.c +++ b/common/lib/libprop/prop_ingest.c @@ -1,4 +1,4 @@ -/* $NetBSD: prop_ingest.c,v 1.3 2008/04/28 20:22:53 martin Exp $ */ +/* $NetBSD: prop_ingest.c,v 1.4 2012/07/27 09:10:59 pooka Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -29,8 +29,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include "prop_object_impl.h" +#include struct _prop_ingest_context { prop_ingest_error_t pic_error; diff --git a/common/lib/libprop/prop_number.c b/common/lib/libprop/prop_number.c index ba61b580f..c6b47c5d7 100644 --- a/common/lib/libprop/prop_number.c +++ b/common/lib/libprop/prop_number.c @@ -1,4 +1,4 @@ -/* $NetBSD: prop_number.c,v 1.23 2010/09/24 22:51:52 rmind Exp $ */ +/* $NetBSD: prop_number.c,v 1.24 2012/07/27 09:10:59 pooka Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -119,7 +119,7 @@ _prop_number_compare_values(const struct _prop_number_value *pnv1, static int /*ARGSUSED*/ -_prop_number_rb_compare_nodes(void *ctx __unused, +_prop_number_rb_compare_nodes(void *ctx _PROP_ARG_UNUSED, const void *n1, const void *n2) { const struct _prop_number *pn1 = n1; @@ -130,7 +130,8 @@ _prop_number_rb_compare_nodes(void *ctx __unused, static int /*ARGSUSED*/ -_prop_number_rb_compare_key(void *ctx __unused, const void *n, const void *v) +_prop_number_rb_compare_key(void *ctx _PROP_ARG_UNUSED, + const void *n, const void *v) { const struct _prop_number *pn = n; const struct _prop_number_value *pnv = v; diff --git a/common/lib/libprop/prop_object.c b/common/lib/libprop/prop_object.c index 9f85c3e76..ea26bff95 100644 --- a/common/lib/libprop/prop_object.c +++ b/common/lib/libprop/prop_object.c @@ -1,4 +1,4 @@ -/* $NetBSD: prop_object.c,v 1.27 2011/04/20 20:00:07 martin Exp $ */ +/* $NetBSD: prop_object.c,v 1.28 2012/07/27 09:10:59 pooka Exp $ */ /*- * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc. @@ -29,8 +29,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include #include "prop_object_impl.h" +#include + +#ifdef _PROP_NEED_REFCNT_MTX +static pthread_mutex_t _prop_refcnt_mtx = PTHREAD_MUTEX_INITIALIZER; +#endif /* _PROP_NEED_REFCNT_MTX */ #if !defined(_KERNEL) && !defined(_STANDALONE) #include @@ -43,7 +47,6 @@ #include #endif /* defined(__minix) */ #endif -#include #ifdef _STANDALONE void * @@ -856,10 +859,14 @@ _prop_object_externalize_write_file(const char *fname, const char *xml, * and create the temporary file. */ _prop_object_externalize_file_dirname(fname, tname); - if (strlcat(tname, "/.plistXXXXXX", sizeof(tname)) >= sizeof(tname)) { +#define PLISTTMP "/.plistXXXXXX" + if (strlen(tname) + strlen(PLISTTMP) >= sizeof(tname)) { errno = ENAMETOOLONG; return (false); } + strcat(tname, PLISTTMP); +#undef PLISTTMP + if ((fd = mkstemp(tname)) == -1) return (false); @@ -996,7 +1003,7 @@ prop_object_retain(prop_object_t obj) struct _prop_object *po = obj; uint32_t ncnt; - ncnt = atomic_inc_32_nv(&po->po_refcnt); + _PROP_ATOMIC_INC32_NV(&po->po_refcnt, ncnt); _PROP_ASSERT(ncnt != 0); } @@ -1028,7 +1035,7 @@ prop_object_release_emergency(prop_object_t obj) unlock = po->po_type->pot_unlock; /* Dance a bit to make sure we always get the non-racy ocnt */ - ocnt = atomic_dec_32_nv(&po->po_refcnt); + _PROP_ATOMIC_DEC32_NV(&po->po_refcnt, ocnt); ocnt++; _PROP_ASSERT(ocnt != 0); @@ -1050,7 +1057,7 @@ prop_object_release_emergency(prop_object_t obj) unlock(); parent = po; - atomic_inc_32(&po->po_refcnt); + _PROP_ATOMIC_INC32(&po->po_refcnt); } _PROP_ASSERT(parent); /* One object was just freed. */ @@ -1087,7 +1094,7 @@ prop_object_release(prop_object_t obj) /* Save pointer to object unlock function */ unlock = po->po_type->pot_unlock; - ocnt = atomic_dec_32_nv(&po->po_refcnt); + _PROP_ATOMIC_DEC32_NV(&po->po_refcnt, ocnt); ocnt++; _PROP_ASSERT(ocnt != 0); @@ -1106,7 +1113,7 @@ prop_object_release(prop_object_t obj) if (ret == _PROP_OBJECT_FREE_DONE) break; - atomic_inc_32(&po->po_refcnt); + _PROP_ATOMIC_INC32(&po->po_refcnt); } while (ret == _PROP_OBJECT_FREE_RECURSE); if (ret == _PROP_OBJECT_FREE_FAILED) prop_object_release_emergency(obj); diff --git a/common/lib/libprop/prop_object_impl.h b/common/lib/libprop/prop_object_impl.h index dd438d086..b854524b0 100644 --- a/common/lib/libprop/prop_object_impl.h +++ b/common/lib/libprop/prop_object_impl.h @@ -1,4 +1,4 @@ -/* $NetBSD: prop_object_impl.h,v 1.30 2009/09/13 18:45:10 pooka Exp $ */ +/* $NetBSD: prop_object_impl.h,v 1.31 2012/07/27 09:10:59 pooka Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -293,6 +293,13 @@ __link_set_add_rodata(prop_linkpools, _link_ ## pp); #define _PROP_ONCE_DECL(x) static ONCE_DECL(x); #define _PROP_ONCE_RUN(x,f) RUN_ONCE(&(x), f) +#include + +#define _PROP_ATOMIC_INC32(x) atomic_inc_32(x) +#define _PROP_ATOMIC_DEC32(x) atomic_dec_32(x) +#define _PROP_ATOMIC_INC32_NV(x, v) v = atomic_inc_32_nv(x) +#define _PROP_ATOMIC_DEC32_NV(x, v) v = atomic_dec_32_nv(x) + #elif defined(_STANDALONE) /* @@ -333,6 +340,11 @@ void * _prop_standalone_realloc(void *, size_t); #define _PROP_ONCE_DECL(x) _PROP_NOTHREAD_ONCE_DECL(x) #define _PROP_ONCE_RUN(x,f) _PROP_NOTHREAD_ONCE_RUN(x,f) +#define _PROP_ATOMIC_INC32(x) ++*(x) +#define _PROP_ATOMIC_DEC32(x) --*(x) +#define _PROP_ATOMIC_INC32_NV(x, v) v = ++*(x) +#define _PROP_ATOMIC_DEC32_NV(x, v) v = --*(x) + #else /* @@ -359,11 +371,12 @@ void * _prop_standalone_realloc(void *, size_t); #define _PROP_MALLOC_DEFINE(t, s, l) /* nothing */ -#if (defined(__NetBSD__) && defined(_LIBPROP)) +#if defined(__NetBSD__) && defined(_LIBPROP) /* * Use the same mechanism as libc; we get pthread mutexes for threaded * programs and do-nothing stubs for non-threaded programs. */ +#include #include "reentrant.h" #define _PROP_MUTEX_DECL_STATIC(x) static mutex_t x; #define _PROP_MUTEX_INIT(x) mutex_init(&(x), NULL) @@ -381,6 +394,11 @@ void * _prop_standalone_realloc(void *, size_t); static pthread_once_t x = PTHREAD_ONCE_INIT; #define _PROP_ONCE_RUN(x,f) thr_once(&(x), (void(*)(void))f); +#define _PROP_ATOMIC_INC32(x) atomic_inc_32(x) +#define _PROP_ATOMIC_DEC32(x) atomic_dec_32(x) +#define _PROP_ATOMIC_INC32_NV(x, v) v = atomic_inc_32_nv(x) +#define _PROP_ATOMIC_DEC32_NV(x, v) v = atomic_dec_32_nv(x) + #elif defined(HAVE_NBTOOL_CONFIG_H) || defined(__minix) /* * None of NetBSD's build tools are multi-threaded. @@ -399,6 +417,12 @@ void * _prop_standalone_realloc(void *, size_t); #define _PROP_ONCE_DECL(x) _PROP_NOTHREAD_ONCE_DECL(x) #define _PROP_ONCE_RUN(x,f) _PROP_NOTHREAD_ONCE_RUN(x,f) + +#define _PROP_ATOMIC_INC32(x) ++*(x) +#define _PROP_ATOMIC_DEC32(x) --*(x) +#define _PROP_ATOMIC_INC32_NV(x, v) v = ++*(x) +#define _PROP_ATOMIC_DEC32_NV(x, v) v = --*(x) + #else /* * Use pthread mutexes everywhere else. @@ -419,8 +443,38 @@ void * _prop_standalone_realloc(void *, size_t); #define _PROP_ONCE_DECL(x) \ static pthread_once_t x = PTHREAD_ONCE_INIT; #define _PROP_ONCE_RUN(x,f) pthread_once(&(x),(void(*)(void))f) -#endif +#define _PROP_NEED_REFCNT_MTX + +#define _PROP_ATOMIC_INC32(x) \ +do { \ + pthread_mutex_lock(&_prop_refcnt_mtx); \ + (*(x))++; \ + pthread_mutex_unlock(&_prop_refcnt_mtx); \ +} while (/*CONSTCOND*/0) + +#define _PROP_ATOMIC_DEC32(x) \ +do { \ + pthread_mutex_lock(&_prop_refcnt_mtx); \ + (*(x))--; \ + pthread_mutex_unlock(&_prop_refcnt_mtx); \ +} while (/*CONSTCOND*/0) + +#define _PROP_ATOMIC_INC32_NV(x, v) \ +do { \ + pthread_mutex_lock(&_prop_refcnt_mtx); \ + v = ++(*(x)); \ + pthread_mutex_unlock(&_prop_refcnt_mtx); \ +} while (/*CONSTCOND*/0) + +#define _PROP_ATOMIC_DEC32_NV(x, v) \ +do { \ + pthread_mutex_lock(&_prop_refcnt_mtx); \ + v = --(*(x)); \ + pthread_mutex_unlock(&_prop_refcnt_mtx); \ +} while (/*CONSTCOND*/0) + +#endif #endif /* _KERNEL */ /* diff --git a/common/lib/libprop/prop_rb.c b/common/lib/libprop/prop_rb.c index 83657bc28..f0c9ed99b 100644 --- a/common/lib/libprop/prop_rb.c +++ b/common/lib/libprop/prop_rb.c @@ -1,4 +1,4 @@ -/* $NetBSD: prop_rb.c,v 1.9 2008/06/17 21:29:47 thorpej Exp $ */ +/* $NetBSD: prop_rb.c,v 1.10 2012/07/27 09:10:59 pooka Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -27,168 +27,122 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. + * + * NetBSD: rb.c,v 1.11 2011/06/20 09:11:16 mrg Exp */ +#include "prop_object_impl.h" #include -#include "prop_object_impl.h" #include "prop_rb_impl.h" -#undef KASSERT #ifdef RBDEBUG -#define KASSERT(x) _PROP_ASSERT(x) +#define KASSERT(s) _PROP_ASSERT(s) #else -#define KASSERT(x) /* nothing */ +#define KASSERT(s) do { } while (/*CONSTCOND*/ 0) #endif #ifndef __predict_false -#define __predict_false(x) (x) +#define __predict_false(x) (x) #endif -static void rb_tree_reparent_nodes(struct rb_tree *, struct rb_node *, - unsigned int); static void rb_tree_insert_rebalance(struct rb_tree *, struct rb_node *); static void rb_tree_removal_rebalance(struct rb_tree *, struct rb_node *, unsigned int); #ifdef RBDEBUG static const struct rb_node *rb_tree_iterate_const(const struct rb_tree *, - const struct rb_node *, unsigned int); + const struct rb_node *, const unsigned int); static bool rb_tree_check_node(const struct rb_tree *, const struct rb_node *, const struct rb_node *, bool); -#endif - -#ifdef RBDEBUG -#define RBT_COUNT_INCR(rbt) (rbt)->rbt_count++ -#define RBT_COUNT_DECR(rbt) (rbt)->rbt_count-- #else -#define RBT_COUNT_INCR(rbt) /* nothing */ -#define RBT_COUNT_DECR(rbt) /* nothing */ +#define rb_tree_check_node(a, b, c, d) true #endif -#define RBUNCONST(a) ((void *)(unsigned long)(const void *)(a)) +#define RB_NODETOITEM(rbto, rbn) \ + ((void *)((uintptr_t)(rbn) - (rbto)->rbto_node_offset)) +#define RB_ITEMTONODE(rbto, rbn) \ + ((rb_node_t *)((uintptr_t)(rbn) + (rbto)->rbto_node_offset)) -/* - * Rather than testing for the NULL everywhere, all terminal leaves are - * pointed to this node (and that includes itself). Note that by setting - * it to be const, that on some architectures trying to write to it will - * cause a fault. - */ -static const struct rb_node sentinel_node = { - .rb_nodes = { RBUNCONST(&sentinel_node), - RBUNCONST(&sentinel_node), - NULL }, - .rb_u = { .u_s = { .s_sentinel = 1 } }, -}; +#define RB_SENTINEL_NODE NULL void -_prop_rb_tree_init(struct rb_tree *rbt, const struct rb_tree_ops *ops) +_prop_rb_tree_init(struct rb_tree *rbt, const rb_tree_ops_t *ops) { + + rbt->rbt_ops = ops; + rbt->rbt_root = RB_SENTINEL_NODE; RB_TAILQ_INIT(&rbt->rbt_nodes); -#ifdef RBDEBUG +#ifndef RBSMALL + rbt->rbt_minmax[RB_DIR_LEFT] = rbt->rbt_root; /* minimum node */ + rbt->rbt_minmax[RB_DIR_RIGHT] = rbt->rbt_root; /* maximum node */ +#endif +#ifdef RBSTATS rbt->rbt_count = 0; + rbt->rbt_insertions = 0; + rbt->rbt_removals = 0; + rbt->rbt_insertion_rebalance_calls = 0; + rbt->rbt_insertion_rebalance_passes = 0; + rbt->rbt_removal_rebalance_calls = 0; + rbt->rbt_removal_rebalance_passes = 0; #endif - rbt->rbt_ops = ops; - *((const struct rb_node **)&rbt->rbt_root) = &sentinel_node; } -/* - * Swap the location and colors of 'self' and its child @ which. The child - * can not be a sentinel node. - */ -/*ARGSUSED*/ -static void -rb_tree_reparent_nodes(struct rb_tree *rbt _PROP_ARG_UNUSED, - struct rb_node *old_father, unsigned int which) +void * +_prop_rb_tree_find(struct rb_tree *rbt, const void *key) { - const unsigned int other = which ^ RB_NODE_OTHER; - struct rb_node * const grandpa = old_father->rb_parent; - struct rb_node * const old_child = old_father->rb_nodes[which]; - struct rb_node * const new_father = old_child; - struct rb_node * const new_child = old_father; - unsigned int properties; - - KASSERT(which == RB_NODE_LEFT || which == RB_NODE_RIGHT); - - KASSERT(!RB_SENTINEL_P(old_child)); - KASSERT(old_child->rb_parent == old_father); - - KASSERT(rb_tree_check_node(rbt, old_father, NULL, false)); - KASSERT(rb_tree_check_node(rbt, old_child, NULL, false)); - KASSERT(RB_ROOT_P(old_father) || rb_tree_check_node(rbt, grandpa, NULL, false)); - - /* - * Exchange descendant linkages. - */ - grandpa->rb_nodes[old_father->rb_position] = new_father; - new_child->rb_nodes[which] = old_child->rb_nodes[other]; - new_father->rb_nodes[other] = new_child; - - /* - * Update ancestor linkages - */ - new_father->rb_parent = grandpa; - new_child->rb_parent = new_father; - - /* - * Exchange properties between new_father and new_child. The only - * change is that new_child's position is now on the other side. - */ - properties = old_child->rb_properties; - new_father->rb_properties = old_father->rb_properties; - new_child->rb_properties = properties; - new_child->rb_position = other; + const rb_tree_ops_t *rbto = rbt->rbt_ops; + rbto_compare_key_fn compare_key = rbto->rbto_compare_key; + struct rb_node *parent = rbt->rbt_root; - /* - * Make sure to reparent the new child to ourself. - */ - if (!RB_SENTINEL_P(new_child->rb_nodes[which])) { - new_child->rb_nodes[which]->rb_parent = new_child; - new_child->rb_nodes[which]->rb_position = which; + while (!RB_SENTINEL_P(parent)) { + void *pobj = RB_NODETOITEM(rbto, parent); + const signed int diff = (*compare_key)(rbto->rbto_context, + pobj, key); + if (diff == 0) + return pobj; + parent = parent->rb_nodes[diff < 0]; } - KASSERT(rb_tree_check_node(rbt, new_father, NULL, false)); - KASSERT(rb_tree_check_node(rbt, new_child, NULL, false)); - KASSERT(RB_ROOT_P(new_father) || rb_tree_check_node(rbt, grandpa, NULL, false)); + return NULL; } -bool -_prop_rb_tree_insert_node(struct rb_tree *rbt, struct rb_node *self) +void * +_prop_rb_tree_insert_node(struct rb_tree *rbt, void *object) { - struct rb_node *parent, *tmp; - rb_compare_nodes_fn compare_nodes = rbt->rbt_ops->rbto_compare_nodes; + const rb_tree_ops_t *rbto = rbt->rbt_ops; + rbto_compare_nodes_fn compare_nodes = rbto->rbto_compare_nodes; + struct rb_node *parent, *tmp, *self = RB_ITEMTONODE(rbto, object); unsigned int position; + bool rebalance; + + RBSTAT_INC(rbt->rbt_insertions); - self->rb_properties = 0; tmp = rbt->rbt_root; /* * This is a hack. Because rbt->rbt_root is just a struct rb_node *, - * just like rb_node->rb_nodes[RB_NODE_LEFT], we can use this fact to + * just like rb_node->rb_nodes[RB_DIR_LEFT], we can use this fact to * avoid a lot of tests for root and know that even at root, - * updating rb_node->rb_parent->rb_nodes[rb_node->rb_position] will - * rbt->rbt_root. + * updating RB_FATHER(rb_node)->rb_nodes[RB_POSITION(rb_node)] will + * update rbt->rbt_root. */ - /* LINTED: see above */ - parent = (struct rb_node *)&rbt->rbt_root; - position = RB_NODE_LEFT; + parent = (struct rb_node *)(void *)&rbt->rbt_root; + position = RB_DIR_LEFT; /* * Find out where to place this new leaf. */ while (!RB_SENTINEL_P(tmp)) { - const int diff = (*compare_nodes)(tmp, self); + void *tobj = RB_NODETOITEM(rbto, tmp); + const signed int diff = (*compare_nodes)(rbto->rbto_context, + tobj, object); if (__predict_false(diff == 0)) { /* - * Node already exists; don't insert. + * Node already exists; return it. */ - return false; + return tobj; } parent = tmp; - KASSERT(diff != 0); - if (diff < 0) { - position = RB_NODE_LEFT; - } else { - position = RB_NODE_RIGHT; - } + position = (diff < 0); tmp = parent->rb_nodes[position]; } @@ -196,7 +150,7 @@ _prop_rb_tree_insert_node(struct rb_tree *rbt, struct rb_node *self) { struct rb_node *prev = NULL, *next = NULL; - if (position == RB_NODE_RIGHT) + if (position == RB_DIR_RIGHT) prev = parent; else if (tmp != rbt->rbt_root) next = parent; @@ -212,212 +166,337 @@ _prop_rb_tree_insert_node(struct rb_tree *rbt, struct rb_node *self) prev = TAILQ_PREV(next, rb_node_qh, rb_link); KASSERT(prev == NULL || !RB_SENTINEL_P(prev)); KASSERT(next == NULL || !RB_SENTINEL_P(next)); - KASSERT(prev == NULL - || (*compare_nodes)(prev, self) > 0); - KASSERT(next == NULL - || (*compare_nodes)(self, next) > 0); + KASSERT(prev == NULL || (*compare_nodes)(rbto->rbto_context, + RB_NODETOITEM(rbto, prev), RB_NODETOITEM(rbto, self)) < 0); + KASSERT(next == NULL || (*compare_nodes)(rbto->rbto_context, + RB_NODETOITEM(rbto, self), RB_NODETOITEM(rbto, next)) < 0); } #endif /* * Initialize the node and insert as a leaf into the tree. */ - self->rb_parent = parent; - self->rb_position = position; - /* LINTED: rbt_root hack */ - if (__predict_false(parent == (struct rb_node *) &rbt->rbt_root)) { - RB_MARK_ROOT(self); + RB_SET_FATHER(self, parent); + RB_SET_POSITION(self, position); + if (__predict_false(parent == (struct rb_node *)(void *)&rbt->rbt_root)) { + RB_MARK_BLACK(self); /* root is always black */ +#ifndef RBSMALL + rbt->rbt_minmax[RB_DIR_LEFT] = self; + rbt->rbt_minmax[RB_DIR_RIGHT] = self; +#endif + rebalance = false; } else { - KASSERT(position == RB_NODE_LEFT || position == RB_NODE_RIGHT); - KASSERT(!RB_ROOT_P(self)); /* Already done */ + KASSERT(position == RB_DIR_LEFT || position == RB_DIR_RIGHT); +#ifndef RBSMALL + /* + * Keep track of the minimum and maximum nodes. If our + * parent is a minmax node and we on their min/max side, + * we must be the new min/max node. + */ + if (parent == rbt->rbt_minmax[position]) + rbt->rbt_minmax[position] = self; +#endif /* !RBSMALL */ + /* + * All new nodes are colored red. We only need to rebalance + * if our parent is also red. + */ + RB_MARK_RED(self); + rebalance = RB_RED_P(parent); } KASSERT(RB_SENTINEL_P(parent->rb_nodes[position])); self->rb_left = parent->rb_nodes[position]; self->rb_right = parent->rb_nodes[position]; parent->rb_nodes[position] = self; - KASSERT(self->rb_left == &sentinel_node && - self->rb_right == &sentinel_node); + KASSERT(RB_CHILDLESS_P(self)); /* * Insert the new node into a sorted list for easy sequential access */ - RBT_COUNT_INCR(rbt); + RBSTAT_INC(rbt->rbt_count); #ifdef RBDEBUG - if (RB_ROOT_P(self)) { + if (RB_ROOT_P(rbt, self)) { RB_TAILQ_INSERT_HEAD(&rbt->rbt_nodes, self, rb_link); - } else if (position == RB_NODE_LEFT) { - KASSERT((*compare_nodes)(self, self->rb_parent) > 0); - RB_TAILQ_INSERT_BEFORE(self->rb_parent, self, rb_link); + } else if (position == RB_DIR_LEFT) { + KASSERT((*compare_nodes)(rbto->rbto_context, + RB_NODETOITEM(rbto, self), + RB_NODETOITEM(rbto, RB_FATHER(self))) < 0); + RB_TAILQ_INSERT_BEFORE(RB_FATHER(self), self, rb_link); } else { - KASSERT((*compare_nodes)(self->rb_parent, self) > 0); - RB_TAILQ_INSERT_AFTER(&rbt->rbt_nodes, self->rb_parent, + KASSERT((*compare_nodes)(rbto->rbto_context, + RB_NODETOITEM(rbto, RB_FATHER(self)), + RB_NODETOITEM(rbto, self)) < 0); + RB_TAILQ_INSERT_AFTER(&rbt->rbt_nodes, RB_FATHER(self), self, rb_link); } #endif + KASSERT(rb_tree_check_node(rbt, self, NULL, !rebalance)); -#if 0 /* - * Validate the tree before we rebalance + * Rebalance tree after insertion */ - _prop_rb_tree_check(rbt, false); -#endif + if (rebalance) { + rb_tree_insert_rebalance(rbt, self); + KASSERT(rb_tree_check_node(rbt, self, NULL, true)); + } + + /* Succesfully inserted, return our node pointer. */ + return object; +} + +/* + * Swap the location and colors of 'self' and its child @ which. The child + * can not be a sentinel node. This is our rotation function. However, + * since it preserves coloring, it great simplifies both insertion and + * removal since rotation almost always involves the exchanging of colors + * as a separate step. + */ +/*ARGSUSED*/ +static void +rb_tree_reparent_nodes(struct rb_tree *rbt, struct rb_node *old_father, + const unsigned int which) +{ + const unsigned int other = which ^ RB_DIR_OTHER; + struct rb_node * const grandpa = RB_FATHER(old_father); + struct rb_node * const old_child = old_father->rb_nodes[which]; + struct rb_node * const new_father = old_child; + struct rb_node * const new_child = old_father; + + KASSERT(which == RB_DIR_LEFT || which == RB_DIR_RIGHT); + + KASSERT(!RB_SENTINEL_P(old_child)); + KASSERT(RB_FATHER(old_child) == old_father); + + KASSERT(rb_tree_check_node(rbt, old_father, NULL, false)); + KASSERT(rb_tree_check_node(rbt, old_child, NULL, false)); + KASSERT(RB_ROOT_P(rbt, old_father) || + rb_tree_check_node(rbt, grandpa, NULL, false)); /* - * Rebalance tree after insertion + * Exchange descendant linkages. */ - rb_tree_insert_rebalance(rbt, self); + grandpa->rb_nodes[RB_POSITION(old_father)] = new_father; + new_child->rb_nodes[which] = old_child->rb_nodes[other]; + new_father->rb_nodes[other] = new_child; -#if 0 /* - * Validate the tree after we rebalanced + * Update ancestor linkages */ - _prop_rb_tree_check(rbt, true); + RB_SET_FATHER(new_father, grandpa); + RB_SET_FATHER(new_child, new_father); + + /* + * Exchange properties between new_father and new_child. The only + * change is that new_child's position is now on the other side. + */ +#if 0 + { + struct rb_node tmp; + tmp.rb_info = 0; + RB_COPY_PROPERTIES(&tmp, old_child); + RB_COPY_PROPERTIES(new_father, old_father); + RB_COPY_PROPERTIES(new_child, &tmp); + } +#else + RB_SWAP_PROPERTIES(new_father, new_child); #endif + RB_SET_POSITION(new_child, other); - return true; + /* + * Make sure to reparent the new child to ourself. + */ + if (!RB_SENTINEL_P(new_child->rb_nodes[which])) { + RB_SET_FATHER(new_child->rb_nodes[which], new_child); + RB_SET_POSITION(new_child->rb_nodes[which], which); + } + + KASSERT(rb_tree_check_node(rbt, new_father, NULL, false)); + KASSERT(rb_tree_check_node(rbt, new_child, NULL, false)); + KASSERT(RB_ROOT_P(rbt, new_father) || + rb_tree_check_node(rbt, grandpa, NULL, false)); } - + static void rb_tree_insert_rebalance(struct rb_tree *rbt, struct rb_node *self) { - RB_MARK_RED(self); - - while (!RB_ROOT_P(self) && RB_RED_P(self->rb_parent)) { - const unsigned int which = - (self->rb_parent == self->rb_parent->rb_parent->rb_left - ? RB_NODE_LEFT - : RB_NODE_RIGHT); - const unsigned int other = which ^ RB_NODE_OTHER; - struct rb_node * father = self->rb_parent; - struct rb_node * grandpa = father->rb_parent; - struct rb_node * const uncle = grandpa->rb_nodes[other]; + struct rb_node * father = RB_FATHER(self); + struct rb_node * grandpa = RB_FATHER(father); + struct rb_node * uncle; + unsigned int which; + unsigned int other; + KASSERT(!RB_ROOT_P(rbt, self)); + KASSERT(RB_RED_P(self)); + KASSERT(RB_RED_P(father)); + RBSTAT_INC(rbt->rbt_insertion_rebalance_calls); + + for (;;) { KASSERT(!RB_SENTINEL_P(self)); + + KASSERT(RB_RED_P(self)); + KASSERT(RB_RED_P(father)); /* * We are red and our parent is red, therefore we must have a * grandfather and he must be black. */ - KASSERT(RB_RED_P(self) - && RB_RED_P(father) - && RB_BLACK_P(grandpa)); + grandpa = RB_FATHER(father); + KASSERT(RB_BLACK_P(grandpa)); + KASSERT(RB_DIR_RIGHT == 1 && RB_DIR_LEFT == 0); + which = (father == grandpa->rb_right); + other = which ^ RB_DIR_OTHER; + uncle = grandpa->rb_nodes[other]; + + if (RB_BLACK_P(uncle)) + break; - if (RB_RED_P(uncle)) { + RBSTAT_INC(rbt->rbt_insertion_rebalance_passes); + /* + * Case 1: our uncle is red + * Simply invert the colors of our parent and + * uncle and make our grandparent red. And + * then solve the problem up at his level. + */ + RB_MARK_BLACK(uncle); + RB_MARK_BLACK(father); + if (__predict_false(RB_ROOT_P(rbt, grandpa))) { /* - * Case 1: our uncle is red - * Simply invert the colors of our parent and - * uncle and make our grandparent red. And - * then solve the problem up at his level. + * If our grandpa is root, don't bother + * setting him to red, just return. */ - RB_MARK_BLACK(uncle); - RB_MARK_BLACK(father); - RB_MARK_RED(grandpa); - self = grandpa; - continue; + KASSERT(RB_BLACK_P(grandpa)); + return; } - /* - * Case 2&3: our uncle is black. - */ - if (self == father->rb_nodes[other]) { + RB_MARK_RED(grandpa); + self = grandpa; + father = RB_FATHER(self); + KASSERT(RB_RED_P(self)); + if (RB_BLACK_P(father)) { /* - * Case 2: we are on the same side as our uncle - * Swap ourselves with our parent so this case - * becomes case 3. Basically our parent becomes our - * child. + * If our greatgrandpa is black, we're done. */ - rb_tree_reparent_nodes(rbt, father, other); - KASSERT(father->rb_parent == self); - KASSERT(self->rb_nodes[which] == father); - KASSERT(self->rb_parent == grandpa); - self = father; - father = self->rb_parent; + KASSERT(RB_BLACK_P(rbt->rbt_root)); + return; } - KASSERT(RB_RED_P(self) && RB_RED_P(father)); - KASSERT(grandpa->rb_nodes[which] == father); + } + + KASSERT(!RB_ROOT_P(rbt, self)); + KASSERT(RB_RED_P(self)); + KASSERT(RB_RED_P(father)); + KASSERT(RB_BLACK_P(uncle)); + KASSERT(RB_BLACK_P(grandpa)); + /* + * Case 2&3: our uncle is black. + */ + if (self == father->rb_nodes[other]) { /* - * Case 3: we are opposite a child of a black uncle. - * Swap our parent and grandparent. Since our grandfather - * is black, our father will become black and our new sibling - * (former grandparent) will become red. + * Case 2: we are on the same side as our uncle + * Swap ourselves with our parent so this case + * becomes case 3. Basically our parent becomes our + * child. */ - rb_tree_reparent_nodes(rbt, grandpa, which); - KASSERT(self->rb_parent == father); - KASSERT(self->rb_parent->rb_nodes[self->rb_position ^ RB_NODE_OTHER] == grandpa); - KASSERT(RB_RED_P(self)); - KASSERT(RB_BLACK_P(father)); - KASSERT(RB_RED_P(grandpa)); - break; + rb_tree_reparent_nodes(rbt, father, other); + KASSERT(RB_FATHER(father) == self); + KASSERT(self->rb_nodes[which] == father); + KASSERT(RB_FATHER(self) == grandpa); + self = father; + father = RB_FATHER(self); } + KASSERT(RB_RED_P(self) && RB_RED_P(father)); + KASSERT(grandpa->rb_nodes[which] == father); + /* + * Case 3: we are opposite a child of a black uncle. + * Swap our parent and grandparent. Since our grandfather + * is black, our father will become black and our new sibling + * (former grandparent) will become red. + */ + rb_tree_reparent_nodes(rbt, grandpa, which); + KASSERT(RB_FATHER(self) == father); + KASSERT(RB_FATHER(self)->rb_nodes[RB_POSITION(self) ^ RB_DIR_OTHER] == grandpa); + KASSERT(RB_RED_P(self)); + KASSERT(RB_BLACK_P(father)); + KASSERT(RB_RED_P(grandpa)); /* * Final step: Set the root to black. */ RB_MARK_BLACK(rbt->rbt_root); } - -struct rb_node * -_prop_rb_tree_find(struct rb_tree *rbt, const void *key) -{ - struct rb_node *parent = rbt->rbt_root; - rb_compare_key_fn compare_key = rbt->rbt_ops->rbto_compare_key; - while (!RB_SENTINEL_P(parent)) { - const int diff = (*compare_key)(parent, key); - if (diff == 0) - return parent; - parent = parent->rb_nodes[diff > 0]; - } - - return NULL; -} - static void -rb_tree_prune_node(struct rb_tree *rbt, struct rb_node *self, int rebalance) +rb_tree_prune_node(struct rb_tree *rbt, struct rb_node *self, bool rebalance) { - const unsigned int which = self->rb_position; - struct rb_node *father = self->rb_parent; + const unsigned int which = RB_POSITION(self); + struct rb_node *father = RB_FATHER(self); +#ifndef RBSMALL + const bool was_root = RB_ROOT_P(rbt, self); +#endif - KASSERT(rebalance || (RB_ROOT_P(self) || RB_RED_P(self))); + KASSERT(rebalance || (RB_ROOT_P(rbt, self) || RB_RED_P(self))); KASSERT(!rebalance || RB_BLACK_P(self)); KASSERT(RB_CHILDLESS_P(self)); KASSERT(rb_tree_check_node(rbt, self, NULL, false)); + /* + * Since we are childless, we know that self->rb_left is pointing + * to the sentinel node. + */ father->rb_nodes[which] = self->rb_left; /* - * Remove ourselves from the node list and decrement the count. + * Remove ourselves from the node list, decrement the count, + * and update min/max. */ RB_TAILQ_REMOVE(&rbt->rbt_nodes, self, rb_link); - RBT_COUNT_DECR(rbt); + RBSTAT_DEC(rbt->rbt_count); +#ifndef RBSMALL + if (__predict_false(rbt->rbt_minmax[RB_POSITION(self)] == self)) { + rbt->rbt_minmax[RB_POSITION(self)] = father; + /* + * When removing the root, rbt->rbt_minmax[RB_DIR_LEFT] is + * updated automatically, but we also need to update + * rbt->rbt_minmax[RB_DIR_RIGHT]; + */ + if (__predict_false(was_root)) { + rbt->rbt_minmax[RB_DIR_RIGHT] = father; + } + } + RB_SET_FATHER(self, NULL); +#endif + /* + * Rebalance if requested. + */ if (rebalance) rb_tree_removal_rebalance(rbt, father, which); - KASSERT(RB_ROOT_P(self) || rb_tree_check_node(rbt, father, NULL, true)); + KASSERT(was_root || rb_tree_check_node(rbt, father, NULL, true)); } +/* + * When deleting an interior node + */ static void rb_tree_swap_prune_and_rebalance(struct rb_tree *rbt, struct rb_node *self, struct rb_node *standin) { - unsigned int standin_which = standin->rb_position; - unsigned int standin_other = standin_which ^ RB_NODE_OTHER; - struct rb_node *standin_child; - struct rb_node *standin_father; + const unsigned int standin_which = RB_POSITION(standin); + unsigned int standin_other = standin_which ^ RB_DIR_OTHER; + struct rb_node *standin_son; + struct rb_node *standin_father = RB_FATHER(standin); bool rebalance = RB_BLACK_P(standin); - if (standin->rb_parent == self) { + if (standin_father == self) { /* * As a child of self, any childen would be opposite of - * our parent (self). + * our parent. */ KASSERT(RB_SENTINEL_P(standin->rb_nodes[standin_other])); - standin_child = standin->rb_nodes[standin_which]; + standin_son = standin->rb_nodes[standin_which]; } else { /* * Since we aren't a child of self, any childen would be - * on the same side as our parent (self). + * on the same side as our parent. */ KASSERT(RB_SENTINEL_P(standin->rb_nodes[standin_which])); - standin_child = standin->rb_nodes[standin_other]; + standin_son = standin->rb_nodes[standin_other]; } /* @@ -427,7 +506,7 @@ rb_tree_swap_prune_and_rebalance(struct rb_tree *rbt, struct rb_node *self, /* * If standin has a child, it must be red. */ - KASSERT(RB_SENTINEL_P(standin_child) || RB_RED_P(standin_child)); + KASSERT(RB_SENTINEL_P(standin_son) || RB_RED_P(standin_son)); /* * Verify things are sane. @@ -435,83 +514,103 @@ rb_tree_swap_prune_and_rebalance(struct rb_tree *rbt, struct rb_node *self, KASSERT(rb_tree_check_node(rbt, self, NULL, false)); KASSERT(rb_tree_check_node(rbt, standin, NULL, false)); - if (!RB_SENTINEL_P(standin_child)) { - /* - * We know we have a red child so if we swap them we can - * void flipping standin's child to black afterwards. - */ - KASSERT(rb_tree_check_node(rbt, standin_child, NULL, true)); - rb_tree_reparent_nodes(rbt, standin, - standin_child->rb_position); - KASSERT(rb_tree_check_node(rbt, standin, NULL, true)); - KASSERT(rb_tree_check_node(rbt, standin_child, NULL, true)); + if (__predict_false(RB_RED_P(standin_son))) { /* - * Since we are removing a red leaf, no need to rebalance. + * We know we have a red child so if we flip it to black + * we don't have to rebalance. */ + KASSERT(rb_tree_check_node(rbt, standin_son, NULL, true)); + RB_MARK_BLACK(standin_son); rebalance = false; - /* - * We know that standin can not be a child of self, so - * update before of that. - */ - KASSERT(standin->rb_parent != self); - standin_which = standin->rb_position; - standin_other = standin_which ^ RB_NODE_OTHER; + + if (standin_father == self) { + KASSERT(RB_POSITION(standin_son) == standin_which); + } else { + KASSERT(RB_POSITION(standin_son) == standin_other); + /* + * Change the son's parentage to point to his grandpa. + */ + RB_SET_FATHER(standin_son, standin_father); + RB_SET_POSITION(standin_son, standin_which); + } } - KASSERT(RB_CHILDLESS_P(standin)); - /* - * If we are about to delete the standin's father, then when we call - * rebalance, we need to use ourselves as our father. Otherwise - * remember our original father. Also, if we are our standin's father - * we only need to reparent the standin's brother. - */ - if (standin->rb_parent == self) { + if (standin_father == self) { /* - * | R --> S | - * | Q S --> Q * | - * | --> | + * If we are about to delete the standin's father, then when + * we call rebalance, we need to use ourselves as our father. + * Otherwise remember our original father. Also, sincef we are + * our standin's father we only need to reparent the standin's + * brother. + * + * | R --> S | + * | Q S --> Q T | + * | t --> | */ - standin_father = standin; KASSERT(RB_SENTINEL_P(standin->rb_nodes[standin_other])); KASSERT(!RB_SENTINEL_P(self->rb_nodes[standin_other])); KASSERT(self->rb_nodes[standin_which] == standin); /* - * Make our brother our son. + * Have our son/standin adopt his brother as his new son. */ - standin->rb_nodes[standin_other] = self->rb_nodes[standin_other]; - standin->rb_nodes[standin_other]->rb_parent = standin; - KASSERT(standin->rb_nodes[standin_other]->rb_position == standin_other); + standin_father = standin; } else { /* - * | P --> P | - * | S --> Q | - * | Q --> | + * | R --> S . | + * | / \ | T --> / \ | / | + * | ..... | S --> ..... | T | + * + * Sever standin's connection to his father. + */ + standin_father->rb_nodes[standin_which] = standin_son; + /* + * Adopt the far son. + */ + standin->rb_nodes[standin_other] = self->rb_nodes[standin_other]; + RB_SET_FATHER(standin->rb_nodes[standin_other], standin); + KASSERT(RB_POSITION(self->rb_nodes[standin_other]) == standin_other); + /* + * Use standin_other because we need to preserve standin_which + * for the removal_rebalance. */ - standin_father = standin->rb_parent; - standin_father->rb_nodes[standin_which] = - standin->rb_nodes[standin_which]; - standin->rb_left = self->rb_left; - standin->rb_right = self->rb_right; - standin->rb_left->rb_parent = standin; - standin->rb_right->rb_parent = standin; + standin_other = standin_which; } + /* + * Move the only remaining son to our standin. If our standin is our + * son, this will be the only son needed to be moved. + */ + KASSERT(standin->rb_nodes[standin_other] != self->rb_nodes[standin_other]); + standin->rb_nodes[standin_other] = self->rb_nodes[standin_other]; + RB_SET_FATHER(standin->rb_nodes[standin_other], standin); + /* * Now copy the result of self to standin and then replace * self with standin in the tree. */ - standin->rb_parent = self->rb_parent; - standin->rb_properties = self->rb_properties; - standin->rb_parent->rb_nodes[standin->rb_position] = standin; + RB_COPY_PROPERTIES(standin, self); + RB_SET_FATHER(standin, RB_FATHER(self)); + RB_FATHER(standin)->rb_nodes[RB_POSITION(standin)] = standin; /* - * Remove ourselves from the node list and decrement the count. + * Remove ourselves from the node list, decrement the count, + * and update min/max. */ RB_TAILQ_REMOVE(&rbt->rbt_nodes, self, rb_link); - RBT_COUNT_DECR(rbt); + RBSTAT_DEC(rbt->rbt_count); +#ifndef RBSMALL + if (__predict_false(rbt->rbt_minmax[RB_POSITION(self)] == self)) + rbt->rbt_minmax[RB_POSITION(self)] = RB_FATHER(self); + RB_SET_FATHER(self, NULL); +#endif KASSERT(rb_tree_check_node(rbt, standin, NULL, false)); - KASSERT(rb_tree_check_node(rbt, standin_father, NULL, false)); + KASSERT(RB_FATHER_SENTINEL_P(standin) + || rb_tree_check_node(rbt, standin_father, NULL, false)); + KASSERT(RB_LEFT_SENTINEL_P(standin) + || rb_tree_check_node(rbt, standin->rb_left, NULL, false)); + KASSERT(RB_RIGHT_SENTINEL_P(standin) + || rb_tree_check_node(rbt, standin->rb_right, NULL, false)); if (!rebalance) return; @@ -527,46 +626,61 @@ rb_tree_swap_prune_and_rebalance(struct rb_tree *rbt, struct rb_node *self, * * But it's more efficient to just evalate and recolor the child. */ -/*ARGSUSED*/ static void -rb_tree_prune_blackred_branch(struct rb_tree *rbt _PROP_ARG_UNUSED, - struct rb_node *self, unsigned int which) +rb_tree_prune_blackred_branch(struct rb_tree *rbt, struct rb_node *self, + unsigned int which) { - struct rb_node *parent = self->rb_parent; - struct rb_node *child = self->rb_nodes[which]; + struct rb_node *father = RB_FATHER(self); + struct rb_node *son = self->rb_nodes[which]; +#ifndef RBSMALL + const bool was_root = RB_ROOT_P(rbt, self); +#endif - KASSERT(which == RB_NODE_LEFT || which == RB_NODE_RIGHT); - KASSERT(RB_BLACK_P(self) && RB_RED_P(child)); - KASSERT(!RB_TWOCHILDREN_P(child)); - KASSERT(RB_CHILDLESS_P(child)); + KASSERT(which == RB_DIR_LEFT || which == RB_DIR_RIGHT); + KASSERT(RB_BLACK_P(self) && RB_RED_P(son)); + KASSERT(!RB_TWOCHILDREN_P(son)); + KASSERT(RB_CHILDLESS_P(son)); KASSERT(rb_tree_check_node(rbt, self, NULL, false)); - KASSERT(rb_tree_check_node(rbt, child, NULL, false)); + KASSERT(rb_tree_check_node(rbt, son, NULL, false)); /* * Remove ourselves from the tree and give our former child our * properties (position, color, root). */ - parent->rb_nodes[self->rb_position] = child; - child->rb_parent = parent; - child->rb_properties = self->rb_properties; + RB_COPY_PROPERTIES(son, self); + father->rb_nodes[RB_POSITION(son)] = son; + RB_SET_FATHER(son, father); /* - * Remove ourselves from the node list and decrement the count. + * Remove ourselves from the node list, decrement the count, + * and update minmax. */ RB_TAILQ_REMOVE(&rbt->rbt_nodes, self, rb_link); - RBT_COUNT_DECR(rbt); + RBSTAT_DEC(rbt->rbt_count); +#ifndef RBSMALL + if (__predict_false(was_root)) { + KASSERT(rbt->rbt_minmax[which] == son); + rbt->rbt_minmax[which ^ RB_DIR_OTHER] = son; + } else if (rbt->rbt_minmax[RB_POSITION(self)] == self) { + rbt->rbt_minmax[RB_POSITION(self)] = son; + } + RB_SET_FATHER(self, NULL); +#endif - KASSERT(RB_ROOT_P(self) || rb_tree_check_node(rbt, parent, NULL, true)); - KASSERT(rb_tree_check_node(rbt, child, NULL, true)); + KASSERT(was_root || rb_tree_check_node(rbt, father, NULL, true)); + KASSERT(rb_tree_check_node(rbt, son, NULL, true)); } -/* - * - */ + void -_prop_rb_tree_remove_node(struct rb_tree *rbt, struct rb_node *self) +_prop_rb_tree_remove_node(struct rb_tree *rbt, void *object) { - struct rb_node *standin; + const rb_tree_ops_t *rbto = rbt->rbt_ops; + struct rb_node *standin, *self = RB_ITEMTONODE(rbto, object); unsigned int which; + + KASSERT(!RB_SENTINEL_P(self)); + RBSTAT_INC(rbt->rbt_removals); + /* * In the following diagrams, we (the node to be removed) are S. Red * nodes are lowercase. T could be either red or black. @@ -585,11 +699,8 @@ _prop_rb_tree_remove_node(struct rb_tree *rbt, struct rb_node *self) * | s --> * | */ if (RB_CHILDLESS_P(self)) { - if (RB_RED_P(self) || RB_ROOT_P(self)) { - rb_tree_prune_node(rbt, self, false); - return; - } - rb_tree_prune_node(rbt, self, true); + const bool rebalance = RB_BLACK_P(self) && !RB_ROOT_P(rbt, self); + rb_tree_prune_node(rbt, self, rebalance); return; } KASSERT(!RB_CHILDLESS_P(self)); @@ -602,7 +713,7 @@ _prop_rb_tree_remove_node(struct rb_tree *rbt, struct rb_node *self) * | S --> R --> R | * | r --> s --> * | */ - which = RB_LEFT_SENTINEL_P(self) ? RB_NODE_RIGHT : RB_NODE_LEFT; + which = RB_LEFT_SENTINEL_P(self) ? RB_DIR_RIGHT : RB_DIR_LEFT; KASSERT(RB_BLACK_P(self)); KASSERT(RB_RED_P(self->rb_nodes[which])); KASSERT(RB_CHILDLESS_P(self->rb_nodes[which])); @@ -615,13 +726,13 @@ _prop_rb_tree_remove_node(struct rb_tree *rbt, struct rb_node *self) * We invert these because we prefer to remove from the inside of * the tree. */ - which = self->rb_position ^ RB_NODE_OTHER; + which = RB_POSITION(self) ^ RB_DIR_OTHER; /* * Let's find the node closes to us opposite of our parent * Now swap it with ourself, "prune" it, and rebalance, if needed. */ - standin = _prop_rb_tree_iterate(rbt, self, which); + standin = RB_ITEMTONODE(rbto,_prop_rb_tree_iterate(rbt, object, which)); rb_tree_swap_prune_and_rebalance(rbt, self, standin); } @@ -631,12 +742,15 @@ rb_tree_removal_rebalance(struct rb_tree *rbt, struct rb_node *parent, { KASSERT(!RB_SENTINEL_P(parent)); KASSERT(RB_SENTINEL_P(parent->rb_nodes[which])); - KASSERT(which == RB_NODE_LEFT || which == RB_NODE_RIGHT); + KASSERT(which == RB_DIR_LEFT || which == RB_DIR_RIGHT); + RBSTAT_INC(rbt->rbt_removal_rebalance_calls); while (RB_BLACK_P(parent->rb_nodes[which])) { - unsigned int other = which ^ RB_NODE_OTHER; + unsigned int other = which ^ RB_DIR_OTHER; struct rb_node *brother = parent->rb_nodes[other]; + RBSTAT_INC(rbt->rbt_removal_rebalance_passes); + KASSERT(!RB_SENTINEL_P(brother)); /* * For cases 1, 2a, and 2b, our brother's children must @@ -645,21 +759,24 @@ rb_tree_removal_rebalance(struct rb_tree *rbt, struct rb_node *parent, if (RB_BLACK_P(parent) && RB_BLACK_P(brother->rb_left) && RB_BLACK_P(brother->rb_right)) { - /* - * Case 1: Our brother is red, swap its position - * (and colors) with our parent. This is now case 2b. - * - * B -> D - * x d -> b E - * C E -> x C - */ if (RB_RED_P(brother)) { + /* + * Case 1: Our brother is red, swap its + * position (and colors) with our parent. + * This should now be case 2b (unless C or E + * has a red child which is case 3; thus no + * explicit branch to case 2b). + * + * B -> D + * A d -> b E + * C E -> A C + */ KASSERT(RB_BLACK_P(parent)); rb_tree_reparent_nodes(rbt, parent, other); brother = parent->rb_nodes[other]; KASSERT(!RB_SENTINEL_P(brother)); - KASSERT(RB_BLACK_P(brother)); KASSERT(RB_RED_P(parent)); + KASSERT(RB_BLACK_P(brother)); KASSERT(rb_tree_check_node(rbt, brother, NULL, false)); KASSERT(rb_tree_check_node(rbt, parent, NULL, false)); } else { @@ -668,63 +785,100 @@ rb_tree_removal_rebalance(struct rb_tree *rbt, struct rb_node *parent, * Change our brother to red, advance up rank * and go through the loop again. * - * B -> B - * A D -> A d + * B -> *B + * *A D -> A d * C E -> C E */ RB_MARK_RED(brother); KASSERT(RB_BLACK_P(brother->rb_left)); KASSERT(RB_BLACK_P(brother->rb_right)); - if (RB_ROOT_P(parent)) - return; + if (RB_ROOT_P(rbt, parent)) + return; /* root == parent == black */ KASSERT(rb_tree_check_node(rbt, brother, NULL, false)); KASSERT(rb_tree_check_node(rbt, parent, NULL, false)); - which = parent->rb_position; - parent = parent->rb_parent; + which = RB_POSITION(parent); + parent = RB_FATHER(parent); + continue; } - } else if (RB_RED_P(parent) + } + /* + * Avoid an else here so that case 2a above can hit either + * case 2b, 3, or 4. + */ + if (RB_RED_P(parent) && RB_BLACK_P(brother) && RB_BLACK_P(brother->rb_left) && RB_BLACK_P(brother->rb_right)) { + KASSERT(RB_RED_P(parent)); KASSERT(RB_BLACK_P(brother)); KASSERT(RB_BLACK_P(brother->rb_left)); KASSERT(RB_BLACK_P(brother->rb_right)); + /* + * We are black, our father is red, our brother and + * both nephews are black. Simply invert/exchange the + * colors of our father and brother (to black and red + * respectively). + * + * | f --> F | + * | * B --> * b | + * | N N --> N N | + */ RB_MARK_BLACK(parent); RB_MARK_RED(brother); KASSERT(rb_tree_check_node(rbt, brother, NULL, true)); break; /* We're done! */ } else { - KASSERT(RB_BLACK_P(brother)); - KASSERT(!RB_CHILDLESS_P(brother)); /* - * Case 3: our brother is black, our left nephew is - * red, and our right nephew is black. Swap our - * brother with our left nephew. This result in a - * tree that matches case 4. - * - * B -> D - * A D -> B E - * c e -> A C + * Our brother must be black and have at least one + * red child (it may have two). */ + KASSERT(RB_BLACK_P(brother)); + KASSERT(RB_RED_P(brother->rb_nodes[which]) || + RB_RED_P(brother->rb_nodes[other])); if (RB_BLACK_P(brother->rb_nodes[other])) { + /* + * Case 3: our brother is black, our near + * nephew is red, and our far nephew is black. + * Swap our brother with our near nephew. + * This result in a tree that matches case 4. + * (Our father could be red or black). + * + * | F --> F | + * | x B --> x B | + * | n --> n | + */ KASSERT(RB_RED_P(brother->rb_nodes[which])); rb_tree_reparent_nodes(rbt, brother, which); - KASSERT(brother->rb_parent == parent->rb_nodes[other]); + KASSERT(RB_FATHER(brother) == parent->rb_nodes[other]); brother = parent->rb_nodes[other]; KASSERT(RB_RED_P(brother->rb_nodes[other])); } /* - * Case 4: our brother is black and our right nephew - * is red. Swap our parent and brother locations and - * change our right nephew to black. (these can be + * Case 4: our brother is black and our far nephew + * is red. Swap our father and brother locations and + * change our far nephew to black. (these can be * done in either order so we change the color first). * The result is a valid red-black tree and is a - * terminal case. + * terminal case. (again we don't care about the + * father's color) * - * B -> D - * A D -> B E - * c e -> A C + * If the father is red, we will get a red-black-black + * tree: + * | f -> f --> b | + * | B -> B --> F N | + * | n -> N --> | + * + * If the father is black, we will get an all black + * tree: + * | F -> F --> B | + * | B -> B --> F N | + * | n -> N --> | + * + * If we had two red nephews, then after the swap, + * our former father would have a red grandson. */ + KASSERT(RB_BLACK_P(brother)); + KASSERT(RB_RED_P(brother->rb_nodes[other])); RB_MARK_BLACK(brother->rb_nodes[other]); rb_tree_reparent_nodes(rbt, parent, other); break; /* We're done! */ @@ -733,31 +887,41 @@ rb_tree_removal_rebalance(struct rb_tree *rbt, struct rb_node *parent, KASSERT(rb_tree_check_node(rbt, parent, NULL, true)); } -struct rb_node * -_prop_rb_tree_iterate(struct rb_tree *rbt, struct rb_node *self, - unsigned int direction) +void * +_prop_rb_tree_iterate(struct rb_tree *rbt, void *object, + const unsigned int direction) { - const unsigned int other = direction ^ RB_NODE_OTHER; - KASSERT(direction == RB_NODE_LEFT || direction == RB_NODE_RIGHT); + const rb_tree_ops_t *rbto = rbt->rbt_ops; + const unsigned int other = direction ^ RB_DIR_OTHER; + struct rb_node *self; - if (self == NULL) { + KASSERT(direction == RB_DIR_LEFT || direction == RB_DIR_RIGHT); + + if (object == NULL) { +#ifndef RBSMALL + if (RB_SENTINEL_P(rbt->rbt_root)) + return NULL; + return RB_NODETOITEM(rbto, rbt->rbt_minmax[direction]); +#else self = rbt->rbt_root; if (RB_SENTINEL_P(self)) return NULL; - while (!RB_SENTINEL_P(self->rb_nodes[other])) - self = self->rb_nodes[other]; - return self; + while (!RB_SENTINEL_P(self->rb_nodes[direction])) + self = self->rb_nodes[direction]; + return RB_NODETOITEM(rbto, self); +#endif /* !RBSMALL */ } + self = RB_ITEMTONODE(rbto, object); KASSERT(!RB_SENTINEL_P(self)); /* * We can't go any further in this direction. We proceed up in the * opposite direction until our parent is in direction we want to go. */ if (RB_SENTINEL_P(self->rb_nodes[direction])) { - while (!RB_ROOT_P(self)) { - if (other == self->rb_position) - return self->rb_parent; - self = self->rb_parent; + while (!RB_ROOT_P(rbt, self)) { + if (other == RB_POSITION(self)) + return RB_NODETOITEM(rbto, RB_FATHER(self)); + self = RB_FATHER(self); } return NULL; } @@ -770,24 +934,30 @@ _prop_rb_tree_iterate(struct rb_tree *rbt, struct rb_node *self, KASSERT(!RB_SENTINEL_P(self)); while (!RB_SENTINEL_P(self->rb_nodes[other])) self = self->rb_nodes[other]; - return self; + return RB_NODETOITEM(rbto, self); } #ifdef RBDEBUG static const struct rb_node * rb_tree_iterate_const(const struct rb_tree *rbt, const struct rb_node *self, - unsigned int direction) + const unsigned int direction) { - const unsigned int other = direction ^ RB_NODE_OTHER; - KASSERT(direction == RB_NODE_LEFT || direction == RB_NODE_RIGHT); + const unsigned int other = direction ^ RB_DIR_OTHER; + KASSERT(direction == RB_DIR_LEFT || direction == RB_DIR_RIGHT); if (self == NULL) { +#ifndef RBSMALL + if (RB_SENTINEL_P(rbt->rbt_root)) + return NULL; + return rbt->rbt_minmax[direction]; +#else self = rbt->rbt_root; if (RB_SENTINEL_P(self)) return NULL; - while (!RB_SENTINEL_P(self->rb_nodes[other])) - self = self->rb_nodes[other]; + while (!RB_SENTINEL_P(self->rb_nodes[direction])) + self = self->rb_nodes[direction]; return self; +#endif /* !RBSMALL */ } KASSERT(!RB_SENTINEL_P(self)); /* @@ -795,10 +965,10 @@ rb_tree_iterate_const(const struct rb_tree *rbt, const struct rb_node *self, * opposite direction until our parent is in direction we want to go. */ if (RB_SENTINEL_P(self->rb_nodes[direction])) { - while (!RB_ROOT_P(self)) { - if (other == self->rb_position) - return self->rb_parent; - self = self->rb_parent; + while (!RB_ROOT_P(rbt, self)) { + if (other == RB_POSITION(self)) + return RB_FATHER(self); + self = RB_FATHER(self); } return NULL; } @@ -814,33 +984,54 @@ rb_tree_iterate_const(const struct rb_tree *rbt, const struct rb_node *self, return self; } +static unsigned int +rb_tree_count_black(const struct rb_node *self) +{ + unsigned int left, right; + + if (RB_SENTINEL_P(self)) + return 0; + + left = rb_tree_count_black(self->rb_left); + right = rb_tree_count_black(self->rb_right); + + KASSERT(left == right); + + return left + RB_BLACK_P(self); +} + static bool rb_tree_check_node(const struct rb_tree *rbt, const struct rb_node *self, const struct rb_node *prev, bool red_check) { - KASSERT(!self->rb_sentinel); - KASSERT(self->rb_left); - KASSERT(self->rb_right); - KASSERT(prev == NULL || - (*rbt->rbt_ops->rbto_compare_nodes)(prev, self) > 0); + const rb_tree_ops_t *rbto = rbt->rbt_ops; + rbto_compare_nodes_fn compare_nodes = rbto->rbto_compare_nodes; + + KASSERT(!RB_SENTINEL_P(self)); + KASSERT(prev == NULL || (*compare_nodes)(rbto->rbto_context, + RB_NODETOITEM(rbto, prev), RB_NODETOITEM(rbto, self)) < 0); /* * Verify our relationship to our parent. */ - if (RB_ROOT_P(self)) { + if (RB_ROOT_P(rbt, self)) { KASSERT(self == rbt->rbt_root); - KASSERT(self->rb_position == RB_NODE_LEFT); - KASSERT(self->rb_parent->rb_nodes[RB_NODE_LEFT] == self); - KASSERT(self->rb_parent == (const struct rb_node *) &rbt->rbt_root); + KASSERT(RB_POSITION(self) == RB_DIR_LEFT); + KASSERT(RB_FATHER(self)->rb_nodes[RB_DIR_LEFT] == self); + KASSERT(RB_FATHER(self) == (const struct rb_node *) &rbt->rbt_root); } else { + int diff = (*compare_nodes)(rbto->rbto_context, + RB_NODETOITEM(rbto, self), + RB_NODETOITEM(rbto, RB_FATHER(self))); + KASSERT(self != rbt->rbt_root); - KASSERT(!RB_PARENT_SENTINEL_P(self)); - if (self->rb_position == RB_NODE_LEFT) { - KASSERT((*rbt->rbt_ops->rbto_compare_nodes)(self, self->rb_parent) > 0); - KASSERT(self->rb_parent->rb_nodes[RB_NODE_LEFT] == self); + KASSERT(!RB_FATHER_SENTINEL_P(self)); + if (RB_POSITION(self) == RB_DIR_LEFT) { + KASSERT(diff < 0); + KASSERT(RB_FATHER(self)->rb_nodes[RB_DIR_LEFT] == self); } else { - KASSERT((*rbt->rbt_ops->rbto_compare_nodes)(self, self->rb_parent) < 0); - KASSERT(self->rb_parent->rb_nodes[RB_NODE_RIGHT] == self); + KASSERT(diff > 0); + KASSERT(RB_FATHER(self)->rb_nodes[RB_DIR_RIGHT] == self); } } @@ -848,12 +1039,14 @@ rb_tree_check_node(const struct rb_tree *rbt, const struct rb_node *self, * Verify our position in the linked list against the tree itself. */ { - const struct rb_node *prev0 = rb_tree_iterate_const(rbt, self, RB_NODE_LEFT); - const struct rb_node *next0 = rb_tree_iterate_const(rbt, self, RB_NODE_RIGHT); + const struct rb_node *prev0 = rb_tree_iterate_const(rbt, self, RB_DIR_LEFT); + const struct rb_node *next0 = rb_tree_iterate_const(rbt, self, RB_DIR_RIGHT); KASSERT(prev0 == TAILQ_PREV(self, rb_node_qh, rb_link)); - if (next0 != TAILQ_NEXT(self, rb_link)) - next0 = rb_tree_iterate_const(rbt, self, RB_NODE_RIGHT); KASSERT(next0 == TAILQ_NEXT(self, rb_link)); +#ifndef RBSMALL + KASSERT(prev0 != NULL || self == rbt->rbt_minmax[RB_DIR_LEFT]); + KASSERT(next0 != NULL || self == rbt->rbt_minmax[RB_DIR_RIGHT]); +#endif } /* @@ -861,12 +1054,13 @@ rb_tree_check_node(const struct rb_tree *rbt, const struct rb_node *self, * There can never be two adjacent red nodes. */ if (red_check) { - KASSERT(!RB_ROOT_P(self) || RB_BLACK_P(self)); + KASSERT(!RB_ROOT_P(rbt, self) || RB_BLACK_P(self)); + (void) rb_tree_count_black(self); if (RB_RED_P(self)) { const struct rb_node *brother; - KASSERT(!RB_ROOT_P(self)); - brother = self->rb_parent->rb_nodes[self->rb_position ^ RB_NODE_OTHER]; - KASSERT(RB_BLACK_P(self->rb_parent)); + KASSERT(!RB_ROOT_P(rbt, self)); + brother = RB_FATHER(self)->rb_nodes[RB_POSITION(self) ^ RB_DIR_OTHER]; + KASSERT(RB_BLACK_P(RB_FATHER(self))); /* * I'm red and have no children, then I must either * have no brother or my brother also be red and @@ -915,11 +1109,11 @@ rb_tree_check_node(const struct rb_tree *rbt, const struct rb_node *self, * black, my 2nd closet relative away from my parent * is either red or has a red parent or red children. */ - if (!RB_ROOT_P(self) + if (!RB_ROOT_P(rbt, self) && RB_CHILDLESS_P(self) - && RB_BLACK_P(self->rb_parent)) { - const unsigned int which = self->rb_position; - const unsigned int other = which ^ RB_NODE_OTHER; + && RB_BLACK_P(RB_FATHER(self))) { + const unsigned int which = RB_POSITION(self); + const unsigned int other = which ^ RB_DIR_OTHER; const struct rb_node *relative0, *relative; relative0 = rb_tree_iterate_const(rbt, @@ -933,7 +1127,7 @@ rb_tree_check_node(const struct rb_tree *rbt, const struct rb_node *self, KASSERT(RB_RED_P(relative) || RB_RED_P(relative->rb_left) || RB_RED_P(relative->rb_right) - || RB_RED_P(relative->rb_parent)); + || RB_RED_P(RB_FATHER(relative))); #endif } } @@ -941,9 +1135,9 @@ rb_tree_check_node(const struct rb_tree *rbt, const struct rb_node *self, * A grandparent's children must be real nodes and not * sentinels. First check out grandparent. */ - KASSERT(RB_ROOT_P(self) - || RB_ROOT_P(self->rb_parent) - || RB_TWOCHILDREN_P(self->rb_parent->rb_parent)); + KASSERT(RB_ROOT_P(rbt, self) + || RB_ROOT_P(rbt, RB_FATHER(self)) + || RB_TWOCHILDREN_P(RB_FATHER(RB_FATHER(self)))); /* * If we are have grandchildren on our left, then * we must have a child on our right. @@ -995,11 +1189,11 @@ rb_tree_check_node(const struct rb_tree *rbt, const struct rb_node *self, const struct rb_node *prev0; const struct rb_node *next0; - prev0 = rb_tree_iterate_const(rbt, self, RB_NODE_LEFT); + prev0 = rb_tree_iterate_const(rbt, self, RB_DIR_LEFT); KASSERT(prev0 != NULL); KASSERT(RB_RIGHT_SENTINEL_P(prev0)); - next0 = rb_tree_iterate_const(rbt, self, RB_NODE_RIGHT); + next0 = rb_tree_iterate_const(rbt, self, RB_DIR_RIGHT); KASSERT(next0 != NULL); KASSERT(RB_LEFT_SENTINEL_P(next0)); } @@ -1008,50 +1202,74 @@ rb_tree_check_node(const struct rb_tree *rbt, const struct rb_node *self, return true; } -static unsigned int -rb_tree_count_black(const struct rb_node *self) -{ - unsigned int left, right; - - if (RB_SENTINEL_P(self)) - return 0; - - left = rb_tree_count_black(self->rb_left); - right = rb_tree_count_black(self->rb_right); - - KASSERT(left == right); - - return left + RB_BLACK_P(self); -} - void _prop_rb_tree_check(const struct rb_tree *rbt, bool red_check) { const struct rb_node *self; const struct rb_node *prev; - unsigned int count; +#ifdef RBSTATS + unsigned int count = 0; +#endif + + KASSERT(rbt->rbt_root != NULL); + KASSERT(RB_LEFT_P(rbt->rbt_root)); - KASSERT(rbt->rbt_root == NULL || rbt->rbt_root->rb_position == RB_NODE_LEFT); +#if defined(RBSTATS) && !defined(RBSMALL) + KASSERT(rbt->rbt_count > 1 + || rbt->rbt_minmax[RB_DIR_LEFT] == rbt->rbt_minmax[RB_DIR_RIGHT]); +#endif prev = NULL; - count = 0; TAILQ_FOREACH(self, &rbt->rbt_nodes, rb_link) { rb_tree_check_node(rbt, self, prev, false); +#ifdef RBSTATS count++; +#endif } +#ifdef RBSTATS KASSERT(rbt->rbt_count == count); - KASSERT(RB_SENTINEL_P(rbt->rbt_root) - || rb_tree_count_black(rbt->rbt_root)); - - /* - * The root must be black. - * There can never be two adjacent red nodes. - */ +#endif if (red_check) { - KASSERT(rbt->rbt_root == NULL || RB_BLACK_P(rbt->rbt_root)); + KASSERT(RB_BLACK_P(rbt->rbt_root)); + KASSERT(RB_SENTINEL_P(rbt->rbt_root) + || rb_tree_count_black(rbt->rbt_root)); + + /* + * The root must be black. + * There can never be two adjacent red nodes. + */ TAILQ_FOREACH(self, &rbt->rbt_nodes, rb_link) { rb_tree_check_node(rbt, self, NULL, true); } } } #endif /* RBDEBUG */ + +#ifdef RBSTATS +static void +rb_tree_mark_depth(const struct rb_tree *rbt, const struct rb_node *self, + size_t *depths, size_t depth) +{ + if (RB_SENTINEL_P(self)) + return; + + if (RB_TWOCHILDREN_P(self)) { + rb_tree_mark_depth(rbt, self->rb_left, depths, depth + 1); + rb_tree_mark_depth(rbt, self->rb_right, depths, depth + 1); + return; + } + depths[depth]++; + if (!RB_LEFT_SENTINEL_P(self)) { + rb_tree_mark_depth(rbt, self->rb_left, depths, depth + 1); + } + if (!RB_RIGHT_SENTINEL_P(self)) { + rb_tree_mark_depth(rbt, self->rb_right, depths, depth + 1); + } +} + +void +rb_tree_depths(const struct rb_tree *rbt, size_t *depths) +{ + rb_tree_mark_depth(rbt, rbt->rbt_root, depths, 1); +} +#endif /* RBSTATS */ diff --git a/common/lib/libprop/prop_rb_impl.h b/common/lib/libprop/prop_rb_impl.h index 682731fbf..0bcf02474 100644 --- a/common/lib/libprop/prop_rb_impl.h +++ b/common/lib/libprop/prop_rb_impl.h @@ -1,4 +1,4 @@ -/* $NetBSD: prop_rb_impl.h,v 1.8 2010/09/25 01:42:38 matt Exp $ */ +/* $NetBSD: prop_rb_impl.h,v 1.9 2012/07/27 09:11:00 pooka Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -47,107 +47,149 @@ #else /* __NetBSD__ */ #include +#ifdef RBDEBUG #include -#include - -struct rb_node { - struct rb_node *rb_nodes[3]; -#define RB_NODE_LEFT 0 -#define RB_NODE_RIGHT 1 -#define RB_NODE_OTHER 1 -#define RB_NODE_PARENT 2 -#define rb_left rb_nodes[RB_NODE_LEFT] -#define rb_right rb_nodes[RB_NODE_RIGHT] -#define rb_parent rb_nodes[RB_NODE_PARENT] - union { - struct { -#if BYTE_ORDER == LITTLE_ENDIAN - unsigned int : 28; - unsigned int s_root : 1; - unsigned int s_position : 1; - unsigned int s_color : 1; - unsigned int s_sentinel : 1; -#endif -#if BYTE_ORDER == BIG_ENDIAN - unsigned int s_sentinel : 1; - unsigned int s_color : 1; - unsigned int s_position : 1; - unsigned int s_root : 1; - unsigned int : 28; #endif - } u_s; - unsigned int u_i; - } rb_u; -#define rb_root rb_u.u_s.s_root -#define rb_position rb_u.u_s.s_position -#define rb_color rb_u.u_s.s_color -#define rb_sentinel rb_u.u_s.s_sentinel -#define rb_properties rb_u.u_i -#define RB_SENTINEL_P(rb) ((rb)->rb_sentinel + 0) -#define RB_LEFT_SENTINEL_P(rb) ((rb)->rb_left->rb_sentinel + 0) -#define RB_RIGHT_SENTINEL_P(rb) ((rb)->rb_right->rb_sentinel + 0) -#define RB_PARENT_SENTINEL_P(rb) ((rb)->rb_parent->rb_sentinel + 0) -#define RB_CHILDLESS_P(rb) (RB_LEFT_SENTINEL_P(rb) \ - && RB_RIGHT_SENTINEL_P(rb)) -#define RB_TWOCHILDREN_P(rb) (!RB_LEFT_SENTINEL_P(rb) \ - && !RB_RIGHT_SENTINEL_P(rb)) -#define RB_ROOT_P(rb) ((rb)->rb_root != false) -#define RB_RED_P(rb) ((rb)->rb_color + 0) -#define RB_BLACK_P(rb) (!(rb)->rb_color) -#define RB_MARK_RED(rb) ((void)((rb)->rb_color = 1)) -#define RB_MARK_BLACK(rb) ((void)((rb)->rb_color = 0)) -#define RB_MARK_ROOT(rb) ((void)((rb)->rb_root = 1)) + +typedef struct rb_node { + struct rb_node *rb_nodes[2]; +#define RB_DIR_LEFT 0 +#define RB_DIR_RIGHT 1 +#define RB_DIR_OTHER 1 +#define rb_left rb_nodes[RB_DIR_LEFT] +#define rb_right rb_nodes[RB_DIR_RIGHT] + + /* + * rb_info contains the two flags and the parent back pointer. + * We put the two flags in the low two bits since we know that + * rb_node will have an alignment of 4 or 8 bytes. + */ + uintptr_t rb_info; +#define RB_FLAG_POSITION 0x2 +#define RB_FLAG_RED 0x1 +#define RB_FLAG_MASK (RB_FLAG_POSITION|RB_FLAG_RED) +#define RB_FATHER(rb) \ + ((struct rb_node *)((rb)->rb_info & ~RB_FLAG_MASK)) +#define RB_SET_FATHER(rb, father) \ + ((void)((rb)->rb_info = (uintptr_t)(father)|((rb)->rb_info & RB_FLAG_MASK))) + +#define RB_SENTINEL_P(rb) ((rb) == NULL) +#define RB_LEFT_SENTINEL_P(rb) RB_SENTINEL_P((rb)->rb_left) +#define RB_RIGHT_SENTINEL_P(rb) RB_SENTINEL_P((rb)->rb_right) +#define RB_FATHER_SENTINEL_P(rb) RB_SENTINEL_P(RB_FATHER((rb))) +#define RB_CHILDLESS_P(rb) \ + (RB_SENTINEL_P(rb) || (RB_LEFT_SENTINEL_P(rb) && RB_RIGHT_SENTINEL_P(rb))) +#define RB_TWOCHILDREN_P(rb) \ + (!RB_SENTINEL_P(rb) && !RB_LEFT_SENTINEL_P(rb) && !RB_RIGHT_SENTINEL_P(rb)) + +#define RB_POSITION(rb) \ + (((rb)->rb_info & RB_FLAG_POSITION) ? RB_DIR_RIGHT : RB_DIR_LEFT) +#define RB_RIGHT_P(rb) (RB_POSITION(rb) == RB_DIR_RIGHT) +#define RB_LEFT_P(rb) (RB_POSITION(rb) == RB_DIR_LEFT) +#define RB_RED_P(rb) (!RB_SENTINEL_P(rb) && ((rb)->rb_info & RB_FLAG_RED) != 0) +#define RB_BLACK_P(rb) (RB_SENTINEL_P(rb) || ((rb)->rb_info & RB_FLAG_RED) == 0) +#define RB_MARK_RED(rb) ((void)((rb)->rb_info |= RB_FLAG_RED)) +#define RB_MARK_BLACK(rb) ((void)((rb)->rb_info &= ~RB_FLAG_RED)) +#define RB_INVERT_COLOR(rb) ((void)((rb)->rb_info ^= RB_FLAG_RED)) +#define RB_ROOT_P(rbt, rb) ((rbt)->rbt_root == (rb)) +#define RB_SET_POSITION(rb, position) \ + ((void)((position) ? ((rb)->rb_info |= RB_FLAG_POSITION) : \ + ((rb)->rb_info &= ~RB_FLAG_POSITION))) +#define RB_ZERO_PROPERTIES(rb) ((void)((rb)->rb_info &= ~RB_FLAG_MASK)) +#define RB_COPY_PROPERTIES(dst, src) \ + ((void)((dst)->rb_info ^= ((dst)->rb_info ^ (src)->rb_info) & RB_FLAG_MASK)) +#define RB_SWAP_PROPERTIES(a, b) do { \ + uintptr_t xorinfo = ((a)->rb_info ^ (b)->rb_info) & RB_FLAG_MASK; \ + (a)->rb_info ^= xorinfo; \ + (b)->rb_info ^= xorinfo; \ + } while (/*CONSTCOND*/ 0) #ifdef RBDEBUG TAILQ_ENTRY(rb_node) rb_link; #endif -}; +} rb_node_t; + +#define RB_TREE_MIN(T) rb_tree_iterate((T), NULL, RB_DIR_LEFT) +#define RB_TREE_MAX(T) rb_tree_iterate((T), NULL, RB_DIR_RIGHT) +#define RB_TREE_FOREACH(N, T) \ + for ((N) = RB_TREE_MIN(T); (N); \ + (N) = rb_tree_iterate((T), (N), RB_DIR_RIGHT)) +#define RB_TREE_FOREACH_REVERSE(N, T) \ + for ((N) = RB_TREE_MAX(T); (N); \ + (N) = rb_tree_iterate((T), (N), RB_DIR_LEFT)) #ifdef RBDEBUG TAILQ_HEAD(rb_node_qh, rb_node); -#define RB_TAILQ_REMOVE TAILQ_REMOVE -#define RB_TAILQ_INIT TAILQ_INIT -#define RB_TAILQ_INSERT_HEAD(a, b, c) TAILQ_INSERT_HEAD -#define RB_TAILQ_INSERT_BEFORE(a, b, c) TAILQ_INSERT_BEFORE -#define RB_TAILQ_INSERT_AFTER(a, b, c, d) TAILQ_INSERT_AFTER +#define RB_TAILQ_REMOVE(a, b, c) TAILQ_REMOVE(a, b, c) +#define RB_TAILQ_INIT(a) TAILQ_INIT(a) +#define RB_TAILQ_INSERT_HEAD(a, b, c) TAILQ_INSERT_HEAD(a, b, c) +#define RB_TAILQ_INSERT_BEFORE(a, b, c) TAILQ_INSERT_BEFORE(a, b, c) +#define RB_TAILQ_INSERT_AFTER(a, b, c, d) TAILQ_INSERT_AFTER(a, b, c, d) #else #define RB_TAILQ_REMOVE(a, b, c) do { } while (/*CONSTCOND*/0) #define RB_TAILQ_INIT(a) do { } while (/*CONSTCOND*/0) #define RB_TAILQ_INSERT_HEAD(a, b, c) do { } while (/*CONSTCOND*/0) #define RB_TAILQ_INSERT_BEFORE(a, b, c) do { } while (/*CONSTCOND*/0) #define RB_TAILQ_INSERT_AFTER(a, b, c, d) do { } while (/*CONSTCOND*/0) -#endif +#endif /* RBDEBUG */ -typedef int (*rb_compare_nodes_fn)(const struct rb_node *, - const struct rb_node *); -typedef int (*rb_compare_key_fn)(const struct rb_node *, const void *); +/* + * rbto_compare_nodes_fn: + * return a positive value if the first node > the second node. + * return a negative value if the first node < the second node. + * return 0 if they are considered same. + * + * rbto_compare_key_fn: + * return a positive value if the node > the key. + * return a negative value if the node < the key. + * return 0 if they are considered same. + */ + +typedef signed int (*rbto_compare_nodes_fn)(void *, const void *, const void *); +typedef signed int (*rbto_compare_key_fn)(void *, const void *, const void *); -struct rb_tree_ops { - rb_compare_nodes_fn rbto_compare_nodes; - rb_compare_key_fn rbto_compare_key; -}; +typedef struct { + rbto_compare_nodes_fn rbto_compare_nodes; + rbto_compare_key_fn rbto_compare_key; + size_t rbto_node_offset; + void *rbto_context; +} rb_tree_ops_t; -struct rb_tree { +typedef struct rb_tree { struct rb_node *rbt_root; + const rb_tree_ops_t *rbt_ops; + struct rb_node *rbt_minmax[2]; #ifdef RBDEBUG struct rb_node_qh rbt_nodes; #endif - const struct rb_tree_ops *rbt_ops; -#ifdef RBDEBUG +#ifdef RBSTATS unsigned int rbt_count; + unsigned int rbt_insertions; + unsigned int rbt_removals; + unsigned int rbt_insertion_rebalance_calls; + unsigned int rbt_insertion_rebalance_passes; + unsigned int rbt_removal_rebalance_calls; + unsigned int rbt_removal_rebalance_passes; +#endif +} rb_tree_t; + +#ifdef RBSTATS +#define RBSTAT_INC(v) ((void)((v)++)) +#define RBSTAT_DEC(v) ((void)((v)--)) +#else +#define RBSTAT_INC(v) do { } while (/*CONSTCOND*/0) +#define RBSTAT_DEC(v) do { } while (/*CONSTCOND*/0) #endif -}; -void _prop_rb_tree_init(struct rb_tree *, const struct rb_tree_ops *); -bool _prop_rb_tree_insert_node(struct rb_tree *, struct rb_node *); -struct rb_node * - _prop_rb_tree_find(struct rb_tree *, const void *); -void _prop_rb_tree_remove_node(struct rb_tree *, struct rb_node *); +void _prop_rb_tree_init(rb_tree_t *, const rb_tree_ops_t *); +void * _prop_rb_tree_insert_node(rb_tree_t *, void *); +void * _prop_rb_tree_find(rb_tree_t *, const void *); +void * _prop_rb_tree_find_node(rb_tree_t *, const void *); +void _prop_rb_tree_remove_node(rb_tree_t *, void *); +void * _prop_rb_tree_iterate(rb_tree_t *, void *, const unsigned int); #ifdef RBDEBUG void _prop_rb_tree_check(const struct rb_tree *, bool); #endif -struct rb_node * - _prop_rb_tree_iterate(struct rb_tree *, struct rb_node *, unsigned int); #endif /* __NetBSD__ */ diff --git a/common/lib/libprop/proplib.3 b/common/lib/libprop/proplib.3 index 1d92f8708..ed6bc2975 100644 --- a/common/lib/libprop/proplib.3 +++ b/common/lib/libprop/proplib.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: proplib.3,v 1.7 2011/01/19 20:34:23 bouyer Exp $ +.\" $NetBSD: proplib.3,v 1.8 2012/03/15 22:35:02 njoly Exp $ .\" .\" Copyright (c) 2006 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -51,7 +51,7 @@ them to an external representation. This external representation is an XML document whose format is described by the following DTD: .Bd -literal -offset indent -http://www.apple.com/DTDs/PropertyList-1.0.dtd +.Lk http://www.apple.com/DTDs/PropertyList-1.0.dtd .Ed .Pp Property container objects are reference counted. diff --git a/common/lib/libutil/getfstypename.c b/common/lib/libutil/getfstypename.c new file mode 100644 index 000000000..4d6ecfc5d --- /dev/null +++ b/common/lib/libutil/getfstypename.c @@ -0,0 +1,131 @@ +/* $NetBSD: getfstypename.c,v 1.8 2012/04/07 16:28:59 christos Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _STANDALONE +# include +# ifndef _KERNEL +# if !defined(lint) +__RCSID("$NetBSD: getfstypename.c,v 1.8 2012/04/07 16:28:59 christos Exp $"); +# endif +# else +__KERNEL_RCSID(0, "$NetBSD: getfstypename.c,v 1.8 2012/04/07 16:28:59 christos Exp $"); +# endif /* _KERNEL */ + +# define FSTYPE_ENUMNAME fstype_enum +# include +# include +# include +# ifndef _KERNEL +# include +# endif + +const char * +getfstypename(int fstype) +{ + /* + * The cast is so that the compiler can check that we + * cover all the enum values + */ + switch ((enum fstype_enum)fstype) { + case FS_UNUSED: + return DKW_PTYPE_UNUSED; + case FS_SWAP: + return DKW_PTYPE_SWAP; + case FS_V6: + return DKW_PTYPE_V6; + case FS_V7: + return DKW_PTYPE_V7; + case FS_SYSV: + return DKW_PTYPE_SYSV; + case FS_V71K: + return DKW_PTYPE_V71K; + case FS_V8: + return DKW_PTYPE_V8; + case FS_BSDFFS: + return DKW_PTYPE_FFS; + case FS_MSDOS: + return DKW_PTYPE_FAT; + case FS_BSDLFS: + return DKW_PTYPE_LFS; + case FS_OTHER: + return DKW_PTYPE_OTHER; + case FS_HPFS: + return DKW_PTYPE_HPFS; + case FS_ISO9660: + return DKW_PTYPE_ISO9660; + case FS_BOOT: + return DKW_PTYPE_BOOT; + case FS_ADOS: + return DKW_PTYPE_AMIGADOS; + case FS_HFS: + return DKW_PTYPE_APPLEHFS; + case FS_FILECORE: + return DKW_PTYPE_FILECORE; + case FS_EX2FS: + return DKW_PTYPE_EXT2FS; + case FS_NTFS: + return DKW_PTYPE_NTFS; + case FS_RAID: + return DKW_PTYPE_RAIDFRAME; + case FS_CCD: + return DKW_PTYPE_CCD; + case FS_JFS2: + return DKW_PTYPE_JFS2; + case FS_APPLEUFS: + return DKW_PTYPE_APPLEUFS; + case FS_VINUM: + return DKW_PTYPE_VINUM; + case FS_UDF: + return DKW_PTYPE_UDF; + case FS_SYSVBFS: + return DKW_PTYPE_SYSVBFS; + case FS_EFS: + return DKW_PTYPE_EFS; + case FS_NILFS: + return DKW_PTYPE_NILFS; + case FS_CGD: + return DKW_PTYPE_CGD; + case FSMAXTYPES: + return DKW_PTYPE_UNKNOWN; + case FS_MINIXFS3: + return DKW_PTYPE_MINIXFS3; + } + /* Stupid gcc, should know it is impossible to get here */ + /*NOTREACHED*/ + return DKW_PTYPE_UNKNOWN; +} +#endif /* !_STANDALONE */ diff --git a/common/lib/libutil/proc_compare.c b/common/lib/libutil/proc_compare.c new file mode 100644 index 000000000..1ea981d31 --- /dev/null +++ b/common/lib/libutil/proc_compare.c @@ -0,0 +1,146 @@ +/* $NetBSD: proc_compare.c,v 1.1 2011/10/21 02:09:00 christos Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#ifndef _STANDALONE +# ifndef _KERNEL + +# if HAVE_NBTOOL_CONFIG_H +# include "nbtool_config.h" +# endif + +# include +# if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: proc_compare.c,v 1.1 2011/10/21 02:09:00 christos Exp $"); +# endif + +# include +# include +# include +# include +# include +# include +# define PROC struct kinfo_proc2 +# define LWP struct kinfo_lwp +# define P_RTIME_SEC p_rtime_sec +# define P_RTIME_USEC p_rtime_usec +# else +# include +__KERNEL_RCSID(0, "$NetBSD: proc_compare.c,v 1.1 2011/10/21 02:09:00 christos Exp $"); +# include +# include +# include +# include +# include +# include +# define PROC struct proc +# define LWP struct lwp +# define P_RTIME_SEC p_rtime.sec +# define P_RTIME_USEC p_rtime.frac +# endif +/* + * Returns 1 if p2 is "better" than p1 + * + * The algorithm for picking the "interesting" process is thus: + * + * 1) Only foreground processes are eligible - implied. + * 2) Runnable processes are favored over anything else. The runner + * with the highest CPU utilization is picked (l_pctcpu). Ties are + * broken by picking the highest pid. + * 3) The sleeper with the shortest sleep time is next. With ties, + * we pick out just "short-term" sleepers (P_SINTR == 0). + * 4) Further ties are broken by picking the one started last. + * 5) Finally the one with the biggest pid wins, but that is nonsense + * because of pid randomization. + */ +#define ISRUN(p) ((p)->p_nrlwps > 0) +#define TESTAB(a, b) (((a) << 1) | (b)) +#define ONLYA 2 +#define ONLYB 1 +#define BOTH 3 + +int +proc_compare(const PROC *p1, const LWP *l1, const PROC *p2, const LWP *l2) +{ + /* + * see if at least one of them is runnable + */ + switch (TESTAB(ISRUN(p1), ISRUN(p2))) { + case ONLYA: + return 0; + case ONLYB: + return 1; + case BOTH: + /* + * tie - favor one with highest recent CPU utilization + */ + if (l2->l_pctcpu > l1->l_pctcpu) + return 1; + goto out; + } + /* + * weed out zombies + */ + switch (TESTAB(P_ZOMBIE(p1), P_ZOMBIE(p2))) { + case ONLYA: + return 1; + case ONLYB: + return 0; + case BOTH: + goto out; + } + /* + * pick the one with the smallest sleep time + */ + if (l1->l_slptime < l2->l_slptime) + return 0; + if (l2->l_slptime < l1->l_slptime) + return 1; + + /* + * favor one sleeping in a non-interruptible sleep + */ + if ((l1->l_flag & LW_SINTR) && (l2->l_flag & LW_SINTR) == 0) + return 0; + if ((l2->l_flag & LW_SINTR) && (l1->l_flag & LW_SINTR) == 0) + return 1; +out: + /* tie, return the one with the smallest realtime */ + if (p1->P_RTIME_SEC < p2->P_RTIME_SEC) + return 0; + if (p2->P_RTIME_SEC < p1->P_RTIME_SEC) + return 1; + if (p1->P_RTIME_USEC < p2->P_RTIME_USEC) + return 0; + if (p2->P_RTIME_USEC < p1->P_RTIME_USEC) + return 1; + + return p2->p_pid > p1->p_pid; /* Nonsense */ +} +#endif /* STANDALONE */ diff --git a/common/lib/libutil/snprintb.c b/common/lib/libutil/snprintb.c index 1ad02dc81..2efaa01cc 100644 --- a/common/lib/libutil/snprintb.c +++ b/common/lib/libutil/snprintb.c @@ -1,4 +1,4 @@ -/* $NetBSD: snprintb.c,v 1.5 2009/05/13 02:50:31 pgoyette Exp $ */ +/* $NetBSD: snprintb.c,v 1.7 2012/01/23 03:22:41 christos Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ # include # if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: snprintb.c,v 1.5 2009/05/13 02:50:31 pgoyette Exp $"); +__RCSID("$NetBSD: snprintb.c,v 1.7 2012/01/23 03:22:41 christos Exp $"); # endif # include @@ -51,7 +51,7 @@ __RCSID("$NetBSD: snprintb.c,v 1.5 2009/05/13 02:50:31 pgoyette Exp $"); # include # else # include -__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.5 2009/05/13 02:50:31 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: snprintb.c,v 1.7 2012/01/23 03:22:41 christos Exp $"); # include # include # include @@ -137,7 +137,7 @@ snprintb_m(char *buf, size_t buflen, const char *bitfmt, uint64_t val, STORE('<'); \ } else { \ /* Remember separator location */ \ - if ( l_max > 0 && sep != '<') { \ + if (l_max > 0 && sep != '<') { \ s_len = l_len; \ s_bp = bp; \ s_fmt = cur_fmt; \ @@ -209,14 +209,13 @@ snprintb_m(char *buf, size_t buflen, const char *bitfmt, uint64_t val, f_len = *bitfmt++; /* field length */ field = (val >> bit) & (((uint64_t)1 << f_len) - 1); + PUTSEP; + if (restart == 0) + sep = ','; if (ch == 'F') /* just extract */ break; - PUTSEP; if (restart == 0) { - sep = ','; PUTS(bitfmt); - } - if (restart == 0) { PUTCHR('='); } if (restart == 0) { diff --git a/drivers/audio/es1371/AC97.c b/drivers/audio/es1371/AC97.c index 6bb9bbce7..a5204a08b 100644 --- a/drivers/audio/es1371/AC97.c +++ b/drivers/audio/es1371/AC97.c @@ -341,7 +341,7 @@ static void set_nice_volume(void) { static int get_volume(u8_t *left, u8_t *right, int cmd) { - u16_t value; + u16_t value = 0; AC97_read_unsynced(dev, (u16_t)cmd, &value); diff --git a/drivers/tty/arch/i386/console.c b/drivers/tty/arch/i386/console.c index de50c67f4..cd383c46f 100644 --- a/drivers/tty/arch/i386/console.c +++ b/drivers/tty/arch/i386/console.c @@ -154,7 +154,7 @@ int try; */ int count; - int result; + int result = OK; register char *tbuf; char buf[64]; console_t *cons = tp->tty_priv; diff --git a/external/gpl3/gcc/files/i386-minix.h b/external/gpl3/gcc/files/i386-minix.h index 0caea817c..0276f3a7b 100644 --- a/external/gpl3/gcc/files/i386-minix.h +++ b/external/gpl3/gcc/files/i386-minix.h @@ -26,6 +26,7 @@ Boston, MA 02110-1301, USA. */ #define MINIX_TARGET_CPU_CPP_BUILTINS() \ do \ { \ + builtin_define ("__i386"); \ builtin_define_with_int_value ("_EM_WSIZE", 4); \ builtin_define_with_int_value ("_EM_PSIZE", 4); \ builtin_define_with_int_value ("_EM_SSIZE", 2); \ @@ -73,29 +74,12 @@ Boston, MA 02110-1301, USA. */ #undef SUBTARGET_EXTRA_SPECS /* i386.h bogusly defines it. */ #define SUBTARGET_EXTRA_SPECS \ { "minix_dynamic_linker", MINIX_DYNAMIC_LINKER } - -/* Provide a STARTFILE_SPEC appropriate for MINIX. Here we add - the magical crtbegin.o file (see crtstuff.c) which provides part - of the support for getting C++ file-scope static object constructed - before entering `main'. */ - + #undef STARTFILE_SPEC -#define STARTFILE_SPEC \ - "%{!shared: \ - %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \ - %{!p:%{profile:gcrt1.o%s} \ - %{!profile:crt1.o%s}}}} \ - crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}" - -/* Provide a ENDFILE_SPEC appropriate for MINIX. Here we tack on - the magical crtend.o file (see crtstuff.c) which provides part of - the support for getting C++ file-scope static object constructed - before entering `main', followed by a normal "finalizer" file, - `crtn.o'. */ +#define STARTFILE_SPEC MINIX_STARTFILE_SPEC #undef ENDFILE_SPEC -#define ENDFILE_SPEC \ - "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s" +#define ENDFILE_SPEC MINIX_ENDFILE_SPEC /* Provide a LINK_SPEC appropriate for MINIX. Here we provide support for the special GCC options -static and -shared, which allow us to diff --git a/external/gpl3/gcc/files/minix-spec.h b/external/gpl3/gcc/files/minix-spec.h index dcd92ea76..eaa617b90 100644 --- a/external/gpl3/gcc/files/minix-spec.h +++ b/external/gpl3/gcc/files/minix-spec.h @@ -48,9 +48,8 @@ Boston, MA 02110-1301, USA. */ #define MINIX_TARGET_OS_CPP_BUILTINS() \ do \ { \ - builtin_define ("__minix"); \ - builtin_define ("__i386"); \ - MINIX_TARGET_CPU_CPP_BUILTINS(); \ + builtin_define ("__minix"); \ + MINIX_TARGET_CPU_CPP_BUILTINS(); \ } \ while (0) @@ -72,10 +71,10 @@ Boston, MA 02110-1301, USA. */ #define MINIX_STARTFILE_SPEC \ "%{!shared: \ - %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \ - %{!p:%{profile:gcrt1.o%s} \ - %{!profile:crt1.o%s}}}} \ - crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}" + %{pg:gcrt0%O%s} %{!pg:%{p:gcrt0%O%s} \ + %{!p:%{profile:gcrt0%O%s} \ + %{!profile:crt0%O%s}}}} \ + crti%O%s %{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}" /* Provide a ENDFILE_SPEC appropriate for MINIX. Here we tack on the magical crtend.o file (see crtstuff.c) which provides part of diff --git a/include/Makefile b/include/Makefile index 1eda080a0..b9f00bbe5 100644 --- a/include/Makefile +++ b/include/Makefile @@ -13,7 +13,7 @@ INCS= a.out.h aio.h ar.h assert.h atomic.h \ fstab.h fts.h ftw.h getopt.h glob.h grp.h ifaddrs.h iconv.h \ inttypes.h iso646.h langinfo.h libgen.h \ limits.h link.h link_aout.h link_elf.h locale.h \ - login_cap.h malloc.h math.h md2.h \ + login_cap.h lwp.h malloc.h math.h md2.h \ memory.h mntopts.h monetary.h mpool.h mqueue.h \ ndbm.h netconfig.h netdb.h netgroup.h nlist.h nl_types.h nsswitch.h \ paths.h pwd.h randomid.h ranlib.h re_comp.h regex.h regexp.h \ diff --git a/include/arch/Makefile b/include/arch/Makefile index 470dcafdd..377af3cda 100644 --- a/include/arch/Makefile +++ b/include/arch/Makefile @@ -1,46 +1,5 @@ -# $NetBSD: Makefile,v 1.40 2009/12/13 05:01:33 nakayama Exp $ - -# For now, we install the machine and arch includes, and symlink 'machine' -# to the location of the machine includes (usually). -# -# Eventually, we should install everything. - .include SUBDIR= ${MACHINE} -ARCHSUBDIR= ${MACHINE_CPU} - -.if ${ARCHSUBDIR} == "mips64" -ARCHSUBDIR= mips -.endif -.if ${ARCHSUBDIR} == "powerpc64" -ARCHSUBDIR= powerpc -.endif - -.if ${MACHINE} != ${ARCHSUBDIR} -.if exists(${ARCHSUBDIR}) -SUBDIR+= ${ARCHSUBDIR} -.endif -.endif -.if ${MACHINE} == sparc -SUBDIR+= sparc64 -.endif -.if (${MACHINE} == hpcmips || ${MACHINE} == hpcsh) -SUBDIR+= hpc -.endif -.if (${MACHINE} == sun2 || ${MACHINE} == sun3) -SUBDIR+= sun68k -.endif -.if defined(XEN_BUILD) -SUBDIR+= xen -.endif - - -INCSYMLINKS= ${MACHINE_ARCH} /usr/include/machine - -INCSYMLINKS+= machine/float.h /usr/include/float.h \ - machine/stdarg.h /usr/include/stdarg.h - -.include .include diff --git a/include/arch/arm/include/stdarg.h b/include/arch/arm/include/stdarg.h deleted file mode 100644 index f5ba7b2c9..000000000 --- a/include/arch/arm/include/stdarg.h +++ /dev/null @@ -1,86 +0,0 @@ -/* $NetBSD: stdarg.h,v 1.10 2008/06/21 00:56:39 gmcgarry Exp $ */ - -/* - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)stdarg.h 8.1 (Berkeley) 6/10/93 - */ - -#ifndef _ARM32_STDARG_H_ -#define _ARM32_STDARG_H_ - -#include -#include - -typedef _BSD_VA_LIST_ va_list; -#ifdef __lint__ -#define __builtin_next_arg(t) ((t) ? 0 : 0) -#define __builtin_stdarg_start(a, l) ((a) = ((l) ? 0 : 0)) -#define __builtin_va_arg(a, t) ((t)((a) ? 0 : 0)) -#define __builtin_va_end /* nothing */ -#define __builtin_va_copy(d, s) ((d) = (s)) -#endif - -#if __GNUC_PREREQ__(4, 1) -#define va_start(ap, last) __builtin_va_start((ap), (last)) -#define va_arg __builtin_va_arg -#define va_end __builtin_va_end -#define __va_copy(dest, src) __builtin_va_copy((dest), (src)) -#elif __GNUC_PREREQ__(2, 96) -#define va_start(ap, last) __builtin_stdarg_start((ap), (last)) -#define va_arg __builtin_va_arg -#define va_end __builtin_va_end -#define __va_copy(dest, src) __builtin_va_copy((dest), (src)) -#elif defined(__PCC__) -#define va_start(ap, last) __builtin_stdarg_start((ap), (last)) -#define va_arg __builtin_va_arg -#define va_end __builtin_va_end -#define __va_copy(dest, src) __builtin_va_copy((dest), (src)) -#else -#define __va_size(type) \ - (((sizeof(type) + sizeof(long) - 1) / sizeof(long)) * sizeof(long)) - -#define va_start(ap, last) \ - ((ap) = (va_list)__builtin_next_arg(last)) - -#define va_arg(ap, type) \ - ((type *)(ap += sizeof(type)))[-1] - -#define va_end(ap) - -#define __va_copy(dest, src) ((dest) = (src)) - -#endif /* __GNUC_PREREQ__(2, 96) */ - -#if !defined(_ANSI_SOURCE) && \ - (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \ - defined(_NETBSD_SOURCE)) -#define va_copy(dest, src) __va_copy((dest), (src)) -#endif - -#endif /* !_ARM32_STDARG_H_ */ diff --git a/include/arch/evbarm/Makefile b/include/arch/evbarm/Makefile index d0c4992e7..3d01d044e 100644 --- a/include/arch/evbarm/Makefile +++ b/include/arch/evbarm/Makefile @@ -1,5 +1,3 @@ -# $NetBSD: Makefile,v 1.38 2009/08/30 02:00:56 dyoung Exp $ - SUBDIR= include diff --git a/include/arch/evbarm/include/Makefile b/include/arch/evbarm/include/Makefile index 3da1ddd3e..eaf08d24e 100644 --- a/include/arch/evbarm/include/Makefile +++ b/include/arch/evbarm/include/Makefile @@ -3,6 +3,6 @@ INCSDIR= /usr/include/arm INCS= archconst.h archtypes.h diskparm.h elf.h interrupt.h \ ipcconst.h memory.h multiboot.h partition.h \ - stackframe.h stdarg.h vm.h + stackframe.h vm.h .include diff --git a/include/arch/evbarm/include/multiboot.h b/include/arch/evbarm/include/multiboot.h index 4b8ac1a3a..19291b283 100644 --- a/include/arch/evbarm/include/multiboot.h +++ b/include/arch/evbarm/include/multiboot.h @@ -1,6 +1,213 @@ +/* $NetBSD: multiboot.h,v 1.8 2009/02/22 18:05:42 ahoka Exp $ */ + +/*- + * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julio M. Merino Vidal. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef __MULTIBOOT_H__ #define __MULTIBOOT_H__ +#if !defined(_KERNEL) && defined(_STANDALONE) + +/* --------------------------------------------------------------------- */ + +/* + * Multiboot header structure. + */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 +#define MULTIBOOT_HEADER_MODS_ALIGNED 0x00000001 +#define MULTIBOOT_HEADER_WANT_MEMORY 0x00000002 +#define MULTIBOOT_HEADER_HAS_VBE 0x00000004 +#define MULTIBOOT_HEADER_HAS_ADDR 0x00010000 + +#if !defined(_LOCORE) +struct multiboot_header { + uint32_t mh_magic; + uint32_t mh_flags; + uint32_t mh_checksum; + + /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ + paddr_t mh_header_addr; + paddr_t mh_load_addr; + paddr_t mh_load_end_addr; + paddr_t mh_bss_end_addr; + paddr_t mh_entry_addr; + + /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */ + uint32_t mh_mode_type; + uint32_t mh_width; + uint32_t mh_height; + uint32_t mh_depth; +}; +#endif /* !defined(_LOCORE) */ + +/* + * Symbols defined in locore.S. + */ +#if !defined(_LOCORE) && defined(_KERNEL) +extern struct multiboot_header *Multiboot_Header; +#endif /* !defined(_LOCORE) && defined(_KERNEL) */ + +/* --------------------------------------------------------------------- */ + +/* + * Multiboot information structure. + */ +#define MULTIBOOT_INFO_MAGIC 0x2BADB002 +#define MULTIBOOT_INFO_HAS_MEMORY 0x00000001 +#define MULTIBOOT_INFO_HAS_BOOT_DEVICE 0x00000002 +#define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004 +#define MULTIBOOT_INFO_HAS_MODS 0x00000008 +#define MULTIBOOT_INFO_HAS_AOUT_SYMS 0x00000010 +#define MULTIBOOT_INFO_HAS_ELF_SYMS 0x00000020 +#define MULTIBOOT_INFO_HAS_MMAP 0x00000040 +#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080 +#define MULTIBOOT_INFO_HAS_CONFIG_TABLE 0x00000100 +#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200 +#define MULTIBOOT_INFO_HAS_APM_TABLE 0x00000400 +#define MULTIBOOT_INFO_HAS_VBE 0x00000800 + +#if !defined(_LOCORE) +struct multiboot_info { + uint32_t mi_flags; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */ + uint32_t mi_mem_lower; + uint32_t mi_mem_upper; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */ + uint8_t mi_boot_device_part3; + uint8_t mi_boot_device_part2; + uint8_t mi_boot_device_part1; + uint8_t mi_boot_device_drive; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */ + char * mi_cmdline; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */ + uint32_t mi_mods_count; + vaddr_t mi_mods_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */ + uint32_t mi_elfshdr_num; + uint32_t mi_elfshdr_size; + vaddr_t mi_elfshdr_addr; + uint32_t mi_elfshdr_shndx; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */ + uint32_t mi_mmap_length; + vaddr_t mi_mmap_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */ + uint32_t mi_drives_length; + vaddr_t mi_drives_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */ + void * unused_mi_config_table; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */ + char * mi_loader_name; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */ + void * unused_mi_apm_table; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */ + void * unused_mi_vbe_control_info; + void * unused_mi_vbe_mode_info; + paddr_t unused_mi_vbe_interface_seg; + paddr_t unused_mi_vbe_interface_off; + uint32_t unused_mi_vbe_interface_len; +}; + +/* --------------------------------------------------------------------- */ + +/* + * Drive information. This describes an entry in the drives table as + * pointed to by mi_drives_addr. + */ +struct multiboot_drive { + uint32_t md_length; + uint8_t md_number; + uint8_t md_mode; + uint16_t md_cylinders; + uint8_t md_heads; + uint8_t md_sectors; + + /* The variable-sized 'ports' field comes here, so this structure + * can be longer. */ +}; + +/* --------------------------------------------------------------------- */ + +/* + * Memory mapping. This describes an entry in the memory mappings table + * as pointed to by mi_mmap_addr. + * + * Be aware that mm_size specifies the size of all other fields *except* + * for mm_size. In order to jump between two different entries, you + * have to count mm_size + 4 bytes. + */ +struct multiboot_mmap { + uint32_t mm_size; + uint64_t mm_base_addr; + uint64_t mm_length; + uint32_t mm_type; +}; + +/* + * Modules. This describes an entry in the modules table as pointed + * to by mi_mods_addr. + */ + +struct multiboot_module { + uint32_t mmo_start; + uint32_t mmo_end; + char * mmo_string; + uint32_t mmo_reserved; +}; + +#endif /* !defined(_LOCORE) */ + +/* --------------------------------------------------------------------- */ + +/* + * Prototypes for public functions defined in multiboot.c. + */ +#if !defined(_LOCORE) && defined(_KERNEL) +void multiboot_pre_reloc(struct multiboot_info *); +void multiboot_post_reloc(void); +void multiboot_print_info(void); +bool multiboot_ksyms_addsyms_elf(void); +#endif /* !defined(_LOCORE) */ + +/* --------------------------------------------------------------------- */ +#else /* !defined(_KERNEL) && defined(_STANDALONE) */ +/* LSC FIXME: OLD MINIX DEFINITION: should be removed and replace with + definition above... */ #define MULTIBOOT_HEADER_MAGIC 0x1BADB002 #define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 @@ -140,4 +347,5 @@ struct multiboot_mmap_entry typedef struct multiboot_mmap_entry multiboot_memory_map_t; #endif /* __ASSEMBLY__ */ +#endif /* !defined(_KERNEL) && defined(_STANDALONE) */ #endif /* __MULTIBOOT_H__ */ diff --git a/include/arch/i386/Makefile b/include/arch/i386/Makefile index d0c4992e7..3d01d044e 100644 --- a/include/arch/i386/Makefile +++ b/include/arch/i386/Makefile @@ -1,5 +1,3 @@ -# $NetBSD: Makefile,v 1.38 2009/08/30 02:00:56 dyoung Exp $ - SUBDIR= include diff --git a/include/arch/i386/include/Makefile b/include/arch/i386/include/Makefile index 5dd64cc4c..1fa8a6df5 100644 --- a/include/arch/i386/include/Makefile +++ b/include/arch/i386/include/Makefile @@ -1,10 +1,11 @@ + INCSDIR= /usr/include/i386 -INCS= archconst.h archtypes.h bios.h cmos.h cpu.h \ +INCS= archconst.h archtypes.h bios.h cmos.h \ diskparm.h elf.h fpu.h int86.h interrupt.h \ ipcconst.h memory.h partition.h \ pci_amd.h pci.h pci_intel.h pci_sis.h \ - pci_via.h ports.h stackframe.h stdarg.h vm.h + pci_via.h ports.h stackframe.h vm.h .include diff --git a/include/arch/i386/include/stdarg.h b/include/arch/i386/include/stdarg.h deleted file mode 100644 index 38d0f81f2..000000000 --- a/include/arch/i386/include/stdarg.h +++ /dev/null @@ -1,86 +0,0 @@ -/* $NetBSD: stdarg.h,v 1.23 2009/08/18 17:40:39 drochner Exp $ */ - -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)stdarg.h 8.1 (Berkeley) 6/10/93 - */ - -#ifndef _I386_STDARG_H_ -#define _I386_STDARG_H_ - -#include -#include - -typedef _BSD_VA_LIST_ va_list; - -#ifdef __lint__ -#define __builtin_next_arg(t) ((t) ? 0 : 0) -#define __builtin_stdarg_start(a, l) ((a) = ((l) ? 0 : 0)) -#define __builtin_va_arg(a, t) ((a) ? 0 : 0) -#define __builtin_va_end /* nothing */ -#define __builtin_va_copy(d, s) ((d) = (s)) -#endif - -#if __GNUC_PREREQ__(4, 1) -#define va_start(ap, last) __builtin_va_start((ap), (last)) -#define va_arg __builtin_va_arg -#define va_end __builtin_va_end -#define __va_copy(dest, src) __builtin_va_copy((dest), (src)) -#elif __GNUC_PREREQ__(2, 96) -#define va_start(ap, last) __builtin_stdarg_start((ap), (last)) -#define va_arg __builtin_va_arg -#define va_end __builtin_va_end -#define __va_copy(dest, src) __builtin_va_copy((dest), (src)) -#elif defined(__PCC__) -#define va_start(ap, last) __builtin_stdarg_start((ap), (last)) -#define va_arg __builtin_va_arg -#define va_end __builtin_va_end -#define __va_copy(dest, src) __builtin_va_copy((dest), (src)) -#else -#define __va_size(type) \ - (((sizeof(type) + sizeof(long) - 1) / sizeof(long)) * sizeof(long)) - -#define va_start(ap, last) \ - ((ap) = (va_list)__builtin_next_arg(last)) - -#define va_arg(ap, type) \ - (*(type *)(void *)((ap) += __va_size(type), (ap) - __va_size(type))) - -#define va_end(ap) - -#define __va_copy(dest, src) ((dest) = (src)) -#endif - -#if !defined(_ANSI_SOURCE) && \ - (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \ - defined(_NETBSD_SOURCE)) -#define va_copy(dest, src) __va_copy((dest), (src)) -#endif - -#endif /* !_I386_STDARG_H_ */ diff --git a/include/assert.h b/include/assert.h index 95d30348e..a2e8b0ab0 100644 --- a/include/assert.h +++ b/include/assert.h @@ -1,4 +1,4 @@ -/* $NetBSD: assert.h,v 1.20 2008/11/02 14:27:44 christos Exp $ */ +/* $NetBSD: assert.h,v 1.21 2011/08/26 01:10:49 joerg Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -98,8 +98,8 @@ #ifndef __ASSERT_DECLARED #define __ASSERT_DECLARED __BEGIN_DECLS -void __assert(const char *, int, const char *); -void __assert13(const char *, int, const char *, const char *); +__dead void __assert(const char *, int, const char *); +__dead void __assert13(const char *, int, const char *, const char *); void __diagassert(const char *, int, const char *); void __diagassert13(const char *, int, const char *, const char *); __END_DECLS diff --git a/include/cdbw.h b/include/cdbw.h index 3625705e1..67e27de70 100644 --- a/include/cdbw.h +++ b/include/cdbw.h @@ -1,4 +1,4 @@ -/* $NetBSD: cdbw.h,v 1.1 2010/04/25 00:54:45 joerg Exp $ */ +/* $NetBSD: cdbw.h,v 1.2 2012/06/03 21:21:45 joerg Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -49,6 +49,7 @@ int cdbw_put_data(struct cdbw *, const void *, size_t, uint32_t *); int cdbw_put_key(struct cdbw *, const void *, size_t, uint32_t); +uint32_t cdbw_stable_seeder(void); int cdbw_output(struct cdbw *, int, const char[16], uint32_t (*)(void)); void cdbw_close(struct cdbw *); diff --git a/include/db.h b/include/db.h index 6e2fb7da3..b3e05111b 100644 --- a/include/db.h +++ b/include/db.h @@ -1,4 +1,4 @@ -/* $NetBSD: db.h,v 1.24 2008/08/26 21:18:38 joerg Exp $ */ +/* $NetBSD: db.h,v 1.25 2012/03/13 21:14:55 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -214,8 +214,7 @@ DB *dbopen(const char *, int, mode_t, DBTYPE, const void *); #ifdef __DBINTERFACE_PRIVATE -#define _DBMASK(a) (~((1ULL << (sizeof(a) * NBBY)) - 1)) -#define _DBFIT(a, t) _DIAGASSERT(((a) & _DBMASK(t)) == 0) +#define _DBFIT(a, t) _DIAGASSERT(__type_fit(t, a)) DB *__bt_open(const char *, int, mode_t, const BTREEINFO *, int); DB *__hash_open(const char *, int, mode_t, const HASHINFO *, int); diff --git a/include/dirent.h b/include/dirent.h index 0fb44e73e..c4a70b20b 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -1,4 +1,4 @@ -/* $NetBSD: dirent.h,v 1.34 2010/09/26 02:26:59 yamt Exp $ */ +/* $NetBSD: dirent.h,v 1.35 2012/07/30 23:11:13 yamt Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -58,7 +58,13 @@ typedef struct _dirdesc DIR; /* structure describing an open directory. */ struct _dirdesc { + /* + * dd_fd should be kept intact to preserve ABI compat. see dirfd(). + */ int dd_fd; /* file descriptor associated with directory */ + /* + * the rest is hidden from user. + */ long dd_loc; /* offset in current buffer */ long dd_size; /* amount of data returned by getdents */ char *dd_buf; /* data buffer */ diff --git a/include/dlfcn.h b/include/dlfcn.h index d50fe64c5..a2fdbea64 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -1,4 +1,4 @@ -/* $NetBSD: dlfcn.h,v 1.22 2010/12/24 12:41:42 skrll Exp $ */ +/* $NetBSD: dlfcn.h,v 1.24 2012/02/16 23:00:39 joerg Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -48,6 +48,8 @@ typedef struct _dl_info { * User interface to the run-time linker. */ __BEGIN_DECLS +void *_dlauxinfo(void) __pure; + void *dlopen(const char *, int); int dlclose(void *); void *dlsym(void * __restrict, const char * __restrict); @@ -55,6 +57,8 @@ void *dlsym(void * __restrict, const char * __restrict); int dladdr(const void * __restrict, Dl_info * __restrict); int dlctl(void *, int, void *); int dlinfo(void *, int, void *); +void *dlvsym(void * __restrict, const char * __restrict, + const char * __restrict); #endif __aconst char *dlerror(void); __END_DECLS diff --git a/include/err.h b/include/err.h index b29a9713d..7d6c8bf4b 100644 --- a/include/err.h +++ b/include/err.h @@ -1,4 +1,4 @@ -/* $NetBSD: err.h,v 1.15 2010/02/25 18:37:12 joerg Exp $ */ +/* $NetBSD: err.h,v 1.16 2011/07/17 20:54:34 joerg Exp $ */ /*- * Copyright (c) 1993 @@ -34,32 +34,25 @@ #ifndef _ERR_H_ #define _ERR_H_ -/* - * Don't use va_list in the err/warn prototypes. Va_list is typedef'd in two - * places ( and ), so if we include one - * of them here we may collide with the utility's includes. It's unreasonable - * for utilities to have to include one of them to include err.h, so we get - * _BSD_VA_LIST_ from and use it. - */ -#include #include +#include __BEGIN_DECLS __dead void err(int, const char *, ...) __printflike(2, 3) __dead; -__dead void verr(int, const char *, _BSD_VA_LIST_) +__dead void verr(int, const char *, va_list) __printflike(2, 0) __dead; __dead void errx(int, const char *, ...) __printflike(2, 3) __dead; -__dead void verrx(int, const char *, _BSD_VA_LIST_) +__dead void verrx(int, const char *, va_list) __printflike(2, 0) __dead; void warn(const char *, ...) __printflike(1, 2); -void vwarn(const char *, _BSD_VA_LIST_) +void vwarn(const char *, va_list) __printflike(1, 0); void warnx(const char *, ...) __printflike(1, 2); -void vwarnx(const char *, _BSD_VA_LIST_) +void vwarnx(const char *, va_list) __printflike(1, 0); __END_DECLS diff --git a/include/fenv.h b/include/fenv.h index dcae51e01..fb3a4d785 100644 --- a/include/fenv.h +++ b/include/fenv.h @@ -1,4 +1,4 @@ -/* $NetBSD: fenv.h,v 1.2 2010/08/02 17:49:04 joerg Exp $ */ +/* $NetBSD: fenv.h,v 1.7 2012/03/22 03:06:06 dholland Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -25,7 +25,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(__i386__) && !defined(__amd64__) +#if !defined(__i386__) && !defined(__amd64__) && !defined(__sparc__) #error "fenv.h is currently not supported for this architecture" #endif @@ -55,7 +55,7 @@ int feenableexcept(int mask); int fedisableexcept(int mask); int fegetexcept(void); -#endif /* _NETBDS_SOURCE || _GNU_SOURCE */ +#endif /* _NETBSD_SOURCE || _GNU_SOURCE */ __END_DECLS diff --git a/include/fnmatch.h b/include/fnmatch.h index b7533d549..42ff72594 100644 --- a/include/fnmatch.h +++ b/include/fnmatch.h @@ -1,4 +1,4 @@ -/* $NetBSD: fnmatch.h,v 1.12 2005/02/03 04:39:32 perry Exp $ */ +/* $NetBSD: fnmatch.h,v 1.13 2011/01/31 04:49:46 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,6 +38,7 @@ #define FNM_NOMATCH 1 /* Match failed. */ #define FNM_NOSYS 2 /* Function not implemented. */ +#define FNM_NORES 3 /* Out of resources */ #define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ #define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ diff --git a/include/ieeefp.h b/include/ieeefp.h index 9b9cce10c..6708112a4 100644 --- a/include/ieeefp.h +++ b/include/ieeefp.h @@ -1,4 +1,4 @@ -/* $NetBSD: ieeefp.h,v 1.7 2005/11/18 20:02:59 christos Exp $ */ +/* $NetBSD: ieeefp.h,v 1.9 2011/03/27 05:13:15 mrg Exp $ */ /* * Written by J.T. Conklin, Apr 6, 1995 @@ -12,12 +12,23 @@ #include __BEGIN_DECLS -fp_rnd fpgetround(void); -fp_rnd fpsetround(fp_rnd); -fp_except fpgetmask(void); -fp_except fpsetmask(fp_except); -fp_except fpgetsticky(void); -fp_except fpsetsticky(fp_except); +typedef fp_rnd fp_rnd_t; +#ifdef _X86_IEEEFP_H_ /* XXX */ +typedef fp_prec fp_prec_t; +#endif +typedef fp_except fp_except_t; + +fp_rnd_t fpgetround(void); +fp_rnd_t fpsetround(fp_rnd_t); +#ifdef _X86_IEEEFP_H_ /* XXX */ +fp_prec_t fpgetprec(void); +fp_prec_t fpsetprec(fp_prec_t); +#endif +fp_except_t fpgetmask(void); +fp_except_t fpsetmask(fp_except_t); +fp_except_t fpgetsticky(void); +fp_except_t fpsetsticky(fp_except_t); +fp_except_t fpresetsticky(fp_except_t); __END_DECLS #endif /* _IEEEFP_H_ */ diff --git a/include/kvm.h b/include/kvm.h index 174ade4af..262f49e37 100644 --- a/include/kvm.h +++ b/include/kvm.h @@ -1,4 +1,4 @@ -/* $NetBSD: kvm.h,v 1.15 2007/11/08 20:48:04 joerg Exp $ */ +/* $NetBSD: kvm.h,v 1.16 2011/09/12 21:14:29 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -82,6 +82,7 @@ kvm_t *kvm_open kvm_t *kvm_openfiles(const char *, const char *, const char *, int, char *); ssize_t kvm_read(kvm_t *, u_long, void *, size_t); ssize_t kvm_write(kvm_t *, u_long, const void *, size_t); +const char *kvm_getkernelname(kvm_t *); __END_DECLS diff --git a/include/limits.h b/include/limits.h index 447fa8acc..770bd2002 100644 --- a/include/limits.h +++ b/include/limits.h @@ -1,4 +1,4 @@ -/* $NetBSD: limits.h,v 1.29 2010/06/07 13:52:29 tnozaki Exp $ */ +/* $NetBSD: limits.h,v 1.32 2012/03/28 17:04:41 christos Exp $ */ /* * Copyright (c) 1988, 1993 @@ -59,9 +59,37 @@ #define _POSIX_STREAM_MAX 8 #define _POSIX_SYMLINK_MAX 255 #define _POSIX_SYMLOOP_MAX 8 + +/* + * We have not implemented these yet + * + * _POSIX_THREAD_ATTR_STACKADDR + * _POSIX_THREAD_ATTR_STACKSIZE + * _POSIX_THREAD_CPUTIME + * _POSIX_THREAD_PRIORITY_SCHEDULING + * _POSIX_THREAD_PRIO_INHERIT + * _POSIX_THREAD_PRIO_PROTECT + * _POSIX_THREAD_PROCESS_SHARED + * _POSIX_THREAD_SAFE_FUNCTIONS + * _POSIX_THREAD_SPORADIC_SERVER + */ + +/* + * The following 3 are not part of the standard + * but left here for compatibility + */ #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 -#define _POSIX_THREAD_KEYS_MAX 128 +#define _POSIX_THREAD_KEYS_MAX 256 #define _POSIX_THREAD_THREADS_MAX 64 + +/* + * These are the correct names, defined in terms of the above + */ +#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS +#define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX +/* Not yet: PTHREAD_STACK_MIN */ +#define PTHREAD_THREADS_MAX _POSIX_THREAD_THREADS_MAX + #define _POSIX_TIMER_MAX 32 #define _POSIX_TTY_NAME_MAX 9 #define _POSIX_TZNAME_MAX 6 @@ -110,12 +138,44 @@ #define MB_LEN_MAX 32 /* Allow ISO/IEC 2022 */ +/* + * X/Open Extended API set 2 (a.k.a. C063) + * This hides unimplemented functions from GNU configure until + * we are done implementing them. + */ +#if !defined(_INCOMPLETE_XOPEN_C063) +#define __stub_linkat +#define __stub_renameat +#define __stub_mkfifoat +#define __stub_mknodat +#define __stub_mkdirat +#define __stub_faccessat +#define __stub_fchmodat +#define __stub_fchownat +#define __stub_fexecve +#define __stub_fstatat +#define __stub_utimensat +#define __stub_openat +#define __stub_readlinkat +#define __stub_symlinkat +#define __stub_unlinkat +#endif + #include -#include + +#ifdef __CHAR_UNSIGNED__ +# define CHAR_MIN 0 +# define CHAR_MAX UCHAR_MAX +#else +# define CHAR_MIN SCHAR_MIN +# define CHAR_MAX SCHAR_MAX +#endif #ifdef __minix #define SYMLOOP_MAX 16 #define SYMLINK_MAX 1024 -#endif +#endif /* __minix */ + +#include #endif /* !_LIMITS_H_ */ diff --git a/include/math.h b/include/math.h index fe0251c97..46a5e7ecf 100644 --- a/include/math.h +++ b/include/math.h @@ -1,4 +1,4 @@ -/* $NetBSD: math.h,v 1.53 2010/09/15 16:11:30 christos Exp $ */ +/* $NetBSD: math.h,v 1.58 2012/05/05 22:07:57 christos Exp $ */ /* * ==================================================== @@ -88,10 +88,10 @@ extern const union __long_double_u __infinityl; #endif /* 7.12#4 INFINITY */ -#if __GNUC_PREREQ__(3, 3) -#define INFINITY __builtin_inff() -#elif defined(__INFINITY) +#if defined(__INFINITY) #define INFINITY __INFINITY /* float constant which overflows */ +#elif __GNUC_PREREQ__(3, 3) +#define INFINITY __builtin_inff() #else #define INFINITY HUGE_VALF /* positive infinity */ #endif /* __INFINITY */ @@ -321,6 +321,8 @@ float sqrtf(float); float erff(float); float erfcf(float); float lgammaf(float); +float tgammaf(float); +double tgamma(double); /* 7.12.9 nearest integer */ @@ -349,6 +351,10 @@ long long int llroundf(float); float fmodf(float, float); float remainderf(float, float); +/* 7.12.10.3 The remquo functions */ +double remquo(double, double, int *); +float remquof(float, float, int *); + /* 7.12.11 manipulation */ float copysignf(float, float); @@ -493,6 +499,11 @@ int __isinfl(long double); int __isnanl(long double); int __signbitl(long double); #endif + +int ilogbl(long double); +long double logbl(long double); +long double scalbnl(long double, int); + __END_DECLS #endif /* _MATH_H_ */ diff --git a/include/minix/Makefile b/include/minix/Makefile index 2c3cec201..0dd522a2d 100644 --- a/include/minix/Makefile +++ b/include/minix/Makefile @@ -1,8 +1,6 @@ -NOOBJ= # defined - .include -INCSDIR= /usr/include/minix +INCSDIR= /usr/include/minix INCS+= dirent.h paths.h param.h INCS+= acpi.h audio_fw.h bitmap.h \ diff --git a/include/mntopts.h b/include/mntopts.h index 8e76a6e71..fd789833e 100644 --- a/include/mntopts.h +++ b/include/mntopts.h @@ -1,4 +1,4 @@ -/* $NetBSD: mntopts.h,v 1.13 2009/01/12 18:14:20 pooka Exp $ */ +/* $NetBSD: mntopts.h,v 1.14 2011/06/17 14:23:50 manu Exp $ */ /*- * Copyright (c) 1994 @@ -57,6 +57,7 @@ struct mntopt { #define MOPT_SOFTDEP { "softdep", 0, MNT_SOFTDEP, 0 } #define MOPT_LOG { "log", 0, MNT_LOG, 0 } #define MOPT_IGNORE { "hidden", 0, MNT_IGNORE, 0 } +#define MOPT_EXTATTR { "extattr", 0, MNT_EXTATTR, 0 } /* Control flags. */ #define MOPT_FORCE { "force", 0, MNT_FORCE, 0 } diff --git a/include/netdb.h b/include/netdb.h index 98a150d85..c69931287 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -1,4 +1,4 @@ -/* $NetBSD: netdb.h,v 1.64 2010/05/05 17:12:29 christos Exp $ */ +/* $NetBSD: netdb.h,v 1.65 2012/03/17 21:57:48 christos Exp $ */ /* * ++Copyright++ 1980, 1983, 1988, 1993 @@ -272,7 +272,9 @@ struct addrinfo { #define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */ /* valid flags for addrinfo (not a standard def, apps should not use it) */ #define AI_MASK \ - (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV) + (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \ + AI_ADDRCONFIG) +#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ #endif #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ diff --git a/include/nsswitch.h b/include/nsswitch.h index d429b9306..405e09795 100644 --- a/include/nsswitch.h +++ b/include/nsswitch.h @@ -1,4 +1,4 @@ -/* $NetBSD: nsswitch.h,v 1.20 2008/04/28 20:22:54 martin Exp $ */ +/* $NetBSD: nsswitch.h,v 1.21 2011/07/17 20:54:34 joerg Exp $ */ /*- * Copyright (c) 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc. @@ -32,15 +32,8 @@ #ifndef _NSSWITCH_H #define _NSSWITCH_H 1 -/* - * Don't use va_list in prototypes. va_list is typedef'd in two places - * ( and ), so if we include one of - * them here we may collide with the utility's includes. It's unreasonable - * for utilities to have to include one of them to include nsswitch.h, so - * we get _BSD_VA_LIST_ from and use it. - */ -#include #include +#include #define NSS_MODULE_INTERFACE_VERSION 0 @@ -108,7 +101,7 @@ /* * ns_dtab `callback' function signature. */ -typedef int (*nss_method)(void *, void *, _BSD_VA_LIST_); +typedef int (*nss_method)(void *, void *, va_list); /* * ns_dtab - `nsswitch dispatch table' diff --git a/include/paths.h b/include/paths.h index 410f92092..2cf6711e6 100644 --- a/include/paths.h +++ b/include/paths.h @@ -1,4 +1,4 @@ -/* $NetBSD: paths.h,v 1.39 2010/12/29 15:53:57 pooka Exp $ */ +/* $NetBSD: paths.h,v 1.41 2012/06/03 21:42:46 joerg Exp $ */ /* * Copyright (c) 1989, 1993 @@ -61,8 +61,10 @@ #define _PATH_CLOCKCTL "/dev/clockctl" #define _PATH_CONSOLE "/dev/console" #define _PATH_CONSTTY "/dev/constty" +#define _PATH_CPUCTL "/dev/cpuctl" #define _PATH_CSMAPPER "/usr/share/i18n/csmapper" #define _PATH_DEFTAPE "/dev/nrst0" +#define _PATH_DEVCDB "/var/run/dev.cdb" #define _PATH_DEVDB "/var/run/dev.db" #define _PATH_DEVNULL "/dev/null" #define _PATH_DRUM "/dev/drum" diff --git a/include/quota.h b/include/quota.h new file mode 100644 index 000000000..45f5a685b --- /dev/null +++ b/include/quota.h @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by David A. Holland. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _QUOTA_H_ +#define _QUOTA_H_ + +#include +#include + +struct quotahandle; /* Opaque. */ +struct quotacursor; /* Opaque. */ + + +void quotaval_clear(struct quotaval *); + +struct quotahandle *quota_open(const char *); +void quota_close(struct quotahandle *); + +const char *quota_getmountpoint(struct quotahandle *); +const char *quota_getmountdevice(struct quotahandle *); + +const char *quota_getimplname(struct quotahandle *); +unsigned quota_getrestrictions(struct quotahandle *); + +int quota_getnumidtypes(struct quotahandle *); +const char *quota_idtype_getname(struct quotahandle *, int /*idtype*/); + +int quota_getnumobjtypes(struct quotahandle *); +const char *quota_objtype_getname(struct quotahandle *, int /*objtype*/); +int quota_objtype_isbytes(struct quotahandle *, int /*objtype*/); + +int quota_quotaon(struct quotahandle *, int /*idtype*/); +int quota_quotaoff(struct quotahandle *, int /*idtype*/); + +int quota_get(struct quotahandle *, const struct quotakey *, + struct quotaval *); + +int quota_put(struct quotahandle *, const struct quotakey *, + const struct quotaval *); + +int quota_delete(struct quotahandle *, const struct quotakey *); + +struct quotacursor *quota_opencursor(struct quotahandle *); +void quotacursor_close(struct quotacursor *); + +int quotacursor_skipidtype(struct quotacursor *, int /*idtype*/); + +int quotacursor_get(struct quotacursor *, struct quotakey *, + struct quotaval *); + +int quotacursor_getn(struct quotacursor *, struct quotakey *, + struct quotaval *, unsigned /*maxnum*/); + +int quotacursor_atend(struct quotacursor *); +int quotacursor_rewind(struct quotacursor *); + +#endif /* _QUOTA_H_ */ diff --git a/include/resolv.h b/include/resolv.h index c5325f8d9..f1d2d11e2 100644 --- a/include/resolv.h +++ b/include/resolv.h @@ -1,4 +1,4 @@ -/* $NetBSD: resolv.h,v 1.38 2009/10/24 17:23:34 christos Exp $ */ +/* $NetBSD: resolv.h,v 1.39 2012/09/09 18:03:17 christos Exp $ */ /* * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC") @@ -256,7 +256,7 @@ union res_sockaddr_union { #define RES_NO_NIBBLE2 0x80000000 /*%< disable alternate nibble lookup */ #define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | \ - RES_DNSRCH | RES_NO_NIBBLE2) + RES_DNSRCH | RES_NO_NIBBLE2 | RES_NOCHECKNAME) /*% * Resolver "pfcode" values. Used by dig. diff --git a/include/rmt.h b/include/rmt.h index 75b4efc15..0b32b4669 100644 --- a/include/rmt.h +++ b/include/rmt.h @@ -1,4 +1,4 @@ -/* $NetBSD: rmt.h,v 1.6 2010/08/31 05:12:35 enami Exp $ */ +/* $NetBSD: rmt.h,v 1.7 2011/02/16 19:29:35 christos Exp $ */ /* * rmt.h @@ -19,6 +19,11 @@ #include +#if _FORTIFY_SOURCE > 0 +#define __ssp_weak_name(x) rmt ## x +#include +#endif + __BEGIN_DECLS int isrmt(int); int rmtaccess(const char *, int); @@ -49,7 +54,9 @@ __END_DECLS #define lseek rmtlseek #define lstat rmtlstat #define open rmtopen +#if __SSP_FORTIFY_LEVEL == 0 #define read rmtread +#endif #define stat rmtstat #define write rmtwrite #endif /* __RMTLIB_PRIVATE */ diff --git a/include/rpc/clnt.h b/include/rpc/clnt.h index 557f78bd2..48707b2b4 100644 --- a/include/rpc/clnt.h +++ b/include/rpc/clnt.h @@ -1,4 +1,4 @@ -/* $NetBSD: clnt.h,v 1.20 2005/12/03 15:16:19 yamt Exp $ */ +/* $NetBSD: clnt.h,v 1.21 2011/08/30 17:06:20 plunky Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -206,11 +206,13 @@ struct rpc_timers { * struct timeval timeout; */ #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ - ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \ - (const char *)(const void *)(argsp), xres, (caddr_t)(void *)resp, secs)) + ((*(rh)->cl_ops->cl_call)(rh, proc, (xdrproc_t)xargs, \ + (const char *)(const void *)(argsp), (xdrproc_t)xres, \ + (caddr_t)(void *)resp, secs)) #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ - ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, \ - (const char *)(const void *)(argsp), xres, (caddr_t)(void *)resp, secs)) + ((*(rh)->cl_ops->cl_call)(rh, proc, (xdrproc_t)xargs, \ + (const char *)(const void *)(argsp), (xdrproc_t)xres, \ + (caddr_t)(void *)resp, secs)) /* * void diff --git a/include/rpc/svc.h b/include/rpc/svc.h index 93fb4b06b..10f4a64d0 100644 --- a/include/rpc/svc.h +++ b/include/rpc/svc.h @@ -1,4 +1,4 @@ -/* $NetBSD: svc.h,v 1.23 2005/12/26 19:01:47 perry Exp $ */ +/* $NetBSD: svc.h,v 1.24 2011/08/30 17:06:20 plunky Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -163,9 +163,9 @@ struct svc_req { (*(xprt)->xp_ops->xp_stat)(xprt) #define SVC_GETARGS(xprt, xargs, argsp) \ - (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) + (*(xprt)->xp_ops->xp_getargs)((xprt), ((xdrproc_t)(xargs)), (argsp)) #define svc_getargs(xprt, xargs, argsp) \ - (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) + (*(xprt)->xp_ops->xp_getargs)((xprt), ((xdrproc_t)(xargs)), (argsp)) #define SVC_REPLY(xprt, msg) \ (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) @@ -173,9 +173,9 @@ struct svc_req { (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) #define SVC_FREEARGS(xprt, xargs, argsp) \ - (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) + (*(xprt)->xp_ops->xp_freeargs)((xprt), ((xdrproc_t)(xargs)), (argsp)) #define svc_freeargs(xprt, xargs, argsp) \ - (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) + (*(xprt)->xp_ops->xp_freeargs)((xprt), ((xdrproc_t)(xargs)), (argsp)) #define SVC_DESTROY(xprt) \ (*(xprt)->xp_ops->xp_destroy)(xprt) diff --git a/include/rpc/xdr.h b/include/rpc/xdr.h index e506f6a68..f15ccb29b 100644 --- a/include/rpc/xdr.h +++ b/include/rpc/xdr.h @@ -1,4 +1,4 @@ -/* $NetBSD: xdr.h,v 1.25 2005/12/28 15:26:06 yamt Exp $ */ +/* $NetBSD: xdr.h,v 1.27 2011/08/30 17:09:51 plunky Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -130,10 +130,8 @@ typedef struct __rpc_xdr { * The opaque pointer generally points to a structure of the data type * to be decoded. If this pointer is 0, then the type routines should * allocate dynamic storage of the appropriate size and return it. - * - * XXX can't actually prototype it, because some take three args!!! */ -typedef bool_t (*xdrproc_t)(/* XDR *, void *, u_int */); +typedef bool_t (*xdrproc_t)(XDR *, const void *); /* * Operations defined on a XDR handle @@ -313,6 +311,7 @@ extern bool_t xdr_hyper(XDR *, longlong_t *); extern bool_t xdr_u_hyper(XDR *, u_longlong_t *); extern bool_t xdr_longlong_t(XDR *, longlong_t *); extern bool_t xdr_u_longlong_t(XDR *, u_longlong_t *); +extern unsigned long xdr_sizeof(xdrproc_t, void *); __END_DECLS /* diff --git a/include/rpcsvc/ypclnt.h b/include/rpcsvc/ypclnt.h index 4a20db445..90e820993 100644 --- a/include/rpcsvc/ypclnt.h +++ b/include/rpcsvc/ypclnt.h @@ -1,4 +1,4 @@ -/* $NetBSD: ypclnt.h,v 1.13 2005/02/03 04:39:33 perry Exp $ */ +/* $NetBSD: ypclnt.h,v 1.14 2012/03/02 17:27:48 christos Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt @@ -80,6 +80,7 @@ int yp_order (const char *, const char *, int *); int yp_all (const char *, const char *, struct ypall_callback *); char * yperr_string (int); int ypprot_err (unsigned int); +int yp_setbindtries (int); __END_DECLS #endif /* _RPCSVC_YPCLNT_H_ */ diff --git a/include/sched.h b/include/sched.h index 3ac9ac63c..444c66c29 100644 --- a/include/sched.h +++ b/include/sched.h @@ -29,9 +29,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifdef __minix -#define _SCHED_H_ -#endif /* !__minix */ +/* LSC: It seems we actually do not want this header to be visible. */ +#ifndef __minix #ifndef _SCHED_H_ #define _SCHED_H_ @@ -79,3 +78,5 @@ __END_DECLS #endif /* _NETBSD_SOURCE */ #endif /* _SCHED_H_ */ + +#endif /* !__minix */ diff --git a/include/search.h b/include/search.h index bf488f4d3..55fed5a36 100644 --- a/include/search.h +++ b/include/search.h @@ -1,4 +1,4 @@ -/* $NetBSD: search.h,v 1.18 2005/07/06 15:47:15 drochner Exp $ */ +/* $NetBSD: search.h,v 1.19 2011/09/14 23:34:26 christos Exp $ */ /* * Written by J.T. Conklin @@ -21,6 +21,15 @@ typedef struct entry { void *data; } ENTRY; +#ifdef _NETBSD_SOURCE +struct _ENTRY; +struct hsearch_data { + struct _ENTRY *table; + size_t size; + size_t filled; +}; +#endif + typedef enum { FIND, ENTER } ACTION; @@ -46,10 +55,17 @@ __BEGIN_DECLS void *bsearch(const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); #endif /* __BSEARCH_DECLARED */ + int hcreate(size_t); void hdestroy(void); ENTRY *hsearch(ENTRY, ACTION); +#ifdef _NETBSD_SOURCE +int hcreate_r(size_t, struct hsearch_data *); +void hdestroy_r(struct hsearch_data *); +int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); +#endif /* _NETBSD_SOURCE */ + void *lfind(const void *, const void *, size_t *, size_t, int (*)(const void *, const void *)); void *lsearch(const void *, void *, size_t *, size_t, diff --git a/include/semaphore.h b/include/semaphore.h index 55047f77b..d9dee950b 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -1,4 +1,4 @@ -/* $NetBSD: semaphore.h,v 1.3 2008/04/28 20:22:54 martin Exp $ */ +/* $NetBSD: semaphore.h,v 1.4 2012/03/08 21:59:28 joerg Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -40,7 +40,7 @@ typedef struct _sem_st *sem_t; #define SEM_FAILED ((sem_t *)0) #define SEM_VALUE_MAX (~0U) -#include +#include __BEGIN_DECLS int sem_close(sem_t *); @@ -48,6 +48,7 @@ int sem_destroy(sem_t *); int sem_getvalue(sem_t * __restrict, int * __restrict); int sem_init(sem_t *, int, unsigned int); int sem_post(sem_t *); +int sem_timedwait(sem_t *, const struct timespec * __restrict); int sem_trywait(sem_t *); int sem_unlink(const char *); int sem_wait(sem_t *); diff --git a/include/setjmp.h b/include/setjmp.h index b95123554..0608342d6 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -1,4 +1,4 @@ -/* $NetBSD: setjmp.h,v 1.25 2009/08/12 04:57:36 matt Exp $ */ +/* $NetBSD: setjmp.h,v 1.26 2011/11/05 09:27:06 joerg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -62,18 +62,18 @@ typedef _BSD_JBSLOT_T_ jmp_buf[_JBLEN] _JB_ATTRIBUTES; __BEGIN_DECLS #ifndef __LIBC12_SOURCE__ -int setjmp(jmp_buf) __RENAME(__setjmp14); +int setjmp(jmp_buf) __RENAME(__setjmp14) __returns_twice; void longjmp(jmp_buf, int) __RENAME(__longjmp14) __dead; #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \ defined(_NETBSD_SOURCE) -int sigsetjmp(sigjmp_buf, int) __RENAME(__sigsetjmp14); +int sigsetjmp(sigjmp_buf, int) __RENAME(__sigsetjmp14) __returns_twice; void siglongjmp(sigjmp_buf, int) __RENAME(__siglongjmp14) __dead; #endif /* not ANSI */ #endif /* __LIBC12_SOURCE__ */ #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) -int _setjmp(jmp_buf); +int _setjmp(jmp_buf) __returns_twice; void _longjmp(jmp_buf, int) __dead; #endif diff --git a/include/ssp/ssp.h b/include/ssp/ssp.h index af22894d6..59e37f16a 100644 --- a/include/ssp/ssp.h +++ b/include/ssp/ssp.h @@ -1,7 +1,7 @@ -/* $NetBSD: ssp.h,v 1.6 2011/01/20 02:58:17 christos Exp $ */ +/* $NetBSD: ssp.h,v 1.10 2012/08/08 20:23:32 joerg Exp $ */ /*- - * Copyright (c) 2006 The NetBSD Foundation, Inc. + * Copyright (c) 2006, 2011 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -34,39 +34,48 @@ #include #if !defined(__cplusplus) -# if _FORTIFY_SOURCE > 0 && __OPTIMIZE__ > 0 && __GNUC_PREREQ__(4, 1) +# if _FORTIFY_SOURCE > 0 && !defined(__lint__) && \ + (__OPTIMIZE__ > 0 || defined(__clang__)) && __GNUC_PREREQ__(4, 1) # if _FORTIFY_SOURCE > 1 # define __SSP_FORTIFY_LEVEL 2 # else # define __SSP_FORTIFY_LEVEL 1 # endif +# else +# define __SSP_FORTIFY_LEVEL 0 # endif +#else +# define __SSP_FORTIFY_LEVEL 0 #endif -#ifdef _NAMESPACE_H_ -#define __ssp_weak_name(fun) _sys ## fun +/* __ssp_real is used by the implementation in libc */ +#if __SSP_FORTIFY_LEVEL == 0 +#define __ssp_real_(fun) fun #else -#define __ssp_weak_name(fun) _sys_ ## fun +#define __ssp_real_(fun) __ssp_real_ ## fun #endif +#define __ssp_real(fun) __ssp_real_(fun) #define __ssp_inline static __inline __attribute__((__always_inline__)) #define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1) #define __ssp_bos0(ptr) __builtin_object_size(ptr, 0) -#define __ssp_redirect_raw(rtype, fun, args, call, bos) \ -rtype __ssp_weak_name(fun) args; \ -__ssp_inline rtype fun args; \ +#define __ssp_check(buf, len, bos) \ + if (bos(buf) != (size_t)-1 && len > bos(buf)) \ + __chk_fail() +#define __ssp_redirect_raw(rtype, fun, symbol, args, call, bos) \ +rtype __ssp_real_(fun) args __RENAME(symbol); \ +__ssp_inline rtype fun args __RENAME(__ssp_protected_ ## fun); \ __ssp_inline rtype fun args { \ - if (bos(__buf) != (size_t)-1 && __len > bos(__buf)) \ - __chk_fail(); \ - return __ssp_weak_name(fun) call; \ + __ssp_check(__buf, __len, bos); \ + return __ssp_real_(fun) call; \ } #define __ssp_redirect(rtype, fun, args, call) \ - __ssp_redirect_raw(rtype, fun, args, call, __ssp_bos) + __ssp_redirect_raw(rtype, fun, fun, args, call, __ssp_bos) #define __ssp_redirect0(rtype, fun, args, call) \ - __ssp_redirect_raw(rtype, fun, args, call, __ssp_bos0) + __ssp_redirect_raw(rtype, fun, fun, args, call, __ssp_bos0) __BEGIN_DECLS void __stack_chk_fail(void) __dead; diff --git a/include/ssp/stdio.h b/include/ssp/stdio.h index 28d8ace58..b03bccaaf 100644 --- a/include/ssp/stdio.h +++ b/include/ssp/stdio.h @@ -1,4 +1,4 @@ -/* $NetBSD: stdio.h,v 1.4 2010/02/25 18:37:13 joerg Exp $ */ +/* $NetBSD: stdio.h,v 1.5 2011/07/17 20:54:34 joerg Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -37,13 +37,13 @@ __BEGIN_DECLS int __sprintf_chk(char *__restrict, int, size_t, const char *__restrict, ...) __printflike(4, 5); int __vsprintf_chk(char *__restrict, int, size_t, const char *__restrict, - _BSD_VA_LIST_) + __va_list) __printflike(4, 0); int __snprintf_chk(char *__restrict, size_t, int, size_t, const char *__restrict, ...) __printflike(5, 6); int __vsnprintf_chk(char *__restrict, size_t, int, size_t, - const char *__restrict, _BSD_VA_LIST_) + const char *__restrict, __va_list) __printflike(5, 0); char *__gets_chk(char *, size_t); char *__fgets_chk(char *, int, size_t, FILE *); diff --git a/include/ssp/string.h b/include/ssp/string.h index d94b6794c..b9002f760 100644 --- a/include/ssp/string.h +++ b/include/ssp/string.h @@ -1,4 +1,4 @@ -/* $NetBSD: string.h,v 1.4 2009/11/17 20:47:59 drochner Exp $ */ +/* $NetBSD: string.h,v 1.5 2012/07/22 21:05:26 joerg Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -33,6 +33,16 @@ #include +__BEGIN_DECLS +void *__memcpy_chk(void *, const void *, size_t, size_t); +void *__memmove_chk(void *, void *, size_t, size_t); +void *__memset_chk(void *, int, size_t, size_t); +char *__strcat_chk(char *, const char *, size_t); +char *__strcpy_chk(char *, const char *, size_t); +char *__strncat_chk(char *, const char *, size_t, size_t); +char *__strncpy_chk(char *, const char *, size_t, size_t); +__END_DECLS + #if __SSP_FORTIFY_LEVEL > 0 #define __ssp_bos_check3(fun, dst, src, len) \ @@ -74,13 +84,6 @@ __ssp_bos_icheck2_restrict(strcpy, char *, const char *) __ssp_bos_icheck2_restrict(strcat, char *, const char *) __ssp_bos_icheck3_restrict(strncpy, char *, const char *) __ssp_bos_icheck3_restrict(strncat, char *, const char *) -void *__memcpy_chk(void *, const void *, size_t, size_t); -void *__memmove_chk(void *, void *, size_t, size_t); -void *__memset_chk(void *, int, size_t, size_t); -char *__strcat_chk(char *, const char *, size_t); -char *__strcpy_chk(char *, const char *, size_t); -char *__strncat_chk(char *, const char *, size_t, size_t); -char *__strncpy_chk(char *, const char *, size_t, size_t); __END_DECLS #define memcpy(dst, src, len) __ssp_bos_check3(memcpy, dst, src, len) diff --git a/include/ssp/unistd.h b/include/ssp/unistd.h index ee14bc00e..1d7079609 100644 --- a/include/ssp/unistd.h +++ b/include/ssp/unistd.h @@ -1,4 +1,4 @@ -/* $NetBSD: unistd.h,v 1.5 2011/01/19 19:21:29 christos Exp $ */ +/* $NetBSD: unistd.h,v 1.6 2011/01/26 18:07:44 christos Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ __BEGIN_DECLS __ssp_redirect0(ssize_t, read, (int __fd, void *__buf, size_t __len), \ (__fd, __buf, __len)); -__ssp_redirect(int, readlink, (const char *__restrict __path, \ +__ssp_redirect(ssize_t, readlink, (const char *__restrict __path, \ char *__restrict __buf, size_t __len), (__path, __buf, __len)); __ssp_redirect(char *, getcwd, (char *__buf, size_t __len), (__buf, __len)); diff --git a/include/stdio.h b/include/stdio.h index 341de8b5d..a33ba4c5c 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -1,4 +1,4 @@ -/* $NetBSD: stdio.h,v 1.78 2010/09/24 09:21:53 tnozaki Exp $ */ +/* $NetBSD: stdio.h,v 1.82 2012/04/18 19:30:15 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -41,7 +41,6 @@ #include #include -#include #ifdef _BSD_SIZE_T_ typedef _BSD_SIZE_T_ size_t; #undef _BSD_SIZE_T_ @@ -51,6 +50,13 @@ typedef _BSD_SSIZE_T_ ssize_t; #undef _BSD_SSIZE_T_ #endif +#if defined(_POSIX_C_SOURCE) +#ifndef __VA_LIST_DECLARED +typedef __va_list va_list; +#define __VA_LIST_DECLARED +#endif +#endif + #include /* @@ -58,13 +64,10 @@ typedef _BSD_SSIZE_T_ ssize_t; * innards of an fpos_t anyway. The library internally uses off_t, * which we assume is exactly as big as eight chars. */ -#if (!defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)) || defined(_LIBC) -typedef __off_t fpos_t; -#else typedef struct __sfpos { __off_t _pos; + __mbstate_t _mbstate_in, _mbstate_out; } fpos_t; -#endif #define _FSTDIO /* Define for new stdio with functions. */ @@ -118,9 +121,9 @@ typedef struct __sFILE { /* operations */ void *_cookie; /* cookie passed to io functions */ int (*_close)(void *); - int (*_read) (void *, char *, int); - fpos_t (*_seek) (void *, fpos_t, int); - int (*_write)(void *, const char *, int); + ssize_t (*_read) (void *, void *, size_t); + __off_t (*_seek) (void *, __off_t, int); + ssize_t (*_write)(void *, const void *, size_t); /* file extension */ struct __sbuf _ext; @@ -133,16 +136,17 @@ typedef struct __sFILE { unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ unsigned char _nbuf[1]; /* guarantee a getc() buffer */ + int (*_flush)(void *); /* Formerly used by fgetln/fgetwln; kept for binary compatibility */ - struct __sbuf _lb__unused; + char _lb_unused[sizeof(struct __sbuf) - sizeof(int (*)(void *))]; /* Unix stdio files get aligned to block boundaries on fseek() */ int _blksize; /* stat.st_blksize (may be != _bf._size) */ - fpos_t _offset; /* current lseek offset */ + __off_t _offset; /* current lseek offset */ } FILE; __BEGIN_DECLS -extern FILE __sF[]; +extern FILE __sF[3]; __END_DECLS #define __SLBF 0x0001 /* line buffered */ @@ -222,7 +226,6 @@ int feof(FILE *); int ferror(FILE *); int fflush(FILE *); int fgetc(FILE *); -int fgetpos(FILE * __restrict, fpos_t * __restrict); char *fgets(char * __restrict, int, FILE * __restrict); FILE *fopen(const char * __restrict , const char * __restrict); int fprintf(FILE * __restrict , const char * __restrict, ...) @@ -235,7 +238,6 @@ FILE *freopen(const char * __restrict, const char * __restrict, int fscanf(FILE * __restrict, const char * __restrict, ...) __scanflike(2, 3); int fseek(FILE *, long, int); -int fsetpos(FILE *, const fpos_t *); long ftell(FILE *); size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); int getc(FILE *); @@ -259,9 +261,9 @@ int sscanf(const char * __restrict, const char * __restrict, ...) __scanflike(2, 3); FILE *tmpfile(void); int ungetc(int, FILE *); -int vfprintf(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_) +int vfprintf(FILE * __restrict, const char * __restrict, __va_list) __printflike(2, 0); -int vprintf(const char * __restrict, _BSD_VA_LIST_) +int vprintf(const char * __restrict, __va_list) __printflike(1, 0); #ifndef __AUDIT__ @@ -270,7 +272,7 @@ int sprintf(char * __restrict, const char * __restrict, ...) __printflike(2, 3); char *tmpnam(char *); int vsprintf(char * __restrict, const char * __restrict, - _BSD_VA_LIST_) + __va_list) __printflike(2, 0); #endif @@ -281,6 +283,10 @@ int rename (const char *, const char *); #endif __END_DECLS +#ifndef __LIBC12_SOURCE__ +int fgetpos(FILE * __restrict, fpos_t * __restrict) __RENAME(__fgetpos50); +int fsetpos(FILE *, const fpos_t *) __RENAME(__fsetpos50); +#endif /* * IEEE Std 1003.1-90 */ @@ -340,7 +346,7 @@ __BEGIN_DECLS int snprintf(char * __restrict, size_t, const char * __restrict, ...) __printflike(3, 4); int vsnprintf(char * __restrict, size_t, const char * __restrict, - _BSD_VA_LIST_) + __va_list) __printflike(3, 0); __END_DECLS #endif @@ -381,12 +387,12 @@ __END_DECLS */ #if defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE) __BEGIN_DECLS -int vscanf(const char * __restrict, _BSD_VA_LIST_) +int vscanf(const char * __restrict, __va_list) __scanflike(1, 0); -int vfscanf(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_) +int vfscanf(FILE * __restrict, const char * __restrict, __va_list) __scanflike(2, 0); int vsscanf(const char * __restrict, const char * __restrict, - _BSD_VA_LIST_) + __va_list) __scanflike(2, 0); __END_DECLS #endif /* _ISOC99_SOURCE || _NETBSD_SOURCE */ @@ -411,7 +417,7 @@ int fpurge(FILE *); void setbuffer(FILE *, char *, int); int setlinebuf(FILE *); int vasprintf(char ** __restrict, const char * __restrict, - _BSD_VA_LIST_) + __va_list) __printflike(2, 0); const char *fmtcheck(const char *, const char *) __format_arg(2); @@ -422,13 +428,21 @@ __END_DECLS */ __BEGIN_DECLS FILE *funopen(const void *, - int (*)(void *, char *, int), - int (*)(void *, const char *, int), - fpos_t (*)(void *, fpos_t, int), - int (*)(void *)); + int (*)(void *, char *, int), + int (*)(void *, const char *, int), + off_t (*)(void *, off_t, int), + int (*)(void *)); +FILE *funopen2(const void *, + ssize_t (*)(void *, void *, size_t), + ssize_t (*)(void *, const void *, size_t), + off_t (*)(void *, off_t, int), + int (*)(void *), + int (*)(void *)); __END_DECLS #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) +#define fropen2(cookie, fn) funopen2(cookie, fn, 0, 0, 0, 0) +#define fwopen2(cookie, fn) funopen2(cookie, 0, fn, 0, 0, 0) #endif /* _NETBSD_SOURCE */ /* @@ -493,7 +507,7 @@ static __inline int __sputc(int _c, FILE *_p) { #endif /* !_ANSI_SOURCE */ #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE) -int vdprintf(int, const char * __restrict, _BSD_VA_LIST_) +int vdprintf(int, const char * __restrict, __va_list) __printflike(2, 0); int dprintf(int, const char * __restrict, ...) __printflike(2, 3); diff --git a/include/stdlib.h b/include/stdlib.h index 63d334719..124be16b7 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -1,4 +1,4 @@ -/* $NetBSD: stdlib.h,v 1.94 2010/12/22 19:47:56 jruoho Exp $ */ +/* $NetBSD: stdlib.h,v 1.100 2012/06/21 21:13:29 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -144,7 +144,6 @@ size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t); int rand_r(unsigned int *); #endif - /* * X/Open Portability Guide >= Issue 4 */ @@ -160,7 +159,9 @@ unsigned short * seed48(unsigned short[3]); void srand48(long); -int putenv(char *); +#ifndef __LIBC12_SOURCE__ +int putenv(char *) __RENAME(__putenv50); +#endif #endif @@ -190,7 +191,7 @@ char *mktemp(char *) int setkey(const char *); -char *realpath(const char *, char *); +char *realpath(const char * __restrict, char * __restrict); int ttyslot(void); @@ -245,6 +246,7 @@ void *alloca(int); /* built-in for gcc */ #elif defined(__PCC__) && !defined(__GNUC__) #define alloca(size) __builtin_alloca(size) #elif (__GNUC__ >= 2) +/* LSC: MINIX Patch needed (2 following lines) */ #define alloca(size) __builtin_alloca(size) #else void *alloca(size_t); @@ -252,6 +254,8 @@ void *alloca(size_t); uint32_t arc4random(void); void arc4random_stir(void); +void arc4random_buf(void *, size_t); +uint32_t arc4random_uniform(uint32_t); void arc4random_addrandom(u_char *, int); char *getbsize(int *, long *); char *cgetcap(char *, const char *, int); @@ -268,6 +272,7 @@ void csetexpandtc(int); int daemon(int, int); #ifndef __minix +int devname_r(dev_t, mode_t, char *, size_t); #ifndef __LIBC12_SOURCE__ __aconst char *devname(dev_t, mode_t) __RENAME(__devname50); #endif diff --git a/include/string.h b/include/string.h index 98825fb70..a02ab19e7 100644 --- a/include/string.h +++ b/include/string.h @@ -1,4 +1,4 @@ -/* $NetBSD: string.h,v 1.39 2009/07/22 19:48:27 kleink Exp $ */ +/* $NetBSD: string.h,v 1.41 2012/08/30 12:16:48 drochner Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -96,9 +96,11 @@ __aconst char *strsignal(int); * strxfrm_l */ #endif +__END_DECLS #if defined(_NETBSD_SOURCE) #include /* for backwards-compatibilty */ +__BEGIN_DECLS void *memmem(const void *, size_t, const void *, size_t); char *strcasestr(const char *, const char *); size_t strlcat(char *, const char *, size_t); @@ -107,8 +109,10 @@ char *strsep(char **, const char *); char *stresep(char **, const char *, int); char *strndup(const char *, size_t); void *memrchr(const void *, int, size_t); -#endif +void __explicit_bzero(void *, size_t); +int __consttime_bcmp(const void *, const void *, size_t); __END_DECLS +#endif #if _FORTIFY_SOURCE > 0 #include diff --git a/include/strings.h b/include/strings.h index dc90dcb35..26be65840 100644 --- a/include/strings.h +++ b/include/strings.h @@ -1,4 +1,4 @@ -/* $NetBSD: strings.h,v 1.17 2009/08/19 04:22:53 yamt Exp $ */ +/* $NetBSD: strings.h,v 1.18 2011/08/22 01:24:15 dholland Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -46,7 +46,7 @@ typedef _BSD_SIZE_T_ size_t; #include -#include +#include __BEGIN_DECLS int bcmp(const void *, const void *, size_t); @@ -57,8 +57,8 @@ char *index(const char *, int); unsigned int popcount(unsigned int) __constfunc; unsigned int popcountl(unsigned long) __constfunc; unsigned int popcountll(unsigned long long) __constfunc; -unsigned int popcount32(uint32_t) __constfunc; -unsigned int popcount64(uint64_t) __constfunc; +unsigned int popcount32(__uint32_t) __constfunc; +unsigned int popcount64(__uint64_t) __constfunc; char *rindex(const char *, int); int strcasecmp(const char *, const char *); int strncasecmp(const char *, const char *, size_t); diff --git a/include/time.h b/include/time.h index 7360bc629..563168074 100644 --- a/include/time.h +++ b/include/time.h @@ -1,4 +1,4 @@ -/* $NetBSD: time.h,v 1.40 2010/12/16 18:36:47 christos Exp $ */ +/* $NetBSD: time.h,v 1.41 2012/10/02 01:42:06 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -156,6 +156,7 @@ extern int getdate_err; #include /* XXX for struct timespec */ struct sigevent; struct itimerspec; +int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); #ifndef __LIBC12_SOURCE__ #ifndef __minix int clock_getres(clockid_t, struct timespec *) @@ -225,9 +226,9 @@ size_t strftime_z(const timezone_t, char * __restrict, size_t, #endif /* _NETBSD_SOURCE */ -#ifdef _MINIX +#ifdef __minix int stime(time_t *_top); -#endif /* _MINIX */ +#endif /* __minix */ __END_DECLS diff --git a/include/ucontext.h b/include/ucontext.h index 8dad20d4d..e5654e506 100644 --- a/include/ucontext.h +++ b/include/ucontext.h @@ -1,4 +1,4 @@ -/* $NetBSD: ucontext.h,v 1.6 2009/03/19 08:04:38 uebayasi Exp $ */ +/* $NetBSD: ucontext.h,v 1.7 2011/11/05 09:27:06 joerg Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ #include __BEGIN_DECLS -int getcontext(ucontext_t *); +int getcontext(ucontext_t *) __returns_twice; int setcontext(const ucontext_t *); void makecontext(ucontext_t *, void (*)(), int, ...); int swapcontext(ucontext_t * __restrict, const ucontext_t * __restrict); diff --git a/include/unistd.h b/include/unistd.h index ef0a30a8e..55a146bac 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -1,4 +1,4 @@ -/* $NetBSD: unistd.h,v 1.125 2011/01/19 19:21:29 christos Exp $ */ +/* $NetBSD: unistd.h,v 1.135 2012/07/14 15:06:26 darrenr Exp $ */ /*- * Copyright (c) 1998, 1999, 2008 The NetBSD Foundation, Inc. @@ -259,8 +259,6 @@ __pure int getpagesize(void); /* legacy */ #ifndef __minix pid_t getpgid(pid_t); -#endif /* !__minix */ -#ifndef __minix #if defined(_XOPEN_SOURCE) int lchown(const char *, uid_t, gid_t) __RENAME(__posix_lchown); #else @@ -284,7 +282,7 @@ void sync(void); useconds_t ualarm(useconds_t, useconds_t); int usleep(useconds_t); #ifndef __LIBC12_SOURCE__ -pid_t vfork(void) __RENAME(__vfork14); +pid_t vfork(void) __RENAME(__vfork14) __returns_twice; #endif #ifndef __AUDIT__ @@ -301,6 +299,24 @@ ssize_t pread(int, void *, size_t, off_t); ssize_t pwrite(int, const void *, size_t, off_t); #endif +/* + * X/Open Extended API set 2 (a.k.a. C063) + */ +#if defined(_INCOMPLETE_XOPEN_C063) +int linkat(int, const char *, int, const char *, int); +int renameat(int, const char *, int, const char *); +int mkfifoat(int, const char *, mode_t); +int mknodat(int, const char *, mode_t, uint32_t); +int mkdirat(int, const char *, mode_t); +int faccessat(int, const char *, int, int); +int fchmodat(int, const char *, mode_t, int); +int fchownat(int, const char *, uid_t, gid_t, int); +int fexecve(int, char * const *, char * const *); +int readlinkat(int, const char *, char *, size_t); +int symlinkat(const char *, int, const char *); +int unlinkat(int, const char *, int); +#endif + /* * Implementation-defined extensions @@ -331,6 +347,7 @@ int acct(const char *); int closefrom(int); int des_cipher(const char *, char *, long, int); int des_setkey(const char *); +int dup3(int, int, int); void endusershell(void); int exect(const char *, char * const *, char * const *); int fchroot(int); @@ -339,6 +356,20 @@ int getdomainname(char *, size_t); int getgrouplist(const char *, gid_t, gid_t *, int *); int getgroupmembership(const char *, gid_t, gid_t *, int, int *); mode_t getmode(const void *, mode_t); +char *getpassfd(const char *, char *, size_t, int *, int, int); +#define GETPASS_NEED_TTY 0x001 /* Fail if we cannot set tty */ +#define GETPASS_FAIL_EOF 0x002 /* Fail on EOF */ +#define GETPASS_BUF_LIMIT 0x004 /* beep on buffer limit */ +#define GETPASS_NO_SIGNAL 0x008 /* don't make ttychars send signals */ +#define GETPASS_NO_BEEP 0x010 /* don't beep */ +#define GETPASS_ECHO 0x020 /* echo characters as they are typed */ +#define GETPASS_ECHO_STAR 0x040 /* echo '*' for each character */ +#define GETPASS_7BIT 0x080 /* mask the high bit each char */ +#define GETPASS_FORCE_LOWER 0x100 /* lowercase each char */ +#define GETPASS_FORCE_UPPER 0x200 /* uppercase each char */ +#define GETPASS_ECHO_NL 0x400 /* echo a newline if successful */ + +char *getpass_r(const char *, char *, size_t); int getpeereid(int, uid_t *, gid_t *); int getsubopt(char **, char * const *, char **); __aconst char *getusershell(void); @@ -347,12 +378,13 @@ int iruserok(uint32_t, int, const char *, const char *); int issetugid(void); int nfssvc(int, void *); #ifndef __minix +int pipe2(int *, int); int profil(char *, size_t, u_long, u_int); #endif /* !__minix */ #ifndef __PSIGNAL_DECLARED #define __PSIGNAL_DECLARED /* also in signal.h */ -void psignal(int, const char *); +void psignal(int, const char *); #endif /* __PSIGNAL_DECLARED */ int rcmd(char **, int, const char *, const char *, const char *, int *); #ifdef __minix @@ -392,6 +424,7 @@ int undelete(const char *); int rcmd_af(char **, int, const char *, const char *, const char *, int *, int); int rresvport_af(int *, int); +int rresvport_af_addr(int *, int, void *); int iruserok_sa(const void *, int, int, const char *, const char *); #endif diff --git a/include/vis.h b/include/vis.h index 7c06b040f..5e8d1d31e 100644 --- a/include/vis.h +++ b/include/vis.h @@ -1,4 +1,4 @@ -/* $NetBSD: vis.h,v 1.18 2010/11/27 19:44:54 christos Exp $ */ +/* $NetBSD: vis.h,v 1.19 2011/03/12 19:52:45 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -61,6 +61,7 @@ #define VIS_MIMESTYLE 0x100 /* mime-style escape = HEX HEX */ #define VIS_HTTP1866 0x200 /* http-style &#num; or &string; */ #define VIS_NOESCAPE 0x400 /* don't decode `\' */ +#define _VIS_END 0x800 /* for unvis */ /* * unvis return codes @@ -74,21 +75,37 @@ /* * unvis flags */ -#define UNVIS_END 1 /* no more characters */ +#define UNVIS_END _VIS_END /* no more characters */ #include __BEGIN_DECLS char *vis(char *, int, int, int); +char *nvis(char *, size_t, int, int, int); + char *svis(char *, int, int, int, const char *); +char *snvis(char *, size_t, int, int, int, const char *); + int strvis(char *, const char *, int); +int strnvis(char *, size_t, const char *, int); + int strsvis(char *, const char *, int, const char *); +int strsnvis(char *, size_t, const char *, int, const char *); + int strvisx(char *, const char *, size_t, int); +int strnvisx(char *, size_t, const char *, size_t, int); + int strsvisx(char *, const char *, size_t, int, const char *); +int strsnvisx(char *, size_t, const char *, size_t, int, const char *); + int strunvis(char *, const char *); +int strnunvis(char *, size_t, const char *); + int strunvisx(char *, const char *, int); +int strnunvisx(char *, size_t, const char *, int); + #ifndef __LIBC12_SOURCE__ -int unvis(char *, int, int *, int) __RENAME(__unvis13); +int unvis(char *, int, int *, int) __RENAME(__unvis50); #endif __END_DECLS diff --git a/include/wchar.h b/include/wchar.h index e7fc28349..686704298 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -1,4 +1,4 @@ -/* $NetBSD: wchar.h,v 1.29 2010/03/27 22:14:09 tnozaki Exp $ */ +/* $NetBSD: wchar.h,v 1.30 2011/07/17 20:54:34 joerg Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -86,6 +86,13 @@ typedef _BSD_SIZE_T_ size_t; #undef _BSD_SIZE_T_ #endif +#if defined(_POSIX_C_SOURCE) +#ifndef __VA_LIST_DECLARED +typedef __va_list va_list; +#define __VA_LIST_DECLARED +#endif +#endif + struct tm; __BEGIN_DECLS @@ -167,18 +174,18 @@ int fwprintf(FILE * __restrict, const wchar_t * __restrict, ...); int fwscanf(FILE * __restrict, const wchar_t * __restrict, ...); int swprintf(wchar_t * __restrict, size_t n, const wchar_t * __restrict, ...); int swscanf(const wchar_t * __restrict, const wchar_t * __restrict, ...); -int vfwprintf(FILE * __restrict, const wchar_t * __restrict, _BSD_VA_LIST_); +int vfwprintf(FILE * __restrict, const wchar_t * __restrict, __va_list); int vswprintf(wchar_t * __restrict, size_t, const wchar_t * __restrict, - _BSD_VA_LIST_); -int vwprintf(const wchar_t * __restrict, _BSD_VA_LIST_); + __va_list); +int vwprintf(const wchar_t * __restrict, __va_list); int wprintf(const wchar_t * __restrict, ...); int wscanf(const wchar_t * __restrict, ...); #if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) > 199901L || \ defined(_NETBSD_SOURCE) -int vfwscanf(FILE * __restrict, const wchar_t * __restrict, _BSD_VA_LIST_); +int vfwscanf(FILE * __restrict, const wchar_t * __restrict, __va_list); int vswscanf(const wchar_t * __restrict, const wchar_t * __restrict, - _BSD_VA_LIST_); -int vwscanf(const wchar_t * __restrict, _BSD_VA_LIST_); + __va_list); +int vwscanf(const wchar_t * __restrict, __va_list); #endif #if defined(_NETBSD_SOURCE) struct tinfo; diff --git a/kernel/Makefile b/kernel/Makefile index 7ec5af9c6..7bcde0eeb 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,6 +1,8 @@ # Makefile for kernel .include +BINDIR= /usr/sbin +MAN= PROG= kernel .include "arch/${MACHINE_ARCH}/Makefile.inc" @@ -8,29 +10,28 @@ PROG= kernel SRCS+= clock.c cpulocals.c interrupt.c main.c proc.c system.c \ table.c utility.c usermapped_data.c -LINKERSCRIPT=${.CURDIR}/arch/${MACHINE_ARCH}/kernel.lds +DPADD+= ${LIBTIMERS} ${LIBSYS} ${LIBEXEC} ${LIBMINLIB} +LDADD+= -ltimers -lsys -lexec -lminlib -L/usr/lib -DPADD+= ${LIBTIMERS} ${LIBSYS} ${LIBEXEC} ${LINKERSCRIPT} -LDADD+= -ltimers -lsys -lexec +LINKERSCRIPT= ${.CURDIR}/arch/${MACHINE_ARCH}/kernel.lds -CFLAGS += -D__kernel__ - -CPPFLAGS+= -fno-stack-protector -D_NETBSD_SOURCE -D_MINIX LDFLAGS+= -T ${LINKERSCRIPT} -LDFLAGS+= -nostdlib -L${DESTDIR}/${LIBDIR} -LDADD+= -lminlib -DPADD+= ${LIBMINLIB} -.if !empty(CC:M*gcc) -LDADD+= -lgcc -lsys -lgcc -lminc -.elif !empty(CC:M*clang) -LDADD+= -L/usr/pkg/compiler-rt/lib -lCompilerRT-Generic -lsys -lCompilerRT-Generic -lminc -DPADD+= ${LIBC} -.endif +LDFLAGS+= -nostdlib +CFLAGS += -fno-stack-protector -CPPFLAGS+= -I${.CURDIR} -I${.CURDIR}/arch/${MACHINE_ARCH}/include -I${NETBSDSRCDIR} +CPPFLAGS+= -D_NETBSD_SOURCE -D_MINIX -D__kernel__ -BINDIR= /usr/sbin -MAN= +# kernel headers are always called through kernel/*.h +CPPFLAGS+= -I${NETBSDSRCDIR} + +# kernel headers are always called through kernel/*.hi, this +# time for generated headers, during cross compilation +CPPFLAGS+= -I${.OBJDIR}/.. + +# Machine-dependent headers, order is important! +CPPFLAGS+= -I${.CURDIR}/arch/${MACHINE_ARCH} +CPPFLAGS+= -I${.CURDIR}/arch/${MACHINE_ARCH}/include +CPPFLAGS+= -I${NETBSDSRCDIR}/include/arch/${MACHINE_ARCH}/include .include "system/Makefile.inc" @@ -69,12 +70,10 @@ CPPFLAGS+= -DUSE_STATECTL CPPFLAGS+= -DUSE_TRACE .endif -.include +CLEANFILES+=extracted-errno.h extracted-mfield.h extracted-mtype.h procoffsets.h debug.d: extracted-errno.h extracted-mfield.h extracted-mtype.h -CLEANFILES+=extracted-errno.h extracted-mfield.h extracted-mtype.h procoffsets.h - extracted-errno.h: extract-errno.sh ../include/errno.h ${_MKTARGET_CREATE} cd ${.CURDIR} ; ${HOST_SH} extract-errno.sh > ${.OBJDIR}/extracted-errno.h @@ -87,7 +86,4 @@ extracted-mtype.h: extract-mtype.sh ../include/minix/com.h ${_MKTARGET_CREATE} cd ${.CURDIR} ; ${HOST_SH} extract-mtype.sh > ${.OBJDIR}/extracted-mtype.h -clean: - rm -f extracted-errno.h extracted-mfield.h extracted-mtype.h - - +.include diff --git a/kernel/arch/arm/direct_tty_utils.c b/kernel/arch/arm/direct_tty_utils.c index 7b7207859..2bd190a4c 100644 --- a/kernel/arch/arm/direct_tty_utils.c +++ b/kernel/arch/arm/direct_tty_utils.c @@ -1,5 +1,5 @@ -#include "kernel.h" +#include "kernel/kernel.h" #include #include #include diff --git a/kernel/arch/arm/mpx.S b/kernel/arch/arm/mpx.S index d40a1fd7c..e16d9562d 100644 --- a/kernel/arch/arm/mpx.S +++ b/kernel/arch/arm/mpx.S @@ -14,7 +14,7 @@ /* sections */ #include -#include "../../kernel.h" +#include "kernel/kernel.h" #include #include #include diff --git a/kernel/arch/arm/pg_utils.c b/kernel/arch/arm/pg_utils.c index 1d3bec48e..ad333a9a0 100644 --- a/kernel/arch/arm/pg_utils.c +++ b/kernel/arch/arm/pg_utils.c @@ -4,7 +4,7 @@ #include #include #include -#include "kernel.h" +#include "kernel/kernel.h" #include "arch_proto.h" #include diff --git a/kernel/arch/arm/pre_init.c b/kernel/arch/arm/pre_init.c index ea7e5aa45..602cc0678 100644 --- a/kernel/arch/arm/pre_init.c +++ b/kernel/arch/arm/pre_init.c @@ -1,7 +1,7 @@ #define UNPAGED 1 /* for proper kmain() prototype */ -#include "kernel.h" +#include "kernel/kernel.h" #include #include #include diff --git a/kernel/arch/arm/procoffsets.cf b/kernel/arch/arm/procoffsets.cf index 3f592535a..c64213c78 100644 --- a/kernel/arch/arm/procoffsets.cf +++ b/kernel/arch/arm/procoffsets.cf @@ -1,6 +1,6 @@ -include "kernel.h" -include "proc.h" +include "kernel/kernel.h" +include "kernel/proc.h" struct proc member REG0 p_reg.retreg diff --git a/kernel/arch/i386/Makefile.inc b/kernel/arch/i386/Makefile.inc index b4ca69ddf..98909456d 100644 --- a/kernel/arch/i386/Makefile.inc +++ b/kernel/arch/i386/Makefile.inc @@ -1,16 +1,50 @@ - # Makefile for arch-dependent kernel code .include HERE=${.CURDIR}/arch/${MACHINE_ARCH} .PATH: ${HERE} -# objects we want unpaged from -lminlib, -lminc +# objects we want unpaged from -lminlib MINLIB_OBJS_UNPAGED=_cpufeature.o _cpuid.o get_bp.o -MINC_OBJS_UNPAGED=strcat.o strlen.o memcpy.o strcpy.o strncmp.o memset.o \ - memmove.o strcmp.o atoi.o ctype_.o _stdfile.o strtol.o _errno.o errno.o \ - udivdi3.o umoddi3.o qdivrem.o -SYS_OBJS_UNPAGED=kprintf.o vprintf.o assert.o stacktrace.o +_cpufeature.o: ${NETBSDSRCDIR}/lib/libminlib/${MACHINE_ARCH}/_cpufeature.c +_cpuid.o: ${NETBSDSRCDIR}/lib/libminlib/${MACHINE_ARCH}/_cpuid.S +get_bp.o: ${NETBSDSRCDIR}/lib/libminlib/${MACHINE_ARCH}/get_bp.S + +# objects we want unpaged from -lsys +SYS_OBJS_UNPAGED=assert.o kprintf.o stacktrace.o vprintf.o +assert.o: ${NETBSDSRCDIR}/lib/libsys/assert.c +kprintf.o: ${NETBSDSRCDIR}/lib/libsys/kprintf.c +stacktrace.o: ${NETBSDSRCDIR}/lib/libsys/stacktrace.c +vprintf.o: ${NETBSDSRCDIR}/lib/libsys/vprintf.c + +# objects we want unpaged from -lminc +MINC_OBJS_UNPAGED=findfp.o strcat.o strlen.o memcpy.o strcpy.o strncmp.o \ + memset.o memmove.o strcmp.o atoi.o ctype_.o strtol.o \ + _errno.o errno.o udivdi3.o umoddi3.o qdivrem.o +memcpy.o: ${NETBSDSRCDIR}/common/lib/libc/string/memcpy.c +memmove.o: ${NETBSDSRCDIR}/common/lib/libc/string/memmove.c +memset.o: ${NETBSDSRCDIR}/common/lib/libc/string/memset.c +strcat.o: ${NETBSDSRCDIR}/common/lib/libc/string/strcat.c +strlen.o: ${NETBSDSRCDIR}/common/lib/libc/string/strlen.c +strcpy.o: ${NETBSDSRCDIR}/common/lib/libc/string/strcpy.c +strcmp.o: ${NETBSDSRCDIR}/common/lib/libc/string/strcmp.c +strncmp.o: ${NETBSDSRCDIR}/common/lib/libc/string/strncmp.c +udivdi3.o: ${NETBSDSRCDIR}/common/lib/libc/quad/udivdi3.c +umoddi3.o: ${NETBSDSRCDIR}/common/lib/libc/quad/umoddi3.c +qdivrem.o: ${NETBSDSRCDIR}/common/lib/libc/quad/qdivrem.c +atoi.o: ${NETBSDSRCDIR}/lib/libc/stdlib/atoi.c +strtol.o: ${NETBSDSRCDIR}/lib/libc/stdlib/strtol.c +findfp.o: ${NETBSDSRCDIR}/lib/libc/stdio/findfp.c +ctype_.o: ${NETBSDSRCDIR}/lib/libc/gen/ctype_.c +_errno.o: ${NETBSDSRCDIR}/lib/libc/gen/_errno.c +errno.o: ${NETBSDSRCDIR}/lib/libc/gen/errno.c + +# Specific flags needed to compile a few of the object files. +CPPFLAGS.strtol.c+= -I ${NETBSDSRCDIR}/common/lib/libc/stdlib +CPPFLAGS.ctype_.c+= -I ${NETBSDSRCDIR}/lib/libc/locale +CPPFLAGS._errno.c+= -I ${NETBSDSRCDIR}/lib/libc/include +CPPFLAGS.assert.c+= -I ${NETBSDSRCDIR}/lib/libc/include +CPPFLAGS.findfp.c+= -I ${NETBSDSRCDIR}/lib/libc/include # some object files we give a symbol prefix (or namespace) of __k_unpaged_ # that must live in their own unique namespace. @@ -19,18 +53,12 @@ SYS_OBJS_UNPAGED=kprintf.o vprintf.o assert.o stacktrace.o io_inb.o pg_utils.o klib.o utility.o arch_reset.o \ ${MINLIB_OBJS_UNPAGED} ${MINC_OBJS_UNPAGED} ${SYS_OBJS_UNPAGED} unpaged_${UNPAGED_OBJ}: ${UNPAGED_OBJ} - ${OBJCOPY} --prefix-symbols=__k_unpaged_ ${UNPAGED_OBJ} unpaged_${UNPAGED_OBJ} + ${OBJCOPY} --prefix-symbols=__k_unpaged_ ${.OBJDIR}/${UNPAGED_OBJ} $@ UNPAGED_OBJS += unpaged_${UNPAGED_OBJ} ORIG_UNPAGED_OBJS += ${UNPAGED_OBJ} .endfor -# we have to extract some object files from libminc.a and libminlib.a -${MINLIB_OBJS_UNPAGED} ${MINC_OBJS_UNPAGED} ${SYS_OBJS_UNPAGED}: ${LIBMINLIB} ${LIBMINC} ${LIBSYS} - ${AR} x ${LIBMINLIB} ${MINLIB_OBJS_UNPAGED} - ${AR} x ${LIBMINC} ${MINC_OBJS_UNPAGED} - ${AR} x ${LIBSYS} ${SYS_OBJS_UNPAGED} - -CLEANFILES+= $(ORIG_UNPAGED_OBJS) +CLEANFILES+= ${ORIG_UNPAGED_OBJS} SRCS+= mpx.S arch_clock.c arch_do_vmctl.c arch_system.c \ do_iopenable.c do_readbios.c do_sdevio.c exception.c i8259.c io_inb.S \ @@ -40,6 +68,10 @@ SRCS+= mpx.S arch_clock.c arch_do_vmctl.c arch_system.c \ OBJS.kernel+= ${UNPAGED_OBJS} +.ifdef CONFIG_SMP +SRCS += arch_smp.c trampoline.S +.endif + .if ${USE_ACPI} != "no" SRCS+= acpi.c CPPFLAGS+= -DUSE_ACPI @@ -59,25 +91,18 @@ SRCS+= arch_watchdog.c CPPFLAGS+= -DUSE_WATCHDOG .endif -sconst.h: procoffsets.h -apic_asm.S head.S klib16.S klib.S mpx.S: sconst.h SRCS+= procoffsets.h -CPPFLAGS+=-I. -# It's OK to hardcode the arch as i386 here as this and procoffsets.cf -# are i386-specific. -TMP=procoffsets.h.tmp -INCLS=../include/arch/i386/include/ PROCOFFSETSCF=procoffsets.cf -procoffsets.h: ${PROCOFFSETSCF} kernel.h proc.h ${INCLS}/stackframe.h ${INCLS}/archtypes.h +.PATH: ${NETBSDSRCDIR}/include/arch/${MACHINE_ARCH}/include + +procoffsets.h: ${PROCOFFSETSCF} kernel.h proc.h stackframe.h archtypes.h ${_MKTARGET_CREATE} ${TOOL_CAT} ${HERE}/${PROCOFFSETSCF} | \ - ${TOOL_GENASSYM} -- ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} >$TMP && \ - mv -f $TMP $@ - -.ifdef CONFIG_SMP -SRCS += arch_smp.c trampoline.S -.endif + ${TOOL_GENASSYM} -- ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} >$@.tmp && \ + mv -f $@.tmp $@ +sconst.h: procoffsets.h +apic_asm.S head.S klib16.S klib.S mpx.S: sconst.h diff --git a/kernel/arch/i386/arch_clock.c b/kernel/arch/i386/arch_clock.c index 62111f360..ee20d2961 100644 --- a/kernel/arch/i386/arch_clock.c +++ b/kernel/arch/i386/arch_clock.c @@ -10,14 +10,14 @@ #include "kernel/interrupt.h" #include #include "glo.h" -#include "profile.h" +#include "kernel/profile.h" #ifdef USE_APIC #include "apic.h" #endif -#include "spinlock.h" +#include "kernel/spinlock.h" #ifdef CONFIG_SMP #include "kernel/smp.h" diff --git a/kernel/arch/i386/direct_tty_utils.c b/kernel/arch/i386/direct_tty_utils.c index b51c7e247..3b5e36c46 100644 --- a/kernel/arch/i386/direct_tty_utils.c +++ b/kernel/arch/i386/direct_tty_utils.c @@ -1,5 +1,5 @@ -#include "kernel.h" +#include "kernel/kernel.h" #include #include #include diff --git a/kernel/arch/i386/head.S b/kernel/arch/i386/head.S index b73befcfb..63fafdc37 100644 --- a/kernel/arch/i386/head.S +++ b/kernel/arch/i386/head.S @@ -3,7 +3,7 @@ /* sections */ #include -#include "../../kernel.h" +#include "kernel/kernel.h" #include #include #include diff --git a/kernel/arch/i386/include/hw_intr.h b/kernel/arch/i386/include/hw_intr.h index 28619272b..3cc7c0b0e 100644 --- a/kernel/arch/i386/include/hw_intr.h +++ b/kernel/arch/i386/include/hw_intr.h @@ -17,7 +17,7 @@ void eoi_8259_slave(void); * either */ #if defined(USE_APIC) -#include "arch/i386/apic.h" +#include "kernel/arch/i386/apic.h" #define hw_intr_mask(irq) ioapic_mask_irq(irq) #define hw_intr_unmask(irq) ioapic_unmask_irq(irq) diff --git a/kernel/arch/i386/kernel.lds b/kernel/arch/i386/kernel.lds index 047484128..560de5f24 100644 --- a/kernel/arch/i386/kernel.lds +++ b/kernel/arch/i386/kernel.lds @@ -33,4 +33,5 @@ SECTIONS __k_unpaged__kern_size = . - _kern_vir_base; _kern_size = __k_unpaged__kern_size; } + _end = .; } diff --git a/kernel/arch/i386/mpx.S b/kernel/arch/i386/mpx.S index 68f7a0b1d..04d8b6ab5 100644 --- a/kernel/arch/i386/mpx.S +++ b/kernel/arch/i386/mpx.S @@ -26,7 +26,7 @@ /* sections */ #include -#include "../../kernel.h" +#include "kernel/kernel.h" #include #include #include diff --git a/kernel/arch/i386/pg_utils.c b/kernel/arch/i386/pg_utils.c index d14563ce8..f76ba516a 100644 --- a/kernel/arch/i386/pg_utils.c +++ b/kernel/arch/i386/pg_utils.c @@ -2,7 +2,7 @@ #include #include -#include "kernel.h" +#include "kernel/kernel.h" #include #include "arch_proto.h" diff --git a/kernel/arch/i386/pre_init.c b/kernel/arch/i386/pre_init.c index 2e8530eb3..3f9dfc44f 100644 --- a/kernel/arch/i386/pre_init.c +++ b/kernel/arch/i386/pre_init.c @@ -1,7 +1,7 @@ #define UNPAGED 1 /* for proper kmain() prototype */ -#include "kernel.h" +#include "kernel/kernel.h" #include #include #include diff --git a/kernel/arch/i386/procoffsets.cf b/kernel/arch/i386/procoffsets.cf index e460650dc..3d21913eb 100644 --- a/kernel/arch/i386/procoffsets.cf +++ b/kernel/arch/i386/procoffsets.cf @@ -1,5 +1,5 @@ -include "kernel.h" +include "kernel/kernel.h" struct proc member DIREG p_reg.di diff --git a/kernel/arch/i386/sconst.h b/kernel/arch/i386/sconst.h index 3732a353c..6138e4402 100644 --- a/kernel/arch/i386/sconst.h +++ b/kernel/arch/i386/sconst.h @@ -1,13 +1,8 @@ #ifndef __SCONST_H__ #define __SCONST_H__ -/* - * LSC Weirdness going on with the const.h header: FIXME #include "kernel/const.h" #include "kernel/procoffsets.h" - */ -#include "const.h" -#include "procoffsets.h" /* * offset to current process pointer right after trap, we assume we always have diff --git a/kernel/arch/i386/usermapped_data_arch.c b/kernel/arch/i386/usermapped_data_arch.c index 1e83fa0b8..a475787c6 100644 --- a/kernel/arch/i386/usermapped_data_arch.c +++ b/kernel/arch/i386/usermapped_data_arch.c @@ -1,4 +1,4 @@ -#include "kernel.h" +#include "kernel/kernel.h" #include "arch_proto.h" struct minix_ipcvecs minix_ipcvecs_softint = { diff --git a/kernel/clock.c b/kernel/clock.c index 2ea4c17d0..edcc3bc19 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -29,7 +29,7 @@ * Instead, notify(), which always returns, should be used. */ -#include "kernel.h" +#include "kernel/kernel.h" #include #include diff --git a/kernel/clock.h b/kernel/clock.h index cec747c38..57a0a48b5 100644 --- a/kernel/clock.h +++ b/kernel/clock.h @@ -1,7 +1,7 @@ #ifndef __CLOCK_H__ #define __CLOCK_H__ -#include "kernel.h" +#include "kernel/kernel.h" #include "arch_clock.h" int boot_cpu_init_timer(unsigned freq); diff --git a/kernel/cpulocals.c b/kernel/cpulocals.c index cb4b95ab0..17be8075a 100644 --- a/kernel/cpulocals.c +++ b/kernel/cpulocals.c @@ -1,3 +1,3 @@ -#include "kernel.h" +#include "kernel/kernel.h" DEFINE_CPULOCAL_VARS; diff --git a/kernel/debug.c b/kernel/debug.c index 7ef956a39..4029f5ca5 100644 --- a/kernel/debug.c +++ b/kernel/debug.c @@ -3,7 +3,7 @@ * functions and sanity checking of the scheduling queues. */ -#include "kernel.h" +#include "kernel/kernel.h" #include #include diff --git a/kernel/extract-errno.sh b/kernel/extract-errno.sh index cb5a10feb..0629f03a0 100644 --- a/kernel/extract-errno.sh +++ b/kernel/extract-errno.sh @@ -3,7 +3,7 @@ set -e # grep message type and errno constants and make them into a .h file -cat ../include/sys/errno.h | \ +cat ../sys/sys/errno.h | \ tr -s ' \t' ' ' | \ sed 's/^# /#/' | \ egrep '^#define [A-Z_][A-Z0-9_]* \( ?_SIGN ?[0-9]+ ?\)' | \ diff --git a/kernel/interrupt.c b/kernel/interrupt.c index cdab6d1f1..0e2323121 100644 --- a/kernel/interrupt.c +++ b/kernel/interrupt.c @@ -15,7 +15,7 @@ #include -#include "kernel.h" +#include "kernel/kernel.h" #include "archconst.h" #include "hw_intr.h" diff --git a/kernel/kernel.h b/kernel/kernel.h index f205b6785..03cd3bd8d 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -37,16 +37,16 @@ #include /* Important kernel header files. */ -#include "config.h" /* configuration, MUST be first */ -#include "const.h" /* constants, MUST be second */ -#include "type.h" /* type definitions, MUST be third */ -#include "proto.h" /* function prototypes */ -#include "glo.h" /* global variables */ -#include "ipc.h" /* IPC constants */ -#include "profile.h" /* system profiling */ -#include "proc.h" /* process table */ -#include "cpulocals.h" /* CPU-local variables */ -#include "debug.h" /* debugging, MUST be last kernel header */ +#include "kernel/config.h" /* configuration, MUST be first */ +#include "kernel/const.h" /* constants, MUST be second */ +#include "kernel/type.h" /* type definitions, MUST be third */ +#include "kernel/proto.h" /* function prototypes */ +#include "kernel/glo.h" /* global variables */ +#include "kernel/ipc.h" /* IPC constants */ +#include "kernel/profile.h" /* system profiling */ +#include "kernel/proc.h" /* process table */ +#include "kernel/cpulocals.h" /* CPU-local variables */ +#include "kernel/debug.h" /* debugging, MUST be last kernel header */ #ifndef CONFIG_SMP /* We only support 1 cpu now */ @@ -57,7 +57,7 @@ #else -#include "smp.h" +#include "kernel/smp.h" #endif diff --git a/kernel/main.c b/kernel/main.c index f107079e3..48ac62368 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -8,7 +8,7 @@ * main: MINIX main program * prepare_shutdown: prepare to take MINIX down */ -#include "kernel.h" +#include "kernel/kernel.h" #include #include #include diff --git a/kernel/priv.h b/kernel/priv.h index c7eacf5a1..f053c3b59 100644 --- a/kernel/priv.h +++ b/kernel/priv.h @@ -15,8 +15,8 @@ #include #include #include -#include "const.h" -#include "type.h" +#include "kernel/const.h" +#include "kernel/type.h" struct priv { proc_nr_t s_proc_nr; /* number of associated process */ diff --git a/kernel/proc.c b/kernel/proc.c index 3bdabd25f..3e597a5ab 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -35,7 +35,7 @@ #include #include -#include "kernel.h" +#include "kernel/kernel.h" #include "vm.h" #include "clock.h" #include "spinlock.h" diff --git a/kernel/profile.c b/kernel/profile.c index c4547f51c..46b0f56b7 100644 --- a/kernel/profile.c +++ b/kernel/profile.c @@ -17,7 +17,7 @@ #include -#include "kernel.h" +#include "kernel/kernel.h" #include #include diff --git a/kernel/smp.h b/kernel/smp.h index 68a29831a..f967fba4f 100644 --- a/kernel/smp.h +++ b/kernel/smp.h @@ -5,7 +5,7 @@ #ifndef __ASSEMBLY__ -#include "kernel.h" +#include "kernel/kernel.h" #include "arch_smp.h" #include "spinlock.h" diff --git a/kernel/spinlock.h b/kernel/spinlock.h index 55e354b2c..7cfee2d9e 100644 --- a/kernel/spinlock.h +++ b/kernel/spinlock.h @@ -1,7 +1,7 @@ #ifndef __SPINLOCK_H__ #define __SPINLOCK_H__ -#include "kernel.h" +#include "kernel/kernel.h" typedef struct spinlock { atomic_t val; diff --git a/kernel/system.c b/kernel/system.c index a28625c61..e8fe0387a 100644 --- a/kernel/system.c +++ b/kernel/system.c @@ -31,9 +31,9 @@ * Sep 30, 2004 source code documentation updated (Jorrit N. Herder) */ -#include "kernel.h" -#include "system.h" -#include "vm.h" +#include "kernel/kernel.h" +#include "kernel/system.h" +#include "kernel/vm.h" #include "kernel/clock.h" #include #include diff --git a/kernel/system.h b/kernel/system.h index 6a2840db3..fa58823b6 100644 --- a/kernel/system.h +++ b/kernel/system.h @@ -30,7 +30,7 @@ #ifndef SYSTEM_H #define SYSTEM_H -#include "kernel.h" +#include "kernel/kernel.h" int do_exec(struct proc * caller, message *m_ptr); #if ! USE_EXEC diff --git a/kernel/system/do_safecopy.c b/kernel/system/do_safecopy.c index 2d3c23f76..80d38fcb3 100644 --- a/kernel/system/do_safecopy.c +++ b/kernel/system/do_safecopy.c @@ -16,7 +16,7 @@ #include #include "kernel/system.h" -#include "kernel.h" +#include "kernel/kernel.h" #define MAX_INDIRECT_DEPTH 5 /* up to how many indirect grants to follow? */ diff --git a/kernel/system/do_safememset.c b/kernel/system/do_safememset.c index cfccec996..cdd127f85 100644 --- a/kernel/system/do_safememset.c +++ b/kernel/system/do_safememset.c @@ -13,7 +13,7 @@ #include #include "kernel/system.h" -#include "kernel.h" +#include "kernel/kernel.h" /*===========================================================================* * do_safememset * diff --git a/kernel/system/do_sprofile.c b/kernel/system/do_sprofile.c index 9f6be5354..b992016af 100644 --- a/kernel/system/do_sprofile.c +++ b/kernel/system/do_sprofile.c @@ -14,7 +14,7 @@ */ #include "kernel/system.h" -#include "watchdog.h" +#include "kernel/watchdog.h" #if SPROFILE diff --git a/kernel/table.c b/kernel/table.c index 18cd1f485..e77dc2013 100644 --- a/kernel/table.c +++ b/kernel/table.c @@ -29,7 +29,7 @@ */ #define _TABLE -#include "kernel.h" +#include "kernel/kernel.h" #include /* The system image table lists all programs that are part of the boot image. diff --git a/kernel/usermapped_data.c b/kernel/usermapped_data.c index d95a085cc..bec1696f5 100644 --- a/kernel/usermapped_data.c +++ b/kernel/usermapped_data.c @@ -1,4 +1,4 @@ -#include "kernel.h" +#include "kernel/kernel.h" /* This is the user-visible struct that has pointers to other bits of data. */ struct minix_kerninfo minix_kerninfo; diff --git a/kernel/utility.c b/kernel/utility.c index af2425e77..f112ee07a 100644 --- a/kernel/utility.c +++ b/kernel/utility.c @@ -3,7 +3,7 @@ * kputc: buffered putc used by kernel printf */ -#include "kernel.h" +#include "kernel/kernel.h" #include "arch_proto.h" #include @@ -89,3 +89,11 @@ int c; /* character to append */ return; } +/*===========================================================================* + * _exit * + *===========================================================================*/ +void _exit(e) +int e; /* error code */ +{ + panic("_exit called from within the kernel, should not happen. (err %i)", e); +} diff --git a/kernel/watchdog.h b/kernel/watchdog.h index 86beba7ab..b2ca56b3e 100644 --- a/kernel/watchdog.h +++ b/kernel/watchdog.h @@ -1,7 +1,7 @@ #ifndef __WATCHDOG_H__ #define __WATCHDOG_H__ -#include "kernel.h" +#include "kernel/kernel.h" #include "arch_watchdog.h" extern int watchdog_enabled; /* if set to non-zero the watch dog is enabled */ diff --git a/lib/csu/alpha/crt0.c b/lib/csu/alpha/crt0.c index 58534d7b6..fdeaff069 100644 --- a/lib/csu/alpha/crt0.c +++ b/lib/csu/alpha/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.24 2003/07/26 19:24:25 salo Exp $ */ +/* $NetBSD: crt0.c,v 1.27 2012/03/22 13:02:15 he Exp $ */ /* * Copyright (c) 1995 Christopher G. Demetriou @@ -40,11 +40,8 @@ void __start __P((char **, void (*cleanup) __P((void)), const Obj_Entry *, struct ps_strings *)); void -__start(sp, cleanup, obj, ps_strings) - char **sp; - void (*cleanup) __P((void)); /* from shared loader */ - const Obj_Entry *obj; /* from shared loader */ - struct ps_strings *ps_strings; +__start(char **sp, void (*cleanup)(void), + const Obj_Entry *obj, struct ps_strings *ps_strings) { long argc; char **argv, *namep; @@ -65,10 +62,12 @@ __start(sp, cleanup, obj, ps_strings) __ps_strings = ps_strings; #ifdef DYNAMIC - if (&_DYNAMIC != NULL) + if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); @@ -84,7 +83,7 @@ __start(sp, cleanup, obj, ps_strings) * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text. */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.24 2003/07/26 19:24:25 salo Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.27 2012/03/22 13:02:15 he Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/arch/arm/Makefile.inc b/lib/csu/arch/arm/Makefile.inc index 77519435c..a58e777e7 100644 --- a/lib/csu/arch/arm/Makefile.inc +++ b/lib/csu/arch/arm/Makefile.inc @@ -1,5 +1,3 @@ -# $NetBSD: Makefile.inc,v 1.1 2010/08/07 18:01:33 joerg Exp $ +# $NetBSD: Makefile.inc,v 1.2 2012/09/16 13:46:49 skrll Exp $ CPPFLAGS+= -DELFSIZE=32 - - diff --git a/lib/csu/arch/arm/crt0.S b/lib/csu/arch/arm/crt0.S index 4e71c1822..a8f7d1961 100644 --- a/lib/csu/arch/arm/crt0.S +++ b/lib/csu/arch/arm/crt0.S @@ -1,11 +1,12 @@ -/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */ +/* $NetBSD: crt0.S,v 1.3 2012/08/11 07:25:44 matt Exp $ */ -/* - * Copyright (C) 1997 Mark Brinicombe - * Copyright (C) 1995 Wolfgang Solfrank. - * Copyright (C) 1995 TooLs GmbH. +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -14,43 +15,41 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ -#include -RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:33 joerg Exp $") +#include + +RCSID("$NetBSD: crt0.S,v 1.3 2012/08/11 07:25:44 matt Exp $") STRONG_ALIAS(_start,__start) _ENTRY(__start) - mov r5, r2 /* cleanup */ - mov r4, r1 /* obj_main */ - mov r3, r0 /* ps_strings */ - /* Get argc, argv, and envp from stack */ - ldr r0, [sp, #0x0000] - add r1, sp, #0x0004 - add r2, r1, r0, lsl #2 - add r2, r2, #0x0004 + /* + * We need to swap ps_strings and cleanup + */ + mov ip, r0 /* ps_strings -> tmp */ + mov r0, r2 /* cleanup -> ps_strings */ + mov r2, ip /* tmp -> ps_strings */ /* Ensure the stack is properly aligned before calling C code. */ bic sp, sp, #7 - sub sp, sp, #8 - str r5, [sp, #4] - str r4, [sp, #0] + + /* + * void ___start(void (*cleanup)(void), + * const Obj_Entry *obj, + * struct ps_strings *ps_strings); + */ b ___start diff --git a/lib/csu/arch/arm/crtbegin.S b/lib/csu/arch/arm/crtbegin.S new file mode 100644 index 000000000..302bc7eb5 --- /dev/null +++ b/lib/csu/arch/arm/crtbegin.S @@ -0,0 +1,293 @@ +/* $NetBSD: crtbegin.S,v 1.4 2012/08/25 15:39:05 matt Exp $ */ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crtbegin.S,v 1.4 2012/08/25 15:39:05 matt Exp $") + + .section .ctors, "aw", %progbits + .p2align 2 +__CTOR_LIST__: + .word -1 + + .section .dtors, "aw", %progbits + .p2align 2 +__DTOR_LIST__: + .word -1 + + .section .eh_frame, "a", %progbits + .p2align 2 +__EH_FRAME_LIST__: + + .section .jcr, "aw", %progbits + .p2align 2 +__JCR_LIST__: + + .section .data.rel, "aw", %progbits + .p2align 2 + .type __dso_handle, %object + .size __dso_handle, 4 + .globl __dso_handle + .hidden __dso_handle +__dso_handle: +#ifdef SHARED + .word __dso_handle +#else + .word 0 +#endif + + .local __dwarf_eh_object + .comm __dwarf_eh_object,24 + .local __initialized + .comm __initialized,1 + .local __finished + .comm __finished,1 + + .text +/* + * All variables are local to this DSO so we can skip using GOT references + * and instead use PCREL references to access them. We do this regardless + * of being PIC since it isn't any additional overhead to do so. + * + * We don't setup a TOC since all of ours calls are indirect so it isn't + * needed. + */ + + .type __do_global_dtors_aux, %function +__do_global_dtors_aux: + GOT_INIT(r3, .Ldtors_got, .Ldtors) /* use r3 temporarily */ + ldr r1, .L__finished +#ifdef PIC + ldrb r0, [r1, r3]! +#else + ldrb r0, [r1] +#endif + cmp r0, #0 /* done this already? */ + RETc(ne) + mov r0, #1 + strb r0, [r1] /* mark it as done */ + + mov ip, sp + stmfd sp!, {r4, r5, r6, r7, fp, ip, lr, pc} + sub fp, ip, #4 + mov r7, r3 /* now that r7 is saved ... */ + +#ifdef SHARED + GOT_GET(ip, r7, .L__cxa_finalize) + cmp ip, #0 + ldrne r2, .L__dso_handle /* GOTOFF */ + ldrne r0, [r2, r7] /* load relative to GOT */ +#ifdef _ARM_ARCH_4T + blxne ip +#else + movne lr, pc + movne pc, ip +#endif +#endif /* SHARED */ + + /* + * We know the first entry is -1 so skip it. We use load with + * preincrement to advance the pointer along. + */ + ldr r4, .L__DTOR_LIST__ + ldr r5, .L__DTOR_LIST_END__ +#ifdef PIC + add r4, r4, r7 /* addr = offset + got */ + add r5, r5, r7 /* addr = offset + got */ +#endif + add r4, r4, #4 /* skip first entry */ +1: + cmp r4, r5 /* end of list */ + ldrne ip, [r4], #4 /* ip = *r4++; */ +#ifndef SHARED + ldmeqfd sp, {r4, r5, r6, r7, fp, sp, pc} /* restore and return */ +#endif + adrne lr, 1b /* set up to return to loop start */ +#ifdef _ARM_ARCH_4T + bxne ip /* call it */ +#else + movne pc, ip /* call entry */ +#endif + +#ifdef SHARED + /* + * if (__deregister_frame_info) + * __deregister_frame_info(&__EH_FRAME_LIST__[0]); + */ + GOT_GET(ip, r7, .L__deregister_frame_info) + cmp ip, #0 + ldmeqfd sp, {r4-r7, fp, sp, pc} /* restore and return */ + + ldr r1, .L__EH_FRAME_LIST__ +#ifdef PIC + add r0, r1, r7 /* add offset to GOT addr */ +#endif + ldmfd sp, {r4-r7, fp, sp, lr} /* restore everthing */ +#ifdef _ARM_ARCH_4T + bx ip /* tail call it */ +#else + mov pc, ip /* tail call it */ +#endif +#endif /* SHARED */ + + .weak __deregister_frame_info + .weak __cxa_finalize + .hidden _C_LABEL(__DTOR_LIST_END__) + + .align 2 + GOT_INITSYM(.Ldtors_got, .Ldtors) +#ifdef SHARED +.L__deregister_frame_info: + .word PIC_SYM(_C_LABEL(__deregister_frame_info), GOT) +.L__cxa_finalize: + .word PIC_SYM(_C_LABEL(__cxa_finalize), GOT) +.L__dso_handle: + .word PIC_SYM(_C_LABEL(__dso_handle), GOTOFF) +#endif +.L__finished: + .word PIC_SYM(_C_LABEL(__finished), GOTOFF) +.L__DTOR_LIST__: + .word PIC_SYM(_C_LABEL(__DTOR_LIST__), GOTOFF) +.L__DTOR_LIST_END__: + .word PIC_SYM(_C_LABEL(__DTOR_LIST_END__), GOTOFF) +.L__EH_FRAME_LIST__: + .word PIC_SYM(_C_LABEL(__EH_FRAME_LIST__), GOTOFF) + + + .weak __register_frame_info + .weak _Jv_RegisterClasses + + .type __do_global_ctors_aux, %function +__do_global_ctors_aux: + GOT_INIT(r3, .Lctors_got, .Lctors) + ldr r1, .L__initialized +#ifdef PIC + ldrb r0, [r1, r3]! +#else + ldrb r0, [r1] +#endif + cmp r0, #0 /* done this already? */ + RETc(ne) + mov r0, #1 + strb r0, [r1] /* mark it as done */ + + mov ip, sp + stmfd sp!, {r4, r5, r6, r7, fp, ip, lr, pc} + sub fp, ip, #4 + mov r7, r3 /* now that r7 is saved ... */ + + /* + * if (__register_frame_info) + * __register_frame_info(&__EH_FRAME_LIST__[0], &__dwarf_eh_object) + */ + GOT_GET(ip, r7, .L__register_frame_info) + cmp ip, #0 + beq 1f + + ldr r0, .L__EH_FRAME_LIST__ + ldr r1, .L__dwarf_eh_object +#ifdef PIC + add r0, r0, r7 /* object addr = got addr + offset */ + add r1, r1, r7 /* object addr = got addr + offset */ +#endif + +#ifdef _ARM_ARCH_4T + blx ip +#else + mov lr, pc + mov pc, ip +#endif +1: + /* + * if (_Jv_RegisterClasses && __JCR_LIST__[0]) + * _Jv_RegisterClasses(&__JCR_LIST__[0]); + */ + GOT_GET(ip, r7, .L_Jv_RegisterClasses) + cmp ip, #0 + + ldrne r0, .L__JCR_LIST__ +#ifdef PIC + ldrne r2, [r0, r7]! /* load 1st one, make r0 point to it */ +#else + ldrne r2, [r0] /* load 1st one */ +#endif + cmpne r2, #0 +#ifdef _ARM_ARCH_4T + blxne ip +#else + movne lr, pc + movne pc, ip +#endif + + /* + * Get the start and end of the CTOR list. + */ + + ldr r4, .L__CTOR_LIST__ + ldr r5, .L__CTOR_LIST_END__ +#ifdef PIC + add r4, r4, r7 /* object addr = got addr + offset */ + add r5, r5, r7 /* object addr = got addr + offset */ +#endif + sub r5, r5, #4 /* ignore first entry */ +3: + cmp r4, r5 /* at first entry? */ + ldmeqfd sp, {r4-r7, fp, sp, pc} /* then return */ + adr lr, 3b /* return to start of loop */ + ldr ip, [r5], #-4 /* get entry */ +#ifdef _ARM_ARCH_4T + bx ip +#else + mov pc, ip /* get entry */ +#endif + + .hidden _C_LABEL(__CTOR_LIST_END__) + + .align 2 + GOT_INITSYM(.Lctors_got, .Lctors) +.L_Jv_RegisterClasses: + .word PIC_SYM(_C_LABEL(_Jv_RegisterClasses), GOT) +.L__register_frame_info: + .word PIC_SYM(_C_LABEL(__register_frame_info), GOT) +.L__initialized: + .word PIC_SYM(_C_LABEL(__initialized), GOTOFF) +.L__CTOR_LIST__: + .word PIC_SYM(_C_LABEL(__CTOR_LIST__), GOTOFF) +.L__CTOR_LIST_END__: + .word PIC_SYM(_C_LABEL(__CTOR_LIST_END__), GOTOFF) +.L__dwarf_eh_object: + .word PIC_SYM(_C_LABEL(__dwarf_eh_object), GOTOFF) +.L__JCR_LIST__: + .word PIC_SYM(_C_LABEL(__JCR_LIST__), GOTOFF) + + .section .init, "ax", %progbits + bl __do_global_ctors_aux + .section .fini, "ax", %progbits + bl __do_global_dtors_aux diff --git a/lib/csu/arch/arm/crtend.S b/lib/csu/arch/arm/crtend.S new file mode 100644 index 000000000..fd8a62a7d --- /dev/null +++ b/lib/csu/arch/arm/crtend.S @@ -0,0 +1,55 @@ +/* $NetBSD: crtend.S,v 1.2 2012/08/11 07:26:25 matt Exp $ */ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crtend.S,v 1.2 2012/08/11 07:26:25 matt Exp $") + + .section .ctors, "aw", %progbits + .p2align 2 + .global __CTOR_LIST_END__ + .hidden __CTOR_LIST_END__ +__CTOR_LIST_END__: + .space 4 + + .section .dtors, "aw", %progbits + .p2align 2 + .global __DTOR_LIST_END__ + .hidden __DTOR_LIST_END__ +__DTOR_LIST_END__: + .space 4 + + .section .eh_frame, "a", %progbits + .p2align 2 + .space 4 + + .section .jcr, "aw", %progbits + .p2align 2 + .space 4 diff --git a/lib/csu/arch/arm/crti.S b/lib/csu/arch/arm/crti.S index fe3ab872b..1e576fdbe 100644 --- a/lib/csu/arch/arm/crti.S +++ b/lib/csu/arch/arm/crti.S @@ -1,4 +1,4 @@ -/* $NetBSD: crti.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */ +/* $NetBSD: crti.S,v 1.2 2012/08/11 01:33:36 matt Exp $ */ /*- * Copyright (c) 2001 Ross Harvey @@ -35,21 +35,23 @@ #include -RCSID("$NetBSD: crti.S,v 1.1 2010/08/07 18:01:33 joerg Exp $") +RCSID("$NetBSD: crti.S,v 1.2 2012/08/11 01:33:36 matt Exp $") #include "sysident.S" - .section ".init", "ax", @progbits + .section ".init", "ax", %progbits .align 0 .globl _init + .type _init,%function _init: mov ip, sp stmfd sp!, {fp, ip, lr, pc} sub fp, ip, #4 - .section ".fini", "ax", @progbits + .section ".fini", "ax", %progbits .align 0 .globl _fini + .type _fini,%function _fini: mov ip, sp stmfd sp!, {fp, ip, lr, pc} diff --git a/lib/csu/arch/arm/crtn.S b/lib/csu/arch/arm/crtn.S index 8d85e0923..ce0939975 100644 --- a/lib/csu/arch/arm/crtn.S +++ b/lib/csu/arch/arm/crtn.S @@ -1,4 +1,4 @@ -/* $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */ +/* $NetBSD: crtn.S,v 1.2 2012/08/11 01:33:36 matt Exp $ */ /*- * Copyright (c) 2001 Ross Harvey @@ -35,10 +35,10 @@ #include -RCSID("$NetBSD: crtn.S,v 1.1 2010/08/07 18:01:33 joerg Exp $") +RCSID("$NetBSD: crtn.S,v 1.2 2012/08/11 01:33:36 matt Exp $") - .section ".init", "ax", @progbits + .section ".init", "ax", %progbits ldmea fp, {fp, sp, pc} - .section ".fini", "ax", @progbits + .section ".fini", "ax", %progbits ldmea fp, {fp, sp, pc} diff --git a/lib/csu/arch/earm/Makefile.inc b/lib/csu/arch/earm/Makefile.inc new file mode 100644 index 000000000..13e18b1cd --- /dev/null +++ b/lib/csu/arch/earm/Makefile.inc @@ -0,0 +1,5 @@ +# $NetBSD: Makefile.inc,v 1.1 2012/08/13 02:49:04 matt Exp $ + +CPPFLAGS+= -DELFSIZE=32 +CPPFLAGS+= -DHAVE_INITFINI_ARRAY + diff --git a/lib/csu/arch/earm/crt0.S b/lib/csu/arch/earm/crt0.S new file mode 100644 index 000000000..1359874bf --- /dev/null +++ b/lib/csu/arch/earm/crt0.S @@ -0,0 +1,55 @@ +/* $NetBSD: crt0.S,v 1.1 2012/08/13 02:49:04 matt Exp $ */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crt0.S,v 1.1 2012/08/13 02:49:04 matt Exp $") + +STRONG_ALIAS(_start,__start) + +_ENTRY(__start) + /* + * We need to swap ps_strings and cleanup + */ + mov ip, r0 /* ps_strings -> tmp */ + mov r0, r2 /* cleanup -> ps_strings */ + mov r2, ip /* tmp -> ps_strings */ + + /* Ensure the stack is properly aligned before calling C code. */ + bic sp, sp, #7 + + /* + * void ___start(void (*cleanup)(void), + * const Obj_Entry *obj, + * struct ps_strings *ps_strings); + */ + + b ___start diff --git a/lib/csu/arch/earm/crtbegin.S b/lib/csu/arch/earm/crtbegin.S new file mode 100644 index 000000000..4bc97505f --- /dev/null +++ b/lib/csu/arch/earm/crtbegin.S @@ -0,0 +1,216 @@ +/* $NetBSD: crtbegin.S,v 1.1 2012/08/13 02:49:04 matt Exp $ */ +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crtbegin.S,v 1.1 2012/08/13 02:49:04 matt Exp $") + + .section .eh_frame, "a", %progbits + .p2align 2 +__EH_FRAME_LIST__: + + .section .jcr, "aw", %progbits + .p2align 2 +__JCR_LIST__: + + .section .data.rel, "aw", %progbits + .p2align 2 + .type __dso_handle, %object + .size __dso_handle, 4 + .globl __dso_handle + .hidden __dso_handle +__dso_handle: +#ifdef SHARED + .word __dso_handle +#else + .word 0 +#endif + + .text +#ifdef SHARED + /* + * If we aren't shared, all we do is set finished + * to 1 if it isn't 1 already. So why bother do that at all? + */ + .type __do_global_dtors_aux, %function +__do_global_dtors_aux: + GOT_INIT(r3, .Ldtors_got, .Ldtors) /* use r3 temporarily */ + ldr r1, .L__finished /* GOTOFF */ + ldrb r0, [r1, r3]! + cmp r0, #0 /* done this already? */ + RETc(ne) + mov r0, #1 + strb r0, [r1] /* mark it as done */ + + GOT_GET(ip, r3, .L__cxa_finalize) + cmp ip, #0 + RETc(eq) + ldr r0, .L__dso_handle /* GOTOFF */ + ldr r0, [r0, r3] /* load relative to got */ +#if defined(_ARM_ARCH_4T) + bx ip /* tail call */ +#else + mov pc, ip +#endif + +#if 0 /* not used */ + /* + * if (__deregister_frame_info) + * __deregister_frame_info(&__EH_FRAME_LIST__[0]); + */ + GOT_GET(ip, r3, .L__deregister_frame_info) + cmp ip, #0 + ldmeqfd sp, {r4, r5, fp, sp, pc} /* restore and return */ + + ldr r1, .L__EH_FRAME_LIST__ /* GOTOFF */ + add r1, r1, r4 /* add got addr */ + ldmfd sp, {r4, r5, fp, sp, lr} /* restore everthing */ +#if !defined(_ARM_ARCH_4T) + bx ip /* tail call it */ +#else + mov pc, ip /* tail call it */ +#endif +#endif /* notused */ + + .weak __cxa_finalize + .weak __deregister_frame_info + + .align 2 + GOT_INITSYM(.Ldtors_got, .Ldtors) +.L__cxa_finalize: + .word PIC_SYM(_C_LABEL(__cxa_finalize), GOT) +#if 0 +.L__deregister_frame_info: + .word PIC_SYM(_C_LABEL(__deregister_frame_info), GOT) +#endif +.L__finished: + .word PIC_SYM(_C_LABEL(__finished), GOTOFF) +.L__dso_handle: + .word PIC_SYM(_C_LABEL(__dso_handle), GOTOFF) + + .pushsection .fini_array,"aw",%fini_array + .p2align 2 + .word __do_global_dtors_aux + .popsection +#endif /* SHARED */ + + .local __finished + .comm __finished,1,1 + + .weak __register_frame_info + .weak _Jv_RegisterClasses + + .type __do_global_ctors_aux, %function +__do_global_ctors_aux: + GOT_INIT(r3, .Lctors_got, .Lctors) + ldr r1, .L__initialized /* GOTOFF if PIC */ +#ifdef PIC + ldrb r0, [r1, r3]! /* r1 = r1 + got */ +#else + ldrb r0, [r1] +#endif + cmp r0, #0 /* done this already? */ + RETc(ne) + mov r0, #1 + strb r0, [r1] /* mark it as done */ + + mov ip, sp + stmfd sp!, {r4, r5, fp, ip, lr, pc} + sub fp, ip, #4 + mov r4, r3 /* now that r4 is saved ... */ + + /* + * if (__register_frame_info) + * __register_frame_info(&__EH_FRAME_LIST__[0], &__dwarf_eh_object) + */ + GOT_GET(ip, r4, .L__register_frame_info) + cmp ip, #0 + beq 1f + + ldr r0, .L__EH_FRAME_LIST__ + ldr r1, .L__dwarf_eh_object +#ifdef PIC + add r0, r0, r4 + add r1, r1, r4 +#endif + +#if defined(_ARM_ARCH_4T) + blx ip +#else + mov lr, pc + mov pc, ip +#endif +1: + /* + * if (_Jv_RegisterClasses && __JCR_LIST__[0]) + * _Jv_RegisterClasses(&__JCR_LIST__[0]); + */ + GOT_GET(ip, r4, .L_Jv_RegisterClasses) + cmp ip, #0 + ldmeqfd sp, {r4, r5, fp, sp, pc} /* return if null */ + + ldr r0, .L__JCR_LIST__ +#ifdef PIC + ldr r2, [r0, r4]! /* GOTOFF + got == address */ +#else + ldr r2, [r0] +#endif + cmp r2, #0 + ldmfd sp, {r4, r5, fp, sp, lr} /* restore everything */ + RETc(eq) /* return if null */ +#if defined(_ARM_ARCH_4T) + bx ip /* return or tail call */ +#else + mov pc, ip /* return or tail call */ +#endif + + .p2align 2 + GOT_INITSYM(.Lctors_got, .Lctors) +.L__register_frame_info: + .word PIC_SYM(_C_LABEL(__register_frame_info), GOT) +.L_Jv_RegisterClasses: + .word PIC_SYM(_C_LABEL(_Jv_RegisterClasses), GOT) +.L__initialized: + .word PIC_SYM(_C_LABEL(__initialized), GOTOFF) +.L__EH_FRAME_LIST__: + .word PIC_SYM(_C_LABEL(__EH_FRAME_LIST__), GOTOFF) +.L__dwarf_eh_object: + .word PIC_SYM(_C_LABEL(__dwarf_eh_object), GOTOFF) +.L__JCR_LIST__: + .word PIC_SYM(_C_LABEL(__JCR_LIST__), GOTOFF) + + .local __initialized + .comm __initialized,1,1 + .local __dwarf_eh_object + .comm __dwarf_eh_object,24,4 + + .section .init_array,"aw",%init_array + .p2align 2 + .word __do_global_ctors_aux diff --git a/lib/csu/arch/earm/crtend.S b/lib/csu/arch/earm/crtend.S new file mode 100644 index 000000000..a05be7d85 --- /dev/null +++ b/lib/csu/arch/earm/crtend.S @@ -0,0 +1,54 @@ +/* $NetBSD: crtend.S,v 1.1 2012/08/13 02:49:04 matt Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crtend.S,v 1.1 2012/08/13 02:49:04 matt Exp $") + + .fpu softvfp + .eabi_attribute 18, 4 /* sizeof(wchar_t) */ + .eabi_attribute 23, 0 /* doesn't use floating point */ + .eabi_attribute 24, 1 /* 8 byte alignment permitted */ + .eabi_attribute 25, 1 /* preserves 8-byte alignment */ + .eabi_attribute 26, 2 /* enums are 32-bits */ + + .section .eh_frame, "a", %progbits + .p2align 2 + .global __EH_FRAME_END__ + .hidden __EH_FRAME_END__ +__EH_FRAME_END__: + .space 4 + + .section .jcr, "aw", %progbits + .p2align 2 + .global __JCR_END__ + .hidden __JCR_END__ +__JCR_END__: + .space 4 diff --git a/lib/csu/arch/earm/crti.S b/lib/csu/arch/earm/crti.S new file mode 100644 index 000000000..6bec16b0f --- /dev/null +++ b/lib/csu/arch/earm/crti.S @@ -0,0 +1,41 @@ +/* $NetBSD: crti.S,v 1.1 2012/08/13 02:49:04 matt Exp $ */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crti.S,v 1.1 2012/08/13 02:49:04 matt Exp $") + +#include "sysident.S" + +/* + * Since ARM EABI uses .init_array/.fini_array, + * there is no need for .init/.fini + */ diff --git a/lib/csu/arch/earm/crtn.S b/lib/csu/arch/earm/crtn.S new file mode 100644 index 000000000..0544e7b63 --- /dev/null +++ b/lib/csu/arch/earm/crtn.S @@ -0,0 +1,3 @@ +/* $NetBSD: crtn.S,v 1.1 2012/08/13 02:49:04 matt Exp $ */ + +/* no need for anything here since ARM EABI uses .init_array/.fini_array */ diff --git a/lib/csu/arch/i386/crt0.S b/lib/csu/arch/i386/crt0.S index bc975d93e..1029f7a7d 100644 --- a/lib/csu/arch/i386/crt0.S +++ b/lib/csu/arch/i386/crt0.S @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:33 joerg Exp $ */ +/* $NetBSD: crt0.S,v 1.3 2011/07/01 02:59:05 joerg Exp $ */ /* * Copyright (c) 1998 Christos Zoulas @@ -37,17 +37,21 @@ #include -RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:33 joerg Exp $") +RCSID("$NetBSD: crt0.S,v 1.3 2011/07/01 02:59:05 joerg Exp $") + + .hidden ___start STRONG_ALIAS(_start,__start) _ENTRY(__start) pushl %ebx pushl %ecx pushl %edx - movl 12(%esp),%eax - leal 16(%esp),%edx - leal 20(%esp,%eax,4),%ecx - pushl %ecx - pushl %edx - pushl %eax +#ifdef __minix + movl 12(%esp),%eax + leal 16(%esp),%edx + leal 20(%esp,%eax,4),%ecx + pushl %ecx + pushl %edx + pushl %eax +#endif /* __minix */ call ___start diff --git a/lib/csu/arch/powerpc/Makefile.inc b/lib/csu/arch/powerpc/Makefile.inc new file mode 100644 index 000000000..5652414af --- /dev/null +++ b/lib/csu/arch/powerpc/Makefile.inc @@ -0,0 +1,5 @@ +# $NetBSD: Makefile.inc,v 1.1 2011/02/08 02:02:25 matt Exp $ + +CPPFLAGS+= -DELFSIZE=32 + + diff --git a/lib/csu/arch/powerpc/crt0.S b/lib/csu/arch/powerpc/crt0.S new file mode 100644 index 000000000..330d46ae7 --- /dev/null +++ b/lib/csu/arch/powerpc/crt0.S @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crt0.S,v 1.4 2011/07/02 20:16:09 matt Exp $") + +STRONG_ALIAS(_start,__start) + + .hidden ___start + + .weak _SDA_BASE_ + +ENTRY_NOPROFILE(__start) + bcl 20,31,1f +1: + mflr %r11 + /* SVR4 ABI says small data is in r13 */ + addis %r13,%r11,_SDA_BASE_-1b@ha + addi %r13,%r13,_SDA_BASE_-1b@l + + mr %r3,%r7 /* cleanup */ + mr %r4,%r6 /* obj */ + mr %r5,%r8 /* ps_strings */ + + b ___start +END(__start) diff --git a/lib/csu/arch/powerpc/crtbegin.S b/lib/csu/arch/powerpc/crtbegin.S new file mode 100644 index 000000000..0c62da9bc --- /dev/null +++ b/lib/csu/arch/powerpc/crtbegin.S @@ -0,0 +1,268 @@ +/* $NetBSD: crtbegin.S,v 1.2 2011/07/04 21:55:09 matt Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crtbegin.S,v 1.2 2011/07/04 21:55:09 matt Exp $") + + .section .ctors, "aw", @progbits + .p2align 2 +__CTOR_LIST__: + .long -1 + + .section .dtors, "aw", @progbits + .p2align 2 +__DTOR_LIST__: + .long -1 + + .section .eh_frame, "a", @progbits + .p2align 2 +__EH_FRAME_LIST__: + + .section .jcr, "aw", @progbits + .p2align 2 +__JCR_LIST__: + + .section ".got2","aw", @progbits +.LCTOC = . + 32768 + + .section .data.rel, "aw", @progbits + .p2align 2 + .type __dso_handle, @object + .size __dso_handle, 4 + .globl __dso_handle + .hidden __dso_handle +__dso_handle: +#ifdef SHARED + .long __dso_handle +#else + .long 0 +#endif + + .lcomm __dwarf_eh_object,8*SZREG,SZREG + .lcomm __initialized,1,1 + .lcomm __finished,1,1 + + .text + .weak __cxa_finalize + .weak __deregister_frame_info + .weak __register_frame_info + .weak _Jv_RegisterClasses + +/* + * All variables are local to this DSO so we can skip using GOT references + * and instead use PCREL references to access them. We do this regardless + * of being PIC since it isn't any additional overhead to do so. + * + * We don't setup a TOC since all of ours calls are indirect so it isn't + * needed. + */ + +__do_global_dtors_aux: + mflr %r7 /* save return address */ + bcl 20,31,1f /* find out what address */ +1: mflr %r3 /* we are at */ + mtlr %r7 /* restore return address */ + + addis %r4,%r3,__finished-1b@ha /* PCREL ref (upper) */ + lbzu %r0,__finished-1b@l(%r4) /* PCREL ref (lower) & load */ + cmpwi %r0,0 /* done this already? */ + bnelr /* yep, return */ + + li %r0, 1 + stb %r0, 0(%r4) /* remember we've done this */ + + stw %r7,(1*SZREG)(%r1) /* save LR */ + stwu %r1,-(8*SZREG)(%r1) /* alloc our stack frame */ + stw %r31,(7*SZREG)(%r1) /* save some registers */ + stw %r30,(6*SZREG)(%r1) + stw %r29,(5*SZREG)(%r1) + stw %r28,(4*SZREG)(%r1) + + mr %r29,%r3 /* move this to a safe place */ + + /* + * Get a reference to our TOC. + */ + addis %r30,%r29,.LCTOC-1b@ha + addi %r30,%r30,.LCTOC-1b@l + + /* + * Get a reference to the GOT. + */ + addis %r31,%r29,_GLOBAL_OFFSET_TABLE_-1b@ha /* pcrel (hi) */ + addi %r31,%r31,_GLOBAL_OFFSET_TABLE_-1b@l /* pcrel (lo) */ + +#ifdef SHARED + /* + * if (__cxa_finalize) + * __cxa_finalize(&__dso_handle); + */ + lwz %r0, __cxa_finalize@got(%r31) + cmpwi %r0, 0 + beq 2f + + addis %r3,%r29,__dso_handle-1b@ha /* get &__dso_handle (pcrel) */ + addi %r3,%r3,__dso_handle-1b@l + mtctr %r0 /* setup for indirect branch */ + bctrl /* and call the routine */ +2: +#endif + + addis %r28,%r29,__DTOR_LIST__-1b@ha /* get &__DTOR_LIST__ */ + addi %r28,%r28,__DTOR_LIST__-1b@l + /* + * We know the first entry is -1 so skip it. We use load with update + * to advance the pointer along. + */ +3: + lwzu %r0, 4(%r28) /* get entry */ + cmpwi %r0, 0 /* end of list? */ + beq 4f /* yep. */ + mtctr %r0 /* setup for indirect branch */ + bctrl /* and call the routine */ + b 3b /* do it again */ + +4: + /* + * if (__deregister_frame_info) + * __deregister_frame_info(&__EH_FRAME_LIST__[0]); + */ + lwz %r0,__deregister_frame_info@got(%r31) + cmpwi %r0, 0 /* routine actually exist? */ + beq 5f /* nope, skip call */ + + addis %r3,%r29,__EH_FRAME_LIST__-1b@ha + addi %r3,%r3,__EH_FRAME_LIST__-1b@l + mtctr %r0 /* setup for indirect branch */ + bctrl /* and call the routine */ +5: + lwz %r28,(4*SZREG)(%r1) /* restore registers */ + lwz %r29,(5*SZREG)(%r1) + lwz %r30,(6*SZREG)(%r1) + lwz %r31,(7*SZREG)(%r1) + addi %r1,%r1,8*SZREG /* adjust stack */ + lwz %r0,(1*SZREG)(%r1) /* get return addr */ + mtlr %r0 + blr /* and return */ + +__do_global_ctors_aux: + mflr %r7 /* save return address */ + bcl 20,31,1f /* find out what address */ +1: mflr %r3 /* we are at */ + mtlr %r7 /* restore return address */ + + addis %r4,%r3,__initialized-1b@ha /* pcrel (hi) */ + lbzu %r0,__initialized-1b@l(%r4) /* pcrel (lo) load+update */ + cmpwi %r0,0 /* have we already done this? */ + bnelr /* yep, return */ + + li %r0,1 + stb %r0,0(%r4) /* remember we've been here */ + + stw %r7,(1*SZREG)(%r1) /* save LR */ + stwu %r1,-(8*SZREG)(%r1) /* alloc our stack frame */ + stw %r31,(7*SZREG)(%r1) /* save some registers */ + stw %r30,(6*SZREG)(%r1) + stw %r29,(5*SZREG)(%r1) + stw %r28,(4*SZREG)(%r1) + + mr %r29,%r3 /* move this to a safe place */ + + /* + * Get a reference to our TOC. + */ + addis %r30,%r29,.LCTOC-1b@ha + addi %r30,%r30,.LCTOC-1b@l + + /* + * Get a reference to the GOT. + */ + addis %r31,%r29,_GLOBAL_OFFSET_TABLE_-1b@ha /* pcrel (hi) */ + addi %r31,%r31,_GLOBAL_OFFSET_TABLE_-1b@l /* pcrel (lo) */ + + /* + * if (__register_frame_info) + * __register_frame_info(&__EH_FRAME_LIST__[0], &__dwarf_eh_object) + */ + lwz %r0, __register_frame_info@got(%r31) + cmpwi %r0, 0 + beq 2f + + addis %r3,%r29,__EH_FRAME_LIST__-1b@ha /* pcrel (hi) */ + addi %r3,%r3,__EH_FRAME_LIST__-1b@l /* pcrel (lo) */ + addis %r4,%r29,__dwarf_eh_object-1b@ha /* pcrel (hi) */ + addi %r4,%r4,__dwarf_eh_object-1b@l /* pcrel (lo) */ + mtctr %r0 /* setup for indirect branch */ + bctrl /* and call the routine */ + +2: + /* + * if (_Jv_RegisterClasses && __JCR_LIST__[0]) + * _Jv_RegisterClasses(&__JCR_LIST__[0]); + */ + lwz %r0, _Jv_RegisterClasses@got(%r31) + cmpwi %r0, 0 + beq 3f + + mtctr %r0 /* setup for indirect branch */ + addis %r3, %r29, __JCR_LIST__-1b@ha /* pcrel (hi) */ + addi %r3, %r3, __JCR_LIST__-1b@l /* pcrel (lo) */ + lwz %r4, 0(%r3) /* load first entry */ + cmpwi %r4, 0 /* is the list empty? */ + bnectrl /* call the routine if not */ +3: + + /* + * Get end of list of CTOR list. + */ + addis %r28,%r29,__CTOR_LIST_END__-1b@ha + addi %r28,%r28,__CTOR_LIST_END__-1b@l +4: + lwzu %r0, -4(%r28) /* get entry */ + cmpwi %r0, -1 /* first entry? */ + beq 5f /* yes, we're done */ + mtctr %r0 /* setup for indirect branch */ + bctrl /* call the routine */ + b 4b /* do it again */ +5: + lwz %r28,(4*SZREG)(%r1) /* restore registers */ + lwz %r29,(5*SZREG)(%r1) + lwz %r30,(6*SZREG)(%r1) + lwz %r31,(7*SZREG)(%r1) + addi %r1,%r1,8*SZREG /* adjust stack */ + lwz %r0,(1*SZREG)(%r1) /* get return addr */ + mtlr %r0 + blr /* and return */ + + .section .init, "ax", @progbits + bl __do_global_ctors_aux + .section .fini, "ax", @progbits + bl __do_global_dtors_aux diff --git a/lib/csu/arch/powerpc/crtend.S b/lib/csu/arch/powerpc/crtend.S new file mode 100644 index 000000000..9e04e6421 --- /dev/null +++ b/lib/csu/arch/powerpc/crtend.S @@ -0,0 +1,52 @@ +/* $NetBSD: crtend.S,v 1.1 2011/02/08 02:02:25 matt Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crtend.S,v 1.1 2011/02/08 02:02:25 matt Exp $") + + .section .ctors, "aw", @progbits + .p2align 2 + .global __CTOR_LIST_END__ + .hidden __CTOR_LIST_END__ +__CTOR_LIST_END__: + .long 0 + + .section .dtors, "aw", @progbits + .p2align 2 + .long 0 + + .section .eh_frame, "a", @progbits + .p2align 2 + .long 0 + + .section .jcr, "aw", @progbits + .p2align 2 + .long 0 diff --git a/lib/csu/arch/powerpc/crti.S b/lib/csu/arch/powerpc/crti.S new file mode 100644 index 000000000..1707b31b4 --- /dev/null +++ b/lib/csu/arch/powerpc/crti.S @@ -0,0 +1,50 @@ +/* $NetBSD: crti.S,v 1.1 2011/02/08 02:02:25 matt Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crti.S,v 1.1 2011/02/08 02:02:25 matt Exp $") + +#include "sysident.S" + + .section ".init", "ax", @progbits + .align 2; .globl _init; .type _init,@function +_init: + mflr %r0 + stw %r0, (1*SZREG)(%r1) + stwu %r1, -(4*SZREG)(%r1) + + .section ".fini", "ax", @progbits + .align 2; .globl _fini; .type _fini,@function +_fini: + mflr %r0 + stw %r0, (1*SZREG)(%r1) + stwu %r1, -(4*SZREG)(%r1) diff --git a/lib/csu/arch/powerpc/crtn.S b/lib/csu/arch/powerpc/crtn.S new file mode 100644 index 000000000..78584c529 --- /dev/null +++ b/lib/csu/arch/powerpc/crtn.S @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crtn.S,v 1.1 2011/02/08 02:02:25 matt Exp $") + + .section ".init", "ax", @progbits + addi %r1, %r1, (4*SZREG) + lwz %r0, (1*SZREG)(%r1) + mtlr %r0 + blr + + .section ".fini", "ax", @progbits + addi %r1, %r1, (4*SZREG) + lwz %r0, (1*SZREG)(%r1) + mtlr %r0 + blr diff --git a/lib/csu/arch/sh3/crt0.S b/lib/csu/arch/sh3/crt0.S index 86ddcf52b..c4c9b4c0a 100644 --- a/lib/csu/arch/sh3/crt0.S +++ b/lib/csu/arch/sh3/crt0.S @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */ +/* $NetBSD: crt0.S,v 1.4 2012/01/31 20:17:57 uwe Exp $ */ /* * Copyright (c) 1998 Christos Zoulas @@ -37,11 +37,23 @@ #include -RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $") +RCSID("$NetBSD: crt0.S,v 1.4 2012/01/31 20:17:57 uwe Exp $") STRONG_ALIAS(_start,__start) +/* + * Kernel setregs() passes arguments for the 6-argument version of + * ___start (but with 5th and 6th in registers, to avoid copyout). + * Since we now use 3-argument version of ___start - that obtains + * argc, argv and environ from ps_strings - move its arguments to + * proper registers. + */ _ENTRY(__start) - mov.l r9,@-r15 - bra ___start - mov.l r8,@-r15 + mov.l .L___start, r0 + mov r7, r4 ! void (*cleanup)(void) + mov r8, r5 ! const Obj_Entry *obj + jmp @r0 + mov r9, r6 ! struct ps_strings *ps_strings + + .p2align 2 +.L___start: .long _C_LABEL(___start) diff --git a/lib/csu/arch/sh3/crtbegin.S b/lib/csu/arch/sh3/crtbegin.S new file mode 100644 index 000000000..033d9b77b --- /dev/null +++ b/lib/csu/arch/sh3/crtbegin.S @@ -0,0 +1,366 @@ +/* $NetBSD: crtbegin.S,v 1.2 2012/06/02 22:15:15 uwe Exp $ */ +/*- + * Copyright (c) 2012 Valeriy E. Ushakov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crtbegin.S,v 1.2 2012/06/02 22:15:15 uwe Exp $") + + .section .ctors, "aw", @progbits + .p2align 2 +__CTOR_LIST__: + .long -1 + + .section .dtors, "aw", @progbits + .p2align 2 +__DTOR_LIST__: + .long -1 + + .section .eh_frame, "a", @progbits + .p2align 2 +__EH_FRAME_LIST__: + + .section .jcr, "aw", @progbits + .p2align 2 +__JCR_LIST__: + + .section .data.rel, "aw", @progbits + .p2align 2 + .globl __dso_handle + .hidden __dso_handle + .type __dso_handle, @object + .size __dso_handle, 4 +__dso_handle: +#ifdef SHARED + .long __dso_handle +#else + .long 0 +#endif + +__dwarf_eh_object: + .zero 32 + +__initialized: + .zero 1 +__finished: + .zero 1 + + .text + .weak __cxa_finalize + .weak __deregister_frame_info + .weak __register_frame_info + .weak _Jv_RegisterClasses + +/* + * A bit of CPP syntactic sugar for accessing variables. + * + * For PIC we are obliged to use @(r0, r12) since r12 has the GOT + * address and only r0 can be used in @(r0, Rm) addressing mode, so we + * always load variable address to r0. + */ +#ifdef PIC +#define VAR_DATUM(var) var@GOTOFF +#define FUNC_DATUM(f) f@GOT +#define R0VAR (r0, r12) +#else +#define VAR_DATUM(var) var +#define FUNC_DATUM(f) f +#define R0VAR r0 +#endif + + +__do_global_ctors_aux: + mov.l r8, @-sp + mov.l r9, @-sp +#ifdef PIC + mov.l r12, @-sp + mov.l .Lc_got, r12 + mova .Lc_got, r0 + add r0, r12 +#endif + mov.l r14, @-sp + sts.l pr, @-sp + mov sp, r14 + + !! if (__initialized) return; + mov.l .Lc___initialized, r0 + mov.b @R0VAR, r1 + tst r1, r1 + bf .Lc_return + + !! __initialized = 1; + mov #1, r1 + mov.b r1, @R0VAR + + + !! if (__register_frame_info) + !! __register_frame_info(&__EH_FRAME_LIST__[0], &__dwarf_eh_object) +#ifdef PIC + mov.l .Lc___register_frame_info_GOT, r0 + mov.l @R0VAR, r1 + tst r1, r1 + bt .Lc___register_frame_info_done + mov.l .Lc___register_frame_info, r0 + mov.l .Lc___EH_FRAME_LIST__, r4 + mov.l .Lc___dwarf_eh_object, r5 + add r12, r4 +.Lc___register_frame_info_call: + CALL r0 + add r12, r5 +#else /* !PIC */ + mov.l .Lc___register_frame_info, r0 + tst r0, r0 + bt .Lc___register_frame_info_done + mov.l .Lc___EH_FRAME_LIST__, r4 + mov.l .Lc___dwarf_eh_object, r5 + CALL r0 + nop +#endif +.Lc___register_frame_info_done: + + !! if (_Jv_RegisterClasses && __JCR_LIST__[0]) + !! _Jv_RegisterClasses(&__JCR_LIST__[0]); +#ifdef PIC + mov.l .Lc__Jv_RegisterClasses_GOT, r0 + mov.l @R0VAR, r1 + tst r1, r1 + bt .Lc__Jv_RegisterClasses_done + + mov.l .Lc___JCR_LIST__, r0 + mov.l @R0VAR, r1 + tst r1, r1 + bt .Lc__Jv_RegisterClasses_done + + mov.l .Lc__Jv_RegisterClasses, r2 + mov r0, r4 +.Lc__Jv_RegisterClasses_call: + CALL r2 + add r12, r4 + +#else /* !PIC */ + mov.l .Lc__Jv_RegisterClasses, r2 + tst r2, r2 + bt .Lc__Jv_RegisterClasses_done + + mov.l .Lc___JCR_LIST__, r0 + mov.l @R0VAR, r1 + tst r1, r1 + bt .Lc__Jv_RegisterClasses_done + + mov r0, r4 +.Lc__Jv_RegisterClasses_call: + CALL r2 + add r12, r4 +#endif +.Lc__Jv_RegisterClasses_done: + + + !! call all constructors on __CTOR_LIST__ in reverse order + mov.l .Lc___CTOR_LIST_END__, r8 +#ifdef PIC + add r12, r8 +#endif + add #-4, r8 + mov.l @r8, r9 + not r9, r0 ! sentinel at __CTOR_LIST__[0] is -1 +.Lc_ctor_list_loop: + tst r0, r0 + bt.s .Lc_ctor_list_done + add #-4, r8 + jsr @r9 + mov.l @r8, r9 + bra .Lc_ctor_list_loop + not r9, r0 +.Lc_ctor_list_done: + +.Lc_return: + mov r14, sp + lds.l @sp+, pr + mov.l @sp+, r14 +#ifdef PIC + mov.l @sp+, r12 +#endif + mov.l @sp+, r9 + rts + mov.l @sp+, r8 + + .p2align 2 +.Lc_got: + PIC_GOT_DATUM +.Lc___initialized: + .long VAR_DATUM(__initialized) +#ifdef PIC +.Lc___register_frame_info_GOT: + .long __register_frame_info@GOT +#endif +.Lc___register_frame_info: + CALL_DATUM(__register_frame_info, .Lc___register_frame_info_call) +.Lc___EH_FRAME_LIST__: + .long VAR_DATUM(__EH_FRAME_LIST__) +.Lc___dwarf_eh_object: + .long VAR_DATUM(__dwarf_eh_object) +#ifdef PIC +.Lc__Jv_RegisterClasses_GOT: + .long _Jv_RegisterClasses@GOT +#endif +.Lc__Jv_RegisterClasses: + CALL_DATUM(_Jv_RegisterClasses, .Lc__Jv_RegisterClasses_call) +.Lc___JCR_LIST__: + .long VAR_DATUM(__JCR_LIST__) +.Lc___CTOR_LIST_END__: + .long VAR_DATUM(__CTOR_LIST_END__) + + +__do_global_dtors_aux: + mov.l r8, @-sp + mov.l r9, @-sp +#ifdef PIC + mov.l r12, @-sp + mov.l .Ld_got, r12 + mova .Ld_got, r0 + add r0, r12 +#endif + mov.l r14, @-sp + sts.l pr, @-sp + mov sp, r14 + + !! if (__finished) return; + mov.l .Ld___finished, r0 + mov.b @R0VAR, r1 + tst r1, r1 + bf .Ld_return + + !! __finished = 1; + mov #1, r1 + mov.b r1, @R0VAR + +#ifdef SHARED /* implies PIC */ + !! if (__cxa_finalize) + !! __cxa_finalize(&__dso_handle); + mov.l .Ld___cxa_finalize_GOT, r0 + mov.l @R0VAR, r1 + tst r1, r1 + bt .Ld___cxa_finalize_done + mov.l .Ld___cxa_finalize, r0 + mov.l .Ld___dso_handle, r4 +.Ld___cxa_finalize_call: + CALL r0 + add r12, r4 +.Ld___cxa_finalize_done: +#endif /* SHARED */ + + !! call all destructors on __DTOR_LIST__ + mov.l .Ld___DTOR_LIST__, r8 +#ifdef PIC + add r12, r8 +#endif + add #4, r8 ! skip first entry that we know to be -1 + mov.l @r8+, r9 + tst r9, r9 +.Ld_dtor_list_loop: + bt .Ld_dtor_list_done + jsr @r9 + mov.l @r8+, r9 + bra .Ld_dtor_list_loop + tst r9, r9 +.Ld_dtor_list_done: + + !! if (__deregister_frame_info) + !! __deregister_frame_info(&__EH_FRAME_LIST__[0]); +#ifdef PIC + mov.l .Ld___deregister_frame_info_GOT, r0 + mov.l @R0VAR, r1 + tst r1, r1 + bt .Ld___deregister_frame_info_done + mov.l .Ld___deregister_frame_info, r0 + mov.l .Ld___EH_FRAME_LIST__, r4 +.Ld___deregister_frame_info_call: + CALL r0 + add r12, r4 +#else /* !PIC */ + mov.l .Ld___deregister_frame_info, r0 + tst r0, r0 + bt .Ld___deregister_frame_info_done + mov.l .Ld___EH_FRAME_LIST__, r4 + CALL r0 + nop +#endif +.Ld___deregister_frame_info_done: + +.Ld_return: + mov r14, sp + lds.l @sp+, pr + mov.l @sp+, r14 +#ifdef PIC + mov.l @sp+, r12 +#endif + mov.l @sp+, r9 + rts + mov.l @sp+, r8 + + .p2align 2 +.Ld_got: + PIC_GOT_DATUM +.Ld___finished: + .long VAR_DATUM(__finished) +#ifdef SHARED /* implies PIC */ +.Ld___cxa_finalize_GOT: + .long __cxa_finalize@GOT +.Ld___cxa_finalize: + CALL_DATUM(__cxa_finalize, .Ld___cxa_finalize_call) +.Ld___dso_handle: + .long VAR_DATUM(__dso_handle) +#endif +.Ld___DTOR_LIST__: + .long VAR_DATUM(__DTOR_LIST__) +#ifdef PIC +.Ld___deregister_frame_info_GOT: + .long __deregister_frame_info@GOT +#endif +.Ld___deregister_frame_info: + CALL_DATUM(__deregister_frame_info, .Ld___deregister_frame_info_call) +.Ld___EH_FRAME_LIST__: + .long VAR_DATUM(__EH_FRAME_LIST__) + + + +#define _CALL_INIT_FINI_FUNCTION(func) \ + mov.l 1f, r1; \ + mova 2f, r0; \ +0: braf r1; /* NB: branch, not call ... */ \ + lds r0, pr; /* skip the following .long when returning */ \ + .p2align 2; \ +1: .long func - (0b+4); \ +2: ; + + .section .init, "ax", @progbits + _CALL_INIT_FINI_FUNCTION(__do_global_ctors_aux) + + .section .fini, "ax", @progbits + _CALL_INIT_FINI_FUNCTION(__do_global_dtors_aux) diff --git a/lib/csu/arch/sh3/crtend.S b/lib/csu/arch/sh3/crtend.S new file mode 100644 index 000000000..c7c37f269 --- /dev/null +++ b/lib/csu/arch/sh3/crtend.S @@ -0,0 +1,52 @@ +/* $NetBSD: crtend.S,v 1.2 2012/01/31 20:12:47 uwe Exp $ */ +/*- + * Copyright (c) 2010 Joerg Sonnenberger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +RCSID("$NetBSD: crtend.S,v 1.2 2012/01/31 20:12:47 uwe Exp $") + + .section .ctors, "aw", @progbits + .p2align 2 + .global __CTOR_LIST_END__ + .hidden __CTOR_LIST_END__ +__CTOR_LIST_END__: + .long 0 + + .section .dtors, "aw", @progbits + .p2align 2 + .long 0 + + .section .eh_frame, "a", @progbits + .p2align 2 + .long 0 + + .section .jcr, "aw", @progbits + .p2align 2 + .long 0 diff --git a/lib/csu/arch/sh3/crti.S b/lib/csu/arch/sh3/crti.S index 808c363f6..7966c7f32 100644 --- a/lib/csu/arch/sh3/crti.S +++ b/lib/csu/arch/sh3/crti.S @@ -1,4 +1,4 @@ -/* $NetBSD: crti.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */ +/* $NetBSD: crti.S,v 1.3 2012/01/31 20:12:47 uwe Exp $ */ /*- * Copyright (c) 2001 Ross Harvey @@ -35,12 +35,18 @@ #include -RCSID("$NetBSD: crti.S,v 1.1 2010/08/07 18:01:34 joerg Exp $") +RCSID("$NetBSD: crti.S,v 1.3 2012/01/31 20:12:47 uwe Exp $") #include "sysident.S" + +/* + * Provide function prologues for the code in .init and .fini sections. + * Corresponding epilogues are in crtn.S + */ + .section ".init", "ax", @progbits - .align 4 + .p2align 2 .globl _init _init: mov.l r14, @-sp @@ -48,7 +54,7 @@ _init: mov sp, r14 .section ".fini", "ax", @progbits - .align 4 + .p2align 2 .globl _fini _fini: mov.l r14, @-sp diff --git a/lib/csu/arch/sh3/crtn.S b/lib/csu/arch/sh3/crtn.S index 54edfb99c..f950e1521 100644 --- a/lib/csu/arch/sh3/crtn.S +++ b/lib/csu/arch/sh3/crtn.S @@ -1,4 +1,4 @@ -/* $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */ +/* $NetBSD: crtn.S,v 1.2 2012/01/28 12:45:43 uwe Exp $ */ /*- * Copyright (c) 2001 Ross Harvey @@ -35,7 +35,13 @@ #include -RCSID("$NetBSD: crtn.S,v 1.1 2010/08/07 18:01:34 joerg Exp $") +RCSID("$NetBSD: crtn.S,v 1.2 2012/01/28 12:45:43 uwe Exp $") + + +/* + * Provide function epilogues for the code in .init and .fini sections. + * Corresponding prologues are in crti.S + */ .section ".init", "ax", @progbits mov r14, sp diff --git a/lib/csu/arch/vax/crt0.S b/lib/csu/arch/vax/crt0.S index 2db43a5a9..d4529219a 100644 --- a/lib/csu/arch/vax/crt0.S +++ b/lib/csu/arch/vax/crt0.S @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */ +/* $NetBSD: crt0.S,v 1.2 2011/07/02 20:14:10 matt Exp $ */ /* * Copyright (c) 1999 Matt Thomas @@ -37,7 +37,7 @@ #include -RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $") +RCSID("$NetBSD: crt0.S,v 1.2 2011/07/02 20:14:10 matt Exp $") STRONG_ALIAS(_start,__start) @@ -46,8 +46,4 @@ _ENTRY(__start) pushl %r9 /* ps_strings */ pushl %r8 /* obj */ pushl %r7 /* cleanup */ - movl (%r6),%r0 /* argc */ - pushal 8(%r6)[%r0] /* envp = &argv[argc + 1] */ - pushal 4(%r6) /* argv */ - pushl %r0 /* argc */ - calls $6,___start + calls $3,___start diff --git a/lib/csu/arch/x86_64/crt0.S b/lib/csu/arch/x86_64/crt0.S index 39bf6eec4..8ee9871a5 100644 --- a/lib/csu/arch/x86_64/crt0.S +++ b/lib/csu/arch/x86_64/crt0.S @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $ */ +/* $NetBSD: crt0.S,v 1.3 2011/07/01 02:59:05 joerg Exp $ */ /* * Copyright (c) 1998 Christos Zoulas @@ -35,18 +35,15 @@ #include -RCSID("$NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $") +RCSID("$NetBSD: crt0.S,v 1.3 2011/07/01 02:59:05 joerg Exp $") STRONG_ALIAS(_start,__start) + .hidden ___start _ENTRY(__start) - movq %rbx,%r9 - movq %rcx,%r8 - movq %rdx,%rcx - movq (%rsp),%rdi - leaq 16(%rsp,%rdi,8),%rdx - leaq 8(%rsp),%rsi - subq $8,%rsp - andq $~15,%rsp - addq $8,%rsp + andq $~15,%rsp + subq $8,%rsp + movq %rdx, %rdi + movq %rcx, %rsi + movq %rbx, %rdx jmp ___start diff --git a/lib/csu/arm_elf/crt0.c b/lib/csu/arm_elf/crt0.c index fa2aa2b31..3a3ff063e 100644 --- a/lib/csu/arm_elf/crt0.c +++ b/lib/csu/arm_elf/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.7 2008/06/21 00:52:52 gmcgarry Exp $ */ +/* $NetBSD: crt0.c,v 1.10 2012/01/25 13:29:58 he Exp $ */ /* * Copyright (C) 1997 Mark Brinicombe @@ -60,7 +60,7 @@ __asm(" .text \n" " add r2, r2, #0x0004 \n" "\n" " /* Ensure the stack is properly aligned before calling C code. */\n" -" bic sp, sp, #" ___STRING(STACKALIGNBYTES) " \n" +" bic sp, sp, #" ___STRING(STACK_ALIGNBYTES) "\n" " sub sp, sp, #8 \n" " str r5, [sp, #4] \n" " str r4, [sp, #0] \n" @@ -68,7 +68,7 @@ __asm(" .text \n" " b " ___STRING(_C_LABEL(___start)) " "); #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.7 2008/06/21 00:52:52 gmcgarry Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.10 2012/01/25 13:29:58 he Exp $"); #endif /* LIBC_SCCS and not lint */ void @@ -89,10 +89,12 @@ ___start(int argc, char **argv, char **envp, struct ps_strings *ps_strings, #ifdef DYNAMIC /* ld(1) convention: if DYNAMIC = 0 then statically linked */ - if (&_DYNAMIC) + if (&rtld_DYNAMIC) _rtld_setup(cleanup, obj); #endif /* DYNAMIC */ + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); diff --git a/lib/csu/arm_elf/dot_init.h b/lib/csu/arm_elf/dot_init.h index 275185abc..46f4b8de5 100644 --- a/lib/csu/arm_elf/dot_init.h +++ b/lib/csu/arm_elf/dot_init.h @@ -1,4 +1,4 @@ -/* $NetBSD: dot_init.h,v 1.6 2008/05/10 15:31:03 martin Exp $ */ +/* $NetBSD: dot_init.h,v 1.9 2012/08/05 01:44:43 matt Exp $ */ /*- * Copyright (c) 2001 Ross Harvey diff --git a/lib/csu/common/Makefile.inc b/lib/csu/common/Makefile.inc index c3a479cd7..98b50d23e 100644 --- a/lib/csu/common/Makefile.inc +++ b/lib/csu/common/Makefile.inc @@ -82,6 +82,5 @@ FILESDIR=${LIBDIR} CLEANFILES+=${OBJS} SYMLINKS+= crtbegin.o ${LIBDIR}/crtbeginT.o SYMLINKS+= crtend.o ${LIBDIR}/crtendS.o -SYMLINKS+= crt0.o ${LIBDIR}/crt1.o .include diff --git a/lib/csu/common/crt0-common.c b/lib/csu/common/crt0-common.c index 77e1a0984..49c085684 100644 --- a/lib/csu/common/crt0-common.c +++ b/lib/csu/common/crt0-common.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0-common.c,v 1.1 2010/08/07 18:01:33 joerg Exp $ */ +/* $NetBSD: crt0-common.c,v 1.9 2012/08/13 02:15:35 matt Exp $ */ /* * Copyright (c) 1998 Christos Zoulas @@ -36,9 +36,10 @@ */ #include -__RCSID("$NetBSD: crt0-common.c,v 1.1 2010/08/07 18:01:33 joerg Exp $"); +__RCSID("$NetBSD: crt0-common.c,v 1.9 2012/08/13 02:15:35 matt Exp $"); #include +#include #ifndef __minix #include #endif @@ -50,8 +51,11 @@ __RCSID("$NetBSD: crt0-common.c,v 1.1 2010/08/07 18:01:33 joerg Exp $"); extern int main(int, char **, char **); +#ifndef HAVE_INITFINI_ARRAY extern void _init(void); extern void _fini(void); +#endif +extern void _libc_init(void); /* * Arrange for _DYNAMIC to be weak and undefined (and therefore to show up @@ -60,13 +64,7 @@ extern void _fini(void); * shared libs present, things will still work. */ -#if __GNUC_PREREQ__(4,2) -static int rtld_DYNAMIC __attribute__((__weakref__, __alias__("_DYNAMIC"))); -#define DYNAMIC_SYM rtld_DYNAMIC -#else -extern int _DYNAMIC __weak_reference(_DYNAMIC); -#define DYNAMIC_SYM _DYNAMIC -#endif +__weakref_visible int rtld_DYNAMIC __weak_reference(_DYNAMIC); #ifdef MCRT0 extern void monstartup(u_long, u_long); @@ -80,12 +78,15 @@ struct ps_strings *__ps_strings = 0; static char empty_string[] = ""; char *__progname = empty_string; -void ___start(int, char **, char **, void (*)(void), - const Obj_Entry *, struct ps_strings *); - #ifndef __minix +__dead __dso_hidden void ___start(void (*)(void), const Obj_Entry *, + struct ps_strings *); + #define write(fd, s, n) __syscall(SYS_write, (fd), (s), (n)) #else +__dead __dso_hidden void ___start(int, char **, char **, void (*)(void), + const Obj_Entry *, struct ps_strings *); + #define write(fd, s, n) /* NO write() from here on minix */ #endif @@ -95,18 +96,69 @@ do { \ _exit(1); \ } while (0) +#ifdef HAVE_INITFINI_ARRAY +/* + * If we are using INIT_ARRAY/FINI_ARRAY and we are linked statically, + * we have to process these instead of relying on RTLD to do it for us. + * + * Since we don't need .init or .fini sections, just code them in C + * to make life easier. + */ +static const fptr_t init_array_start[] __weak_reference(__init_array_start); +static const fptr_t init_array_end[] __weak_reference(__init_array_end); +static const fptr_t fini_array_start[] __weak_reference(__fini_array_start); +static const fptr_t fini_array_end[] __weak_reference(__fini_array_end); + +static inline void +_init(void) +{ + for (const fptr_t *f = init_array_start; f < init_array_end; f++) { + (*f)(); + } +} + +static void +_fini(void) +{ + for (const fptr_t *f = fini_array_start; f < fini_array_end; f++) { + (*f)(); + } +} +#endif /* HAVE_INITFINI_ARRAY */ + void +#ifdef __minix ___start(int argc, char **argv, char **envp, - void (*cleanup)(void), /* from shared loader */ + void (*cleanup)(void), /* from shared loader */ +#else +___start(void (*cleanup)(void), /* from shared loader */ +#endif /* __minix */ const Obj_Entry *obj, /* from shared loader */ struct ps_strings *ps_strings) { - environ = envp; +#ifdef __minix + /* LSC: We have not yet updated the way we pass arguments to + the userspace, so here some code to adapt this to the new + ways. */ + struct ps_strings minix_ps_strings; + + if (ps_strings == NULL) { + minix_ps_strings.ps_envstr = envp; + minix_ps_strings.ps_argvstr = argv; + minix_ps_strings.ps_nargvstr = argc; + ps_strings = &minix_ps_strings; + } +#endif /* __minix */ + if (ps_strings == NULL) + _FATAL("ps_strings missing\n"); + __ps_strings = ps_strings; + + environ = ps_strings->ps_envstr; - if (argv[0] != NULL) { + if (ps_strings->ps_argvstr[0] != NULL) { char *c; - __progname = argv[0]; - for (c = argv[0]; *c; ++c) { + __progname = ps_strings->ps_argvstr[0]; + for (c = ps_strings->ps_argvstr[0]; *c; ++c) { if (*c == '/') __progname = c + 1; } @@ -114,17 +166,18 @@ ___start(int argc, char **argv, char **envp, __progname = empty_string; } - if (ps_strings != NULL) - __ps_strings = ps_strings; - - if (&DYNAMIC_SYM != NULL) { - if ((obj == NULL) || (obj->magic != RTLD_MAGIC)) + if (&rtld_DYNAMIC != NULL) { + if (obj == NULL) + _FATAL("NULL Obj_Entry pointer in GOT\n"); + if (obj->magic != RTLD_MAGIC) _FATAL("Corrupt Obj_Entry pointer in GOT\n"); if (obj->version != RTLD_VERSION) _FATAL("Dynamic linker version mismatch\n"); atexit(cleanup); } + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&__eprol, (u_long)&__etext); @@ -133,5 +186,5 @@ ___start(int argc, char **argv, char **envp, atexit(_fini); _init(); - exit(main(argc, argv, environ)); + exit(main(ps_strings->ps_nargvstr, ps_strings->ps_argvstr, environ)); } diff --git a/lib/csu/common_elf/Makefile.inc b/lib/csu/common_elf/Makefile.inc index 0e489d59b..08df8b60d 100644 --- a/lib/csu/common_elf/Makefile.inc +++ b/lib/csu/common_elf/Makefile.inc @@ -6,11 +6,7 @@ ELFSIZE=32 .include "../../Makefile.inc" -.if defined(__MINIX) && ${MACHINE_ARCH} == "arm" -CPPFLAGS+= -DLIBC_SCCS -DPIC -DELFSIZE=${ELFSIZE} -.else CPPFLAGS+= -DLIBC_SCCS -DPIC -DDYNAMIC -DELFSIZE=${ELFSIZE} -.endif CPPFLAGS+= -I${NETBSDSRCDIR}/libexec/ld.elf_so CPPFLAGS+= -I${.CURDIR}/../common_elf CPPFLAGS+= -I${NETBSDSRCDIR}/lib/libc/dlfcn diff --git a/lib/csu/common_elf/common.h b/lib/csu/common_elf/common.h index f121aaf6d..8fd1e04a1 100644 --- a/lib/csu/common_elf/common.h +++ b/lib/csu/common_elf/common.h @@ -1,4 +1,4 @@ -/* $NetBSD: common.h,v 1.13 2009/12/14 01:04:02 matt Exp $ */ +/* $NetBSD: common.h,v 1.16 2012/03/21 10:09:20 matt Exp $ */ /* * Copyright (c) 1995 Christopher G. Demetriou @@ -68,11 +68,12 @@ do { \ static char *_strrchr(char *, int); char **environ; -char *__progname = ""; +char *__progname = __UNCONST(""); struct ps_strings *__ps_strings = 0; extern void _init(void); extern void _fini(void); +extern void _libc_init(void); #ifdef DYNAMIC void _rtld_setup(void (*)(void), const Obj_Entry *obj); @@ -83,7 +84,7 @@ void _rtld_setup(void (*)(void), const Obj_Entry *obj); * if we happen to be compiling without -static but with without any * shared libs present, things will still work. */ -extern int _DYNAMIC __weak_reference(_DYNAMIC); +__weakref_visible int rtld_DYNAMIC __weak_reference(_DYNAMIC); #endif /* DYNAMIC */ #ifdef MCRT0 diff --git a/lib/csu/hppa/crt0.c b/lib/csu/hppa/crt0.c index f46b3f035..cee69a2ff 100644 --- a/lib/csu/hppa/crt0.c +++ b/lib/csu/hppa/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.7 2004/08/26 21:07:14 thorpej Exp $ */ +/* $NetBSD: crt0.c,v 1.10 2011/03/07 05:09:10 joerg Exp $ */ /* * Copyright (c) 2002 Matt Fredette @@ -89,31 +89,12 @@ ___start(struct ps_strings *ps_strings, __ps_strings = ps_strings; #ifdef DYNAMIC - /* - * XXX fredette - when not compiling PIC, you currently - * can't detect an undefined weak symbol by seeing if - * its address is NULL. The compiler emits code to find - * _DYNAMIC relative to %dp, the assembler notes the - * needed relocations, but when the linker sees that the - * (weak) symbol isn't defined it drops the ball - the - * relocations are never filled, and the binary ends up - * with code that sees an address of %dp plus zero, - * which != NULL. - * - * Arguably the linker could/should distinguish between - * code that is after a weak undefined symbol's contents - * from code that is after its address. In the first case, - * it would warn and/or bail. In the second case, it - * would fix up instructions to give a symbol address - * of NULL. - * - * For now, we take the easy way out and compare &_DYNAMIC - * to %dp, as well as to NULL. - */ - if (&_DYNAMIC != NULL && (int)&_DYNAMIC != dp) + if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); @@ -152,7 +133,7 @@ ___start(struct ps_strings *ps_strings, * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text. */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.7 2004/08/26 21:07:14 thorpej Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.10 2011/03/07 05:09:10 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/ia64/crt0.c b/lib/csu/ia64/crt0.c index 3983db92c..82201672b 100644 --- a/lib/csu/ia64/crt0.c +++ b/lib/csu/ia64/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.2 2006/09/15 05:29:44 skrll Exp $ */ +/* $NetBSD: crt0.c,v 1.4 2011/03/07 05:09:10 joerg Exp $ */ /* * Copyright (c) 1995 Christopher G. Demetriou @@ -72,10 +72,12 @@ __start(char **sp, __ps_strings = ps_strings; #ifdef DYNAMIC - if (&_DYNAMIC != NULL) + if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); @@ -91,7 +93,7 @@ __start(char **sp, * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text. */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.2 2006/09/15 05:29:44 skrll Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.4 2011/03/07 05:09:10 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/m68k_elf/crt0.c b/lib/csu/m68k_elf/crt0.c index fcb5e7597..fcce8e65b 100644 --- a/lib/csu/m68k_elf/crt0.c +++ b/lib/csu/m68k_elf/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.11 2004/08/26 21:09:52 thorpej Exp $ */ +/* $NetBSD: crt0.c,v 1.13 2011/03/07 05:09:10 joerg Exp $ */ /* * Copyright (c) 1999 Klaus Klein @@ -75,10 +75,12 @@ __start(int argc, char **argv, char **envp, __ps_strings = ps_strings; #ifdef DYNAMIC - if (&_DYNAMIC != NULL) + if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); @@ -94,7 +96,7 @@ __start(int argc, char **argv, char **envp, * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text. */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.11 2004/08/26 21:09:52 thorpej Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.13 2011/03/07 05:09:10 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/mips/crt0.c b/lib/csu/mips/crt0.c index 32418382c..ac19baa41 100644 --- a/lib/csu/mips/crt0.c +++ b/lib/csu/mips/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.20 2009/12/14 01:04:02 matt Exp $ */ +/* $NetBSD: crt0.c,v 1.22 2011/02/22 05:45:07 joerg Exp $ */ /* * Copyright (c) 1995 Christopher G. Demetriou @@ -52,13 +52,13 @@ * as well as the usual registers (pc, sp, and t9 == pc for ABI). */ -void __start(u_long, void (*)(void), const Obj_Entry *, +void __start(uintptr_t, void (*)(void), const Obj_Entry *, struct ps_strings *); __asm(".text; .align 4; .globl _start; _start:"); void -__start(u_long sp, +__start(uintptr_t sp, void (*cleanup)(void), /* from shared loader */ const Obj_Entry *obj, /* from shared loader */ struct ps_strings *ps_strings) @@ -118,7 +118,7 @@ __start(u_long sp, #endif - argc = *(int *)ksp; + argc = *(long *)ksp; argv = ksp + 1; environ = ksp + 2 + argc; /* 2: argc + NULL ending argv */ @@ -142,14 +142,14 @@ __start(u_long sp, * XXX If we were loaded by that loader, just abort * XXX the rtld setup. */ - if (&_DYNAMIC != NULL && cleanup != NULL && obj != NULL) + if (&rtld_DYNAMIC != NULL && cleanup != NULL && obj != NULL) _rtld_setup(cleanup, obj); #endif } #ifdef MCRT0 atexit(_mcleanup); - monstartup((u_long)&_eprol, (u_long)&_etext); + monstartup((uintptr_t)&_eprol, (uintptr_t)&_etext); #endif atexit(_fini); @@ -163,7 +163,7 @@ __start(u_long sp, * is the entrypoint. (Only needed for old toolchains). */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.20 2009/12/14 01:04:02 matt Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.22 2011/02/22 05:45:07 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/powerpc/crt0.c b/lib/csu/powerpc/crt0.c index 4f0e77793..8e5cb84f8 100644 --- a/lib/csu/powerpc/crt0.c +++ b/lib/csu/powerpc/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.26 2006/05/18 17:54:19 christos Exp $ */ +/* $NetBSD: crt0.c,v 1.30 2011/03/12 07:56:36 matt Exp $ */ /* * Copyright (c) 1997 Jason R. Thorpe. @@ -41,8 +41,8 @@ * Small Data Area designators. If not defined, will show up as being * at address zero. */ -extern int _SDA_BASE_[] __weak_reference(_SDA_BASE_); -extern int _SDA2_BASE_[] __weak_reference(_SDA2_BASE_); +__weakref_visible int rtld_SDA_BASE_[] __weak_reference(_SDA_BASE_); +__weakref_visible int rtld_SDA2_BASE_[] __weak_reference(_SDA2_BASE_); /* * First 5 arguments are specified by the PowerPC SVR4 ABI. The @@ -62,12 +62,15 @@ _start(int argc, char **argv, char **envp, /* * Initialize the Small Data Area registers. * _SDA_BASE is defined in the SVR4 ABI for PPC. - * _SDA2_BASE is defined in the E[mbedded] ABI for PPC. + * + * Do the initialization in a PIC manner. */ - __asm( "lis %r13,_SDA_BASE_@ha;" - "addi %r13,%r13,_SDA_BASE_@l;" - "lis %r2,_SDA2_BASE_@ha;" - "addi %r2,%r2,_SDA2_BASE_@l" ); + __asm( + "bcl 20,31,1f;" + "1: mflr 11;" + "addis 13,11,rtld_SDA_BASE_-1b@ha;" + "addi 13,13,rtld_SDA_BASE_-1b@l;" + ::: "lr" ); if ((namep = argv[0]) != NULL) { /* NULL ptr if argc = 0 */ if ((__progname = _strrchr(namep, '/')) == NULL) @@ -82,10 +85,12 @@ _start(int argc, char **argv, char **envp, __ps_strings = ps_strings; #ifdef DYNAMIC - if (&_DYNAMIC != NULL) + if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); @@ -101,7 +106,7 @@ _start(int argc, char **argv, char **envp, * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text. */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.26 2006/05/18 17:54:19 christos Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.30 2011/03/12 07:56:36 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/powerpc/dot_init.h b/lib/csu/powerpc/dot_init.h index 6918dd7a9..cb6d1f1c6 100644 --- a/lib/csu/powerpc/dot_init.h +++ b/lib/csu/powerpc/dot_init.h @@ -1,4 +1,4 @@ -/* $NetBSD: dot_init.h,v 1.7 2008/05/10 15:31:04 martin Exp $ */ +/* $NetBSD: dot_init.h,v 1.8 2011/07/02 07:28:08 matt Exp $ */ /*- * Copyright (c) 2001 Ross Harvey @@ -40,18 +40,18 @@ ".section "#sect",\"ax\",@progbits \n" \ ".global "#entry_pt" \n" \ #entry_pt": \n" \ - " stwu %r1,-16(%r1) \n" \ " mflr %r0 \n" \ - " stw %r0,12(%r1) \n" \ + " stw %r0,4(%r1) \n" \ + " stwu %r1,-16(%r1) \n" \ " /* fall thru */ \n" \ ".previous") #define MD_SECTION_EPILOGUE(sect) \ __asm ( \ ".section "#sect",\"ax\",@progbits \n" \ - " lwz %r0,12(%r1) \n" \ + " addi %r1,%r1,16 \n" \ + " lwz %r0,4(%r1) \n" \ " mtlr %r0 \n" \ - " la %r1,16(%r1) \n" \ " blr \n" \ ".previous") diff --git a/lib/csu/powerpc64/Makefile b/lib/csu/powerpc64/Makefile index 3231bfab9..3774e1c31 100644 --- a/lib/csu/powerpc64/Makefile +++ b/lib/csu/powerpc64/Makefile @@ -1,5 +1,5 @@ -# $NetBSD: Makefile,v 1.1 2006/06/30 22:49:50 ross Exp $ +# $NetBSD: Makefile,v 1.2 2011/10/29 10:28:37 mrg Exp $ -CPPFLAGS+= -I- -I${.CURDIR} +CPPFLAGS+= -I${.CURDIR} .include "${.CURDIR}/../common_elf/Makefile.inc" diff --git a/lib/csu/powerpc64/crt0.c b/lib/csu/powerpc64/crt0.c index 8ee36609c..98b155ae9 100644 --- a/lib/csu/powerpc64/crt0.c +++ b/lib/csu/powerpc64/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.2 2006/07/01 01:39:17 ross Exp $ */ +/* $NetBSD: crt0.c,v 1.4 2011/03/07 05:09:10 joerg Exp $ */ /* * Copyright (c) 1997 Jason R. Thorpe. @@ -74,10 +74,12 @@ _start(int argc, char **argv, char **envp, __ps_strings = ps_strings; #ifdef DYNAMIC - if (&_DYNAMIC != NULL) + if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); @@ -93,7 +95,7 @@ _start(int argc, char **argv, char **envp, * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text. */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.2 2006/07/01 01:39:17 ross Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.4 2011/03/07 05:09:10 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/sh3_elf/crt0.c b/lib/csu/sh3_elf/crt0.c index f47cea219..7d2007b98 100644 --- a/lib/csu/sh3_elf/crt0.c +++ b/lib/csu/sh3_elf/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.10 2004/08/26 21:16:41 thorpej Exp $ */ +/* $NetBSD: crt0.c,v 1.12 2011/03/07 05:09:11 joerg Exp $ */ /* * Copyright (c) 1998 Christos Zoulas @@ -69,10 +69,12 @@ ___start(int argc, char **argv, char **envp, __ps_strings = ps_strings; #ifdef DYNAMIC - if (&_DYNAMIC != NULL) + if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); @@ -88,7 +90,7 @@ ___start(int argc, char **argv, char **envp, * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text. */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.10 2004/08/26 21:16:41 thorpej Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.12 2011/03/07 05:09:11 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/sparc64/Makefile b/lib/csu/sparc64/Makefile index 21a68d67a..322757050 100644 --- a/lib/csu/sparc64/Makefile +++ b/lib/csu/sparc64/Makefile @@ -1,7 +1,7 @@ -# $NetBSD: Makefile,v 1.6 2006/05/19 19:11:12 christos Exp $ +# $NetBSD: Makefile,v 1.9 2012/08/10 16:37:31 martin Exp $ -#Uncomment the next line to enable the new .init fallthru CPPFLAGS+= -I${.CURDIR}/../sparc_elf +CFLAGS+= -fPIC ELFSIZE=64 diff --git a/lib/csu/sparc64/crt0.c b/lib/csu/sparc64/crt0.c index 73ef61ee6..594eda76a 100644 --- a/lib/csu/sparc64/crt0.c +++ b/lib/csu/sparc64/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.24 2005/12/24 21:38:40 perry Exp $ */ +/* $NetBSD: crt0.c,v 1.27 2012/08/10 16:37:31 martin Exp $ */ /* * Copyright (c) 1995 Christopher G. Demetriou @@ -45,8 +45,6 @@ */ __asm("\n\ - .data\n\ -__data_start: ! Start of data section\n\ .text\n\ .align 4\n\ .global _start\n\ @@ -55,11 +53,9 @@ __data_start: ! Start of data section\n\ .register %g2,#scratch\n\ _start:\n\ __start:\n\ - setx __data_start, %o0, %g4 ! Point %g4 to start of data section\n\ - clr %g4 ! egcs thinks this is zero. XXX\n\ + clr %g4 ! XXX depends on memory model used \n\ clr %fp\n\ add %sp, 8*16 + 0x7ff, %o0 ! start of stack\n\ - mov %g1, %o1 ! Cleanup routine\n\ mov %g3, %o1 ! XXXX our rtld uses %g3\n\ mov %g2, %o2 ! XXXX obj from rtld.\n\ ba,pt %icc, ___start ! XXXX jump over the retl egcs 2.96 inserts\n\ @@ -94,10 +90,12 @@ ___start(char **sp, __ps_strings = ps_strings; #ifdef DYNAMIC - if (&_DYNAMIC != NULL) + if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); @@ -113,7 +111,7 @@ ___start(char **sp, * NOTE: Leave the RCS ID _after_ _start(), in case it gets placed in .text. */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.24 2005/12/24 21:38:40 perry Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.27 2012/08/10 16:37:31 martin Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/sparc_elf/Makefile b/lib/csu/sparc_elf/Makefile index 68929c415..882e0c201 100644 --- a/lib/csu/sparc_elf/Makefile +++ b/lib/csu/sparc_elf/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.6 2006/05/19 19:11:12 christos Exp $ +# $NetBSD: Makefile,v 1.7 2012/08/10 12:37:39 martin Exp $ -#Uncomment the next line to enable the new .init fallthru CPPFLAGS+= -I${.CURDIR} +CFLAGS+= -fPIC .include "${.CURDIR}/../common_elf/Makefile.inc" diff --git a/lib/csu/sparc_elf/crt0.c b/lib/csu/sparc_elf/crt0.c index cc27c9b7d..b6661f574 100644 --- a/lib/csu/sparc_elf/crt0.c +++ b/lib/csu/sparc_elf/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.12 2004/08/26 21:18:36 thorpej Exp $ */ +/* $NetBSD: crt0.c,v 1.15 2012/08/10 12:37:39 martin Exp $ */ /* * Copyright (c) 1998 Christos Zoulas @@ -56,7 +56,7 @@ _start:\n\ sub %sp, 24, %sp ! expand to standard stack frame size\n\ mov %g3, %o3\n\ mov %g2, %o4\n\ - call ___start\n\ + ba ___start\n\ mov %g1, %o5\n\ "); @@ -79,10 +79,12 @@ ___start(int argc, char **argv, char **envp, __ps_strings = ps_strings; #ifdef DYNAMIC - if (&_DYNAMIC != NULL) + if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); @@ -98,7 +100,7 @@ ___start(int argc, char **argv, char **envp, * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text. */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.12 2004/08/26 21:18:36 thorpej Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.15 2012/08/10 12:37:39 martin Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/vax_elf/crt0.c b/lib/csu/vax_elf/crt0.c index 1ee996352..713e66eec 100644 --- a/lib/csu/vax_elf/crt0.c +++ b/lib/csu/vax_elf/crt0.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0.c,v 1.10 2004/08/26 21:24:09 thorpej Exp $ */ +/* $NetBSD: crt0.c,v 1.12 2011/03/07 05:09:11 joerg Exp $ */ /* * Copyright (c) 1999 Matt Thomas @@ -76,10 +76,12 @@ ___start(int argc, char **argv, char **envp, __ps_strings = ps_strings; #ifdef DYNAMIC - if (&_DYNAMIC != NULL) + if (&rtld_DYNAMIC != NULL) _rtld_setup(cleanup, obj); #endif + _libc_init(); + #ifdef MCRT0 atexit(_mcleanup); monstartup((u_long)&_eprol, (u_long)&_etext); @@ -95,7 +97,7 @@ ___start(int argc, char **argv, char **envp, * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text. */ #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: crt0.c,v 1.10 2004/08/26 21:24:09 thorpej Exp $"); +__RCSID("$NetBSD: crt0.c,v 1.12 2011/03/07 05:09:11 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "common.c" diff --git a/lib/csu/vax_elf/dot_init.h b/lib/csu/vax_elf/dot_init.h index 97c5082c4..5bab0c5e1 100644 --- a/lib/csu/vax_elf/dot_init.h +++ b/lib/csu/vax_elf/dot_init.h @@ -1,4 +1,4 @@ -/* $NetBSD: dot_init.h,v 1.7 2008/05/10 15:31:04 martin Exp $ */ +/* $NetBSD: dot_init.h,v 1.8 2011/07/30 15:28:58 matt Exp $ */ /*- * Copyright (c) 2001 Ross Harvey @@ -34,7 +34,6 @@ */ #include /* RCS ID & Copyright macro defns */ -#include #define MD_SECTION_PROLOGUE(sect, entry_pt) \ __asm ( \ diff --git a/lib/libc/Makefile b/lib/libc/Makefile index 125b66bfa..6dc6106be 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -49,13 +49,12 @@ BUILDCOLD?= no SUBDIR=compat .include .else -.if !defined(__MINIX) COMPATDIR=${.CURDIR}/compat .include "${.CURDIR}/compat/Makefile.inc" -.else +.if defined(__MINIX) SUBDIR+= pkgconfig .include -.endif +.endif # defined(__MINIX) .endif .include "${.CURDIR}/../../common/lib/libc/Makefile.inc" diff --git a/lib/libc/arch/arm/Makefile.inc b/lib/libc/arch/arm/Makefile.inc index 6f48e382e..50509c683 100644 --- a/lib/libc/arch/arm/Makefile.inc +++ b/lib/libc/arch/arm/Makefile.inc @@ -1,12 +1,24 @@ -# $NetBSD: Makefile.inc,v 1.9 2010/07/06 05:59:52 mrg Exp $ +# $NetBSD: Makefile.inc,v 1.16 2012/09/27 11:20:20 skrll Exp $ .include .if !defined(__MINIX) -SRCS+= __sigaction14_sigtramp.c __sigtramp2.S +SRCS+= __aeabi_read_tp.S __sigaction14_sigtramp.c __sigtramp2.S .endif +CPPFLAGS += -I. CPPFLAGS += -DSOFTFLOAT +.if ${MACHINE_ARCH} == "earm" || ${MACHINE_ARCH} == "earmeb" +SRCS+= __aeabi_ldivmod.S __aeabi_uldivmod.S +SRCS+= __aeabi_lcmp.c __aeabi_ulcmp.c +SRCS+= fixunsgen_ieee754.c fixunssfsi_ieee754.c +SRCS+= fixunsgen64_ieee754.c fixunsdfsi_ieee754.c +.endif + +# for earm, use the 64-bit softfloat +.if ${MACHINE_ARCH} == "arm" || ${MACHINE_ARCH} == "armeb" SOFTFLOAT_BITS=32 +.endif + .include diff --git a/lib/libc/arch/arm/gen/Makefile.inc b/lib/libc/arch/arm/gen/Makefile.inc index fcca160e4..b5fd2b8f5 100644 --- a/lib/libc/arch/arm/gen/Makefile.inc +++ b/lib/libc/arch/arm/gen/Makefile.inc @@ -1,7 +1,7 @@ -# $NetBSD: Makefile.inc,v 1.16 2009/12/06 07:12:17 uebayasi Exp $ +# $NetBSD: Makefile.inc,v 1.19 2012/10/10 02:15:03 christos Exp $ SRCS+= alloca.S byte_swap_2.S byte_swap_4.S bswap64.c divsi3.S \ - fabs.c flt_rounds.c + fabs.c flt_rounds.c modsi3.S umodsi3.S # Common ieee754 constants and functions SRCS+= infinityf_ieee754.c infinity_ieee754.c infinityl_dbl_ieee754.c diff --git a/lib/libc/arch/arm/gen/_lwp.c b/lib/libc/arch/arm/gen/_lwp.c index fcc78bd2c..8ff945c59 100644 --- a/lib/libc/arch/arm/gen/_lwp.c +++ b/lib/libc/arch/arm/gen/_lwp.c @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.4 2005/06/12 05:21:25 lukem Exp $ */ +/* $NetBSD: _lwp.c,v 1.8 2012/03/22 09:32:04 he Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -37,7 +37,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.4 2005/06/12 05:21:25 lukem Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.8 2012/03/22 09:32:04 he Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -50,7 +50,7 @@ void _lwp_makecontext(ucontext_t *u, void (*start)(void *), void *arg, void *private, caddr_t stack_base, size_t stack_size) { - void **sp; + uintptr_t sp; getcontext(u); u->uc_link = NULL; @@ -58,14 +58,15 @@ _lwp_makecontext(ucontext_t *u, void (*start)(void *), u->uc_stack.ss_sp = stack_base; u->uc_stack.ss_size = stack_size; - sp = (void **) (stack_base + stack_size); - + sp = (uintptr_t)stack_base + stack_size; /* * Note: We make sure the stack is 8-byte aligned, here. */ - u->uc_mcontext.__gregs[_REG_R0] = (__greg_t) arg; - u->uc_mcontext.__gregs[_REG_SP] = ((__greg_t) sp) & ~7; - u->uc_mcontext.__gregs[_REG_LR] = (__greg_t) _lwp_exit; - u->uc_mcontext.__gregs[_REG_PC] = (__greg_t) start; + u->uc_mcontext.__gregs[_REG_R0] = (__greg_t)(uintptr_t)arg; + u->uc_mcontext.__gregs[_REG_SP] = ((__greg_t)sp) & ~7; + u->uc_mcontext.__gregs[_REG_LR] = (__greg_t)(uintptr_t)_lwp_exit; + u->uc_mcontext.__gregs[_REG_PC] = (__greg_t)(uintptr_t)start; + u->uc_mcontext._mc_tlsbase = (__greg_t)(uintptr_t)private; + u->uc_flags |= _UC_TLSBASE; } diff --git a/lib/libc/arch/arm/gen/_setjmp.S b/lib/libc/arch/arm/gen/_setjmp.S index 559d9b38f..f6debae3d 100644 --- a/lib/libc/arch/arm/gen/_setjmp.S +++ b/lib/libc/arch/arm/gen/_setjmp.S @@ -1,4 +1,4 @@ -/* $NetBSD: _setjmp.S,v 1.6 2004/08/21 11:20:10 rearnsha Exp $ */ +/* $NetBSD: _setjmp.S,v 1.7 2012/08/01 06:02:13 matt Exp $ */ /* * Copyright (c) 1997 Mark Brinicombe @@ -53,6 +53,8 @@ ENTRY(_setjmp) str r1, [r0], #4 #ifdef SOFTFLOAT add r0, r0, #52 +#elif defined(__VFP_FP__) +#error _setjmp VFP support missing #else /* Store fp registers */ sfm f4, 4, [r0], #48 @@ -77,6 +79,8 @@ ENTRY(_longjmp) #ifdef SOFTFLOAT add r0, r0, #52 +#elif defined(__VFP_FP__) +#error _longjmp VFP support missing #else /* Restore fp registers */ lfm f4, 4, [r0], #48 diff --git a/lib/libc/arch/arm/gen/flt_rounds.c b/lib/libc/arch/arm/gen/flt_rounds.c index a341e6e3c..8125a791c 100644 --- a/lib/libc/arch/arm/gen/flt_rounds.c +++ b/lib/libc/arch/arm/gen/flt_rounds.c @@ -1,4 +1,4 @@ -/* $NetBSD: flt_rounds.c,v 1.3 2006/02/25 00:58:35 wiz Exp $ */ +/* $NetBSD: flt_rounds.c,v 1.4 2012/03/21 20:04:57 he Exp $ */ /* * Copyright (c) 1996 Mark Brinicombe @@ -33,7 +33,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: flt_rounds.c,v 1.3 2006/02/25 00:58:35 wiz Exp $"); +__RCSID("$NetBSD: flt_rounds.c,v 1.4 2012/03/21 20:04:57 he Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -75,7 +75,7 @@ static const int map[] = { int __flt_rounds(void); int -__flt_rounds() +__flt_rounds(void) { return(map[fpgetround()]); } diff --git a/lib/libc/arch/arm/gen/makecontext.c b/lib/libc/arch/arm/gen/makecontext.c index cf9bfeaf1..40cef0614 100644 --- a/lib/libc/arch/arm/gen/makecontext.c +++ b/lib/libc/arch/arm/gen/makecontext.c @@ -1,4 +1,4 @@ -/* $NetBSD: makecontext.c,v 1.3 2008/04/28 20:22:55 martin Exp $ */ +/* $NetBSD: makecontext.c,v 1.4 2012/03/21 14:03:06 christos Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: makecontext.c,v 1.3 2008/04/28 20:22:55 martin Exp $"); +__RCSID("$NetBSD: makecontext.c,v 1.4 2012/03/21 14:03:06 christos Exp $"); #endif #include @@ -55,12 +55,12 @@ makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) /* Allocate necessary stack space for arguments exceeding r0-3. */ if (argc > 4) sp -= argc - 4; - gr[_REG_SP] = (__greg_t)sp; + gr[_REG_SP] = (__greg_t)(uintptr_t)sp; /* Wipe out frame pointer. */ gr[_REG_FP] = 0; /* Arrange for return via the trampoline code. */ - gr[_REG_LR] = (__greg_t)_resumecontext; - gr[_REG_PC] = (__greg_t)func; + gr[_REG_LR] = (__greg_t)(uintptr_t)_resumecontext; + gr[_REG_PC] = (__greg_t)(uintptr_t)func; va_start(ap, argc); /* Pass up to four arguments in r0-3. */ diff --git a/lib/libc/arch/arm/gen/resumecontext.c b/lib/libc/arch/arm/gen/resumecontext.c index 7cb6a420d..66781b68f 100644 --- a/lib/libc/arch/arm/gen/resumecontext.c +++ b/lib/libc/arch/arm/gen/resumecontext.c @@ -1,4 +1,4 @@ -/* $NetBSD: resumecontext.c,v 1.4 2008/04/28 20:22:55 martin Exp $ */ +/* $NetBSD: resumecontext.c,v 1.5 2011/09/19 21:24:57 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: resumecontext.c,v 1.4 2008/04/28 20:22:55 martin Exp $"); +__RCSID("$NetBSD: resumecontext.c,v 1.5 2011/09/19 21:24:57 joerg Exp $"); #endif #include "namespace.h" @@ -41,7 +41,7 @@ __RCSID("$NetBSD: resumecontext.c,v 1.4 2008/04/28 20:22:55 martin Exp $"); #include "extern.h" void -_resumecontext() +_resumecontext(void) { ucontext_t uct; diff --git a/lib/libc/arch/arm/gen/setjmp.S b/lib/libc/arch/arm/gen/setjmp.S index b3f5a6204..3f3750c9c 100644 --- a/lib/libc/arch/arm/gen/setjmp.S +++ b/lib/libc/arch/arm/gen/setjmp.S @@ -1,4 +1,4 @@ -/* $NetBSD: setjmp.S,v 1.8 2005/10/16 17:26:24 christos Exp $ */ +/* $NetBSD: setjmp.S,v 1.9 2012/08/01 06:02:13 matt Exp $ */ /* * Copyright (c) 1997 Mark Brinicombe @@ -59,6 +59,8 @@ ENTRY(__setjmp14) #ifdef SOFTFLOAT add r0, r0, #52 +#elif defined(__VFP_FP__) +#error __setjmp14 VFP support missing #else /* Store fp registers */ sfm f4, 4, [r0], #48 @@ -92,6 +94,8 @@ ENTRY(__longjmp14) add r0, r0, #4 #ifdef SOFTFLOAT add r0, r0, #52 +#elif defined(__VFP_FP__) +#error __longjmp14 VFP support missing #else /* Restore fp registers */ lfm f4, 4, [r0], #48 diff --git a/lib/libc/arch/arm/gen/swapcontext.S b/lib/libc/arch/arm/gen/swapcontext.S index a193733d6..3a0405168 100644 --- a/lib/libc/arch/arm/gen/swapcontext.S +++ b/lib/libc/arch/arm/gen/swapcontext.S @@ -1,4 +1,4 @@ -/* $NetBSD: swapcontext.S,v 1.5 2008/04/28 20:22:55 martin Exp $ */ +/* $NetBSD: swapcontext.S,v 1.8 2012/09/27 11:20:20 skrll Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -30,18 +30,22 @@ */ #include "SYS.h" +#include "assym.h" #if defined(LIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: swapcontext.S,v 1.5 2008/04/28 20:22:55 martin Exp $") + RCSID("$NetBSD: swapcontext.S,v 1.8 2012/09/27 11:20:20 skrll Exp $") #endif /* LIBC_SCCS && !lint */ ENTRY(swapcontext) stmfd sp!, {r0-r1, lr} /* Must save oucp, ucp, lr. */ + sub sp, #4 bl PIC_SYM(_C_LABEL(_getcontext), PLT) /* getcontext(oucp) */ cmp r0, #0 + add sp, #4 ldmfd sp!, {r0-r1, lr} RETc(ne) - str lr, [r0, #(36 + 15*4)] /* Adjust saved PC. */ + str sp, [r0, #_UC_REGS_SP] /* Adjust saved SP. */ + str lr, [r0, #_UC_REGS_PC] /* Adjust saved PC. */ #ifdef SOFTFLOAT /* Ahem. */ #endif diff --git a/lib/libc/arch/arm/genassym.cf b/lib/libc/arch/arm/genassym.cf new file mode 100644 index 000000000..75cb98e19 --- /dev/null +++ b/lib/libc/arch/arm/genassym.cf @@ -0,0 +1,36 @@ +# $NetBSD: genassym.cf,v 1.1 2012/09/27 11:20:20 skrll Exp $ + +# +# Copyright (c) 2012 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Nick Hudson +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +include +include + +define _UC_REGS_SP offsetof(ucontext_t, uc_mcontext.__gregs[_REG_SP]) +define _UC_REGS_PC offsetof(ucontext_t, uc_mcontext.__gregs[_REG_PC]) diff --git a/lib/libc/arch/arm/hardfloat/fpgetmask.S b/lib/libc/arch/arm/hardfloat/fpgetmask.S index 706460863..816aca311 100644 --- a/lib/libc/arch/arm/hardfloat/fpgetmask.S +++ b/lib/libc/arch/arm/hardfloat/fpgetmask.S @@ -1,4 +1,4 @@ -/* $NetBSD: fpgetmask.S,v 1.4 2004/08/21 11:21:00 rearnsha Exp $ */ +/* $NetBSD: fpgetmask.S,v 1.5 2012/08/01 06:10:21 matt Exp $ */ /* * Copyright (c) 1996 Mark Brinicombe @@ -45,7 +45,11 @@ ENTRY(_fpgetmask) #else ENTRY(fpgetmask) #endif +#ifdef __VFP_FP__ +#error _fpgetmask VFP support missing +#else rfs r0 mov r0, r0, lsr #16 and r0, r0, #0x1f RET +#endif diff --git a/lib/libc/arch/arm/hardfloat/fpgetround.c b/lib/libc/arch/arm/hardfloat/fpgetround.c index e333bcd65..d94d5a6cc 100644 --- a/lib/libc/arch/arm/hardfloat/fpgetround.c +++ b/lib/libc/arch/arm/hardfloat/fpgetround.c @@ -1,4 +1,4 @@ -/* $NetBSD: fpgetround.c,v 1.4 2006/02/25 02:28:55 wiz Exp $ */ +/* $NetBSD: fpgetround.c,v 1.5 2012/06/24 15:26:02 christos Exp $ */ /* * Copyright (c) 1996 Mark Brinicombe @@ -33,7 +33,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: fpgetround.c,v 1.4 2006/02/25 02:28:55 wiz Exp $"); +__RCSID("$NetBSD: fpgetround.c,v 1.5 2012/06/24 15:26:02 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -65,7 +65,7 @@ __weak_alias(fpgetround,_fpgetround) */ fp_rnd -fpgetround() +fpgetround(void) { return(FP_RN); diff --git a/lib/libc/arch/arm/hardfloat/fpgetsticky.S b/lib/libc/arch/arm/hardfloat/fpgetsticky.S index f7ee5805b..a6debb5bd 100644 --- a/lib/libc/arch/arm/hardfloat/fpgetsticky.S +++ b/lib/libc/arch/arm/hardfloat/fpgetsticky.S @@ -1,4 +1,4 @@ -/* $NetBSD: fpgetsticky.S,v 1.4 2004/08/21 11:21:00 rearnsha Exp $ */ +/* $NetBSD: fpgetsticky.S,v 1.5 2012/08/01 06:10:21 matt Exp $ */ /* * Copyright (c) 1996 Mark Brinicombe @@ -45,6 +45,10 @@ ENTRY(_fpgetsticky) #else ENTRY(fpgetsticky) #endif +#ifdef __VFP_FP__ +#error _fpgetsticky VFP support missing +#else rfs r0 and r0, r0, #0x1f RET +#endif diff --git a/lib/libc/arch/arm/hardfloat/fpsetmask.S b/lib/libc/arch/arm/hardfloat/fpsetmask.S index 1c956cf61..53fc6ccf9 100644 --- a/lib/libc/arch/arm/hardfloat/fpsetmask.S +++ b/lib/libc/arch/arm/hardfloat/fpsetmask.S @@ -1,4 +1,4 @@ -/* $NetBSD: fpsetmask.S,v 1.4 2004/08/21 11:21:00 rearnsha Exp $ */ +/* $NetBSD: fpsetmask.S,v 1.5 2012/08/01 06:10:21 matt Exp $ */ /* * Copyright (c) 1996 Mark Brinicombe @@ -45,6 +45,9 @@ ENTRY(_fpsetmask) #else ENTRY(fpsetmask) #endif +#ifdef __VFP_FP__ +#error _fpsetmask VFP support missing +#else rfs r1 bic r1, r1, #0x001f0000 and r0, r0, #0x0000001f @@ -52,3 +55,4 @@ ENTRY(fpsetmask) wfs r0 mov r0, r1, lsr #16 /* Return old mask */ RET +#endif diff --git a/lib/libc/arch/arm/hardfloat/fpsetsticky.S b/lib/libc/arch/arm/hardfloat/fpsetsticky.S index dd81e897f..4e6aae397 100644 --- a/lib/libc/arch/arm/hardfloat/fpsetsticky.S +++ b/lib/libc/arch/arm/hardfloat/fpsetsticky.S @@ -1,4 +1,4 @@ -/* $NetBSD: fpsetsticky.S,v 1.4 2004/08/21 11:21:00 rearnsha Exp $ */ +/* $NetBSD: fpsetsticky.S,v 1.5 2012/08/01 06:10:21 matt Exp $ */ /* * Copyright (c) 1996 Mark Brinicombe @@ -45,6 +45,9 @@ ENTRY(_fpsetsticky) #else ENTRY(fpsetsticky) #endif +#ifdef __VFP_FP__ +#error _fpsetsticky VFP support missing +#else rfs r1 bic r1, r1, #0x1f and r0, r0, #0x1f @@ -52,3 +55,4 @@ ENTRY(fpsetsticky) wfs r0 mov r0, r1 /* Return old mask */ RET +#endif diff --git a/lib/libc/arch/arm/softfloat/softfloat.h b/lib/libc/arch/arm/softfloat/softfloat.h index f424abec8..07933873d 100644 --- a/lib/libc/arch/arm/softfloat/softfloat.h +++ b/lib/libc/arch/arm/softfloat/softfloat.h @@ -1,4 +1,4 @@ -/* $NetBSD: softfloat.h,v 1.7 2006/05/16 20:55:51 mrg Exp $ */ +/* $NetBSD: softfloat.h,v 1.9 2011/07/07 07:14:57 matt Exp $ */ /* This is a derivative work. */ @@ -84,12 +84,10 @@ Software IEC/IEEE floating-point rounding mode. ------------------------------------------------------------------------------- */ extern fp_rnd float_rounding_mode; -enum { - float_round_nearest_even = FP_RN, - float_round_to_zero = FP_RZ, - float_round_down = FP_RM, - float_round_up = FP_RP -}; +#define float_round_nearest_even FP_RN +#define float_round_to_zero FP_RZ +#define float_round_down FP_RM +#define float_round_up FP_RP /* ------------------------------------------------------------------------------- @@ -119,13 +117,17 @@ void float_raise( fp_except ); Software IEC/IEEE integer-to-floating-point conversion routines. ------------------------------------------------------------------------------- */ -float32 int32_to_float32( int ); -float64 int32_to_float64( int ); +float32 int32_to_float32( int32 ); +float32 uint32_to_float32( uint32 ); +float64 int32_to_float64( int32 ); +float64 uint32_to_float64( uint32 ); #ifdef FLOATX80 -floatx80 int32_to_floatx80( int ); +floatx80 int32_to_floatx80( int32 ); +floatx80 uint32_to_floatx80( uint32 ); #endif #ifdef FLOAT128 -float128 int32_to_float128( int ); +float128 int32_to_float128( int32 ); +float128 uint32_to_float128( uint32 ); #endif #ifndef SOFTFLOAT_FOR_GCC /* __floatdi?f is in libgcc2.c */ float32 int64_to_float32( long long ); diff --git a/lib/libc/arch/arm/sys-minix/Makefile.inc b/lib/libc/arch/arm/sys-minix/Makefile.inc index 8550577ef..0259a31b1 100644 --- a/lib/libc/arch/arm/sys-minix/Makefile.inc +++ b/lib/libc/arch/arm/sys-minix/Makefile.inc @@ -2,9 +2,8 @@ HERE=${.CURDIR}/arch/${MACHINE_ARCH}/sys-minix .PATH: ${HERE} +ARCHINCLS=${NETBSDSRCDIR}/include/arch/${MACHINE_ARCH}/include/ TMP=ucontextoffsets.h.tmp -INCLS=../../include -ARCHINCLS=$(INCLS)/arch/arm/include/ CF=ucontextoffsets.cf INCS+=ucontextoffsets.h @@ -18,8 +17,9 @@ SRCS+= \ brksize.S \ ucontext.S -ucontextoffsets.h: $(CF) $(ARCHINCLS)/stackframe.h $(INCLS)/sys/ucontext.h +ucontextoffsets.h: ${CF} ${ARCHINCLS}/stackframe.h ${NETBSDSRCDIR}/sys/sys/ucontext.h ${_MKTARGET_CREATE} cat ${HERE}/$(CF) | \ ${TOOL_GENASSYM} -- ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} >$TMP && \ mv -f $TMP $@ + diff --git a/lib/libc/arch/arm/sys/__aeabi_read_tp.S b/lib/libc/arch/arm/sys/__aeabi_read_tp.S new file mode 100644 index 000000000..e43e9e241 --- /dev/null +++ b/lib/libc/arch/arm/sys/__aeabi_read_tp.S @@ -0,0 +1,13 @@ +#include "SYS.h" + +ENTRY(__aeabi_read_tp) + mrc p15, 0, r0, c13, c0, 3 +#ifndef _ARM_ARCH_6 + cmp r0, #0 /* was it zero? */ + RETc(ne) /* return it's not zero */ + push {r1} /* syscall zeroes r1 */ + SYSTRAP(_lwp_getprivate) /* can't fail */ + pop {r1} /* restore r1 */ +#endif + RET +_END(__aeabi_read_tp) diff --git a/lib/libc/arch/arm/sys/brk.S b/lib/libc/arch/arm/sys/brk.S index b5cbbd440..d5b52eb1c 100644 --- a/lib/libc/arch/arm/sys/brk.S +++ b/lib/libc/arch/arm/sys/brk.S @@ -1,4 +1,4 @@ -/* $NetBSD: brk.S,v 1.8 2004/08/21 11:30:17 rearnsha Exp $ */ +/* $NetBSD: brk.S,v 1.9 2011/05/13 23:14:36 nonaka Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -33,7 +33,7 @@ #include "SYS.h" - .globl _C_LABEL(end) + .globl _C_LABEL(_end) .globl CURBRK #ifdef WEAK_ALIAS @@ -45,7 +45,7 @@ WEAK_ALIAS(brk, _brk) .globl _C_LABEL(__minbrk) .type _C_LABEL(__minbrk),#object _C_LABEL(__minbrk): - .word _C_LABEL(end) + .word _C_LABEL(_end) /* * Change the data segment size diff --git a/lib/libc/arch/arm/sys/cerror.S b/lib/libc/arch/arm/sys/cerror.S index f05cd69ee..2f1d4a763 100644 --- a/lib/libc/arch/arm/sys/cerror.S +++ b/lib/libc/arch/arm/sys/cerror.S @@ -1,4 +1,4 @@ -/* $NetBSD: cerror.S,v 1.7 2011/01/14 06:12:17 matt Exp $ */ +/* $NetBSD: cerror.S,v 1.8 2012/02/27 12:26:21 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -34,7 +34,7 @@ #include "SYS.h" #ifdef PIC - .hidden CERROR + .protected CERROR #endif ASENTRY(CERROR) diff --git a/lib/libc/arch/arm/sys/sbrk.S b/lib/libc/arch/arm/sys/sbrk.S index 6ad161997..8dd96ae83 100644 --- a/lib/libc/arch/arm/sys/sbrk.S +++ b/lib/libc/arch/arm/sys/sbrk.S @@ -1,4 +1,4 @@ -/* $NetBSD: sbrk.S,v 1.8 2004/08/21 11:30:17 rearnsha Exp $ */ +/* $NetBSD: sbrk.S,v 1.9 2011/05/13 23:14:36 nonaka Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -33,7 +33,7 @@ #include "SYS.h" - .globl _C_LABEL(end) + .globl _C_LABEL(_end) #ifdef WEAK_ALIAS WEAK_ALIAS(sbrk, _sbrk) @@ -44,7 +44,7 @@ WEAK_ALIAS(sbrk, _sbrk) .globl CURBRK .type CURBRK,#object CURBRK: - .word _C_LABEL(end) + .word _C_LABEL(_end) /* * Change the data segment size diff --git a/lib/libc/arch/i386/gdtoa/gd_qnan.h b/lib/libc/arch/i386/gdtoa/gd_qnan.h index b316779ef..915d0ced5 100644 --- a/lib/libc/arch/i386/gdtoa/gd_qnan.h +++ b/lib/libc/arch/i386/gdtoa/gd_qnan.h @@ -1,4 +1,4 @@ -/* $NetBSD: gd_qnan.h,v 1.1 2006/01/25 15:33:28 kleink Exp $ */ +/* $NetBSD: gd_qnan.h,v 1.2 2011/06/05 14:43:12 christos Exp $ */ #define f_QNAN 0x7fc00000 #define d_QNAN0 0x0 @@ -6,6 +6,6 @@ #define ldus_QNAN0 0x0 #define ldus_QNAN1 0x0 #define ldus_QNAN2 0x0 -#define ldus_QNAN3 0x4000 +#define ldus_QNAN3 0xc000 #define ldus_QNAN4 0x7fff /* 2 bytes of tail padding follow, per i386 ABI */ diff --git a/lib/libc/arch/i386/gen/Makefile.inc b/lib/libc/arch/i386/gen/Makefile.inc index efc6290fa..460ffbd1d 100644 --- a/lib/libc/arch/i386/gen/Makefile.inc +++ b/lib/libc/arch/i386/gen/Makefile.inc @@ -1,9 +1,10 @@ -# $NetBSD: Makefile.inc,v 1.26 2009/12/06 07:12:17 uebayasi Exp $ +# $NetBSD: Makefile.inc,v 1.27 2011/03/26 19:51:41 christos Exp $ # objects built from assembler sources (need lint stubs) SRCS+= alloca.S byte_swap_2.S byte_swap_4.S fabs.S \ flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S \ - fpsetmask.S fpsetround.S fpsetsticky.S + fpsetmask.S fpsetround.S fpsetsticky.S fpgetprec.S \ + fpsetprec.S SRCS+= setjmp.S _setjmp.S sigsetjmp.S diff --git a/lib/libc/arch/i386/gen/_lwp.c b/lib/libc/arch/i386/gen/_lwp.c index 0837709bd..a8b486d5f 100644 --- a/lib/libc/arch/i386/gen/_lwp.c +++ b/lib/libc/arch/i386/gen/_lwp.c @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.6 2008/04/28 20:22:56 martin Exp $ */ +/* $NetBSD: _lwp.c,v 1.8 2012/08/31 20:57:24 drochner Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.6 2008/04/28 20:22:56 martin Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.8 2012/08/31 20:57:24 drochner Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -56,9 +56,9 @@ _lwp_makecontext(ucontext_t *u, void (*start)(void *), /* LINTED uintptr_t is safe */ u->uc_mcontext.__gregs[_REG_EIP] = (uintptr_t)start; - /* Align to a word */ + /* Align to a 16-byte boundary for SSE */ /* LINTED uintptr_t is safe */ - sp = (void **) ((uintptr_t)(stack_base + stack_size) & ~0x3); + sp = (void **) (((uintptr_t)(stack_base + stack_size - 4) & ~0xf) + 4); *--sp = arg; *--sp = (void *) _lwp_exit; @@ -66,5 +66,6 @@ _lwp_makecontext(ucontext_t *u, void (*start)(void *), /* LINTED uintptr_t is safe */ u->uc_mcontext.__gregs[_REG_UESP] = (uintptr_t) sp; - /* LINTED private is currently unused */ + u->uc_mcontext._mc_tlsbase = (uintptr_t)private; + u->uc_flags |= _UC_TLSBASE; } diff --git a/common/lib/libc/arch/i386/gen/_setjmp.S b/lib/libc/arch/i386/gen/_setjmp.S similarity index 100% rename from common/lib/libc/arch/i386/gen/_setjmp.S rename to lib/libc/arch/i386/gen/_setjmp.S diff --git a/lib/libc/arch/i386/gen/fixunsdfsi.S b/lib/libc/arch/i386/gen/fixunsdfsi.S index e9c2e67a8..8d7d4fc11 100644 --- a/lib/libc/arch/i386/gen/fixunsdfsi.S +++ b/lib/libc/arch/i386/gen/fixunsdfsi.S @@ -1,4 +1,4 @@ -/* $NetBSD: fixunsdfsi.S,v 1.11 2003/08/07 16:42:07 agc Exp $ */ +/* $NetBSD: fixunsdfsi.S,v 1.12 2011/05/22 20:11:47 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(LIBC_SCCS) - RCSID("$NetBSD: fixunsdfsi.S,v 1.11 2003/08/07 16:42:07 agc Exp $") + RCSID("$NetBSD: fixunsdfsi.S,v 1.12 2011/05/22 20:11:47 joerg Exp $") #endif ENTRY(__fixunsdfsi) @@ -72,4 +72,4 @@ ENTRY(__fixunsdfsi) orl $0x80000000,%eax /* restore bias */ ret -fbiggestsigned: .double 0r2147483648.0 +fbiggestsigned: .double 2147483648.0 diff --git a/lib/libc/arch/i386/gen/flt_rounds.S b/lib/libc/arch/i386/gen/flt_rounds.S index 4b2132769..5440036ce 100644 --- a/lib/libc/arch/i386/gen/flt_rounds.S +++ b/lib/libc/arch/i386/gen/flt_rounds.S @@ -1,33 +1,21 @@ -/* $NetBSD: flt_rounds.S,v 1.6 1999/08/23 08:45:09 kleink Exp $ */ - -/* - * Written by J.T. Conklin, Apr 4, 1995 - * Public domain. - */ +/* $NetBSD: flt_rounds.S,v 1.9 2011/09/30 23:42:00 christos Exp $ */ #include +/* + * 00 0 round to zero + * 01 1 round to nearest + * 10 2 round to positive infinity + * 11 3 round to negative infinity + */ .text _ALIGN_TEXT -_map: - .byte 1 /* round to nearest */ - .byte 3 /* round to negative infinity */ - .byte 2 /* round to positive infinity */ - .byte 0 /* round to zero */ - ENTRY(__flt_rounds) - subl $4,%esp - fnstcw (%esp) - movl (%esp),%eax - shrl $10,%eax - andl $3,%eax -#ifdef PIC - PIC_PROLOGUE - leal PIC_GOTOFF(_map),%ecx - PIC_EPILOGUE - movb (%ecx,%eax,1),%al -#else - movb _map(,%eax,1),%al -#endif - addl $4,%esp + fnstcw -4(%esp) + movl -4(%esp), %ecx + shrl $9, %ecx + andl $6, %ecx + movl $0x2d, %eax /* 0x2d = 00.10.11.01 */ + sarl %cl, %eax /* 0,1,2,3 -> 1,3,2,0 */ + andl $3, %eax ret diff --git a/lib/libc/arch/i386/gen/fpgetprec.S b/lib/libc/arch/i386/gen/fpgetprec.S new file mode 100644 index 000000000..1514bb480 --- /dev/null +++ b/lib/libc/arch/i386/gen/fpgetprec.S @@ -0,0 +1,22 @@ +/* $NetBSD: fpgetprec.S,v 1.1 2011/03/26 19:51:41 christos Exp $ */ + +/* + * Written by J.T. Conklin, Apr 4, 1995 + * Public domain. + */ + +#include + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpgetprec, _fpgetprec) +ENTRY(_fpgetprec) +#else +ENTRY(fpgetprec) +#endif + subl $4,%esp + fnstcw (%esp) + movl (%esp),%eax + rorl $8,%eax + andl $3,%eax + addl $4,%esp + ret diff --git a/lib/libc/arch/i386/gen/fpgetround.S b/lib/libc/arch/i386/gen/fpgetround.S index 093c11559..1cb1a55cb 100644 --- a/lib/libc/arch/i386/gen/fpgetround.S +++ b/lib/libc/arch/i386/gen/fpgetround.S @@ -1,4 +1,4 @@ -/* $NetBSD: fpgetround.S,v 1.5 2002/01/13 21:45:43 thorpej Exp $ */ +/* $NetBSD: fpgetround.S,v 1.6 2011/09/30 23:42:00 christos Exp $ */ /* * Written by J.T. Conklin, Apr 4, 1995 @@ -7,16 +7,17 @@ #include +/* + * XXX load only x87 state. + */ + #ifdef WEAK_ALIAS WEAK_ALIAS(fpgetround, _fpgetround) ENTRY(_fpgetround) #else ENTRY(fpgetround) #endif - subl $4,%esp - fnstcw (%esp) - movl (%esp),%eax - rorl $10,%eax - andl $3,%eax - addl $4,%esp + fnstcw -4(%esp) + movl -4(%esp), %eax + andl $0x00000c00, %eax ret diff --git a/lib/libc/arch/i386/gen/fpsetprec.S b/lib/libc/arch/i386/gen/fpsetprec.S new file mode 100644 index 000000000..c587ed2c5 --- /dev/null +++ b/lib/libc/arch/i386/gen/fpsetprec.S @@ -0,0 +1,34 @@ +/* $NetBSD: fpsetprec.S,v 1.1 2011/03/26 19:51:41 christos Exp $ */ + +/* + * Written by Charles M. Hannum, Apr 9, 1995 + * Public domain. + */ + +#include + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpsetprec, _fpsetprec) +ENTRY(_fpsetprec) +#else +ENTRY(fpsetprec) +#endif + subl $4,%esp + + fnstcw (%esp) + movl (%esp),%eax + + rorl $8,%eax + movl %eax,%edx + andl $3,%eax + + subl %eax,%edx + movl 8(%esp),%ecx + andl $3,%ecx + orl %ecx,%edx + roll $8,%edx + movl %edx,(%esp) + fldcw (%esp) + + addl $4,%esp + ret diff --git a/lib/libc/arch/i386/gen/fpsetround.S b/lib/libc/arch/i386/gen/fpsetround.S index 6e00f87b5..0a0766097 100644 --- a/lib/libc/arch/i386/gen/fpsetround.S +++ b/lib/libc/arch/i386/gen/fpsetround.S @@ -1,34 +1,33 @@ -/* $NetBSD: fpsetround.S,v 1.3 2002/01/13 21:45:43 thorpej Exp $ */ +/* $NetBSD: fpsetround.S,v 1.5 2011/09/30 23:45:41 christos Exp $ */ /* - * Written by Charles M. Hannum, Apr 9, 1995 + * Written by Frank van der Linden at Wasabi Systems for NetBSD. * Public domain. */ #include +/* + * XXX set both the x87 control word + * Applications should only set exception and round flags + */ + + #ifdef WEAK_ALIAS WEAK_ALIAS(fpsetround, _fpsetround) ENTRY(_fpsetround) #else ENTRY(fpsetround) #endif - subl $4,%esp - - fnstcw (%esp) - movl (%esp),%eax - - rorl $10,%eax - movl %eax,%edx - andl $3,%eax - subl %eax,%edx - movl 8(%esp),%ecx - andl $3,%ecx - orl %ecx,%edx - roll $10,%edx - movl %edx,(%esp) - fldcw (%esp) + fnstcw -4(%esp) + movl -4(%esp), %edx + movl %edx, %eax + andl $0x00000c00, %eax + andl $0xfffff3ff, %edx + movl 4(%esp), %ecx + orl %ecx, %edx + movl %edx, -4(%esp) + fldcw -4(%esp) - addl $4,%esp ret diff --git a/lib/libc/arch/i386/gen/infinityl.c b/lib/libc/arch/i386/gen/infinityl.c index 3e7f543a2..de21245c5 100644 --- a/lib/libc/arch/i386/gen/infinityl.c +++ b/lib/libc/arch/i386/gen/infinityl.c @@ -1,4 +1,4 @@ -/* $NetBSD: infinityl.c,v 1.2 2005/06/12 05:21:26 lukem Exp $ */ +/* $NetBSD: infinityl.c,v 1.4 2011/06/06 17:02:30 drochner Exp $ */ /* * IEEE-compatible infinityl.c for little-endian 80-bit format -- public domain. @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: infinityl.c,v 1.2 2005/06/12 05:21:26 lukem Exp $"); +__RCSID("$NetBSD: infinityl.c,v 1.4 2011/06/06 17:02:30 drochner Exp $"); #endif /* LIBC_SCCS and not lint */ #include diff --git a/lib/libc/arch/i386/gen/isnanl.c b/lib/libc/arch/i386/gen/isnanl.c index a85fdc6c0..045798c8d 100644 --- a/lib/libc/arch/i386/gen/isnanl.c +++ b/lib/libc/arch/i386/gen/isnanl.c @@ -1,4 +1,4 @@ -/* $NetBSD: isnanl.c,v 1.6 2007/02/02 23:14:09 christos Exp $ */ +/* $NetBSD: isnanl.c,v 1.8 2011/06/05 14:43:13 christos Exp $ */ /* * Copyright (c) 1992, 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: isnanl.c,v 1.6 2007/02/02 23:14:09 christos Exp $"); +__RCSID("$NetBSD: isnanl.c,v 1.8 2011/06/05 14:43:13 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ diff --git a/lib/libc/arch/i386/stdlib/div.S b/lib/libc/arch/i386/stdlib/div.S index 66f335188..7830b1e03 100644 --- a/lib/libc/arch/i386/stdlib/div.S +++ b/lib/libc/arch/i386/stdlib/div.S @@ -1,4 +1,4 @@ -/* $NetBSD: div.S,v 1.8 2003/07/26 19:24:33 salo Exp $ */ +/* $NetBSD: div.S,v 1.9 2011/06/12 20:29:25 plunky Exp $ */ /* * Written by J.T. Conklin . * Public domain. @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) -RCSID("$NetBSD: div.S,v 1.8 2003/07/26 19:24:33 salo Exp $") +RCSID("$NetBSD: div.S,v 1.9 2011/06/12 20:29:25 plunky Exp $") #endif ENTRY(div) @@ -19,5 +19,6 @@ ENTRY(div) idiv %ecx movl %eax,(%ebx) movl %edx,4(%ebx) + movl %ebx,%eax popl %ebx ret $4 diff --git a/lib/libc/arch/i386/stdlib/ldiv.S b/lib/libc/arch/i386/stdlib/ldiv.S index d9acd25f2..6ae661a2e 100644 --- a/lib/libc/arch/i386/stdlib/ldiv.S +++ b/lib/libc/arch/i386/stdlib/ldiv.S @@ -1,4 +1,4 @@ -/* $NetBSD: ldiv.S,v 1.8 2003/07/26 19:24:33 salo Exp $ */ +/* $NetBSD: ldiv.S,v 1.9 2011/06/12 20:29:25 plunky Exp $ */ /* * Written by J.T. Conklin . * Public domain. @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) -RCSID("$NetBSD: ldiv.S,v 1.8 2003/07/26 19:24:33 salo Exp $") +RCSID("$NetBSD: ldiv.S,v 1.9 2011/06/12 20:29:25 plunky Exp $") #endif ENTRY(ldiv) @@ -19,5 +19,6 @@ ENTRY(ldiv) idiv %ecx movl %eax,(%ebx) movl %edx,4(%ebx) + movl %ebx,%eax popl %ebx ret $4 diff --git a/lib/libc/arch/i386/sys/__clone.S b/lib/libc/arch/i386/sys/__clone.S index ef27f464d..354de5618 100644 --- a/lib/libc/arch/i386/sys/__clone.S +++ b/lib/libc/arch/i386/sys/__clone.S @@ -1,4 +1,4 @@ -/* $NetBSD: __clone.S,v 1.3 2001/07/18 12:24:53 fvdl Exp $ */ +/* $NetBSD: __clone.S,v 1.4 2011/11/18 20:21:41 joerg Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -100,11 +100,4 @@ ENTRY(__clone) addl $12,%esp 5: popl %ebp -#ifdef PIC - PIC_PROLOGUE - movl PIC_GOT(CERROR),%edx - PIC_EPILOGUE - jmp *%edx -#else jmp CERROR -#endif diff --git a/lib/libc/arch/i386/sys/__syscall.S b/lib/libc/arch/i386/sys/__syscall.S index cb5db5139..f37c59797 100644 --- a/lib/libc/arch/i386/sys/__syscall.S +++ b/lib/libc/arch/i386/sys/__syscall.S @@ -1,4 +1,4 @@ -/* $NetBSD: __syscall.S,v 1.3 2003/08/07 16:42:08 agc Exp $ */ +/* $NetBSD: __syscall.S,v 1.4 2011/11/18 20:21:41 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: __syscall.S,v 1.3 2003/08/07 16:42:08 agc Exp $") + RCSID("$NetBSD: __syscall.S,v 1.4 2011/11/18 20:21:41 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -52,11 +52,4 @@ ENTRY(__syscall) jc err ret err: -#ifdef PIC - PIC_PROLOGUE - mov PIC_GOT(CERROR), %ecx - PIC_EPILOGUE - jmp *%ecx -#else jmp CERROR -#endif diff --git a/lib/libc/arch/i386/sys/__vfork14.S b/lib/libc/arch/i386/sys/__vfork14.S index 2dc085d8e..d861b09b0 100644 --- a/lib/libc/arch/i386/sys/__vfork14.S +++ b/lib/libc/arch/i386/sys/__vfork14.S @@ -1,4 +1,4 @@ -/* $NetBSD: __vfork14.S,v 1.8 2007/03/09 14:30:48 ad Exp $ */ +/* $NetBSD: __vfork14.S,v 1.9 2011/11/18 20:21:41 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: __vfork14.S,v 1.8 2007/03/09 14:30:48 ad Exp $") + RCSID("$NetBSD: __vfork14.S,v 1.9 2011/11/18 20:21:41 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -57,11 +57,4 @@ ENTRY(__vfork14) jmp *%ecx err: pushl %ecx -#ifdef PIC - PIC_PROLOGUE - mov PIC_GOT(CERROR), %ecx - PIC_EPILOGUE - jmp *%ecx -#else jmp CERROR -#endif diff --git a/lib/libc/arch/i386/sys/brk.S b/lib/libc/arch/i386/sys/brk.S index 73e363cdf..f616e481d 100644 --- a/lib/libc/arch/i386/sys/brk.S +++ b/lib/libc/arch/i386/sys/brk.S @@ -1,4 +1,4 @@ -/* $NetBSD: brk.S,v 1.21 2007/03/09 14:30:56 ad Exp $ */ +/* $NetBSD: brk.S,v 1.22 2011/11/18 20:21:41 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: brk.S,v 1.21 2007/03/09 14:30:56 ad Exp $") + RCSID("$NetBSD: brk.S,v 1.22 2011/11/18 20:21:41 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -74,10 +74,7 @@ ENTRY(_brk) xorl %eax,%eax ret err: - PIC_PROLOGUE - mov PIC_GOT(CERROR),%edx - PIC_EPILOGUE - jmp *%edx + jmp CERROR #else movl 4(%esp),%ecx cmpl %ecx,_C_LABEL(__minbrk) diff --git a/lib/libc/arch/i386/sys/cerror.S b/lib/libc/arch/i386/sys/cerror.S index 3a0c7223d..56ddba75a 100644 --- a/lib/libc/arch/i386/sys/cerror.S +++ b/lib/libc/arch/i386/sys/cerror.S @@ -1,4 +1,4 @@ -/* $NetBSD: cerror.S,v 1.14 2003/08/07 16:42:08 agc Exp $ */ +/* $NetBSD: cerror.S,v 1.16 2012/02/27 12:26:21 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,12 +36,13 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: cerror.S,v 1.14 2003/08/07 16:42:08 agc Exp $") + RCSID("$NetBSD: cerror.S,v 1.16 2012/02/27 12:26:21 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" .globl _C_LABEL(__errno) + .protected CERROR _ENTRY(CERROR) pushl %eax diff --git a/lib/libc/arch/i386/sys/exect.S b/lib/libc/arch/i386/sys/exect.S index dacc45052..d58b1d549 100644 --- a/lib/libc/arch/i386/sys/exect.S +++ b/lib/libc/arch/i386/sys/exect.S @@ -1,4 +1,4 @@ -/* $NetBSD: exect.S,v 1.13 2003/08/07 16:42:08 agc Exp $ */ +/* $NetBSD: exect.S,v 1.14 2011/11/18 20:21:41 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: exect.S,v 1.13 2003/08/07 16:42:08 agc Exp $") + RCSID("$NetBSD: exect.S,v 1.14 2011/11/18 20:21:41 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -47,11 +47,4 @@ ENTRY(exect) orb $(PSL_T>>8),1(%esp) popfl SYSTRAP(execve) -#ifdef PIC - PIC_PROLOGUE - mov PIC_GOT(CERROR), %ecx - PIC_EPILOGUE - jmp *%ecx -#else jmp CERROR -#endif diff --git a/lib/libc/arch/i386/sys/ptrace.S b/lib/libc/arch/i386/sys/ptrace.S index 1fd7acf0f..e18f1ebf9 100644 --- a/lib/libc/arch/i386/sys/ptrace.S +++ b/lib/libc/arch/i386/sys/ptrace.S @@ -1,4 +1,4 @@ -/* $NetBSD: ptrace.S,v 1.16 2003/08/07 16:42:09 agc Exp $ */ +/* $NetBSD: ptrace.S,v 1.17 2011/11/18 20:21:41 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: ptrace.S,v 1.16 2003/08/07 16:42:09 agc Exp $") + RCSID("$NetBSD: ptrace.S,v 1.17 2011/11/18 20:21:41 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -57,11 +57,4 @@ ENTRY(ptrace) jc err ret err: -#ifdef PIC - PIC_PROLOGUE - mov PIC_GOT(CERROR), %ecx - PIC_EPILOGUE - jmp *%ecx -#else jmp CERROR -#endif diff --git a/lib/libc/arch/i386/sys/sbrk.S b/lib/libc/arch/i386/sys/sbrk.S index 359e50057..d73a25bd6 100644 --- a/lib/libc/arch/i386/sys/sbrk.S +++ b/lib/libc/arch/i386/sys/sbrk.S @@ -1,4 +1,4 @@ -/* $NetBSD: sbrk.S,v 1.19 2008/07/02 20:07:43 rmind Exp $ */ +/* $NetBSD: sbrk.S,v 1.20 2011/11/18 20:21:41 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: sbrk.S,v 1.19 2008/07/02 20:07:43 rmind Exp $") + RCSID("$NetBSD: sbrk.S,v 1.20 2011/11/18 20:21:41 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -73,10 +73,7 @@ ENTRY(_sbrk) out: ret err: - PIC_PROLOGUE - mov PIC_GOT(CERROR),%edx - PIC_EPILOGUE - jmp *%edx + jmp CERROR #else movl 4(%esp),%ecx movl CURBRK,%eax diff --git a/lib/libc/arch/i386/sys/syscall.S b/lib/libc/arch/i386/sys/syscall.S index 3fe3f72ab..983f38690 100644 --- a/lib/libc/arch/i386/sys/syscall.S +++ b/lib/libc/arch/i386/sys/syscall.S @@ -1,4 +1,4 @@ -/* $NetBSD: syscall.S,v 1.11 2003/08/07 16:42:09 agc Exp $ */ +/* $NetBSD: syscall.S,v 1.12 2011/11/18 20:21:41 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: syscall.S,v 1.11 2003/08/07 16:42:09 agc Exp $") + RCSID("$NetBSD: syscall.S,v 1.12 2011/11/18 20:21:41 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -50,11 +50,4 @@ ENTRY(syscall) jc err ret err: -#ifdef PIC - PIC_PROLOGUE - mov PIC_GOT(CERROR), %ecx - PIC_EPILOGUE - jmp *%ecx -#else jmp CERROR -#endif diff --git a/lib/libc/arch/sparc64/gen/swapcontext.S b/lib/libc/arch/sparc64/gen/swapcontext.S index 262bd50b8..abcd569e4 100644 --- a/lib/libc/arch/sparc64/gen/swapcontext.S +++ b/lib/libc/arch/sparc64/gen/swapcontext.S @@ -1,4 +1,4 @@ -/* $NetBSD: swapcontext.S,v 1.6 2012/09/12 02:00:53 manu Exp $ */ +/* $NetBSD: swapcontext.S,v 1.7 2012/09/13 11:47:46 martin Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include "SYS.h" #if defined(LIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: swapcontext.S,v 1.6 2012/09/12 02:00:53 manu Exp $") + RCSID("$NetBSD: swapcontext.S,v 1.7 2012/09/13 11:47:46 martin Exp $") #endif /* LIBC_SCCS && !lint */ @@ -53,12 +53,12 @@ ENTRY(swapcontext) #ifdef PIC PIC_PROLOGUE(%g5,%o4) /* %g5 = _GLOBAL_OFFSET_TABLE */ #ifdef BIGPIC - set _C_LABEL(setcontext), %o6 - ldx [%g5+%o6], %o5 + set _C_LABEL(setcontext), %o5 + ldx [%g5+%o5], %o4 #else - ldx [%g5+_C_LABEL(setcontext)], %o5 + ldx [%g5+_C_LABEL(setcontext)], %o4 #endif - jmp %o5 + jmp %o4 mov %o3, %o0 #else ba,a _C_LABEL(setcontext) diff --git a/lib/libc/arch/x86_64/SYS.h b/lib/libc/arch/x86_64/SYS.h index 2b0260346..9fbb570b9 100644 --- a/lib/libc/arch/x86_64/SYS.h +++ b/lib/libc/arch/x86_64/SYS.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 - * $NetBSD: SYS.h,v 1.10 2007/11/23 07:36:05 dsl Exp $ + * $NetBSD: SYS.h,v 1.11 2011/11/18 20:43:01 joerg Exp $ */ #include @@ -49,14 +49,8 @@ ENTRY(x); \ SYSTRAP(y) -#ifdef PIC #define _SYSCALL_ERR \ - mov PIC_GOT(CERROR), %rcx; \ - jmp *%rcx -#else -#define _SYSCALL_ERR \ jmp CERROR -#endif #define _SYSCALL(x,y) \ .text; _ALIGN_TEXT; \ diff --git a/lib/libc/arch/x86_64/gdtoa/gd_qnan.h b/lib/libc/arch/x86_64/gdtoa/gd_qnan.h index 98638cc8a..d702c6792 100644 --- a/lib/libc/arch/x86_64/gdtoa/gd_qnan.h +++ b/lib/libc/arch/x86_64/gdtoa/gd_qnan.h @@ -1,11 +1,15 @@ -/* $NetBSD: gd_qnan.h,v 1.1 2006/01/25 15:33:28 kleink Exp $ */ +/* $NetBSD: gd_qnan.h,v 1.3 2011/06/05 14:43:13 christos Exp $ */ #define f_QNAN 0x7fc00000 #define d_QNAN0 0x0 #define d_QNAN1 0x7ff80000 +#define ld_QNAN0 0x0 +#define ld_QNAN1 0xc0000000 +#define ld_QNAN2 0x7fff +#define ld_QNAN3 0x0 #define ldus_QNAN0 0x0 #define ldus_QNAN1 0x0 #define ldus_QNAN2 0x0 -#define ldus_QNAN3 0x4000 +#define ldus_QNAN3 0xc000 #define ldus_QNAN4 0x7fff /* 6 bytes of tail padding follow, per AMD64 ABI */ diff --git a/lib/libc/arch/x86_64/gen/Makefile.inc b/lib/libc/arch/x86_64/gen/Makefile.inc index 3f794563a..de53e99df 100644 --- a/lib/libc/arch/x86_64/gen/Makefile.inc +++ b/lib/libc/arch/x86_64/gen/Makefile.inc @@ -1,9 +1,10 @@ -# $NetBSD: Makefile.inc,v 1.15 2010/01/14 02:09:46 joerg Exp $ +# $NetBSD: Makefile.inc,v 1.16 2011/03/26 19:51:42 christos Exp $ # objects built from assembler sources (need lint stubs) SRCS+= alloca.S byte_swap_2.S byte_swap_4.S byte_swap_8.S fabs.S \ flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S \ - fpsetmask.S fpsetround.S fpsetsticky.S + fpsetmask.S fpsetround.S fpsetsticky.S fpgetprec.S \ + fpsetprec.S SRCS+= __setjmp14.S SRCS+= _setjmp.S diff --git a/lib/libc/arch/x86_64/gen/_lwp.c b/lib/libc/arch/x86_64/gen/_lwp.c index 511c12696..b8c9f9b97 100644 --- a/lib/libc/arch/x86_64/gen/_lwp.c +++ b/lib/libc/arch/x86_64/gen/_lwp.c @@ -1,4 +1,4 @@ -/* $NetBSD: _lwp.c,v 1.6 2009/07/02 09:57:09 joerg Exp $ */ +/* $NetBSD: _lwp.c,v 1.7 2011/02/24 04:28:43 joerg Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _lwp.c,v 1.6 2009/07/02 09:57:09 joerg Exp $"); +__RCSID("$NetBSD: _lwp.c,v 1.7 2011/02/24 04:28:43 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -66,5 +66,6 @@ _lwp_makecontext(ucontext_t *u, void (*start)(void *), /* LINTED uintptr_t is safe */ gr[_REG_URSP] = (uintptr_t) sp; - /* LINTED private is currently unused */ + u->uc_mcontext._mc_tlsbase = (uintptr_t)private; + u->uc_flags |= _UC_TLSBASE; } diff --git a/lib/libc/arch/x86_64/gen/flt_rounds.S b/lib/libc/arch/x86_64/gen/flt_rounds.S index 1b23501cd..ac3eca3d0 100644 --- a/lib/libc/arch/x86_64/gen/flt_rounds.S +++ b/lib/libc/arch/x86_64/gen/flt_rounds.S @@ -1,29 +1,21 @@ -/* $NetBSD: flt_rounds.S,v 1.2 2002/06/06 23:04:35 fvdl Exp $ */ - -/* - * Written by J.T. Conklin, Apr 4, 1995 - * Public domain. - */ +/* $NetBSD: flt_rounds.S,v 1.6 2011/09/30 17:42:34 christos Exp $ */ #include +/* + * 00 0 round to zero + * 01 1 round to nearest + * 10 2 round to positive infinity + * 11 3 round to negative infinity + */ .text _ALIGN_TEXT -_map: - .byte 1 /* round to nearest */ - .byte 3 /* round to negative infinity */ - .byte 2 /* round to positive infinity */ - .byte 0 /* round to zero */ - ENTRY(__flt_rounds) - fnstcw -4(%rsp) - movl -4(%rsp),%eax - shrl $10,%eax - andl $3,%eax -#ifdef PIC - leaq PIC_GOT(_map),%rcx - movb (%rcx,%rax,1),%al -#else - movb _map(,%rax,1),%al -#endif + fnstcw -4(%rsp) + movl -4(%rsp), %ecx + shrl $9, %ecx + andl $6, %ecx + movl $0x2d, %eax /* 0x2d = 00.10.11.01 */ + sarl %cl, %eax /* 0,1,2,3 -> 1,3,2,0 */ + andl $3, %eax ret diff --git a/lib/libc/arch/x86_64/gen/fpgetprec.S b/lib/libc/arch/x86_64/gen/fpgetprec.S new file mode 100644 index 000000000..d3728fa3b --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fpgetprec.S @@ -0,0 +1,25 @@ +/* $NetBSD: fpgetprec.S,v 1.1 2011/03/26 19:51:42 christos Exp $ */ + +/* + * Written by J.T. Conklin, Apr 4, 1995 + * Public domain. + */ + +#include + +/* + * XXX store only x87 state. If an application only uses the fp* + * interface, this should be in sync with the SSE mxcsr register. + */ + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpgetprec, _fpgetprec) +ENTRY(_fpgetprec) +#else +ENTRY(fpgetprec) +#endif + fnstcw -4(%rsp) + movl -4(%rsp),%eax + rorl $8,%eax + andl $3,%eax + ret diff --git a/lib/libc/arch/x86_64/gen/fpgetround.S b/lib/libc/arch/x86_64/gen/fpgetround.S index 2693c2791..f32af8333 100644 --- a/lib/libc/arch/x86_64/gen/fpgetround.S +++ b/lib/libc/arch/x86_64/gen/fpgetround.S @@ -1,4 +1,4 @@ -/* $NetBSD: fpgetround.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ +/* $NetBSD: fpgetround.S,v 1.4 2011/09/30 17:42:34 christos Exp $ */ /* * Written by J.T. Conklin, Apr 4, 1995 @@ -8,7 +8,7 @@ #include /* - * XXX store only x87 state. If an application only uses the fp* + * XXX load only x87 state. If an application only uses the fp* * interface, this should be in sync with the SSE mxcsr register. */ @@ -19,7 +19,6 @@ ENTRY(_fpgetround) ENTRY(fpgetround) #endif fnstcw -4(%rsp) - movl -4(%rsp),%eax - rorl $10,%eax - andl $3,%eax + movl -4(%rsp), %eax + andl $0x00000c00, %eax ret diff --git a/lib/libc/arch/x86_64/gen/fpsetmask.S b/lib/libc/arch/x86_64/gen/fpsetmask.S index 0e1809928..4d4896661 100644 --- a/lib/libc/arch/x86_64/gen/fpsetmask.S +++ b/lib/libc/arch/x86_64/gen/fpsetmask.S @@ -1,4 +1,4 @@ -/* $NetBSD: fpsetmask.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ +/* $NetBSD: fpsetmask.S,v 1.5 2012/01/19 16:37:18 drochner Exp $ */ /* * Written by Frank van der Linden at Wasabi Systems for NetBSD. @@ -20,22 +20,25 @@ ENTRY(_fpsetmask) #else ENTRY(fpsetmask) #endif - fnstcw -4(%rsp) - stmxcsr -8(%rsp) - andl $63,%edi notl %edi + andl $0x0000003f,%edi - movl -4(%rsp),%edx - movl %edx,%eax - andl %edi,%edx + fnstcw -4(%rsp) + movl -4(%rsp), %edx + movl %edx, %eax + andl $0xffffffc0, %edx + orl %edi, %edx movl %edx,-4(%rsp) + fldcw -4(%rsp) - movl -8(%rsp),%edx - roll $7,%edi - andl %edi,%edx - movl %edx,-8(%rsp) + stmxcsr -4(%rsp) + movl -4(%rsp), %edx + andl $0xffffe07f, %edx + sall $7, %edi + orl %edi, %edx + movl %edx,-4(%rsp) + ldmxcsr -4(%rsp) - fldcw -4(%rsp) - ldmxcsr -8(%rsp) - andl $63,%eax + notl %eax + andl $0x0000003f, %eax ret diff --git a/lib/libc/arch/x86_64/gen/fpsetprec.S b/lib/libc/arch/x86_64/gen/fpsetprec.S new file mode 100644 index 000000000..43410c61a --- /dev/null +++ b/lib/libc/arch/x86_64/gen/fpsetprec.S @@ -0,0 +1,39 @@ +/* $NetBSD: fpsetprec.S,v 1.1 2011/03/26 19:51:42 christos Exp $ */ + +/* + * Written by Frank van der Linden at Wasabi Systems for NetBSD. + * Public domain. + */ + +#include + +/* + * XXX set both the x87 control word and the SSE mxcsr register. + * Applications should only set exception and round flags + * via the fp*() interface, otherwise the status words + * will get our of sync. + */ + + +#ifdef WEAK_ALIAS +WEAK_ALIAS(fpsetprec, _fpsetprec) +ENTRY(_fpsetprec) +#else +ENTRY(fpsetprec) +#endif + fnstcw -4(%rsp) + + andl $3,%edi + + movl -4(%rsp),%edx + rorl $8,%edx + movl %edx,%eax + andl $3,%eax + + andl $~3,%edx + orl %edi,%edx + roll $8,%edx + movl %edx,-4(%rsp) + + fldcw -4(%rsp) + ret diff --git a/lib/libc/arch/x86_64/gen/fpsetround.S b/lib/libc/arch/x86_64/gen/fpsetround.S index 68e275f77..96422ba36 100644 --- a/lib/libc/arch/x86_64/gen/fpsetround.S +++ b/lib/libc/arch/x86_64/gen/fpsetround.S @@ -1,4 +1,4 @@ -/* $NetBSD: fpsetround.S,v 1.3 2002/06/12 19:17:22 fvdl Exp $ */ +/* $NetBSD: fpsetround.S,v 1.4 2011/09/30 17:42:34 christos Exp $ */ /* * Written by Frank van der Linden at Wasabi Systems for NetBSD. @@ -21,28 +21,22 @@ ENTRY(_fpsetround) #else ENTRY(fpsetround) #endif - fnstcw -4(%rsp) - stmxcsr -8(%rsp) - - andl $3,%edi - movl -4(%rsp),%edx - rorl $10,%edx - movl %edx,%eax - andl $3,%eax + fnstcw -4(%rsp) + movl -4(%rsp), %edx + movl %edx, %eax + andl $0x00000c00, %eax + andl $0xfffff3ff, %edx + orl %edi, %edx + movl %edx, -4(%rsp) + fldcw -4(%rsp) - andl $~3,%edx + stmxcsr -4(%rsp) + movl -4(%rsp), %edx + andl $0xffff9fff, %edx + sall $3, %edi orl %edi,%edx - roll $10,%edx movl %edx,-4(%rsp) + ldmxcsr -4(%rsp) - movl -8(%rsp),%edx - rorl $13,%edx - andl $~3,%edx - orl %edi,%edx - roll $13,%edx - movl %edx,-8(%rsp) - - ldmxcsr -8(%rsp) - fldcw -4(%rsp) ret diff --git a/lib/libc/arch/x86_64/gen/infinityl.c b/lib/libc/arch/x86_64/gen/infinityl.c index d931768dd..521f10186 100644 --- a/lib/libc/arch/x86_64/gen/infinityl.c +++ b/lib/libc/arch/x86_64/gen/infinityl.c @@ -1,4 +1,4 @@ -/* $NetBSD: infinityl.c,v 1.2 2005/06/12 05:21:27 lukem Exp $ */ +/* $NetBSD: infinityl.c,v 1.4 2011/06/06 17:02:29 drochner Exp $ */ /* * IEEE-compatible infinityl.c for little-endian 80-bit format -- public domain. @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: infinityl.c,v 1.2 2005/06/12 05:21:27 lukem Exp $"); +__RCSID("$NetBSD: infinityl.c,v 1.4 2011/06/06 17:02:29 drochner Exp $"); #endif /* LIBC_SCCS and not lint */ #include diff --git a/lib/libc/arch/x86_64/gen/isnanl.c b/lib/libc/arch/x86_64/gen/isnanl.c index 8694ec83c..045798c8d 100644 --- a/lib/libc/arch/x86_64/gen/isnanl.c +++ b/lib/libc/arch/x86_64/gen/isnanl.c @@ -1,4 +1,4 @@ -/* $NetBSD: isnanl.c,v 1.6 2007/02/02 23:19:25 christos Exp $ */ +/* $NetBSD: isnanl.c,v 1.8 2011/06/05 14:43:13 christos Exp $ */ /* * Copyright (c) 1992, 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)isinf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: isnanl.c,v 1.6 2007/02/02 23:19:25 christos Exp $"); +__RCSID("$NetBSD: isnanl.c,v 1.8 2011/06/05 14:43:13 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ diff --git a/lib/libc/arch/x86_64/sys/__clone.S b/lib/libc/arch/x86_64/sys/__clone.S index 76d687425..37025be3b 100644 --- a/lib/libc/arch/x86_64/sys/__clone.S +++ b/lib/libc/arch/x86_64/sys/__clone.S @@ -1,4 +1,4 @@ -/* $NetBSD: __clone.S,v 1.2 2002/06/06 20:51:17 fvdl Exp $ */ +/* $NetBSD: __clone.S,v 1.3 2011/11/18 20:43:01 joerg Exp $ */ /* * Copyright (c) 2002 Wasabi Systems, Inc. @@ -93,9 +93,4 @@ ENTRY(__clone) 5: popq %r13 popq %r12 -#ifdef PIC - movq PIC_GOT(CERROR),%rdx - jmp *%rdx -#else jmp CERROR -#endif diff --git a/lib/libc/arch/x86_64/sys/__vfork14.S b/lib/libc/arch/x86_64/sys/__vfork14.S index bbd682164..4a9a3592e 100644 --- a/lib/libc/arch/x86_64/sys/__vfork14.S +++ b/lib/libc/arch/x86_64/sys/__vfork14.S @@ -1,4 +1,4 @@ -/* $NetBSD: __vfork14.S,v 1.3 2003/08/07 16:42:37 agc Exp $ */ +/* $NetBSD: __vfork14.S,v 1.4 2011/11/18 20:43:01 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: __vfork14.S,v 1.3 2003/08/07 16:42:37 agc Exp $") + RCSID("$NetBSD: __vfork14.S,v 1.4 2011/11/18 20:43:01 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -57,9 +57,4 @@ ENTRY(__vfork14) jmp *%r9 err: pushq %r9 -#ifdef PIC - movq PIC_GOT(CERROR), %rcx - jmp *%rcx -#else jmp CERROR -#endif diff --git a/lib/libc/arch/x86_64/sys/brk.S b/lib/libc/arch/x86_64/sys/brk.S index 7d969e9d7..c64483281 100644 --- a/lib/libc/arch/x86_64/sys/brk.S +++ b/lib/libc/arch/x86_64/sys/brk.S @@ -1,4 +1,4 @@ -/* $NetBSD: brk.S,v 1.3 2003/08/07 16:42:37 agc Exp $ */ +/* $NetBSD: brk.S,v 1.4 2011/11/18 20:43:01 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: brk.S,v 1.3 2003/08/07 16:42:37 agc Exp $") + RCSID("$NetBSD: brk.S,v 1.4 2011/11/18 20:43:01 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -68,8 +68,7 @@ ENTRY(_brk) xorl %eax,%eax ret err: - movq PIC_GOT(CERROR),%rdx - jmp *%rdx + jmp CERROR #else cmpq %rdi,_C_LABEL(__minbrk)(%rip) jb 1f diff --git a/lib/libc/arch/x86_64/sys/cerror.S b/lib/libc/arch/x86_64/sys/cerror.S index 6c06fa4b5..9a608dd5b 100644 --- a/lib/libc/arch/x86_64/sys/cerror.S +++ b/lib/libc/arch/x86_64/sys/cerror.S @@ -1,4 +1,4 @@ -/* $NetBSD: cerror.S,v 1.3 2003/08/07 16:42:37 agc Exp $ */ +/* $NetBSD: cerror.S,v 1.5 2012/02/27 12:26:21 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,12 +36,13 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: cerror.S,v 1.3 2003/08/07 16:42:37 agc Exp $") + RCSID("$NetBSD: cerror.S,v 1.5 2012/02/27 12:26:21 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" .globl _C_LABEL(__errno) + .protected CERROR _ENTRY(CERROR) pushq %r12 diff --git a/lib/libc/arch/x86_64/sys/exect.S b/lib/libc/arch/x86_64/sys/exect.S index 9f32e5e5c..7e221e0d3 100644 --- a/lib/libc/arch/x86_64/sys/exect.S +++ b/lib/libc/arch/x86_64/sys/exect.S @@ -1,4 +1,4 @@ -/* $NetBSD: exect.S,v 1.2 2003/08/07 16:42:37 agc Exp $ */ +/* $NetBSD: exect.S,v 1.3 2011/11/18 20:43:01 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: exect.S,v 1.2 2003/08/07 16:42:37 agc Exp $") + RCSID("$NetBSD: exect.S,v 1.3 2011/11/18 20:43:01 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -47,9 +47,4 @@ ENTRY(exect) orb $(PSL_T>>8),1(%rsp) popfq SYSTRAP(execve) -#ifdef PIC - movq PIC_GOT(CERROR), %rcx - jmp *%rcx -#else jmp CERROR -#endif diff --git a/lib/libc/arch/x86_64/sys/ptrace.S b/lib/libc/arch/x86_64/sys/ptrace.S index 8b7cc33ae..77c1de87f 100644 --- a/lib/libc/arch/x86_64/sys/ptrace.S +++ b/lib/libc/arch/x86_64/sys/ptrace.S @@ -1,4 +1,4 @@ -/* $NetBSD: ptrace.S,v 1.2 2003/08/07 16:42:37 agc Exp $ */ +/* $NetBSD: ptrace.S,v 1.3 2011/11/18 20:43:01 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: ptrace.S,v 1.2 2003/08/07 16:42:37 agc Exp $") + RCSID("$NetBSD: ptrace.S,v 1.3 2011/11/18 20:43:01 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -54,9 +54,4 @@ ENTRY(ptrace) jc err ret err: -#ifdef PIC - movq PIC_GOT(CERROR), %rcx - jmp *%rcx -#else jmp CERROR -#endif diff --git a/lib/libc/arch/x86_64/sys/sbrk.S b/lib/libc/arch/x86_64/sys/sbrk.S index 65c33625b..812e15b38 100644 --- a/lib/libc/arch/x86_64/sys/sbrk.S +++ b/lib/libc/arch/x86_64/sys/sbrk.S @@ -1,4 +1,4 @@ -/* $NetBSD: sbrk.S,v 1.3 2008/07/02 20:07:43 rmind Exp $ */ +/* $NetBSD: sbrk.S,v 1.4 2011/11/18 20:43:01 joerg Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -36,7 +36,7 @@ #include #if defined(SYSLIBC_SCCS) && !defined(lint) - RCSID("$NetBSD: sbrk.S,v 1.3 2008/07/02 20:07:43 rmind Exp $") + RCSID("$NetBSD: sbrk.S,v 1.4 2011/11/18 20:43:01 joerg Exp $") #endif /* SYSLIBC_SCCS and not lint */ #include "SYS.h" @@ -67,8 +67,7 @@ ENTRY(_sbrk) out: ret err: - mov PIC_GOT(CERROR),%rdx - jmp *%rdx + jmp CERROR #else movq CURBRK(%rip),%rax test %rdi,%rdi diff --git a/lib/libc/atomic/membar_ops.3 b/lib/libc/atomic/membar_ops.3 index 125d696b4..b91f72d24 100644 --- a/lib/libc/atomic/membar_ops.3 +++ b/lib/libc/atomic/membar_ops.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: membar_ops.3,v 1.2 2009/05/18 12:39:17 wiz Exp $ +.\" $NetBSD: membar_ops.3,v 1.3 2011/04/28 11:56:26 wiz Exp $ .\" .\" Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -62,7 +62,7 @@ relaxed load and store order. .Pp .Bl -tag -width "mem" .It Fn membar_enter -Any store preceeding +Any store preceding .Fn membar_enter will reach global visibility before all loads and stores following it. .Pp diff --git a/lib/libc/cdb/cdbr.c b/lib/libc/cdb/cdbr.c index d5a357c96..bf970baae 100644 --- a/lib/libc/cdb/cdbr.c +++ b/lib/libc/cdb/cdbr.c @@ -1,4 +1,4 @@ -/* $NetBSD: cdbr.c,v 1.2 2010/06/03 12:40:52 veego Exp $ */ +/* $NetBSD: cdbr.c,v 1.4 2012/09/27 00:37:43 joerg Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -36,12 +36,17 @@ #endif #include -__RCSID("$NetBSD: cdbr.c,v 1.2 2010/06/03 12:40:52 veego Exp $"); +__RCSID("$NetBSD: cdbr.c,v 1.4 2012/09/27 00:37:43 joerg Exp $"); #include "namespace.h" +#if !HAVE_NBTOOL_CONFIG_H #include +#endif +#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H #include +#endif + #include #include #include @@ -59,6 +64,11 @@ __weak_alias(cdbr_get,_cdbr_get) __weak_alias(cdbr_open,_cdbr_open) #endif +#if HAVE_NBTOOL_CONFIG_H +#define fast_divide32_prepare(d,m,s1,s2) (void)0 +#define fast_remainder32(v,d,m,s1,s2) (v%d) +#endif + struct cdbr { uint8_t *mmap_base; size_t mmap_size; @@ -156,17 +166,21 @@ cdbr_open(const char *path, int flags) cdbr->data_base < cdbr->mmap_base || cdbr->data_base + cdbr->data_size < cdbr->mmap_base || cdbr->data_base + cdbr->data_size > - cdbr->mmap_base + cdbr->mmap_size || - cdbr->entries == 0 || cdbr->entries_index == 0) { + cdbr->mmap_base + cdbr->mmap_size) { errno = EINVAL; cdbr_close(cdbr); return NULL; } - fast_divide32_prepare(cdbr->entries, &cdbr->entries_m, - &cdbr->entries_s1, &cdbr->entries_s2); - fast_divide32_prepare(cdbr->entries_index, &cdbr->entries_index_m, - &cdbr->entries_index_s1, &cdbr->entries_index_s2); + if (cdbr->entries) { + fast_divide32_prepare(cdbr->entries, &cdbr->entries_m, + &cdbr->entries_s1, &cdbr->entries_s2); + } + if (cdbr->entries_index) { + fast_divide32_prepare(cdbr->entries_index, + &cdbr->entries_index_m, + &cdbr->entries_index_s1, &cdbr->entries_index_s2); + } return cdbr; } diff --git a/lib/libc/cdb/cdbw.3 b/lib/libc/cdb/cdbw.3 index bd6e152d0..173412f90 100644 --- a/lib/libc/cdb/cdbw.3 +++ b/lib/libc/cdb/cdbw.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: cdbw.3,v 1.3 2010/11/03 16:17:48 plunky Exp $ +.\" $NetBSD: cdbw.3,v 1.5 2012/06/04 00:26:29 wiz Exp $ .\" .\" Copyright (c) 2010 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -28,7 +28,7 @@ .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. -.Dd November 3, 2010 +.Dd June 3, 2012 .Dt CDBW 3 .Os .Sh NAME @@ -36,6 +36,8 @@ .Nm cdbw_put , .Nm cdbw_put_data , .Nm cdbw_put_key , +.Nm cdbw_stable_seeder , +.Nm cdbw_output , .Nm cdbw_close .Nd create constant databases .Sh SYNOPSIS @@ -64,6 +66,10 @@ .Fa "size_t keylen" .Fa "uint32_t index" .Fc +.Ft uint32_t +.Fo cdbw_stable_seeder +.Fa "void" +.Fc .Ft int .Fo cdbw_output .Fa "struct cdbw *cdbw" @@ -111,8 +117,12 @@ parameter provides a human readable description of the database content. The .Fn seedgen parameter can be used to override the default PRNG. -The function should return a different value for each invokation. The bitwise layout of the output depends on the chosen seed. +The function should return a different value for each invocation. +The +.Fn cdbw_stable_seeder +can be used to create reproducible output. +It may be slower than the default. .Sh SEE ALSO .Xr cdbr 3 , .Xr cdb 5 diff --git a/lib/libc/cdb/cdbw.c b/lib/libc/cdb/cdbw.c index d670740d2..379a6d50b 100644 --- a/lib/libc/cdb/cdbw.c +++ b/lib/libc/cdb/cdbw.c @@ -1,4 +1,4 @@ -/* $NetBSD: cdbw.c,v 1.1 2010/04/25 00:54:46 joerg Exp $ */ +/* $NetBSD: cdbw.c,v 1.5 2012/07/21 22:49:37 joerg Exp $ */ /*- * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -36,11 +36,13 @@ #endif #include -__RCSID("$NetBSD: cdbw.c,v 1.1 2010/04/25 00:54:46 joerg Exp $"); +__RCSID("$NetBSD: cdbw.c,v 1.5 2012/07/21 22:49:37 joerg Exp $"); #include "namespace.h" +#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H #include +#endif #include #include #include @@ -270,6 +272,12 @@ cdbw_close(struct cdbw *cdbw) free(cdbw); } +uint32_t +cdbw_stable_seeder(void) +{ + return 0; +} + #define unused 0xffffffffU struct vertex { @@ -379,6 +387,13 @@ build_graph(struct cdbw *cdbw, struct state *state) e->middle = hashes[1] % state->entries; e->right = hashes[2] % state->entries; + if (e->left == e->middle) + return -1; + if (e->left == e->right) + return -1; + if (e->middle == e->right) + return -1; + ++e; } } @@ -556,8 +571,13 @@ cdbw_output(struct cdbw *cdbw, int fd, const char descr[16], return 0; } +#if HAVE_NBTOOL_CONFIG_H + if (seedgen == NULL) + seedgen = cdbw_stable_seeder; +#else if (seedgen == NULL) seedgen = arc4random; +#endif rv = 0; @@ -581,8 +601,12 @@ cdbw_output(struct cdbw *cdbw, int fd, const char descr[16], goto release; } + state.seed = 0; do { - state.seed = (*seedgen)(); + if (seedgen == cdbw_stable_seeder) + ++state.seed; + else + state.seed = (*seedgen)(); } while (build_graph(cdbw, &state)); assign_nodes(&state); diff --git a/lib/libc/citrus/Makefile.inc b/lib/libc/citrus/Makefile.inc index e2cf7af62..c5955390f 100644 --- a/lib/libc/citrus/Makefile.inc +++ b/lib/libc/citrus/Makefile.inc @@ -3,8 +3,10 @@ # sources .PATH: ${ARCHDIR}/citrus ${.CURDIR}/citrus -#MODULE_SHLIB_MAJOR!= . ${NETBSDSRCDIR}/lib/i18n_module/shlib_version ; echo $$major -#CPPFLAGS.citrus_module.c+=-DI18NMODULE_MAJOR=${MODULE_SHLIB_MAJOR} +.if !defined(__MINIX) +MODULE_SHLIB_MAJOR!= . ${NETBSDSRCDIR}/lib/i18n_module/shlib_version ; echo $$major +CPPFLAGS.citrus_module.c+=-DI18NMODULE_MAJOR=${MODULE_SHLIB_MAJOR} +.endif # !defined(__MINIX) SRCS+= citrus_bcs.c citrus_bcs_strtol.c citrus_bcs_strtoul.c \ citrus_csmapper.c citrus_ctype.c citrus_ctype_fallback.c \ citrus_db.c citrus_db_hash.c citrus_esdb.c citrus_hash.c \ diff --git a/lib/libc/citrus/citrus_csmapper.c b/lib/libc/citrus/citrus_csmapper.c index bcbc9776b..4e8f445c5 100644 --- a/lib/libc/citrus/citrus_csmapper.c +++ b/lib/libc/citrus/citrus_csmapper.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_csmapper.c,v 1.10 2009/01/11 02:46:24 christos Exp $ */ +/* $NetBSD: citrus_csmapper.c,v 1.11 2011/11/20 07:43:52 tnozaki Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_csmapper.c,v 1.10 2009/01/11 02:46:24 christos Exp $"); +__RCSID("$NetBSD: citrus_csmapper.c,v 1.11 2011/11/20 07:43:52 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -142,6 +142,7 @@ find_best_pivot_pvdb(const char *src, const char *dst, char *pivot, if (ret) goto quit3; if (_db_lookup_by_s(db3, dst, &r2, NULL) != 0) + /* don't break the loop, test all src/dst pairs. */ goto quit4; /* r2: norm among pivot and dst */ ret = get32(&r2, &val32); diff --git a/lib/libc/citrus/citrus_ctype.c b/lib/libc/citrus/citrus_ctype.c index d661c2a9f..5155dfcfe 100644 --- a/lib/libc/citrus/citrus_ctype.c +++ b/lib/libc/citrus/citrus_ctype.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_ctype.c,v 1.5 2008/06/14 16:01:07 tnozaki Exp $ */ +/* $NetBSD: citrus_ctype.c,v 1.6 2011/11/19 18:34:21 tnozaki Exp $ */ /*- * Copyright (c)1999, 2000, 2001, 2002 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_ctype.c,v 1.5 2008/06/14 16:01:07 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_ctype.c,v 1.6 2011/11/19 18:34:21 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -113,8 +113,10 @@ _initctypemodule(_citrus_ctype_t cc, char const *modname, cc->cc_ops->co_wcstombs == NULL || cc->cc_ops->co_wctomb == NULL || cc->cc_ops->co_btowc == NULL || - cc->cc_ops->co_wctob == NULL) + cc->cc_ops->co_wctob == NULL) { + ret = EINVAL; goto bad; + } /* init and get closure */ ret = (*cc->cc_ops->co_init)( diff --git a/lib/libc/citrus/citrus_iconv.c b/lib/libc/citrus/citrus_iconv.c index 585b285a6..3b8f61e53 100644 --- a/lib/libc/citrus/citrus_iconv.c +++ b/lib/libc/citrus/citrus_iconv.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_iconv.c,v 1.8 2009/09/05 06:44:27 dholland Exp $ */ +/* $NetBSD: citrus_iconv.c,v 1.10 2011/11/19 18:34:21 tnozaki Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,22 +28,25 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_iconv.c,v 1.8 2009/09/05 06:44:27 dholland Exp $"); +__RCSID("$NetBSD: citrus_iconv.c,v 1.10 2011/11/19 18:34:21 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include "reentrant.h" + +#include +#include + #include +#include +#include +#include +#include +#include #include #include #include -#include -#include #include -#include -#include -#include -#include #include "citrus_namespace.h" #include "citrus_bcs.h" @@ -65,7 +68,8 @@ __RCSID("$NetBSD: citrus_iconv.c,v 1.8 2009/09/05 06:44:27 dholland Exp $"); #ifdef _REENTRANT static rwlock_t lock = RWLOCK_INITIALIZER; #endif -static int isinit = 0; + +static bool isinit = false; static _CITRUS_HASH_HEAD(, _citrus_iconv_shared, CI_HASH_SIZE) shared_pool; static TAILQ_HEAD(, _citrus_iconv_shared) shared_unused; static int shared_num_unused, shared_max_reuse; @@ -82,7 +86,7 @@ init_cache(void) shared_max_reuse = atoi(getenv(CI_ENV_MAX_REUSE)); if (shared_max_reuse < 0) shared_max_reuse = CI_INITIAL_MAX_REUSE; - isinit = 1; + isinit = true; } rwlock_unlock(&lock); } @@ -218,8 +222,10 @@ open_shared(struct _citrus_iconv_shared * __restrict * __restrict rci, ci->ci_ops->io_uninit_shared == NULL || ci->ci_ops->io_init_context == NULL || ci->ci_ops->io_uninit_context == NULL || - ci->ci_ops->io_convert == NULL) + ci->ci_ops->io_convert == NULL) { + ret = EINVAL; goto err; + } /* initialize the converter */ ret = (*ci->ci_ops->io_init_shared)(ci, basedir, src, dst, diff --git a/lib/libc/citrus/citrus_lc_ctype.c b/lib/libc/citrus/citrus_lc_ctype.c index e6d55e7c8..b330c4466 100644 --- a/lib/libc/citrus/citrus_lc_ctype.c +++ b/lib/libc/citrus/citrus_lc_ctype.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_lc_ctype.c,v 1.9 2010/06/19 13:26:51 tnozaki Exp $ */ +/* $NetBSD: citrus_lc_ctype.c,v 1.10 2012/03/04 21:14:55 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_lc_ctype.c,v 1.9 2010/06/19 13:26:51 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_lc_ctype.c,v 1.10 2012/03/04 21:14:55 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "reentrant.h" @@ -130,4 +130,3 @@ _PREFIX(fixup)(_RuneLocale *data) #define _CATEGORY_DEFAULT _DefaultRuneLocale #include "nb_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_citrus_LC_CTYPE_); diff --git a/lib/libc/citrus/citrus_lc_messages.c b/lib/libc/citrus/citrus_lc_messages.c index 6e62db5b8..8f0936042 100644 --- a/lib/libc/citrus/citrus_lc_messages.c +++ b/lib/libc/citrus/citrus_lc_messages.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_lc_messages.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $ */ +/* $NetBSD: citrus_lc_messages.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_lc_messages.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_lc_messages.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -160,4 +160,3 @@ fatal: #define _CATEGORY_MAGIC _CITRUS_LC_MESSAGES_MAGIC_1 #include "citrus_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_citrus_LC_MESSAGES_); diff --git a/lib/libc/citrus/citrus_lc_monetary.c b/lib/libc/citrus/citrus_lc_monetary.c index 833a5a126..563dc3e99 100644 --- a/lib/libc/citrus/citrus_lc_monetary.c +++ b/lib/libc/citrus/citrus_lc_monetary.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_lc_monetary.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $ */ +/* $NetBSD: citrus_lc_monetary.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_lc_monetary.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_lc_monetary.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -217,4 +217,3 @@ fatal: #define _CATEGORY_MAGIC _CITRUS_LC_MONETARY_MAGIC_1 #include "citrus_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_citrus_LC_MONETARY_); diff --git a/lib/libc/citrus/citrus_lc_numeric.c b/lib/libc/citrus/citrus_lc_numeric.c index 65616ee20..7115bf1fe 100644 --- a/lib/libc/citrus/citrus_lc_numeric.c +++ b/lib/libc/citrus/citrus_lc_numeric.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_lc_numeric.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $ */ +/* $NetBSD: citrus_lc_numeric.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_lc_numeric.c,v 1.4 2010/06/13 04:14:57 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_lc_numeric.c,v 1.5 2012/03/04 21:14:55 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -166,4 +166,3 @@ fatal: #define _CATEGORY_MAGIC _CITRUS_LC_NUMERIC_MAGIC_1 #include "citrus_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_citrus_LC_NUMERIC_); diff --git a/lib/libc/citrus/citrus_lc_time.c b/lib/libc/citrus/citrus_lc_time.c index e2100af4e..159a3cedd 100644 --- a/lib/libc/citrus/citrus_lc_time.c +++ b/lib/libc/citrus/citrus_lc_time.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_lc_time.c,v 1.5 2010/06/13 04:14:57 tnozaki Exp $ */ +/* $NetBSD: citrus_lc_time.c,v 1.6 2012/03/04 21:14:55 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_lc_time.c,v 1.5 2010/06/13 04:14:57 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_lc_time.c,v 1.6 2012/03/04 21:14:55 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -211,4 +211,3 @@ fatal: #define _CATEGORY_MAGIC _CITRUS_LC_TIME_MAGIC_1 #include "citrus_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_citrus_LC_TIME_); diff --git a/lib/libc/citrus/citrus_lookup.c b/lib/libc/citrus/citrus_lookup.c index 95adc585e..57af4460b 100644 --- a/lib/libc/citrus/citrus_lookup.c +++ b/lib/libc/citrus/citrus_lookup.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_lookup.c,v 1.6 2009/02/03 04:58:38 lukem Exp $ */ +/* $NetBSD: citrus_lookup.c,v 1.7 2012/05/04 16:45:05 joerg Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_lookup.c,v 1.6 2009/02/03 04:58:38 lukem Exp $"); +__RCSID("$NetBSD: citrus_lookup.c,v 1.7 2012/05/04 16:45:05 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -276,7 +276,7 @@ _citrus_lookup_seq_open(struct _citrus_lookup **rcl, const char *name, cl = malloc(sizeof(*cl)); if (cl == NULL) - return errno; + return ENOMEM; cl->cl_key = NULL; cl->cl_keylen = 0; diff --git a/lib/libc/citrus/citrus_mapper.c b/lib/libc/citrus/citrus_mapper.c index cef71bac6..384990909 100644 --- a/lib/libc/citrus/citrus_mapper.c +++ b/lib/libc/citrus/citrus_mapper.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_mapper.c,v 1.7 2008/07/25 14:05:25 christos Exp $ */ +/* $NetBSD: citrus_mapper.c,v 1.10 2012/06/08 07:49:42 martin Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_mapper.c,v 1.7 2008/07/25 14:05:25 christos Exp $"); +__RCSID("$NetBSD: citrus_mapper.c,v 1.10 2012/06/08 07:49:42 martin Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -102,8 +102,8 @@ _citrus_mapper_create_area( } ma->ma_dir = strdup(area); if (ma->ma_dir == NULL) { + free(ma); ret = errno; - free(ma->ma_dir); goto quit; } _CITRUS_HASH_INIT(&ma->ma_cache, CM_HASH_SIZE); @@ -251,8 +251,10 @@ mapper_open(struct _citrus_mapper_area *__restrict ma, if (!cm->cm_ops->mo_init || !cm->cm_ops->mo_uninit || !cm->cm_ops->mo_convert || - !cm->cm_ops->mo_init_state) + !cm->cm_ops->mo_init_state) { + ret = EINVAL; goto err; + } /* allocate traits structure */ cm->cm_traits = malloc(sizeof(*cm->cm_traits)); diff --git a/lib/libc/citrus/citrus_memstream.c b/lib/libc/citrus/citrus_memstream.c index e32a97c4a..17f9ea3ba 100644 --- a/lib/libc/citrus/citrus_memstream.c +++ b/lib/libc/citrus/citrus_memstream.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_memstream.c,v 1.4 2009/02/03 05:02:12 lukem Exp $ */ +/* $NetBSD: citrus_memstream.c,v 1.5 2012/03/13 21:13:31 christos Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_memstream.c,v 1.4 2009/02/03 05:02:12 lukem Exp $"); +__RCSID("$NetBSD: citrus_memstream.c,v 1.5 2012/03/13 21:13:31 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -46,7 +46,7 @@ const char * _citrus_memory_stream_getln(struct _citrus_memory_stream * __restrict ms, size_t * __restrict rlen) { - int i; + size_t i; const uint8_t *h, *p; size_t ret; diff --git a/lib/libc/citrus/citrus_mmap.c b/lib/libc/citrus/citrus_mmap.c index cc166a6d2..3f338faf7 100644 --- a/lib/libc/citrus/citrus_mmap.c +++ b/lib/libc/citrus/citrus_mmap.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_mmap.c,v 1.3 2005/01/19 00:52:37 mycroft Exp $ */ +/* $NetBSD: citrus_mmap.c,v 1.4 2011/10/15 23:00:01 christos Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_mmap.c,v 1.3 2005/01/19 00:52:37 mycroft Exp $"); +__RCSID("$NetBSD: citrus_mmap.c,v 1.4 2011/10/15 23:00:01 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -46,6 +46,10 @@ __RCSID("$NetBSD: citrus_mmap.c,v 1.3 2005/01/19 00:52:37 mycroft Exp $"); #include "citrus_region.h" #include "citrus_mmap.h" +#if defined(__minix) && !defined(O_CLOEXEC) +#define O_CLOEXEC 0 +#endif + int _citrus_map_file(struct _citrus_region * __restrict r, const char * __restrict path) @@ -58,12 +62,8 @@ _citrus_map_file(struct _citrus_region * __restrict r, _region_init(r, NULL, 0); - if ((fd = open(path, O_RDONLY)) == -1) + if ((fd = open(path, O_RDONLY | O_CLOEXEC)) == -1) return errno; - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { - ret = errno; - goto error; - } if (fstat(fd, &st) == -1) { ret = errno; diff --git a/lib/libc/citrus/citrus_module.c b/lib/libc/citrus/citrus_module.c index e0f542cc7..1249dc62b 100644 --- a/lib/libc/citrus/citrus_module.c +++ b/lib/libc/citrus/citrus_module.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_module.c,v 1.9 2009/01/11 02:46:24 christos Exp $ */ +/* $NetBSD: citrus_module.c,v 1.10 2012/10/15 22:22:01 msaitoh Exp $ */ /*- * Copyright (c)1999, 2000, 2001, 2002 Citrus Project, @@ -89,7 +89,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_module.c,v 1.9 2009/01/11 02:46:24 christos Exp $"); +__RCSID("$NetBSD: citrus_module.c,v 1.10 2012/10/15 22:22:01 msaitoh Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -111,8 +111,8 @@ __RCSID("$NetBSD: citrus_module.c,v 1.9 2009/01/11 02:46:24 christos Exp $"); #ifdef _I18N_DYNAMIC -static int _getdewey(int [], char *); -static int _cmpndewey(int [], int, int [], int); +static unsigned int _getdewey(int [], char *); +static int _cmpndewey(int [], unsigned int, int [], unsigned int); static const char *_findshlib(char *, int *, int *); static const char *_pathI18nModule = NULL; @@ -122,10 +122,10 @@ static const char *_pathI18nModule = NULL; #undef minor #define MAXDEWEY 3 /*ELF*/ -static int +static unsigned int _getdewey(int dewey[], char *cp) { - int i, n; + unsigned int i, n; _DIAGASSERT(dewey != NULL); _DIAGASSERT(cp != NULL); @@ -151,9 +151,9 @@ _getdewey(int dewey[], char *cp) * Return 0 if equal. */ static int -_cmpndewey(int d1[], int n1, int d2[], int n2) +_cmpndewey(int d1[], unsigned int n1, int d2[], unsigned int n2) { - register int i; + register unsigned int i; _DIAGASSERT(d1 != NULL); _DIAGASSERT(d2 != NULL); @@ -182,7 +182,7 @@ static const char * _findshlib(char *name, int *majorp, int *minorp) { int dewey[MAXDEWEY]; - int ndewey; + unsigned int ndewey; int tmp[MAXDEWEY]; int i; int len; @@ -215,7 +215,7 @@ _findshlib(char *name, int *majorp, int *minorp) continue; while ((dp = readdir(dd)) != NULL) { - int n; + unsigned int n; if (dp->d_namlen < len + 4) continue; diff --git a/lib/libc/citrus/citrus_prop.c b/lib/libc/citrus/citrus_prop.c index 0b23628b1..2aec991c2 100644 --- a/lib/libc/citrus/citrus_prop.c +++ b/lib/libc/citrus/citrus_prop.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_prop.c,v 1.3 2006/11/22 23:47:21 tnozaki Exp $ */ +/* $NetBSD: citrus_prop.c,v 1.4 2011/03/30 08:22:01 jruoho Exp $ */ /*- * Copyright (c)2006 Citrus Project, @@ -29,12 +29,13 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_prop.c,v 1.3 2006/11/22 23:47:21 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_prop.c,v 1.4 2011/03/30 08:22:01 jruoho Exp $"); #endif /* LIBC_SCCS and not lint */ #include -#include #include +#include +#include #include #include #include @@ -51,7 +52,8 @@ typedef struct { _citrus_prop_type_t type; union { const char *str; - int bool, chr; + int chr; + bool boolean; uint64_t num; } u; } _citrus_prop_object_t; @@ -228,7 +230,7 @@ _citrus_prop_read_bool(struct _memstream * __restrict ms, if (_bcs_tolower(_memstream_getc(ms)) == 'r' && _bcs_tolower(_memstream_getc(ms)) == 'u' && _bcs_tolower(_memstream_getc(ms)) == 'e') { - obj->u.bool = 1; + obj->u.boolean = true; return 0; } break; @@ -237,7 +239,7 @@ _citrus_prop_read_bool(struct _memstream * __restrict ms, _bcs_tolower(_memstream_getc(ms)) == 'l' && _bcs_tolower(_memstream_getc(ms)) == 's' && _bcs_tolower(_memstream_getc(ms)) == 'e') { - obj->u.bool = 0; + obj->u.boolean = false; return 0; } } @@ -406,11 +408,25 @@ do { \ errnum = (*hint->cb._func_.func)(context, \ hint->name, ostart.u._func_, oend.u._func_);\ } while (/*CONSTCOND*/0) + switch (hint->type) { - case _CITRUS_PROP_BOOL: CALL0(bool); break; - case _CITRUS_PROP_STR : CALL0( str); break; - case _CITRUS_PROP_CHR : CALL1( chr); break; - case _CITRUS_PROP_NUM : CALL1( num); break; + + case _CITRUS_PROP_BOOL: + CALL0(boolean); + break; + + case _CITRUS_PROP_STR: + CALL0(str); + break; + + case _CITRUS_PROP_CHR: + CALL1(chr); + break; + + case _CITRUS_PROP_NUM: + CALL1(num); + break; + default: abort(); /*NOTREACHED*/ diff --git a/lib/libc/citrus/citrus_prop.h b/lib/libc/citrus/citrus_prop.h index 86d3ed179..6637a9b25 100644 --- a/lib/libc/citrus/citrus_prop.h +++ b/lib/libc/citrus/citrus_prop.h @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_prop.h,v 1.3 2006/11/23 13:59:03 tnozaki Exp $ */ +/* $NetBSD: citrus_prop.h,v 1.5 2011/05/23 14:52:32 joerg Exp $ */ /*- * Copyright (c)2006 Citrus Project, @@ -45,7 +45,7 @@ typedef int (*_citrus_prop_##_func_##_cb_func_t) \ typedef struct { \ _citrus_prop_##_func_##_cb_func_t func; \ } _citrus_prop_##_func_##_cb_t; -_CITRUS_PROP_CB0_T(bool, int) +_CITRUS_PROP_CB0_T(boolean, int) _CITRUS_PROP_CB0_T(str, const char *) #undef _CITRUS_PROP_CB0_T @@ -65,7 +65,7 @@ struct _citrus_prop_hint_t { #define _CITRUS_PROP_CB_T_OPS(_name_) \ _citrus_prop_##_name_##_cb_t _name_ union { - _CITRUS_PROP_CB_T_OPS(bool); + _CITRUS_PROP_CB_T_OPS(boolean); _CITRUS_PROP_CB_T_OPS(str); _CITRUS_PROP_CB_T_OPS(chr); _CITRUS_PROP_CB_T_OPS(num); @@ -73,7 +73,7 @@ struct _citrus_prop_hint_t { }; #define _CITRUS_PROP_HINT_BOOL(name, cb) \ - { name, _CITRUS_PROP_BOOL, { .bool = { cb } } } + { name, _CITRUS_PROP_BOOL, { .boolean = { cb } } } #define _CITRUS_PROP_HINT_STR(name, cb) \ { name, _CITRUS_PROP_STR, { .str = { cb } } } #define _CITRUS_PROP_HINT_CHR(name, cb) \ @@ -81,7 +81,7 @@ struct _citrus_prop_hint_t { #define _CITRUS_PROP_HINT_NUM(name, cb) \ { name, _CITRUS_PROP_NUM, { .num = { cb } } } #define _CITRUS_PROP_HINT_END \ - { NULL } + { .name = NULL } __BEGIN_DECLS int _citrus_prop_parse_variable(const _citrus_prop_hint_t * __restrict, diff --git a/lib/libc/citrus/citrus_stdenc.c b/lib/libc/citrus/citrus_stdenc.c index d78407569..3dadbfbac 100644 --- a/lib/libc/citrus/citrus_stdenc.c +++ b/lib/libc/citrus/citrus_stdenc.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_stdenc.c,v 1.3 2005/10/29 18:02:04 tshiozak Exp $ */ +/* $NetBSD: citrus_stdenc.c,v 1.4 2011/11/19 18:39:58 tnozaki Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_stdenc.c,v 1.3 2005/10/29 18:02:04 tshiozak Exp $"); +__RCSID("$NetBSD: citrus_stdenc.c,v 1.4 2011/11/19 18:39:58 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -128,8 +128,10 @@ _citrus_stdenc_open(struct _citrus_stdenc * __restrict * __restrict rce, ce->ce_ops->eo_cstomb == NULL || ce->ce_ops->eo_mbtowc == NULL || ce->ce_ops->eo_wctomb == NULL || - ce->ce_ops->eo_get_state_desc == NULL) + ce->ce_ops->eo_get_state_desc == NULL) { + ret = EINVAL; goto bad; + } /* allocate traits */ ce->ce_traits = malloc(sizeof(*ce->ce_traits)); diff --git a/lib/libc/citrus/modules/citrus_big5.c b/lib/libc/citrus/modules/citrus_big5.c index eda3a718f..f42a93006 100644 --- a/lib/libc/citrus/modules/citrus_big5.c +++ b/lib/libc/citrus/modules/citrus_big5.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_big5.c,v 1.12 2008/06/14 16:01:07 tnozaki Exp $ */ +/* $NetBSD: citrus_big5.c,v 1.13 2011/05/23 14:53:46 joerg Exp $ */ /*- * Copyright (c)2002, 2006 Citrus Project, @@ -60,7 +60,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_big5.c,v 1.12 2008/06/14 16:01:07 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_big5.c,v 1.13 2011/05/23 14:53:46 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -393,7 +393,7 @@ _citrus_BIG5_wcrtomb_priv(_BIG5EncodingInfo * __restrict ei, size_t n, wchar_t wc, _BIG5State * __restrict psenc, size_t * __restrict nresult) { - int l, ret; + size_t l, ret; _DIAGASSERT(ei != NULL); _DIAGASSERT(nresult != 0); diff --git a/lib/libc/citrus/modules/citrus_dechanyu.c b/lib/libc/citrus/modules/citrus_dechanyu.c index 09c40f935..6e480f6e2 100644 --- a/lib/libc/citrus/modules/citrus_dechanyu.c +++ b/lib/libc/citrus/modules/citrus_dechanyu.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_dechanyu.c,v 1.3 2008/06/14 16:01:07 tnozaki Exp $ */ +/* $NetBSD: citrus_dechanyu.c,v 1.4 2011/11/19 18:20:13 tnozaki Exp $ */ /*- * Copyright (c)2007 Citrus Project, @@ -27,7 +27,7 @@ */ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_dechanyu.c,v 1.3 2008/06/14 16:01:07 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_dechanyu.c,v 1.4 2011/11/19 18:20:13 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -187,7 +187,7 @@ _citrus_DECHanyu_mbrtowc_priv(_DECHanyuEncodingInfo * __restrict ei, _DECHanyuState * __restrict psenc, size_t * __restrict nresult) { const char *s0; - int ch, i; + int ch; wchar_t wc; /* ei may be unused */ diff --git a/lib/libc/citrus/modules/citrus_iconv_none.c b/lib/libc/citrus/modules/citrus_iconv_none.c index 45cc2b15f..83a0ec41a 100644 --- a/lib/libc/citrus/modules/citrus_iconv_none.c +++ b/lib/libc/citrus/modules/citrus_iconv_none.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_iconv_none.c,v 1.2 2003/07/01 09:42:16 tshiozak Exp $ */ +/* $NetBSD: citrus_iconv_none.c,v 1.3 2011/05/23 14:45:44 joerg Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_iconv_none.c,v 1.2 2003/07/01 09:42:16 tshiozak Exp $"); +__RCSID("$NetBSD: citrus_iconv_none.c,v 1.3 2011/05/23 14:45:44 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -87,6 +87,7 @@ static int _citrus_iconv_none_iconv_init_context(struct _citrus_iconv *cv) { cv->cv_closure = NULL; + return 0; } static void diff --git a/lib/libc/citrus/modules/citrus_iconv_std.c b/lib/libc/citrus/modules/citrus_iconv_std.c index 59929d892..f344d75eb 100644 --- a/lib/libc/citrus/modules/citrus_iconv_std.c +++ b/lib/libc/citrus/modules/citrus_iconv_std.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_iconv_std.c,v 1.15 2006/11/13 19:08:19 tnozaki Exp $ */ +/* $NetBSD: citrus_iconv_std.c,v 1.16 2012/02/12 13:51:29 wiz Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_iconv_std.c,v 1.15 2006/11/13 19:08:19 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_iconv_std.c,v 1.16 2012/02/12 13:51:29 wiz Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -418,7 +418,6 @@ _citrus_iconv_std_iconv_init_context(struct _citrus_iconv *cv) { const struct _citrus_iconv_std_shared *is = cv->cv_shared->ci_closure; struct _citrus_iconv_std_context *sc; - int ret; size_t szpssrc, szpsdst, sz; char *ptr; diff --git a/lib/libc/citrus/modules/citrus_iso2022.c b/lib/libc/citrus/modules/citrus_iso2022.c index 3f0eec6ff..c31449a6a 100644 --- a/lib/libc/citrus/modules/citrus_iso2022.c +++ b/lib/libc/citrus/modules/citrus_iso2022.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_iso2022.c,v 1.20 2010/12/07 22:01:45 joerg Exp $ */ +/* $NetBSD: citrus_iso2022.c,v 1.22 2011/10/10 22:45:45 tnozaki Exp $ */ /*- * Copyright (c)1999, 2002 Citrus Project, @@ -30,7 +30,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_iso2022.c,v 1.20 2010/12/07 22:01:45 joerg Exp $"); +__RCSID("$NetBSD: citrus_iso2022.c,v 1.22 2011/10/10 22:45:45 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include diff --git a/lib/libc/citrus/modules/citrus_mapper_std.c b/lib/libc/citrus/modules/citrus_mapper_std.c index 7d49f5ff5..9e7d10cbf 100644 --- a/lib/libc/citrus/modules/citrus_mapper_std.c +++ b/lib/libc/citrus/modules/citrus_mapper_std.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_mapper_std.c,v 1.8 2006/09/11 13:06:33 tnozaki Exp $ */ +/* $NetBSD: citrus_mapper_std.c,v 1.10 2011/11/19 18:48:39 tnozaki Exp $ */ /*- * Copyright (c)2003, 2006 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_mapper_std.c,v 1.8 2006/09/11 13:06:33 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_mapper_std.c,v 1.10 2011/11/19 18:48:39 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -185,8 +185,11 @@ rowcol_parse_variable_compat(struct _citrus_mapper_std_rowcol *rc, n = be32toh(rcx->rcx_src_row_end); if (m + n > 0) { ret = set_linear_zone(lz, m, n); - if (ret != 0) + if (ret != 0) { + free(rc->rc_src_rowcol); + rc->rc_src_rowcol = NULL; return ret; + } ++rc->rc_src_rowcol_len, ++lz; } m = be32toh(rcx->rcx_src_col_begin); @@ -426,7 +429,7 @@ _citrus_mapper_std_mapper_uninit(struct _citrus_mapper *cm) { struct _citrus_mapper_std *ms; - _DIAGASSERT(cm!=NULL & cm->cm_closure!=NULL); + _DIAGASSERT(cm!=NULL && cm->cm_closure!=NULL); ms = cm->cm_closure; if (ms->ms_uninit) diff --git a/lib/libc/citrus/modules/citrus_ues.c b/lib/libc/citrus/modules/citrus_ues.c index 08b23d506..f31e83d7c 100644 --- a/lib/libc/citrus/modules/citrus_ues.c +++ b/lib/libc/citrus/modules/citrus_ues.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_ues.c,v 1.2 2010/12/07 22:01:22 joerg Exp $ */ +/* $NetBSD: citrus_ues.c,v 1.3 2012/02/12 13:51:29 wiz Exp $ */ /*- * Copyright (c)2006 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_ues.c,v 1.2 2010/12/07 22:01:22 joerg Exp $"); +__RCSID("$NetBSD: citrus_ues.c,v 1.3 2012/02/12 13:51:29 wiz Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -212,7 +212,7 @@ _citrus_UES_mbrtowc_priv(_UESEncodingInfo * __restrict ei, _UESState * __restrict psenc, size_t * __restrict nresult) { const char *s0; - int ch, head, tail, i, num; + int ch, head, tail, num; wchar_t hi, wc; _DIAGASSERT(ei != NULL); diff --git a/lib/libc/citrus/modules/citrus_utf1632.c b/lib/libc/citrus/modules/citrus_utf1632.c index e582fd60b..ce05d2117 100644 --- a/lib/libc/citrus/modules/citrus_utf1632.c +++ b/lib/libc/citrus/modules/citrus_utf1632.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_utf1632.c,v 1.11 2010/03/20 18:15:32 tnozaki Exp $ */ +/* $NetBSD: citrus_utf1632.c,v 1.12 2012/02/12 13:51:29 wiz Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_utf1632.c,v 1.11 2010/03/20 18:15:32 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_utf1632.c,v 1.12 2012/02/12 13:51:29 wiz Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -250,7 +250,6 @@ _citrus_UTF1632_wcrtomb_priv(_UTF1632EncodingInfo *ei, char *s, size_t n, wchar_t wc, _UTF1632State *psenc, size_t *nresult) { - int ret; wchar_t wc2; static const char _bom[4] = { #if BYTE_ORDER == BIG_ENDIAN diff --git a/lib/libc/citrus/modules/citrus_viqr.c b/lib/libc/citrus/modules/citrus_viqr.c index f27c6cf0e..5d340a130 100644 --- a/lib/libc/citrus/modules/citrus_viqr.c +++ b/lib/libc/citrus/modules/citrus_viqr.c @@ -1,4 +1,4 @@ -/* $NetBSD: citrus_viqr.c,v 1.4 2008/06/14 16:01:08 tnozaki Exp $ */ +/* $NetBSD: citrus_viqr.c,v 1.5 2011/11/19 18:20:13 tnozaki Exp $ */ /*- * Copyright (c)2006 Citrus Project, @@ -29,7 +29,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: citrus_viqr.c,v 1.4 2008/06/14 16:01:08 tnozaki Exp $"); +__RCSID("$NetBSD: citrus_viqr.c,v 1.5 2011/11/19 18:20:13 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -360,7 +360,7 @@ _citrus_VIQR_wcrtomb_priv(_VIQREncodingInfo * __restrict ei, _VIQRState * __restrict psenc, size_t * __restrict nresult) { mnemonic_t *m; - int ch, escape; + int ch; const char *p; _DIAGASSERT(ei != NULL); diff --git a/lib/libc/compat-43/getdtablesize.3 b/lib/libc/compat-43/getdtablesize.3 index 5f19f7fed..e6ec1fba4 100644 --- a/lib/libc/compat-43/getdtablesize.3 +++ b/lib/libc/compat-43/getdtablesize.3 @@ -26,9 +26,9 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)getdtablesize.2 8.1 (Berkeley) 6/4/93 -.\" $NetBSD: getdtablesize.3,v 1.13 2003/08/07 16:42:39 agc Exp $ +.\" $NetBSD: getdtablesize.3,v 1.14 2012/01/05 07:05:59 yamt Exp $ .\" -.Dd June 4, 1993 +.Dd January 5, 2012 .Dt GETDTABLESIZE 3 .Os .Sh NAME @@ -41,13 +41,12 @@ .Ft int .Fn getdtablesize void .Sh DESCRIPTION -Each process has a fixed size descriptor table, -which is guaranteed to have at least 20 slots. -The entries in -the descriptor table are numbered with small integers starting at 0. -The call -.Fn getdtablesize -returns the size of this table. +The +.Nm +function is an equivalent of +.Fn sysconf +with +.Dv _SC_OPEN_MAX . .Sh SEE ALSO .Xr close 2 , .Xr dup 2 , @@ -60,3 +59,12 @@ The .Fn getdtablesize function call appeared in .Bx 4.2 . +.Pp +Historically, each process had a fixed size descriptor table, +which is guaranteed to have at least 20 slots. +The entries in +the descriptor table are numbered with small integers starting at 0. +The call +.Fn getdtablesize +used to return the size of this table. +It doesn't make much sense these days because the size of the table is dynamic. diff --git a/lib/libc/compat-43/getdtablesize.c b/lib/libc/compat-43/getdtablesize.c index eff7c1847..058fc8f8a 100644 --- a/lib/libc/compat-43/getdtablesize.c +++ b/lib/libc/compat-43/getdtablesize.c @@ -1,4 +1,4 @@ -/* $NetBSD: getdtablesize.c,v 1.9 2003/07/26 19:24:41 salo Exp $ */ +/* $NetBSD: getdtablesize.c,v 1.10 2012/06/24 15:26:03 christos Exp $ */ /* * Written by J.T. Conklin . @@ -7,14 +7,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getdtablesize.c,v 1.9 2003/07/26 19:24:41 salo Exp $"); +__RCSID("$NetBSD: getdtablesize.c,v 1.10 2012/06/24 15:26:03 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include int -getdtablesize() +getdtablesize(void) { return ((int)sysconf(_SC_OPEN_MAX)); } diff --git a/lib/libc/compat-43/getwd.c b/lib/libc/compat-43/getwd.c index 98b72c193..4e5aa8ec0 100644 --- a/lib/libc/compat-43/getwd.c +++ b/lib/libc/compat-43/getwd.c @@ -1,4 +1,4 @@ -/* $NetBSD: getwd.c,v 1.14 2003/08/07 16:42:39 agc Exp $ */ +/* $NetBSD: getwd.c,v 1.15 2012/06/25 22:32:43 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getwd.c 8.1 (Berkeley) 6/2/93"; #else -__RCSID("$NetBSD: getwd.c,v 1.14 2003/08/07 16:42:39 agc Exp $"); +__RCSID("$NetBSD: getwd.c,v 1.15 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,8 +51,7 @@ __warn_references(getwd, "warning: getwd() possibly used unsafely, consider using getcwd()") char * -getwd(buf) - char *buf; +getwd(char *buf) { char *p; diff --git a/lib/libc/compat/Makefile b/lib/libc/compat/Makefile index 56fdd7943..d019964c6 100644 --- a/lib/libc/compat/Makefile +++ b/lib/libc/compat/Makefile @@ -12,14 +12,20 @@ COMPATDIR=${.CURDIR} .include "${.CURDIR}/Makefile.inc" +.if !defined(__MINIX) .include "${.CURDIR}/db/Makefile.inc" +.endif # !defined(__MINIX) .include "${.CURDIR}/gen/Makefile.inc" +.if !defined(__MINIX) .include "${.CURDIR}/locale/Makefile.inc" .include "${.CURDIR}/net/Makefile.inc" .include "${.CURDIR}/rpc/Makefile.inc" .include "${.CURDIR}/stdio/Makefile.inc" +.endif # !defined(__MINIX) .include "${.CURDIR}/stdlib/Makefile.inc" +.if !defined(__MINIX) .include "${.CURDIR}/sys/Makefile.inc" +.endif # !defined(__MINIX) COMPATARCHDIR=${.CURDIR}/arch/${ARCHSUBDIR} .PATH: ${COMPATARCHDIR}/gen ${COMPATARCHDIR}/sys diff --git a/lib/libc/compat/Makefile.inc b/lib/libc/compat/Makefile.inc index 68bfbc7b9..ec2033056 100644 --- a/lib/libc/compat/Makefile.inc +++ b/lib/libc/compat/Makefile.inc @@ -5,13 +5,19 @@ CPPFLAGS+= -I${NETBSDSRCDIR}/sys COMPATARCHDIR=${COMPATDIR}/arch/${ARCHSUBDIR} .PATH: ${COMPATARCHDIR}/gen ${COMPATARCHDIR}/sys +.if !defined(__MINIX) .include "${COMPATDIR}/db/Makefile.inc" .include "${COMPATDIR}/locale/Makefile.inc" +.endif #!defined(__MINIX) .include "${COMPATDIR}/gen/Makefile.inc" +.if !defined(__MINIX) .include "${COMPATDIR}/net/Makefile.inc" .include "${COMPATDIR}/rpc/Makefile.inc" .include "${COMPATDIR}/stdio/Makefile.inc" +.if !defined(__MINIX) .include "${COMPATDIR}/stdlib/Makefile.inc" +.endif #!defined(__MINIX) .include "${COMPATDIR}/sys/Makefile.inc" .include "${COMPATDIR}/time/Makefile.inc" .include "${COMPATARCHDIR}/Makefile.inc" +.endif #!defined(__MINIX) diff --git a/lib/libc/compat/arch/arm/sys/Makefile.inc b/lib/libc/compat/arch/arm/sys/Makefile.inc index 64c52469b..47154b1b6 100644 --- a/lib/libc/compat/arch/arm/sys/Makefile.inc +++ b/lib/libc/compat/arch/arm/sys/Makefile.inc @@ -1,6 +1,6 @@ -# $NetBSD: Makefile.inc,v 1.1 2005/10/16 17:27:50 christos Exp $ +# $NetBSD: Makefile.inc,v 1.2 2011/03/06 17:08:13 bouyer Exp $ SRCS+=compat_Ovfork.S compat___semctl.S compat___sigreturn14.S \ compat___sigtramp1.S compat_msgctl.S compat_shmctl.S compat_sigaction.S \ compat_sigpending.S compat_sigprocmask.S compat_sigreturn.S \ - compat_sigsuspend.S + compat_sigsuspend.S compat_quotactl.S diff --git a/lib/libc/compat/arch/arm/sys/compat_quotactl.S b/lib/libc/compat/arch/arm/sys/compat_quotactl.S new file mode 100644 index 000000000..8df4a3de5 --- /dev/null +++ b/lib/libc/compat/arch/arm/sys/compat_quotactl.S @@ -0,0 +1,38 @@ +/* $NetBSD: compat_quotactl.S,v 1.2 2011/03/06 17:08:13 bouyer Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "SYS.h" + +WARN_REFERENCES(quotactl, \ + "warning: reference to compatibility quotactl(); include for correct reference") + +PSEUDO(quotactl,compat_50_quotactl) diff --git a/lib/libc/compat/arch/i386/sys/Makefile.inc b/lib/libc/compat/arch/i386/sys/Makefile.inc index 60a6c2d1b..47154b1b6 100644 --- a/lib/libc/compat/arch/i386/sys/Makefile.inc +++ b/lib/libc/compat/arch/i386/sys/Makefile.inc @@ -1,6 +1,6 @@ -# $NetBSD: Makefile.inc,v 1.1 2005/09/13 01:44:08 christos Exp $ +# $NetBSD: Makefile.inc,v 1.2 2011/03/06 17:08:13 bouyer Exp $ SRCS+=compat_Ovfork.S compat___semctl.S compat___sigreturn14.S \ compat___sigtramp1.S compat_msgctl.S compat_shmctl.S compat_sigaction.S \ compat_sigpending.S compat_sigprocmask.S compat_sigreturn.S \ - compat_sigsuspend.S + compat_sigsuspend.S compat_quotactl.S diff --git a/lib/libc/compat/arch/i386/sys/compat_quotactl.S b/lib/libc/compat/arch/i386/sys/compat_quotactl.S new file mode 100644 index 000000000..8df4a3de5 --- /dev/null +++ b/lib/libc/compat/arch/i386/sys/compat_quotactl.S @@ -0,0 +1,38 @@ +/* $NetBSD: compat_quotactl.S,v 1.2 2011/03/06 17:08:13 bouyer Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "SYS.h" + +WARN_REFERENCES(quotactl, \ + "warning: reference to compatibility quotactl(); include for correct reference") + +PSEUDO(quotactl,compat_50_quotactl) diff --git a/lib/libc/compat/arch/x86_64/sys/Makefile.inc b/lib/libc/compat/arch/x86_64/sys/Makefile.inc index 28fe0557a..f17a650ef 100644 --- a/lib/libc/compat/arch/x86_64/sys/Makefile.inc +++ b/lib/libc/compat/arch/x86_64/sys/Makefile.inc @@ -1,6 +1,6 @@ -# $NetBSD: Makefile.inc,v 1.1 2006/03/11 18:59:21 christos Exp $ +# $NetBSD: Makefile.inc,v 1.2 2011/03/06 17:08:15 bouyer Exp $ SRCS+=compat_Ovfork.S compat___semctl.S compat___sigreturn14.S \ compat_msgctl.S compat_shmctl.S compat_sigaction.S \ compat_sigpending.S compat_sigprocmask.S compat_sigreturn.S \ - compat_sigsuspend.S + compat_sigsuspend.S compat_quotactl.S diff --git a/lib/libc/compat/arch/x86_64/sys/compat_quotactl.S b/lib/libc/compat/arch/x86_64/sys/compat_quotactl.S new file mode 100644 index 000000000..efb80312a --- /dev/null +++ b/lib/libc/compat/arch/x86_64/sys/compat_quotactl.S @@ -0,0 +1,38 @@ +/* $NetBSD: compat_quotactl.S,v 1.2 2011/03/06 17:08:15 bouyer Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "SYS.h" + +WARN_REFERENCES(quotactl, \ + "warning: reference to compatibility quotactl(); include for correct reference") + +PSEUDO(quotactl,compat_50_quotactl) diff --git a/lib/libc/compat/db/hash/compat_ndbmdatum.c b/lib/libc/compat/db/hash/compat_ndbmdatum.c index 098e0e81f..a238834fe 100644 --- a/lib/libc/compat/db/hash/compat_ndbmdatum.c +++ b/lib/libc/compat/db/hash/compat_ndbmdatum.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_ndbmdatum.c,v 1.1 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: compat_ndbmdatum.c,v 1.2 2012/03/13 21:13:31 christos Exp $ */ /* * Written by Klaus Klein , April 28, 2004. @@ -28,4 +28,6 @@ __warn_references(dbm_store, " include for correct reference") #define datum datum12 +#define datum_truncate(a) ((a) > INT_MAX ? INT_MAX : (int)(a)) + #include "db/hash/ndbmdatum.c" diff --git a/lib/libc/compat/gen/Makefile.inc b/lib/libc/compat/gen/Makefile.inc index 501a8dfaf..500dcdb94 100644 --- a/lib/libc/compat/gen/Makefile.inc +++ b/lib/libc/compat/gen/Makefile.inc @@ -1,6 +1,7 @@ -# $NetBSD: Makefile.inc,v 1.13 2010/04/23 19:04:54 drochner Exp $ +# $NetBSD: Makefile.inc,v 1.15 2012/10/10 22:52:26 christos Exp $ .PATH: ${COMPATDIR}/gen +.if !defined(__MINIX) SRCS+=compat_errlist.c compat_fts.c compat___fts13.c compat___fts30.c \ compat___fts31.c compat_getmntinfo.c compat_glob.c compat___glob13.c \ compat_opendir.c compat_readdir.c compat__readdir_unlocked30.c \ @@ -8,4 +9,9 @@ SRCS+=compat_errlist.c compat_fts.c compat___fts13.c compat___fts30.c \ compat_times.c compat_timezone.c compat_unvis.c compat_utmpx.c \ compat__sys_errlist.c compat__sys_nerr.c compat__sys_siglist.c \ compat_time.c compat_utime.c compat_devname.c compat_alphasort.c \ - compat_getpwent.c compat___fts32.c compat_utmp.c compat___fts50.c + compat_getpwent.c compat___fts32.c compat_utmp.c compat___fts50.c \ + compat___unvis13.c compat_syslog.c +.else +SRCS+= \ + compat___unvis13.c compat_syslog.c +.endif # !defined(__MINIX) diff --git a/lib/libc/compat/gen/compat___fts13.c b/lib/libc/compat/gen/compat___fts13.c index f39a62499..7d832f27c 100644 --- a/lib/libc/compat/gen/compat___fts13.c +++ b/lib/libc/compat/gen/compat___fts13.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat___fts13.c,v 1.6 2009/10/19 17:52:01 christos Exp $ */ +/* $NetBSD: compat___fts13.c,v 1.9 2012/03/14 00:25:19 christos Exp $ */ #include "namespace.h" #include @@ -33,6 +33,15 @@ __warn_references(__fts_set13, #define __fts_dev_t uint32_t #define __fts_level_t short +#ifndef ftsent_namelen_truncate +#define ftsent_namelen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif +#ifndef ftsent_pathlen_truncate +#define ftsent_pathlen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif + #define stat __stat13 #define lstat __lstat13 #define fstat __fstat13 diff --git a/lib/libc/compat/gen/compat___fts30.c b/lib/libc/compat/gen/compat___fts30.c index 03ec5cec9..f69e51e18 100644 --- a/lib/libc/compat/gen/compat___fts30.c +++ b/lib/libc/compat/gen/compat___fts30.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat___fts30.c,v 1.3 2009/10/19 17:52:04 christos Exp $ */ +/* $NetBSD: compat___fts30.c,v 1.6 2012/03/14 00:25:19 christos Exp $ */ #include "namespace.h" #include @@ -36,6 +36,15 @@ __warn_references(__fts_set30, #define lstat __lstat30 #define fstat __fstat30 +#ifndef ftsent_namelen_truncate +#define ftsent_namelen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif +#ifndef ftsent_pathlen_truncate +#define ftsent_pathlen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif + #undef fts_children #define fts_children __fts_children30 #undef fts_close diff --git a/lib/libc/compat/gen/compat___fts31.c b/lib/libc/compat/gen/compat___fts31.c index ea5184711..32e872686 100644 --- a/lib/libc/compat/gen/compat___fts31.c +++ b/lib/libc/compat/gen/compat___fts31.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat___fts31.c,v 1.2 2009/10/19 17:52:05 christos Exp $ */ +/* $NetBSD: compat___fts31.c,v 1.4 2012/03/14 00:25:19 christos Exp $ */ #include "namespace.h" #include @@ -31,6 +31,15 @@ __warn_references(__fts_set31, #define __fts_dev_t uint32_t #define __fts_level_t short +#ifndef ftsent_namelen_truncate +#define ftsent_namelen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif +#ifndef ftsent_pathlen_truncate +#define ftsent_pathlen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif + #define stat __stat30 #define lstat __lstat30 #define fstat __fstat30 diff --git a/lib/libc/compat/gen/compat___unvis13.c b/lib/libc/compat/gen/compat___unvis13.c new file mode 100644 index 000000000..df938ba31 --- /dev/null +++ b/lib/libc/compat/gen/compat___unvis13.c @@ -0,0 +1,57 @@ +/* $NetBSD: compat___unvis13.c,v 1.1 2011/03/12 19:52:47 christos Exp $ */ + +/*- + * Copyright (c) 2011 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: compat___unvis13.c,v 1.1 2011/03/12 19:52:47 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#define __LIBC12_SOURCE__ + +#include "namespace.h" +#include + +#include +#include +#include +#include + +#ifdef __warn_references +__warn_references(__unvis13, + "warning: reference to compatibility __unvis13(); include for correct reference") +#endif + +int +__unvis13(char *cp, int c, int *astate, int flag) +{ + flag = (flag & ~1) | ((flag & 1) ? UNVIS_END : 0); + return __unvis50(cp, c, astate, flag); +} diff --git a/lib/libc/compat/gen/compat_fts.c b/lib/libc/compat/gen/compat_fts.c index b3bfdceb7..e590120b0 100644 --- a/lib/libc/compat/gen/compat_fts.c +++ b/lib/libc/compat/gen/compat_fts.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_fts.c,v 1.4 2009/10/19 17:52:05 christos Exp $ */ +/* $NetBSD: compat_fts.c,v 1.6 2012/03/15 16:47:38 christos Exp $ */ /* * Written by Jason R. Thorpe , October 21, 1997. @@ -22,6 +22,15 @@ #define __fts_dev_t uint32_t #define __fts_level_t short +#ifndef ftsent_namelen +#define ftsent_namelen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif +#ifndef fts_pathlen_truncate +#define ftsent_pathlen_truncate(a) \ + ((a) > USHRT_MAX ? USHRT_MAX : (unsigned short)(a)) +#endif + #include #include diff --git a/lib/libc/compat/gen/compat_getmntinfo.c b/lib/libc/compat/gen/compat_getmntinfo.c index 3db1895f3..c3f0f608c 100644 --- a/lib/libc/compat/gen/compat_getmntinfo.c +++ b/lib/libc/compat/gen/compat_getmntinfo.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_getmntinfo.c,v 1.1 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: compat_getmntinfo.c,v 1.2 2012/03/20 17:05:59 matt Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getmntinfo.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: compat_getmntinfo.c,v 1.1 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: compat_getmntinfo.c,v 1.2 2012/03/20 17:05:59 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -58,9 +58,7 @@ __weak_alias(getmntinfo,_getmntinfo) * Return information about mounted filesystems. */ int -getmntinfo(mntbufp, flags) - struct statfs12 **mntbufp; - int flags; +getmntinfo(struct statfs12 **mntbufp, int flags) { static struct statfs12 *mntbuf; static int mntsize; diff --git a/lib/libc/compat/gen/compat_readdir.c b/lib/libc/compat/gen/compat_readdir.c index 08632979e..72d524377 100644 --- a/lib/libc/compat/gen/compat_readdir.c +++ b/lib/libc/compat/gen/compat_readdir.c @@ -1,8 +1,12 @@ -/* $NetBSD: compat_readdir.c,v 1.1 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: compat_readdir.c,v 1.3 2012/02/08 12:10:17 mbalmer Exp $ */ #define __LIBC12_SOURCE__ #include "namespace.h" +#include #include +#include +#include +#include #include #ifdef __weak_alias @@ -17,6 +21,42 @@ __warn_references(readdir_r, "warning: reference to compatibility readdir_r(); include for correct reference") #endif -#define dirent dirent12 +static struct dirent12 * +direnttodirent12(struct dirent12 *d12, const struct dirent *d) +{ + if (d == NULL) + return NULL; -#include "gen/readdir.c" + if (d->d_fileno > UINT_MAX || d->d_namlen >= sizeof(d12->d_name)) { + errno = ERANGE; + return NULL; + } + d12->d_fileno = (uint32_t)d->d_fileno; + d12->d_reclen = (uint16_t)d->d_reclen; + d12->d_namlen = (uint8_t)MIN(d->d_namlen, sizeof(d->d_name) - 1); + d12->d_type = (uint8_t)d->d_type; + memcpy(d12->d_name, d->d_name, (size_t)d12->d_namlen); + d12->d_name[d12->d_namlen] = '\0'; + return d12; +} + +struct dirent12 * +readdir(DIR *dirp) +{ + static struct dirent12 d12; + return direnttodirent12(&d12, __readdir30(dirp)); +} + +int +readdir_r(DIR *dirp, struct dirent12 *entry, struct dirent12 **result) +{ + int error; + struct dirent e, *ep; + + if ((error = __readdir_r30(dirp, &e, &ep)) != 0) + return error; + + *result = entry; + (void)direnttodirent12(entry, &e); + return 0; +} diff --git a/lib/libc/compat/gen/compat_sigsetops.c b/lib/libc/compat/gen/compat_sigsetops.c index dee1ec6a5..f7911b11e 100644 --- a/lib/libc/compat/gen/compat_sigsetops.c +++ b/lib/libc/compat/gen/compat_sigsetops.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_sigsetops.c,v 1.2 2009/01/11 02:46:25 christos Exp $ */ +/* $NetBSD: compat_sigsetops.c,v 1.3 2012/03/20 17:05:59 matt Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -36,7 +36,7 @@ #if 0 static char sccsid[] = "@(#)sigsetops.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: compat_sigsetops.c,v 1.2 2009/01/11 02:46:25 christos Exp $"); +__RCSID("$NetBSD: compat_sigsetops.c,v 1.3 2012/03/20 17:05:59 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -66,25 +66,21 @@ __warn_references(sigismember, "warning: reference to compatibility sigismember(); include for correct reference") int -sigemptyset(set) - sigset13_t *set; +sigemptyset(sigset13_t *set) { *set = 0; return (0); } int -sigfillset(set) - sigset13_t *set; +sigfillset(sigset13_t *set) { *set = ~(sigset13_t)0; return (0); } int -sigaddset(set, signo) - sigset13_t *set; - int signo; +sigaddset(sigset13_t *set, int signo) { if (signo <= 0 || signo >= NSIG13) { errno = EINVAL; @@ -95,9 +91,7 @@ sigaddset(set, signo) } int -sigdelset(set, signo) - sigset13_t *set; - int signo; +sigdelset(sigset13_t *set, int signo) { if (signo <= 0 || signo >= NSIG13) { errno = EINVAL; @@ -108,9 +102,7 @@ sigdelset(set, signo) } int -sigismember(set, signo) - const sigset13_t *set; - int signo; +sigismember(const sigset13_t *set, int signo) { if (signo <= 0 || signo >= NSIG13) { errno = EINVAL; diff --git a/lib/libc/compat/gen/compat_syslog.c b/lib/libc/compat/gen/compat_syslog.c new file mode 100644 index 000000000..e653463d4 --- /dev/null +++ b/lib/libc/compat/gen/compat_syslog.c @@ -0,0 +1,205 @@ +/* $NetBSD: compat_syslog.c,v 1.2 2012/10/11 17:09:55 christos Exp $ */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "namespace.h" +#include + +#define __LIBC12_SOURCE__ +#include + +#include +#include +#include + +void syslog_ss(int, struct syslog_data60 *, const char *, ...) + __printflike(3, 4); +void vsyslog_ss(int, struct syslog_data60 *, const char *, va_list) + __printflike(3, 0); +void syslogp_ss(int, struct syslog_data60 *, const char *, const char *, + const char *, ...) __printflike(5, 0); +void vsyslogp_ss(int, struct syslog_data60 *, const char *, const char *, + const char *, va_list) __printflike(5, 0); + +#ifdef __weak_alias +__weak_alias(closelog_r,_closelog_r) +__weak_alias(openlog_r,_openlog_r) +__weak_alias(setlogmask_r,_setlogmask_r) +__weak_alias(syslog_r,_syslog_r) +__weak_alias(vsyslog_r,_vsyslog_r) +__weak_alias(syslogp_r,_syslogp_r) +__weak_alias(vsyslogp_r,_vsyslogp_r) + +__weak_alias(syslog_ss,_syslog_ss) +__weak_alias(vsyslog_ss,_vsyslog_ss) +__weak_alias(syslogp_ss,_syslogp_ss) +__weak_alias(vsyslogp_ss,_vsyslogp_ss) +#endif /* __weak_alias */ + +__warn_references(closelog_r, + "warning: reference to compatibility closelog_r();" + " include for correct reference") +__warn_references(openlog_r, + "warning: reference to compatibility openlog_r();" + " include for correct reference") +__warn_references(setlogmask_r, + "warning: reference to compatibility setlogmask_r();" + " include for correct reference") +__warn_references(syslog_r, + "warning: reference to compatibility syslog_r();" + " include for correct reference") +__warn_references(vsyslog_r, + "warning: reference to compatibility vsyslog_r();" + " include for correct reference") +__warn_references(syslogp_r, + "warning: reference to compatibility syslogp_r();" + " include for correct reference") +__warn_references(vsyslogp_r, + "warning: reference to compatibility vsyslogp_r();" + " include for correct reference") + +static void +syslog_data_convert(struct syslog_data *d, const struct syslog_data60 *s) +{ + d->log_file = s->log_file; + d->log_connected = s->connected; + d->log_opened = s->opened; + d->log_stat = s->log_stat; + d->log_tag = s->log_tag; + d->log_fac = s->log_fac; + d->log_mask = s->log_mask; +} + +void +closelog_r(struct syslog_data60 *data60) +{ + struct syslog_data data = SYSLOG_DATA_INIT; + syslog_data_convert(&data, data60); + __closelog_r60(&data); +} + +void +openlog_r(const char *ident, int logstat, int logfac, + struct syslog_data60 *data60) +{ + struct syslog_data data = SYSLOG_DATA_INIT; + syslog_data_convert(&data, data60); + __openlog_r60(ident, logstat, logfac, &data); +} + +int +setlogmask_r(int pmask, struct syslog_data60 *data60) +{ + struct syslog_data data = SYSLOG_DATA_INIT; + syslog_data_convert(&data, data60); + return __setlogmask_r60(pmask, &data); +} + +void +syslog_r(int pri, struct syslog_data60 *data60, const char *fmt, ...) +{ + va_list ap; + struct syslog_data data = SYSLOG_DATA_INIT; + syslog_data_convert(&data, data60); + + va_start(ap, fmt); + __vsyslog_r60(pri, &data, fmt, ap); + va_end(ap); +} + +void +vsyslog_r(int pri, struct syslog_data60 *data60, const char *fmt, __va_list ap) +{ + struct syslog_data data = SYSLOG_DATA_INIT; + syslog_data_convert(&data, data60); + __vsyslog_r60(pri, &data, fmt, ap); +} + +void +syslogp_r(int pri, struct syslog_data60 *data60, const char *msgid, + const char *sdfmt, const char *msgfmt, ...) +{ + va_list ap; + struct syslog_data data = SYSLOG_DATA_INIT; + syslog_data_convert(&data, data60); + + va_start(ap, msgfmt); + __vsyslogp_r60(pri, &data, msgid, sdfmt, msgfmt, ap); + va_end(ap); +} + +void +vsyslogp_r(int pri, struct syslog_data60 *data60, const char *msgid, + const char *sdfmt, const char *msgfmt, __va_list ap) +{ + struct syslog_data data = SYSLOG_DATA_INIT; + syslog_data_convert(&data, data60); + + __vsyslogp_r60(pri, &data, msgid, sdfmt, msgfmt, ap); +} + +/* + * These are semi-private + */ +#define LOG_SIGNAL_SAFE (int)0x80000000 + +void +syslog_ss(int pri, struct syslog_data60 *data, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vsyslog_r(pri | LOG_SIGNAL_SAFE, data, fmt, ap); + va_end(ap); +} + +void +syslogp_ss(int pri, struct syslog_data60 *data, const char *msgid, + const char *sdfmt, const char *msgfmt, ...) +{ + va_list ap; + + va_start(ap, msgfmt); + vsyslogp_r(pri | LOG_SIGNAL_SAFE, data, msgid, sdfmt, msgfmt, ap); + va_end(ap); +} + +void +vsyslog_ss(int pri, struct syslog_data60 *data, const char *fmt, va_list ap) +{ + vsyslog_r(pri | LOG_SIGNAL_SAFE, data, fmt, ap); +} + +void +vsyslogp_ss(int pri, struct syslog_data60 *data, const char *msgid, + const char *sdfmt, const char *msgfmt, va_list ap) +{ + vsyslogp_r(pri | LOG_SIGNAL_SAFE, data, msgid, sdfmt, msgfmt, ap); +} diff --git a/lib/libc/compat/gen/compat_timezone.c b/lib/libc/compat/gen/compat_timezone.c index 91a4f0147..5c6165211 100644 --- a/lib/libc/compat/gen/compat_timezone.c +++ b/lib/libc/compat/gen/compat_timezone.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_timezone.c,v 1.3 2009/01/11 02:46:25 christos Exp $ */ +/* $NetBSD: compat_timezone.c,v 1.4 2012/03/20 17:05:59 matt Exp $ */ /* * Copyright (c) 1987, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)timezone.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: compat_timezone.c,v 1.3 2009/01/11 02:46:25 christos Exp $"); +__RCSID("$NetBSD: compat_timezone.c,v 1.4 2012/03/20 17:05:59 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -116,9 +116,7 @@ static const struct zone { * STANDARD LIBRARY. */ char * -_tztab(zone,dst) - int zone; - int dst; +_tztab(int zone, int dst) { const struct zone *zp; char sign; diff --git a/lib/libc/compat/gen/compat_unvis.c b/lib/libc/compat/gen/compat_unvis.c index a90512cdd..fb529a59f 100644 --- a/lib/libc/compat/gen/compat_unvis.c +++ b/lib/libc/compat/gen/compat_unvis.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_unvis.c,v 1.2 2007/03/10 01:13:14 hubertf Exp $ */ +/* $NetBSD: compat_unvis.c,v 1.3 2011/03/12 19:52:47 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: compat_unvis.c,v 1.2 2007/03/10 01:13:14 hubertf Exp $"); +__RCSID("$NetBSD: compat_unvis.c,v 1.3 2011/03/12 19:52:47 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,10 +48,6 @@ __RCSID("$NetBSD: compat_unvis.c,v 1.2 2007/03/10 01:13:14 hubertf Exp $"); #include #include -#ifdef __weak_alias -__weak_alias(unvis,_unvis) -#endif - #ifdef __warn_references __warn_references(unvis, "warning: reference to compatibility unvis(); include for correct reference") @@ -60,5 +56,6 @@ __warn_references(unvis, int unvis(char *cp, int c, int *astate, int flag) { - return __unvis13(cp, c, astate, flag); + flag = (flag & ~1) | ((flag & 1) ? UNVIS_END : 0); + return __unvis50(cp, c, astate, flag); } diff --git a/lib/libc/compat/gen/compat_utmpx.c b/lib/libc/compat/gen/compat_utmpx.c index 44784a268..ad3beb67f 100644 --- a/lib/libc/compat/gen/compat_utmpx.c +++ b/lib/libc/compat/gen/compat_utmpx.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_utmpx.c,v 1.3 2009/01/11 02:46:25 christos Exp $ */ +/* $NetBSD: compat_utmpx.c,v 1.4 2011/07/01 01:08:59 joerg Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: compat_utmpx.c,v 1.3 2009/01/11 02:46:25 christos Exp $"); +__RCSID("$NetBSD: compat_utmpx.c,v 1.4 2011/07/01 01:08:59 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -79,7 +79,7 @@ lastlogx50_to_lastlogx(const struct lastlogx50 *ll50, struct lastlogx *ll) { (void)memcpy(ll->ll_line, ll50->ll_line, sizeof(ll->ll_line)); (void)memcpy(ll->ll_host, ll50->ll_host, sizeof(ll->ll_host)); - (void)memcpy(&ll->ll_ss, &ll50->ll_ss, sizeof(&ll->ll_ss)); + (void)memcpy(&ll->ll_ss, &ll50->ll_ss, sizeof(ll->ll_ss)); timeval50_to_timeval(&ll50->ll_tv, &ll->ll_tv); } @@ -88,7 +88,7 @@ lastlogx_to_lastlogx50(const struct lastlogx *ll, struct lastlogx50 *ll50) { (void)memcpy(ll50->ll_line, ll->ll_line, sizeof(ll50->ll_line)); (void)memcpy(ll50->ll_host, ll->ll_host, sizeof(ll50->ll_host)); - (void)memcpy(&ll50->ll_ss, &ll->ll_ss, sizeof(&ll50->ll_ss)); + (void)memcpy(&ll50->ll_ss, &ll->ll_ss, sizeof(ll50->ll_ss)); timeval_to_timeval50(&ll->ll_tv, &ll50->ll_tv); } diff --git a/lib/libc/compat/include/setjmp.h b/lib/libc/compat/include/setjmp.h index 6160931df..9998e185a 100644 --- a/lib/libc/compat/include/setjmp.h +++ b/lib/libc/compat/include/setjmp.h @@ -1,4 +1,4 @@ -/* $NetBSD: setjmp.h,v 1.1 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: setjmp.h,v 1.2 2011/11/05 09:27:06 joerg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -40,11 +40,11 @@ #define _COMPAT_SETJMP_H_ __BEGIN_DECLS -int __setjmp14(jmp_buf); -void __longjmp14(jmp_buf, int) __attribute__((__noreturn__)); +int __setjmp14(jmp_buf) __returns_twice; +void __longjmp14(jmp_buf, int) __dead; -int __sigsetjmp14(sigjmp_buf, int); -void __siglongjmp14(sigjmp_buf, int) __attribute__((__noreturn__)); +int __sigsetjmp14(sigjmp_buf, int) __returns_twice; +void __siglongjmp14(sigjmp_buf, int) __dead; __END_DECLS #endif /* !_COMPAT_SETJMP_H_ */ diff --git a/lib/libminc/_stdfile.c b/lib/libc/compat/include/stdio.h similarity index 72% rename from lib/libminc/_stdfile.c rename to lib/libc/compat/include/stdio.h index 0f8cc8fe4..b58852f8f 100644 --- a/lib/libminc/_stdfile.c +++ b/lib/libc/compat/include/stdio.h @@ -1,4 +1,4 @@ -/* $NetBSD: findfp.c,v 1.25 2010/09/06 14:52:55 christos Exp $ */ +/* $NetBSD: stdio.h,v 1.1 2012/01/22 18:36:14 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -30,21 +30,17 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * @(#)stdio.h 8.5 (Berkeley) 4/29/95 + * */ -#include -#include +#ifndef _COMPAT_STDIO_H_ +#define _COMPAT_STDIO_H_ -#define std(flags, file) \ -/* p r w flags file bf lfbsize cookie close */ \ - { NULL, 0, 0, flags, file, { NULL, 0 }, 0, __sF + file, NULL, \ -/* read seek write ext up */ \ - NULL, NULL, NULL, { NULL, 0 }, NULL, \ -/* ur ubuf, nbuf lb blksize offset */ \ - 0, { '\0', '\0', '\0' }, { '\0' }, { NULL, 0 }, 0, (fpos_t)0 } +__BEGIN_DECLS +int fgetpos(FILE * __restrict, off_t * __restrict); +int fsetpos(FILE *, const off_t *); +__END_DECLS -FILE __sF[3] = { - std(__SRD, STDIN_FILENO), /* stdin */ - std(__SWR, STDOUT_FILENO), /* stdout */ - std(__SWR|__SNBF, STDERR_FILENO) /* stderr */ -}; +#endif /* _COMPAT_STDIO_H_ */ diff --git a/lib/libc/compat/include/stdlib.h b/lib/libc/compat/include/stdlib.h index 1295041fc..0f713405a 100644 --- a/lib/libc/compat/include/stdlib.h +++ b/lib/libc/compat/include/stdlib.h @@ -1,4 +1,4 @@ -/* $NetBSD: stdlib.h,v 1.4 2009/01/26 15:05:56 drochner Exp $ */ +/* $NetBSD: stdlib.h,v 1.5 2012/04/20 17:31:29 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,6 +38,8 @@ __BEGIN_DECLS void unsetenv(const char *); int __unsetenv13(const char *); +int putenv(char *); +int __putenv50(char *); __aconst char *devname(int32_t, mode_t); __aconst char *__devname50(dev_t, mode_t); diff --git a/lib/libc/compat/include/vis.h b/lib/libc/compat/include/vis.h index 83b17c6e8..084386e50 100644 --- a/lib/libc/compat/include/vis.h +++ b/lib/libc/compat/include/vis.h @@ -1,4 +1,4 @@ -/* $NetBSD: vis.h,v 1.1 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: vis.h,v 1.2 2011/03/12 19:52:47 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,6 +37,7 @@ __BEGIN_DECLS int unvis(char *, int, int *, int); int __unvis13(char *, int, int *, int); +int __unvis50(char *, int, int *, int); __END_DECLS #endif /* !_COMPAT_VIS_H_ */ diff --git a/lib/libc/compat/net/Makefile.inc b/lib/libc/compat/net/Makefile.inc index 1a59b9380..aa8f2513c 100644 --- a/lib/libc/compat/net/Makefile.inc +++ b/lib/libc/compat/net/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.1 2006/08/26 16:07:01 matt Exp $ +# $NetBSD: Makefile.inc,v 1.2 2012/01/20 14:08:05 joerg Exp $ .PATH: ${COMPATDIR}/net -SRCS+=compat_ns_addr.c compat_ns_ntoa.c +SRCS+= __cmsg_alignbytes.c compat_ns_addr.c compat_ns_ntoa.c diff --git a/common/lib/libc/net/__cmsg_alignbytes.c b/lib/libc/compat/net/__cmsg_alignbytes.c similarity index 85% rename from common/lib/libc/net/__cmsg_alignbytes.c rename to lib/libc/compat/net/__cmsg_alignbytes.c index 726ff566e..dbf21f86f 100644 --- a/common/lib/libc/net/__cmsg_alignbytes.c +++ b/lib/libc/compat/net/__cmsg_alignbytes.c @@ -1,4 +1,4 @@ -/* $NetBSD: __cmsg_alignbytes.c,v 1.3 2009/03/16 05:59:21 cegger Exp $ */ +/* $NetBSD: __cmsg_alignbytes.c,v 1.1 2012/01/20 14:08:05 joerg Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -29,22 +29,16 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#if !defined(_KERNEL) && !defined(_STANDALONE) #include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: __cmsg_alignbytes.c,v 1.3 2009/03/16 05:59:21 cegger Exp $"); -#endif /* LIBC_SCCS and not lint */ +__RCSID("$NetBSD: __cmsg_alignbytes.c,v 1.1 2012/01/20 14:08:05 joerg Exp $"); #include "namespace.h" #include #include #include #include -#else -#include -#include -#include -#endif + +int __cmsg_alignbytes(void); int __cmsg_alignbytes(void) diff --git a/lib/libc/compat/net/compat_ns_addr.c b/lib/libc/compat/net/compat_ns_addr.c index be55f3bbf..a3667fca3 100644 --- a/lib/libc/compat/net/compat_ns_addr.c +++ b/lib/libc/compat/net/compat_ns_addr.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_ns_addr.c,v 1.1 2006/08/26 16:07:01 matt Exp $ */ +/* $NetBSD: compat_ns_addr.c,v 1.3 2012/10/15 22:22:01 msaitoh Exp $ */ /* * Copyright (c) 1986, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)ns_addr.c 8.1 (Berkeley) 6/7/93"; #else -__RCSID("$NetBSD: compat_ns_addr.c,v 1.1 2006/08/26 16:07:01 matt Exp $"); +__RCSID("$NetBSD: compat_ns_addr.c,v 1.3 2012/10/15 22:22:01 msaitoh Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,12 +49,11 @@ __RCSID("$NetBSD: compat_ns_addr.c,v 1.1 2006/08/26 16:07:01 matt Exp $"); #include #include -static void Field __P((char *, u_int8_t *, int)); -static void cvtbase __P((long, int, int[], int, u_int8_t[], int)); +static void Field(char *, uint8_t *, int); +static void cvtbase(long, int, int[], int, uint8_t [], int); struct ns_addr -ns_addr(name) - const char *name; +ns_addr(const char *name) { char separator; char *hostname, *socketname, *cp; @@ -93,7 +92,7 @@ ns_addr(name) socketname = strchr(hostname, separator); if (socketname) { *socketname++ = 0; - Field(socketname, (u_int8_t *)(void *)&addr.x_port, 2); + Field(socketname, (uint8_t *)(void *)&addr.x_port, 2); } Field(hostname, addr.x_host.c_host, 6); @@ -102,13 +101,11 @@ ns_addr(name) } static void -Field(buf, out, len) - char *buf; - u_int8_t *out; - int len; +Field(char *buf, uint8_t *out, int len) { register char *bp = buf; - int i, ibase, base16 = 0, base10 = 0, clen = 0; + int i, ibase, base16 = 0, base10 = 0; + unsigned int clen = 0; int hb[6], *hp; _DIAGASSERT(buf != NULL); @@ -218,19 +215,15 @@ Field(buf, out, len) } static void -cvtbase(oldbase,newbase,input,inlen,result,reslen) - long oldbase; - int newbase; - int input[]; - int inlen; - unsigned char result[]; - int reslen; +cvtbase(long oldbase, int newbase, int input[], int inlen, + uint8_t result[], int reslen) { int d, e; long sum; _DIAGASSERT(input != NULL); _DIAGASSERT(result != NULL); + _DIAGASSERT(inlen > 0); e = 1; while (e > 0 && reslen > 0) { diff --git a/lib/libc/compat/net/compat_ns_ntoa.c b/lib/libc/compat/net/compat_ns_ntoa.c index 469b2e731..3aaa5d9f7 100644 --- a/lib/libc/compat/net/compat_ns_ntoa.c +++ b/lib/libc/compat/net/compat_ns_ntoa.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_ns_ntoa.c,v 1.1 2006/08/26 16:07:01 matt Exp $ */ +/* $NetBSD: compat_ns_ntoa.c,v 1.2 2012/03/20 17:05:59 matt Exp $ */ /* * Copyright (c) 1986, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)ns_ntoa.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: compat_ns_ntoa.c,v 1.1 2006/08/26 16:07:01 matt Exp $"); +__RCSID("$NetBSD: compat_ns_ntoa.c,v 1.2 2012/03/20 17:05:59 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -44,19 +44,18 @@ __RCSID("$NetBSD: compat_ns_ntoa.c,v 1.1 2006/08/26 16:07:01 matt Exp $"); #include #include -static char *spectHex __P((char *)); +static char *spectHex(char *); char * -ns_ntoa(addr) - struct ns_addr addr; +ns_ntoa(struct ns_addr addr) { static char obuf[40]; - union { union ns_net net_e; u_int32_t long_e; } net; - u_int16_t port = htons(addr.x_port); + union { union ns_net net_e; uint32_t long_e; } net; + uint16_t port = htons(addr.x_port); char *cp; char *cp2; - u_int8_t *up = addr.x_host.c_host; - u_int8_t *uplim = up + 6; + uint8_t *up = addr.x_host.c_host; + uint8_t *uplim = up + 6; net.net_e = addr.x_net; sprintf(obuf, "%x", ntohl(net.long_e)); @@ -85,8 +84,7 @@ ns_ntoa(addr) } static char * -spectHex(p0) - char *p0; +spectHex(char *p0) { int ok = 0; int nonzero = 0; diff --git a/lib/libc/compat/shlib_version b/lib/libc/compat/shlib_version index 97c9f92d6..5b1659f3c 100644 --- a/lib/libc/compat/shlib_version +++ b/lib/libc/compat/shlib_version @@ -1,2 +1,5 @@ +# $NetBSD: shlib_version,v 1.1 2006/03/11 21:07:18 christos Exp $ +# Remember to update distrib/sets/lists/base/shl.* when changing +# major=0 minor=0 diff --git a/lib/libc/compat/stdio/Makefile.inc b/lib/libc/compat/stdio/Makefile.inc new file mode 100644 index 000000000..0a02e2680 --- /dev/null +++ b/lib/libc/compat/stdio/Makefile.inc @@ -0,0 +1,23 @@ +# $NetBSD: Makefile.inc,v 1.1 2012/01/22 18:36:18 christos Exp $ + +.PATH: ${COMPATDIR}/arch/${MACHINE_ARCH}/stdio ${COMPATDIR}/stdio + +SRCS+= compat_fgetpos.c compat_fsetpos.c +CPPFLAGS.compat_fgetpos.c+= -I${COMPATDIR}/../stdio +CPPFLAGS.compat_fsetpos.c+= -I${COMPATDIR}/../stdio +# $NetBSD: Makefile.inc,v 1.1 2012/01/22 18:36:18 christos Exp $ + +.ifndef ABSTOP +ABSTOP!= cd ${.PARSEDIR}; pwd + +.if (${.PARSEDIR} == ${.CURDIR}) +RELTOP:= . +.else +RELTOP:= ${.PARSEDIR:S,^${.CURDIR},,} +.endif + +# you can set BSD{SRC,OBJ}DIR in Makefile.local.inc +.if exists(${ABSTOP}/Makefile.local.inc) +.include "${ABSTOP}/Makefile.local.inc" +.endif +.endif diff --git a/lib/libc/compat/stdio/compat_fgetpos.c b/lib/libc/compat/stdio/compat_fgetpos.c new file mode 100644 index 000000000..c2b129826 --- /dev/null +++ b/lib/libc/compat/stdio/compat_fgetpos.c @@ -0,0 +1,64 @@ +/* $NetBSD: compat_fgetpos.c,v 1.1 2012/01/22 18:36:18 christos Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Original version ID: + * NetBSD: fgetpos.c,v 1.11 2003/08/07 16:43:23 agc Exp + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: compat_fgetpos.c,v 1.1 2012/01/22 18:36:18 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#define __LIBC12_SOURCE__ + +#include "namespace.h" +#include + +#include +#include +#include + +#ifdef __warn_references +__warn_references(fgetpos, + "warning: reference to compatibility fgetpos(); include for correct reference") +#endif + +int +fgetpos(FILE * __restrict fp, off_t * __restrict pos) +{ + _DIAGASSERT(fp != NULL); + _DIAGASSERT(pos != NULL); + + return (*pos = ftello(fp)) == (off_t)-1; +} diff --git a/lib/libc/compat/stdio/compat_fsetpos.c b/lib/libc/compat/stdio/compat_fsetpos.c new file mode 100644 index 000000000..a0522829c --- /dev/null +++ b/lib/libc/compat/stdio/compat_fsetpos.c @@ -0,0 +1,68 @@ +/* $NetBSD: compat_fsetpos.c,v 1.1 2012/01/22 18:36:19 christos Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Original version ID: + * NetBSD: fsetpos.c,v 1.10 2003/08/07 16:43:25 agc Exp + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: compat_fsetpos.c,v 1.1 2012/01/22 18:36:19 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#define __LIBC12_SOURCE__ + +#include "namespace.h" +#include + +#include +#include +#include + +#ifdef __warn_references +__warn_references(fsetpos, + "warning: reference to compatibility fsetpos(); include for correc t reference") +#endif + + +/* + * fsetpos: like fseek. + */ +int +fsetpos(FILE * __restrict iop, const off_t * __restrict pos) +{ + _DIAGASSERT(iop != NULL); + _DIAGASSERT(pos != NULL); + + return fseeko(iop, *pos, SEEK_SET) == (off_t)-1; +} diff --git a/lib/libc/compat/stdlib/Makefile.inc b/lib/libc/compat/stdlib/Makefile.inc index c844080ce..3908980ec 100644 --- a/lib/libc/compat/stdlib/Makefile.inc +++ b/lib/libc/compat/stdlib/Makefile.inc @@ -1,5 +1,5 @@ -# $NetBSD: Makefile.inc,v 1.2 2006/03/11 21:07:18 christos Exp $ +# $NetBSD: Makefile.inc,v 1.3 2012/04/20 17:31:30 christos Exp $ .PATH: ${COMPATDIR}/stdlib CPPFLAGS+=-I${COMPATDIR}/stdlib -I${COMPATDIR}/../stdlib -SRCS+=compat_unsetenv.c +SRCS+=compat_putenv.c compat_unsetenv.c diff --git a/lib/libc/locale/localeio_lc_time.c b/lib/libc/compat/stdlib/compat_putenv.c similarity index 58% rename from lib/libc/locale/localeio_lc_time.c rename to lib/libc/compat/stdlib/compat_putenv.c index 7da22da5c..a234f8292 100644 --- a/lib/libc/locale/localeio_lc_time.c +++ b/lib/libc/compat/stdlib/compat_putenv.c @@ -1,11 +1,11 @@ -/* $NetBSD: localeio_lc_time.c,v 1.2 2009/01/11 02:46:28 christos Exp $ */ +/* $NetBSD: compat_putenv.c,v 1.2 2012/04/22 15:55:41 christos Exp $ */ -/* - * Copyright (c) 2008, The NetBSD Foundation, Inc. +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. - * + * * This code is derived from software contributed to The NetBSD Foundation - * by Brian Ginsbach. + * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -28,57 +28,57 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: localeio_lc_time.c,v 1.2 2009/01/11 02:46:28 christos Exp $"); +__RCSID("$NetBSD: compat_putenv.c,v 1.2 2012/04/22 15:55:41 christos Exp $"); #endif /* LIBC_SCCS and not lint */ -#include "reentrant.h" -#include -#include -#include +#define __LIBC12_SOURCE__ +#include "namespace.h" + #include #include -#include -#include -#define __SETLOCALE_SOURCE__ -#include -#include #include #include +#include -#include "setlocale_local.h" +#include "env.h" +#include "reentrant.h" +#include "local.h" -#include "aliasname_local.h" -#include "fix_grouping.h" -#include "localeio.h" +#ifdef __weak_alias +__weak_alias(putenv,_putenv) +#endif + +__warn_references(putenv, + "warning: reference to compatibility putenv();" + " include for correct reference") /* - * macro required by all template headers + * putenv(name) -- + * This version implicitly copies the string for compatibility. */ -#define _PREFIX(name) __CONCAT(_localeio_LC_TIME_, name) +int +putenv(char *name) +{ + size_t l_name; + char *copy; + int rv; -#include "nb_lc_time_misc.h" -#include "nb_lc_template_decl.h" + _DIAGASSERT(name != NULL); -#define NSTRINGS (sizeof(_TimeLocale)/sizeof(const char **)) + l_name = __envvarnamelen(name, true); + if (l_name == 0) { + errno = EINVAL; + return -1; + } -static int -_localeio_LC_TIME_create_impl(const char * __restrict root, - const char * __restrict name, _TimeLocale ** __restrict pdata) -{ - char path[PATH_MAX + 1]; + if ((copy = strdup(name)) == NULL) + return -1; + copy[l_name++] = '\0'; - _DIAGASSERT(root != NULL); - _DIAGASSERT(name != NULL); - _DIAGASSERT(pdata != NULL); + rv = setenv(copy, copy + l_name, 1); - snprintf(path, sizeof(path), - "%s/%s/LC_TIME", root, name); - return __loadlocale(path, NSTRINGS, 0, sizeof(_TimeLocale), - (void *)pdata); + free(copy); + return rv; } - -#include "nb_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_localeio_LC_TIME_); diff --git a/lib/libc/compat/sys/compat___semctl13.c b/lib/libc/compat/sys/compat___semctl13.c index 94ca2000c..c3eacf9d9 100644 --- a/lib/libc/compat/sys/compat___semctl13.c +++ b/lib/libc/compat/sys/compat___semctl13.c @@ -1,6 +1,6 @@ -/* $NetBSD: compat___semctl13.c,v 1.2 2009/01/11 02:46:26 christos Exp $ */ +/* $NetBSD: compat___semctl13.c,v 1.3 2011/01/31 22:51:39 christos Exp $ */ -/* $NetBSD: compat___semctl13.c,v 1.2 2009/01/11 02:46:26 christos Exp $ */ +/* $NetBSD: compat___semctl13.c,v 1.3 2011/01/31 22:51:39 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ */ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: compat___semctl13.c,v 1.2 2009/01/11 02:46:26 christos Exp $"); +__RCSID("$NetBSD: compat___semctl13.c,v 1.3 2011/01/31 22:51:39 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -77,14 +77,25 @@ __semctl13(int semid, int semnum, int cmd, ...) #else semun = va_arg(ap, union __semun); #endif + break; + default: + break; } va_end(ap); - ds13 = (struct semid_ds13 *)(void *)semun.buf; - semun.buf = &ds; + switch (cmd) { + case IPC_SET: + case IPC_STAT: + ds13 = (void *)semun.buf; + semun.buf = &ds; + if (cmd == IPC_SET) + __semid_ds13_to_native(ds13, &ds); + break; + default: + ds13 = NULL; + break; + } - if (cmd == IPC_SET) - __semid_ds13_to_native(ds13, &ds); error = ____semctl50(semid, semnum, cmd, &semun); if (error) @@ -92,7 +103,5 @@ __semctl13(int semid, int semnum, int cmd, ...) if (cmd == IPC_STAT) __native_to_semid_ds13(&ds, ds13); - - semun.buf = (struct semid_ds *)(void *)ds13; return 0; } diff --git a/lib/libc/compat/sys/compat_getdents.c b/lib/libc/compat/sys/compat_getdents.c index 20a70e498..c0c372338 100644 --- a/lib/libc/compat/sys/compat_getdents.c +++ b/lib/libc/compat/sys/compat_getdents.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_getdents.c,v 1.3 2008/04/28 20:22:59 martin Exp $ */ +/* $NetBSD: compat_getdents.c,v 1.6 2012/03/13 22:24:48 joerg Exp $ */ /*- * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -31,14 +31,16 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: compat_getdents.c,v 1.3 2008/04/28 20:22:59 martin Exp $"); +__RCSID("$NetBSD: compat_getdents.c,v 1.6 2012/03/13 22:24:48 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #define __LIBC12_SOURCE__ #include "namespace.h" #include +#include #include +#include #include #include @@ -50,7 +52,9 @@ getdents(int fd, char *buf, size_t nbytes) { struct dirent *ndp, *nndp, *endp; struct dirent12 *odp; + ino_t ino; int rv; + size_t len; if ((rv = __getdents30(fd, buf, nbytes)) == -1) return rv; @@ -67,7 +71,9 @@ getdents(int fd, char *buf, size_t nbytes) for (; ndp < endp; ndp = nndp) { nndp = _DIRENT_NEXT(ndp); /* XXX: avoid unaligned 64-bit access on sparc64 */ - odp->d_ino = ((u_int32_t *)(void *)&ndp->d_ino)[_QUAD_LOWWORD]; + /* XXX: does this work? */ + memcpy(&ino, &ndp->d_ino, sizeof(ino_t)); + odp->d_ino = (uint32_t)ino; if (ndp->d_namlen >= sizeof(odp->d_name)) odp->d_namlen = sizeof(odp->d_name) - 1; else @@ -75,8 +81,12 @@ getdents(int fd, char *buf, size_t nbytes) odp->d_type = ndp->d_type; (void)memcpy(odp->d_name, ndp->d_name, (size_t)odp->d_namlen); odp->d_name[odp->d_namlen] = '\0'; - odp->d_reclen = _DIRENT_SIZE(odp); + len = _DIRENT_SIZE(odp); + _DIAGASSERT(__type_fit(uint16_t, len)); + odp->d_reclen = (uint16_t)len; odp = _DIRENT_NEXT(odp); } - return ((char *)(void *)odp) - buf; + ptrdiff_t td = (((char *)(void *)odp) - buf); + _DIAGASSERT(__type_fit(int, td)); + return (int)td; } diff --git a/lib/libc/compat/sys/compat_getdirentries.c b/lib/libc/compat/sys/compat_getdirentries.c index 5942cc778..a77de9ea2 100644 --- a/lib/libc/compat/sys/compat_getdirentries.c +++ b/lib/libc/compat/sys/compat_getdirentries.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_getdirentries.c,v 1.2 2009/02/22 06:33:38 dholland Exp $ */ +/* $NetBSD: compat_getdirentries.c,v 1.3 2012/03/20 17:06:00 matt Exp $ */ /* * Copyright (c) 1997 Frank van der Linden @@ -34,7 +34,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: compat_getdirentries.c,v 1.2 2009/02/22 06:33:38 dholland Exp $"); +__RCSID("$NetBSD: compat_getdirentries.c,v 1.3 2012/03/20 17:06:00 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #define __LIBC12_SOURCE__ @@ -48,10 +48,7 @@ __warn_references(getdirentries, "reference to compatibility-only getdirentries(); this will break; use getdents() or readdir() instead") int -getdirentries(fd, buf, nbytes, basep) - int fd, nbytes; - char *buf; - long *basep; +getdirentries(int fd, char *buf, int nbytes, long *basep) { *basep = (long)lseek(fd, (off_t)0, SEEK_CUR); return getdents(fd, buf, (size_t)nbytes); diff --git a/lib/libc/compat/sys/compat_msync.c b/lib/libc/compat/sys/compat_msync.c index 3e05ff64b..b0c2822fe 100644 --- a/lib/libc/compat/sys/compat_msync.c +++ b/lib/libc/compat/sys/compat_msync.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_msync.c,v 1.1 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: compat_msync.c,v 1.2 2012/03/20 17:06:00 matt Exp $ */ /* * Copyright (c) 1997 Frank van der Linden @@ -33,7 +33,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: compat_msync.c,v 1.1 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: compat_msync.c,v 1.2 2012/03/20 17:06:00 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #define __LIBC12_SOURCE__ @@ -46,9 +46,7 @@ __warn_references(msync, "warning: reference to compatibility msync(); include for correct reference") int -msync(addr, size) - void *addr; - size_t size; +msync(void *addr, size_t size) { return __msync13(addr, size, MS_SYNC|MS_INVALIDATE); } diff --git a/lib/libc/compat/sys/compat_semctl.c b/lib/libc/compat/sys/compat_semctl.c index 8e5f05aab..96b6ad01c 100644 --- a/lib/libc/compat/sys/compat_semctl.c +++ b/lib/libc/compat/sys/compat_semctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_semctl.c,v 1.2 2009/01/11 02:46:26 christos Exp $ */ +/* $NetBSD: compat_semctl.c,v 1.3 2011/01/31 22:51:39 christos Exp $ */ /* * Copyright (c) 1994, 1995 Christopher G. Demetriou @@ -36,7 +36,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: compat_semctl.c,v 1.2 2009/01/11 02:46:26 christos Exp $"); +__RCSID("$NetBSD: compat_semctl.c,v 1.3 2011/01/31 22:51:39 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #define __LIBC12_SOURCE__ @@ -53,7 +53,7 @@ semctl(int semid, int semnum, int cmd, ...) va_list ap; union __semun semun; struct semid_ds ds; - struct semid_ds14 *ds14 = NULL; + struct semid_ds14 *ds14; int error; va_start(ap, cmd); @@ -68,27 +68,30 @@ semctl(int semid, int semnum, int cmd, ...) #else semun = va_arg(ap, union __semun); #endif + break; + default: + break; } va_end(ap); switch (cmd) { case IPC_SET: case IPC_STAT: - ds14 = (struct semid_ds14 *)(void *)semun.buf; + ds14 = (void *)semun.buf; if (cmd == IPC_SET) __semid_ds14_to_native(ds14, &ds); semun.buf = &ds; break; + default: + ds14 = NULL; + break; } error = __semctl50(semid, semnum, cmd, &semun); - switch (cmd) { - case IPC_SET: - case IPC_STAT: - semun.buf = (struct semid_ds *)(void *)ds14; - if (cmd == IPC_STAT && error == 0) - __native_to_semid_ds14(&ds, ds14); - break; - } - return error; + if (error) + return error; + + if (cmd == IPC_STAT) + __native_to_semid_ds14(&ds, ds14); + return 0; } diff --git a/lib/libc/compat/sys/compat_sigaltstack.c b/lib/libc/compat/sys/compat_sigaltstack.c index 909e84cfe..dfa6d46ef 100644 --- a/lib/libc/compat/sys/compat_sigaltstack.c +++ b/lib/libc/compat/sys/compat_sigaltstack.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_sigaltstack.c,v 1.3 2009/01/11 02:46:26 christos Exp $ */ +/* $NetBSD: compat_sigaltstack.c,v 1.5 2012/03/20 17:06:00 matt Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: compat_sigaltstack.c,v 1.3 2009/01/11 02:46:26 christos Exp $"); +__RCSID("$NetBSD: compat_sigaltstack.c,v 1.5 2012/03/20 17:06:00 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #define __LIBC12_SOURCE__ @@ -44,9 +44,7 @@ __RCSID("$NetBSD: compat_sigaltstack.c,v 1.3 2009/01/11 02:46:26 christos Exp $" #include int -sigaltstack(onss, ooss) - const struct sigaltstack13 *onss; - struct sigaltstack13 *ooss; +sigaltstack(const struct sigaltstack13 *onss, struct sigaltstack13 *ooss) { stack_t nss, oss; int error; @@ -62,7 +60,7 @@ sigaltstack(onss, ooss) if (oss.ss_size > INT_MAX) ooss->ss_size = INT_MAX; else - ooss->ss_size = oss.ss_size; + ooss->ss_size = (int)oss.ss_size; ooss->ss_flags = oss.ss_flags; } diff --git a/lib/libc/compat/time/compat_localtime.c b/lib/libc/compat/time/compat_localtime.c index 8a2224e30..03a63e1a0 100644 --- a/lib/libc/compat/time/compat_localtime.c +++ b/lib/libc/compat/time/compat_localtime.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_localtime.c,v 1.2 2009/01/11 03:46:25 christos Exp $ */ +/* $NetBSD: compat_localtime.c,v 1.3 2011/02/21 22:07:44 christos Exp $ */ /* * Written by Jason R. Thorpe , October 21, 1997. @@ -16,10 +16,14 @@ #ifdef __weak_alias __weak_alias(ctime_r,_ctime_r) +__weak_alias(ctime_rz,_ctime_rz) __weak_alias(gmtime_r,_gmtime_r) __weak_alias(localtime_r,_localtime_r) +__weak_alias(localtime_rz,_localtime_rz) +__weak_alias(mktime_z,_mktime_z) __weak_alias(offtime,_offtime) __weak_alias(posix2time,_posix2time) +__weak_alias(posix2time_z,_posix2time_z) __weak_alias(time2posix,_time2posix) __weak_alias(timegm,_timegm) __weak_alias(timelocal,_timelocal) @@ -31,18 +35,30 @@ __weak_alias(tzsetwall,_tzsetwall) __warn_references(ctime_r, "warning: reference to compatibility ctime_r();" " include for correct reference") +__warn_references(ctime_rz, + "warning: reference to compatibility ctime_rz();" + " include for correct reference") __warn_references(gmtime_r, "warning: reference to compatibility gmtime_r();" " include for correct reference") __warn_references(localtime_r, "warning: reference to compatibility localtime_r();" " include for correct reference") +__warn_references(localtime_rz, + "warning: reference to compatibility localtime_rz();" + " include for correct reference") +__warn_references(mktime_z, + "warning: reference to compatibility mktime_z();" + " include for correct reference") __warn_references(offtime, "warning: reference to compatibility offtime();" " include for correct reference") __warn_references(posix2time, "warning: reference to compatibility posix2time();" " include for correct reference") +__warn_references(posix2time_z, + "warning: reference to compatibility posix2time_z();" + " include for correct reference") __warn_references(time2posix, "warning: reference to compatibility time2posix();" " include for correct reference") diff --git a/lib/libc/db/btree/bt_debug.c b/lib/libc/db/btree/bt_debug.c index 590ca4ac2..5b5f2cd81 100644 --- a/lib/libc/db/btree/bt_debug.c +++ b/lib/libc/db/btree/bt_debug.c @@ -1,4 +1,4 @@ -/* $NetBSD: bt_debug.c,v 1.15 2008/09/10 17:52:35 joerg Exp $ */ +/* $NetBSD: bt_debug.c,v 1.16 2011/07/17 20:47:39 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: bt_debug.c,v 1.15 2008/09/10 17:52:35 joerg Exp $"); +__RCSID("$NetBSD: bt_debug.c,v 1.16 2011/07/17 20:47:39 christos Exp $"); #include #include @@ -124,6 +124,22 @@ __bt_dmpage(PAGE *h) } } +static pgno_t +__bt_pgno_t(const void *m) +{ + pgno_t r; + memcpy(&r, m, sizeof(r)); + return r; +} + +static uint32_t +__bt_uint32_t(const void *m) +{ + uint32_t r; + memcpy(&r, m, sizeof(r)); + return r; +} + /* * BT_DNPAGE -- Dump the page * @@ -206,15 +222,16 @@ __bt_dpage(PAGE *h) if (bl->flags & P_BIGKEY) (void)fprintf(stderr, "big key page %lu size %u/", - (unsigned long) *(pgno_t *)(void *)bl->bytes, - *(uint32_t *)(void *)(bl->bytes + sizeof(pgno_t))); + (unsigned long) __bt_pgno_t(bl->bytes), + __bt_uint32_t(bl->bytes + sizeof(pgno_t))); else if (bl->ksize) (void)fprintf(stderr, "%s/", bl->bytes); if (bl->flags & P_BIGDATA) (void)fprintf(stderr, "big data page %lu size %u", - (unsigned long) *(pgno_t *)(void *)(bl->bytes + bl->ksize), - *(uint32_t *)(void *)(bl->bytes + bl->ksize + + (unsigned long) + __bt_pgno_t(bl->bytes + bl->ksize), + __bt_uint32_t(bl->bytes + bl->ksize + sizeof(pgno_t))); else if (bl->dsize) (void)fprintf(stderr, "%.*s", @@ -225,8 +242,8 @@ __bt_dpage(PAGE *h) if (rl->flags & P_BIGDATA) (void)fprintf(stderr, "big data page %lu size %u", - (unsigned long) *(pgno_t *)(void *)rl->bytes, - *(uint32_t *)(void *)(rl->bytes + sizeof(pgno_t))); + (unsigned long) __bt_pgno_t(rl->bytes), + __bt_uint32_t(rl->bytes + sizeof(pgno_t))); else if (rl->dsize) (void)fprintf(stderr, "%.*s", (int)rl->dsize, rl->bytes); diff --git a/lib/libc/db/btree/bt_open.c b/lib/libc/db/btree/bt_open.c index b5f7158a8..2553f16c7 100644 --- a/lib/libc/db/btree/bt_open.c +++ b/lib/libc/db/btree/bt_open.c @@ -1,4 +1,4 @@ -/* $NetBSD: bt_open.c,v 1.24 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: bt_open.c,v 1.26 2012/03/13 21:13:32 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: bt_open.c,v 1.24 2008/09/11 12:58:00 joerg Exp $"); +__RCSID("$NetBSD: bt_open.c,v 1.26 2012/03/13 21:13:32 christos Exp $"); /* * Implementation of btree access method for 4.4BSD. @@ -270,8 +270,7 @@ __bt_open(const char *fname, int flags, mode_t mode, const BTREEINFO *openinfo, b.psize = MINIX_ST_BLKSIZE; } else #endif - b.psize = sb.st_blksize; - + b.psize = sb.st_blksize; if (b.psize < MINPSIZE) b.psize = MINPSIZE; if (b.psize > MAX_PAGE_OFFSET + 1) @@ -313,9 +312,11 @@ __bt_open(const char *fname, int flags, mode_t mode, const BTREEINFO *openinfo, (sizeof(indx_t) + NBLEAFDBT(0, 0)); _DBFIT(temp, indx_t); t->bt_ovflsize = (indx_t)temp; - if (t->bt_ovflsize < NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t)) - t->bt_ovflsize = - NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t); + if (t->bt_ovflsize < NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t)) { + size_t l = NBLEAFDBT(NOVFLSIZE, NOVFLSIZE) + sizeof(indx_t); + _DBFIT(l, indx_t); + t->bt_ovflsize = (indx_t)l; + } /* Initialize the buffer pool. */ if ((t->bt_mp = @@ -400,7 +401,7 @@ static int tmp(void) { sigset_t set, oset; - size_t len; + int len; int fd; char *envtmp; char path[PATH_MAX]; @@ -412,8 +413,10 @@ tmp(void) len = snprintf(path, sizeof(path), "%s/bt.XXXXXX", envtmp ? envtmp : _PATH_TMP); - if (len >= sizeof(path)) + if (len < 0 || (size_t)len >= sizeof(path)) { + errno = ENAMETOOLONG; return -1; + } (void)sigfillset(&set); (void)sigprocmask(SIG_BLOCK, &set, &oset); diff --git a/lib/libc/db/btree/bt_overflow.c b/lib/libc/db/btree/bt_overflow.c index 965480487..54f2e82f3 100644 --- a/lib/libc/db/btree/bt_overflow.c +++ b/lib/libc/db/btree/bt_overflow.c @@ -1,4 +1,4 @@ -/* $NetBSD: bt_overflow.c,v 1.16 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: bt_overflow.c,v 1.18 2012/03/13 21:13:32 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: bt_overflow.c,v 1.16 2008/09/11 12:58:00 joerg Exp $"); +__RCSID("$NetBSD: bt_overflow.c,v 1.18 2012/03/13 21:13:32 christos Exp $"); #include "namespace.h" #include @@ -87,7 +87,7 @@ __ovfl_get(BTREE *t, void *p, size_t *ssz, void **buf, size_t *bufsz) uint32_t sz, nb, plen; size_t temp; - memmove(&pg, p, sizeof(pgno_t)); + memmove(&pg, p, sizeof(pg)); memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(uint32_t)); *ssz = sz; @@ -97,7 +97,7 @@ __ovfl_get(BTREE *t, void *p, size_t *ssz, void **buf, size_t *bufsz) #endif /* Make the buffer bigger as necessary. */ if (*bufsz < sz) { - *buf = (char *)(*buf == NULL ? malloc(sz) : realloc(*buf, sz)); + *buf = (*buf == NULL ? malloc(sz) : realloc(*buf, sz)); if (*buf == NULL) return (RET_ERROR); *bufsz = sz; @@ -155,7 +155,7 @@ __ovfl_put(BTREE *t, const DBT *dbt, pgno_t *pg) p = dbt->data; temp = dbt->size; _DBFIT(temp, uint32_t); - sz = temp; + sz = (uint32_t)temp; for (;; p = (char *)p + plen, last = h) { if ((h = __bt_new(t, &npg)) == NULL) return (RET_ERROR); @@ -200,7 +200,7 @@ __ovfl_delete(BTREE *t, void *p) uint32_t sz, plen; size_t temp; - (void)memmove(&pg, p, sizeof(pgno_t)); + (void)memmove(&pg, p, sizeof(pg)); (void)memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(uint32_t)); #ifdef DEBUG diff --git a/lib/libc/db/btree/bt_put.c b/lib/libc/db/btree/bt_put.c index 37630b819..986d6c184 100644 --- a/lib/libc/db/btree/bt_put.c +++ b/lib/libc/db/btree/bt_put.c @@ -1,4 +1,4 @@ -/* $NetBSD: bt_put.c,v 1.19 2009/02/12 06:40:14 lukem Exp $ */ +/* $NetBSD: bt_put.c,v 1.20 2011/06/26 22:20:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: bt_put.c,v 1.19 2009/02/12 06:40:14 lukem Exp $"); +__RCSID("$NetBSD: bt_put.c,v 1.20 2011/06/26 22:20:31 christos Exp $"); #include "namespace.h" #include @@ -127,7 +127,7 @@ storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) return (RET_ERROR); tkey.data = kb; tkey.size = NOVFLSIZE; - memmove(kb, &pg, sizeof(pgno_t)); + memmove(kb, &pg, sizeof(pg)); memmove(kb + sizeof(pgno_t), &key->size, sizeof(uint32_t)); dflags |= P_BIGKEY; @@ -138,7 +138,7 @@ storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) return (RET_ERROR); tdata.data = db; tdata.size = NOVFLSIZE; - memmove(db, &pg, sizeof(pgno_t)); + memmove(db, &pg, sizeof(pg)); _DBFIT(data->size, uint32_t); temp = (uint32_t)data->size; (void)memmove(db + sizeof(pgno_t), diff --git a/lib/libc/db/btree/bt_split.c b/lib/libc/db/btree/bt_split.c index 8a97501b5..f7356c7e3 100644 --- a/lib/libc/db/btree/bt_split.c +++ b/lib/libc/db/btree/bt_split.c @@ -1,4 +1,4 @@ -/* $NetBSD: bt_split.c,v 1.19 2009/04/22 18:44:06 christos Exp $ */ +/* $NetBSD: bt_split.c,v 1.20 2011/06/20 09:11:17 mrg Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: bt_split.c,v 1.19 2009/04/22 18:44:06 christos Exp $"); +__RCSID("$NetBSD: bt_split.c,v 1.20 2011/06/20 09:11:17 mrg Exp $"); #include "namespace.h" #include @@ -245,10 +245,12 @@ __bt_split(BTREE *t, PAGE *sp, const DBT *key, const DBT *data, int flags, WR_BINTERNAL(dest, nksize ? nksize : bl->ksize, rchild->pgno, bl->flags & P_BIGKEY); memmove(dest, bl->bytes, nksize ? nksize : bl->ksize); - if (bl->flags & P_BIGKEY && - bt_preserve(t, *(pgno_t *)(void *)bl->bytes) == - RET_ERROR) - goto err1; + if (bl->flags & P_BIGKEY) { + pgno_t pgno; + memcpy(&pgno, bl->bytes, sizeof(pgno)); + if (bt_preserve(t, pgno) == RET_ERROR) + goto err1; + } break; case P_RINTERNAL: /* @@ -564,9 +566,12 @@ bt_broot(BTREE *t, PAGE *h, PAGE *l, PAGE *r) * If the key is on an overflow page, mark the overflow chain * so it isn't deleted when the leaf copy of the key is deleted. */ - if (bl->flags & P_BIGKEY && - bt_preserve(t, *(pgno_t *)(void *)bl->bytes) == RET_ERROR) - return (RET_ERROR); + if (bl->flags & P_BIGKEY) { + pgno_t pgno; + memcpy(&pgno, bl->bytes, sizeof(pgno)); + if (bt_preserve(t, pgno) == RET_ERROR) + return (RET_ERROR); + } break; case P_BINTERNAL: bi = GETBINTERNAL(r, 0); diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c index 5e69e4cfe..79cb812d5 100644 --- a/lib/libc/db/hash/hash.c +++ b/lib/libc/db/hash/hash.c @@ -1,4 +1,4 @@ -/* $NetBSD: hash.c,v 1.31 2009/02/12 06:35:54 lukem Exp $ */ +/* $NetBSD: hash.c,v 1.32 2012/03/13 21:13:32 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: hash.c,v 1.31 2009/02/12 06:35:54 lukem Exp $"); +__RCSID("$NetBSD: hash.c,v 1.32 2012/03/13 21:13:32 christos Exp $"); #include "namespace.h" #include @@ -212,7 +212,7 @@ __hash_open(const char *file, int flags, mode_t mode, const HASHINFO *info, dbp->sync = hash_sync; dbp->type = DB_HASH; -#ifdef DEBUG +#ifdef DEBUG1 (void)fprintf(stderr, "%s\n%s%p\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%x\n%s%x\n%s%d\n%s%d\n", "init_htab:", @@ -309,8 +309,7 @@ init_hash(HTAB *hashp, const char *file, const HASHINFO *info) hashp->BSIZE = MIN(MINIX_ST_BLKSIZE, MAX_BSIZE); } else #endif - hashp->BSIZE = MIN(statbuf.st_blksize, MAX_BSIZE); - + hashp->BSIZE = MIN(statbuf.st_blksize, MAX_BSIZE); hashp->BSHIFT = __log2((uint32_t)hashp->BSIZE); } @@ -822,7 +821,9 @@ __expand_table(HTAB *hashp) dirsize = hashp->DSIZE * sizeof(SEGMENT *); if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1)) return (-1); - hashp->DSIZE = dirsize << 1; + dirsize <<= 1; + _DBFIT(dirsize, uint32_t); + hashp->DSIZE = (uint32_t)dirsize; } if ((hashp->dir[new_segnum] = calloc((size_t)hashp->SGSIZE, sizeof(SEGMENT))) == NULL) diff --git a/lib/libc/db/hash/hash_bigkey.c b/lib/libc/db/hash/hash_bigkey.c index 5c6fc9b18..eba679d7f 100644 --- a/lib/libc/db/hash/hash_bigkey.c +++ b/lib/libc/db/hash/hash_bigkey.c @@ -1,4 +1,4 @@ -/* $NetBSD: hash_bigkey.c,v 1.23 2009/02/12 06:33:13 lukem Exp $ */ +/* $NetBSD: hash_bigkey.c,v 1.24 2012/03/13 21:13:32 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: hash_bigkey.c,v 1.23 2009/02/12 06:33:13 lukem Exp $"); +__RCSID("$NetBSD: hash_bigkey.c,v 1.24 2012/03/13 21:13:32 christos Exp $"); /* * PACKAGE: hash @@ -107,7 +107,9 @@ __big_insert(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) _DBFIT(temp, uint16_t); space = (uint16_t)temp; while (key_size) { - move_bytes = MIN(space, key_size); + size_t kspace = MIN(space, key_size); + _DBFIT(kspace, uint16_t); + move_bytes = (uint16_t)kspace; off = OFFSET(p) - move_bytes; memmove(cp + off, key_data, (size_t)move_bytes); key_size -= move_bytes; @@ -127,7 +129,9 @@ __big_insert(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) if (!key_size) { space = FREESPACE(p); if (space) { - move_bytes = MIN(space, val_size); + size_t vspace = MIN(space, val_size); + _DBFIT(vspace, uint16_t); + move_bytes = (uint16_t)vspace; /* * If the data would fit exactly in the * remaining space, we must overflow it to the @@ -163,7 +167,9 @@ __big_insert(HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val) _DBFIT(temp, uint16_t); space = (uint16_t)temp; while (val_size) { - move_bytes = MIN(space, val_size); + size_t vspace = MIN(space, val_size); + _DBFIT(vspace, uint16_t); + move_bytes = (uint16_t)vspace; /* * Here's the hack to make sure that if the data ends on the * same page as the key ends, FREESPACE is at least one. diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index e79dfd9bf..65ca97834 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -1,4 +1,4 @@ -/* $NetBSD: hash_page.c,v 1.23 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: hash_page.c,v 1.25 2012/03/13 21:13:33 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: hash_page.c,v 1.23 2008/09/11 12:58:00 joerg Exp $"); +__RCSID("$NetBSD: hash_page.c,v 1.25 2012/03/13 21:13:33 christos Exp $"); /* * PACKAGE: hashing @@ -85,7 +85,7 @@ static int ugly_split(HTAB *, uint32_t, BUFHEAD *, BUFHEAD *, int, int); #define PAGE_INIT(P) { \ ((uint16_t *)(void *)(P))[0] = 0; \ temp = 3 * sizeof(uint16_t); \ - _DIAGASSERT(hashp->BSIZE >= temp); \ + _DIAGASSERT((size_t)hashp->BSIZE >= temp); \ ((uint16_t *)(void *)(P))[1] = (uint16_t)(hashp->BSIZE - temp); \ ((uint16_t *)(void *)(P))[2] = hashp->BSIZE; \ } @@ -869,15 +869,19 @@ open_temp(HTAB *hashp) sigset_t set, oset; char *envtmp; char namestr[PATH_MAX]; + int len; if (issetugid()) envtmp = NULL; else envtmp = getenv("TMPDIR"); - if (-1 == snprintf(namestr, sizeof(namestr), "%s/_hashXXXXXX", - envtmp ? envtmp : _PATH_TMP)) + len = snprintf(namestr, sizeof(namestr), "%s/_hashXXXXXX", + envtmp ? envtmp : _PATH_TMP); + if (len < 0 || (size_t)len >= sizeof(namestr)) { + errno = ENAMETOOLONG; return -1; + } /* Block signals; make sure file goes away at process exit. */ (void)sigfillset(&set); diff --git a/lib/libc/db/hash/ndbmdatum.c b/lib/libc/db/hash/ndbmdatum.c index 904120e6d..2ae7a2790 100644 --- a/lib/libc/db/hash/ndbmdatum.c +++ b/lib/libc/db/hash/ndbmdatum.c @@ -1,4 +1,4 @@ -/* $NetBSD: ndbmdatum.c,v 1.4 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: ndbmdatum.c,v 1.5 2012/03/13 21:13:33 christos Exp $ */ /* from: NetBSD: ndbm.c,v 1.18 2004/04/27 20:03:45 kleink Exp */ /*- @@ -38,7 +38,7 @@ #endif #include -__RCSID("$NetBSD: ndbmdatum.c,v 1.4 2008/09/11 12:58:00 joerg Exp $"); +__RCSID("$NetBSD: ndbmdatum.c,v 1.5 2012/03/13 21:13:33 christos Exp $"); /* * This package provides a dbm compatible interface to the new hashing @@ -54,6 +54,9 @@ __RCSID("$NetBSD: ndbmdatum.c,v 1.4 2008/09/11 12:58:00 joerg Exp $"); #include #include "hash.h" +#ifndef datum_truncate +#define datum_truncate(a) (a) +#endif /* * Returns: * DATUM on success @@ -74,7 +77,7 @@ dbm_fetch(DBM *db, datum key) dbtretdata.size = 0; } retdata.dptr = dbtretdata.data; - retdata.dsize = dbtretdata.size; + retdata.dsize = datum_truncate(dbtretdata.size); return (retdata); } @@ -94,7 +97,7 @@ dbm_firstkey(DBM *db) if (status) dbtretkey.data = NULL; retkey.dptr = dbtretkey.data; - retkey.dsize = dbtretkey.size; + retkey.dsize = datum_truncate(dbtretkey.size); return (retkey); } @@ -114,7 +117,7 @@ dbm_nextkey(DBM *db) if (status) dbtretkey.data = NULL; retkey.dptr = dbtretkey.data; - retkey.dsize = dbtretkey.size; + retkey.dsize = datum_truncate(dbtretkey.size); return (retkey); } diff --git a/lib/libc/db/man/btree.3 b/lib/libc/db/man/btree.3 index 193638696..c226251c2 100644 --- a/lib/libc/db/man/btree.3 +++ b/lib/libc/db/man/btree.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: btree.3,v 1.12 2010/03/22 19:30:53 joerg Exp $ +.\" $NetBSD: btree.3,v 1.13 2012/10/13 15:28:33 njoly Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -225,7 +225,6 @@ for any of the errors specified for the library routine .Xr hash 3 , .Xr mpool 3 , .Xr recno 3 -.Pp .Rs .%T "The Ubiquitous B-tree" .%A "Douglas Comer" diff --git a/lib/libc/db/recno/rec_open.c b/lib/libc/db/recno/rec_open.c index ff1852e40..fa5237572 100644 --- a/lib/libc/db/recno/rec_open.c +++ b/lib/libc/db/recno/rec_open.c @@ -1,4 +1,4 @@ -/* $NetBSD: rec_open.c,v 1.17 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: rec_open.c,v 1.19 2011/06/26 22:27:14 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #endif #include -__RCSID("$NetBSD: rec_open.c,v 1.17 2008/09/11 12:58:00 joerg Exp $"); +__RCSID("$NetBSD: rec_open.c,v 1.19 2011/06/26 22:27:14 christos Exp $"); #include "namespace.h" #include @@ -70,10 +70,15 @@ __rec_open(const char *fname, int flags, mode_t mode, const RECNOINFO *openinfo, dbp = NULL; /* Open the user's file -- if this fails, we're done. */ if (fname != NULL) { - if ((rfd = open(fname, flags, mode)) == -1) - return (NULL); +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + if ((rfd = open(fname, flags | O_CLOEXEC, mode)) == -1) + return NULL; +#if O_CLOEXEC == 0 if (fcntl(rfd, F_SETFD, FD_CLOEXEC) == -1) goto err; +#endif } /* Create a btree in memory (backed by disk). */ diff --git a/lib/libc/db/recno/rec_put.c b/lib/libc/db/recno/rec_put.c index 7c1181c64..6245d55e0 100644 --- a/lib/libc/db/recno/rec_put.c +++ b/lib/libc/db/recno/rec_put.c @@ -1,4 +1,4 @@ -/* $NetBSD: rec_put.c,v 1.17 2008/09/11 12:58:00 joerg Exp $ */ +/* $NetBSD: rec_put.c,v 1.19 2011/06/26 22:18:16 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: rec_put.c,v 1.17 2008/09/11 12:58:00 joerg Exp $"); +__RCSID("$NetBSD: rec_put.c,v 1.19 2011/06/26 22:18:16 christos Exp $"); #include "namespace.h" #include @@ -167,8 +167,14 @@ einval: errno = EINVAL; if ((status = __rec_iput(t, nrec - 1, &fdata, flags)) != RET_SUCCESS) return (status); - if (flags == R_SETCURSOR) + switch (flags) { + case R_IAFTER: + nrec++; + break; + case R_SETCURSOR: t->bt_cursor.rcursor = nrec; + break; + } F_SET(t, R_MODIFIED); return (__rec_ret(t, NULL, nrec, key, NULL)); @@ -208,7 +214,7 @@ __rec_iput(BTREE *t, recno_t nrec, const DBT *data, u_int flags) return (RET_ERROR); tdata.data = db; tdata.size = NOVFLSIZE; - *(pgno_t *)(void *)db = pg; + memcpy(db, &pg, sizeof(pg)); _DBFIT(data->size, uint32_t); *(uint32_t *)(void *)(db + sizeof(pgno_t)) = (uint32_t)data->size; diff --git a/lib/libc/dlfcn/dlfcn_elf.c b/lib/libc/dlfcn/dlfcn_elf.c index 1f9bb8daf..8543d2731 100644 --- a/lib/libc/dlfcn/dlfcn_elf.c +++ b/lib/libc/dlfcn/dlfcn_elf.c @@ -1,4 +1,4 @@ -/* $NetBSD: dlfcn_elf.c,v 1.7 2010/10/16 10:27:07 skrll Exp $ */ +/* $NetBSD: dlfcn_elf.c,v 1.13 2012/06/24 15:26:03 christos Exp $ */ /* * Copyright (c) 2000 Takuya SHIOZAKI @@ -27,10 +27,16 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: dlfcn_elf.c,v 1.7 2010/10/16 10:27:07 skrll Exp $"); +__RCSID("$NetBSD: dlfcn_elf.c,v 1.13 2012/06/24 15:26:03 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" +#include +#include +#include +#include +#include +#include #undef dlopen #undef dlclose @@ -42,6 +48,7 @@ __RCSID("$NetBSD: dlfcn_elf.c,v 1.7 2010/10/16 10:27:07 skrll Exp $"); #define dlopen ___dlopen #define dlclose ___dlclose #define dlsym ___dlsym +#define dlvsym ___dlvsym #define dlerror ___dlerror #define dladdr ___dladdr #define dlinfo ___dlinfo @@ -54,6 +61,7 @@ __RCSID("$NetBSD: dlfcn_elf.c,v 1.7 2010/10/16 10:27:07 skrll Exp $"); __weak_alias(dlopen,___dlopen) __weak_alias(dlclose,___dlclose) __weak_alias(dlsym,___dlsym) +__weak_alias(dlvsym,___dlvsym) __weak_alias(dlerror,___dlerror) __weak_alias(dladdr,___dladdr) __weak_alias(dlinfo,___dlinfo) @@ -62,6 +70,7 @@ __weak_alias(dl_iterate_phdr,___dl_iterate_phdr) __weak_alias(__dlopen,___dlopen) __weak_alias(__dlclose,___dlclose) __weak_alias(__dlsym,___dlsym) +__weak_alias(__dlvsym,___dlvsym) __weak_alias(__dlerror,___dlerror) __weak_alias(__dladdr,___dladdr) __weak_alias(__dlinfo,___dlinfo) @@ -104,9 +113,17 @@ dlsym(void *handle, const char *name) return NULL; } +/*ARGSUSED*/ +void * +dlvsym(void *handle, const char *name, const char *version) +{ + + return NULL; +} + /*ARGSUSED*/ __aconst char * -dlerror() +dlerror(void) { return dlfcn_error; @@ -128,11 +145,61 @@ dlinfo(void *handle, int req, void *v) return -1; } +static const char *dlpi_name; +static Elf_Addr dlpi_addr; +static const Elf_Phdr *dlpi_phdr; +static Elf_Half dlpi_phnum; + +static void +dl_iterate_phdr_setup(void) +{ + const AuxInfo *aux; + + _DIAGASSERT(_dlauxinfo() != NULL); + + for (aux = _dlauxinfo(); aux->a_type != AT_NULL; ++aux) { + switch (aux->a_type) { + case AT_BASE: + dlpi_addr = aux->a_v; + break; + case AT_PHDR: + dlpi_phdr = (void *)aux->a_v; + break; + case AT_PHNUM: + _DIAGASSERT(__type_fit(Elf_Half, aux->a_v)); + dlpi_phnum = (Elf_Half)aux->a_v; + break; + case AT_SUN_EXECNAME: + dlpi_name = (void *)aux->a_v; + break; + } + } +} + /*ARGSUSED*/ int dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *), void *data) { - - return 0; + static bool setup_done; + struct dl_phdr_info phdr_info; + + if (!setup_done) { + /* + * This can race on the first call to dl_iterate_phdr. + * dl_iterate_phdr_setup only touches field of pointer size + * and smaller and such stores are atomic. + */ + dl_iterate_phdr_setup(); + membar_producer(); + setup_done = true; + } + + memset(&phdr_info, 0, sizeof(phdr_info)); + phdr_info.dlpi_addr = dlpi_addr; + phdr_info.dlpi_phdr = dlpi_phdr; + phdr_info.dlpi_phnum = dlpi_phnum; + phdr_info.dlpi_name = dlpi_name; + + return callback(&phdr_info, sizeof(phdr_info), data); } diff --git a/lib/libc/gdtoa/README b/lib/libc/gdtoa/README index 0c8a8f8a8..0c034f1bf 100644 --- a/lib/libc/gdtoa/README +++ b/lib/libc/gdtoa/README @@ -1,5 +1,3 @@ -$NetBSD: README,v 1.1.1.1 2006/01/25 15:18:40 kleink Exp $ - This directory contains source for a library of binary -> decimal and decimal -> binary conversion routines, for single-, double-, and extended-precision IEEE binary floating-point arithmetic, and @@ -58,7 +56,9 @@ two letters: whose sum is the desired value For decimal -> binary conversions, there are three families of -helper routines: one for round-nearest: +helper routines: one for round-nearest (or the current rounding +mode on IEEE-arithmetic systems that provide the C99 fegetround() +function, if compiled with -DHonor_FLT_ROUNDS): strtof strtod @@ -193,6 +193,9 @@ in the buffer, if the buffer was long enough, or 0. Other forms of conversion are easily done with the help of gdtoa(), such as %e or %f style and conversions with direction of rounding specified (so that, if desired, the decimal value is either >= or <= the binary value). +On IEEE-arithmetic systems that provide the C99 fegetround() function, +if compiled with -DHonor_FLT_ROUNDS, these routines honor the current +rounding mode. For an example of more general conversions based on dtoa(), see netlib's "printf.c from ampl/solvers". @@ -334,5 +337,28 @@ Compiling g__fmt.c, strtod.c, and strtodg.c with -DUSE_LOCALE causes the decimal-point character to be taken from the current locale; otherwise it is '.'. +Source files dtoa.c and strtod.c in this directory are derived from +netlib's "dtoa.c from fp" and are meant to function equivalently. +When compiled with Honor_FLT_ROUNDS #defined (on systems that provide +FLT_ROUNDS and fegetround() as specified in the C99 standard), they +honor the current rounding mode. Because FLT_ROUNDS is buggy on some +(Linux) systems -- not reflecting calls on fesetround(), as the C99 +standard says it should -- when Honor_FLT_ROUNDS is #defined, the +current rounding mode is obtained from fegetround() rather than from +FLT_ROUNDS, unless Trust_FLT_ROUNDS is also #defined. + +Compile with -DUSE_LOCALE to use the current locale; otherwise +decimal points are assumed to be '.'. With -DUSE_LOCALE, unless +you also compile with -DNO_LOCALE_CACHE, the details about the +current "decimal point" character string are cached and assumed not +to change during the program's execution. + +On machines with a 64-bit long double and perhaps a 113-bit "quad" +type, you can invoke "make Printf" to add Printf (and variants, such +as Fprintf) to gdtoa.a. These are analogs, declared in stdio1.h, of +printf and fprintf, etc. in which %La, %Le, %Lf, and %Lg are for long +double and (if appropriate) %Lqa, %Lqe, %Lqf, and %Lqg are for quad +precision printing. + Please send comments to David M. Gay (dmg at acm dot org, with " at " changed at "@" and " dot " changed to "."). diff --git a/lib/libc/gdtoa/arithchk.c b/lib/libc/gdtoa/arithchk.c index e36cdbf49..305aec415 100644 --- a/lib/libc/gdtoa/arithchk.c +++ b/lib/libc/gdtoa/arithchk.c @@ -1,4 +1,4 @@ -/* $NetBSD: arithchk.c,v 1.3 2010/01/17 23:06:31 wiz Exp $ */ +/* $NetBSD: arithchk.c,v 1.4 2012/06/24 15:26:03 christos Exp $ */ /**************************************************************** Copyright (C) 1997, 1998 Lucent Technologies @@ -28,22 +28,22 @@ THIS SOFTWARE. #include - static int dalign; - typedef struct +static int dalign; +typedef struct Akind { char *name; int kind; } Akind; - static Akind +static Akind IEEE_LITTLE_ENDIAN = { "IEEE_LITTLE_ENDIAN", 1 }, IEEE_BIG_ENDIAN = { "IEEE_BIG_ENDIAN", 2 }, IBM = { "IBM", 3 }, VAX = { "VAX", 4 }, CRAY = { "CRAY", 5}; - static Akind * -Lcheck() +static Akind * +Lcheck(void) { union { double d; @@ -69,8 +69,8 @@ Lcheck() return 0; } - static Akind * -icheck() +static Akind * +icheck(void) { union { double d; @@ -98,8 +98,8 @@ icheck() char *emptyfmt = ""; /* avoid possible warning message with printf("") */ - static Akind * -ccheck() +static Akind * +ccheck(void) { union { double d; @@ -119,8 +119,8 @@ ccheck() return 0; } - static int -fzcheck() +static int +fzcheck(void) { double a, b; int i; @@ -138,8 +138,8 @@ fzcheck() return b == 0.; } - int -main() +int +main(void) { Akind *a = 0; int Ldef = 0; diff --git a/lib/libc/gdtoa/dtoa.c b/lib/libc/gdtoa/dtoa.c index ede9cb1d3..66fe35cdc 100644 --- a/lib/libc/gdtoa/dtoa.c +++ b/lib/libc/gdtoa/dtoa.c @@ -1,4 +1,4 @@ -/* $NetBSD: dtoa.c,v 1.5 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: dtoa.c,v 1.10 2012/05/16 17:48:59 alnsn Exp $ */ /**************************************************************** @@ -68,7 +68,6 @@ THIS SOFTWARE. */ #ifdef Honor_FLT_ROUNDS -#define Rounding rounding #undef Check_FLT_ROUNDS #define Check_FLT_ROUNDS #else @@ -78,10 +77,10 @@ THIS SOFTWARE. char * dtoa #ifdef KR_headers - (d, mode, ndigits, decpt, sign, rve) - double d; int mode, ndigits, *decpt, *sign; char **rve; + (d0, mode, ndigits, decpt, sign, rve) + double d0; int mode, ndigits, *decpt, *sign; char **rve; #else - (double d, int mode, int ndigits, int *decpt, int *sign, char **rve) + (double d0, int mode, int ndigits, int *decpt, int *sign, char **rve) #endif { /* Arguments ndigits, decpt, sign are similar to those @@ -129,14 +128,25 @@ dtoa #endif Bigint *b, *b1, *delta, *mhi, *S; Bigint *mlo = NULL; /* pacify gcc */ - double d2, ds, eps; + U d, d2, eps; + double ds; char *s, *s0; -#ifdef Honor_FLT_ROUNDS - int rounding; -#endif #ifdef SET_INEXACT int inexact, oldinexact; #endif +#ifdef Honor_FLT_ROUNDS /*{*/ + int Rounding; +#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */ + Rounding = Flt_Rounds; +#else /*}{*/ + Rounding = 1; + switch(fegetround()) { + case FE_TOWARDZERO: Rounding = 0; break; + case FE_UPWARD: Rounding = 2; break; + case FE_DOWNWARD: Rounding = 3; + } +#endif /*}}*/ +#endif /*}*/ #ifndef MULTIPLE_THREADS if (dtoa_result) { @@ -144,35 +154,35 @@ dtoa dtoa_result = 0; } #endif - - if (word0(d) & Sign_bit) { + d.d = d0; + if (word0(&d) & Sign_bit) { /* set sign for everything, including 0's and NaNs */ *sign = 1; - word0(d) &= ~Sign_bit; /* clear sign bit */ + word0(&d) &= ~Sign_bit; /* clear sign bit */ } else *sign = 0; #if defined(IEEE_Arith) + defined(VAX) #ifdef IEEE_Arith - if ((word0(d) & Exp_mask) == Exp_mask) + if ((word0(&d) & Exp_mask) == Exp_mask) #else - if (word0(d) == 0x8000) + if (word0(&d) == 0x8000) #endif { /* Infinity or NaN */ *decpt = 9999; #ifdef IEEE_Arith - if (!word1(d) && !(word0(d) & 0xfffff)) + if (!word1(&d) && !(word0(&d) & 0xfffff)) return nrv_alloc("Infinity", rve, 8); #endif return nrv_alloc("NaN", rve, 3); } #endif #ifdef IBM - dval(d) += 0; /* normalize */ + dval(&d) += 0; /* normalize */ #endif - if (!dval(d)) { + if (!dval(&d)) { *decpt = 1; return nrv_alloc("0", rve, 1); } @@ -182,37 +192,37 @@ dtoa inexact = 1; #endif #ifdef Honor_FLT_ROUNDS - if ((rounding = Flt_Rounds) >= 2) { + if (Rounding >= 2) { if (*sign) - rounding = rounding == 2 ? 0 : 2; + Rounding = Rounding == 2 ? 0 : 2; else - if (rounding != 2) - rounding = 0; + if (Rounding != 2) + Rounding = 0; } #endif - b = d2b(dval(d), &be, &bbits); + b = d2b(dval(&d), &be, &bbits); if (b == NULL) return NULL; #ifdef Sudden_Underflow - i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); + i = (int)(word0(&d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); #else - if (( i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)) )!=0) { + if (( i = (int)(word0(&d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)) )!=0) { #endif - dval(d2) = dval(d); - word0(d2) &= Frac_mask1; - word0(d2) |= Exp_11; + dval(&d2) = dval(&d); + word0(&d2) &= Frac_mask1; + word0(&d2) |= Exp_11; #ifdef IBM - if (( j = 11 - hi0bits(word0(d2) & Frac_mask) )!=0) - dval(d2) /= 1 << j; + if (( j = 11 - hi0bits(word0(&d2) & Frac_mask) )!=0) + dval(&d2) /= 1 << j; #endif /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 * log10(x) = log(x) / log(10) * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) - * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) + * log10(&d) = (i-Bias)*log(2)/log(10) + log10(&d2) * - * This suggests computing an approximation k to log10(d) by + * This suggests computing an approximation k to log10(&d) by * * k = (i - Bias)*0.301029995663981 * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); @@ -241,21 +251,21 @@ dtoa /* d is denormalized */ i = bbits + be + (Bias + (P-1) - 1); - x = i > 32 ? word0(d) << (64 - i) | word1(d) >> (i - 32) - : word1(d) << (32 - i); - dval(d2) = x; - word0(d2) -= 31*Exp_msk1; /* adjust exponent */ + x = i > 32 ? word0(&d) << (64 - i) | word1(&d) >> (i - 32) + : word1(&d) << (32 - i); + dval(&d2) = x; + word0(&d2) -= 31*Exp_msk1; /* adjust exponent */ i -= (Bias + (P-1) - 1) + 1; denorm = 1; } #endif - ds = (dval(d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; + ds = (dval(&d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; k = (int)ds; if (ds < 0. && ds != k) k--; /* want k = floor(ds) */ k_check = 1; if (k >= 0 && k <= Ten_pmax) { - if (dval(d) < tens[k]) + if (dval(&d) < tens[k]) k--; k_check = 0; } @@ -294,10 +304,11 @@ dtoa try_quick = 0; } leftright = 1; + ilim = ilim1 = -1; /* Values for cases 0 and 1; done here to */ + /* silence erroneous "gcc -Wall" warning. */ switch(mode) { case 0: case 1: - ilim = ilim1 = -1; i = 18; ndigits = 0; break; @@ -324,7 +335,7 @@ dtoa return NULL; #ifdef Honor_FLT_ROUNDS - if (mode > 1 && rounding != 1) + if (mode > 1 && Rounding != 1) leftright = 0; #endif @@ -333,7 +344,7 @@ dtoa /* Try to get by with floating-point arithmetic. */ i = 0; - dval(d2) = dval(d); + dval(&d2) = dval(&d); k0 = k; ilim0 = ilim; ieps = 2; /* conservative */ @@ -343,7 +354,7 @@ dtoa if (j & Bletch) { /* prevent overflows */ j &= Bletch - 1; - dval(d) /= bigtens[n_bigtens-1]; + dval(&d) /= bigtens[n_bigtens-1]; ieps++; } for(; j; j = (unsigned int)j >> 1, i++) @@ -351,32 +362,32 @@ dtoa ieps++; ds *= bigtens[i]; } - dval(d) /= ds; + dval(&d) /= ds; } else if (( jj1 = -k )!=0) { - dval(d) *= tens[jj1 & 0xf]; + dval(&d) *= tens[jj1 & 0xf]; for(j = jj1 >> 4; j; j >>= 1, i++) if (j & 1) { ieps++; - dval(d) *= bigtens[i]; + dval(&d) *= bigtens[i]; } } - if (k_check && dval(d) < 1. && ilim > 0) { + if (k_check && dval(&d) < 1. && ilim > 0) { if (ilim1 <= 0) goto fast_failed; ilim = ilim1; k--; - dval(d) *= 10.; + dval(&d) *= 10.; ieps++; } - dval(eps) = ieps*dval(d) + 7.; - word0(eps) -= (P-1)*Exp_msk1; + dval(&eps) = ieps*dval(&d) + 7.; + word0(&eps) -= (P-1)*Exp_msk1; if (ilim == 0) { S = mhi = 0; - dval(d) -= 5.; - if (dval(d) > dval(eps)) + dval(&d) -= 5.; + if (dval(&d) > dval(&eps)) goto one_digit; - if (dval(d) < -dval(eps)) + if (dval(&d) < -dval(&eps)) goto no_digits; goto fast_failed; } @@ -385,34 +396,34 @@ dtoa /* Use Steele & White method of only * generating digits needed. */ - dval(eps) = 0.5/tens[ilim-1] - dval(eps); + dval(&eps) = 0.5/tens[ilim-1] - dval(&eps); for(i = 0;;) { - L = dval(d); - dval(d) -= L; + L = dval(&d); + dval(&d) -= L; *s++ = '0' + (int)L; - if (dval(d) < dval(eps)) + if (dval(&d) < dval(&eps)) goto ret1; - if (1. - dval(d) < dval(eps)) + if (1. - dval(&d) < dval(&eps)) goto bump_up; if (++i >= ilim) break; - dval(eps) *= 10.; - dval(d) *= 10.; + dval(&eps) *= 10.; + dval(&d) *= 10.; } } else { #endif /* Generate ilim digits, then fix them up. */ - dval(eps) *= tens[ilim-1]; - for(i = 1;; i++, dval(d) *= 10.) { - L = (Long)(dval(d)); - if (!(dval(d) -= L)) + dval(&eps) *= tens[ilim-1]; + for(i = 1;; i++, dval(&d) *= 10.) { + L = (Long)(dval(&d)); + if (!(dval(&d) -= L)) ilim = i; *s++ = '0' + (int)L; if (i == ilim) { - if (dval(d) > 0.5 + dval(eps)) + if (dval(&d) > 0.5 + dval(&eps)) goto bump_up; - else if (dval(d) < 0.5 - dval(eps)) { + else if (dval(&d) < 0.5 - dval(&eps)) { while(*--s == '0'); s++; goto ret1; @@ -425,7 +436,7 @@ dtoa #endif fast_failed: s = s0; - dval(d) = dval(d2); + dval(&d) = dval(&d2); k = k0; ilim = ilim0; } @@ -437,22 +448,22 @@ dtoa ds = tens[k]; if (ndigits < 0 && ilim <= 0) { S = mhi = 0; - if (ilim < 0 || dval(d) <= 5*ds) + if (ilim < 0 || dval(&d) <= 5*ds) goto no_digits; goto one_digit; } - for(i = 1;; i++, dval(d) *= 10.) { - L = (Long)(dval(d) / ds); - dval(d) -= L*ds; + for(i = 1;; i++, dval(&d) *= 10.) { + L = (Long)(dval(&d) / ds); + dval(&d) -= L*ds; #ifdef Check_FLT_ROUNDS /* If FLT_ROUNDS == 2, L will usually be high by 1 */ - if (dval(d) < 0) { + if (dval(&d) < 0) { L--; - dval(d) += ds; + dval(&d) += ds; } #endif *s++ = '0' + (int)L; - if (!dval(d)) { + if (!dval(&d)) { #ifdef SET_INEXACT inexact = 0; #endif @@ -461,13 +472,18 @@ dtoa if (i == ilim) { #ifdef Honor_FLT_ROUNDS if (mode > 1) - switch(rounding) { + switch(Rounding) { case 0: goto ret1; case 2: goto bump_up; } #endif - dval(d) += dval(d); - if (dval(d) > ds || (dval(d) == ds && L & 1)) { + dval(&d) += dval(&d); +#ifdef ROUND_BIASED + if (dval(&d) >= ds) +#else + if (dval(&d) > ds || (dval(&d) == ds && L & 1)) +#endif + { bump_up: while(*--s == '9') if (s == s0) { @@ -520,15 +536,17 @@ dtoa Bfree(b); b = b1; } - if (( j = b5 - m5 )!=0) + if (( j = b5 - m5 )!=0) { b = pow5mult(b, j); if (b == NULL) return NULL; + } } - else + else { b = pow5mult(b, b5); if (b == NULL) return NULL; + } } S = i2b(1); if (S == NULL) @@ -537,19 +555,19 @@ dtoa S = pow5mult(S, s5); if (S == NULL) return NULL; - } + } /* Check for special case that d is a normalized power of 2. */ spec_case = 0; if ((mode < 2 || leftright) #ifdef Honor_FLT_ROUNDS - && rounding == 1 + && Rounding == 1 #endif ) { - if (!word1(d) && !(word0(d) & Bndry_mask) + if (!word1(&d) && !(word0(&d) & Bndry_mask) #ifndef Sudden_Underflow - && word0(d) & (Exp_mask & ~Exp_msk1) + && word0(&d) & (Exp_mask & ~Exp_msk1) #endif ) { /* The special case */ @@ -589,12 +607,12 @@ dtoa b = lshift(b, b2); if (b == NULL) return NULL; - } + } if (s2 > 0) { S = lshift(S, s2); if (S == NULL) return NULL; - } + } if (k_check) { if (cmp(b,S) < 0) { k--; @@ -605,7 +623,7 @@ dtoa mhi = multadd(mhi, 10, 0); if (mhi == NULL) return NULL; - } + } ilim = ilim1; } } @@ -626,7 +644,7 @@ dtoa mhi = lshift(mhi, m2); if (mhi == NULL) return NULL; - } + } /* Compute mlo -- check for special case * that d is a normalized power of 2. @@ -655,9 +673,9 @@ dtoa jj1 = delta->sign ? 1 : cmp(b, delta); Bfree(delta); #ifndef ROUND_BIASED - if (jj1 == 0 && mode != 1 && !(word1(d) & 1) + if (jj1 == 0 && mode != 1 && !(word1(&d) & 1) #ifdef Honor_FLT_ROUNDS - && rounding >= 1 + && Rounding >= 1 #endif ) { if (dig == '9') @@ -674,7 +692,7 @@ dtoa #endif if (j < 0 || (j == 0 && mode != 1 #ifndef ROUND_BIASED - && !(word1(d) & 1) + && !(word1(&d) & 1) #endif )) { if (!b->x[0] && b->wds <= 1) { @@ -685,7 +703,7 @@ dtoa } #ifdef Honor_FLT_ROUNDS if (mode > 1) - switch(rounding) { + switch(Rounding) { case 0: goto accept_dig; case 2: goto keep_dig; } @@ -695,7 +713,11 @@ dtoa if (b == NULL) return NULL; jj1 = cmp(b, S); +#ifdef ROUND_BIASED + if (jj1 >= 0 /*)*/ +#else if ((jj1 > 0 || (jj1 == 0 && dig & 1)) +#endif && dig++ == '9') goto round_9_up; } @@ -705,7 +727,7 @@ dtoa } if (jj1 > 0) { #ifdef Honor_FLT_ROUNDS - if (!rounding) + if (!Rounding) goto accept_dig; #endif if (dig == '9') { /* possible if i == 1 */ @@ -759,14 +781,19 @@ dtoa /* Round off last digit */ #ifdef Honor_FLT_ROUNDS - switch(rounding) { + switch(Rounding) { case 0: goto trimzeros; case 2: goto roundoff; } #endif b = lshift(b, 1); j = cmp(b, S); - if (j > 0 || (j == 0 && dig & 1)) { +#ifdef ROUND_BIASED + if (j >= 0) +#else + if (j > 0 || (j == 0 && dig & 1)) +#endif + { roundoff: while(*--s == '9') if (s == s0) { @@ -794,9 +821,9 @@ dtoa #ifdef SET_INEXACT if (inexact) { if (!oldinexact) { - word0(d) = Exp_1 + (70 << Exp_shift); - word1(d) = 0; - dval(d) += 1.; + word0(&d) = Exp_1 + (70 << Exp_shift); + word1(&d) = 0; + dval(&d) += 1.; } } else if (!oldinexact) diff --git a/lib/libc/gdtoa/g_Qfmt.c b/lib/libc/gdtoa/g_Qfmt.c index 83a204179..f9291affe 100644 --- a/lib/libc/gdtoa/g_Qfmt.c +++ b/lib/libc/gdtoa/g_Qfmt.c @@ -1,4 +1,4 @@ -/* $NetBSD: g_Qfmt.c,v 1.3 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: g_Qfmt.c,v 1.4 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -53,15 +53,20 @@ THIS SOFTWARE. char* #ifdef KR_headers -g_Qfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; unsigned bufsize; +g_Qfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; size_t bufsize; #else -g_Qfmt(char *buf, void *V, int ndig, unsigned bufsize) +g_Qfmt(char *buf, void *V, int ndig, size_t bufsize) #endif { - static FPI fpi = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, 0 }; + static FPI fpi0 = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, 0 }; char *b, *s, *se; ULong bits[4], *L, sign; int decpt, ex, i, mode; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif if (ndig < 0) ndig = 0; @@ -111,8 +116,8 @@ g_Qfmt(char *buf, void *V, int ndig, unsigned bufsize) return 0; mode = 0; } - s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se); if (s == NULL) return NULL; - return g__fmt(buf, s, se, decpt, sign); + return g__fmt(buf, s, se, decpt, sign, bufsize); } diff --git a/lib/libc/gdtoa/g__fmt.c b/lib/libc/gdtoa/g__fmt.c index de85452b5..052978368 100644 --- a/lib/libc/gdtoa/g__fmt.c +++ b/lib/libc/gdtoa/g__fmt.c @@ -1,5 +1,3 @@ -/* $NetBSD: g__fmt.c,v 1.1.1.1 2006/01/25 15:18:41 kleink Exp $ */ - /**************************************************************** The author of this software is David M. Gay. @@ -39,24 +37,51 @@ THIS SOFTWARE. char * #ifdef KR_headers -g__fmt(b, s, se, decpt, sign) char *b; char *s; char *se; int decpt; ULong sign; +g__fmt(b, s, se, decpt, sign, blen) char *b; char *s; char *se; int decpt; ULong sign; size_t blen; #else -g__fmt(char *b, char *s, char *se, int decpt, ULong sign) +g__fmt(char *b, char *s, char *se, int decpt, ULong sign, size_t blen) #endif { int i, j, k; - char *s0 = s; + char *be, *s0; + size_t len; #ifdef USE_LOCALE - char decimalpoint = *localeconv()->decimal_point; +#ifdef NO_LOCALE_CACHE + char *decimalpoint = localeconv()->decimal_point; + size_t dlen = strlen(decimalpoint); +#else + char *decimalpoint; + static char *decimalpoint_cache; + static size_t dlen; + if (!(s0 = decimalpoint_cache)) { + s0 = localeconv()->decimal_point; + dlen = strlen(s0); + if ((decimalpoint_cache = MALLOC(strlen(s0) + 1)) != NULL) { + strcpy(decimalpoint_cache, s0); + s0 = decimalpoint_cache; + } + } + decimalpoint = s0; +#endif #else -#define decimalpoint '.' +#define dlen 0 #endif + s0 = s; + len = (se-s) + dlen + 6; /* 6 = sign + e+dd + trailing null */ + if (blen < len) + goto ret0; + be = b + blen - 1; if (sign) *b++ = '-'; if (decpt <= -4 || decpt > se - s + 5) { *b++ = *s++; if (*s) { - *b++ = decimalpoint; +#ifdef USE_LOCALE + while((*b = *decimalpoint++)) + ++b; +#else + *b++ = '.'; +#endif while((*b = *s++) !=0) b++; } @@ -71,6 +96,8 @@ g__fmt(char *b, char *s, char *se, int decpt, ULong sign) for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10){} for(;;) { i = decpt / k; + if (b >= be) + goto ret0; *b++ = i + '0'; if (--j <= 0) break; @@ -80,22 +107,41 @@ g__fmt(char *b, char *s, char *se, int decpt, ULong sign) *b = 0; } else if (decpt <= 0) { - *b++ = decimalpoint; +#ifdef USE_LOCALE + while((*b = *decimalpoint++)) + ++b; +#else + *b++ = '.'; +#endif + if (be < b - decpt + (se - s)) + goto ret0; for(; decpt < 0; decpt++) *b++ = '0'; - while((*b = *s++) !=0) + while((*b = *s++) != 0) b++; } else { - while((*b = *s++) !=0) { + while((*b = *s++) != 0) { b++; - if (--decpt == 0 && *s) - *b++ = decimalpoint; + if (--decpt == 0 && *s) { +#ifdef USE_LOCALE + while(*b = *decimalpoint++) + ++b; +#else + *b++ = '.'; +#endif + } + } + if (b + decpt > be) { + ret0: + b = 0; + goto ret; } for(; decpt > 0; decpt--) *b++ = '0'; *b = 0; } + ret: freedtoa(s0); return b; } diff --git a/lib/libc/gdtoa/g_ddfmt.c b/lib/libc/gdtoa/g_ddfmt.c index 9b0725d7d..742eee98c 100644 --- a/lib/libc/gdtoa/g_ddfmt.c +++ b/lib/libc/gdtoa/g_ddfmt.c @@ -1,4 +1,4 @@ -/* $NetBSD: g_ddfmt.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: g_ddfmt.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -35,9 +35,9 @@ THIS SOFTWARE. char * #ifdef KR_headers -g_ddfmt(buf, dd, ndig, bufsize) char *buf; double *dd; int ndig; unsigned bufsize; +g_ddfmt(buf, dd0, ndig, bufsize) char *buf; double *dd0; int ndig; size_t bufsize; #else -g_ddfmt(char *buf, double *dd, int ndig, unsigned bufsize) +g_ddfmt(char *buf, double *dd0, int ndig, size_t bufsize) #endif { FPI fpi; @@ -45,12 +45,28 @@ g_ddfmt(char *buf, double *dd, int ndig, unsigned bufsize) ULong *L, bits0[4], *bits, *zx; int bx, by, decpt, ex, ey, i, j, mode; Bigint *x, *y, *z; - double ddx[2]; + U *dd, ddx[2]; +#ifdef Honor_FLT_ROUNDS /*{{*/ + int Rounding; +#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */ + Rounding = Flt_Rounds; +#else /*}{*/ + Rounding = 1; + switch(fegetround()) { + case FE_TOWARDZERO: Rounding = 0; break; + case FE_UPWARD: Rounding = 2; break; + case FE_DOWNWARD: Rounding = 3; + } +#endif /*}}*/ +#else /*}{*/ +#define Rounding FPI_Round_near +#endif /*}}*/ if (bufsize < 10 || bufsize < ndig + 8) return 0; - L = (ULong*)dd; + dd = (U*)dd0; + L = dd->L; if ((L[_0] & 0x7ff00000L) == 0x7ff00000L) { /* Infinity or NaN */ if (L[_0] & 0xfffff || L[_1]) { @@ -75,7 +91,7 @@ g_ddfmt(char *buf, double *dd, int ndig, unsigned bufsize) goto nanret; goto infret; } - if (dd[0] + dd[1] == 0.) { + if (dval(&dd[0]) + dval(&dd[1]) == 0.) { b = buf; #ifndef IGNORE_ZERO_SIGN if (L[_0] & L[2+_0] & 0x80000000L) @@ -86,18 +102,18 @@ g_ddfmt(char *buf, double *dd, int ndig, unsigned bufsize) return b; } if ((L[_0] & 0x7ff00000L) < (L[2+_0] & 0x7ff00000L)) { - ddx[1] = dd[0]; - ddx[0] = dd[1]; + dval(&ddx[1]) = dval(&dd[0]); + dval(&ddx[0]) = dval(&dd[1]); dd = ddx; - L = (ULong*)dd; + L = dd->L; } - z = d2b(dd[0], &ex, &bx); + z = d2b(dval(&dd[0]), &ex, &bx); if (z == NULL) return NULL; - if (dd[1] == 0.) + if (dval(&dd[1]) == 0.) goto no_y; x = z; - y = d2b(dd[1], &ey, &by); + y = d2b(dval(&dd[1]), &ey, &by); if (y == NULL) return NULL; if ( (i = ex - ey) !=0) { @@ -159,13 +175,13 @@ g_ddfmt(char *buf, double *dd, int ndig, unsigned bufsize) } fpi.emin = 1-1023-53+1; fpi.emax = 2046-1023-106+1; - fpi.rounding = FPI_Round_near; + fpi.rounding = Rounding; fpi.sudden_underflow = 0; i = STRTOG_Normal; s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); if (s == NULL) return NULL; - b = g__fmt(buf, s, se, decpt, z->sign); + b = g__fmt(buf, s, se, decpt, z->sign, bufsize); if (b == NULL) return NULL; Bfree(z); diff --git a/lib/libc/gdtoa/g_dfmt.c b/lib/libc/gdtoa/g_dfmt.c index d8379f054..dd18e8903 100644 --- a/lib/libc/gdtoa/g_dfmt.c +++ b/lib/libc/gdtoa/g_dfmt.c @@ -1,4 +1,4 @@ -/* $NetBSD: g_dfmt.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: g_dfmt.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -35,15 +35,20 @@ THIS SOFTWARE. char* #ifdef KR_headers -g_dfmt(buf, d, ndig, bufsize) char *buf; double *d; int ndig; unsigned bufsize; +g_dfmt(buf, d, ndig, bufsize) char *buf; double *d; int ndig; size_t bufsize; #else -g_dfmt(char *buf, double *d, int ndig, unsigned bufsize) +g_dfmt(char *buf, double *d, int ndig, size_t bufsize) #endif { - static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, 0 }; + static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, 0 }; char *b, *s, *se; ULong bits[2], *L, sign; int decpt, ex, i, mode; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif if (ndig < 0) ndig = 0; @@ -54,6 +59,8 @@ g_dfmt(char *buf, double *d, int ndig, unsigned bufsize) sign = L[_0] & 0x80000000L; if ((L[_0] & 0x7ff00000) == 0x7ff00000) { /* Infinity or NaN */ + if (bufsize < 10) + return 0; if (L[_0] & 0xfffff || L[_1]) { return strcp(buf, "NaN"); } @@ -80,14 +87,13 @@ g_dfmt(char *buf, double *d, int ndig, unsigned bufsize) ex = 1; ex -= 0x3ff + 52; mode = 2; - if (ndig <= 0) { - if (bufsize < 25) - return 0; + if (ndig <= 0) mode = 0; - } i = STRTOG_Normal; - s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + if (sign) + i = STRTOG_Normal | STRTOG_Neg; + s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se); if (s == NULL) return NULL; - return g__fmt(buf, s, se, decpt, sign); + return g__fmt(buf, s, se, decpt, sign, bufsize); } diff --git a/lib/libc/gdtoa/g_ffmt.c b/lib/libc/gdtoa/g_ffmt.c index ca7f646b3..a260d799a 100644 --- a/lib/libc/gdtoa/g_ffmt.c +++ b/lib/libc/gdtoa/g_ffmt.c @@ -1,4 +1,4 @@ -/* $NetBSD: g_ffmt.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: g_ffmt.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -35,15 +35,20 @@ THIS SOFTWARE. char* #ifdef KR_headers -g_ffmt(buf, f, ndig, bufsize) char *buf; float *f; int ndig; unsigned bufsize; +g_ffmt(buf, f, ndig, bufsize) char *buf; float *f; int ndig; size_t bufsize; #else -g_ffmt(char *buf, float *f, int ndig, unsigned bufsize) +g_ffmt(char *buf, float *f, int ndig, size_t bufsize) #endif { - static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, 0 }; + static FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, 0 }; char *b, *s, *se; ULong bits[1], *L, sign; int decpt, ex, i, mode; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif if (ndig < 0) ndig = 0; @@ -85,8 +90,8 @@ g_ffmt(char *buf, float *f, int ndig, unsigned bufsize) mode = 0; } i = STRTOG_Normal; - s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se); if (s == NULL) return NULL; - return g__fmt(buf, s, se, decpt, sign); + return g__fmt(buf, s, se, decpt, sign, bufsize); } diff --git a/lib/libc/gdtoa/g_xLfmt.c b/lib/libc/gdtoa/g_xLfmt.c index a1126ffdf..d35cd1acb 100644 --- a/lib/libc/gdtoa/g_xLfmt.c +++ b/lib/libc/gdtoa/g_xLfmt.c @@ -1,4 +1,4 @@ -/* $NetBSD: g_xLfmt.c,v 1.3 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: g_xLfmt.c,v 1.4 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -51,15 +51,20 @@ THIS SOFTWARE. char* #ifdef KR_headers -g_xLfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; unsigned bufsize; +g_xLfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; size_t bufsize; #else -g_xLfmt(char *buf, void *V, int ndig, unsigned bufsize) +g_xLfmt(char *buf, void *V, int ndig, size_t bufsize) #endif { - static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 }; + static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 }; char *b, *s, *se; ULong bits[2], *L, sign; int decpt, ex, i, mode; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif if (ndig < 0) ndig = 0; @@ -105,8 +110,8 @@ g_xLfmt(char *buf, void *V, int ndig, unsigned bufsize) return 0; mode = 0; } - s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se); if (s == NULL) return NULL; - return g__fmt(buf, s, se, decpt, sign); + return g__fmt(buf, s, se, decpt, sign, bufsize); } diff --git a/lib/libc/gdtoa/g_xfmt.c b/lib/libc/gdtoa/g_xfmt.c index 18b434e19..f7cd39142 100644 --- a/lib/libc/gdtoa/g_xfmt.c +++ b/lib/libc/gdtoa/g_xfmt.c @@ -1,4 +1,4 @@ -/* $NetBSD: g_xfmt.c,v 1.3 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: g_xfmt.c,v 1.4 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -55,16 +55,21 @@ THIS SOFTWARE. char* #ifdef KR_headers -g_xfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; unsigned bufsize; +g_xfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; size_t bufsize; #else -g_xfmt(char *buf, void *V, int ndig, unsigned bufsize) +g_xfmt(char *buf, void *V, int ndig, size_t bufsize) #endif { - static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 }; + static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 }; char *b, *s, *se; ULong bits[2], sign; UShort *L; int decpt, ex, i, mode; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif if (ndig < 0) ndig = 0; @@ -111,8 +116,8 @@ g_xfmt(char *buf, void *V, int ndig, unsigned bufsize) return 0; mode = 0; } - s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se); + s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se); if (s == NULL) return NULL; - return g__fmt(buf, s, se, decpt, sign); + return g__fmt(buf, s, se, decpt, sign, bufsize); } diff --git a/lib/libc/gdtoa/gdtoa.c b/lib/libc/gdtoa/gdtoa.c index 95f7f4f11..c4a595abe 100644 --- a/lib/libc/gdtoa/gdtoa.c +++ b/lib/libc/gdtoa/gdtoa.c @@ -1,4 +1,4 @@ -/* $NetBSD: gdtoa.c,v 1.4 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: gdtoa.c,v 1.6 2012/03/13 21:13:33 christos Exp $ */ /**************************************************************** @@ -65,7 +65,9 @@ bitstob(ULong *bits, int nbits, int *bbits) *x++ = (*bits >> 16) & ALL_ON; #endif } while(++bits <= be); - i = x - x0; + ptrdiff_t td = x - x0; + _DIAGASSERT(__type_fit(int, td)); + i = (int)td; while(!x0[--i]) if (!i) { b->wds = 0; @@ -127,6 +129,7 @@ gdtoa the returned string. If not null, *rve is set to point to the end of the return value. If d is +-Infinity or NaN, then *decpt is set to 9999. + be = exponent: value = (integer represented by bits) * (2 to the power of be). mode: 0 ==> shortest string that yields d when read in @@ -161,8 +164,9 @@ gdtoa int rdir, s2, s5, spec_case, try_quick; Long L; Bigint *b, *b1, *delta, *mlo, *mhi, *mhi1, *S; - double d, d2, ds, eps; + double d2, ds; char *s, *s0; + U d, eps; #ifndef MULTIPLE_THREADS if (dtoa_result) { @@ -205,21 +209,21 @@ gdtoa return nrv_alloc("0", rve, 1); } - dval(d) = b2d(b, &i); + dval(&d) = b2d(b, &i); i = be + bbits - 1; - word0(d) &= Frac_mask1; - word0(d) |= Exp_11; + word0(&d) &= Frac_mask1; + word0(&d) |= Exp_11; #ifdef IBM - if ( (j = 11 - hi0bits(word0(d) & Frac_mask)) !=0) - dval(d) /= 1 << j; + if ( (j = 11 - hi0bits(word0(&d) & Frac_mask)) !=0) + dval(&d) /= 1 << j; #endif /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 * log10(x) = log(x) / log(10) * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) - * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) + * log10(&d) = (i-Bias)*log(2)/log(10) + log10(d2) * - * This suggests computing an approximation k to log10(d) by + * This suggests computing an approximation k to log10(&d) by * * k = (i - Bias)*0.301029995663981 * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); @@ -239,7 +243,7 @@ gdtoa i <<= 2; i += j; #endif - ds = (dval(d)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; + ds = (dval(&d)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; /* correct assumption about exponent range */ if ((j = i) < 0) @@ -254,13 +258,13 @@ gdtoa #ifdef IBM j = be + bbits - 1; if ( (jj1 = j & 3) !=0) - dval(d) *= 1 << jj1; - word0(d) += j << Exp_shift - 2 & Exp_mask; + dval(&d) *= 1 << jj1; + word0(&d) += j << Exp_shift - 2 & Exp_mask; #else - word0(d) += (be + bbits - 1) << Exp_shift; + word0(&d) += (be + bbits - 1) << Exp_shift; #endif if (k >= 0 && k <= Ten_pmax) { - if (dval(d) < tens[k]) + if (dval(&d) < tens[k]) k--; k_check = 0; } @@ -290,11 +294,14 @@ gdtoa mode -= 4; try_quick = 0; } + else if (i >= -4 - Emin || i < Emin) + try_quick = 0; leftright = 1; + ilim = ilim1 = -1; /* Values for cases 0 and 1; done here to */ + /* silence erroneous "gcc -Wall" warning. */ switch(mode) { case 0: case 1: - ilim = ilim1 = -1; i = (int)(nbits * .30103) + 3; ndigits = 0; break; @@ -338,10 +345,10 @@ gdtoa /* Try to get by with floating-point arithmetic. */ i = 0; - d2 = dval(d); + d2 = dval(&d); #ifdef IBM - if ( (j = 11 - hi0bits(word0(d) & Frac_mask)) !=0) - dval(d) /= 1 << j; + if ( (j = 11 - hi0bits(word0(&d) & Frac_mask)) !=0) + dval(&d) /= 1 << j; #endif k0 = k; ilim0 = ilim; @@ -352,7 +359,7 @@ gdtoa if (j & Bletch) { /* prevent overflows */ j &= Bletch - 1; - dval(d) /= bigtens[n_bigtens-1]; + dval(&d) /= bigtens[n_bigtens-1]; ieps++; } for(; j; j /= 2, i++) @@ -364,30 +371,30 @@ gdtoa else { ds = 1.; if ( (jj1 = -k) !=0) { - dval(d) *= tens[jj1 & 0xf]; + dval(&d) *= tens[jj1 & 0xf]; for(j = jj1 >> 4; j; j >>= 1, i++) if (j & 1) { ieps++; - dval(d) *= bigtens[i]; + dval(&d) *= bigtens[i]; } } } - if (k_check && dval(d) < 1. && ilim > 0) { + if (k_check && dval(&d) < 1. && ilim > 0) { if (ilim1 <= 0) goto fast_failed; ilim = ilim1; k--; - dval(d) *= 10.; + dval(&d) *= 10.; ieps++; } - dval(eps) = ieps*dval(d) + 7.; - word0(eps) -= (P-1)*Exp_msk1; + dval(&eps) = ieps*dval(&d) + 7.; + word0(&eps) -= (P-1)*Exp_msk1; if (ilim == 0) { S = mhi = 0; - dval(d) -= 5.; - if (dval(d) > dval(eps)) + dval(&d) -= 5.; + if (dval(&d) > dval(&eps)) goto one_digit; - if (dval(d) < -dval(eps)) + if (dval(&d) < -dval(&eps)) goto no_digits; goto fast_failed; } @@ -396,42 +403,40 @@ gdtoa /* Use Steele & White method of only * generating digits needed. */ - dval(eps) = ds*0.5/tens[ilim-1] - dval(eps); + dval(&eps) = ds*0.5/tens[ilim-1] - dval(&eps); for(i = 0;;) { - L = (Long)(dval(d)/ds); - dval(d) -= L*ds; + L = (Long)(dval(&d)/ds); + dval(&d) -= L*ds; *s++ = '0' + (int)L; - if (dval(d) < dval(eps)) { - if (dval(d)) + if (dval(&d) < dval(&eps)) { + if (dval(&d)) inex = STRTOG_Inexlo; goto ret1; } - if (ds - dval(d) < dval(eps)) + if (ds - dval(&d) < dval(&eps)) goto bump_up; if (++i >= ilim) break; - dval(eps) *= 10.; - dval(d) *= 10.; + dval(&eps) *= 10.; + dval(&d) *= 10.; } } else { #endif /* Generate ilim digits, then fix them up. */ - dval(eps) *= tens[ilim-1]; - for(i = 1;; i++, dval(d) *= 10.) { - if ( (L = (Long)(dval(d)/ds)) !=0) - dval(d) -= L*ds; + dval(&eps) *= tens[ilim-1]; + for(i = 1;; i++, dval(&d) *= 10.) { + if ( (L = (Long)(dval(&d)/ds)) !=0) + dval(&d) -= L*ds; *s++ = '0' + (int)L; if (i == ilim) { ds *= 0.5; - if (dval(d) > ds + dval(eps)) + if (dval(&d) > ds + dval(&eps)) goto bump_up; - else if (dval(d) < ds - dval(eps)) { - while(*--s == '0'){} - s++; - if (dval(d)) + else if (dval(&d) < ds - dval(&eps)) { + if (dval(&d)) inex = STRTOG_Inexlo; - goto ret1; + goto clear_trailing0; } break; } @@ -441,7 +446,7 @@ gdtoa #endif fast_failed: s = s0; - dval(d) = d2; + dval(&d) = d2; k = k0; ilim = ilim0; } @@ -453,22 +458,22 @@ gdtoa ds = tens[k]; if (ndigits < 0 && ilim <= 0) { S = mhi = 0; - if (ilim < 0 || dval(d) <= 5*ds) + if (ilim < 0 || dval(&d) <= 5*ds) goto no_digits; goto one_digit; } - for(i = 1;; i++, dval(d) *= 10.) { - L = dval(d) / ds; - dval(d) -= L*ds; + for(i = 1;; i++, dval(&d) *= 10.) { + L = dval(&d) / ds; + dval(&d) -= L*ds; #ifdef Check_FLT_ROUNDS /* If FLT_ROUNDS == 2, L will usually be high by 1 */ - if (dval(d) < 0) { + if (dval(&d) < 0) { L--; - dval(d) += ds; + dval(&d) += ds; } #endif *s++ = '0' + (int)L; - if (dval(d) == 0.) + if (dval(&d) == 0.) break; if (i == ilim) { if (rdir) { @@ -477,8 +482,13 @@ gdtoa inex = STRTOG_Inexlo; goto ret1; } - dval(d) += dval(d); - if (dval(d) > ds || (dval(d) == ds && L & 1)) { + dval(&d) += dval(&d); +#ifdef ROUND_BIASED + if (dval(&d) >= ds) +#else + if (dval(&d) > ds || (dval(&d) == ds && L & 1)) +#endif + { bump_up: inex = STRTOG_Inexhi; while(*--s == '9') @@ -489,8 +499,12 @@ gdtoa } ++*s++; } - else + else { inex = STRTOG_Inexlo; + clear_trailing0: + while(*--s == '0'){} + ++s; + } break; } } @@ -501,13 +515,15 @@ gdtoa m5 = b5; mhi = mlo = 0; if (leftright) { - if (mode < 2) { - i = nbits - bbits; - if (be - i++ < fpi->emin) - /* denormal */ - i = be - fpi->emin + 1; + i = nbits - bbits; + if (be - i++ < fpi->emin && mode != 3 && mode != 5) { + /* denormal */ + i = be - fpi->emin + 1; + if (mode >= 2 && ilim > 0 && ilim < i) + goto small_ilim; } - else { + else if (mode >= 2) { + small_ilim: j = ilim - 1; if (m5 >= j) m5 -= j; @@ -583,28 +599,11 @@ gdtoa * and for all and pass them and a shift to quorem, so it * can do shifts and ors to compute the numerator for q. */ -#ifdef Pack_32 - if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) !=0) - i = 32 - i; -#else - if ( (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) !=0) - i = 16 - i; -#endif - if (i > 4) { - i -= 4; - b2 += i; - m2 += i; - s2 += i; - } - else if (i < 4) { - i += 28; - b2 += i; - m2 += i; - s2 += i; - } - if (b2 > 0) + i = ((s5 ? hi0bits(S->x[S->wds-1]) : ULbits - 1) - s2 - 4) & kmask; + m2 += i; + if ((b2 += i) > 0) b = lshift(b, b2); - if (s2 > 0) + if ((s2 += i) > 0) S = lshift(S, s2); if (k_check) { if (cmp(b,S) < 0) { @@ -716,7 +715,11 @@ gdtoa if (b == NULL) return NULL; jj1 = cmp(b, S); +#ifdef ROUND_BIASED + if (jj1 >= 0 /*)*/ +#else if ((jj1 > 0 || (jj1 == 0 && dig & 1)) +#endif && dig++ == '9') goto round_9_up; inex = STRTOG_Inexhi; @@ -780,7 +783,12 @@ gdtoa if (b == NULL) return NULL; j = cmp(b, S); - if (j > 0 || (j == 0 && dig & 1)) { +#ifdef ROUND_BIASED + if (j >= 0) +#else + if (j > 0 || (j == 0 && dig & 1)) +#endif + { roundoff: inex = STRTOG_Inexhi; while(*--s == '9') @@ -796,7 +804,7 @@ gdtoa if (b->wds > 1 || b->x[0]) inex = STRTOG_Inexlo; while(*--s == '0'){} - s++; + ++s; } ret: Bfree(S); diff --git a/lib/libc/gdtoa/gdtoa.h b/lib/libc/gdtoa/gdtoa.h index 63840250f..12cf691bb 100644 --- a/lib/libc/gdtoa/gdtoa.h +++ b/lib/libc/gdtoa/gdtoa.h @@ -1,4 +1,4 @@ -/* $NetBSD: gdtoa.h,v 1.8 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: gdtoa.h,v 1.9 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -35,6 +35,8 @@ THIS SOFTWARE. #define GDTOA_H_INCLUDED #include "arith.h" +#include /* for size_t */ +#include #ifndef Long #define Long int32_t @@ -76,9 +78,9 @@ THIS SOFTWARE. /* The following may be or-ed into one of the above values. */ - STRTOG_Neg = 0x08, - STRTOG_Inexlo = 0x10, - STRTOG_Inexhi = 0x20, + STRTOG_Neg = 0x08, /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */ + STRTOG_Inexlo = 0x10, /* returned result rounded toward zero */ + STRTOG_Inexhi = 0x20, /* returned result rounded away from zero */ STRTOG_Inexact = 0x30, STRTOG_Underflow= 0x40, STRTOG_Overflow = 0x80, @@ -133,12 +135,12 @@ extern float strtof ANSI((CONST char *, char **)); extern double strtod ANSI((CONST char *, char **)); extern int strtodg ANSI((CONST char*, char**, CONST FPI*, Long*, ULong*)); -extern char* g_ddfmt ANSI((char*, double*, int, unsigned)); -extern char* g_dfmt ANSI((char*, double*, int, unsigned)); -extern char* g_ffmt ANSI((char*, float*, int, unsigned)); -extern char* g_Qfmt ANSI((char*, void*, int, unsigned)); -extern char* g_xfmt ANSI((char*, void*, int, unsigned)); -extern char* g_xLfmt ANSI((char*, void*, int, unsigned)); +extern char* g_ddfmt ANSI((char*, double*, int, size_t)); +extern char* g_dfmt ANSI((char*, double*, int, size_t)); +extern char* g_ffmt ANSI((char*, float*, int, size_t)); +extern char* g_Qfmt ANSI((char*, void*, int, size_t)); +extern char* g_xfmt ANSI((char*, void*, int, size_t)); +extern char* g_xLfmt ANSI((char*, void*, int, size_t)); extern int strtoId ANSI((CONST char*, char**, double*, double*)); extern int strtoIdd ANSI((CONST char*, char**, double*, double*)); diff --git a/lib/libc/gdtoa/gdtoa_fltrnds.h b/lib/libc/gdtoa/gdtoa_fltrnds.h new file mode 100644 index 000000000..33e5f9e53 --- /dev/null +++ b/lib/libc/gdtoa/gdtoa_fltrnds.h @@ -0,0 +1,18 @@ + FPI *fpi, fpi1; + int Rounding; +#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */ + Rounding = Flt_Rounds; +#else /*}{*/ + Rounding = 1; + switch(fegetround()) { + case FE_TOWARDZERO: Rounding = 0; break; + case FE_UPWARD: Rounding = 2; break; + case FE_DOWNWARD: Rounding = 3; + } +#endif /*}}*/ + fpi = &fpi0; + if (Rounding != 1) { + fpi1 = fpi0; + fpi = &fpi1; + fpi1.rounding = Rounding; + } diff --git a/lib/libc/gdtoa/gdtoaimp.h b/lib/libc/gdtoa/gdtoaimp.h index b897f0084..09517ee4a 100644 --- a/lib/libc/gdtoa/gdtoaimp.h +++ b/lib/libc/gdtoa/gdtoaimp.h @@ -1,4 +1,4 @@ -/* $NetBSD: gdtoaimp.h,v 1.8 2011/01/21 23:36:49 christos Exp $ */ +/* $NetBSD: gdtoaimp.h,v 1.13 2012/03/13 21:13:34 christos Exp $ */ /**************************************************************** @@ -96,7 +96,12 @@ THIS SOFTWARE. * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines * that use extended-precision instructions to compute rounded * products and quotients) with IBM. - * #define ROUND_BIASED for IEEE-format with biased rounding. + * #define ROUND_BIASED for IEEE-format with biased rounding and arithmetic + * that rounds toward +Infinity. + * #define ROUND_BIASED_without_Round_Up for IEEE-format with biased + * rounding when the underlying floating-point arithmetic uses + * unbiased rounding. This prevent using ordinary floating-point + * arithmetic when the result could be computed with one rounding error. * #define Inaccurate_Divide for IEEE-format with correctly rounded * products but inaccurate quotients, e.g., for Intel i860. * #define NO_LONG_LONG on machines that do not have a "long long" @@ -115,7 +120,12 @@ THIS SOFTWARE. * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) * if memory is available and otherwise does something you deem * appropriate. If MALLOC is undefined, malloc will be invoked - * directly -- and assumed always to succeed. + * directly -- and assumed always to succeed. Similarly, if you + * want something other than the system's free() to be called to + * recycle memory acquired from MALLOC, #define FREE to be the + * name of the alternate routine. (FREE or free is only called in + * pathological cases, e.g., in a gdtoa call after a gdtoa return in + * mode 3 with thousands of digits requested.) * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making * memory allocations from a private pool of memory when possible. * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes, @@ -128,17 +138,22 @@ THIS SOFTWARE. * conversions of IEEE doubles in single-threaded executions with * 8-byte pointers, PRIVATE_MEM >= 7400 appears to suffice; with * 4-byte pointers, PRIVATE_MEM >= 7112 appears adequate. - * #define INFNAN_CHECK on IEEE systems to cause strtod to check for - * Infinity and NaN (case insensitively). + * #define NO_INFNAN_CHECK if you do not wish to have INFNAN_CHECK + * #defined automatically on IEEE systems. On such systems, + * when INFNAN_CHECK is #defined, strtod checks + * for Infinity and NaN (case insensitively). * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined, * strtodg also accepts (case insensitively) strings of the form - * NaN(x), where x is a string of hexadecimal digits and spaces; - * if there is only one string of hexadecimal digits, it is taken - * for the fraction bits of the resulting NaN; if there are two or - * more strings of hexadecimal digits, each string is assigned - * to the next available sequence of 32-bit words of fractions - * bits (starting with the most significant), right-aligned in - * each sequence. + * NaN(x), where x is a string of hexadecimal digits (optionally + * preceded by 0x or 0X) and spaces; if there is only one string + * of hexadecimal digits, it is taken for the fraction bits of the + * resulting NaN; if there are two or more strings of hexadecimal + * digits, each string is assigned to the next available sequence + * of 32-bit words of fractions bits (starting with the most + * significant), right-aligned in each sequence. + * Unless GDTOA_NON_PEDANTIC_NANCHECK is #defined, input "NaN(...)" + * is consumed even when ... has the wrong form (in which case the + * "(...)" is consumed but ignored). * #define MULTIPLE_THREADS if the system offers preemptively scheduled * multiple threads. In this case, you must provide (or suitably * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed @@ -150,7 +165,7 @@ THIS SOFTWARE. * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined. * #define IMPRECISE_INEXACT if you do not care about the setting of * the STRTOG_Inexact bits in the special case of doing IEEE double - * precision conversions (which could also be done by the strtog in + * precision conversions (which could also be done by the strtod in * dtoa.c). * #define NO_HEX_FP to disable recognition of C9x's hexadecimal * floating-point constants. @@ -159,16 +174,12 @@ THIS SOFTWARE. * #define NO_STRING_H to use private versions of memcpy. * On some K&R systems, it may also be necessary to * #define DECLARE_SIZE_T in this case. - * #define YES_ALIAS to permit aliasing certain double values with - * arrays of ULongs. This leads to slightly better code with - * some compilers and was always used prior to 19990916, but it - * is not strictly legal and can cause trouble with aggressively - * optimizing compilers (e.g., gcc 2.95.1 under -O2). * #define USE_LOCALE to use the current locale's decimal_point value. */ /* #define IEEE_{BIG,LITTLE}_ENDIAN in ${ARCHDIR}/gdtoa/arith.h */ +#include #include #define Short int16_t #define UShort uint16_t @@ -187,6 +198,9 @@ THIS SOFTWARE. #define GDTOAIMP_H_INCLUDED #include "gdtoa.h" #include "gd_qnan.h" +#ifdef Honor_FLT_ROUNDS +#include +#endif #ifdef DEBUG #include "stdio.h" @@ -281,21 +295,21 @@ typedef union { double d; ULong L[2]; } __attribute__((__may_alias__)) U; #ifdef YES_ALIAS #define dval(x) x #ifdef IEEE_LITTLE_ENDIAN -#define word0(x) ((ULong *)&x)[1] -#define word1(x) ((ULong *)&x)[0] +#define word0(x) ((ULong *)x)[1] +#define word1(x) ((ULong *)x)[0] #else -#define word0(x) ((ULong *)&x)[0] -#define word1(x) ((ULong *)&x)[1] +#define word0(x) ((ULong *)x)[0] +#define word1(x) ((ULong *)x)[1] #endif #else /* !YES_ALIAS */ #ifdef IEEE_LITTLE_ENDIAN -#define word0(x) ( /* LINTED */ (U*)&x)->L[1] -#define word1(x) ( /* LINTED */ (U*)&x)->L[0] +#define word0(x) ( /* LINTED */ (U*)x)->L[1] +#define word1(x) ( /* LINTED */ (U*)x)->L[0] #else -#define word0(x) ( /* LINTED */ (U*)&x)->L[0] -#define word1(x) ( /* LINTED */ (U*)&x)->L[1] +#define word0(x) ( /* LINTED */ (U*)x)->L[0] +#define word1(x) ( /* LINTED */ (U*)x)->L[1] #endif -#define dval(x) ( /* LINTED */ (U*)&x)->d +#define dval(x) ( /* LINTED */ (U*)x)->d #endif /* YES_ALIAS */ /* The following definition of Storeinc is appropriate for MIPS processors. @@ -393,6 +407,7 @@ typedef union { double d; ULong L[2]; } __attribute__((__may_alias__)) U; #define Exp_mask 0x7f80 #define P 56 #define Bias 129 +#define Emin (-127) /* XXX: Check this */ #define Exp_1 0x40800000 #define Exp_11 0x4080 #define Ebits 8 @@ -414,6 +429,11 @@ typedef union { double d; ULong L[2]; } __attribute__((__may_alias__)) U; #ifndef IEEE_Arith #define ROUND_BIASED +#else +#ifdef ROUND_BIASED_without_Round_Up +#undef ROUND_BIASED +#define ROUND_BIASED +#endif #endif #ifdef RND_PRODQUOT @@ -576,11 +596,11 @@ extern void memcpy_D2A ANSI((void*, const void*, size_t)); extern int cmp ANSI((Bigint*, Bigint*)); extern void copybits ANSI((ULong*, int, Bigint*)); extern Bigint *d2b ANSI((double, int*, int*)); - extern int decrement ANSI((Bigint*)); + extern void decrement ANSI((Bigint*)); extern Bigint *diff ANSI((Bigint*, Bigint*)); extern char *dtoa ANSI((double d, int mode, int ndigits, int *decpt, int *sign, char **rve)); - extern char *g__fmt ANSI((char*, char*, char*, int, ULong)); + extern char *g__fmt ANSI((char*, char*, char*, int, ULong, size_t)); extern int gethex ANSI((CONST char**, CONST FPI*, Long*, Bigint**, int)); extern void hexdig_init_D2A(Void); extern int hexnan ANSI((CONST char**, CONST FPI*, ULong*)); @@ -598,14 +618,14 @@ extern void memcpy_D2A ANSI((void*, const void*, size_t)); extern double ratio ANSI((Bigint*, Bigint*)); extern void rshift ANSI((Bigint*, int)); extern char *rv_alloc ANSI((size_t)); - extern Bigint *s2b ANSI((CONST char*, int, int, ULong)); + extern Bigint *s2b ANSI((CONST char*, int, int, ULong, size_t)); extern Bigint *set_ones ANSI((Bigint*, int)); extern char *strcp ANSI((char*, const char*)); extern int strtoIg ANSI((CONST char*, char**, FPI*, Long*, Bigint**, int*)); extern double strtod ANSI((const char *s00, char **se)); extern Bigint *sum ANSI((Bigint*, Bigint*)); extern int trailz ANSI((CONST Bigint*)); - extern double ulp ANSI((double)); + extern double ulp ANSI((U*)); #ifdef __cplusplus } @@ -620,6 +640,10 @@ extern void memcpy_D2A ANSI((void*, const void*, size_t)); * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.) */ #ifdef IEEE_Arith +#ifndef NO_INFNAN_CHECK +#undef INFNAN_CHECK +#define INFNAN_CHECK +#endif #ifdef IEEE_BIG_ENDIAN #define _0 0 #define _1 1 diff --git a/lib/libc/gdtoa/gethex.c b/lib/libc/gdtoa/gethex.c index a63ce977f..31bd91951 100644 --- a/lib/libc/gdtoa/gethex.c +++ b/lib/libc/gdtoa/gethex.c @@ -1,4 +1,4 @@ -/* $NetBSD: gethex.c,v 1.4 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: gethex.c,v 1.5 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -46,20 +46,33 @@ gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign) #endif { Bigint *b; - CONST unsigned char *decpt, *s0, *s, *s1; - int esign, havedig, irv, k, n, nbits, up, zret; + CONST char *decpt, *s, *s0, *s1; + int big, esign, havedig, irv, j, k, n, n0, nbits, up, zret; ULong L, lostbits, *x; Long e, e1; #ifdef USE_LOCALE - unsigned char decimalpoint = *localeconv()->decimal_point; + int i; +#ifdef NO_LOCALE_CACHE + const char *decimalpoint = localeconv()->decimal_point; #else -#define decimalpoint '.' + const unsigned char *decimalpoint; + static char *decimalpoint_cache; + if (!(s0 = decimalpoint_cache)) { + s0 = localeconv()->decimal_point; + if ((decimalpoint_cache = MALLOC(strlen(s0) + 1)) != NULL) { + strcpy(decimalpoint_cache, s0); + s0 = decimalpoint_cache; + } + } + decimalpoint = __UNCONST(s0); +#endif #endif - if (!hexdig['0']) + if (!hexdig[(unsigned char)'0']) hexdig_init_D2A(); + *bp = 0; havedig = 0; - s0 = *(CONST unsigned char **)sp + 2; + s0 = *(CONST char **)sp + 2; while(s0[havedig] == '0') havedig++; s0 += havedig; @@ -67,35 +80,54 @@ gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign) decpt = 0; zret = 0; e = 0; - if (!hexdig[*s]) { + if (hexdig[(unsigned char)*s]) + havedig++; + else { zret = 1; - if (*s != decimalpoint) +#ifdef USE_LOCALE + for(i = 0; decimalpoint[i]; ++i) { + if (s[i] != decimalpoint[i]) + goto pcheck; + } + decpt = s += i; +#else + if (*s != '.') goto pcheck; decpt = ++s; - if (!hexdig[*s]) +#endif + if (!hexdig[(unsigned char)*s]) goto pcheck; while(*s == '0') s++; - if (hexdig[*s]) + if (hexdig[(unsigned char)*s]) zret = 0; havedig = 1; s0 = s; } - while(hexdig[*s]) + while(hexdig[(unsigned char)*s]) s++; - if (*s == decimalpoint && !decpt) { +#ifdef USE_LOCALE + if (*s == *decimalpoint && !decpt) { + for(i = 1; decimalpoint[i]; ++i) { + if (s[i] != decimalpoint[i]) + goto pcheck; + } + decpt = s += i; +#else + if (*s == '.' && !decpt) { decpt = ++s; - while(hexdig[*s]) +#endif + while(hexdig[(unsigned char)*s]) s++; - } + }/*}*/ if (decpt) e = -(((Long)(s-decpt)) << 2); pcheck: s1 = s; + big = esign = 0; switch(*s) { case 'p': case 'P': - esign = 0; switch(*++s) { case '-': esign = 1; @@ -103,22 +135,73 @@ gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign) case '+': s++; } - if ((n = hexdig[*s]) == 0 || n > 0x19) { + if ((n = hexdig[(unsigned char)*s]) == 0 || n > 0x19) { s = s1; break; } e1 = n - 0x10; - while((n = hexdig[*++s]) !=0 && n <= 0x19) + while((n = hexdig[(unsigned char)*++s]) !=0 && n <= 0x19) { + if (e1 & 0xf8000000) + big = 1; e1 = 10*e1 + n - 0x10; + } if (esign) e1 = -e1; e += e1; } *sp = __UNCONST(s); + if (!havedig) + *sp = (char*)__UNCONST(s0) - 1; if (zret) - return havedig ? STRTOG_Zero : STRTOG_NoNumber; - n = s1 - s0 - 1; - for(k = 0; n > 7; n = (unsigned int)n >> 1) + return STRTOG_Zero; + if (big) { + if (esign) { + switch(fpi->rounding) { + case FPI_Round_up: + if (sign) + break; + goto ret_tiny; + case FPI_Round_down: + if (!sign) + break; + goto ret_tiny; + } + goto retz; + ret_tiny: + b = Balloc(0); + b->wds = 1; + b->x[0] = 1; + goto dret; + } + switch(fpi->rounding) { + case FPI_Round_near: + goto ovfl1; + case FPI_Round_up: + if (!sign) + goto ovfl1; + goto ret_big; + case FPI_Round_down: + if (sign) + goto ovfl1; + goto ret_big; + } + ret_big: + nbits = fpi->nbits; + n0 = n = (unsigned int)nbits >> kshift; + if (nbits & kmask) + ++n; + for(j = n, k = 0; (j = (unsigned int)j >> 1) != 0; ++k); + *bp = b = Balloc(k); + b->wds = n; + for(j = 0; j < n0; ++j) + b->x[j] = ALL_ON; + if (n > n0) + b->x[j] = ULbits >> (ULbits - (nbits & kmask)); + *expt = fpi->emin; + return STRTOG_Normal | STRTOG_Inexlo; + } + n = (int)(s1 - s0) - 1; + for(k = 0; n > (1 << (kshift-2)) - 1; n = (unsigned int)n >> 1) k++; b = Balloc(k); if (b == NULL) @@ -126,20 +209,30 @@ gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign) x = b->x; n = 0; L = 0; +#ifdef USE_LOCALE + for(i = 0; decimalpoint[i+1]; ++i); +#endif while(s1 > s0) { - if (*--s1 == decimalpoint) +#ifdef USE_LOCALE + if (*--s1 == decimalpoint[i]) { + s1 -= i; continue; - if (n == 32) { + } +#else + if (*--s1 == '.') + continue; +#endif + if (n == ULbits) { *x++ = L; L = 0; n = 0; } - L |= (hexdig[*s1] & 0x0f) << n; + L |= (hexdig[(unsigned char)*s1] & 0x0f) << n; n += 4; } *x++ = L; - b->wds = n = x - b->x; - n = 32*n - hi0bits(L); + b->wds = n = (int)(x - b->x); + n = ULbits*n - hi0bits(L); nbits = fpi->nbits; lostbits = 0; x = b->x; @@ -150,7 +243,7 @@ gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign) k = n - 1; if (x[(unsigned int)k>>kshift] & 1 << (k & kmask)) { lostbits = 2; - if (k > 1 && any_on(b,k-1)) + if (k > 0 && any_on(b,k)) lostbits = 3; } } @@ -168,7 +261,10 @@ gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign) if (e > fpi->emax) { ovfl: Bfree(b); - *bp = 0; + ovfl1: +#ifndef NO_ERRNO + errno = ERANGE; +#endif return STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi; } irv = STRTOG_Normal; @@ -188,15 +284,22 @@ gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign) case FPI_Round_down: if (sign) { one_bit: - *expt = fpi->emin; x[0] = b->wds = 1; + dret: *bp = b; + *expt = fpi->emin; +#ifndef NO_ERRNO + errno = ERANGE; +#endif return STRTOG_Denormal | STRTOG_Inexhi | STRTOG_Underflow; } } Bfree(b); - *bp = 0; + retz: +#ifndef NO_ERRNO + errno = ERANGE; +#endif return STRTOG_Zero | STRTOG_Inexlo | STRTOG_Underflow; } k = n - 1; @@ -217,7 +320,7 @@ gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign) break; case FPI_Round_near: if (lostbits & 2 - && (lostbits & 1) | (x[0] & 1)) + && (lostbits | x[0]) & 1) up = 1; break; case FPI_Round_up: @@ -237,7 +340,7 @@ gethex( CONST char **sp, CONST FPI *fpi, Long *expt, Bigint **bp, int sign) } else if (b->wds > k || ((n = nbits & kmask) !=0 - && hi0bits(x[k-1]) < 32-n)) { + && hi0bits(x[k-1]) < 32-n)) { rshift(b,1); if (++e > fpi->emax) goto ovfl; diff --git a/lib/libc/gdtoa/gmisc.c b/lib/libc/gdtoa/gmisc.c index 36ae1d887..9c54580f9 100644 --- a/lib/libc/gdtoa/gmisc.c +++ b/lib/libc/gdtoa/gmisc.c @@ -1,4 +1,4 @@ -/* $NetBSD: gmisc.c,v 1.3 2006/03/11 18:38:14 kleink Exp $ */ +/* $NetBSD: gmisc.c,v 1.4 2012/03/13 21:13:34 christos Exp $ */ /**************************************************************** @@ -62,7 +62,10 @@ rshift(Bigint *b, int k) while(x < xe) *x1++ = *x++; } - if ((b->wds = x1 - b->x) == 0) + + ptrdiff_t td = x1 - b->x; + _DIAGASSERT(__type_fit(int, td)); + if ((b->wds = (int)td) == 0) b->x[0] = 0; } diff --git a/lib/libc/gdtoa/hdtoa.c b/lib/libc/gdtoa/hdtoa.c index 8396bbe55..243bd05ff 100644 --- a/lib/libc/gdtoa/hdtoa.c +++ b/lib/libc/gdtoa/hdtoa.c @@ -1,4 +1,4 @@ -/* $NetBSD: hdtoa.c,v 1.6 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: hdtoa.c,v 1.9 2011/07/04 11:46:41 mrg Exp $ */ /*- * Copyright (c) 2004, 2005 David Schultz @@ -30,7 +30,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/gdtoa/_hdtoa.c,v 1.4 2007/01/03 04:57:58 das Exp $"); #else -__RCSID("$NetBSD: hdtoa.c,v 1.6 2008/03/21 23:13:48 christos Exp $"); +__RCSID("$NetBSD: hdtoa.c,v 1.9 2011/07/04 11:46:41 mrg Exp $"); #endif #include @@ -161,8 +161,15 @@ hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign, *decpt = 1; return (nrv_alloc("0", rve, 1)); case FP_SUBNORMAL: +#ifdef __vax__ + /* (DBL_MAX_EXP=127 / 2) + 2 = 65? */ + u.dblu_d *= 0x1p65; + *decpt = u.dblu_dbl.dbl_exp - (65 + DBL_ADJ); +#else + /* (DBL_MAX_EXP=1024 / 2) + 2 = 514? */ u.dblu_d *= 0x1p514; *decpt = u.dblu_dbl.dbl_exp - (514 + DBL_ADJ); +#endif break; case FP_INFINITE: *decpt = INT_MAX; @@ -254,6 +261,7 @@ hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign, char *s, *s0; size_t bufsize; + memset(&u, 0, sizeof u); u.extu_ld = e; *sign = u.extu_ext.ext_sign; diff --git a/lib/libc/gdtoa/hexnan.c b/lib/libc/gdtoa/hexnan.c index 405328ab3..267703e78 100644 --- a/lib/libc/gdtoa/hexnan.c +++ b/lib/libc/gdtoa/hexnan.c @@ -1,4 +1,4 @@ -/* $NetBSD: hexnan.c,v 1.3 2006/03/11 18:38:14 kleink Exp $ */ +/* $NetBSD: hexnan.c,v 1.5 2011/03/21 04:52:09 christos Exp $ */ /**************************************************************** @@ -73,7 +73,13 @@ hexnan( CONST char **sp, CONST FPI *fpi, ULong *x0) x1 = xe = x; havedig = hd0 = i = 0; s = *sp; - while((c = *(CONST unsigned char*)++s) != 0) { + /* allow optional initial 0x or 0X */ + while((c = *(CONST unsigned char*)(s+1)) && c <= ' ') + ++s; + if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X') + && *(CONST unsigned char*)(s+3) > ' ') + s += 2; + while((c = *(CONST unsigned char*)++s) != '\0') { if (!(h = hexdig[c])) { if (c <= ' ') { if (hd0 < havedig) { @@ -88,12 +94,25 @@ hexnan( CONST char **sp, CONST FPI *fpi, ULong *x0) x1 = x; i = 0; } + while(*(CONST unsigned char*)(s+1) <= ' ') + ++s; + if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X') + && *(CONST unsigned char*)(s+3) > ' ') + s += 2; continue; } if (/*(*/ c == ')' && havedig) { *sp = s + 1; break; } +#ifndef GDTOA_NON_PEDANTIC_NANCHECK + do { + if (/*(*/ c == ')') { + *sp = s + 1; + break; + } + } while((c = *++s) != '\0'); +#endif return STRTOG_NaN; } havedig++; diff --git a/lib/libc/gdtoa/makefile b/lib/libc/gdtoa/makefile index ff33a3d8d..62f14df2e 100644 --- a/lib/libc/gdtoa/makefile +++ b/lib/libc/gdtoa/makefile @@ -1,4 +1,4 @@ -# $NetBSD: makefile,v 1.3 2006/01/25 16:40:57 kleink Exp $ +# $NetBSD: makefile,v 1.4 2011/03/20 23:15:35 christos Exp $ # /**************************************************************** # Copyright (C) 1998 by Lucent Technologies @@ -27,11 +27,13 @@ .SUFFIXES: .c .o CC = cc -CFLAGS = -g -DINFNAN_CHECK +CFLAGS = -g .c.o: $(CC) -c $(CFLAGS) $*.c +# invoke "make Printf" to add printf.o to gdtoa.a (if desired) + all: arith.h gd_qnan.h gdtoa.a arith.h: arithchk.c @@ -44,27 +46,36 @@ gd_qnan.h: arith.h qnan.c ./a.out >gd_qnan.h rm -f a.out qnan.o -gdtoa.a: dmisc.c dtoa.c g_Qfmt.c g__fmt.c g_ddfmt.c g_dfmt.c g_ffmt.c\ - g_xLfmt.c g_xfmt.c gdtoa.c gethex.c gmisc.c hd_init.c hexnan.c\ - misc.c smisc.c strtoIQ.c strtoId.c strtoIdd.c strtoIf.c strtoIg.c\ - strtoIx.c strtoIxL.c strtod.c strtodI.c strtodg.c strtof.c strtopQ.c\ - strtopd.c strtopdd.c strtopf.c strtopx.c strtopxL.c strtorQ.c\ - strtord.c strtordd.c strtorf.c strtorx.c strtorxL.c sum.c ulp.c +gdtoa.a: dmisc.c dtoa.c g_Qfmt.c g__fmt.c g_ddfmt.c g_dfmt.c\ + g_ffmt.c g_xLfmt.c g_xfmt.c gdtoa.c gethex.c gmisc.c hd_init.c\ + hexnan.c misc.c smisc.c strtoIQ.c strtoId.c strtoIdd.c\ + strtoIf.c strtoIg.c strtoIx.c strtoIxL.c strtod.c strtodI.c\ + strtodg.c strtof.c strtopQ.c strtopd.c strtopdd.c strtopf.c\ + strtopx.c strtopxL.c strtorQ.c strtord.c strtordd.c strtorf.c\ + strtorx.c strtorxL.c sum.c ulp.c $(CC) -c $(CFLAGS) $? x=`echo $? | sed 's/\.c/.o/g'` && ar ruv gdtoa.a $$x && rm $$x ranlib gdtoa.a || true +Printf: all printf.c + $(CC) -c $(CFLAGS) printf.c + ar ruv gdtoa.a printf.o + rm printf.o + touch Printf + # If your system lacks ranlib, you do not need it. -xs0 = README arithchk.c dmisc.c dtoa.c g_Qfmt.c g__fmt.c g_ddfmt.c g_dfmt.c\ - g_ffmt.c g_xLfmt.c g_xfmt.c gdtoa.c gdtoa.h gdtoaimp.h gethex.c\ - gmisc.c hd_init.c hexnan.c makefile misc.c qnan.c smisc.c strtoIQ.c\ - strtoId.c strtoIdd.c strtoIf.c strtoIg.c strtoIx.c strtoIxL.c\ - strtod.c strtodI.c strtodg.c strtodnrp.c strtof.c strtopQ.c strtopd.c\ - strtopdd.c strtopf.c strtopx.c strtopxL.c strtorQ.c strtord.c strtordd.c\ - strtorf.c strtorx.c strtorxL.c sum.c ulp.c +xs0 = README arithchk.c dmisc.c dtoa.c g_Qfmt.c g__fmt.c g_ddfmt.c\ + g_dfmt.c g_ffmt.c g_xLfmt.c g_xfmt.c gdtoa.c gdtoa.h\ + gdtoa_fltrnds.h gdtoaimp.h gethex.c gmisc.c hd_init.c hexnan.c\ + makefile misc.c printf.c printf.c0 qnan.c smisc.c stdio1.h\ + strtoIQ.c strtoId.c strtoIdd.c strtoIf.c strtoIg.c strtoIx.c\ + strtoIxL.c strtod.c strtodI.c strtodg.c strtodnrp.c strtof.c\ + strtopQ.c strtopd.c strtopdd.c strtopf.c strtopx.c strtopxL.c\ + strtorQ.c strtord.c strtordd.c strtorf.c strtorx.c strtorxL.c\ + sum.c ulp.c -# "make xsum.out" to check for transmission errors; source for xsum is +# "make -r xsum.out" to check for transmission errors; source for xsum is # netlib's "xsum.c from f2c", e.g., # ftp://netlib.bell-labs.com/netlib/f2c/xsum.c.gz @@ -73,4 +84,4 @@ xsum.out: xsum0.out $(xs0) cmp xsum0.out xsum1.out && mv xsum1.out xsum.out || diff xsum[01].out clean: - rm -f arith.h gd_qnan.h *.[ao] xsum.out xsum1.out + rm -f arith.h gd_qnan.h *.[ao] Printf xsum.out xsum1.out diff --git a/lib/libc/gdtoa/misc.c b/lib/libc/gdtoa/misc.c index 8ae13cce6..9f3d4c008 100644 --- a/lib/libc/gdtoa/misc.c +++ b/lib/libc/gdtoa/misc.c @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.5 2009/01/30 23:35:35 lukem Exp $ */ +/* $NetBSD: misc.c,v 1.11 2011/11/21 09:46:19 mlelstv Exp $ */ /**************************************************************** @@ -53,11 +53,13 @@ Balloc int x; Bigint *rv; #ifndef Omit_Private_Memory - unsigned int len; + size_t len; #endif ACQUIRE_DTOA_LOCK(0); - if ( (rv = freelist[k]) !=0) { + /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */ + /* but this case seems very unlikely. */ + if ((size_t)k <= Kmax && (rv = freelist[k]) !=0) { freelist[k] = rv->next; } else { @@ -67,15 +69,17 @@ Balloc #else len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) /sizeof(double); - if ((double *)(pmem_next - private_mem + len) <= (double *)PRIVATE_mem) { + if ((size_t)k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) { rv = (Bigint*)(void *)pmem_next; pmem_next += len; } else rv = (Bigint*)MALLOC(len*sizeof(double)); #endif - if (rv == NULL) + if (rv == NULL) { + FREE_DTOA_LOCK(0); return NULL; + } rv->k = k; rv->maxwds = x; } @@ -93,10 +97,18 @@ Bfree #endif { if (v) { - ACQUIRE_DTOA_LOCK(0); - v->next = freelist[v->k]; - freelist[v->k] = v; - FREE_DTOA_LOCK(0); + if ((size_t)v->k > Kmax) +#ifdef FREE + FREE((void*)v); +#else + free((void*)v); +#endif + else { + ACQUIRE_DTOA_LOCK(0); + v->next = freelist[v->k]; + freelist[v->k] = v; + FREE_DTOA_LOCK(0); + } } } @@ -405,8 +417,10 @@ pow5mult ACQUIRE_DTOA_LOCK(1); if (!(p5 = p5s)) { p5 = p5s = i2b(625); - if (p5 == NULL) + if (p5 == NULL) { + FREE_DTOA_LOCK(1); return NULL; + } p5->next = 0; } FREE_DTOA_LOCK(1); @@ -422,6 +436,7 @@ pow5mult b1 = mult(b, p5); if (b1 == NULL) return NULL; + Bfree(b); b = b1; } if (!(k = (unsigned int)k >> 1)) @@ -431,8 +446,10 @@ pow5mult ACQUIRE_DTOA_LOCK(1); if (!(p51 = p5->next)) { p51 = p5->next = mult(p5,p5); - if (p51 == NULL) + if (p51 == NULL) { + FREE_DTOA_LOCK(1); return NULL; + } p51->next = 0; } FREE_DTOA_LOCK(1); @@ -648,12 +665,12 @@ b2d { ULong *xa, *xa0, w, y, z; int k; - double d; + U d; #ifdef VAX ULong d0, d1; #else -#define d0 word0(d) -#define d1 word1(d) +#define d0 word0(&d) +#define d1 word1(&d) #endif xa0 = a->x; @@ -699,10 +716,10 @@ b2d #endif ret_d: #ifdef VAX - word0(d) = d0 >> 16 | d0 << 16; - word1(d) = d1 >> 16 | d1 << 16; + word0(&d) = d0 >> 16 | d0 << 16; + word1(&d) = d1 >> 16 | d1 << 16; #endif - return dval(d); + return dval(&d); } #undef d0 #undef d1 @@ -710,12 +727,13 @@ b2d Bigint * d2b #ifdef KR_headers - (d, e, bits) double d; int *e, *bits; + (dd, e, bits) double dd; int *e, *bits; #else - (double d, int *e, int *bits) + (double dd, int *e, int *bits) #endif { Bigint *b; + U d; #ifndef Sudden_Underflow int i; #endif @@ -723,11 +741,14 @@ d2b ULong *x, y, z; #ifdef VAX ULong d0, d1; - d0 = word0(d) >> 16 | word0(d) << 16; - d1 = word1(d) >> 16 | word1(d) << 16; #else -#define d0 word0(d) -#define d1 word1(d) +#define d0 word0(&d) +#define d1 word1(&d) +#endif + d.d = dd; +#ifdef VAX + d0 = word0(&d) >> 16 | word0(&d) << 16; + d1 = word1(&d) >> 16 | word1(&d) << 16; #endif #ifdef Pack_32 @@ -764,10 +785,6 @@ d2b b->wds = (x[1] = z) !=0 ? 2 : 1; } else { -#ifdef DEBUG - if (!z) - Bug("Zero passed to d2b"); -#endif k = lo0bits(&z); x[0] = z; #ifndef Sudden_Underflow @@ -826,7 +843,7 @@ d2b #endif #ifdef IBM *e = (de - Bias - (P-1) << 2) + k; - *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask); + *bits = 4*P + 8 - k - hi0bits(word0(&d) & Frac_mask); #else *e = de - Bias - (P-1) + k; *bits = P - k; diff --git a/lib/libc/gdtoa/smisc.c b/lib/libc/gdtoa/smisc.c index 349ff817a..27b9d6a8c 100644 --- a/lib/libc/gdtoa/smisc.c +++ b/lib/libc/gdtoa/smisc.c @@ -1,4 +1,4 @@ -/* $NetBSD: smisc.c,v 1.3 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: smisc.c,v 1.5 2012/03/13 21:13:34 christos Exp $ */ /**************************************************************** @@ -36,9 +36,9 @@ THIS SOFTWARE. Bigint * s2b #ifdef KR_headers - (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9; + (s, nd0, nd, y9, dplen) CONST char *s; int dplen, nd0, nd; ULong y9; #else - (CONST char *s, int nd0, int nd, ULong y9) + (CONST char *s, int nd0, int nd, ULong y9, size_t dplen) #endif { Bigint *b; @@ -64,15 +64,15 @@ s2b i = 9; if (9 < nd0) { s += 9; - do { + do { b = multadd(b, 10, *s++ - '0'); if (b == NULL) return NULL; } while(++i < nd0); - s++; + s += dplen; } else - s += 10; + s += dplen + 9; for(; i < nd; i++) { b = multadd(b, 10, *s++ - '0'); if (b == NULL) @@ -80,7 +80,6 @@ s2b } return b; } - double ratio #ifdef KR_headers @@ -89,33 +88,33 @@ ratio (Bigint *a, Bigint *b) #endif { - double da, db; + U da, db; int k, ka, kb; - dval(da) = b2d(a, &ka); - dval(db) = b2d(b, &kb); + dval(&da) = b2d(a, &ka); + dval(&db) = b2d(b, &kb); k = ka - kb + ULbits*(a->wds - b->wds); #ifdef IBM if (k > 0) { - word0(da) += (k >> 2)*Exp_msk1; + word0(&da) += (k >> 2)*Exp_msk1; if (k &= 3) - dval(da) *= 1 << k; + dval(&da) *= 1 << k; } else { k = -k; - word0(db) += (k >> 2)*Exp_msk1; + word0(&db) += (k >> 2)*Exp_msk1; if (k &= 3) - dval(db) *= 1 << k; + dval(&db) *= 1 << k; } #else if (k > 0) - word0(da) += k*Exp_msk1; + word0(&da) += k*Exp_msk1; else { k = -k; - word0(db) += k*Exp_msk1; + word0(&db) += k*Exp_msk1; } #endif - return dval(da) / dval(db); + return dval(&da) / dval(&db); } #ifdef INFNAN_CHECK diff --git a/lib/libc/gdtoa/strtoIg.c b/lib/libc/gdtoa/strtoIg.c index 20a4c1cbd..0dc3e36c7 100644 --- a/lib/libc/gdtoa/strtoIg.c +++ b/lib/libc/gdtoa/strtoIg.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtoIg.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtoIg.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -67,16 +67,20 @@ strtoIg(CONST char *s00, char **se, FPI *fpi, Long *exp, Bigint **B, int *rvp) if (rv & STRTOG_Inexlo) { swap = 0; b1 = increment(b1); - if (fpi->sudden_underflow - && (rv & STRTOG_Retmask) == STRTOG_Zero) { - b1->x[0] = 0; - b1->x[nw1] = 1L << nb11; - rv1 += STRTOG_Normal - STRTOG_Zero; - rv1 &= ~STRTOG_Underflow; + if ((rv & STRTOG_Retmask) == STRTOG_Zero) { + if (fpi->sudden_underflow) { + b1->x[0] = 0; + b1->x[nw1] = 1L << nb11; + rv1 += STRTOG_Normal - STRTOG_Zero; + rv1 &= ~STRTOG_Underflow; + goto swapcheck; + } + rv1 &= STRTOG_Inexlo | STRTOG_Underflow | STRTOG_Zero; + rv1 |= STRTOG_Inexhi | STRTOG_Denormal; goto swapcheck; } if (b1->wds > nw - || nb1 && b1->x[nw1] & 1L << nb1) { + || (nb1 && b1->x[nw1] & 1L << nb1)) { if (++e1 > fpi->emax) rv1 = STRTOG_Infinite | STRTOG_Inexhi; rshift(b1, 1); diff --git a/lib/libc/gdtoa/strtod.c b/lib/libc/gdtoa/strtod.c index b37119301..a01da8b2f 100644 --- a/lib/libc/gdtoa/strtod.c +++ b/lib/libc/gdtoa/strtod.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtod.c,v 1.5 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtod.c,v 1.11 2012/03/22 15:34:14 christos Exp $ */ /**************************************************************** @@ -44,16 +44,15 @@ THIS SOFTWARE. #ifndef NO_IEEE_Scale #define Avoid_Underflow #undef tinytens -/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */ +/* The factor of 2^106 in tinytens[4] helps us avoid setting the underflow */ /* flag unnecessarily. It leads to a song and dance at the end of strtod. */ static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, - 9007199254740992.e-256 + 9007199254740992.*9007199254740992.e-256 }; #endif #endif #ifdef Honor_FLT_ROUNDS -#define Rounding rounding #undef Check_FLT_ROUNDS #define Check_FLT_ROUNDS #else @@ -65,6 +64,28 @@ __strong_alias(_strtold, strtod) __weak_alias(strtold, _strtold) #endif +#ifdef Avoid_Underflow /*{*/ + static double +sulp +#ifdef KR_headers + (x, scale) U *x; int scale; +#else + (U *x, int scale) +#endif +{ + U u; + double rv; + int i; + + rv = ulp(x); + if (!scale || (i = 2*P + 1 - ((word0(x) & Exp_mask) >> Exp_shift)) <= 0) + return rv; /* Is there an example where i <= 0 ? */ + word0(&u) = Exp_1 + (i << Exp_shift); + word1(&u) = 0; + return rv * u.d; + } +#endif /*}*/ + double strtod #ifdef KR_headers @@ -76,23 +97,65 @@ strtod #ifdef Avoid_Underflow int scale; #endif - int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, dsign, +#ifdef INFNAN_CHECK + int decpt; +#endif + int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; CONST char *s, *s0, *s1; - double aadj, aadj1, adj, rv, rv0; + double aadj; Long L; + U adj, aadj1, rv, rv0; ULong y, z; Bigint *bb = NULL, *bb1, *bd0; Bigint *bd = NULL, *bs = NULL, *delta = NULL; /* pacify gcc */ +#ifdef Avoid_Underflow + ULong Lsb, Lsb1; +#endif #ifdef SET_INEXACT int inexact, oldinexact; #endif -#ifdef Honor_FLT_ROUNDS - int rounding; -#endif +#ifdef USE_LOCALE /*{{*/ +#ifdef NO_LOCALE_CACHE + char *decimalpoint = localeconv()->decimal_point; + size_t dplen = strlen(decimalpoint); +#else + char *decimalpoint; + static char *decimalpoint_cache; + static size_t dplen; + if (!(s0 = decimalpoint_cache)) { + s0 = localeconv()->decimal_point; + if ((decimalpoint_cache = MALLOC(strlen(s0) + 1)) != NULL) { + strcpy(decimalpoint_cache, s0); + s0 = decimalpoint_cache; + } + dplen = strlen(s0); + } + decimalpoint = __UNCONST(s0); +#endif /*NO_LOCALE_CACHE*/ +#else /*USE_LOCALE}{*/ +#define dplen 1 +#endif /*USE_LOCALE}}*/ + +#ifdef Honor_FLT_ROUNDS /*{*/ + int Rounding; +#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */ + Rounding = Flt_Rounds; +#else /*}{*/ + Rounding = 1; + switch(fegetround()) { + case FE_TOWARDZERO: Rounding = 0; break; + case FE_UPWARD: Rounding = 2; break; + case FE_DOWNWARD: Rounding = 3; + } +#endif /*}}*/ +#endif /*}*/ - sign = nz0 = nz = decpt = 0; - dval(rv) = 0.; +#ifdef INFNAN_CHECK + decpt = 0; +#endif + sign = nz0 = nz = 0; + dval(&rv) = 0.; for(s = s00;;s++) switch(*s) { case '-': sign = 1; @@ -115,7 +178,7 @@ strtod } break2: if (*s == '0') { -#ifndef NO_HEX_FP +#ifndef NO_HEX_FP /*{*/ { static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; Long expt; @@ -124,13 +187,9 @@ strtod case 'x': case 'X': { -#if defined(FE_DOWNWARD) && defined(FE_TONEAREST) && defined(FE_TOWARDZERO) && defined(FE_UPWARD) +#ifdef Honor_FLT_ROUNDS FPI fpi1 = fpi; - switch(fegetround()) { - case FE_TOWARDZERO: fpi1.rounding = 0; break; - case FE_UPWARD: fpi1.rounding = 2; break; - case FE_DOWNWARD: fpi1.rounding = 3; - } + fpi1.rounding = Rounding; #else #define fpi1 fpi #endif @@ -151,7 +210,7 @@ strtod goto ret; } } -#endif +#endif /*}*/ nz0 = 1; while(*++s == '0') ; if (!*s) @@ -166,13 +225,19 @@ strtod z = 10*z + c - '0'; nd0 = nd; #ifdef USE_LOCALE - if (c == *localeconv()->decimal_point) + if (c == *decimalpoint) { + for(i = 1; decimalpoint[i]; ++i) + if (s[i] != decimalpoint[i]) + goto dig_done; + s += i; + c = *s; #else - if (c == '.') + if (c == '.') { + c = *++s; #endif - { +#ifdef INFNAN_CHECK decpt = 1; - c = *++s; +#endif if (!nd) { for(; c == '0'; c = *++s) nz++; @@ -201,7 +266,7 @@ strtod nz = 0; } } - } + }/*}*/ dig_done: e = 0; if (c == 'e' || c == 'E') { @@ -256,8 +321,8 @@ strtod --s; if (!match(&s,"inity")) ++s; - word0(rv) = 0x7ff00000; - word1(rv) = 0; + word0(&rv) = 0x7ff00000; + word1(&rv) = 0; goto ret; } break; @@ -268,13 +333,13 @@ strtod if (*s == '(' /*)*/ && hexnan(&s, &fpinan, bits) == STRTOG_NaNbits) { - word0(rv) = 0x7ff00000 | bits[1]; - word1(rv) = bits[0]; + word0(&rv) = 0x7ff00000 | bits[1]; + word1(&rv) = bits[0]; } else { #endif - word0(rv) = NAN_WORD0; - word1(rv) = NAN_WORD1; + word0(&rv) = NAN_WORD0; + word1(&rv) = NAN_WORD1; #ifndef No_Hex_NaN } #endif @@ -298,13 +363,13 @@ strtod if (!nd0) nd0 = nd; k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; - dval(rv) = y; + dval(&rv) = y; if (k > 9) { #ifdef SET_INEXACT if (k > DBL_DIG) oldinexact = get_inexact(); #endif - dval(rv) = tens[k - 9] * dval(rv) + z; + dval(&rv) = tens[k - 9] * dval(&rv) + z; } bd0 = 0; if (nd <= DBL_DIG @@ -316,6 +381,7 @@ strtod ) { if (!e) goto ret; +#ifndef ROUND_BIASED_without_Round_Up if (e > 0) { if (e <= Ten_pmax) { #ifdef VAX @@ -324,11 +390,11 @@ strtod #ifdef Honor_FLT_ROUNDS /* round correctly FLT_ROUNDS = 2 or 3 */ if (sign) { - rv = -rv; + rv.d = -rv.d; sign = 0; } #endif - /* rv = */ rounded_product(dval(rv), tens[e]); + /* rv = */ rounded_product(dval(&rv), tens[e]); goto ret; #endif } @@ -340,25 +406,25 @@ strtod #ifdef Honor_FLT_ROUNDS /* round correctly FLT_ROUNDS = 2 or 3 */ if (sign) { - rv = -rv; + rv.d = -rv.d; sign = 0; } #endif e -= i; - dval(rv) *= tens[i]; + dval(&rv) *= tens[i]; #ifdef VAX /* VAX exponent range is so narrow we must * worry about overflow here... */ vax_ovfl_check: - word0(rv) -= P*Exp_msk1; - /* rv = */ rounded_product(dval(rv), tens[e]); - if ((word0(rv) & Exp_mask) + word0(&rv) -= P*Exp_msk1; + /* rv = */ rounded_product(dval(&rv), tens[e]); + if ((word0(&rv) & Exp_mask) > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) goto ovfl; - word0(rv) += P*Exp_msk1; + word0(&rv) += P*Exp_msk1; #else - /* rv = */ rounded_product(dval(rv), tens[e]); + /* rv = */ rounded_product(dval(&rv), tens[e]); #endif goto ret; } @@ -368,14 +434,15 @@ strtod #ifdef Honor_FLT_ROUNDS /* round correctly FLT_ROUNDS = 2 or 3 */ if (sign) { - rv = -rv; + rv.d = -rv.d; sign = 0; } #endif - /* rv = */ rounded_quotient(dval(rv), tens[-e]); + /* rv = */ rounded_quotient(dval(&rv), tens[-e]); goto ret; } #endif +#endif /* ROUND_BIASED_without_Round_Up */ } e1 += nd - k; @@ -389,12 +456,12 @@ strtod scale = 0; #endif #ifdef Honor_FLT_ROUNDS - if ((rounding = Flt_Rounds) >= 2) { + if (Rounding >= 2) { if (sign) - rounding = rounding == 2 ? 0 : 2; + Rounding = Rounding == 2 ? 0 : 2; else - if (rounding != 2) - rounding = 0; + if (Rounding != 2) + Rounding = 0; } #endif #endif /*IEEE_Arith*/ @@ -403,67 +470,73 @@ strtod if (e1 > 0) { if ( (i = e1 & 15) !=0) - dval(rv) *= tens[i]; + dval(&rv) *= tens[i]; if (e1 &= ~15) { if (e1 > DBL_MAX_10_EXP) { ovfl: -#ifndef NO_ERRNO - errno = ERANGE; -#endif /* Can't trust HUGE_VAL */ #ifdef IEEE_Arith #ifdef Honor_FLT_ROUNDS - switch(rounding) { + switch(Rounding) { case 0: /* toward 0 */ case 3: /* toward -infinity */ - word0(rv) = Big0; - word1(rv) = Big1; + word0(&rv) = Big0; + word1(&rv) = Big1; break; default: - word0(rv) = Exp_mask; - word1(rv) = 0; + word0(&rv) = Exp_mask; + word1(&rv) = 0; } #else /*Honor_FLT_ROUNDS*/ - word0(rv) = Exp_mask; - word1(rv) = 0; + word0(&rv) = Exp_mask; + word1(&rv) = 0; #endif /*Honor_FLT_ROUNDS*/ #ifdef SET_INEXACT /* set overflow bit */ - dval(rv0) = 1e300; - dval(rv0) *= dval(rv0); + dval(&rv0) = 1e300; + dval(&rv0) *= dval(&rv0); #endif #else /*IEEE_Arith*/ - word0(rv) = Big0; - word1(rv) = Big1; + word0(&rv) = Big0; + word1(&rv) = Big1; #endif /*IEEE_Arith*/ - if (bd0) - goto retfree; + range_err: + if (bd0) { + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(bd0); + Bfree(delta); + } +#ifndef NO_ERRNO + errno = ERANGE; +#endif goto ret; } e1 = (unsigned int)e1 >> 4; for(j = 0; e1 > 1; j++, e1 = (unsigned int)e1 >> 1) if (e1 & 1) - dval(rv) *= bigtens[j]; + dval(&rv) *= bigtens[j]; /* The last multiplication could overflow. */ - word0(rv) -= P*Exp_msk1; - dval(rv) *= bigtens[j]; - if ((z = word0(rv) & Exp_mask) + word0(&rv) -= P*Exp_msk1; + dval(&rv) *= bigtens[j]; + if ((z = word0(&rv) & Exp_mask) > Exp_msk1*(DBL_MAX_EXP+Bias-P)) goto ovfl; if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) { /* set to largest number */ /* (Can't trust DBL_MAX) */ - word0(rv) = Big0; - word1(rv) = Big1; + word0(&rv) = Big0; + word1(&rv) = Big1; } else - word0(rv) += P*Exp_msk1; + word0(&rv) += P*Exp_msk1; } } else if (e1 < 0) { e1 = -e1; if ( (i = e1 & 15) !=0) - dval(rv) /= tens[i]; + dval(&rv) /= tens[i]; if (e1 >>= 4) { if (e1 >= 1 << n_bigtens) goto undfl; @@ -472,44 +545,39 @@ strtod scale = 2*P; for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1) if (e1 & 1) - dval(rv) *= tinytens[j]; - if (scale && (j = 2*P + 1 - ((word0(rv) & Exp_mask) + dval(&rv) *= tinytens[j]; + if (scale && (j = 2*P + 1 - ((word0(&rv) & Exp_mask) >> Exp_shift)) > 0) { /* scaled rv is denormal; zap j low bits */ if (j >= 32) { - word1(rv) = 0; + word1(&rv) = 0; if (j >= 53) - word0(rv) = (P+2)*Exp_msk1; + word0(&rv) = (P+2)*Exp_msk1; else - word0(rv) &= 0xffffffff << (j-32); + word0(&rv) &= 0xffffffffU << (j-32); } else - word1(rv) &= 0xffffffff << j; + word1(&rv) &= 0xffffffffU << j; } #else - for(j = 0; e1 > 1; j++, e1 >>= 1) + for(j = 0; e1 > 1; j++, e1 = (unsigned int)e1 >> 1) if (e1 & 1) - dval(rv) *= tinytens[j]; + dval(&rv) *= tinytens[j]; /* The last multiplication could underflow. */ - dval(rv0) = dval(rv); - dval(rv) *= tinytens[j]; - if (!dval(rv)) { - dval(rv) = 2.*dval(rv0); - dval(rv) *= tinytens[j]; + dval(&rv0) = dval(&rv); + dval(&rv) *= tinytens[j]; + if (!dval(&rv)) { + dval(&rv) = 2.*dval(&rv0); + dval(&rv) *= tinytens[j]; #endif - if (!dval(rv)) { + if (!dval(&rv)) { undfl: - dval(rv) = 0.; -#ifndef NO_ERRNO - errno = ERANGE; -#endif - if (bd0) - goto retfree; - goto ret; + dval(&rv) = 0.; + goto range_err; } #ifndef Avoid_Underflow - word0(rv) = Tiny0; - word1(rv) = Tiny1; + word0(&rv) = Tiny0; + word1(&rv) = Tiny1; /* The refinement below will clean * this approximation up. */ @@ -522,7 +590,7 @@ strtod /* Put digits into bd: true value = bd * 10^e */ - bd0 = s2b(s0, nd0, nd, y); + bd0 = s2b(s0, nd0, nd, y, dplen); if (bd0 == NULL) goto ovfl; @@ -531,7 +599,7 @@ strtod if (bd == NULL) goto ovfl; Bcopy(bd, bd0); - bb = d2b(dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */ + bb = d2b(dval(&rv), &bbe, &bbbits); /* rv = bb * 2^bbe */ if (bb == NULL) goto ovfl; bs = i2b(1); @@ -552,16 +620,23 @@ strtod bd2 -= bbe; bs2 = bb2; #ifdef Honor_FLT_ROUNDS - if (rounding != 1) + if (Rounding != 1) bs2++; #endif #ifdef Avoid_Underflow + Lsb = LSB; + Lsb1 = 0; j = bbe - scale; i = j + bbbits - 1; /* logb(rv) */ - if (i < Emin) /* denormal */ - j += P - Emin; - else - j = P + 1 - bbbits; + j = P + 1 - bbbits; + if (i < Emin) { /* denormal */ + i = Emin - i; + j -= i; + if (i < 32) + Lsb <<= i; + else + Lsb1 = Lsb << (i-32); + } #else /*Avoid_Underflow*/ #ifdef Sudden_Underflow #ifdef IBM @@ -571,7 +646,7 @@ strtod #endif #else /*Sudden_Underflow*/ j = bbe; - i = j + bbbits - 1; /* logb(rv) */ + i = j + bbbits - 1; /* logb(&rv) */ if (i < Emin) /* denormal */ j += P - Emin; else @@ -628,7 +703,7 @@ strtod delta->sign = 0; i = cmp(delta, bs); #ifdef Honor_FLT_ROUNDS - if (rounding != 1) { + if (Rounding != 1) { if (i < 0) { /* Error is less than an ulp */ if (!delta->x[0] && delta->wds <= 1) { @@ -638,17 +713,17 @@ strtod #endif break; } - if (rounding) { + if (Rounding) { if (dsign) { - adj = 1.; + dval(&adj) = 1.; goto apply_adj; } } else if (!dsign) { - adj = -1.; - if (!word1(rv) - && !(word0(rv) & Frac_mask)) { - y = word0(rv) & Exp_mask; + dval(&adj) = -1.; + if (!word1(&rv) + && !(word0(&rv) & Frac_mask)) { + y = word0(&rv) & Exp_mask; #ifdef Avoid_Underflow if (!scale || y > 2*P*Exp_msk1) #else @@ -657,63 +732,66 @@ strtod { delta = lshift(delta,Log2P); if (cmp(delta, bs) <= 0) - adj = -0.5; + dval(&adj) = -0.5; } } apply_adj: #ifdef Avoid_Underflow - if (scale && (y = word0(rv) & Exp_mask) + if (scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1) - word0(adj) += (2*P+1)*Exp_msk1 - y; + word0(&adj) += (2*P+1)*Exp_msk1 - y; #else #ifdef Sudden_Underflow - if ((word0(rv) & Exp_mask) <= + if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) { - word0(rv) += P*Exp_msk1; - dval(rv) += adj*ulp(dval(rv)); - word0(rv) -= P*Exp_msk1; + word0(&rv) += P*Exp_msk1; + dval(&rv) += adj*ulp(&rv); + word0(&rv) -= P*Exp_msk1; } else #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ - dval(rv) += adj*ulp(dval(rv)); + dval(&rv) += adj.d*ulp(&rv); } break; } - adj = ratio(delta, bs); - if (adj < 1.) - adj = 1.; - if (adj <= 0x7ffffffe) { - /* adj = rounding ? ceil(adj) : floor(adj); */ - y = adj; - if (y != adj) { - if (!((rounding>>1) ^ dsign)) + dval(&adj) = ratio(delta, bs); + if (adj.d < 1.) + dval(&adj) = 1.; + if (adj.d <= 0x7ffffffe) { + /* dval(&adj) = Rounding ? ceil(&adj) : floor(&adj); */ + y = adj.d; + if (y != adj.d) { + if (!((Rounding>>1) ^ dsign)) y++; - adj = y; + dval(&adj) = y; } } #ifdef Avoid_Underflow - if (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1) - word0(adj) += (2*P+1)*Exp_msk1 - y; + if (scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1) + word0(&adj) += (2*P+1)*Exp_msk1 - y; #else #ifdef Sudden_Underflow - if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { - word0(rv) += P*Exp_msk1; - adj *= ulp(dval(rv)); + if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) { + word0(&rv) += P*Exp_msk1; + dval(&adj) *= ulp(&rv); if (dsign) - dval(rv) += adj; + dval(&rv) += adj; else - dval(rv) -= adj; - word0(rv) -= P*Exp_msk1; + dval(&rv) -= adj; + word0(&rv) -= P*Exp_msk1; goto cont; } #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ - adj *= ulp(dval(rv)); - if (dsign) - dval(rv) += adj; + dval(&adj) *= ulp(&rv); + if (dsign) { + if (word0(&rv) == Big0 && word1(&rv) == Big1) + goto ovfl; + dval(&rv) += adj.d; + } else - dval(rv) -= adj; + dval(&rv) -= adj.d; goto cont; } #endif /*Honor_FLT_ROUNDS*/ @@ -722,12 +800,12 @@ strtod /* Error is less than half an ulp -- check for * special case of mantissa a power of two. */ - if (dsign || word1(rv) || word0(rv) & Bndry_mask + if (dsign || word1(&rv) || word0(&rv) & Bndry_mask #ifdef IEEE_Arith #ifdef Avoid_Underflow - || (word0(rv) & Exp_mask) <= (2*P+1)*Exp_msk1 + || (word0(&rv) & Exp_mask) <= (2*P+1)*Exp_msk1 #else - || (word0(rv) & Exp_mask) <= Exp_msk1 + || (word0(&rv) & Exp_mask) <= Exp_msk1 #endif #endif ) { @@ -752,32 +830,34 @@ strtod if (i == 0) { /* exactly half-way between */ if (dsign) { - if ((word0(rv) & Bndry_mask1) == Bndry_mask1 - && word1(rv) == ( + if ((word0(&rv) & Bndry_mask1) == Bndry_mask1 + && word1(&rv) == ( #ifdef Avoid_Underflow - (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1) + (scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1) ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) : #endif 0xffffffff)) { /*boundary case -- increment exponent*/ - word0(rv) = (word0(rv) & Exp_mask) + if (word0(&rv) == Big0 && word1(&rv) == Big1) + goto ovfl; + word0(&rv) = (word0(&rv) & Exp_mask) + Exp_msk1 #ifdef IBM | Exp_msk1 >> 4 #endif ; - word1(rv) = 0; + word1(&rv) = 0; #ifdef Avoid_Underflow dsign = 0; #endif break; } } - else if (!(word0(rv) & Bndry_mask) && !word1(rv)) { + else if (!(word0(&rv) & Bndry_mask) && !word1(&rv)) { drop_down: /* boundary case -- decrement exponent */ #ifdef Sudden_Underflow /*{{*/ - L = word0(rv) & Exp_mask; + L = word0(&rv) & Exp_mask; #ifdef IBM if (L < Exp_msk1) #else @@ -792,7 +872,7 @@ strtod #else /*Sudden_Underflow}{*/ #ifdef Avoid_Underflow if (scale) { - L = word0(rv) & Exp_mask; + L = word0(&rv) & Exp_mask; if (L <= (2*P+1)*Exp_msk1) { if (L > (P+2)*Exp_msk1) /* round even ==> */ @@ -803,10 +883,10 @@ strtod } } #endif /*Avoid_Underflow*/ - L = (word0(rv) & Exp_mask) - Exp_msk1; -#endif /*Sudden_Underflow}*/ - word0(rv) = L | Bndry_mask1; - word1(rv) = 0xffffffff; + L = (word0(&rv) & Exp_mask) - Exp_msk1; +#endif /*Sudden_Underflow}}*/ + word0(&rv) = L | Bndry_mask1; + word1(&rv) = 0xffffffff; #ifdef IBM goto cont; #else @@ -814,16 +894,33 @@ strtod #endif } #ifndef ROUND_BIASED - if (!(word1(rv) & LSB)) +#ifdef Avoid_Underflow + if (Lsb1) { + if (!(word0(&rv) & Lsb1)) + break; + } + else if (!(word1(&rv) & Lsb)) + break; +#else + if (!(word1(&rv) & LSB)) break; +#endif #endif if (dsign) - dval(rv) += ulp(dval(rv)); +#ifdef Avoid_Underflow + dval(&rv) += sulp(&rv, scale); +#else + dval(&rv) += ulp(&rv); +#endif #ifndef ROUND_BIASED else { - dval(rv) -= ulp(dval(rv)); +#ifdef Avoid_Underflow + dval(&rv) -= sulp(&rv, scale); +#else + dval(&rv) -= ulp(&rv); +#endif #ifndef Sudden_Underflow - if (!dval(rv)) + if (!dval(&rv)) goto undfl; #endif } @@ -835,14 +932,14 @@ strtod } if ((aadj = ratio(delta, bs)) <= 2.) { if (dsign) - aadj = aadj1 = 1.; - else if (word1(rv) || word0(rv) & Bndry_mask) { + aadj = dval(&aadj1) = 1.; + else if (word1(&rv) || word0(&rv) & Bndry_mask) { #ifndef Sudden_Underflow - if (word1(rv) == Tiny1 && !word0(rv)) + if (word1(&rv) == Tiny1 && !word0(&rv)) goto undfl; #endif aadj = 1.; - aadj1 = -1.; + dval(&aadj1) = -1.; } else { /* special case -- power of FLT_RADIX to be */ @@ -852,45 +949,47 @@ strtod aadj = 1./FLT_RADIX; else aadj *= 0.5; - aadj1 = -aadj; + dval(&aadj1) = -aadj; } } else { aadj *= 0.5; - aadj1 = dsign ? aadj : -aadj; + dval(&aadj1) = dsign ? aadj : -aadj; #ifdef Check_FLT_ROUNDS + /* CONSTCOND */ switch(Rounding) { case 2: /* towards +infinity */ - aadj1 -= 0.5; + dval(&aadj1) -= 0.5; break; case 0: /* towards 0 */ case 3: /* towards -infinity */ - aadj1 += 0.5; + dval(&aadj1) += 0.5; } #else + /* CONSTCOND */ if (Flt_Rounds == 0) - aadj1 += 0.5; + dval(&aadj1) += 0.5; #endif /*Check_FLT_ROUNDS*/ } - y = word0(rv) & Exp_mask; + y = word0(&rv) & Exp_mask; /* Check for overflow */ if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { - dval(rv0) = dval(rv); - word0(rv) -= P*Exp_msk1; - adj = aadj1 * ulp(dval(rv)); - dval(rv) += adj; - if ((word0(rv) & Exp_mask) >= + dval(&rv0) = dval(&rv); + word0(&rv) -= P*Exp_msk1; + dval(&adj) = dval(&aadj1) * ulp(&rv); + dval(&rv) += dval(&adj); + if ((word0(&rv) & Exp_mask) >= Exp_msk1*(DBL_MAX_EXP+Bias-P)) { - if (word0(rv0) == Big0 && word1(rv0) == Big1) + if (word0(&rv0) == Big0 && word1(&rv0) == Big1) goto ovfl; - word0(rv) = Big0; - word1(rv) = Big1; + word0(&rv) = Big0; + word1(&rv) = Big1; goto cont; } else - word0(rv) += P*Exp_msk1; + word0(&rv) += P*Exp_msk1; } else { #ifdef Avoid_Underflow @@ -899,58 +998,58 @@ strtod if ((z = aadj) == 0) z = 1; aadj = z; - aadj1 = dsign ? aadj : -aadj; + dval(&aadj1) = dsign ? aadj : -aadj; } - word0(aadj1) += (2*P+1)*Exp_msk1 - y; + word0(&aadj1) += (2*P+1)*Exp_msk1 - y; } - adj = aadj1 * ulp(dval(rv)); - dval(rv) += adj; + dval(&adj) = dval(&aadj1) * ulp(&rv); + dval(&rv) += dval(&adj); #else #ifdef Sudden_Underflow - if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { - dval(rv0) = dval(rv); - word0(rv) += P*Exp_msk1; - adj = aadj1 * ulp(dval(rv)); - dval(rv) += adj; + if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) { + dval(&rv0) = dval(&rv); + word0(&rv) += P*Exp_msk1; + dval(&adj) = dval(&aadj1) * ulp(&rv); + dval(&rv) += dval(&adj); #ifdef IBM - if ((word0(rv) & Exp_mask) < P*Exp_msk1) + if ((word0(&rv) & Exp_mask) < P*Exp_msk1) #else - if ((word0(rv) & Exp_mask) <= P*Exp_msk1) + if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) #endif { - if (word0(rv0) == Tiny0 - && word1(rv0) == Tiny1) + if (word0(&rv0) == Tiny0 + && word1(&rv0) == Tiny1) goto undfl; - word0(rv) = Tiny0; - word1(rv) = Tiny1; + word0(&rv) = Tiny0; + word1(&rv) = Tiny1; goto cont; } else - word0(rv) -= P*Exp_msk1; + word0(&rv) -= P*Exp_msk1; } else { - adj = aadj1 * ulp(dval(rv)); - dval(rv) += adj; + dval(&adj) = dval(&aadj1) * ulp(&rv); + dval(&rv) += dval(&adj); } #else /*Sudden_Underflow*/ - /* Compute adj so that the IEEE rounding rules will - * correctly round rv + adj in some half-way cases. - * If rv * ulp(rv) is denormalized (i.e., + /* Compute dval(&adj) so that the IEEE rounding rules will + * correctly round rv + dval(&adj) in some half-way cases. + * If rv * ulp(&rv) is denormalized (i.e., * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid * trouble from bits lost to denormalization; * example: 1.2e-307 . */ if (y <= (P-1)*Exp_msk1 && aadj > 1.) { - aadj1 = (double)(int)(aadj + 0.5); + dval(&aadj1) = (double)(int)(aadj + 0.5); if (!dsign) - aadj1 = -aadj1; + dval(&aadj1) = -dval(&aadj1); } - adj = aadj1 * ulp(dval(rv)); - dval(rv) += adj; + dval(&adj) = dval(&aadj1) * ulp(&rv); + dval(&rv) += adj; #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ } - z = word0(rv) & Exp_mask; + z = word0(&rv) & Exp_mask; #ifndef SET_INEXACT #ifdef Avoid_Underflow if (!scale) @@ -960,7 +1059,7 @@ strtod L = (Long)aadj; aadj -= L; /* The tolerances below are conservative. */ - if (dsign || word1(rv) || word0(rv) & Bndry_mask) { + if (dsign || word1(&rv) || word0(&rv) & Bndry_mask) { if (aadj < .4999999 || aadj > .5000001) break; } @@ -974,12 +1073,17 @@ strtod Bfree(bs); Bfree(delta); } + Bfree(bb); + Bfree(bd); + Bfree(bs); + Bfree(bd0); + Bfree(delta); #ifdef SET_INEXACT if (inexact) { if (!oldinexact) { - word0(rv0) = Exp_1 + (70 << Exp_shift); - word1(rv0) = 0; - dval(rv0) += 1.; + word0(&rv0) = Exp_1 + (70 << Exp_shift); + word1(&rv0) = 0; + dval(&rv0) += 1.; } } else if (!oldinexact) @@ -987,32 +1091,30 @@ strtod #endif #ifdef Avoid_Underflow if (scale) { - word0(rv0) = Exp_1 - 2*P*Exp_msk1; - word1(rv0) = 0; - dval(rv) *= dval(rv0); + word0(&rv0) = Exp_1 - 2*P*Exp_msk1; + word1(&rv0) = 0; + dval(&rv) *= dval(&rv0); #ifndef NO_ERRNO /* try to avoid the bug of testing an 8087 register value */ - if (word0(rv) == 0 && word1(rv) == 0) +#ifdef IEEE_Arith + if (!(word0(&rv) & Exp_mask)) +#else + if (word0(&rv) == 0 && word1(&rv) == 0) +#endif errno = ERANGE; #endif } #endif /* Avoid_Underflow */ #ifdef SET_INEXACT - if (inexact && !(word0(rv) & Exp_mask)) { + if (inexact && !(word0(&rv) & Exp_mask)) { /* set underflow bit */ - dval(rv0) = 1e-300; - dval(rv0) *= dval(rv0); + dval(&rv0) = 1e-300; + dval(&rv0) *= dval(&rv0); } #endif - retfree: - Bfree(bb); - Bfree(bd); - Bfree(bs); - Bfree(bd0); - Bfree(delta); ret: if (se) *se = __UNCONST(s); - return sign ? -dval(rv) : dval(rv); + return sign ? -dval(&rv) : dval(&rv); } diff --git a/lib/libc/gdtoa/strtodI.c b/lib/libc/gdtoa/strtodI.c index 2631d5cbf..54b96a839 100644 --- a/lib/libc/gdtoa/strtodI.c +++ b/lib/libc/gdtoa/strtodI.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtodI.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtodI.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -35,16 +35,16 @@ THIS SOFTWARE. static double #ifdef KR_headers -ulpdown(d) double *d; +ulpdown(d) U *d; #else -ulpdown(double *d) +ulpdown(U *d) #endif { double u; - ULong *L = (ULong*)d; + ULong *L = d->L; - u = ulp(*d); - if (!(L[_1] | L[_0] & 0xfffff) + u = ulp(d); + if (!(L[_1] | (L[_0] & 0xfffff)) && (L[_0] & 0x7ff00000) > 0x00100000) u *= 0.5; return u; @@ -61,10 +61,6 @@ strtodI(CONST char *s, char **sp, double *dd) ULong bits[2], sign; Long exp; int j, k; - typedef union { - double d[2]; - ULong L[4]; - } U; U *u; k = strtodg(s, sp, &fpi, &exp, bits); @@ -74,17 +70,17 @@ strtodI(CONST char *s, char **sp, double *dd) sign = k & STRTOG_Neg ? 0x80000000L : 0; switch(k & STRTOG_Retmask) { case STRTOG_NoNumber: - u->d[0] = u->d[1] = 0.; + dval(&u[0]) = dval(&u[1]) = 0.; break; case STRTOG_Zero: - u->d[0] = u->d[1] = 0.; + dval(&u[0]) = dval(&u[1]) = 0.; #ifdef Sudden_Underflow if (k & STRTOG_Inexact) { if (sign) - u->L[_0] = 0x80100000L; + word0(&u[0]) = 0x80100000L; else - u->L[2+_0] = 0x100000L; + word0(&u[1]) = 0x100000L; } break; #else @@ -92,80 +88,80 @@ strtodI(CONST char *s, char **sp, double *dd) #endif case STRTOG_Denormal: - u->L[_1] = bits[0]; - u->L[_0] = bits[1]; + word1(&u[0]) = bits[0]; + word0(&u[0]) = bits[1]; goto contain; case STRTOG_Normal: - u->L[_1] = bits[0]; - u->L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20); + word1(&u[0]) = bits[0]; + word0(&u[0]) = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20); contain: j = k & STRTOG_Inexact; if (sign) { - u->L[_0] |= sign; + word0(&u[0]) |= sign; j = STRTOG_Inexact - j; } switch(j) { case STRTOG_Inexlo: #ifdef Sudden_Underflow if ((u->L[_0] & 0x7ff00000) < 0x3500000) { - u->L[2+_0] = u->L[_0] + 0x3500000; - u->L[2+_1] = u->L[_1]; - u->d[1] += ulp(u->d[1]); - u->L[2+_0] -= 0x3500000; - if (!(u->L[2+_0] & 0x7ff00000)) { - u->L[2+_0] = sign; - u->L[2+_1] = 0; + word0(&u[1]) = word0(&u[0]) + 0x3500000; + word1(&u[1]) = word1(&u[0]); + dval(&u[1]) += ulp(&u[1]); + word0(&u[1]) -= 0x3500000; + if (!(word0(&u[1]) & 0x7ff00000)) { + word0(&u[1]) = sign; + word1(&u[1]) = 0; } } else #endif - u->d[1] = u->d[0] + ulp(u->d[0]); + dval(&u[1]) = dval(&u[0]) + ulp(&u[0]); break; case STRTOG_Inexhi: - u->d[1] = u->d[0]; + dval(&u[1]) = dval(&u[0]); #ifdef Sudden_Underflow - if ((u->L[_0] & 0x7ff00000) < 0x3500000) { - u->L[_0] += 0x3500000; - u->d[0] -= ulpdown(u->d); - u->L[_0] -= 0x3500000; - if (!(u->L[_0] & 0x7ff00000)) { - u->L[_0] = sign; - u->L[_1] = 0; + if ((word0(&u[0]) & 0x7ff00000) < 0x3500000) { + word0(&u[0]) += 0x3500000; + dval(&u[0]) -= ulpdown(u); + word0(&u[0]) -= 0x3500000; + if (!(word0(&u[0]) & 0x7ff00000)) { + word0(&u[0]) = sign; + word1(&u[0]) = 0; } } else #endif - u->d[0] -= ulpdown(u->d); + dval(&u[0]) -= ulpdown(u); break; default: - u->d[1] = u->d[0]; + dval(&u[1]) = dval(&u[0]); } break; case STRTOG_Infinite: - u->L[_0] = u->L[2+_0] = sign | 0x7ff00000; - u->L[_1] = u->L[2+_1] = 0; + word0(&u[0]) = word0(&u[1]) = sign | 0x7ff00000; + word1(&u[0]) = word1(&u[1]) = 0; if (k & STRTOG_Inexact) { if (sign) { - u->L[2+_0] = 0xffefffffL; - u->L[2+_1] = 0xffffffffL; + word0(&u[1]) = 0xffefffffL; + word1(&u[1]) = 0xffffffffL; } else { - u->L[_0] = 0x7fefffffL; - u->L[_1] = 0xffffffffL; + word0(&u[0]) = 0x7fefffffL; + word1(&u[0]) = 0xffffffffL; } } break; case STRTOG_NaN: - u->L[0] = u->L[2] = d_QNAN0; - u->L[1] = u->L[3] = d_QNAN1; + u->L[0] = (u+1)->L[0] = d_QNAN0; + u->L[1] = (u+1)->L[1] = d_QNAN1; break; case STRTOG_NaNbits: - u->L[_0] = u->L[2+_0] = 0x7ff00000 | sign | bits[1]; - u->L[_1] = u->L[2+_1] = bits[0]; + word0(&u[0]) = word0(&u[1]) = 0x7ff00000 | sign | bits[1]; + word1(&u[0]) = word1(&u[1]) = bits[0]; } return k; } diff --git a/lib/libc/gdtoa/strtodg.c b/lib/libc/gdtoa/strtodg.c index 3b3c7be7f..c8f807c40 100644 --- a/lib/libc/gdtoa/strtodg.c +++ b/lib/libc/gdtoa/strtodg.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtodg.c,v 1.6 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtodg.c,v 1.10 2012/03/22 13:09:12 he Exp $ */ /**************************************************************** @@ -37,14 +37,13 @@ THIS SOFTWARE. #include "locale.h" #endif +#ifndef VAX static CONST int fivesbits[] = { 0, 3, 5, 7, 10, 12, 14, 17, 19, 21, 24, 26, 28, 31, 33, 35, 38, 40, 42, 45, 47, 49, 52 -#ifdef VAX - , 54, 56 -#endif }; +#endif Bigint * #ifdef KR_headers @@ -93,7 +92,7 @@ increment(Bigint *b) return b; } - int + void #ifdef KR_headers decrement(b) Bigint *b; #else @@ -123,7 +122,6 @@ decrement(Bigint *b) *x++ = y & 0xffff; } while(borrow && x < xe); #endif - return STRTOG_Inexlo; } static int @@ -179,9 +177,9 @@ set_ones(Bigint *b, int n) rvOK #ifdef KR_headers (d, fpi, expt, bits, exact, rd, irv) - double d; CONST FPI *fpi; Long *expt; ULong *bits; int exact, rd, *irv; + U *d; CONST FPI *fpi; Long *expt; ULong *bits; int exact, rd, *irv; #else - (double d, CONST FPI *fpi, Long *expt, ULong *bits, int exact, int rd, int *irv) + (U *d, CONST FPI *fpi, Long *expt, ULong *bits, int exact, int rd, int *irv) #endif { Bigint *b; @@ -189,7 +187,7 @@ rvOK int bdif, e, j, k, k1, nb, rv; carry = rv = 0; - b = d2b(d, &e, &bdif); + b = d2b(dval(d), &e, &bdif); bdif -= nb = fpi->nbits; e += bdif; if (bdif <= 0) { @@ -212,9 +210,9 @@ rvOK goto ret; } switch(rd) { - case 1: + case 1: /* round down (toward -Infinity) */ goto trunc; - case 2: + case 2: /* round up (toward +Infinity) */ break; default: /* round near */ k = bdif - 1; @@ -298,9 +296,9 @@ rvOK #ifndef VAX static int #ifdef KR_headers -mantbits(d) double d; +mantbits(d) U *d; #else -mantbits(double d) +mantbits(U *d) #endif { ULong L; @@ -330,21 +328,46 @@ strtodg #endif { int abe, abits, asub; - int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm; +#ifdef INFNAN_CHECK + int decpt; +#endif + int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, denorm; int dsign, e, e1, e2, emin, esign, finished, i, inex, irv; int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign; int sudden_underflow = 0; /* pacify gcc */ CONST char *s, *s0, *s1; - double adj, adj0, rv, tol; + double adj0, tol; Long L; - ULong y, z; + U adj, rv; + ULong *b, *be, y, z; Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0; +#ifdef USE_LOCALE /*{{*/ +#ifdef NO_LOCALE_CACHE + char *decimalpoint = localeconv()->decimal_point; + size_t dplen = strlen(decimalpoint); +#else + char *decimalpoint; + static char *decimalpoint_cache; + static size_t dplen; + if (!(s0 = decimalpoint_cache)) { + s0 = localeconv()->decimal_point; + if ((decimalpoint_cache = MALLOC(strlen(s0) + 1)) != NULL) { + strcpy(decimalpoint_cache, s0); + s0 = decimalpoint_cache; + } + dplen = strlen(s0); + } + decimalpoint = __UNCONST(s0); +#endif /*NO_LOCALE_CACHE*/ +#else /*USE_LOCALE}{*/ +#define dplen 1 +#endif /*USE_LOCALE}}*/ e2 = 0; /* XXX gcc */ irv = STRTOG_Zero; denorm = sign = nz0 = nz = 0; - dval(rv) = 0.; + dval(&rv) = 0.; rvb = 0; nbits = fpi->nbits; for(s = s00;;s++) switch(*s) { @@ -392,20 +415,29 @@ strtodg sudden_underflow = fpi->sudden_underflow; s0 = s; y = z = 0; - for(decpt = nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) +#ifdef INFNAN_CHECK + decpt = 0; +#endif + for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) if (nd < 9) y = 10*y + c - '0'; else if (nd < 16) z = 10*z + c - '0'; nd0 = nd; #ifdef USE_LOCALE - if (c == *localeconv()->decimal_point) + if (c == *decimalpoint) { + for(i = 1; decimalpoint[i]; ++i) + if (s[i] != decimalpoint[i]) + goto dig_done; + s += i; + c = *s; #else - if (c == '.') + if (c == '.') { + c = *++s; #endif - { +#ifdef INFNAN_CHECK decpt = 1; - c = *++s; +#endif if (!nd) { for(; c == '0'; c = *++s) nz++; @@ -434,7 +466,7 @@ strtodg nz = 0; } } - } + }/*}*/ dig_done: e = 0; if (c == 'e' || c == 'E') { @@ -533,13 +565,13 @@ strtodg if (!nd0) nd0 = nd; k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; - dval(rv) = y; + dval(&rv) = y; if (k > 9) - dval(rv) = tens[k - 9] * dval(rv) + z; + dval(&rv) = tens[k - 9] * dval(&rv) + z; bd0 = 0; if (nbits <= P && nd <= DBL_DIG) { if (!e) { - if (rvOK(dval(rv), fpi, expt, bits, 1, rd, &irv)) + if (rvOK(&rv, fpi, expt, bits, 1, rd, &irv)) goto ret; } else if (e > 0) { @@ -547,9 +579,9 @@ strtodg #ifdef VAX goto vax_ovfl_check; #else - i = fivesbits[e] + mantbits(dval(rv)) <= P; - /* rv = */ rounded_product(dval(rv), tens[e]); - if (rvOK(dval(rv), fpi, expt, bits, i, rd, &irv)) + i = fivesbits[e] + mantbits(&rv) <= P; + /* rv = */ rounded_product(dval(&rv), tens[e]); + if (rvOK(&rv, fpi, expt, bits, i, rd, &irv)) goto ret; e1 -= e; goto rv_notOK; @@ -562,32 +594,32 @@ strtodg */ e2 = e - i; e1 -= i; - dval(rv) *= tens[i]; + dval(&rv) *= tens[i]; #ifdef VAX /* VAX exponent range is so narrow we must * worry about overflow here... */ vax_ovfl_check: - dval(adj) = dval(rv); - word0(adj) -= P*Exp_msk1; - /* adj = */ rounded_product(dval(adj), tens[e2]); - if ((word0(adj) & Exp_mask) + dval(&adj) = dval(&rv); + word0(&adj) -= P*Exp_msk1; + /* adj = */ rounded_product(dval(&adj), tens[e2]); + if ((word0(&adj) & Exp_mask) > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) goto rv_notOK; - word0(adj) += P*Exp_msk1; - dval(rv) = dval(adj); + word0(&adj) += P*Exp_msk1; + dval(&rv) = dval(&adj); #else - /* rv = */ rounded_product(dval(rv), tens[e2]); + /* rv = */ rounded_product(dval(&rv), tens[e2]); #endif - if (rvOK(dval(rv), fpi, expt, bits, 0, rd, &irv)) + if (rvOK(&rv, fpi, expt, bits, 0, rd, &irv)) goto ret; e1 -= e2; } } #ifndef Inaccurate_Divide else if (e >= -Ten_pmax) { - /* rv = */ rounded_quotient(dval(rv), tens[-e]); - if (rvOK(dval(rv), fpi, expt, bits, 0, rd, &irv)) + /* rv = */ rounded_quotient(dval(&rv), tens[-e]); + if (rvOK(&rv, fpi, expt, bits, 0, rd, &irv)) goto ret; e1 -= e; } @@ -601,45 +633,45 @@ strtodg e2 = 0; if (e1 > 0) { if ( (i = e1 & 15) !=0) - dval(rv) *= tens[i]; + dval(&rv) *= tens[i]; if (e1 &= ~15) { e1 = (unsigned int)e1 >> 4; while(e1 >= (1 << (n_bigtens-1))) { - e2 += ((word0(rv) & Exp_mask) + e2 += ((word0(&rv) & Exp_mask) >> Exp_shift1) - Bias; - word0(rv) &= ~Exp_mask; - word0(rv) |= Bias << Exp_shift1; - dval(rv) *= bigtens[n_bigtens-1]; + word0(&rv) &= ~Exp_mask; + word0(&rv) |= Bias << Exp_shift1; + dval(&rv) *= bigtens[n_bigtens-1]; e1 -= 1 << (n_bigtens-1); } - e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias; - word0(rv) &= ~Exp_mask; - word0(rv) |= Bias << Exp_shift1; + e2 += ((word0(&rv) & Exp_mask) >> Exp_shift1) - Bias; + word0(&rv) &= ~Exp_mask; + word0(&rv) |= Bias << Exp_shift1; for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1) if (e1 & 1) - dval(rv) *= bigtens[j]; + dval(&rv) *= bigtens[j]; } } else if (e1 < 0) { e1 = -e1; if ( (i = e1 & 15) !=0) - dval(rv) /= tens[i]; + dval(&rv) /= tens[i]; if (e1 &= ~15) { e1 = (unsigned int)e1 >> 4; while(e1 >= (1 << (n_bigtens-1))) { - e2 += ((word0(rv) & Exp_mask) + e2 += ((word0(&rv) & Exp_mask) >> Exp_shift1) - Bias; - word0(rv) &= ~Exp_mask; - word0(rv) |= Bias << Exp_shift1; - dval(rv) *= tinytens[n_bigtens-1]; + word0(&rv) &= ~Exp_mask; + word0(&rv) |= Bias << Exp_shift1; + dval(&rv) *= tinytens[n_bigtens-1]; e1 -= 1 << (n_bigtens-1); } - e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias; - word0(rv) &= ~Exp_mask; - word0(rv) |= Bias << Exp_shift1; + e2 += ((word0(&rv) & Exp_mask) >> Exp_shift1) - Bias; + word0(&rv) &= ~Exp_mask; + word0(&rv) |= Bias << Exp_shift1; for(j = 0; e1 > 0; j++, e1 = (unsigned int)e1 >> 1) if (e1 & 1) - dval(rv) *= tinytens[j]; + dval(&rv) *= tinytens[j]; } } #ifdef IBM @@ -650,7 +682,7 @@ strtodg */ e2 <<= 2; #endif - rvb = d2b(dval(rv), &rve, &rvbits); /* rv = rvb * 2^rve */ + rvb = d2b(dval(&rv), &rve, &rvbits); /* rv = rvb * 2^rve */ if (rvb == NULL) return STRTOG_NoMemory; rve += e2; @@ -696,7 +728,7 @@ strtodg /* Put digits into bd: true value = bd * 10^e */ - bd0 = s2b(s0, nd0, nd, y); + bd0 = s2b(s0, nd0, nd, y, dplen); for(;;) { bd = Balloc(bd0->k); @@ -866,11 +898,8 @@ strtodg rvb = increment(rvb); if (rvb == NULL) return STRTOG_NoMemory; - if ( (j = rvbits & kmask) !=0) - j = ULbits - j; - if (hi0bits(rvb->x[(unsigned int)(rvb->wds - 1) - >> kshift]) - != j) + j = kmask & (ULbits - (rvbits & kmask)); + if (hi0bits(rvb->x[rvb->wds - 1]) != j) rvbits++; irv = STRTOG_Normal | STRTOG_Inexhi; } @@ -882,7 +911,7 @@ strtodg } break; } - if ((dval(adj) = ratio(delta, bs)) <= 2.) { + if ((dval(&adj) = ratio(delta, bs)) <= 2.) { adj1: inex = STRTOG_Inexlo; if (dsign) { @@ -896,15 +925,15 @@ strtodg irv = STRTOG_Underflow | STRTOG_Inexlo; break; } - adj0 = dval(adj) = 1.; + adj0 = dval(&adj) = 1.; } else { - adj0 = dval(adj) *= 0.5; + adj0 = dval(&adj) *= 0.5; if (dsign) { asub = 0; inex = STRTOG_Inexlo; } - if (dval(adj) < 2147483647.) { + if (dval(&adj) < 2147483647.) { L = adj0; adj0 -= L; switch(rd) { @@ -923,12 +952,12 @@ strtodg inex = STRTOG_Inexact - inex; } } - dval(adj) = L; + dval(&adj) = L; } } y = rve + rvbits; - /* adj *= ulp(dval(rv)); */ + /* adj *= ulp(dval(&rv)); */ /* if (asub) rv -= adj; else rv += adj; */ if (!denorm && rvbits < nbits) { @@ -938,7 +967,7 @@ strtodg rve -= j; rvbits = nbits; } - ab = d2b(dval(adj), &abe, &abits); + ab = d2b(dval(&adj), &abe, &abits); if (ab == NULL) return STRTOG_NoMemory; if (abe < 0) @@ -1000,15 +1029,15 @@ strtodg z = rve + rvbits; if (y == z && L) { /* Can we stop now? */ - tol = dval(adj) * 5e-16; /* > max rel error */ - dval(adj) = adj0 - .5; - if (dval(adj) < -tol) { + tol = dval(&adj) * 5e-16; /* > max rel error */ + dval(&adj) = adj0 - .5; + if (dval(&adj) < -tol) { if (adj0 > tol) { irv |= inex; break; } } - else if (dval(adj) > tol && adj0 < 1. - tol) { + else if (dval(&adj) > tol && adj0 < 1. - tol) { irv |= inex; break; } @@ -1033,6 +1062,29 @@ strtodg Bfree(bd0); Bfree(delta); if (rve > fpi->emax) { + switch(fpi->rounding & 3) { + case FPI_Round_near: + goto huge; + case FPI_Round_up: + if (!sign) + goto huge; + break; + case FPI_Round_down: + if (sign) + goto huge; + } + /* Round to largest representable magnitude */ + Bfree(rvb); + rvb = 0; + irv = STRTOG_Normal | STRTOG_Inexlo; + *expt = fpi->emax; + b = bits; + be = b + ((unsigned int)(fpi->nbits + 31) >> 5); + while(b < be) + *b++ = (unsigned int)-1; + if ((j = fpi->nbits & 0x1f) != 0) + *--be >>= (32 - j); + goto ret; huge: rvb->wds = 0; irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi; @@ -1049,12 +1101,19 @@ strtodg if (sudden_underflow) { rvb->wds = 0; irv = STRTOG_Underflow | STRTOG_Inexlo; +#ifndef NO_ERRNO + errno = ERANGE; +#endif } else { irv = (irv & ~STRTOG_Retmask) | (rvb->wds > 0 ? STRTOG_Denormal : STRTOG_Zero); - if (irv & STRTOG_Inexact) + if (irv & STRTOG_Inexact) { irv |= STRTOG_Underflow; +#ifndef NO_ERRNO + errno = ERANGE; +#endif + } } } if (se) diff --git a/lib/libc/gdtoa/strtodnrp.c b/lib/libc/gdtoa/strtodnrp.c index cc448bfd1..1c5dc7242 100644 --- a/lib/libc/gdtoa/strtodnrp.c +++ b/lib/libc/gdtoa/strtodnrp.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtodnrp.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtodnrp.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -46,13 +46,13 @@ strtod(s, sp) CONST char *s; char **sp; strtod(CONST char *s, char **sp) #endif { - static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; + static const FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; ULong bits[2]; - Long exp; + Long expt; int k; union { ULong L[2]; double d; } u; - k = strtodg(s, sp, &fpi, &exp, bits); + k = strtodg(s, sp, &fpi, &expt, bits); if (k == STRTOG_NoMemory) { errno = ERANGE; u.L[0] = Big0; @@ -67,7 +67,7 @@ strtod(CONST char *s, char **sp) case STRTOG_Normal: u.L[_1] = bits[0]; - u.L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20); + u.L[_0] = (bits[1] & ~0x100000) | ((expt + 0x3ff + 52) << 20); break; case STRTOG_Denormal: diff --git a/lib/libc/gdtoa/strtof.c b/lib/libc/gdtoa/strtof.c index fb07ff698..bee802fff 100644 --- a/lib/libc/gdtoa/strtof.c +++ b/lib/libc/gdtoa/strtof.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtof.c,v 1.3 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtof.c,v 1.5 2011/06/20 09:11:17 mrg Exp $ */ /**************************************************************** @@ -45,13 +45,18 @@ strtof(s, sp) CONST char *s; char **sp; strtof(CONST char *s, char **sp) #endif { - static CONST FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; + static CONST FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; ULong bits[1]; Long expt; int k; union { ULong L[1]; float f; } u; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif - k = strtodg(s, sp, &fpi, &expt, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) { errno = ERANGE; return HUGE_VALF; @@ -77,6 +82,11 @@ strtof(CONST char *s, char **sp) case STRTOG_NaN: u.L[0] = f_QNAN; + break; + + default: + u.L[0] = 0; /* for gcc warning */ + break; } if (k & STRTOG_Neg) u.L[0] |= 0x80000000L; diff --git a/lib/libc/gdtoa/strtof_vaxf.c b/lib/libc/gdtoa/strtof_vaxf.c index 3710e62f4..c94087829 100644 --- a/lib/libc/gdtoa/strtof_vaxf.c +++ b/lib/libc/gdtoa/strtof_vaxf.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtof_vaxf.c,v 1.5 2008/03/28 00:56:54 he Exp $ */ +/* $NetBSD: strtof_vaxf.c,v 1.6 2011/07/01 03:20:06 matt Exp $ */ /**************************************************************** @@ -56,14 +56,13 @@ strtof(CONST char *s, char **sp) k = strtodg(s, sp, &fpi, &expt, bits); if (k == STRTOG_NoMemory) { errno = ERANGE; - u.L[0] = Big0; - u.L[1] = Big1; - return u.f; + return HUGE_VALF; } switch(k & STRTOG_Retmask) { case STRTOG_NoNumber: case STRTOG_Zero: - u.L[0] = 0; + default: + u.f = 0.0; break; case STRTOG_Normal: @@ -73,11 +72,11 @@ strtof(CONST char *s, char **sp) break; case STRTOG_Infinite: - u.L[0] = 0xffff7fff; + u.f = HUGE_VALF; break; } if (k & STRTOG_Neg) u.L[0] |= 0x00008000L; return u.f; - } +} diff --git a/lib/libc/gdtoa/strtopQ.c b/lib/libc/gdtoa/strtopQ.c index 2fd7ec553..bd5308b7b 100644 --- a/lib/libc/gdtoa/strtopQ.c +++ b/lib/libc/gdtoa/strtopQ.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtopQ.c,v 1.4 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtopQ.c,v 1.5 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -58,13 +58,18 @@ strtopQ(s, sp, V) CONST char *s; char **sp; void *V; strtopQ(CONST char *s, char **sp, void *V) #endif { - static CONST FPI fpi = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, SI }; + static CONST FPI fpi0 = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, SI }; ULong bits[4]; Long expt; int k; ULong *L = (ULong*)V; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif - k = strtodg(s, sp, &fpi, &expt, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) return k; switch(k & STRTOG_Retmask) { diff --git a/lib/libc/gdtoa/strtopd.c b/lib/libc/gdtoa/strtopd.c index 9fe46ab12..832027150 100644 --- a/lib/libc/gdtoa/strtopd.c +++ b/lib/libc/gdtoa/strtopd.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtopd.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtopd.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -42,12 +42,17 @@ strtopd(CONST char *s, char **sp, double *d) { static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI }; ULong bits[2]; - Long exp; + Long expt; int k; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif - k = strtodg(s, sp, &fpi0, &exp, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) return k; - ULtod((ULong*)d, bits, exp, k); + ULtod((ULong*)d, bits, expt, k); return k; } diff --git a/lib/libc/gdtoa/strtopdd.c b/lib/libc/gdtoa/strtopdd.c index 47357b9b2..74ff16521 100644 --- a/lib/libc/gdtoa/strtopdd.c +++ b/lib/libc/gdtoa/strtopdd.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtopdd.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtopdd.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -41,20 +41,25 @@ strtopdd(CONST char *s, char **sp, double *dd) #endif { #ifdef Sudden_Underflow - static FPI fpi = { 106, 1-1023, 2046-1023-106+1, 1, 1 }; + static FPI fpi0 = { 106, 1-1023, 2046-1023-106+1, 1, 1 }; #else - static FPI fpi = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 }; + static FPI fpi0 = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 }; #endif ULong bits[4]; - Long exp; + Long expt; int i, j, rv; typedef union { double d[2]; ULong L[4]; } U; U *u; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif - rv = strtodg(s, sp, &fpi, &exp, bits); + rv = strtodg(s, sp, fpi, &expt, bits); if (rv == STRTOG_NoMemory) return rv; u = (U*)dd; @@ -66,36 +71,36 @@ strtopdd(CONST char *s, char **sp, double *dd) case STRTOG_Normal: u->L[_1] = (bits[1] >> 21 | bits[2] << 11) & 0xffffffffL; - u->L[_0] = bits[2] >> 21 | bits[3] << 11 & 0xfffff - | exp + 0x3ff + 105 << 20; - exp += 0x3ff + 52; + u->L[_0] = (bits[2] >> 21) | ((bits[3] << 11) & 0xfffff) + | ((expt + 0x3ff + 105) << 20); + expt += 0x3ff + 52; if (bits[1] &= 0x1fffff) { i = hi0bits(bits[1]) - 11; - if (i >= exp) { - i = exp - 1; - exp = 0; + if (i >= expt) { + i = expt - 1; + expt = 0; } else - exp -= i; + expt -= i; if (i > 0) { - bits[1] = bits[1] << i | bits[0] >> 32-i; + bits[1] = bits[1] << i | bits[0] >> (32-i); bits[0] = bits[0] << i & 0xffffffffL; } } else if (bits[0]) { i = hi0bits(bits[0]) + 21; - if (i >= exp) { - i = exp - 1; - exp = 0; + if (i >= expt) { + i = expt - 1; + expt = 0; } else - exp -= i; + expt -= i; if (i < 32) { - bits[1] = bits[0] >> 32 - i; + bits[1] = bits[0] >> (32 - i); bits[0] = bits[0] << i & 0xffffffffL; } else { - bits[1] = bits[0] << i - 32; + bits[1] = bits[0] << (i - 32); bits[0] = 0; } } @@ -104,7 +109,7 @@ strtopdd(CONST char *s, char **sp, double *dd) break; } u->L[2+_1] = bits[0]; - u->L[2+_0] = bits[1] & 0xfffff | exp << 20; + u->L[2+_0] = (bits[1] & 0xfffff) | (expt << 20); break; case STRTOG_Denormal: @@ -123,10 +128,10 @@ strtopdd(CONST char *s, char **sp, double *dd) nearly_normal: i = hi0bits(bits[3]) - 11; /* i >= 12 */ j = 32 - i; - u->L[_0] = (bits[3] << i | bits[2] >> j) & 0xfffff - | 65 - i << 20; + u->L[_0] = ((bits[3] << i | bits[2] >> j) & 0xfffff) + | ((65 - i) << 20); u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL; - u->L[2+_0] = bits[1] & (1L << j) - 1; + u->L[2+_0] = bits[1] & ((1L << j) - 1); u->L[2+_1] = bits[0]; break; @@ -135,34 +140,34 @@ strtopdd(CONST char *s, char **sp, double *dd) if (i < 0) { j = -i; i += 32; - u->L[_0] = bits[2] >> j & 0xfffff | (33 + j) << 20; - u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL; - u->L[2+_0] = bits[1] & (1L << j) - 1; + u->L[_0] = (bits[2] >> j & 0xfffff) | (33 + j) << 20; + u->L[_1] = ((bits[2] << i) | (bits[1] >> j)) & 0xffffffffL; + u->L[2+_0] = bits[1] & ((1L << j) - 1); u->L[2+_1] = bits[0]; break; } if (i == 0) { - u->L[_0] = bits[2] & 0xfffff | 33 << 20; + u->L[_0] = (bits[2] & 0xfffff) | (33 << 20); u->L[_1] = bits[1]; u->L[2+_0] = 0; u->L[2+_1] = bits[0]; break; } j = 32 - i; - u->L[_0] = (bits[2] << i | bits[1] >> j) & 0xfffff - | j + 1 << 20; + u->L[_0] = (((bits[2] << i) | (bits[1] >> j)) & 0xfffff) + | ((j + 1) << 20); u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL; u->L[2+_0] = 0; - u->L[2+_1] = bits[0] & (1L << j) - 1; + u->L[2+_1] = bits[0] & ((1L << j) - 1); break; hardly_normal: j = 11 - hi0bits(bits[1]); i = 32 - j; - u->L[_0] = bits[1] >> j & 0xfffff | j + 1 << 20; + u->L[_0] = (bits[1] >> j & 0xfffff) | ((j + 1) << 20); u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL; u->L[2+_0] = 0; - u->L[2+_1] = bits[0] & (1L << j) - 1; + u->L[2+_1] = bits[0] & ((1L << j) - 1); break; case STRTOG_Infinite: diff --git a/lib/libc/gdtoa/strtopf.c b/lib/libc/gdtoa/strtopf.c index 3bb9d5a7b..880aa82cc 100644 --- a/lib/libc/gdtoa/strtopf.c +++ b/lib/libc/gdtoa/strtopf.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtopf.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtopf.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -40,12 +40,17 @@ strtopf(s, sp, f) CONST char *s; char **sp; float *f; strtopf(CONST char *s, char **sp, float *f) #endif { - static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; + static FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; ULong bits[1], *L; - Long exp; + Long expt; int k; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif - k = strtodg(s, sp, &fpi, &exp, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) return k; L = (ULong*)f; @@ -57,7 +62,7 @@ strtopf(CONST char *s, char **sp, float *f) case STRTOG_Normal: case STRTOG_NaNbits: - L[0] = bits[0] & 0x7fffff | exp + 0x7f + 23 << 23; + L[0] = (bits[0] & 0x7fffff) | ((expt + 0x7f + 23) << 23); break; case STRTOG_Denormal: diff --git a/lib/libc/gdtoa/strtopx.c b/lib/libc/gdtoa/strtopx.c index c2a122782..2e803c2ac 100644 --- a/lib/libc/gdtoa/strtopx.c +++ b/lib/libc/gdtoa/strtopx.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtopx.c,v 1.4 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtopx.c,v 1.5 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -60,13 +60,18 @@ strtopx(s, sp, V) CONST char *s; char **sp; void *V; strtopx(CONST char *s, char **sp, void *V) #endif { - static CONST FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; + static const FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; ULong bits[2]; Long expt; int k; UShort *L = (UShort*)V; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif - k = strtodg(s, sp, &fpi, &expt, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) return k; switch(k & STRTOG_Retmask) { @@ -91,7 +96,8 @@ strtopx(CONST char *s, char **sp, void *V) case STRTOG_Infinite: L[_0] = 0x7fff; - L[_1] = L[_2] = L[_3] = L[_4] = 0; + L[_1] = 0x8000; + L[_2] = L[_3] = L[_4] = 0; break; case STRTOG_NaN: diff --git a/lib/libc/gdtoa/strtopxL.c b/lib/libc/gdtoa/strtopxL.c index d0890f25d..12f3336ba 100644 --- a/lib/libc/gdtoa/strtopxL.c +++ b/lib/libc/gdtoa/strtopxL.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtopxL.c,v 1.4 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtopxL.c,v 1.5 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -56,13 +56,18 @@ strtopxL(s, sp, V) CONST char *s; char **sp; void *V; strtopxL(CONST char *s, char **sp, void *V) #endif { - static CONST FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; + static CONST FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; ULong bits[2]; Long expt; int k; ULong *L = (ULong*)V; +#ifdef Honor_FLT_ROUNDS +#include "gdtoa_fltrnds.h" +#else +#define fpi &fpi0 +#endif - k = strtodg(s, sp, &fpi, &expt, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) return k; switch(k & STRTOG_Retmask) { @@ -81,7 +86,8 @@ strtopxL(CONST char *s, char **sp, void *V) case STRTOG_Infinite: L[_0] = 0x7fff << 16; - L[_1] = L[_2] = 0; + L[_1] = 0x80000000; + L[_2] = 0; break; case STRTOG_NaN: diff --git a/lib/libc/gdtoa/strtorQ.c b/lib/libc/gdtoa/strtorQ.c index 349ef804f..a001271a8 100644 --- a/lib/libc/gdtoa/strtorQ.c +++ b/lib/libc/gdtoa/strtorQ.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtorQ.c,v 1.3 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtorQ.c,v 1.4 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -53,9 +53,9 @@ THIS SOFTWARE. void #ifdef KR_headers -ULtoQ(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; +ULtoQ(L, bits, expt, k) ULong *L; ULong *bits; Long expt; int k; #else -ULtoQ(ULong *L, ULong *bits, Long exp, int k) +ULtoQ(ULong *L, ULong *bits, Long expt, int k) #endif { switch(k & STRTOG_Retmask) { @@ -69,7 +69,7 @@ ULtoQ(ULong *L, ULong *bits, Long exp, int k) L[_3] = bits[0]; L[_2] = bits[1]; L[_1] = bits[2]; - L[_0] = (bits[3] & ~0x10000) | ((exp + 0x3fff + 112) << 16); + L[_0] = (bits[3] & ~0x10000) | ((expt + 0x3fff + 112) << 16); break; case STRTOG_Denormal: @@ -104,7 +104,7 @@ strtorQ(CONST char *s, char **sp, int rounding, void *L) static FPI fpi0 = { 113, 1-16383-113+1, 32766-16383-113+1, 1, SI }; FPI *fpi, fpi1; ULong bits[4]; - Long exp; + Long expt; int k; fpi = &fpi0; @@ -113,9 +113,9 @@ strtorQ(CONST char *s, char **sp, int rounding, void *L) fpi1.rounding = rounding; fpi = &fpi1; } - k = strtodg(s, sp, fpi, &exp, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) return k; - ULtoQ((ULong*)L, bits, exp, k); + ULtoQ((ULong*)L, bits, expt, k); return k; } diff --git a/lib/libc/gdtoa/strtordd.c b/lib/libc/gdtoa/strtordd.c index 3e2d1aa26..d60f52941 100644 --- a/lib/libc/gdtoa/strtordd.c +++ b/lib/libc/gdtoa/strtordd.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtordd.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtordd.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -35,9 +35,9 @@ THIS SOFTWARE. void #ifdef KR_headers -ULtodd(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; +ULtodd(L, bits, expt, k) ULong *L; ULong *bits; Long expt; int k; #else -ULtodd(ULong *L, ULong *bits, Long exp, int k) +ULtodd(ULong *L, ULong *bits, Long expt, int k) #endif { int i, j; @@ -50,36 +50,36 @@ ULtodd(ULong *L, ULong *bits, Long exp, int k) case STRTOG_Normal: L[_1] = (bits[1] >> 21 | bits[2] << 11) & (ULong)0xffffffffL; - L[_0] = bits[2] >> 21 | bits[3] << 11 & 0xfffff - | exp + 0x3ff + 105 << 20; - exp += 0x3ff + 52; + L[_0] = (bits[2] >> 21) | (bits[3] << 11 & 0xfffff) + | ((expt + 0x3ff + 105) << 20); + expt += 0x3ff + 52; if (bits[1] &= 0x1fffff) { i = hi0bits(bits[1]) - 11; - if (i >= exp) { - i = exp - 1; - exp = 0; + if (i >= expt) { + i = expt - 1; + expt = 0; } else - exp -= i; + expt -= i; if (i > 0) { - bits[1] = bits[1] << i | bits[0] >> 32-i; + bits[1] = bits[1] << i | bits[0] >> (32-i); bits[0] = bits[0] << i & (ULong)0xffffffffL; } } else if (bits[0]) { i = hi0bits(bits[0]) + 21; - if (i >= exp) { - i = exp - 1; - exp = 0; + if (i >= expt) { + i = expt - 1; + expt = 0; } else - exp -= i; + expt -= i; if (i < 32) { - bits[1] = bits[0] >> 32 - i; + bits[1] = bits[0] >> (32 - i); bits[0] = bits[0] << i & (ULong)0xffffffffL; } else { - bits[1] = bits[0] << i - 32; + bits[1] = bits[0] << (i - 32); bits[0] = 0; } } @@ -88,7 +88,7 @@ ULtodd(ULong *L, ULong *bits, Long exp, int k) break; } L[2+_1] = bits[0]; - L[2+_0] = bits[1] & 0xfffff | exp << 20; + L[2+_0] = (bits[1] & 0xfffff) | (expt << 20); break; case STRTOG_Denormal: @@ -107,10 +107,10 @@ ULtodd(ULong *L, ULong *bits, Long exp, int k) nearly_normal: i = hi0bits(bits[3]) - 11; /* i >= 12 */ j = 32 - i; - L[_0] = (bits[3] << i | bits[2] >> j) & 0xfffff - | 65 - i << 20; + L[_0] = ((bits[3] << i | bits[2] >> j) & 0xfffff) + | ((65 - i) << 20); L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL; - L[2+_0] = bits[1] & ((ULong)1L << j) - 1; + L[2+_0] = bits[1] & (((ULong)1L << j) - 1); L[2+_1] = bits[0]; break; @@ -119,34 +119,34 @@ ULtodd(ULong *L, ULong *bits, Long exp, int k) if (i < 0) { j = -i; i += 32; - L[_0] = bits[2] >> j & 0xfffff | (33 + j) << 20; + L[_0] = (bits[2] >> j & 0xfffff) | ((33 + j) << 20); L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL; - L[2+_0] = bits[1] & ((ULong)1L << j) - 1; + L[2+_0] = bits[1] & (((ULong)1L << j) - 1); L[2+_1] = bits[0]; break; } if (i == 0) { - L[_0] = bits[2] & 0xfffff | 33 << 20; + L[_0] = (bits[2] & 0xfffff) | (33 << 20); L[_1] = bits[1]; L[2+_0] = 0; L[2+_1] = bits[0]; break; } j = 32 - i; - L[_0] = (bits[2] << i | bits[1] >> j) & 0xfffff - | j + 1 << 20; + L[_0] = (((bits[2] << i) | (bits[1] >> j)) & 0xfffff) + | ((j + 1) << 20); L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL; L[2+_0] = 0; - L[2+_1] = bits[0] & (1L << j) - 1; + L[2+_1] = bits[0] & ((1L << j) - 1); break; hardly_normal: j = 11 - hi0bits(bits[1]); i = 32 - j; - L[_0] = bits[1] >> j & 0xfffff | j + 1 << 20; + L[_0] = (bits[1] >> j & 0xfffff) | ((j + 1) << 20); L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL; L[2+_0] = 0; - L[2+_1] = bits[0] & ((ULong)1L << j) - 1; + L[2+_1] = bits[0] & (((ULong)1L << j) - 1); break; case STRTOG_Infinite: @@ -180,13 +180,14 @@ strtordd(CONST char *s, char **sp, int rounding, double *dd) #endif { #ifdef Sudden_Underflow - static FPI fpi0 = { 106, 1-1023, 2046-1023-106+1, 1, 1 }; + static CONST FPI fpi0 = { 106, 1-1023, 2046-1023-106+1, 1, 1 }; #else - static FPI fpi0 = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 }; + static CONST FPI fpi0 = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 }; #endif - FPI *fpi, fpi1; + CONST FPI *fpi; + FPI fpi1; ULong bits[4]; - Long exp; + Long expt; int k; fpi = &fpi0; @@ -195,9 +196,9 @@ strtordd(CONST char *s, char **sp, int rounding, double *dd) fpi1.rounding = rounding; fpi = &fpi1; } - k = strtodg(s, sp, fpi, &exp, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) return k; - ULtodd((ULong*)dd, bits, exp, k); + ULtodd((ULong*)dd, bits, expt, k); return k; } diff --git a/lib/libc/gdtoa/strtorf.c b/lib/libc/gdtoa/strtorf.c index 8617e40dd..5cf3c2dc4 100644 --- a/lib/libc/gdtoa/strtorf.c +++ b/lib/libc/gdtoa/strtorf.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtorf.c,v 1.2 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtorf.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -35,9 +35,9 @@ THIS SOFTWARE. void #ifdef KR_headers -ULtof(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; +ULtof(L, bits, expt, k) ULong *L; ULong *bits; Long expt; int k; #else -ULtof(ULong *L, ULong *bits, Long exp, int k) +ULtof(ULong *L, ULong *bits, Long expt, int k) #endif { switch(k & STRTOG_Retmask) { @@ -48,7 +48,7 @@ ULtof(ULong *L, ULong *bits, Long exp, int k) case STRTOG_Normal: case STRTOG_NaNbits: - L[0] = bits[0] & 0x7fffff | exp + 0x7f + 23 << 23; + L[0] = (bits[0] & 0x7fffff) | ((expt + 0x7f + 23) << 23); break; case STRTOG_Denormal: @@ -73,10 +73,11 @@ strtorf(s, sp, rounding, f) CONST char *s; char **sp; int rounding; float *f; strtorf(CONST char *s, char **sp, int rounding, float *f) #endif { - static FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; - FPI *fpi, fpi1; + static CONST FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; + CONST FPI *fpi; + FPI fpi1; ULong bits[1]; - Long exp; + Long expt; int k; fpi = &fpi0; @@ -85,9 +86,9 @@ strtorf(CONST char *s, char **sp, int rounding, float *f) fpi1.rounding = rounding; fpi = &fpi1; } - k = strtodg(s, sp, fpi, &exp, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) return k; - ULtof((ULong*)f, bits, exp, k); + ULtof((ULong*)f, bits, expt, k); return k; } diff --git a/lib/libc/gdtoa/strtorx.c b/lib/libc/gdtoa/strtorx.c index 1512486bd..d0305a2ac 100644 --- a/lib/libc/gdtoa/strtorx.c +++ b/lib/libc/gdtoa/strtorx.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtorx.c,v 1.3 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtorx.c,v 1.4 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -55,9 +55,9 @@ THIS SOFTWARE. void #ifdef KR_headers -ULtox(L, bits, exp, k) UShort *L; ULong *bits; Long exp; int k; +ULtox(L, bits, expt, k) UShort *L; ULong *bits; Long expt; int k; #else -ULtox(UShort *L, ULong *bits, Long exp, int k) +ULtox(UShort *L, ULong *bits, Long expt, int k) #endif { switch(k & STRTOG_Retmask) { @@ -72,7 +72,7 @@ ULtox(UShort *L, ULong *bits, Long exp, int k) case STRTOG_Normal: case STRTOG_NaNbits: - L[_0] = exp + 0x3fff + 63; + L[_0] = expt + 0x3fff + 63; normal_bits: L[_4] = (UShort)bits[0]; L[_3] = (UShort)(bits[0] >> 16); @@ -82,7 +82,8 @@ ULtox(UShort *L, ULong *bits, Long exp, int k) case STRTOG_Infinite: L[_0] = 0x7fff; - L[_1] = L[_2] = L[_3] = L[_4] = 0; + L[_1] = 0x8000; + L[_2] = L[_3] = L[_4] = 0; break; case STRTOG_NaN: @@ -103,10 +104,11 @@ strtorx(s, sp, rounding, L) CONST char *s; char **sp; int rounding; void *L; strtorx(CONST char *s, char **sp, int rounding, void *L) #endif { - static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; - FPI *fpi, fpi1; + static CONST FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; + CONST FPI *fpi; + FPI fpi1; ULong bits[2]; - Long exp; + Long expt; int k; fpi = &fpi0; @@ -115,9 +117,9 @@ strtorx(CONST char *s, char **sp, int rounding, void *L) fpi1.rounding = rounding; fpi = &fpi1; } - k = strtodg(s, sp, fpi, &exp, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) return k; - ULtox((UShort*)L, bits, exp, k); + ULtox((UShort*)L, bits, expt, k); return k; } diff --git a/lib/libc/gdtoa/strtorxL.c b/lib/libc/gdtoa/strtorxL.c index 4f11648b2..a8f7b403f 100644 --- a/lib/libc/gdtoa/strtorxL.c +++ b/lib/libc/gdtoa/strtorxL.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtorxL.c,v 1.3 2008/03/21 23:13:48 christos Exp $ */ +/* $NetBSD: strtorxL.c,v 1.4 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -51,9 +51,9 @@ THIS SOFTWARE. void #ifdef KR_headers -ULtoxL(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; +ULtoxL(L, bits, expt, k) ULong *L; ULong *bits; Long expt; int k; #else -ULtoxL(ULong *L, ULong *bits, Long exp, int k) +ULtoxL(ULong *L, ULong *bits, Long expt, int k) #endif { switch(k & STRTOG_Retmask) { @@ -65,14 +65,15 @@ ULtoxL(ULong *L, ULong *bits, Long exp, int k) case STRTOG_Normal: case STRTOG_Denormal: case STRTOG_NaNbits: - L[_0] = (exp + 0x3fff + 63) << 16; + L[_0] = (expt + 0x3fff + 63) << 16; L[_1] = bits[1]; L[_2] = bits[0]; break; case STRTOG_Infinite: L[_0] = 0x7fff << 16; - L[_1] = L[_2] = 0; + L[_1] = 0x80000000; + L[_2] = 0; break; case STRTOG_NaN: @@ -91,10 +92,11 @@ strtorxL(s, sp, rounding, L) CONST char *s; char **sp; int rounding; void *L; strtorxL(CONST char *s, char **sp, int rounding, void *L) #endif { - static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; - FPI *fpi, fpi1; + static CONST FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI }; + CONST FPI *fpi; + FPI fpi1; ULong bits[2]; - Long exp; + Long expt; int k; fpi = &fpi0; @@ -103,9 +105,9 @@ strtorxL(CONST char *s, char **sp, int rounding, void *L) fpi1.rounding = rounding; fpi = &fpi1; } - k = strtodg(s, sp, fpi, &exp, bits); + k = strtodg(s, sp, fpi, &expt, bits); if (k == STRTOG_NoMemory) return k; - ULtoxL((ULong*)L, bits, exp, k); + ULtoxL((ULong*)L, bits, expt, k); return k; } diff --git a/lib/libc/gdtoa/test/Q.ou0 b/lib/libc/gdtoa/test/Q.ou0 new file mode 100644 index 000000000..66c7e9b0b --- /dev/null +++ b/lib/libc/gdtoa/test/Q.ou0 @@ -0,0 +1,1180 @@ + +Input: 1.23 + +strtoQ consumes 4 bytes and returns 17 +with bits = #3fff3ae1 47ae147a e147ae14 7ae147ae +g_Qfmt(0) gives 4 bytes: "1.23" + +strtoIQ returns 17, consuming 4 bytes. +fI[0] = #3fff3ae1 47ae147a e147ae14 7ae147ae +fI[1] = #3fff3ae1 47ae147a e147ae14 7ae147af +fI[0] == strtod + + +Input: 1.23e+20 + +strtoQ consumes 8 bytes and returns 1 +with bits = #4041aabd f2145b43 0 0 +g_Qfmt(0) gives 8 bytes: "1.23e+20" + +strtoIQ returns 1, consuming 8 bytes. +fI[0] == fI[1] = #4041aabd f2145b43 0 0 + + +Input: 1.23e-20 + +strtoQ consumes 8 bytes and returns 17 +with bits = #3fbcd0ae 4cf76753 9e4cbca ad934841 +g_Qfmt(0) gives 8 bytes: "1.23e-20" + +strtoIQ returns 17, consuming 8 bytes. +fI[0] = #3fbcd0ae 4cf76753 9e4cbca ad934841 +fI[1] = #3fbcd0ae 4cf76753 9e4cbca ad934842 +fI[0] == strtod + + +Input: 1.23456789 + +strtoQ consumes 10 bytes and returns 17 +with bits = #3fff3c0c a4283de1 b7eb6945 1304948f +g_Qfmt(0) gives 10 bytes: "1.23456789" + +strtoIQ returns 17, consuming 10 bytes. +fI[0] = #3fff3c0c a4283de1 b7eb6945 1304948f +fI[1] = #3fff3c0c a4283de1 b7eb6945 13049490 +fI[0] == strtod + + +Input: 1.23456589e+20 + +strtoQ consumes 14 bytes and returns 1 +with bits = #4041ac53 7a660b99 74000000 0 +g_Qfmt(0) gives 14 bytes: "1.23456589e+20" + +strtoIQ returns 1, consuming 14 bytes. +fI[0] == fI[1] = #4041ac53 7a660b99 74000000 0 + + +Input: 1.23e+30 + +strtoQ consumes 8 bytes and returns 1 +with bits = #4062f0cb 4e8fb79 4945600 0 +g_Qfmt(0) gives 8 bytes: "1.23e+30" + +strtoIQ returns 1, consuming 8 bytes. +fI[0] == fI[1] = #4062f0cb 4e8fb79 4945600 0 + + +Input: 1.23e-30 + +strtoQ consumes 8 bytes and returns 17 +with bits = #3f9b8f28 66f5010a a9d63f9e d7e8ba14 +g_Qfmt(0) gives 8 bytes: "1.23e-30" + +strtoIQ returns 17, consuming 8 bytes. +fI[0] = #3f9b8f28 66f5010a a9d63f9e d7e8ba14 +fI[1] = #3f9b8f28 66f5010a a9d63f9e d7e8ba15 +fI[0] == strtod + + +Input: 1.23456789e-20 + +strtoQ consumes 14 bytes and returns 33 +with bits = #3fbcd268 1471e7ad a6a4a029 d86c1fa2 +g_Qfmt(0) gives 14 bytes: "1.23456789e-20" + +strtoIQ returns 33, consuming 14 bytes. +fI[0] = #3fbcd268 1471e7ad a6a4a029 d86c1fa1 +fI[1] = #3fbcd268 1471e7ad a6a4a029 d86c1fa2 +fI[1] == strtod + + +Input: 1.23456789e-30 + +strtoQ consumes 14 bytes and returns 17 +with bits = #3f9b90a3 e33bbd99 51f85855 5a6b19d4 +g_Qfmt(0) gives 14 bytes: "1.23456789e-30" + +strtoIQ returns 17, consuming 14 bytes. +fI[0] = #3f9b90a3 e33bbd99 51f85855 5a6b19d4 +fI[1] = #3f9b90a3 e33bbd99 51f85855 5a6b19d5 +fI[0] == strtod + + +Input: 1.234567890123456789 + +strtoQ consumes 20 bytes and returns 17 +with bits = #3fff3c0c a428c59f b71a4194 68dd175b +g_Qfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIQ returns 17, consuming 20 bytes. +fI[0] = #3fff3c0c a428c59f b71a4194 68dd175b +fI[1] = #3fff3c0c a428c59f b71a4194 68dd175c +fI[0] == strtod + + +Input: 1.23456789012345678901234567890123456789 + +strtoQ consumes 40 bytes and returns 17 +with bits = #3fff3c0c a428c59f b71a7be1 6b6b6d5b +g_Qfmt(0) gives 36 bytes: "1.2345678901234567890123456789012346" + +strtoIQ returns 17, consuming 40 bytes. +fI[0] = #3fff3c0c a428c59f b71a7be1 6b6b6d5b +fI[1] = #3fff3c0c a428c59f b71a7be1 6b6b6d5c +fI[0] == strtod + + +Input: 1.23e306 + +strtoQ consumes 8 bytes and returns 33 +with bits = #43f7c067 6cd1c61f 4daac5f1 e9fa3b55 +g_Qfmt(0) gives 9 bytes: "1.23e+306" + +strtoIQ returns 33, consuming 8 bytes. +fI[0] = #43f7c067 6cd1c61f 4daac5f1 e9fa3b54 +fI[1] = #43f7c067 6cd1c61f 4daac5f1 e9fa3b55 +fI[1] == strtod + + +Input: 1.23e-306 + +strtoQ consumes 9 bytes and returns 17 +with bits = #3c06ba3b 85da396e 7e496ab7 d233c3dd +g_Qfmt(0) gives 9 bytes: "1.23e-306" + +strtoIQ returns 17, consuming 9 bytes. +fI[0] = #3c06ba3b 85da396e 7e496ab7 d233c3dd +fI[1] = #3c06ba3b 85da396e 7e496ab7 d233c3de +fI[0] == strtod + + +Input: 1.23e-320 + +strtoQ consumes 9 bytes and returns 33 +with bits = #3bd83731 86e30898 7e33b2e8 355f847b +g_Qfmt(0) gives 9 bytes: "1.23e-320" + +strtoIQ returns 33, consuming 9 bytes. +fI[0] = #3bd83731 86e30898 7e33b2e8 355f847a +fI[1] = #3bd83731 86e30898 7e33b2e8 355f847b +fI[1] == strtod + + +Input: 1.23e-20 + +strtoQ consumes 8 bytes and returns 17 +with bits = #3fbcd0ae 4cf76753 9e4cbca ad934841 +g_Qfmt(0) gives 8 bytes: "1.23e-20" + +strtoIQ returns 17, consuming 8 bytes. +fI[0] = #3fbcd0ae 4cf76753 9e4cbca ad934841 +fI[1] = #3fbcd0ae 4cf76753 9e4cbca ad934842 +fI[0] == strtod + + +Input: 1.23456789e307 + +strtoQ consumes 14 bytes and returns 17 +with bits = #43fb194b 14bdaecd bcea468c 902464cf +g_Qfmt(0) gives 15 bytes: "1.23456789e+307" + +strtoIQ returns 17, consuming 14 bytes. +fI[0] = #43fb194b 14bdaecd bcea468c 902464cf +fI[1] = #43fb194b 14bdaecd bcea468c 902464d0 +fI[0] == strtod + + +Input: 1.23456589e-307 + +strtoQ consumes 15 bytes and returns 17 +with bits = #3c036319 6bb9845f a6d234e3 39163574 +g_Qfmt(0) gives 15 bytes: "1.23456589e-307" + +strtoIQ returns 17, consuming 15 bytes. +fI[0] = #3c036319 6bb9845f a6d234e3 39163574 +fI[1] = #3c036319 6bb9845f a6d234e3 39163575 +fI[0] == strtod + + +Input: 1.234567890123456789 + +strtoQ consumes 20 bytes and returns 17 +with bits = #3fff3c0c a428c59f b71a4194 68dd175b +g_Qfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIQ returns 17, consuming 20 bytes. +fI[0] = #3fff3c0c a428c59f b71a4194 68dd175b +fI[1] = #3fff3c0c a428c59f b71a4194 68dd175c +fI[0] == strtod + + +Input: 1.234567890123456789e301 + +strtoQ consumes 24 bytes and returns 33 +with bits = #43e726f5 175f5641 3017ea80 763990ef +g_Qfmt(0) gives 25 bytes: "1.234567890123456789e+301" + +strtoIQ returns 33, consuming 24 bytes. +fI[0] = #43e726f5 175f5641 3017ea80 763990ee +fI[1] = #43e726f5 175f5641 3017ea80 763990ef +fI[1] == strtod + + +Input: 1.234567890123456789e-301 + +strtoQ consumes 25 bytes and returns 17 +with bits = #3c1752a6 4e34ba0d 35b19b04 3222fce5 +g_Qfmt(0) gives 25 bytes: "1.234567890123456789e-301" + +strtoIQ returns 17, consuming 25 bytes. +fI[0] = #3c1752a6 4e34ba0d 35b19b04 3222fce5 +fI[1] = #3c1752a6 4e34ba0d 35b19b04 3222fce6 +fI[0] == strtod + + +Input: 1.234567890123456789e-321 + +strtoQ consumes 25 bytes and returns 17 +with bits = #3bd4f3c2 3699d4db 99d1ea94 2fecd7de +g_Qfmt(0) gives 25 bytes: "1.234567890123456789e-321" + +strtoIQ returns 17, consuming 25 bytes. +fI[0] = #3bd4f3c2 3699d4db 99d1ea94 2fecd7de +fI[1] = #3bd4f3c2 3699d4db 99d1ea94 2fecd7df +fI[0] == strtod + + +Input: 1e23 + +strtoQ consumes 4 bytes and returns 1 +with bits = #404b52d0 2c7e14af 68000000 0 +g_Qfmt(0) gives 5 bytes: "1e+23" + +strtoIQ returns 1, consuming 4 bytes. +fI[0] == fI[1] = #404b52d0 2c7e14af 68000000 0 + + +Input: 1e310 + +strtoQ consumes 5 bytes and returns 33 +with bits = #4404bd03 c8140697 9e9ff00e fefd4cbd +g_Qfmt(0) gives 6 bytes: "1e+310" + +strtoIQ returns 33, consuming 5 bytes. +fI[0] = #4404bd03 c8140697 9e9ff00e fefd4cbc +fI[1] = #4404bd03 c8140697 9e9ff00e fefd4cbd +fI[1] == strtod + + +Input: 9.0259718793241475e-277 + +strtoQ consumes 23 bytes and returns 17 +with bits = #3c69ffff ffffffff f9ed5779 ac118fe1 +g_Qfmt(0) gives 23 bytes: "9.0259718793241475e-277" + +strtoIQ returns 17, consuming 23 bytes. +fI[0] = #3c69ffff ffffffff f9ed5779 ac118fe1 +fI[1] = #3c69ffff ffffffff f9ed5779 ac118fe2 +fI[0] == strtod + + +Input: 9.025971879324147880346310405869e-277 + +strtoQ consumes 37 bytes and returns 33 +with bits = #3c6a0000 0 0 9a +g_Qfmt(0) gives 37 bytes: "9.025971879324147880346310405869e-277" + +strtoIQ returns 33, consuming 37 bytes. +fI[0] = #3c6a0000 0 0 99 +fI[1] = #3c6a0000 0 0 9a +fI[1] == strtod + + +Input: 9.025971879324147880346310405868e-277 + +strtoQ consumes 37 bytes and returns 17 +with bits = #3c69ffff ffffffff ffffffff fffffcb5 +g_Qfmt(0) gives 37 bytes: "9.025971879324147880346310405868e-277" + +strtoIQ returns 17, consuming 37 bytes. +fI[0] = #3c69ffff ffffffff ffffffff fffffcb5 +fI[1] = #3c69ffff ffffffff ffffffff fffffcb6 +fI[0] == strtod + + +Input: 2.2250738585072014e-308 + +strtoQ consumes 23 bytes and returns 33 +with bits = #3c010000 0 8c304c cf867de0 +g_Qfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoIQ returns 33, consuming 23 bytes. +fI[0] = #3c010000 0 8c304c cf867ddf +fI[1] = #3c010000 0 8c304c cf867de0 +fI[1] == strtod + + +Input: 2.2250738585072013e-308 + +strtoQ consumes 23 bytes and returns 33 +with bits = #3c00ffff ffffffff fa9e4c4f 4c1e8a10 +g_Qfmt(0) gives 23 bytes: "2.2250738585072013e-308" + +strtoIQ returns 33, consuming 23 bytes. +fI[0] = #3c00ffff ffffffff fa9e4c4f 4c1e8a0f +fI[1] = #3c00ffff ffffffff fa9e4c4f 4c1e8a10 +fI[1] == strtod + +Rounding mode for strtor... changed from 1 (nearest) to 0 (toward zero) + +Input: 1.1 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff1999 99999999 99999999 99999999 +g_Qfmt(0) gives 36 bytes: "1.0999999999999999999999999999999999" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff1999 99999999 99999999 99999999 +fI[1] = #3fff1999 99999999 99999999 9999999a +fI[0] == strtod + + +Input: -1.1 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff1999 99999999 99999999 99999999 +g_Qfmt(0) gives 37 bytes: "-1.0999999999999999999999999999999999" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff1999 99999999 99999999 9999999a +fI[1] = #bfff1999 99999999 99999999 99999999 +fI[1] == strtod + + +Input: 1.2 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff3333 33333333 33333333 33333333 +g_Qfmt(0) gives 3 bytes: "1.2" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff3333 33333333 33333333 33333333 +fI[1] = #3fff3333 33333333 33333333 33333334 +fI[0] == strtod + + +Input: -1.2 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff3333 33333333 33333333 33333333 +g_Qfmt(0) gives 4 bytes: "-1.2" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff3333 33333333 33333333 33333334 +fI[1] = #bfff3333 33333333 33333333 33333333 +fI[1] == strtod + + +Input: 1.3 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff4ccc cccccccc cccccccc cccccccc +g_Qfmt(0) gives 36 bytes: "1.2999999999999999999999999999999998" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff4ccc cccccccc cccccccc cccccccc +fI[1] = #3fff4ccc cccccccc cccccccc cccccccd +fI[0] == strtod + + +Input: -1.3 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff4ccc cccccccc cccccccc cccccccc +g_Qfmt(0) gives 37 bytes: "-1.2999999999999999999999999999999998" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff4ccc cccccccc cccccccc cccccccd +fI[1] = #bfff4ccc cccccccc cccccccc cccccccc +fI[1] == strtod + + +Input: 1.4 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff6666 66666666 66666666 66666666 +g_Qfmt(0) gives 3 bytes: "1.4" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff6666 66666666 66666666 66666666 +fI[1] = #3fff6666 66666666 66666666 66666667 +fI[0] == strtod + + +Input: -1.4 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff6666 66666666 66666666 66666666 +g_Qfmt(0) gives 4 bytes: "-1.4" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff6666 66666666 66666666 66666667 +fI[1] = #bfff6666 66666666 66666666 66666666 +fI[1] == strtod + + +Input: 1.5 + +strtoQ consumes 3 bytes and returns 1 +with bits = #3fff8000 0 0 0 +g_Qfmt(0) gives 3 bytes: "1.5" + +strtoIQ returns 1, consuming 3 bytes. +fI[0] == fI[1] = #3fff8000 0 0 0 + + +Input: -1.5 + +strtoQ consumes 4 bytes and returns 9 +with bits = #bfff8000 0 0 0 +g_Qfmt(0) gives 4 bytes: "-1.5" + +strtoIQ returns 9, consuming 4 bytes. +fI[0] == fI[1] = #bfff8000 0 0 0 + + +Input: 1.6 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff9999 99999999 99999999 99999999 +g_Qfmt(0) gives 36 bytes: "1.5999999999999999999999999999999999" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff9999 99999999 99999999 99999999 +fI[1] = #3fff9999 99999999 99999999 9999999a +fI[0] == strtod + + +Input: -1.6 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff9999 99999999 99999999 99999999 +g_Qfmt(0) gives 37 bytes: "-1.5999999999999999999999999999999999" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff9999 99999999 99999999 9999999a +fI[1] = #bfff9999 99999999 99999999 99999999 +fI[1] == strtod + + +Input: 1.7 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffb333 33333333 33333333 33333333 +g_Qfmt(0) gives 3 bytes: "1.7" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffb333 33333333 33333333 33333333 +fI[1] = #3fffb333 33333333 33333333 33333334 +fI[0] == strtod + + +Input: -1.7 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffb333 33333333 33333333 33333333 +g_Qfmt(0) gives 4 bytes: "-1.7" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffb333 33333333 33333333 33333334 +fI[1] = #bfffb333 33333333 33333333 33333333 +fI[1] == strtod + + +Input: 1.8 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffcccc cccccccc cccccccc cccccccc +g_Qfmt(0) gives 36 bytes: "1.7999999999999999999999999999999998" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fffcccc cccccccc cccccccc cccccccc +fI[1] = #3fffcccc cccccccc cccccccc cccccccd +fI[0] == strtod + + +Input: -1.8 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffcccc cccccccc cccccccc cccccccc +g_Qfmt(0) gives 37 bytes: "-1.7999999999999999999999999999999998" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfffcccc cccccccc cccccccc cccccccd +fI[1] = #bfffcccc cccccccc cccccccc cccccccc +fI[1] == strtod + + +Input: 1.9 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffe666 66666666 66666666 66666666 +g_Qfmt(0) gives 3 bytes: "1.9" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffe666 66666666 66666666 66666666 +fI[1] = #3fffe666 66666666 66666666 66666667 +fI[0] == strtod + + +Input: -1.9 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffe666 66666666 66666666 66666666 +g_Qfmt(0) gives 4 bytes: "-1.9" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffe666 66666666 66666666 66666667 +fI[1] = #bfffe666 66666666 66666666 66666666 +fI[1] == strtod + +Rounding mode for strtor... changed from 0 (toward zero) to 1 (nearest) + +Input: 1.1 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff1999 99999999 99999999 9999999a +g_Qfmt(0) gives 3 bytes: "1.1" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff1999 99999999 99999999 99999999 +fI[1] = #3fff1999 99999999 99999999 9999999a +fI[1] == strtod + + +Input: -1.1 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff1999 99999999 99999999 9999999a +g_Qfmt(0) gives 4 bytes: "-1.1" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff1999 99999999 99999999 9999999a +fI[1] = #bfff1999 99999999 99999999 99999999 +fI[0] == strtod + + +Input: 1.2 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff3333 33333333 33333333 33333333 +g_Qfmt(0) gives 3 bytes: "1.2" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff3333 33333333 33333333 33333333 +fI[1] = #3fff3333 33333333 33333333 33333334 +fI[0] == strtod + + +Input: -1.2 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff3333 33333333 33333333 33333333 +g_Qfmt(0) gives 4 bytes: "-1.2" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff3333 33333333 33333333 33333334 +fI[1] = #bfff3333 33333333 33333333 33333333 +fI[1] == strtod + + +Input: 1.3 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff4ccc cccccccc cccccccc cccccccd +g_Qfmt(0) gives 3 bytes: "1.3" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff4ccc cccccccc cccccccc cccccccc +fI[1] = #3fff4ccc cccccccc cccccccc cccccccd +fI[1] == strtod + + +Input: -1.3 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff4ccc cccccccc cccccccc cccccccd +g_Qfmt(0) gives 4 bytes: "-1.3" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff4ccc cccccccc cccccccc cccccccd +fI[1] = #bfff4ccc cccccccc cccccccc cccccccc +fI[0] == strtod + + +Input: 1.4 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff6666 66666666 66666666 66666666 +g_Qfmt(0) gives 3 bytes: "1.4" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff6666 66666666 66666666 66666666 +fI[1] = #3fff6666 66666666 66666666 66666667 +fI[0] == strtod + + +Input: -1.4 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff6666 66666666 66666666 66666666 +g_Qfmt(0) gives 4 bytes: "-1.4" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff6666 66666666 66666666 66666667 +fI[1] = #bfff6666 66666666 66666666 66666666 +fI[1] == strtod + + +Input: 1.5 + +strtoQ consumes 3 bytes and returns 1 +with bits = #3fff8000 0 0 0 +g_Qfmt(0) gives 3 bytes: "1.5" + +strtoIQ returns 1, consuming 3 bytes. +fI[0] == fI[1] = #3fff8000 0 0 0 + + +Input: -1.5 + +strtoQ consumes 4 bytes and returns 9 +with bits = #bfff8000 0 0 0 +g_Qfmt(0) gives 4 bytes: "-1.5" + +strtoIQ returns 9, consuming 4 bytes. +fI[0] == fI[1] = #bfff8000 0 0 0 + + +Input: 1.6 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff9999 99999999 99999999 9999999a +g_Qfmt(0) gives 3 bytes: "1.6" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff9999 99999999 99999999 99999999 +fI[1] = #3fff9999 99999999 99999999 9999999a +fI[1] == strtod + + +Input: -1.6 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff9999 99999999 99999999 9999999a +g_Qfmt(0) gives 4 bytes: "-1.6" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff9999 99999999 99999999 9999999a +fI[1] = #bfff9999 99999999 99999999 99999999 +fI[0] == strtod + + +Input: 1.7 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffb333 33333333 33333333 33333333 +g_Qfmt(0) gives 3 bytes: "1.7" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffb333 33333333 33333333 33333333 +fI[1] = #3fffb333 33333333 33333333 33333334 +fI[0] == strtod + + +Input: -1.7 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffb333 33333333 33333333 33333333 +g_Qfmt(0) gives 4 bytes: "-1.7" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffb333 33333333 33333333 33333334 +fI[1] = #bfffb333 33333333 33333333 33333333 +fI[1] == strtod + + +Input: 1.8 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fffcccc cccccccc cccccccc cccccccd +g_Qfmt(0) gives 3 bytes: "1.8" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fffcccc cccccccc cccccccc cccccccc +fI[1] = #3fffcccc cccccccc cccccccc cccccccd +fI[1] == strtod + + +Input: -1.8 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfffcccc cccccccc cccccccc cccccccd +g_Qfmt(0) gives 4 bytes: "-1.8" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfffcccc cccccccc cccccccc cccccccd +fI[1] = #bfffcccc cccccccc cccccccc cccccccc +fI[0] == strtod + + +Input: 1.9 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffe666 66666666 66666666 66666666 +g_Qfmt(0) gives 3 bytes: "1.9" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffe666 66666666 66666666 66666666 +fI[1] = #3fffe666 66666666 66666666 66666667 +fI[0] == strtod + + +Input: -1.9 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffe666 66666666 66666666 66666666 +g_Qfmt(0) gives 4 bytes: "-1.9" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffe666 66666666 66666666 66666667 +fI[1] = #bfffe666 66666666 66666666 66666666 +fI[1] == strtod + +Rounding mode for strtor... changed from 1 (nearest) to 2 (toward +Infinity) + +Input: 1.1 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff1999 99999999 99999999 9999999a +g_Qfmt(0) gives 3 bytes: "1.1" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff1999 99999999 99999999 99999999 +fI[1] = #3fff1999 99999999 99999999 9999999a +fI[1] == strtod + + +Input: -1.1 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff1999 99999999 99999999 99999999 +g_Qfmt(0) gives 37 bytes: "-1.0999999999999999999999999999999999" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff1999 99999999 99999999 9999999a +fI[1] = #bfff1999 99999999 99999999 99999999 +fI[1] == strtod + + +Input: 1.2 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff3333 33333333 33333333 33333334 +g_Qfmt(0) gives 36 bytes: "1.2000000000000000000000000000000002" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff3333 33333333 33333333 33333333 +fI[1] = #3fff3333 33333333 33333333 33333334 +fI[1] == strtod + + +Input: -1.2 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff3333 33333333 33333333 33333333 +g_Qfmt(0) gives 4 bytes: "-1.2" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff3333 33333333 33333333 33333334 +fI[1] = #bfff3333 33333333 33333333 33333333 +fI[1] == strtod + + +Input: 1.3 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff4ccc cccccccc cccccccc cccccccd +g_Qfmt(0) gives 3 bytes: "1.3" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff4ccc cccccccc cccccccc cccccccc +fI[1] = #3fff4ccc cccccccc cccccccc cccccccd +fI[1] == strtod + + +Input: -1.3 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff4ccc cccccccc cccccccc cccccccc +g_Qfmt(0) gives 37 bytes: "-1.2999999999999999999999999999999998" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff4ccc cccccccc cccccccc cccccccd +fI[1] = #bfff4ccc cccccccc cccccccc cccccccc +fI[1] == strtod + + +Input: 1.4 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff6666 66666666 66666666 66666667 +g_Qfmt(0) gives 36 bytes: "1.4000000000000000000000000000000001" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff6666 66666666 66666666 66666666 +fI[1] = #3fff6666 66666666 66666666 66666667 +fI[1] == strtod + + +Input: -1.4 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff6666 66666666 66666666 66666666 +g_Qfmt(0) gives 4 bytes: "-1.4" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff6666 66666666 66666666 66666667 +fI[1] = #bfff6666 66666666 66666666 66666666 +fI[1] == strtod + + +Input: 1.5 + +strtoQ consumes 3 bytes and returns 1 +with bits = #3fff8000 0 0 0 +g_Qfmt(0) gives 3 bytes: "1.5" + +strtoIQ returns 1, consuming 3 bytes. +fI[0] == fI[1] = #3fff8000 0 0 0 + + +Input: -1.5 + +strtoQ consumes 4 bytes and returns 9 +with bits = #bfff8000 0 0 0 +g_Qfmt(0) gives 4 bytes: "-1.5" + +strtoIQ returns 9, consuming 4 bytes. +fI[0] == fI[1] = #bfff8000 0 0 0 + + +Input: 1.6 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff9999 99999999 99999999 9999999a +g_Qfmt(0) gives 3 bytes: "1.6" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff9999 99999999 99999999 99999999 +fI[1] = #3fff9999 99999999 99999999 9999999a +fI[1] == strtod + + +Input: -1.6 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff9999 99999999 99999999 99999999 +g_Qfmt(0) gives 37 bytes: "-1.5999999999999999999999999999999999" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff9999 99999999 99999999 9999999a +fI[1] = #bfff9999 99999999 99999999 99999999 +fI[1] == strtod + + +Input: 1.7 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fffb333 33333333 33333333 33333334 +g_Qfmt(0) gives 36 bytes: "1.7000000000000000000000000000000002" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffb333 33333333 33333333 33333333 +fI[1] = #3fffb333 33333333 33333333 33333334 +fI[1] == strtod + + +Input: -1.7 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffb333 33333333 33333333 33333333 +g_Qfmt(0) gives 4 bytes: "-1.7" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffb333 33333333 33333333 33333334 +fI[1] = #bfffb333 33333333 33333333 33333333 +fI[1] == strtod + + +Input: 1.8 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fffcccc cccccccc cccccccc cccccccd +g_Qfmt(0) gives 3 bytes: "1.8" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fffcccc cccccccc cccccccc cccccccc +fI[1] = #3fffcccc cccccccc cccccccc cccccccd +fI[1] == strtod + + +Input: -1.8 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffcccc cccccccc cccccccc cccccccc +g_Qfmt(0) gives 37 bytes: "-1.7999999999999999999999999999999998" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfffcccc cccccccc cccccccc cccccccd +fI[1] = #bfffcccc cccccccc cccccccc cccccccc +fI[1] == strtod + + +Input: 1.9 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fffe666 66666666 66666666 66666667 +g_Qfmt(0) gives 36 bytes: "1.9000000000000000000000000000000001" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffe666 66666666 66666666 66666666 +fI[1] = #3fffe666 66666666 66666666 66666667 +fI[1] == strtod + + +Input: -1.9 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffe666 66666666 66666666 66666666 +g_Qfmt(0) gives 4 bytes: "-1.9" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffe666 66666666 66666666 66666667 +fI[1] = #bfffe666 66666666 66666666 66666666 +fI[1] == strtod + +Rounding mode for strtor... changed from 2 (toward +Infinity) to 3 (toward -Infinity) + +Input: 1.1 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff1999 99999999 99999999 99999999 +g_Qfmt(0) gives 36 bytes: "1.0999999999999999999999999999999999" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff1999 99999999 99999999 99999999 +fI[1] = #3fff1999 99999999 99999999 9999999a +fI[0] == strtod + + +Input: -1.1 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff1999 99999999 99999999 9999999a +g_Qfmt(0) gives 4 bytes: "-1.1" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff1999 99999999 99999999 9999999a +fI[1] = #bfff1999 99999999 99999999 99999999 +fI[0] == strtod + + +Input: 1.2 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff3333 33333333 33333333 33333333 +g_Qfmt(0) gives 3 bytes: "1.2" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff3333 33333333 33333333 33333333 +fI[1] = #3fff3333 33333333 33333333 33333334 +fI[0] == strtod + + +Input: -1.2 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff3333 33333333 33333333 33333334 +g_Qfmt(0) gives 37 bytes: "-1.2000000000000000000000000000000002" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff3333 33333333 33333333 33333334 +fI[1] = #bfff3333 33333333 33333333 33333333 +fI[0] == strtod + + +Input: 1.3 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff4ccc cccccccc cccccccc cccccccc +g_Qfmt(0) gives 36 bytes: "1.2999999999999999999999999999999998" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff4ccc cccccccc cccccccc cccccccc +fI[1] = #3fff4ccc cccccccc cccccccc cccccccd +fI[0] == strtod + + +Input: -1.3 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff4ccc cccccccc cccccccc cccccccd +g_Qfmt(0) gives 4 bytes: "-1.3" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff4ccc cccccccc cccccccc cccccccd +fI[1] = #bfff4ccc cccccccc cccccccc cccccccc +fI[0] == strtod + + +Input: 1.4 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff6666 66666666 66666666 66666666 +g_Qfmt(0) gives 3 bytes: "1.4" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff6666 66666666 66666666 66666666 +fI[1] = #3fff6666 66666666 66666666 66666667 +fI[0] == strtod + + +Input: -1.4 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff6666 66666666 66666666 66666667 +g_Qfmt(0) gives 37 bytes: "-1.4000000000000000000000000000000001" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff6666 66666666 66666666 66666667 +fI[1] = #bfff6666 66666666 66666666 66666666 +fI[0] == strtod + + +Input: 1.5 + +strtoQ consumes 3 bytes and returns 1 +with bits = #3fff8000 0 0 0 +g_Qfmt(0) gives 3 bytes: "1.5" + +strtoIQ returns 1, consuming 3 bytes. +fI[0] == fI[1] = #3fff8000 0 0 0 + + +Input: -1.5 + +strtoQ consumes 4 bytes and returns 9 +with bits = #bfff8000 0 0 0 +g_Qfmt(0) gives 4 bytes: "-1.5" + +strtoIQ returns 9, consuming 4 bytes. +fI[0] == fI[1] = #bfff8000 0 0 0 + + +Input: 1.6 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff9999 99999999 99999999 99999999 +g_Qfmt(0) gives 36 bytes: "1.5999999999999999999999999999999999" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff9999 99999999 99999999 99999999 +fI[1] = #3fff9999 99999999 99999999 9999999a +fI[0] == strtod + + +Input: -1.6 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff9999 99999999 99999999 9999999a +g_Qfmt(0) gives 4 bytes: "-1.6" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff9999 99999999 99999999 9999999a +fI[1] = #bfff9999 99999999 99999999 99999999 +fI[0] == strtod + + +Input: 1.7 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffb333 33333333 33333333 33333333 +g_Qfmt(0) gives 3 bytes: "1.7" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffb333 33333333 33333333 33333333 +fI[1] = #3fffb333 33333333 33333333 33333334 +fI[0] == strtod + + +Input: -1.7 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfffb333 33333333 33333333 33333334 +g_Qfmt(0) gives 37 bytes: "-1.7000000000000000000000000000000002" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffb333 33333333 33333333 33333334 +fI[1] = #bfffb333 33333333 33333333 33333333 +fI[0] == strtod + + +Input: 1.8 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffcccc cccccccc cccccccc cccccccc +g_Qfmt(0) gives 36 bytes: "1.7999999999999999999999999999999998" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fffcccc cccccccc cccccccc cccccccc +fI[1] = #3fffcccc cccccccc cccccccc cccccccd +fI[0] == strtod + + +Input: -1.8 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfffcccc cccccccc cccccccc cccccccd +g_Qfmt(0) gives 4 bytes: "-1.8" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfffcccc cccccccc cccccccc cccccccd +fI[1] = #bfffcccc cccccccc cccccccc cccccccc +fI[0] == strtod + + +Input: 1.9 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffe666 66666666 66666666 66666666 +g_Qfmt(0) gives 3 bytes: "1.9" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffe666 66666666 66666666 66666666 +fI[1] = #3fffe666 66666666 66666666 66666667 +fI[0] == strtod + + +Input: -1.9 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfffe666 66666666 66666666 66666667 +g_Qfmt(0) gives 37 bytes: "-1.9000000000000000000000000000000001" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffe666 66666666 66666666 66666667 +fI[1] = #bfffe666 66666666 66666666 66666666 +fI[0] == strtod + diff --git a/lib/libc/gdtoa/test/Q.ou1 b/lib/libc/gdtoa/test/Q.ou1 new file mode 100644 index 000000000..cb2a23f61 --- /dev/null +++ b/lib/libc/gdtoa/test/Q.ou1 @@ -0,0 +1,1468 @@ + +Input: 1.23 + +strtoQ consumes 4 bytes and returns 17 +with bits = #3fff3ae1 47ae147a e147ae14 7ae147ae +printf("%.35Lg") gives 1.23 +g_Qfmt(0) gives 4 bytes: "1.23" + +strtoIQ returns 17, consuming 4 bytes. +fI[0] = #3fff3ae1 47ae147a e147ae14 7ae147ae += 1.23 +fI[1] = #3fff3ae1 47ae147a e147ae14 7ae147af += 1.2300000000000000000000000000000002 +fI[0] == strtod + + +Input: 1.23e+20 + +strtoQ consumes 8 bytes and returns 1 +with bits = #4041aabd f2145b43 0 0 +printf("%.35Lg") gives 123000000000000000000 +g_Qfmt(0) gives 8 bytes: "1.23e+20" + +strtoIQ returns 1, consuming 8 bytes. +fI[0] == fI[1] = #4041aabd f2145b43 0 0 += 123000000000000000000 + + +Input: 1.23e-20 + +strtoQ consumes 8 bytes and returns 17 +with bits = #3fbcd0ae 4cf76753 9e4cbca ad934841 +printf("%.35Lg") gives 1.2299999999999999999999999999999999e-20 +g_Qfmt(0) gives 8 bytes: "1.23e-20" + +strtoIQ returns 17, consuming 8 bytes. +fI[0] = #3fbcd0ae 4cf76753 9e4cbca ad934841 += 1.2299999999999999999999999999999999e-20 +fI[1] = #3fbcd0ae 4cf76753 9e4cbca ad934842 += 1.2300000000000000000000000000000001e-20 +fI[0] == strtod + + +Input: 1.23456789 + +strtoQ consumes 10 bytes and returns 17 +with bits = #3fff3c0c a4283de1 b7eb6945 1304948f +printf("%.35Lg") gives 1.2345678899999999999999999999999999 +g_Qfmt(0) gives 10 bytes: "1.23456789" + +strtoIQ returns 17, consuming 10 bytes. +fI[0] = #3fff3c0c a4283de1 b7eb6945 1304948f += 1.2345678899999999999999999999999999 +fI[1] = #3fff3c0c a4283de1 b7eb6945 13049490 += 1.2345678900000000000000000000000001 +fI[0] == strtod + + +Input: 1.23456589e+20 + +strtoQ consumes 14 bytes and returns 1 +with bits = #4041ac53 7a660b99 74000000 0 +printf("%.35Lg") gives 123456589000000000000 +g_Qfmt(0) gives 14 bytes: "1.23456589e+20" + +strtoIQ returns 1, consuming 14 bytes. +fI[0] == fI[1] = #4041ac53 7a660b99 74000000 0 += 123456589000000000000 + + +Input: 1.23e+30 + +strtoQ consumes 8 bytes and returns 1 +with bits = #4062f0cb 4e8fb79 4945600 0 +printf("%.35Lg") gives 1230000000000000000000000000000 +g_Qfmt(0) gives 8 bytes: "1.23e+30" + +strtoIQ returns 1, consuming 8 bytes. +fI[0] == fI[1] = #4062f0cb 4e8fb79 4945600 0 += 1230000000000000000000000000000 + + +Input: 1.23e-30 + +strtoQ consumes 8 bytes and returns 17 +with bits = #3f9b8f28 66f5010a a9d63f9e d7e8ba14 +printf("%.35Lg") gives 1.2299999999999999999999999999999999e-30 +g_Qfmt(0) gives 8 bytes: "1.23e-30" + +strtoIQ returns 17, consuming 8 bytes. +fI[0] = #3f9b8f28 66f5010a a9d63f9e d7e8ba14 += 1.2299999999999999999999999999999999e-30 +fI[1] = #3f9b8f28 66f5010a a9d63f9e d7e8ba15 += 1.2300000000000000000000000000000001e-30 +fI[0] == strtod + + +Input: 1.23456789e-20 + +strtoQ consumes 14 bytes and returns 33 +with bits = #3fbcd268 1471e7ad a6a4a029 d86c1fa2 +printf("%.35Lg") gives 1.2345678900000000000000000000000001e-20 +g_Qfmt(0) gives 14 bytes: "1.23456789e-20" + +strtoIQ returns 33, consuming 14 bytes. +fI[0] = #3fbcd268 1471e7ad a6a4a029 d86c1fa1 += 1.2345678899999999999999999999999999e-20 +fI[1] = #3fbcd268 1471e7ad a6a4a029 d86c1fa2 += 1.2345678900000000000000000000000001e-20 +fI[1] == strtod + + +Input: 1.23456789e-30 + +strtoQ consumes 14 bytes and returns 17 +with bits = #3f9b90a3 e33bbd99 51f85855 5a6b19d4 +printf("%.35Lg") gives 1.23456789e-30 +g_Qfmt(0) gives 14 bytes: "1.23456789e-30" + +strtoIQ returns 17, consuming 14 bytes. +fI[0] = #3f9b90a3 e33bbd99 51f85855 5a6b19d4 += 1.23456789e-30 +fI[1] = #3f9b90a3 e33bbd99 51f85855 5a6b19d5 += 1.2345678900000000000000000000000001e-30 +fI[0] == strtod + + +Input: 1.234567890123456789 + +strtoQ consumes 20 bytes and returns 17 +with bits = #3fff3c0c a428c59f b71a4194 68dd175b +printf("%.35Lg") gives 1.234567890123456789 +g_Qfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIQ returns 17, consuming 20 bytes. +fI[0] = #3fff3c0c a428c59f b71a4194 68dd175b += 1.234567890123456789 +fI[1] = #3fff3c0c a428c59f b71a4194 68dd175c += 1.2345678901234567890000000000000002 +fI[0] == strtod + + +Input: 1.23456789012345678901234567890123456789 + +strtoQ consumes 40 bytes and returns 17 +with bits = #3fff3c0c a428c59f b71a7be1 6b6b6d5b +printf("%.35Lg") gives 1.2345678901234567890123456789012346 +g_Qfmt(0) gives 36 bytes: "1.2345678901234567890123456789012346" + +strtoIQ returns 17, consuming 40 bytes. +fI[0] = #3fff3c0c a428c59f b71a7be1 6b6b6d5b += 1.2345678901234567890123456789012346 +fI[1] = #3fff3c0c a428c59f b71a7be1 6b6b6d5c += 1.2345678901234567890123456789012347 +fI[0] == strtod + + +Input: 1.23e306 + +strtoQ consumes 8 bytes and returns 33 +with bits = #43f7c067 6cd1c61f 4daac5f1 e9fa3b55 +printf("%.35Lg") gives 1.23e+306 +g_Qfmt(0) gives 9 bytes: "1.23e+306" + +strtoIQ returns 33, consuming 8 bytes. +fI[0] = #43f7c067 6cd1c61f 4daac5f1 e9fa3b54 += 1.2299999999999999999999999999999999e+306 +fI[1] = #43f7c067 6cd1c61f 4daac5f1 e9fa3b55 += 1.23e+306 +fI[1] == strtod + + +Input: 1.23e-306 + +strtoQ consumes 9 bytes and returns 17 +with bits = #3c06ba3b 85da396e 7e496ab7 d233c3dd +printf("%.35Lg") gives 1.23e-306 +g_Qfmt(0) gives 9 bytes: "1.23e-306" + +strtoIQ returns 17, consuming 9 bytes. +fI[0] = #3c06ba3b 85da396e 7e496ab7 d233c3dd += 1.23e-306 +fI[1] = #3c06ba3b 85da396e 7e496ab7 d233c3de += 1.2300000000000000000000000000000001e-306 +fI[0] == strtod + + +Input: 1.23e-320 + +strtoQ consumes 9 bytes and returns 33 +with bits = #3bd83731 86e30898 7e33b2e8 355f847b +printf("%.35Lg") gives 1.2300000000000000000000000000000001e-320 +g_Qfmt(0) gives 9 bytes: "1.23e-320" + +strtoIQ returns 33, consuming 9 bytes. +fI[0] = #3bd83731 86e30898 7e33b2e8 355f847a += 1.2299999999999999999999999999999999e-320 +fI[1] = #3bd83731 86e30898 7e33b2e8 355f847b += 1.2300000000000000000000000000000001e-320 +fI[1] == strtod + + +Input: 1.23e-20 + +strtoQ consumes 8 bytes and returns 17 +with bits = #3fbcd0ae 4cf76753 9e4cbca ad934841 +printf("%.35Lg") gives 1.2299999999999999999999999999999999e-20 +g_Qfmt(0) gives 8 bytes: "1.23e-20" + +strtoIQ returns 17, consuming 8 bytes. +fI[0] = #3fbcd0ae 4cf76753 9e4cbca ad934841 += 1.2299999999999999999999999999999999e-20 +fI[1] = #3fbcd0ae 4cf76753 9e4cbca ad934842 += 1.2300000000000000000000000000000001e-20 +fI[0] == strtod + + +Input: 1.23456789e307 + +strtoQ consumes 14 bytes and returns 17 +with bits = #43fb194b 14bdaecd bcea468c 902464cf +printf("%.35Lg") gives 1.2345678899999999999999999999999999e+307 +g_Qfmt(0) gives 15 bytes: "1.23456789e+307" + +strtoIQ returns 17, consuming 14 bytes. +fI[0] = #43fb194b 14bdaecd bcea468c 902464cf += 1.2345678899999999999999999999999999e+307 +fI[1] = #43fb194b 14bdaecd bcea468c 902464d0 += 1.2345678900000000000000000000000001e+307 +fI[0] == strtod + + +Input: 1.23456589e-307 + +strtoQ consumes 15 bytes and returns 17 +with bits = #3c036319 6bb9845f a6d234e3 39163574 +printf("%.35Lg") gives 1.23456589e-307 +g_Qfmt(0) gives 15 bytes: "1.23456589e-307" + +strtoIQ returns 17, consuming 15 bytes. +fI[0] = #3c036319 6bb9845f a6d234e3 39163574 += 1.23456589e-307 +fI[1] = #3c036319 6bb9845f a6d234e3 39163575 += 1.2345658900000000000000000000000002e-307 +fI[0] == strtod + + +Input: 1.234567890123456789 + +strtoQ consumes 20 bytes and returns 17 +with bits = #3fff3c0c a428c59f b71a4194 68dd175b +printf("%.35Lg") gives 1.234567890123456789 +g_Qfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIQ returns 17, consuming 20 bytes. +fI[0] = #3fff3c0c a428c59f b71a4194 68dd175b += 1.234567890123456789 +fI[1] = #3fff3c0c a428c59f b71a4194 68dd175c += 1.2345678901234567890000000000000002 +fI[0] == strtod + + +Input: 1.234567890123456789e301 + +strtoQ consumes 24 bytes and returns 33 +with bits = #43e726f5 175f5641 3017ea80 763990ef +printf("%.35Lg") gives 1.2345678901234567890000000000000001e+301 +g_Qfmt(0) gives 25 bytes: "1.234567890123456789e+301" + +strtoIQ returns 33, consuming 24 bytes. +fI[0] = #43e726f5 175f5641 3017ea80 763990ee += 1.2345678901234567889999999999999999e+301 +fI[1] = #43e726f5 175f5641 3017ea80 763990ef += 1.2345678901234567890000000000000001e+301 +fI[1] == strtod + + +Input: 1.234567890123456789e-301 + +strtoQ consumes 25 bytes and returns 17 +with bits = #3c1752a6 4e34ba0d 35b19b04 3222fce5 +printf("%.35Lg") gives 1.234567890123456789e-301 +g_Qfmt(0) gives 25 bytes: "1.234567890123456789e-301" + +strtoIQ returns 17, consuming 25 bytes. +fI[0] = #3c1752a6 4e34ba0d 35b19b04 3222fce5 += 1.234567890123456789e-301 +fI[1] = #3c1752a6 4e34ba0d 35b19b04 3222fce6 += 1.2345678901234567890000000000000002e-301 +fI[0] == strtod + + +Input: 1.234567890123456789e-321 + +strtoQ consumes 25 bytes and returns 17 +with bits = #3bd4f3c2 3699d4db 99d1ea94 2fecd7de +printf("%.35Lg") gives 1.234567890123456789e-321 +g_Qfmt(0) gives 25 bytes: "1.234567890123456789e-321" + +strtoIQ returns 17, consuming 25 bytes. +fI[0] = #3bd4f3c2 3699d4db 99d1ea94 2fecd7de += 1.234567890123456789e-321 +fI[1] = #3bd4f3c2 3699d4db 99d1ea94 2fecd7df += 1.2345678901234567890000000000000001e-321 +fI[0] == strtod + + +Input: 1e23 + +strtoQ consumes 4 bytes and returns 1 +with bits = #404b52d0 2c7e14af 68000000 0 +printf("%.35Lg") gives 100000000000000000000000 +g_Qfmt(0) gives 5 bytes: "1e+23" + +strtoIQ returns 1, consuming 4 bytes. +fI[0] == fI[1] = #404b52d0 2c7e14af 68000000 0 += 100000000000000000000000 + + +Input: 1e310 + +strtoQ consumes 5 bytes and returns 33 +with bits = #4404bd03 c8140697 9e9ff00e fefd4cbd +printf("%.35Lg") gives 1e+310 +g_Qfmt(0) gives 6 bytes: "1e+310" + +strtoIQ returns 33, consuming 5 bytes. +fI[0] = #4404bd03 c8140697 9e9ff00e fefd4cbc += 9.9999999999999999999999999999999992e+309 +fI[1] = #4404bd03 c8140697 9e9ff00e fefd4cbd += 1e+310 +fI[1] == strtod + + +Input: 9.0259718793241475e-277 + +strtoQ consumes 23 bytes and returns 17 +with bits = #3c69ffff ffffffff f9ed5779 ac118fe1 +printf("%.35Lg") gives 9.0259718793241474999999999999999997e-277 +g_Qfmt(0) gives 23 bytes: "9.0259718793241475e-277" + +strtoIQ returns 17, consuming 23 bytes. +fI[0] = #3c69ffff ffffffff f9ed5779 ac118fe1 += 9.0259718793241474999999999999999997e-277 +fI[1] = #3c69ffff ffffffff f9ed5779 ac118fe2 += 9.0259718793241475000000000000000006e-277 +fI[0] == strtod + + +Input: 9.025971879324147880346310405869e-277 + +strtoQ consumes 37 bytes and returns 33 +with bits = #3c6a0000 0 0 9a +printf("%.35Lg") gives 9.0259718793241478803463104058690004e-277 +g_Qfmt(0) gives 37 bytes: "9.025971879324147880346310405869e-277" + +strtoIQ returns 33, consuming 37 bytes. +fI[0] = #3c6a0000 0 0 99 += 9.0259718793241478803463104058689987e-277 +fI[1] = #3c6a0000 0 0 9a += 9.0259718793241478803463104058690004e-277 +fI[1] == strtod + + +Input: 9.025971879324147880346310405868e-277 + +strtoQ consumes 37 bytes and returns 17 +with bits = #3c69ffff ffffffff ffffffff fffffcb5 +printf("%.35Lg") gives 9.025971879324147880346310405868e-277 +g_Qfmt(0) gives 37 bytes: "9.025971879324147880346310405868e-277" + +strtoIQ returns 17, consuming 37 bytes. +fI[0] = #3c69ffff ffffffff ffffffff fffffcb5 += 9.025971879324147880346310405868e-277 +fI[1] = #3c69ffff ffffffff ffffffff fffffcb6 += 9.0259718793241478803463104058680009e-277 +fI[0] == strtod + + +Input: 2.2250738585072014e-308 + +strtoQ consumes 23 bytes and returns 33 +with bits = #3c010000 0 8c304c cf867de0 +printf("%.35Lg") gives 2.2250738585072014000000000000000001e-308 +g_Qfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoIQ returns 33, consuming 23 bytes. +fI[0] = #3c010000 0 8c304c cf867ddf += 2.2250738585072013999999999999999997e-308 +fI[1] = #3c010000 0 8c304c cf867de0 += 2.2250738585072014000000000000000001e-308 +fI[1] == strtod + + +Input: 2.2250738585072013e-308 + +strtoQ consumes 23 bytes and returns 33 +with bits = #3c00ffff ffffffff fa9e4c4f 4c1e8a10 +printf("%.35Lg") gives 2.2250738585072013e-308 +g_Qfmt(0) gives 23 bytes: "2.2250738585072013e-308" + +strtoIQ returns 33, consuming 23 bytes. +fI[0] = #3c00ffff ffffffff fa9e4c4f 4c1e8a0f += 2.2250738585072012999999999999999998e-308 +fI[1] = #3c00ffff ffffffff fa9e4c4f 4c1e8a10 += 2.2250738585072013e-308 +fI[1] == strtod + +Rounding mode for strtor... changed from 1 (nearest) to 0 (toward zero) + +Input: 1.1 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff1999 99999999 99999999 99999999 +printf("%.35Lg") gives 1.0999999999999999999999999999999999 +g_Qfmt(0) gives 36 bytes: "1.0999999999999999999999999999999999" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff1999 99999999 99999999 99999999 += 1.0999999999999999999999999999999999 +fI[1] = #3fff1999 99999999 99999999 9999999a += 1.1000000000000000000000000000000001 +fI[0] == strtod + + +Input: -1.1 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff1999 99999999 99999999 99999999 +printf("%.35Lg") gives -1.0999999999999999999999999999999999 +g_Qfmt(0) gives 37 bytes: "-1.0999999999999999999999999999999999" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff1999 99999999 99999999 9999999a += -1.1000000000000000000000000000000001 +fI[1] = #bfff1999 99999999 99999999 99999999 += -1.0999999999999999999999999999999999 +fI[1] == strtod + + +Input: 1.2 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff3333 33333333 33333333 33333333 +printf("%.35Lg") gives 1.2 +g_Qfmt(0) gives 3 bytes: "1.2" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff3333 33333333 33333333 33333333 += 1.2 +fI[1] = #3fff3333 33333333 33333333 33333334 += 1.2000000000000000000000000000000002 +fI[0] == strtod + + +Input: -1.2 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff3333 33333333 33333333 33333333 +printf("%.35Lg") gives -1.2 +g_Qfmt(0) gives 4 bytes: "-1.2" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff3333 33333333 33333333 33333334 += -1.2000000000000000000000000000000002 +fI[1] = #bfff3333 33333333 33333333 33333333 += -1.2 +fI[1] == strtod + + +Input: 1.3 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff4ccc cccccccc cccccccc cccccccc +printf("%.35Lg") gives 1.2999999999999999999999999999999998 +g_Qfmt(0) gives 36 bytes: "1.2999999999999999999999999999999998" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff4ccc cccccccc cccccccc cccccccc += 1.2999999999999999999999999999999998 +fI[1] = #3fff4ccc cccccccc cccccccc cccccccd += 1.3 +fI[0] == strtod + + +Input: -1.3 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff4ccc cccccccc cccccccc cccccccc +printf("%.35Lg") gives -1.2999999999999999999999999999999998 +g_Qfmt(0) gives 37 bytes: "-1.2999999999999999999999999999999998" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff4ccc cccccccc cccccccc cccccccd += -1.3 +fI[1] = #bfff4ccc cccccccc cccccccc cccccccc += -1.2999999999999999999999999999999998 +fI[1] == strtod + + +Input: 1.4 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff6666 66666666 66666666 66666666 +printf("%.35Lg") gives 1.3999999999999999999999999999999999 +g_Qfmt(0) gives 3 bytes: "1.4" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff6666 66666666 66666666 66666666 += 1.3999999999999999999999999999999999 +fI[1] = #3fff6666 66666666 66666666 66666667 += 1.4000000000000000000000000000000001 +fI[0] == strtod + + +Input: -1.4 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff6666 66666666 66666666 66666666 +printf("%.35Lg") gives -1.3999999999999999999999999999999999 +g_Qfmt(0) gives 4 bytes: "-1.4" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff6666 66666666 66666666 66666667 += -1.4000000000000000000000000000000001 +fI[1] = #bfff6666 66666666 66666666 66666666 += -1.3999999999999999999999999999999999 +fI[1] == strtod + + +Input: 1.5 + +strtoQ consumes 3 bytes and returns 1 +with bits = #3fff8000 0 0 0 +printf("%.35Lg") gives 1.5 +g_Qfmt(0) gives 3 bytes: "1.5" + +strtoIQ returns 1, consuming 3 bytes. +fI[0] == fI[1] = #3fff8000 0 0 0 += 1.5 + + +Input: -1.5 + +strtoQ consumes 4 bytes and returns 9 +with bits = #bfff8000 0 0 0 +printf("%.35Lg") gives -1.5 +g_Qfmt(0) gives 4 bytes: "-1.5" + +strtoIQ returns 9, consuming 4 bytes. +fI[0] == fI[1] = #bfff8000 0 0 0 += -1.5 + + +Input: 1.6 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff9999 99999999 99999999 99999999 +printf("%.35Lg") gives 1.5999999999999999999999999999999999 +g_Qfmt(0) gives 36 bytes: "1.5999999999999999999999999999999999" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff9999 99999999 99999999 99999999 += 1.5999999999999999999999999999999999 +fI[1] = #3fff9999 99999999 99999999 9999999a += 1.6000000000000000000000000000000001 +fI[0] == strtod + + +Input: -1.6 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff9999 99999999 99999999 99999999 +printf("%.35Lg") gives -1.5999999999999999999999999999999999 +g_Qfmt(0) gives 37 bytes: "-1.5999999999999999999999999999999999" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff9999 99999999 99999999 9999999a += -1.6000000000000000000000000000000001 +fI[1] = #bfff9999 99999999 99999999 99999999 += -1.5999999999999999999999999999999999 +fI[1] == strtod + + +Input: 1.7 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffb333 33333333 33333333 33333333 +printf("%.35Lg") gives 1.7 +g_Qfmt(0) gives 3 bytes: "1.7" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffb333 33333333 33333333 33333333 += 1.7 +fI[1] = #3fffb333 33333333 33333333 33333334 += 1.7000000000000000000000000000000002 +fI[0] == strtod + + +Input: -1.7 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffb333 33333333 33333333 33333333 +printf("%.35Lg") gives -1.7 +g_Qfmt(0) gives 4 bytes: "-1.7" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffb333 33333333 33333333 33333334 += -1.7000000000000000000000000000000002 +fI[1] = #bfffb333 33333333 33333333 33333333 += -1.7 +fI[1] == strtod + + +Input: 1.8 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffcccc cccccccc cccccccc cccccccc +printf("%.35Lg") gives 1.7999999999999999999999999999999998 +g_Qfmt(0) gives 36 bytes: "1.7999999999999999999999999999999998" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fffcccc cccccccc cccccccc cccccccc += 1.7999999999999999999999999999999998 +fI[1] = #3fffcccc cccccccc cccccccc cccccccd += 1.8 +fI[0] == strtod + + +Input: -1.8 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffcccc cccccccc cccccccc cccccccc +printf("%.35Lg") gives -1.7999999999999999999999999999999998 +g_Qfmt(0) gives 37 bytes: "-1.7999999999999999999999999999999998" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfffcccc cccccccc cccccccc cccccccd += -1.8 +fI[1] = #bfffcccc cccccccc cccccccc cccccccc += -1.7999999999999999999999999999999998 +fI[1] == strtod + + +Input: 1.9 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffe666 66666666 66666666 66666666 +printf("%.35Lg") gives 1.8999999999999999999999999999999999 +g_Qfmt(0) gives 3 bytes: "1.9" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffe666 66666666 66666666 66666666 += 1.8999999999999999999999999999999999 +fI[1] = #3fffe666 66666666 66666666 66666667 += 1.9000000000000000000000000000000001 +fI[0] == strtod + + +Input: -1.9 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffe666 66666666 66666666 66666666 +printf("%.35Lg") gives -1.8999999999999999999999999999999999 +g_Qfmt(0) gives 4 bytes: "-1.9" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffe666 66666666 66666666 66666667 += -1.9000000000000000000000000000000001 +fI[1] = #bfffe666 66666666 66666666 66666666 += -1.8999999999999999999999999999999999 +fI[1] == strtod + +Rounding mode for strtor... changed from 0 (toward zero) to 1 (nearest) + +Input: 1.1 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff1999 99999999 99999999 9999999a +printf("%.35Lg") gives 1.1000000000000000000000000000000001 +g_Qfmt(0) gives 3 bytes: "1.1" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff1999 99999999 99999999 99999999 += 1.0999999999999999999999999999999999 +fI[1] = #3fff1999 99999999 99999999 9999999a += 1.1000000000000000000000000000000001 +fI[1] == strtod + + +Input: -1.1 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff1999 99999999 99999999 9999999a +printf("%.35Lg") gives -1.1000000000000000000000000000000001 +g_Qfmt(0) gives 4 bytes: "-1.1" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff1999 99999999 99999999 9999999a += -1.1000000000000000000000000000000001 +fI[1] = #bfff1999 99999999 99999999 99999999 += -1.0999999999999999999999999999999999 +fI[0] == strtod + + +Input: 1.2 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff3333 33333333 33333333 33333333 +printf("%.35Lg") gives 1.2 +g_Qfmt(0) gives 3 bytes: "1.2" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff3333 33333333 33333333 33333333 += 1.2 +fI[1] = #3fff3333 33333333 33333333 33333334 += 1.2000000000000000000000000000000002 +fI[0] == strtod + + +Input: -1.2 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff3333 33333333 33333333 33333333 +printf("%.35Lg") gives -1.2 +g_Qfmt(0) gives 4 bytes: "-1.2" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff3333 33333333 33333333 33333334 += -1.2000000000000000000000000000000002 +fI[1] = #bfff3333 33333333 33333333 33333333 += -1.2 +fI[1] == strtod + + +Input: 1.3 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff4ccc cccccccc cccccccc cccccccd +printf("%.35Lg") gives 1.3 +g_Qfmt(0) gives 3 bytes: "1.3" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff4ccc cccccccc cccccccc cccccccc += 1.2999999999999999999999999999999998 +fI[1] = #3fff4ccc cccccccc cccccccc cccccccd += 1.3 +fI[1] == strtod + + +Input: -1.3 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff4ccc cccccccc cccccccc cccccccd +printf("%.35Lg") gives -1.3 +g_Qfmt(0) gives 4 bytes: "-1.3" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff4ccc cccccccc cccccccc cccccccd += -1.3 +fI[1] = #bfff4ccc cccccccc cccccccc cccccccc += -1.2999999999999999999999999999999998 +fI[0] == strtod + + +Input: 1.4 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff6666 66666666 66666666 66666666 +printf("%.35Lg") gives 1.3999999999999999999999999999999999 +g_Qfmt(0) gives 3 bytes: "1.4" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff6666 66666666 66666666 66666666 += 1.3999999999999999999999999999999999 +fI[1] = #3fff6666 66666666 66666666 66666667 += 1.4000000000000000000000000000000001 +fI[0] == strtod + + +Input: -1.4 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff6666 66666666 66666666 66666666 +printf("%.35Lg") gives -1.3999999999999999999999999999999999 +g_Qfmt(0) gives 4 bytes: "-1.4" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff6666 66666666 66666666 66666667 += -1.4000000000000000000000000000000001 +fI[1] = #bfff6666 66666666 66666666 66666666 += -1.3999999999999999999999999999999999 +fI[1] == strtod + + +Input: 1.5 + +strtoQ consumes 3 bytes and returns 1 +with bits = #3fff8000 0 0 0 +printf("%.35Lg") gives 1.5 +g_Qfmt(0) gives 3 bytes: "1.5" + +strtoIQ returns 1, consuming 3 bytes. +fI[0] == fI[1] = #3fff8000 0 0 0 += 1.5 + + +Input: -1.5 + +strtoQ consumes 4 bytes and returns 9 +with bits = #bfff8000 0 0 0 +printf("%.35Lg") gives -1.5 +g_Qfmt(0) gives 4 bytes: "-1.5" + +strtoIQ returns 9, consuming 4 bytes. +fI[0] == fI[1] = #bfff8000 0 0 0 += -1.5 + + +Input: 1.6 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff9999 99999999 99999999 9999999a +printf("%.35Lg") gives 1.6000000000000000000000000000000001 +g_Qfmt(0) gives 3 bytes: "1.6" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff9999 99999999 99999999 99999999 += 1.5999999999999999999999999999999999 +fI[1] = #3fff9999 99999999 99999999 9999999a += 1.6000000000000000000000000000000001 +fI[1] == strtod + + +Input: -1.6 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff9999 99999999 99999999 9999999a +printf("%.35Lg") gives -1.6000000000000000000000000000000001 +g_Qfmt(0) gives 4 bytes: "-1.6" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff9999 99999999 99999999 9999999a += -1.6000000000000000000000000000000001 +fI[1] = #bfff9999 99999999 99999999 99999999 += -1.5999999999999999999999999999999999 +fI[0] == strtod + + +Input: 1.7 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffb333 33333333 33333333 33333333 +printf("%.35Lg") gives 1.7 +g_Qfmt(0) gives 3 bytes: "1.7" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffb333 33333333 33333333 33333333 += 1.7 +fI[1] = #3fffb333 33333333 33333333 33333334 += 1.7000000000000000000000000000000002 +fI[0] == strtod + + +Input: -1.7 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffb333 33333333 33333333 33333333 +printf("%.35Lg") gives -1.7 +g_Qfmt(0) gives 4 bytes: "-1.7" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffb333 33333333 33333333 33333334 += -1.7000000000000000000000000000000002 +fI[1] = #bfffb333 33333333 33333333 33333333 += -1.7 +fI[1] == strtod + + +Input: 1.8 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fffcccc cccccccc cccccccc cccccccd +printf("%.35Lg") gives 1.8 +g_Qfmt(0) gives 3 bytes: "1.8" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fffcccc cccccccc cccccccc cccccccc += 1.7999999999999999999999999999999998 +fI[1] = #3fffcccc cccccccc cccccccc cccccccd += 1.8 +fI[1] == strtod + + +Input: -1.8 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfffcccc cccccccc cccccccc cccccccd +printf("%.35Lg") gives -1.8 +g_Qfmt(0) gives 4 bytes: "-1.8" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfffcccc cccccccc cccccccc cccccccd += -1.8 +fI[1] = #bfffcccc cccccccc cccccccc cccccccc += -1.7999999999999999999999999999999998 +fI[0] == strtod + + +Input: 1.9 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffe666 66666666 66666666 66666666 +printf("%.35Lg") gives 1.8999999999999999999999999999999999 +g_Qfmt(0) gives 3 bytes: "1.9" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffe666 66666666 66666666 66666666 += 1.8999999999999999999999999999999999 +fI[1] = #3fffe666 66666666 66666666 66666667 += 1.9000000000000000000000000000000001 +fI[0] == strtod + + +Input: -1.9 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffe666 66666666 66666666 66666666 +printf("%.35Lg") gives -1.8999999999999999999999999999999999 +g_Qfmt(0) gives 4 bytes: "-1.9" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffe666 66666666 66666666 66666667 += -1.9000000000000000000000000000000001 +fI[1] = #bfffe666 66666666 66666666 66666666 += -1.8999999999999999999999999999999999 +fI[1] == strtod + +Rounding mode for strtor... changed from 1 (nearest) to 2 (toward +Infinity) + +Input: 1.1 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff1999 99999999 99999999 9999999a +printf("%.35Lg") gives 1.1000000000000000000000000000000001 +g_Qfmt(0) gives 3 bytes: "1.1" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff1999 99999999 99999999 99999999 += 1.0999999999999999999999999999999999 +fI[1] = #3fff1999 99999999 99999999 9999999a += 1.1000000000000000000000000000000001 +fI[1] == strtod + + +Input: -1.1 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff1999 99999999 99999999 99999999 +printf("%.35Lg") gives -1.0999999999999999999999999999999999 +g_Qfmt(0) gives 37 bytes: "-1.0999999999999999999999999999999999" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff1999 99999999 99999999 9999999a += -1.1000000000000000000000000000000001 +fI[1] = #bfff1999 99999999 99999999 99999999 += -1.0999999999999999999999999999999999 +fI[1] == strtod + + +Input: 1.2 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff3333 33333333 33333333 33333334 +printf("%.35Lg") gives 1.2000000000000000000000000000000002 +g_Qfmt(0) gives 36 bytes: "1.2000000000000000000000000000000002" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff3333 33333333 33333333 33333333 += 1.2 +fI[1] = #3fff3333 33333333 33333333 33333334 += 1.2000000000000000000000000000000002 +fI[1] == strtod + + +Input: -1.2 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff3333 33333333 33333333 33333333 +printf("%.35Lg") gives -1.2 +g_Qfmt(0) gives 4 bytes: "-1.2" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff3333 33333333 33333333 33333334 += -1.2000000000000000000000000000000002 +fI[1] = #bfff3333 33333333 33333333 33333333 += -1.2 +fI[1] == strtod + + +Input: 1.3 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff4ccc cccccccc cccccccc cccccccd +printf("%.35Lg") gives 1.3 +g_Qfmt(0) gives 3 bytes: "1.3" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff4ccc cccccccc cccccccc cccccccc += 1.2999999999999999999999999999999998 +fI[1] = #3fff4ccc cccccccc cccccccc cccccccd += 1.3 +fI[1] == strtod + + +Input: -1.3 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff4ccc cccccccc cccccccc cccccccc +printf("%.35Lg") gives -1.2999999999999999999999999999999998 +g_Qfmt(0) gives 37 bytes: "-1.2999999999999999999999999999999998" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff4ccc cccccccc cccccccc cccccccd += -1.3 +fI[1] = #bfff4ccc cccccccc cccccccc cccccccc += -1.2999999999999999999999999999999998 +fI[1] == strtod + + +Input: 1.4 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff6666 66666666 66666666 66666667 +printf("%.35Lg") gives 1.4000000000000000000000000000000001 +g_Qfmt(0) gives 36 bytes: "1.4000000000000000000000000000000001" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff6666 66666666 66666666 66666666 += 1.3999999999999999999999999999999999 +fI[1] = #3fff6666 66666666 66666666 66666667 += 1.4000000000000000000000000000000001 +fI[1] == strtod + + +Input: -1.4 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff6666 66666666 66666666 66666666 +printf("%.35Lg") gives -1.3999999999999999999999999999999999 +g_Qfmt(0) gives 4 bytes: "-1.4" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff6666 66666666 66666666 66666667 += -1.4000000000000000000000000000000001 +fI[1] = #bfff6666 66666666 66666666 66666666 += -1.3999999999999999999999999999999999 +fI[1] == strtod + + +Input: 1.5 + +strtoQ consumes 3 bytes and returns 1 +with bits = #3fff8000 0 0 0 +printf("%.35Lg") gives 1.5 +g_Qfmt(0) gives 3 bytes: "1.5" + +strtoIQ returns 1, consuming 3 bytes. +fI[0] == fI[1] = #3fff8000 0 0 0 += 1.5 + + +Input: -1.5 + +strtoQ consumes 4 bytes and returns 9 +with bits = #bfff8000 0 0 0 +printf("%.35Lg") gives -1.5 +g_Qfmt(0) gives 4 bytes: "-1.5" + +strtoIQ returns 9, consuming 4 bytes. +fI[0] == fI[1] = #bfff8000 0 0 0 += -1.5 + + +Input: 1.6 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fff9999 99999999 99999999 9999999a +printf("%.35Lg") gives 1.6000000000000000000000000000000001 +g_Qfmt(0) gives 3 bytes: "1.6" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff9999 99999999 99999999 99999999 += 1.5999999999999999999999999999999999 +fI[1] = #3fff9999 99999999 99999999 9999999a += 1.6000000000000000000000000000000001 +fI[1] == strtod + + +Input: -1.6 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfff9999 99999999 99999999 99999999 +printf("%.35Lg") gives -1.5999999999999999999999999999999999 +g_Qfmt(0) gives 37 bytes: "-1.5999999999999999999999999999999999" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff9999 99999999 99999999 9999999a += -1.6000000000000000000000000000000001 +fI[1] = #bfff9999 99999999 99999999 99999999 += -1.5999999999999999999999999999999999 +fI[1] == strtod + + +Input: 1.7 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fffb333 33333333 33333333 33333334 +printf("%.35Lg") gives 1.7000000000000000000000000000000002 +g_Qfmt(0) gives 36 bytes: "1.7000000000000000000000000000000002" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffb333 33333333 33333333 33333333 += 1.7 +fI[1] = #3fffb333 33333333 33333333 33333334 += 1.7000000000000000000000000000000002 +fI[1] == strtod + + +Input: -1.7 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffb333 33333333 33333333 33333333 +printf("%.35Lg") gives -1.7 +g_Qfmt(0) gives 4 bytes: "-1.7" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffb333 33333333 33333333 33333334 += -1.7000000000000000000000000000000002 +fI[1] = #bfffb333 33333333 33333333 33333333 += -1.7 +fI[1] == strtod + + +Input: 1.8 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fffcccc cccccccc cccccccc cccccccd +printf("%.35Lg") gives 1.8 +g_Qfmt(0) gives 3 bytes: "1.8" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fffcccc cccccccc cccccccc cccccccc += 1.7999999999999999999999999999999998 +fI[1] = #3fffcccc cccccccc cccccccc cccccccd += 1.8 +fI[1] == strtod + + +Input: -1.8 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffcccc cccccccc cccccccc cccccccc +printf("%.35Lg") gives -1.7999999999999999999999999999999998 +g_Qfmt(0) gives 37 bytes: "-1.7999999999999999999999999999999998" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfffcccc cccccccc cccccccc cccccccd += -1.8 +fI[1] = #bfffcccc cccccccc cccccccc cccccccc += -1.7999999999999999999999999999999998 +fI[1] == strtod + + +Input: 1.9 + +strtoQ consumes 3 bytes and returns 33 +with bits = #3fffe666 66666666 66666666 66666667 +printf("%.35Lg") gives 1.9000000000000000000000000000000001 +g_Qfmt(0) gives 36 bytes: "1.9000000000000000000000000000000001" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffe666 66666666 66666666 66666666 += 1.8999999999999999999999999999999999 +fI[1] = #3fffe666 66666666 66666666 66666667 += 1.9000000000000000000000000000000001 +fI[1] == strtod + + +Input: -1.9 + +strtoQ consumes 4 bytes and returns 25 +with bits = #bfffe666 66666666 66666666 66666666 +printf("%.35Lg") gives -1.8999999999999999999999999999999999 +g_Qfmt(0) gives 4 bytes: "-1.9" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffe666 66666666 66666666 66666667 += -1.9000000000000000000000000000000001 +fI[1] = #bfffe666 66666666 66666666 66666666 += -1.8999999999999999999999999999999999 +fI[1] == strtod + +Rounding mode for strtor... changed from 2 (toward +Infinity) to 3 (toward -Infinity) + +Input: 1.1 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff1999 99999999 99999999 99999999 +printf("%.35Lg") gives 1.0999999999999999999999999999999999 +g_Qfmt(0) gives 36 bytes: "1.0999999999999999999999999999999999" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff1999 99999999 99999999 99999999 += 1.0999999999999999999999999999999999 +fI[1] = #3fff1999 99999999 99999999 9999999a += 1.1000000000000000000000000000000001 +fI[0] == strtod + + +Input: -1.1 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff1999 99999999 99999999 9999999a +printf("%.35Lg") gives -1.1000000000000000000000000000000001 +g_Qfmt(0) gives 4 bytes: "-1.1" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff1999 99999999 99999999 9999999a += -1.1000000000000000000000000000000001 +fI[1] = #bfff1999 99999999 99999999 99999999 += -1.0999999999999999999999999999999999 +fI[0] == strtod + + +Input: 1.2 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff3333 33333333 33333333 33333333 +printf("%.35Lg") gives 1.2 +g_Qfmt(0) gives 3 bytes: "1.2" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff3333 33333333 33333333 33333333 += 1.2 +fI[1] = #3fff3333 33333333 33333333 33333334 += 1.2000000000000000000000000000000002 +fI[0] == strtod + + +Input: -1.2 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff3333 33333333 33333333 33333334 +printf("%.35Lg") gives -1.2000000000000000000000000000000002 +g_Qfmt(0) gives 37 bytes: "-1.2000000000000000000000000000000002" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff3333 33333333 33333333 33333334 += -1.2000000000000000000000000000000002 +fI[1] = #bfff3333 33333333 33333333 33333333 += -1.2 +fI[0] == strtod + + +Input: 1.3 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff4ccc cccccccc cccccccc cccccccc +printf("%.35Lg") gives 1.2999999999999999999999999999999998 +g_Qfmt(0) gives 36 bytes: "1.2999999999999999999999999999999998" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff4ccc cccccccc cccccccc cccccccc += 1.2999999999999999999999999999999998 +fI[1] = #3fff4ccc cccccccc cccccccc cccccccd += 1.3 +fI[0] == strtod + + +Input: -1.3 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff4ccc cccccccc cccccccc cccccccd +printf("%.35Lg") gives -1.3 +g_Qfmt(0) gives 4 bytes: "-1.3" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff4ccc cccccccc cccccccc cccccccd += -1.3 +fI[1] = #bfff4ccc cccccccc cccccccc cccccccc += -1.2999999999999999999999999999999998 +fI[0] == strtod + + +Input: 1.4 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff6666 66666666 66666666 66666666 +printf("%.35Lg") gives 1.3999999999999999999999999999999999 +g_Qfmt(0) gives 3 bytes: "1.4" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fff6666 66666666 66666666 66666666 += 1.3999999999999999999999999999999999 +fI[1] = #3fff6666 66666666 66666666 66666667 += 1.4000000000000000000000000000000001 +fI[0] == strtod + + +Input: -1.4 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff6666 66666666 66666666 66666667 +printf("%.35Lg") gives -1.4000000000000000000000000000000001 +g_Qfmt(0) gives 37 bytes: "-1.4000000000000000000000000000000001" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfff6666 66666666 66666666 66666667 += -1.4000000000000000000000000000000001 +fI[1] = #bfff6666 66666666 66666666 66666666 += -1.3999999999999999999999999999999999 +fI[0] == strtod + + +Input: 1.5 + +strtoQ consumes 3 bytes and returns 1 +with bits = #3fff8000 0 0 0 +printf("%.35Lg") gives 1.5 +g_Qfmt(0) gives 3 bytes: "1.5" + +strtoIQ returns 1, consuming 3 bytes. +fI[0] == fI[1] = #3fff8000 0 0 0 += 1.5 + + +Input: -1.5 + +strtoQ consumes 4 bytes and returns 9 +with bits = #bfff8000 0 0 0 +printf("%.35Lg") gives -1.5 +g_Qfmt(0) gives 4 bytes: "-1.5" + +strtoIQ returns 9, consuming 4 bytes. +fI[0] == fI[1] = #bfff8000 0 0 0 += -1.5 + + +Input: 1.6 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fff9999 99999999 99999999 99999999 +printf("%.35Lg") gives 1.5999999999999999999999999999999999 +g_Qfmt(0) gives 36 bytes: "1.5999999999999999999999999999999999" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fff9999 99999999 99999999 99999999 += 1.5999999999999999999999999999999999 +fI[1] = #3fff9999 99999999 99999999 9999999a += 1.6000000000000000000000000000000001 +fI[0] == strtod + + +Input: -1.6 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfff9999 99999999 99999999 9999999a +printf("%.35Lg") gives -1.6000000000000000000000000000000001 +g_Qfmt(0) gives 4 bytes: "-1.6" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfff9999 99999999 99999999 9999999a += -1.6000000000000000000000000000000001 +fI[1] = #bfff9999 99999999 99999999 99999999 += -1.5999999999999999999999999999999999 +fI[0] == strtod + + +Input: 1.7 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffb333 33333333 33333333 33333333 +printf("%.35Lg") gives 1.7 +g_Qfmt(0) gives 3 bytes: "1.7" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffb333 33333333 33333333 33333333 += 1.7 +fI[1] = #3fffb333 33333333 33333333 33333334 += 1.7000000000000000000000000000000002 +fI[0] == strtod + + +Input: -1.7 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfffb333 33333333 33333333 33333334 +printf("%.35Lg") gives -1.7000000000000000000000000000000002 +g_Qfmt(0) gives 37 bytes: "-1.7000000000000000000000000000000002" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffb333 33333333 33333333 33333334 += -1.7000000000000000000000000000000002 +fI[1] = #bfffb333 33333333 33333333 33333333 += -1.7 +fI[0] == strtod + + +Input: 1.8 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffcccc cccccccc cccccccc cccccccc +printf("%.35Lg") gives 1.7999999999999999999999999999999998 +g_Qfmt(0) gives 36 bytes: "1.7999999999999999999999999999999998" + +strtoIQ returns 33, consuming 3 bytes. +fI[0] = #3fffcccc cccccccc cccccccc cccccccc += 1.7999999999999999999999999999999998 +fI[1] = #3fffcccc cccccccc cccccccc cccccccd += 1.8 +fI[0] == strtod + + +Input: -1.8 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfffcccc cccccccc cccccccc cccccccd +printf("%.35Lg") gives -1.8 +g_Qfmt(0) gives 4 bytes: "-1.8" + +strtoIQ returns 41, consuming 4 bytes. +fI[0] = #bfffcccc cccccccc cccccccc cccccccd += -1.8 +fI[1] = #bfffcccc cccccccc cccccccc cccccccc += -1.7999999999999999999999999999999998 +fI[0] == strtod + + +Input: 1.9 + +strtoQ consumes 3 bytes and returns 17 +with bits = #3fffe666 66666666 66666666 66666666 +printf("%.35Lg") gives 1.8999999999999999999999999999999999 +g_Qfmt(0) gives 3 bytes: "1.9" + +strtoIQ returns 17, consuming 3 bytes. +fI[0] = #3fffe666 66666666 66666666 66666666 += 1.8999999999999999999999999999999999 +fI[1] = #3fffe666 66666666 66666666 66666667 += 1.9000000000000000000000000000000001 +fI[0] == strtod + + +Input: -1.9 + +strtoQ consumes 4 bytes and returns 41 +with bits = #bfffe666 66666666 66666666 66666667 +printf("%.35Lg") gives -1.9000000000000000000000000000000001 +g_Qfmt(0) gives 37 bytes: "-1.9000000000000000000000000000000001" + +strtoIQ returns 25, consuming 4 bytes. +fI[0] = #bfffe666 66666666 66666666 66666667 += -1.9000000000000000000000000000000001 +fI[1] = #bfffe666 66666666 66666666 66666666 += -1.8999999999999999999999999999999999 +fI[0] == strtod + diff --git a/lib/libc/gdtoa/test/Qtest.c b/lib/libc/gdtoa/test/Qtest.c new file mode 100644 index 000000000..057c2ed80 --- /dev/null +++ b/lib/libc/gdtoa/test/Qtest.c @@ -0,0 +1,178 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998-2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +/* Test program for g_Qfmt, strtoIQ, strtopQ, and strtorQ. + * + * Inputs (on stdin): + * r rounding_mode + * n ndig + * number + * #hex0 hex1 hex2 hex3 + * + * rounding_mode values: + * 0 = toward zero + * 1 = nearest + * 2 = toward +Infinity + * 3 = toward -Infinity + * + * where number is a decimal floating-point number, + * hex0 is a string of <= 8 Hex digits for the most significant + * word of the number, hex1 is a similar string for the next + * word, etc., and ndig is a parameters to g_Qfmt. + */ + +#include "gdtoa.h" +#include +#include +#include + + extern int getround ANSI((int,char*)); + + static char ibuf[2048], obuf[2048]; +#undef _0 +#undef _1 + +/* one or the other of IEEE_BIG_ENDIAN or IEEE_LITTLE_ENDIAN should be #defined */ + +#ifdef IEEE_BIG_ENDIAN +#define _0 0 +#define _1 1 +#define _2 2 +#define _3 3 +#endif +#ifdef IEEE_LITTLE_ENDIAN +#define _0 3 +#define _1 2 +#define _2 1 +#define _3 0 +#endif + +#define U (unsigned long) + + int +main(Void) +{ + char *s, *s1, *se, *se1; + int Ltest, i, dItry, ndig = 0, r = 1; + union { long double d; ULong bits[4]; } u, v[2], w; + + w.bits[0] = w.bits[3] = 0; + w.d = 1.; + u.d = 3.; + w.d = w.d / u.d; + Ltest = sizeof(long double) == 16 && w.bits[0] && w.bits[3]; + while( (s = fgets(ibuf, sizeof(ibuf), stdin)) !=0) { + while(*s <= ' ') + if (!*s++) + continue; + dItry = 0; + switch(*s) { + case 'r': + r = getround(r, s); + continue; + case 'n': + i = s[1]; + if (i <= ' ' || (i >= '0' && i <= '9')) { + ndig = atoi(s+1); + continue; + } + break; /* nan? */ + case '#': + /* sscanf(s+1, "%lx %lx %lx %lx", &u.bits[_0], */ + /* &u.bits[_1], &u.bits[_2], &u.bits[_3]); */ + u.bits[_0] = (ULong)strtoul(s1 = s+1, &se, 16); + if (se > s1) { + u.bits[_1] = (ULong)strtoul(s1 = se, &se, 16); + if (se > s1) { + u.bits[_2] = (ULong)strtoul(s1 = se, &se, 16); + if (se > s1) + u.bits[_3] = (ULong)strtoul(s1 = se, &se, 16); + } + } + printf("\nInput: %s", ibuf); + printf(" --> f = #%lx %lx %lx %lx\n", U u.bits[_0], + U u.bits[_1], U u.bits[_2], U u.bits[_3]); + goto fmt_test; + } + dItry = 1; + printf("\nInput: %s", ibuf); + i = strtorQ(ibuf, &se, r, u.bits); + if (r == 1 && (strtopQ(ibuf,&se1,v[0].bits) != i + || se != se1 || memcmp(u.bits, v[0].bits, 16))) + printf("***strtoQ and strtorQ disagree!!\n:"); + printf("\nstrtoQ consumes %d bytes and returns %d\n", + (int)(se-ibuf), i); + printf("with bits = #%lx %lx %lx %lx\n", + U u.bits[_0], U u.bits[_1], U u.bits[_2], U u.bits[_3]); + fmt_test: + if (Ltest) + printf("printf(\"%%.35Lg\") gives %.35Lg\n", u.d); + se = g_Qfmt(obuf, u.bits, ndig, sizeof(obuf)); + printf("g_Qfmt(%d) gives %d bytes: \"%s\"\n\n", ndig, + (int)(se-obuf), se ? obuf : ""); + if (!dItry) + continue; + printf("strtoIQ returns %d,", + strtoIQ(ibuf, &se, v[0].bits, v[1].bits)); + printf(" consuming %d bytes.\n", (int)(se-ibuf)); + if (!memcmp(v[0].bits, v[1].bits, 16)) { + if (!memcpy(u.bits, v[0].bits, 16)) + printf("fI[0] == fI[1] == strtoQ\n"); + else { + printf("fI[0] == fI[1] = #%lx %lx %lx %lx\n", + U v[0].bits[_0], U v[0].bits[_1], + U v[0].bits[_2], U v[0].bits[_3]); + if (Ltest) + printf("= %.35Lg\n", v[0].d); + } + } + else { + printf("fI[0] = #%lx %lx %lx %lx\n", + U v[0].bits[_0], U v[0].bits[_1], + U v[0].bits[_2], U v[0].bits[_3]); + if (Ltest) + printf("= %.35Lg\n", v[0].d); + printf("fI[1] = #%lx %lx %lx %lx\n", + U v[1].bits[_0], U v[1].bits[_1], + U v[1].bits[_2], U v[1].bits[_3]); + if (Ltest) + printf("= %.35Lg\n", v[1].d); + if (!memcmp(v[0].bits, u.bits, 16)) + printf("fI[0] == strtod\n"); + else if (!memcmp(v[1].bits, u.bits, 16)) + printf("fI[1] == strtod\n"); + else + printf("**** Both differ from strtod ****\n"); + } + printf("\n"); + } + return 0; + } diff --git a/lib/libc/gdtoa/test/README b/lib/libc/gdtoa/test/README new file mode 100644 index 000000000..042ecfea0 --- /dev/null +++ b/lib/libc/gdtoa/test/README @@ -0,0 +1,81 @@ +This directory contains source for several test programs: + +dt is for conversion to/from double; it permits input of pairs of +32-bit hex integers as #hhhhhhhh hhhhhhhh (i.e., the initial '#' +indicates hex input). No initial # ==> decimal input. +After the input number is an optional : mode ndigits +(colon, and decimal integers for parameters "mode" and "ndigits" +to gdtoa). + +Qtest, ddtest, dtest, ftest, xLtest and xtest are for conversion to/from + + f IEEE single precision + d IEEE double precision + xL IEEE extended precision, as on Motorola 680x0 chips + x IEEE extended precision, as on Intel 80x87 chips or + software emulation of Motorola 680x0 chips + Q quad precision, as on Sun Sparc chips + dd double double, pairs of IEEE double numbers + whose sum is the desired value + +They're all similar, except for the precision. They test both +directed roundings and interval input (the strtoI* routines). +Lines that begin with "r" specify or interrogate the desired rounding +direction: + + 0 = toward 0 + 1 = nearest (default) + 2 = toward +Infinity + 3 = toward -Infinity + +These are the FPI_Round_* values in gdota.h. The "r" value is sticky: +it stays in effect til changed. To change the value, give a line that +starts with r followed by 0, 1, 2, or 3. To check the value, give "r" +by itself. + +Lines that begin with n followed by a number specify the ndig +argument for subsequent calls to the relevant g_*fmt routine. + +Lines that start with # followed by the appropriate number of +hexadecimal strings (see the comments) give the big-endian +internal representation of the desired number. + +When routines Qtest, xLtest, and xtest are used on machines whose +long double is of type "quad" (for Qtest) or "extended" (for x*test), +they try to print with %Lg as another way to show binary values. + +Program ddtest also accepts (white-space separated) pairs of decimal +input numbers; it converts both with strtod and feeds the result +to g_ddfmt. + +Program dItest exercises strtodI and strtoId. + +Programs dItestsi and ddtestsi are for testing the sudden-underflow +logic (on double and double-double conversions). + +Program strtodt tests strtod on some hard cases (in file testnos3) +posted by Fred Tydeman to comp.arch.arithmetic on 26 Feb. 1996. +To get correct results on Intel (x86) systems, the rounding precision +must be set to 53 bits. This can be done, e.g., by invoking +fpinit_ASL(), whose source appears in +http://www.netlib.org/ampl/solvers/fpinit.c . + +The obad directory shows results expected on (at least some) Intel x86 +Linux systems and may not be relevant to other systems. + +You can optionally compile getround.c with -DHonor_FLT_ROUNDS +to manually test strtof, strtod, etc., using fegetround(). +You can also or alternatively compile getround.c with +-DUSE_MY_LOCALE (when ../gdtoa.a is compiled with -DUSE_LOCALE) +to test multi-byte decimal points. + +If in the parent directory, you have sucessfully invoked "make Printf" +to add a "printf" (called Printf and accessed via ../stdio1.h), then +here you can use "make pf_test" and (if you have both a 64-bit long +double and a 113-bit "quad" double type) "make pf_testLq" for a brief +test of %g and %a variants in Printf. + +These are simple test programs, not meant for exhaustive testing, +but for manually testing "interesting" cases. Paxson's testbase +is good for more exhaustive testing, in part with random inputs. +See ftp://ftp.ee.lbl.gov/testbase-report.ps.Z . diff --git a/lib/libc/gdtoa/test/d.out b/lib/libc/gdtoa/test/d.out new file mode 100644 index 000000000..a0ac991c4 --- /dev/null +++ b/lib/libc/gdtoa/test/d.out @@ -0,0 +1,986 @@ + +Input: 1.23 +strtod consumes 4 bytes and returns 17 with f = 1.23 = #3ff3ae14 7ae147ae +g_dfmt(0) gives 4 bytes: "1.23" + +strtoId returns 17, consuming 4 bytes. +fI[0] = #3ff3ae14 7ae147ae = 1.23 +fI[1] = #3ff3ae14 7ae147af = 1.2300000000000002 +fI[0] == strtod + + +Input: 1.23e+20 +strtod consumes 8 bytes and returns 1 with f = 1.23e+20 = #441aabdf 2145b430 +g_dfmt(0) gives 8 bytes: "1.23e+20" + +strtoId returns 1, consuming 8 bytes. +fI[0] == fI[1] == strtod + + +Input: 1.23e-20 +strtod consumes 8 bytes and returns 33 with f = 1.2300000000000001e-20 = #3bcd0ae4 cf767531 +g_dfmt(0) gives 8 bytes: "1.23e-20" + +strtoId returns 33, consuming 8 bytes. +fI[0] = #3bcd0ae4 cf767530 = 1.2299999999999999e-20 +fI[1] = #3bcd0ae4 cf767531 = 1.2300000000000001e-20 +fI[1] == strtod + + +Input: 1.23456789 +strtod consumes 10 bytes and returns 17 with f = 1.2345678899999999 = #3ff3c0ca 4283de1b +g_dfmt(0) gives 10 bytes: "1.23456789" + +strtoId returns 17, consuming 10 bytes. +fI[0] = #3ff3c0ca 4283de1b = 1.2345678899999999 +fI[1] = #3ff3c0ca 4283de1c = 1.2345678900000001 +fI[0] == strtod + + +Input: 1.23456589e+20 +strtod consumes 14 bytes and returns 17 with f = 1.23456589e+20 = #441ac537 a660b997 +g_dfmt(0) gives 14 bytes: "1.23456589e+20" + +strtoId returns 17, consuming 14 bytes. +fI[0] = #441ac537 a660b997 = 1.23456589e+20 +fI[1] = #441ac537 a660b998 = 1.2345658900000001e+20 +fI[0] == strtod + + +Input: 1.23e+30 +strtod consumes 8 bytes and returns 17 with f = 1.23e+30 = #462f0cb0 4e8fb790 +g_dfmt(0) gives 8 bytes: "1.23e+30" + +strtoId returns 17, consuming 8 bytes. +fI[0] = #462f0cb0 4e8fb790 = 1.23e+30 +fI[1] = #462f0cb0 4e8fb791 = 1.2300000000000001e+30 +fI[0] == strtod + + +Input: 1.23e-30 +strtod consumes 8 bytes and returns 33 with f = 1.2300000000000001e-30 = #39b8f286 6f5010ab +g_dfmt(0) gives 8 bytes: "1.23e-30" + +strtoId returns 33, consuming 8 bytes. +fI[0] = #39b8f286 6f5010aa = 1.2299999999999999e-30 +fI[1] = #39b8f286 6f5010ab = 1.2300000000000001e-30 +fI[1] == strtod + + +Input: 1.23456789e-20 +strtod consumes 14 bytes and returns 17 with f = 1.2345678899999999e-20 = #3bcd2681 471e7ada +g_dfmt(0) gives 14 bytes: "1.23456789e-20" + +strtoId returns 17, consuming 14 bytes. +fI[0] = #3bcd2681 471e7ada = 1.2345678899999999e-20 +fI[1] = #3bcd2681 471e7adb = 1.2345678900000001e-20 +fI[0] == strtod + + +Input: 1.23456789e-30 +strtod consumes 14 bytes and returns 17 with f = 1.23456789e-30 = #39b90a3e 33bbd995 +g_dfmt(0) gives 14 bytes: "1.23456789e-30" + +strtoId returns 17, consuming 14 bytes. +fI[0] = #39b90a3e 33bbd995 = 1.23456789e-30 +fI[1] = #39b90a3e 33bbd996 = 1.2345678900000002e-30 +fI[0] == strtod + + +Input: 1.234567890123456789 +strtod consumes 20 bytes and returns 17 with f = 1.2345678901234567 = #3ff3c0ca 428c59fb +g_dfmt(0) gives 18 bytes: "1.2345678901234567" + +strtoId returns 17, consuming 20 bytes. +fI[0] = #3ff3c0ca 428c59fb = 1.2345678901234567 +fI[1] = #3ff3c0ca 428c59fc = 1.2345678901234569 +fI[0] == strtod + + +Input: 1.23456789012345678901234567890123456789 +strtod consumes 40 bytes and returns 17 with f = 1.2345678901234567 = #3ff3c0ca 428c59fb +g_dfmt(0) gives 18 bytes: "1.2345678901234567" + +strtoId returns 17, consuming 40 bytes. +fI[0] = #3ff3c0ca 428c59fb = 1.2345678901234567 +fI[1] = #3ff3c0ca 428c59fc = 1.2345678901234569 +fI[0] == strtod + + +Input: 1.23e306 +strtod consumes 8 bytes and returns 33 with f = 1.23e+306 = #7f7c0676 cd1c61f5 +g_dfmt(0) gives 9 bytes: "1.23e+306" + +strtoId returns 33, consuming 8 bytes. +fI[0] = #7f7c0676 cd1c61f4 = 1.2299999999999999e+306 +fI[1] = #7f7c0676 cd1c61f5 = 1.23e+306 +fI[1] == strtod + + +Input: 1.23e-306 +strtod consumes 9 bytes and returns 33 with f = 1.23e-306 = #6ba3b8 5da396e8 +g_dfmt(0) gives 9 bytes: "1.23e-306" + +strtoId returns 33, consuming 9 bytes. +fI[0] = #6ba3b8 5da396e7 = 1.2299999999999999e-306 +fI[1] = #6ba3b8 5da396e8 = 1.23e-306 +fI[1] == strtod + + +Input: 1.23e-320 +strtod consumes 9 bytes and returns 98 with f = 1.2302234581447039e-320 = #0 9ba +g_dfmt(0) gives 9 bytes: "1.23e-320" + +strtoId returns 98, consuming 9 bytes. +fI[0] = #0 9b9 = 1.2297293924988626e-320 +fI[1] = #0 9ba = 1.2302234581447039e-320 +fI[1] == strtod + + +Input: 1.23e-20 +strtod consumes 8 bytes and returns 33 with f = 1.2300000000000001e-20 = #3bcd0ae4 cf767531 +g_dfmt(0) gives 8 bytes: "1.23e-20" + +strtoId returns 33, consuming 8 bytes. +fI[0] = #3bcd0ae4 cf767530 = 1.2299999999999999e-20 +fI[1] = #3bcd0ae4 cf767531 = 1.2300000000000001e-20 +fI[1] == strtod + + +Input: 1.23456789e307 +strtod consumes 14 bytes and returns 33 with f = 1.23456789e+307 = #7fb194b1 4bdaecdc +g_dfmt(0) gives 15 bytes: "1.23456789e+307" + +strtoId returns 33, consuming 14 bytes. +fI[0] = #7fb194b1 4bdaecdb = 1.2345678899999998e+307 +fI[1] = #7fb194b1 4bdaecdc = 1.23456789e+307 +fI[1] == strtod + + +Input: 1.23456589e-307 +strtod consumes 15 bytes and returns 17 with f = 1.2345658899999999e-307 = #363196 bb9845fa +g_dfmt(0) gives 15 bytes: "1.23456589e-307" + +strtoId returns 17, consuming 15 bytes. +fI[0] = #363196 bb9845fa = 1.2345658899999999e-307 +fI[1] = #363196 bb9845fb = 1.2345658900000001e-307 +fI[0] == strtod + + +Input: 1.234567890123456789 +strtod consumes 20 bytes and returns 17 with f = 1.2345678901234567 = #3ff3c0ca 428c59fb +g_dfmt(0) gives 18 bytes: "1.2345678901234567" + +strtoId returns 17, consuming 20 bytes. +fI[0] = #3ff3c0ca 428c59fb = 1.2345678901234567 +fI[1] = #3ff3c0ca 428c59fc = 1.2345678901234569 +fI[0] == strtod + + +Input: 1.234567890123456789e301 +strtod consumes 24 bytes and returns 17 with f = 1.2345678901234568e+301 = #7e726f51 75f56413 +g_dfmt(0) gives 23 bytes: "1.2345678901234568e+301" + +strtoId returns 17, consuming 24 bytes. +fI[0] = #7e726f51 75f56413 = 1.2345678901234568e+301 +fI[1] = #7e726f51 75f56414 = 1.234567890123457e+301 +fI[0] == strtod + + +Input: 1.234567890123456789e-301 +strtod consumes 25 bytes and returns 17 with f = 1.2345678901234567e-301 = #1752a64 e34ba0d3 +g_dfmt(0) gives 23 bytes: "1.2345678901234567e-301" + +strtoId returns 17, consuming 25 bytes. +fI[0] = #1752a64 e34ba0d3 = 1.2345678901234567e-301 +fI[1] = #1752a64 e34ba0d4 = 1.2345678901234569e-301 +fI[0] == strtod + + +Input: 1.234567890123456789e-321 +strtod consumes 25 bytes and returns 98 with f = 1.2351641146031164e-321 = #0 fa +g_dfmt(0) gives 10 bytes: "1.235e-321" + +strtoId returns 98, consuming 25 bytes. +fI[0] = #0 f9 = 1.2302234581447039e-321 +fI[1] = #0 fa = 1.2351641146031164e-321 +fI[1] == strtod + + +Input: 1e23 +strtod consumes 4 bytes and returns 17 with f = 9.9999999999999992e+22 = #44b52d02 c7e14af6 +g_dfmt(0) gives 5 bytes: "1e+23" + +strtoId returns 17, consuming 4 bytes. +fI[0] = #44b52d02 c7e14af6 = 9.9999999999999992e+22 +fI[1] = #44b52d02 c7e14af7 = 1.0000000000000001e+23 +fI[0] == strtod + + +Input: 1e310 +strtod consumes 5 bytes and returns 163 with f = Infinity = #7ff00000 0 +g_dfmt(0) gives 8 bytes: "Infinity" + +strtoId returns 163, consuming 5 bytes. +fI[0] = #7fefffff ffffffff = 1.7976931348623157e+308 +fI[1] = #7ff00000 0 = Infinity +fI[1] == strtod + + +Input: 9.0259718793241475e-277 +strtod consumes 23 bytes and returns 33 with f = 9.0259718793241479e-277 = #6a00000 0 +g_dfmt(0) gives 22 bytes: "9.025971879324148e-277" + +strtoId returns 33, consuming 23 bytes. +fI[0] = #69fffff ffffffff = 9.0259718793241469e-277 +fI[1] = #6a00000 0 = 9.0259718793241479e-277 +fI[1] == strtod + + +Input: 9.025971879324147880346310405869e-277 +strtod consumes 37 bytes and returns 17 with f = 9.0259718793241479e-277 = #6a00000 0 +g_dfmt(0) gives 22 bytes: "9.025971879324148e-277" + +strtoId returns 17, consuming 37 bytes. +fI[0] = #6a00000 0 = 9.0259718793241479e-277 +fI[1] = #6a00000 1 = 9.0259718793241499e-277 +fI[0] == strtod + + +Input: 9.025971879324147880346310405868e-277 +strtod consumes 37 bytes and returns 33 with f = 9.0259718793241479e-277 = #6a00000 0 +g_dfmt(0) gives 22 bytes: "9.025971879324148e-277" + +strtoId returns 33, consuming 37 bytes. +fI[0] = #69fffff ffffffff = 9.0259718793241469e-277 +fI[1] = #6a00000 0 = 9.0259718793241479e-277 +fI[1] == strtod + + +Input: 2.2250738585072014e-308 +strtod consumes 23 bytes and returns 17 with f = 2.2250738585072014e-308 = #100000 0 +g_dfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoId returns 17, consuming 23 bytes. +fI[0] = #100000 0 = 2.2250738585072014e-308 +fI[1] = #100000 1 = 2.2250738585072019e-308 +fI[0] == strtod + + +Input: 2.2250738585072013e-308 +strtod consumes 23 bytes and returns 33 with f = 2.2250738585072014e-308 = #100000 0 +g_dfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoId returns 33, consuming 23 bytes. +fI[0] = #fffff ffffffff = 2.2250738585072009e-308 +fI[1] = #100000 0 = 2.2250738585072014e-308 +fI[1] == strtod + +Rounding mode for strtor... changed from 1 (nearest) to 0 (toward zero) + +Input: 1.1 +strtod consumes 3 bytes and returns 17 with f = 1.0999999999999999 = #3ff19999 99999999 +g_dfmt(0) gives 18 bytes: "1.0999999999999999" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff19999 99999999 = 1.0999999999999999 +fI[1] = #3ff19999 9999999a = 1.1000000000000001 +fI[0] == strtod + + +Input: -1.1 +strtod consumes 4 bytes and returns 25 with f = -1.0999999999999999 = #bff19999 99999999 +g_dfmt(0) gives 19 bytes: "-1.0999999999999999" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff19999 9999999a = -1.1000000000000001 +fI[1] = #bff19999 99999999 = -1.0999999999999999 +fI[1] == strtod + + +Input: 1.2 +strtod consumes 3 bytes and returns 17 with f = 1.2 = #3ff33333 33333333 +g_dfmt(0) gives 3 bytes: "1.2" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ff33333 33333333 = 1.2 +fI[1] = #3ff33333 33333334 = 1.2000000000000002 +fI[0] == strtod + + +Input: -1.2 +strtod consumes 4 bytes and returns 25 with f = -1.2 = #bff33333 33333333 +g_dfmt(0) gives 4 bytes: "-1.2" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bff33333 33333334 = -1.2000000000000002 +fI[1] = #bff33333 33333333 = -1.2 +fI[1] == strtod + + +Input: 1.3 +strtod consumes 3 bytes and returns 17 with f = 1.2999999999999998 = #3ff4cccc cccccccc +g_dfmt(0) gives 18 bytes: "1.2999999999999998" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff4cccc cccccccc = 1.2999999999999998 +fI[1] = #3ff4cccc cccccccd = 1.3 +fI[0] == strtod + + +Input: -1.3 +strtod consumes 4 bytes and returns 25 with f = -1.2999999999999998 = #bff4cccc cccccccc +g_dfmt(0) gives 19 bytes: "-1.2999999999999998" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff4cccc cccccccd = -1.3 +fI[1] = #bff4cccc cccccccc = -1.2999999999999998 +fI[1] == strtod + + +Input: 1.4 +strtod consumes 3 bytes and returns 17 with f = 1.3999999999999999 = #3ff66666 66666666 +g_dfmt(0) gives 3 bytes: "1.4" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ff66666 66666666 = 1.3999999999999999 +fI[1] = #3ff66666 66666667 = 1.4000000000000001 +fI[0] == strtod + + +Input: -1.4 +strtod consumes 4 bytes and returns 25 with f = -1.3999999999999999 = #bff66666 66666666 +g_dfmt(0) gives 4 bytes: "-1.4" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bff66666 66666667 = -1.4000000000000001 +fI[1] = #bff66666 66666666 = -1.3999999999999999 +fI[1] == strtod + + +Input: 1.5 +strtod consumes 3 bytes and returns 1 with f = 1.5 = #3ff80000 0 +g_dfmt(0) gives 3 bytes: "1.5" + +strtoId returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtod + + +Input: -1.5 +strtod consumes 4 bytes and returns 9 with f = -1.5 = #bff80000 0 +g_dfmt(0) gives 4 bytes: "-1.5" + +strtoId returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtod + + +Input: 1.6 +strtod consumes 3 bytes and returns 17 with f = 1.5999999999999999 = #3ff99999 99999999 +g_dfmt(0) gives 18 bytes: "1.5999999999999999" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff99999 99999999 = 1.5999999999999999 +fI[1] = #3ff99999 9999999a = 1.6000000000000001 +fI[0] == strtod + + +Input: -1.6 +strtod consumes 4 bytes and returns 25 with f = -1.5999999999999999 = #bff99999 99999999 +g_dfmt(0) gives 19 bytes: "-1.5999999999999999" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff99999 9999999a = -1.6000000000000001 +fI[1] = #bff99999 99999999 = -1.5999999999999999 +fI[1] == strtod + + +Input: 1.7 +strtod consumes 3 bytes and returns 17 with f = 1.7 = #3ffb3333 33333333 +g_dfmt(0) gives 3 bytes: "1.7" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ffb3333 33333333 = 1.7 +fI[1] = #3ffb3333 33333334 = 1.7000000000000002 +fI[0] == strtod + + +Input: -1.7 +strtod consumes 4 bytes and returns 25 with f = -1.7 = #bffb3333 33333333 +g_dfmt(0) gives 4 bytes: "-1.7" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bffb3333 33333334 = -1.7000000000000002 +fI[1] = #bffb3333 33333333 = -1.7 +fI[1] == strtod + + +Input: 1.8 +strtod consumes 3 bytes and returns 17 with f = 1.7999999999999998 = #3ffccccc cccccccc +g_dfmt(0) gives 18 bytes: "1.7999999999999998" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ffccccc cccccccc = 1.7999999999999998 +fI[1] = #3ffccccc cccccccd = 1.8 +fI[0] == strtod + + +Input: -1.8 +strtod consumes 4 bytes and returns 25 with f = -1.7999999999999998 = #bffccccc cccccccc +g_dfmt(0) gives 19 bytes: "-1.7999999999999998" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bffccccc cccccccd = -1.8 +fI[1] = #bffccccc cccccccc = -1.7999999999999998 +fI[1] == strtod + + +Input: 1.9 +strtod consumes 3 bytes and returns 17 with f = 1.8999999999999999 = #3ffe6666 66666666 +g_dfmt(0) gives 3 bytes: "1.9" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ffe6666 66666666 = 1.8999999999999999 +fI[1] = #3ffe6666 66666667 = 1.9000000000000001 +fI[0] == strtod + + +Input: -1.9 +strtod consumes 4 bytes and returns 25 with f = -1.8999999999999999 = #bffe6666 66666666 +g_dfmt(0) gives 4 bytes: "-1.9" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bffe6666 66666667 = -1.9000000000000001 +fI[1] = #bffe6666 66666666 = -1.8999999999999999 +fI[1] == strtod + +Rounding mode for strtor... changed from 0 (toward zero) to 1 (nearest) + +Input: 1.1 +strtod consumes 3 bytes and returns 33 with f = 1.1000000000000001 = #3ff19999 9999999a +g_dfmt(0) gives 3 bytes: "1.1" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff19999 99999999 = 1.0999999999999999 +fI[1] = #3ff19999 9999999a = 1.1000000000000001 +fI[1] == strtod + + +Input: -1.1 +strtod consumes 4 bytes and returns 41 with f = -1.1000000000000001 = #bff19999 9999999a +g_dfmt(0) gives 4 bytes: "-1.1" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff19999 9999999a = -1.1000000000000001 +fI[1] = #bff19999 99999999 = -1.0999999999999999 +fI[0] == strtod + + +Input: 1.2 +strtod consumes 3 bytes and returns 17 with f = 1.2 = #3ff33333 33333333 +g_dfmt(0) gives 3 bytes: "1.2" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ff33333 33333333 = 1.2 +fI[1] = #3ff33333 33333334 = 1.2000000000000002 +fI[0] == strtod + + +Input: -1.2 +strtod consumes 4 bytes and returns 25 with f = -1.2 = #bff33333 33333333 +g_dfmt(0) gives 4 bytes: "-1.2" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bff33333 33333334 = -1.2000000000000002 +fI[1] = #bff33333 33333333 = -1.2 +fI[1] == strtod + + +Input: 1.3 +strtod consumes 3 bytes and returns 33 with f = 1.3 = #3ff4cccc cccccccd +g_dfmt(0) gives 3 bytes: "1.3" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff4cccc cccccccc = 1.2999999999999998 +fI[1] = #3ff4cccc cccccccd = 1.3 +fI[1] == strtod + + +Input: -1.3 +strtod consumes 4 bytes and returns 41 with f = -1.3 = #bff4cccc cccccccd +g_dfmt(0) gives 4 bytes: "-1.3" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff4cccc cccccccd = -1.3 +fI[1] = #bff4cccc cccccccc = -1.2999999999999998 +fI[0] == strtod + + +Input: 1.4 +strtod consumes 3 bytes and returns 17 with f = 1.3999999999999999 = #3ff66666 66666666 +g_dfmt(0) gives 3 bytes: "1.4" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ff66666 66666666 = 1.3999999999999999 +fI[1] = #3ff66666 66666667 = 1.4000000000000001 +fI[0] == strtod + + +Input: -1.4 +strtod consumes 4 bytes and returns 25 with f = -1.3999999999999999 = #bff66666 66666666 +g_dfmt(0) gives 4 bytes: "-1.4" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bff66666 66666667 = -1.4000000000000001 +fI[1] = #bff66666 66666666 = -1.3999999999999999 +fI[1] == strtod + + +Input: 1.5 +strtod consumes 3 bytes and returns 1 with f = 1.5 = #3ff80000 0 +g_dfmt(0) gives 3 bytes: "1.5" + +strtoId returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtod + + +Input: -1.5 +strtod consumes 4 bytes and returns 9 with f = -1.5 = #bff80000 0 +g_dfmt(0) gives 4 bytes: "-1.5" + +strtoId returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtod + + +Input: 1.6 +strtod consumes 3 bytes and returns 33 with f = 1.6000000000000001 = #3ff99999 9999999a +g_dfmt(0) gives 3 bytes: "1.6" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff99999 99999999 = 1.5999999999999999 +fI[1] = #3ff99999 9999999a = 1.6000000000000001 +fI[1] == strtod + + +Input: -1.6 +strtod consumes 4 bytes and returns 41 with f = -1.6000000000000001 = #bff99999 9999999a +g_dfmt(0) gives 4 bytes: "-1.6" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff99999 9999999a = -1.6000000000000001 +fI[1] = #bff99999 99999999 = -1.5999999999999999 +fI[0] == strtod + + +Input: 1.7 +strtod consumes 3 bytes and returns 17 with f = 1.7 = #3ffb3333 33333333 +g_dfmt(0) gives 3 bytes: "1.7" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ffb3333 33333333 = 1.7 +fI[1] = #3ffb3333 33333334 = 1.7000000000000002 +fI[0] == strtod + + +Input: -1.7 +strtod consumes 4 bytes and returns 25 with f = -1.7 = #bffb3333 33333333 +g_dfmt(0) gives 4 bytes: "-1.7" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bffb3333 33333334 = -1.7000000000000002 +fI[1] = #bffb3333 33333333 = -1.7 +fI[1] == strtod + + +Input: 1.8 +strtod consumes 3 bytes and returns 33 with f = 1.8 = #3ffccccc cccccccd +g_dfmt(0) gives 3 bytes: "1.8" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ffccccc cccccccc = 1.7999999999999998 +fI[1] = #3ffccccc cccccccd = 1.8 +fI[1] == strtod + + +Input: -1.8 +strtod consumes 4 bytes and returns 41 with f = -1.8 = #bffccccc cccccccd +g_dfmt(0) gives 4 bytes: "-1.8" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bffccccc cccccccd = -1.8 +fI[1] = #bffccccc cccccccc = -1.7999999999999998 +fI[0] == strtod + + +Input: 1.9 +strtod consumes 3 bytes and returns 17 with f = 1.8999999999999999 = #3ffe6666 66666666 +g_dfmt(0) gives 3 bytes: "1.9" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ffe6666 66666666 = 1.8999999999999999 +fI[1] = #3ffe6666 66666667 = 1.9000000000000001 +fI[0] == strtod + + +Input: -1.9 +strtod consumes 4 bytes and returns 25 with f = -1.8999999999999999 = #bffe6666 66666666 +g_dfmt(0) gives 4 bytes: "-1.9" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bffe6666 66666667 = -1.9000000000000001 +fI[1] = #bffe6666 66666666 = -1.8999999999999999 +fI[1] == strtod + +Rounding mode for strtor... changed from 1 (nearest) to 2 (toward +Infinity) + +Input: 1.1 +strtod consumes 3 bytes and returns 33 with f = 1.1000000000000001 = #3ff19999 9999999a +g_dfmt(0) gives 3 bytes: "1.1" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff19999 99999999 = 1.0999999999999999 +fI[1] = #3ff19999 9999999a = 1.1000000000000001 +fI[1] == strtod + + +Input: -1.1 +strtod consumes 4 bytes and returns 25 with f = -1.0999999999999999 = #bff19999 99999999 +g_dfmt(0) gives 19 bytes: "-1.0999999999999999" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff19999 9999999a = -1.1000000000000001 +fI[1] = #bff19999 99999999 = -1.0999999999999999 +fI[1] == strtod + + +Input: 1.2 +strtod consumes 3 bytes and returns 33 with f = 1.2000000000000002 = #3ff33333 33333334 +g_dfmt(0) gives 18 bytes: "1.2000000000000002" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ff33333 33333333 = 1.2 +fI[1] = #3ff33333 33333334 = 1.2000000000000002 +fI[1] == strtod + + +Input: -1.2 +strtod consumes 4 bytes and returns 25 with f = -1.2 = #bff33333 33333333 +g_dfmt(0) gives 4 bytes: "-1.2" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bff33333 33333334 = -1.2000000000000002 +fI[1] = #bff33333 33333333 = -1.2 +fI[1] == strtod + + +Input: 1.3 +strtod consumes 3 bytes and returns 33 with f = 1.3 = #3ff4cccc cccccccd +g_dfmt(0) gives 3 bytes: "1.3" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff4cccc cccccccc = 1.2999999999999998 +fI[1] = #3ff4cccc cccccccd = 1.3 +fI[1] == strtod + + +Input: -1.3 +strtod consumes 4 bytes and returns 25 with f = -1.2999999999999998 = #bff4cccc cccccccc +g_dfmt(0) gives 19 bytes: "-1.2999999999999998" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff4cccc cccccccd = -1.3 +fI[1] = #bff4cccc cccccccc = -1.2999999999999998 +fI[1] == strtod + + +Input: 1.4 +strtod consumes 3 bytes and returns 33 with f = 1.4000000000000001 = #3ff66666 66666667 +g_dfmt(0) gives 18 bytes: "1.4000000000000001" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ff66666 66666666 = 1.3999999999999999 +fI[1] = #3ff66666 66666667 = 1.4000000000000001 +fI[1] == strtod + + +Input: -1.4 +strtod consumes 4 bytes and returns 25 with f = -1.3999999999999999 = #bff66666 66666666 +g_dfmt(0) gives 4 bytes: "-1.4" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bff66666 66666667 = -1.4000000000000001 +fI[1] = #bff66666 66666666 = -1.3999999999999999 +fI[1] == strtod + + +Input: 1.5 +strtod consumes 3 bytes and returns 1 with f = 1.5 = #3ff80000 0 +g_dfmt(0) gives 3 bytes: "1.5" + +strtoId returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtod + + +Input: -1.5 +strtod consumes 4 bytes and returns 9 with f = -1.5 = #bff80000 0 +g_dfmt(0) gives 4 bytes: "-1.5" + +strtoId returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtod + + +Input: 1.6 +strtod consumes 3 bytes and returns 33 with f = 1.6000000000000001 = #3ff99999 9999999a +g_dfmt(0) gives 3 bytes: "1.6" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff99999 99999999 = 1.5999999999999999 +fI[1] = #3ff99999 9999999a = 1.6000000000000001 +fI[1] == strtod + + +Input: -1.6 +strtod consumes 4 bytes and returns 25 with f = -1.5999999999999999 = #bff99999 99999999 +g_dfmt(0) gives 19 bytes: "-1.5999999999999999" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff99999 9999999a = -1.6000000000000001 +fI[1] = #bff99999 99999999 = -1.5999999999999999 +fI[1] == strtod + + +Input: 1.7 +strtod consumes 3 bytes and returns 33 with f = 1.7000000000000002 = #3ffb3333 33333334 +g_dfmt(0) gives 18 bytes: "1.7000000000000002" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ffb3333 33333333 = 1.7 +fI[1] = #3ffb3333 33333334 = 1.7000000000000002 +fI[1] == strtod + + +Input: -1.7 +strtod consumes 4 bytes and returns 25 with f = -1.7 = #bffb3333 33333333 +g_dfmt(0) gives 4 bytes: "-1.7" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bffb3333 33333334 = -1.7000000000000002 +fI[1] = #bffb3333 33333333 = -1.7 +fI[1] == strtod + + +Input: 1.8 +strtod consumes 3 bytes and returns 33 with f = 1.8 = #3ffccccc cccccccd +g_dfmt(0) gives 3 bytes: "1.8" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ffccccc cccccccc = 1.7999999999999998 +fI[1] = #3ffccccc cccccccd = 1.8 +fI[1] == strtod + + +Input: -1.8 +strtod consumes 4 bytes and returns 25 with f = -1.7999999999999998 = #bffccccc cccccccc +g_dfmt(0) gives 19 bytes: "-1.7999999999999998" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bffccccc cccccccd = -1.8 +fI[1] = #bffccccc cccccccc = -1.7999999999999998 +fI[1] == strtod + + +Input: 1.9 +strtod consumes 3 bytes and returns 33 with f = 1.9000000000000001 = #3ffe6666 66666667 +g_dfmt(0) gives 18 bytes: "1.9000000000000001" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ffe6666 66666666 = 1.8999999999999999 +fI[1] = #3ffe6666 66666667 = 1.9000000000000001 +fI[1] == strtod + + +Input: -1.9 +strtod consumes 4 bytes and returns 25 with f = -1.8999999999999999 = #bffe6666 66666666 +g_dfmt(0) gives 4 bytes: "-1.9" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bffe6666 66666667 = -1.9000000000000001 +fI[1] = #bffe6666 66666666 = -1.8999999999999999 +fI[1] == strtod + +Rounding mode for strtor... changed from 2 (toward +Infinity) to 3 (toward -Infinity) + +Input: 1.1 +strtod consumes 3 bytes and returns 17 with f = 1.0999999999999999 = #3ff19999 99999999 +g_dfmt(0) gives 18 bytes: "1.0999999999999999" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff19999 99999999 = 1.0999999999999999 +fI[1] = #3ff19999 9999999a = 1.1000000000000001 +fI[0] == strtod + + +Input: -1.1 +strtod consumes 4 bytes and returns 41 with f = -1.1000000000000001 = #bff19999 9999999a +g_dfmt(0) gives 4 bytes: "-1.1" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff19999 9999999a = -1.1000000000000001 +fI[1] = #bff19999 99999999 = -1.0999999999999999 +fI[0] == strtod + + +Input: 1.2 +strtod consumes 3 bytes and returns 17 with f = 1.2 = #3ff33333 33333333 +g_dfmt(0) gives 3 bytes: "1.2" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ff33333 33333333 = 1.2 +fI[1] = #3ff33333 33333334 = 1.2000000000000002 +fI[0] == strtod + + +Input: -1.2 +strtod consumes 4 bytes and returns 41 with f = -1.2000000000000002 = #bff33333 33333334 +g_dfmt(0) gives 19 bytes: "-1.2000000000000002" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bff33333 33333334 = -1.2000000000000002 +fI[1] = #bff33333 33333333 = -1.2 +fI[0] == strtod + + +Input: 1.3 +strtod consumes 3 bytes and returns 17 with f = 1.2999999999999998 = #3ff4cccc cccccccc +g_dfmt(0) gives 18 bytes: "1.2999999999999998" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff4cccc cccccccc = 1.2999999999999998 +fI[1] = #3ff4cccc cccccccd = 1.3 +fI[0] == strtod + + +Input: -1.3 +strtod consumes 4 bytes and returns 41 with f = -1.3 = #bff4cccc cccccccd +g_dfmt(0) gives 4 bytes: "-1.3" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff4cccc cccccccd = -1.3 +fI[1] = #bff4cccc cccccccc = -1.2999999999999998 +fI[0] == strtod + + +Input: 1.4 +strtod consumes 3 bytes and returns 17 with f = 1.3999999999999999 = #3ff66666 66666666 +g_dfmt(0) gives 3 bytes: "1.4" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ff66666 66666666 = 1.3999999999999999 +fI[1] = #3ff66666 66666667 = 1.4000000000000001 +fI[0] == strtod + + +Input: -1.4 +strtod consumes 4 bytes and returns 41 with f = -1.4000000000000001 = #bff66666 66666667 +g_dfmt(0) gives 19 bytes: "-1.4000000000000001" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bff66666 66666667 = -1.4000000000000001 +fI[1] = #bff66666 66666666 = -1.3999999999999999 +fI[0] == strtod + + +Input: 1.5 +strtod consumes 3 bytes and returns 1 with f = 1.5 = #3ff80000 0 +g_dfmt(0) gives 3 bytes: "1.5" + +strtoId returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtod + + +Input: -1.5 +strtod consumes 4 bytes and returns 9 with f = -1.5 = #bff80000 0 +g_dfmt(0) gives 4 bytes: "-1.5" + +strtoId returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtod + + +Input: 1.6 +strtod consumes 3 bytes and returns 17 with f = 1.5999999999999999 = #3ff99999 99999999 +g_dfmt(0) gives 18 bytes: "1.5999999999999999" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ff99999 99999999 = 1.5999999999999999 +fI[1] = #3ff99999 9999999a = 1.6000000000000001 +fI[0] == strtod + + +Input: -1.6 +strtod consumes 4 bytes and returns 41 with f = -1.6000000000000001 = #bff99999 9999999a +g_dfmt(0) gives 4 bytes: "-1.6" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bff99999 9999999a = -1.6000000000000001 +fI[1] = #bff99999 99999999 = -1.5999999999999999 +fI[0] == strtod + + +Input: 1.7 +strtod consumes 3 bytes and returns 17 with f = 1.7 = #3ffb3333 33333333 +g_dfmt(0) gives 3 bytes: "1.7" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ffb3333 33333333 = 1.7 +fI[1] = #3ffb3333 33333334 = 1.7000000000000002 +fI[0] == strtod + + +Input: -1.7 +strtod consumes 4 bytes and returns 41 with f = -1.7000000000000002 = #bffb3333 33333334 +g_dfmt(0) gives 19 bytes: "-1.7000000000000002" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bffb3333 33333334 = -1.7000000000000002 +fI[1] = #bffb3333 33333333 = -1.7 +fI[0] == strtod + + +Input: 1.8 +strtod consumes 3 bytes and returns 17 with f = 1.7999999999999998 = #3ffccccc cccccccc +g_dfmt(0) gives 18 bytes: "1.7999999999999998" + +strtoId returns 33, consuming 3 bytes. +fI[0] = #3ffccccc cccccccc = 1.7999999999999998 +fI[1] = #3ffccccc cccccccd = 1.8 +fI[0] == strtod + + +Input: -1.8 +strtod consumes 4 bytes and returns 41 with f = -1.8 = #bffccccc cccccccd +g_dfmt(0) gives 4 bytes: "-1.8" + +strtoId returns 41, consuming 4 bytes. +fI[0] = #bffccccc cccccccd = -1.8 +fI[1] = #bffccccc cccccccc = -1.7999999999999998 +fI[0] == strtod + + +Input: 1.9 +strtod consumes 3 bytes and returns 17 with f = 1.8999999999999999 = #3ffe6666 66666666 +g_dfmt(0) gives 3 bytes: "1.9" + +strtoId returns 17, consuming 3 bytes. +fI[0] = #3ffe6666 66666666 = 1.8999999999999999 +fI[1] = #3ffe6666 66666667 = 1.9000000000000001 +fI[0] == strtod + + +Input: -1.9 +strtod consumes 4 bytes and returns 41 with f = -1.9000000000000001 = #bffe6666 66666667 +g_dfmt(0) gives 19 bytes: "-1.9000000000000001" + +strtoId returns 25, consuming 4 bytes. +fI[0] = #bffe6666 66666667 = -1.9000000000000001 +fI[1] = #bffe6666 66666666 = -1.8999999999999999 +fI[0] == strtod + diff --git a/lib/libc/gdtoa/test/dI.out b/lib/libc/gdtoa/test/dI.out new file mode 100644 index 000000000..b4070de80 --- /dev/null +++ b/lib/libc/gdtoa/test/dI.out @@ -0,0 +1,168 @@ + +Input: 1.23 +strtodI consumes 4 bytes and returns 17 +dd[0] = #3ff3ae14 7ae147ae = 1.23 +dd[1] = #3ff3ae14 7ae147af = 1.2300000000000002 + + +Input: 1.23e+20 +strtodI consumes 8 bytes and returns 1 +dd[0] = #441aabdf 2145b430 = 1.23e+20 +dd[1] = #441aabdf 2145b430 = 1.23e+20 + + +Input: 1.23e-20 +strtodI consumes 8 bytes and returns 33 +dd[0] = #3bcd0ae4 cf767530 = 1.2299999999999999e-20 +dd[1] = #3bcd0ae4 cf767531 = 1.23e-20 + + +Input: 1.23456789 +strtodI consumes 10 bytes and returns 17 +dd[0] = #3ff3c0ca 4283de1b = 1.23456789 +dd[1] = #3ff3c0ca 4283de1c = 1.2345678900000001 + + +Input: 1.23456589e+20 +strtodI consumes 14 bytes and returns 17 +dd[0] = #441ac537 a660b997 = 1.23456589e+20 +dd[1] = #441ac537 a660b998 = 123456589000000010000 + + +Input: 1.23e+30 +strtodI consumes 8 bytes and returns 17 +dd[0] = #462f0cb0 4e8fb790 = 1.23e+30 +dd[1] = #462f0cb0 4e8fb791 = 1.2300000000000001e+30 + + +Input: 1.23e-30 +strtodI consumes 8 bytes and returns 33 +dd[0] = #39b8f286 6f5010aa = 1.2299999999999999e-30 +dd[1] = #39b8f286 6f5010ab = 1.23e-30 + + +Input: 1.23456789e-20 +strtodI consumes 14 bytes and returns 17 +dd[0] = #3bcd2681 471e7ada = 1.23456789e-20 +dd[1] = #3bcd2681 471e7adb = 1.2345678900000001e-20 + + +Input: 1.23456789e-30 +strtodI consumes 14 bytes and returns 17 +dd[0] = #39b90a3e 33bbd995 = 1.23456789e-30 +dd[1] = #39b90a3e 33bbd996 = 1.2345678900000002e-30 + + +Input: 1.234567890123456789 +strtodI consumes 20 bytes and returns 17 +dd[0] = #3ff3c0ca 428c59fb = 1.2345678901234567 +dd[1] = #3ff3c0ca 428c59fc = 1.234567890123457 + + +Input: 1.23456789012345678901234567890123456789 +strtodI consumes 40 bytes and returns 17 +dd[0] = #3ff3c0ca 428c59fb = 1.2345678901234567 +dd[1] = #3ff3c0ca 428c59fc = 1.234567890123457 + + +Input: 1.23e306 +strtodI consumes 8 bytes and returns 33 +dd[0] = #7f7c0676 cd1c61f4 = 1.2299999999999999e+306 +dd[1] = #7f7c0676 cd1c61f5 = 1.23e+306 + + +Input: 1.23e-306 +strtodI consumes 9 bytes and returns 33 +dd[0] = #6ba3b8 5da396e7 = 1.2299999999999999e-306 +dd[1] = #6ba3b8 5da396e8 = 1.23e-306 + + +Input: 1.23e-320 +strtodI consumes 9 bytes and returns 98 +dd[0] = #0 9b9 = 1.2297e-320 +dd[1] = #0 9ba = 1.23e-320 + + +Input: 1.23e-20 +strtodI consumes 8 bytes and returns 33 +dd[0] = #3bcd0ae4 cf767530 = 1.2299999999999999e-20 +dd[1] = #3bcd0ae4 cf767531 = 1.23e-20 + + +Input: 1.23456789e307 +strtodI consumes 14 bytes and returns 33 +dd[0] = #7fb194b1 4bdaecdb = 1.2345678899999998e+307 +dd[1] = #7fb194b1 4bdaecdc = 1.23456789e+307 + + +Input: 1.23456589e-307 +strtodI consumes 15 bytes and returns 17 +dd[0] = #363196 bb9845fa = 1.23456589e-307 +dd[1] = #363196 bb9845fb = 1.2345658900000001e-307 + + +Input: 1.234567890123456789 +strtodI consumes 20 bytes and returns 17 +dd[0] = #3ff3c0ca 428c59fb = 1.2345678901234567 +dd[1] = #3ff3c0ca 428c59fc = 1.234567890123457 + + +Input: 1.234567890123456789e301 +strtodI consumes 24 bytes and returns 17 +dd[0] = #7e726f51 75f56413 = 1.2345678901234568e+301 +dd[1] = #7e726f51 75f56414 = 1.234567890123457e+301 + + +Input: 1.234567890123456789e-301 +strtodI consumes 25 bytes and returns 17 +dd[0] = #1752a64 e34ba0d3 = 1.2345678901234567e-301 +dd[1] = #1752a64 e34ba0d4 = 1.234567890123457e-301 + + +Input: 1.234567890123456789e-321 +strtodI consumes 25 bytes and returns 98 +dd[0] = #0 f9 = 1.23e-321 +dd[1] = #0 fa = 1.235e-321 + + +Input: 1e23 +strtodI consumes 4 bytes and returns 17 +dd[0] = #44b52d02 c7e14af6 = 1e+23 +dd[1] = #44b52d02 c7e14af7 = 1.0000000000000001e+23 + + +Input: 1e310 +strtodI consumes 5 bytes and returns 163 +dd[0] = #7fefffff ffffffff = 1.7976931348623157e+308 +dd[1] = #7ff00000 0 = Infinity + + +Input: 9.0259718793241475e-277 +strtodI consumes 23 bytes and returns 33 +dd[0] = #69fffff ffffffff = 9.025971879324147e-277 +dd[1] = #6a00000 0 = 9.025971879324148e-277 + + +Input: 9.025971879324147880346310405869e-277 +strtodI consumes 37 bytes and returns 17 +dd[0] = #6a00000 0 = 9.025971879324148e-277 +dd[1] = #6a00000 1 = 9.02597187932415e-277 + + +Input: 9.025971879324147880346310405868e-277 +strtodI consumes 37 bytes and returns 33 +dd[0] = #69fffff ffffffff = 9.025971879324147e-277 +dd[1] = #6a00000 0 = 9.025971879324148e-277 + + +Input: 2.2250738585072014e-308 +strtodI consumes 23 bytes and returns 17 +dd[0] = #100000 0 = 2.2250738585072014e-308 +dd[1] = #100000 1 = 2.225073858507202e-308 + + +Input: 2.2250738585072013e-308 +strtodI consumes 23 bytes and returns 33 +dd[0] = #fffff ffffffff = 2.225073858507201e-308 +dd[1] = #100000 0 = 2.2250738585072014e-308 + diff --git a/lib/libc/gdtoa/test/dIsi.out b/lib/libc/gdtoa/test/dIsi.out new file mode 100644 index 000000000..3388a1a4b --- /dev/null +++ b/lib/libc/gdtoa/test/dIsi.out @@ -0,0 +1,168 @@ + +Input: 1.23 +strtodI consumes 4 bytes and returns 17 +dd[0] = #3ff3ae14 7ae147ae = 1.23 +dd[1] = #3ff3ae14 7ae147af = 1.2300000000000002 + + +Input: 1.23e+20 +strtodI consumes 8 bytes and returns 1 +dd[0] = #441aabdf 2145b430 = 1.23e+20 +dd[1] = #441aabdf 2145b430 = 1.23e+20 + + +Input: 1.23e-20 +strtodI consumes 8 bytes and returns 33 +dd[0] = #3bcd0ae4 cf767530 = 1.2299999999999999e-20 +dd[1] = #3bcd0ae4 cf767531 = 1.23e-20 + + +Input: 1.23456789 +strtodI consumes 10 bytes and returns 17 +dd[0] = #3ff3c0ca 4283de1b = 1.23456789 +dd[1] = #3ff3c0ca 4283de1c = 1.2345678900000001 + + +Input: 1.23456589e+20 +strtodI consumes 14 bytes and returns 17 +dd[0] = #441ac537 a660b997 = 1.23456589e+20 +dd[1] = #441ac537 a660b998 = 123456589000000010000 + + +Input: 1.23e+30 +strtodI consumes 8 bytes and returns 17 +dd[0] = #462f0cb0 4e8fb790 = 1.23e+30 +dd[1] = #462f0cb0 4e8fb791 = 1.2300000000000001e+30 + + +Input: 1.23e-30 +strtodI consumes 8 bytes and returns 33 +dd[0] = #39b8f286 6f5010aa = 1.2299999999999999e-30 +dd[1] = #39b8f286 6f5010ab = 1.23e-30 + + +Input: 1.23456789e-20 +strtodI consumes 14 bytes and returns 17 +dd[0] = #3bcd2681 471e7ada = 1.23456789e-20 +dd[1] = #3bcd2681 471e7adb = 1.2345678900000001e-20 + + +Input: 1.23456789e-30 +strtodI consumes 14 bytes and returns 17 +dd[0] = #39b90a3e 33bbd995 = 1.23456789e-30 +dd[1] = #39b90a3e 33bbd996 = 1.2345678900000002e-30 + + +Input: 1.234567890123456789 +strtodI consumes 20 bytes and returns 17 +dd[0] = #3ff3c0ca 428c59fb = 1.2345678901234567 +dd[1] = #3ff3c0ca 428c59fc = 1.234567890123457 + + +Input: 1.23456789012345678901234567890123456789 +strtodI consumes 40 bytes and returns 17 +dd[0] = #3ff3c0ca 428c59fb = 1.2345678901234567 +dd[1] = #3ff3c0ca 428c59fc = 1.234567890123457 + + +Input: 1.23e306 +strtodI consumes 8 bytes and returns 33 +dd[0] = #7f7c0676 cd1c61f4 = 1.2299999999999999e+306 +dd[1] = #7f7c0676 cd1c61f5 = 1.23e+306 + + +Input: 1.23e-306 +strtodI consumes 9 bytes and returns 33 +dd[0] = #6ba3b8 5da396e7 = 1.2299999999999999e-306 +dd[1] = #6ba3b8 5da396e8 = 1.23e-306 + + +Input: 1.23e-320 +strtodI consumes 9 bytes and returns 80 +dd[0] = #0 0 = 0 +dd[1] = #100000 0 = 2.2250738585072014e-308 + + +Input: 1.23e-20 +strtodI consumes 8 bytes and returns 33 +dd[0] = #3bcd0ae4 cf767530 = 1.2299999999999999e-20 +dd[1] = #3bcd0ae4 cf767531 = 1.23e-20 + + +Input: 1.23456789e307 +strtodI consumes 14 bytes and returns 33 +dd[0] = #7fb194b1 4bdaecdb = 1.2345678899999998e+307 +dd[1] = #7fb194b1 4bdaecdc = 1.23456789e+307 + + +Input: 1.23456589e-307 +strtodI consumes 15 bytes and returns 17 +dd[0] = #363196 bb9845fa = 1.23456589e-307 +dd[1] = #363196 bb9845fb = 1.2345658900000001e-307 + + +Input: 1.234567890123456789 +strtodI consumes 20 bytes and returns 17 +dd[0] = #3ff3c0ca 428c59fb = 1.2345678901234567 +dd[1] = #3ff3c0ca 428c59fc = 1.234567890123457 + + +Input: 1.234567890123456789e301 +strtodI consumes 24 bytes and returns 17 +dd[0] = #7e726f51 75f56413 = 1.2345678901234568e+301 +dd[1] = #7e726f51 75f56414 = 1.234567890123457e+301 + + +Input: 1.234567890123456789e-301 +strtodI consumes 25 bytes and returns 17 +dd[0] = #1752a64 e34ba0d3 = 1.2345678901234567e-301 +dd[1] = #1752a64 e34ba0d4 = 1.234567890123457e-301 + + +Input: 1.234567890123456789e-321 +strtodI consumes 25 bytes and returns 80 +dd[0] = #0 0 = 0 +dd[1] = #100000 0 = 2.2250738585072014e-308 + + +Input: 1e23 +strtodI consumes 4 bytes and returns 17 +dd[0] = #44b52d02 c7e14af6 = 1e+23 +dd[1] = #44b52d02 c7e14af7 = 1.0000000000000001e+23 + + +Input: 1e310 +strtodI consumes 5 bytes and returns 163 +dd[0] = #7fefffff ffffffff = 1.7976931348623157e+308 +dd[1] = #7ff00000 0 = Infinity + + +Input: 9.0259718793241475e-277 +strtodI consumes 23 bytes and returns 33 +dd[0] = #69fffff ffffffff = 9.025971879324147e-277 +dd[1] = #6a00000 0 = 9.025971879324148e-277 + + +Input: 9.025971879324147880346310405869e-277 +strtodI consumes 37 bytes and returns 17 +dd[0] = #6a00000 0 = 9.025971879324148e-277 +dd[1] = #6a00000 1 = 9.02597187932415e-277 + + +Input: 9.025971879324147880346310405868e-277 +strtodI consumes 37 bytes and returns 33 +dd[0] = #69fffff ffffffff = 9.025971879324147e-277 +dd[1] = #6a00000 0 = 9.025971879324148e-277 + + +Input: 2.2250738585072014e-308 +strtodI consumes 23 bytes and returns 17 +dd[0] = #100000 0 = 2.2250738585072014e-308 +dd[1] = #100000 1 = 2.225073858507202e-308 + + +Input: 2.2250738585072013e-308 +strtodI consumes 23 bytes and returns 33 +dd[0] = #0 0 = 0 +dd[1] = #100000 0 = 2.2250738585072014e-308 + diff --git a/lib/libc/gdtoa/test/dItest.c b/lib/libc/gdtoa/test/dItest.c new file mode 100644 index 000000000..1724c7153 --- /dev/null +++ b/lib/libc/gdtoa/test/dItest.c @@ -0,0 +1,82 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998, 2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +#include "gdtoaimp.h" +#include +#include + + static char ibuf[2048]; + +#define U (unsigned long) + + static void +#ifdef KR_headers +dshow(what, d) char *what; double d; +#else +dshow(char *what, double d) +#endif +{ + char buf[32]; + g_dfmt(buf, &d, 0, sizeof(buf)); + printf("%s = #%lx %lx = %s\n", what, + U ((ULong*)&d)[_0], U ((ULong*)&d)[_1], buf); + } + + int +main(Void) +{ + /* Input: one number per line */ + + char *s, *se, *se1; + int i, j; + double dd[2], dd1, dd2; + static char cfmt[] = "%s consumes %d bytes and returns %d\n"; + + while( (s = fgets(ibuf, sizeof(ibuf), stdin)) !=0) { + while(*s <= ' ') + if (!*s++) + continue; + printf("\nInput: %s", ibuf); + i = strtodI(ibuf, &se, dd); + printf(cfmt, "strtodI", (int)(se-ibuf), i); + dshow("dd[0]", dd[0]); + dshow("dd[1]", dd[1]); + printf("\n"); + j = strtoId(ibuf, &se1, &dd1, &dd2); + if (j != i || se != se1 + || dd[0] != dd1 || dd[1] != dd2) { + printf(cfmt, "**** strtoId", (int)(se-ibuf), j); + dshow("dd1", dd1); + dshow("dd2", dd2); + } + } + return 0; + } diff --git a/lib/libc/gdtoa/test/dd.out b/lib/libc/gdtoa/test/dd.out new file mode 100644 index 000000000..b1d274447 --- /dev/null +++ b/lib/libc/gdtoa/test/dd.out @@ -0,0 +1,1356 @@ + +Input: 1.23 +strtopdd consumes 4 bytes and returns 17 +dd[0] = 1.23 = #3ff3ae14 7ae147ae +dd[1] = 1.7763568394002496e-17 = #3c747ae1 47ae1478 +g_ddfmt(0) gives 4 bytes: "1.23" + +strtoIdd returns 17, consuming 4 bytes. +ddI[0] = #3ff3ae14 7ae147ae + 3c747ae1 47ae1478 += 1.23 + 1.7763568394002496e-17 +ddI[1] = #3ff3ae14 7ae147ae + 3c747ae1 47ae1480 += 1.23 + 1.776356839400252e-17 +ddI[0] == strtod + + +Input: 1.23e+20 +strtopdd consumes 8 bytes and returns 1 +dd[0] = 1.23e+20 = #441aabdf 2145b430 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 8 bytes: "1.23e+20" + +strtoIdd returns 1, consuming 8 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1.23e-20 +strtopdd consumes 8 bytes and returns 33 +dd[0] = 1.2299999999999999e-20 = #3bcd0ae4 cf767530 +dd[1] = 9.304023318521521e-37 = #3873c997 955b2691 +g_ddfmt(0) gives 8 bytes: "1.23e-20" + +strtoIdd returns 33, consuming 8 bytes. +ddI[0] = #3bcd0ae4 cf767530 + 3873c997 955b2690 += 1.2299999999999999e-20 + 9.3040233185215194e-37 +ddI[1] = #3bcd0ae4 cf767530 + 3873c997 955b2691 += 1.2299999999999999e-20 + 9.3040233185215211e-37 +ddI[1] == strtod + + +Input: 1.23456789 +strtopdd consumes 10 bytes and returns 17 +dd[0] = 1.23456789 = #3ff3c0ca 4283de1b +dd[1] = 1.0990618193318369e-16 = #3c9fada5 144c1252 +g_ddfmt(0) gives 10 bytes: "1.23456789" + +strtoIdd returns 17, consuming 10 bytes. +ddI[0] = #3ff3c0ca 4283de1b + 3c9fada5 144c1252 += 1.2345678899999999 + 1.0990618193318369e-16 +ddI[1] = #3ff3c0ca 4283de1b + 3c9fada5 144c1254 += 1.2345678899999999 + 1.0990618193318371e-16 +ddI[0] == strtod + + +Input: 1.23456589e+20 +strtopdd consumes 14 bytes and returns 1 +dd[0] = 1.23456589e+20 = #441ac537 a660b997 +dd[1] = 4096 = #40b00000 0 +g_ddfmt(0) gives 14 bytes: "1.23456589e+20" + +strtoIdd returns 1, consuming 14 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1.23e+30 +strtopdd consumes 8 bytes and returns 1 +dd[0] = 1.23e+30 = #462f0cb0 4e8fb790 +dd[1] = 40281156091904 = #42c25158 0 +g_ddfmt(0) gives 8 bytes: "1.23e+30" + +strtoIdd returns 1, consuming 8 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1.23e-30 +strtopdd consumes 8 bytes and returns 17 +dd[0] = 1.2299999999999999e-30 = #39b8f286 6f5010aa +dd[1] = 1.076909723013918e-46 = #3663ac7f 3dafd174 +g_ddfmt(0) gives 8 bytes: "1.23e-30" + +strtoIdd returns 17, consuming 8 bytes. +ddI[0] = #39b8f286 6f5010aa + 3663ac7f 3dafd174 += 1.2299999999999999e-30 + 1.076909723013918e-46 +ddI[1] = #39b8f286 6f5010aa + 3663ac7f 3dafd175 += 1.2299999999999999e-30 + 1.0769097230139181e-46 +ddI[0] == strtod + + +Input: 1.23456789e-20 +strtopdd consumes 14 bytes and returns 17 +dd[0] = 1.23456789e-20 = #3bcd2681 471e7ada +dd[1] = 6.247111971663133e-37 = #386a9280 a761b07e +g_ddfmt(0) gives 14 bytes: "1.23456789e-20" + +strtoIdd returns 17, consuming 14 bytes. +ddI[0] = #3bcd2681 471e7ada + 386a9280 a761b07e += 1.2345678899999999e-20 + 6.2471119716631328e-37 +ddI[1] = #3bcd2681 471e7ada + 386a9280 a761b080 += 1.2345678899999999e-20 + 6.2471119716631345e-37 +ddI[0] == strtod + + +Input: 1.23456789e-30 +strtopdd consumes 14 bytes and returns 33 +dd[0] = 1.23456789e-30 = #39b90a3e 33bbd995 +dd[1] = 2.1567930523648577e-47 = #363f8585 55a6b1a0 +g_ddfmt(0) gives 14 bytes: "1.23456789e-30" + +strtoIdd returns 33, consuming 14 bytes. +ddI[0] = #39b90a3e 33bbd995 + 363f8585 55a6b198 += 1.23456789e-30 + 2.1567930523648558e-47 +ddI[1] = #39b90a3e 33bbd995 + 363f8585 55a6b1a0 += 1.23456789e-30 + 2.1567930523648577e-47 +ddI[1] == strtod + + +Input: 1.234567890123456789 +strtopdd consumes 20 bytes and returns 33 +dd[0] = 1.2345678901234567 = #3ff3c0ca 428c59fb +dd[1] = 9.856786452588859e-17 = #3c9c6906 51a3745e +g_ddfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIdd returns 33, consuming 20 bytes. +ddI[0] = #3ff3c0ca 428c59fb + 3c9c6906 51a3745c += 1.2345678901234567 + 9.8567864525888563e-17 +ddI[1] = #3ff3c0ca 428c59fb + 3c9c6906 51a3745e += 1.2345678901234567 + 9.8567864525888588e-17 +ddI[1] == strtod + + +Input: 1.23456789012345678901234567890123456789 +strtopdd consumes 40 bytes and returns 33 +dd[0] = 1.2345678901234567 = #3ff3c0ca 428c59fb +dd[1] = 9.858021020478982e-17 = #3c9c69ef 85adadb6 +g_ddfmt(0) gives 34 bytes: "1.23456789012345678901234567890124" + +strtoIdd returns 33, consuming 40 bytes. +ddI[0] = #3ff3c0ca 428c59fb + 3c9c69ef 85adadb4 += 1.2345678901234567 + 9.8580210204789798e-17 +ddI[1] = #3ff3c0ca 428c59fb + 3c9c69ef 85adadb6 += 1.2345678901234567 + 9.8580210204789823e-17 +ddI[1] == strtod + + +Input: 1.23e306 +strtopdd consumes 8 bytes and returns 33 +dd[0] = 1.2299999999999999e+306 = #7f7c0676 cd1c61f4 +dd[1] = 1.3319001448659015e+290 = #7c2b558b e3d3f477 +g_ddfmt(0) gives 9 bytes: "1.23e+306" + +strtoIdd returns 33, consuming 8 bytes. +ddI[0] = #7f7c0676 cd1c61f4 + 7c2b558b e3d3f476 += 1.2299999999999999e+306 + 1.3319001448659013e+290 +ddI[1] = #7f7c0676 cd1c61f4 + 7c2b558b e3d3f477 += 1.2299999999999999e+306 + 1.3319001448659015e+290 +ddI[1] == strtod + + +Input: 1.23e-306 +strtopdd consumes 9 bytes and returns 98 +dd[0] = 1.2299999999999999e-306 = #6ba3b8 5da396e7 +dd[1] = 1.43e-322 = #0 1d +g_ddfmt(0) gives 9 bytes: "1.23e-306" + +strtoIdd returns 98, consuming 9 bytes. +ddI[0] = #6ba3b8 5da396e7 + 0 1c += 1.2299999999999999e-306 + 1.3833838083554903e-322 +ddI[1] = #6ba3b8 5da396e7 + 0 1d += 1.2299999999999999e-306 + 1.432790372939615e-322 +ddI[1] == strtod + + +Input: 1.23e-320 +strtopdd consumes 9 bytes and returns 98 +dd[0] = 1.23e-320 = #0 9ba +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 9 bytes: "1.23e-320" + +strtoIdd returns 98, consuming 9 bytes. +ddI[0] = #0 9b9 + 0 0 += 1.2297293924988626e-320 + 0 +ddI[1] = #0 9ba + 0 0 += 1.2302234581447039e-320 + 0 +ddI[1] == strtod + + +Input: 1.23e-20 +strtopdd consumes 8 bytes and returns 33 +dd[0] = 1.2299999999999999e-20 = #3bcd0ae4 cf767530 +dd[1] = 9.304023318521521e-37 = #3873c997 955b2691 +g_ddfmt(0) gives 8 bytes: "1.23e-20" + +strtoIdd returns 33, consuming 8 bytes. +ddI[0] = #3bcd0ae4 cf767530 + 3873c997 955b2690 += 1.2299999999999999e-20 + 9.3040233185215194e-37 +ddI[1] = #3bcd0ae4 cf767530 + 3873c997 955b2691 += 1.2299999999999999e-20 + 9.3040233185215211e-37 +ddI[1] == strtod + + +Input: 1.23456789e307 +strtopdd consumes 14 bytes and returns 33 +dd[0] = 1.2345678899999998e+307 = #7fb194b1 4bdaecdb +dd[1] = 2.0137933598720243e+291 = #7c69d48d 192048ca +g_ddfmt(0) gives 15 bytes: "1.23456789e+307" + +strtoIdd returns 33, consuming 14 bytes. +ddI[0] = #7fb194b1 4bdaecdb + 7c69d48d 192048c9 += 1.2345678899999998e+307 + 2.013793359872024e+291 +ddI[1] = #7fb194b1 4bdaecdb + 7c69d48d 192048ca += 1.2345678899999998e+307 + 2.0137933598720243e+291 +ddI[1] == strtod + + +Input: 1.23456589e-307 +strtopdd consumes 15 bytes and returns 98 +dd[0] = 1.23456589e-307 = #363196 bb9845fa +dd[1] = 1e-323 = #0 2 +g_ddfmt(0) gives 15 bytes: "1.23456589e-307" + +strtoIdd returns 98, consuming 15 bytes. +ddI[0] = #363196 bb9845fa + 0 1 += 1.2345658899999999e-307 + 4.9406564584124654e-324 +ddI[1] = #363196 bb9845fa + 0 2 += 1.2345658899999999e-307 + 9.8813129168249309e-324 +ddI[1] == strtod + + +Input: 1.234567890123456789 +strtopdd consumes 20 bytes and returns 33 +dd[0] = 1.2345678901234567 = #3ff3c0ca 428c59fb +dd[1] = 9.856786452588859e-17 = #3c9c6906 51a3745e +g_ddfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIdd returns 33, consuming 20 bytes. +ddI[0] = #3ff3c0ca 428c59fb + 3c9c6906 51a3745c += 1.2345678901234567 + 9.8567864525888563e-17 +ddI[1] = #3ff3c0ca 428c59fb + 3c9c6906 51a3745e += 1.2345678901234567 + 9.8567864525888588e-17 +ddI[1] == strtod + + +Input: 1.234567890123456789e301 +strtopdd consumes 24 bytes and returns 33 +dd[0] = 1.2345678901234568e+301 = #7e726f51 75f56413 +dd[1] = 1.3892003943918827e+283 = #7ab7ea80 76399100 +g_ddfmt(0) gives 25 bytes: "1.234567890123456789e+301" + +strtoIdd returns 33, consuming 24 bytes. +ddI[0] = #7e726f51 75f56413 + 7ab7ea80 76399080 += 1.2345678901234568e+301 + 1.3892003943918563e+283 +ddI[1] = #7e726f51 75f56413 + 7ab7ea80 76399100 += 1.2345678901234568e+301 + 1.3892003943918827e+283 +ddI[1] == strtod + + +Input: 1.234567890123456789e-301 +strtopdd consumes 25 bytes and returns 82 +dd[0] = 1.2345678901234567e-301 = #1752a64 e34ba0d3 +dd[1] = 7.374365e-318 = #0 16c66c +g_ddfmt(0) gives 25 bytes: "1.234567890123456789e-301" + +strtoIdd returns 82, consuming 25 bytes. +ddI[0] = #1752a64 e34ba0d3 + 0 16c66c += 1.2345678901234567e-301 + 7.374364541948945e-318 +ddI[1] = #1752a64 e34ba0d3 + 0 16c66d += 1.2345678901234567e-301 + 7.3743694826054034e-318 +ddI[0] == strtod + + +Input: 1.234567890123456789e-321 +strtopdd consumes 25 bytes and returns 98 +dd[0] = 1.235e-321 = #0 fa +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 10 bytes: "1.235e-321" + +strtoIdd returns 98, consuming 25 bytes. +ddI[0] = #0 f9 + 0 0 += 1.2302234581447039e-321 + 0 +ddI[1] = #0 fa + 0 0 += 1.2351641146031164e-321 + 0 +ddI[1] == strtod + + +Input: 1e23 +strtopdd consumes 4 bytes and returns 1 +dd[0] = 1e+23 = #44b52d02 c7e14af6 +dd[1] = 8388608 = #41600000 0 +g_ddfmt(0) gives 5 bytes: "1e+23" + +strtoIdd returns 1, consuming 4 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1e310 +strtopdd consumes 5 bytes and returns 163 +dd[0] = Infinity = #7ff00000 0 +dd[1] = Infinity = #7ff00000 0 +g_ddfmt(0) gives 8 bytes: "Infinity" + +strtoIdd returns 163, consuming 5 bytes. +ddI[0] = #7fefffff ffffffff + 7c9fffff ffffffff += 1.7976931348623157e+308 + 1.9958403095347196e+292 +ddI[1] = #7ff00000 0 + 7ff00000 0 += Infinity + Infinity +ddI[1] == strtod + + +Input: 9.0259718793241475e-277 +strtopdd consumes 23 bytes and returns 33 +dd[0] = 9.025971879324147e-277 = #69fffff ffffffff +dd[1] = 6.217378695986177e-293 = #343daae f3582320 +g_ddfmt(0) gives 23 bytes: "9.0259718793241475e-277" + +strtoIdd returns 33, consuming 23 bytes. +ddI[0] = #69fffff ffffffff + 343daae f358231f += 9.0259718793241469e-277 + 6.2173786959861757e-293 +ddI[1] = #69fffff ffffffff + 343daae f3582320 += 9.0259718793241469e-277 + 6.2173786959861768e-293 +ddI[1] == strtod + + +Input: 9.025971879324147880346310405869e-277 +strtopdd consumes 37 bytes and returns 17 +dd[0] = 9.025971879324148e-277 = #6a00000 0 +dd[1] = 2.2250738585072014e-308 = #100000 0 +g_ddfmt(0) gives 37 bytes: "9.025971879324147880346310405869e-277" + +strtoIdd returns 17, consuming 37 bytes. +ddI[0] = #6a00000 0 + 100000 0 += 9.0259718793241479e-277 + 2.2250738585072014e-308 +ddI[1] = #6a00000 0 + 200000 0 += 9.0259718793241479e-277 + 4.4501477170144028e-308 +ddI[0] == strtod + + +Input: 9.025971879324147880346310405868e-277 +strtopdd consumes 37 bytes and returns 17 +dd[0] = 9.025971879324147e-277 = #69fffff ffffffff +dd[1] = 1.0020841800044856e-292 = #34fffff fffffff9 +g_ddfmt(0) gives 37 bytes: "9.025971879324147880346310405868e-277" + +strtoIdd returns 17, consuming 37 bytes. +ddI[0] = #69fffff ffffffff + 34fffff fffffff9 += 9.0259718793241469e-277 + 1.0020841800044856e-292 +ddI[1] = #69fffff ffffffff + 34fffff fffffffa += 9.0259718793241469e-277 + 1.0020841800044857e-292 +ddI[0] == strtod + + +Input: 2.2250738585072014e-308 +strtopdd consumes 23 bytes and returns 82 +dd[0] = 2.2250738585072014e-308 = #100000 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoIdd returns 82, consuming 23 bytes. +ddI[0] = #100000 0 + 0 0 += 2.2250738585072014e-308 + 0 +ddI[1] = #100000 1 + 0 0 += 2.2250738585072019e-308 + 0 +ddI[0] == strtod + + +Input: 2.2250738585072013e-308 +strtopdd consumes 23 bytes and returns 98 +dd[0] = 2.2250738585072014e-308 = #100000 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoIdd returns 98, consuming 23 bytes. +ddI[0] = #fffff ffffffff + 0 0 += 2.2250738585072009e-308 + 0 +ddI[1] = #100000 0 + 0 0 += 2.2250738585072014e-308 + 0 +ddI[1] == strtod + +Rounding mode for strtor... changed from 1 (nearest) to 0 (toward zero) + +Input: 1.1 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.0999999999999999 = #3ff19999 99999999 +dd[1] = 1.3322676295501878e-16 = #3ca33333 33333333 +g_ddfmt(0) gives 3 bytes: "1.1" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff19999 99999999 + 3ca33333 33333333 += 1.0999999999999999 + 1.3322676295501878e-16 +ddI[1] = #3ff19999 99999999 + 3ca33333 33333334 += 1.0999999999999999 + 1.332267629550188e-16 +ddI[0] == strtod + + +Input: -1.1 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.0999999999999999 = #bff19999 99999999 +dd[1] = -1.3322676295501878e-16 = #bca33333 33333333 +g_ddfmt(0) gives 4 bytes: "-1.1" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff19999 99999999 + bca33333 33333334 += -1.0999999999999999 + -1.332267629550188e-16 +ddI[1] = #bff19999 99999999 + bca33333 33333333 += -1.0999999999999999 + -1.3322676295501878e-16 +ddI[1] == strtod + + +Input: 1.2 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.2 = #3ff33333 33333333 +dd[1] = 4.440892098500625e-17 = #3c899999 99999998 +g_ddfmt(0) gives 3 bytes: "1.2" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff33333 33333333 + 3c899999 99999998 += 1.2 + 4.4408920985006252e-17 +ddI[1] = #3ff33333 33333333 + 3c899999 9999999c += 1.2 + 4.4408920985006276e-17 +ddI[0] == strtod + + +Input: -1.2 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.2 = #bff33333 33333333 +dd[1] = -4.440892098500625e-17 = #bc899999 99999998 +g_ddfmt(0) gives 4 bytes: "-1.2" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff33333 33333333 + bc899999 9999999c += -1.2 + -4.4408920985006276e-17 +ddI[1] = #bff33333 33333333 + bc899999 99999998 += -1.2 + -4.4408920985006252e-17 +ddI[1] == strtod + + +Input: 1.3 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.2999999999999998 = #3ff4cccc cccccccc +dd[1] = 1.7763568394002503e-16 = #3ca99999 99999999 +g_ddfmt(0) gives 34 bytes: "1.29999999999999999999999999999999" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ff4cccc cccccccc + 3ca99999 99999999 += 1.2999999999999998 + 1.7763568394002503e-16 +ddI[1] = #3ff4cccc cccccccc + 3ca99999 9999999a += 1.2999999999999998 + 1.7763568394002506e-16 +ddI[0] == strtod + + +Input: -1.3 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.2999999999999998 = #bff4cccc cccccccc +dd[1] = -1.7763568394002503e-16 = #bca99999 99999999 +g_ddfmt(0) gives 35 bytes: "-1.29999999999999999999999999999999" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bff4cccc cccccccc + bca99999 9999999a += -1.2999999999999998 + -1.7763568394002506e-16 +ddI[1] = #bff4cccc cccccccc + bca99999 99999999 += -1.2999999999999998 + -1.7763568394002503e-16 +ddI[1] == strtod + + +Input: 1.4 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.4 = #3ff66666 66666666 +dd[1] = 8.88178419700125e-17 = #3c999999 99999998 +g_ddfmt(0) gives 34 bytes: "1.39999999999999999999999999999998" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ff66666 66666666 + 3c999999 99999998 += 1.3999999999999999 + 8.8817841970012504e-17 +ddI[1] = #3ff66666 66666666 + 3c999999 9999999a += 1.3999999999999999 + 8.8817841970012528e-17 +ddI[0] == strtod + + +Input: -1.4 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.4 = #bff66666 66666666 +dd[1] = -8.88178419700125e-17 = #bc999999 99999998 +g_ddfmt(0) gives 35 bytes: "-1.39999999999999999999999999999998" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bff66666 66666666 + bc999999 9999999a += -1.3999999999999999 + -8.8817841970012528e-17 +ddI[1] = #bff66666 66666666 + bc999999 99999998 += -1.3999999999999999 + -8.8817841970012504e-17 +ddI[1] == strtod + + +Input: 1.5 +strtopdd consumes 3 bytes and returns 1 +dd[0] = 1.5 = #3ff80000 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 3 bytes: "1.5" + +strtoIdd returns 1, consuming 3 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: -1.5 +strtopdd consumes 4 bytes and returns 9 +dd[0] = -1.5 = #bff80000 0 +dd[1] = -0 = #80000000 0 +g_ddfmt(0) gives 3 bytes: "1.5" + +strtoIdd returns 9, consuming 4 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1.6 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.5999999999999999 = #3ff99999 99999999 +dd[1] = 1.3322676295501878e-16 = #3ca33333 33333333 +g_ddfmt(0) gives 3 bytes: "1.6" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff99999 99999999 + 3ca33333 33333333 += 1.5999999999999999 + 1.3322676295501878e-16 +ddI[1] = #3ff99999 99999999 + 3ca33333 33333334 += 1.5999999999999999 + 1.332267629550188e-16 +ddI[0] == strtod + + +Input: -1.6 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.5999999999999999 = #bff99999 99999999 +dd[1] = -1.3322676295501878e-16 = #bca33333 33333333 +g_ddfmt(0) gives 4 bytes: "-1.6" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff99999 99999999 + bca33333 33333334 += -1.5999999999999999 + -1.332267629550188e-16 +ddI[1] = #bff99999 99999999 + bca33333 33333333 += -1.5999999999999999 + -1.3322676295501878e-16 +ddI[1] == strtod + + +Input: 1.7 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.7 = #3ffb3333 33333333 +dd[1] = 4.440892098500625e-17 = #3c899999 99999998 +g_ddfmt(0) gives 3 bytes: "1.7" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ffb3333 33333333 + 3c899999 99999998 += 1.7 + 4.4408920985006252e-17 +ddI[1] = #3ffb3333 33333333 + 3c899999 9999999c += 1.7 + 4.4408920985006276e-17 +ddI[0] == strtod + + +Input: -1.7 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.7 = #bffb3333 33333333 +dd[1] = -4.440892098500625e-17 = #bc899999 99999998 +g_ddfmt(0) gives 4 bytes: "-1.7" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bffb3333 33333333 + bc899999 9999999c += -1.7 + -4.4408920985006276e-17 +ddI[1] = #bffb3333 33333333 + bc899999 99999998 += -1.7 + -4.4408920985006252e-17 +ddI[1] == strtod + + +Input: 1.8 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.7999999999999998 = #3ffccccc cccccccc +dd[1] = 1.7763568394002503e-16 = #3ca99999 99999999 +g_ddfmt(0) gives 34 bytes: "1.79999999999999999999999999999999" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ffccccc cccccccc + 3ca99999 99999999 += 1.7999999999999998 + 1.7763568394002503e-16 +ddI[1] = #3ffccccc cccccccc + 3ca99999 9999999a += 1.7999999999999998 + 1.7763568394002506e-16 +ddI[0] == strtod + + +Input: -1.8 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.7999999999999998 = #bffccccc cccccccc +dd[1] = -1.7763568394002503e-16 = #bca99999 99999999 +g_ddfmt(0) gives 35 bytes: "-1.79999999999999999999999999999999" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bffccccc cccccccc + bca99999 9999999a += -1.7999999999999998 + -1.7763568394002506e-16 +ddI[1] = #bffccccc cccccccc + bca99999 99999999 += -1.7999999999999998 + -1.7763568394002503e-16 +ddI[1] == strtod + + +Input: 1.9 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.9 = #3ffe6666 66666666 +dd[1] = 8.88178419700125e-17 = #3c999999 99999998 +g_ddfmt(0) gives 34 bytes: "1.89999999999999999999999999999998" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ffe6666 66666666 + 3c999999 99999998 += 1.8999999999999999 + 8.8817841970012504e-17 +ddI[1] = #3ffe6666 66666666 + 3c999999 9999999a += 1.8999999999999999 + 8.8817841970012528e-17 +ddI[0] == strtod + + +Input: -1.9 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.9 = #bffe6666 66666666 +dd[1] = -8.88178419700125e-17 = #bc999999 99999998 +g_ddfmt(0) gives 35 bytes: "-1.89999999999999999999999999999998" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bffe6666 66666666 + bc999999 9999999a += -1.8999999999999999 + -8.8817841970012528e-17 +ddI[1] = #bffe6666 66666666 + bc999999 99999998 += -1.8999999999999999 + -8.8817841970012504e-17 +ddI[1] == strtod + +Rounding mode for strtor... changed from 0 (toward zero) to 1 (nearest) + +Input: 1.1 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.0999999999999999 = #3ff19999 99999999 +dd[1] = 1.3322676295501878e-16 = #3ca33333 33333333 +g_ddfmt(0) gives 3 bytes: "1.1" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff19999 99999999 + 3ca33333 33333333 += 1.0999999999999999 + 1.3322676295501878e-16 +ddI[1] = #3ff19999 99999999 + 3ca33333 33333334 += 1.0999999999999999 + 1.332267629550188e-16 +ddI[0] == strtod + + +Input: -1.1 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.0999999999999999 = #bff19999 99999999 +dd[1] = -1.3322676295501878e-16 = #bca33333 33333333 +g_ddfmt(0) gives 4 bytes: "-1.1" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff19999 99999999 + bca33333 33333334 += -1.0999999999999999 + -1.332267629550188e-16 +ddI[1] = #bff19999 99999999 + bca33333 33333333 += -1.0999999999999999 + -1.3322676295501878e-16 +ddI[1] == strtod + + +Input: 1.2 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.2 = #3ff33333 33333333 +dd[1] = 4.440892098500625e-17 = #3c899999 99999998 +g_ddfmt(0) gives 3 bytes: "1.2" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff33333 33333333 + 3c899999 99999998 += 1.2 + 4.4408920985006252e-17 +ddI[1] = #3ff33333 33333333 + 3c899999 9999999c += 1.2 + 4.4408920985006276e-17 +ddI[0] == strtod + + +Input: -1.2 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.2 = #bff33333 33333333 +dd[1] = -4.440892098500625e-17 = #bc899999 99999998 +g_ddfmt(0) gives 4 bytes: "-1.2" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff33333 33333333 + bc899999 9999999c += -1.2 + -4.4408920985006276e-17 +ddI[1] = #bff33333 33333333 + bc899999 99999998 += -1.2 + -4.4408920985006252e-17 +ddI[1] == strtod + + +Input: 1.3 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.2999999999999998 = #3ff4cccc cccccccc +dd[1] = 1.7763568394002506e-16 = #3ca99999 9999999a +g_ddfmt(0) gives 3 bytes: "1.3" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ff4cccc cccccccc + 3ca99999 99999999 += 1.2999999999999998 + 1.7763568394002503e-16 +ddI[1] = #3ff4cccc cccccccc + 3ca99999 9999999a += 1.2999999999999998 + 1.7763568394002506e-16 +ddI[1] == strtod + + +Input: -1.3 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.2999999999999998 = #bff4cccc cccccccc +dd[1] = -1.7763568394002506e-16 = #bca99999 9999999a +g_ddfmt(0) gives 4 bytes: "-1.3" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bff4cccc cccccccc + bca99999 9999999a += -1.2999999999999998 + -1.7763568394002506e-16 +ddI[1] = #bff4cccc cccccccc + bca99999 99999999 += -1.2999999999999998 + -1.7763568394002503e-16 +ddI[0] == strtod + + +Input: 1.4 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.4 = #3ff66666 66666666 +dd[1] = 8.881784197001253e-17 = #3c999999 9999999a +g_ddfmt(0) gives 3 bytes: "1.4" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ff66666 66666666 + 3c999999 99999998 += 1.3999999999999999 + 8.8817841970012504e-17 +ddI[1] = #3ff66666 66666666 + 3c999999 9999999a += 1.3999999999999999 + 8.8817841970012528e-17 +ddI[1] == strtod + + +Input: -1.4 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.4 = #bff66666 66666666 +dd[1] = -8.881784197001253e-17 = #bc999999 9999999a +g_ddfmt(0) gives 4 bytes: "-1.4" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bff66666 66666666 + bc999999 9999999a += -1.3999999999999999 + -8.8817841970012528e-17 +ddI[1] = #bff66666 66666666 + bc999999 99999998 += -1.3999999999999999 + -8.8817841970012504e-17 +ddI[0] == strtod + + +Input: 1.5 +strtopdd consumes 3 bytes and returns 1 +dd[0] = 1.5 = #3ff80000 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 3 bytes: "1.5" + +strtoIdd returns 1, consuming 3 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: -1.5 +strtopdd consumes 4 bytes and returns 9 +dd[0] = -1.5 = #bff80000 0 +dd[1] = -0 = #80000000 0 +g_ddfmt(0) gives 3 bytes: "1.5" + +strtoIdd returns 9, consuming 4 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1.6 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.5999999999999999 = #3ff99999 99999999 +dd[1] = 1.3322676295501878e-16 = #3ca33333 33333333 +g_ddfmt(0) gives 3 bytes: "1.6" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff99999 99999999 + 3ca33333 33333333 += 1.5999999999999999 + 1.3322676295501878e-16 +ddI[1] = #3ff99999 99999999 + 3ca33333 33333334 += 1.5999999999999999 + 1.332267629550188e-16 +ddI[0] == strtod + + +Input: -1.6 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.5999999999999999 = #bff99999 99999999 +dd[1] = -1.3322676295501878e-16 = #bca33333 33333333 +g_ddfmt(0) gives 4 bytes: "-1.6" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff99999 99999999 + bca33333 33333334 += -1.5999999999999999 + -1.332267629550188e-16 +ddI[1] = #bff99999 99999999 + bca33333 33333333 += -1.5999999999999999 + -1.3322676295501878e-16 +ddI[1] == strtod + + +Input: 1.7 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.7 = #3ffb3333 33333333 +dd[1] = 4.440892098500625e-17 = #3c899999 99999998 +g_ddfmt(0) gives 3 bytes: "1.7" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ffb3333 33333333 + 3c899999 99999998 += 1.7 + 4.4408920985006252e-17 +ddI[1] = #3ffb3333 33333333 + 3c899999 9999999c += 1.7 + 4.4408920985006276e-17 +ddI[0] == strtod + + +Input: -1.7 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.7 = #bffb3333 33333333 +dd[1] = -4.440892098500625e-17 = #bc899999 99999998 +g_ddfmt(0) gives 4 bytes: "-1.7" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bffb3333 33333333 + bc899999 9999999c += -1.7 + -4.4408920985006276e-17 +ddI[1] = #bffb3333 33333333 + bc899999 99999998 += -1.7 + -4.4408920985006252e-17 +ddI[1] == strtod + + +Input: 1.8 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.7999999999999998 = #3ffccccc cccccccc +dd[1] = 1.7763568394002506e-16 = #3ca99999 9999999a +g_ddfmt(0) gives 3 bytes: "1.8" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ffccccc cccccccc + 3ca99999 99999999 += 1.7999999999999998 + 1.7763568394002503e-16 +ddI[1] = #3ffccccc cccccccc + 3ca99999 9999999a += 1.7999999999999998 + 1.7763568394002506e-16 +ddI[1] == strtod + + +Input: -1.8 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.7999999999999998 = #bffccccc cccccccc +dd[1] = -1.7763568394002506e-16 = #bca99999 9999999a +g_ddfmt(0) gives 4 bytes: "-1.8" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bffccccc cccccccc + bca99999 9999999a += -1.7999999999999998 + -1.7763568394002506e-16 +ddI[1] = #bffccccc cccccccc + bca99999 99999999 += -1.7999999999999998 + -1.7763568394002503e-16 +ddI[0] == strtod + + +Input: 1.9 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.9 = #3ffe6666 66666666 +dd[1] = 8.881784197001253e-17 = #3c999999 9999999a +g_ddfmt(0) gives 3 bytes: "1.9" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ffe6666 66666666 + 3c999999 99999998 += 1.8999999999999999 + 8.8817841970012504e-17 +ddI[1] = #3ffe6666 66666666 + 3c999999 9999999a += 1.8999999999999999 + 8.8817841970012528e-17 +ddI[1] == strtod + + +Input: -1.9 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.9 = #bffe6666 66666666 +dd[1] = -8.881784197001253e-17 = #bc999999 9999999a +g_ddfmt(0) gives 4 bytes: "-1.9" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bffe6666 66666666 + bc999999 9999999a += -1.8999999999999999 + -8.8817841970012528e-17 +ddI[1] = #bffe6666 66666666 + bc999999 99999998 += -1.8999999999999999 + -8.8817841970012504e-17 +ddI[0] == strtod + +Rounding mode for strtor... changed from 1 (nearest) to 2 (toward +Infinity) + +Input: 1.1 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.0999999999999999 = #3ff19999 99999999 +dd[1] = 1.332267629550188e-16 = #3ca33333 33333334 +g_ddfmt(0) gives 34 bytes: "1.10000000000000000000000000000002" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff19999 99999999 + 3ca33333 33333333 += 1.0999999999999999 + 1.3322676295501878e-16 +ddI[1] = #3ff19999 99999999 + 3ca33333 33333334 += 1.0999999999999999 + 1.332267629550188e-16 +ddI[1] == strtod + + +Input: -1.1 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.0999999999999999 = #bff19999 99999999 +dd[1] = -1.3322676295501878e-16 = #bca33333 33333333 +g_ddfmt(0) gives 4 bytes: "-1.1" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff19999 99999999 + bca33333 33333334 += -1.0999999999999999 + -1.332267629550188e-16 +ddI[1] = #bff19999 99999999 + bca33333 33333333 += -1.0999999999999999 + -1.3322676295501878e-16 +ddI[1] == strtod + + +Input: 1.2 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.2 = #3ff33333 33333333 +dd[1] = 4.4408920985006276e-17 = #3c899999 9999999c +g_ddfmt(0) gives 34 bytes: "1.20000000000000000000000000000001" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff33333 33333333 + 3c899999 99999998 += 1.2 + 4.4408920985006252e-17 +ddI[1] = #3ff33333 33333333 + 3c899999 9999999c += 1.2 + 4.4408920985006276e-17 +ddI[1] == strtod + + +Input: -1.2 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.2 = #bff33333 33333333 +dd[1] = -4.440892098500625e-17 = #bc899999 99999998 +g_ddfmt(0) gives 4 bytes: "-1.2" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff33333 33333333 + bc899999 9999999c += -1.2 + -4.4408920985006276e-17 +ddI[1] = #bff33333 33333333 + bc899999 99999998 += -1.2 + -4.4408920985006252e-17 +ddI[1] == strtod + + +Input: 1.3 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.2999999999999998 = #3ff4cccc cccccccc +dd[1] = 1.7763568394002506e-16 = #3ca99999 9999999a +g_ddfmt(0) gives 3 bytes: "1.3" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ff4cccc cccccccc + 3ca99999 99999999 += 1.2999999999999998 + 1.7763568394002503e-16 +ddI[1] = #3ff4cccc cccccccc + 3ca99999 9999999a += 1.2999999999999998 + 1.7763568394002506e-16 +ddI[1] == strtod + + +Input: -1.3 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.2999999999999998 = #bff4cccc cccccccc +dd[1] = -1.7763568394002503e-16 = #bca99999 99999999 +g_ddfmt(0) gives 35 bytes: "-1.29999999999999999999999999999999" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bff4cccc cccccccc + bca99999 9999999a += -1.2999999999999998 + -1.7763568394002506e-16 +ddI[1] = #bff4cccc cccccccc + bca99999 99999999 += -1.2999999999999998 + -1.7763568394002503e-16 +ddI[1] == strtod + + +Input: 1.4 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.4 = #3ff66666 66666666 +dd[1] = 8.881784197001253e-17 = #3c999999 9999999a +g_ddfmt(0) gives 3 bytes: "1.4" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ff66666 66666666 + 3c999999 99999998 += 1.3999999999999999 + 8.8817841970012504e-17 +ddI[1] = #3ff66666 66666666 + 3c999999 9999999a += 1.3999999999999999 + 8.8817841970012528e-17 +ddI[1] == strtod + + +Input: -1.4 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.4 = #bff66666 66666666 +dd[1] = -8.88178419700125e-17 = #bc999999 99999998 +g_ddfmt(0) gives 35 bytes: "-1.39999999999999999999999999999998" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bff66666 66666666 + bc999999 9999999a += -1.3999999999999999 + -8.8817841970012528e-17 +ddI[1] = #bff66666 66666666 + bc999999 99999998 += -1.3999999999999999 + -8.8817841970012504e-17 +ddI[1] == strtod + + +Input: 1.5 +strtopdd consumes 3 bytes and returns 1 +dd[0] = 1.5 = #3ff80000 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 3 bytes: "1.5" + +strtoIdd returns 1, consuming 3 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: -1.5 +strtopdd consumes 4 bytes and returns 9 +dd[0] = -1.5 = #bff80000 0 +dd[1] = -0 = #80000000 0 +g_ddfmt(0) gives 3 bytes: "1.5" + +strtoIdd returns 9, consuming 4 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1.6 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.5999999999999999 = #3ff99999 99999999 +dd[1] = 1.332267629550188e-16 = #3ca33333 33333334 +g_ddfmt(0) gives 34 bytes: "1.60000000000000000000000000000002" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff99999 99999999 + 3ca33333 33333333 += 1.5999999999999999 + 1.3322676295501878e-16 +ddI[1] = #3ff99999 99999999 + 3ca33333 33333334 += 1.5999999999999999 + 1.332267629550188e-16 +ddI[1] == strtod + + +Input: -1.6 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.5999999999999999 = #bff99999 99999999 +dd[1] = -1.3322676295501878e-16 = #bca33333 33333333 +g_ddfmt(0) gives 4 bytes: "-1.6" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff99999 99999999 + bca33333 33333334 += -1.5999999999999999 + -1.332267629550188e-16 +ddI[1] = #bff99999 99999999 + bca33333 33333333 += -1.5999999999999999 + -1.3322676295501878e-16 +ddI[1] == strtod + + +Input: 1.7 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.7 = #3ffb3333 33333333 +dd[1] = 4.4408920985006276e-17 = #3c899999 9999999c +g_ddfmt(0) gives 34 bytes: "1.70000000000000000000000000000001" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ffb3333 33333333 + 3c899999 99999998 += 1.7 + 4.4408920985006252e-17 +ddI[1] = #3ffb3333 33333333 + 3c899999 9999999c += 1.7 + 4.4408920985006276e-17 +ddI[1] == strtod + + +Input: -1.7 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.7 = #bffb3333 33333333 +dd[1] = -4.440892098500625e-17 = #bc899999 99999998 +g_ddfmt(0) gives 4 bytes: "-1.7" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bffb3333 33333333 + bc899999 9999999c += -1.7 + -4.4408920985006276e-17 +ddI[1] = #bffb3333 33333333 + bc899999 99999998 += -1.7 + -4.4408920985006252e-17 +ddI[1] == strtod + + +Input: 1.8 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.7999999999999998 = #3ffccccc cccccccc +dd[1] = 1.7763568394002506e-16 = #3ca99999 9999999a +g_ddfmt(0) gives 3 bytes: "1.8" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ffccccc cccccccc + 3ca99999 99999999 += 1.7999999999999998 + 1.7763568394002503e-16 +ddI[1] = #3ffccccc cccccccc + 3ca99999 9999999a += 1.7999999999999998 + 1.7763568394002506e-16 +ddI[1] == strtod + + +Input: -1.8 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.7999999999999998 = #bffccccc cccccccc +dd[1] = -1.7763568394002503e-16 = #bca99999 99999999 +g_ddfmt(0) gives 35 bytes: "-1.79999999999999999999999999999999" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bffccccc cccccccc + bca99999 9999999a += -1.7999999999999998 + -1.7763568394002506e-16 +ddI[1] = #bffccccc cccccccc + bca99999 99999999 += -1.7999999999999998 + -1.7763568394002503e-16 +ddI[1] == strtod + + +Input: 1.9 +strtopdd consumes 3 bytes and returns 33 +dd[0] = 1.9 = #3ffe6666 66666666 +dd[1] = 8.881784197001253e-17 = #3c999999 9999999a +g_ddfmt(0) gives 3 bytes: "1.9" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ffe6666 66666666 + 3c999999 99999998 += 1.8999999999999999 + 8.8817841970012504e-17 +ddI[1] = #3ffe6666 66666666 + 3c999999 9999999a += 1.8999999999999999 + 8.8817841970012528e-17 +ddI[1] == strtod + + +Input: -1.9 +strtopdd consumes 4 bytes and returns 25 +dd[0] = -1.9 = #bffe6666 66666666 +dd[1] = -8.88178419700125e-17 = #bc999999 99999998 +g_ddfmt(0) gives 35 bytes: "-1.89999999999999999999999999999998" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bffe6666 66666666 + bc999999 9999999a += -1.8999999999999999 + -8.8817841970012528e-17 +ddI[1] = #bffe6666 66666666 + bc999999 99999998 += -1.8999999999999999 + -8.8817841970012504e-17 +ddI[1] == strtod + +Rounding mode for strtor... changed from 2 (toward +Infinity) to 3 (toward -Infinity) + +Input: 1.1 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.0999999999999999 = #3ff19999 99999999 +dd[1] = 1.3322676295501878e-16 = #3ca33333 33333333 +g_ddfmt(0) gives 3 bytes: "1.1" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff19999 99999999 + 3ca33333 33333333 += 1.0999999999999999 + 1.3322676295501878e-16 +ddI[1] = #3ff19999 99999999 + 3ca33333 33333334 += 1.0999999999999999 + 1.332267629550188e-16 +ddI[0] == strtod + + +Input: -1.1 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.0999999999999999 = #bff19999 99999999 +dd[1] = -1.332267629550188e-16 = #bca33333 33333334 +g_ddfmt(0) gives 35 bytes: "-1.10000000000000000000000000000002" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff19999 99999999 + bca33333 33333334 += -1.0999999999999999 + -1.332267629550188e-16 +ddI[1] = #bff19999 99999999 + bca33333 33333333 += -1.0999999999999999 + -1.3322676295501878e-16 +ddI[0] == strtod + + +Input: 1.2 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.2 = #3ff33333 33333333 +dd[1] = 4.440892098500625e-17 = #3c899999 99999998 +g_ddfmt(0) gives 3 bytes: "1.2" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff33333 33333333 + 3c899999 99999998 += 1.2 + 4.4408920985006252e-17 +ddI[1] = #3ff33333 33333333 + 3c899999 9999999c += 1.2 + 4.4408920985006276e-17 +ddI[0] == strtod + + +Input: -1.2 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.2 = #bff33333 33333333 +dd[1] = -4.4408920985006276e-17 = #bc899999 9999999c +g_ddfmt(0) gives 35 bytes: "-1.20000000000000000000000000000001" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff33333 33333333 + bc899999 9999999c += -1.2 + -4.4408920985006276e-17 +ddI[1] = #bff33333 33333333 + bc899999 99999998 += -1.2 + -4.4408920985006252e-17 +ddI[0] == strtod + + +Input: 1.3 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.2999999999999998 = #3ff4cccc cccccccc +dd[1] = 1.7763568394002503e-16 = #3ca99999 99999999 +g_ddfmt(0) gives 34 bytes: "1.29999999999999999999999999999999" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ff4cccc cccccccc + 3ca99999 99999999 += 1.2999999999999998 + 1.7763568394002503e-16 +ddI[1] = #3ff4cccc cccccccc + 3ca99999 9999999a += 1.2999999999999998 + 1.7763568394002506e-16 +ddI[0] == strtod + + +Input: -1.3 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.2999999999999998 = #bff4cccc cccccccc +dd[1] = -1.7763568394002506e-16 = #bca99999 9999999a +g_ddfmt(0) gives 4 bytes: "-1.3" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bff4cccc cccccccc + bca99999 9999999a += -1.2999999999999998 + -1.7763568394002506e-16 +ddI[1] = #bff4cccc cccccccc + bca99999 99999999 += -1.2999999999999998 + -1.7763568394002503e-16 +ddI[0] == strtod + + +Input: 1.4 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.4 = #3ff66666 66666666 +dd[1] = 8.88178419700125e-17 = #3c999999 99999998 +g_ddfmt(0) gives 34 bytes: "1.39999999999999999999999999999998" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ff66666 66666666 + 3c999999 99999998 += 1.3999999999999999 + 8.8817841970012504e-17 +ddI[1] = #3ff66666 66666666 + 3c999999 9999999a += 1.3999999999999999 + 8.8817841970012528e-17 +ddI[0] == strtod + + +Input: -1.4 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.4 = #bff66666 66666666 +dd[1] = -8.881784197001253e-17 = #bc999999 9999999a +g_ddfmt(0) gives 4 bytes: "-1.4" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bff66666 66666666 + bc999999 9999999a += -1.3999999999999999 + -8.8817841970012528e-17 +ddI[1] = #bff66666 66666666 + bc999999 99999998 += -1.3999999999999999 + -8.8817841970012504e-17 +ddI[0] == strtod + + +Input: 1.5 +strtopdd consumes 3 bytes and returns 1 +dd[0] = 1.5 = #3ff80000 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 3 bytes: "1.5" + +strtoIdd returns 1, consuming 3 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: -1.5 +strtopdd consumes 4 bytes and returns 9 +dd[0] = -1.5 = #bff80000 0 +dd[1] = -0 = #80000000 0 +g_ddfmt(0) gives 3 bytes: "1.5" + +strtoIdd returns 9, consuming 4 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1.6 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.5999999999999999 = #3ff99999 99999999 +dd[1] = 1.3322676295501878e-16 = #3ca33333 33333333 +g_ddfmt(0) gives 3 bytes: "1.6" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ff99999 99999999 + 3ca33333 33333333 += 1.5999999999999999 + 1.3322676295501878e-16 +ddI[1] = #3ff99999 99999999 + 3ca33333 33333334 += 1.5999999999999999 + 1.332267629550188e-16 +ddI[0] == strtod + + +Input: -1.6 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.5999999999999999 = #bff99999 99999999 +dd[1] = -1.332267629550188e-16 = #bca33333 33333334 +g_ddfmt(0) gives 35 bytes: "-1.60000000000000000000000000000002" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bff99999 99999999 + bca33333 33333334 += -1.5999999999999999 + -1.332267629550188e-16 +ddI[1] = #bff99999 99999999 + bca33333 33333333 += -1.5999999999999999 + -1.3322676295501878e-16 +ddI[0] == strtod + + +Input: 1.7 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.7 = #3ffb3333 33333333 +dd[1] = 4.440892098500625e-17 = #3c899999 99999998 +g_ddfmt(0) gives 3 bytes: "1.7" + +strtoIdd returns 17, consuming 3 bytes. +ddI[0] = #3ffb3333 33333333 + 3c899999 99999998 += 1.7 + 4.4408920985006252e-17 +ddI[1] = #3ffb3333 33333333 + 3c899999 9999999c += 1.7 + 4.4408920985006276e-17 +ddI[0] == strtod + + +Input: -1.7 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.7 = #bffb3333 33333333 +dd[1] = -4.4408920985006276e-17 = #bc899999 9999999c +g_ddfmt(0) gives 35 bytes: "-1.70000000000000000000000000000001" + +strtoIdd returns 25, consuming 4 bytes. +ddI[0] = #bffb3333 33333333 + bc899999 9999999c += -1.7 + -4.4408920985006276e-17 +ddI[1] = #bffb3333 33333333 + bc899999 99999998 += -1.7 + -4.4408920985006252e-17 +ddI[0] == strtod + + +Input: 1.8 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.7999999999999998 = #3ffccccc cccccccc +dd[1] = 1.7763568394002503e-16 = #3ca99999 99999999 +g_ddfmt(0) gives 34 bytes: "1.79999999999999999999999999999999" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ffccccc cccccccc + 3ca99999 99999999 += 1.7999999999999998 + 1.7763568394002503e-16 +ddI[1] = #3ffccccc cccccccc + 3ca99999 9999999a += 1.7999999999999998 + 1.7763568394002506e-16 +ddI[0] == strtod + + +Input: -1.8 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.7999999999999998 = #bffccccc cccccccc +dd[1] = -1.7763568394002506e-16 = #bca99999 9999999a +g_ddfmt(0) gives 4 bytes: "-1.8" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bffccccc cccccccc + bca99999 9999999a += -1.7999999999999998 + -1.7763568394002506e-16 +ddI[1] = #bffccccc cccccccc + bca99999 99999999 += -1.7999999999999998 + -1.7763568394002503e-16 +ddI[0] == strtod + + +Input: 1.9 +strtopdd consumes 3 bytes and returns 17 +dd[0] = 1.9 = #3ffe6666 66666666 +dd[1] = 8.88178419700125e-17 = #3c999999 99999998 +g_ddfmt(0) gives 34 bytes: "1.89999999999999999999999999999998" + +strtoIdd returns 33, consuming 3 bytes. +ddI[0] = #3ffe6666 66666666 + 3c999999 99999998 += 1.8999999999999999 + 8.8817841970012504e-17 +ddI[1] = #3ffe6666 66666666 + 3c999999 9999999a += 1.8999999999999999 + 8.8817841970012528e-17 +ddI[0] == strtod + + +Input: -1.9 +strtopdd consumes 4 bytes and returns 41 +dd[0] = -1.9 = #bffe6666 66666666 +dd[1] = -8.881784197001253e-17 = #bc999999 9999999a +g_ddfmt(0) gives 4 bytes: "-1.9" + +strtoIdd returns 41, consuming 4 bytes. +ddI[0] = #bffe6666 66666666 + bc999999 9999999a += -1.8999999999999999 + -8.8817841970012528e-17 +ddI[1] = #bffe6666 66666666 + bc999999 99999998 += -1.8999999999999999 + -8.8817841970012504e-17 +ddI[0] == strtod + diff --git a/lib/libc/gdtoa/test/ddsi.out b/lib/libc/gdtoa/test/ddsi.out new file mode 100644 index 000000000..1677707f2 --- /dev/null +++ b/lib/libc/gdtoa/test/ddsi.out @@ -0,0 +1,376 @@ + +Input: 1.23 +strtopdd consumes 4 bytes and returns 17 +dd[0] = 1.23 = #3ff3ae14 7ae147ae +dd[1] = 1.7763568394002496e-17 = #3c747ae1 47ae1478 +g_ddfmt(0) gives 4 bytes: "1.23" + +strtoIdd returns 17, consuming 4 bytes. +ddI[0] = #3ff3ae14 7ae147ae + 3c747ae1 47ae1478 += 1.23 + 1.7763568394002496e-17 +ddI[1] = #3ff3ae14 7ae147ae + 3c747ae1 47ae1480 += 1.23 + 1.776356839400252e-17 +ddI[0] == strtod + + +Input: 1.23e+20 +strtopdd consumes 8 bytes and returns 1 +dd[0] = 1.23e+20 = #441aabdf 2145b430 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 8 bytes: "1.23e+20" + +strtoIdd returns 1, consuming 8 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1.23e-20 +strtopdd consumes 8 bytes and returns 33 +dd[0] = 1.2299999999999999e-20 = #3bcd0ae4 cf767530 +dd[1] = 9.304023318521521e-37 = #3873c997 955b2691 +g_ddfmt(0) gives 8 bytes: "1.23e-20" + +strtoIdd returns 33, consuming 8 bytes. +ddI[0] = #3bcd0ae4 cf767530 + 3873c997 955b2690 += 1.2299999999999999e-20 + 9.3040233185215194e-37 +ddI[1] = #3bcd0ae4 cf767530 + 3873c997 955b2691 += 1.2299999999999999e-20 + 9.3040233185215211e-37 +ddI[1] == strtod + + +Input: 1.23456789 +strtopdd consumes 10 bytes and returns 17 +dd[0] = 1.23456789 = #3ff3c0ca 4283de1b +dd[1] = 1.0990618193318369e-16 = #3c9fada5 144c1252 +g_ddfmt(0) gives 10 bytes: "1.23456789" + +strtoIdd returns 17, consuming 10 bytes. +ddI[0] = #3ff3c0ca 4283de1b + 3c9fada5 144c1252 += 1.2345678899999999 + 1.0990618193318369e-16 +ddI[1] = #3ff3c0ca 4283de1b + 3c9fada5 144c1254 += 1.2345678899999999 + 1.0990618193318371e-16 +ddI[0] == strtod + + +Input: 1.23456589e+20 +strtopdd consumes 14 bytes and returns 1 +dd[0] = 1.23456589e+20 = #441ac537 a660b997 +dd[1] = 4096 = #40b00000 0 +g_ddfmt(0) gives 14 bytes: "1.23456589e+20" + +strtoIdd returns 1, consuming 14 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1.23e+30 +strtopdd consumes 8 bytes and returns 1 +dd[0] = 1.23e+30 = #462f0cb0 4e8fb790 +dd[1] = 40281156091904 = #42c25158 0 +g_ddfmt(0) gives 8 bytes: "1.23e+30" + +strtoIdd returns 1, consuming 8 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1.23e-30 +strtopdd consumes 8 bytes and returns 17 +dd[0] = 1.2299999999999999e-30 = #39b8f286 6f5010aa +dd[1] = 1.076909723013918e-46 = #3663ac7f 3dafd174 +g_ddfmt(0) gives 8 bytes: "1.23e-30" + +strtoIdd returns 17, consuming 8 bytes. +ddI[0] = #39b8f286 6f5010aa + 3663ac7f 3dafd174 += 1.2299999999999999e-30 + 1.076909723013918e-46 +ddI[1] = #39b8f286 6f5010aa + 3663ac7f 3dafd175 += 1.2299999999999999e-30 + 1.0769097230139181e-46 +ddI[0] == strtod + + +Input: 1.23456789e-20 +strtopdd consumes 14 bytes and returns 17 +dd[0] = 1.23456789e-20 = #3bcd2681 471e7ada +dd[1] = 6.247111971663133e-37 = #386a9280 a761b07e +g_ddfmt(0) gives 14 bytes: "1.23456789e-20" + +strtoIdd returns 17, consuming 14 bytes. +ddI[0] = #3bcd2681 471e7ada + 386a9280 a761b07e += 1.2345678899999999e-20 + 6.2471119716631328e-37 +ddI[1] = #3bcd2681 471e7ada + 386a9280 a761b080 += 1.2345678899999999e-20 + 6.2471119716631345e-37 +ddI[0] == strtod + + +Input: 1.23456789e-30 +strtopdd consumes 14 bytes and returns 33 +dd[0] = 1.23456789e-30 = #39b90a3e 33bbd995 +dd[1] = 2.1567930523648577e-47 = #363f8585 55a6b1a0 +g_ddfmt(0) gives 14 bytes: "1.23456789e-30" + +strtoIdd returns 33, consuming 14 bytes. +ddI[0] = #39b90a3e 33bbd995 + 363f8585 55a6b198 += 1.23456789e-30 + 2.1567930523648558e-47 +ddI[1] = #39b90a3e 33bbd995 + 363f8585 55a6b1a0 += 1.23456789e-30 + 2.1567930523648577e-47 +ddI[1] == strtod + + +Input: 1.234567890123456789 +strtopdd consumes 20 bytes and returns 33 +dd[0] = 1.2345678901234567 = #3ff3c0ca 428c59fb +dd[1] = 9.856786452588859e-17 = #3c9c6906 51a3745e +g_ddfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIdd returns 33, consuming 20 bytes. +ddI[0] = #3ff3c0ca 428c59fb + 3c9c6906 51a3745c += 1.2345678901234567 + 9.8567864525888563e-17 +ddI[1] = #3ff3c0ca 428c59fb + 3c9c6906 51a3745e += 1.2345678901234567 + 9.8567864525888588e-17 +ddI[1] == strtod + + +Input: 1.23456789012345678901234567890123456789 +strtopdd consumes 40 bytes and returns 33 +dd[0] = 1.2345678901234567 = #3ff3c0ca 428c59fb +dd[1] = 9.858021020478982e-17 = #3c9c69ef 85adadb6 +g_ddfmt(0) gives 34 bytes: "1.23456789012345678901234567890124" + +strtoIdd returns 33, consuming 40 bytes. +ddI[0] = #3ff3c0ca 428c59fb + 3c9c69ef 85adadb4 += 1.2345678901234567 + 9.8580210204789798e-17 +ddI[1] = #3ff3c0ca 428c59fb + 3c9c69ef 85adadb6 += 1.2345678901234567 + 9.8580210204789823e-17 +ddI[1] == strtod + + +Input: 1.23e306 +strtopdd consumes 8 bytes and returns 33 +dd[0] = 1.2299999999999999e+306 = #7f7c0676 cd1c61f4 +dd[1] = 1.3319001448659015e+290 = #7c2b558b e3d3f477 +g_ddfmt(0) gives 9 bytes: "1.23e+306" + +strtoIdd returns 33, consuming 8 bytes. +ddI[0] = #7f7c0676 cd1c61f4 + 7c2b558b e3d3f476 += 1.2299999999999999e+306 + 1.3319001448659013e+290 +ddI[1] = #7f7c0676 cd1c61f4 + 7c2b558b e3d3f477 += 1.2299999999999999e+306 + 1.3319001448659015e+290 +ddI[1] == strtod + + +Input: 1.23e-306 +strtopdd consumes 9 bytes and returns 80 +dd[0] = 0 = #0 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 1 bytes: "0" + +strtoIdd returns 80, consuming 9 bytes. +ddI[0] = #0 0 + 0 0 += 0 + 0 +ddI[1] = #6a00000 0 + 0 0 += 9.0259718793241479e-277 + 0 +ddI[0] == strtod + + +Input: 1.23e-320 +strtopdd consumes 9 bytes and returns 80 +dd[0] = 0 = #0 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 1 bytes: "0" + +strtoIdd returns 80, consuming 9 bytes. +ddI[0] = #0 0 + 0 0 += 0 + 0 +ddI[1] = #6a00000 0 + 0 0 += 9.0259718793241479e-277 + 0 +ddI[0] == strtod + + +Input: 1.23e-20 +strtopdd consumes 8 bytes and returns 33 +dd[0] = 1.2299999999999999e-20 = #3bcd0ae4 cf767530 +dd[1] = 9.304023318521521e-37 = #3873c997 955b2691 +g_ddfmt(0) gives 8 bytes: "1.23e-20" + +strtoIdd returns 33, consuming 8 bytes. +ddI[0] = #3bcd0ae4 cf767530 + 3873c997 955b2690 += 1.2299999999999999e-20 + 9.3040233185215194e-37 +ddI[1] = #3bcd0ae4 cf767530 + 3873c997 955b2691 += 1.2299999999999999e-20 + 9.3040233185215211e-37 +ddI[1] == strtod + + +Input: 1.23456789e307 +strtopdd consumes 14 bytes and returns 33 +dd[0] = 1.2345678899999998e+307 = #7fb194b1 4bdaecdb +dd[1] = 2.0137933598720243e+291 = #7c69d48d 192048ca +g_ddfmt(0) gives 15 bytes: "1.23456789e+307" + +strtoIdd returns 33, consuming 14 bytes. +ddI[0] = #7fb194b1 4bdaecdb + 7c69d48d 192048c9 += 1.2345678899999998e+307 + 2.013793359872024e+291 +ddI[1] = #7fb194b1 4bdaecdb + 7c69d48d 192048ca += 1.2345678899999998e+307 + 2.0137933598720243e+291 +ddI[1] == strtod + + +Input: 1.23456589e-307 +strtopdd consumes 15 bytes and returns 80 +dd[0] = 0 = #0 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 1 bytes: "0" + +strtoIdd returns 80, consuming 15 bytes. +ddI[0] = #0 0 + 0 0 += 0 + 0 +ddI[1] = #6a00000 0 + 0 0 += 9.0259718793241479e-277 + 0 +ddI[0] == strtod + + +Input: 1.234567890123456789 +strtopdd consumes 20 bytes and returns 33 +dd[0] = 1.2345678901234567 = #3ff3c0ca 428c59fb +dd[1] = 9.856786452588859e-17 = #3c9c6906 51a3745e +g_ddfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIdd returns 33, consuming 20 bytes. +ddI[0] = #3ff3c0ca 428c59fb + 3c9c6906 51a3745c += 1.2345678901234567 + 9.8567864525888563e-17 +ddI[1] = #3ff3c0ca 428c59fb + 3c9c6906 51a3745e += 1.2345678901234567 + 9.8567864525888588e-17 +ddI[1] == strtod + + +Input: 1.234567890123456789e301 +strtopdd consumes 24 bytes and returns 33 +dd[0] = 1.2345678901234568e+301 = #7e726f51 75f56413 +dd[1] = 1.3892003943918827e+283 = #7ab7ea80 76399100 +g_ddfmt(0) gives 25 bytes: "1.234567890123456789e+301" + +strtoIdd returns 33, consuming 24 bytes. +ddI[0] = #7e726f51 75f56413 + 7ab7ea80 76399080 += 1.2345678901234568e+301 + 1.3892003943918563e+283 +ddI[1] = #7e726f51 75f56413 + 7ab7ea80 76399100 += 1.2345678901234568e+301 + 1.3892003943918827e+283 +ddI[1] == strtod + + +Input: 1.234567890123456789e-301 +strtopdd consumes 25 bytes and returns 80 +dd[0] = 0 = #0 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 1 bytes: "0" + +strtoIdd returns 80, consuming 25 bytes. +ddI[0] = #0 0 + 0 0 += 0 + 0 +ddI[1] = #6a00000 0 + 0 0 += 9.0259718793241479e-277 + 0 +ddI[0] == strtod + + +Input: 1.234567890123456789e-321 +strtopdd consumes 25 bytes and returns 80 +dd[0] = 0 = #0 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 1 bytes: "0" + +strtoIdd returns 80, consuming 25 bytes. +ddI[0] = #0 0 + 0 0 += 0 + 0 +ddI[1] = #6a00000 0 + 0 0 += 9.0259718793241479e-277 + 0 +ddI[0] == strtod + + +Input: 1e23 +strtopdd consumes 4 bytes and returns 1 +dd[0] = 1e+23 = #44b52d02 c7e14af6 +dd[1] = 8388608 = #41600000 0 +g_ddfmt(0) gives 5 bytes: "1e+23" + +strtoIdd returns 1, consuming 4 bytes. +ddI[0] == ddI[1] == strtopdd + + +Input: 1e310 +strtopdd consumes 5 bytes and returns 163 +dd[0] = Infinity = #7ff00000 0 +dd[1] = Infinity = #7ff00000 0 +g_ddfmt(0) gives 8 bytes: "Infinity" + +strtoIdd returns 163, consuming 5 bytes. +ddI[0] = #7fefffff ffffffff + 7c9fffff ffffffff += 1.7976931348623157e+308 + 1.9958403095347196e+292 +ddI[1] = #7ff00000 0 + 7ff00000 0 += Infinity + Infinity +ddI[1] == strtod + + +Input: 9.0259718793241475e-277 +strtopdd consumes 23 bytes and returns 80 +dd[0] = 0 = #0 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 1 bytes: "0" + +strtoIdd returns 80, consuming 23 bytes. +ddI[0] = #0 0 + 0 0 += 0 + 0 +ddI[1] = #6a00000 0 + 0 0 += 9.0259718793241479e-277 + 0 +ddI[0] == strtod + + +Input: 9.025971879324147880346310405869e-277 +strtopdd consumes 37 bytes and returns 17 +dd[0] = 9.025971879324148e-277 = #6a00000 0 +dd[1] = 2.2250738585072014e-308 = #100000 0 +g_ddfmt(0) gives 37 bytes: "9.025971879324147880346310405869e-277" + +strtoIdd returns 17, consuming 37 bytes. +ddI[0] = #6a00000 0 + 100000 0 += 9.0259718793241479e-277 + 2.2250738585072014e-308 +ddI[1] = #6a00000 0 + 200000 0 += 9.0259718793241479e-277 + 4.4501477170144028e-308 +ddI[0] == strtod + + +Input: 9.025971879324147880346310405868e-277 +strtopdd consumes 37 bytes and returns 80 +dd[0] = 0 = #0 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 1 bytes: "0" + +strtoIdd returns 80, consuming 37 bytes. +ddI[0] = #0 0 + 0 0 += 0 + 0 +ddI[1] = #6a00000 0 + 0 0 += 9.0259718793241479e-277 + 0 +ddI[0] == strtod + + +Input: 2.2250738585072014e-308 +strtopdd consumes 23 bytes and returns 80 +dd[0] = 0 = #0 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 1 bytes: "0" + +strtoIdd returns 80, consuming 23 bytes. +ddI[0] = #0 0 + 0 0 += 0 + 0 +ddI[1] = #6a00000 0 + 0 0 += 9.0259718793241479e-277 + 0 +ddI[0] == strtod + + +Input: 2.2250738585072013e-308 +strtopdd consumes 23 bytes and returns 80 +dd[0] = 0 = #0 0 +dd[1] = 0 = #0 0 +g_ddfmt(0) gives 1 bytes: "0" + +strtoIdd returns 80, consuming 23 bytes. +ddI[0] = #0 0 + 0 0 += 0 + 0 +ddI[1] = #6a00000 0 + 0 0 += 9.0259718793241479e-277 + 0 +ddI[0] == strtod + diff --git a/lib/libc/gdtoa/test/ddtest.c b/lib/libc/gdtoa/test/ddtest.c new file mode 100644 index 000000000..2cf31524a --- /dev/null +++ b/lib/libc/gdtoa/test/ddtest.c @@ -0,0 +1,177 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998-2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +/* Test program for g_ddfmt, strtoIdd, strtopdd, and strtordd. + * + * Inputs (on stdin): + * r rounding_mode + * n ndig + * number + * #hex0 hex1 hex2 hex3 + * + * rounding_mode values: + * 0 = toward zero + * 1 = nearest + * 2 = toward +Infinity + * 3 = toward -Infinity + * + * where number is a decimal floating-point number, + * hex0 is a string of <= 8 Hex digits for the most significant + * word of the number, hex1 is a similar string for the next + * word, etc., and ndig is a parameters to g_ddfmt. + */ + +#include "gdtoaimp.h" +#include +#include + + extern int getround ANSI((int,char*)); + + static char ibuf[2048], obuf[1024]; + +#define U (unsigned long) + + static void +#ifdef KR_headers +dprint(what, d) char *what; double d; +#else +dprint(char *what, double d) +#endif +{ + char buf[32]; + union { double d; ULong L[2]; } u; + + u.d = d; + g_dfmt(buf,&d,0,sizeof(buf)); + printf("%s = %s = #%lx %lx\n", what, buf, U u.L[_0], U u.L[_1]); + } + + int +main(Void) +{ + char *s, *s1, *se, *se1; + int dItry, i, j, r = 1, ndig = 0; + double ddI[4]; + long LL[4]; + union { double dd[2]; ULong L[4]; } u; + + while( (s = fgets(ibuf, sizeof(ibuf), stdin)) !=0) { + while(*s <= ' ') + if (!*s++) + continue; + dItry = 0; + switch(*s) { + case 'r': + r = getround(r, s); + continue; + case 'n': + i = s[1]; + if (i <= ' ' || (i >= '0' && i <= '9')) { + ndig = atoi(s+1); + continue; + } + break; /* nan? */ + case '#': + LL[0] = u.L[_0]; + LL[1] = u.L[_1]; + LL[2] = u.L[2+_0]; + LL[3] = u.L[2+_1]; + sscanf(s+1, "%lx %lx %lx %lx", &LL[0], &LL[1], + &LL[2], &LL[3]); + u.L[_0] = LL[0]; + u.L[_1] = LL[1]; + u.L[2+_0] = LL[2]; + u.L[2+_1] = LL[3]; + printf("\nInput: %s", ibuf); + printf(" --> f = #%lx %lx %lx %lx\n", + LL[0],LL[1],LL[2],LL[3]); + goto fmt_test; + } + printf("\nInput: %s", ibuf); + for(s1 = s; *s1 > ' '; s1++){}; + while(*s1 <= ' ' && *s1) s1++; + if (!*s1) { + dItry = 1; + i = strtordd(ibuf, &se, r, u.dd); + if (r == 1) { + j = strtopdd(ibuf, &se1, ddI); + if (i != j || u.dd[0] != ddI[0] + || u.dd[1] != ddI[1] || se != se1) + printf("***strtopdd and strtordd disagree!!\n:"); + } + printf("strtopdd consumes %d bytes and returns %d\n", + (int)(se-ibuf), i); + } + else { + u.dd[0] = strtod(s, &se); + u.dd[1] = strtod(se, &se); + } + fmt_test: + dprint("dd[0]", u.dd[0]); + dprint("dd[1]", u.dd[1]); + se = g_ddfmt(obuf, u.dd, ndig, sizeof(obuf)); + printf("g_ddfmt(%d) gives %d bytes: \"%s\"\n\n", + ndig, (int)(se-obuf), se ? obuf : ""); + if (!dItry) + continue; + printf("strtoIdd returns %d,", strtoIdd(ibuf, &se, ddI,&ddI[2])); + printf(" consuming %d bytes.\n", (int)(se-ibuf)); + if (ddI[0] == ddI[2] && ddI[1] == ddI[3]) { + if (ddI[0] == u.dd[0] && ddI[1] == u.dd[1]) + printf("ddI[0] == ddI[1] == strtopdd\n"); + else + printf("ddI[0] == ddI[1] = #%lx %lx + %lx %lx\n= %.17g + %17.g\n", + U ((ULong*)ddI)[_0], + U ((ULong*)ddI)[_1], + U ((ULong*)ddI)[2+_0], + U ((ULong*)ddI)[2+_1], + ddI[0], ddI[1]); + } + else { + printf("ddI[0] = #%lx %lx + %lx %lx\n= %.17g + %.17g\n", + U ((ULong*)ddI)[_0], U ((ULong*)ddI)[_1], + U ((ULong*)ddI)[2+_0], U ((ULong*)ddI)[2+_1], + ddI[0], ddI[1]); + printf("ddI[1] = #%lx %lx + %lx %lx\n= %.17g + %.17g\n", + U ((ULong*)ddI)[4+_0], U ((ULong*)ddI)[4+_1], + U ((ULong*)ddI)[6+_0], U ((ULong*)ddI)[6+_1], + ddI[2], ddI[3]); + if (ddI[0] == u.dd[0] && ddI[1] == u.dd[1]) + printf("ddI[0] == strtod\n"); + else if (ddI[2] == u.dd[0] && ddI[3] == u.dd[1]) + printf("ddI[1] == strtod\n"); + else + printf("**** Both differ from strtopdd ****\n"); + } + printf("\n"); + } + return 0; + } diff --git a/lib/libc/gdtoa/test/dt.c b/lib/libc/gdtoa/test/dt.c new file mode 100644 index 000000000..355476ff2 --- /dev/null +++ b/lib/libc/gdtoa/test/dt.c @@ -0,0 +1,291 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +/* Test program for strtod and dtoa. + * + * Inputs (on stdin): + * number[: mode [ndigits]] + * or + * #hex0 hex1[: mode [ndigits]] + * where number is a decimal floating-point number, + * hex0 is a string of Hex digits for the most significant + * word of the number, hex1 is a similar string for the other + * (least significant) word, and mode and ndigits are + * parameters to dtoa. + */ + +#include +#include "gdtoa.h" +int STRTOD_DIGLIM = 24; +#ifdef KR_headers +#define Void /*void*/ +#else +#define Void void +#endif + +#ifdef __STDC__ +#include +#else +#ifdef __cplusplus +extern "C" double atof(const char*); +#else +extern double atof ANSI((char*)); +#endif +#endif + +typedef union { double d; ULong L[2]; } U; + +#ifdef IEEE_8087 +#define word0(x) (x)->L[1] +#define word1(x) (x)->L[0] +#else +#define word0(x) (x)->L[0] +#define word1(x) (x)->L[1] +#endif +#define dval(x) (x)->d + +#include "errno.h" + +#ifdef __cplusplus +extern "C" char *dtoa(double, int, int, int*, int*, char **); +#else +extern char *dtoa ANSI((double, int, int, int*, int*, char **)); +#endif + + static void +#ifdef KR_headers +g_fmt(b, x) char *b; double x; +#else +g_fmt(char *b, double x) +#endif +{ + char *s, *se; + int decpt, i, j, k, sign; + + if (!x) { + *b++ = '0'; + *b = 0; + return; + } + s = dtoa(x, 0, 0, &decpt, &sign, &se); + if (sign) + *b++ = '-'; + if (decpt == 9999) /* Infinity or Nan */ { + while((*b++ = *s++)); + return; + } + if (decpt <= -4 || decpt > se - s + 5) { + *b++ = *s++; + if (*s) { + *b++ = '.'; + while((*b = *s++)) + b++; + } + *b++ = 'e'; + /* sprintf(b, "%+.2d", decpt - 1); */ + if (--decpt < 0) { + *b++ = '-'; + decpt = -decpt; + } + else + *b++ = '+'; + for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10){}; + for(;;) { + i = decpt / k; + *b++ = i + '0'; + if (--j <= 0) + break; + decpt -= i*k; + decpt *= 10; + } + *b = 0; + } + else if (decpt <= 0) { + *b++ = '.'; + for(; decpt < 0; decpt++) + *b++ = '0'; + while((*b++ = *s++)); + } + else { + while((*b = *s++)) { + b++; + if (--decpt == 0 && *s) + *b++ = '.'; + } + for(; decpt > 0; decpt--) + *b++ = '0'; + *b = 0; + } + } + + static void +baderrno(Void) +{ + fflush(stdout); + perror("\nerrno strtod"); + fflush(stderr); + } + +#define UL (unsigned long) + + static void +#ifdef KR_headers +check(d) U *d; +#else +check(U *d) +#endif +{ + char buf[64]; + int decpt, sign; + char *s, *se; + U d1; + + s = dtoa(dval(d), 0, 0, &decpt, &sign, &se); + sprintf(buf, "%s%s%se%d", sign ? "-" : "", + decpt == 9999 ? "" : ".", s, decpt); + errno = 0; + dval(&d1) = strtod(buf, (char **)0); + if (errno) + baderrno(); + if (dval(d) != dval(&d1)) { + printf("sent d = %.17g = 0x%lx %lx, buf = %s\n", + dval(d), UL word0(d), UL word1(d), buf); + printf("got d1 = %.17g = 0x%lx %lx\n", + dval(&d1), UL word0(&d1), UL word1(&d1)); + } + } + + int +main(Void) +{ + U d, d1; + char buf[2048], buf1[32]; + char *fmt, *s, *s1, *se; + int decpt, sign; + int mode = 0, ndigits = 17; + ULong x, y; +#ifdef VAX + ULong z; +#endif + + while(fgets(buf, sizeof(buf), stdin)) { + if (*buf == '*') { + printf("%s", buf); + continue; + } + printf("Input: %s", buf); + if (*buf == '#') { + x = word0(&d); + y = word1(&d); + /* sscanf(buf+1, "%lx %lx:%d %d", &x, &y, &mode, &ndigits); */ + x = (ULong)strtoul(s1 = buf+1, &se, 16); + if (se > s1) { + y = (ULong)strtoul(s1 = se, &se, 16); + if (se > s1) + sscanf(se, ":%d %d", &mode, &ndigits); + } + word0(&d) = x; + word1(&d) = y; + fmt = "Output: d =\n%.17g = 0x%lx %lx\n"; + } + else if (*buf == '*') { + x = strtoul(buf,&s,10); + if (!*s && x > 18) + STRTOD_DIGLIM = (int)x; + printf("STRTOD_DIGLIM = %lu\n", UL x); + continue; + } + else { + errno = 0; + dval(&d) = strtod(buf,&se); + if (*se == ':') + sscanf(se+1,"%d %d", &mode, &ndigits); + dval(&d1) = atof(buf); + fmt = "Output: d =\n%.17g = 0x%lx %lx, se = %s"; + if (errno) + baderrno(); + } + printf(fmt, dval(&d), UL word0(&d), UL word1(&d), se); + g_fmt(buf1, dval(&d)); + printf("\tg_fmt gives \"%s\"\n", buf1); + if (*buf != '#' && dval(&d) != dval(&d1)) + printf("atof gives\n\ + d1 = %.17g = 0x%lx %lx\nversus\n\ + d = %.17g = 0x%lx %lx\n", dval(&d1), UL word0(&d1), UL word1(&d1), + dval(&d), UL word0(&d), UL word1(&d)); + check(&d); + s = dtoa(dval(&d), mode, ndigits, &decpt, &sign, &se); + printf("\tdtoa(mode = %d, ndigits = %d):\n", mode, ndigits); + printf("\tdtoa returns sign = %d, decpt = %d, %d digits:\n%s\n", + sign, decpt, (int)(se-s), s); + x = word1(&d); + if (x != 0xffffffff + && (word0(&d) & 0x7ff00000) != 0x7ff00000) { +#ifdef VAX + z = x << 16 | x >> 16; + z++; + z = z << 16 | z >> 16; + word1(&d) = z; +#else + word1(&d) = x + 1; +#endif + printf("\tnextafter(d,+Inf) = %.17g = 0x%lx %lx:\n", + dval(&d), UL word0(&d), UL word1(&d)); + g_fmt(buf1, dval(&d)); + printf("\tg_fmt gives \"%s\"\n", buf1); + s = dtoa(dval(&d), mode, ndigits, &decpt, &sign, &se); + printf( + "\tdtoa returns sign = %d, decpt = %d, %d digits:\n%s\n", + sign, decpt, (int)(se-s), s); + check(&d); + } + if (x) { +#ifdef VAX + z = x << 16 | x >> 16; + z--; + z = z << 16 | z >> 16; + word1(&d) = z; +#else + word1(&d) = x - 1; +#endif + printf("\tnextafter(d,-Inf) = %.17g = 0x%lx %lx:\n", + dval(&d), UL word0(&d), UL word1(&d)); + g_fmt(buf1, dval(&d)); + printf("\tg_fmt gives \"%s\"\n", buf1); + s = dtoa(dval(&d), mode, ndigits, &decpt, &sign, &se); + printf( + "\tdtoa returns sign = %d, decpt = %d, %d digits:\n%s\n", + sign, decpt, (int)(se-s), s); + check(&d); + } + } + return 0; + } diff --git a/lib/libc/gdtoa/test/dtest.c b/lib/libc/gdtoa/test/dtest.c new file mode 100644 index 000000000..0140f2ed3 --- /dev/null +++ b/lib/libc/gdtoa/test/dtest.c @@ -0,0 +1,139 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998-2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +/* Test program for g_dfmt, strtoId, strtod, strtopd, and strtord. + * + * Inputs (on stdin): + * r rounding_mode + * n ndig + * number + * #hex0 hex1 + * + * rounding_mode values: + * 0 = toward zero + * 1 = nearest + * 2 = toward +Infinity + * 3 = toward -Infinity + * + * where number is a decimal floating-point number, + * hex0 is a string of Hex <= 8 digits for the most significant + * word of the number, hex1 is a similar string for the other + * (least significant) word, and ndig is a parameters to g_dfmt. + */ + +#include "gdtoaimp.h" +#include +#include + + extern int getround ANSI((int,char*)); + + static char ibuf[2048], obuf[1024]; + +#define U (unsigned long) + + int +main(Void) +{ + char *s, *se, *se1; + double f1, fI[2]; + int i, i1, ndig = 0, r = 1; + long LL[2]; + union { double f; ULong L[2]; } u; + + while( (s = fgets(ibuf, sizeof(ibuf), stdin)) !=0) { + while(*s <= ' ') + if (!*s++) + continue; + switch(*s) { + case 'r': + r = getround(r, s); + continue; + case 'n': + i = s[1]; + if (i <= ' ' || (i >= '0' && i <= '9')) { + ndig = atoi(s+1); + continue; + } + break; /* nan? */ + case '#': + LL[0] = u.L[_0]; + LL[1] = u.L[_1]; + sscanf(s+1, "%lx %lx", &LL[0], &LL[1]); + u.L[_0] = LL[0]; + u.L[_1] = LL[1]; + printf("\nInput: %s", ibuf); + printf("--> f = #%lx %lx\n", (long)u.L[_0], (long)u.L[_1]); + goto fmt_test; + } + printf("\nInput: %s", ibuf); + i = strtord(ibuf, &se, r, &u.f); + if (r == 1) { + if ((u.f != strtod(ibuf, &se1) || se1 != se)) + printf("***strtod and strtord disagree!!\n"); + i1 = strtopd(ibuf, &se, &f1); + if (i != i1 || u.f != f1 || se != se1) + printf("***strtord and strtopd disagree!!\n"); + } + printf("strtod consumes %d bytes and returns %d with f = %.17g = #%lx %lx\n", + (int)(se-ibuf), i, u.f, U u.L[_0], U u.L[_1]); + fmt_test: + se = g_dfmt(obuf, &u.f, ndig, sizeof(obuf)); + printf("g_dfmt(%d) gives %d bytes: \"%s\"\n\n", + ndig, (int)(se-obuf), se ? obuf : ""); + if (*s == '#') + continue; + printf("strtoId returns %d,", strtoId(ibuf, &se, fI, &fI[1])); + printf(" consuming %d bytes.\n", (int)(se-ibuf)); + if (fI[0] == fI[1]) { + if (fI[0] == u.f) + printf("fI[0] == fI[1] == strtod\n"); + else + printf("fI[0] == fI[1] = #%lx %lx = %.17g\n", + U ((ULong*)fI)[_0], U ((ULong*)fI)[_1], + fI[0]); + } + else { + printf("fI[0] = #%lx %lx = %.17g\n", + U ((ULong*)fI)[_0], U ((ULong*)fI)[_1], fI[0]); + printf("fI[1] = #%lx %lx = %.17g\n", + U ((ULong*)&fI[1])[_0], U ((ULong*)&fI[1])[_1], + fI[1]); + if (fI[0] == u.f) + printf("fI[0] == strtod\n"); + else if (fI[1] == u.f) + printf("fI[1] == strtod\n"); + else + printf("**** Both differ from strtod ****\n"); + } + printf("\n"); + } + return 0; + } diff --git a/lib/libc/gdtoa/test/dtst.out b/lib/libc/gdtoa/test/dtst.out new file mode 100644 index 000000000..7b7a09a60 --- /dev/null +++ b/lib/libc/gdtoa/test/dtst.out @@ -0,0 +1,684 @@ +Input: 1.23 +Output: d = +1.23 = 0x3ff3ae14 7ae147ae, se = + g_fmt gives "1.23" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 1, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002 = 0x3ff3ae14 7ae147af: + g_fmt gives "1.2300000000000002" + dtoa returns sign = 0, decpt = 1, 17 digits: +12300000000000002 + nextafter(d,-Infinity) = 1.2299999999999998 = 0x3ff3ae14 7ae147ad: + g_fmt gives "1.2299999999999998" + dtoa returns sign = 0, decpt = 1, 17 digits: +12299999999999998 +Input: 1.23e+20 +Output: d = +1.23e+20 = 0x441aabdf 2145b430, se = + g_fmt gives "1.23e+20" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 21, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002e+20 = 0x441aabdf 2145b431: + g_fmt gives "123000000000000020000" + dtoa returns sign = 0, decpt = 21, 17 digits: +12300000000000002 + nextafter(d,-Infinity) = 1.2299999999999998e+20 = 0x441aabdf 2145b42f: + g_fmt gives "122999999999999980000" + dtoa returns sign = 0, decpt = 21, 17 digits: +12299999999999998 +Input: 1.23e-20 +Output: d = +1.2300000000000001e-20 = 0x3bcd0ae4 cf767531, se = + g_fmt gives "1.23e-20" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -19, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002e-20 = 0x3bcd0ae4 cf767532: + g_fmt gives "1.2300000000000002e-20" + dtoa returns sign = 0, decpt = -19, 17 digits: +12300000000000002 + nextafter(d,-Infinity) = 1.2299999999999999e-20 = 0x3bcd0ae4 cf767530: + g_fmt gives "1.2299999999999999e-20" + dtoa returns sign = 0, decpt = -19, 17 digits: +12299999999999999 +Input: 1.23456789 +Output: d = +1.2345678899999999 = 0x3ff3c0ca 4283de1b, se = + g_fmt gives "1.23456789" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 1, 9 digits: +123456789 + nextafter(d,+Infinity) = 1.2345678900000001 = 0x3ff3c0ca 4283de1c: + g_fmt gives "1.2345678900000001" + dtoa returns sign = 0, decpt = 1, 17 digits: +12345678900000001 + nextafter(d,-Infinity) = 1.2345678899999997 = 0x3ff3c0ca 4283de1a: + g_fmt gives "1.2345678899999997" + dtoa returns sign = 0, decpt = 1, 17 digits: +12345678899999997 +Input: 1.23456589e+20 +Output: d = +1.23456589e+20 = 0x441ac537 a660b997, se = + g_fmt gives "1.23456589e+20" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 21, 9 digits: +123456589 + nextafter(d,+Infinity) = 1.2345658900000001e+20 = 0x441ac537 a660b998: + g_fmt gives "123456589000000010000" + dtoa returns sign = 0, decpt = 21, 17 digits: +12345658900000001 + nextafter(d,-Infinity) = 1.2345658899999998e+20 = 0x441ac537 a660b996: + g_fmt gives "123456588999999980000" + dtoa returns sign = 0, decpt = 21, 17 digits: +12345658899999998 +Input: 1.23e+30 +Output: d = +1.23e+30 = 0x462f0cb0 4e8fb790, se = + g_fmt gives "1.23e+30" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 31, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000001e+30 = 0x462f0cb0 4e8fb791: + g_fmt gives "1.2300000000000001e+30" + dtoa returns sign = 0, decpt = 31, 17 digits: +12300000000000001 + nextafter(d,-Infinity) = 1.2299999999999998e+30 = 0x462f0cb0 4e8fb78f: + g_fmt gives "1.2299999999999998e+30" + dtoa returns sign = 0, decpt = 31, 17 digits: +12299999999999998 +Input: 1.23e-30 +Output: d = +1.2300000000000001e-30 = 0x39b8f286 6f5010ab, se = + g_fmt gives "1.23e-30" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -29, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002e-30 = 0x39b8f286 6f5010ac: + g_fmt gives "1.2300000000000002e-30" + dtoa returns sign = 0, decpt = -29, 17 digits: +12300000000000002 + nextafter(d,-Infinity) = 1.2299999999999999e-30 = 0x39b8f286 6f5010aa: + g_fmt gives "1.2299999999999999e-30" + dtoa returns sign = 0, decpt = -29, 17 digits: +12299999999999999 +Input: 1.23456789e-20 +Output: d = +1.2345678899999999e-20 = 0x3bcd2681 471e7ada, se = + g_fmt gives "1.23456789e-20" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -19, 9 digits: +123456789 + nextafter(d,+Infinity) = 1.2345678900000001e-20 = 0x3bcd2681 471e7adb: + g_fmt gives "1.2345678900000001e-20" + dtoa returns sign = 0, decpt = -19, 17 digits: +12345678900000001 + nextafter(d,-Infinity) = 1.2345678899999998e-20 = 0x3bcd2681 471e7ad9: + g_fmt gives "1.2345678899999998e-20" + dtoa returns sign = 0, decpt = -19, 17 digits: +12345678899999998 +Input: 1.23456789e-30 +Output: d = +1.23456789e-30 = 0x39b90a3e 33bbd995, se = + g_fmt gives "1.23456789e-30" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -29, 9 digits: +123456789 + nextafter(d,+Infinity) = 1.2345678900000002e-30 = 0x39b90a3e 33bbd996: + g_fmt gives "1.2345678900000002e-30" + dtoa returns sign = 0, decpt = -29, 17 digits: +12345678900000002 + nextafter(d,-Infinity) = 1.2345678899999998e-30 = 0x39b90a3e 33bbd994: + g_fmt gives "1.2345678899999998e-30" + dtoa returns sign = 0, decpt = -29, 17 digits: +12345678899999998 +Input: 1.234567890123456789 +Output: d = +1.2345678901234567 = 0x3ff3c0ca 428c59fb, se = + g_fmt gives "1.2345678901234567" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 1, 17 digits: +12345678901234567 + nextafter(d,+Infinity) = 1.2345678901234569 = 0x3ff3c0ca 428c59fc: + g_fmt gives "1.234567890123457" + dtoa returns sign = 0, decpt = 1, 16 digits: +1234567890123457 + nextafter(d,-Infinity) = 1.2345678901234565 = 0x3ff3c0ca 428c59fa: + g_fmt gives "1.2345678901234565" + dtoa returns sign = 0, decpt = 1, 17 digits: +12345678901234565 +Input: 1.23456789012345678901234567890123456789 +Output: d = +1.2345678901234567 = 0x3ff3c0ca 428c59fb, se = + g_fmt gives "1.2345678901234567" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 1, 17 digits: +12345678901234567 + nextafter(d,+Infinity) = 1.2345678901234569 = 0x3ff3c0ca 428c59fc: + g_fmt gives "1.234567890123457" + dtoa returns sign = 0, decpt = 1, 16 digits: +1234567890123457 + nextafter(d,-Infinity) = 1.2345678901234565 = 0x3ff3c0ca 428c59fa: + g_fmt gives "1.2345678901234565" + dtoa returns sign = 0, decpt = 1, 17 digits: +12345678901234565 +Input: 1.23e306 +Output: d = +1.23e+306 = 0x7f7c0676 cd1c61f5, se = + g_fmt gives "1.23e+306" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 307, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002e+306 = 0x7f7c0676 cd1c61f6: + g_fmt gives "1.2300000000000002e+306" + dtoa returns sign = 0, decpt = 307, 17 digits: +12300000000000002 + nextafter(d,-Infinity) = 1.2299999999999999e+306 = 0x7f7c0676 cd1c61f4: + g_fmt gives "1.2299999999999999e+306" + dtoa returns sign = 0, decpt = 307, 17 digits: +12299999999999999 +Input: 1.23e-306 +Output: d = +1.23e-306 = 0x6ba3b8 5da396e8, se = + g_fmt gives "1.23e-306" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -305, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002e-306 = 0x6ba3b8 5da396e9: + g_fmt gives "1.2300000000000002e-306" + dtoa returns sign = 0, decpt = -305, 17 digits: +12300000000000002 + nextafter(d,-Infinity) = 1.2299999999999999e-306 = 0x6ba3b8 5da396e7: + g_fmt gives "1.2299999999999999e-306" + dtoa returns sign = 0, decpt = -305, 17 digits: +12299999999999999 +Input: 1.23e-320 +Output: d = +1.2302234581447039e-320 = 0x0 9ba, se = + g_fmt gives "1.23e-320" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -319, 3 digits: +123 + nextafter(d,+Infinity) = 1.2307175237905451e-320 = 0x0 9bb: + g_fmt gives "1.2307e-320" + dtoa returns sign = 0, decpt = -319, 5 digits: +12307 + nextafter(d,-Infinity) = 1.2297293924988626e-320 = 0x0 9b9: + g_fmt gives "1.2297e-320" + dtoa returns sign = 0, decpt = -319, 5 digits: +12297 +Input: 1.23e-20 +Output: d = +1.2300000000000001e-20 = 0x3bcd0ae4 cf767531, se = + g_fmt gives "1.23e-20" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -19, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002e-20 = 0x3bcd0ae4 cf767532: + g_fmt gives "1.2300000000000002e-20" + dtoa returns sign = 0, decpt = -19, 17 digits: +12300000000000002 + nextafter(d,-Infinity) = 1.2299999999999999e-20 = 0x3bcd0ae4 cf767530: + g_fmt gives "1.2299999999999999e-20" + dtoa returns sign = 0, decpt = -19, 17 digits: +12299999999999999 +Input: 1.23456789e307 +Output: d = +1.23456789e+307 = 0x7fb194b1 4bdaecdc, se = + g_fmt gives "1.23456789e+307" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 308, 9 digits: +123456789 + nextafter(d,+Infinity) = 1.2345678900000003e+307 = 0x7fb194b1 4bdaecdd: + g_fmt gives "1.2345678900000003e+307" + dtoa returns sign = 0, decpt = 308, 17 digits: +12345678900000003 + nextafter(d,-Infinity) = 1.2345678899999998e+307 = 0x7fb194b1 4bdaecdb: + g_fmt gives "1.2345678899999998e+307" + dtoa returns sign = 0, decpt = 308, 17 digits: +12345678899999998 +Input: 1.23456589e-307 +Output: d = +1.2345658899999999e-307 = 0x363196 bb9845fa, se = + g_fmt gives "1.23456589e-307" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -306, 9 digits: +123456589 + nextafter(d,+Infinity) = 1.2345658900000001e-307 = 0x363196 bb9845fb: + g_fmt gives "1.2345658900000001e-307" + dtoa returns sign = 0, decpt = -306, 17 digits: +12345658900000001 + nextafter(d,-Infinity) = 1.2345658899999997e-307 = 0x363196 bb9845f9: + g_fmt gives "1.2345658899999997e-307" + dtoa returns sign = 0, decpt = -306, 17 digits: +12345658899999997 +Input: 1.234567890123456789 +Output: d = +1.2345678901234567 = 0x3ff3c0ca 428c59fb, se = + g_fmt gives "1.2345678901234567" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 1, 17 digits: +12345678901234567 + nextafter(d,+Infinity) = 1.2345678901234569 = 0x3ff3c0ca 428c59fc: + g_fmt gives "1.234567890123457" + dtoa returns sign = 0, decpt = 1, 16 digits: +1234567890123457 + nextafter(d,-Infinity) = 1.2345678901234565 = 0x3ff3c0ca 428c59fa: + g_fmt gives "1.2345678901234565" + dtoa returns sign = 0, decpt = 1, 17 digits: +12345678901234565 +Input: 1.234567890123456789e301 +Output: d = +1.2345678901234568e+301 = 0x7e726f51 75f56413, se = + g_fmt gives "1.2345678901234568e+301" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 302, 17 digits: +12345678901234568 + nextafter(d,+Infinity) = 1.234567890123457e+301 = 0x7e726f51 75f56414: + g_fmt gives "1.234567890123457e+301" + dtoa returns sign = 0, decpt = 302, 16 digits: +1234567890123457 + nextafter(d,-Infinity) = 1.2345678901234565e+301 = 0x7e726f51 75f56412: + g_fmt gives "1.2345678901234565e+301" + dtoa returns sign = 0, decpt = 302, 17 digits: +12345678901234565 +Input: 1.234567890123456789e-301 +Output: d = +1.2345678901234567e-301 = 0x1752a64 e34ba0d3, se = + g_fmt gives "1.2345678901234567e-301" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -300, 17 digits: +12345678901234567 + nextafter(d,+Infinity) = 1.2345678901234569e-301 = 0x1752a64 e34ba0d4: + g_fmt gives "1.234567890123457e-301" + dtoa returns sign = 0, decpt = -300, 16 digits: +1234567890123457 + nextafter(d,-Infinity) = 1.2345678901234565e-301 = 0x1752a64 e34ba0d2: + g_fmt gives "1.2345678901234565e-301" + dtoa returns sign = 0, decpt = -300, 17 digits: +12345678901234565 +Input: 1.234567890123456789e-321 +Output: d = +1.2351641146031164e-321 = 0x0 fa, se = + g_fmt gives "1.235e-321" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -320, 4 digits: +1235 + nextafter(d,+Infinity) = 1.2401047710615288e-321 = 0x0 fb: + g_fmt gives "1.24e-321" + dtoa returns sign = 0, decpt = -320, 3 digits: +124 + nextafter(d,-Infinity) = 1.2302234581447039e-321 = 0x0 f9: + g_fmt gives "1.23e-321" + dtoa returns sign = 0, decpt = -320, 3 digits: +123 +Input: 1e23 +Output: d = +9.9999999999999992e+22 = 0x44b52d02 c7e14af6, se = + g_fmt gives "1e+23" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 24, 1 digits: +1 + nextafter(d,+Infinity) = 1.0000000000000001e+23 = 0x44b52d02 c7e14af7: + g_fmt gives "1.0000000000000001e+23" + dtoa returns sign = 0, decpt = 24, 17 digits: +10000000000000001 + nextafter(d,-Infinity) = 9.9999999999999975e+22 = 0x44b52d02 c7e14af5: + g_fmt gives "9.999999999999997e+22" + dtoa returns sign = 0, decpt = 23, 16 digits: +9999999999999997 +Input: 1e310 +Output: d = +Infinity = 0x7ff00000 0, se = + g_fmt gives "Infinity" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = 9999, 8 digits: +Infinity +Input: 9.0259718793241475e-277 +Output: d = +9.0259718793241479e-277 = 0x6a00000 0, se = + g_fmt gives "9.025971879324148e-277" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -276, 16 digits: +9025971879324148 + nextafter(d,+Infinity) = 9.0259718793241499e-277 = 0x6a00000 1: + g_fmt gives "9.02597187932415e-277" + dtoa returns sign = 0, decpt = -276, 15 digits: +902597187932415 +Input: 9.025971879324147880346310405869e-277 +Output: d = +9.0259718793241479e-277 = 0x6a00000 0, se = + g_fmt gives "9.025971879324148e-277" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -276, 16 digits: +9025971879324148 + nextafter(d,+Infinity) = 9.0259718793241499e-277 = 0x6a00000 1: + g_fmt gives "9.02597187932415e-277" + dtoa returns sign = 0, decpt = -276, 15 digits: +902597187932415 +Input: 9.025971879324147880346310405868e-277 +Output: d = +9.0259718793241479e-277 = 0x6a00000 0, se = + g_fmt gives "9.025971879324148e-277" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -276, 16 digits: +9025971879324148 + nextafter(d,+Infinity) = 9.0259718793241499e-277 = 0x6a00000 1: + g_fmt gives "9.02597187932415e-277" + dtoa returns sign = 0, decpt = -276, 15 digits: +902597187932415 +Input: 2.2250738585072014e-308 +Output: d = +2.2250738585072014e-308 = 0x100000 0, se = + g_fmt gives "2.2250738585072014e-308" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -307, 17 digits: +22250738585072014 + nextafter(d,+Infinity) = 2.2250738585072019e-308 = 0x100000 1: + g_fmt gives "2.225073858507202e-308" + dtoa returns sign = 0, decpt = -307, 16 digits: +2225073858507202 +Input: 2.2250738585072013e-308 +Output: d = +2.2250738585072014e-308 = 0x100000 0, se = + g_fmt gives "2.2250738585072014e-308" + dtoa(mode = 0, ndigits = 17): + dtoa returns sign = 0, decpt = -307, 17 digits: +22250738585072014 + nextafter(d,+Infinity) = 2.2250738585072019e-308 = 0x100000 1: + g_fmt gives "2.225073858507202e-308" + dtoa returns sign = 0, decpt = -307, 16 digits: +2225073858507202 +Input: 1.23:2 6 +Output: d = +1.23 = 0x3ff3ae14 7ae147ae, se = :2 6 + g_fmt gives "1.23" + dtoa(mode = 2, ndigits = 6): + dtoa returns sign = 0, decpt = 1, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002 = 0x3ff3ae14 7ae147af: + g_fmt gives "1.2300000000000002" + dtoa returns sign = 0, decpt = 1, 3 digits: +123 + nextafter(d,-Infinity) = 1.2299999999999998 = 0x3ff3ae14 7ae147ad: + g_fmt gives "1.2299999999999998" + dtoa returns sign = 0, decpt = 1, 3 digits: +123 +Input: 1.23:4 6 +Output: d = +1.23 = 0x3ff3ae14 7ae147ae, se = :4 6 + g_fmt gives "1.23" + dtoa(mode = 4, ndigits = 6): + dtoa returns sign = 0, decpt = 1, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002 = 0x3ff3ae14 7ae147af: + g_fmt gives "1.2300000000000002" + dtoa returns sign = 0, decpt = 1, 3 digits: +123 + nextafter(d,-Infinity) = 1.2299999999999998 = 0x3ff3ae14 7ae147ad: + g_fmt gives "1.2299999999999998" + dtoa returns sign = 0, decpt = 1, 3 digits: +123 +Input: 1.23e+20:2 6 +Output: d = +1.23e+20 = 0x441aabdf 2145b430, se = :2 6 + g_fmt gives "1.23e+20" + dtoa(mode = 2, ndigits = 6): + dtoa returns sign = 0, decpt = 21, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002e+20 = 0x441aabdf 2145b431: + g_fmt gives "123000000000000020000" + dtoa returns sign = 0, decpt = 21, 3 digits: +123 + nextafter(d,-Infinity) = 1.2299999999999998e+20 = 0x441aabdf 2145b42f: + g_fmt gives "122999999999999980000" + dtoa returns sign = 0, decpt = 21, 3 digits: +123 +Input: 1.23e+20:4 6 +Output: d = +1.23e+20 = 0x441aabdf 2145b430, se = :4 6 + g_fmt gives "1.23e+20" + dtoa(mode = 4, ndigits = 6): + dtoa returns sign = 0, decpt = 21, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002e+20 = 0x441aabdf 2145b431: + g_fmt gives "123000000000000020000" + dtoa returns sign = 0, decpt = 21, 3 digits: +123 + nextafter(d,-Infinity) = 1.2299999999999998e+20 = 0x441aabdf 2145b42f: + g_fmt gives "122999999999999980000" + dtoa returns sign = 0, decpt = 21, 3 digits: +123 +Input: 1.23e-20:2 6 +Output: d = +1.2300000000000001e-20 = 0x3bcd0ae4 cf767531, se = :2 6 + g_fmt gives "1.23e-20" + dtoa(mode = 2, ndigits = 6): + dtoa returns sign = 0, decpt = -19, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002e-20 = 0x3bcd0ae4 cf767532: + g_fmt gives "1.2300000000000002e-20" + dtoa returns sign = 0, decpt = -19, 3 digits: +123 + nextafter(d,-Infinity) = 1.2299999999999999e-20 = 0x3bcd0ae4 cf767530: + g_fmt gives "1.2299999999999999e-20" + dtoa returns sign = 0, decpt = -19, 3 digits: +123 +Input: 1.23e-20:4 6 +Output: d = +1.2300000000000001e-20 = 0x3bcd0ae4 cf767531, se = :4 6 + g_fmt gives "1.23e-20" + dtoa(mode = 4, ndigits = 6): + dtoa returns sign = 0, decpt = -19, 3 digits: +123 + nextafter(d,+Infinity) = 1.2300000000000002e-20 = 0x3bcd0ae4 cf767532: + g_fmt gives "1.2300000000000002e-20" + dtoa returns sign = 0, decpt = -19, 3 digits: +123 + nextafter(d,-Infinity) = 1.2299999999999999e-20 = 0x3bcd0ae4 cf767530: + g_fmt gives "1.2299999999999999e-20" + dtoa returns sign = 0, decpt = -19, 3 digits: +123 +Input: 1.23456789:2 6 +Output: d = +1.2345678899999999 = 0x3ff3c0ca 4283de1b, se = :2 6 + g_fmt gives "1.23456789" + dtoa(mode = 2, ndigits = 6): + dtoa returns sign = 0, decpt = 1, 6 digits: +123457 + nextafter(d,+Infinity) = 1.2345678900000001 = 0x3ff3c0ca 4283de1c: + g_fmt gives "1.2345678900000001" + dtoa returns sign = 0, decpt = 1, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345678899999997 = 0x3ff3c0ca 4283de1a: + g_fmt gives "1.2345678899999997" + dtoa returns sign = 0, decpt = 1, 6 digits: +123457 +Input: 1.23456789:4 6 +Output: d = +1.2345678899999999 = 0x3ff3c0ca 4283de1b, se = :4 6 + g_fmt gives "1.23456789" + dtoa(mode = 4, ndigits = 6): + dtoa returns sign = 0, decpt = 1, 6 digits: +123457 + nextafter(d,+Infinity) = 1.2345678900000001 = 0x3ff3c0ca 4283de1c: + g_fmt gives "1.2345678900000001" + dtoa returns sign = 0, decpt = 1, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345678899999997 = 0x3ff3c0ca 4283de1a: + g_fmt gives "1.2345678899999997" + dtoa returns sign = 0, decpt = 1, 6 digits: +123457 +Input: 1.23456589e+20:2 6 +Output: d = +1.23456589e+20 = 0x441ac537 a660b997, se = :2 6 + g_fmt gives "1.23456589e+20" + dtoa(mode = 2, ndigits = 6): + dtoa returns sign = 0, decpt = 21, 6 digits: +123457 + nextafter(d,+Infinity) = 1.2345658900000001e+20 = 0x441ac537 a660b998: + g_fmt gives "123456589000000010000" + dtoa returns sign = 0, decpt = 21, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345658899999998e+20 = 0x441ac537 a660b996: + g_fmt gives "123456588999999980000" + dtoa returns sign = 0, decpt = 21, 6 digits: +123457 +Input: 1.23456589e+20:4 6 +Output: d = +1.23456589e+20 = 0x441ac537 a660b997, se = :4 6 + g_fmt gives "1.23456589e+20" + dtoa(mode = 4, ndigits = 6): + dtoa returns sign = 0, decpt = 21, 6 digits: +123457 + nextafter(d,+Infinity) = 1.2345658900000001e+20 = 0x441ac537 a660b998: + g_fmt gives "123456589000000010000" + dtoa returns sign = 0, decpt = 21, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345658899999998e+20 = 0x441ac537 a660b996: + g_fmt gives "123456588999999980000" + dtoa returns sign = 0, decpt = 21, 6 digits: +123457 +Input: 1.23456789e-20:2 6 +Output: d = +1.2345678899999999e-20 = 0x3bcd2681 471e7ada, se = :2 6 + g_fmt gives "1.23456789e-20" + dtoa(mode = 2, ndigits = 6): + dtoa returns sign = 0, decpt = -19, 6 digits: +123457 + nextafter(d,+Infinity) = 1.2345678900000001e-20 = 0x3bcd2681 471e7adb: + g_fmt gives "1.2345678900000001e-20" + dtoa returns sign = 0, decpt = -19, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345678899999998e-20 = 0x3bcd2681 471e7ad9: + g_fmt gives "1.2345678899999998e-20" + dtoa returns sign = 0, decpt = -19, 6 digits: +123457 +Input: 1.23456789e-20:4 6 +Output: d = +1.2345678899999999e-20 = 0x3bcd2681 471e7ada, se = :4 6 + g_fmt gives "1.23456789e-20" + dtoa(mode = 4, ndigits = 6): + dtoa returns sign = 0, decpt = -19, 6 digits: +123457 + nextafter(d,+Infinity) = 1.2345678900000001e-20 = 0x3bcd2681 471e7adb: + g_fmt gives "1.2345678900000001e-20" + dtoa returns sign = 0, decpt = -19, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345678899999998e-20 = 0x3bcd2681 471e7ad9: + g_fmt gives "1.2345678899999998e-20" + dtoa returns sign = 0, decpt = -19, 6 digits: +123457 +Input: 1234565:2 6 +Output: d = +1234565 = 0x4132d685 0, se = :2 6 + g_fmt gives "1234565" + dtoa(mode = 2, ndigits = 6): + dtoa returns sign = 0, decpt = 7, 6 digits: +123456 + nextafter(d,+Infinity) = 1234565.0000000002 = 0x4132d685 1: + g_fmt gives "1234565.0000000002" + dtoa returns sign = 0, decpt = 7, 6 digits: +123457 +Input: 1234565:4 6 +Output: d = +1234565 = 0x4132d685 0, se = :4 6 + g_fmt gives "1234565" + dtoa(mode = 4, ndigits = 6): + dtoa returns sign = 0, decpt = 7, 6 digits: +123456 + nextafter(d,+Infinity) = 1234565.0000000002 = 0x4132d685 1: + g_fmt gives "1234565.0000000002" + dtoa returns sign = 0, decpt = 7, 6 digits: +123457 +Input: 1.234565:2 6 +Output: d = +1.2345649999999999 = 0x3ff3c0c7 3abc9470, se = :2 6 + g_fmt gives "1.234565" + dtoa(mode = 2, ndigits = 6): + dtoa returns sign = 0, decpt = 1, 6 digits: +123456 + nextafter(d,+Infinity) = 1.2345650000000001 = 0x3ff3c0c7 3abc9471: + g_fmt gives "1.2345650000000001" + dtoa returns sign = 0, decpt = 1, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345649999999997 = 0x3ff3c0c7 3abc946f: + g_fmt gives "1.2345649999999997" + dtoa returns sign = 0, decpt = 1, 6 digits: +123456 +Input: 1.234565:4 6 +Output: d = +1.2345649999999999 = 0x3ff3c0c7 3abc9470, se = :4 6 + g_fmt gives "1.234565" + dtoa(mode = 4, ndigits = 6): + dtoa returns sign = 0, decpt = 1, 6 digits: +123456 + nextafter(d,+Infinity) = 1.2345650000000001 = 0x3ff3c0c7 3abc9471: + g_fmt gives "1.2345650000000001" + dtoa returns sign = 0, decpt = 1, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345649999999997 = 0x3ff3c0c7 3abc946f: + g_fmt gives "1.2345649999999997" + dtoa returns sign = 0, decpt = 1, 6 digits: +123456 +Input: 1.234565e+20:2 6 +Output: d = +1.234565e+20 = 0x441ac536 6299040d, se = :2 6 + g_fmt gives "1.234565e+20" + dtoa(mode = 2, ndigits = 6): + dtoa returns sign = 0, decpt = 21, 6 digits: +123456 + nextafter(d,+Infinity) = 1.2345650000000002e+20 = 0x441ac536 6299040e: + g_fmt gives "123456500000000020000" + dtoa returns sign = 0, decpt = 21, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345649999999998e+20 = 0x441ac536 6299040c: + g_fmt gives "123456499999999980000" + dtoa returns sign = 0, decpt = 21, 6 digits: +123456 +Input: 1.234565e+20:4 6 +Output: d = +1.234565e+20 = 0x441ac536 6299040d, se = :4 6 + g_fmt gives "1.234565e+20" + dtoa(mode = 4, ndigits = 6): + dtoa returns sign = 0, decpt = 21, 6 digits: +123456 + nextafter(d,+Infinity) = 1.2345650000000002e+20 = 0x441ac536 6299040e: + g_fmt gives "123456500000000020000" + dtoa returns sign = 0, decpt = 21, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345649999999998e+20 = 0x441ac536 6299040c: + g_fmt gives "123456499999999980000" + dtoa returns sign = 0, decpt = 21, 6 digits: +123456 +Input: 1.234565e-20:2 6 +Output: d = +1.234565e-20 = 0x3bcd267c ce45a93f, se = :2 6 + g_fmt gives "1.234565e-20" + dtoa(mode = 2, ndigits = 6): + dtoa returns sign = 0, decpt = -19, 6 digits: +123456 + nextafter(d,+Infinity) = 1.2345650000000001e-20 = 0x3bcd267c ce45a940: + g_fmt gives "1.2345650000000001e-20" + dtoa returns sign = 0, decpt = -19, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345649999999998e-20 = 0x3bcd267c ce45a93e: + g_fmt gives "1.2345649999999998e-20" + dtoa returns sign = 0, decpt = -19, 6 digits: +123456 +Input: 1.234565e-20:4 6 +Output: d = +1.234565e-20 = 0x3bcd267c ce45a93f, se = :4 6 + g_fmt gives "1.234565e-20" + dtoa(mode = 4, ndigits = 6): + dtoa returns sign = 0, decpt = -19, 6 digits: +123456 + nextafter(d,+Infinity) = 1.2345650000000001e-20 = 0x3bcd267c ce45a940: + g_fmt gives "1.2345650000000001e-20" + dtoa returns sign = 0, decpt = -19, 6 digits: +123457 + nextafter(d,-Infinity) = 1.2345649999999998e-20 = 0x3bcd267c ce45a93e: + g_fmt gives "1.2345649999999998e-20" + dtoa returns sign = 0, decpt = -19, 6 digits: +123456 diff --git a/lib/libc/gdtoa/test/f.out b/lib/libc/gdtoa/test/f.out new file mode 100644 index 000000000..d82e4e6f9 --- /dev/null +++ b/lib/libc/gdtoa/test/f.out @@ -0,0 +1,988 @@ + +Input: 1.23 +strtof consumes 4 bytes and returns 1.23 = #3f9d70a4 +g_ffmt(0) gives 4 bytes: "1.23" + +strtoIf returns 33, consuming 4 bytes. +fI[0] = #3f9d70a3 = 1.2299999 +fI[1] = #3f9d70a4 = 1.23 +fI[1] == strtof + + +Input: 1.23e+20 +strtof consumes 8 bytes and returns 1.23e+20 = #60d55ef9 +g_ffmt(0) gives 8 bytes: "1.23e+20" + +strtoIf returns 17, consuming 8 bytes. +fI[0] = #60d55ef9 = 1.23e+20 +fI[1] = #60d55efa = 1.2300001e+20 +fI[0] == strtof + + +Input: 1.23e-20 +strtof consumes 8 bytes and returns 1.23e-20 = #1e685726 +g_ffmt(0) gives 8 bytes: "1.23e-20" + +strtoIf returns 17, consuming 8 bytes. +fI[0] = #1e685726 = 1.23e-20 +fI[1] = #1e685727 = 1.23e-20 +fI[0] == strtof + + +Input: 1.23456789 +strtof consumes 10 bytes and returns 1.2345679 = #3f9e0652 +g_ffmt(0) gives 9 bytes: "1.2345679" + +strtoIf returns 17, consuming 10 bytes. +fI[0] = #3f9e0652 = 1.2345679 +fI[1] = #3f9e0653 = 1.234568 +fI[0] == strtof + + +Input: 1.23456589e+20 +strtof consumes 14 bytes and returns 1.2345659e+20 = #60d629bd +g_ffmt(0) gives 13 bytes: "1.2345659e+20" + +strtoIf returns 17, consuming 14 bytes. +fI[0] = #60d629bd = 1.2345659e+20 +fI[1] = #60d629be = 1.234566e+20 +fI[0] == strtof + + +Input: 1.23e+30 +strtof consumes 8 bytes and returns 1.23e+30 = #71786582 +g_ffmt(0) gives 8 bytes: "1.23e+30" + +strtoIf returns 17, consuming 8 bytes. +fI[0] = #71786582 = 1.23e+30 +fI[1] = #71786583 = 1.23e+30 +fI[0] == strtof + + +Input: 1.23e-30 +strtof consumes 8 bytes and returns 1.23e-30 = #dc79433 +g_ffmt(0) gives 8 bytes: "1.23e-30" + +strtoIf returns 17, consuming 8 bytes. +fI[0] = #dc79433 = 1.23e-30 +fI[1] = #dc79434 = 1.23e-30 +fI[0] == strtof + + +Input: 1.23456789e-20 +strtof consumes 14 bytes and returns 1.2345679e-20 = #1e69340a +g_ffmt(0) gives 13 bytes: "1.2345679e-20" + +strtoIf returns 17, consuming 14 bytes. +fI[0] = #1e69340a = 1.2345679e-20 +fI[1] = #1e69340b = 1.234568e-20 +fI[0] == strtof + + +Input: 1.23456789e-30 +strtof consumes 14 bytes and returns 1.2345679e-30 = #dc851f2 +g_ffmt(0) gives 13 bytes: "1.2345679e-30" + +strtoIf returns 33, consuming 14 bytes. +fI[0] = #dc851f1 = 1.2345678e-30 +fI[1] = #dc851f2 = 1.2345679e-30 +fI[1] == strtof + + +Input: 1.234567890123456789 +strtof consumes 20 bytes and returns 1.2345679 = #3f9e0652 +g_ffmt(0) gives 9 bytes: "1.2345679" + +strtoIf returns 17, consuming 20 bytes. +fI[0] = #3f9e0652 = 1.2345679 +fI[1] = #3f9e0653 = 1.234568 +fI[0] == strtof + + +Input: 1.23456789012345678901234567890123456789 +strtof consumes 40 bytes and returns 1.2345679 = #3f9e0652 +g_ffmt(0) gives 9 bytes: "1.2345679" + +strtoIf returns 17, consuming 40 bytes. +fI[0] = #3f9e0652 = 1.2345679 +fI[1] = #3f9e0653 = 1.234568 +fI[0] == strtof + + +Input: 1.23e306 +strtof consumes 8 bytes and returns Infinity = #7f800000 +g_ffmt(0) gives 8 bytes: "Infinity" + +strtoIf returns 163, consuming 8 bytes. +fI[0] = #7f7fffff = 3.4028235e+38 +fI[1] = #7f800000 = Infinity +fI[1] == strtof + + +Input: 1.23e-306 +strtof consumes 9 bytes and returns 0 = #0 +g_ffmt(0) gives 1 bytes: "0" + +strtoIf returns 80, consuming 9 bytes. +fI[0] = #0 = 0 +fI[1] = #1 = 1.4012985e-45 +fI[0] == strtof + + +Input: 1.23e-320 +strtof consumes 9 bytes and returns 0 = #0 +g_ffmt(0) gives 1 bytes: "0" + +strtoIf returns 80, consuming 9 bytes. +fI[0] = #0 = 0 +fI[1] = #1 = 1.4012985e-45 +fI[0] == strtof + + +Input: 1.23e-20 +strtof consumes 8 bytes and returns 1.23e-20 = #1e685726 +g_ffmt(0) gives 8 bytes: "1.23e-20" + +strtoIf returns 17, consuming 8 bytes. +fI[0] = #1e685726 = 1.23e-20 +fI[1] = #1e685727 = 1.23e-20 +fI[0] == strtof + + +Input: 1.23456789e307 +strtof consumes 14 bytes and returns Infinity = #7f800000 +g_ffmt(0) gives 8 bytes: "Infinity" + +strtoIf returns 163, consuming 14 bytes. +fI[0] = #7f7fffff = 3.4028235e+38 +fI[1] = #7f800000 = Infinity +fI[1] == strtof + + +Input: 1.23456589e-307 +strtof consumes 15 bytes and returns 0 = #0 +g_ffmt(0) gives 1 bytes: "0" + +strtoIf returns 80, consuming 15 bytes. +fI[0] = #0 = 0 +fI[1] = #1 = 1.4012985e-45 +fI[0] == strtof + + +Input: 1.234567890123456789 +strtof consumes 20 bytes and returns 1.2345679 = #3f9e0652 +g_ffmt(0) gives 9 bytes: "1.2345679" + +strtoIf returns 17, consuming 20 bytes. +fI[0] = #3f9e0652 = 1.2345679 +fI[1] = #3f9e0653 = 1.234568 +fI[0] == strtof + + +Input: 1.234567890123456789e301 +strtof consumes 24 bytes and returns Infinity = #7f800000 +g_ffmt(0) gives 8 bytes: "Infinity" + +strtoIf returns 163, consuming 24 bytes. +fI[0] = #7f7fffff = 3.4028235e+38 +fI[1] = #7f800000 = Infinity +fI[1] == strtof + + +Input: 1.234567890123456789e-301 +strtof consumes 25 bytes and returns 0 = #0 +g_ffmt(0) gives 1 bytes: "0" + +strtoIf returns 80, consuming 25 bytes. +fI[0] = #0 = 0 +fI[1] = #1 = 1.4012985e-45 +fI[0] == strtof + + +Input: 1.234567890123456789e-321 +strtof consumes 25 bytes and returns 0 = #0 +g_ffmt(0) gives 1 bytes: "0" + +strtoIf returns 80, consuming 25 bytes. +fI[0] = #0 = 0 +fI[1] = #1 = 1.4012985e-45 +fI[0] == strtof + + +Input: 1e23 +strtof consumes 4 bytes and returns 9.9999998e+22 = #65a96816 +g_ffmt(0) gives 5 bytes: "1e+23" + +strtoIf returns 17, consuming 4 bytes. +fI[0] = #65a96816 = 9.9999998e+22 +fI[1] = #65a96817 = 1.0000001e+23 +fI[0] == strtof + + +Input: 1e310 +strtof consumes 5 bytes and returns Infinity = #7f800000 +g_ffmt(0) gives 8 bytes: "Infinity" + +strtoIf returns 163, consuming 5 bytes. +fI[0] = #7f7fffff = 3.4028235e+38 +fI[1] = #7f800000 = Infinity +fI[1] == strtof + + +Input: 9.0259718793241475e-277 +strtof consumes 23 bytes and returns 0 = #0 +g_ffmt(0) gives 1 bytes: "0" + +strtoIf returns 80, consuming 23 bytes. +fI[0] = #0 = 0 +fI[1] = #1 = 1.4012985e-45 +fI[0] == strtof + + +Input: 9.025971879324147880346310405869e-277 +strtof consumes 37 bytes and returns 0 = #0 +g_ffmt(0) gives 1 bytes: "0" + +strtoIf returns 80, consuming 37 bytes. +fI[0] = #0 = 0 +fI[1] = #1 = 1.4012985e-45 +fI[0] == strtof + + +Input: 9.025971879324147880346310405868e-277 +strtof consumes 37 bytes and returns 0 = #0 +g_ffmt(0) gives 1 bytes: "0" + +strtoIf returns 80, consuming 37 bytes. +fI[0] = #0 = 0 +fI[1] = #1 = 1.4012985e-45 +fI[0] == strtof + + +Input: 2.2250738585072014e-308 +strtof consumes 23 bytes and returns 0 = #0 +g_ffmt(0) gives 1 bytes: "0" + +strtoIf returns 80, consuming 23 bytes. +fI[0] = #0 = 0 +fI[1] = #1 = 1.4012985e-45 +fI[0] == strtof + + +Input: 2.2250738585072013e-308 +strtof consumes 23 bytes and returns 0 = #0 +g_ffmt(0) gives 1 bytes: "0" + +strtoIf returns 80, consuming 23 bytes. +fI[0] = #0 = 0 +fI[1] = #1 = 1.4012985e-45 +fI[0] == strtof + +Rounding mode for strtor... changed from 1 (nearest) to 0 (toward zero) + +Input: 1.1 +strtof consumes 3 bytes and returns 1.0999999 = #3f8ccccc +g_ffmt(0) gives 9 bytes: "1.0999999" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3f8ccccc = 1.0999999 +fI[1] = #3f8ccccd = 1.1 +fI[0] == strtof + + +Input: -1.1 +strtof consumes 4 bytes and returns -1.0999999 = #bf8ccccc +g_ffmt(0) gives 10 bytes: "-1.0999999" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bf8ccccd = -1.1 +fI[1] = #bf8ccccc = -1.0999999 +fI[1] == strtof + + +Input: 1.2 +strtof consumes 3 bytes and returns 1.1999999 = #3f999999 +g_ffmt(0) gives 9 bytes: "1.1999999" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3f999999 = 1.1999999 +fI[1] = #3f99999a = 1.2 +fI[0] == strtof + + +Input: -1.2 +strtof consumes 4 bytes and returns -1.1999999 = #bf999999 +g_ffmt(0) gives 10 bytes: "-1.1999999" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bf99999a = -1.2 +fI[1] = #bf999999 = -1.1999999 +fI[1] == strtof + + +Input: 1.3 +strtof consumes 3 bytes and returns 1.3 = #3fa66666 +g_ffmt(0) gives 3 bytes: "1.3" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fa66666 = 1.3 +fI[1] = #3fa66667 = 1.3000001 +fI[0] == strtof + + +Input: -1.3 +strtof consumes 4 bytes and returns -1.3 = #bfa66666 +g_ffmt(0) gives 4 bytes: "-1.3" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfa66667 = -1.3000001 +fI[1] = #bfa66666 = -1.3 +fI[1] == strtof + + +Input: 1.4 +strtof consumes 3 bytes and returns 1.4 = #3fb33333 +g_ffmt(0) gives 3 bytes: "1.4" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fb33333 = 1.4 +fI[1] = #3fb33334 = 1.4000001 +fI[0] == strtof + + +Input: -1.4 +strtof consumes 4 bytes and returns -1.4 = #bfb33333 +g_ffmt(0) gives 4 bytes: "-1.4" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfb33334 = -1.4000001 +fI[1] = #bfb33333 = -1.4 +fI[1] == strtof + + +Input: 1.5 +strtof consumes 3 bytes and returns 1.5 = #3fc00000 +g_ffmt(0) gives 3 bytes: "1.5" + +strtoIf returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtof + + +Input: -1.5 +strtof consumes 4 bytes and returns -1.5 = #bfc00000 +g_ffmt(0) gives 4 bytes: "-1.5" + +strtoIf returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtof + + +Input: 1.6 +strtof consumes 3 bytes and returns 1.5999999 = #3fcccccc +g_ffmt(0) gives 9 bytes: "1.5999999" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3fcccccc = 1.5999999 +fI[1] = #3fcccccd = 1.6 +fI[0] == strtof + + +Input: -1.6 +strtof consumes 4 bytes and returns -1.5999999 = #bfcccccc +g_ffmt(0) gives 10 bytes: "-1.5999999" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bfcccccd = -1.6 +fI[1] = #bfcccccc = -1.5999999 +fI[1] == strtof + + +Input: 1.7 +strtof consumes 3 bytes and returns 1.6999999 = #3fd99999 +g_ffmt(0) gives 9 bytes: "1.6999999" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3fd99999 = 1.6999999 +fI[1] = #3fd9999a = 1.7 +fI[0] == strtof + + +Input: -1.7 +strtof consumes 4 bytes and returns -1.6999999 = #bfd99999 +g_ffmt(0) gives 10 bytes: "-1.6999999" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bfd9999a = -1.7 +fI[1] = #bfd99999 = -1.6999999 +fI[1] == strtof + + +Input: 1.8 +strtof consumes 3 bytes and returns 1.8 = #3fe66666 +g_ffmt(0) gives 3 bytes: "1.8" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fe66666 = 1.8 +fI[1] = #3fe66667 = 1.8000001 +fI[0] == strtof + + +Input: -1.8 +strtof consumes 4 bytes and returns -1.8 = #bfe66666 +g_ffmt(0) gives 4 bytes: "-1.8" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfe66667 = -1.8000001 +fI[1] = #bfe66666 = -1.8 +fI[1] == strtof + + +Input: 1.9 +strtof consumes 3 bytes and returns 1.9 = #3ff33333 +g_ffmt(0) gives 3 bytes: "1.9" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3ff33333 = 1.9 +fI[1] = #3ff33334 = 1.9000001 +fI[0] == strtof + + +Input: -1.9 +strtof consumes 4 bytes and returns -1.9 = #bff33333 +g_ffmt(0) gives 4 bytes: "-1.9" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bff33334 = -1.9000001 +fI[1] = #bff33333 = -1.9 +fI[1] == strtof + +Rounding mode for strtor... changed from 0 (toward zero) to 1 (nearest) + +Input: 1.1 +strtof consumes 3 bytes and returns 1.1 = #3f8ccccd +g_ffmt(0) gives 3 bytes: "1.1" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3f8ccccc = 1.0999999 +fI[1] = #3f8ccccd = 1.1 +fI[1] == strtof + + +Input: -1.1 +strtof consumes 4 bytes and returns -1.1 = #bf8ccccd +g_ffmt(0) gives 4 bytes: "-1.1" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bf8ccccd = -1.1 +fI[1] = #bf8ccccc = -1.0999999 +fI[0] == strtof + + +Input: 1.2 +strtof consumes 3 bytes and returns 1.2 = #3f99999a +g_ffmt(0) gives 3 bytes: "1.2" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3f999999 = 1.1999999 +fI[1] = #3f99999a = 1.2 +fI[1] == strtof + + +Input: -1.2 +strtof consumes 4 bytes and returns -1.2 = #bf99999a +g_ffmt(0) gives 4 bytes: "-1.2" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bf99999a = -1.2 +fI[1] = #bf999999 = -1.1999999 +fI[0] == strtof + + +Input: 1.3 +strtof consumes 3 bytes and returns 1.3 = #3fa66666 +g_ffmt(0) gives 3 bytes: "1.3" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fa66666 = 1.3 +fI[1] = #3fa66667 = 1.3000001 +fI[0] == strtof + + +Input: -1.3 +strtof consumes 4 bytes and returns -1.3 = #bfa66666 +g_ffmt(0) gives 4 bytes: "-1.3" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfa66667 = -1.3000001 +fI[1] = #bfa66666 = -1.3 +fI[1] == strtof + + +Input: 1.4 +strtof consumes 3 bytes and returns 1.4 = #3fb33333 +g_ffmt(0) gives 3 bytes: "1.4" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fb33333 = 1.4 +fI[1] = #3fb33334 = 1.4000001 +fI[0] == strtof + + +Input: -1.4 +strtof consumes 4 bytes and returns -1.4 = #bfb33333 +g_ffmt(0) gives 4 bytes: "-1.4" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfb33334 = -1.4000001 +fI[1] = #bfb33333 = -1.4 +fI[1] == strtof + + +Input: 1.5 +strtof consumes 3 bytes and returns 1.5 = #3fc00000 +g_ffmt(0) gives 3 bytes: "1.5" + +strtoIf returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtof + + +Input: -1.5 +strtof consumes 4 bytes and returns -1.5 = #bfc00000 +g_ffmt(0) gives 4 bytes: "-1.5" + +strtoIf returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtof + + +Input: 1.6 +strtof consumes 3 bytes and returns 1.6 = #3fcccccd +g_ffmt(0) gives 3 bytes: "1.6" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3fcccccc = 1.5999999 +fI[1] = #3fcccccd = 1.6 +fI[1] == strtof + + +Input: -1.6 +strtof consumes 4 bytes and returns -1.6 = #bfcccccd +g_ffmt(0) gives 4 bytes: "-1.6" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bfcccccd = -1.6 +fI[1] = #bfcccccc = -1.5999999 +fI[0] == strtof + + +Input: 1.7 +strtof consumes 3 bytes and returns 1.7 = #3fd9999a +g_ffmt(0) gives 3 bytes: "1.7" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3fd99999 = 1.6999999 +fI[1] = #3fd9999a = 1.7 +fI[1] == strtof + + +Input: -1.7 +strtof consumes 4 bytes and returns -1.7 = #bfd9999a +g_ffmt(0) gives 4 bytes: "-1.7" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bfd9999a = -1.7 +fI[1] = #bfd99999 = -1.6999999 +fI[0] == strtof + + +Input: 1.8 +strtof consumes 3 bytes and returns 1.8 = #3fe66666 +g_ffmt(0) gives 3 bytes: "1.8" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fe66666 = 1.8 +fI[1] = #3fe66667 = 1.8000001 +fI[0] == strtof + + +Input: -1.8 +strtof consumes 4 bytes and returns -1.8 = #bfe66666 +g_ffmt(0) gives 4 bytes: "-1.8" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfe66667 = -1.8000001 +fI[1] = #bfe66666 = -1.8 +fI[1] == strtof + + +Input: 1.9 +strtof consumes 3 bytes and returns 1.9 = #3ff33333 +g_ffmt(0) gives 3 bytes: "1.9" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3ff33333 = 1.9 +fI[1] = #3ff33334 = 1.9000001 +fI[0] == strtof + + +Input: -1.9 +strtof consumes 4 bytes and returns -1.9 = #bff33333 +g_ffmt(0) gives 4 bytes: "-1.9" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bff33334 = -1.9000001 +fI[1] = #bff33333 = -1.9 +fI[1] == strtof + +Rounding mode for strtor... changed from 1 (nearest) to 2 (toward +Infinity) + +Input: 1.1 +strtof consumes 3 bytes and returns 1.1 = #3f8ccccd +g_ffmt(0) gives 3 bytes: "1.1" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3f8ccccc = 1.0999999 +fI[1] = #3f8ccccd = 1.1 +fI[1] == strtof + + +Input: -1.1 +strtof consumes 4 bytes and returns -1.0999999 = #bf8ccccc +g_ffmt(0) gives 10 bytes: "-1.0999999" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bf8ccccd = -1.1 +fI[1] = #bf8ccccc = -1.0999999 +fI[1] == strtof + + +Input: 1.2 +strtof consumes 3 bytes and returns 1.2 = #3f99999a +g_ffmt(0) gives 3 bytes: "1.2" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3f999999 = 1.1999999 +fI[1] = #3f99999a = 1.2 +fI[1] == strtof + + +Input: -1.2 +strtof consumes 4 bytes and returns -1.1999999 = #bf999999 +g_ffmt(0) gives 10 bytes: "-1.1999999" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bf99999a = -1.2 +fI[1] = #bf999999 = -1.1999999 +fI[1] == strtof + + +Input: 1.3 +strtof consumes 3 bytes and returns 1.3000001 = #3fa66667 +g_ffmt(0) gives 9 bytes: "1.3000001" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fa66666 = 1.3 +fI[1] = #3fa66667 = 1.3000001 +fI[1] == strtof + + +Input: -1.3 +strtof consumes 4 bytes and returns -1.3 = #bfa66666 +g_ffmt(0) gives 4 bytes: "-1.3" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfa66667 = -1.3000001 +fI[1] = #bfa66666 = -1.3 +fI[1] == strtof + + +Input: 1.4 +strtof consumes 3 bytes and returns 1.4000001 = #3fb33334 +g_ffmt(0) gives 9 bytes: "1.4000001" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fb33333 = 1.4 +fI[1] = #3fb33334 = 1.4000001 +fI[1] == strtof + + +Input: -1.4 +strtof consumes 4 bytes and returns -1.4 = #bfb33333 +g_ffmt(0) gives 4 bytes: "-1.4" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfb33334 = -1.4000001 +fI[1] = #bfb33333 = -1.4 +fI[1] == strtof + + +Input: 1.5 +strtof consumes 3 bytes and returns 1.5 = #3fc00000 +g_ffmt(0) gives 3 bytes: "1.5" + +strtoIf returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtof + + +Input: -1.5 +strtof consumes 4 bytes and returns -1.5 = #bfc00000 +g_ffmt(0) gives 4 bytes: "-1.5" + +strtoIf returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtof + + +Input: 1.6 +strtof consumes 3 bytes and returns 1.6 = #3fcccccd +g_ffmt(0) gives 3 bytes: "1.6" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3fcccccc = 1.5999999 +fI[1] = #3fcccccd = 1.6 +fI[1] == strtof + + +Input: -1.6 +strtof consumes 4 bytes and returns -1.5999999 = #bfcccccc +g_ffmt(0) gives 10 bytes: "-1.5999999" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bfcccccd = -1.6 +fI[1] = #bfcccccc = -1.5999999 +fI[1] == strtof + + +Input: 1.7 +strtof consumes 3 bytes and returns 1.7 = #3fd9999a +g_ffmt(0) gives 3 bytes: "1.7" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3fd99999 = 1.6999999 +fI[1] = #3fd9999a = 1.7 +fI[1] == strtof + + +Input: -1.7 +strtof consumes 4 bytes and returns -1.6999999 = #bfd99999 +g_ffmt(0) gives 10 bytes: "-1.6999999" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bfd9999a = -1.7 +fI[1] = #bfd99999 = -1.6999999 +fI[1] == strtof + + +Input: 1.8 +strtof consumes 3 bytes and returns 1.8000001 = #3fe66667 +g_ffmt(0) gives 9 bytes: "1.8000001" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fe66666 = 1.8 +fI[1] = #3fe66667 = 1.8000001 +fI[1] == strtof + + +Input: -1.8 +strtof consumes 4 bytes and returns -1.8 = #bfe66666 +g_ffmt(0) gives 4 bytes: "-1.8" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfe66667 = -1.8000001 +fI[1] = #bfe66666 = -1.8 +fI[1] == strtof + + +Input: 1.9 +strtof consumes 3 bytes and returns 1.9000001 = #3ff33334 +g_ffmt(0) gives 9 bytes: "1.9000001" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3ff33333 = 1.9 +fI[1] = #3ff33334 = 1.9000001 +fI[1] == strtof + + +Input: -1.9 +strtof consumes 4 bytes and returns -1.9 = #bff33333 +g_ffmt(0) gives 4 bytes: "-1.9" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bff33334 = -1.9000001 +fI[1] = #bff33333 = -1.9 +fI[1] == strtof + +Rounding mode for strtor... changed from 2 (toward +Infinity) to 3 (toward -Infinity) + +Input: 1.1 +strtof consumes 3 bytes and returns 1.0999999 = #3f8ccccc +g_ffmt(0) gives 9 bytes: "1.0999999" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3f8ccccc = 1.0999999 +fI[1] = #3f8ccccd = 1.1 +fI[0] == strtof + + +Input: -1.1 +strtof consumes 4 bytes and returns -1.1 = #bf8ccccd +g_ffmt(0) gives 4 bytes: "-1.1" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bf8ccccd = -1.1 +fI[1] = #bf8ccccc = -1.0999999 +fI[0] == strtof + + +Input: 1.2 +strtof consumes 3 bytes and returns 1.1999999 = #3f999999 +g_ffmt(0) gives 9 bytes: "1.1999999" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3f999999 = 1.1999999 +fI[1] = #3f99999a = 1.2 +fI[0] == strtof + + +Input: -1.2 +strtof consumes 4 bytes and returns -1.2 = #bf99999a +g_ffmt(0) gives 4 bytes: "-1.2" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bf99999a = -1.2 +fI[1] = #bf999999 = -1.1999999 +fI[0] == strtof + + +Input: 1.3 +strtof consumes 3 bytes and returns 1.3 = #3fa66666 +g_ffmt(0) gives 3 bytes: "1.3" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fa66666 = 1.3 +fI[1] = #3fa66667 = 1.3000001 +fI[0] == strtof + + +Input: -1.3 +strtof consumes 4 bytes and returns -1.3000001 = #bfa66667 +g_ffmt(0) gives 10 bytes: "-1.3000001" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfa66667 = -1.3000001 +fI[1] = #bfa66666 = -1.3 +fI[0] == strtof + + +Input: 1.4 +strtof consumes 3 bytes and returns 1.4 = #3fb33333 +g_ffmt(0) gives 3 bytes: "1.4" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fb33333 = 1.4 +fI[1] = #3fb33334 = 1.4000001 +fI[0] == strtof + + +Input: -1.4 +strtof consumes 4 bytes and returns -1.4000001 = #bfb33334 +g_ffmt(0) gives 10 bytes: "-1.4000001" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfb33334 = -1.4000001 +fI[1] = #bfb33333 = -1.4 +fI[0] == strtof + + +Input: 1.5 +strtof consumes 3 bytes and returns 1.5 = #3fc00000 +g_ffmt(0) gives 3 bytes: "1.5" + +strtoIf returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtof + + +Input: -1.5 +strtof consumes 4 bytes and returns -1.5 = #bfc00000 +g_ffmt(0) gives 4 bytes: "-1.5" + +strtoIf returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtof + + +Input: 1.6 +strtof consumes 3 bytes and returns 1.5999999 = #3fcccccc +g_ffmt(0) gives 9 bytes: "1.5999999" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3fcccccc = 1.5999999 +fI[1] = #3fcccccd = 1.6 +fI[0] == strtof + + +Input: -1.6 +strtof consumes 4 bytes and returns -1.6 = #bfcccccd +g_ffmt(0) gives 4 bytes: "-1.6" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bfcccccd = -1.6 +fI[1] = #bfcccccc = -1.5999999 +fI[0] == strtof + + +Input: 1.7 +strtof consumes 3 bytes and returns 1.6999999 = #3fd99999 +g_ffmt(0) gives 9 bytes: "1.6999999" + +strtoIf returns 33, consuming 3 bytes. +fI[0] = #3fd99999 = 1.6999999 +fI[1] = #3fd9999a = 1.7 +fI[0] == strtof + + +Input: -1.7 +strtof consumes 4 bytes and returns -1.7 = #bfd9999a +g_ffmt(0) gives 4 bytes: "-1.7" + +strtoIf returns 41, consuming 4 bytes. +fI[0] = #bfd9999a = -1.7 +fI[1] = #bfd99999 = -1.6999999 +fI[0] == strtof + + +Input: 1.8 +strtof consumes 3 bytes and returns 1.8 = #3fe66666 +g_ffmt(0) gives 3 bytes: "1.8" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3fe66666 = 1.8 +fI[1] = #3fe66667 = 1.8000001 +fI[0] == strtof + + +Input: -1.8 +strtof consumes 4 bytes and returns -1.8000001 = #bfe66667 +g_ffmt(0) gives 10 bytes: "-1.8000001" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bfe66667 = -1.8000001 +fI[1] = #bfe66666 = -1.8 +fI[0] == strtof + + +Input: 1.9 +strtof consumes 3 bytes and returns 1.9 = #3ff33333 +g_ffmt(0) gives 3 bytes: "1.9" + +strtoIf returns 17, consuming 3 bytes. +fI[0] = #3ff33333 = 1.9 +fI[1] = #3ff33334 = 1.9000001 +fI[0] == strtof + + +Input: -1.9 +strtof consumes 4 bytes and returns -1.9000001 = #bff33334 +g_ffmt(0) gives 10 bytes: "-1.9000001" + +strtoIf returns 25, consuming 4 bytes. +fI[0] = #bff33334 = -1.9000001 +fI[1] = #bff33333 = -1.9 +fI[0] == strtof + diff --git a/lib/libc/gdtoa/test/ftest.c b/lib/libc/gdtoa/test/ftest.c new file mode 100644 index 000000000..2006fdcdd --- /dev/null +++ b/lib/libc/gdtoa/test/ftest.c @@ -0,0 +1,140 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998-2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +/* Test program for g_ffmt, strtof, strtoIf, strtopf, and strtorf. + * + * Inputs (on stdin): + * r rounding_mode + * n ndig + * number + * #hex + * + * rounding_mode values: + * 0 = toward zero + * 1 = nearest + * 2 = toward +Infinity + * 3 = toward -Infinity + * + * where number is a decimal floating-point number, + * hex is a string of <= 8 Hex digits for the internal representation + * of the number, and ndig is a parameters to g_ffmt. + */ + +#include "gdtoa.h" +#include +#include + + extern int getround ANSI((int,char*)); + + static char ibuf[2048], obuf[1024]; + +#define U (unsigned long) + + int +main(Void) +{ + char *s, *se, *se1; + int dItry, i, i1, ndig = 0, r = 1; + float f1, fI[2]; + union { float f; ULong L[1]; } u; + + while( (s = fgets(ibuf, sizeof(ibuf), stdin)) !=0) { + while(*s <= ' ') + if (!*s++) + continue; + dItry = 0; + switch(*s) { + case 'r': + r = getround(r, s); + continue; + case 'n': + i = s[1]; + if (i <= ' ' || (i >= '0' && i <= '9')) { + ndig = atoi(s+1); + continue; + } + break; /* nan? */ + case '#': + /* sscanf(s+1, "%lx", &u.L[0]); */ + u.L[0] = (ULong)strtoul(s+1, &se, 16); + printf("\nInput: %s", ibuf); + printf(" --> f = #%lx\n", U u.L[0]); + goto fmt_test; + } + dItry = 1; + printf("\nInput: %s", ibuf); + i = strtorf(ibuf, &se, r, &u.f); + if (r == 1) { + if (u.f != (i1 = strtopf(ibuf, &se1, &f1), f1) + || se != se1 || i != i1) { + printf("***strtopf and strtorf disagree!!\n"); + if (u.f != f1) + printf("\tf1 = %g\n", (double)f1); + if (i != i1) + printf("\ti = %d but i1 = %d\n", i, i1); + if (se != se1) + printf("se - se1 = %d\n", (int)(se-se1)); + } + if (u.f != strtof(ibuf, &se1) || se != se1) + printf("***strtof and strtorf disagree!\n"); + } + printf("strtof consumes %d bytes and returns %.8g = #%lx\n", + (int)(se-ibuf), u.f, U u.L[0]); + fmt_test: + se = g_ffmt(obuf, &u.f, ndig, sizeof(obuf)); + printf("g_ffmt(%d) gives %d bytes: \"%s\"\n\n", + ndig, (int)(se-obuf), se ? obuf : ""); + if (!dItry) + continue; + printf("strtoIf returns %d,", strtoIf(ibuf, &se, fI, &fI[1])); + printf(" consuming %d bytes.\n", (int)(se-ibuf)); + if (fI[0] == fI[1]) { + if (fI[0] == u.f) + printf("fI[0] == fI[1] == strtof\n"); + else + printf("fI[0] == fI[1] = #%lx = %.8g\n", + U *(ULong*)fI, fI[0]); + } + else { + printf("fI[0] = #%lx = %.8g\nfI[1] = #%lx = %.8g\n", + U *(ULong*)fI, fI[0], + U *(ULong*)&fI[1], fI[1]); + if (fI[0] == u.f) + printf("fI[0] == strtof\n"); + else if (fI[1] == u.f) + printf("fI[1] == strtof\n"); + else + printf("**** Both differ from strtof ****\n"); + } + printf("\n"); + } + return 0; + } diff --git a/lib/libc/gdtoa/test/getround.c b/lib/libc/gdtoa/test/getround.c new file mode 100644 index 000000000..05eb199e7 --- /dev/null +++ b/lib/libc/gdtoa/test/getround.c @@ -0,0 +1,90 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +#include +#include + +static char *dir[4] = { "toward zero", "nearest", "toward +Infinity", + "toward -Infinity" }; + +#ifdef Honor_FLT_ROUNDS +#include +static int fe_conv[4] = {FE_TOWARDZERO, FE_TONEAREST, FE_UPWARD, FE_DOWNWARD }; +#endif + + int +#ifdef KR_headers +getround(r, s) int r; char *s; +#else +getround(int r, char *s) +#endif +{ + int i; + + while(*++s <= ' ') { + if (!*s) { + printf("Current round mode for strtor... is %d (%s).\n", + r, dir[r]); + return r; + } + } + i = atoi(s); + if (i >= 0 && i < 4) { + printf("Rounding mode for strtor... "); + if (i == r) + printf("was and is %d (%s)\n", i, dir[i]); + else + printf("changed from %d (%s) to %d (%s)\n", + r, dir[r], i, dir[i]); +#ifdef Honor_FLT_ROUNDS + fesetround(fe_conv[i]); +#endif + return i; + } + printf("Bad rounding direction %d: choose among\n", i); + for(i = 0; i < 4; i++) + printf("\t%d (%s)\n", i, dir[i]); + printf("Leaving rounding mode for strtor... at %d (%s)\n", r, dir[r]); + return r; + } + +#ifdef USE_MY_LOCALE +#include + + struct lconv * +localeconv(void) +{ + static struct lconv mylocale; + mylocale.decimal_point = ""; + return &mylocale; + } +#endif + diff --git a/lib/libc/gdtoa/test/makefile b/lib/libc/gdtoa/test/makefile new file mode 100644 index 000000000..79c9874ea --- /dev/null +++ b/lib/libc/gdtoa/test/makefile @@ -0,0 +1,169 @@ +# /**************************************************************** +# Copyright (C) 1998, 2000 by Lucent Technologies +# All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and +# its documentation for any purpose and without fee is hereby +# granted, provided that the above copyright notice appear in all +# copies and that both that the copyright notice and this +# permission notice and warranty disclaimer appear in supporting +# documentation, and that the name of Lucent or any of its entities +# not be used in advertising or publicity pertaining to +# distribution of the software without specific, written prior +# permission. +# +# LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +# IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +# SPECIAL, 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. +# +# ****************************************************************/ + +CC = cc +CFLAGS = -g -I.. +CFLAGS+=-I${.CURDIR}/../../arch/${MACHINE_ARCH}/gdtoa +L = -lm +L1 = -lm +#use "L1=-lm" when compiled with -DHonor_FLTP_ROUNDS or -DUSE_LOCALE +INFFIX = | sed 's/[Ii][Nn][Ff][intyINTY]*/Infinity/g' + +.PATH: /usr/src/lib/libc/gdtoa + +all: dt dItest ddtest dtest ftest Qtest xLtest xtest ddtestsi dItestsi tests + +dt = dt.o $A +dt: $(dt) + $(CC) -o dt $(dt) $L + +dItest = dItest.o getround.o g_dfmt.o strtoId.o strtodI.o \ + g__fmt.o strtoIg.o +dItest: $(dItest) + $(CC) -o dItest $(dItest) $(L1) + +ddtest = ddtest.o getround.o g_dfmt.o strtordd.o strtopdd.o g_ddfmt.o \ + strtoIdd.o g__fmt.o strtoIg.o +ddtest: $(ddtest) + $(CC) -o ddtest $(ddtest) $L + +dtest = dtest.o getround.o g_dfmt.o strtopd.o strtoId.o \ + g__fmt.o strtoIg.o +dtest: $(dtest) + $(CC) -o dtest $(dtest) $L + +ftest = ftest.o getround.o strtorf.o strtopf.o g_ffmt.o strtoIf.o \ + g__fmt.o strtoIg.o +ftest: $(ftest) + $(CC) -o ftest $(ftest) $(L1) + +Qtest = Qtest.o getround.o strtorQ.o g_Qfmt.o strtoIQ.o strtopQ.o \ + g__fmt.o strtoIg.o +Qtest: $(Qtest) + $(CC) -o Qtest $(Qtest) $(L1) + +xtest = xtest.o getround.o strtorx.o g_xfmt.o strtoIx.o \ + g__fmt.o strtoIg.o +xtest: $(xtest) + $(CC) -o xtest $(xtest) $(L1) + +xLtest = xLtest.o getround.o strtorxL.o strtopxL.o g_xLfmt.o strtoIxL.o \ + g__fmt.o strtoIg.o +xLtest: $(xLtest) + $(CC) -o xLtest $(xLtest) $(L1) + +ddtestsi = ddtest.o strtopddSI.o strtorddSI.o strtoIddSI.o getround.o \ + g_dfmt.o g_ddfmt.o g__fmt.o strtoIg.o +ddtestsi: $(ddtestsi) + $(CC) -o ddtestsi $(ddtestsi) $L + +dItestsi = dItest.o strtodISI.o strtoIdSI.o getround.o \ + g_dfmt.o g__fmt.o strtoIg.o +dItestsi: $(dItestsi) + $(CC) -o dItestsi $(dItestsi) $(L1) + +strtodt = strtodt.o $A +strtodt: $(strtodt) + $(CC) -o strtodt $(strtodt) $L + +pftest = pftest.o $A +pftest: $(pftest) + $(CC) -o pftest $(pftest) $L + +## On Intel (and Intel-like) systems using extended-precision registers +## for double-precision (C type double) computations that sometimes suffer +## double rounding errors, the test below involving strtodt generally shows +## five lines of unexpected results. Variant strtodtnrp uses ../strtodrnp.c +## (which does all computations in integer arithmetic) and should show no +## unexpected results. + +strtodtnrp = strtodt.o strtodnrp.o +strtodtnrp: $(strtodtnrp) + $(CC) -o strtodtnrp $(strtodtnrp) + +# xQtest generates cp commands that depend on sizeof(long double). +# See the source for details. If you know better, create Q.out, +# x.out and xL.out by copying the relevant *.ou0 or *.ou1 files +# to the corresponding .out files. In short, the *.ou0 files are +# for long double == double; x.ou1 and xL.ou1 are for +# long double == extended (a la 80x87 and MC680x0), and Q.ou1 is +# for long double == quad. + +Q.out x.out xL.out: + $(CC) -o xQtest xQtest.c + ./xQtest | sh + rm -f xQtest xQtest.o + +## The rmdir below will fail if any test results differ. + +tests: Q.out x.out xL.out dt dItest ddtest dtest ftest Qtest xLtest xtest ddtestsi dItestsi strtodt strtodtnrp + mkdir bad + cat testnos testnos1 | ./dt $(INFFIX) >zap 2>&1 + cmp dtst.out zap || mv zap bad/dtst.out + ./dItest zap 2>&1 + cmp dI.out zap || mv zap bad/dI.out + ./dItestsi zap 2>&1 + cmp dIsi.out zap || mv zap bad/dIsi.out + ./ddtestsi zap 2>&1 + cmp ddsi.out zap || mv zap bad/ddsi.out + for i in dd d f x xL Q; do cat testnos rtestnos | \ + ./"$$i"test $(INFFIX) >zap 2>&1;\ + cmp $$i.out zap || mv zap bad/$$i.out; done + ./strtodt testnos3 >bad/strtodt.out && rm bad/strtodt.out || \ + cat bad/strtodt.out + ./strtodtnrp testnos3 >bad/strtodtnrp.out && rm bad/strtodtnrp.out || \ + cat bad/strtodtnrp.out + rmdir bad 2>/dev/null || \ + (cd bad; for i in *; do cmp -s $$i ../obad/$$i && rm $$i;done; cd ..; rmdir bad) + touch tests + +# To test Printf in ../gdtoa.a, "make pf_test" and perhaps "make pf_testLq" +# (if both long double and quad are desired and available). + +pf_test: pftest + ./pftest zap + cmp pftest.out zap && rm zap + +pf_testLq: pftest + ./pftest zap + cmp pftestLq.out zap && rm zap + +xs0 = README Q.ou0 Q.ou1 Qtest.c d.out dI.out dIsi.out dItest.c dd.out\ + ddsi.out ddtest.c dt.c dtest.c dtst.out f.out ftest.c\ + getround.c makefile pfLqtestnos pftest.c pftestQ.out\ + pftestx.out pftestLq.out pftestnos rtestnos strtoIdSI.c\ + strtoIddSI.c strtodISI.c strtodt.c strtopddSI.c strtorddSI.c\ + testnos testnos1 testnos3 x.ou0 x.ou1 xL.ou0 xL.ou1 xLtest.c\ + xQtest.c xtest.c + +# invoke "make -r xsum.out" +xsum.out: xsum0.out $(xs0) + xsum $(xs0) >xsum1.out + cmp xsum0.out xsum1.out && mv xsum1.out xsum.out || diff xsum[01].out + +clean: + rm -f *.[ao] dt *test *testsi pftest.out strtodt strtodtnrp xsum.out\ + xsum1.out tests zap x.out xL.out Q.out + rm -rf bad diff --git a/lib/libc/gdtoa/test/obad/strtodt.out b/lib/libc/gdtoa/test/obad/strtodt.out new file mode 100644 index 000000000..79516bfaa --- /dev/null +++ b/lib/libc/gdtoa/test/obad/strtodt.out @@ -0,0 +1,6 @@ +Line 31 of testnos3: got 4585747a b143e354; expected 4585747a b143e353 +Line 46 of testnos3: got 64fdcf7d f8f573b8; expected 64fdcf7d f8f573b7 +Line 47 of testnos3: got 650dcf7d f8f573b8; expected 650dcf7d f8f573b7 +Line 72 of testnos3: got 3cc70385 6844bdbe; expected 3cc70385 6844bdbf +Line 73 of testnos3: got 3cb70385 6844bdbe; expected 3cb70385 6844bdbf +5 bad conversions diff --git a/lib/libc/gdtoa/test/obad/xL.out b/lib/libc/gdtoa/test/obad/xL.out new file mode 100644 index 000000000..19a7fd1c1 --- /dev/null +++ b/lib/libc/gdtoa/test/obad/xL.out @@ -0,0 +1,1460 @@ + +Input: 1.23 + +strtoxL consumes 4 bytes and returns 33 +with bits = #3fff0000 9d70a3d7 a3d70a4 +printf("%.21Lg") gives 7.73283722915781506499e-4933 +g_xLfmt(0) gives 4 bytes: "1.23" + +strtoIxL returns 33, consuming 4 bytes. +fI[0] = #3fff0000 9d70a3d7 a3d70a3 += 7.73283722915781506134e-4933 +fI[1] = #3fff0000 9d70a3d7 a3d70a4 += 7.73283722915781506499e-4933 +fI[1] == strtoxL + + +Input: 1.23e+20 + +strtoxL consumes 8 bytes and returns 1 +with bits = #40410000 d55ef90a 2da18000 +printf("%.21Lg") gives 2.24239113715721119512e-4932 +g_xLfmt(0) gives 8 bytes: "1.23e+20" + +strtoIxL returns 1, consuming 8 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.23e-20 + +strtoxL consumes 8 bytes and returns 17 +with bits = #3fbc0000 e857267b b3a984f2 +printf("%.21Lg") gives 2.74065070995958800375e-4932 +g_xLfmt(0) gives 8 bytes: "1.23e-20" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #3fbc0000 e857267b b3a984f2 += 2.74065070995958800375e-4932 +fI[1] = #3fbc0000 e857267b b3a984f3 += 2.74065070995958800411e-4932 +fI[0] == strtoxL + + +Input: 1.23456789 + +strtoxL consumes 10 bytes and returns 33 +with bits = #3fff0000 9e065214 1ef0dbf6 +printf("%.21Lg") gives 7.88641440242171807354e-4933 +g_xLfmt(0) gives 10 bytes: "1.23456789" + +strtoIxL returns 33, consuming 10 bytes. +fI[0] = #3fff0000 9e065214 1ef0dbf5 += 7.8864144024217180699e-4933 +fI[1] = #3fff0000 9e065214 1ef0dbf6 += 7.88641440242171807354e-4933 +fI[1] == strtoxL + + +Input: 1.23456589e+20 + +strtoxL consumes 14 bytes and returns 1 +with bits = #40410000 d629bd33 5ccba00 +printf("%.21Lg") gives 2.26319561227049478508e-4932 +g_xLfmt(0) gives 14 bytes: "1.23456589e+20" + +strtoIxL returns 1, consuming 14 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.23e+30 + +strtoxL consumes 8 bytes and returns 17 +with bits = #40620000 f8658274 7dbc824a +printf("%.21Lg") gives 3.16238691003557160385e-4932 +g_xLfmt(0) gives 8 bytes: "1.23e+30" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #40620000 f8658274 7dbc824a += 3.16238691003557160385e-4932 +fI[1] = #40620000 f8658274 7dbc824b += 3.16238691003557160421e-4932 +fI[0] == strtoxL + + +Input: 1.23e-30 + +strtoxL consumes 8 bytes and returns 17 +with bits = #3f9b0000 c794337a 808554eb +printf("%.21Lg") gives 1.88012249978407873966e-4932 +g_xLfmt(0) gives 8 bytes: "1.23e-30" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #3f9b0000 c794337a 808554eb += 1.88012249978407873966e-4932 +fI[1] = #3f9b0000 c794337a 808554ec += 1.88012249978407874003e-4932 +fI[0] == strtoxL + + +Input: 1.23456789e-20 + +strtoxL consumes 14 bytes and returns 17 +with bits = #3fbc0000 e9340a38 f3d6d352 +printf("%.21Lg") gives 2.76331470044569174626e-4932 +g_xLfmt(0) gives 14 bytes: "1.23456789e-20" + +strtoIxL returns 17, consuming 14 bytes. +fI[0] = #3fbc0000 e9340a38 f3d6d352 += 2.76331470044569174626e-4932 +fI[1] = #3fbc0000 e9340a38 f3d6d353 += 2.76331470044569174663e-4932 +fI[0] == strtoxL + + +Input: 1.23456789e-30 + +strtoxL consumes 14 bytes and returns 17 +with bits = #3f9b0000 c851f19d decca8fc +printf("%.21Lg") gives 1.89959071937101288293e-4932 +g_xLfmt(0) gives 14 bytes: "1.23456789e-30" + +strtoIxL returns 17, consuming 14 bytes. +fI[0] = #3f9b0000 c851f19d decca8fc += 1.89959071937101288293e-4932 +fI[1] = #3f9b0000 c851f19d decca8fd += 1.89959071937101288329e-4932 +fI[0] == strtoxL + + +Input: 1.234567890123456789 + +strtoxL consumes 20 bytes and returns 17 +with bits = #3fff0000 9e065214 62cfdb8d +printf("%.21Lg") gives 7.88641440657246265535e-4933 +g_xLfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIxL returns 17, consuming 20 bytes. +fI[0] = #3fff0000 9e065214 62cfdb8d += 7.88641440657246265535e-4933 +fI[1] = #3fff0000 9e065214 62cfdb8e += 7.886414406572462659e-4933 +fI[0] == strtoxL + + +Input: 1.23456789012345678901234567890123456789 + +strtoxL consumes 40 bytes and returns 17 +with bits = #3fff0000 9e065214 62cfdb8d +printf("%.21Lg") gives 7.88641440657246265535e-4933 +g_xLfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIxL returns 17, consuming 40 bytes. +fI[0] = #3fff0000 9e065214 62cfdb8d += 7.88641440657246265535e-4933 +fI[1] = #3fff0000 9e065214 62cfdb8e += 7.886414406572462659e-4933 +fI[0] == strtoxL + + +Input: 1.23e306 + +strtoxL consumes 8 bytes and returns 17 +with bits = #43f70000 e033b668 e30fa6d5 +printf("%.21Lg") gives 2.52688323155200052759e-4932 +g_xLfmt(0) gives 9 bytes: "1.23e+306" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #43f70000 e033b668 e30fa6d5 += 2.52688323155200052759e-4932 +fI[1] = #43f70000 e033b668 e30fa6d6 += 2.52688323155200052796e-4932 +fI[0] == strtoxL + + +Input: 1.23e-306 + +strtoxL consumes 9 bytes and returns 33 +with bits = #3c060000 dd1dc2ed 1cb73f25 +printf("%.21Lg") gives 2.44583168427704605801e-4932 +g_xLfmt(0) gives 9 bytes: "1.23e-306" + +strtoIxL returns 33, consuming 9 bytes. +fI[0] = #3c060000 dd1dc2ed 1cb73f24 += 2.44583168427704605765e-4932 +fI[1] = #3c060000 dd1dc2ed 1cb73f25 += 2.44583168427704605801e-4932 +fI[1] == strtoxL + + +Input: 1.23e-320 + +strtoxL consumes 9 bytes and returns 33 +with bits = #3bd80000 9b98c371 844c3f1a +printf("%.21Lg") gives 7.24867657578821329238e-4933 +g_xLfmt(0) gives 9 bytes: "1.23e-320" + +strtoIxL returns 33, consuming 9 bytes. +fI[0] = #3bd80000 9b98c371 844c3f19 += 7.24867657578821328874e-4933 +fI[1] = #3bd80000 9b98c371 844c3f1a += 7.24867657578821329238e-4933 +fI[1] == strtoxL + + +Input: 1.23e-20 + +strtoxL consumes 8 bytes and returns 17 +with bits = #3fbc0000 e857267b b3a984f2 +printf("%.21Lg") gives 2.74065070995958800375e-4932 +g_xLfmt(0) gives 8 bytes: "1.23e-20" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #3fbc0000 e857267b b3a984f2 += 2.74065070995958800375e-4932 +fI[1] = #3fbc0000 e857267b b3a984f3 += 2.74065070995958800411e-4932 +fI[0] == strtoxL + + +Input: 1.23456789e307 + +strtoxL consumes 14 bytes and returns 17 +with bits = #43fb0000 8ca58a5e d766de75 +printf("%.21Lg") gives 3.32182163192682931854e-4933 +g_xLfmt(0) gives 15 bytes: "1.23456789e+307" + +strtoIxL returns 17, consuming 14 bytes. +fI[0] = #43fb0000 8ca58a5e d766de75 += 3.32182163192682931854e-4933 +fI[1] = #43fb0000 8ca58a5e d766de76 += 3.32182163192682932219e-4933 +fI[0] == strtoxL + + +Input: 1.23456589e-307 + +strtoxL consumes 15 bytes and returns 17 +with bits = #3c030000 b18cb5dc c22fd369 +printf("%.21Lg") gives 1.30149245314004923345e-4932 +g_xLfmt(0) gives 15 bytes: "1.23456589e-307" + +strtoIxL returns 17, consuming 15 bytes. +fI[0] = #3c030000 b18cb5dc c22fd369 += 1.30149245314004923345e-4932 +fI[1] = #3c030000 b18cb5dc c22fd36a += 1.30149245314004923382e-4932 +fI[0] == strtoxL + + +Input: 1.234567890123456789 + +strtoxL consumes 20 bytes and returns 17 +with bits = #3fff0000 9e065214 62cfdb8d +printf("%.21Lg") gives 7.88641440657246265535e-4933 +g_xLfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIxL returns 17, consuming 20 bytes. +fI[0] = #3fff0000 9e065214 62cfdb8d += 7.88641440657246265535e-4933 +fI[1] = #3fff0000 9e065214 62cfdb8e += 7.886414406572462659e-4933 +fI[0] == strtoxL + + +Input: 1.234567890123456789e301 + +strtoxL consumes 24 bytes and returns 33 +with bits = #43e70000 937a8baf ab20980c +printf("%.21Lg") gives 5.11635766619117643114e-4933 +g_xLfmt(0) gives 25 bytes: "1.234567890123456789e+301" + +strtoIxL returns 33, consuming 24 bytes. +fI[0] = #43e70000 937a8baf ab20980b += 5.1163576661911764275e-4933 +fI[1] = #43e70000 937a8baf ab20980c += 5.11635766619117643114e-4933 +fI[1] == strtoxL + + +Input: 1.234567890123456789e-301 + +strtoxL consumes 25 bytes and returns 33 +with bits = #3c170000 a953271a 5d069ad9 +printf("%.21Lg") gives 1.08545540462853463561e-4932 +g_xLfmt(0) gives 25 bytes: "1.234567890123456789e-301" + +strtoIxL returns 33, consuming 25 bytes. +fI[0] = #3c170000 a953271a 5d069ad8 += 1.08545540462853463524e-4932 +fI[1] = #3c170000 a953271a 5d069ad9 += 1.08545540462853463561e-4932 +fI[1] == strtoxL + + +Input: 1.234567890123456789e-321 + +strtoxL consumes 25 bytes and returns 33 +with bits = #3bd40000 f9e11b4c ea6dcce9 +printf("%.21Lg") gives 3.20133479952876185942e-4932 +g_xLfmt(0) gives 25 bytes: "1.234567890123456789e-321" + +strtoIxL returns 33, consuming 25 bytes. +fI[0] = #3bd40000 f9e11b4c ea6dcce8 += 3.20133479952876185905e-4932 +fI[1] = #3bd40000 f9e11b4c ea6dcce9 += 3.20133479952876185942e-4932 +fI[1] == strtoxL + + +Input: 1e23 + +strtoxL consumes 4 bytes and returns 1 +with bits = #404b0000 a968163f a57b400 +printf("%.21Lg") gives 1.08760331670538037378e-4932 +g_xLfmt(0) gives 5 bytes: "1e+23" + +strtoIxL returns 1, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1e310 + +strtoxL consumes 5 bytes and returns 33 +with bits = #44040000 de81e40a 34bcf50 +printf("%.21Lg") gives 2.48237171106260601618e-4932 +g_xLfmt(0) gives 6 bytes: "1e+310" + +strtoIxL returns 33, consuming 5 bytes. +fI[0] = #44040000 de81e40a 34bcf4f += 2.48237171106260601582e-4932 +fI[1] = #44040000 de81e40a 34bcf50 += 2.48237171106260601618e-4932 +fI[1] == strtoxL + + +Input: 9.0259718793241475e-277 + +strtoxL consumes 23 bytes and returns 33 +with bits = #3c690000 ffffffff fffffcf7 +printf("%.21Lg") gives 3.36210314311209322303e-4932 +g_xLfmt(0) gives 23 bytes: "9.0259718793241475e-277" + +strtoIxL returns 33, consuming 23 bytes. +fI[0] = #3c690000 ffffffff fffffcf6 += 3.36210314311209322267e-4932 +fI[1] = #3c690000 ffffffff fffffcf7 += 3.36210314311209322303e-4932 +fI[1] == strtoxL + + +Input: 9.025971879324147880346310405869e-277 + +strtoxL consumes 37 bytes and returns 17 +with bits = #3c6a0000 80000000 0 +printf("%.21Lg") gives 3.36210314311209350626e-4932 +g_xLfmt(0) gives 26 bytes: "9.0259718793241478803e-277" + +strtoIxL returns 17, consuming 37 bytes. +fI[0] = #3c6a0000 80000000 0 += 3.36210314311209350626e-4932 +fI[1] = #3c6a0000 80000000 1 += 3.64519953188247460253e-4951 +fI[0] == strtoxL + + +Input: 9.025971879324147880346310405868e-277 + +strtoxL consumes 37 bytes and returns 33 +with bits = #3c6a0000 80000000 0 +printf("%.21Lg") gives 3.36210314311209350626e-4932 +g_xLfmt(0) gives 26 bytes: "9.0259718793241478803e-277" + +strtoIxL returns 33, consuming 37 bytes. +fI[0] = #3c690000 ffffffff ffffffff += 3.3621031431120935059e-4932 +fI[1] = #3c6a0000 80000000 0 += 3.36210314311209350626e-4932 +fI[1] == strtoxL + + +Input: 2.2250738585072014e-308 + +strtoxL consumes 23 bytes and returns 17 +with bits = #3c010000 80000000 46 +printf("%.21Lg") gives 2.55163967231773222177e-4949 +g_xLfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoIxL returns 17, consuming 23 bytes. +fI[0] = #3c010000 80000000 46 += 2.55163967231773222177e-4949 +fI[1] = #3c010000 80000000 47 += 2.5880916676365569678e-4949 +fI[0] == strtoxL + + +Input: 2.2250738585072013e-308 + +strtoxL consumes 23 bytes and returns 17 +with bits = #3c000000 ffffffff fffffd4f +printf("%.21Lg") gives 3.36210314311209325511e-4932 +g_xLfmt(0) gives 23 bytes: "2.2250738585072013e-308" + +strtoIxL returns 17, consuming 23 bytes. +fI[0] = #3c000000 ffffffff fffffd4f += 3.36210314311209325511e-4932 +fI[1] = #3c000000 ffffffff fffffd50 += 3.36210314311209325547e-4932 +fI[0] == strtoxL + +Rounding mode for strtor... changed from 1 (nearest) to 0 (toward zero) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 8ccccccc cccccccc +printf("%.21Lg") gives 3.36210314311209350335e-4933 +g_xLfmt(0) gives 21 bytes: "1.0999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] = #3fff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[0] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 8ccccccc cccccccc +printf("%.21Lg") gives 3.36210314311209350335e-4933 +g_xLfmt(0) gives 22 bytes: "-1.0999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] = #bfff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 99999999 99999999 +printf("%.21Lg") gives 6.72420628622418701034e-4933 +g_xLfmt(0) gives 21 bytes: "1.1999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] = #3fff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[0] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 99999999 99999999 +printf("%.21Lg") gives 6.72420628622418701034e-4933 +g_xLfmt(0) gives 22 bytes: "-1.1999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] = #bfff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 3 bytes: "1.3" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] = #3fff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[0] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 4 bytes: "-1.3" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[1] = #bfff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 3 bytes: "1.4" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] = #3fff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[0] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 4 bytes: "-1.4" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[1] = #bfff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 cccccccc cccccccc +printf("%.21Lg") gives 2.01726188586725610347e-4932 +g_xLfmt(0) gives 21 bytes: "1.5999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] = #3fff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[0] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 cccccccc cccccccc +printf("%.21Lg") gives 2.01726188586725610347e-4932 +g_xLfmt(0) gives 22 bytes: "-1.5999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] = #bfff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 d9999999 99999999 +printf("%.21Lg") gives 2.35347220017846545417e-4932 +g_xLfmt(0) gives 21 bytes: "1.6999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] = #3fff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[0] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 d9999999 99999999 +printf("%.21Lg") gives 2.35347220017846545417e-4932 +g_xLfmt(0) gives 22 bytes: "-1.6999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] = #bfff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 3 bytes: "1.8" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] = #3fff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[0] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 4 bytes: "-1.8" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[1] = #bfff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 3 bytes: "1.9" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] = #3fff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[0] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 4 bytes: "-1.9" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[1] = #bfff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] == strtoxL + +Rounding mode for strtor... changed from 0 (toward zero) to 1 (nearest) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 8ccccccc cccccccd +printf("%.21Lg") gives 3.36210314311209350699e-4933 +g_xLfmt(0) gives 3 bytes: "1.1" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] = #3fff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 8ccccccc cccccccd +printf("%.21Lg") gives 3.36210314311209350699e-4933 +g_xLfmt(0) gives 4 bytes: "-1.1" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] = #bfff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[0] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 99999999 9999999a +printf("%.21Lg") gives 6.72420628622418701398e-4933 +g_xLfmt(0) gives 3 bytes: "1.2" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] = #3fff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 99999999 9999999a +printf("%.21Lg") gives 6.72420628622418701398e-4933 +g_xLfmt(0) gives 4 bytes: "-1.2" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] = #bfff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[0] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 3 bytes: "1.3" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] = #3fff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[0] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 4 bytes: "-1.3" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[1] = #bfff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 3 bytes: "1.4" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] = #3fff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[0] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 4 bytes: "-1.4" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[1] = #bfff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 cccccccc cccccccd +printf("%.21Lg") gives 2.01726188586725610383e-4932 +g_xLfmt(0) gives 3 bytes: "1.6" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] = #3fff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 cccccccc cccccccd +printf("%.21Lg") gives 2.01726188586725610383e-4932 +g_xLfmt(0) gives 4 bytes: "-1.6" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] = #bfff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[0] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 d9999999 9999999a +printf("%.21Lg") gives 2.35347220017846545453e-4932 +g_xLfmt(0) gives 3 bytes: "1.7" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] = #3fff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 d9999999 9999999a +printf("%.21Lg") gives 2.35347220017846545453e-4932 +g_xLfmt(0) gives 4 bytes: "-1.7" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] = #bfff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[0] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 3 bytes: "1.8" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] = #3fff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[0] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 4 bytes: "-1.8" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[1] = #bfff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 3 bytes: "1.9" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] = #3fff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[0] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 4 bytes: "-1.9" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[1] = #bfff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] == strtoxL + +Rounding mode for strtor... changed from 1 (nearest) to 2 (toward +Infinity) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 8ccccccc cccccccd +printf("%.21Lg") gives 3.36210314311209350699e-4933 +g_xLfmt(0) gives 3 bytes: "1.1" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] = #3fff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 8ccccccc cccccccc +printf("%.21Lg") gives 3.36210314311209350335e-4933 +g_xLfmt(0) gives 22 bytes: "-1.0999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] = #bfff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 99999999 9999999a +printf("%.21Lg") gives 6.72420628622418701398e-4933 +g_xLfmt(0) gives 3 bytes: "1.2" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] = #3fff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 99999999 99999999 +printf("%.21Lg") gives 6.72420628622418701034e-4933 +g_xLfmt(0) gives 22 bytes: "-1.1999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] = #bfff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 a6666666 66666667 +printf("%.21Lg") gives 1.0086309429336280521e-4932 +g_xLfmt(0) gives 21 bytes: "1.3000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] = #3fff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[1] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 4 bytes: "-1.3" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[1] = #bfff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 b3333333 33333334 +printf("%.21Lg") gives 1.3448412572448374028e-4932 +g_xLfmt(0) gives 21 bytes: "1.4000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] = #3fff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[1] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 4 bytes: "-1.4" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[1] = #bfff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 cccccccc cccccccd +printf("%.21Lg") gives 2.01726188586725610383e-4932 +g_xLfmt(0) gives 3 bytes: "1.6" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] = #3fff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 cccccccc cccccccc +printf("%.21Lg") gives 2.01726188586725610347e-4932 +g_xLfmt(0) gives 22 bytes: "-1.5999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] = #bfff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 d9999999 9999999a +printf("%.21Lg") gives 2.35347220017846545453e-4932 +g_xLfmt(0) gives 3 bytes: "1.7" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] = #3fff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 d9999999 99999999 +printf("%.21Lg") gives 2.35347220017846545417e-4932 +g_xLfmt(0) gives 22 bytes: "-1.6999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] = #bfff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 e6666666 66666667 +printf("%.21Lg") gives 2.68968251448967480523e-4932 +g_xLfmt(0) gives 21 bytes: "1.8000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] = #3fff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[1] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 4 bytes: "-1.8" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[1] = #bfff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 f3333333 33333334 +printf("%.21Lg") gives 3.02589282880088415593e-4932 +g_xLfmt(0) gives 21 bytes: "1.9000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] = #3fff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[1] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 4 bytes: "-1.9" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[1] = #bfff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] == strtoxL + +Rounding mode for strtor... changed from 2 (toward +Infinity) to 3 (toward -Infinity) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 8ccccccc cccccccc +printf("%.21Lg") gives 3.36210314311209350335e-4933 +g_xLfmt(0) gives 21 bytes: "1.0999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] = #3fff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[0] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 8ccccccc cccccccd +printf("%.21Lg") gives 3.36210314311209350699e-4933 +g_xLfmt(0) gives 4 bytes: "-1.1" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] = #bfff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[0] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 99999999 99999999 +printf("%.21Lg") gives 6.72420628622418701034e-4933 +g_xLfmt(0) gives 21 bytes: "1.1999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] = #3fff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[0] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 99999999 9999999a +printf("%.21Lg") gives 6.72420628622418701398e-4933 +g_xLfmt(0) gives 4 bytes: "-1.2" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] = #bfff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[0] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 3 bytes: "1.3" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] = #3fff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[0] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 a6666666 66666667 +printf("%.21Lg") gives 1.0086309429336280521e-4932 +g_xLfmt(0) gives 22 bytes: "-1.3000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[1] = #bfff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[0] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 3 bytes: "1.4" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] = #3fff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[0] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 b3333333 33333334 +printf("%.21Lg") gives 1.3448412572448374028e-4932 +g_xLfmt(0) gives 22 bytes: "-1.4000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[1] = #bfff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[0] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 cccccccc cccccccc +printf("%.21Lg") gives 2.01726188586725610347e-4932 +g_xLfmt(0) gives 21 bytes: "1.5999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] = #3fff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[0] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 cccccccc cccccccd +printf("%.21Lg") gives 2.01726188586725610383e-4932 +g_xLfmt(0) gives 4 bytes: "-1.6" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] = #bfff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[0] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 d9999999 99999999 +printf("%.21Lg") gives 2.35347220017846545417e-4932 +g_xLfmt(0) gives 21 bytes: "1.6999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] = #3fff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[0] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 d9999999 9999999a +printf("%.21Lg") gives 2.35347220017846545453e-4932 +g_xLfmt(0) gives 4 bytes: "-1.7" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] = #bfff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[0] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 3 bytes: "1.8" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] = #3fff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[0] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 e6666666 66666667 +printf("%.21Lg") gives 2.68968251448967480523e-4932 +g_xLfmt(0) gives 22 bytes: "-1.8000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[1] = #bfff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[0] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 3 bytes: "1.9" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] = #3fff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[0] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 f3333333 33333334 +printf("%.21Lg") gives 3.02589282880088415593e-4932 +g_xLfmt(0) gives 22 bytes: "-1.9000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[1] = #bfff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[0] == strtoxL + diff --git a/lib/libc/gdtoa/test/pfLqtestnos b/lib/libc/gdtoa/test/pfLqtestnos new file mode 100644 index 000000000..068092337 --- /dev/null +++ b/lib/libc/gdtoa/test/pfLqtestnos @@ -0,0 +1,13 @@ +%.8a 1.23 +%.7a +%.2a +%.La 1.23 +%.20Lqa 1.23 +%La 3e27 +%La 1.7e27 +%Lqa 3e48 +%Lqa 1e49 +1.5 +2.5 +4.5 +8.5 diff --git a/lib/libc/gdtoa/test/pftest.c b/lib/libc/gdtoa/test/pftest.c new file mode 100644 index 000000000..99d78ee45 --- /dev/null +++ b/lib/libc/gdtoa/test/pftest.c @@ -0,0 +1,158 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 2009 by David M. Gay +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +source-code copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation. + +THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 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. + +****************************************************************/ +#include "stdio1.h" +#include "gdtoa.h" +#include + +#undef allow_Quad +#undef want_Quad +#undef want_Ux +#define want_LD +typedef union Ud {double x; unsigned int u[2]; } Ud; +#ifdef __x86_64 /*{{*/ +#define want_Ux +#ifndef NO_GDTOA_i386_Quad /*{*/ +typedef union UQ {__float128 x; unsigned int u[4]; } UQ; +#define allow_Quad(x) x +#define want_Quad +#endif /*}*/ +#else /*}{*/ +#ifdef __i386 /*{{*/ +#define want_Ux +#else /*}{*/ +#ifdef __sparc /*{{*/ +typedef union UQ {long double x; unsigned int u[4]; } Ux; +#else /*}{*/ +#ifdef __INTEL_COMPILER /*{*/ +#undef want_Quad +#undef want_Ux +#undef want_LD +#endif /*}*/ +#endif /*}}*/ +#endif /*}}*/ +#endif /*}}*/ + +#ifndef allow_Quad +#define allow_Quad(x) /*nothing*/ +#endif + +#ifdef want_Ux /*{{*/ +typedef union Ux {long double x; unsigned short u[5]; } Ux; +#else /*}{*/ +#ifdef __sparc +#define want_Ux +#endif +#endif /*}}*/ + + int +main(void) +{ + Ud d; + allow_Quad(UQ q;) + char *b, buf[256], fmt[32], *s; +#ifdef want_Ux + Ux x; + x.x = 0.; +#endif + int k; + + k = 0; + strcpy(fmt, "%.g"); + d.x = 0.; + allow_Quad(q.x = 0.;) + while(fgets(buf, sizeof(buf), stdin)) { + for(b = buf; *b && *b != '\n'; ++b); + *b = 0; + if (b == buf) + continue; + b = buf; + if (*b == '%') { + for(k = 0; *b > ' '; ++b) +#ifdef want_LD /*{{*/ + switch(*b) { + case 'L': + k = 1; +#ifdef want_Quad + break; + case 'q': + if (k >= 1) + k = 2; +#endif + } +#else /*}{*/ + ; +#endif /*}}*/ + if (*b) + *b++ = 0; + if (b - buf < sizeof(fmt)) { + strcpy(fmt, buf); + } + } + if (*b) { + switch(k) { + case 0: + d.x = strtod(b,&s); + break; + case 1: +#ifdef want_Ux +#ifdef __sparc + strtopQ(b,&s,&x.x); +#else + strtopx(b,&s,&x.x); +#endif +#else + strtopQ(b,&s,&q.x); +#endif + break; + allow_Quad(case 2: strtopQ(b,&s,&q.x);) + } + if (*s) + printf("Ignoring \"%s\"\n", s); + } + switch(k) { + case 0: + printf("d.x = %.g = #%x %x; %s ==> ", d.x, d.u[1], d.u[0], fmt); + printf(fmt, d.x); + break; + case 1: +#ifdef __sparc + printf("x.x = %.Lg = #%x %x %x %x; %s ==> ", x.x, + x.u[0], x.u[1], x.u[2], x.u[3], fmt); +#else + printf("x.x = %.Lg = #%x %x %x %x %x; %s ==> ", x.x, + x.u[4], x.u[3], x.u[2], x.u[1], x.u[0], fmt); +#endif + printf(fmt, x.x); +#ifdef want_Quad + break; + case 2: + printf("q.x = %.Lqg = #%x %x %x %x; %s ==> ", q.x, + q.u[3], q.u[2], q.u[1], q.u[0], fmt); + printf(fmt, q.x); +#endif + } + putchar('\n'); + } + return 0; + } diff --git a/lib/libc/gdtoa/test/pftestLq.out b/lib/libc/gdtoa/test/pftestLq.out new file mode 100644 index 000000000..0bcec7461 --- /dev/null +++ b/lib/libc/gdtoa/test/pftestLq.out @@ -0,0 +1,13 @@ +d.x = 1.23 = #3ff3ae14 7ae147ae; %.8a ==> 0x1.3ae147aep+0 +d.x = 1.23 = #3ff3ae14 7ae147ae; %.7a ==> 0x1.3ae147bp+0 +d.x = 1.23 = #3ff3ae14 7ae147ae; %.2a ==> 0x1.3bp+0 +x.x = 1.23 = #3fff 9d70 a3d7 a3d 70a4; %.La ==> 0xap-3 +q.x = 1.23 = #3fff3ae1 47ae147a e147ae14 7ae147ae; %.20Lqa ==> 0x1.3ae147ae147ae147ae14p+0 +x.x = 3e+27 = #405a 9b18 ab5d f718 b6c; %La ==> 0x9.b18ab5df7180b6cp+88 +x.x = 1.7e+27 = #4059 afc6 a015 291b 4024; %La ==> 0xa.fc6a015291b4024p+87 +q.x = 3e+48 = #40a006be 53879565 60c1e1a9 9c13ee2; %Lqa ==> 0x1.06be5387956560c1e1a909c13ee2p+161 +q.x = 1e+49 = #40a1b5e7 e08ca3a8 f6987819 baecbe22; %Lqa ==> 0x1.b5e7e08ca3a8f6987819baecbe22p+162 +q.x = 1.5 = #3fff8000 0 0 0; %Lqa ==> 0x1.8p+0 +q.x = 2.5 = #40004000 0 0 0; %Lqa ==> 0x1.4p+1 +q.x = 4.5 = #40012000 0 0 0; %Lqa ==> 0x1.2p+2 +q.x = 8.5 = #40021000 0 0 0; %Lqa ==> 0x1.1p+3 diff --git a/lib/libc/gdtoa/test/pftestQ.out b/lib/libc/gdtoa/test/pftestQ.out new file mode 100644 index 000000000..8c42afe69 --- /dev/null +++ b/lib/libc/gdtoa/test/pftestQ.out @@ -0,0 +1,15 @@ +d.x = 1.23 = #7ae147ae 3ff3ae14; %.8a ==> 0x1.3ae147aep+0 +d.x = 1.23 = #7ae147ae 3ff3ae14; %.7a ==> 0x1.3ae147bp+0 +d.x = 1.23 = #7ae147ae 3ff3ae14; %.2a ==> 0x1.3bp+0 +x.x = 1.23 = #3fff3ae1 47ae147a e147ae14 7ae147ae; %.La ==> 0x1p+0 +x.x = 1.23 = #3fff3ae1 47ae147a e147ae14 7ae147ae; %.20La ==> 0x1.3ae147ae147ae147ae14p+0 +x.x = 3e+27 = #405a3631 56bbee30 16d70000 0; %La ==> 0x1.363156bbee3016d7p+91 +x.x = 1.7e+27 = #40595f8d 402a5236 80490000 0; %La ==> 0x1.5f8d402a52368049p+90 +d.x = 1.5 = #0 3ff80000; %a ==> 0x1.8p+0 +d.x = 2.5 = #0 40040000; %a ==> 0x1.4p+1 +d.x = 4.5 = #0 40120000; %a ==> 0x1.2p+2 +d.x = 8.5 = #0 40210000; %a ==> 0x1.1p+3 +x.x = 1.5 = #3fff8000 0 0 0; %La ==> 0x1.8p+0 +x.x = 2.5 = #40004000 0 0 0; %La ==> 0x1.4p+1 +x.x = 4.5 = #40012000 0 0 0; %La ==> 0x1.2p+2 +x.x = 8.5 = #40021000 0 0 0; %La ==> 0x1.1p+3 diff --git a/lib/libc/gdtoa/test/pftestnos b/lib/libc/gdtoa/test/pftestnos new file mode 100644 index 000000000..7b3010a8b --- /dev/null +++ b/lib/libc/gdtoa/test/pftestnos @@ -0,0 +1,15 @@ +%.8a 1.23 +%.7a +%.2a +%.La 1.23 +%.20La 1.23 +%La 3e27 +%La 1.7e27 +%a 1.5 +2.5 +4.5 +8.5 +%La 1.5 +2.5 +4.5 +8.5 diff --git a/lib/libc/gdtoa/test/pftestx.out b/lib/libc/gdtoa/test/pftestx.out new file mode 100644 index 000000000..15a08d362 --- /dev/null +++ b/lib/libc/gdtoa/test/pftestx.out @@ -0,0 +1,15 @@ +d.x = 1.23 = #3ff3ae14 7ae147ae; %.8a ==> 0x1.3ae147aep+0 +d.x = 1.23 = #3ff3ae14 7ae147ae; %.7a ==> 0x1.3ae147bp+0 +d.x = 1.23 = #3ff3ae14 7ae147ae; %.2a ==> 0x1.3bp+0 +x.x = 1.23 = #3fff 9d70 a3d7 a3d 70a4; %.La ==> 0xap-3 +x.x = 1.23 = #3fff 9d70 a3d7 a3d 70a4; %.20La ==> 0x9.d70a3d70a3d70a4p-3 +x.x = 3e+27 = #405a 9b18 ab5d f718 b6c; %La ==> 0x9.b18ab5df7180b6cp+88 +x.x = 1.7e+27 = #4059 afc6 a015 291b 4024; %La ==> 0xa.fc6a015291b4024p+87 +d.x = 1.5 = #3ff80000 0; %a ==> 0x1.8p+0 +d.x = 2.5 = #40040000 0; %a ==> 0x1.4p+1 +d.x = 4.5 = #40120000 0; %a ==> 0x1.2p+2 +d.x = 8.5 = #40210000 0; %a ==> 0x1.1p+3 +x.x = 1.5 = #3fff c000 0 0 0; %La ==> 0xcp-3 +x.x = 2.5 = #4000 a000 0 0 0; %La ==> 0xap-2 +x.x = 4.5 = #4001 9000 0 0 0; %La ==> 0x9p-1 +x.x = 8.5 = #4002 8800 0 0 0; %La ==> 0x8.8p+0 diff --git a/lib/libc/gdtoa/test/rtestnos b/lib/libc/gdtoa/test/rtestnos new file mode 100644 index 000000000..cde95b78a --- /dev/null +++ b/lib/libc/gdtoa/test/rtestnos @@ -0,0 +1,76 @@ +r0 +1.1 +-1.1 +1.2 +-1.2 +1.3 +-1.3 +1.4 +-1.4 +1.5 +-1.5 +1.6 +-1.6 +1.7 +-1.7 +1.8 +-1.8 +1.9 +-1.9 +r1 +1.1 +-1.1 +1.2 +-1.2 +1.3 +-1.3 +1.4 +-1.4 +1.5 +-1.5 +1.6 +-1.6 +1.7 +-1.7 +1.8 +-1.8 +1.9 +-1.9 +r2 +1.1 +-1.1 +1.2 +-1.2 +1.3 +-1.3 +1.4 +-1.4 +1.5 +-1.5 +1.6 +-1.6 +1.7 +-1.7 +1.8 +-1.8 +1.9 +-1.9 +r3 +1.1 +-1.1 +1.2 +-1.2 +1.3 +-1.3 +1.4 +-1.4 +1.5 +-1.5 +1.6 +-1.6 +1.7 +-1.7 +1.8 +-1.8 +1.9 +-1.9 diff --git a/lib/libc/gdtoa/test/strtoIdSI.c b/lib/libc/gdtoa/test/strtoIdSI.c new file mode 100644 index 000000000..c5342edfa --- /dev/null +++ b/lib/libc/gdtoa/test/strtoIdSI.c @@ -0,0 +1,2 @@ +#define Sudden_Underflow +#include "../strtoId.c" diff --git a/lib/libc/gdtoa/test/strtoIddSI.c b/lib/libc/gdtoa/test/strtoIddSI.c new file mode 100644 index 000000000..2966259a8 --- /dev/null +++ b/lib/libc/gdtoa/test/strtoIddSI.c @@ -0,0 +1,2 @@ +#define Sudden_Underflow +#include "../strtoIdd.c" diff --git a/lib/libc/gdtoa/test/strtodISI.c b/lib/libc/gdtoa/test/strtodISI.c new file mode 100644 index 000000000..66d2addfe --- /dev/null +++ b/lib/libc/gdtoa/test/strtodISI.c @@ -0,0 +1,2 @@ +#define Sudden_Underflow +#include "../strtodI.c" diff --git a/lib/libc/gdtoa/test/strtodt.c b/lib/libc/gdtoa/test/strtodt.c new file mode 100644 index 000000000..2983615c0 --- /dev/null +++ b/lib/libc/gdtoa/test/strtodt.c @@ -0,0 +1,138 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +/* Test strtod. */ + +/* On stdin, read triples: d x y: + * d = decimal string + * x = high-order Hex value expected from strtod + * y = low-order Hex value + * Complain about errors. + */ + +#include "gdtoa.h" /* for ULong */ +#include +#include +#include + + static int W0, W1; + typedef union { + double d; + ULong L[2]; + } U; + +#define UL (unsigned long) + + static int +process(char *fname, FILE *f) +{ + U a, b; + char buf[2048]; + char *s, *s1, *se; + int line, n; + + line = n = 0; + + top: + while(fgets(s = buf, sizeof(buf), f)) { + line++; + while(*s <= ' ') + if (!*s++) + goto top; /* break 2 */ + if (*s == '#') + continue; + while(*s > ' ') + s++; + /* if (sscanf(s,"\t%lx\t%lx", &a.L[0], &a.L[1]) != 2) */ + if ((a.L[0] = (ULong)strtoul(s, &s1,16), s1 <= s) + || (a.L[1] = (ULong)strtoul(s1,&se,16), se <= s1)) { + printf("Badly formatted line %d of %s\n", + line, fname); + n++; + continue; + } + b.d = strtod(buf,0); + if (b.L[W0] != a.L[0] || b.L[W1] != a.L[1]) { + n++; + printf("Line %d of %s: got %lx %lx; expected %lx %lx\n", + line, fname, UL b.L[W0], UL b.L[W1], UL a.L[0], UL a.L[1]); + } + } + return n; + } + + int +main(int argc, char **argv) +{ + FILE *f; + char *prog, *s; + int n, rc; + U u; + + prog = argv[0]; + if (argc == 2 && !strcmp(argv[1],"-?")) { + fprintf(stderr, "Usage: %s [file [file...]]\n" + "\tto read data file(s) of tab-separated triples d x y with\n" + "\t\td decimal string\n" + "\t\tx = high-order Hex value expected from strtod\n" + "\t\ty = low-order Hex value\n" + "\tComplain about errors by strtod.\n" + "\tIf no files, read triples from stdin.\n", + prog); + return 0; + } + + /* determine endian-ness */ + + u.d = 1.; + W0 = u.L[0] == 0; + W1 = 1 - W0; + + /* test */ + + n = rc = 0; + if (argc <= 1) + n = process("", stdin); + else + while((s = *++argv)) + if ((f = fopen(s,"r"))) { + n += process(s, f); + fclose(f); + } + else { + rc = 2; + fprintf(stderr, "Cannot open %s\n", s); + } + printf("%d bad conversions\n", n); + if (n) + rc |= 1; + return rc; + } diff --git a/lib/libc/gdtoa/test/strtopddSI.c b/lib/libc/gdtoa/test/strtopddSI.c new file mode 100644 index 000000000..d2004e5b7 --- /dev/null +++ b/lib/libc/gdtoa/test/strtopddSI.c @@ -0,0 +1,2 @@ +#define Sudden_Underflow +#include "../strtopdd.c" diff --git a/lib/libc/gdtoa/test/strtorddSI.c b/lib/libc/gdtoa/test/strtorddSI.c new file mode 100644 index 000000000..dd6a3812e --- /dev/null +++ b/lib/libc/gdtoa/test/strtorddSI.c @@ -0,0 +1,2 @@ +#define Sudden_Underflow +#include "../strtordd.c" diff --git a/lib/libc/gdtoa/test/testnos b/lib/libc/gdtoa/test/testnos new file mode 100644 index 000000000..a36a98676 --- /dev/null +++ b/lib/libc/gdtoa/test/testnos @@ -0,0 +1,28 @@ +1.23 +1.23e+20 +1.23e-20 +1.23456789 +1.23456589e+20 +1.23e+30 +1.23e-30 +1.23456789e-20 +1.23456789e-30 +1.234567890123456789 +1.23456789012345678901234567890123456789 +1.23e306 +1.23e-306 +1.23e-320 +1.23e-20 +1.23456789e307 +1.23456589e-307 +1.234567890123456789 +1.234567890123456789e301 +1.234567890123456789e-301 +1.234567890123456789e-321 +1e23 +1e310 +9.0259718793241475e-277 +9.025971879324147880346310405869e-277 +9.025971879324147880346310405868e-277 +2.2250738585072014e-308 +2.2250738585072013e-308 diff --git a/lib/libc/gdtoa/test/testnos1 b/lib/libc/gdtoa/test/testnos1 new file mode 100644 index 000000000..d734b35db --- /dev/null +++ b/lib/libc/gdtoa/test/testnos1 @@ -0,0 +1,20 @@ +1.23:2 6 +1.23:4 6 +1.23e+20:2 6 +1.23e+20:4 6 +1.23e-20:2 6 +1.23e-20:4 6 +1.23456789:2 6 +1.23456789:4 6 +1.23456589e+20:2 6 +1.23456589e+20:4 6 +1.23456789e-20:2 6 +1.23456789e-20:4 6 +1234565:2 6 +1234565:4 6 +1.234565:2 6 +1.234565:4 6 +1.234565e+20:2 6 +1.234565e+20:4 6 +1.234565e-20:2 6 +1.234565e-20:4 6 diff --git a/lib/libc/gdtoa/test/testnos3 b/lib/libc/gdtoa/test/testnos3 new file mode 100644 index 000000000..2a7cf7944 --- /dev/null +++ b/lib/libc/gdtoa/test/testnos3 @@ -0,0 +1,352 @@ +# Test triples for strtodt, derived from Fred Tydeman's posting +# of 26 February 1996 to comp.arch.arithmetic. + +9e0306 7fa9a202 8368022e +4e-079 2fa7b6d7 1d20b96c +7e-261 9eb8d7e 32be6396 +6e-025 3ae7361c b863de62 +7e-161 1eaf7e0d b3799aa3 +7e0289 7c1cbb54 7777a285 +5e0079 507afcef 51f0fb5f +1e0080 508afcef 51f0fb5f +7e-303 1333391 31c46f8b +5e0152 5fa317e5 ef3ab327 +5e0125 5a07a2ec c414a03f +2e0126 5a27a2ec c414a03f +7e-141 22d5570f 59bd178c +4e-192 18323ff0 6eea847a +9e0043 49102498 ea6df0c4 +1e0303 7ed754e3 1cd072da +95e-089 2dde3cbc 9907fdc8 +85e0194 689d1c26 db7d0dae +69e0267 77c0b7cb 60c994da +97e-019 3c665dde 8e688ba6 +37e0046 49d033d7 eca0adef +74e0046 49e033d7 eca0adef +61e-099 2bc0ad83 6f269a17 +53e-208 151b39ae 1909c31b +93e-234 fc27b2e 4f210075 +79e-095 2c9a5db8 12948281 +87e-274 772d36c f48e7abd +83e0025 4585747a b143e353 +17e-036 38b698cc dc60015a +53e0033 47246a34 18629ef6 +51e-074 30ecd5be e57763e6 +63e-022 3bbdc03b 8fd7016a +839e0143 5e3ae03f 245703e2 +749e-182 1abf1472 7744c63e +999e-026 3b282782 afe1869e +345e0266 77b0b7cb 60c994da +914e-102 2b5ffc81 bc29f02b +829e0102 55b7221a 79cdd1d9 +307e0090 5322d6b1 83fe4b55 +859e0182 6654374d 8b87ac63 +283e0085 5216c309 24bab4b +589e0187 675526be 9c22eb17 +302e0176 64fdcf7d f8f573b7 +604e0176 650dcf7d f8f573b7 +761e-244 de03cea 3586452e +647e0230 7044d64d 4079150c +755e0174 64a7d931 93f78fc6 +255e-075 30dcd5be e57763e6 +3391e0055 4c159bd3 ad46e346 +4147e-015 3d923d1b 5eb1d778 +3996e-026 3b482782 afe1869e +1998e-026 3b382782 afe1869e +3338e-296 335519a c5142aab +1669e-296 325519a c5142aab +8699e-276 772d2df 246ecd2d +5311e0243 73284e91 f4aa0fdb +7903e-096 2cd07c2d 27a5b989 +7611e-226 11d19b87 44033457 +3257e0058 4cb444b3 4a6fb3eb +6514e0058 4cc444b3 4a6fb3eb +3571e0263 77462644 c61d41aa +7142e0263 77562644 c61d41aa +5311e0242 72f3720e 5d54d97c +1617e-063 3384c98f ce16152e +51881e0037 4897d295 dc76da4 +31441e-118 285ef890 f5de4c86 +30179e0079 5143e272 a77478e8 +60358e0079 5153e272 a77478e8 +63876e-020 3cc70385 6844bdbf +31938e-020 3cb70385 6844bdbf +46073e-032 3a42405b 773fbdf3 +32941e0051 4b757eb8 ad52a5c9 +82081e0041 49770105 df3d47cb +38701e-215 1440492a 4a8a37fd +62745e0047 4ab0c52f e6dc6a1b +12549e0048 4ac0c52f e6dc6a1b +64009e-183 1af099b3 93b84832 +89275e0261 77262644 c61d41aa +75859e0025 46232645 e1ba93f0 +57533e0287 7c8272ed 2307f56a +584169e0229 70ad6570 59dc79aa +940189e-112 29eb99d6 240c1a28 +416121e0197 6a00fd07 ed297f80 +832242e0197 6a10fd07 ed297f80 +584738e0076 50e8a85e b277e645 +933587e-140 241b2487 28b9c117 +252601e0121 5a2dda59 2e398dd7 +358423e0274 79f9463b 59b8f2bd +892771e-213 14f25818 c7294f27 +410405e0040 49670105 df3d47cb +928609e-261 afbe2dd 66200bef +302276e-254 c55a462 d91c6ab3 +920657e-023 3c653a99 85dbde6c +609019e-025 3bf1f99e 11ea0a24 +252601e0120 59f7e1e0 f1c7a4ac +654839e-060 34b00e7d b3b3f242 +8823691e0130 5c5e597c b94b7ae +2920845e0228 709d6570 59dc79aa +9210917e0080 51fda232 347e6032 +5800419e-303 26e58ff a48f4fce +6119898e-243 ee3ecf2 2ea07863 +3059949e-243 ed3ecf2 2ea07863 +2572231e0223 6f90f73b e1dff9ad +5444097e-021 3cf8849d d33c95af +5783893e-127 26f7e590 2ce0e151 +3865421e-225 1295d4fe 53afec65 +4590831e0156 61b4689b 4a5fa201 +9181662e0156 61c4689b 4a5fa201 +5906361e-027 3bbbe45a 312d08a0 +7315057e0235 7225f0d4 8362a72 +9088115e0106 5762e51a 84a3c6a0 +1817623e0107 5772e51a 84a3c6a0 +44118455e0129 5c4e597c b94b7ae +35282041e0293 7e5512d5 273e62e8 +31279898e-291 5129b01 b6885d36 +15639949e-291 5029b01 b6885d36 +27966061e0145 5f955bcf 72fd10f9 +55932122e0145 5fa55bcf 72fd10f9 +70176353e-053 36900683 a21de855 +40277543e-032 3adf29ca ff893b1 +50609263e0157 622193af f1f1c8e3 +66094077e0077 518b37c4 b7928317 +84863171e0114 59406e98 f5ec8f37 +89396333e0264 786526f0 61ca9053 +87575437e-309 16e0732 602056c +78693511e-044 3870bc7b 7603a2ca +90285923e-206 16d14700 83f89d48 +30155207e-030 3b423a4a d20748a2 +245540327e0121 5acc569e 968e0944 +263125459e0287 7d44997a 298b2f2e +566446538e-257 c64472b a9550e86 +283223269e-257 c54472b a9550e86 +245540327e0122 5b01b623 1e18c5cb +491080654e0122 5b11b623 1e18c5cb +971212611e-126 27a397d3 c9745d2f +229058583e0052 4c76ce94 febdc7a5 +325270231e0039 49cc7ccf 90c9f8ab +989648089e-035 3a8880a3 d515e849 +653777767e0273 7a720223 f2b3a881 +923091487e0209 6d30bc60 e6896717 +526250918e0288 7d89bfd8 b3edfafa +350301748e-309 18e0732 602056c +741111169e-203 17a14fe7 daf8f3ae +667284113e-240 ff09355 f8050c02 +1227701635e0120 5abc569e 968e0944 +9981396317e-182 1c38afe1 a2a66aa +5232604057e-298 41465b8 96c24520 +5572170023e-088 2fb08478 22f765b2 +1964322616e0122 5b31b623 1e18c5cb +3928645232e0122 5b41b623 1e18c5cb +8715380633e-058 35f4614c 3219891f +4856063055e-127 279397d3 c9745d2f +8336960483e-153 223a06a1 24b95e1 +1007046393e-155 21a01891 fc4717fd +5378822089e-176 1d695fd4 c88d4b1b +5981342308e-190 1a83db11 ac608107 +7214782613e-086 3020b552 d2edcdea +5458466829e0142 5f70acde 6a98eb4c +9078555839e-109 2b5fc575 867314ee +6418488827e0079 526021f1 4ed7b3fa +65325840981e0069 5081a151 ddbd3c4a +49573485983e0089 54a221bd 871d2cf4 +46275205733e0074 51830e6c 7d4e3480 +92550411466e0074 51930e6c 7d4e3480 +41129842097e-202 1832c3e7 2d179607 +93227267727e-049 380960fe 8d5847f +41297294357e0185 688c4943 7fccfadb +41534892987e-067 343a1266 6477886d +42333842451e0201 6be0189a 26df575f +78564021519e-227 13115551 5fd37265 +53587107423e-061 35800a19 a3ffd981 +53827010643e-200 18a32fa6 9a69bd6d +83356057653e0193 6a4544e6 daee2a18 +45256834646e-118 29a541ec dfd48694 +45392779195e-110 2b4fc575 867314ee +23934638219e0291 7e81deaf 40ead9a0 +995779191233e0113 59e2d44e dcc51304 +997422852243e-265 b676688 faee99bc +653532977297e-123 28d925a0 aabcdc68 +938885684947e0147 60f11894 b202e9f4 +619534293513e0124 5c210c20 303fe0f1 +539879452414e-042 39a5e66d c3d6bdb5 +742522891517e0259 782c1c35 2fc3c309 +254901016865e-022 3dbc06d3 66394441 +685763015669e0280 7c85fd7a a44d9477 +384865004907e-285 72aa65b 58639e69 +286556458711e0081 5321958b 36c5102b +573112917422e0081 5331958b 36c5102b +769525178383e-150 234253ec e161420 +416780288265e0192 6a3544e6 daee2a18 +226963895975e-111 2b3fc575 867314ee +665592809339e0063 4f778b65 16c2b478 +3891901811465e0217 6f99ab82 61990292 +4764593340755e0069 50e4177a 9915fbf8 +6336156586177e0269 7a7173f7 6c63b792 +8233559360849e0095 56566fee 5649a7a +3662265515198e-107 2c538e6e dd48f2a3 +1831132757599e-107 2c438e6e dd48f2a3 +7812878489261e-179 1d726dae 7bbeda75 +6363857920591e0145 60b28a61 cf9483b7 +8811915538555e0082 53a51f50 8b287ae7 +9997878507563e-195 1a253db2 fea1ea31 +9224786422069e-291 634ee5d 56b32957 +6284426329974e-294 58d3409 dfbca26f +9199302046091e-062 35c13597 2630774c +6070482281213e-122 29423fa9 e6fcf47e +2780161250963e-301 405acc2 53064c2 +8233559360849e0094 5621f324 d11d4862 +72027097041701e0206 6d946778 12d3a606 +97297545286625e0215 6f79ab82 61990292 +99021992302453e-025 3da5c671 4def374c +54104687080198e-022 3e373cdf 8db7a7bc +33519685743233e0089 5537f203 339c9629 +67039371486466e0089 5547f203 339c9629 +39064392446305e-180 1d626dae 7bbeda75 +17796979903653e0261 78e072f3 819c1321 +28921916763211e0038 4a9eebab e0957af3 +87605699161665e0155 6302920f 96e7f9ef +41921560615349e-067 34d9b2a5 c4041e4b +80527976643809e0061 4f7c7c5a ea080a49 +72335858886654e-159 21cce77c 2b3328fc +52656615219377e0102 57f561de f4a9ee32 +15400733123779e-072 33b8bf7e 7fa6f02a +77003665618895e-073 33a8bf7e 7fa6f02a +475603213226859e-042 3a42d730 88f4050a +972708181182949e0116 5b218a7f 36172332 +246411729980464e-071 342eef5e 1f90ac34 +123205864990232e-071 341eef5e 1f90ac34 +609610927149051e-255 e104273 b18918b1 +475603213226859e-041 3a778cfc ab31064d +672574798934795e0065 508226c6 84c87261 +134514959786959e0066 509226c6 84c87261 +294897574603217e-151 2395f2df 5e675a0f +723047919080275e0036 4a7eebab e0957af3 +660191429952702e-088 30bddc7e 975c5045 +330095714976351e-088 30addc7e 975c5045 +578686871093232e-159 21fce77c 2b3328fc +144671717773308e-159 21dce77c 2b3328fc +385018328094475e-074 3398bf7e 7fa6f02a +330095714976351e-089 3077e398 7916a69e +2215901545757777e-212 171a80a6 e566428c +1702061899637397e-276 9cacc46 749dccfe +1864950924021923e0213 6f53ae60 753af6ca +3729901848043846e0213 6f63ae60 753af6ca +7487252720986826e-165 20f8823a 57adbef9 +3743626360493413e-165 20e8823a 57adbef9 +4988915232824583e0119 5be5f6de 9d5d6b5b +3771476185376383e0277 7cae3c14 d6916ce9 +6182410494241627e-119 2a81b964 58445d07 +2572981889477453e0142 609dfc11 fbf46087 +7793560217139653e0051 4dd28046 1b856ec5 +9163942927285259e-202 194fe601 457dce4d +6353227084707473e0155 63650aff 653ffe8a +4431803091515554e-211 17609068 4f5fe998 +9324754620109615e0211 6f0f7d67 21f7f144 +8870461176410409e0263 79d90529 a37b7e22 +90372559027740405e0143 612491da ad0ba280 +18074511805548081e0146 61a011f2 d73116f4 +54897030182071313e0029 496ec556 66d8f9ec +76232626624829156e-032 3ccb7738 11e75fe +59898021767894608e-165 2128823a 57adbef9 +29949010883947304e-165 2118823a 57adbef9 +26153245263757307e0049 4d83de00 5bd620df +27176258005319167e-261 d27c074 7bd76fa1 +18074511805548081e0147 61d4166f 8cfd5cb1 +24691002732654881e-115 2b759a27 83ce70ab +58483921078398283e0057 4f408ce4 99519ce3 +64409240769861689e-159 22692238 f7987779 +94080055902682397e-242 11364981 e39e66ca +31766135423537365e0154 63550aff 653ffe8a +68985865317742005e0164 657a999d dec72aca +13797173063548401e0165 658a999d dec72aca +902042358290366539e-281 9522dc0 1ca1cb8c +238296178309629163e0272 7c038fd9 3f1f5342 +783308178698887621e0226 72925ae6 2cb346d8 +439176241456570504e0029 499ec556 66d8f9ec +899810892172646163e0283 7e6adf51 fa055e03 +926145344610700019e-225 14f307a6 7f1f69ff +653831131593932675e0047 4d63de00 5bd620df +130766226318786535e0048 4d73de00 5bd620df +557035730189854663e-294 693bfac 6bc4767b +902042358290366539e-280 986b930 23ca3e6f +272104041512242479e0200 6d13bbb4 bf05f087 +544208083024484958e0200 6d23bbb4 bf05f087 +680429695511221511e0192 6b808ebc 116f8a20 +308975121073410857e0236 7490db75 cc001072 +792644927852378159e0078 53d7bff3 36d8ff06 +783308178698887621e0223 71f2cbac 35f71140 +8396094300569779681e-252 f8ab223 efcee35a +3507665085003296281e-074 346b85c0 26a264e4 +7322325862592278999e0074 5336775b 6caa5ae0 +6014546754280072926e0209 6f396397 b06732a4 +7120190517612959703e0120 5cc3220d cd5899fd +3507665085003296281e-073 34a13398 18257f0f +4345544743100783551e-218 168a9c42 e5b6d89f +9778613303868468131e-090 313146fe 1075e1ef +7539204280836061195e-082 32d3d969 e3dbe723 +7862637540082247119e-202 19eaba32 62ee707b +2176832332097939832e0200 6d43bbb4 bf05f087 +8643988913946659879e0115 5bbe71ec 1ed0a4f9 +5529436763613147623e0138 6079c677 be6f236e +6764958008109694533e-173 1fed0669 2e6f5ef6 +6802601037806061975e0197 6cbf92ba cb3cb40c +1360520207561212395e0198 6ccf92ba cb3cb40c +62259110684423957791e0047 4dcd8f2c fc20d6e8 +88800290202542652011e-226 1526cec5 1a43f41a +41010852717673354694e-221 16201295 4b6aabba +20505426358836677347e-221 16101295 4b6aabba +66102447903809911604e0055 4f776206 8a24fd55 +35600952588064798515e0119 5cb3220d cd5899fd +14371240869903838702e0205 6e78d92d 2bcc7a81 +57500690832492901689e0043 4cf65d3e 2acd616b +23432630639573022093e-107 2dbdd54c 40a2f25f +62259110684423957791e0048 4e02797c 1d948651 +35620497849450218807e-306 475b220 82529425 +69658634627134074624e0200 6d93bbb4 bf05f087 +99440755792436956989e-062 37362d10 462a26f4 +55277197169490210673e0081 54d945bf a911e32a +36992084760177624177e-318 1f8c5f9 551c2f9a +30888265282878466443e-111 2cf01b8e f28251fc + +# examples of bugs introduced 20001113, fixed 20010207 +# first is 2^-1075 (half the smallest denormal) +2.4703282292062327208828439643411068618252990130716238221279284125033775363510437593264991818081799618989828234772285886546332835517796989819938739800539093906315035659515570226392290858392449105184435931802849936536152500319370457678249219365623669863658480757001585769269903706311928279558551332927834338409351978015531246597263579574622766465272827220056374006485499977096599470454020828166226237857393450736339007967761930577506740176324673600968951340535537458516661134223766678604162159680461914467291840300530057530849048765391711386591646239524912623653881879636239373280423891018672348497668235089863388587925628302755995657524455507255189313690836254779186948667994968324049705821028513185451396213837722826145437693412532098591327667236328125e-324 0 0 +2.47032822920623272e-324 0 0 + +# examples reported by Mark Dickinson of bugs in the bigcomp() logic introduced +# 20090316 in dtoa.c to speed handling of absurdly long input: +12579816049008305546974391768996369464963024663104e-357 90bbd 7412d19f +17489628565202117263145367596028389348922981857013e-357 c938e 9000492f +18487398785991994634182916638542680759613590482273e-357 d4b3a ee198863 +32002864200581033134358724675198044527469366773928e-358 24d1e ed8448e3 +99999999999999994487665465554760717039532578546e-47 3ff00000 0 +1.0000000000000000100000000000000000000001e44 4911efc6 59cf7d4c +1000000000000000000000000000000000000000e-16 44b52d02 c7e14af6 +10000000000000000000000000000000000000000e-17 44b52d02 c7e14af6 +10.900000000000000012345678912345678912345 4025cccc cccccccd +104308485241983990666713401708072175773165034278685682646111762292409330928739751702404658197872319129036519947435319418387839758990478549477777586673075945844895981012024387992135617064532141489278815239849108105951619997829153633535314849999674266169258928940692239684771590065027025835804863585454872499320500023126142553932654370362024104462255244034053203998964360882487378334860197725139151265590832887433736189468858614521708567646743455601905935595381852723723645799866672558576993978025033590728687206296379801363024094048327273913079612469982585674824156000783167963081616214710691759864332339239688734656548790656486646106983450809073750535624894296242072010195710276073042036425579852459556183541199012652571123898996574563824424330960027873516082763671875e-1075 78026 65fd9600 +99037485700245683102805043437346965248029601286431e-373 0 2 +99617639833743863161109961162881027406769510558457e-373 0 2 +98852915025769345295749278351563179840130565591462e-372 0 14 +99059944827693569659153042769690930905148015876788e-373 0 2 +98914979205069368270421829889078356254059760327101e-372 0 14 +0.999999999999999999999999999999999999999999999e23 44b52d02 c7e14af6 +991633793189150720000000000000000000000000000000000000000e-33 44ea3f92 6bad90c6 +37652435753827922121470370984740152789920e234 78f1667a c9e75d61 +999999999999999996790597280027956716285163e-42 3ff00000 0 +9483973038658180570348795755328802873667739881500874740826641664593613312413122937394311083577538394191754403820631172036846773125424639263833553383990195662207006139342261292777056851379062046720e0 68a03d69 82f2f936 +20209005503919489280000000000000000000000000000000000000000e-40 43bc0bae 57e880e6 diff --git a/lib/libc/gdtoa/test/x.ou0 b/lib/libc/gdtoa/test/x.ou0 new file mode 100644 index 000000000..6421bc7a1 --- /dev/null +++ b/lib/libc/gdtoa/test/x.ou0 @@ -0,0 +1,1182 @@ + +Input: 1.23 + +strtox consumes 4 bytes and returns 33 +with bits = #3fff 9d70 a3d7 a3d 70a4 +g_xfmt(0) gives 4 bytes: "1.23" + +strtoIx returns 33, consuming 4 bytes. +fI[0] = #3fff 9d70 a3d7 a3d 70a3 +fI[1] = #3fff 9d70 a3d7 a3d 70a4 +fI[1] == strtox + + +Input: 1.23e+20 + +strtox consumes 8 bytes and returns 1 +with bits = #4041 d55e f90a 2da1 8000 +g_xfmt(0) gives 8 bytes: "1.23e+20" + +strtoIx returns 1, consuming 8 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.23e-20 + +strtox consumes 8 bytes and returns 17 +with bits = #3fbc e857 267b b3a9 84f2 +g_xfmt(0) gives 8 bytes: "1.23e-20" + +strtoIx returns 17, consuming 8 bytes. +fI[0] = #3fbc e857 267b b3a9 84f2 +fI[1] = #3fbc e857 267b b3a9 84f3 +fI[0] == strtox + + +Input: 1.23456789 + +strtox consumes 10 bytes and returns 33 +with bits = #3fff 9e06 5214 1ef0 dbf6 +g_xfmt(0) gives 10 bytes: "1.23456789" + +strtoIx returns 33, consuming 10 bytes. +fI[0] = #3fff 9e06 5214 1ef0 dbf5 +fI[1] = #3fff 9e06 5214 1ef0 dbf6 +fI[1] == strtox + + +Input: 1.23456589e+20 + +strtox consumes 14 bytes and returns 1 +with bits = #4041 d629 bd33 5cc ba00 +g_xfmt(0) gives 14 bytes: "1.23456589e+20" + +strtoIx returns 1, consuming 14 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.23e+30 + +strtox consumes 8 bytes and returns 17 +with bits = #4062 f865 8274 7dbc 824a +g_xfmt(0) gives 8 bytes: "1.23e+30" + +strtoIx returns 17, consuming 8 bytes. +fI[0] = #4062 f865 8274 7dbc 824a +fI[1] = #4062 f865 8274 7dbc 824b +fI[0] == strtox + + +Input: 1.23e-30 + +strtox consumes 8 bytes and returns 17 +with bits = #3f9b c794 337a 8085 54eb +g_xfmt(0) gives 8 bytes: "1.23e-30" + +strtoIx returns 17, consuming 8 bytes. +fI[0] = #3f9b c794 337a 8085 54eb +fI[1] = #3f9b c794 337a 8085 54ec +fI[0] == strtox + + +Input: 1.23456789e-20 + +strtox consumes 14 bytes and returns 17 +with bits = #3fbc e934 a38 f3d6 d352 +g_xfmt(0) gives 14 bytes: "1.23456789e-20" + +strtoIx returns 17, consuming 14 bytes. +fI[0] = #3fbc e934 a38 f3d6 d352 +fI[1] = #3fbc e934 a38 f3d6 d353 +fI[0] == strtox + + +Input: 1.23456789e-30 + +strtox consumes 14 bytes and returns 17 +with bits = #3f9b c851 f19d decc a8fc +g_xfmt(0) gives 14 bytes: "1.23456789e-30" + +strtoIx returns 17, consuming 14 bytes. +fI[0] = #3f9b c851 f19d decc a8fc +fI[1] = #3f9b c851 f19d decc a8fd +fI[0] == strtox + + +Input: 1.234567890123456789 + +strtox consumes 20 bytes and returns 17 +with bits = #3fff 9e06 5214 62cf db8d +g_xfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIx returns 17, consuming 20 bytes. +fI[0] = #3fff 9e06 5214 62cf db8d +fI[1] = #3fff 9e06 5214 62cf db8e +fI[0] == strtox + + +Input: 1.23456789012345678901234567890123456789 + +strtox consumes 40 bytes and returns 17 +with bits = #3fff 9e06 5214 62cf db8d +g_xfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIx returns 17, consuming 40 bytes. +fI[0] = #3fff 9e06 5214 62cf db8d +fI[1] = #3fff 9e06 5214 62cf db8e +fI[0] == strtox + + +Input: 1.23e306 + +strtox consumes 8 bytes and returns 17 +with bits = #43f7 e033 b668 e30f a6d5 +g_xfmt(0) gives 9 bytes: "1.23e+306" + +strtoIx returns 17, consuming 8 bytes. +fI[0] = #43f7 e033 b668 e30f a6d5 +fI[1] = #43f7 e033 b668 e30f a6d6 +fI[0] == strtox + + +Input: 1.23e-306 + +strtox consumes 9 bytes and returns 33 +with bits = #3c06 dd1d c2ed 1cb7 3f25 +g_xfmt(0) gives 9 bytes: "1.23e-306" + +strtoIx returns 33, consuming 9 bytes. +fI[0] = #3c06 dd1d c2ed 1cb7 3f24 +fI[1] = #3c06 dd1d c2ed 1cb7 3f25 +fI[1] == strtox + + +Input: 1.23e-320 + +strtox consumes 9 bytes and returns 33 +with bits = #3bd8 9b98 c371 844c 3f1a +g_xfmt(0) gives 9 bytes: "1.23e-320" + +strtoIx returns 33, consuming 9 bytes. +fI[0] = #3bd8 9b98 c371 844c 3f19 +fI[1] = #3bd8 9b98 c371 844c 3f1a +fI[1] == strtox + + +Input: 1.23e-20 + +strtox consumes 8 bytes and returns 17 +with bits = #3fbc e857 267b b3a9 84f2 +g_xfmt(0) gives 8 bytes: "1.23e-20" + +strtoIx returns 17, consuming 8 bytes. +fI[0] = #3fbc e857 267b b3a9 84f2 +fI[1] = #3fbc e857 267b b3a9 84f3 +fI[0] == strtox + + +Input: 1.23456789e307 + +strtox consumes 14 bytes and returns 17 +with bits = #43fb 8ca5 8a5e d766 de75 +g_xfmt(0) gives 15 bytes: "1.23456789e+307" + +strtoIx returns 17, consuming 14 bytes. +fI[0] = #43fb 8ca5 8a5e d766 de75 +fI[1] = #43fb 8ca5 8a5e d766 de76 +fI[0] == strtox + + +Input: 1.23456589e-307 + +strtox consumes 15 bytes and returns 17 +with bits = #3c03 b18c b5dc c22f d369 +g_xfmt(0) gives 15 bytes: "1.23456589e-307" + +strtoIx returns 17, consuming 15 bytes. +fI[0] = #3c03 b18c b5dc c22f d369 +fI[1] = #3c03 b18c b5dc c22f d36a +fI[0] == strtox + + +Input: 1.234567890123456789 + +strtox consumes 20 bytes and returns 17 +with bits = #3fff 9e06 5214 62cf db8d +g_xfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIx returns 17, consuming 20 bytes. +fI[0] = #3fff 9e06 5214 62cf db8d +fI[1] = #3fff 9e06 5214 62cf db8e +fI[0] == strtox + + +Input: 1.234567890123456789e301 + +strtox consumes 24 bytes and returns 33 +with bits = #43e7 937a 8baf ab20 980c +g_xfmt(0) gives 25 bytes: "1.234567890123456789e+301" + +strtoIx returns 33, consuming 24 bytes. +fI[0] = #43e7 937a 8baf ab20 980b +fI[1] = #43e7 937a 8baf ab20 980c +fI[1] == strtox + + +Input: 1.234567890123456789e-301 + +strtox consumes 25 bytes and returns 33 +with bits = #3c17 a953 271a 5d06 9ad9 +g_xfmt(0) gives 25 bytes: "1.234567890123456789e-301" + +strtoIx returns 33, consuming 25 bytes. +fI[0] = #3c17 a953 271a 5d06 9ad8 +fI[1] = #3c17 a953 271a 5d06 9ad9 +fI[1] == strtox + + +Input: 1.234567890123456789e-321 + +strtox consumes 25 bytes and returns 33 +with bits = #3bd4 f9e1 1b4c ea6d cce9 +g_xfmt(0) gives 25 bytes: "1.234567890123456789e-321" + +strtoIx returns 33, consuming 25 bytes. +fI[0] = #3bd4 f9e1 1b4c ea6d cce8 +fI[1] = #3bd4 f9e1 1b4c ea6d cce9 +fI[1] == strtox + + +Input: 1e23 + +strtox consumes 4 bytes and returns 1 +with bits = #404b a968 163f a57 b400 +g_xfmt(0) gives 5 bytes: "1e+23" + +strtoIx returns 1, consuming 4 bytes. +fI[0] == fI[1] == strtox + + +Input: 1e310 + +strtox consumes 5 bytes and returns 33 +with bits = #4404 de81 e40a 34b cf50 +g_xfmt(0) gives 6 bytes: "1e+310" + +strtoIx returns 33, consuming 5 bytes. +fI[0] = #4404 de81 e40a 34b cf4f +fI[1] = #4404 de81 e40a 34b cf50 +fI[1] == strtox + + +Input: 9.0259718793241475e-277 + +strtox consumes 23 bytes and returns 33 +with bits = #3c69 ffff ffff ffff fcf7 +g_xfmt(0) gives 23 bytes: "9.0259718793241475e-277" + +strtoIx returns 33, consuming 23 bytes. +fI[0] = #3c69 ffff ffff ffff fcf6 +fI[1] = #3c69 ffff ffff ffff fcf7 +fI[1] == strtox + + +Input: 9.025971879324147880346310405869e-277 + +strtox consumes 37 bytes and returns 17 +with bits = #3c6a 8000 0 0 0 +g_xfmt(0) gives 26 bytes: "9.0259718793241478803e-277" + +strtoIx returns 17, consuming 37 bytes. +fI[0] = #3c6a 8000 0 0 0 +fI[1] = #3c6a 8000 0 0 1 +fI[0] == strtox + + +Input: 9.025971879324147880346310405868e-277 + +strtox consumes 37 bytes and returns 33 +with bits = #3c6a 8000 0 0 0 +g_xfmt(0) gives 26 bytes: "9.0259718793241478803e-277" + +strtoIx returns 33, consuming 37 bytes. +fI[0] = #3c69 ffff ffff ffff ffff +fI[1] = #3c6a 8000 0 0 0 +fI[1] == strtox + + +Input: 2.2250738585072014e-308 + +strtox consumes 23 bytes and returns 17 +with bits = #3c01 8000 0 0 46 +g_xfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoIx returns 17, consuming 23 bytes. +fI[0] = #3c01 8000 0 0 46 +fI[1] = #3c01 8000 0 0 47 +fI[0] == strtox + + +Input: 2.2250738585072013e-308 + +strtox consumes 23 bytes and returns 17 +with bits = #3c00 ffff ffff ffff fd4f +g_xfmt(0) gives 23 bytes: "2.2250738585072013e-308" + +strtoIx returns 17, consuming 23 bytes. +fI[0] = #3c00 ffff ffff ffff fd4f +fI[1] = #3c00 ffff ffff ffff fd50 +fI[0] == strtox + +Rounding mode for strtor... changed from 1 (nearest) to 0 (toward zero) + +Input: 1.1 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff 8ccc cccc cccc cccc +g_xfmt(0) gives 21 bytes: "1.0999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 8ccc cccc cccc cccc +fI[1] = #3fff 8ccc cccc cccc cccd +fI[0] == strtox + + +Input: -1.1 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff 8ccc cccc cccc cccc +g_xfmt(0) gives 22 bytes: "-1.0999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 8ccc cccc cccc cccd +fI[1] = #bfff 8ccc cccc cccc cccc +fI[1] == strtox + + +Input: 1.2 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff 9999 9999 9999 9999 +g_xfmt(0) gives 21 bytes: "1.1999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 9999 9999 9999 9999 +fI[1] = #3fff 9999 9999 9999 999a +fI[0] == strtox + + +Input: -1.2 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff 9999 9999 9999 9999 +g_xfmt(0) gives 22 bytes: "-1.1999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 9999 9999 9999 999a +fI[1] = #bfff 9999 9999 9999 9999 +fI[1] == strtox + + +Input: 1.3 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff a666 6666 6666 6666 +g_xfmt(0) gives 3 bytes: "1.3" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff a666 6666 6666 6666 +fI[1] = #3fff a666 6666 6666 6667 +fI[0] == strtox + + +Input: -1.3 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff a666 6666 6666 6666 +g_xfmt(0) gives 4 bytes: "-1.3" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff a666 6666 6666 6667 +fI[1] = #bfff a666 6666 6666 6666 +fI[1] == strtox + + +Input: 1.4 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff b333 3333 3333 3333 +g_xfmt(0) gives 3 bytes: "1.4" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff b333 3333 3333 3333 +fI[1] = #3fff b333 3333 3333 3334 +fI[0] == strtox + + +Input: -1.4 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff b333 3333 3333 3333 +g_xfmt(0) gives 4 bytes: "-1.4" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff b333 3333 3333 3334 +fI[1] = #bfff b333 3333 3333 3333 +fI[1] == strtox + + +Input: 1.5 + +strtox consumes 3 bytes and returns 1 +with bits = #3fff c000 0 0 0 +g_xfmt(0) gives 3 bytes: "1.5" + +strtoIx returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtox + + +Input: -1.5 + +strtox consumes 4 bytes and returns 9 +with bits = #bfff c000 0 0 0 +g_xfmt(0) gives 4 bytes: "-1.5" + +strtoIx returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.6 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff cccc cccc cccc cccc +g_xfmt(0) gives 21 bytes: "1.5999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff cccc cccc cccc cccc +fI[1] = #3fff cccc cccc cccc cccd +fI[0] == strtox + + +Input: -1.6 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff cccc cccc cccc cccc +g_xfmt(0) gives 22 bytes: "-1.5999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff cccc cccc cccc cccd +fI[1] = #bfff cccc cccc cccc cccc +fI[1] == strtox + + +Input: 1.7 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff d999 9999 9999 9999 +g_xfmt(0) gives 21 bytes: "1.6999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff d999 9999 9999 9999 +fI[1] = #3fff d999 9999 9999 999a +fI[0] == strtox + + +Input: -1.7 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff d999 9999 9999 9999 +g_xfmt(0) gives 22 bytes: "-1.6999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff d999 9999 9999 999a +fI[1] = #bfff d999 9999 9999 9999 +fI[1] == strtox + + +Input: 1.8 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff e666 6666 6666 6666 +g_xfmt(0) gives 3 bytes: "1.8" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff e666 6666 6666 6666 +fI[1] = #3fff e666 6666 6666 6667 +fI[0] == strtox + + +Input: -1.8 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff e666 6666 6666 6666 +g_xfmt(0) gives 4 bytes: "-1.8" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff e666 6666 6666 6667 +fI[1] = #bfff e666 6666 6666 6666 +fI[1] == strtox + + +Input: 1.9 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff f333 3333 3333 3333 +g_xfmt(0) gives 3 bytes: "1.9" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff f333 3333 3333 3333 +fI[1] = #3fff f333 3333 3333 3334 +fI[0] == strtox + + +Input: -1.9 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff f333 3333 3333 3333 +g_xfmt(0) gives 4 bytes: "-1.9" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff f333 3333 3333 3334 +fI[1] = #bfff f333 3333 3333 3333 +fI[1] == strtox + +Rounding mode for strtor... changed from 0 (toward zero) to 1 (nearest) + +Input: 1.1 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff 8ccc cccc cccc cccd +g_xfmt(0) gives 3 bytes: "1.1" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 8ccc cccc cccc cccc +fI[1] = #3fff 8ccc cccc cccc cccd +fI[1] == strtox + + +Input: -1.1 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff 8ccc cccc cccc cccd +g_xfmt(0) gives 4 bytes: "-1.1" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 8ccc cccc cccc cccd +fI[1] = #bfff 8ccc cccc cccc cccc +fI[0] == strtox + + +Input: 1.2 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff 9999 9999 9999 999a +g_xfmt(0) gives 3 bytes: "1.2" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 9999 9999 9999 9999 +fI[1] = #3fff 9999 9999 9999 999a +fI[1] == strtox + + +Input: -1.2 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff 9999 9999 9999 999a +g_xfmt(0) gives 4 bytes: "-1.2" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 9999 9999 9999 999a +fI[1] = #bfff 9999 9999 9999 9999 +fI[0] == strtox + + +Input: 1.3 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff a666 6666 6666 6666 +g_xfmt(0) gives 3 bytes: "1.3" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff a666 6666 6666 6666 +fI[1] = #3fff a666 6666 6666 6667 +fI[0] == strtox + + +Input: -1.3 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff a666 6666 6666 6666 +g_xfmt(0) gives 4 bytes: "-1.3" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff a666 6666 6666 6667 +fI[1] = #bfff a666 6666 6666 6666 +fI[1] == strtox + + +Input: 1.4 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff b333 3333 3333 3333 +g_xfmt(0) gives 3 bytes: "1.4" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff b333 3333 3333 3333 +fI[1] = #3fff b333 3333 3333 3334 +fI[0] == strtox + + +Input: -1.4 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff b333 3333 3333 3333 +g_xfmt(0) gives 4 bytes: "-1.4" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff b333 3333 3333 3334 +fI[1] = #bfff b333 3333 3333 3333 +fI[1] == strtox + + +Input: 1.5 + +strtox consumes 3 bytes and returns 1 +with bits = #3fff c000 0 0 0 +g_xfmt(0) gives 3 bytes: "1.5" + +strtoIx returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtox + + +Input: -1.5 + +strtox consumes 4 bytes and returns 9 +with bits = #bfff c000 0 0 0 +g_xfmt(0) gives 4 bytes: "-1.5" + +strtoIx returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.6 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff cccc cccc cccc cccd +g_xfmt(0) gives 3 bytes: "1.6" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff cccc cccc cccc cccc +fI[1] = #3fff cccc cccc cccc cccd +fI[1] == strtox + + +Input: -1.6 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff cccc cccc cccc cccd +g_xfmt(0) gives 4 bytes: "-1.6" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff cccc cccc cccc cccd +fI[1] = #bfff cccc cccc cccc cccc +fI[0] == strtox + + +Input: 1.7 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff d999 9999 9999 999a +g_xfmt(0) gives 3 bytes: "1.7" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff d999 9999 9999 9999 +fI[1] = #3fff d999 9999 9999 999a +fI[1] == strtox + + +Input: -1.7 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff d999 9999 9999 999a +g_xfmt(0) gives 4 bytes: "-1.7" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff d999 9999 9999 999a +fI[1] = #bfff d999 9999 9999 9999 +fI[0] == strtox + + +Input: 1.8 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff e666 6666 6666 6666 +g_xfmt(0) gives 3 bytes: "1.8" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff e666 6666 6666 6666 +fI[1] = #3fff e666 6666 6666 6667 +fI[0] == strtox + + +Input: -1.8 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff e666 6666 6666 6666 +g_xfmt(0) gives 4 bytes: "-1.8" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff e666 6666 6666 6667 +fI[1] = #bfff e666 6666 6666 6666 +fI[1] == strtox + + +Input: 1.9 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff f333 3333 3333 3333 +g_xfmt(0) gives 3 bytes: "1.9" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff f333 3333 3333 3333 +fI[1] = #3fff f333 3333 3333 3334 +fI[0] == strtox + + +Input: -1.9 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff f333 3333 3333 3333 +g_xfmt(0) gives 4 bytes: "-1.9" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff f333 3333 3333 3334 +fI[1] = #bfff f333 3333 3333 3333 +fI[1] == strtox + +Rounding mode for strtor... changed from 1 (nearest) to 2 (toward +Infinity) + +Input: 1.1 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff 8ccc cccc cccc cccd +g_xfmt(0) gives 3 bytes: "1.1" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 8ccc cccc cccc cccc +fI[1] = #3fff 8ccc cccc cccc cccd +fI[1] == strtox + + +Input: -1.1 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff 8ccc cccc cccc cccc +g_xfmt(0) gives 22 bytes: "-1.0999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 8ccc cccc cccc cccd +fI[1] = #bfff 8ccc cccc cccc cccc +fI[1] == strtox + + +Input: 1.2 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff 9999 9999 9999 999a +g_xfmt(0) gives 3 bytes: "1.2" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 9999 9999 9999 9999 +fI[1] = #3fff 9999 9999 9999 999a +fI[1] == strtox + + +Input: -1.2 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff 9999 9999 9999 9999 +g_xfmt(0) gives 22 bytes: "-1.1999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 9999 9999 9999 999a +fI[1] = #bfff 9999 9999 9999 9999 +fI[1] == strtox + + +Input: 1.3 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff a666 6666 6666 6667 +g_xfmt(0) gives 21 bytes: "1.3000000000000000001" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff a666 6666 6666 6666 +fI[1] = #3fff a666 6666 6666 6667 +fI[1] == strtox + + +Input: -1.3 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff a666 6666 6666 6666 +g_xfmt(0) gives 4 bytes: "-1.3" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff a666 6666 6666 6667 +fI[1] = #bfff a666 6666 6666 6666 +fI[1] == strtox + + +Input: 1.4 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff b333 3333 3333 3334 +g_xfmt(0) gives 21 bytes: "1.4000000000000000001" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff b333 3333 3333 3333 +fI[1] = #3fff b333 3333 3333 3334 +fI[1] == strtox + + +Input: -1.4 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff b333 3333 3333 3333 +g_xfmt(0) gives 4 bytes: "-1.4" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff b333 3333 3333 3334 +fI[1] = #bfff b333 3333 3333 3333 +fI[1] == strtox + + +Input: 1.5 + +strtox consumes 3 bytes and returns 1 +with bits = #3fff c000 0 0 0 +g_xfmt(0) gives 3 bytes: "1.5" + +strtoIx returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtox + + +Input: -1.5 + +strtox consumes 4 bytes and returns 9 +with bits = #bfff c000 0 0 0 +g_xfmt(0) gives 4 bytes: "-1.5" + +strtoIx returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.6 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff cccc cccc cccc cccd +g_xfmt(0) gives 3 bytes: "1.6" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff cccc cccc cccc cccc +fI[1] = #3fff cccc cccc cccc cccd +fI[1] == strtox + + +Input: -1.6 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff cccc cccc cccc cccc +g_xfmt(0) gives 22 bytes: "-1.5999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff cccc cccc cccc cccd +fI[1] = #bfff cccc cccc cccc cccc +fI[1] == strtox + + +Input: 1.7 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff d999 9999 9999 999a +g_xfmt(0) gives 3 bytes: "1.7" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff d999 9999 9999 9999 +fI[1] = #3fff d999 9999 9999 999a +fI[1] == strtox + + +Input: -1.7 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff d999 9999 9999 9999 +g_xfmt(0) gives 22 bytes: "-1.6999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff d999 9999 9999 999a +fI[1] = #bfff d999 9999 9999 9999 +fI[1] == strtox + + +Input: 1.8 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff e666 6666 6666 6667 +g_xfmt(0) gives 21 bytes: "1.8000000000000000001" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff e666 6666 6666 6666 +fI[1] = #3fff e666 6666 6666 6667 +fI[1] == strtox + + +Input: -1.8 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff e666 6666 6666 6666 +g_xfmt(0) gives 4 bytes: "-1.8" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff e666 6666 6666 6667 +fI[1] = #bfff e666 6666 6666 6666 +fI[1] == strtox + + +Input: 1.9 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff f333 3333 3333 3334 +g_xfmt(0) gives 21 bytes: "1.9000000000000000001" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff f333 3333 3333 3333 +fI[1] = #3fff f333 3333 3333 3334 +fI[1] == strtox + + +Input: -1.9 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff f333 3333 3333 3333 +g_xfmt(0) gives 4 bytes: "-1.9" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff f333 3333 3333 3334 +fI[1] = #bfff f333 3333 3333 3333 +fI[1] == strtox + +Rounding mode for strtor... changed from 2 (toward +Infinity) to 3 (toward -Infinity) + +Input: 1.1 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff 8ccc cccc cccc cccc +g_xfmt(0) gives 21 bytes: "1.0999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 8ccc cccc cccc cccc +fI[1] = #3fff 8ccc cccc cccc cccd +fI[0] == strtox + + +Input: -1.1 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff 8ccc cccc cccc cccd +g_xfmt(0) gives 4 bytes: "-1.1" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 8ccc cccc cccc cccd +fI[1] = #bfff 8ccc cccc cccc cccc +fI[0] == strtox + + +Input: 1.2 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff 9999 9999 9999 9999 +g_xfmt(0) gives 21 bytes: "1.1999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 9999 9999 9999 9999 +fI[1] = #3fff 9999 9999 9999 999a +fI[0] == strtox + + +Input: -1.2 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff 9999 9999 9999 999a +g_xfmt(0) gives 4 bytes: "-1.2" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 9999 9999 9999 999a +fI[1] = #bfff 9999 9999 9999 9999 +fI[0] == strtox + + +Input: 1.3 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff a666 6666 6666 6666 +g_xfmt(0) gives 3 bytes: "1.3" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff a666 6666 6666 6666 +fI[1] = #3fff a666 6666 6666 6667 +fI[0] == strtox + + +Input: -1.3 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff a666 6666 6666 6667 +g_xfmt(0) gives 22 bytes: "-1.3000000000000000001" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff a666 6666 6666 6667 +fI[1] = #bfff a666 6666 6666 6666 +fI[0] == strtox + + +Input: 1.4 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff b333 3333 3333 3333 +g_xfmt(0) gives 3 bytes: "1.4" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff b333 3333 3333 3333 +fI[1] = #3fff b333 3333 3333 3334 +fI[0] == strtox + + +Input: -1.4 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff b333 3333 3333 3334 +g_xfmt(0) gives 22 bytes: "-1.4000000000000000001" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff b333 3333 3333 3334 +fI[1] = #bfff b333 3333 3333 3333 +fI[0] == strtox + + +Input: 1.5 + +strtox consumes 3 bytes and returns 1 +with bits = #3fff c000 0 0 0 +g_xfmt(0) gives 3 bytes: "1.5" + +strtoIx returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtox + + +Input: -1.5 + +strtox consumes 4 bytes and returns 9 +with bits = #bfff c000 0 0 0 +g_xfmt(0) gives 4 bytes: "-1.5" + +strtoIx returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.6 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff cccc cccc cccc cccc +g_xfmt(0) gives 21 bytes: "1.5999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff cccc cccc cccc cccc +fI[1] = #3fff cccc cccc cccc cccd +fI[0] == strtox + + +Input: -1.6 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff cccc cccc cccc cccd +g_xfmt(0) gives 4 bytes: "-1.6" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff cccc cccc cccc cccd +fI[1] = #bfff cccc cccc cccc cccc +fI[0] == strtox + + +Input: 1.7 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff d999 9999 9999 9999 +g_xfmt(0) gives 21 bytes: "1.6999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff d999 9999 9999 9999 +fI[1] = #3fff d999 9999 9999 999a +fI[0] == strtox + + +Input: -1.7 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff d999 9999 9999 999a +g_xfmt(0) gives 4 bytes: "-1.7" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff d999 9999 9999 999a +fI[1] = #bfff d999 9999 9999 9999 +fI[0] == strtox + + +Input: 1.8 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff e666 6666 6666 6666 +g_xfmt(0) gives 3 bytes: "1.8" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff e666 6666 6666 6666 +fI[1] = #3fff e666 6666 6666 6667 +fI[0] == strtox + + +Input: -1.8 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff e666 6666 6666 6667 +g_xfmt(0) gives 22 bytes: "-1.8000000000000000001" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff e666 6666 6666 6667 +fI[1] = #bfff e666 6666 6666 6666 +fI[0] == strtox + + +Input: 1.9 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff f333 3333 3333 3333 +g_xfmt(0) gives 3 bytes: "1.9" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff f333 3333 3333 3333 +fI[1] = #3fff f333 3333 3333 3334 +fI[0] == strtox + + +Input: -1.9 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff f333 3333 3333 3334 +g_xfmt(0) gives 22 bytes: "-1.9000000000000000001" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff f333 3333 3333 3334 +fI[1] = #bfff f333 3333 3333 3333 +fI[0] == strtox + diff --git a/lib/libc/gdtoa/test/x.ou1 b/lib/libc/gdtoa/test/x.ou1 new file mode 100644 index 000000000..437783f71 --- /dev/null +++ b/lib/libc/gdtoa/test/x.ou1 @@ -0,0 +1,1460 @@ + +Input: 1.23 + +strtox consumes 4 bytes and returns 33 +with bits = #3fff 9d70 a3d7 a3d 70a4 +printf("%.21Lg") gives 1.23000000000000000002 +g_xfmt(0) gives 4 bytes: "1.23" + +strtoIx returns 33, consuming 4 bytes. +fI[0] = #3fff 9d70 a3d7 a3d 70a3 += 1.22999999999999999991 +fI[1] = #3fff 9d70 a3d7 a3d 70a4 += 1.23000000000000000002 +fI[1] == strtox + + +Input: 1.23e+20 + +strtox consumes 8 bytes and returns 1 +with bits = #4041 d55e f90a 2da1 8000 +printf("%.21Lg") gives 123000000000000000000 +g_xfmt(0) gives 8 bytes: "1.23e+20" + +strtoIx returns 1, consuming 8 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.23e-20 + +strtox consumes 8 bytes and returns 17 +with bits = #3fbc e857 267b b3a9 84f2 +printf("%.21Lg") gives 1.22999999999999999997e-20 +g_xfmt(0) gives 8 bytes: "1.23e-20" + +strtoIx returns 17, consuming 8 bytes. +fI[0] = #3fbc e857 267b b3a9 84f2 += 1.22999999999999999997e-20 +fI[1] = #3fbc e857 267b b3a9 84f3 += 1.23000000000000000004e-20 +fI[0] == strtox + + +Input: 1.23456789 + +strtox consumes 10 bytes and returns 33 +with bits = #3fff 9e06 5214 1ef0 dbf6 +printf("%.21Lg") gives 1.23456789000000000003 +g_xfmt(0) gives 10 bytes: "1.23456789" + +strtoIx returns 33, consuming 10 bytes. +fI[0] = #3fff 9e06 5214 1ef0 dbf5 += 1.23456788999999999992 +fI[1] = #3fff 9e06 5214 1ef0 dbf6 += 1.23456789000000000003 +fI[1] == strtox + + +Input: 1.23456589e+20 + +strtox consumes 14 bytes and returns 1 +with bits = #4041 d629 bd33 5cc ba00 +printf("%.21Lg") gives 123456589000000000000 +g_xfmt(0) gives 14 bytes: "1.23456589e+20" + +strtoIx returns 1, consuming 14 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.23e+30 + +strtox consumes 8 bytes and returns 17 +with bits = #4062 f865 8274 7dbc 824a +printf("%.21Lg") gives 1.22999999999999999999e+30 +g_xfmt(0) gives 8 bytes: "1.23e+30" + +strtoIx returns 17, consuming 8 bytes. +fI[0] = #4062 f865 8274 7dbc 824a += 1.22999999999999999999e+30 +fI[1] = #4062 f865 8274 7dbc 824b += 1.23000000000000000006e+30 +fI[0] == strtox + + +Input: 1.23e-30 + +strtox consumes 8 bytes and returns 17 +with bits = #3f9b c794 337a 8085 54eb +printf("%.21Lg") gives 1.22999999999999999999e-30 +g_xfmt(0) gives 8 bytes: "1.23e-30" + +strtoIx returns 17, consuming 8 bytes. +fI[0] = #3f9b c794 337a 8085 54eb += 1.22999999999999999999e-30 +fI[1] = #3f9b c794 337a 8085 54ec += 1.23000000000000000007e-30 +fI[0] == strtox + + +Input: 1.23456789e-20 + +strtox consumes 14 bytes and returns 17 +with bits = #3fbc e934 a38 f3d6 d352 +printf("%.21Lg") gives 1.23456788999999999998e-20 +g_xfmt(0) gives 14 bytes: "1.23456789e-20" + +strtoIx returns 17, consuming 14 bytes. +fI[0] = #3fbc e934 a38 f3d6 d352 += 1.23456788999999999998e-20 +fI[1] = #3fbc e934 a38 f3d6 d353 += 1.23456789000000000005e-20 +fI[0] == strtox + + +Input: 1.23456789e-30 + +strtox consumes 14 bytes and returns 17 +with bits = #3f9b c851 f19d decc a8fc +printf("%.21Lg") gives 1.23456788999999999999e-30 +g_xfmt(0) gives 14 bytes: "1.23456789e-30" + +strtoIx returns 17, consuming 14 bytes. +fI[0] = #3f9b c851 f19d decc a8fc += 1.23456788999999999999e-30 +fI[1] = #3f9b c851 f19d decc a8fd += 1.23456789000000000007e-30 +fI[0] == strtox + + +Input: 1.234567890123456789 + +strtox consumes 20 bytes and returns 17 +with bits = #3fff 9e06 5214 62cf db8d +printf("%.21Lg") gives 1.23456789012345678899 +g_xfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIx returns 17, consuming 20 bytes. +fI[0] = #3fff 9e06 5214 62cf db8d += 1.23456789012345678899 +fI[1] = #3fff 9e06 5214 62cf db8e += 1.23456789012345678909 +fI[0] == strtox + + +Input: 1.23456789012345678901234567890123456789 + +strtox consumes 40 bytes and returns 17 +with bits = #3fff 9e06 5214 62cf db8d +printf("%.21Lg") gives 1.23456789012345678899 +g_xfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIx returns 17, consuming 40 bytes. +fI[0] = #3fff 9e06 5214 62cf db8d += 1.23456789012345678899 +fI[1] = #3fff 9e06 5214 62cf db8e += 1.23456789012345678909 +fI[0] == strtox + + +Input: 1.23e306 + +strtox consumes 8 bytes and returns 17 +with bits = #43f7 e033 b668 e30f a6d5 +printf("%.21Lg") gives 1.22999999999999999997e+306 +g_xfmt(0) gives 9 bytes: "1.23e+306" + +strtoIx returns 17, consuming 8 bytes. +fI[0] = #43f7 e033 b668 e30f a6d5 += 1.22999999999999999997e+306 +fI[1] = #43f7 e033 b668 e30f a6d6 += 1.23000000000000000005e+306 +fI[0] == strtox + + +Input: 1.23e-306 + +strtox consumes 9 bytes and returns 33 +with bits = #3c06 dd1d c2ed 1cb7 3f25 +printf("%.21Lg") gives 1.23000000000000000002e-306 +g_xfmt(0) gives 9 bytes: "1.23e-306" + +strtoIx returns 33, consuming 9 bytes. +fI[0] = #3c06 dd1d c2ed 1cb7 3f24 += 1.22999999999999999995e-306 +fI[1] = #3c06 dd1d c2ed 1cb7 3f25 += 1.23000000000000000002e-306 +fI[1] == strtox + + +Input: 1.23e-320 + +strtox consumes 9 bytes and returns 33 +with bits = #3bd8 9b98 c371 844c 3f1a +printf("%.21Lg") gives 1.23000000000000000002e-320 +g_xfmt(0) gives 9 bytes: "1.23e-320" + +strtoIx returns 33, consuming 9 bytes. +fI[0] = #3bd8 9b98 c371 844c 3f19 += 1.22999999999999999991e-320 +fI[1] = #3bd8 9b98 c371 844c 3f1a += 1.23000000000000000002e-320 +fI[1] == strtox + + +Input: 1.23e-20 + +strtox consumes 8 bytes and returns 17 +with bits = #3fbc e857 267b b3a9 84f2 +printf("%.21Lg") gives 1.22999999999999999997e-20 +g_xfmt(0) gives 8 bytes: "1.23e-20" + +strtoIx returns 17, consuming 8 bytes. +fI[0] = #3fbc e857 267b b3a9 84f2 += 1.22999999999999999997e-20 +fI[1] = #3fbc e857 267b b3a9 84f3 += 1.23000000000000000004e-20 +fI[0] == strtox + + +Input: 1.23456789e307 + +strtox consumes 14 bytes and returns 17 +with bits = #43fb 8ca5 8a5e d766 de75 +printf("%.21Lg") gives 1.23456788999999999998e+307 +g_xfmt(0) gives 15 bytes: "1.23456789e+307" + +strtoIx returns 17, consuming 14 bytes. +fI[0] = #43fb 8ca5 8a5e d766 de75 += 1.23456788999999999998e+307 +fI[1] = #43fb 8ca5 8a5e d766 de76 += 1.23456789000000000011e+307 +fI[0] == strtox + + +Input: 1.23456589e-307 + +strtox consumes 15 bytes and returns 17 +with bits = #3c03 b18c b5dc c22f d369 +printf("%.21Lg") gives 1.23456588999999999999e-307 +g_xfmt(0) gives 15 bytes: "1.23456589e-307" + +strtoIx returns 17, consuming 15 bytes. +fI[0] = #3c03 b18c b5dc c22f d369 += 1.23456588999999999999e-307 +fI[1] = #3c03 b18c b5dc c22f d36a += 1.23456589000000000009e-307 +fI[0] == strtox + + +Input: 1.234567890123456789 + +strtox consumes 20 bytes and returns 17 +with bits = #3fff 9e06 5214 62cf db8d +printf("%.21Lg") gives 1.23456789012345678899 +g_xfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIx returns 17, consuming 20 bytes. +fI[0] = #3fff 9e06 5214 62cf db8d += 1.23456789012345678899 +fI[1] = #3fff 9e06 5214 62cf db8e += 1.23456789012345678909 +fI[0] == strtox + + +Input: 1.234567890123456789e301 + +strtox consumes 24 bytes and returns 33 +with bits = #43e7 937a 8baf ab20 980c +printf("%.21Lg") gives 1.234567890123456789e+301 +g_xfmt(0) gives 25 bytes: "1.234567890123456789e+301" + +strtoIx returns 33, consuming 24 bytes. +fI[0] = #43e7 937a 8baf ab20 980b += 1.23456789012345678889e+301 +fI[1] = #43e7 937a 8baf ab20 980c += 1.234567890123456789e+301 +fI[1] == strtox + + +Input: 1.234567890123456789e-301 + +strtox consumes 25 bytes and returns 33 +with bits = #3c17 a953 271a 5d06 9ad9 +printf("%.21Lg") gives 1.23456789012345678902e-301 +g_xfmt(0) gives 25 bytes: "1.234567890123456789e-301" + +strtoIx returns 33, consuming 25 bytes. +fI[0] = #3c17 a953 271a 5d06 9ad8 += 1.23456789012345678892e-301 +fI[1] = #3c17 a953 271a 5d06 9ad9 += 1.23456789012345678902e-301 +fI[1] == strtox + + +Input: 1.234567890123456789e-321 + +strtox consumes 25 bytes and returns 33 +with bits = #3bd4 f9e1 1b4c ea6d cce9 +printf("%.21Lg") gives 1.234567890123456789e-321 +g_xfmt(0) gives 25 bytes: "1.234567890123456789e-321" + +strtoIx returns 33, consuming 25 bytes. +fI[0] = #3bd4 f9e1 1b4c ea6d cce8 += 1.23456789012345678893e-321 +fI[1] = #3bd4 f9e1 1b4c ea6d cce9 += 1.234567890123456789e-321 +fI[1] == strtox + + +Input: 1e23 + +strtox consumes 4 bytes and returns 1 +with bits = #404b a968 163f a57 b400 +printf("%.21Lg") gives 1e+23 +g_xfmt(0) gives 5 bytes: "1e+23" + +strtoIx returns 1, consuming 4 bytes. +fI[0] == fI[1] == strtox + + +Input: 1e310 + +strtox consumes 5 bytes and returns 33 +with bits = #4404 de81 e40a 34b cf50 +printf("%.21Lg") gives 1e+310 +g_xfmt(0) gives 6 bytes: "1e+310" + +strtoIx returns 33, consuming 5 bytes. +fI[0] = #4404 de81 e40a 34b cf4f += 9.9999999999999999994e+309 +fI[1] = #4404 de81 e40a 34b cf50 += 1e+310 +fI[1] == strtox + + +Input: 9.0259718793241475e-277 + +strtox consumes 23 bytes and returns 33 +with bits = #3c69 ffff ffff ffff fcf7 +printf("%.21Lg") gives 9.02597187932414750016e-277 +g_xfmt(0) gives 23 bytes: "9.0259718793241475e-277" + +strtoIx returns 33, consuming 23 bytes. +fI[0] = #3c69 ffff ffff ffff fcf6 += 9.02597187932414749967e-277 +fI[1] = #3c69 ffff ffff ffff fcf7 += 9.02597187932414750016e-277 +fI[1] == strtox + + +Input: 9.025971879324147880346310405869e-277 + +strtox consumes 37 bytes and returns 17 +with bits = #3c6a 8000 0 0 0 +printf("%.21Lg") gives 9.02597187932414788035e-277 +g_xfmt(0) gives 26 bytes: "9.0259718793241478803e-277" + +strtoIx returns 17, consuming 37 bytes. +fI[0] = #3c6a 8000 0 0 0 += 9.02597187932414788035e-277 +fI[1] = #3c6a 8000 0 0 1 += 9.02597187932414788132e-277 +fI[0] == strtox + + +Input: 9.025971879324147880346310405868e-277 + +strtox consumes 37 bytes and returns 33 +with bits = #3c6a 8000 0 0 0 +printf("%.21Lg") gives 9.02597187932414788035e-277 +g_xfmt(0) gives 26 bytes: "9.0259718793241478803e-277" + +strtoIx returns 33, consuming 37 bytes. +fI[0] = #3c69 ffff ffff ffff ffff += 9.02597187932414787986e-277 +fI[1] = #3c6a 8000 0 0 0 += 9.02597187932414788035e-277 +fI[1] == strtox + + +Input: 2.2250738585072014e-308 + +strtox consumes 23 bytes and returns 17 +with bits = #3c01 8000 0 0 46 +printf("%.21Lg") gives 2.22507385850720139998e-308 +g_xfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoIx returns 17, consuming 23 bytes. +fI[0] = #3c01 8000 0 0 46 += 2.22507385850720139998e-308 +fI[1] = #3c01 8000 0 0 47 += 2.22507385850720140022e-308 +fI[0] == strtox + + +Input: 2.2250738585072013e-308 + +strtox consumes 23 bytes and returns 17 +with bits = #3c00 ffff ffff ffff fd4f +printf("%.21Lg") gives 2.22507385850720129998e-308 +g_xfmt(0) gives 23 bytes: "2.2250738585072013e-308" + +strtoIx returns 17, consuming 23 bytes. +fI[0] = #3c00 ffff ffff ffff fd4f += 2.22507385850720129998e-308 +fI[1] = #3c00 ffff ffff ffff fd50 += 2.2250738585072013001e-308 +fI[0] == strtox + +Rounding mode for strtor... changed from 1 (nearest) to 0 (toward zero) + +Input: 1.1 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff 8ccc cccc cccc cccc +printf("%.21Lg") gives 1.09999999999999999991 +g_xfmt(0) gives 21 bytes: "1.0999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 8ccc cccc cccc cccc += 1.09999999999999999991 +fI[1] = #3fff 8ccc cccc cccc cccd += 1.10000000000000000002 +fI[0] == strtox + + +Input: -1.1 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff 8ccc cccc cccc cccc +printf("%.21Lg") gives -1.09999999999999999991 +g_xfmt(0) gives 22 bytes: "-1.0999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 8ccc cccc cccc cccd += -1.10000000000000000002 +fI[1] = #bfff 8ccc cccc cccc cccc += -1.09999999999999999991 +fI[1] == strtox + + +Input: 1.2 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff 9999 9999 9999 9999 +printf("%.21Lg") gives 1.19999999999999999993 +g_xfmt(0) gives 21 bytes: "1.1999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 9999 9999 9999 9999 += 1.19999999999999999993 +fI[1] = #3fff 9999 9999 9999 999a += 1.20000000000000000004 +fI[0] == strtox + + +Input: -1.2 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff 9999 9999 9999 9999 +printf("%.21Lg") gives -1.19999999999999999993 +g_xfmt(0) gives 22 bytes: "-1.1999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 9999 9999 9999 999a += -1.20000000000000000004 +fI[1] = #bfff 9999 9999 9999 9999 += -1.19999999999999999993 +fI[1] == strtox + + +Input: 1.3 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff a666 6666 6666 6666 +printf("%.21Lg") gives 1.29999999999999999996 +g_xfmt(0) gives 3 bytes: "1.3" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff a666 6666 6666 6666 += 1.29999999999999999996 +fI[1] = #3fff a666 6666 6666 6667 += 1.30000000000000000007 +fI[0] == strtox + + +Input: -1.3 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff a666 6666 6666 6666 +printf("%.21Lg") gives -1.29999999999999999996 +g_xfmt(0) gives 4 bytes: "-1.3" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff a666 6666 6666 6667 += -1.30000000000000000007 +fI[1] = #bfff a666 6666 6666 6666 += -1.29999999999999999996 +fI[1] == strtox + + +Input: 1.4 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff b333 3333 3333 3333 +printf("%.21Lg") gives 1.39999999999999999998 +g_xfmt(0) gives 3 bytes: "1.4" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff b333 3333 3333 3333 += 1.39999999999999999998 +fI[1] = #3fff b333 3333 3333 3334 += 1.40000000000000000009 +fI[0] == strtox + + +Input: -1.4 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff b333 3333 3333 3333 +printf("%.21Lg") gives -1.39999999999999999998 +g_xfmt(0) gives 4 bytes: "-1.4" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff b333 3333 3333 3334 += -1.40000000000000000009 +fI[1] = #bfff b333 3333 3333 3333 += -1.39999999999999999998 +fI[1] == strtox + + +Input: 1.5 + +strtox consumes 3 bytes and returns 1 +with bits = #3fff c000 0 0 0 +printf("%.21Lg") gives 1.5 +g_xfmt(0) gives 3 bytes: "1.5" + +strtoIx returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtox + + +Input: -1.5 + +strtox consumes 4 bytes and returns 9 +with bits = #bfff c000 0 0 0 +printf("%.21Lg") gives -1.5 +g_xfmt(0) gives 4 bytes: "-1.5" + +strtoIx returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.6 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff cccc cccc cccc cccc +printf("%.21Lg") gives 1.59999999999999999991 +g_xfmt(0) gives 21 bytes: "1.5999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff cccc cccc cccc cccc += 1.59999999999999999991 +fI[1] = #3fff cccc cccc cccc cccd += 1.60000000000000000002 +fI[0] == strtox + + +Input: -1.6 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff cccc cccc cccc cccc +printf("%.21Lg") gives -1.59999999999999999991 +g_xfmt(0) gives 22 bytes: "-1.5999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff cccc cccc cccc cccd += -1.60000000000000000002 +fI[1] = #bfff cccc cccc cccc cccc += -1.59999999999999999991 +fI[1] == strtox + + +Input: 1.7 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff d999 9999 9999 9999 +printf("%.21Lg") gives 1.69999999999999999993 +g_xfmt(0) gives 21 bytes: "1.6999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff d999 9999 9999 9999 += 1.69999999999999999993 +fI[1] = #3fff d999 9999 9999 999a += 1.70000000000000000004 +fI[0] == strtox + + +Input: -1.7 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff d999 9999 9999 9999 +printf("%.21Lg") gives -1.69999999999999999993 +g_xfmt(0) gives 22 bytes: "-1.6999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff d999 9999 9999 999a += -1.70000000000000000004 +fI[1] = #bfff d999 9999 9999 9999 += -1.69999999999999999993 +fI[1] == strtox + + +Input: 1.8 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff e666 6666 6666 6666 +printf("%.21Lg") gives 1.79999999999999999996 +g_xfmt(0) gives 3 bytes: "1.8" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff e666 6666 6666 6666 += 1.79999999999999999996 +fI[1] = #3fff e666 6666 6666 6667 += 1.80000000000000000007 +fI[0] == strtox + + +Input: -1.8 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff e666 6666 6666 6666 +printf("%.21Lg") gives -1.79999999999999999996 +g_xfmt(0) gives 4 bytes: "-1.8" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff e666 6666 6666 6667 += -1.80000000000000000007 +fI[1] = #bfff e666 6666 6666 6666 += -1.79999999999999999996 +fI[1] == strtox + + +Input: 1.9 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff f333 3333 3333 3333 +printf("%.21Lg") gives 1.89999999999999999998 +g_xfmt(0) gives 3 bytes: "1.9" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff f333 3333 3333 3333 += 1.89999999999999999998 +fI[1] = #3fff f333 3333 3333 3334 += 1.90000000000000000009 +fI[0] == strtox + + +Input: -1.9 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff f333 3333 3333 3333 +printf("%.21Lg") gives -1.89999999999999999998 +g_xfmt(0) gives 4 bytes: "-1.9" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff f333 3333 3333 3334 += -1.90000000000000000009 +fI[1] = #bfff f333 3333 3333 3333 += -1.89999999999999999998 +fI[1] == strtox + +Rounding mode for strtor... changed from 0 (toward zero) to 1 (nearest) + +Input: 1.1 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff 8ccc cccc cccc cccd +printf("%.21Lg") gives 1.10000000000000000002 +g_xfmt(0) gives 3 bytes: "1.1" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 8ccc cccc cccc cccc += 1.09999999999999999991 +fI[1] = #3fff 8ccc cccc cccc cccd += 1.10000000000000000002 +fI[1] == strtox + + +Input: -1.1 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff 8ccc cccc cccc cccd +printf("%.21Lg") gives -1.10000000000000000002 +g_xfmt(0) gives 4 bytes: "-1.1" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 8ccc cccc cccc cccd += -1.10000000000000000002 +fI[1] = #bfff 8ccc cccc cccc cccc += -1.09999999999999999991 +fI[0] == strtox + + +Input: 1.2 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff 9999 9999 9999 999a +printf("%.21Lg") gives 1.20000000000000000004 +g_xfmt(0) gives 3 bytes: "1.2" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 9999 9999 9999 9999 += 1.19999999999999999993 +fI[1] = #3fff 9999 9999 9999 999a += 1.20000000000000000004 +fI[1] == strtox + + +Input: -1.2 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff 9999 9999 9999 999a +printf("%.21Lg") gives -1.20000000000000000004 +g_xfmt(0) gives 4 bytes: "-1.2" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 9999 9999 9999 999a += -1.20000000000000000004 +fI[1] = #bfff 9999 9999 9999 9999 += -1.19999999999999999993 +fI[0] == strtox + + +Input: 1.3 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff a666 6666 6666 6666 +printf("%.21Lg") gives 1.29999999999999999996 +g_xfmt(0) gives 3 bytes: "1.3" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff a666 6666 6666 6666 += 1.29999999999999999996 +fI[1] = #3fff a666 6666 6666 6667 += 1.30000000000000000007 +fI[0] == strtox + + +Input: -1.3 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff a666 6666 6666 6666 +printf("%.21Lg") gives -1.29999999999999999996 +g_xfmt(0) gives 4 bytes: "-1.3" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff a666 6666 6666 6667 += -1.30000000000000000007 +fI[1] = #bfff a666 6666 6666 6666 += -1.29999999999999999996 +fI[1] == strtox + + +Input: 1.4 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff b333 3333 3333 3333 +printf("%.21Lg") gives 1.39999999999999999998 +g_xfmt(0) gives 3 bytes: "1.4" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff b333 3333 3333 3333 += 1.39999999999999999998 +fI[1] = #3fff b333 3333 3333 3334 += 1.40000000000000000009 +fI[0] == strtox + + +Input: -1.4 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff b333 3333 3333 3333 +printf("%.21Lg") gives -1.39999999999999999998 +g_xfmt(0) gives 4 bytes: "-1.4" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff b333 3333 3333 3334 += -1.40000000000000000009 +fI[1] = #bfff b333 3333 3333 3333 += -1.39999999999999999998 +fI[1] == strtox + + +Input: 1.5 + +strtox consumes 3 bytes and returns 1 +with bits = #3fff c000 0 0 0 +printf("%.21Lg") gives 1.5 +g_xfmt(0) gives 3 bytes: "1.5" + +strtoIx returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtox + + +Input: -1.5 + +strtox consumes 4 bytes and returns 9 +with bits = #bfff c000 0 0 0 +printf("%.21Lg") gives -1.5 +g_xfmt(0) gives 4 bytes: "-1.5" + +strtoIx returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.6 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff cccc cccc cccc cccd +printf("%.21Lg") gives 1.60000000000000000002 +g_xfmt(0) gives 3 bytes: "1.6" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff cccc cccc cccc cccc += 1.59999999999999999991 +fI[1] = #3fff cccc cccc cccc cccd += 1.60000000000000000002 +fI[1] == strtox + + +Input: -1.6 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff cccc cccc cccc cccd +printf("%.21Lg") gives -1.60000000000000000002 +g_xfmt(0) gives 4 bytes: "-1.6" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff cccc cccc cccc cccd += -1.60000000000000000002 +fI[1] = #bfff cccc cccc cccc cccc += -1.59999999999999999991 +fI[0] == strtox + + +Input: 1.7 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff d999 9999 9999 999a +printf("%.21Lg") gives 1.70000000000000000004 +g_xfmt(0) gives 3 bytes: "1.7" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff d999 9999 9999 9999 += 1.69999999999999999993 +fI[1] = #3fff d999 9999 9999 999a += 1.70000000000000000004 +fI[1] == strtox + + +Input: -1.7 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff d999 9999 9999 999a +printf("%.21Lg") gives -1.70000000000000000004 +g_xfmt(0) gives 4 bytes: "-1.7" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff d999 9999 9999 999a += -1.70000000000000000004 +fI[1] = #bfff d999 9999 9999 9999 += -1.69999999999999999993 +fI[0] == strtox + + +Input: 1.8 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff e666 6666 6666 6666 +printf("%.21Lg") gives 1.79999999999999999996 +g_xfmt(0) gives 3 bytes: "1.8" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff e666 6666 6666 6666 += 1.79999999999999999996 +fI[1] = #3fff e666 6666 6666 6667 += 1.80000000000000000007 +fI[0] == strtox + + +Input: -1.8 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff e666 6666 6666 6666 +printf("%.21Lg") gives -1.79999999999999999996 +g_xfmt(0) gives 4 bytes: "-1.8" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff e666 6666 6666 6667 += -1.80000000000000000007 +fI[1] = #bfff e666 6666 6666 6666 += -1.79999999999999999996 +fI[1] == strtox + + +Input: 1.9 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff f333 3333 3333 3333 +printf("%.21Lg") gives 1.89999999999999999998 +g_xfmt(0) gives 3 bytes: "1.9" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff f333 3333 3333 3333 += 1.89999999999999999998 +fI[1] = #3fff f333 3333 3333 3334 += 1.90000000000000000009 +fI[0] == strtox + + +Input: -1.9 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff f333 3333 3333 3333 +printf("%.21Lg") gives -1.89999999999999999998 +g_xfmt(0) gives 4 bytes: "-1.9" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff f333 3333 3333 3334 += -1.90000000000000000009 +fI[1] = #bfff f333 3333 3333 3333 += -1.89999999999999999998 +fI[1] == strtox + +Rounding mode for strtor... changed from 1 (nearest) to 2 (toward +Infinity) + +Input: 1.1 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff 8ccc cccc cccc cccd +printf("%.21Lg") gives 1.10000000000000000002 +g_xfmt(0) gives 3 bytes: "1.1" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 8ccc cccc cccc cccc += 1.09999999999999999991 +fI[1] = #3fff 8ccc cccc cccc cccd += 1.10000000000000000002 +fI[1] == strtox + + +Input: -1.1 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff 8ccc cccc cccc cccc +printf("%.21Lg") gives -1.09999999999999999991 +g_xfmt(0) gives 22 bytes: "-1.0999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 8ccc cccc cccc cccd += -1.10000000000000000002 +fI[1] = #bfff 8ccc cccc cccc cccc += -1.09999999999999999991 +fI[1] == strtox + + +Input: 1.2 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff 9999 9999 9999 999a +printf("%.21Lg") gives 1.20000000000000000004 +g_xfmt(0) gives 3 bytes: "1.2" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 9999 9999 9999 9999 += 1.19999999999999999993 +fI[1] = #3fff 9999 9999 9999 999a += 1.20000000000000000004 +fI[1] == strtox + + +Input: -1.2 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff 9999 9999 9999 9999 +printf("%.21Lg") gives -1.19999999999999999993 +g_xfmt(0) gives 22 bytes: "-1.1999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 9999 9999 9999 999a += -1.20000000000000000004 +fI[1] = #bfff 9999 9999 9999 9999 += -1.19999999999999999993 +fI[1] == strtox + + +Input: 1.3 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff a666 6666 6666 6667 +printf("%.21Lg") gives 1.30000000000000000007 +g_xfmt(0) gives 21 bytes: "1.3000000000000000001" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff a666 6666 6666 6666 += 1.29999999999999999996 +fI[1] = #3fff a666 6666 6666 6667 += 1.30000000000000000007 +fI[1] == strtox + + +Input: -1.3 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff a666 6666 6666 6666 +printf("%.21Lg") gives -1.29999999999999999996 +g_xfmt(0) gives 4 bytes: "-1.3" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff a666 6666 6666 6667 += -1.30000000000000000007 +fI[1] = #bfff a666 6666 6666 6666 += -1.29999999999999999996 +fI[1] == strtox + + +Input: 1.4 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff b333 3333 3333 3334 +printf("%.21Lg") gives 1.40000000000000000009 +g_xfmt(0) gives 21 bytes: "1.4000000000000000001" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff b333 3333 3333 3333 += 1.39999999999999999998 +fI[1] = #3fff b333 3333 3333 3334 += 1.40000000000000000009 +fI[1] == strtox + + +Input: -1.4 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff b333 3333 3333 3333 +printf("%.21Lg") gives -1.39999999999999999998 +g_xfmt(0) gives 4 bytes: "-1.4" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff b333 3333 3333 3334 += -1.40000000000000000009 +fI[1] = #bfff b333 3333 3333 3333 += -1.39999999999999999998 +fI[1] == strtox + + +Input: 1.5 + +strtox consumes 3 bytes and returns 1 +with bits = #3fff c000 0 0 0 +printf("%.21Lg") gives 1.5 +g_xfmt(0) gives 3 bytes: "1.5" + +strtoIx returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtox + + +Input: -1.5 + +strtox consumes 4 bytes and returns 9 +with bits = #bfff c000 0 0 0 +printf("%.21Lg") gives -1.5 +g_xfmt(0) gives 4 bytes: "-1.5" + +strtoIx returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.6 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff cccc cccc cccc cccd +printf("%.21Lg") gives 1.60000000000000000002 +g_xfmt(0) gives 3 bytes: "1.6" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff cccc cccc cccc cccc += 1.59999999999999999991 +fI[1] = #3fff cccc cccc cccc cccd += 1.60000000000000000002 +fI[1] == strtox + + +Input: -1.6 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff cccc cccc cccc cccc +printf("%.21Lg") gives -1.59999999999999999991 +g_xfmt(0) gives 22 bytes: "-1.5999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff cccc cccc cccc cccd += -1.60000000000000000002 +fI[1] = #bfff cccc cccc cccc cccc += -1.59999999999999999991 +fI[1] == strtox + + +Input: 1.7 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff d999 9999 9999 999a +printf("%.21Lg") gives 1.70000000000000000004 +g_xfmt(0) gives 3 bytes: "1.7" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff d999 9999 9999 9999 += 1.69999999999999999993 +fI[1] = #3fff d999 9999 9999 999a += 1.70000000000000000004 +fI[1] == strtox + + +Input: -1.7 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff d999 9999 9999 9999 +printf("%.21Lg") gives -1.69999999999999999993 +g_xfmt(0) gives 22 bytes: "-1.6999999999999999999" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff d999 9999 9999 999a += -1.70000000000000000004 +fI[1] = #bfff d999 9999 9999 9999 += -1.69999999999999999993 +fI[1] == strtox + + +Input: 1.8 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff e666 6666 6666 6667 +printf("%.21Lg") gives 1.80000000000000000007 +g_xfmt(0) gives 21 bytes: "1.8000000000000000001" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff e666 6666 6666 6666 += 1.79999999999999999996 +fI[1] = #3fff e666 6666 6666 6667 += 1.80000000000000000007 +fI[1] == strtox + + +Input: -1.8 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff e666 6666 6666 6666 +printf("%.21Lg") gives -1.79999999999999999996 +g_xfmt(0) gives 4 bytes: "-1.8" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff e666 6666 6666 6667 += -1.80000000000000000007 +fI[1] = #bfff e666 6666 6666 6666 += -1.79999999999999999996 +fI[1] == strtox + + +Input: 1.9 + +strtox consumes 3 bytes and returns 33 +with bits = #3fff f333 3333 3333 3334 +printf("%.21Lg") gives 1.90000000000000000009 +g_xfmt(0) gives 21 bytes: "1.9000000000000000001" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff f333 3333 3333 3333 += 1.89999999999999999998 +fI[1] = #3fff f333 3333 3333 3334 += 1.90000000000000000009 +fI[1] == strtox + + +Input: -1.9 + +strtox consumes 4 bytes and returns 25 +with bits = #bfff f333 3333 3333 3333 +printf("%.21Lg") gives -1.89999999999999999998 +g_xfmt(0) gives 4 bytes: "-1.9" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff f333 3333 3333 3334 += -1.90000000000000000009 +fI[1] = #bfff f333 3333 3333 3333 += -1.89999999999999999998 +fI[1] == strtox + +Rounding mode for strtor... changed from 2 (toward +Infinity) to 3 (toward -Infinity) + +Input: 1.1 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff 8ccc cccc cccc cccc +printf("%.21Lg") gives 1.09999999999999999991 +g_xfmt(0) gives 21 bytes: "1.0999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 8ccc cccc cccc cccc += 1.09999999999999999991 +fI[1] = #3fff 8ccc cccc cccc cccd += 1.10000000000000000002 +fI[0] == strtox + + +Input: -1.1 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff 8ccc cccc cccc cccd +printf("%.21Lg") gives -1.10000000000000000002 +g_xfmt(0) gives 4 bytes: "-1.1" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 8ccc cccc cccc cccd += -1.10000000000000000002 +fI[1] = #bfff 8ccc cccc cccc cccc += -1.09999999999999999991 +fI[0] == strtox + + +Input: 1.2 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff 9999 9999 9999 9999 +printf("%.21Lg") gives 1.19999999999999999993 +g_xfmt(0) gives 21 bytes: "1.1999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff 9999 9999 9999 9999 += 1.19999999999999999993 +fI[1] = #3fff 9999 9999 9999 999a += 1.20000000000000000004 +fI[0] == strtox + + +Input: -1.2 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff 9999 9999 9999 999a +printf("%.21Lg") gives -1.20000000000000000004 +g_xfmt(0) gives 4 bytes: "-1.2" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff 9999 9999 9999 999a += -1.20000000000000000004 +fI[1] = #bfff 9999 9999 9999 9999 += -1.19999999999999999993 +fI[0] == strtox + + +Input: 1.3 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff a666 6666 6666 6666 +printf("%.21Lg") gives 1.29999999999999999996 +g_xfmt(0) gives 3 bytes: "1.3" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff a666 6666 6666 6666 += 1.29999999999999999996 +fI[1] = #3fff a666 6666 6666 6667 += 1.30000000000000000007 +fI[0] == strtox + + +Input: -1.3 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff a666 6666 6666 6667 +printf("%.21Lg") gives -1.30000000000000000007 +g_xfmt(0) gives 22 bytes: "-1.3000000000000000001" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff a666 6666 6666 6667 += -1.30000000000000000007 +fI[1] = #bfff a666 6666 6666 6666 += -1.29999999999999999996 +fI[0] == strtox + + +Input: 1.4 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff b333 3333 3333 3333 +printf("%.21Lg") gives 1.39999999999999999998 +g_xfmt(0) gives 3 bytes: "1.4" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff b333 3333 3333 3333 += 1.39999999999999999998 +fI[1] = #3fff b333 3333 3333 3334 += 1.40000000000000000009 +fI[0] == strtox + + +Input: -1.4 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff b333 3333 3333 3334 +printf("%.21Lg") gives -1.40000000000000000009 +g_xfmt(0) gives 22 bytes: "-1.4000000000000000001" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff b333 3333 3333 3334 += -1.40000000000000000009 +fI[1] = #bfff b333 3333 3333 3333 += -1.39999999999999999998 +fI[0] == strtox + + +Input: 1.5 + +strtox consumes 3 bytes and returns 1 +with bits = #3fff c000 0 0 0 +printf("%.21Lg") gives 1.5 +g_xfmt(0) gives 3 bytes: "1.5" + +strtoIx returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtox + + +Input: -1.5 + +strtox consumes 4 bytes and returns 9 +with bits = #bfff c000 0 0 0 +printf("%.21Lg") gives -1.5 +g_xfmt(0) gives 4 bytes: "-1.5" + +strtoIx returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtox + + +Input: 1.6 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff cccc cccc cccc cccc +printf("%.21Lg") gives 1.59999999999999999991 +g_xfmt(0) gives 21 bytes: "1.5999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff cccc cccc cccc cccc += 1.59999999999999999991 +fI[1] = #3fff cccc cccc cccc cccd += 1.60000000000000000002 +fI[0] == strtox + + +Input: -1.6 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff cccc cccc cccc cccd +printf("%.21Lg") gives -1.60000000000000000002 +g_xfmt(0) gives 4 bytes: "-1.6" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff cccc cccc cccc cccd += -1.60000000000000000002 +fI[1] = #bfff cccc cccc cccc cccc += -1.59999999999999999991 +fI[0] == strtox + + +Input: 1.7 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff d999 9999 9999 9999 +printf("%.21Lg") gives 1.69999999999999999993 +g_xfmt(0) gives 21 bytes: "1.6999999999999999999" + +strtoIx returns 33, consuming 3 bytes. +fI[0] = #3fff d999 9999 9999 9999 += 1.69999999999999999993 +fI[1] = #3fff d999 9999 9999 999a += 1.70000000000000000004 +fI[0] == strtox + + +Input: -1.7 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff d999 9999 9999 999a +printf("%.21Lg") gives -1.70000000000000000004 +g_xfmt(0) gives 4 bytes: "-1.7" + +strtoIx returns 41, consuming 4 bytes. +fI[0] = #bfff d999 9999 9999 999a += -1.70000000000000000004 +fI[1] = #bfff d999 9999 9999 9999 += -1.69999999999999999993 +fI[0] == strtox + + +Input: 1.8 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff e666 6666 6666 6666 +printf("%.21Lg") gives 1.79999999999999999996 +g_xfmt(0) gives 3 bytes: "1.8" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff e666 6666 6666 6666 += 1.79999999999999999996 +fI[1] = #3fff e666 6666 6666 6667 += 1.80000000000000000007 +fI[0] == strtox + + +Input: -1.8 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff e666 6666 6666 6667 +printf("%.21Lg") gives -1.80000000000000000007 +g_xfmt(0) gives 22 bytes: "-1.8000000000000000001" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff e666 6666 6666 6667 += -1.80000000000000000007 +fI[1] = #bfff e666 6666 6666 6666 += -1.79999999999999999996 +fI[0] == strtox + + +Input: 1.9 + +strtox consumes 3 bytes and returns 17 +with bits = #3fff f333 3333 3333 3333 +printf("%.21Lg") gives 1.89999999999999999998 +g_xfmt(0) gives 3 bytes: "1.9" + +strtoIx returns 17, consuming 3 bytes. +fI[0] = #3fff f333 3333 3333 3333 += 1.89999999999999999998 +fI[1] = #3fff f333 3333 3333 3334 += 1.90000000000000000009 +fI[0] == strtox + + +Input: -1.9 + +strtox consumes 4 bytes and returns 41 +with bits = #bfff f333 3333 3333 3334 +printf("%.21Lg") gives -1.90000000000000000009 +g_xfmt(0) gives 22 bytes: "-1.9000000000000000001" + +strtoIx returns 25, consuming 4 bytes. +fI[0] = #bfff f333 3333 3333 3334 += -1.90000000000000000009 +fI[1] = #bfff f333 3333 3333 3333 += -1.89999999999999999998 +fI[0] == strtox + diff --git a/lib/libc/gdtoa/test/xL.ou0 b/lib/libc/gdtoa/test/xL.ou0 new file mode 100644 index 000000000..dc75f9113 --- /dev/null +++ b/lib/libc/gdtoa/test/xL.ou0 @@ -0,0 +1,1182 @@ + +Input: 1.23 + +strtoxL consumes 4 bytes and returns 33 +with bits = #3fff0000 9d70a3d7 a3d70a4 +g_xLfmt(0) gives 4 bytes: "1.23" + +strtoIxL returns 33, consuming 4 bytes. +fI[0] = #3fff0000 9d70a3d7 a3d70a3 +fI[1] = #3fff0000 9d70a3d7 a3d70a4 +fI[1] == strtoxL + + +Input: 1.23e+20 + +strtoxL consumes 8 bytes and returns 1 +with bits = #40410000 d55ef90a 2da18000 +g_xLfmt(0) gives 8 bytes: "1.23e+20" + +strtoIxL returns 1, consuming 8 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.23e-20 + +strtoxL consumes 8 bytes and returns 17 +with bits = #3fbc0000 e857267b b3a984f2 +g_xLfmt(0) gives 8 bytes: "1.23e-20" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #3fbc0000 e857267b b3a984f2 +fI[1] = #3fbc0000 e857267b b3a984f3 +fI[0] == strtoxL + + +Input: 1.23456789 + +strtoxL consumes 10 bytes and returns 33 +with bits = #3fff0000 9e065214 1ef0dbf6 +g_xLfmt(0) gives 10 bytes: "1.23456789" + +strtoIxL returns 33, consuming 10 bytes. +fI[0] = #3fff0000 9e065214 1ef0dbf5 +fI[1] = #3fff0000 9e065214 1ef0dbf6 +fI[1] == strtoxL + + +Input: 1.23456589e+20 + +strtoxL consumes 14 bytes and returns 1 +with bits = #40410000 d629bd33 5ccba00 +g_xLfmt(0) gives 14 bytes: "1.23456589e+20" + +strtoIxL returns 1, consuming 14 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.23e+30 + +strtoxL consumes 8 bytes and returns 17 +with bits = #40620000 f8658274 7dbc824a +g_xLfmt(0) gives 8 bytes: "1.23e+30" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #40620000 f8658274 7dbc824a +fI[1] = #40620000 f8658274 7dbc824b +fI[0] == strtoxL + + +Input: 1.23e-30 + +strtoxL consumes 8 bytes and returns 17 +with bits = #3f9b0000 c794337a 808554eb +g_xLfmt(0) gives 8 bytes: "1.23e-30" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #3f9b0000 c794337a 808554eb +fI[1] = #3f9b0000 c794337a 808554ec +fI[0] == strtoxL + + +Input: 1.23456789e-20 + +strtoxL consumes 14 bytes and returns 17 +with bits = #3fbc0000 e9340a38 f3d6d352 +g_xLfmt(0) gives 14 bytes: "1.23456789e-20" + +strtoIxL returns 17, consuming 14 bytes. +fI[0] = #3fbc0000 e9340a38 f3d6d352 +fI[1] = #3fbc0000 e9340a38 f3d6d353 +fI[0] == strtoxL + + +Input: 1.23456789e-30 + +strtoxL consumes 14 bytes and returns 17 +with bits = #3f9b0000 c851f19d decca8fc +g_xLfmt(0) gives 14 bytes: "1.23456789e-30" + +strtoIxL returns 17, consuming 14 bytes. +fI[0] = #3f9b0000 c851f19d decca8fc +fI[1] = #3f9b0000 c851f19d decca8fd +fI[0] == strtoxL + + +Input: 1.234567890123456789 + +strtoxL consumes 20 bytes and returns 17 +with bits = #3fff0000 9e065214 62cfdb8d +g_xLfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIxL returns 17, consuming 20 bytes. +fI[0] = #3fff0000 9e065214 62cfdb8d +fI[1] = #3fff0000 9e065214 62cfdb8e +fI[0] == strtoxL + + +Input: 1.23456789012345678901234567890123456789 + +strtoxL consumes 40 bytes and returns 17 +with bits = #3fff0000 9e065214 62cfdb8d +g_xLfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIxL returns 17, consuming 40 bytes. +fI[0] = #3fff0000 9e065214 62cfdb8d +fI[1] = #3fff0000 9e065214 62cfdb8e +fI[0] == strtoxL + + +Input: 1.23e306 + +strtoxL consumes 8 bytes and returns 17 +with bits = #43f70000 e033b668 e30fa6d5 +g_xLfmt(0) gives 9 bytes: "1.23e+306" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #43f70000 e033b668 e30fa6d5 +fI[1] = #43f70000 e033b668 e30fa6d6 +fI[0] == strtoxL + + +Input: 1.23e-306 + +strtoxL consumes 9 bytes and returns 33 +with bits = #3c060000 dd1dc2ed 1cb73f25 +g_xLfmt(0) gives 9 bytes: "1.23e-306" + +strtoIxL returns 33, consuming 9 bytes. +fI[0] = #3c060000 dd1dc2ed 1cb73f24 +fI[1] = #3c060000 dd1dc2ed 1cb73f25 +fI[1] == strtoxL + + +Input: 1.23e-320 + +strtoxL consumes 9 bytes and returns 33 +with bits = #3bd80000 9b98c371 844c3f1a +g_xLfmt(0) gives 9 bytes: "1.23e-320" + +strtoIxL returns 33, consuming 9 bytes. +fI[0] = #3bd80000 9b98c371 844c3f19 +fI[1] = #3bd80000 9b98c371 844c3f1a +fI[1] == strtoxL + + +Input: 1.23e-20 + +strtoxL consumes 8 bytes and returns 17 +with bits = #3fbc0000 e857267b b3a984f2 +g_xLfmt(0) gives 8 bytes: "1.23e-20" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #3fbc0000 e857267b b3a984f2 +fI[1] = #3fbc0000 e857267b b3a984f3 +fI[0] == strtoxL + + +Input: 1.23456789e307 + +strtoxL consumes 14 bytes and returns 17 +with bits = #43fb0000 8ca58a5e d766de75 +g_xLfmt(0) gives 15 bytes: "1.23456789e+307" + +strtoIxL returns 17, consuming 14 bytes. +fI[0] = #43fb0000 8ca58a5e d766de75 +fI[1] = #43fb0000 8ca58a5e d766de76 +fI[0] == strtoxL + + +Input: 1.23456589e-307 + +strtoxL consumes 15 bytes and returns 17 +with bits = #3c030000 b18cb5dc c22fd369 +g_xLfmt(0) gives 15 bytes: "1.23456589e-307" + +strtoIxL returns 17, consuming 15 bytes. +fI[0] = #3c030000 b18cb5dc c22fd369 +fI[1] = #3c030000 b18cb5dc c22fd36a +fI[0] == strtoxL + + +Input: 1.234567890123456789 + +strtoxL consumes 20 bytes and returns 17 +with bits = #3fff0000 9e065214 62cfdb8d +g_xLfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIxL returns 17, consuming 20 bytes. +fI[0] = #3fff0000 9e065214 62cfdb8d +fI[1] = #3fff0000 9e065214 62cfdb8e +fI[0] == strtoxL + + +Input: 1.234567890123456789e301 + +strtoxL consumes 24 bytes and returns 33 +with bits = #43e70000 937a8baf ab20980c +g_xLfmt(0) gives 25 bytes: "1.234567890123456789e+301" + +strtoIxL returns 33, consuming 24 bytes. +fI[0] = #43e70000 937a8baf ab20980b +fI[1] = #43e70000 937a8baf ab20980c +fI[1] == strtoxL + + +Input: 1.234567890123456789e-301 + +strtoxL consumes 25 bytes and returns 33 +with bits = #3c170000 a953271a 5d069ad9 +g_xLfmt(0) gives 25 bytes: "1.234567890123456789e-301" + +strtoIxL returns 33, consuming 25 bytes. +fI[0] = #3c170000 a953271a 5d069ad8 +fI[1] = #3c170000 a953271a 5d069ad9 +fI[1] == strtoxL + + +Input: 1.234567890123456789e-321 + +strtoxL consumes 25 bytes and returns 33 +with bits = #3bd40000 f9e11b4c ea6dcce9 +g_xLfmt(0) gives 25 bytes: "1.234567890123456789e-321" + +strtoIxL returns 33, consuming 25 bytes. +fI[0] = #3bd40000 f9e11b4c ea6dcce8 +fI[1] = #3bd40000 f9e11b4c ea6dcce9 +fI[1] == strtoxL + + +Input: 1e23 + +strtoxL consumes 4 bytes and returns 1 +with bits = #404b0000 a968163f a57b400 +g_xLfmt(0) gives 5 bytes: "1e+23" + +strtoIxL returns 1, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1e310 + +strtoxL consumes 5 bytes and returns 33 +with bits = #44040000 de81e40a 34bcf50 +g_xLfmt(0) gives 6 bytes: "1e+310" + +strtoIxL returns 33, consuming 5 bytes. +fI[0] = #44040000 de81e40a 34bcf4f +fI[1] = #44040000 de81e40a 34bcf50 +fI[1] == strtoxL + + +Input: 9.0259718793241475e-277 + +strtoxL consumes 23 bytes and returns 33 +with bits = #3c690000 ffffffff fffffcf7 +g_xLfmt(0) gives 23 bytes: "9.0259718793241475e-277" + +strtoIxL returns 33, consuming 23 bytes. +fI[0] = #3c690000 ffffffff fffffcf6 +fI[1] = #3c690000 ffffffff fffffcf7 +fI[1] == strtoxL + + +Input: 9.025971879324147880346310405869e-277 + +strtoxL consumes 37 bytes and returns 17 +with bits = #3c6a0000 80000000 0 +g_xLfmt(0) gives 26 bytes: "9.0259718793241478803e-277" + +strtoIxL returns 17, consuming 37 bytes. +fI[0] = #3c6a0000 80000000 0 +fI[1] = #3c6a0000 80000000 1 +fI[0] == strtoxL + + +Input: 9.025971879324147880346310405868e-277 + +strtoxL consumes 37 bytes and returns 33 +with bits = #3c6a0000 80000000 0 +g_xLfmt(0) gives 26 bytes: "9.0259718793241478803e-277" + +strtoIxL returns 33, consuming 37 bytes. +fI[0] = #3c690000 ffffffff ffffffff +fI[1] = #3c6a0000 80000000 0 +fI[1] == strtoxL + + +Input: 2.2250738585072014e-308 + +strtoxL consumes 23 bytes and returns 17 +with bits = #3c010000 80000000 46 +g_xLfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoIxL returns 17, consuming 23 bytes. +fI[0] = #3c010000 80000000 46 +fI[1] = #3c010000 80000000 47 +fI[0] == strtoxL + + +Input: 2.2250738585072013e-308 + +strtoxL consumes 23 bytes and returns 17 +with bits = #3c000000 ffffffff fffffd4f +g_xLfmt(0) gives 23 bytes: "2.2250738585072013e-308" + +strtoIxL returns 17, consuming 23 bytes. +fI[0] = #3c000000 ffffffff fffffd4f +fI[1] = #3c000000 ffffffff fffffd50 +fI[0] == strtoxL + +Rounding mode for strtor... changed from 1 (nearest) to 0 (toward zero) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 8ccccccc cccccccc +g_xLfmt(0) gives 21 bytes: "1.0999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc +fI[1] = #3fff0000 8ccccccc cccccccd +fI[0] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 8ccccccc cccccccc +g_xLfmt(0) gives 22 bytes: "-1.0999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd +fI[1] = #bfff0000 8ccccccc cccccccc +fI[1] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 99999999 99999999 +g_xLfmt(0) gives 21 bytes: "1.1999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 +fI[1] = #3fff0000 99999999 9999999a +fI[0] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 99999999 99999999 +g_xLfmt(0) gives 22 bytes: "-1.1999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a +fI[1] = #bfff0000 99999999 99999999 +fI[1] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 a6666666 66666666 +g_xLfmt(0) gives 3 bytes: "1.3" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 +fI[1] = #3fff0000 a6666666 66666667 +fI[0] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 a6666666 66666666 +g_xLfmt(0) gives 4 bytes: "-1.3" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 +fI[1] = #bfff0000 a6666666 66666666 +fI[1] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 b3333333 33333333 +g_xLfmt(0) gives 3 bytes: "1.4" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 +fI[1] = #3fff0000 b3333333 33333334 +fI[0] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 b3333333 33333333 +g_xLfmt(0) gives 4 bytes: "-1.4" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 +fI[1] = #bfff0000 b3333333 33333333 +fI[1] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 cccccccc cccccccc +g_xLfmt(0) gives 21 bytes: "1.5999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc +fI[1] = #3fff0000 cccccccc cccccccd +fI[0] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 cccccccc cccccccc +g_xLfmt(0) gives 22 bytes: "-1.5999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd +fI[1] = #bfff0000 cccccccc cccccccc +fI[1] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 d9999999 99999999 +g_xLfmt(0) gives 21 bytes: "1.6999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 +fI[1] = #3fff0000 d9999999 9999999a +fI[0] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 d9999999 99999999 +g_xLfmt(0) gives 22 bytes: "-1.6999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a +fI[1] = #bfff0000 d9999999 99999999 +fI[1] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 e6666666 66666666 +g_xLfmt(0) gives 3 bytes: "1.8" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 +fI[1] = #3fff0000 e6666666 66666667 +fI[0] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 e6666666 66666666 +g_xLfmt(0) gives 4 bytes: "-1.8" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 +fI[1] = #bfff0000 e6666666 66666666 +fI[1] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 f3333333 33333333 +g_xLfmt(0) gives 3 bytes: "1.9" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 +fI[1] = #3fff0000 f3333333 33333334 +fI[0] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 f3333333 33333333 +g_xLfmt(0) gives 4 bytes: "-1.9" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 +fI[1] = #bfff0000 f3333333 33333333 +fI[1] == strtoxL + +Rounding mode for strtor... changed from 0 (toward zero) to 1 (nearest) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 8ccccccc cccccccd +g_xLfmt(0) gives 3 bytes: "1.1" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc +fI[1] = #3fff0000 8ccccccc cccccccd +fI[1] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 8ccccccc cccccccd +g_xLfmt(0) gives 4 bytes: "-1.1" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd +fI[1] = #bfff0000 8ccccccc cccccccc +fI[0] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 99999999 9999999a +g_xLfmt(0) gives 3 bytes: "1.2" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 +fI[1] = #3fff0000 99999999 9999999a +fI[1] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 99999999 9999999a +g_xLfmt(0) gives 4 bytes: "-1.2" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a +fI[1] = #bfff0000 99999999 99999999 +fI[0] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 a6666666 66666666 +g_xLfmt(0) gives 3 bytes: "1.3" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 +fI[1] = #3fff0000 a6666666 66666667 +fI[0] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 a6666666 66666666 +g_xLfmt(0) gives 4 bytes: "-1.3" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 +fI[1] = #bfff0000 a6666666 66666666 +fI[1] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 b3333333 33333333 +g_xLfmt(0) gives 3 bytes: "1.4" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 +fI[1] = #3fff0000 b3333333 33333334 +fI[0] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 b3333333 33333333 +g_xLfmt(0) gives 4 bytes: "-1.4" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 +fI[1] = #bfff0000 b3333333 33333333 +fI[1] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 cccccccc cccccccd +g_xLfmt(0) gives 3 bytes: "1.6" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc +fI[1] = #3fff0000 cccccccc cccccccd +fI[1] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 cccccccc cccccccd +g_xLfmt(0) gives 4 bytes: "-1.6" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd +fI[1] = #bfff0000 cccccccc cccccccc +fI[0] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 d9999999 9999999a +g_xLfmt(0) gives 3 bytes: "1.7" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 +fI[1] = #3fff0000 d9999999 9999999a +fI[1] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 d9999999 9999999a +g_xLfmt(0) gives 4 bytes: "-1.7" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a +fI[1] = #bfff0000 d9999999 99999999 +fI[0] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 e6666666 66666666 +g_xLfmt(0) gives 3 bytes: "1.8" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 +fI[1] = #3fff0000 e6666666 66666667 +fI[0] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 e6666666 66666666 +g_xLfmt(0) gives 4 bytes: "-1.8" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 +fI[1] = #bfff0000 e6666666 66666666 +fI[1] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 f3333333 33333333 +g_xLfmt(0) gives 3 bytes: "1.9" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 +fI[1] = #3fff0000 f3333333 33333334 +fI[0] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 f3333333 33333333 +g_xLfmt(0) gives 4 bytes: "-1.9" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 +fI[1] = #bfff0000 f3333333 33333333 +fI[1] == strtoxL + +Rounding mode for strtor... changed from 1 (nearest) to 2 (toward +Infinity) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 8ccccccc cccccccd +g_xLfmt(0) gives 3 bytes: "1.1" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc +fI[1] = #3fff0000 8ccccccc cccccccd +fI[1] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 8ccccccc cccccccc +g_xLfmt(0) gives 22 bytes: "-1.0999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd +fI[1] = #bfff0000 8ccccccc cccccccc +fI[1] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 99999999 9999999a +g_xLfmt(0) gives 3 bytes: "1.2" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 +fI[1] = #3fff0000 99999999 9999999a +fI[1] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 99999999 99999999 +g_xLfmt(0) gives 22 bytes: "-1.1999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a +fI[1] = #bfff0000 99999999 99999999 +fI[1] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 a6666666 66666667 +g_xLfmt(0) gives 21 bytes: "1.3000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 +fI[1] = #3fff0000 a6666666 66666667 +fI[1] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 a6666666 66666666 +g_xLfmt(0) gives 4 bytes: "-1.3" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 +fI[1] = #bfff0000 a6666666 66666666 +fI[1] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 b3333333 33333334 +g_xLfmt(0) gives 21 bytes: "1.4000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 +fI[1] = #3fff0000 b3333333 33333334 +fI[1] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 b3333333 33333333 +g_xLfmt(0) gives 4 bytes: "-1.4" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 +fI[1] = #bfff0000 b3333333 33333333 +fI[1] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 cccccccc cccccccd +g_xLfmt(0) gives 3 bytes: "1.6" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc +fI[1] = #3fff0000 cccccccc cccccccd +fI[1] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 cccccccc cccccccc +g_xLfmt(0) gives 22 bytes: "-1.5999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd +fI[1] = #bfff0000 cccccccc cccccccc +fI[1] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 d9999999 9999999a +g_xLfmt(0) gives 3 bytes: "1.7" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 +fI[1] = #3fff0000 d9999999 9999999a +fI[1] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 d9999999 99999999 +g_xLfmt(0) gives 22 bytes: "-1.6999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a +fI[1] = #bfff0000 d9999999 99999999 +fI[1] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 e6666666 66666667 +g_xLfmt(0) gives 21 bytes: "1.8000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 +fI[1] = #3fff0000 e6666666 66666667 +fI[1] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 e6666666 66666666 +g_xLfmt(0) gives 4 bytes: "-1.8" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 +fI[1] = #bfff0000 e6666666 66666666 +fI[1] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 f3333333 33333334 +g_xLfmt(0) gives 21 bytes: "1.9000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 +fI[1] = #3fff0000 f3333333 33333334 +fI[1] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 f3333333 33333333 +g_xLfmt(0) gives 4 bytes: "-1.9" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 +fI[1] = #bfff0000 f3333333 33333333 +fI[1] == strtoxL + +Rounding mode for strtor... changed from 2 (toward +Infinity) to 3 (toward -Infinity) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 8ccccccc cccccccc +g_xLfmt(0) gives 21 bytes: "1.0999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc +fI[1] = #3fff0000 8ccccccc cccccccd +fI[0] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 8ccccccc cccccccd +g_xLfmt(0) gives 4 bytes: "-1.1" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd +fI[1] = #bfff0000 8ccccccc cccccccc +fI[0] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 99999999 99999999 +g_xLfmt(0) gives 21 bytes: "1.1999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 +fI[1] = #3fff0000 99999999 9999999a +fI[0] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 99999999 9999999a +g_xLfmt(0) gives 4 bytes: "-1.2" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a +fI[1] = #bfff0000 99999999 99999999 +fI[0] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 a6666666 66666666 +g_xLfmt(0) gives 3 bytes: "1.3" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 +fI[1] = #3fff0000 a6666666 66666667 +fI[0] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 a6666666 66666667 +g_xLfmt(0) gives 22 bytes: "-1.3000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 +fI[1] = #bfff0000 a6666666 66666666 +fI[0] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 b3333333 33333333 +g_xLfmt(0) gives 3 bytes: "1.4" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 +fI[1] = #3fff0000 b3333333 33333334 +fI[0] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 b3333333 33333334 +g_xLfmt(0) gives 22 bytes: "-1.4000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 +fI[1] = #bfff0000 b3333333 33333333 +fI[0] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 cccccccc cccccccc +g_xLfmt(0) gives 21 bytes: "1.5999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc +fI[1] = #3fff0000 cccccccc cccccccd +fI[0] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 cccccccc cccccccd +g_xLfmt(0) gives 4 bytes: "-1.6" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd +fI[1] = #bfff0000 cccccccc cccccccc +fI[0] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 d9999999 99999999 +g_xLfmt(0) gives 21 bytes: "1.6999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 +fI[1] = #3fff0000 d9999999 9999999a +fI[0] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 d9999999 9999999a +g_xLfmt(0) gives 4 bytes: "-1.7" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a +fI[1] = #bfff0000 d9999999 99999999 +fI[0] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 e6666666 66666666 +g_xLfmt(0) gives 3 bytes: "1.8" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 +fI[1] = #3fff0000 e6666666 66666667 +fI[0] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 e6666666 66666667 +g_xLfmt(0) gives 22 bytes: "-1.8000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 +fI[1] = #bfff0000 e6666666 66666666 +fI[0] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 f3333333 33333333 +g_xLfmt(0) gives 3 bytes: "1.9" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 +fI[1] = #3fff0000 f3333333 33333334 +fI[0] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 f3333333 33333334 +g_xLfmt(0) gives 22 bytes: "-1.9000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 +fI[1] = #bfff0000 f3333333 33333333 +fI[0] == strtoxL + diff --git a/lib/libc/gdtoa/test/xL.ou1 b/lib/libc/gdtoa/test/xL.ou1 new file mode 100644 index 000000000..c22d0f418 --- /dev/null +++ b/lib/libc/gdtoa/test/xL.ou1 @@ -0,0 +1,1462 @@ +***** This file is not right. It needs to be generated on a +***** system with a Motorla 68881 or the equivalent. + +Input: 1.23 + +strtoxL consumes 4 bytes and returns 33 +with bits = #3fff0000 9d70a3d7 a3d70a4 +printf("%.21Lg") gives 7.73283722915781506499e-4933 +g_xLfmt(0) gives 4 bytes: "1.23" + +strtoIxL returns 33, consuming 4 bytes. +fI[0] = #3fff0000 9d70a3d7 a3d70a3 += 7.73283722915781506134e-4933 +fI[1] = #3fff0000 9d70a3d7 a3d70a4 += 7.73283722915781506499e-4933 +fI[1] == strtoxL + + +Input: 1.23e+20 + +strtoxL consumes 8 bytes and returns 1 +with bits = #40410000 d55ef90a 2da18000 +printf("%.21Lg") gives 2.24239113715721119512e-4932 +g_xLfmt(0) gives 8 bytes: "1.23e+20" + +strtoIxL returns 1, consuming 8 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.23e-20 + +strtoxL consumes 8 bytes and returns 17 +with bits = #3fbc0000 e857267b b3a984f2 +printf("%.21Lg") gives 2.74065070995958800375e-4932 +g_xLfmt(0) gives 8 bytes: "1.23e-20" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #3fbc0000 e857267b b3a984f2 += 2.74065070995958800375e-4932 +fI[1] = #3fbc0000 e857267b b3a984f3 += 2.74065070995958800411e-4932 +fI[0] == strtoxL + + +Input: 1.23456789 + +strtoxL consumes 10 bytes and returns 33 +with bits = #3fff0000 9e065214 1ef0dbf6 +printf("%.21Lg") gives 7.88641440242171807354e-4933 +g_xLfmt(0) gives 10 bytes: "1.23456789" + +strtoIxL returns 33, consuming 10 bytes. +fI[0] = #3fff0000 9e065214 1ef0dbf5 += 7.8864144024217180699e-4933 +fI[1] = #3fff0000 9e065214 1ef0dbf6 += 7.88641440242171807354e-4933 +fI[1] == strtoxL + + +Input: 1.23456589e+20 + +strtoxL consumes 14 bytes and returns 1 +with bits = #40410000 d629bd33 5ccba00 +printf("%.21Lg") gives 2.26319561227049478508e-4932 +g_xLfmt(0) gives 14 bytes: "1.23456589e+20" + +strtoIxL returns 1, consuming 14 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.23e+30 + +strtoxL consumes 8 bytes and returns 17 +with bits = #40620000 f8658274 7dbc824a +printf("%.21Lg") gives 3.16238691003557160385e-4932 +g_xLfmt(0) gives 8 bytes: "1.23e+30" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #40620000 f8658274 7dbc824a += 3.16238691003557160385e-4932 +fI[1] = #40620000 f8658274 7dbc824b += 3.16238691003557160421e-4932 +fI[0] == strtoxL + + +Input: 1.23e-30 + +strtoxL consumes 8 bytes and returns 17 +with bits = #3f9b0000 c794337a 808554eb +printf("%.21Lg") gives 1.88012249978407873966e-4932 +g_xLfmt(0) gives 8 bytes: "1.23e-30" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #3f9b0000 c794337a 808554eb += 1.88012249978407873966e-4932 +fI[1] = #3f9b0000 c794337a 808554ec += 1.88012249978407874003e-4932 +fI[0] == strtoxL + + +Input: 1.23456789e-20 + +strtoxL consumes 14 bytes and returns 17 +with bits = #3fbc0000 e9340a38 f3d6d352 +printf("%.21Lg") gives 2.76331470044569174626e-4932 +g_xLfmt(0) gives 14 bytes: "1.23456789e-20" + +strtoIxL returns 17, consuming 14 bytes. +fI[0] = #3fbc0000 e9340a38 f3d6d352 += 2.76331470044569174626e-4932 +fI[1] = #3fbc0000 e9340a38 f3d6d353 += 2.76331470044569174663e-4932 +fI[0] == strtoxL + + +Input: 1.23456789e-30 + +strtoxL consumes 14 bytes and returns 17 +with bits = #3f9b0000 c851f19d decca8fc +printf("%.21Lg") gives 1.89959071937101288293e-4932 +g_xLfmt(0) gives 14 bytes: "1.23456789e-30" + +strtoIxL returns 17, consuming 14 bytes. +fI[0] = #3f9b0000 c851f19d decca8fc += 1.89959071937101288293e-4932 +fI[1] = #3f9b0000 c851f19d decca8fd += 1.89959071937101288329e-4932 +fI[0] == strtoxL + + +Input: 1.234567890123456789 + +strtoxL consumes 20 bytes and returns 17 +with bits = #3fff0000 9e065214 62cfdb8d +printf("%.21Lg") gives 7.88641440657246265535e-4933 +g_xLfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIxL returns 17, consuming 20 bytes. +fI[0] = #3fff0000 9e065214 62cfdb8d += 7.88641440657246265535e-4933 +fI[1] = #3fff0000 9e065214 62cfdb8e += 7.886414406572462659e-4933 +fI[0] == strtoxL + + +Input: 1.23456789012345678901234567890123456789 + +strtoxL consumes 40 bytes and returns 17 +with bits = #3fff0000 9e065214 62cfdb8d +printf("%.21Lg") gives 7.88641440657246265535e-4933 +g_xLfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIxL returns 17, consuming 40 bytes. +fI[0] = #3fff0000 9e065214 62cfdb8d += 7.88641440657246265535e-4933 +fI[1] = #3fff0000 9e065214 62cfdb8e += 7.886414406572462659e-4933 +fI[0] == strtoxL + + +Input: 1.23e306 + +strtoxL consumes 8 bytes and returns 17 +with bits = #43f70000 e033b668 e30fa6d5 +printf("%.21Lg") gives 2.52688323155200052759e-4932 +g_xLfmt(0) gives 9 bytes: "1.23e+306" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #43f70000 e033b668 e30fa6d5 += 2.52688323155200052759e-4932 +fI[1] = #43f70000 e033b668 e30fa6d6 += 2.52688323155200052796e-4932 +fI[0] == strtoxL + + +Input: 1.23e-306 + +strtoxL consumes 9 bytes and returns 33 +with bits = #3c060000 dd1dc2ed 1cb73f25 +printf("%.21Lg") gives 2.44583168427704605801e-4932 +g_xLfmt(0) gives 9 bytes: "1.23e-306" + +strtoIxL returns 33, consuming 9 bytes. +fI[0] = #3c060000 dd1dc2ed 1cb73f24 += 2.44583168427704605765e-4932 +fI[1] = #3c060000 dd1dc2ed 1cb73f25 += 2.44583168427704605801e-4932 +fI[1] == strtoxL + + +Input: 1.23e-320 + +strtoxL consumes 9 bytes and returns 33 +with bits = #3bd80000 9b98c371 844c3f1a +printf("%.21Lg") gives 7.24867657578821329238e-4933 +g_xLfmt(0) gives 9 bytes: "1.23e-320" + +strtoIxL returns 33, consuming 9 bytes. +fI[0] = #3bd80000 9b98c371 844c3f19 += 7.24867657578821328874e-4933 +fI[1] = #3bd80000 9b98c371 844c3f1a += 7.24867657578821329238e-4933 +fI[1] == strtoxL + + +Input: 1.23e-20 + +strtoxL consumes 8 bytes and returns 17 +with bits = #3fbc0000 e857267b b3a984f2 +printf("%.21Lg") gives 2.74065070995958800375e-4932 +g_xLfmt(0) gives 8 bytes: "1.23e-20" + +strtoIxL returns 17, consuming 8 bytes. +fI[0] = #3fbc0000 e857267b b3a984f2 += 2.74065070995958800375e-4932 +fI[1] = #3fbc0000 e857267b b3a984f3 += 2.74065070995958800411e-4932 +fI[0] == strtoxL + + +Input: 1.23456789e307 + +strtoxL consumes 14 bytes and returns 17 +with bits = #43fb0000 8ca58a5e d766de75 +printf("%.21Lg") gives 3.32182163192682931854e-4933 +g_xLfmt(0) gives 15 bytes: "1.23456789e+307" + +strtoIxL returns 17, consuming 14 bytes. +fI[0] = #43fb0000 8ca58a5e d766de75 += 3.32182163192682931854e-4933 +fI[1] = #43fb0000 8ca58a5e d766de76 += 3.32182163192682932219e-4933 +fI[0] == strtoxL + + +Input: 1.23456589e-307 + +strtoxL consumes 15 bytes and returns 17 +with bits = #3c030000 b18cb5dc c22fd369 +printf("%.21Lg") gives 1.30149245314004923345e-4932 +g_xLfmt(0) gives 15 bytes: "1.23456589e-307" + +strtoIxL returns 17, consuming 15 bytes. +fI[0] = #3c030000 b18cb5dc c22fd369 += 1.30149245314004923345e-4932 +fI[1] = #3c030000 b18cb5dc c22fd36a += 1.30149245314004923382e-4932 +fI[0] == strtoxL + + +Input: 1.234567890123456789 + +strtoxL consumes 20 bytes and returns 17 +with bits = #3fff0000 9e065214 62cfdb8d +printf("%.21Lg") gives 7.88641440657246265535e-4933 +g_xLfmt(0) gives 20 bytes: "1.234567890123456789" + +strtoIxL returns 17, consuming 20 bytes. +fI[0] = #3fff0000 9e065214 62cfdb8d += 7.88641440657246265535e-4933 +fI[1] = #3fff0000 9e065214 62cfdb8e += 7.886414406572462659e-4933 +fI[0] == strtoxL + + +Input: 1.234567890123456789e301 + +strtoxL consumes 24 bytes and returns 33 +with bits = #43e70000 937a8baf ab20980c +printf("%.21Lg") gives 5.11635766619117643114e-4933 +g_xLfmt(0) gives 25 bytes: "1.234567890123456789e+301" + +strtoIxL returns 33, consuming 24 bytes. +fI[0] = #43e70000 937a8baf ab20980b += 5.1163576661911764275e-4933 +fI[1] = #43e70000 937a8baf ab20980c += 5.11635766619117643114e-4933 +fI[1] == strtoxL + + +Input: 1.234567890123456789e-301 + +strtoxL consumes 25 bytes and returns 33 +with bits = #3c170000 a953271a 5d069ad9 +printf("%.21Lg") gives 1.08545540462853463561e-4932 +g_xLfmt(0) gives 25 bytes: "1.234567890123456789e-301" + +strtoIxL returns 33, consuming 25 bytes. +fI[0] = #3c170000 a953271a 5d069ad8 += 1.08545540462853463524e-4932 +fI[1] = #3c170000 a953271a 5d069ad9 += 1.08545540462853463561e-4932 +fI[1] == strtoxL + + +Input: 1.234567890123456789e-321 + +strtoxL consumes 25 bytes and returns 33 +with bits = #3bd40000 f9e11b4c ea6dcce9 +printf("%.21Lg") gives 3.20133479952876185942e-4932 +g_xLfmt(0) gives 25 bytes: "1.234567890123456789e-321" + +strtoIxL returns 33, consuming 25 bytes. +fI[0] = #3bd40000 f9e11b4c ea6dcce8 += 3.20133479952876185905e-4932 +fI[1] = #3bd40000 f9e11b4c ea6dcce9 += 3.20133479952876185942e-4932 +fI[1] == strtoxL + + +Input: 1e23 + +strtoxL consumes 4 bytes and returns 1 +with bits = #404b0000 a968163f a57b400 +printf("%.21Lg") gives 1.08760331670538037378e-4932 +g_xLfmt(0) gives 5 bytes: "1e+23" + +strtoIxL returns 1, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1e310 + +strtoxL consumes 5 bytes and returns 33 +with bits = #44040000 de81e40a 34bcf50 +printf("%.21Lg") gives 2.48237171106260601618e-4932 +g_xLfmt(0) gives 6 bytes: "1e+310" + +strtoIxL returns 33, consuming 5 bytes. +fI[0] = #44040000 de81e40a 34bcf4f += 2.48237171106260601582e-4932 +fI[1] = #44040000 de81e40a 34bcf50 += 2.48237171106260601618e-4932 +fI[1] == strtoxL + + +Input: 9.0259718793241475e-277 + +strtoxL consumes 23 bytes and returns 33 +with bits = #3c690000 ffffffff fffffcf7 +printf("%.21Lg") gives 3.36210314311209322303e-4932 +g_xLfmt(0) gives 23 bytes: "9.0259718793241475e-277" + +strtoIxL returns 33, consuming 23 bytes. +fI[0] = #3c690000 ffffffff fffffcf6 += 3.36210314311209322267e-4932 +fI[1] = #3c690000 ffffffff fffffcf7 += 3.36210314311209322303e-4932 +fI[1] == strtoxL + + +Input: 9.025971879324147880346310405869e-277 + +strtoxL consumes 37 bytes and returns 17 +with bits = #3c6a0000 80000000 0 +printf("%.21Lg") gives 3.36210314311209350626e-4932 +g_xLfmt(0) gives 26 bytes: "9.0259718793241478803e-277" + +strtoIxL returns 17, consuming 37 bytes. +fI[0] = #3c6a0000 80000000 0 += 3.36210314311209350626e-4932 +fI[1] = #3c6a0000 80000000 1 += 3.64519953188247460253e-4951 +fI[0] == strtoxL + + +Input: 9.025971879324147880346310405868e-277 + +strtoxL consumes 37 bytes and returns 33 +with bits = #3c6a0000 80000000 0 +printf("%.21Lg") gives 3.36210314311209350626e-4932 +g_xLfmt(0) gives 26 bytes: "9.0259718793241478803e-277" + +strtoIxL returns 33, consuming 37 bytes. +fI[0] = #3c690000 ffffffff ffffffff += 3.3621031431120935059e-4932 +fI[1] = #3c6a0000 80000000 0 += 3.36210314311209350626e-4932 +fI[1] == strtoxL + + +Input: 2.2250738585072014e-308 + +strtoxL consumes 23 bytes and returns 17 +with bits = #3c010000 80000000 46 +printf("%.21Lg") gives 2.55163967231773222177e-4949 +g_xLfmt(0) gives 23 bytes: "2.2250738585072014e-308" + +strtoIxL returns 17, consuming 23 bytes. +fI[0] = #3c010000 80000000 46 += 2.55163967231773222177e-4949 +fI[1] = #3c010000 80000000 47 += 2.5880916676365569678e-4949 +fI[0] == strtoxL + + +Input: 2.2250738585072013e-308 + +strtoxL consumes 23 bytes and returns 17 +with bits = #3c000000 ffffffff fffffd4f +printf("%.21Lg") gives 3.36210314311209325511e-4932 +g_xLfmt(0) gives 23 bytes: "2.2250738585072013e-308" + +strtoIxL returns 17, consuming 23 bytes. +fI[0] = #3c000000 ffffffff fffffd4f += 3.36210314311209325511e-4932 +fI[1] = #3c000000 ffffffff fffffd50 += 3.36210314311209325547e-4932 +fI[0] == strtoxL + +Rounding mode for strtor... changed from 1 (nearest) to 0 (toward zero) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 8ccccccc cccccccc +printf("%.21Lg") gives 3.36210314311209350335e-4933 +g_xLfmt(0) gives 21 bytes: "1.0999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] = #3fff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[0] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 8ccccccc cccccccc +printf("%.21Lg") gives 3.36210314311209350335e-4933 +g_xLfmt(0) gives 22 bytes: "-1.0999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] = #bfff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 99999999 99999999 +printf("%.21Lg") gives 6.72420628622418701034e-4933 +g_xLfmt(0) gives 21 bytes: "1.1999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] = #3fff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[0] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 99999999 99999999 +printf("%.21Lg") gives 6.72420628622418701034e-4933 +g_xLfmt(0) gives 22 bytes: "-1.1999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] = #bfff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 3 bytes: "1.3" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] = #3fff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[0] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 4 bytes: "-1.3" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[1] = #bfff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 3 bytes: "1.4" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] = #3fff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[0] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 4 bytes: "-1.4" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[1] = #bfff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 cccccccc cccccccc +printf("%.21Lg") gives 2.01726188586725610347e-4932 +g_xLfmt(0) gives 21 bytes: "1.5999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] = #3fff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[0] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 cccccccc cccccccc +printf("%.21Lg") gives 2.01726188586725610347e-4932 +g_xLfmt(0) gives 22 bytes: "-1.5999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] = #bfff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 d9999999 99999999 +printf("%.21Lg") gives 2.35347220017846545417e-4932 +g_xLfmt(0) gives 21 bytes: "1.6999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] = #3fff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[0] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 d9999999 99999999 +printf("%.21Lg") gives 2.35347220017846545417e-4932 +g_xLfmt(0) gives 22 bytes: "-1.6999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] = #bfff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 3 bytes: "1.8" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] = #3fff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[0] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 4 bytes: "-1.8" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[1] = #bfff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 3 bytes: "1.9" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] = #3fff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[0] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 4 bytes: "-1.9" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[1] = #bfff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] == strtoxL + +Rounding mode for strtor... changed from 0 (toward zero) to 1 (nearest) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 8ccccccc cccccccd +printf("%.21Lg") gives 3.36210314311209350699e-4933 +g_xLfmt(0) gives 3 bytes: "1.1" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] = #3fff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 8ccccccc cccccccd +printf("%.21Lg") gives 3.36210314311209350699e-4933 +g_xLfmt(0) gives 4 bytes: "-1.1" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] = #bfff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[0] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 99999999 9999999a +printf("%.21Lg") gives 6.72420628622418701398e-4933 +g_xLfmt(0) gives 3 bytes: "1.2" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] = #3fff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 99999999 9999999a +printf("%.21Lg") gives 6.72420628622418701398e-4933 +g_xLfmt(0) gives 4 bytes: "-1.2" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] = #bfff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[0] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 3 bytes: "1.3" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] = #3fff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[0] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 4 bytes: "-1.3" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[1] = #bfff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 3 bytes: "1.4" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] = #3fff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[0] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 4 bytes: "-1.4" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[1] = #bfff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 cccccccc cccccccd +printf("%.21Lg") gives 2.01726188586725610383e-4932 +g_xLfmt(0) gives 3 bytes: "1.6" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] = #3fff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 cccccccc cccccccd +printf("%.21Lg") gives 2.01726188586725610383e-4932 +g_xLfmt(0) gives 4 bytes: "-1.6" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] = #bfff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[0] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 d9999999 9999999a +printf("%.21Lg") gives 2.35347220017846545453e-4932 +g_xLfmt(0) gives 3 bytes: "1.7" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] = #3fff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 d9999999 9999999a +printf("%.21Lg") gives 2.35347220017846545453e-4932 +g_xLfmt(0) gives 4 bytes: "-1.7" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] = #bfff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[0] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 3 bytes: "1.8" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] = #3fff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[0] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 4 bytes: "-1.8" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[1] = #bfff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 3 bytes: "1.9" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] = #3fff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[0] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 4 bytes: "-1.9" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[1] = #bfff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] == strtoxL + +Rounding mode for strtor... changed from 1 (nearest) to 2 (toward +Infinity) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 8ccccccc cccccccd +printf("%.21Lg") gives 3.36210314311209350699e-4933 +g_xLfmt(0) gives 3 bytes: "1.1" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] = #3fff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 8ccccccc cccccccc +printf("%.21Lg") gives 3.36210314311209350335e-4933 +g_xLfmt(0) gives 22 bytes: "-1.0999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] = #bfff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 99999999 9999999a +printf("%.21Lg") gives 6.72420628622418701398e-4933 +g_xLfmt(0) gives 3 bytes: "1.2" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] = #3fff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 99999999 99999999 +printf("%.21Lg") gives 6.72420628622418701034e-4933 +g_xLfmt(0) gives 22 bytes: "-1.1999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] = #bfff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 a6666666 66666667 +printf("%.21Lg") gives 1.0086309429336280521e-4932 +g_xLfmt(0) gives 21 bytes: "1.3000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] = #3fff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[1] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 4 bytes: "-1.3" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[1] = #bfff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 b3333333 33333334 +printf("%.21Lg") gives 1.3448412572448374028e-4932 +g_xLfmt(0) gives 21 bytes: "1.4000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] = #3fff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[1] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 4 bytes: "-1.4" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[1] = #bfff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 cccccccc cccccccd +printf("%.21Lg") gives 2.01726188586725610383e-4932 +g_xLfmt(0) gives 3 bytes: "1.6" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] = #3fff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 cccccccc cccccccc +printf("%.21Lg") gives 2.01726188586725610347e-4932 +g_xLfmt(0) gives 22 bytes: "-1.5999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] = #bfff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 d9999999 9999999a +printf("%.21Lg") gives 2.35347220017846545453e-4932 +g_xLfmt(0) gives 3 bytes: "1.7" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] = #3fff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 d9999999 99999999 +printf("%.21Lg") gives 2.35347220017846545417e-4932 +g_xLfmt(0) gives 22 bytes: "-1.6999999999999999999" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] = #bfff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 e6666666 66666667 +printf("%.21Lg") gives 2.68968251448967480523e-4932 +g_xLfmt(0) gives 21 bytes: "1.8000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] = #3fff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[1] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 4 bytes: "-1.8" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[1] = #bfff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 33 +with bits = #3fff0000 f3333333 33333334 +printf("%.21Lg") gives 3.02589282880088415593e-4932 +g_xLfmt(0) gives 21 bytes: "1.9000000000000000001" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] = #3fff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[1] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 25 +with bits = #bfff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 4 bytes: "-1.9" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[1] = #bfff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] == strtoxL + +Rounding mode for strtor... changed from 2 (toward +Infinity) to 3 (toward -Infinity) + +Input: 1.1 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 8ccccccc cccccccc +printf("%.21Lg") gives 3.36210314311209350335e-4933 +g_xLfmt(0) gives 21 bytes: "1.0999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[1] = #3fff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[0] == strtoxL + + +Input: -1.1 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 8ccccccc cccccccd +printf("%.21Lg") gives 3.36210314311209350699e-4933 +g_xLfmt(0) gives 4 bytes: "-1.1" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 8ccccccc cccccccd += 3.36210314311209350699e-4933 +fI[1] = #bfff0000 8ccccccc cccccccc += 3.36210314311209350335e-4933 +fI[0] == strtoxL + + +Input: 1.2 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 99999999 99999999 +printf("%.21Lg") gives 6.72420628622418701034e-4933 +g_xLfmt(0) gives 21 bytes: "1.1999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[1] = #3fff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[0] == strtoxL + + +Input: -1.2 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 99999999 9999999a +printf("%.21Lg") gives 6.72420628622418701398e-4933 +g_xLfmt(0) gives 4 bytes: "-1.2" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 99999999 9999999a += 6.72420628622418701398e-4933 +fI[1] = #bfff0000 99999999 99999999 += 6.72420628622418701034e-4933 +fI[0] == strtoxL + + +Input: 1.3 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 a6666666 66666666 +printf("%.21Lg") gives 1.00863094293362805173e-4932 +g_xLfmt(0) gives 3 bytes: "1.3" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[1] = #3fff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[0] == strtoxL + + +Input: -1.3 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 a6666666 66666667 +printf("%.21Lg") gives 1.0086309429336280521e-4932 +g_xLfmt(0) gives 22 bytes: "-1.3000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 a6666666 66666667 += 1.0086309429336280521e-4932 +fI[1] = #bfff0000 a6666666 66666666 += 1.00863094293362805173e-4932 +fI[0] == strtoxL + + +Input: 1.4 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 b3333333 33333333 +printf("%.21Lg") gives 1.34484125724483740243e-4932 +g_xLfmt(0) gives 3 bytes: "1.4" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[1] = #3fff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[0] == strtoxL + + +Input: -1.4 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 b3333333 33333334 +printf("%.21Lg") gives 1.3448412572448374028e-4932 +g_xLfmt(0) gives 22 bytes: "-1.4000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 b3333333 33333334 += 1.3448412572448374028e-4932 +fI[1] = #bfff0000 b3333333 33333333 += 1.34484125724483740243e-4932 +fI[0] == strtoxL + + +Input: 1.5 + +strtoxL consumes 3 bytes and returns 1 +with bits = #3fff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 3 bytes: "1.5" + +strtoIxL returns 1, consuming 3 bytes. +fI[0] == fI[1] == strtoxL + + +Input: -1.5 + +strtoxL consumes 4 bytes and returns 9 +with bits = #bfff0000 c0000000 0 +printf("%.21Lg") gives 1.68105157155604675313e-4932 +g_xLfmt(0) gives 4 bytes: "-1.5" + +strtoIxL returns 9, consuming 4 bytes. +fI[0] == fI[1] == strtoxL + + +Input: 1.6 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 cccccccc cccccccc +printf("%.21Lg") gives 2.01726188586725610347e-4932 +g_xLfmt(0) gives 21 bytes: "1.5999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[1] = #3fff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[0] == strtoxL + + +Input: -1.6 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 cccccccc cccccccd +printf("%.21Lg") gives 2.01726188586725610383e-4932 +g_xLfmt(0) gives 4 bytes: "-1.6" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 cccccccc cccccccd += 2.01726188586725610383e-4932 +fI[1] = #bfff0000 cccccccc cccccccc += 2.01726188586725610347e-4932 +fI[0] == strtoxL + + +Input: 1.7 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 d9999999 99999999 +printf("%.21Lg") gives 2.35347220017846545417e-4932 +g_xLfmt(0) gives 21 bytes: "1.6999999999999999999" + +strtoIxL returns 33, consuming 3 bytes. +fI[0] = #3fff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[1] = #3fff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[0] == strtoxL + + +Input: -1.7 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 d9999999 9999999a +printf("%.21Lg") gives 2.35347220017846545453e-4932 +g_xLfmt(0) gives 4 bytes: "-1.7" + +strtoIxL returns 41, consuming 4 bytes. +fI[0] = #bfff0000 d9999999 9999999a += 2.35347220017846545453e-4932 +fI[1] = #bfff0000 d9999999 99999999 += 2.35347220017846545417e-4932 +fI[0] == strtoxL + + +Input: 1.8 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 e6666666 66666666 +printf("%.21Lg") gives 2.68968251448967480486e-4932 +g_xLfmt(0) gives 3 bytes: "1.8" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[1] = #3fff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[0] == strtoxL + + +Input: -1.8 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 e6666666 66666667 +printf("%.21Lg") gives 2.68968251448967480523e-4932 +g_xLfmt(0) gives 22 bytes: "-1.8000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 e6666666 66666667 += 2.68968251448967480523e-4932 +fI[1] = #bfff0000 e6666666 66666666 += 2.68968251448967480486e-4932 +fI[0] == strtoxL + + +Input: 1.9 + +strtoxL consumes 3 bytes and returns 17 +with bits = #3fff0000 f3333333 33333333 +printf("%.21Lg") gives 3.02589282880088415556e-4932 +g_xLfmt(0) gives 3 bytes: "1.9" + +strtoIxL returns 17, consuming 3 bytes. +fI[0] = #3fff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[1] = #3fff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[0] == strtoxL + + +Input: -1.9 + +strtoxL consumes 4 bytes and returns 41 +with bits = #bfff0000 f3333333 33333334 +printf("%.21Lg") gives 3.02589282880088415593e-4932 +g_xLfmt(0) gives 22 bytes: "-1.9000000000000000001" + +strtoIxL returns 25, consuming 4 bytes. +fI[0] = #bfff0000 f3333333 33333334 += 3.02589282880088415593e-4932 +fI[1] = #bfff0000 f3333333 33333333 += 3.02589282880088415556e-4932 +fI[0] == strtoxL + diff --git a/lib/libc/gdtoa/test/xLtest.c b/lib/libc/gdtoa/test/xLtest.c new file mode 100644 index 000000000..cf348e2ed --- /dev/null +++ b/lib/libc/gdtoa/test/xLtest.c @@ -0,0 +1,169 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998-2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +/* Test program for g_xLfmt, strtoIxL, strtopxL, and strtorxL. + * + * Inputs (on stdin): + * r rounding_mode + * n ndig + * number + * #hex0 hex1 hex2 + * + * rounding_mode values: + * 0 = toward zero + * 1 = nearest + * 2 = toward +Infinity + * 3 = toward -Infinity + * + * where number is a decimal floating-point number, + * hex0 is a string of <= 8 Hex digits for the most significant + * word of the number, hex1 is a similar string for the next + * word, etc., and ndig is a parameters to g_xLfmt. + */ + +#include "gdtoa.h" +#include +#include +#include + + extern int getround ANSI((int,char*)); + + static char ibuf[2048], obuf[2048]; + +#define U (unsigned long) + +#undef _0 +#undef _1 + +/* one or the other of IEEE_BIG_ENDIAN or IEEE_LITTLE_ENDIAN should be #defined */ + +#ifdef IEEE_BIG_ENDIAN +#define _0 0 +#define _1 1 +#define _2 2 +#endif +#ifdef IEEE_LITTLE_ENDIAN +#define _0 2 +#define _1 1 +#define _2 0 +#endif + + int +main(Void) +{ + char *s, *s1, *se, *se1; + int dItry, i, ndig = 0, r = 1; + union { long double d; ULong bits[3]; } u, v[2]; + + while((s = fgets(ibuf, sizeof(ibuf), stdin))) { + while(*s <= ' ') + if (!*s++) + continue; + dItry = 0; + switch(*s) { + case 'r': + r = getround(r, s); + continue; + case 'n': + i = s[1]; + if (i <= ' ' || (i >= '0' && i <= '9')) { + ndig = atoi(s+1); + continue; + } + break; /* nan? */ + case '#': + /* sscanf(s+1, "%lx %lx %lx", &u.bits[_0], */ + /* &u.bits[_1], &u.bits[_2]); */ + u.bits[_0] = (ULong)strtoul(s1 = s+1, &se, 16); + if (se > s1) { + u.bits[_1] = (ULong)strtoul(s1=se, &se, 16); + if (se > s1) + u.bits[_2] = (ULong)strtoul(s1=se, &se, 16); + } + printf("\nInput: %s", ibuf); + printf(" --> f = #%lx %lx %lx\n", U u.bits[_0], + U u.bits[_1], U u.bits[_2]); + goto fmt_test; + } + dItry = 1; + printf("\nInput: %s", ibuf); + i = strtorxL(ibuf, &se, r, u.bits); + if (r == 1 && (i != strtopxL(ibuf, &se1, v[0].bits) || se1 != se + || memcmp(u.bits, v[0].bits, 12))) + printf("***strtoxL and strtorxL disagree!!\n:"); + printf("\nstrtoxL consumes %d bytes and returns %d\n", + (int)(se-ibuf), i); + printf("with bits = #%lx %lx %lx\n", + U u.bits[_0], U u.bits[_1], U u.bits[_2]); + if (sizeof(long double) == 12) + printf("printf(\"%%.21Lg\") gives %.21Lg\n", u.d); + fmt_test: + se = g_xLfmt(obuf, u.bits, ndig, sizeof(obuf)); + printf("g_xLfmt(%d) gives %d bytes: \"%s\"\n\n", + ndig, (int)(se-obuf), se ? obuf : ""); + if (!dItry) + continue; + printf("strtoIxL returns %d,", + strtoIxL(ibuf, &se, v[0].bits, v[1].bits)); + printf(" consuming %d bytes.\n", (int)(se-ibuf)); + if (!memcmp(v[0].bits, v[1].bits, 12)) { + if (!memcmp(u.bits, v[0].bits, 12)) + printf("fI[0] == fI[1] == strtoxL\n"); + else { + printf("fI[0] == fI[1] = #%lx %lx %lx\n", + U v[0].bits[_0], U v[0].bits[_1], + U v[0].bits[_2]); + if (sizeof(long double) == 12) + printf("= %.21Lg\n", v[0].d); + } + } + else { + printf("fI[0] = #%lx %lx %lx\n", + U v[0].bits[_0], U v[0].bits[_1], + U v[0].bits[_2]); + if (sizeof(long double) == 12) + printf("= %.21Lg\n", v[0].d); + printf("fI[1] = #%lx %lx %lx\n", + U v[1].bits[_0], U v[1].bits[_1], + U v[1].bits[_2]); + if (sizeof(long double) == 12) + printf("= %.21Lg\n", v[1].d); + if (!memcmp(v[0].bits, u.bits, 12)) + printf("fI[0] == strtoxL\n"); + else if (!memcmp(v[1].bits, u.bits, 12)) + printf("fI[1] == strtoxL\n"); + else + printf("**** Both differ from strtod ****\n"); + } + printf("\n"); + } + return 0; + } diff --git a/lib/libc/gdtoa/test/xQtest.c b/lib/libc/gdtoa/test/xQtest.c new file mode 100644 index 000000000..93bc4142f --- /dev/null +++ b/lib/libc/gdtoa/test/xQtest.c @@ -0,0 +1,58 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 2002 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +#include + + int +main(void) +{ + union { long double d; unsigned int bits[4]; } u, w; + switch(sizeof(long double)) { + case 16: + w.bits[0] = w.bits[3] = 0; + w.d = 1.; + u.d = 3.; + w.d = w.d / u.d; + if (w.bits[0] && w.bits[3]) + printf("cp x.ou0 x.out; cp xL.ou0 xL.out;" + " cp Q.ou1 Q.out; cp pftestQ.out pftest.out\n"); + else + printf("cp x.ou0 x.out; cp xL.ou0 xL.out;" + " cp Q.ou0 Q.out; cp pftestx.out pftest.out\n"); + break; + case 10: + case 12: + printf("cp x.ou1 x.out; cp xL.ou1 xL.out; cp Q.ou0 Q.out;" + " cp pftestx.out pftest.out\n"); + break; + default: + printf("cp x.ou0 x.out; cp xL.ou0 xL.out; cp Q.ou0 Q.out;" + " cp pftestx.out pftest.out\n"); + } + return 0; + } diff --git a/lib/libc/gdtoa/test/xsum0.out b/lib/libc/gdtoa/test/xsum0.out new file mode 100644 index 000000000..52b8a3e60 --- /dev/null +++ b/lib/libc/gdtoa/test/xsum0.out @@ -0,0 +1,41 @@ +README efba0d5d 3412 +Q.ou0 e4592b85 28742 +Q.ou1 ea0b344d 39572 +Qtest.c efe2b3f4 5116 +d.out f271efc9 28131 +dI.out d522eef 4369 +dIsi.out 1dd6d02f 4350 +dItest.c e33800ce 2371 +dd.out e262456e 40923 +ddsi.out 1f94bbe2 10251 +ddtest.c ef71cbf3 4986 +dt.c e562c302 6808 +dtest.c 9a5d01 4080 +dtst.out e284ac98 23711 +f.out 9013e91 21537 +ftest.c 1c824a88 4001 +getround.c ee95ed1 2502 +makefile f714a641 5634 +pfLqtestnos ffb9723 99 +pftest.c ea314d7f 3452 +pftestQ.out 198434fd 830 +pftestx.out 1ccea5dd 788 +pftestLq.out 1691dbfc 845 +pftestnos ecbc9be6 101 +rtestnos f94bcdf6 336 +strtoIdSI.c 7bfb88b 49 +strtoIddSI.c 72e8852 50 +strtodISI.c ed08b740 49 +strtodt.c f1aa53af 3374 +strtopddSI.c 13e7138d 50 +strtorddSI.c f7e4b1d5 50 +testnos e89999d6 485 +testnos1 7e16229 294 +testnos3 f5ae7ef3 14403 +x.ou0 1402f834 25372 +x.ou1 f1af5a00 34581 +xL.ou0 faa3a741 26363 +xL.ou1 e349e5c 37165 +xLtest.c ee11f673 4843 +xQtest.c efbe29be 1912 +xtest.c ec9f5deb 4834 diff --git a/lib/libc/gdtoa/test/xtest.c b/lib/libc/gdtoa/test/xtest.c new file mode 100644 index 000000000..6e7fa4696 --- /dev/null +++ b/lib/libc/gdtoa/test/xtest.c @@ -0,0 +1,170 @@ +/**************************************************************** + +The author of this software is David M. Gay. + +Copyright (C) 1998-2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, 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. + +****************************************************************/ + +/* Please send bug reports to David M. Gay (dmg at acm dot org, + * with " at " changed at "@" and " dot " changed to "."). */ + +/* Test program for g_xfmt, strtoIx, strtopx, and strtorx. + * + * Inputs (on stdin): + * r rounding_mode + * n ndig + * number + * #hex0 hex1 hex2 hex3 hex4 + * + * rounding_mode values: + * 0 = toward zero + * 1 = nearest + * 2 = toward +Infinity + * 3 = toward -Infinity + * + * where number is a decimal floating-point number, + * hex0 is a string of <= 4 Hex digits for the most significant + * half-word of the number, hex1 is a similar string for the next + * half-word, etc., and ndig is a parameters to g_xfmt. + */ + +#include "gdtoa.h" +#include +#include +#include + + extern int getround ANSI((int,char*)); + + static char ibuf[2048], obuf[2048]; + +#undef _0 +#undef _1 + +/* one or the other of IEEE_BIG_ENDIAN or IEEE_LITTLE_ENDIAN should be #defined */ + +#ifdef IEEE_BIG_ENDIAN +#define _0 0 +#define _1 1 +#define _2 2 +#define _3 3 +#define _4 4 +#endif +#ifdef IEEE_LITTLE_ENDIAN +#define _0 4 +#define _1 3 +#define _2 2 +#define _3 1 +#define _4 0 +#endif + + int +main(Void) +{ + char *s, *se, *se1; + int i, dItry, ndig = 0, r = 1; + union { long double d; UShort bits[5]; } u, v[2]; + + while((s = fgets(ibuf, sizeof(ibuf), stdin))) { + while(*s <= ' ') + if (!*s++) + continue; + dItry = 0; + switch(*s) { + case 'r': + r = getround(r, s); + continue; + case 'n': + i = s[1]; + if (i <= ' ' || (i >= '0' && i <= '9')) { + ndig = atoi(s+1); + continue; + } + break; /* nan? */ + case '#': + sscanf(s+1, "%hx %hx %hx %hx %hx", &u.bits[_0], + &u.bits[_1], &u.bits[_2], &u.bits[_3], + &u.bits[_4]); + printf("\nInput: %s", ibuf); + printf(" --> f = #%x %x %x %x %x\n", u.bits[_0], + u.bits[_1], u.bits[_2], u.bits[_3], u.bits[_4]); + goto fmt_test; + } + dItry = 1; + printf("\nInput: %s", ibuf); + i = strtorx(ibuf, &se, r, u.bits); + if (r == 1 && (i != strtopx(ibuf, &se1, v[0].bits) || se1 != se + || memcmp(u.bits, v[0].bits, 10))) + printf("***strtox and strtorx disagree!!\n:"); + printf("\nstrtox consumes %d bytes and returns %d\n", + (int)(se-ibuf), i); + printf("with bits = #%x %x %x %x %x\n", + u.bits[_0], u.bits[_1], u.bits[_2], + u.bits[_3], u.bits[_4]); + if (sizeof(long double) == 12) + printf("printf(\"%%.21Lg\") gives %.21Lg\n", u.d); + fmt_test: + se = g_xfmt(obuf, u.bits, ndig, sizeof(obuf)); + printf("g_xfmt(%d) gives %d bytes: \"%s\"\n\n", + ndig, (int)(se-obuf), se ? obuf : ""); + if (!dItry) + continue; + printf("strtoIx returns %d,", + strtoIx(ibuf, &se, v[0].bits, v[1].bits)); + printf(" consuming %d bytes.\n", (int)(se-ibuf)); + if (!memcmp(v[0].bits, v[1].bits, 10)) { + if (!memcmp(u.bits, v[0].bits, 10)) + printf("fI[0] == fI[1] == strtox\n"); + else { + printf("fI[0] == fI[1] = #%x %x %x %x %x\n", + v[0].bits[_0], v[0].bits[_1], + v[0].bits[_2], v[0].bits[_3], + v[0].bits[_4]); + if (sizeof(long double) == 12) + printf("= %.21Lg\n", v[0].d); + } + } + else { + printf("fI[0] = #%x %x %x %x %x\n", + v[0].bits[_0], v[0].bits[_1], + v[0].bits[_2], v[0].bits[_3], + v[0].bits[_4]); + if (sizeof(long double) == 12) + printf("= %.21Lg\n", v[0].d); + printf("fI[1] = #%x %x %x %x %x\n", + v[1].bits[_0], v[1].bits[_1], + v[1].bits[_2], v[1].bits[_3], + v[1].bits[_4]); + if (sizeof(long double) == 12) + printf("= %.21Lg\n", v[1].d); + if (!memcmp(v[0].bits, u.bits, 10)) + printf("fI[0] == strtox\n"); + else if (!memcmp(v[1].bits, u.bits, 10)) + printf("fI[1] == strtox\n"); + else + printf("**** Both differ from strtod ****\n"); + } + printf("\n"); + } + return 0; + } diff --git a/lib/libc/gdtoa/ulp.c b/lib/libc/gdtoa/ulp.c index ef909ae78..2da0c0336 100644 --- a/lib/libc/gdtoa/ulp.c +++ b/lib/libc/gdtoa/ulp.c @@ -1,4 +1,4 @@ -/* $NetBSD: ulp.c,v 1.2 2006/01/25 15:27:42 kleink Exp $ */ +/* $NetBSD: ulp.c,v 1.3 2011/03/20 23:15:35 christos Exp $ */ /**************************************************************** @@ -36,13 +36,13 @@ THIS SOFTWARE. double ulp #ifdef KR_headers - (x) double x; + (x) U *x; #else - (double x) + (U *x) #endif { Long L; - double a; + U a; L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; #ifndef Sudden_Underflow @@ -51,22 +51,22 @@ ulp #ifdef IBM L |= Exp_msk1 >> 4; #endif - word0(a) = L; - word1(a) = 0; + word0(&a) = L; + word1(&a) = 0; #ifndef Sudden_Underflow } else { L = (unsigned int)-L >> Exp_shift; if (L < Exp_shift) { - word0(a) = 0x80000 >> L; - word1(a) = 0; + word0(&a) = 0x80000 >> L; + word1(&a) = 0; } else { - word0(a) = 0; + word0(&a) = 0; L -= Exp_shift; - word1(a) = L >= 31 ? 1 : 1 << (31 - L); + word1(&a) = L >= 31 ? 1 : 1 << (31 - L); } } #endif - return a; + return dval(&a); } diff --git a/lib/libc/gdtoa/xsum0.out b/lib/libc/gdtoa/xsum0.out index 701b55d31..e9c29bc23 100644 --- a/lib/libc/gdtoa/xsum0.out +++ b/lib/libc/gdtoa/xsum0.out @@ -1,48 +1,52 @@ -README f2477cff 14190 +README 664d441 15750 arithchk.c ebbe5bc7 4075 dmisc.c c8daa18 4682 -dtoa.c 6a7b6fe 16876 -g_Qfmt.c f791d807 2839 -g__fmt.c 14dca85 2504 -g_ddfmt.c 10eae12a 3695 -g_dfmt.c f36c1014 2503 -g_ffmt.c fb83cfb5 2429 -g_xLfmt.c f216a096 2686 -g_xfmt.c ed824bf3 2775 -gdtoa.c e29409a6 16988 -gdtoa.h f208c204 4780 -gdtoaimp.h e3c2a970 19441 -gethex.c dba1616 5201 +dtoa.c f6ed7306 17542 +g_Qfmt.c f6aad16c 2926 +g__fmt.c e961947e 3401 +g_ddfmt.c 1f75ef12 4161 +g_dfmt.c 24be3a8 2629 +g_ffmt.c 197652f1 2516 +g_xLfmt.c 3fd29c5 2773 +g_xfmt.c f6a580a 2862 +gdtoa.c e4651ba8 17355 +gdtoa.h f966845d 4944 +gdtoa_fltrnds.h 1aaf5112 421 +gdtoaimp.h 395c83e 20044 +gethex.c 144ecbb4 7107 gmisc.c 1859d016 2084 hd_init.c efdbe921 1797 -hexnan.c f7ea38f9 2958 -makefile f890b12 2932 -misc.c 1757f7fc 14252 +hexnan.c 891b04e 3468 +makefile ffae86d0 3148 +misc.c 1d84f517 14416 +printf.c 15c97ab 158 +printf.c0 efece124 29696 qnan.c efd33d64 3417 -smisc.c e282e715 3655 +smisc.c feb7290 3699 +stdio1.h e6e5dc11 2909 strtoIQ.c 1809dfcf 1939 strtoId.c f41ddac2 1931 strtoIdd.c f13e3bc3 2105 strtoIf.c f12c6af4 1875 -strtoIg.c ef30d392 3454 +strtoIg.c fe47bc72 3591 strtoIx.c e50f716d 1960 strtoIxL.c ea0b821b 1931 -strtod.c eec1df60 20532 -strtodI.c 1c2440ce 3915 -strtodg.c f6c3dd52 19911 +strtod.c 1dabf6 22744 +strtodI.c f1dbb0af 4004 +strtodg.c eacc7424 21188 strtodnrp.c af895e9 2538 -strtof.c 1c5192d3 2073 -strtopQ.c f116d4f0 2563 -strtopd.c f7681c7a 1671 -strtopdd.c 9864fba 4497 -strtopf.c eb15b627 2067 -strtopx.c 1cafe482 2618 -strtopxL.c 1e4b77e9 2373 +strtof.c e1cb24dd 2161 +strtopQ.c f244b012 2645 +strtopd.c 1c3c9ce 1751 +strtopdd.c 177251c9 4640 +strtopf.c f305c6ea 2155 +strtopx.c 1529e1f5 2710 +strtopxL.c 69418e3 2469 strtorQ.c 9360a0b 2885 strtord.c af5c50e 2491 -strtordd.c 1b266865 4936 -strtorf.c f0d86e2b 2396 -strtorx.c f19a56af 2947 -strtorxL.c 167fe87c 2704 +strtordd.c e3d20ab 4992 +strtorf.c fbe2ea18 2402 +strtorx.c 168faee5 2957 +strtorxL.c 42c6cec 2718 sum.c f525bad9 2494 -ulp.c 1e2e148f 1864 +ulp.c edb56c0b 1866 diff --git a/lib/libc/gen/Lint_flt_rounds.c b/lib/libc/gen/Lint_flt_rounds.c index b0744ad64..0cff68679 100644 --- a/lib/libc/gen/Lint_flt_rounds.c +++ b/lib/libc/gen/Lint_flt_rounds.c @@ -1,4 +1,4 @@ -/* $NetBSD: Lint_flt_rounds.c,v 1.2 2000/06/14 06:49:05 cgd Exp $ */ +/* $NetBSD: Lint_flt_rounds.c,v 1.3 2012/06/24 15:26:03 christos Exp $ */ /* * This file placed in the public domain. @@ -7,7 +7,7 @@ /*ARGSUSED*/ int -__flt_rounds() +__flt_rounds(void) { return (0); } diff --git a/lib/libc/gen/Lint_fpgetmask.c b/lib/libc/gen/Lint_fpgetmask.c index 8c6a12eb1..2d0f57b71 100644 --- a/lib/libc/gen/Lint_fpgetmask.c +++ b/lib/libc/gen/Lint_fpgetmask.c @@ -1,4 +1,4 @@ -/* $NetBSD: Lint_fpgetmask.c,v 1.2 2000/06/14 06:49:05 cgd Exp $ */ +/* $NetBSD: Lint_fpgetmask.c,v 1.3 2012/06/24 15:26:03 christos Exp $ */ /* * This file placed in the public domain. @@ -9,7 +9,7 @@ /*ARGSUSED*/ fp_except -fpgetmask() +fpgetmask(void) { fp_except rv = { 0 }; diff --git a/lib/libc/gen/Lint_fpgetround.c b/lib/libc/gen/Lint_fpgetround.c index 94f5f8c1b..44cfc63e3 100644 --- a/lib/libc/gen/Lint_fpgetround.c +++ b/lib/libc/gen/Lint_fpgetround.c @@ -1,4 +1,4 @@ -/* $NetBSD: Lint_fpgetround.c,v 1.2 2000/06/14 06:49:05 cgd Exp $ */ +/* $NetBSD: Lint_fpgetround.c,v 1.3 2012/06/24 15:26:03 christos Exp $ */ /* * This file placed in the public domain. @@ -9,7 +9,7 @@ /*ARGSUSED*/ fp_rnd -fpgetround() +fpgetround(void) { fp_rnd rv = { 0 }; diff --git a/lib/libc/gen/Lint_fpgetsticky.c b/lib/libc/gen/Lint_fpgetsticky.c index 413898cf1..64e8793b6 100644 --- a/lib/libc/gen/Lint_fpgetsticky.c +++ b/lib/libc/gen/Lint_fpgetsticky.c @@ -1,4 +1,4 @@ -/* $NetBSD: Lint_fpgetsticky.c,v 1.2 2000/06/14 06:49:05 cgd Exp $ */ +/* $NetBSD: Lint_fpgetsticky.c,v 1.3 2012/06/24 15:26:03 christos Exp $ */ /* * This file placed in the public domain. @@ -9,7 +9,7 @@ /*ARGSUSED*/ fp_except -fpgetsticky() +fpgetsticky(void) { fp_except rv = { 0 }; diff --git a/lib/libc/gen/Lint_resumecontext.c b/lib/libc/gen/Lint_resumecontext.c index 529b96f54..4933908d9 100644 --- a/lib/libc/gen/Lint_resumecontext.c +++ b/lib/libc/gen/Lint_resumecontext.c @@ -1,4 +1,4 @@ -/* $NetBSD: Lint_resumecontext.c,v 1.2 2003/01/18 11:38:46 thorpej Exp $ */ +/* $NetBSD: Lint_resumecontext.c,v 1.3 2011/09/19 21:24:58 joerg Exp $ */ /* * This file placed in the public domain. @@ -9,6 +9,6 @@ /*ARGSUSED*/ void -_resumecontext() +_resumecontext(void) { } diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index e32a15aa4..4ed8a2ec3 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.173 2010/12/12 20:22:48 christos Exp $ +# $NetBSD: Makefile.inc,v 1.184 2012/04/12 22:08:32 christos Exp $ # from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # gen sources @@ -24,7 +24,8 @@ # setprogname.c SRCS+= _errno.c alarm.c alphasort.c arc4random.c assert.c basename.c clock.c \ - closedir.c ctermid.c ctype_.c daemon.c \ + closedir.c \ + ctermid.c ctype_.c daemon.c \ dehumanize_number.c dirname.c err.c errx.c \ errlist.c errno.c execl.c execle.c execlp.c execv.c execvp.c \ fmtcheck.c fmtmsg.c fnmatch.c fstab.c ftok.c \ @@ -37,10 +38,10 @@ SRCS+= _errno.c alarm.c alphasort.c arc4random.c assert.c basename.c clock.c \ getusershell.c glob.c humanize_number.c initdir.c initgroups.c \ isascii.c isatty.c isctype.c lockf.c nftw.c \ nice.c \ - opendir.c \ - pause.c popen.c psignal.c ptree.c pwcache.c \ - pw_scan.c raise.c randomid.c rb.c readdir.c rewinddir.c \ - scandir.c seekdir.c \ + opendir.c pause.c popen.c \ + psignal.c \ + ptree.c pwcache.c pw_scan.c raise.c randomid.c rb.c readdir.c \ + rewinddir.c scandir.c seekdir.c \ setjmperr.c setmode.c \ shquote.c shquotev.c sighold.c sigignore.c siginterrupt.c \ siglist.c signal.c signame.c sigrelse.c \ @@ -49,37 +50,7 @@ SRCS+= _errno.c alarm.c alphasort.c arc4random.c assert.c basename.c clock.c \ syslog.c telldir.c time.c \ times.c toascii.c tolower_.c ttyname.c ttyslot.c \ toupper_.c ualarm.c ulimit.c uname.c unvis.c usleep.c utime.c utmp.c \ - utmpx.c valloc.c vis.c warn.c warnx.c \ - vwarn.c vwarnx.c verr.c verrx.c wait.c waitpid.c wordexp.c -.else -SRCS+= _errno.c alarm.c alphasort.c arc4random.c assert.c basename.c clock.c \ - closedir.c closefrom.c \ - confstr.c ctermid.c ctype_.c daemon.c \ - dehumanize_number.c devname.c dirname.c disklabel.c err.c errx.c \ - errlist.c errno.c execl.c execle.c execlp.c execv.c execvp.c \ - extattr.c fmtcheck.c fmtmsg.c fnmatch.c fstab.c ftok.c \ - fts.c ftw.c getbsize.c getcap.c getcwd.c \ - getdevmajor.c getdomainname.c getgrent.c \ - getgrouplist.c getgroupmembership.c gethostname.c \ - getloadavg.c getlogin.c getmntinfo.c \ - getnetgrent.c getpagesize.c \ - getpass.c getprogname.c getpwent.c getttyent.c \ - getusershell.c glob.c humanize_number.c initdir.c initgroups.c \ - isascii.c isatty.c isctype.c lockf.c nftw.c \ - nice.c nlist.c nlist_aout.c nlist_coff.c nlist_ecoff.c nlist_elf32.c \ - nlist_elf64.c opendir.c pause.c popen.c posix_spawn_sched.c \ - posix_spawn_fileactions.c posix_spawnp.c psignal.c pthread_atfork.c \ - ptree.c pwcache.c pw_scan.c raise.c randomid.c rb.c readdir.c \ - rewinddir.c scandir.c seekdir.c setdomainname.c \ - sethostname.c setjmperr.c setmode.c setproctitle.c setprogname.c \ - shquote.c shquotev.c sighold.c sigignore.c siginterrupt.c \ - siglist.c signal.c signame.c sigrelse.c \ - sigset.c sigsetops.c sleep.c \ - stringlist.c sysconf.c sysctl.c sysctlbyname.c sysctlgetmibinfo.c \ - sysctlnametomib.c syslog.c telldir.c time.c \ - times.c toascii.c tolower_.c ttyname.c ttyslot.c \ - toupper_.c ualarm.c ulimit.c uname.c unvis.c usleep.c utime.c utmp.c \ - utmpx.c valloc.c vis.c wait.c wait3.c waitpid.c warn.c warnx.c \ + utmpx.c valloc.c vis.c wait.c waitpid.c warn.c warnx.c \ vwarn.c vwarnx.c verr.c verrx.c wordexp.c .endif @@ -104,7 +75,7 @@ COPTS.syslog.c = -Wno-format-nonliteral MAN+= alarm.3 arc4random.3 basename.3 bswap.3 clock.3 closefrom.3 \ confstr.3 \ cpuset.3 ctermid.3 ctype.3 daemon.3 devname.3 directory.3 dirname.3 \ - endutxent.3 err.3 exec.3 extattr.3 \ + endutxent.3 err.3 exec.3 extattr_copy_file.3 extattr_namespace_to_string.3 \ fmtcheck.3 fmtmsg.3 fnmatch.3 fpclassify.3 fpgetmask.3 \ ftok.3 fts.3 ftw.3 \ getbsize.3 cgetcap.3 getcwd.3 getdevmajor.3 \ @@ -118,7 +89,13 @@ MAN+= alarm.3 arc4random.3 basename.3 bswap.3 clock.3 closefrom.3 \ isnormal.3 isprint.3 ispunct.3 isspace.3 isupper.3 isxdigit.3 \ lockf.3 _lwp_makecontext.3 makecontext.3 \ nice.3 nlist.3 \ - pause.3 popen.3 psignal.3 pwcache.3 pthread_atfork.3 \ + pause.3 popen.3 \ + posix_spawn.3 posix_spawn_file_actions_addopen.3 \ + posix_spawn_file_actions_init.3 posix_spawnattr_getflags.3 \ + posix_spawnattr_getpgroup.3 posix_spawnattr_getschedparam.3 \ + posix_spawnattr_getschedpolicy.3 posix_spawnattr_init.3 \ + posix_spawnattr_getsigdefault.3 posix_spawnattr_getsigmask.3 \ + psignal.3 pwcache.3 pthread_atfork.3 \ raise.3 randomid.3 realpath.3 scandir.3 setjmp.3 setmode.3 \ setproctitle.3 shquote.3 sighold.3 sigignore.3 siginterrupt.3 \ signal.3 signbit.3 sigrelse.3 sigset.3 sigsetops.3 sleep.3 \ @@ -142,11 +119,16 @@ MLINKS+=err.3 verr.3 err.3 errx.3 err.3 verrx.3 err.3 warn.3 err.3 vwarn.3 \ err.3 warnx.3 err.3 vwarnx.3 MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 execv.3 \ exec.3 execvp.3 exec.3 exect.3 -MLINKS+=extattr.3 extattr_namespace_to_string.3 \ - extattr.3 extattr_string_to_namespace.3 +MLINKS+=extattr_namespace_to_string.3 extattr_string_to_namespace.3 \ + extattr_copy_file.3 extattr_copy_fd.3 \ + extattr_copy_file.3 extattr_copy_link.3 \ + extattr_copy_file.3 cpxattr.3 \ + extattr_copy_file.3 fcpxattr.3 \ + extattr_copy_file.3 lcpxattr.3 MLINKS+=fpgetmask.3 fpgetround.3 fpgetmask.3 fpgetsticky.3 \ fpgetmask.3 fpsetmask.3 fpgetmask.3 fpsetround.3 \ - fpgetmask.3 fpsetsticky.3 + fpgetmask.3 fpsetsticky.3 fpgetmask.3 fpgetprec.3 \ + fpgetmask.3 fpsetprec.3 MLINKS+=fts.3 fts_open.3 fts.3 fts_read.3 fts.3 fts_children.3 \ fts.3 fts_set.3 fts.3 fts_close.3 MLINKS+=ftw.3 nftw.3 @@ -155,6 +137,8 @@ MLINKS+=cgetcap.3 cgetclose.3 cgetcap.3 cgetent.3 \ cgetcap.3 cgetnum.3 cgetcap.3 cgetset.3 cgetcap.3 cgetstr.3 \ cgetcap.3 cgetustr.3 MLINKS+=getcwd.3 getwd.3 +MLINKS+=getpass.3 getpass_r.3 +MLINKS+=getpass.3 getpassfd.3 MLINKS+=getdiskbyname.3 setdisktab.3 MLINKS+=getdomainname.3 setdomainname.3 MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \ @@ -182,6 +166,17 @@ MLINKS+=glob.3 glob_pattern_p.3 MLINKS+=humanize_number.3 dehumanize_number.3 MLINKS+=makecontext.3 swapcontext.3 MLINKS+=popen.3 pclose.3 +MLINKS+=posix_spawn.3 posix_spawnp.3 \ + posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addclose.3 \ + posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_adddup2.3 \ + posix_spawn_file_actions_init.3 posix_spawn_file_actions_destroy.3 \ + posix_spawnattr_getflags.3 posix_spawnattr_setflags.3 \ + posix_spawnattr_getpgroup.3 posix_spawnattr_setpgroup.3 \ + posix_spawnattr_getschedparam.3 posix_spawnattr_setschedparam.3 \ + posix_spawnattr_getschedpolicy.3 posix_spawnattr_setschedpolicy.3 \ + posix_spawnattr_getsigdefault.3 posix_spawnattr_setsigdefault.3 \ + posix_spawnattr_getsigmask.3 posix_spawnattr_setsigmask.3 \ + posix_spawnattr_init.3 posix_spawnattr_destroy.3 MLINKS+=psignal.3 sys_siglist.3 psignal.3 sys_signame.3 psignal.3 psiginfo.3 MLINKS+=pwcache.3 user_from_uid.3 pwcache.3 group_from_gid.3 MLINKS+=pwcache.3 uid_from_user.3 pwcache.3 gid_from_group.3 @@ -207,19 +202,21 @@ MLINKS+=syslog.3 syslogp.3 syslog.3 syslogp_r.3 \ syslog.3 vsyslogp.3 syslog.3 vsyslogp_r.3 MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyslot.3 ttyname.3 ttyname_r.3 MLINKS+=unvis.3 strunvis.3 unvis.3 strunvisx.3 +MLINKS+=unvis.3 strnunvis.3 unvis.3 strnunvisx.3 MLINKS+=vis.3 svis.3 vis.3 strvis.3 vis.3 strvisx.3 vis.3 strsvis.3 \ - vis.3 strsvisx.3 + vis.3 strsvisx.3 vis.3 nvis.3 +MLINKS+=vis.3 snvis.3 vis.3 strnvis.3 vis.3 strnvisx.3 vis.3 strsnvis.3 \ + vis.3 strsnvisx.3 CPPFLAGS.ctype_.c+= -I${LIBCDIR}/locale CPPFLAGS.isctype.c+= -I${LIBCDIR}/locale CPPFLAGS.tolower_.c+= -I${LIBCDIR}/locale CPPFLAGS.toupper_.c+= -I${LIBCDIR}/locale +errlist.c: errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h .if defined(__MINIX) -errlist.c: errlist.awk ${NETBSDSRCDIR}/include/sys/errno.h - cat ${NETBSDSRCDIR}/include/sys/errno.h | ${TOOL_SED} 's/(_SIGN//' | ${TOOL_AWK} -f ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk > ${.TARGET} + ${TOOL_CAT} ${NETBSDSRCDIR}/sys/sys/errno.h | ${TOOL_SED} 's/(_SIGN//' | ${TOOL_AWK} -f ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk > ${.TARGET} .else -errlist.c: errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h ${TOOL_AWK} -f ${.ALLSRC} > ${.TARGET} .endif diff --git a/lib/libc/gen/_err.c b/lib/libc/gen/_err.c index ddeef6824..9b2024d8f 100644 --- a/lib/libc/gen/_err.c +++ b/lib/libc/gen/_err.c @@ -1,4 +1,4 @@ -/* $NetBSD: _err.c,v 1.11 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: _err.c,v 1.12 2011/07/17 20:54:34 joerg Exp $ */ /* * J.T. Conklin, December 12, 1994 @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _err.c,v 1.11 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: _err.c,v 1.12 2011/07/17 20:54:34 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #if defined(__indr_reference) @@ -16,7 +16,7 @@ __indr_reference(_err, err) #include -__dead void _verr(int eval, const char *, _BSD_VA_LIST_); +__dead void _verr(int eval, const char *, va_list); __dead void err(int eval, const char *fmt, ...) diff --git a/lib/libc/gen/_errx.c b/lib/libc/gen/_errx.c index 79b5b8034..5a1345ede 100644 --- a/lib/libc/gen/_errx.c +++ b/lib/libc/gen/_errx.c @@ -1,4 +1,4 @@ -/* $NetBSD: _errx.c,v 1.11 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: _errx.c,v 1.12 2011/07/17 20:54:34 joerg Exp $ */ /* * J.T. Conklin, December 12, 1994 @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _errx.c,v 1.11 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: _errx.c,v 1.12 2011/07/17 20:54:34 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #if defined(__indr_reference) @@ -16,7 +16,7 @@ __indr_reference(_errx, errx) #include -__dead void _verrx(int eval, const char *, _BSD_VA_LIST_); +__dead void _verrx(int eval, const char *, va_list); __dead void errx(int eval, const char *fmt, ...) diff --git a/lib/libc/gen/_sysconf.c b/lib/libc/gen/_sysconf.c index b4738c19c..c39248e19 100644 --- a/lib/libc/gen/_sysconf.c +++ b/lib/libc/gen/_sysconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: _sysconf.c,v 1.5 2009/10/21 01:07:45 snj Exp $ */ +/* $NetBSD: _sysconf.c,v 1.6 2012/03/20 16:36:04 matt Exp $ */ /* * Copyright (c) 1996 Christos Zoulas. All rights reserved. @@ -26,7 +26,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _sysconf.c,v 1.5 2009/10/21 01:07:45 snj Exp $"); +__RCSID("$NetBSD: _sysconf.c,v 1.6 2012/03/20 16:36:04 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #if defined(__indr_reference) @@ -34,11 +34,10 @@ __indr_reference(__sysconf, sysconf) #else #include -long __sysconf __P((int)); /* XXX */ +long __sysconf(int); /* XXX */ long -sysconf(name) - int name; +sysconf(int name) { return __sysconf(name); diff --git a/lib/libc/gen/_verr.c b/lib/libc/gen/_verr.c index 6cea67fc1..23577bae7 100644 --- a/lib/libc/gen/_verr.c +++ b/lib/libc/gen/_verr.c @@ -1,4 +1,4 @@ -/* $NetBSD: _verr.c,v 1.10 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: _verr.c,v 1.11 2011/07/17 20:54:34 joerg Exp $ */ /* * J.T. Conklin, December 12, 1994 @@ -7,20 +7,19 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _verr.c,v 1.10 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: _verr.c,v 1.11 2011/07/17 20:54:34 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ +#include + #if defined(__indr_reference) __indr_reference(_verr, verr) #else -#ifdef __minix -#include -#endif -__dead void _verr(int, const char *, _BSD_VA_LIST_); +__dead void _verr(int, const char *, va_list); void -verr(int eval, const char *fmt, _BSD_VA_LIST_ ap) +verr(int eval, const char *fmt, va_list ap) { _verr(eval, fmt, ap); } diff --git a/lib/libc/gen/_verrx.c b/lib/libc/gen/_verrx.c index 5af3d3ca5..784d3c2b8 100644 --- a/lib/libc/gen/_verrx.c +++ b/lib/libc/gen/_verrx.c @@ -1,4 +1,4 @@ -/* $NetBSD: _verrx.c,v 1.10 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: _verrx.c,v 1.11 2011/07/17 20:54:34 joerg Exp $ */ /* * J.T. Conklin, December 12, 1994 @@ -7,20 +7,19 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _verrx.c,v 1.10 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: _verrx.c,v 1.11 2011/07/17 20:54:34 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ +#include + #if defined(__indr_reference) __indr_reference(_verrx, verrx) #else -#ifdef __minix -#include -#endif -__dead void _verrx(int, const char *, _BSD_VA_LIST_); +__dead void _verrx(int, const char *, va_list); void -verrx(int eval, const char *fmt, _BSD_VA_LIST_ ap) +verrx(int eval, const char *fmt, va_list ap) { _verrx(eval, fmt, ap); } diff --git a/lib/libc/gen/_vwarn.c b/lib/libc/gen/_vwarn.c index 5508926ab..47b843901 100644 --- a/lib/libc/gen/_vwarn.c +++ b/lib/libc/gen/_vwarn.c @@ -1,4 +1,4 @@ -/* $NetBSD: _vwarn.c,v 1.10 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: _vwarn.c,v 1.11 2011/07/17 20:54:34 joerg Exp $ */ /* * J.T. Conklin, December 12, 1994 @@ -7,20 +7,19 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _vwarn.c,v 1.10 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: _vwarn.c,v 1.11 2011/07/17 20:54:34 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ +#include + #if defined(__indr_reference) __indr_reference(_vwarn, vwarn) #else -#ifdef __minix -#include -#endif -void _vwarn(const char *, _BSD_VA_LIST_); +void _vwarn(const char *, va_list); void -vwarn(const char *fmt, _BSD_VA_LIST_ ap) +vwarn(const char *fmt, va_list ap) { _vwarn(fmt, ap); } diff --git a/lib/libc/gen/_vwarnx.c b/lib/libc/gen/_vwarnx.c index 16533de3f..790059433 100644 --- a/lib/libc/gen/_vwarnx.c +++ b/lib/libc/gen/_vwarnx.c @@ -1,4 +1,4 @@ -/* $NetBSD: _vwarnx.c,v 1.10 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: _vwarnx.c,v 1.11 2011/07/17 20:54:34 joerg Exp $ */ /* * J.T. Conklin, December 12, 1994 @@ -7,20 +7,19 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _vwarnx.c,v 1.10 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: _vwarnx.c,v 1.11 2011/07/17 20:54:34 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ +#include + #if defined(__indr_reference) __indr_reference(_vwarnx, vwarnx) #else -#ifdef __minix -#include -#endif -void _vwarnx(const char *, _BSD_VA_LIST_); +void _vwarnx(const char *, va_list); void -vwarnx(const char *fmt, _BSD_VA_LIST_ ap) +vwarnx(const char *fmt, va_list ap) { _vwarnx(fmt, ap); } diff --git a/lib/libc/gen/_warn.c b/lib/libc/gen/_warn.c index 37c606a61..ffb4965e5 100644 --- a/lib/libc/gen/_warn.c +++ b/lib/libc/gen/_warn.c @@ -1,4 +1,4 @@ -/* $NetBSD: _warn.c,v 1.10 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: _warn.c,v 1.11 2011/07/17 20:54:34 joerg Exp $ */ /* * J.T. Conklin, December 12, 1994 @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _warn.c,v 1.10 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: _warn.c,v 1.11 2011/07/17 20:54:34 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #if defined(__indr_reference) @@ -16,7 +16,7 @@ __indr_reference(_warn, warn) #include -void _vwarn(const char *, _BSD_VA_LIST_); +void _vwarn(const char *, va_list); void warn(const char *fmt, ...) diff --git a/lib/libc/gen/_warnx.c b/lib/libc/gen/_warnx.c index ef09ffe54..5942be241 100644 --- a/lib/libc/gen/_warnx.c +++ b/lib/libc/gen/_warnx.c @@ -1,4 +1,4 @@ -/* $NetBSD: _warnx.c,v 1.10 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: _warnx.c,v 1.11 2011/07/17 20:54:34 joerg Exp $ */ /* * J.T. Conklin, December 12, 1994 @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _warnx.c,v 1.10 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: _warnx.c,v 1.11 2011/07/17 20:54:34 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #if defined(__indr_reference) @@ -16,7 +16,7 @@ __indr_reference(_warnx, warnx) #include -void _vwarnx(const char *, _BSD_VA_LIST_); +void _vwarnx(const char *, va_list); void warnx(const char *fmt, ...) diff --git a/lib/libc/gen/alarm.c b/lib/libc/gen/alarm.c index 5ad22c10c..6d8f2d8f3 100644 --- a/lib/libc/gen/alarm.c +++ b/lib/libc/gen/alarm.c @@ -1,4 +1,4 @@ -/* $NetBSD: alarm.c,v 1.10 2003/08/07 16:42:45 agc Exp $ */ +/* $NetBSD: alarm.c,v 1.11 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)alarm.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: alarm.c,v 1.10 2003/08/07 16:42:45 agc Exp $"); +__RCSID("$NetBSD: alarm.c,v 1.11 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,8 +50,7 @@ __weak_alias(alarm,_alarm) #endif unsigned int -alarm(secs) - unsigned int secs; +alarm(unsigned int secs) { struct itimerval it, oitv; struct itimerval *itp = ⁢ diff --git a/lib/libc/gen/arc4random.3 b/lib/libc/gen/arc4random.3 index 702ad788d..735aaf5ab 100644 --- a/lib/libc/gen/arc4random.3 +++ b/lib/libc/gen/arc4random.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: arc4random.3,v 1.7 2005/12/26 19:40:14 perry Exp $ +.\" $NetBSD: arc4random.3,v 1.9 2011/02/05 00:24:08 wiz Exp $ .\" $OpenBSD: arc4random.3,v 1.17 2000/12/21 14:07:41 aaron Exp $ .\" .\" Copyright 1997 Niels Provos @@ -31,11 +31,13 @@ .\" .\" Manual page, using -mandoc macros .\" -.Dd April 15, 1997 +.Dd February 4, 2011 .Dt ARC4RANDOM 3 .Os .Sh NAME .Nm arc4random , +.Nm arc4random_buf , +.Nm arc4random_uniform , .Nm arc4random_stir , .Nm arc4random_addrandom .Nd arc4 random number generator @@ -46,6 +48,10 @@ .Ft uint32_t .Fn arc4random "void" .Ft void +.Fn arc4random_buf "void *buffer" "size_t length" +.Ft uint32_t +.Fn arc4random_uniform "uint32_t upper_bound" +.Ft void .Fn arc4random_stir "void" .Ft void .Fn arc4random_addrandom "u_char *dat" "int datlen" @@ -77,6 +83,20 @@ and .Xr drand48 3 . .Pp The +.Fn arc4random_buf +function fills the +.Fa buffer +with +.Fa length +bytes of ARC4-derived random data. +.Pp +The +.Fn arc4random_uniform +function returns a uniformly distributed random number less than +.Fa upper_bound +avoiding modulo bias when the upper bound is not a power of two. +.Pp +The .Fn arc4random_stir function reads data from .Pa /dev/urandom diff --git a/lib/libc/gen/arc4random.c b/lib/libc/gen/arc4random.c index 1b9f2229d..5326ac91b 100644 --- a/lib/libc/gen/arc4random.c +++ b/lib/libc/gen/arc4random.c @@ -1,4 +1,4 @@ -/* $NetBSD: arc4random.c,v 1.9 2005/12/24 21:11:16 perry Exp $ */ +/* $NetBSD: arc4random.c,v 1.20 2012/08/20 21:38:09 dsl Exp $ */ /* $OpenBSD: arc4random.c,v 1.6 2001/06/05 05:05:38 pvalchev Exp $ */ /* @@ -27,10 +27,11 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: arc4random.c,v 1.9 2005/12/24 21:11:16 perry Exp $"); +__RCSID("$NetBSD: arc4random.c,v 1.20 2012/08/20 21:38:09 dsl Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" +#include "reentrant.h" #include #include #include @@ -41,65 +42,98 @@ __RCSID("$NetBSD: arc4random.c,v 1.9 2005/12/24 21:11:16 perry Exp $"); #ifdef __weak_alias __weak_alias(arc4random,_arc4random) +__weak_alias(arc4random_addrandom,_arc4random_addrandom) +__weak_alias(arc4random_buf,_arc4random_buf) +__weak_alias(arc4random_stir,_arc4random_stir) +__weak_alias(arc4random_uniform,_arc4random_uniform) #endif struct arc4_stream { - u_int8_t i; - u_int8_t j; - u_int8_t s[256]; + uint8_t stirred; + uint8_t pad; + uint8_t i; + uint8_t j; + uint8_t s[(uint8_t)~0u + 1u]; /* 256 to you and me */ +#ifdef _REENTRANT + mutex_t mtx; +#endif }; -static int rs_initialized; -static struct arc4_stream rs; +#ifdef _REENTRANT +#define LOCK(rs) { \ + int isthreaded = __isthreaded; \ + if (isthreaded) \ + mutex_lock(&(rs)->mtx); +#define UNLOCK(rs) \ + if (isthreaded) \ + mutex_unlock(&(rs)->mtx); \ + } +#else +#define LOCK(rs) +#define UNLOCK(rs) +#endif + +#define S(n) (n) +#define S4(n) S(n), S(n + 1), S(n + 2), S(n + 3) +#define S16(n) S4(n), S4(n + 4), S4(n + 8), S4(n + 12) +#define S64(n) S16(n), S16(n + 16), S16(n + 32), S16(n + 48) +#define S256 S64(0), S64(64), S64(128), S64(192) + +static struct arc4_stream rs = { .i = 0xff, .j = 0, .s = { S256 }, +#ifdef _REENTRANT + .stirred = 0, .mtx = MUTEX_INITIALIZER }; +#else + .stirred = 0 }; +#endif + +#undef S +#undef S4 +#undef S16 +#undef S64 +#undef S256 -static inline void arc4_init(struct arc4_stream *); static inline void arc4_addrandom(struct arc4_stream *, u_char *, int); -static void arc4_stir(struct arc4_stream *); -static inline u_int8_t arc4_getbyte(struct arc4_stream *); -static inline u_int32_t arc4_getword(struct arc4_stream *); +static __noinline void arc4_stir(struct arc4_stream *); +static inline uint8_t arc4_getbyte(struct arc4_stream *); +static inline uint32_t arc4_getword(struct arc4_stream *); -static inline void -arc4_init(as) - struct arc4_stream *as; +static inline int +arc4_check_init(struct arc4_stream *as) { - int n; + if (__predict_true(rs.stirred)) + return 0; - for (n = 0; n < 256; n++) - as->s[n] = n; - as->i = 0; - as->j = 0; + arc4_stir(as); + return 1; } static inline void -arc4_addrandom(as, dat, datlen) - struct arc4_stream *as; - u_char *dat; - int datlen; +arc4_addrandom(struct arc4_stream *as, u_char *dat, int datlen) { - int n; - u_int8_t si; + uint8_t si; + size_t n; - as->i--; - for (n = 0; n < 256; n++) { + for (n = 0; n < __arraycount(as->s); n++) { as->i = (as->i + 1); si = as->s[as->i]; as->j = (as->j + si + dat[n % datlen]); as->s[as->i] = as->s[as->j]; as->s[as->j] = si; } - as->j = as->i; } -static void -arc4_stir(as) - struct arc4_stream *as; +static __noinline void +arc4_stir(struct arc4_stream *as) { - int fd; +#ifdef __minix + /* LSC: We do not have a compatibility layer for the + * KERN_URND call, so use the old way... */ + int fd; + size_t j; struct { struct timeval tv; u_int rnd[(128 - sizeof(struct timeval)) / sizeof(u_int)]; } rdat; - int n; gettimeofday(&rdat.tv, NULL); fd = open("/dev/urandom", O_RDONLY); @@ -107,59 +141,68 @@ arc4_stir(as) read(fd, rdat.rnd, sizeof(rdat.rnd)); close(fd); } -#ifdef KERN_URND - else { - int mib[2]; - u_int i; - size_t len; - - /* Device could not be opened, we might be chrooted, take - * randomness from sysctl. */ - - mib[0] = CTL_KERN; - mib[1] = KERN_URND; - - for (i = 0; i < sizeof(rdat.rnd) / sizeof(u_int); i++) { - len = sizeof(u_int); - if (sysctl(mib, 2, &rdat.rnd[i], &len, NULL, 0) == -1) - break; - } - } -#endif + /* fd < 0 or failed sysctl ? Ah, what the heck. We'll just take * whatever was on the stack... */ +#else + int rdat[32]; + int mib[] = { CTL_KERN, KERN_URND }; + size_t len; + size_t i, j; - arc4_addrandom(as, (void *) &rdat, sizeof(rdat)); + /* + * This code once opened and read /dev/urandom on each + * call. That causes repeated rekeying of the kernel stream + * generator, which is very wasteful. Because of application + * behavior, caching the fd doesn't really help. So we just + * fill up the tank from sysctl, which is a tiny bit slower + * for us but much friendlier to other entropy consumers. + */ + + for (i = 0; i < __arraycount(rdat); i++) { + len = sizeof(rdat[i]); + if (sysctl(mib, 2, &rdat[i], &len, NULL, 0) == -1) + abort(); + } +#endif + + arc4_addrandom(as, (void *) &rdat, (int)sizeof(rdat)); /* * Throw away the first N words of output, as suggested in the * paper "Weaknesses in the Key Scheduling Algorithm of RC4" * by Fluher, Mantin, and Shamir. (N = 256 in our case.) */ - for (n = 0; n < 256 * 4; n++) + for (j = 0; j < __arraycount(as->s) * 4; j++) arc4_getbyte(as); + + as->stirred = 1; } -static inline u_int8_t -arc4_getbyte(as) - struct arc4_stream *as; +static __always_inline uint8_t +arc4_getbyte_ij(struct arc4_stream *as, uint8_t *i, uint8_t *j) { - u_int8_t si, sj; - - as->i = (as->i + 1); - si = as->s[as->i]; - as->j = (as->j + si); - sj = as->s[as->j]; - as->s[as->i] = sj; - as->s[as->j] = si; + uint8_t si, sj; + + *i = *i + 1; + si = as->s[*i]; + *j = *j + si; + sj = as->s[*j]; + as->s[*i] = sj; + as->s[*j] = si; return (as->s[(si + sj) & 0xff]); } -static inline u_int32_t -arc4_getword(as) - struct arc4_stream *as; +static inline uint8_t +arc4_getbyte(struct arc4_stream *as) +{ + return arc4_getbyte_ij(as, &as->i, &as->j); +} + +static inline uint32_t +arc4_getword(struct arc4_stream *as) { - u_int32_t val; + uint32_t val; val = arc4_getbyte(as) << 24; val |= arc4_getbyte(as) << 16; val |= arc4_getbyte(as) << 8; @@ -168,50 +211,97 @@ arc4_getword(as) } void -arc4random_stir() +arc4random_stir(void) { - if (!rs_initialized) { - arc4_init(&rs); - rs_initialized = 1; - } + LOCK(&rs); arc4_stir(&rs); + UNLOCK(&rs); } void -arc4random_addrandom(dat, datlen) - u_char *dat; - int datlen; +arc4random_addrandom(u_char *dat, int datlen) { - if (!rs_initialized) - arc4random_stir(); + LOCK(&rs); + arc4_check_init(&rs); arc4_addrandom(&rs, dat, datlen); + UNLOCK(&rs); } -u_int32_t -arc4random() +uint32_t +arc4random(void) { - if (!rs_initialized) - arc4random_stir(); - return arc4_getword(&rs); + uint32_t v; + + LOCK(&rs); + arc4_check_init(&rs); + v = arc4_getword(&rs); + UNLOCK(&rs); + return v; } -#if 0 -/*-------- Test code for i386 --------*/ -#include -#include -int -main(int argc, char **argv) +void +arc4random_buf(void *buf, size_t len) { - const int iter = 1000000; - int i; - pctrval v; + uint8_t *bp = buf; + uint8_t *ep = bp + len; + uint8_t i, j; - v = rdtsc(); - for (i = 0; i < iter; i++) - arc4random(); - v = rdtsc() - v; - v /= iter; + LOCK(&rs); + arc4_check_init(&rs); - printf("%qd cycles\n", v); + /* cache i and j - compiler can't know 'buf' doesn't alias them */ + i = rs.i; + j = rs.j; + + while (bp < ep) + *bp++ = arc4_getbyte_ij(&rs, &i, &j); + rs.i = i; + rs.j = j; + + UNLOCK(&rs); +} + +/*- + * Written by Damien Miller. + * With simplifications by Jinmei Tatuya. + */ + +/* + * Calculate a uniformly distributed random number less than + * upper_bound avoiding "modulo bias". + * + * Uniformity is achieved by generating new random numbers + * until the one returned is outside the range + * [0, 2^32 % upper_bound[. This guarantees the selected + * random number will be inside the range + * [2^32 % upper_bound, 2^32[ which maps back to + * [0, upper_bound[ after reduction modulo upper_bound. + */ +uint32_t +arc4random_uniform(uint32_t upper_bound) +{ + uint32_t r, min; + + if (upper_bound < 2) + return 0; + + /* calculate (2^32 % upper_bound) avoiding 64-bit math */ + /* ((2^32 - x) % x) == (2^32 % x) when x <= 2^31 */ + min = (0xFFFFFFFFU - upper_bound + 1) % upper_bound; + + LOCK(&rs); + arc4_check_init(&rs); + + /* + * This could theoretically loop forever but each retry has + * p > 0.5 (worst case, usually far better) of selecting a + * number inside the range we need, so it should rarely need + * to re-roll (at all). + */ + do + r = arc4_getword(&rs); + while (r < min); + UNLOCK(&rs); + + return r % upper_bound; } -#endif diff --git a/lib/libc/gen/assert.c b/lib/libc/gen/assert.c index 7cbf555de..3197671b8 100644 --- a/lib/libc/gen/assert.c +++ b/lib/libc/gen/assert.c @@ -1,4 +1,4 @@ -/* $NetBSD: assert.c,v 1.16 2005/02/09 21:35:46 kleink Exp $ */ +/* $NetBSD: assert.c,v 1.17 2012/06/25 22:32:43 abs Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)assert.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: assert.c,v 1.16 2005/02/09 21:35:46 kleink Exp $"); +__RCSID("$NetBSD: assert.c,v 1.17 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -47,9 +47,8 @@ __RCSID("$NetBSD: assert.c,v 1.16 2005/02/09 21:35:46 kleink Exp $"); #include void -__assert13(file, line, function, failedexpr) - const char *file, *function, *failedexpr; - int line; +__assert13(const char *file, int line, const char *function, + const char *failedexpr) { (void)fprintf(stderr, @@ -63,9 +62,7 @@ __assert13(file, line, function, failedexpr) } void -__assert(file, line, failedexpr) - const char *file, *failedexpr; - int line; +__assert(const char *file, int line, const char *failedexpr) { __assert13(file, line, NULL, failedexpr); @@ -82,9 +79,8 @@ enum { static int diagassert_flags = -1; void -__diagassert13(file, line, function, failedexpr) - const char *file, *function, *failedexpr; - int line; +__diagassert13(const char *file, int line, const char *function, + const char *failedexpr) { char buf[1024]; @@ -132,9 +128,7 @@ __diagassert13(file, line, function, failedexpr) } void -__diagassert(file, line, failedexpr) - const char *file, *failedexpr; - int line; +__diagassert(const char *file, int line, const char *failedexpr) { __diagassert13(file, line, NULL, failedexpr); diff --git a/lib/libc/gen/cgetcap.3 b/lib/libc/gen/cgetcap.3 index 1a43ccc13..5854c1d26 100644 --- a/lib/libc/gen/cgetcap.3 +++ b/lib/libc/gen/cgetcap.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: cgetcap.3,v 1.6 2009/08/19 15:43:02 joerg Exp $ +.\" $NetBSD: cgetcap.3,v 1.8 2012/04/22 10:13:52 wiz Exp $ .\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)getcap.3 8.4 (Berkeley) 5/13/94 .\" -.Dd February 1, 2008 +.Dd April 5, 2012 .Dt CGETCAP 3 .Os .Sh NAME @@ -178,11 +178,10 @@ is returned on success, .Dv NULL if the requested capability couldn't be found. The end of the capability value is signaled by a -.Sq \&: -or -.Tn ASCII -.Dv NUL -(see below for capability database syntax). +.Sq \&: . +See +.Xr capfile 5 +for a description of the capability syntax. .Pp .Fn cgetnum retrieves the value of the numeric capability @@ -263,84 +262,6 @@ closes the sequential access and frees any memory and file descriptors being used. Note that it does not erase the buffer pushed by a call to .Fn cgetset . -.Sh CAPABILITY DATABASE SYNTAX -Capability databases are normally -.Tn ASCII -and may be edited with standard text editors. -Blank lines and lines beginning with a -.Sq # -are comments and are ignored. -Lines ending with a -.Sq \|\e -indicate that the next line is a continuation -of the current line; the -.Sq \|\e -and following newline are ignored. -Long lines are usually continued onto several physical -lines by ending each line except the last with a -.Sq \|\e . -.Pp -Capability databases consist of a series of records, one per logical line. -Each record contains a variable number of -.So \&: Sc Ns -separated -fields (capabilities). -Empty fields consisting entirely of white space -characters (spaces and tabs) are ignored. -.Pp -The first capability of each record specifies its names, separated by -.Sq | -characters. -These names are used to reference records in the database. -By convention, the last name is usually a comment and is not intended as -a lookup tag. -For example, the -.Em vt100 -record from the -.Pa termcap -database begins: -.Pp -.Dl "d0\||\|vt100\||\|vt100-am\||\|vt100am\||\|dec vt100:" -.Pp -giving four names that can be used to access the record. -.Pp -The remaining non-empty capabilities describe a set of (name, value) -bindings, consisting of a name optionally followed by a typed value: -.Bl -column "nameTvalue" -.It name Ta "typeless [boolean] capability" -.Em name No "is present [true]" -.It name Ns Em \&T Ns value Ta capability -.Pq Em name , \&T -has value -.Em value -.It name@ Ta "no capability" Em name No exists -.It name Ns Em T Ns \&@ Ta capability -.Pq Em name , T -does not exist -.El -.Pp -Names consist of one or more characters. -Names may contain any character except -.Sq \&: , -but it's usually best -to restrict them to the printable characters and avoid use of -graphics like -.Sq # , -.Sq = , -.Sq % , -.Sq @ , -etc. -.Pp -Types are single characters used to separate capability names from -their associated typed values. -Types may be any character except a -.Sq \&: . -Typically, graphics like -.Sq # , -.Sq = , -.Sq % , -etc. are used. -Values may be any number of characters and may contain any character except -.Sq \&: . .Sh CAPABILITY DATABASE SEMANTICS Capability records describe a set of (name, value) bindings. Names may have multiple values bound to them. @@ -394,174 +315,6 @@ is declared and all subsequent files in the file array. can be used to control if .Qq tc expansion is performed or not. -.Pp -When a database is searched for a capability record, the first matching -record in the search is returned. -When a record is scanned for a capability, the first matching -capability is returned; the capability -.Qq :nameT@: -will hide any following definition of a value of type -.Em T -for -.Fa name ; -and the capability -.Qq :name@: -will prevent any following values of -.Fa name -from being seen. -.Pp -These features combined with -.Qq tc -capabilities can be used to generate variations of other databases and -records by either adding new capabilities, overriding definitions with new -definitions, or hiding following definitions via -.Sq @ -capabilities. -.Sh EXAMPLES -.Bd -unfilled -offset indent -example\||\|an example of binding multiple values to names:\e - :foo%bar:foo^blah:foo@:\e - :abc%xyz:abc^frap:abc$@:\e - :tc=more: -.Ed -.Pp -The capability -.Em foo -has two values bound to it -.Po -.Em bar -of type -.Sq % -and -.Em blah -of type -.Sq ^ -.Pc -and any other value bindings are hidden. -The capability -.Em abc -also has two values bound but only a value of type -.Sq $ -is prevented from -being defined in the capability record more. -.Pp -.Bd -unfilled -offset indent -file1: - new\||\|new_record\||\|a modification of "old":\e - :fript=bar:who-cares@:tc=old:blah:tc=extensions: -file2: - old\||\|old_record\||\|an old database record:\e - :fript=foo:who-cares:glork#200: -.Ed -.Pp -The records are extracted by calling -.Fn cgetent -with -.Fa file1 -preceding -.Fa file2 . -In the capability record -.Em new -in -.Fa file1 , -.Qq fript=bar -overrides the definition of -.Qq fript=foo -interpolated from the capability record -.Em old -in -.Fa file2 , -.Qq who-cares@ -prevents the definition of any who-cares definitions in -.Em old -from being seen, -.Qq glork#200 -is inherited from -.Em old , -and -.Em blah -and anything defined by the record extensions is added to those -definitions in -.Em old . -Note that the position of the -.Qq fript=bar -and -.Qq who-cares@ -definitions before -.Qq tc=old -is important here. -If they were after, the definitions in -.Em old -would take precedence. -.Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICS -Two types are predefined by -.Fn cgetnum -and -.Fn cgetstr : -.Bl -column "nameXnumber" -.It Em name Ns \&# Ns Em number Ta numeric -capability -.Em name -has value -.Em number -.It Em name Ns = Ns Em string Ta "string capability" -.Em name -has value -.Em string -.It Em name Ns \&#@ Ns Ta "the numeric capability" -.Em name -does not exist -.It Em name Ns \&=@ Ns Ta "the string capability" -.Em name -does not exist -.El -.Pp -Numeric capability values may be given in one of three numeric bases. -If the number starts with either -.Ql 0x -or -.Ql 0X -it is interpreted as a hexadecimal number (both upper and lower case a-f -may be used to denote the extended hexadecimal digits). -Otherwise, if the number starts with a -.Ql 0 -it is interpreted as an octal number. -Otherwise the number is interpreted as a decimal number. -.Pp -String capability values may contain any character. -Non-printable -.Dv ASCII -codes, new lines, and colons may be conveniently represented by the use -of escape sequences: -.Bl -column "\e\|X,X\e\|X" "(ASCII octal nnn)" -.It ^X ('\fIX\fP' \*[Am] 037) control-\fIX\fP -.It \e\|b, \e\|B (ASCII 010) backspace -.It \e\|t, \e\|T (ASCII 011) tab -.It \e\|n, \e\|N (ASCII 012) line feed (newline) -.It \e\|f, \e\|F (ASCII 014) form feed -.It \e\|r, \e\|R (ASCII 015) carriage return -.It \e\|e, \e\|E (ASCII 027) escape -.It \e\|c, \e\|C (:) colon -.It \e\|\e (\e\|) back slash -.It \e\|^ (^) caret -.It \e\|\fInnn\fP (ASCII octal \fInnn\fP) -.El -.Pp -A -.Sq \|\e -followed by up to three octal digits directly specifies -the numeric code for a character. -The use of -.Tn ASCII -.Dv NUL Ns s , -while easily -encoded, causes all sorts of problems and must be used with care since -.Dv NUL Ns s -are typically used to denote the end of strings; many applications -use -.Sq \e\|200 -to represent a -.Dv NUL . .Sh DIAGNOSTICS .Fn cgetent , .Fn cgetset , @@ -607,12 +360,9 @@ No memory to allocate. .El .Sh SEE ALSO .Xr cap_mkdb 1 , -.Xr malloc 3 +.Xr malloc 3 , +.Xr capfile 5 .Sh BUGS -Colons -.Pq Sq \&: -can't be used in names, types, or values. -.Pp There are no checks for .Qq tc=name loops in diff --git a/lib/libc/gen/confstr.c b/lib/libc/gen/confstr.c index 4641e9463..1160908c6 100644 --- a/lib/libc/gen/confstr.c +++ b/lib/libc/gen/confstr.c @@ -1,4 +1,4 @@ -/* $NetBSD: confstr.c,v 1.12 2006/12/03 00:39:19 christos Exp $ */ +/* $NetBSD: confstr.c,v 1.13 2012/06/25 22:32:43 abs Exp $ */ /*- * Copyright (c) 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)confstr.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: confstr.c,v 1.12 2006/12/03 00:39:19 christos Exp $"); +__RCSID("$NetBSD: confstr.c,v 1.13 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,10 +53,7 @@ __weak_alias(confstr,_confstr) #endif size_t -confstr(name, buf, len) - int name; - char *buf; - size_t len; +confstr(int name, char *buf, size_t len) { size_t tlen; int mib[2], sverrno; diff --git a/lib/libc/gen/cpuset.3 b/lib/libc/gen/cpuset.3 index e27ef046b..8a3298377 100644 --- a/lib/libc/gen/cpuset.3 +++ b/lib/libc/gen/cpuset.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: cpuset.3,v 1.3 2008/09/12 13:39:04 rmind Exp $ +.\" $NetBSD: cpuset.3,v 1.6 2011/11/02 20:25:20 wiz Exp $ .\" .\" Copyright (c) 2008 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd September 12, 2008 +.Dd November 2, 2011 .Dt CPUSET 3 .Os .Sh NAME @@ -41,7 +41,7 @@ .Nd dynamic CPU sets .Sh SYNOPSIS .In sched.h -.Ft cpuset_t +.Ft cpuset_t * .Fn cpuset_create "void" .Ft void .Fn cpuset_destroy "cpuset_t *set" @@ -112,7 +112,8 @@ Returns the size in bytes of CPU-set specified by .Xr affinity 3 , .Xr pset 3 , .Xr sched 3 , -.Xr schedctl 8 +.Xr schedctl 8 , +.Xr kcpuset 9 .Sh HISTORY The dynamic CPU sets appeared in .Nx 5.0 . diff --git a/lib/libc/gen/ctermid.c b/lib/libc/gen/ctermid.c index f0db511d6..21ace8a6b 100644 --- a/lib/libc/gen/ctermid.c +++ b/lib/libc/gen/ctermid.c @@ -1,4 +1,4 @@ -/* $NetBSD: ctermid.c,v 1.10 2003/08/07 16:42:46 agc Exp $ */ +/* $NetBSD: ctermid.c,v 1.11 2012/06/25 22:32:43 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)ctermid.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: ctermid.c,v 1.10 2003/08/07 16:42:46 agc Exp $"); +__RCSID("$NetBSD: ctermid.c,v 1.11 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,8 +48,7 @@ __weak_alias(ctermid,_ctermid) #endif char * -ctermid(s) - char *s; +ctermid(char *s) { static char def[] = _PATH_TTY; diff --git a/lib/libc/gen/daemon.c b/lib/libc/gen/daemon.c index 032149dc3..1cec204fc 100644 --- a/lib/libc/gen/daemon.c +++ b/lib/libc/gen/daemon.c @@ -1,4 +1,4 @@ -/* $NetBSD: daemon.c,v 1.9 2003/08/07 16:42:46 agc Exp $ */ +/* $NetBSD: daemon.c,v 1.10 2012/06/25 22:32:43 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: daemon.c,v 1.9 2003/08/07 16:42:46 agc Exp $"); +__RCSID("$NetBSD: daemon.c,v 1.10 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,8 +49,7 @@ __weak_alias(daemon,_daemon) #endif int -daemon(nochdir, noclose) - int nochdir, noclose; +daemon(int nochdir, int noclose) { int fd; diff --git a/lib/libc/gen/dehumanize_number.c b/lib/libc/gen/dehumanize_number.c index 89afead87..10218485c 100644 --- a/lib/libc/gen/dehumanize_number.c +++ b/lib/libc/gen/dehumanize_number.c @@ -1,4 +1,4 @@ -/* $NetBSD: dehumanize_number.c,v 1.3 2008/04/28 20:22:59 martin Exp $ */ +/* $NetBSD: dehumanize_number.c,v 1.4 2012/03/13 21:13:34 christos Exp $ */ /* * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. @@ -31,10 +31,11 @@ */ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: dehumanize_number.c,v 1.3 2008/04/28 20:22:59 martin Exp $"); +__RCSID("$NetBSD: dehumanize_number.c,v 1.4 2012/03/13 21:13:34 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" +#include #include #include #include @@ -109,7 +110,9 @@ dehumanize_number(const char *str, int64_t *size) errno = ERANGE; return -1; /* Out of range. */ } - *size = tmp * multiplier; + tmp *= multiplier; + _DIAGASSERT(__type_fit(int64_t, tmp)); + *size = (int64_t)tmp; return 0; } diff --git a/lib/libc/gen/devname.3 b/lib/libc/gen/devname.3 index 1c00fc5b5..6ab0318d1 100644 --- a/lib/libc/gen/devname.3 +++ b/lib/libc/gen/devname.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: devname.3,v 1.11 2003/08/07 16:42:46 agc Exp $ +.\" $NetBSD: devname.3,v 1.12 2012/06/03 21:42:46 joerg Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)devname.3 8.2 (Berkeley) 4/29/95 .\" -.Dd April 29, 1995 +.Dd June 3, 2012 .Dt DEVNAME 3 .Os .Sh NAME @@ -53,11 +53,6 @@ with a device number of and a file type matching the one encoded in .Fa type which must be one of S_IFBLK or S_IFCHR. -The device name is cached so that multiple calls with the same -.Fa dev -and -.Fa type -do not require additional queries of the device database file. If no device matches the specified values, or no information is available, .Dv NULL @@ -67,8 +62,8 @@ The traditional display for applications when no device is found is the string .Dq ?? . .Sh FILES -.Bl -tag -width /var/run/dev.db -compact -.It Pa /var/run/dev.db +.Bl -tag -width /var/run/dev.cdb -compact +.It Pa /var/run/dev.cdb Device database file. .El .Sh SEE ALSO diff --git a/lib/libc/gen/devname.c b/lib/libc/gen/devname.c index e11d11f06..f6719108f 100644 --- a/lib/libc/gen/devname.c +++ b/lib/libc/gen/devname.c @@ -1,7 +1,7 @@ -/* $NetBSD: devname.c,v 1.21 2010/03/23 20:28:59 drochner Exp $ */ +/* $NetBSD: devname.c,v 1.22 2012/06/03 21:42:46 joerg Exp $ */ /*- - * Copyright (c) 2000 The NetBSD Foundation, Inc. + * Copyright (c) 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -29,170 +29,139 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/*- - * Copyright (c) 1992 Keith Muller. - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Keith Muller of the University of California, San Diego. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - #include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)devname.c 8.2 (Berkeley) 4/29/95"; -#else -__RCSID("$NetBSD: devname.c,v 1.21 2010/03/23 20:28:59 drochner Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ +__RCSID("$NetBSD: devname.c,v 1.22 2012/06/03 21:42:46 joerg Exp $"); #include "namespace.h" -#include +#include "reentrant.h" #include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include -#include -#define DEV_SZ 317 /* show be prime for best results */ -#define VALID 1 /* entry and devname are valid */ -#define INVALID 2 /* entry valid, devname NOT valid */ +#ifdef __weak_alias +__weak_alias(devname_r,_devname_r) +#endif -typedef struct devc { - int valid; /* entry valid? */ - dev_t dev; /* cached device */ - mode_t type; /* cached file type */ - char name[NAME_MAX]; /* device name */ -} DEVC; +static once_t db_opened = ONCE_INITIALIZER; +static struct cdbr *db; +static devmajor_t pts; -char * -devname(dev, type) - dev_t dev; - mode_t type; +static void +devname_dbopen(void) { - struct { - mode_t type; - dev_t dev; - } bkey; - struct { - mode_t type; - int32_t dev; - } obkey; - static DB *db; - static int failure; - DBT data, key; - DEVC *ptr, **pptr; - static DEVC **devtb = NULL; - static devmajor_t pts; - static int pts_valid = 0; - - if (!db && !failure && - !(db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL))) { - warn("warning: %s", _PATH_DEVDB); - failure = 1; - } - /* initialise dev cache */ - if (!failure && devtb == NULL) { - devtb = calloc(DEV_SZ, sizeof(DEVC *)); - if (devtb == NULL) - failure= 1; - } - if (failure) - return (NULL); + db = cdbr_open(_PATH_DEVCDB, CDBR_DEFAULT); + pts = getdevmajor("pts", S_IFCHR); +} - /* see if we have this dev/type cached */ - pptr = devtb + (size_t)((dev + type) % DEV_SZ); - ptr = *pptr; +__CTASSERT(sizeof(dev_t) == 8); - if (ptr && ptr->valid > 0 && ptr->dev == dev && ptr->type == type) { - if (ptr->valid == VALID) - return (ptr->name); - return (NULL); - } +static int +devname_dblookup(dev_t dev, mode_t type, char *path, size_t len) +{ + const void *data; + size_t datalen; + uint8_t key[10]; + + le64enc(key, dev); + le16enc(key + 8, type); + if (cdbr_find(db, key, sizeof(key), &data, &datalen) != 0) + return ENOENT; + if (datalen <= sizeof(key)) + return ENOENT; + if (memcmp(key, data, sizeof(key)) != 0) + return ENOENT; + data = (const char *)data + sizeof(key); + datalen -= sizeof(key); + if (memchr(data, '\0', datalen) != (const char *)data + datalen - 1) + return ENOENT; + if (datalen > len) + return ERANGE; + memcpy(path, data, datalen); + return 0; +} + +static int +devname_ptslookup(dev_t dev, mode_t type, char *path, size_t len) +{ + int rv; + + if (type != S_IFCHR || pts == NODEVMAJOR || major(dev) != pts) + return ENOENT; + + rv = snprintf(path, len, "%s%d", _PATH_DEV_PTS + sizeof(_PATH_DEV) - 1, + minor(dev)); + if (rv < 0 || (size_t)rv >= len) + return ERANGE; + return 0; +} - if (ptr == NULL) - *pptr = ptr = malloc(sizeof(DEVC)); - - /* - * Keys are a mode_t followed by a dev_t. The former is the type of - * the file (mode & S_IFMT), the latter is the st_rdev field. Be - * sure to clear any padding that may be found in bkey. - */ - (void)memset(&bkey, 0, sizeof(bkey)); - bkey.dev = dev; - bkey.type = type; - key.data = &bkey; - key.size = sizeof(bkey); - if ((db->get)(db, &key, &data, 0) == 0) { -found_it: - if (ptr == NULL) - return (char *)data.data; - ptr->dev = dev; - ptr->type = type; - strncpy(ptr->name, (char *)data.data, NAME_MAX); - ptr->name[NAME_MAX - 1] = '\0'; - ptr->valid = VALID; - } else { - /* Look for a 32 bit dev_t. */ - (void)memset(&obkey, 0, sizeof(obkey)); - obkey.dev = (int32_t)(uint32_t)dev; - obkey.type = type; - key.data = &obkey; - key.size = sizeof(obkey); - if ((db->get)(db, &key, &data, 0) == 0) - goto found_it; - - if (ptr == NULL) - return (NULL); - ptr->valid = INVALID; - if (type == S_IFCHR) { - if (!pts_valid) { - pts = getdevmajor("pts", S_IFCHR); - pts_valid = 1; - } - if (pts != NODEVMAJOR && major(dev) == pts) { - (void)snprintf(ptr->name, sizeof(ptr->name), - "%s%d", _PATH_DEV_PTS + - sizeof(_PATH_DEV) - 1, - minor(dev)); - ptr->valid = VALID; - } +static int +devname_fts(dev_t dev, mode_t type, char *path, size_t len) +{ + FTS *ftsp; + FTSENT *fe; + static const char path_dev[] = _PATH_DEV; + static char * const dirs[2] = { __UNCONST(path_dev), NULL }; + const size_t len_dev = strlen(path_dev); + int rv; + + if ((ftsp = fts_open(dirs, FTS_NOCHDIR | FTS_PHYSICAL, NULL)) == NULL) + return ENOENT; + + rv = ENOENT; + while ((fe = fts_read(ftsp)) != NULL) { + if (fe->fts_info != FTS_DEFAULT) + continue; + if (fe->fts_statp->st_rdev != dev) + continue; + if ((type & S_IFMT) != (fe->fts_statp->st_mode & S_IFMT)) + continue; + if (strncmp(fe->fts_path, path_dev, len_dev)) + continue; + if (strlcpy(path, fe->fts_path + len_dev, len) < len) { + rv = 0; + break; } - ptr->dev = dev; - ptr->type = type; } - if (ptr->valid == VALID) - return (ptr->name); - else - return (NULL); + + fts_close(ftsp); + return rv; +} + +int +devname_r(dev_t dev, mode_t type, char *path, size_t len) +{ + int rv; + + thr_once(&db_opened, devname_dbopen); + + if (db != NULL) { + rv = devname_dblookup(dev, type, path, len); + if (rv == 0 || rv == ERANGE) + return rv; + } + + rv = devname_ptslookup(dev, type, path, len); + if (rv == 0 || rv == ERANGE) + return rv; + + if (db != NULL) + return ENOENT; + rv = devname_fts(dev, type, path, len); + return rv; +} + +char * +devname(dev_t dev, mode_t type) +{ + static char path[PATH_MAX]; + + return devname_r(dev, type, path, sizeof(path)) == 0 ? path : NULL; } diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3 index 432cf60ae..7b7392587 100644 --- a/lib/libc/gen/directory.3 +++ b/lib/libc/gen/directory.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: directory.3,v 1.36 2010/12/17 19:20:42 njoly Exp $ +.\" $NetBSD: directory.3,v 1.38 2012/10/08 18:15:09 njoly Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)directory.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 4, 2010 +.Dd October 15, 2011 .Dt DIRECTORY 3 .Os .Sh NAME @@ -58,7 +58,7 @@ .Ft long .Fn telldir "DIR *dirp" .Ft void -.Fn seekdir "DIR *dirp" "long loc" +.Fn seekdir "DIR *dirp" "long loc" .Ft void .Fn rewinddir "DIR *dirp" .Ft int @@ -393,3 +393,7 @@ and .Fn dirfd functions appeared in .Bx 4.2 . +The +.Fn fdopendir +function appeared in +.Nx 6.0 . diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c index 94a118443..591de811c 100644 --- a/lib/libc/gen/disklabel.c +++ b/lib/libc/gen/disklabel.c @@ -1,4 +1,4 @@ -/* $NetBSD: disklabel.c,v 1.34 2006/03/19 02:17:16 christos Exp $ */ +/* $NetBSD: disklabel.c,v 1.37 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1983, 1987, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)disklabel.c 8.2 (Berkeley) 5/3/95"; #else -__RCSID("$NetBSD: disklabel.c,v 1.34 2006/03/19 02:17:16 christos Exp $"); +__RCSID("$NetBSD: disklabel.c,v 1.37 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -71,15 +71,14 @@ __weak_alias(getdiskbyname,_getdiskbyname) #endif #if 0 -static void error __P((int)); +static void error(int); #endif -static int gettype __P((char *, const char *const *)); +static int gettype(char *, const char *const *); static const char *db_array[2] = { _PATH_DISKTAB, 0 }; int -setdisktab(name) - const char *name; +setdisktab(const char *name) { if (!name || !*name) return -1; @@ -90,8 +89,7 @@ setdisktab(name) struct disklabel * -getdiskbyname(name) - const char *name; +getdiskbyname(const char *name) { static struct disklabel disk; struct disklabel *dp = &disk; @@ -208,9 +206,7 @@ getdiskbyname(name) } static int -gettype(t, names) - char *t; - const char *const *names; +gettype(char *t, const char *const *names) { const char *const *nm; @@ -219,7 +215,7 @@ gettype(t, names) for (nm = names; *nm; nm++) if (strcasecmp(t, *nm) == 0) - return (nm - names); + return (int)(nm - names); if (isdigit((unsigned char) *t)) return (atoi(t)); return (0); diff --git a/lib/libc/gen/execl.c b/lib/libc/gen/execl.c index 35aab72d8..cdc45ffac 100644 --- a/lib/libc/gen/execl.c +++ b/lib/libc/gen/execl.c @@ -1,4 +1,4 @@ -/* $NetBSD: execl.c,v 1.16 2008/01/09 11:26:03 simonb Exp $ */ +/* $NetBSD: execl.c,v 1.17 2011/06/30 19:46:07 joerg Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: execl.c,v 1.16 2008/01/09 11:26:03 simonb Exp $"); +__RCSID("$NetBSD: execl.c,v 1.17 2011/06/30 19:46:07 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -56,10 +56,6 @@ int execl(const char *name, const char *arg, ...) { int r; -#if (defined(__i386__) || defined(__m68k__)) && !defined(__minix) - r = execve(name, __UNCONST(&arg), environ); - return r; -#else va_list ap; char **argv; int i; @@ -82,5 +78,4 @@ execl(const char *name, const char *arg, ...) r = execve(name, argv, environ); return r; -#endif } diff --git a/lib/libc/gen/execle.c b/lib/libc/gen/execle.c index 37980b982..9c91b88fe 100644 --- a/lib/libc/gen/execle.c +++ b/lib/libc/gen/execle.c @@ -1,4 +1,4 @@ -/* $NetBSD: execle.c,v 1.11 2008/01/09 11:26:03 simonb Exp $ */ +/* $NetBSD: execle.c,v 1.12 2011/06/30 19:46:07 joerg Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: execle.c,v 1.11 2008/01/09 11:26:03 simonb Exp $"); +__RCSID("$NetBSD: execle.c,v 1.12 2011/06/30 19:46:07 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,18 +50,6 @@ __weak_alias(execle,_execle) int execle(const char *name, const char *arg, ...) { -#if (defined(__i386__) || defined(__m68k__)) && !defined(__minix) - va_list ap; - char **envp; - - va_start(ap, arg); - while ((va_arg(ap, char *)) != NULL) - continue; - envp = va_arg(ap, char **); - va_end(ap); - - return execve(name, __UNCONST(&arg), envp); -#else va_list ap; char **argv, **envp; int i; @@ -81,5 +69,4 @@ execle(const char *name, const char *arg, ...) va_end(ap); return execve(name, argv, envp); -#endif } diff --git a/lib/libc/gen/execlp.c b/lib/libc/gen/execlp.c index 8358221e7..4d9dd7062 100644 --- a/lib/libc/gen/execlp.c +++ b/lib/libc/gen/execlp.c @@ -1,4 +1,4 @@ -/* $NetBSD: execlp.c,v 1.11 2008/01/09 11:26:03 simonb Exp $ */ +/* $NetBSD: execlp.c,v 1.12 2011/06/30 19:46:07 joerg Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: execlp.c,v 1.11 2008/01/09 11:26:03 simonb Exp $"); +__RCSID("$NetBSD: execlp.c,v 1.12 2011/06/30 19:46:07 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,9 +50,6 @@ __weak_alias(execlp,_execlp) int execlp(const char *name, const char *arg, ...) { -#if (defined(__i386__) || defined(__m68k__)) && !defined(__minix) - return execvp(name, __UNCONST(&arg)); -#else va_list ap; char **argv; int i; @@ -71,5 +68,4 @@ execlp(const char *name, const char *arg, ...) va_end(ap); return execvp(name, argv); -#endif } diff --git a/lib/libc/gen/execv.c b/lib/libc/gen/execv.c index 2bfc80069..148b4c2b2 100644 --- a/lib/libc/gen/execv.c +++ b/lib/libc/gen/execv.c @@ -1,4 +1,4 @@ -/* $NetBSD: execv.c,v 1.9 2005/11/29 13:30:49 christos Exp $ */ +/* $NetBSD: execv.c,v 1.10 2012/06/25 22:32:43 abs Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: execv.c,v 1.9 2005/11/29 13:30:49 christos Exp $"); +__RCSID("$NetBSD: execv.c,v 1.10 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,9 +49,7 @@ __weak_alias(execv,_execv) extern char **environ; int -execv(name, argv) - const char *name; - char * const *argv; +execv(const char *name, char * const *argv) { return execve(name, argv, environ); } diff --git a/lib/libc/gen/extattr.c b/lib/libc/gen/extattr.c index 90c9c5c2c..5499b912c 100644 --- a/lib/libc/gen/extattr.c +++ b/lib/libc/gen/extattr.c @@ -1,4 +1,4 @@ -/* $NetBSD: extattr.c,v 1.2 2005/02/09 21:35:46 kleink Exp $ */ +/* $NetBSD: extattr.c,v 1.4 2012/03/13 21:13:34 christos Exp $ */ /*- * Copyright (c) 2001 Robert N. M. Watson @@ -32,16 +32,25 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: extattr.c,v 1.2 2005/02/09 21:35:46 kleink Exp $"); +__RCSID("$NetBSD: extattr.c,v 1.4 2012/03/13 21:13:34 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include +#include #include #include +#include +#include #include +const int extattr_namespaces[] = { + EXTATTR_NAMESPACE_USER, + EXTATTR_NAMESPACE_SYSTEM, + 0, +}; + int extattr_namespace_to_string(int attrnamespace, char **string) { @@ -85,3 +94,288 @@ extattr_string_to_namespace(const char *string, int *attrnamespace) return (-1); } } + + +int +extattr_copy_fd(int from_fd, int to_fd, int namespace) +{ + ssize_t llen, vlen, maxvlen; + size_t alen; + void *alist = NULL; + void *aval = NULL; + size_t i; + int error = -1; + + llen = extattr_list_fd(from_fd, namespace, NULL, 0); + if (llen == -1) { + /* Silently ignore when EA are not supported */ + if (errno == EOPNOTSUPP) + error = 0; + goto out; + } + + if (llen == 0) { + error = 0; + goto out; + } + + if ((alist = malloc((size_t)llen)) == NULL) + goto out; + + llen = extattr_list_fd(from_fd, namespace, alist, (size_t)llen); + if (llen == -1) + goto out; + + maxvlen = 1024; + if ((aval = malloc((size_t)maxvlen)) == NULL) + goto out; + + for (i = 0; i < (size_t)llen; i += alen + 1) { + char aname[NAME_MAX + 1]; + char *ap; + + alen = ((uint8_t *)alist)[i]; + ap = ((char *)alist) + i + 1; + (void)memcpy(aname, ap, alen); + aname[alen] = '\0'; + + vlen = extattr_get_fd(from_fd, namespace, aname, NULL, 0); + if (vlen == -1) + goto out; + + if (vlen > maxvlen) { + if ((aval = realloc(aval, (size_t)vlen)) == NULL) + goto out; + maxvlen = vlen; + } + + if ((vlen = extattr_get_fd(from_fd, namespace, aname, + aval, (size_t)vlen)) == -1) + goto out; + + if (extattr_set_fd(to_fd, namespace, aname, + aval, (size_t)vlen) != vlen) + goto out; + } + + error = 0; +out: + if (aval != NULL) + free(aval); + + if (alist != NULL) + free(alist); + + return error; +} + +int +extattr_copy_file(const char *from, const char *to, int namespace) +{ + ssize_t llen, vlen, maxvlen; + size_t alen; + void *alist = NULL; + void *aval = NULL; + size_t i; + int error = -1; + + llen = extattr_list_file(from, namespace, NULL, 0); + if (llen == -1) { + /* Silently ignore when EA are not supported */ + if (errno == EOPNOTSUPP) + error = 0; + goto out; + } + + if (llen == 0) { + error = 0; + goto out; + } + + if ((alist = malloc((size_t)llen)) == NULL) + goto out; + + llen = extattr_list_file(from, namespace, alist, (size_t)llen); + if (llen == -1) + goto out; + + maxvlen = 1024; + if ((aval = malloc((size_t)maxvlen)) == NULL) + goto out; + + for (i = 0; i < (size_t)llen; i += alen + 1) { + char aname[NAME_MAX + 1]; + char *ap; + + alen = ((uint8_t *)alist)[i]; + ap = ((char *)alist) + i + 1; + (void)memcpy(aname, ap, alen); + aname[alen] = '\0'; + + vlen = extattr_get_file(from, namespace, aname, NULL, 0); + if (vlen == -1) + goto out; + + if (vlen > maxvlen) { + if ((aval = realloc(aval, (size_t)vlen)) == NULL) + goto out; + maxvlen = vlen; + } + + if ((vlen = extattr_get_file(from, namespace, aname, aval, (size_t)vlen)) == -1) + goto out; + + if (extattr_set_file(to, namespace, aname, + aval, (size_t)vlen) != vlen) + goto out; + } + + error = 0; +out: + if (aval != NULL) + free(aval); + + if (alist != NULL) + free(alist); + + return error; +} + +int +extattr_copy_link(const char *from, const char *to, int namespace) +{ + ssize_t llen, vlen, maxvlen; + size_t alen; + void *alist = NULL; + void *aval = NULL; + size_t i; + int error = -1; + + llen = extattr_list_link(from, namespace, NULL, 0); + if (llen == -1) { + /* Silently ignore when EA are not supported */ + if (errno == EOPNOTSUPP) + error = 0; + goto out; + } + + if (llen == 0) { + error = 0; + goto out; + } + + if ((alist = malloc((size_t)llen)) == NULL) + goto out; + + llen = extattr_list_link(from, namespace, alist, (size_t)llen); + if (llen == -1) + goto out; + + maxvlen = 1024; + if ((aval = malloc((size_t)maxvlen)) == NULL) + goto out; + + for (i = 0; i < (size_t)llen; i += alen + 1) { + char aname[NAME_MAX + 1]; + char *ap; + + alen = ((uint8_t *)alist)[i]; + ap = ((char *)alist) + i + 1; + (void)memcpy(aname, ap, alen); + aname[alen] = '\0'; + + vlen = extattr_get_link(from, namespace, aname, NULL, 0); + if (vlen == -1) + goto out; + + if (vlen > maxvlen) { + if ((aval = realloc(aval, (size_t)vlen)) == NULL) + goto out; + maxvlen = vlen; + } + + if ((vlen = extattr_get_link(from, namespace, aname, + aval, (size_t)vlen)) == -1) + goto out; + + if (extattr_set_link(to, namespace, aname, + aval, (size_t)vlen) != vlen) + goto out; + } + + error = 0; +out: + if (aval != NULL) + free(aval); + + if (alist != NULL) + free(alist); + + return error; +} + +static int +extattr_namespace_access(int namespace, int mode) +{ + switch (namespace) { + case EXTATTR_NAMESPACE_SYSTEM: + if ((mode & (R_OK|W_OK)) && getuid() != 0) + return -1; + break; + default: + break; + } + + return 0; +} + +int +fcpxattr(int from_fd, int to_fd) +{ + const int *ns; + int error; + + for (ns = extattr_namespaces; *ns; ns++) { + if (extattr_namespace_access(*ns, R_OK|W_OK) != 0) + continue; + + if ((error = extattr_copy_fd(from_fd, to_fd, *ns)) != 0) + return error; + } + + return 0; +} + +int +cpxattr(const char *from, const char *to) +{ + const int *ns; + int error; + + for (ns = extattr_namespaces; *ns; ns++) { + if (extattr_namespace_access(*ns, R_OK|W_OK) != 0) + continue; + + if ((error = extattr_copy_file(from, to, *ns)) != 0) + return error; + } + + return 0; +} + +int +lcpxattr(const char *from, const char *to) +{ + const int *ns; + int error; + + for (ns = extattr_namespaces; *ns; ns++) { + if (extattr_namespace_access(*ns, R_OK|W_OK) != 0) + continue; + + if ((error = extattr_copy_link(from, to, *ns)) != 0) + return error; + } + + return 0; +} diff --git a/lib/libc/gen/extattr_copy_file.3 b/lib/libc/gen/extattr_copy_file.3 new file mode 100644 index 000000000..9f9a2a00d --- /dev/null +++ b/lib/libc/gen/extattr_copy_file.3 @@ -0,0 +1,105 @@ +.\" $NetBSD: extattr_copy_file.3,v 1.2 2011/12/16 15:21:13 manu Exp $ +.\" +.\" Copyright (c) 2001 Dima Dorfman +.\" Copyright (c) 2011 Emmanuel Dreyfus +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" FreeBSD: src/lib/libc/posix1e/extattr.3,v 1.5 2002/12/12 17:25:53 ru Exp +.\" +.Dd December 16, 2011 +.Dt EXTATTR_COPY_FILE 3 +.Os +.Sh NAME +.Nm extattr_copy_file , +.Nm extattr_copy_fd , +.Nm extattr_copy_link , +.Nm cpxattr , +.Nm fcpxattr , +.Nm lcpxattr +.Nd copy extended attributes from a file to another one +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/extattr.h +.Ft int +.Fn extattr_copy_file "const char *from" "const char *to" "int namespace" +.Ft int +.Fn extattr_copy_fd "int from_fd" "int to_fd" "int namespace" +.Ft int +.Fn extattr_copy_link "const char *from" "const char *to" "int namespace" +.Ft int +.Fn cpxattr "const char *from" "const char *to" +.Ft int +.Fn fcpxattr "int from_fd" "int to_fd" +.Ft int +.Fn lcpxattr "const char *from" "const char *to" +.Sh DESCRIPTION +.Fn extattr_copy_file +copies extended attributes of namespace +.Ar namespace +from a file to another one. +.Fn extattr_copy_fd +does the same using open file descriptors, and +.Fn extattr_copy_link +does the same as +.Fn extattr_copy_file +but operates on symbolic links themselves instead of their targets. +.Pp +.Fn cpxattr , +.Fn fcpxattr , +and +.Fn lcpxattr +respectively work the same was as +.Fn extattr_copy_file , +.Fn extattr_copy_fd , +and +.Fn extattr_copy_link , +but will copy extended attributes from all namespaces accessible to the user, +silently skiping unaccessible namespaces. +.Pp +Please note that none of the extended attribute copying functions are atomic. +.Sh RETURN VALUES +If any of the calls are unsuccessful, the value \-1 is returned +and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +Extended attribute copying functions may raise errors produced by +.Xr extattr_list_file 2 +and +.Xr extattr_get_file 2 . +.Sh SEE ALSO +.Xr getextattr 1 , +.Xr extattr_get_file 2 , +.Xr extattr_namespace_to_string 3 , +.Xr extattr 9 +.Sh HISTORY +Extended attribute support was developed as part of the +.Tn TrustedBSD +Project, and introduced in +.Fx 5.0 +and +.Nx 3.0 . +It was developed to support security extensions requiring additional labels +to be associated with each file or directory. diff --git a/lib/libc/gen/extattr.3 b/lib/libc/gen/extattr_namespace_to_string.3 similarity index 93% rename from lib/libc/gen/extattr.3 rename to lib/libc/gen/extattr_namespace_to_string.3 index 3c6a97c08..6df4b11d4 100644 --- a/lib/libc/gen/extattr.3 +++ b/lib/libc/gen/extattr_namespace_to_string.3 @@ -1,6 +1,7 @@ -.\" $NetBSD: extattr.3,v 1.3 2005/01/02 18:25:09 wiz Exp $ +.\" $NetBSD: extattr_namespace_to_string.3,v 1.1 2011/12/16 12:46:00 wiz Exp $ .\" .\" Copyright (c) 2001 Dima Dorfman +.\" Copyright (c) 2011 Emmanuel Dreyfus .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -26,8 +27,8 @@ .\" .\" FreeBSD: src/lib/libc/posix1e/extattr.3,v 1.5 2002/12/12 17:25:53 ru Exp .\" -.Dd January 2, 2004 -.Dt EXTATTR 3 +.Dd December 16, 2011 +.Dt EXTATTR_NAMESPACE_TO_STRING 3 .Os .Sh NAME .Nm extattr_namespace_to_string , @@ -87,6 +88,7 @@ The requested namespace could not be identified. .Sh SEE ALSO .Xr getextattr 1 , .Xr extattr_get_file 2 , +.Xr extattr_copy_file 3 , .Xr extattr 9 .Sh HISTORY Extended attribute support was developed as part of the diff --git a/lib/libc/gen/fixunsdfsi_ieee754.c b/lib/libc/gen/fixunsdfsi_ieee754.c new file mode 100644 index 000000000..c52573ab9 --- /dev/null +++ b/lib/libc/gen/fixunsdfsi_ieee754.c @@ -0,0 +1,69 @@ +/* $NetBSD: fixunsdfsi_ieee754.c,v 1.2 2012/08/05 04:28:58 matt Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: fixunsdfsi_ieee754.c,v 1.2 2012/08/05 04:28:58 matt Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + +uint32_t __fixunsgen32(int, bool, size_t, size_t, const uint32_t *); + +uint32_t __fixunsdfsi(double); + +/* + * Convert double to (unsigned) int. All operations are done module 2^32. + */ +uint32_t +__fixunsdfsi(double x) +{ + const union ieee_double_u dblu = { .dblu_d = x }; + const uint32_t frac[(DBL_FRACBITS + 31)/32 + 1] = { + [0] = 0, + [1] = dblu.dblu_dbl.dbl_fracl, + [2] = dblu.dblu_dbl.dbl_frach, + }; + + return __fixunsgen32( + dblu.dblu_dbl.dbl_exp - DBL_EXP_BIAS, + dblu.dblu_dbl.dbl_sign != 0, + DBL_MANT_DIG, + DBL_FRACHBITS, + &frac[__arraycount(frac)-1]); +} diff --git a/lib/libc/locale/bsdctype_file.h b/lib/libc/gen/fixunsgen64_ieee754.c similarity index 54% rename from lib/libc/locale/bsdctype_file.h rename to lib/libc/gen/fixunsgen64_ieee754.c index c5effbf2f..bb3417090 100644 --- a/lib/libc/locale/bsdctype_file.h +++ b/lib/libc/gen/fixunsgen64_ieee754.c @@ -1,8 +1,12 @@ -/* $NetBSD: bsdctype_file.h,v 1.1 2010/06/13 04:14:57 tnozaki Exp $ */ +/* $NetBSD: fixunsgen64_ieee754.c,v 1.1 2011/07/09 02:30:27 matt Exp $ */ /*- - * Copyright (c)2008 Citrus Project, - * All rights reserved. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,11 +16,14 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -26,21 +33,13 @@ * SUCH DAMAGE. */ -#ifndef _BSDCTYPE_FILE_H_ -#define _BSDCTYPE_FILE_H_ - -#include "ctype_local.h" +#include -typedef struct { - char fbl_id[8]; - uint32_t fbl_rev; - uint32_t fbl_num_chars; - uint8_t fbl_ctype_tab [_CTYPE_CACHE_SIZE]; - int16_t fbl_tolower_tab[_CTYPE_CACHE_SIZE]; - int16_t fbl_toupper_tab[_CTYPE_CACHE_SIZE]; -} __packed _FileBSDCTypeLocale; +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: fixunsgen64_ieee754.c,v 1.1 2011/07/09 02:30:27 matt Exp $"); +#endif /* LIBC_SCCS and not lint */ -#define _CTYPE_ID "BSDCTYPE" -#define _CTYPE_REV 2 +#define FIXUNSNAME(n) n##64 +#define UINTXX_T uint64_t -#endif /*_BSDCTYPE_FILE_H_*/ +#include "fixunsgen_ieee754.c" diff --git a/lib/libc/gen/fixunsgen_ieee754.c b/lib/libc/gen/fixunsgen_ieee754.c new file mode 100644 index 000000000..d10fd7a79 --- /dev/null +++ b/lib/libc/gen/fixunsgen_ieee754.c @@ -0,0 +1,111 @@ +/* $NetBSD: fixunsgen_ieee754.c,v 1.3 2012/03/25 19:53:41 christos Exp $ */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#if !defined(FIXUNSNAME) && defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: fixunsgen_ieee754.c,v 1.3 2012/03/25 19:53:41 christos Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +#ifndef FIXUNSNAME +#define FIXUNSNAME(n) n##32 +#define UINTXX_T uint32_t +#endif + +__dso_hidden UINTXX_T + FIXUNSNAME(__fixunsgen)(int, bool, size_t, size_t, const uint32_t *); + +/* + * Convert double to (unsigned) int. All operations are done module 2^32. + */ +UINTXX_T +FIXUNSNAME(__fixunsgen)(int exp, bool sign, size_t mant_dig, size_t fracbits, + const uint32_t *frac) +{ + UINTXX_T tmp; + + /* + * If it's less than 1 (negative exponent), it's going to round + * to zero. If the exponent is so large that it is a multiple of + * 2^N, then x module 2^N will be 0. (we use the fact treating a + * negative value as unsigned will be greater than nonnegative value) + */ + if (__predict_false((size_t)exp >= mant_dig + sizeof(UINTXX_T)*8)) + return 0; + + /* + * This is simplier than it seems. Basically we are constructing + * fixed binary representation of the floating point number tossing + * away bits that wont be in the modulis we return. + */ + tmp = 1; + for (size_t ebits = exp;;) { + if (ebits <= fracbits) { + /* + * The current fraction has more bits than we need. + * Shift the current value over and insert the bits + * we want. We're done. + */ + tmp <<= (unsigned int)ebits; + tmp |= *frac >> (fracbits - ebits); + break; + } + if (fracbits == sizeof(tmp)*4) { + /* + * Shifts must be < sizeof(type). If it's going to be + * sizeof(type), just replace the value. + */ + tmp = *frac--; + } else { + tmp <<= (unsigned int)fracbits; + tmp |= *frac--; + } + ebits -= fracbits; + fracbits = sizeof(frac[0]) * 4; + } + + /* + * If the input was negative, make tmp negative module 2^32. + */ + if (sign) + tmp = -tmp; + + return tmp; +} diff --git a/lib/libc/gen/fixunssfsi_ieee754.c b/lib/libc/gen/fixunssfsi_ieee754.c new file mode 100644 index 000000000..5b370648e --- /dev/null +++ b/lib/libc/gen/fixunssfsi_ieee754.c @@ -0,0 +1,68 @@ +/* $NetBSD: fixunssfsi_ieee754.c,v 1.2 2012/08/05 04:28:58 matt Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: fixunssfsi_ieee754.c,v 1.2 2012/08/05 04:28:58 matt Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + +uint32_t __fixunsgen32(int, bool, size_t, size_t, const uint32_t *); + +uint32_t __fixunssfsi(float); + +/* + * Convert float to (unsigned) int. All operations are done module 2^32. + */ +uint32_t +__fixunssfsi(float x) +{ + const union ieee_single_u sngu = { .sngu_f = x }; + const uint32_t frac[(SNG_FRACBITS + 31)/32 + 1] = { + [0] = 0, + [1] = sngu.sngu_sng.sng_frac, + }; + + return __fixunsgen32( + sngu.sngu_sng.sng_exp - SNG_EXP_BIAS, + sngu.sngu_sng.sng_sign != 0, + FLT_MANT_DIG, + SNG_FRACBITS, + &frac[__arraycount(frac)-1]); +} diff --git a/lib/libc/gen/fixunstfdi_ieee754.c b/lib/libc/gen/fixunstfdi_ieee754.c new file mode 100644 index 000000000..9c906cfb9 --- /dev/null +++ b/lib/libc/gen/fixunstfdi_ieee754.c @@ -0,0 +1,72 @@ +/* $NetBSD: fixunstfdi_ieee754.c,v 1.1 2011/07/09 02:30:27 matt Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas of 3am Software Foundry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#if defined(LIBC_SCCS) && !defined(lint) +__RCSID("$NetBSD: fixunstfdi_ieee754.c,v 1.1 2011/07/09 02:30:27 matt Exp $"); +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +#if defined(__x86_64__) || defined(__i486__) +#define FIXUNS __fixunsxfdi +#else +#define FIXUNS __fixunstfdi +#endif + +uint64_t __fixunsgen64(int, bool, size_t, size_t, const uint32_t *); + +uint64_t FIXUNS(long double); + +/* + * Convert long double to uint64_t. All operations are done module 2^64. + */ +uint64_t +FIXUNS(long double x) +{ + const union ieee_ext_u extu = { .extu_ld = x }; + uint32_t frac[(EXT_FRACBITS + 31)/32 + 2]; + + frac[0] = 0; + frac[1] = 0; + + EXT_TO_ARRAY32(extu, &frac[2]); + + return __fixunsgen64( + extu.extu_ext.ext_exp - EXT_EXP_BIAS, + extu.extu_ext.ext_sign != 0, + LDBL_MANT_DIG, + EXT_FRACHBITS, + &frac[__arraycount(frac)-1]); +} diff --git a/lib/libc/locale/localeio_lc_numeric.c b/lib/libc/gen/fixunstfsi_ieee754.c similarity index 50% rename from lib/libc/locale/localeio_lc_numeric.c rename to lib/libc/gen/fixunstfsi_ieee754.c index 364589cc7..d055ce709 100644 --- a/lib/libc/locale/localeio_lc_numeric.c +++ b/lib/libc/gen/fixunstfsi_ieee754.c @@ -1,11 +1,10 @@ -/* $NetBSD: localeio_lc_numeric.c,v 1.2 2009/01/11 02:46:28 christos Exp $ */ - -/* - * Copyright (c) 2008, The NetBSD Foundation, Inc. +/* $NetBSD: fixunstfsi_ieee754.c,v 1.2 2012/08/05 04:28:58 matt Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. - * + * * This code is derived from software contributed to The NetBSD Foundation - * by Brian Ginsbach. + * by Matt Thomas of 3am Software Foundry. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,7 +14,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -30,61 +29,47 @@ */ #include + #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: localeio_lc_numeric.c,v 1.2 2009/01/11 02:46:28 christos Exp $"); +__RCSID("$NetBSD: fixunstfsi_ieee754.c,v 1.2 2012/08/05 04:28:58 matt Exp $"); #endif /* LIBC_SCCS and not lint */ -#include "reentrant.h" -#include -#include -#include -#include -#include -#include -#include -#define __SETLOCALE_SOURCE__ -#include -#include -#include -#include - -#include "setlocale_local.h" +#include +#include +#include +#include -#include "aliasname_local.h" -#include "fix_grouping.h" -#include "localeio.h" +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif -/* - * macro required by all template headers - */ -#define _PREFIX(name) __CONCAT(_localeio_LC_NUMERIC_, name) +#if defined(__x86_64__) || defined(__i486__) +#define FIXUNS __fixunsxfsi +#else +#define FIXUNS __fixunstfsi +#endif -#include "nb_lc_numeric_misc.h" -#include "nb_lc_template_decl.h" +uint32_t __fixunsgen32(int, bool, size_t, size_t, const uint32_t *); -#define NSTRINGS (sizeof(_NumericLocale)/sizeof(const char **)) +uint32_t FIXUNS(long double); -static int -_localeio_LC_NUMERIC_create_impl(const char * __restrict root, - const char * __restrict name, _NumericLocale ** __restrict pdata) +/* + * Convert long double to (unsigned) int. All operations are done module 2^32. + */ +uint32_t +FIXUNS(long double x) { - char path[PATH_MAX + 1]; - int ret; + const union ieee_ext_u extu = { .extu_ld = x }; + uint32_t frac[(EXT_FRACBITS + 31)/32 + 1]; - _DIAGASSERT(root != NULL); - _DIAGASSERT(name != NULL); - _DIAGASSERT(pdata != NULL); + frac[0] = 0; - snprintf(path, sizeof(path), - "%s/%s/LC_NUMERIC", root, name); - ret = __loadlocale(path, NSTRINGS, 0, sizeof(_NumericLocale), - (void *)pdata); - if (!ret) { - (*pdata)->grouping = - __fix_locale_grouping_str((*pdata)->grouping); - } - return ret; -} + EXT_TO_ARRAY32(extu, &frac[1]); -#include "nb_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_localeio_LC_NUMERIC_); + return __fixunsgen32( + extu.extu_ext.ext_exp - EXT_EXP_BIAS, + extu.extu_ext.ext_sign != 0, + LDBL_MANT_DIG, + EXT_FRACHBITS, + &frac[__arraycount(frac)-1]); +} diff --git a/lib/libc/gen/fmtmsg.3 b/lib/libc/gen/fmtmsg.3 index 3b3fb646c..09a27083b 100644 --- a/lib/libc/gen/fmtmsg.3 +++ b/lib/libc/gen/fmtmsg.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: fmtmsg.3,v 1.6 2008/04/30 13:10:50 martin Exp $ +.\" $NetBSD: fmtmsg.3,v 1.7 2011/04/11 05:59:11 jruoho Exp $ .\" .\" Copyright (c) 1999 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd September 10, 1999 +.Dd April 11, 2011 .Dt FMTMSG 3 .Os .Sh NAME @@ -56,7 +56,7 @@ Further information such as the origin of the message, the recoverability from the condition causing the message and where to display the message is specified in .Fa classification . -.Ss classification +.Ss Classification The .Fa classification argument consists of a major classification and several sub-classifications. @@ -65,8 +65,8 @@ With the exception of the display sub-classification, only a single identifier may be specified for each (sub-)classification. The following classifications are available: -.Bl -tag -width MessageXSourceXSub-classificationsXX -.It Major Classifications +.Bl -tag -width "XXX" +.It Em Major classifications The source of the condition. Available identifiers are: .Dv MM_HARD @@ -75,7 +75,7 @@ Available identifiers are: (software), and .Dv MM_FIRM (firmware). -.It Message Source Sub-classifications +.It Em Message source sub-classifications The type of software detecting the condition. Available identifiers are: .Dv MM_APPL @@ -84,14 +84,14 @@ Available identifiers are: (utility), and .Dv MM_OPSYS (operating system). -.It Display Sub-classifications +.It Em Display sub-classifications The displays the formatted messages is to be written to. Available identifiers are: .Dv MM_PRINT (standard error stream) and .Dv MM_CONSOLE (system console). -.It Status Sub-classifications +.It Em Status sub-classifications The capability of the calling software to recover from the condition. Available identifiers are: .Dv MM_RECOVER @@ -105,7 +105,7 @@ If no is to be supplied, .Dv MM_NULLMC must be specified. -.Ss label +.Ss Label The .Fa label argument identifies the source of the message. @@ -117,12 +117,12 @@ If no is to be supplied, .Dv MM_NULLLBL must be specified. -.Ss severity +.Ss Severity The seriousness of the condition causing the message. The following .Fa severity levels are available: -.Bl -tag -width MM_WARNINGXX +.Bl -tag -width MM_WARNING -offset indent .It Dv MM_HALT The software has encountered a severe fault and is halting. .It Dv MM_ERROR @@ -138,7 +138,7 @@ If no level is to be supplied, .Dv MM_NOSEV must be specified. -.Ss text +.Ss Text The description of the condition the software encountered. The character string is not limited to a specific size. @@ -148,7 +148,7 @@ If no is to be supplied, .Dv MM_NOTXT must be specified. -.Ss action +.Ss Action The first step to be taken to recover from the condition the software encountered; it will be preceded by the prefix .Dq TO FIX: . @@ -159,7 +159,7 @@ If no is to be supplied, .Dv MM_NOACT must be specified. -.Ss tag +.Ss Tag The on-line documentation which provides further information about the condition and the message, such as .Dq Xr fmtmsg 3 . diff --git a/lib/libc/gen/fmtmsg.c b/lib/libc/gen/fmtmsg.c index 9ca13ace3..5bd4c5f07 100644 --- a/lib/libc/gen/fmtmsg.c +++ b/lib/libc/gen/fmtmsg.c @@ -1,4 +1,4 @@ -/* $NetBSD: fmtmsg.c,v 1.4 2008/04/28 20:22:59 martin Exp $ */ +/* $NetBSD: fmtmsg.c,v 1.5 2012/03/20 16:36:05 matt Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: fmtmsg.c,v 1.4 2008/04/28 20:22:59 martin Exp $"); +__RCSID("$NetBSD: fmtmsg.c,v 1.5 2012/03/20 16:36:05 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -40,11 +40,11 @@ __RCSID("$NetBSD: fmtmsg.c,v 1.4 2008/04/28 20:22:59 martin Exp $"); #include #include -static unsigned int msgverb __P((const char *)); -static const char * severity2str __P((int)); -static int writeit __P((FILE *, unsigned int, const char *, +static unsigned int msgverb(const char *); +static const char * severity2str(int); +static int writeit(FILE *, unsigned int, const char *, const char *, const char *, const char *, - const char *)); + const char *); #define MM_VERBLABEL 0x01U #define MM_VERBSEVERITY 0x02U @@ -74,8 +74,7 @@ static const size_t nkeywords = sizeof (keywords) / sizeof (keywords[0]); * keywords. */ static unsigned int -msgverb(str) - const char *str; +msgverb(const char *str) { u_int i; unsigned int result; @@ -107,7 +106,7 @@ msgverb(str) return (result); } -static const char * const severities[] = { +static const char severities[][8] = { "", /* MM_NONE */ "HALT", "ERROR", @@ -122,8 +121,7 @@ static const size_t nseverities = sizeof (severities) / sizeof (severities[0]); * value, defaulting to NULL for an unknown value. */ static const char * -severity2str(severity) - int severity; +severity2str(int severity) { const char *result; @@ -142,14 +140,9 @@ severity2str(severity) * written, or a negative value in case of an error. */ static int -writeit(stream, which, label, sevstr, text, action, tag) - FILE *stream; - unsigned int which; - const char *label; - const char *sevstr; - const char *text; - const char *action; - const char *tag; +writeit(FILE *stream, unsigned int which, const char *label, + const char *sevstr, const char *text, const char *action, + const char *tag) { int nwritten; @@ -184,13 +177,8 @@ writeit(stream, which, label, sevstr, text, action, tag) } int -fmtmsg(classification, label, severity, text, action, tag) - long classification; - const char *label; - int severity; - const char *text; - const char *action; - const char *tag; +fmtmsg(long classification, const char *label, int severity, + const char *text, const char *action, const char *tag) { FILE *console; const char *p, *sevstr; diff --git a/lib/libc/gen/fnmatch.c b/lib/libc/gen/fnmatch.c index 556cae7bc..c944dda42 100644 --- a/lib/libc/gen/fnmatch.c +++ b/lib/libc/gen/fnmatch.c @@ -1,4 +1,4 @@ -/* $NetBSD: fnmatch.c,v 1.21 2005/12/24 21:11:16 perry Exp $ */ +/* $NetBSD: fnmatch.c,v 1.25 2012/03/25 16:31:23 christos Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94"; #else -__RCSID("$NetBSD: fnmatch.c,v 1.21 2005/12/24 21:11:16 perry Exp $"); +__RCSID("$NetBSD: fnmatch.c,v 1.25 2012/03/25 16:31:23 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -59,23 +59,59 @@ __weak_alias(fnmatch,_fnmatch) #define EOS '\0' -static const char *rangematch __P((const char *, int, int)); - static inline int foldcase(int ch, int flags) { if ((flags & FNM_CASEFOLD) != 0 && isupper(ch)) - return (tolower(ch)); - return (ch); + return tolower(ch); + return ch; } #define FOLDCASE(ch, flags) foldcase((unsigned char)(ch), (flags)) -int -fnmatch(pattern, string, flags) - const char *pattern, *string; - int flags; +static const char * +rangematch(const char *pattern, int test, int flags) +{ + int negate, ok; + char c, c2; + + _DIAGASSERT(pattern != NULL); + + /* + * A bracket expression starting with an unquoted circumflex + * character produces unspecified results (IEEE 1003.2-1992, + * 3.13.2). This implementation treats it like '!', for + * consistency with the regular expression syntax. + * J.T. Conklin (conklin@ngai.kaleida.com) + */ + if ((negate = (*pattern == '!' || *pattern == '^')) != 0) + ++pattern; + + for (ok = 0; (c = FOLDCASE(*pattern++, flags)) != ']';) { + if (c == '\\' && !(flags & FNM_NOESCAPE)) + c = FOLDCASE(*pattern++, flags); + if (c == EOS) + return NULL; + if (*pattern == '-' + && (c2 = FOLDCASE(*(pattern + 1), flags)) != EOS && + c2 != ']') { + pattern += 2; + if (c2 == '\\' && !(flags & FNM_NOESCAPE)) + c2 = FOLDCASE(*pattern++, flags); + if (c2 == EOS) + return NULL; + if (c <= test && test <= c2) + ok = 1; + } else if (c == test) + ok = 1; + } + return ok == negate ? NULL : pattern; +} + + +static int +fnmatchx(const char *pattern, const char *string, int flags, size_t recursion) { const char *stringstart; char c, test; @@ -83,21 +119,24 @@ fnmatch(pattern, string, flags) _DIAGASSERT(pattern != NULL); _DIAGASSERT(string != NULL); - for (stringstart = string;;) + if (recursion-- == 0) + return FNM_NORES; + + for (stringstart = string;;) { switch (c = FOLDCASE(*pattern++, flags)) { case EOS: if ((flags & FNM_LEADING_DIR) && *string == '/') - return (0); - return (*string == EOS ? 0 : FNM_NOMATCH); + return 0; + return *string == EOS ? 0 : FNM_NOMATCH; case '?': if (*string == EOS) - return (FNM_NOMATCH); + return FNM_NOMATCH; if (*string == '/' && (flags & FNM_PATHNAME)) - return (FNM_NOMATCH); + return FNM_NOMATCH; if (*string == '.' && (flags & FNM_PERIOD) && (string == stringstart || ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - return (FNM_NOMATCH); + return FNM_NOMATCH; ++string; break; case '*': @@ -109,96 +148,66 @@ fnmatch(pattern, string, flags) if (*string == '.' && (flags & FNM_PERIOD) && (string == stringstart || ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - return (FNM_NOMATCH); + return FNM_NOMATCH; /* Optimize for pattern with * at end or before /. */ if (c == EOS) { if (flags & FNM_PATHNAME) - return ((flags & FNM_LEADING_DIR) || + return (flags & FNM_LEADING_DIR) || strchr(string, '/') == NULL ? - 0 : FNM_NOMATCH); + 0 : FNM_NOMATCH; else - return (0); + return 0; } else if (c == '/' && flags & FNM_PATHNAME) { if ((string = strchr(string, '/')) == NULL) - return (FNM_NOMATCH); + return FNM_NOMATCH; break; } /* General case, use recursion. */ while ((test = FOLDCASE(*string, flags)) != EOS) { - if (!fnmatch(pattern, string, - flags & ~FNM_PERIOD)) - return (0); + int e; + switch ((e = fnmatchx(pattern, string, + flags & ~FNM_PERIOD, recursion))) { + case FNM_NOMATCH: + break; + default: + return e; + } if (test == '/' && flags & FNM_PATHNAME) break; ++string; } - return (FNM_NOMATCH); + return FNM_NOMATCH; case '[': if (*string == EOS) - return (FNM_NOMATCH); + return FNM_NOMATCH; if (*string == '/' && flags & FNM_PATHNAME) - return (FNM_NOMATCH); - if ((pattern = - rangematch(pattern, FOLDCASE(*string, flags), - flags)) == NULL) - return (FNM_NOMATCH); + return FNM_NOMATCH; + if ((pattern = rangematch(pattern, + FOLDCASE(*string, flags), flags)) == NULL) + return FNM_NOMATCH; ++string; break; case '\\': if (!(flags & FNM_NOESCAPE)) { if ((c = FOLDCASE(*pattern++, flags)) == EOS) { - c = '\\'; + c = '\0'; --pattern; } } /* FALLTHROUGH */ default: if (c != FOLDCASE(*string++, flags)) - return (FNM_NOMATCH); + return FNM_NOMATCH; break; } + } /* NOTREACHED */ } -static const char * -rangematch(pattern, test, flags) - const char *pattern; - int test, flags; +int +fnmatch(const char *pattern, const char *string, int flags) { - int negate, ok; - char c, c2; - - _DIAGASSERT(pattern != NULL); - - /* - * A bracket expression starting with an unquoted circumflex - * character produces unspecified results (IEEE 1003.2-1992, - * 3.13.2). This implementation treats it like '!', for - * consistency with the regular expression syntax. - * J.T. Conklin (conklin@ngai.kaleida.com) - */ - if ((negate = (*pattern == '!' || *pattern == '^')) != 0) - ++pattern; - - for (ok = 0; (c = FOLDCASE(*pattern++, flags)) != ']';) { - if (c == '\\' && !(flags & FNM_NOESCAPE)) - c = FOLDCASE(*pattern++, flags); - if (c == EOS) - return (NULL); - if (*pattern == '-' - && (c2 = FOLDCASE(*(pattern+1), flags)) != EOS && - c2 != ']') { - pattern += 2; - if (c2 == '\\' && !(flags & FNM_NOESCAPE)) - c2 = FOLDCASE(*pattern++, flags); - if (c2 == EOS) - return (NULL); - if (c <= test && test <= c2) - ok = 1; - } else if (c == test) - ok = 1; - } - return (ok == negate ? NULL : pattern); + return fnmatchx(pattern, string, flags, 64); } diff --git a/lib/libc/gen/fpgetmask.3 b/lib/libc/gen/fpgetmask.3 index 04b27ff1f..9ca8aa6b4 100644 --- a/lib/libc/gen/fpgetmask.3 +++ b/lib/libc/gen/fpgetmask.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: fpgetmask.3,v 1.10 2008/04/30 13:10:50 martin Exp $ +.\" $NetBSD: fpgetmask.3,v 1.12 2011/03/27 22:55:07 wiz Exp $ .\" .\" Copyright (c) 1999 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,14 +27,16 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd April 4, 2004 +.Dd March 26, 2011 .Dt FPGETMASK 3 .Os .Sh NAME .Nm fpgetmask , +.Nm fpgetprec , .Nm fpgetround , .Nm fpgetsticky , .Nm fpsetmask , +.Nm fpsetprec , .Nm fpsetround , .Nm fpsetsticky .Nd IEEE FP mode control @@ -42,35 +44,37 @@ .Lb libc .Sh SYNOPSIS .In ieeefp.h -.Ft fp_except +.Ft fp_except_t .Fn fpgetmask void -.Ft fp_rnd +.Ft fp_prec_t +.Fn fpgetprec void +.Ft fp_rnd_t .Fn fpgetround void -.Ft fp_except +.Ft fp_except_t .Fn fpgetsticky void -.Ft fp_except -.Fn fpsetmask fp_except\ mask -.Ft fp_rnd -.Fn fpsetround fp_rnd\ rnd_dir -.Ft fp_except -.Fn fpsetsticky fp_except\ sticky +.Ft fp_except_t +.Fn fpsetmask "fp_except_t mask" +.Ft fp_prec_t +.Fn fpsetprec "fp_prec_t prec" +.Ft fp_rnd_t +.Fn fpsetround "fp_rnd_t rnd_dir" +.Ft fp_except_t +.Fn fpsetsticky "fp_except_t sticky" .Sh DESCRIPTION -A rounding mode is one of -.Dv FP_RZ , FP_RM , FP_RN , -or -.Dv FP_RP , -for rounding towards zero, rounding -.Pq Em Minus infinity -down, rounding to -.Em nearest , -and rounding -.Pq Em Plus infinity -up. +A rounding mode +.Ft fp_rnd_t +is one of: +.Bl -column -offset indent FP_RZ +.It Dv FP_RZ Ta rounding towards Em zero +.It Dv FP_RM Ta rounding down to Pq Em Minus infinity +.It Dv FP_RN Ta rounding to Em nearest +.It Dv FP_RP Ta rounding down to Pq Em Plus infinity +.El The default mode is .Dv FP_RN . .Pp An -.Ft fp_except +.Ft fp_except_t value is a bitmask specifying an exception type and containing any of the values listed below. .Bl -column -offset indent FP_X_UFLxx @@ -82,6 +86,16 @@ the values listed below. .It Dv FP_X_IOV Ta Integer\ Overflow .El .Pp +An +.Ft fp_prec_t +specifies the precision of the floating point operations listed below. +.Bl -column -offset indent FP_RPS +.It Dv FP_PS Ta Dv 24 bit (single-precision) +.It Dv FP_PRS Ta reserved +.It Dv FP_PD Ta Dv 53 bit (double-precision) +.It Dv FP_PE Ta Dv 64 bit (extended-precision) +.El +.Pp The .Fn fpsetmask function will set the current exception mask, i.e., it will cause @@ -93,6 +107,14 @@ The function will return the current exception mask. .Pp The +.Fn fpgetprec +function will return the current floating point precision. +The +.Fn fpsetprec +function will set the floating point precision and will return +the previous precision. +.Pp +The .Fn fpsetround function will cause future operations to use the specified dynamic rounding mode. @@ -137,4 +159,14 @@ functions return the .Pq previous exception mask and exception history bits. .Sh SEE ALSO -.Xr sigaction 2 +.Xr sigaction 2 , +.Xr fenv 3 +.Sh BUGS +There is no way to return an unsupported value. +Not all processors support all the modes. +These interfaces are deprecated and the ones +in +.Xr fenv 3 +should be used, although the interfaces in +.Xr fenv 3 +don't support getting or setting the precision. diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c index bd8305e59..908055561 100644 --- a/lib/libc/gen/fstab.c +++ b/lib/libc/gen/fstab.c @@ -1,4 +1,4 @@ -/* $NetBSD: fstab.c,v 1.28 2006/08/12 23:49:54 christos Exp $ */ +/* $NetBSD: fstab.c,v 1.31 2012/03/13 21:13:34 christos Exp $ */ /* * Copyright (c) 1980, 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)fstab.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fstab.c,v 1.28 2006/08/12 23:49:54 christos Exp $"); +__RCSID("$NetBSD: fstab.c,v 1.31 2012/03/13 21:13:34 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -63,8 +63,6 @@ static size_t _fs_lineno = 0; static const char *_fs_file = _PATH_FSTAB; static struct fstab _fs_fstab; -static int fstabscan __P((void)); - static char *nextfld(char **, const char *); static int fstabscan(void); @@ -98,7 +96,7 @@ fstabscan(void) (void)memset(&_fs_fstab, 0, sizeof(_fs_fstab)); for (;;) { - if (!(lp = fgets(line, sizeof(line), _fs_fp))) + if (!(lp = fgets(line, (int)sizeof(line), _fs_fp))) return 0; _fs_lineno++; /* OLD_STYLE_FSTAB */ @@ -216,7 +214,7 @@ setfsent(void) rewind(_fs_fp); return 1; } - if ((_fs_fp = fopen(_PATH_FSTAB, "r")) == NULL) { + if ((_fs_fp = fopen(_PATH_FSTAB, "re")) == NULL) { warn("Cannot open `%s'", _PATH_FSTAB); return 0; } diff --git a/lib/libc/gen/ftok.c b/lib/libc/gen/ftok.c index d50acc63c..b50c3d486 100644 --- a/lib/libc/gen/ftok.c +++ b/lib/libc/gen/ftok.c @@ -1,4 +1,4 @@ -/* $NetBSD: ftok.c,v 1.10 2004/09/15 19:45:17 hubertf Exp $ */ +/* $NetBSD: ftok.c,v 1.11 2012/03/20 16:36:05 matt Exp $ */ /* * Copyright (c) 1994 SigmaSoft, Th. Lockert @@ -27,7 +27,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: ftok.c,v 1.10 2004/09/15 19:45:17 hubertf Exp $"); +__RCSID("$NetBSD: ftok.c,v 1.11 2012/03/20 16:36:05 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -43,9 +43,7 @@ __weak_alias(ftok,_ftok) #endif key_t -ftok(path, id) - const char *path; - int id; +ftok(const char *path, int id) { struct stat st; diff --git a/lib/libc/gen/fts.3 b/lib/libc/gen/fts.3 index 596c0654d..9d7e0b7ec 100644 --- a/lib/libc/gen/fts.3 +++ b/lib/libc/gen/fts.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: fts.3,v 1.29 2010/04/29 17:39:03 jruoho Exp $ +.\" $NetBSD: fts.3,v 1.30 2011/03/30 16:29:26 jruoho Exp $ .\" .\" Copyright (c) 1989, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)fts.3 8.5 (Berkeley) 4/16/94 .\" -.Dd April 29, 2010 +.Dd March 30, 2011 .Dt FTS 3 .Os .Sh NAME @@ -115,7 +115,7 @@ The .Fa FTSENT structure contains at least the following fields, which are described in greater detail below: -.Bd -literal +.Bd -literal -offset 2n typedef struct _ftsent { u_short fts_info; /* flags for FTSENT structure */ char *fts_accpath; /* access path */ @@ -369,7 +369,7 @@ must be specified. The options are selected by .Em or Ns 'ing the following values: -.Bl -tag -width "FTS_PHYSICAL" +.Bl -tag -width "FTS_COMFOLLOW " .It Dv FTS_COMFOLLOW This option causes any symbolic link specified as a root path to be followed immediately whether or not @@ -618,7 +618,7 @@ on the same file hierarchy stream. .Pp .Em Option may be set to the following value: -.Bl -tag -width FTS_NAMEONLY +.Bl -tag -width "FTS_COMFOLLOW " .It Dv FTS_NAMEONLY Only the names of the files are needed. The contents of all the fields in the returned linked list of structures @@ -642,7 +642,7 @@ function returns 0 on success, and \-1 if an error occurs. .Em Option must be set to one of the following values: -.Bl -tag -width FTS_PHYSICAL +.Bl -tag -width "FTS_COMFOLLOW " .It Dv FTS_AGAIN Re-visit the file; any file type may be re-visited. The next call to diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index dadc9c2e4..bcf005b1f 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -1,4 +1,4 @@ -/* $NetBSD: fts.c,v 1.40 2009/11/02 17:17:34 stacktic Exp $ */ +/* $NetBSD: fts.c,v 1.46 2012/09/26 15:33:43 msaitoh Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; #else -__RCSID("$NetBSD: fts.c,v 1.40 2009/11/02 17:17:34 stacktic Exp $"); +__RCSID("$NetBSD: fts.c,v 1.46 2012/09/26 15:33:43 msaitoh Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -81,6 +81,23 @@ static int fts_safe_changedir(const FTS *, const FTSENT *, int, #undef FTS_ALLOC_ALIGNED #endif +#ifndef ftsent_namelen_truncate +#define ftsent_namelen_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif +#ifndef ftsent_pathlen_truncate +#define ftsent_pathlen_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif +#ifndef fts_pathlen_truncate +#define fts_pathlen_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif +#ifndef fts_nitems_truncate +#define fts_nitems_truncate(a) \ + ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) +#endif + #define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) #define CLR(opt) (sp->fts_options &= ~(opt)) @@ -118,7 +135,7 @@ fts_open(char * const *argv, int options, } /* Allocate/initialize the stream */ - if ((sp = malloc((unsigned int)sizeof(FTS))) == NULL) + if ((sp = malloc(sizeof(FTS))) == NULL) return (NULL); memset(sp, 0, sizeof(FTS)); sp->fts_compar = compar; @@ -190,19 +207,18 @@ fts_open(char * const *argv, int options, sp->fts_cur->fts_info = FTS_INIT; /* - * If using chdir(2), grab a file descriptor pointing to dot to insure + * If using chdir(2), grab a file descriptor pointing to dot to ensure * that we can get back here; this could be avoided for some paths, * but almost certainly not worth the effort. Slashes, symbolic links, * and ".." are all fairly nasty problems. Note, if we can't get the * descriptor we run anyway, just more slowly. */ +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif if (!ISSET(FTS_NOCHDIR)) { - if ((sp->fts_rfd = open(".", O_RDONLY, 0)) == -1) + if ((sp->fts_rfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) SET(FTS_NOCHDIR); - else if (fcntl(sp->fts_rfd, F_SETFD, FD_CLOEXEC) == -1) { - close(sp->fts_rfd); - SET(FTS_NOCHDIR); - } } if (nitems == 0) @@ -238,7 +254,7 @@ fts_load(FTS *sp, FTSENT *p) if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { len = strlen(++cp); memmove(p->fts_name, cp, len + 1); - p->fts_namelen = len; + p->fts_namelen = ftsent_namelen_truncate(len); } p->fts_accpath = p->fts_path = sp->fts_path; sp->fts_dev = p->fts_dev; @@ -354,13 +370,10 @@ fts_read(FTS *sp) (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { p->fts_info = fts_stat(sp, p, 1); if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { - if ((p->fts_symfd = open(".", O_RDONLY, 0)) == -1) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else if (fcntl(p->fts_symfd, F_SETFD, FD_CLOEXEC) == -1) { + if ((p->fts_symfd = open(".", O_RDONLY | O_CLOEXEC, 0)) + == -1) { p->fts_errno = errno; p->fts_info = FTS_ERR; - close(p->fts_symfd); } else p->fts_flags |= FTS_SYMFOLLOW; } @@ -448,13 +461,9 @@ next: tmp = p; p->fts_info = fts_stat(sp, p, 1); if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { if ((p->fts_symfd = - open(".", O_RDONLY, 0)) == -1) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else if (fcntl(p->fts_symfd, F_SETFD, FD_CLOEXEC) == -1) { + open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) { p->fts_errno = errno; p->fts_info = FTS_ERR; - close(p->fts_symfd); } else p->fts_flags |= FTS_SYMFOLLOW; } @@ -481,7 +490,7 @@ name: t = sp->fts_path + NAPPEND(p->fts_parent); return (sp->fts_cur = NULL); } - /* Nul terminate the pathname. */ + /* NUL terminate the pathname. */ sp->fts_path[p->fts_pathlen] = '\0'; /* @@ -800,7 +809,7 @@ mem1: saved_errno = errno; } #endif p->fts_level = level; - p->fts_pathlen = len + dnamlen; + p->fts_pathlen = ftsent_pathlen_truncate(len + dnamlen); p->fts_parent = sp->fts_cur; #ifdef FTS_WHITEOUT @@ -1004,7 +1013,7 @@ fts_sort(FTS *sp, FTSENT *head, size_t nitems) if (new == 0) return (head); sp->fts_array = new; - sp->fts_nitems = nitems + 40; + sp->fts_nitems = fts_nitems_truncate(nitems + 40); } for (ap = sp->fts_array, p = head; p; p = p->fts_link) *ap++ = p; @@ -1062,7 +1071,7 @@ fts_alloc(FTS *sp, const char *name, size_t namelen) /* Copy the name plus the trailing NULL. */ memmove(p->fts_name, name, namelen + 1); - p->fts_namelen = namelen; + p->fts_namelen = ftsent_namelen_truncate(namelen); p->fts_path = sp->fts_path; p->fts_errno = 0; p->fts_flags = 0; @@ -1141,7 +1150,7 @@ fts_palloc(FTS *sp, size_t size) if (new == 0) return (1); sp->fts_path = new; - sp->fts_pathlen = size; + sp->fts_pathlen = fts_pathlen_truncate(size); return (0); } diff --git a/lib/libc/gen/getbsize.c b/lib/libc/gen/getbsize.c index c5e4c33cc..a9ce2c14e 100644 --- a/lib/libc/gen/getbsize.c +++ b/lib/libc/gen/getbsize.c @@ -1,4 +1,4 @@ -/* $NetBSD: getbsize.c,v 1.16 2005/11/29 03:11:59 christos Exp $ */ +/* $NetBSD: getbsize.c,v 1.17 2012/06/25 22:32:43 abs Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getbsize.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getbsize.c,v 1.16 2005/11/29 03:11:59 christos Exp $"); +__RCSID("$NetBSD: getbsize.c,v 1.17 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* not lint */ @@ -51,9 +51,7 @@ __weak_alias(getbsize,_getbsize) #endif char * -getbsize(headerlenp, blocksizep) - int *headerlenp; - long *blocksizep; +getbsize(int *headerlenp, long *blocksizep) { static char header[20]; long n, max, mul, blocksize; diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index f17873e59..4d1762140 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -1,4 +1,4 @@ -/* $NetBSD: getcap.c,v 1.48 2008/02/02 20:56:46 christos Exp $ */ +/* $NetBSD: getcap.c,v 1.52 2012/06/04 20:56:40 joerg Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; #else -__RCSID("$NetBSD: getcap.c,v 1.48 2008/02/02 20:56:46 christos Exp $"); +__RCSID("$NetBSD: getcap.c,v 1.52 2012/06/04 20:56:40 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,6 +52,7 @@ __RCSID("$NetBSD: getcap.c,v 1.48 2008/02/02 20:56:46 christos Exp $"); #include #include +#include #include #ifndef SMALL #include @@ -64,7 +65,7 @@ __RCSID("$NetBSD: getcap.c,v 1.48 2008/02/02 20:56:46 christos Exp $"); #include #include -#ifdef __weak_alias +#if defined(__weak_alias) && !defined(SMALL) __weak_alias(cgetcap,_cgetcap) __weak_alias(cgetclose,_cgetclose) __weak_alias(cgetent,_cgetent) @@ -159,10 +160,7 @@ cgetset(const char *ent) * return NULL. */ char * -cgetcap(buf, cap, type) - char *buf; - const char *cap; - int type; +cgetcap(char *buf, const char *cap, int type) { char *bp; const char *cp; @@ -393,7 +391,7 @@ getent(char **cap, size_t *len, const char * const *db_array, int fd, rp = record; for (;;) { if (bp >= b_end) { - int n; + ssize_t n; n = read(fd, buf, sizeof(buf)); if (n <= 0) { @@ -456,7 +454,7 @@ getent(char **cap, size_t *len, const char * const *db_array, int fd, * some more. */ if (rp >= r_end) { - u_int pos; + ptrdiff_t pos; size_t newsize; pos = rp - record; @@ -518,7 +516,8 @@ tc_exp: if (expandtc) { char *newicap, *s; size_t ilen, newilen; - int diff, iret, tclen; + int iret; + ptrdiff_t diff, tclen; char *icap, *scan, *tc, *tcstart, *tcend; /* @@ -597,7 +596,7 @@ tc_exp: */ diff = newilen - tclen; if (diff >= r_end - rp) { - u_int pos, tcpos, tcposend; + ptrdiff_t pos, tcpos, tcposend; size_t newsize; pos = rp - record; @@ -789,7 +788,7 @@ cgetnext(char **bp, const char * const *db_array) if (dbp == NULL) dbp = db_array; - if (pfp == NULL && (pfp = fopen(*dbp, "r")) == NULL) { + if (pfp == NULL && (pfp = fopen(*dbp, "re")) == NULL) { (void)cgetclose(); return -1; } @@ -812,7 +811,7 @@ cgetnext(char **bp, const char * const *db_array) (void)cgetclose(); return 0; } else if ((pfp = - fopen(*dbp, "r")) == NULL) { + fopen(*dbp, "re")) == NULL) { (void)cgetclose(); return -1; } else @@ -917,7 +916,7 @@ cgetstr(char *buf, const char *cap, char **str) u_int m_room; const char *bp; char *mp; - int len; + ptrdiff_t len; char *mem, *newmem; _DIAGASSERT(buf != NULL); @@ -1033,7 +1032,8 @@ cgetstr(char *buf, const char *cap, char **str) mem = newmem; } *str = mem; - return len; + _DIAGASSERT(__type_fit(int, len)); + return (int)len; } /* @@ -1052,7 +1052,7 @@ cgetustr(char *buf, const char *cap, char **str) u_int m_room; const char *bp; char *mp; - int len; + size_t len; char *mem, *newmem; _DIAGASSERT(buf != NULL); @@ -1117,7 +1117,8 @@ cgetustr(char *buf, const char *cap, char **str) mem = newmem; } *str = mem; - return len; + _DIAGASSERT(__type_fit(int, len)); + return (int)len; } /* diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c index 75a8bb6a1..a0763a6e0 100644 --- a/lib/libc/gen/getcwd.c +++ b/lib/libc/gen/getcwd.c @@ -1,4 +1,4 @@ -/* $NetBSD: getcwd.c,v 1.47 2011/01/20 02:57:00 christos Exp $ */ +/* $NetBSD: getcwd.c,v 1.53 2012/06/21 23:29:23 enami Exp $ */ /* * Copyright (c) 1989, 1991, 1993, 1995 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)getcwd.c 8.5 (Berkeley) 2/7/95"; #else -__RCSID("$NetBSD: getcwd.c,v 1.47 2011/01/20 02:57:00 christos Exp $"); +__RCSID("$NetBSD: getcwd.c,v 1.53 2012/06/21 23:29:23 enami Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,42 +50,32 @@ __RCSID("$NetBSD: getcwd.c,v 1.47 2011/01/20 02:57:00 christos Exp $"); #include #include #include +#include #include "extern.h" #ifdef __weak_alias -#ifdef __minix __weak_alias(getcwd,_getcwd) -#else -__weak_alias(getcwd,_sys_getcwd) -__weak_alias(_getcwd,_sys_getcwd) -#endif +__weak_alias(_sys_getcwd,_getcwd) __weak_alias(realpath,_realpath) - -#if defined(_FORTIFY_SOURCE) && !defined(__lint__) -#undef getcwd -#define getcwd _sys_getcwd -#endif - #endif /* - * char *realpath(const char *path, char resolved[MAXPATHLEN]); + * char *realpath(const char *path, char *resolved); * * Find the real name of path, by removing all ".", ".." and symlink * components. Returns (resolved) on success, or (NULL) on failure, * in which case the path which caused trouble is left in (resolved). */ char * -realpath(const char *path, char *resolved) +realpath(const char * __restrict path, char * __restrict resolved) { struct stat sb; - int idx = 0, n, nlnk = 0; + int idx = 0, nlnk = 0; const char *q; - char *p, wbuf[2][MAXPATHLEN]; + char *p, wbuf[2][MAXPATHLEN], *fres; size_t len; - - _DIAGASSERT(resolved != NULL); + ssize_t n; /* POSIX sez we must test for this */ if (path == NULL) { @@ -93,6 +83,14 @@ realpath(const char *path, char *resolved) return NULL; } + if (resolved == NULL) { + fres = resolved = malloc(MAXPATHLEN); + if (resolved == NULL) + return NULL; + } else + fres = NULL; + + /* * Build real path one by one with paying an attention to ., * .. and symbolic link. @@ -104,10 +102,10 @@ realpath(const char *path, char *resolved) */ p = resolved; - if (*path == 0) { - *p = 0; + if (*path == '\0') { + *p = '\0'; errno = ENOENT; - return (NULL); + goto out; } /* If relative path, start from current working directory. */ @@ -115,8 +113,8 @@ realpath(const char *path, char *resolved) /* check for resolved pointer to appease coverity */ if (resolved && getcwd(resolved, MAXPATHLEN) == NULL) { p[0] = '.'; - p[1] = 0; - return (NULL); + p[1] = '\0'; + goto out; } len = strlen(resolved); if (len > 1) @@ -128,18 +126,18 @@ loop: while (*path == '/') path++; - if (*path == 0) { + if (*path == '\0') { if (p == resolved) *p++ = '/'; - *p = 0; - return (resolved); + *p = '\0'; + return resolved; } /* Find the end of this component. */ q = path; do q++; - while (*q != '/' && *q != 0); + while (*q != '/' && *q != '\0'); /* Test . or .. */ if (path[0] == '.') { @@ -151,7 +149,7 @@ loop: /* Trim the last component. */ if (p != resolved) while (*--p != '/') - ; + continue; path = q; goto loop; } @@ -162,39 +160,39 @@ loop: errno = ENAMETOOLONG; if (p == resolved) *p++ = '/'; - *p = 0; - return (NULL); + *p = '\0'; + goto out; } p[0] = '/'; memcpy(&p[1], path, /* LINTED We know q > path. */ q - path); - p[1 + q - path] = 0; + p[1 + q - path] = '\0'; /* * If this component is a symlink, toss it and prepend link * target to unresolved path. */ - if (lstat(resolved, &sb) == -1) { - return (NULL); - } + if (lstat(resolved, &sb) == -1) + goto out; + if (S_ISLNK(sb.st_mode)) { if (nlnk++ >= MAXSYMLINKS) { errno = ELOOP; - return (NULL); + goto out; } n = readlink(resolved, wbuf[idx], sizeof(wbuf[0]) - 1); if (n < 0) - return (NULL); + goto out; if (n == 0) { errno = ENOENT; - return (NULL); + goto out; } /* Append unresolved path to link target and switch to it. */ if (n + (len = strlen(q)) + 1 > sizeof(wbuf[0])) { errno = ENAMETOOLONG; - return (NULL); + goto out; } memcpy(&wbuf[idx][n], q, len + 1); path = wbuf[idx]; @@ -207,17 +205,20 @@ loop: } if (*q == '/' && !S_ISDIR(sb.st_mode)) { errno = ENOTDIR; - return (NULL); + goto out; } /* Advance both resolved and unresolved path. */ p += 1 + q - path; path = q; goto loop; +out: + free(fres); + return NULL; } char * -getcwd(char *pt, size_t size) +__ssp_real(getcwd)(char *pt, size_t size) { char *npt; diff --git a/lib/libc/gen/getdevmajor.c b/lib/libc/gen/getdevmajor.c index b946694ff..95cb7ca00 100644 --- a/lib/libc/gen/getdevmajor.c +++ b/lib/libc/gen/getdevmajor.c @@ -1,4 +1,4 @@ -/* $NetBSD: getdevmajor.c,v 1.5 2009/01/20 20:08:12 drochner Exp $ */ +/* $NetBSD: getdevmajor.c,v 1.6 2012/03/13 21:13:35 christos Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getdevmajor.c,v 1.5 2009/01/20 20:08:12 drochner Exp $"); +__RCSID("$NetBSD: getdevmajor.c,v 1.6 2012/03/13 21:13:35 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -67,8 +67,8 @@ devmajor_t getdevmajor(const char *name, mode_t type) { struct kinfo_drivers kd[200], *kdp = &kd[0]; - int rc, i; - size_t sz = sizeof(kd); + size_t i, sz = sizeof(kd); + int rc; devmajor_t n = NODEVMAJOR; if (type != S_IFCHR && type != S_IFBLK) { @@ -88,9 +88,9 @@ getdevmajor(const char *name, mode_t type) } } while (rc == -1); - rc = sz / sizeof(*kdp); + sz /= sizeof(*kdp); - for (i = 0; i < rc; i++) { + for (i = 0; i < sz; i++) { if (strcmp(name, kdp[i].d_name) == 0) { if (type == S_IFCHR) n = kdp[i].d_cmajor; @@ -99,7 +99,7 @@ getdevmajor(const char *name, mode_t type) break; } } - if (i >= rc) + if (i >= sz) errno = ENOENT; out: diff --git a/lib/libc/gen/getdomainname.c b/lib/libc/gen/getdomainname.c index 0832218f9..cd58c7788 100644 --- a/lib/libc/gen/getdomainname.c +++ b/lib/libc/gen/getdomainname.c @@ -1,4 +1,4 @@ -/* $NetBSD: getdomainname.c,v 1.12 2003/08/07 16:42:49 agc Exp $ */ +/* $NetBSD: getdomainname.c,v 1.13 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)gethostname.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getdomainname.c,v 1.12 2003/08/07 16:42:49 agc Exp $"); +__RCSID("$NetBSD: getdomainname.c,v 1.13 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,9 +51,7 @@ __weak_alias(getdomainname,_getdomainname) #endif int -getdomainname(name, namelen) - char *name; - size_t namelen; +getdomainname(char *name, size_t namelen) { int mib[2]; size_t size; diff --git a/lib/libc/gen/getfsent.3 b/lib/libc/gen/getfsent.3 index 685a6c754..abfecfefd 100644 --- a/lib/libc/gen/getfsent.3 +++ b/lib/libc/gen/getfsent.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getfsent.3,v 1.11 2010/03/22 19:30:53 joerg Exp $ +.\" $NetBSD: getfsent.3,v 1.12 2012/04/07 03:47:30 christos Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getfsent.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 4, 1993 +.Dd March 6, 2012 .Dt GETFSENT 3 .Os .Sh NAME @@ -128,6 +128,7 @@ returns nothing. .It Pa /etc/fstab .El .Sh SEE ALSO +.Xr getfsspecname 3 , .Xr fstab 5 .Sh HISTORY The diff --git a/lib/libc/gen/getgrent.3 b/lib/libc/gen/getgrent.3 index 2dea4e351..9e89befe2 100644 --- a/lib/libc/gen/getgrent.3 +++ b/lib/libc/gen/getgrent.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getgrent.3,v 1.30 2010/03/22 19:30:53 joerg Exp $ +.\" $NetBSD: getgrent.3,v 1.31 2011/04/28 16:34:01 wiz Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -216,9 +216,19 @@ The and .Fn setgrent functions have no return value. +.Sh FILES +.Bl -tag -width /etc/group -compact +.It Pa /etc/group +group database file +.El +.Sh COMPATIBILITY +The historic function +.Fn setgrfile , +which allowed the specification of alternative group databases, has +been deprecated and is no longer available. .Sh ERRORS The following error codes may be set in -.Va errno +.Va errno for .Nm getgrent , .Nm getgrent_r , @@ -229,10 +239,10 @@ for and .Nm setgroupent : .Bl -tag -width Er -.It Bq Er EIO -An I/O error has occurred. .It Bq Er EINTR A signal was caught during the database search. +.It Bq Er EIO +An I/O error has occurred. .It Bq Er EMFILE The limit on open files for this process has been reached. .It Bq Er ENFILE @@ -240,7 +250,7 @@ The system limit on open files has been reached. .El .Pp The following error code may be set in -.Va errno +.Va errno for .Nm getgrent_r , .Nm getgrnam_r , @@ -259,11 +269,6 @@ and Other .Dv errno values may be set depending on the specific database backends. -.Sh FILES -.Bl -tag -width /etc/group -compact -.It Pa /etc/group -group database file -.El .Sh SEE ALSO .Xr getpwent 3 , .Xr group 5 , @@ -313,11 +318,6 @@ and .Fn getgrnam_r appeared in .Nx 3.0 . -.Sh COMPATIBILITY -The historic function -.Fn setgrfile , -which allowed the specification of alternative group databases, has -been deprecated and is no longer available. .Sh BUGS The functions .Fn getgrent , diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 9e2b6957f..783446528 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -1,4 +1,4 @@ -/* $NetBSD: getgrent.c,v 1.62 2008/04/28 20:22:59 martin Exp $ */ +/* $NetBSD: getgrent.c,v 1.67 2012/08/29 18:50:35 dholland Exp $ */ /*- * Copyright (c) 1999-2000, 2004-2005 The NetBSD Foundation, Inc. @@ -88,7 +88,7 @@ #if 0 static char sccsid[] = "@(#)getgrent.c 8.2 (Berkeley) 3/21/94"; #else -__RCSID("$NetBSD: getgrent.c,v 1.62 2008/04/28 20:22:59 martin Exp $"); +__RCSID("$NetBSD: getgrent.c,v 1.67 2012/08/29 18:50:35 dholland Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -221,9 +221,9 @@ _gr_parse(const char *entry, struct group *grp, char *buf, size_t buflen) } /* grab ALIGNed char **gr_mem from buf */ ep = _gr_memfrombuf(memc * sizeof(char *) + ALIGNBYTES, &buf, &buflen); - grp->gr_mem = (char **)ALIGN(ep); - if (grp->gr_mem == NULL) + if (ep == NULL) return 0; + grp->gr_mem = (char **)ALIGN(ep); for (memc = 0; *entry != '\0'; memc++) { count = strcspn(entry, ","); /* parse member */ @@ -270,6 +270,9 @@ _gr_copy(struct group *fromgrp, struct group *grp, char *buf, size_t buflen) COPYSTR(grp->gr_passwd, fromgrp->gr_passwd); grp->gr_gid = fromgrp->gr_gid; + if (fromgrp->gr_mem == NULL) + return 0; + for (memc = 0; fromgrp->gr_mem[memc]; memc++) continue; memc++; /* for final NULL */ @@ -301,7 +304,7 @@ __grstart_files(struct __grstate_files *state) _DIAGASSERT(state != NULL); if (state->fp == NULL) { - state->fp = fopen(_PATH_GROUP, "r"); + state->fp = fopen(_PATH_GROUP, "re"); if (state->fp == NULL) return NS_UNAVAIL; } else { @@ -356,7 +359,7 @@ __grscan_files(int *retval, struct group *grp, char *buffer, size_t buflen, rv = NS_NOTFOUND; /* scan line by line */ - while (fgets(filebuf, sizeof(filebuf), state->fp) != NULL) { + while (fgets(filebuf, (int)sizeof(filebuf), state->fp) != NULL) { ep = strchr(filebuf, '\n'); if (ep == NULL) { /* skip lines that are too big */ int ch; @@ -1187,9 +1190,17 @@ _nis_getgrgid_r(void *nsrv, void *nscb, va_list ap) _DIAGASSERT(result != NULL); *result = NULL; - memset(&state, 0, sizeof(state)); - rv = __grscan_nis(retval, grp, buffer, buflen, &state, 1, NULL, gid); - __grend_nis(&state); +/* remark: we run under a global mutex inside of this module ... */ + if (_nis_state.stayopen) + { /* use global state only if stayopen is set - otherwiese we would blow up getgrent_r() ... */ + rv = __grscan_nis(retval, grp, buffer, buflen, &_nis_state, 1, NULL, gid); + } + else + { + memset(&state, 0, sizeof(state)); + rv = __grscan_nis(retval, grp, buffer, buflen, &state, 1, NULL, gid); + __grend_nis(&state); + } if (rv == NS_SUCCESS) *result = grp; return rv; @@ -1239,9 +1250,17 @@ _nis_getgrnam_r(void *nsrv, void *nscb, va_list ap) _DIAGASSERT(result != NULL); *result = NULL; - memset(&state, 0, sizeof(state)); - rv = __grscan_nis(retval, grp, buffer, buflen, &state, 1, name, 0); - __grend_nis(&state); +/* remark: we run under a global mutex inside of this module ... */ + if (_nis_state.stayopen) + { /* use global state only if stayopen is set - otherwiese we would blow up getgrent_r() ... */ + rv = __grscan_nis(retval, grp, buffer, buflen, &_nis_state, 1, name, 0); + } + else + { + memset(&state, 0, sizeof(state)); + rv = __grscan_nis(retval, grp, buffer, buflen, &state, 1, name, 0); + __grend_nis(&state); + } if (rv == NS_SUCCESS) *result = grp; return rv; @@ -1262,7 +1281,7 @@ __grstart_compat(struct __grstate_compat *state) _DIAGASSERT(state != NULL); if (state->fp == NULL) { - state->fp = fopen(_PATH_GROUP, "r"); + state->fp = fopen(_PATH_GROUP, "re"); if (state->fp == NULL) return NS_UNAVAIL; } else { @@ -1424,7 +1443,7 @@ __grscan_compat(int *retval, struct group *grp, char *buffer, size_t buflen, } /* get next file line */ - if (fgets(filebuf, sizeof(filebuf), state->fp) == NULL) + if (fgets(filebuf, (int)sizeof(filebuf), state->fp) == NULL) break; ep = strchr(filebuf, '\n'); diff --git a/lib/libc/gen/gethostname.c b/lib/libc/gen/gethostname.c index eba55d1ca..8d1eed6ca 100644 --- a/lib/libc/gen/gethostname.c +++ b/lib/libc/gen/gethostname.c @@ -1,4 +1,4 @@ -/* $NetBSD: gethostname.c,v 1.12 2005/10/14 23:53:41 christos Exp $ */ +/* $NetBSD: gethostname.c,v 1.13 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)gethostname.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: gethostname.c,v 1.12 2005/10/14 23:53:41 christos Exp $"); +__RCSID("$NetBSD: gethostname.c,v 1.13 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,9 +51,7 @@ __weak_alias(gethostname,_gethostname) #endif int -gethostname(name, namelen) - char *name; - size_t namelen; +gethostname(char *name, size_t namelen) { int mib[2]; size_t size; diff --git a/lib/libc/gen/getloadavg.3 b/lib/libc/gen/getloadavg.3 index 954992a97..7f879b00a 100644 --- a/lib/libc/gen/getloadavg.3 +++ b/lib/libc/gen/getloadavg.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getloadavg.3,v 1.14 2003/08/07 16:42:50 agc Exp $ +.\" $NetBSD: getloadavg.3,v 1.15 2011/04/12 04:55:05 jruoho Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getloadavg.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 4, 1993 +.Dd April 12, 2011 .Dt GETLOADAVG 3 .Os .Sh NAME @@ -52,7 +52,7 @@ samples are retrieved and assigned to successive elements of .Fa loadavg Ns Bq . The system imposes a maximum of 3 samples, representing averages over the last 1, 5, and 15 minutes, respectively. -.Sh DIAGNOSTICS +.Sh RETURN VALUES If the load average was unobtainable, \-1 is returned; otherwise, the number of samples actually retrieved is returned. .Sh SEE ALSO diff --git a/lib/libc/gen/getloadavg.c b/lib/libc/gen/getloadavg.c index 870bb3139..f548c42d9 100644 --- a/lib/libc/gen/getloadavg.c +++ b/lib/libc/gen/getloadavg.c @@ -1,4 +1,4 @@ -/* $NetBSD: getloadavg.c,v 1.13 2003/08/07 16:42:50 agc Exp $ */ +/* $NetBSD: getloadavg.c,v 1.14 2012/03/13 21:13:36 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getloadavg.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getloadavg.c,v 1.13 2003/08/07 16:42:50 agc Exp $"); +__RCSID("$NetBSD: getloadavg.c,v 1.14 2012/03/13 21:13:36 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -60,25 +60,22 @@ __weak_alias(getloadavg,_getloadavg) * Return number of samples retrieved, or -1 on error. */ int -getloadavg(loadavg, nelem) - double loadavg[]; - int nelem; +getloadavg(double loadavg[], int nelem) { struct loadavg loadinfo; - int i, mib[2]; - size_t size; + static const int mib[] = { CTL_VM, VM_LOADAVG }; + size_t size, i; _DIAGASSERT(loadavg != NULL); _DIAGASSERT(nelem >= 0); - mib[0] = CTL_VM; - mib[1] = VM_LOADAVG; size = sizeof(loadinfo); - if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) < 0) - return (-1); + if (sysctl(mib, (u_int)__arraycount(mib), &loadinfo, &size, NULL, 0) + == -1) + return -1; - nelem = MIN((size_t) nelem, sizeof(loadinfo.ldavg) / sizeof(fixpt_t)); - for (i = 0; i < nelem; i++) + size = MIN((size_t)nelem, __arraycount(loadinfo.ldavg)); + for (i = 0; i < size; i++) loadavg[i] = (double) loadinfo.ldavg[i] / loadinfo.fscale; - return (nelem); + return nelem; } diff --git a/lib/libc/gen/getmntinfo.c b/lib/libc/gen/getmntinfo.c index 62eca752b..a8615c6a7 100644 --- a/lib/libc/gen/getmntinfo.c +++ b/lib/libc/gen/getmntinfo.c @@ -1,4 +1,4 @@ -/* $NetBSD: getmntinfo.c,v 1.16 2005/09/13 01:44:09 christos Exp $ */ +/* $NetBSD: getmntinfo.c,v 1.17 2012/03/20 16:36:05 matt Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getmntinfo.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getmntinfo.c,v 1.16 2005/09/13 01:44:09 christos Exp $"); +__RCSID("$NetBSD: getmntinfo.c,v 1.17 2012/03/20 16:36:05 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,9 +51,7 @@ __RCSID("$NetBSD: getmntinfo.c,v 1.16 2005/09/13 01:44:09 christos Exp $"); * Return information about mounted filesystems. */ int -getmntinfo(mntbufp, flags) - struct statvfs **mntbufp; - int flags; +getmntinfo(struct statvfs **mntbufp, int flags) { static struct statvfs *mntbuf; static int mntsize; diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c index 80eb129f3..410ef1c7b 100644 --- a/lib/libc/gen/getnetgrent.c +++ b/lib/libc/gen/getnetgrent.c @@ -1,4 +1,4 @@ -/* $NetBSD: getnetgrent.c,v 1.41 2009/10/21 01:07:45 snj Exp $ */ +/* $NetBSD: getnetgrent.c,v 1.42 2012/03/20 16:36:05 matt Exp $ */ /* * Copyright (c) 1994 Christos Zoulas @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getnetgrent.c,v 1.41 2009/10/21 01:07:45 snj Exp $"); +__RCSID("$NetBSD: getnetgrent.c,v 1.42 2012/03/20 16:36:05 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -142,8 +142,7 @@ getstring(char **pp, int del, char __aconst **str) * getnetgroup(): Parse a netgroup, and advance the pointer */ static struct netgroup * -getnetgroup(pp) - char **pp; +getnetgroup(char **pp) { struct netgroup *ng; diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c index 515339d06..8353788e4 100644 --- a/lib/libc/gen/getpagesize.c +++ b/lib/libc/gen/getpagesize.c @@ -1,4 +1,4 @@ -/* $NetBSD: getpagesize.c,v 1.10 2009/12/14 01:04:46 matt Exp $ */ +/* $NetBSD: getpagesize.c,v 1.11 2012/06/24 15:26:03 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getpagesize.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getpagesize.c,v 1.10 2009/12/14 01:04:46 matt Exp $"); +__RCSID("$NetBSD: getpagesize.c,v 1.11 2012/06/24 15:26:03 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,7 +49,7 @@ __weak_alias(getpagesize,_getpagesize) #endif int -getpagesize() +getpagesize(void) { static int pagsz; diff --git a/lib/libc/gen/getpass.3 b/lib/libc/gen/getpass.3 index 64220f0a9..da8d19694 100644 --- a/lib/libc/gen/getpass.3 +++ b/lib/libc/gen/getpass.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getpass.3,v 1.13 2010/05/06 11:09:39 jruoho Exp $ +.\" $NetBSD: getpass.3,v 1.22 2012/04/14 10:34:29 wiz Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getpass.3 8.1 (Berkeley) 6/4/93 .\" -.Dd May 6, 2010 +.Dd April 13, 2012 .Dt GETPASS 3 .Os .Sh NAME @@ -38,10 +38,13 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In pwd.h .In unistd.h .Ft char * .Fn getpass "const char *prompt" +.Ft char * +.Fn getpass_r "const char *prompt" "char *buf" "size_t buflen" +.Ft char * +.Fn getpassfd "const char *prompt" "char *buf" "size_t buflen" "int *fd" "int flags" "int timeout" .Sh DESCRIPTION The .Fn getpass @@ -52,16 +55,105 @@ If this file is not accessible, displays the prompt on the standard error output and reads from the standard input. .Pp -The password may be up to _PASSWORD_LEN (currently 128) +The password may be up to +.Xr sysconf 3 +.Dv _SC_PASS_MAX characters in length. Any additional characters and the terminating newline character are discarded. .Pp .Fn getpass turns off character echoing while reading the password. +.Pp +.Fn getpass_r +is similar to +.Fn getpass +only it puts its result in +.Fa buf +for up to +.Fa buflen +characters. +If the +.Fa buf +argument is +.Dv NULL , +then a buffer will be dynamically allocated. +.Pp +The +.Fn getpassfd +function allows one to specify the three file descriptors corresponding to +.Dv stdin , +.Dv stdout , +and +.Dv stderr +in the +.Fa fd +argument, or if +.Fa fd +is +.Dv NULL , +.Fn getpassfd +first attempts to open +.Pa /dev/tty +and if that fails, defaults to +.Dv STDIN_FILENO +for input and +.Dv STDERR_FILENO +for output. +.Pp +The behavior of +.Fn getpassfd +is controlled by the +.Fa flags +argument: +.Bl -tag -width GETPASS_FORCE_UPPER +.It Dv GETPASS_NEED_TTY +Fail if we are unable to set the tty modes like we want. +.It Dv GETPASS_FAIL_EOF +Fail if we get the end-of-file character instead of returning the result so far. +.It Dv GETPASS_BUF_LIMIT +Beep when the buffer limit is reached, instead of silently absorbing it. +.It Dv GETPASS_NO_SIGNAL +Don't make ttychars send signals. +.It Dv GETPASS_NO_BEEP +Don't beep if we erase past the beginning of the buffer or we try to enter past +the end. +.It Dv GETPASS_ECHO_STAR +Echo a +.Sq * +for each character entered. +.It Dv GETPASS_ECHO +Echo characters as they are typed. +.It Dv GETPASS_ECHO_NL +Echoes a newline if successful. +.It Dv GETPASS_7BIT +Mask the high bit for each entered character. +.It Dv GETPASS_FORCE_LOWER +Lowercase each entered character. +.It Dv GETPASS_FORCE_UPPER +Uppercase each entered character. +.El +.Pp +Finally if the +.Fa timeout +argument is non zero, +.Fn getpassfd +will wait for +.Fa timeout +seconds for input after each character before returning an error, instead of +waiting forever. .Sh RETURN VALUES +The .Fn getpass -returns a pointer to the null terminated password. +function returns a pointer to the NUL terminated password, or an empty +string on error. +The +.Fn getpass_r +and +.Fn getpassfd +functions return a pointer to the NUL terminated password, or +.Dv NULL +on error. .Sh FILES .Bl -tag -width /dev/tty -compact .It Pa /dev/tty @@ -82,6 +174,12 @@ A .Fn getpass function appeared in .At v7 . +The +.Fn getpass_r +and +.Fn getpassfd +functions appeared in +.Nx 7.0 . .Sh BUGS The .Fn getpass @@ -94,3 +192,9 @@ will modify the same object. The calling process should zero the password as soon as possible to avoid leaving the cleartext password visible in the process's address space. +.Pp +Historically +.Nm +accepted and returned a password if it could not modify the terminal +settings to turn echo off (or if the input was not a terminal). +In this implementation, only terminal input is accepted. diff --git a/lib/libc/gen/getpass.c b/lib/libc/gen/getpass.c index ee4a8961b..8f026968c 100644 --- a/lib/libc/gen/getpass.c +++ b/lib/libc/gen/getpass.c @@ -1,8 +1,11 @@ -/* $NetBSD: getpass.c,v 1.16 2008/01/01 21:22:55 christos Exp $ */ +/* $NetBSD: getpass.c,v 1.27 2012/05/26 19:34:16 christos Exp $ */ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -12,96 +15,346 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ - #include #if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)getpass.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: getpass.c,v 1.16 2008/01/01 21:22:55 christos Exp $"); -#endif +__RCSID("$NetBSD: getpass.c,v 1.27 2012/05/26 19:34:16 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include -#include -#include -#include +#ifdef TEST #include +#endif +#include +#include +#include +#include +#include +#include +#include #include #include +#include +#include #ifdef __weak_alias +__weak_alias(getpassfd,_getpassfd) +__weak_alias(getpass_r,_getpass_r) __weak_alias(getpass,_getpass) #endif +/* + * Notes: + * - There is no getpass_r in POSIX + * - Historically EOF is documented to be treated as EOL, we provide a + * tunable for that GETPASS_FAIL_EOF to disable this. + * - Historically getpass ate extra characters silently, we provide + * a tunable for that GETPASS_BUF_LIMIT to disable this. + * - Historically getpass "worked" by echoing characters when turning + * off echo failed, we provide a tunable GETPASS_NEED_TTY to + * disable this. + * - Some implementations say that on interrupt the program shall + * receive an interrupt signal before the function returns. We + * send all the tty signals before we return, but we don't expect + * suspend to do something useful unless the caller calls us again. + * We also provide a tunable to disable signal delivery + * GETPASS_NO_SIGNAL. + * - GETPASS_NO_BEEP disables beeping. + * - GETPASS_ECHO_STAR will echo '*' for each character of the password + * - GETPASS_ECHO will echo the password (as pam likes it) + * - GETPASS_7BIT strips the 8th bit + * - GETPASS_FORCE_UPPER forces to uppercase + * - GETPASS_FORCE_LOWER forces to uppercase + * - GETPASS_ECHO_NL echo's a new line on success if echo was off. + */ char * -getpass(prompt) - const char *prompt; +/*ARGSUSED*/ +getpassfd(const char *prompt, char *buf, size_t len, int *fd, int flags, + int tout) { - struct termios term; - int ch; - char *p; - FILE *fp, *outfp; - int echo; - static char buf[_PASSWORD_LEN + 1]; - sigset_t oset, nset; + struct termios gt; + char c; + int sig; + bool lnext, havetty, allocated, opentty, good; + int fdc[3]; _DIAGASSERT(prompt != NULL); - /* - * note - blocking signals isn't necessarily the - * right thing, but we leave it for now. - */ - sigemptyset(&nset); - sigaddset(&nset, SIGINT); - sigaddset(&nset, SIGTSTP); - (void)sigprocmask(SIG_BLOCK, &nset, &oset); + if (buf != NULL && len == 0) { + errno = EINVAL; + return NULL; + } - /* - * read and write to /dev/tty if possible; else read from - * stdin and write to stderr. - */ - if ((outfp = fp = fopen(_PATH_TTY, "w+")) == NULL) { - outfp = stderr; - fp = stdin; + good = false; + opentty = false; + if (fd == NULL) { + /* + * Try to use /dev/tty if possible; otherwise read from stdin + * and write to stderr. + */ + fd = fdc; + if ((fd[0] = fd[1] = fd[2] = open(_PATH_TTY, O_RDWR)) == -1) { + fd[0] = STDIN_FILENO; + fd[1] = fd[2] = STDERR_FILENO; + } else + opentty = true; + } + + sig = 0; + allocated = buf == NULL; + if (tcgetattr(fd[0], >) == -1) { + havetty = false; + if (flags & GETPASS_NEED_TTY) + goto out; + memset(>, -1, sizeof(gt)); + } else + havetty = true; + + if (havetty) { + struct termios st = gt; + + st.c_lflag &= ~(ECHO|ECHOK|ECHOE|ECHOKE|ECHOCTL|ISIG|ICANON); + st.c_cc[VMIN] = 1; + st.c_cc[VTIME] = 0; + if (tcsetattr(fd[0], TCSAFLUSH|TCSASOFT, &st) == -1) + goto out; } - (void)tcgetattr(fileno(fp), &term); - if ((echo = (term.c_lflag & ECHO)) != 0) { - term.c_lflag &= ~ECHO; - (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); + + if (prompt != NULL) { + size_t plen = strlen(prompt); + (void)write(fd[1], prompt, plen); } - if (prompt != NULL) - (void)fputs(prompt, outfp); - rewind(outfp); /* implied flush */ - for (p = buf; (ch = getc(fp)) != EOF && ch != '\n';) - if (p < buf + _PASSWORD_LEN) - *p++ = ch; - *p = '\0'; - (void)write(fileno(outfp), "\n", 1); - if (echo) { - term.c_lflag |= ECHO; - (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); + + if (allocated) { + len = 1024; + if ((buf = malloc(len)) == NULL) + goto restore; } - if (fp != stdin) - (void)fclose(fp); - (void)sigprocmask(SIG_SETMASK, &oset, NULL); - return(buf); + + c = '\1'; + lnext = false; + for (size_t l = 0; c != '\0'; ) { + if (tout) { + struct pollfd pfd; + pfd.fd = fd[0]; + pfd.events = POLLIN|POLLRDNORM; + pfd.revents = 0; + switch (poll(&pfd, 1, tout * 1000)) { + case 0: + errno = ETIMEDOUT; + /*FALLTHROUGH*/ + case -1: + goto restore; + default: + break; + } + } + if (read(fd[0], &c, 1) != 1) + goto restore; + +#define beep() \ + do \ + if (flags & GETPASS_NO_BEEP) \ + (void)write(fd[2], "\a", 1); \ + while (/*CONSTCOND*/ 0) +#define erase() (void)write(fd[1], "\b \b", 3) +/* + * We test for both _POSIX_VDISABLE and NUL here because _POSIX_VDISABLE + * propagation does not seem to be very consistent on multiple daemon hops + * between different OS's. Perhaps we should not even bother with + * _POSIX_VDISABLE and use ~0 and 0 directly. + */ +#define C(a, b) ((gt.c_cc[(a)] == _POSIX_VDISABLE || gt.c_cc[(a)] == '\0') ? \ + (b) : gt.c_cc[(a)]) + if (lnext) { + lnext = false; + goto add; + } + + /* Ignored */ + if (c == C(VREPRINT, CTRL('r')) || c == C(VSTART, CTRL('q')) || + c == C(VSTOP, CTRL('s')) || c == C(VSTATUS, CTRL('t')) || + c == C(VDISCARD, CTRL('o'))) + continue; + + /* Literal next */ + if (c == C(VLNEXT, CTRL('v'))) { + lnext = true; + continue; + } + + /* Line or word kill, treat as reset */ + if (c == C(VKILL, CTRL('u')) || c == C(VWERASE, CTRL('w'))) { + if (flags & (GETPASS_ECHO | GETPASS_ECHO_STAR)) { + while (l--) + erase(); + } + l = 0; + continue; + } + + /* Character erase */ + if (c == C(VERASE, CTRL('h'))) { + if (l == 0) + beep(); + else { + l--; + if (flags & (GETPASS_ECHO | GETPASS_ECHO_STAR)) + erase(); + } + continue; + } + + /* tty signal characters */ + if (c == C(VINTR, CTRL('c'))) { + sig = SIGINT; + goto out; + } + if (c == C(VQUIT, CTRL('\\'))) { + sig = SIGQUIT; + goto out; + } + if (c == C(VSUSP, CTRL('z')) || c == C(VDSUSP, CTRL('y'))) { + sig = SIGTSTP; + goto out; + } + + /* EOF */ + if (c == C(VEOF, CTRL('d'))) { + if (flags & GETPASS_FAIL_EOF) { + errno = ENODATA; + goto out; + } else { + c = '\0'; + goto add; + } + } + + /* End of line */ + if (c == C(VEOL, CTRL('j')) || c == C(VEOL2, CTRL('l'))) + c = '\0'; +add: + if (l >= len) { + if (allocated) { + size_t nlen = len + 1024; + char *nbuf = realloc(buf, nlen); + if (nbuf == NULL) + goto restore; + buf = nbuf; + len = nlen; + } else { + if (flags & GETPASS_BUF_LIMIT) { + beep(); + continue; + } + if (c == '\0' && l > 0) + l--; + else + continue; + } + } + + if (flags & GETPASS_7BIT) + c &= 0x7f; + if ((flags & GETPASS_FORCE_LOWER) && isupper((unsigned char)c)) + c = tolower((unsigned char)c); + if ((flags & GETPASS_FORCE_UPPER) && islower((unsigned char)c)) + c = toupper((unsigned char)c); + + buf[l++] = c; + if (c) { + if (flags & GETPASS_ECHO_STAR) + (void)write(fd[1], "*", 1); + else if (flags & GETPASS_ECHO) + (void)write(fd[1], isprint((unsigned char)c) ? + &c : "?", 1); + } + } + good = true; + +restore: + if (havetty) { + c = errno; + (void)tcsetattr(fd[0], TCSAFLUSH|TCSASOFT, >); + errno = c; + } +out: + if (good && (flags & GETPASS_ECHO_NL)) + (void)write(fd[1], "\n", 1); + + if (opentty) { + c = errno; + (void)close(fd[0]); + errno = c; + } + + if (good) + return buf; + + if (sig) { + if ((flags & GETPASS_NO_SIGNAL) == 0) + (void)raise(sig); + errno = EINTR; + } + memset(buf, 0, len); + if (allocated) + free(buf); + return NULL; +} + +char * +getpass_r(const char *prompt, char *buf, size_t len) +{ + return getpassfd(prompt, buf, len, NULL, GETPASS_ECHO_NL, 0); } + +char * +getpass(const char *prompt) +{ + static char e[] = ""; + static char *buf; + static long bufsiz; + char *rv; + + /* + * Strictly speaking we could double allocate here, if we get + * called at the same time, but this function is not re-entrant + * anyway and it is not supposed to work if called concurrently. + */ + if (buf == NULL) { + if ((bufsiz = sysconf(_SC_PASS_MAX)) == -1) + return e; + if ((buf = malloc((size_t)bufsiz)) == NULL) + return e; + } + + if ((rv = getpass_r(prompt, buf, (size_t)bufsiz)) == NULL) + return e; + + return rv; +} + +#ifdef TEST +int +main(int argc, char *argv[]) +{ + char buf[28]; + printf("[%s]\n", getpassfd("foo>", buf, sizeof(buf), NULL, + GETPASS_ECHO_STAR|GETPASS_ECHO_NL, 2)); + return 0; +} +#endif diff --git a/lib/libc/gen/getprogname.3 b/lib/libc/gen/getprogname.3 index 878d6c6da..3dfc42480 100644 --- a/lib/libc/gen/getprogname.3 +++ b/lib/libc/gen/getprogname.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getprogname.3,v 1.7 2008/03/29 16:51:40 dholland Exp $ +.\" $NetBSD: getprogname.3,v 1.8 2011/05/21 19:06:44 dholland Exp $ .\" .\" Copyright (c) 2001 Christopher G. Demetriou .\" All rights reserved. @@ -32,7 +32,7 @@ .\" .\" <> .\" -.Dd March 29, 2008 +.Dd May 21, 2011 .Dt GETPROGNAME 3 .Os .Sh NAME @@ -87,18 +87,19 @@ Therefore, in .Nx , calling .Fn setprogname +explicitly has no effect. +However, portable programs that wish to use +.Fn getprogname +should call +.Fn setprogname from -.Fn main -has no effect. -However, it does serve to increase the portability of the program: -on other operating systems, +.Fn main . +On operating systems where .Fn getprogname and .Fn setprogname -may be implemented by a portability library, and a call to -.Fn setprogname -allows that library to know the program name without -modifications to that system's program start-up code. +are implemented via a portability library, this call is needed to +make the name available. .Sh SEE ALSO .Xr err 3 , .Xr setproctitle 3 diff --git a/lib/libc/gen/getprogname.c b/lib/libc/gen/getprogname.c index 417d3349a..6904fad6f 100644 --- a/lib/libc/gen/getprogname.c +++ b/lib/libc/gen/getprogname.c @@ -1,4 +1,4 @@ -/* $NetBSD: getprogname.c,v 1.3 2003/07/26 19:24:42 salo Exp $ */ +/* $NetBSD: getprogname.c,v 1.4 2011/10/06 20:31:41 christos Exp $ */ /* * Copyright (c) 2001 Christopher G. Demetriou @@ -36,7 +36,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getprogname.c,v 1.3 2003/07/26 19:24:42 salo Exp $"); +__RCSID("$NetBSD: getprogname.c,v 1.4 2011/10/06 20:31:41 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -47,7 +47,7 @@ __RCSID("$NetBSD: getprogname.c,v 1.3 2003/07/26 19:24:42 salo Exp $"); __weak_alias(getprogname,_getprogname) #endif -extern const char *__progname; +const char *__progname; const char * getprogname(void) diff --git a/lib/libc/gen/getpwent.3 b/lib/libc/gen/getpwent.3 index db97f378a..5d55919cf 100644 --- a/lib/libc/gen/getpwent.3 +++ b/lib/libc/gen/getpwent.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getpwent.3,v 1.37 2010/03/22 19:30:53 joerg Exp $ +.\" $NetBSD: getpwent.3,v 1.38 2011/04/28 16:35:05 wiz Exp $ .\" .\" Copyright (c) 1988, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -236,9 +236,25 @@ on success or entry not found, and non-zero on failure, setting the global variable .Dv errno to indicate the nature of the failure. +.Sh FILES +.Bl -tag -width /etc/master.passwd -compact +.It Pa /etc/pwd.db +The insecure password database file +.It Pa /etc/spwd.db +The secure password database file +.It Pa /etc/master.passwd +The current password file +.It Pa /etc/passwd +A Version 7 format password file +.El +.Sh COMPATIBILITY +The historic function +.Fn setpwfile +which allowed the specification of alternative password databases, +has been deprecated and is no longer available. .Sh ERRORS The following error codes may be set in -.Va errno +.Va errno for .Nm getpwent , .Nm getpwent_r , @@ -249,10 +265,10 @@ for and .Nm setpassent : .Bl -tag -width Er -.It Bq Er EIO -An I/O error has occurred. .It Bq Er EINTR A signal was caught during the database search. +.It Bq Er EIO +An I/O error has occurred. .It Bq Er EMFILE The limit on open files for this process has been reached. .It Bq Er ENFILE @@ -260,7 +276,7 @@ The system limit on open files has been reached. .El .Pp The following error code may be set in -.Va errno +.Va errno for .Nm getpwent_r , .Nm getpwnam_r , @@ -279,17 +295,6 @@ and Other .Dv errno values may be set depending on the specific database backends. -.Sh FILES -.Bl -tag -width /etc/master.passwd -compact -.It Pa /etc/pwd.db -The insecure password database file -.It Pa /etc/spwd.db -The secure password database file -.It Pa /etc/master.passwd -The current password file -.It Pa /etc/passwd -A Version 7 format password file -.El .Sh SEE ALSO .Xr getlogin 2 , .Xr getgrent 3 , @@ -363,8 +368,3 @@ avoided, if possible. makes no attempt to suppress duplicate information if multiple sources are specified in .Xr nsswitch.conf 5 . -.Sh COMPATIBILITY -The historic function -.Fn setpwfile -which allowed the specification of alternative password databases, -has been deprecated and is no longer available. diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 64de868c2..61020f75b 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -1,4 +1,4 @@ -/* $NetBSD: getpwent.c,v 1.77 2010/03/23 20:28:59 drochner Exp $ */ +/* $NetBSD: getpwent.c,v 1.81 2012/09/08 15:15:06 dholland Exp $ */ /*- * Copyright (c) 1997-2000, 2004-2005 The NetBSD Foundation, Inc. @@ -88,7 +88,7 @@ #if 0 static char sccsid[] = "@(#)getpwent.c 8.2 (Berkeley) 4/27/95"; #else -__RCSID("$NetBSD: getpwent.c,v 1.77 2010/03/23 20:28:59 drochner Exp $"); +__RCSID("$NetBSD: getpwent.c,v 1.81 2012/09/08 15:15:06 dholland Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -1126,7 +1126,7 @@ struct nis_state { char *current; /* current first/next match */ int currentlen; /* length of _nis_current */ enum { /* shadow map type */ - NISMAP_UNKNOWN, /* unknown ... */ + NISMAP_UNKNOWN = 0, /* unknown ... */ NISMAP_NONE, /* none: use "passwd.by*" */ NISMAP_ADJUNCT, /* pw_passwd from "passwd.adjunct.*" */ NISMAP_MASTER /* all from "master.passwd.by*" */ @@ -1138,11 +1138,17 @@ static struct nis_state _nis_state; static struct passwd _nis_passwd; static char _nis_passwdbuf[_GETPW_R_SIZE_MAX]; +static const char __nis_pw_n_1[] = "master.passwd.byname"; +static const char __nis_pw_n_2[] = "passwd.byname"; +static const char __nis_pw_u_1[] = "master.passwd.byuid"; +static const char __nis_pw_u_2[] = "passwd.byuid"; + +static const char * const __nis_pw_n_map[4] = { __nis_pw_n_2, __nis_pw_n_2, __nis_pw_n_2, __nis_pw_n_1 }; +static const char * const __nis_pw_u_map[4] = { __nis_pw_u_2, __nis_pw_u_2, __nis_pw_u_2, __nis_pw_u_1 }; + /* macros for deciding which NIS maps to use. */ -#define PASSWD_BYNAME(x) ((x)->maptype == NISMAP_MASTER \ - ? "master.passwd.byname" : "passwd.byname") -#define PASSWD_BYUID(x) ((x)->maptype == NISMAP_MASTER \ - ? "master.passwd.byuid" : "passwd.byuid") +#define PASSWD_BYNAME(x) ((x)->maptype == NISMAP_MASTER ? __nis_pw_n_1 : __nis_pw_n_2) +#define PASSWD_BYUID(x) ((x)->maptype == NISMAP_MASTER ? __nis_pw_u_1 : __nis_pw_u_2) static int _nis_start(struct nis_state *state) @@ -1224,7 +1230,7 @@ _nis_parse(const char *entry, struct passwd *pw, char *buf, size_t buflen, _DIAGASSERT(buf != NULL); _DIAGASSERT(state != NULL); - elen = strlen(entry); + elen = strlen(entry) + 1; if (elen >= buflen) return 0; if (! _pw_parse(entry, pw, buf, buflen, @@ -1242,10 +1248,14 @@ _nis_parse(const char *entry, struct passwd *pw, char *buf, size_t buflen, char *bp, *ep; /* skip name to get password */ ep = data; - if ((bp = strsep(&ep, ":")) != NULL && + if (strsep(&ep, ":") != NULL && (bp = strsep(&ep, ":")) != NULL) { /* store new pw_passwd after entry */ - strlcpy(buf + elen, bp, buflen - elen); + if (strlcpy(buf + elen, bp, buflen - elen) >= + buflen - elen) { + free(data); + return 0; + } pw->pw_passwd = &buf[elen]; } free(data); @@ -1263,7 +1273,7 @@ _nis_parse(const char *entry, struct passwd *pw, char *buf, size_t buflen, */ static int _nis_pwscan(int *retval, struct passwd *pw, char *buffer, size_t buflen, - struct nis_state *state, const char *map) + struct nis_state *state, const char * const *map_arr, size_t nmaps) { char *data; int nisr, rv, datalen; @@ -1272,7 +1282,7 @@ _nis_pwscan(int *retval, struct passwd *pw, char *buffer, size_t buflen, _DIAGASSERT(pw != NULL); _DIAGASSERT(buffer != NULL); _DIAGASSERT(state != NULL); - _DIAGASSERT(map != NULL); + _DIAGASSERT(map_arr != NULL); *retval = 0; @@ -1284,9 +1294,11 @@ _nis_pwscan(int *retval, struct passwd *pw, char *buffer, size_t buflen, data = NULL; rv = NS_NOTFOUND; + _DIAGASSERT(state->maptype != NISMAP_UNKNOWN && + (unsigned)state->maptype < nmaps); /* search map */ - nisr = yp_match(state->domain, map, buffer, (int)strlen(buffer), + nisr = yp_match(state->domain, map_arr[state->maptype], buffer, (int)strlen(buffer), &data, &datalen); switch (nisr) { case 0: @@ -1521,7 +1533,7 @@ _nis_getpwuid(void *nsrv, void *nscb, va_list ap) snprintf(_nis_passwdbuf, sizeof(_nis_passwdbuf), "%u", (unsigned int)uid); rv = _nis_pwscan(&rerror, &_nis_passwd, _nis_passwdbuf, sizeof(_nis_passwdbuf), - &_nis_state, PASSWD_BYUID(&_nis_state)); + &_nis_state, __nis_pw_u_map, __arraycount(__nis_pw_u_map)); if (!_nis_state.stayopen) _nis_end(&_nis_state); if (rv == NS_SUCCESS && uid == _nis_passwd.pw_uid) @@ -1549,14 +1561,21 @@ _nis_getpwuid_r(void *nsrv, void *nscb, va_list ap) _DIAGASSERT(result != NULL); *result = NULL; - memset(&state, 0, sizeof(state)); - rv = _nis_start(&state); - if (rv != NS_SUCCESS) - return rv; snprintf(buffer, buflen, "%u", (unsigned int)uid); - rv = _nis_pwscan(retval, pw, buffer, buflen, - &state, PASSWD_BYUID(&state)); - _nis_end(&state); +/* remark: we run under a global mutex inside of this module ... */ + if (_nis_state.stayopen) + { /* use global state only if stayopen is set - otherwise we would blow up getpwent_r() ... */ + rv = _nis_pwscan(retval, pw, buffer, buflen, + &_nis_state, __nis_pw_u_map, __arraycount(__nis_pw_u_map)); + } + else + { /* keep old semantic if no stayopen set - no need to call _nis_start() here - _nis_pwscan() will do it for us ... */ + /* use same way as in getgrent.c ... */ + memset(&state, 0, sizeof(state)); + rv = _nis_pwscan(retval, pw, buffer, buflen, + &state, __nis_pw_u_map, __arraycount(__nis_pw_u_map)); + _nis_end(&state); + } if (rv != NS_SUCCESS) return rv; if (uid == pw->pw_uid) { @@ -1584,7 +1603,7 @@ _nis_getpwnam(void *nsrv, void *nscb, va_list ap) snprintf(_nis_passwdbuf, sizeof(_nis_passwdbuf), "%s", name); rv = _nis_pwscan(&rerror, &_nis_passwd, _nis_passwdbuf, sizeof(_nis_passwdbuf), - &_nis_state, PASSWD_BYNAME(&_nis_state)); + &_nis_state, __nis_pw_n_map, __arraycount(__nis_pw_n_map)); if (!_nis_state.stayopen) _nis_end(&_nis_state); if (rv == NS_SUCCESS && strcmp(name, _nis_passwd.pw_name) == 0) @@ -1613,13 +1632,20 @@ _nis_getpwnam_r(void *nsrv, void *nscb, va_list ap) *result = NULL; snprintf(buffer, buflen, "%s", name); - memset(&state, 0, sizeof(state)); - rv = _nis_start(&state); - if (rv != NS_SUCCESS) - return rv; - rv = _nis_pwscan(retval, pw, buffer, buflen, - &state, PASSWD_BYNAME(&state)); - _nis_end(&state); +/* remark: we run under a global mutex inside of this module ... */ + if (_nis_state.stayopen) + { /* use global state only if stayopen is set - otherwise we would blow up getpwent_r() ... */ + rv = _nis_pwscan(retval, pw, buffer, buflen, + &_nis_state, __nis_pw_n_map, __arraycount(__nis_pw_n_map)); + } + else + { /* keep old semantic if no stayopen set - no need to call _nis_start() here - _nis_pwscan() will do it for us ... */ + /* use same way as in getgrent.c ... */ + memset(&state, 0, sizeof(state)); + rv = _nis_pwscan(retval, pw, buffer, buflen, + &state, __nis_pw_n_map, __arraycount(__nis_pw_n_map)); + _nis_end(&state); + } if (rv != NS_SUCCESS) return rv; if (strcmp(name, pw->pw_name) == 0) { @@ -2077,7 +2103,7 @@ _compat_pwscan(int *retval, struct passwd *pw, char *buffer, size_t buflen, state->mode = COMPAT_FULL; /* reset passwd_compat search */ /* XXXREENTRANT: setpassent is not thread safe ? */ - (void) _passwdcompat_setpassent(0); + (void) _passwdcompat_setpassent(_compat_state.stayopen); break; case '@': /* `+@netgroup' */ state->mode = COMPAT_NETGROUP; @@ -2511,7 +2537,6 @@ getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t buflen, mutex_lock(&_pwmutex); r = nsdispatch(NULL, dtab, NSDB_PASSWD, "getpwuid_r", __nsdefaultcompat, &retval, uid, pwd, buffer, buflen, result); - mutex_unlock(&_pwmutex); switch (r) { case NS_SUCCESS: diff --git a/lib/libc/gen/getttyent.3 b/lib/libc/gen/getttyent.3 index e0757bad9..09bb1f516 100644 --- a/lib/libc/gen/getttyent.3 +++ b/lib/libc/gen/getttyent.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getttyent.3,v 1.18 2006/04/23 16:46:32 wiz Exp $ +.\" $NetBSD: getttyent.3,v 1.20 2012/04/22 10:14:18 wiz Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getttyent.3 8.1 (Berkeley) 6/4/93 .\" -.Dd April 18, 2006 +.Dd April 5, 2012 .Dt GETTTYENT 3 .Os .Sh NAME @@ -124,7 +124,7 @@ The command to execute for a window system associated with the line. Any trailing comment field, with any leading hash marks (``#'') or whitespace removed. .It Fa ty_class -A key indexing into a termcap-style database (/etc/ttyclasses) +A key indexing into a capfile style database (/etc/ttyclasses) of attributes for this class of tty. No attributes are currently defined or used, so there are currently no functions to retrieve them. @@ -194,8 +194,8 @@ return 0 on failure and 1 on success. .Sh SEE ALSO .Xr login 1 , .Xr ttyslot 3 , +.Xr capfile 5 , .Xr gettytab 5 , -.Xr termcap 5 , .Xr ttys 5 , .Xr getty 8 , .Xr init 8 , diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c index aa6f5df2f..74f7e4dad 100644 --- a/lib/libc/gen/getttyent.c +++ b/lib/libc/gen/getttyent.c @@ -1,4 +1,4 @@ -/* $NetBSD: getttyent.c,v 1.23 2006/04/17 23:29:21 salo Exp $ */ +/* $NetBSD: getttyent.c,v 1.24 2011/10/15 23:00:01 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getttyent.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getttyent.c,v 1.23 2006/04/17 23:29:21 salo Exp $"); +__RCSID("$NetBSD: getttyent.c,v 1.24 2011/10/15 23:00:01 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c index a9c7c241b..c7f5c2895 100644 --- a/lib/libc/gen/getusershell.c +++ b/lib/libc/gen/getusershell.c @@ -1,4 +1,4 @@ -/* $NetBSD: getusershell.c,v 1.27 2008/04/28 20:22:59 martin Exp $ */ +/* $NetBSD: getusershell.c,v 1.29 2012/03/13 21:13:36 christos Exp $ */ /*- * Copyright (c) 1999, 2005 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ #if 0 static char sccsid[] = "@(#)getusershell.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getusershell.c,v 1.27 2008/04/28 20:22:59 martin Exp $"); +__RCSID("$NetBSD: getusershell.c,v 1.29 2012/03/13 21:13:36 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -133,7 +133,7 @@ _files_start(struct files_state *state) _DIAGASSERT(state != NULL); if (state->fp == NULL) { - state->fp = fopen(_PATH_SHELLS, "r"); + state->fp = fopen(_PATH_SHELLS, "re"); if (state->fp == NULL) return NS_UNAVAIL; } else { @@ -189,7 +189,8 @@ _files_getusershell(void *nsrv, void *nscb, va_list ap) return rv; } - while (fgets(curshell, sizeof(curshell) - 1, _files_state.fp) != NULL) { + while (fgets(curshell, (int)sizeof(curshell) - 1, _files_state.fp) + != NULL) { sp = cp = curshell; while (*cp != '#' && *cp != '/' && *cp != '\0') cp++; diff --git a/lib/libc/gen/glob.3 b/lib/libc/gen/glob.3 index 7d8e47a65..cf7cd3c2a 100644 --- a/lib/libc/gen/glob.3 +++ b/lib/libc/gen/glob.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: glob.3,v 1.39 2010/11/30 21:03:07 jruoho Exp $ +.\" $NetBSD: glob.3,v 1.41 2012/08/12 13:31:41 christos Exp $ .\" .\" Copyright (c) 1989, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -31,7 +31,7 @@ .\" .\" @(#)glob.3 8.3 (Berkeley) 4/16/94 .\" -.Dd November 30, 2010 +.Dd August 12, 2012 .Dt GLOB 3 .Os .Sh NAME @@ -44,7 +44,7 @@ .Sh SYNOPSIS .In glob.h .Ft int -.Fn glob "const char * restrict pattern" "int flags" "const int (*errfunc)(const char *, int)" "glob_t * restrict pglob" +.Fn glob "const char * restrict pattern" "int flags" "int (*errfunc)(const char *, int)" "glob_t * restrict pglob" .Ft void .Fn globfree "glob_t *pglob" .Ft int @@ -230,6 +230,18 @@ does the same thing to ease typing of .Xr find 1 patterns .Pc . +.It Dv GLOB_LIMIT +Limit the amount of memory used to store matched strings to +.Li 64K , +the number of +.Xr stat 2 +calls to 128, and the number of +.Xr readdir 3 +calls to 16K. +This option should be set for programs that can be coerced to a denial of +service attack via patterns that expand to a very large number of matches, +such as a long string of +.Li */../*/.. .It Dv GLOB_MAGCHAR Set by the .Fn glob @@ -237,6 +249,10 @@ function if the pattern included globbing characters. See the description of the usage of the .Fa gl_matchc structure member for more details. +.It Dv GLOB_NOESCAPE +Disable the use of the backslash +.Pq Ql \e +character for quoting. .It Dv GLOB_NOMAGIC Is the same as .Dv GLOB_NOCHECK @@ -247,28 +263,6 @@ if it does not contain any of the special characters ``*'', ``?'' or ``[''. is provided to simplify implementing the historic .Xr csh 1 globbing behavior and should probably not be used anywhere else. -.It Dv GLOB_NOESCAPE -Disable the use of the backslash -.Pq Ql \e -character for quoting. -.It Dv GLOB_TILDE -Expand patterns that start with -.Ql ~ -to user name home directories. -.It Dv GLOB_LIMIT -Limit the amount of memory used to store matched strings to -.Li 64K , -the number of -.Xr stat 2 -calls to 128, and the number of -.Xr readdir 3 -calls to 16K. -This option should be set for programs that can be coerced to a denial of -service attack via patterns that expand to a very large number of matches, -such as a long string of -.Li */../*/.. -.It Dv GLOB_PERIOD -Allow metacharacters to match a leading period in a filename. .It Dv GLOB_NO_DOTDIRS Hide .Sq Li \&. @@ -277,13 +271,19 @@ and from metacharacter matches, regardless of whether .Dv GLOB_PERIOD is set and whether the pattern component begins with a literal period. -.Dv GLOB_STAR +.It Dv GLOB_PERIOD +Allow metacharacters to match a leading period in a filename. +.It Dv GLOB_STAR Indicates that two adjacent .Li * characters will do a recursive match in all subdirs, without following symbolic links and three adjacent .Li * characters will also follow symbolic links. +.It Dv GLOB_TILDE +Expand patterns that start with +.Ql ~ +to user name home directories. .El .Pp If, during the search, a directory is encountered that cannot be opened @@ -486,11 +486,14 @@ compatible with the exception that the flags .Dv GLOB_ALTDIRFUNC , .Dv GLOB_BRACE , +.Dv GLOB_LIMIT , .Dv GLOB_MAGCHAR , +.Dv GLOB_NOESCAPE , .Dv GLOB_NOMAGIC , +.Dv GLOB_NO_DOTDIRS , +.Dv GLOB_PERIOD , +.Dv GLOB_STAR , .Dv GLOB_TILDE , -and -.Dv GLOB_LIMIT and the fields .Fa gl_matchc and diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c index 71631b7df..220ac7658 100644 --- a/lib/libc/gen/glob.c +++ b/lib/libc/gen/glob.c @@ -1,4 +1,4 @@ -/* $NetBSD: glob.c,v 1.28 2011/01/21 23:30:31 christos Exp $ */ +/* $NetBSD: glob.c,v 1.31 2011/10/30 21:53:43 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; #else -__RCSID("$NetBSD: glob.c,v 1.28 2011/01/21 23:30:31 christos Exp $"); +__RCSID("$NetBSD: glob.c,v 1.31 2011/10/30 21:53:43 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -180,8 +180,8 @@ static void qprintf(const char *, Char *); #endif int -glob(const char *pattern, int flags, int (*errfunc)(const char *, int), - glob_t *pglob) +glob(const char * __restrict pattern, int flags, int (*errfunc)(const char *, + int), glob_t * __restrict pglob) { const u_char *patnext; int c; @@ -638,7 +638,6 @@ glob2(Char *pathbuf, Char *pathend, Char *pathlim, const Char *pattern, errno = 0; *pathend++ = SEP; *pathend = EOS; -printf("stat limit\n"); return GLOB_NOSPACE; } if (((pglob->gl_flags & GLOB_MARK) && @@ -790,7 +789,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pathlim, const Char *pattern, if (pglob->gl_flags & GLOB_ALTDIRFUNC) readdirfunc = pglob->gl_readdir; else - readdirfunc = (struct dirent *(*)__P((void *))) readdir; + readdirfunc = (struct dirent *(*)(void *)) readdir; while ((dp = (*readdirfunc)(dirp)) != NULL) { u_char *sc; Char *dc; @@ -800,7 +799,8 @@ glob3(Char *pathbuf, Char *pathend, Char *pathlim, const Char *pattern, errno = 0; *pathend++ = SEP; *pathend = EOS; - return GLOB_NOSPACE; + error = GLOB_NOSPACE; + break; } /* diff --git a/lib/libc/gen/humanize_number.3 b/lib/libc/gen/humanize_number.3 index 0179636ab..b078c3785 100644 --- a/lib/libc/gen/humanize_number.3 +++ b/lib/libc/gen/humanize_number.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: humanize_number.3,v 1.9 2011/01/14 10:08:57 jruoho Exp $ +.\" $NetBSD: humanize_number.3,v 1.11 2011/08/20 21:35:32 wiz Exp $ .\" .\" Copyright (c) 1999, 2002, 2008 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -33,13 +33,13 @@ .Sh NAME .Nm dehumanize_number , .Nm humanize_number -.Nd format a number into a human readable form and viceversa +.Nd format a number into a human readable form and vice versa .Sh SYNOPSIS .In stdlib.h .Ft int .Fn dehumanize_number "const char *str" "int64_t *result" .Ft int -.Fn humanize_number "char *buf" "size_t len" "int64_t number" "const char *suffix" "int scale" "int flags" +.Fn humanize_number "char *buffer" "size_t len" "int64_t number" "const char *suffix" "int scale" "int flags" .Sh DESCRIPTION The .Fn humanize_number diff --git a/lib/libc/gen/humanize_number.c b/lib/libc/gen/humanize_number.c index 9166b0677..533560f31 100644 --- a/lib/libc/gen/humanize_number.c +++ b/lib/libc/gen/humanize_number.c @@ -1,4 +1,4 @@ -/* $NetBSD: humanize_number.c,v 1.14 2008/04/28 20:22:59 martin Exp $ */ +/* $NetBSD: humanize_number.c,v 1.16 2012/03/17 20:01:14 christos Exp $ */ /* * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: humanize_number.c,v 1.14 2008/04/28 20:22:59 martin Exp $"); +__RCSID("$NetBSD: humanize_number.c,v 1.16 2012/03/17 20:01:14 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -48,9 +48,9 @@ humanize_number(char *buf, size_t len, int64_t bytes, const char *suffix, int scale, int flags) { const char *prefixes, *sep; - int b, i, r, maxscale, s1, s2, sign; - int64_t divisor, max; - size_t baselen; + int b, r, s1, s2, sign; + int64_t divisor, max, post = 1; + size_t i, baselen, maxscale; _DIAGASSERT(buf != NULL); _DIAGASSERT(suffix != NULL); @@ -78,7 +78,7 @@ humanize_number(char *buf, size_t len, int64_t bytes, #define SCALE2PREFIX(scale) (&prefixes[(scale) << 1]) maxscale = 7; - if (scale >= maxscale && + if ((size_t)scale >= maxscale && (scale & (HN_AUTOSCALE | HN_GETSCALE)) == 0) return (-1); @@ -89,12 +89,23 @@ humanize_number(char *buf, size_t len, int64_t bytes, buf[0] = '\0'; if (bytes < 0) { sign = -1; - bytes *= -100; baselen = 3; /* sign, digit, prefix */ + if (-bytes < INT64_MAX / 100) + bytes *= -100; + else { + bytes = -bytes; + post = 100; + baselen += 2; + } } else { sign = 1; - bytes *= 100; baselen = 2; /* digit, prefix */ + if (bytes < INT64_MAX / 100) + bytes *= 100; + else { + post = 100; + baselen += 2; + } } if (flags & HN_NOSPACE) sep = ""; @@ -121,11 +132,14 @@ humanize_number(char *buf, size_t len, int64_t bytes, for (i = 0; bytes >= max - 50 && i < maxscale; i++) bytes /= divisor; - if (scale & HN_GETSCALE) - return (i); + if (scale & HN_GETSCALE) { + _DIAGASSERT(__type_fit(int, i)); + return (int)i; + } } else - for (i = 0; i < scale && i < maxscale; i++) + for (i = 0; i < (size_t)scale && i < maxscale; i++) bytes /= divisor; + bytes *= post; /* If a value <= 9.9 after rounding and ... */ if (bytes < 995 && i > 0 && flags & HN_DECIMAL) { diff --git a/lib/libc/gen/initdir.c b/lib/libc/gen/initdir.c index 953ea24d0..2a6e74dcf 100644 --- a/lib/libc/gen/initdir.c +++ b/lib/libc/gen/initdir.c @@ -1,4 +1,4 @@ -/* $NetBSD: initdir.c,v 1.1 2010/09/26 02:26:59 yamt Exp $ */ +/* $NetBSD: initdir.c,v 1.3 2012/03/13 21:13:36 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: initdir.c,v 1.1 2010/09/26 02:26:59 yamt Exp $"); +__RCSID("$NetBSD: initdir.c,v 1.3 2012/03/13 21:13:36 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -41,6 +41,11 @@ __RCSID("$NetBSD: initdir.c,v 1.1 2010/09/26 02:26:59 yamt Exp $"); #include #include #include + +#if !defined(O_CLOEXEC) +#define O_CLOEXEC 0 +#endif + #endif #include "reentrant.h" @@ -161,8 +166,7 @@ retry: */ if (flags & DTF_REWIND) { (void) close(fd); - if ((fd = open(name, O_RDONLY)) == -1 || - fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { + if ((fd = open(name, O_RDONLY | O_CLOEXEC)) == -1) { dirp->dd_buf = buf; return errno; } @@ -247,7 +251,8 @@ retry: } } - dirp->dd_len = len; + _DIAGASSERT(__type_fit(int, len)); + dirp->dd_len = (int)len; dirp->dd_size = ddptr - dirp->dd_buf; } else { dirp->dd_len = incr; diff --git a/lib/libc/gen/initgroups.c b/lib/libc/gen/initgroups.c index e1c293b00..86c6f4ef3 100644 --- a/lib/libc/gen/initgroups.c +++ b/lib/libc/gen/initgroups.c @@ -1,4 +1,4 @@ -/* $NetBSD: initgroups.c,v 1.21 2003/08/07 16:42:51 agc Exp $ */ +/* $NetBSD: initgroups.c,v 1.22 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)initgroups.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: initgroups.c,v 1.21 2003/08/07 16:42:51 agc Exp $"); +__RCSID("$NetBSD: initgroups.c,v 1.22 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,9 +52,7 @@ __weak_alias(initgroups,_initgroups) #endif int -initgroups(uname, agroup) - const char *uname; - gid_t agroup; +initgroups(const char *uname, gid_t agroup) { gid_t groups_list[NGROUPS]; int ngroups; diff --git a/lib/libc/gen/isascii.c b/lib/libc/gen/isascii.c index b441a3298..d5fff2d03 100644 --- a/lib/libc/gen/isascii.c +++ b/lib/libc/gen/isascii.c @@ -1,4 +1,4 @@ -/* $NetBSD: isascii.c,v 1.3 2010/06/01 13:52:08 tnozaki Exp $ */ +/* $NetBSD: isascii.c,v 1.4 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -38,15 +38,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: isascii.c,v 1.3 2010/06/01 13:52:08 tnozaki Exp $"); +__RCSID("$NetBSD: isascii.c,v 1.4 2012/06/25 22:32:43 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #define _CTYPE_NOINLINE #include int -isascii(c) - int c; +isascii(int c) { return ((unsigned)(c) <= 0177); } diff --git a/lib/libc/gen/isatty.c b/lib/libc/gen/isatty.c index 2bc3106c7..e7191966c 100644 --- a/lib/libc/gen/isatty.c +++ b/lib/libc/gen/isatty.c @@ -1,4 +1,4 @@ -/* $NetBSD: isatty.c,v 1.12 2003/08/07 16:42:51 agc Exp $ */ +/* $NetBSD: isatty.c,v 1.13 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)isatty.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: isatty.c,v 1.12 2003/08/07 16:42:51 agc Exp $"); +__RCSID("$NetBSD: isatty.c,v 1.13 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,8 +50,7 @@ __weak_alias(isatty,_isatty) #endif int -isatty(fd) - int fd; +isatty(int fd) { struct termios t; diff --git a/lib/libc/gen/isfinite.3 b/lib/libc/gen/isfinite.3 index 2d159a690..dd7eb1bae 100644 --- a/lib/libc/gen/isfinite.3 +++ b/lib/libc/gen/isfinite.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: isfinite.3,v 1.3 2008/04/30 13:10:50 martin Exp $ +.\" $NetBSD: isfinite.3,v 1.4 2011/08/06 11:02:41 jruoho Exp $ .\" .\" Copyright (c) 2003 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 29, 2003 +.Dd August 6, 2011 .Dt ISFINITE 3 .Os .Sh NAME @@ -66,6 +66,7 @@ Otherwise 0 is returned. .Sh ERRORS No errors are defined. .Sh SEE ALSO +.Xr finite 3 , .Xr fpclassify 3 , .Xr isnormal 3 , .Xr math 3 , diff --git a/lib/libc/gen/isspace.3 b/lib/libc/gen/isspace.3 index bb1dcbbcb..4c6d1306a 100644 --- a/lib/libc/gen/isspace.3 +++ b/lib/libc/gen/isspace.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: isspace.3,v 1.14 2008/04/17 16:25:36 apb Exp $ +.\" $NetBSD: isspace.3,v 1.15 2012/10/03 19:28:44 wiz Exp $ .\" .\" Copyright (c) 1991 The Regents of the University of California. .\" All rights reserved. @@ -68,7 +68,7 @@ Carriage return. .It Li \et Horizontal tab. .It Li \ev -And vertical tab. +Vertical tab. .El .Pp In the diff --git a/lib/libc/gen/lockf.3 b/lib/libc/gen/lockf.3 index 293b8ace8..8a0716683 100644 --- a/lib/libc/gen/lockf.3 +++ b/lib/libc/gen/lockf.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: lockf.3,v 1.10 2008/04/30 13:10:50 martin Exp $ +.\" $NetBSD: lockf.3,v 1.12 2011/10/15 21:35:49 rmind Exp $ .\" .\" Copyright (c) 1997 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd December 19, 1997 +.Dd October 15, 2011 .Dt LOCKF 3 .Os .Sh NAME @@ -64,6 +64,7 @@ argument is a control value which specifies the action to be taken. The permissible values for .Fa function are as follows: +.Pp .Bl -tag -width F_ULOCKXX -compact -offset indent .It Sy Function .Sy Description @@ -245,9 +246,17 @@ of locked regions in the system exceeding a system-imposed limit. .El .Sh SEE ALSO .Xr fcntl 2 , -.Xr flock 2 +.Xr flock 2 , +.Xr flockfile 3 .Sh STANDARDS The .Fn lockf function conforms to -.St -xpg4.2 . +.St -xpg4.2 +and +.St -p1003.1-2008 . +.Sh HISTORY +The +.Fn lockf +function first appeared in +.Fx 1.4 . diff --git a/lib/libc/gen/lockf.c b/lib/libc/gen/lockf.c index c892e9f5d..6f82f5e2c 100644 --- a/lib/libc/gen/lockf.c +++ b/lib/libc/gen/lockf.c @@ -1,4 +1,4 @@ -/* $NetBSD: lockf.c,v 1.3 2008/04/28 20:22:59 martin Exp $ */ +/* $NetBSD: lockf.c,v 1.4 2012/06/25 22:32:43 abs Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: lockf.c,v 1.3 2008/04/28 20:22:59 martin Exp $"); +__RCSID("$NetBSD: lockf.c,v 1.4 2012/06/25 22:32:43 abs Exp $"); #endif #include "namespace.h" @@ -45,10 +45,7 @@ __weak_alias(lockf,_lockf) int -lockf(filedes, function, size) - int filedes; - int function; - off_t size; +lockf(int filedes, int function, off_t size) { struct flock fl; int cmd; diff --git a/lib/libc/gen/makecontext.3 b/lib/libc/gen/makecontext.3 index 00b798c8a..0742e2185 100644 --- a/lib/libc/gen/makecontext.3 +++ b/lib/libc/gen/makecontext.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: makecontext.3,v 1.9 2010/04/29 06:07:35 jruoho Exp $ +.\" $NetBSD: makecontext.3,v 1.10 2012/05/04 12:28:03 joerg Exp $ .\" .\" Copyright (c) 2001, 2009 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd April 29, 2010 +.Dd May 4, 2012 .Dt MAKECONTEXT 3 .Os .Sh NAME @@ -167,9 +167,3 @@ and .Fn swapcontext functions first appeared in .At V.4 . -.Sh CAVEATS -Due to limitations in the current pthread implementation, -.Nm -should not be used in programs which link against the -.Xr pthread 3 -library (whether threads are used or not). diff --git a/lib/libc/gen/modf_ieee754.c b/lib/libc/gen/modf_ieee754.c index 2132036b3..39b4d0543 100644 --- a/lib/libc/gen/modf_ieee754.c +++ b/lib/libc/gen/modf_ieee754.c @@ -1,4 +1,4 @@ -/* $NetBSD: modf_ieee754.c,v 1.3 2010/01/27 14:10:41 drochner Exp $ */ +/* $NetBSD: modf_ieee754.c,v 1.4 2012/03/22 13:25:45 he Exp $ */ /* * Copyright (c) 1994, 1995 Carnegie-Mellon University. @@ -92,8 +92,8 @@ modf(double val, double *iptr) frac = ((u_int64_t)v.dblu_dbl.dbl_frach << 32) + v.dblu_dbl.dbl_fracl; frac >>= DBL_FRACBITS - (u.dblu_dbl.dbl_exp - DBL_EXP_BIAS); frac <<= DBL_FRACBITS - (u.dblu_dbl.dbl_exp - DBL_EXP_BIAS); - v.dblu_dbl.dbl_fracl = frac & 0xffffffff; - v.dblu_dbl.dbl_frach = frac >> 32; + v.dblu_dbl.dbl_fracl = (u_int) (frac & 0xffffffffULL); + v.dblu_dbl.dbl_frach = (u_int) (frac >> 32); *iptr = v.dblu_d; u.dblu_d -= v.dblu_d; diff --git a/lib/libc/gen/nice.3 b/lib/libc/gen/nice.3 index e59f12327..3aa293f45 100644 --- a/lib/libc/gen/nice.3 +++ b/lib/libc/gen/nice.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: nice.3,v 1.13 2003/08/07 16:42:53 agc Exp $ +.\" $NetBSD: nice.3,v 1.14 2011/05/01 02:54:22 christos Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)nice.3 8.1 (Berkeley) 6/4/93 .\" -.Dd February 16, 1998 +.Dd April 30, 2011 .Dt NICE 3 .Os .Sh NAME @@ -54,7 +54,7 @@ from the system and sets it to the priority value specified in .Fa incr . The priority is a value in the range -20 to 20. The default priority is 0; lower priorities cause more favorable scheduling. -Only the super-user may lower priorities. +Only a process with appropriate privileges may lower priorities. .Pp Children inherit the priority of their parent processes via .Xr fork 2 . @@ -74,7 +74,7 @@ function will fail if: .It Bq Er EPERM The .Fa incr -argument is negative and the caller is not the super-user. +argument is negative and the caller does not have appropriate privileges. .El .Sh SEE ALSO .Xr nice 1 , diff --git a/lib/libc/gen/nice.c b/lib/libc/gen/nice.c index 907653181..19d671148 100644 --- a/lib/libc/gen/nice.c +++ b/lib/libc/gen/nice.c @@ -1,4 +1,4 @@ -/* $NetBSD: nice.c,v 1.12 2003/08/07 16:42:53 agc Exp $ */ +/* $NetBSD: nice.c,v 1.13 2011/05/01 02:49:54 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)nice.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: nice.c,v 1.12 2003/08/07 16:42:53 agc Exp $"); +__RCSID("$NetBSD: nice.c,v 1.13 2011/05/01 02:49:54 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,16 +53,18 @@ __weak_alias(nice,_nice) * Backwards compatible nice. */ int -nice(incr) - int incr; +nice(int incr) { int prio; errno = 0; prio = getpriority(PRIO_PROCESS, 0); if (prio == -1 && errno) - return (-1); - if (setpriority(PRIO_PROCESS, 0, prio + incr) != 0) - return (-1); - return (getpriority(PRIO_PROCESS, 0)); + return -1; + if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) { + if (errno == EACCES) + errno = EPERM; + return -1; + } + return getpriority(PRIO_PROCESS, 0); } diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c index 5689be1dc..ee229e025 100644 --- a/lib/libc/gen/nlist.c +++ b/lib/libc/gen/nlist.c @@ -1,4 +1,4 @@ -/* $NetBSD: nlist.c,v 1.22 2009/08/20 08:30:04 he Exp $ */ +/* $NetBSD: nlist.c,v 1.24 2012/03/21 15:32:26 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -66,7 +66,7 @@ #if 0 static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: nlist.c,v 1.22 2009/08/20 08:30:04 he Exp $"); +__RCSID("$NetBSD: nlist.c,v 1.24 2012/03/21 15:32:26 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -92,7 +92,7 @@ __weak_alias(nlist,_nlist) #include "nlist_private.h" static const struct { - int (*fdnlist) __P((int, struct nlist *)); + int (*fdnlist)(int, struct nlist *); } fdnlist_fmts[] = { #ifdef NLIST_AOUT { __fdnlist_aout }, @@ -112,9 +112,7 @@ static const struct { }; int -nlist(name, list) - const char *name; - struct nlist *list; +nlist(const char *name, struct nlist *list) { int fd, n; @@ -130,9 +128,7 @@ nlist(name, list) } int -__fdnlist(fd, list) - int fd; - struct nlist *list; +__fdnlist(int fd, struct nlist *list) { size_t i; int rv; diff --git a/lib/libc/gen/nlist_aout.c b/lib/libc/gen/nlist_aout.c index e51fd88b3..618f35f07 100644 --- a/lib/libc/gen/nlist_aout.c +++ b/lib/libc/gen/nlist_aout.c @@ -1,4 +1,4 @@ -/* $NetBSD: nlist_aout.c,v 1.22 2009/08/20 11:08:59 martin Exp $ */ +/* $NetBSD: nlist_aout.c,v 1.23 2012/03/21 15:32:26 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -66,7 +66,7 @@ #if 0 static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: nlist_aout.c,v 1.22 2009/08/20 11:08:59 martin Exp $"); +__RCSID("$NetBSD: nlist_aout.c,v 1.23 2012/03/21 15:32:26 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -91,9 +91,7 @@ struct nlist; #include int -__fdnlist_aout(fd, list) - int fd; - struct nlist *list; +__fdnlist_aout(int fd, struct nlist *list) { struct nlist *p, *s; char *strtab; diff --git a/lib/libc/gen/nlist_coff.c b/lib/libc/gen/nlist_coff.c index 1ef347542..c808c82aa 100644 --- a/lib/libc/gen/nlist_coff.c +++ b/lib/libc/gen/nlist_coff.c @@ -1,4 +1,4 @@ -/* $NetBSD: nlist_coff.c,v 1.8 2009/08/21 08:42:02 he Exp $ */ +/* $NetBSD: nlist_coff.c,v 1.11 2012/03/22 14:18:34 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou @@ -36,7 +36,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: nlist_coff.c,v 1.8 2009/08/21 08:42:02 he Exp $"); +__RCSID("$NetBSD: nlist_coff.c,v 1.11 2012/03/22 14:18:34 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -58,8 +58,6 @@ __RCSID("$NetBSD: nlist_coff.c,v 1.8 2009/08/21 08:42:02 he Exp $"); #endif #ifdef NLIST_COFF -#define BAD do { rv = -1; goto out; } while (/*CONSTCOND*/0) -#define BADUNMAP do { rv = -1; goto unmap; } while (/*CONSTCOND*/0) #define ES_LEN 18 struct coff_extsym { @@ -81,9 +79,7 @@ struct coff_extsym { #define es_offset u.s.u_offset int -__fdnlist_coff(fd, list) - int fd; - struct nlist *list; +__fdnlist_coff(int fd, struct nlist *list) { struct nlist *p; struct coff_filehdr *filehdrp; @@ -103,20 +99,20 @@ __fdnlist_coff(fd, list) * If we can't fstat() the file, something bad is going on. */ if (fstat(fd, &st) < 0) - BAD; + goto out; /* * Map the file in its entirety. */ if ((uintmax_t)st.st_size > (uintmax_t)SIZE_T_MAX) { errno = EFBIG; - BAD; + goto out; } - mappedsize = st.st_size; + mappedsize = (size_t)st.st_size; mappedfile = mmap(NULL, mappedsize, PROT_READ, MAP_PRIVATE|MAP_FILE, fd, 0); - if (mappedfile == (char *)-1) - BAD; + if (mappedfile == MAP_FAILED) + goto out; /* * Make sure we can access the executable's header @@ -124,11 +120,11 @@ __fdnlist_coff(fd, list) * as an COFF binary. */ if (mappedsize < sizeof (struct coff_filehdr)) - BADUNMAP; - filehdrp = (struct coff_filehdr *)&mappedfile[0]; + goto unmap; + filehdrp = (void *)&mappedfile[0]; if (COFF_BADMAG(filehdrp)) - BADUNMAP; + goto unmap; /* * Find the symbol list. @@ -137,7 +133,7 @@ __fdnlist_coff(fd, list) nesyms = filehdrp->f_nsyms; if (symoff + ES_LEN * nesyms > mappedsize) - BADUNMAP; + goto unmap; extstroff = symoff + ES_LEN * nesyms; nent = 0; @@ -193,7 +189,7 @@ done: unmap: munmap(mappedfile, mappedsize); out: - return (rv); + return rv; } #endif /* NLIST_COFF */ diff --git a/lib/libc/gen/nlist_ecoff.c b/lib/libc/gen/nlist_ecoff.c index 8555590a2..8ac558912 100644 --- a/lib/libc/gen/nlist_ecoff.c +++ b/lib/libc/gen/nlist_ecoff.c @@ -1,4 +1,4 @@ -/* $NetBSD: nlist_ecoff.c,v 1.18 2009/08/21 08:42:02 he Exp $ */ +/* $NetBSD: nlist_ecoff.c,v 1.23 2012/03/20 00:31:24 matt Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou @@ -36,7 +36,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: nlist_ecoff.c,v 1.18 2009/08/21 08:42:02 he Exp $"); +__RCSID("$NetBSD: nlist_ecoff.c,v 1.23 2012/03/20 00:31:24 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -58,21 +58,18 @@ __RCSID("$NetBSD: nlist_ecoff.c,v 1.18 2009/08/21 08:42:02 he Exp $"); #endif #ifdef NLIST_ECOFF -#define check(off, size) ((off < 0) || (off + size > mappedsize)) -#define BAD do { rv = -1; goto out; } while (/*CONSTCOND*/0) -#define BADUNMAP do { rv = -1; goto unmap; } while (/*CONSTCOND*/0) +#define check(off, size) \ + ((size_t)off >= mappedsize || (size_t)(off + size) > mappedsize) int -__fdnlist_ecoff(fd, list) - int fd; - struct nlist *list; +__fdnlist_ecoff(int fd, struct nlist *list) { struct nlist *p; - struct ecoff_exechdr *exechdrp; - struct ecoff_symhdr *symhdrp; - struct ecoff_extsym *esyms; + const struct ecoff_exechdr *exechdrp; + const struct ecoff_symhdr *symhdrp; + const struct ecoff_extsym *esyms; struct stat st; - char *mappedfile; + const char *mappedfile; size_t mappedsize; u_long symhdroff, extstroff; u_int symhdrsize; @@ -88,20 +85,20 @@ __fdnlist_ecoff(fd, list) * If we can't fstat() the file, something bad is going on. */ if (fstat(fd, &st) < 0) - BAD; + goto out; /* * Map the file in its entirety. */ if ((uintmax_t)st.st_size > (uintmax_t)SIZE_T_MAX) { errno = EFBIG; - BAD; + goto out; } - mappedsize = st.st_size; + mappedsize = (size_t)st.st_size; mappedfile = mmap(NULL, mappedsize, PROT_READ, MAP_PRIVATE|MAP_FILE, fd, 0); - if (mappedfile == (char *)-1) - BAD; + if (mappedfile == MAP_FAILED) + goto out; /* * Make sure we can access the executable's header @@ -109,11 +106,11 @@ __fdnlist_ecoff(fd, list) * as an ECOFF binary. */ if (check(0, sizeof *exechdrp)) - BADUNMAP; - exechdrp = (struct ecoff_exechdr *)&mappedfile[0]; + goto unmap; + exechdrp = (const void *)mappedfile; if (ECOFF_BADMAG(exechdrp)) - BADUNMAP; + goto unmap; /* * Find the symbol list. @@ -123,13 +120,13 @@ __fdnlist_ecoff(fd, list) if ((symhdroff + sizeof *symhdrp) > mappedsize || sizeof *symhdrp != symhdrsize) - BADUNMAP; - symhdrp = (struct ecoff_symhdr *)&mappedfile[symhdroff]; + goto unmap; + symhdrp = (const void *)&mappedfile[symhdroff]; nesyms = symhdrp->esymMax; if (check(symhdrp->cbExtOffset, nesyms * sizeof *esyms)) - BADUNMAP; - esyms = (struct ecoff_extsym *)&mappedfile[symhdrp->cbExtOffset]; + goto unmap; + esyms = (const void *)&mappedfile[symhdrp->cbExtOffset]; extstroff = symhdrp->cbSsExtOffset; /* @@ -152,7 +149,7 @@ __fdnlist_ecoff(fd, list) for (i = 0; i < nesyms; i++) { for (p = list; !ISLAST(p); p++) { const char *nlistname; - char *symtabname; + const char *symtabname; /* This may be incorrect */ nlistname = N_NAME(p); @@ -181,9 +178,9 @@ __fdnlist_ecoff(fd, list) done: rv = nent; unmap: - munmap(mappedfile, mappedsize); + munmap(__UNCONST(mappedfile), mappedsize); out: - return (rv); + return rv; } #endif /* NLIST_ECOFF */ diff --git a/lib/libc/gen/nlist_elf32.c b/lib/libc/gen/nlist_elf32.c index 7658f31a6..104504ea2 100644 --- a/lib/libc/gen/nlist_elf32.c +++ b/lib/libc/gen/nlist_elf32.c @@ -1,4 +1,4 @@ -/* $NetBSD: nlist_elf32.c,v 1.32 2010/08/28 21:30:02 joerg Exp $ */ +/* $NetBSD: nlist_elf32.c,v 1.35 2012/03/21 02:18:14 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou @@ -36,7 +36,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: nlist_elf32.c,v 1.32 2010/08/28 21:30:02 joerg Exp $"); +__RCSID("$NetBSD: nlist_elf32.c,v 1.35 2012/03/21 02:18:14 christos Exp $"); #endif /* LIBC_SCCS and not lint */ /* If not included by nlist_elf64.c, ELFSIZE won't be defined. */ @@ -73,34 +73,35 @@ __RCSID("$NetBSD: nlist_elf32.c,v 1.32 2010/08/28 21:30:02 joerg Exp $"); #define BADUNMAP goto unmap int -ELFNAMEEND(__fdnlist)(fd, list) - int fd; - struct nlist *list; +ELFNAMEEND(__fdnlist)(int fd, struct nlist *list) { struct stat st; - struct nlist *p; - char *mappedfile, *strtab; - size_t mappedsize; - Elf_Ehdr *ehdrp, ehdr; - Elf_Shdr *shdrp, *symshdrp, *symstrshdrp; - Elf_Sym *symp; - Elf_Off shdr_off; - Elf_Word shdr_size; + Elf_Ehdr ehdr; +#if _LP64 || ELFSIZE == 32 #if (ELFSIZE == 32) Elf32_Half nshdr; #elif (ELFSIZE == 64) Elf64_Word nshdr; #endif - size_t i, nsyms; - int rv, nent; + /* Only support 64+32 mode on LP64; no support for 64 mode on ILP32 */ + Elf_Ehdr *ehdrp; + Elf_Shdr *shdrp, *symshdrp, *symstrshdrp; + Elf_Sym *symp; + Elf_Off shdr_off; + Elf_Word shdr_size; + struct nlist *p; + char *mappedfile, *strtab; + size_t mappedsize, nsyms; + int nent; +#endif + int rv; + size_t i; _DIAGASSERT(fd != -1); _DIAGASSERT(list != NULL); rv = -1; - symshdrp = symstrshdrp = NULL; - /* * If we can't fstat() the file, something bad is going on. */ @@ -136,7 +137,10 @@ ELFNAMEEND(__fdnlist)(fd, list) default: BAD; } +#if _LP64 || ELFSIZE == 32 + symshdrp = symstrshdrp = NULL; + /* Only support 64+32 mode on LP64; no support for 64 mode on ILP32 */ if (S_ISCHR(st.st_mode)) { const char *nlistname; struct ksyms_gsymbol kg; @@ -157,11 +161,12 @@ ELFNAMEEND(__fdnlist)(fd, list) kg.kg_name = nlistname; kg.kg_sym = &sym; if (ioctl(fd, KIOCGSYMBOL, &kg) == 0) { - p->n_value = sym.st_value; + p->n_value = (uintptr_t)sym.st_value; switch (ELF_ST_TYPE(sym.st_info)) { case STT_NOTYPE: p->n_type = N_UNDF; break; + case STT_COMMON: case STT_OBJECT: p->n_type = N_DATA; break; @@ -212,7 +217,7 @@ ELFNAMEEND(__fdnlist)(fd, list) if (check(shdr_off, shdr_size) || (sizeof *shdrp != ehdrp->e_shentsize)) BADUNMAP; - shdrp = (Elf_Shdr *)(void *)&mappedfile[shdr_off]; + shdrp = (void *)&mappedfile[(size_t)shdr_off]; for (i = 0; i < nshdr; i++) { if (shdrp[i].sh_type == SHT_SYMTAB) { @@ -231,9 +236,9 @@ ELFNAMEEND(__fdnlist)(fd, list) if (check(symstrshdrp->sh_offset, symstrshdrp->sh_size)) BADUNMAP; - symp = (Elf_Sym *)(void *)&mappedfile[symshdrp->sh_offset]; - nsyms = symshdrp->sh_size / sizeof(*symp); - strtab = &mappedfile[symstrshdrp->sh_offset]; + symp = (void *)&mappedfile[(size_t)symshdrp->sh_offset]; + nsyms = (size_t)(symshdrp->sh_size / sizeof(*symp)); + strtab = &mappedfile[(size_t)symstrshdrp->sh_offset]; /* * Clean out any left-over information for all valid entries. @@ -268,12 +273,13 @@ ELFNAMEEND(__fdnlist)(fd, list) /* * Translate (roughly) from ELF to nlist */ - p->n_value = symp[i].st_value; + p->n_value = (uintptr_t)symp[i].st_value; switch (ELF_ST_TYPE(symp[i].st_info)) { case STT_NOTYPE: p->n_type = N_UNDF; break; case STT_OBJECT: + case STT_COMMON: p->n_type = N_DATA; break; case STT_FUNC: @@ -302,6 +308,7 @@ done: rv = nent; unmap: munmap(mappedfile, mappedsize); +#endif /* _LP64 || ELFSIZE == 32 */ out: return (rv); } diff --git a/lib/libc/gen/nlist_private.h b/lib/libc/gen/nlist_private.h index 485fc4de6..d9de46b20 100644 --- a/lib/libc/gen/nlist_private.h +++ b/lib/libc/gen/nlist_private.h @@ -1,4 +1,4 @@ -/* $NetBSD: nlist_private.h,v 1.21 2011/01/17 23:32:31 matt Exp $ */ +/* $NetBSD: nlist_private.h,v 1.22 2012/03/20 16:36:05 matt Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou @@ -74,17 +74,17 @@ struct nlist; #ifdef NLIST_AOUT -int __fdnlist_aout __P((int, struct nlist *)); +int __fdnlist_aout(int, struct nlist *); #endif #ifdef NLIST_COFF -int __fdnlist_coff __P((int, struct nlist *)); +int __fdnlist_coff(int, struct nlist *); #endif #ifdef NLIST_ECOFF -int __fdnlist_ecoff __P((int, struct nlist *)); +int __fdnlist_ecoff(int, struct nlist *); #endif #ifdef NLIST_ELF32 -int __fdnlist_elf32 __P((int, struct nlist *)); +int __fdnlist_elf32(int, struct nlist *); #endif #ifdef NLIST_ELF64 -int __fdnlist_elf64 __P((int, struct nlist *)); +int __fdnlist_elf64(int, struct nlist *); #endif diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index 55e8acedb..76845017a 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -1,4 +1,4 @@ -/* $NetBSD: opendir.c,v 1.37 2010/09/26 02:26:59 yamt Exp $ */ +/* $NetBSD: opendir.c,v 1.38 2011/10/15 23:00:01 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)opendir.c 8.7 (Berkeley) 12/10/94"; #else -__RCSID("$NetBSD: opendir.c,v 1.37 2010/09/26 02:26:59 yamt Exp $"); +__RCSID("$NetBSD: opendir.c,v 1.38 2011/10/15 23:00:01 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -44,6 +44,11 @@ __RCSID("$NetBSD: opendir.c,v 1.37 2010/09/26 02:26:59 yamt Exp $"); #ifdef __minix #include #include + +#if !defined(O_CLOEXEC) +#define O_CLOEXEC 0 +#endif + #endif #include "extern.h" @@ -83,8 +88,15 @@ __opendir2(const char *name, int flags) { int fd; - if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1) + if ((fd = open(name, O_RDONLY | O_NONBLOCK | O_CLOEXEC)) == -1) return NULL; +#if defined(__minix) + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { + close(fd); + return NULL; + } +#endif /* defined(__minix) */ + return __opendir_common(fd, name, flags); } @@ -92,6 +104,8 @@ __opendir2(const char *name, int flags) DIR * _fdopendir(int fd) { + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) + return NULL; return __opendir_common(fd, NULL, DTF_HIDEW|DTF_NODUP); } @@ -108,13 +122,11 @@ __opendir_common(int fd, const char *name, int flags) #endif int error; - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) - goto error; if (fstat(fd, &sb) || !S_ISDIR(sb.st_mode)) { errno = ENOTDIR; goto error; } - if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) + if ((dirp = malloc(sizeof(*dirp))) == NULL) goto error; dirp->dd_buf = NULL; dirp->dd_internal = NULL; diff --git a/lib/libc/gen/pause.c b/lib/libc/gen/pause.c index f11547a49..06414c54e 100644 --- a/lib/libc/gen/pause.c +++ b/lib/libc/gen/pause.c @@ -1,4 +1,4 @@ -/* $NetBSD: pause.c,v 1.10 2003/08/07 16:42:55 agc Exp $ */ +/* $NetBSD: pause.c,v 1.11 2012/06/24 15:26:03 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)pause.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: pause.c,v 1.10 2003/08/07 16:42:55 agc Exp $"); +__RCSID("$NetBSD: pause.c,v 1.11 2012/06/24 15:26:03 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,7 +50,7 @@ __weak_alias(pause,_pause) * Backwards compatible pause. */ int -pause() +pause(void) { sigset_t omask; diff --git a/lib/libc/gen/popen.3 b/lib/libc/gen/popen.3 index d5cf7bb28..84009044c 100644 --- a/lib/libc/gen/popen.3 +++ b/lib/libc/gen/popen.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: popen.3,v 1.16 2007/08/02 23:45:10 wiz Exp $ +.\" $NetBSD: popen.3,v 1.18 2011/06/27 08:21:07 wiz Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)popen.3 8.2 (Berkeley) 5/3/95 .\" -.Dd August 2, 2007 +.Dd June 24, 2011 .Dt POPEN 3 .Os .Sh NAME @@ -76,6 +76,12 @@ for reading, for writing, or .Ql r+ for reading and writing. +In addition if the character +.Ql e +is present in the +.Fa type +string, the file descriptor used internally is set to be closed on +.Xr exec 3 . .Pp The .Fa command diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c index edd85d5d0..aa58d8493 100644 --- a/lib/libc/gen/popen.c +++ b/lib/libc/gen/popen.c @@ -1,4 +1,4 @@ -/* $NetBSD: popen.c,v 1.30 2010/11/14 18:11:42 tron Exp $ */ +/* $NetBSD: popen.c,v 1.32 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1988, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95"; #else -__RCSID("$NetBSD: popen.c,v 1.30 2010/11/14 18:11:42 tron Exp $"); +__RCSID("$NetBSD: popen.c,v 1.32 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,10 +54,15 @@ __RCSID("$NetBSD: popen.c,v 1.30 2010/11/14 18:11:42 tron Exp $"); #include #include #include +#include #include "env.h" #include "reentrant.h" +#if defined(__minix) && !defined(O_CLOEXEC) +#define O_CLOEXEC 0 +#endif + #ifdef __weak_alias __weak_alias(popen,_popen) __weak_alias(pclose,_pclose) @@ -84,22 +89,23 @@ popen(const char *command, const char *type) const char * volatile xtype = type; int pdes[2], pid, serrno; volatile int twoway; + int flags; _DIAGASSERT(command != NULL); _DIAGASSERT(xtype != NULL); + flags = strchr(xtype, 'e') ? O_CLOEXEC : 0; if (strchr(xtype, '+')) { + int stype = flags ? (SOCK_STREAM | SOCK_CLOEXEC) : SOCK_STREAM; twoway = 1; - type = "r+"; - if (socketpair(AF_LOCAL, SOCK_STREAM, 0, pdes) < 0) - return (NULL); + xtype = "r+"; + if (socketpair(AF_LOCAL, stype, 0, pdes) < 0) + return NULL; } else { twoway = 0; - if ((*xtype != 'r' && *xtype != 'w') || xtype[1] || - (pipe(pdes) < 0)) { - errno = EINVAL; - return (NULL); - } + xtype = strrchr(xtype, 'r') ? "r" : "w"; + if (pipe2(pdes, flags) == -1) + return NULL; } if ((cur = malloc(sizeof(struct pid))) == NULL) { @@ -186,8 +192,7 @@ popen(const char *command, const char *type) * if already `pclosed', or waitpid returns an error. */ int -pclose(iop) - FILE *iop; +pclose(FILE *iop) { struct pid *cur, *last; int pstat; diff --git a/lib/libc/gen/posix_spawn.3 b/lib/libc/gen/posix_spawn.3 new file mode 100644 index 000000000..9e7eb47d0 --- /dev/null +++ b/lib/libc/gen/posix_spawn.3 @@ -0,0 +1,473 @@ +.\" $NetBSD: posix_spawn.3,v 1.3 2012/03/23 18:08:34 njoly Exp $ +.\" +.\" Copyright (c) 2008 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- +.\" Portable Operating System Interface (POSIX), The Open Group Base +.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of +.\" Electrical and Electronics Engineers, Inc and The Open Group. In the +.\" event of any discrepancy between this version and the original IEEE and +.\" The Open Group Standard, the original IEEE and The Open Group Standard is +.\" the referee document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" $FreeBSD: src/lib/libc/gen/posix_spawn.3,v 1.2.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ +.\" +.Dd December 20, 2011 +.Dt POSIX_SPAWN 3 +.Os +.Sh NAME +.Nm posix_spawn , +.Nm posix_spawnp +.Nd "spawn a process" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In spawn.h +.Ft int +.Fn posix_spawn "pid_t *restrict pid" "const char *restrict path" "const posix_spawn_file_actions_t *file_actions" "const posix_spawnattr_t *restrict attrp" "char *const argv[restrict]" "char *const envp[restrict]" +.Ft int +.Fn posix_spawnp "pid_t *restrict pid" "const char *restrict file" "const posix_spawn_file_actions_t *file_actions" "const posix_spawnattr_t *restrict attrp" "char *const argv[restrict]" "char *const envp[restrict]" +.Sh DESCRIPTION +The +.Fn posix_spawn +and +.Fn posix_spawnp +functions create a new process (child process) from the specified +process image. +The new process image is constructed from a regular executable +file called the new process image file. +.Pp +When a C program is executed as the result of this call, it is +entered as a C-language function call as follows: +.Bd -literal -offset indent +int main(int argc, char *argv[]); +.Ed +.Pp +where +.Fa argc +is the argument count and +.Fa argv +is an array of character pointers to the arguments themselves. +In addition, the variable: +.Bd -literal -offset indent +extern char **environ; +.Ed +.Pp +points to an array of character pointers to +the environment strings. +.Pp +The argument +.Fa argv +is an array of character pointers to null-terminated +strings. +The last member of this array is a null pointer and is not counted +in +.Fa argc . +These strings constitute the argument list available to the new process +image. +The value in +.Fa argv Ns [0] +should point to +a filename that is associated with the process image being started by +the +.Fn posix_spawn +or +.Fn posix_spawnp +function. +.Pp +The argument +.Fa envp +is an array of character pointers to null-terminated strings. +These strings constitute the environment for the new process image. +The environment array is terminated by a null pointer. +.Pp +The +.Fa path +argument to +.Fn posix_spawn +is a pathname that identifies the new process image file to execute. +.Pp +The +.Fa file +parameter to +.Fn posix_spawnp +is used to construct a pathname that identifies the new process +image file. +If the file parameter contains a slash character, the file parameter +is used as the pathname for the new process image file. +Otherwise, the path prefix for this file is obtained by a search +of the directories passed as the environment variable +.Dq Ev PATH . +If this variable is not specified, +the default path is set according to the +.Dv _PATH_DEFPATH +definition in +.In paths.h , +which is set to +.Dq Ev /usr/bin:/bin . +.Pp +If +.Fa file_actions +is a null pointer, then file descriptors open in the +calling process remain open in the child process, except for those +whose close-on-exec flag +.Dv FD_CLOEXEC +is set (see +.Fn fcntl ) . +For those +file descriptors that remain open, all attributes of the corresponding +open file descriptions, including file locks (see +.Fn fcntl ) , +remain unchanged. +.Pp +If +.Fa file_actions +is not +.Dv NULL , +then the file descriptors open in the child process are +those open in the calling process as modified by the spawn file +actions object pointed to by +.Fa file_actions +and the +.Dv FD_CLOEXEC +flag of each remaining open file descriptor after the spawn file actions +have been processed. +The effective order of processing the spawn file actions are: +.Bl -enum +.It +The set of open file descriptors for the child process initially +are the same set as is open for the calling process. +All attributes of the corresponding open file descriptions, including +file locks (see +.Fn fcntl ) , +remain unchanged. +.It +The signal mask, signal default actions, and the effective user and +group IDs for the child process are changed as specified in the +attributes object referenced by +.Fa attrp . +.It +The file actions specified by the spawn file actions object are +performed in the order in which they were added to the spawn file +actions object. +.It +Any file descriptor that has its +.Dv FD_CLOEXEC +flag set (see +.Fn fcntl ) +is closed. +.El +.Pp +The +.Vt posix_spawnattr_t +spawn attributes object type is defined in +.In spawn.h . +It contains the attributes defined below. +.Pp +If the +.Dv POSIX_SPAWN_SETPGROUP +flag is set in the spawn-flags attribute of the object referenced by +.Fa attrp , +and the spawn-pgroup attribute of the same object is non-zero, then the +child's process group is as specified in the spawn-pgroup +attribute of the object referenced by +.Fa attrp . +.Pp +As a special case, if the +.Dv POSIX_SPAWN_SETPGROUP +flag is set in the spawn-flags attribute of the object referenced by +.Fa attrp , +and the spawn-pgroup attribute of the same object is set to zero, then +the child is in a new process group with a process group ID equal +to its process ID. +.Pp +If the +.Dv POSIX_SPAWN_SETPGROUP +flag is not set in the spawn-flags attribute of the object referenced by +.Fa attrp , +the new child process inherits the parent's process group. +.Pp +If the +.Dv POSIX_SPAWN_SETSCHEDPARAM +flag is set in the spawn-flags attribute of the object referenced by +.Fa attrp , +but +.Dv POSIX_SPAWN_SETSCHEDULER +is not set, the new process image initially has the scheduling +policy of the calling process with the scheduling parameters specified +in the spawn-schedparam attribute of the object referenced by +.Fa attrp . +.Pp +If the +.Dv POSIX_SPAWN_SETSCHEDULER +flag is set in the spawn-flags attribute of the object referenced by +.Fa attrp +(regardless of the setting of the +.Dv POSIX_SPAWN_SETSCHEDPARAM +flag), the new process image initially has the scheduling policy +specified in the spawn-schedpolicy attribute of the object referenced by +.Fa attrp +and the scheduling parameters specified in the spawn-schedparam +attribute of the same object. +.Pp +The +.Dv POSIX_SPAWN_RESETIDS +flag in the spawn-flags attribute of the object referenced by +.Fa attrp +governs the effective user ID of the child process. +If this flag is not set, the child process inherits the parent +process' effective user ID. +If this flag is set, the child process' effective user ID is reset +to the parent's real user ID. +In either case, if the set-user-ID mode bit of the new process image +file is set, the effective user ID of the child process becomes +that file's owner ID before the new process image begins execution. +.Pp +The +.Dv POSIX_SPAWN_RESETIDS +flag in the spawn-flags attribute of the object referenced by +.Fa attrp +also governs the effective group ID of the child process. +If this flag is not set, the child process inherits the parent +process' effective group ID. +If this flag is set, the child process' effective group ID is +reset to the parent's real group ID. +In either case, if the set-group-ID mode bit of the new process image +file is set, the effective group ID of the child process becomes +that file's group ID before the new process image begins execution. +.Pp +If the +.Dv POSIX_SPAWN_SETSIGMASK +flag is set in the spawn-flags attribute of the object referenced by +.Fa attrp , +the child process initially has the signal mask specified in the +spawn-sigmask attribute of the object referenced by +.Fa attrp . +.Pp +If the +.Dv POSIX_SPAWN_SETSIGDEF +flag is set in the spawn-flags attribute of the object referenced by +.Fa attrp , +the signals specified in the spawn-sigdefault attribute of the same +object is set to their default actions in the child process. +Signals set to the default action in the parent process is set to +the default action in the child process. +.Pp +Signals set to be caught by the calling process is set to the +default action in the child process. +.Pp +Signals set to be ignored by the calling process image is set to +be ignored by the child process, unless otherwise specified by the +.Dv POSIX_SPAWN_SETSIGDEF +flag being set in the spawn-flags attribute of the object referenced by +.Fa attrp +and the signals being indicated in the spawn-sigdefault attribute +of the object referenced by +.Fa attrp . +.Pp +If the value of the +.Fa attrp +pointer is +.Dv NULL , +then the default values are used. +.Pp +All process attributes, other than those influenced by the attributes +set in the object referenced by +.Fa attrp +as specified above or by the file descriptor manipulations specified in +.Fa file_actions , +appear in the new process image as though +.Fn vfork +had been called to create a child process and then +.Fn execve +had been called by the child process to execute the new process image. +.Pp +The implementation uses vfork(), thus the fork handlers are not run when +.Fn posix_spawn +or +.Fn posix_spawnp +is called. +.Sh RETURN VALUES +Upon successful completion, +.Fn posix_spawn +and +.Fn posix_spawnp +return the process ID of the child process to the parent process, +in the variable pointed to by a +.Pf non- Dv NULL +.Fa pid +argument, and return zero as the function return value. +Otherwise, no child process is created, no value is stored into +the variable pointed to by +.Fa pid , +and an error number is returned as the function return value to +indicate the error. +If the +.Fa pid +argument is a null pointer, the process ID of the child is not returned +to the caller. +.Sh ERRORS +.Bl -enum +.It +If +.Fn posix_spawn +and +.Fn posix_spawnp +fail for any of the reasons that would cause +.Fn vfork +or one of the +.Nm exec +to fail, an error value is returned as described by +.Fn vfork +and +.Nm exec , +respectively (or, if the error occurs after the calling process successfully +returns, the child process exits with exit status 127). +.It +If +.Nm POSIX_SPAWN_SETPGROUP +is set in the spawn-flags attribute of the object referenced by attrp, and +.Fn posix_spawn +or +.Fn posix_spawnp +fails while changing the child's process group, an error value is returned as +described by +.Fn setpgid +(or, if the error occurs after the calling process successfully returns, +the child process exits with exit status 127). +.It +If +.Nm POSIX_SPAWN_SETSCHEDPARAM +is set and +.Nm POSIX_SPAWN_SETSCHEDULER +is not set in the spawn-flags attribute of the object referenced by attrp, then +if +.Fn posix_spawn +or +.Fn posix_spawnp +fails for any of the reasons that would cause +.Fn sched_setparam +to fail, an error value is returned as described by +.Fn sched_setparam +(or, if the error occurs after the calling process successfully returns, the +child process exits with exit status 127). +.It +If +.Nm POSIX_SPAWN_SETSCHEDULER +is set in the spawn-flags attribute of the object referenced by attrp, and if +.Fn posix_spawn +or +.Fn posix_spawnp +fails for any of the reasons that would cause +.Fn sched_setscheduler +to fail, an error value is returned as described by +.Fn sched_setscheduler +(or, if the error occurs after the calling process successfully returns, +the child process exits with exit status 127). +.It +If the +.Fa file_actions +argument is not +.Dv NULL , +and specifies any +.Fn close , +.Fn dup2 , +or +.Fn open +actions to be performed, and if +.Fn posix_spawn +or +.Fn posix_spawnp +fails for any of the reasons that would cause +.Fn close , +.Fn dup2 , +or +.Fn open +to fail, an error value is returned as described by +.Fn close , +.Fn dup2 , +and +.Fn open , +respectively (or, if the error occurs after the calling process successfully +returns, the child process exits with exit status 127). An open file action +may, by itself, result in any of the errors described by +.Fn close +or +.Fn dup2 , +in addition to those described by +.Fn open . +.El +.Sh SEE ALSO +.Xr close 2 , +.Xr dup2 2 , +.Xr execve 2 , +.Xr fcntl 2 , +.Xr open 2 , +.Xr setpgid 2 , +.Xr vfork 2 , +.Xr posix_spawn_file_actions_addclose 3 , +.Xr posix_spawn_file_actions_adddup2 3 , +.Xr posix_spawn_file_actions_addopen 3 , +.Xr posix_spawn_file_actions_destroy 3 , +.Xr posix_spawn_file_actions_init 3 , +.Xr posix_spawnattr_destroy 3 , +.Xr posix_spawnattr_getflags 3 , +.Xr posix_spawnattr_getpgroup 3 , +.Xr posix_spawnattr_getschedparam 3 , +.Xr posix_spawnattr_getschedpolicy 3 , +.Xr posix_spawnattr_getsigdefault 3 , +.Xr posix_spawnattr_getsigmask 3 , +.Xr posix_spawnattr_init 3 , +.Xr posix_spawnattr_setflags 3 , +.Xr posix_spawnattr_setpgroup 3 , +.Xr posix_spawnattr_setschedparam 3 , +.Xr posix_spawnattr_setschedpolicy 3 , +.Xr posix_spawnattr_setsigdefault 3 , +.Xr posix_spawnattr_setsigmask 3 , +.Xr sched_setparam 3 , +.Xr sched_setscheduler 3 +.Sh STANDARDS +The +.Fn posix_spawn +and +.Fn posix_spawnp +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn posix_spawn +and +.Fn posix_spawnp +functions first appeared in +.Fx 8.0 . +The library parts were ported and a kernel implementation of +.Fn posix_spawn +added for +.Nx 6.0 +during Google Summer of Code by Charles Zhang and Martin Husemann. +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libc/gen/posix_spawn_file_actions_addopen.3 b/lib/libc/gen/posix_spawn_file_actions_addopen.3 new file mode 100644 index 000000000..1fcddae8f --- /dev/null +++ b/lib/libc/gen/posix_spawn_file_actions_addopen.3 @@ -0,0 +1,186 @@ +.\" $NetBSD: posix_spawn_file_actions_addopen.3,v 1.2 2012/03/23 18:08:34 njoly Exp $ +.\" +.\" Copyright (c) 2008 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- +.\" Portable Operating System Interface (POSIX), The Open Group Base +.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of +.\" Electrical and Electronics Engineers, Inc and The Open Group. In the +.\" event of any discrepancy between this version and the original IEEE and +.\" The Open Group Standard, the original IEEE and The Open Group Standard is +.\" the referee document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" $FreeBSD: src/lib/libc/gen/posix_spawn_file_actions_addopen.3,v 1.2.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ +.\" +.Dd December 20, 2011 +.Dt POSIX_SPAWN_FILE_ACTIONS_ADDOPEN 3 +.Os +.Sh NAME +.Nm posix_spawn_file_actions_addopen , +.Nm posix_spawn_file_actions_adddup2 , +.Nm posix_spawn_file_actions_addclose +.Nd "add open, dup2 or close action to spawn file actions object" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In spawn.h +.Ft int +.Fn posix_spawn_file_actions_addopen "posix_spawn_file_actions_t * file_actions" "int fildes" "const char *restrict path" "int oflag" "mode_t mode" +.Ft int +.Fn posix_spawn_file_actions_adddup2 "posix_spawn_file_actions_t * file_actions" "int fildes" "int newfildes" +.Ft int +.Fn posix_spawn_file_actions_addclose "posix_spawn_file_actions_t * file_actions" "int fildes" +.Sh DESCRIPTION +These functions add an open, dup2 or close action to a spawn +file actions object. +.Pp +A spawn file actions object is of type +.Vt posix_spawn_file_actions_t +(defined in +.In spawn.h ) +and is used to specify a series of actions to be performed by a +.Fn posix_spawn +or +.Fn posix_spawnp +operation in order to arrive at the set of open file descriptors for the +child process given the set of open file descriptors of the parent. +.Pp +A spawn file actions object, when passed to +.Fn posix_spawn +or +.Fn posix_spawnp , +specify how the set of open file descriptors in the calling +process is transformed into a set of potentially open file descriptors +for the spawned process. +This transformation is as if the specified sequence of actions was +performed exactly once, in the context of the spawned process (prior to +execution of the new process image), in the order in which the actions +were added to the object; additionally, when the new process image is +executed, any file descriptor (from this new set) which has its +.Dv FD_CLOEXEC +flag set is closed (see +.Fn posix_spawn ) . +.Pp +The +.Fn posix_spawn_file_actions_addopen +function adds an open action to the object referenced by +.Fa file_actions +that causes the file named by +.Fa path +to be opened (as if +.Bd -literal -offset indent +open(path, oflag, mode) +.Ed +.Pp +had been called, and the returned file descriptor, if not +.Fa fildes , +had been changed to +.Fa fildes ) +when a new process is spawned using this file actions object. +If +.Fa fildes +was already an open file descriptor, it is closed before the new +file is opened. +.Pp +The string described by +.Fa path +is copied by the +.Fn posix_spawn_file_actions_addopen +function. +.Pp +The +.Fn posix_spawn_file_actions_adddup2 +function adds a dup2 action to the object referenced by +.Fa file_actions +that causes the file descriptor +.Fa fildes +to be duplicated as +.Fa newfildes +(as if +.Bd -literal -offset indent +dup2(fildes, newfildes) +.Ed +.Pp +had been called) when a new process is spawned using this file actions object. +.Pp +The +.Fn posix_spawn_file_actions_addclose +function adds a close action to the object referenced by +.Fa file_actions +that causes the file descriptor +.Fa fildes +to be closed (as if +.Bd -literal -offset indent +close(fildes) +.Ed +.Pp +had been called) when a new process is spawned using this file actions +object. +.Sh RETURN VALUES +Upon successful completion, these functions return zero; +otherwise, an error number is returned to indicate the error. +.Sh ERRORS +These +functions fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The value specified by +.Fa fildes +or +.Fa newfildes +is negative. +.It Bq Er ENOMEM +Insufficient memory exists to add to the spawn file actions object. +.El +.Sh SEE ALSO +.Xr close 2 , +.Xr dup2 2 , +.Xr open 2 , +.Xr posix_spawn 3 , +.Xr posix_spawn_file_actions_destroy 3 , +.Xr posix_spawn_file_actions_init 3 , +.Xr posix_spawnp 3 +.Sh STANDARDS +The +.Fn posix_spawn_file_actions_addopen , +.Fn posix_spawn_file_actions_adddup2 +and +.Fn posix_spawn_file_actions_addclose +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn posix_spawn_file_actions_addopen , +.Fn posix_spawn_file_actions_adddup2 +and +.Fn posix_spawn_file_actions_addclose +functions first appeared in +.Fx 8.0 +and imported for +.Nx 6.0 . +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libc/gen/posix_spawn_file_actions_init.3 b/lib/libc/gen/posix_spawn_file_actions_init.3 new file mode 100644 index 000000000..55879b84a --- /dev/null +++ b/lib/libc/gen/posix_spawn_file_actions_init.3 @@ -0,0 +1,108 @@ +.\" $NetBSD: posix_spawn_file_actions_init.3,v 1.2 2012/03/23 18:08:34 njoly Exp $ +.\" +.\" Copyright (c) 2008 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- +.\" Portable Operating System Interface (POSIX), The Open Group Base +.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of +.\" Electrical and Electronics Engineers, Inc and The Open Group. In the +.\" event of any discrepancy between this version and the original IEEE and +.\" The Open Group Standard, the original IEEE and The Open Group Standard is +.\" the referee document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" $FreeBSD: src/lib/libc/gen/posix_spawn_file_actions_init.3,v 1.1.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ +.\" +.Dd December 20, 2011 +.Dt POSIX_SPAWN_FILE_ACTIONS_INIT 3 +.Os +.Sh NAME +.Nm posix_spawn_file_actions_init , +.Nm posix_spawn_file_actions_destroy +.Nd "initialize and destroy spawn file actions object" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In spawn.h +.Ft int +.Fn posix_spawn_file_actions_init "posix_spawn_file_actions_t * file_actions" +.Ft int +.Fn posix_spawn_file_actions_destroy "posix_spawn_file_actions_t * file_actions" +.Sh DESCRIPTION +The +.Fn posix_spawn_file_actions_init +function initialize the object referenced by +.Fn file_actions +to contain no file actions for +.Fn posix_spawn +or +.Fn posix_spawnp . +Initializing an already initialized spawn file actions object may cause +memory to be leaked. +.Pp +The +.Fn posix_spawn_file_actions_destroy +function destroy the object referenced by +.Fa file_actions ; +the object becomes, in effect, uninitialized. +A destroyed spawn file actions object can be reinitialized using +.Fn posix_spawn_file_actions_init . +The object should not be used after it has been destroyed. +.Sh RETURN VALUES +Upon successful completion, these functions return zero; +otherwise, an error number is returned to indicate the error. +.Sh ERRORS +The +.Fn posix_spawn_file_actions_init +function will fail if: +.Bl -tag -width Er +.It Bq Er ENOMEM +Insufficient memory exists to initialize the spawn file actions object. +.El +.Sh SEE ALSO +.Xr posix_spawn 3 , +.Xr posix_spawn_file_actions_addclose 3 , +.Xr posix_spawn_file_actions_adddup2 3 , +.Xr posix_spawn_file_actions_addopen 3 , +.Xr posix_spawnp 3 +.Sh STANDARDS +The +.Fn posix_spawn_file_actions_init +and +.Fn posix_spawn_file_actions_destroy +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn posix_spawn_file_actions_init +and +.Fn posix_spawn_file_actions_destroy +functions first appeared in +.Fx 8.0 +and imported for +.Nx 6.0 . +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libc/gen/posix_spawn_fileactions.c b/lib/libc/gen/posix_spawn_fileactions.c new file mode 100644 index 000000000..0455934f5 --- /dev/null +++ b/lib/libc/gen/posix_spawn_fileactions.c @@ -0,0 +1,166 @@ +/*- + * Copyright (c) 2008 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__RCSID("$NetBSD: posix_spawn_fileactions.c,v 1.2 2012/04/08 11:27:44 martin Exp $"); + +#include "namespace.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MIN_SIZE 16 + +/* + * File descriptor actions + */ + +int +posix_spawn_file_actions_init(posix_spawn_file_actions_t *fa) +{ + if (fa == NULL) + return (-1); + + fa->fae = malloc(MIN_SIZE * sizeof(struct posix_spawn_file_actions_entry)); + if (fa->fae == NULL) + return (-1); + fa->size = MIN_SIZE; + fa->len = 0; + + return (0); +} + +int +posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *fa) +{ + unsigned int i; + + if (fa == NULL) + return (-1); + + for (i = 0; i < fa->len; i++) { + if (fa->fae[i].fae_action == FAE_OPEN) + free(fa->fae[i].fae_path); + } + + free(fa->fae); + return (0); +} + +static int +posix_spawn_file_actions_getentry(posix_spawn_file_actions_t *fa) +{ + if (fa == NULL) + return -1; + + if (fa->len < fa->size) + return fa->len; + + fa->fae = realloc(fa->fae, (fa->size + MIN_SIZE) * + sizeof(struct posix_spawn_file_actions_entry)); + + if (fa->fae == NULL) + return -1; + + fa->size += MIN_SIZE; + + return fa->len; +} + +int +posix_spawn_file_actions_addopen(posix_spawn_file_actions_t * __restrict fa, + int fildes, const char * __restrict path, int oflag, mode_t mode) +{ + int i, error; + + if (fildes < 0) + return (EBADF); + + i = posix_spawn_file_actions_getentry(fa); + if (i < 0) + return (ENOMEM); + + fa->fae[i].fae_action = FAE_OPEN; + fa->fae[i].fae_path = strdup(path); + if (fa->fae[i].fae_path == NULL) { + error = errno; + return (error); + } + fa->fae[i].fae_fildes = fildes; + fa->fae[i].fae_oflag = oflag; + fa->fae[i].fae_mode = mode; + + fa->len++; + + return (0); +} + +int +posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, + int fildes, int newfildes) +{ + int i; + + if (fildes < 0 || newfildes < 0) + return (EBADF); + + i = posix_spawn_file_actions_getentry(fa); + if (i < 0) + return (ENOMEM); + + fa->fae[i].fae_action = FAE_DUP2; + fa->fae[i].fae_fildes = fildes; + fa->fae[i].fae_newfildes = newfildes; + fa->len++; + + return (0); +} + +int +posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, + int fildes) +{ + int i; + + if (fildes < 0) + return (EBADF); + + i = posix_spawn_file_actions_getentry(fa); + if (i < 0) + return (ENOMEM); + + fa->fae[i].fae_action = FAE_CLOSE; + fa->fae[i].fae_fildes = fildes; + fa->len++; + + return (0); +} diff --git a/lib/libc/gen/posix_spawn_sched.c b/lib/libc/gen/posix_spawn_sched.c new file mode 100644 index 000000000..d3cc341a8 --- /dev/null +++ b/lib/libc/gen/posix_spawn_sched.c @@ -0,0 +1,155 @@ +/*- + * Copyright (c) 2008 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__RCSID("$NetBSD: posix_spawn_sched.c,v 1.1 2012/02/11 23:31:24 martin Exp $"); + +#include "namespace.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Spawn attributes + */ + +int +posix_spawnattr_init(posix_spawnattr_t *ret) +{ + if (ret == NULL) + return -1; + + memset(ret, 0, sizeof(posix_spawnattr_t)); + return (0); +} + +int +posix_spawnattr_destroy(posix_spawnattr_t *sa) +{ + if (sa == NULL) + return -1; + + return (0); +} + +int +posix_spawnattr_getflags(const posix_spawnattr_t * __restrict sa, + short * __restrict flags) +{ + *flags = sa->sa_flags; + return (0); +} + +int +posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict sa, + pid_t * __restrict pgroup) +{ + *pgroup = sa->sa_pgroup; + return (0); +} + +int +posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict sa, + struct sched_param * __restrict schedparam) +{ + *schedparam = sa->sa_schedparam; + return (0); +} + +int +posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict sa, + int * __restrict schedpolicy) +{ + *schedpolicy = sa->sa_schedpolicy; + return (0); +} + +int +posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict sa, + sigset_t * __restrict sigdefault) +{ + *sigdefault = sa->sa_sigdefault; + return (0); +} + +int +posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict sa, + sigset_t * __restrict sigmask) +{ + *sigmask = sa->sa_sigmask; + return (0); +} + +int +posix_spawnattr_setflags(posix_spawnattr_t *sa, short flags) +{ + sa->sa_flags = flags; + return (0); +} + +int +posix_spawnattr_setpgroup(posix_spawnattr_t *sa, pid_t pgroup) +{ + sa->sa_pgroup = pgroup; + return (0); +} + +int +posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict sa, + const struct sched_param * __restrict schedparam) +{ + sa->sa_schedparam = *schedparam; + return (0); +} + +int +posix_spawnattr_setschedpolicy(posix_spawnattr_t *sa, int schedpolicy) +{ + sa->sa_schedpolicy = schedpolicy; + return (0); +} + +int +posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict sa, + const sigset_t * __restrict sigdefault) +{ + sa->sa_sigdefault = *sigdefault; + return (0); +} + +int +posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict sa, + const sigset_t * __restrict sigmask) +{ + sa->sa_sigmask = *sigmask; + return (0); +} diff --git a/lib/libc/gen/posix_spawnattr_getflags.3 b/lib/libc/gen/posix_spawnattr_getflags.3 new file mode 100644 index 000000000..2647f7850 --- /dev/null +++ b/lib/libc/gen/posix_spawnattr_getflags.3 @@ -0,0 +1,115 @@ +.\" $NetBSD: posix_spawnattr_getflags.3,v 1.2 2012/03/23 18:08:34 njoly Exp $ +.\" +.\" Copyright (c) 2008 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- +.\" Portable Operating System Interface (POSIX), The Open Group Base +.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of +.\" Electrical and Electronics Engineers, Inc and The Open Group. In the +.\" event of any discrepancy between this version and the original IEEE and +.\" The Open Group Standard, the original IEEE and The Open Group Standard is +.\" the referee document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" $FreeBSD: src/lib/libc/gen/posix_spawnattr_getflags.3,v 1.1.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ +.\" +.Dd December 20, 2011 +.Dt POSIX_SPAWNATTR_GETFLAGS 3 +.Os +.Sh NAME +.Nm posix_spawnattr_getflags , +.Nm posix_spawnattr_setflags +.Nd "get and set the spawn-flags attribute of a spawn attributes object" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In spawn.h +.Ft int +.Fn posix_spawnattr_getflags "const posix_spawnattr_t *restrict attr" "short *restrict flags" +.Ft int +.Fn posix_spawnattr_setflags "posix_spawnattr_t *attr" "short flags" +.Sh DESCRIPTION +The +.Fn posix_spawnattr_getflags +function obtains the value of the spawn-flags attribute from the +attributes object referenced by +.Fa attr . +.Pp +The +.Fn posix_spawnattr_setflags +function sets the spawn-flags attribute in an initialized +attributes object referenced by +.Fa attr . +.Pp +The spawn-flags attribute is used to indicate which process attributes +are to be changed in the new process image when invoking +.Fn posix_spawn +or +.Fn posix_spawnp . +It is the bitwise-inclusive OR of zero or more of the following flags +(see +.Fn posix_spawn ) : +.Bl -tag -offset indent +.It Dv POSIX_SPAWN_RESETIDS +.It Dv POSIX_SPAWN_SETPGROUP +.It Dv POSIX_SPAWN_SETSIGDEF +.It Dv POSIX_SPAWN_SETSIGMASK +.It Dv POSIX_SPAWN_SETSCHEDPARAM +.It Dv POSIX_SPAWN_SETSCHEDULER +.El +.Pp +These flags are defined in +.In spawn.h . +The default value of this attribute is as if no flags were set. +.Sh RETURN VALUES +The +.Fn posix_spawnattr_getflags +and +.Fn posix_spawnattr_setflags +functions return zero. +.Sh SEE ALSO +.Xr posix_spawn 3 , +.Xr posix_spawnattr_destroy 3 , +.Xr posix_spawnattr_init 3 , +.Xr posix_spawnp 3 +.Sh STANDARDS +The +.Fn posix_spawnattr_getflags +and +.Fn posix_spawnattr_setflags +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn posix_spawnattr_getflags +and +.Fn posix_spawnattr_setflags +functions first appeared in +.Fx 8.0 +and imported for +.Nx 6.0 . +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libc/gen/posix_spawnattr_getpgroup.3 b/lib/libc/gen/posix_spawnattr_getpgroup.3 new file mode 100644 index 000000000..1848efae5 --- /dev/null +++ b/lib/libc/gen/posix_spawnattr_getpgroup.3 @@ -0,0 +1,100 @@ +.\" $NetBSD: posix_spawnattr_getpgroup.3,v 1.2 2012/03/23 18:08:34 njoly Exp $ +.\" +.\" Copyright (c) 2008 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- +.\" Portable Operating System Interface (POSIX), The Open Group Base +.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of +.\" Electrical and Electronics Engineers, Inc and The Open Group. In the +.\" event of any discrepancy between this version and the original IEEE and +.\" The Open Group Standard, the original IEEE and The Open Group Standard is +.\" the referee document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" $FreeBSD: src/lib/libc/gen/posix_spawnattr_getpgroup.3,v 1.1.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ +.\" +.Dd December 20, 2011 +.Dt POSIX_SPAWNATTR_GETPGROUP 3 +.Os +.Sh NAME +.Nm posix_spawnattr_getpgroup , +.Nm posix_spawnattr_setpgroup +.Nd "get and set the spawn-pgroup attribute of a spawn attributes object" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In spawn.h +.Ft int +.Fn posix_spawnattr_getpgroup "const posix_spawnattr_t *restrict attr" "pid_t *restrict pgroup" +.Ft int +.Fn posix_spawnattr_setpgroup "posix_spawnattr_t *attr" "pid_t pgroup" +.Sh DESCRIPTION +The +.Fn posix_spawnattr_getpgroup +function obtains the value of the spawn-pgroup attribute from the +attributes object referenced by +.Fa attr . +.Pp +The +.Fn posix_spawnattr_setpgroup +function sets the spawn-pgroup attribute in an initialized +attributes object referenced by +.Fa attr . +.Pp +The spawn-pgroup attribute represents the process group to be joined by +the new process image in a spawn operation (if +.Dv POSIX_SPAWN_SETPGROUP +is set in the spawn-flags attribute). +The default value of this attribute is zero. +.Sh RETURN VALUES +The +.Fn posix_spawnattr_getpgroup +and +.Fn posix_spawnattr_setpgroup +functions return zero. +.Sh SEE ALSO +.Xr posix_spawn 3 , +.Xr posix_spawnattr_destroy 3 , +.Xr posix_spawnattr_init 3 , +.Xr posix_spawnp 3 +.Sh STANDARDS +The +.Fn posix_spawnattr_getpgroup +and +.Fn posix_spawnattr_setpgroup +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn posix_spawnattr_getpgroup +and +.Fn posix_spawnattr_setpgroup +functions first appeared in +.Fx 8.0 +and imported for +.Nx 6.0 . +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libc/gen/posix_spawnattr_getschedparam.3 b/lib/libc/gen/posix_spawnattr_getschedparam.3 new file mode 100644 index 000000000..9ef519996 --- /dev/null +++ b/lib/libc/gen/posix_spawnattr_getschedparam.3 @@ -0,0 +1,104 @@ +.\" $NetBSD: posix_spawnattr_getschedparam.3,v 1.2 2012/03/23 18:08:34 njoly Exp $ +.\" +.\" Copyright (c) 2008 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- +.\" Portable Operating System Interface (POSIX), The Open Group Base +.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of +.\" Electrical and Electronics Engineers, Inc and The Open Group. In the +.\" event of any discrepancy between this version and the original IEEE and +.\" The Open Group Standard, the original IEEE and The Open Group Standard is +.\" the referee document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" $FreeBSD: src/lib/libc/gen/posix_spawnattr_getschedparam.3,v 1.1.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ +.\" +.Dd December 20, 2011 +.Dt POSIX_SPAWNATTR_GETSCHEDPARAM 3 +.Os +.Sh NAME +.Nm posix_spawnattr_getschedparam , +.Nm posix_spawnattr_setschedparam +.Nd "get and set the spawn-schedparam attribute of a spawn attributes object" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In spawn.h +.Ft int +.Fn posix_spawnattr_getschedparam "const posix_spawnattr_t *restrict attr" "struct sched_param *restrict schedparam" +.Ft int +.Fn posix_spawnattr_setschedparam "posix_spawnattr_t *attr" "const struct sched_param *restrict schedparam" +.Sh DESCRIPTION +The +.Fn posix_spawnattr_getschedparam +function obtains the value of the spawn-schedparam attribute from the +attributes object referenced by +.Fa attr . +.Pp +The +.Fn posix_spawnattr_setschedparam +function sets the spawn-schedparam attribute in an initialized attributes +object referenced by +.Fa attr . +.Pp +The spawn-schedparam attribute represents the scheduling parameters to +be assigned to the new process image in a spawn operation (if +.Dv POSIX_SPAWN_SETSCHEDULER +or +.Dv POSIX_SPAWN_SETSCHEDPARAM +is set in the spawn-flags attribute). +The default value of this attribute is unspecified. +.Sh RETURN VALUES +The +.Fn posix_spawnattr_getschedparam +and +.Fn posix_spawnattr_setschedparam +functions return zero. +.Sh SEE ALSO +.Xr posix_spawn 3 , +.Xr posix_spawnattr_destroy 3 , +.Xr posix_spawnattr_getschedpolicy 3 , +.Xr posix_spawnattr_init 3 , +.Xr posix_spawnattr_setschedpolicy 3 , +.Xr posix_spawnp 3 +.Sh STANDARDS +The +.Fn posix_spawnattr_getschedparam +and +.Fn posix_spawnattr_setschedparam +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn posix_spawnattr_getschedparam +and +.Fn posix_spawnattr_setschedparam +functions first appeared in +.Fx 8.0 +and imported for +.Nx 6.0 . +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libc/gen/posix_spawnattr_getschedpolicy.3 b/lib/libc/gen/posix_spawnattr_getschedpolicy.3 new file mode 100644 index 000000000..943e4392a --- /dev/null +++ b/lib/libc/gen/posix_spawnattr_getschedpolicy.3 @@ -0,0 +1,102 @@ +.\" $NetBSD: posix_spawnattr_getschedpolicy.3,v 1.2 2012/03/23 18:08:35 njoly Exp $ +.\" +.\" Copyright (c) 2008 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- +.\" Portable Operating System Interface (POSIX), The Open Group Base +.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of +.\" Electrical and Electronics Engineers, Inc and The Open Group. In the +.\" event of any discrepancy between this version and the original IEEE and +.\" The Open Group Standard, the original IEEE and The Open Group Standard is +.\" the referee document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" $FreeBSD: src/lib/libc/gen/posix_spawnattr_getschedpolicy.3,v 1.1.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ +.\" +.Dd December 20, 2011 +.Dt POSIX_SPAWNATTR_GETSCHEDPOLICY 3 +.Os +.Sh NAME +.Nm posix_spawnattr_getschedpolicy , +.Nm posix_spawnattr_setschedpolicy +.Nd "get and set the spawn-schedpolicy attribute of a spawn attributes object" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In spawn.h +.Ft int +.Fn posix_spawnattr_getschedpolicy "const posix_spawnattr_t *restrict attr" "int *restrict schedpolicy" +.Ft int +.Fn posix_spawnattr_setschedpolicy "posix_spawnattr_t *attr" "int schedpolicy" +.Sh DESCRIPTION +The +.Fn posix_spawnattr_getschedpolicy +function obtains the value of the spawn-schedpolicy attribute from the +attributes object referenced by +.Fa attr . +.Pp +The +.Fn posix_spawnattr_setschedpolicy +function sets the spawn-schedpolicy attribute in an initialized attributes +object referenced by +.Fa attr . +.Pp +The spawn-schedpolicy attribute represents the scheduling policy to +be assigned to the new process image in a spawn operation (if +.Dv POSIX_SPAWN_SETSCHEDULER +is set in the spawn-flags attribute). +The default value of this attribute is unspecified. +.Sh RETURN VALUES +The +.Fn posix_spawnattr_getschedpolicy +and +.Fn posix_spawnattr_setschedpolicy +functions return zero. +.Sh SEE ALSO +.Xr posix_spawn 3 , +.Xr posix_spawnattr_destroy 3 , +.Xr posix_spawnattr_getschedparam 3 , +.Xr posix_spawnattr_init 3 , +.Xr posix_spawnattr_setschedparam 3 , +.Xr posix_spawnp 3 +.Sh STANDARDS +The +.Fn posix_spawnattr_getschedpolicy +and +.Fn posix_spawnattr_setschedpolicy +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn posix_spawnattr_getschedpolicy +and +.Fn posix_spawnattr_setschedpolicy +functions first appeared in +.Fx 8.0 +and imported for +.Nx 6.0 . +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libc/gen/posix_spawnattr_getsigdefault.3 b/lib/libc/gen/posix_spawnattr_getsigdefault.3 new file mode 100644 index 000000000..d1eb27e30 --- /dev/null +++ b/lib/libc/gen/posix_spawnattr_getsigdefault.3 @@ -0,0 +1,102 @@ +.\" $NetBSD: posix_spawnattr_getsigdefault.3,v 1.2 2012/03/23 18:08:35 njoly Exp $ +.\" +.\" Copyright (c) 2008 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- +.\" Portable Operating System Interface (POSIX), The Open Group Base +.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of +.\" Electrical and Electronics Engineers, Inc and The Open Group. In the +.\" event of any discrepancy between this version and the original IEEE and +.\" The Open Group Standard, the original IEEE and The Open Group Standard is +.\" the referee document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" $FreeBSD: src/lib/libc/gen/posix_spawnattr_getsigdefault.3,v 1.1.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ +.\" +.Dd December 20, 2011 +.Dt POSIX_SPAWNATTR_GETSIGDEFAULT 3 +.Os +.Sh NAME +.Nm posix_spawnattr_getsigdefault , +.Nm posix_spawnattr_setsigdefault +.Nd "get and set the spawn-sigdefault attribute of a spawn attributes object" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In spawn.h +.Ft int +.Fn posix_spawnattr_getsigdefault "const posix_spawnattr_t *restrict attr" "sigset_t *restrict sigdefault" +.Ft int +.Fn posix_spawnattr_setsigdefault "posix_spawnattr_t *attr" "const sigset_t *restrict sigdefault" +.Sh DESCRIPTION +The +.Fn posix_spawnattr_getsigdefault +function obtains the value of the spawn-sigdefault attribute from the +attributes object referenced by +.Fa attr . +.Pp +The +.Fn posix_spawnattr_setsigdefault +function sets the spawn-sigdefault attribute in an initialized attributes +object referenced by +.Fa attr . +.Pp +The spawn-sigdefault attribute represents the set of signals to be forced to +default signal handling in the new process image (if +.Dv POSIX_SPAWN_SETSIGDEF +is set in the spawn-flags attribute) by a spawn operation. +The default value of this attribute is an empty signal set. +.Sh RETURN VALUES +The +.Fn posix_spawnattr_getsigdefault +and +.Fn posix_spawnattr_setsigdefault +functions return zero. +.Sh SEE ALSO +.Xr posix_spawn 3 , +.Xr posix_spawnattr_destroy 3 , +.Xr posix_spawnattr_getsigmask 3 , +.Xr posix_spawnattr_init 3 , +.Xr posix_spawnattr_setsigmask 3 , +.Xr posix_spawnp 3 +.Sh STANDARDS +The +.Fn posix_spawnattr_getsigdefault +and +.Fn posix_spawnattr_setsigdefault +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn posix_spawnattr_getsigdefault +and +.Fn posix_spawnattr_setsigdefault +functions first appeared in +.Fx 8.0 +and imported for +.Nx 6.0 . +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libc/gen/posix_spawnattr_getsigmask.3 b/lib/libc/gen/posix_spawnattr_getsigmask.3 new file mode 100644 index 000000000..72151b4f3 --- /dev/null +++ b/lib/libc/gen/posix_spawnattr_getsigmask.3 @@ -0,0 +1,101 @@ +.\" $NetBSD: posix_spawnattr_getsigmask.3,v 1.2 2012/03/23 18:08:35 njoly Exp $ +.\" +.\" Copyright (c) 2008 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- +.\" Portable Operating System Interface (POSIX), The Open Group Base +.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of +.\" Electrical and Electronics Engineers, Inc and The Open Group. In the +.\" event of any discrepancy between this version and the original IEEE and +.\" The Open Group Standard, the original IEEE and The Open Group Standard is +.\" the referee document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" $FreeBSD: src/lib/libc/gen/posix_spawnattr_getsigmask.3,v 1.1.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ +.\" +.Dd December 20, 2011 +.Dt POSIX_SPAWNATTR_GETSIGMASK 3 +.Os +.Sh NAME +.Nm posix_spawnattr_getsigmask , +.Nm posix_spawnattr_setsigmask +.Nd "get and set the spawn-sigmask attribute of a spawn attributes object" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In spawn.h +.Ft int +.Fn posix_spawnattr_getsigmask "const posix_spawnattr_t *restrict attr" "sigset_t *restrict sigmask" +.Ft int +.Fn posix_spawnattr_setsigmask "posix_spawnattr_t *attr" "const sigset_t *restrict sigmask" +.Sh DESCRIPTION +The +.Fn posix_spawnattr_getsigmask +function obtains the value of the spawn-sigmask attribute from the +attributes object referenced by +.Fa attr . +.Pp +The +.Fn posix_spawnattr_setsigmask +function sets the spawn-sigmask attribute in an initialized attributes +object referenced by +.Fa attr . +.Pp +The spawn-sigmask attribute represents the signal mask in effect in the +new process image of a spawn operation (if +.Dv POSIX_SPAWN_SETSIGMASK +is set in the spawn-flags attribute). +The default value of this attribute is unspecified. +.Sh RETURN VALUES +The +.Fn posix_spawnattr_getsigmask +and +.Fn posix_spawnattr_setsigmask +functions return zero. +.Sh SEE ALSO +.Xr posix_spawn 3 , +.Xr posix_spawnattr_destroy 3 , +.Xr posix_spawnattr_init 3 , +.Xr posix_spawnattr_setsigmask 3 , +.Xr posix_spawnp 3 +.Sh STANDARDS +The +.Fn posix_spawnattr_getsigmask +and +.Fn posix_spawnattr_setsigmask +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn posix_spawnattr_getsigmask +and +.Fn posix_spawnattr_setsigmask +functions first appeared in +.Fx 8.0 +and imported for +.Nx 6.0 . +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libc/gen/posix_spawnattr_init.3 b/lib/libc/gen/posix_spawnattr_init.3 new file mode 100644 index 000000000..f5b421dd1 --- /dev/null +++ b/lib/libc/gen/posix_spawnattr_init.3 @@ -0,0 +1,127 @@ +.\" $NetBSD: posix_spawnattr_init.3,v 1.2 2012/03/23 18:08:35 njoly Exp $ +.\" +.\" Copyright (c) 2008 Ed Schouten +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Portions of this text are reprinted and reproduced in electronic form +.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- +.\" Portable Operating System Interface (POSIX), The Open Group Base +.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of +.\" Electrical and Electronics Engineers, Inc and The Open Group. In the +.\" event of any discrepancy between this version and the original IEEE and +.\" The Open Group Standard, the original IEEE and The Open Group Standard is +.\" the referee document. The original Standard can be obtained online at +.\" http://www.opengroup.org/unix/online.html. +.\" +.\" $FreeBSD: src/lib/libc/gen/posix_spawnattr_init.3,v 1.1.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $ +.\" +.Dd December 20, 2011 +.Dt POSIX_SPAWNATTR_INIT 3 +.Os +.Sh NAME +.Nm posix_spawnattr_init , +.Nm posix_spawnattr_destroy +.Nd "initialize and destroy spawn attributes object" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In spawn.h +.Ft int +.Fn posix_spawnattr_init "posix_spawnattr_t * attr" +.Ft int +.Fn posix_spawnattr_destroy "posix_spawnattr_t * attr" +.Sh DESCRIPTION +The +.Fn posix_spawnattr_init +function initializes a spawn attributes object +.Fa attr +with the default value for all of the individual attributes used by the +implementation. +Initializing an already initialized spawn attributes object may cause +memory to be leaked. +.Pp +The +.Fn posix_spawnattr_destroy +function destroys a spawn attributes object. +A destroyed +.Fa attr +attributes object can be reinitialized using +.Fn posix_spawnattr_init . +The object should not be used after it has been destroyed. +.Pp +A spawn attributes object is of type +.Vt posix_spawnattr_t +(defined in +.In spawn.h ) +and is used to specify the inheritance of process attributes across a +spawn operation. +.Pp +The resulting spawn attributes object (possibly modified by setting +individual attribute values), is used to modify the behavior of +.Fn posix_spawn +or +.Fn posix_spawnp . +After a spawn attributes object has been used to spawn a process by a +call to a +.Fn posix_spawn +or +.Fn posix_spawnp , +any function affecting the attributes object (including destruction) +will not affect any process that has been spawned in this way. +.Sh RETURN VALUES +Upon successful completion, +.Fn posix_spawnattr_init +and +.Fn posix_spawnattr_destroy +return zero; +otherwise, an error number is returned to indicate the error. +.Sh ERRORS +The +.Fn posix_spawnattr_init +function will fail if: +.Bl -tag -width Er +.It Bq Er ENOMEM +Insufficient memory exists to initialize the spawn file actions object. +.El +.Sh SEE ALSO +.Xr posix_spawn 3 , +.Xr posix_spawnp 3 +.Sh STANDARDS +The +.Fn posix_spawnattr_init +and +.Fn posix_spawnattr_destroy +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn posix_spawnattr_init +and +.Fn posix_spawnattr_destroy +functions first appeared in +.Fx 8.0 +and imported for +.Nx 6.0 . +.Sh AUTHORS +.An Ed Schouten Aq ed@FreeBSD.org diff --git a/lib/libc/locale/localeio_lc_messages.c b/lib/libc/gen/posix_spawnp.c similarity index 55% rename from lib/libc/locale/localeio_lc_messages.c rename to lib/libc/gen/posix_spawnp.c index adb575432..5149f625d 100644 --- a/lib/libc/locale/localeio_lc_messages.c +++ b/lib/libc/gen/posix_spawnp.c @@ -1,11 +1,11 @@ -/* $NetBSD: localeio_lc_messages.c,v 1.2 2009/01/11 02:46:28 christos Exp $ */ +/* $NetBSD: posix_spawnp.c,v 1.2 2012/02/22 17:51:01 martin Exp $ */ -/* - * Copyright (c) 2008, The NetBSD Foundation, Inc. +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. - * + * * This code is derived from software contributed to The NetBSD Foundation - * by Brian Ginsbach. + * by Martin Husemann . * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -31,53 +31,51 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: localeio_lc_messages.c,v 1.2 2009/01/11 02:46:28 christos Exp $"); +__RCSID("$NetBSD: posix_spawnp.c,v 1.2 2012/02/22 17:51:01 martin Exp $"); #endif /* LIBC_SCCS and not lint */ -#include "reentrant.h" -#include -#include -#include -#include -#include -#include -#include -#define __SETLOCALE_SOURCE__ -#include #include -#include #include +#include +#include +#include +#include -#include "setlocale_local.h" - -#include "aliasname_local.h" -#include "localeio.h" - -/* - * macro required by all template headers - */ -#define _PREFIX(name) __CONCAT(_localeio_LC_MESSAGES_, name) -#include "nb_lc_messages_misc.h" -#include "nb_lc_template_decl.h" +int posix_spawnp(pid_t * __restrict pid, const char * __restrict file, + const posix_spawn_file_actions_t *fa, + const posix_spawnattr_t * __restrict sa, + char * const *__restrict cav, char * const *__restrict env) +{ + char fpath[FILENAME_MAX], *last, *p; + char *path; -#define NSTRINGS (sizeof(_MessagesLocale)/sizeof(const char **)) + /* + * If there is a / in the filename, or no PATH environment variable + * set, fall straight through to posix_spawn(). + */ + if (strchr(file, '/') != NULL || (path = getenv("PATH")) == NULL) + return posix_spawn(pid, file, fa, sa, cav, env); -static int -_localeio_LC_MESSAGES_create_impl(const char * __restrict root, - const char * __restrict name, _MessagesLocale ** __restrict pdata) -{ - char path[PATH_MAX + 1]; + path = strdup(path); + if (path == NULL) + return ENOMEM; - _DIAGASSERT(root != NULL); - _DIAGASSERT(name != NULL); - _DIAGASSERT(pdata != NULL); + /* + * Find an executable image with the given name in the PATH + */ + for (p = strtok_r(path, ":", &last); p; + p = strtok_r(NULL, ":", &last)) { + snprintf(fpath, sizeof fpath, "%s/%s", p, file); + fpath[FILENAME_MAX-1] = 0; + if (access(fpath, X_OK) == 0) + break; + } + free(path); - snprintf(path, sizeof(path), - "%s/%s/LC_MESSAGES/SYS_LC_MESSAGES", root, name); - return __loadlocale(path, NSTRINGS, 0, sizeof(_MessagesLocale), - (void *)pdata); + /* + * Use posix_spawn() with the found binary + */ + return posix_spawn(pid, fpath, fa, sa, cav, env); } -#include "nb_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_localeio_LC_MESSAGES_); diff --git a/lib/libc/gen/psignal.c b/lib/libc/gen/psignal.c index c2363519c..4472be69c 100644 --- a/lib/libc/gen/psignal.c +++ b/lib/libc/gen/psignal.c @@ -1,4 +1,4 @@ -/* $NetBSD: psignal.c,v 1.22 2010/08/27 08:38:41 christos Exp $ */ +/* $NetBSD: psignal.c,v 1.23 2012/03/13 21:13:36 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)psignal.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: psignal.c,v 1.22 2010/08/27 08:38:41 christos Exp $"); +__RCSID("$NetBSD: psignal.c,v 1.23 2012/03/13 21:13:36 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -75,7 +75,7 @@ psignal(int sig, const char *s) v++; v->iov_base = __UNCONST("\n"); v->iov_len = 1; - (void)writev(STDERR_FILENO, iov, (v - iov) + 1); + (void)writev(STDERR_FILENO, iov, (int)((v - iov) + 1)); } void diff --git a/lib/libc/gen/pthread_atfork.c b/lib/libc/gen/pthread_atfork.c index 4f7f5608c..25c27a762 100644 --- a/lib/libc/gen/pthread_atfork.c +++ b/lib/libc/gen/pthread_atfork.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_atfork.c,v 1.8 2008/04/28 20:22:59 martin Exp $ */ +/* $NetBSD: pthread_atfork.c,v 1.9 2012/03/20 16:36:05 matt Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: pthread_atfork.c,v 1.8 2008/04/28 20:22:59 martin Exp $"); +__RCSID("$NetBSD: pthread_atfork.c,v 1.9 2012/03/20 16:36:05 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -47,7 +47,7 @@ __weak_alias(pthread_atfork, _pthread_atfork) __weak_alias(fork, _fork) #endif /* __weak_alias */ -pid_t __fork __P((void)); /* XXX */ +pid_t __fork(void); /* XXX */ struct atfork_callback { SIMPLEQ_ENTRY(atfork_callback) next; diff --git a/lib/libc/gen/pw_private.h b/lib/libc/gen/pw_private.h index 646fb2d5c..ee451d8e2 100644 --- a/lib/libc/gen/pw_private.h +++ b/lib/libc/gen/pw_private.h @@ -1,8 +1,8 @@ -/* $NetBSD: pw_private.h,v 1.2 2003/07/26 19:24:43 salo Exp $ */ +/* $NetBSD: pw_private.h,v 1.3 2012/03/20 16:36:05 matt Exp $ */ /* * Written by Jason R. Thorpe , June 26, 1998. * Public domain. */ -int __pw_scan __P((char *bp, struct passwd *pw, int *flags)); +int __pw_scan(char *bp, struct passwd *pw, int *flags); diff --git a/lib/libc/gen/pw_scan.c b/lib/libc/gen/pw_scan.c index 5bb8a105a..7c162d8c6 100644 --- a/lib/libc/gen/pw_scan.c +++ b/lib/libc/gen/pw_scan.c @@ -1,4 +1,4 @@ -/* $NetBSD: pw_scan.c,v 1.22 2009/01/29 10:41:39 enami Exp $ */ +/* $NetBSD: pw_scan.c,v 1.23 2012/03/13 21:13:36 christos Exp $ */ /* * Copyright (c) 1987, 1993, 1994, 1995 @@ -36,7 +36,7 @@ #else #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: pw_scan.c,v 1.22 2009/01/29 10:41:39 enami Exp $"); +__RCSID("$NetBSD: pw_scan.c,v 1.23 2012/03/13 21:13:36 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #if defined(_LIBC) @@ -60,7 +60,7 @@ __RCSID("$NetBSD: pw_scan.c,v 1.22 2009/01/29 10:41:39 enami Exp $"); #endif /* ! HAVE_NBTOOL_CONFIG_H */ static int -gettime(long long *res, const char *p, int *flags, int dowarn, int flag) +gettime(time_t *res, const char *p, int *flags, int dowarn, int flag) { long long l; char *ep; @@ -80,8 +80,8 @@ gettime(long long *res, const char *p, int *flags, int dowarn, int flag) vp = strerror(errno); goto done; } - - *res = l; + _DIAGASSERT(__type_fit(time_t, l)); + *res = (time_t)l; return 1; done: if (dowarn) { @@ -135,7 +135,7 @@ pw_scan( char *bp, struct passwd *pw, int *flags) #endif { unsigned long id; - long long ti; + time_t ti; int root, inflags; int dowarn; const char *p, *sh; diff --git a/lib/libc/gen/raise.3 b/lib/libc/gen/raise.3 index 1b3b81463..bbef77457 100644 --- a/lib/libc/gen/raise.3 +++ b/lib/libc/gen/raise.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: raise.3,v 1.9 2009/01/30 23:52:28 wiz Exp $ +.\" $NetBSD: raise.3,v 1.10 2011/05/09 09:06:21 jruoho Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)raise.3 8.1 (Berkeley) 6/4/93 .\" -.Dd January 29, 2009 +.Dd May 9, 2011 .Dt RAISE 3 .Os .Sh NAME @@ -68,7 +68,8 @@ library functions and .Xr _lwp_kill 2 . .Sh SEE ALSO -.Xr kill 2 +.Xr kill 2 , +.Xr raise_default_signal 3 .Sh STANDARDS The .Fn raise diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c index 277b70938..59f5105ac 100644 --- a/lib/libc/gen/readdir.c +++ b/lib/libc/gen/readdir.c @@ -1,4 +1,4 @@ -/* $NetBSD: readdir.c,v 1.25 2010/09/16 02:38:50 yamt Exp $ */ +/* $NetBSD: readdir.c,v 1.26 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)readdir.c 8.3 (Berkeley) 9/29/94"; #else -__RCSID("$NetBSD: readdir.c,v 1.25 2010/09/16 02:38:50 yamt Exp $"); +__RCSID("$NetBSD: readdir.c,v 1.26 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -96,8 +96,7 @@ _readdir_unlocked(DIR *dirp, int skipdeleted) } struct dirent * -readdir(dirp) - DIR *dirp; +readdir(DIR *dirp) { struct dirent *dp; @@ -114,10 +113,7 @@ readdir(dirp) } int -readdir_r(dirp, entry, result) - DIR *dirp; - struct dirent *entry; - struct dirent **result; +readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { struct dirent *dp; int saved_errno; diff --git a/lib/libc/gen/realpath.3 b/lib/libc/gen/realpath.3 index 37cff784b..2711e7c6f 100644 --- a/lib/libc/gen/realpath.3 +++ b/lib/libc/gen/realpath.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: realpath.3,v 1.12 2005/08/13 19:53:53 elad Exp $ +.\" $NetBSD: realpath.3,v 1.14 2012/06/21 21:35:25 wiz Exp $ .\" .\" Copyright (c) 1994 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" from: @(#)realpath.3 8.2 (Berkeley) 2/16/94 .\" -.Dd August 13, 2005 +.Dd June 21, 2012 .Dt REALPATH 3 .Os .Sh NAME @@ -44,7 +44,7 @@ .In sys/param.h .In stdlib.h .Ft "char *" -.Fn realpath "const char *pathname" "char resolvedname[MAXPATHLEN]" +.Fn realpath "const char * restrict pathname" "char * restrict resolvedname" .Sh DESCRIPTION The .Fn realpath @@ -73,6 +73,12 @@ function will resolve both absolute and relative paths and return the absolute pathname corresponding to .Fa pathname . .Sh RETURN VALUES +If +.Fa resolvednamed +is +.Dv NULL , +it will be allocated and the returned pointer can be deallocated using +.Xr free 3 . The .Fn realpath function returns @@ -84,7 +90,9 @@ returns .Dv NULL , and .Fa resolvedname -contains the pathname which caused the problem. +was not allocated by +.Nm , +it will contain the pathname which caused the problem. .Sh ERRORS The function .Fn realpath @@ -95,17 +103,31 @@ for any of the errors specified for the library functions .Xr close 2 , .Xr fchdir 2 , .Xr lstat 2 , +.Xr malloc 3 , .Xr open 2 , .Xr readlink 2 and .Xr getcwd 3 . .Sh SEE ALSO .Xr getcwd 3 +.Sh STANDARDS +.Fn realpath +first appeared in +.St -xpg4.2 +and is part of +.St -p1003.1-2001 . .Sh HISTORY The .Fn realpath function call first appeared in .Bx 4.4 . +In +.Nx 7.0 +the function was updated to accept a +.Dv NULL +pointer for the +.Fa resolvedname +argument. .Sh BUGS This implementation of .Fn realpath diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 614b02338..740928940 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -1,4 +1,4 @@ -/* $NetBSD: scandir.c,v 1.26 2007/06/09 23:57:25 christos Exp $ */ +/* $NetBSD: scandir.c,v 1.27 2012/03/13 21:13:36 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)scandir.c 8.3 (Berkeley) 1/2/94"; #else -__RCSID("$NetBSD: scandir.c,v 1.26 2007/06/09 23:57:25 christos Exp $"); +__RCSID("$NetBSD: scandir.c,v 1.27 2012/03/13 21:13:36 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -143,7 +143,8 @@ scandir(const char *dirname, struct dirent ***namelist, if (nitems && dcomp != NULL) qsort(names, nitems, sizeof(*names), dcomp); *namelist = names; - return nitems; + _DIAGASSERT(__type_fit(int, nitems)); + return (int)nitems; bad2: while (nitems-- > 0) diff --git a/lib/libc/gen/setdomainname.c b/lib/libc/gen/setdomainname.c index 8ec82bb46..b392c1fc2 100644 --- a/lib/libc/gen/setdomainname.c +++ b/lib/libc/gen/setdomainname.c @@ -1,4 +1,4 @@ -/* $NetBSD: setdomainname.c,v 1.12 2003/08/07 16:42:56 agc Exp $ */ +/* $NetBSD: setdomainname.c,v 1.13 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)sethostname.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: setdomainname.c,v 1.12 2003/08/07 16:42:56 agc Exp $"); +__RCSID("$NetBSD: setdomainname.c,v 1.13 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,9 +51,7 @@ __weak_alias(setdomainname,_setdomainname) #endif int -setdomainname(name, namelen) - const char *name; - size_t namelen; +setdomainname(const char *name, size_t namelen) { int mib[2]; diff --git a/lib/libc/gen/sethostname.c b/lib/libc/gen/sethostname.c index 9ff569fd4..4da934ae4 100644 --- a/lib/libc/gen/sethostname.c +++ b/lib/libc/gen/sethostname.c @@ -1,4 +1,4 @@ -/* $NetBSD: sethostname.c,v 1.12 2003/08/07 16:42:56 agc Exp $ */ +/* $NetBSD: sethostname.c,v 1.13 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)sethostname.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: sethostname.c,v 1.12 2003/08/07 16:42:56 agc Exp $"); +__RCSID("$NetBSD: sethostname.c,v 1.13 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,9 +51,7 @@ __weak_alias(sethostname,_sethostname) #endif int -sethostname(name, namelen) - const char *name; - size_t namelen; +sethostname(const char *name, size_t namelen) { int mib[2]; diff --git a/lib/libc/gen/setjmperr.c b/lib/libc/gen/setjmperr.c index f47eb8780..5b1432e15 100644 --- a/lib/libc/gen/setjmperr.c +++ b/lib/libc/gen/setjmperr.c @@ -1,4 +1,4 @@ -/* $NetBSD: setjmperr.c,v 1.7 2003/08/07 16:42:56 agc Exp $ */ +/* $NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)setjmperr.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: setjmperr.c,v 1.7 2003/08/07 16:42:56 agc Exp $"); +__RCSID("$NetBSD: setjmperr.c,v 1.8 2012/06/24 15:26:03 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,7 +49,7 @@ __RCSID("$NetBSD: setjmperr.c,v 1.7 2003/08/07 16:42:56 agc Exp $"); #include void -longjmperror() +longjmperror(void) { #define ERRMSG "longjmp botch.\n" (void)write(STDERR_FILENO, ERRMSG, sizeof(ERRMSG) - 1); diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c index 4fed4b9cd..a2ea01d4c 100644 --- a/lib/libc/gen/setmode.c +++ b/lib/libc/gen/setmode.c @@ -1,4 +1,4 @@ -/* $NetBSD: setmode.c,v 1.31 2005/10/01 20:08:01 christos Exp $ */ +/* $NetBSD: setmode.c,v 1.34 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94"; #else -__RCSID("$NetBSD: setmode.c,v 1.31 2005/10/01 20:08:01 christos Exp $"); +__RCSID("$NetBSD: setmode.c,v 1.34 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -77,10 +77,10 @@ typedef struct bitcmd { #define CMD2_OBITS 0x08 #define CMD2_UBITS 0x10 -static BITCMD *addcmd __P((BITCMD *, mode_t, mode_t, mode_t, mode_t)); -static void compress_mode __P((BITCMD *)); +static BITCMD *addcmd(BITCMD *, mode_t, mode_t, mode_t, mode_t); +static void compress_mode(BITCMD *); #ifdef SETMODE_DEBUG -static void dumpmode __P((BITCMD *)); +static void dumpmode(BITCMD *); #endif /* @@ -411,8 +411,7 @@ addcmd(BITCMD *set, mode_t op, mode_t who, mode_t oparg, mode_t mask) #ifdef SETMODE_DEBUG static void -dumpmode(set) - BITCMD *set; +dumpmode(BITCMD *set) { _DIAGASSERT(set != NULL); @@ -435,8 +434,7 @@ dumpmode(set) * compacted, but it's not worth the effort. */ static void -compress_mode(set) - BITCMD *set; +compress_mode(BITCMD *set) { BITCMD *nset; int setbits, clrbits, Xbits, op; diff --git a/lib/libc/gen/siginterrupt.c b/lib/libc/gen/siginterrupt.c index 56e98b851..1e79d42ce 100644 --- a/lib/libc/gen/siginterrupt.c +++ b/lib/libc/gen/siginterrupt.c @@ -1,4 +1,4 @@ -/* $NetBSD: siginterrupt.c,v 1.12 2003/08/07 16:42:56 agc Exp $ */ +/* $NetBSD: siginterrupt.c,v 1.13 2012/06/25 22:32:43 abs Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)siginterrupt.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: siginterrupt.c,v 1.12 2003/08/07 16:42:56 agc Exp $"); +__RCSID("$NetBSD: siginterrupt.c,v 1.13 2012/06/25 22:32:43 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,8 +51,7 @@ extern sigset_t __sigintr; * after an instance of the indicated signal. */ int -siginterrupt(sig, flag) - int sig, flag; +siginterrupt(int sig, int flag) { struct sigaction sa; int ret; diff --git a/lib/libc/gen/signal.c b/lib/libc/gen/signal.c index 09f6e57c0..cc3cce2c5 100644 --- a/lib/libc/gen/signal.c +++ b/lib/libc/gen/signal.c @@ -1,4 +1,4 @@ -/* $NetBSD: signal.c,v 1.12 2003/08/07 16:42:56 agc Exp $ */ +/* $NetBSD: signal.c,v 1.13 2012/06/25 22:32:44 abs Exp $ */ /* * Copyright (c) 1985, 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)signal.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: signal.c,v 1.12 2003/08/07 16:42:56 agc Exp $"); +__RCSID("$NetBSD: signal.c,v 1.13 2012/06/25 22:32:44 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,9 +51,7 @@ __weak_alias(signal,_signal) sigset_t __sigintr; /* shared with siginterrupt */ sig_t -signal(s, a) - int s; - sig_t a; +signal(int s, sig_t a) { struct sigaction sa, osa; diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c index a6b3cc9b7..abb60d398 100644 --- a/lib/libc/gen/sleep.c +++ b/lib/libc/gen/sleep.c @@ -1,4 +1,4 @@ -/* $NetBSD: sleep.c,v 1.22 2008/04/28 20:22:59 martin Exp $ */ +/* $NetBSD: sleep.c,v 1.23 2012/06/25 22:32:44 abs Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: sleep.c,v 1.22 2008/04/28 20:22:59 martin Exp $"); +__RCSID("$NetBSD: sleep.c,v 1.23 2012/06/25 22:32:44 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -43,8 +43,7 @@ __weak_alias(sleep,_sleep) #endif unsigned int -sleep(seconds) - unsigned int seconds; +sleep(unsigned int seconds) { struct timespec rqt, rmt; diff --git a/lib/libc/gen/sysconf.3 b/lib/libc/gen/sysconf.3 index 34235f898..4b66db77e 100644 --- a/lib/libc/gen/sysconf.3 +++ b/lib/libc/gen/sysconf.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: sysconf.3,v 1.37 2010/03/22 19:30:54 joerg Exp $ +.\" $NetBSD: sysconf.3,v 1.40 2011/08/23 17:28:34 jmcneill Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)sysconf.3 8.3 (Berkeley) 4/19/94 .\" -.Dd August 6, 2008 +.Dd August 23, 2011 .Dt SYSCONF 3 .Os .Sh NAME @@ -63,7 +63,7 @@ The available values are as follows: The maximum bytes of argument to .Xr execve 2 . .It Li _SC_ATEXIT_MAX -The maxmimum number of functions that may be registered with +The maximum number of functions that may be registered with .Xr atexit 3 . .It Li _SC_BARRIERS The version of @@ -86,7 +86,8 @@ The number of clock ticks per second. Return 1 if the File Synchronization Option is available on this system, otherwise \-1. .It Li _SC_HOST_NAME_MAX -The maximum size of a hostname, including NULL. +The maximum size of a hostname, including +.Dv NULL . .It Li _SC_IOV_MAX The maximum number of .Va iovec @@ -128,7 +129,8 @@ The maximum number of open files per process. .It Li _SC_PAGESIZE The size of a system page in bytes. .It Li _SC_PASS_MAX -The maximum length of the password, not counting NULL. +The maximum length of the password, not counting +.Dv NULL . .It Li _SC_READER_WRITER_LOCKS The version of .St -p1003.1 @@ -307,6 +309,8 @@ The value of the argument is invalid. .El .Sh SEE ALSO +.Xr getconf 1 , +.Xr limits 3 , .Xr sysctl 3 .Sh STANDARDS The diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c index 48e47a8e5..4ec517692 100644 --- a/lib/libc/gen/sysconf.c +++ b/lib/libc/gen/sysconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysconf.c,v 1.33 2008/08/06 17:17:04 matt Exp $ */ +/* $NetBSD: sysconf.c,v 1.34 2012/08/01 15:24:22 martin Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94"; #else -__RCSID("$NetBSD: sysconf.c,v 1.33 2008/08/06 17:17:04 matt Exp $"); +__RCSID("$NetBSD: sysconf.c,v 1.34 2012/08/01 15:24:22 martin Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -346,6 +346,8 @@ sysconf(int name) return _POSIX_REGEXP; case _SC_SHELL: return _POSIX_SHELL; + case _SC_SPAWN: + return _POSIX_SPAWN; case _SC_SYMLOOP_MAX: return MAXSYMLINKS; diff --git a/lib/libc/gen/sysctl.c b/lib/libc/gen/sysctl.c index 6af568586..843bcb054 100644 --- a/lib/libc/gen/sysctl.c +++ b/lib/libc/gen/sysctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysctl.c,v 1.30 2008/08/27 08:56:49 christos Exp $ */ +/* $NetBSD: sysctl.c,v 1.32 2012/03/20 16:36:05 matt Exp $ */ /*- * Copyright (c) 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)sysctl.c 8.2 (Berkeley) 1/4/94"; #else -__RCSID("$NetBSD: sysctl.c,v 1.30 2008/08/27 08:56:49 christos Exp $"); +__RCSID("$NetBSD: sysctl.c,v 1.32 2012/03/20 16:36:05 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -43,6 +43,7 @@ __RCSID("$NetBSD: sysctl.c,v 1.30 2008/08/27 08:56:49 christos Exp $"); #define __COMPAT_SYSCTL #include +#include #include #include #include @@ -69,12 +70,9 @@ static size_t __cvt_node_out(uint, const struct sysctlnode *, void **, #include int -sysctl(name, namelen, oldp, oldlenp, newp, newlen) - const int *name; - unsigned int namelen; - void *oldp; - const void *newp; - size_t *oldlenp, newlen; +sysctl(const int *name, unsigned int namelen, + void *oldp, size_t *oldlenp, + const void *newp, size_t newlen) { size_t oldlen, savelen; int error; @@ -104,12 +102,9 @@ sysctl(name, namelen, oldp, oldlenp, newp, newlen) } static int -user_sysctl(name, namelen, oldp, oldlenp, newp, newlen) - const int *name; - unsigned int namelen; - void *oldp; - const void *newp; - size_t *oldlenp, newlen; +user_sysctl(const int *name, unsigned int namelen, + void *oldp, size_t *oldlenp, + const void *newp, size_t newlen) { #define _INT(s, n, v, d) { \ .sysctl_flags = CTLFLAG_IMMEDIATE|CTLFLAG_PERMANENT| \ @@ -317,10 +312,13 @@ user_sysctl(name, namelen, oldp, oldlenp, newp, newlen) if (sysctl_usermib[ni].sysctl_desc == NULL) d1->descr_len = 1; else { + size_t dlen; (void)strlcpy(d1->descr_str, sysctl_usermib[ni].sysctl_desc, sizeof(buf) - sizeof(*d1)); - d1->descr_len = strlen(d1->descr_str) + 1; + dlen = strlen(d1->descr_str) + 1; + _DIAGASSERT(__type_fit(uint32_t, dlen)); + d1->descr_len = (uint32_t)dlen; } d = (size_t)__sysc_desc_adv(NULL, d1->descr_len); if (d2 != NULL) diff --git a/lib/libc/gen/sysctlgetmibinfo.c b/lib/libc/gen/sysctlgetmibinfo.c index 10d5c077f..6eee30db5 100644 --- a/lib/libc/gen/sysctlgetmibinfo.c +++ b/lib/libc/gen/sysctlgetmibinfo.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysctlgetmibinfo.c,v 1.9 2010/12/13 23:10:13 pooka Exp $ */ +/* $NetBSD: sysctlgetmibinfo.c,v 1.10 2012/03/13 21:13:37 christos Exp $ */ /*- * Copyright (c) 2003,2004 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: sysctlgetmibinfo.c,v 1.9 2010/12/13 23:10:13 pooka Exp $"); +__RCSID("$NetBSD: sysctlgetmibinfo.c,v 1.10 2012/03/13 21:13:37 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #ifndef RUMP_ACTION @@ -43,6 +43,7 @@ __RCSID("$NetBSD: sysctlgetmibinfo.c,v 1.9 2010/12/13 23:10:13 pooka Exp $"); #include #include +#include #include #include #include @@ -131,7 +132,8 @@ relearnhead(void) { struct sysctlnode *h, *i, *o, qnode; size_t si, so; - int rc, name, nlen, olen, ni, oi; + int rc, name; + size_t nlen, olen, ni, oi; uint32_t t; /* @@ -165,7 +167,7 @@ relearnhead(void) * order the new copy of the head */ nlen = so / sizeof(struct sysctlnode); - qsort(h, (size_t)nlen, sizeof(struct sysctlnode), compar); + qsort(h, nlen, sizeof(struct sysctlnode), compar); /* * verify that everything is the same. if it is, we don't @@ -259,8 +261,9 @@ relearnhead(void) /* * pop new head in */ - sysctl_mibroot.sysctl_clen = nlen; - sysctl_mibroot.sysctl_csize = nlen; + _DIAGASSERT(__type_fit(uint32_t, nlen)); + sysctl_mibroot.sysctl_csize = + sysctl_mibroot.sysctl_clen = (uint32_t)nlen; sysctl_mibroot.sysctl_child = h; free(o); } @@ -330,9 +333,9 @@ __learn_tree(int *name, u_int namelen, struct sysctlnode *pnode) /* * how many did we get? */ - pnode->sysctl_clen = sz / sizeof(struct sysctlnode); - pnode->sysctl_csize = sz / sizeof(struct sysctlnode); - if (pnode->sysctl_clen * sizeof(struct sysctlnode) != sz) { + sz /= sizeof(struct sysctlnode); + pnode->sysctl_csize = pnode->sysctl_clen = (uint32_t)sz; + if (pnode->sysctl_clen != sz) { free(pnode->sysctl_child); pnode->sysctl_child = NULL; errno = EINVAL; diff --git a/lib/libc/gen/sysctlnametomib.c b/lib/libc/gen/sysctlnametomib.c index 92376e1ff..735f4f0d0 100644 --- a/lib/libc/gen/sysctlnametomib.c +++ b/lib/libc/gen/sysctlnametomib.c @@ -1,4 +1,4 @@ -/* $NetBSD: sysctlnametomib.c,v 1.6 2010/12/13 23:10:13 pooka Exp $ */ +/* $NetBSD: sysctlnametomib.c,v 1.7 2012/03/13 21:13:37 christos Exp $ */ /*- * Copyright (c) 2003,2004 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: sysctlnametomib.c,v 1.6 2010/12/13 23:10:13 pooka Exp $"); +__RCSID("$NetBSD: sysctlnametomib.c,v 1.7 2012/03/13 21:13:37 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #ifndef RUMP_ACTION @@ -39,6 +39,7 @@ __RCSID("$NetBSD: sysctlnametomib.c,v 1.6 2010/12/13 23:10:13 pooka Exp $"); #endif #include #include +#include #ifdef RUMP_ACTION #include @@ -61,7 +62,8 @@ sysctlnametomib(const char *gname, int *iname, size_t *namelenp) u_int unamelen; int rc; - unamelen = *namelenp; + _DIAGASSERT(__type_fit(u_int, *namelenp)); + unamelen = (u_int)*namelenp; rc = sysctlgetmibinfo(gname, iname, &unamelen, NULL, NULL, NULL, SYSCTL_VERSION); *namelenp = unamelen; diff --git a/lib/libc/gen/syslog.3 b/lib/libc/gen/syslog.3 index 278b0616d..1b7baeda6 100644 --- a/lib/libc/gen/syslog.3 +++ b/lib/libc/gen/syslog.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: syslog.3,v 1.28 2010/05/13 18:04:58 jruoho Exp $ +.\" $NetBSD: syslog.3,v 1.29 2011/07/25 19:42:50 njoly Exp $ .\" $OpenBSD: syslog.3,v 1.25 2005/07/22 03:16:58 jaredy Exp $ .\" .\" Copyright (c) 1985, 1991, 1993 @@ -199,7 +199,7 @@ The function is an alternative form in which the arguments have already been captured using the variable-length argument facilities of -.Xr varargs 3 . +.Xr stdarg 3 . .Pp The .Fn syslogp diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index 225919c99..971710387 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -1,4 +1,4 @@ -/* $NetBSD: syslog.c,v 1.48 2010/05/13 22:40:14 christos Exp $ */ +/* $NetBSD: syslog.c,v 1.53 2012/10/11 17:09:55 christos Exp $ */ /* * Copyright (c) 1983, 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)syslog.c 8.5 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: syslog.c,v 1.48 2010/05/13 22:40:14 christos Exp $"); +__RCSID("$NetBSD: syslog.c,v 1.53 2012/10/11 17:09:55 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -67,18 +67,6 @@ __weak_alias(syslog,_syslog) __weak_alias(vsyslog,_vsyslog) __weak_alias(syslogp,_syslogp) __weak_alias(vsyslogp,_vsyslogp) - -__weak_alias(closelog_r,_closelog_r) -__weak_alias(openlog_r,_openlog_r) -__weak_alias(setlogmask_r,_setlogmask_r) -__weak_alias(syslog_r,_syslog_r) -__weak_alias(vsyslog_r,_vsyslog_r) -__weak_alias(syslog_ss,_syslog_ss) -__weak_alias(vsyslog_ss,_vsyslog_ss) -__weak_alias(syslogp_r,_syslogp_r) -__weak_alias(vsyslogp_r,_vsyslogp_r) -__weak_alias(syslogp_ss,_syslogp_ss) -__weak_alias(vsyslogp_ss,_vsyslogp_ss) #endif static struct syslog_data sdata = SYSLOG_DATA_INIT; @@ -95,8 +83,6 @@ static void connectlog_r(struct syslog_data *); static mutex_t syslog_mutex = MUTEX_INITIALIZER; #endif -static char hostname[MAXHOSTNAMELEN]; - /* * syslog, vsyslog -- * print message on log file; output is intended for syslogd(8). @@ -298,21 +284,43 @@ vsyslogp_r(int pri, struct syslog_data *data, const char *msgid, } } else { prlen = snprintf_ss(p, tbuf_left, "-"); - - /* if gmtime_r() was signal-safe we could output the UTC-time: +#if 0 + /* + * if gmtime_r() was signal-safe we could output + * the UTC-time: + */ gmtime_r(&now, &tmnow); prlen = strftime(p, tbuf_left, "%FT%TZ", &tmnow); - */ +#endif } + +#ifndef __minix + if (data == &sdata) + mutex_lock(&syslog_mutex); +#endif + + if (data->log_hostname[0] == '\0' && gethostname(data->log_hostname, + sizeof(data->log_hostname)) == -1) { + /* can this really happen? */ + data->log_hostname[0] = '-'; + data->log_hostname[1] = '\0'; + } + DEC(); - prlen = snprintf_ss(p, tbuf_left, " %s ", hostname); - DEC(); + prlen = snprintf_ss(p, tbuf_left, " %s ", data->log_hostname); if (data->log_tag == NULL) data->log_tag = getprogname(); + DEC(); prlen = snprintf_ss(p, tbuf_left, "%s ", data->log_tag ? data->log_tag : "-"); + +#ifndef __minix + if (data == &sdata) + mutex_unlock(&syslog_mutex); +#endif + if (data->log_stat & (LOG_PERROR|LOG_CONS)) { iovcnt = 0; iov[iovcnt].iov_base = p; @@ -426,7 +434,7 @@ vsyslogp_r(int pri, struct syslog_data *data, const char *msgid, if (data == &sdata) mutex_lock(&syslog_mutex); #endif - opened = !data->opened; + opened = !data->log_opened; if (opened) openlog_unlocked_r(data->log_tag, data->log_stat, 0, data); connectlog_r(data); @@ -487,7 +495,7 @@ disconnectlog_r(struct syslog_data *data) (void)close(data->log_file); data->log_file = -1; } - data->connected = 0; /* retry connect */ + data->log_connected = 0; /* retry connect */ } static void @@ -503,19 +511,19 @@ connectlog_r(struct syslog_data *data) }; if (data->log_file == -1 || fcntl(data->log_file, F_GETFL, 0) == -1) { - if ((data->log_file = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) + if ((data->log_file = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, + 0)) == -1) return; - (void)fcntl(data->log_file, F_SETFD, FD_CLOEXEC); - data->connected = 0; + data->log_connected = 0; } - if (!data->connected) { + if (!data->log_connected) { if (connect(data->log_file, (const struct sockaddr *)(const void *)&sun, - sizeof(sun)) == -1) { + (socklen_t)sizeof(sun)) == -1) { (void)close(data->log_file); data->log_file = -1; } else - data->connected = 1; + data->log_connected = 1; } } @@ -532,14 +540,7 @@ openlog_unlocked_r(const char *ident, int logstat, int logfac, if (data->log_stat & LOG_NDELAY) /* open immediately */ connectlog_r(data); - /* We could cache this, but then it might change */ - if (gethostname(hostname, sizeof(hostname)) == -1 - || hostname[0] == '\0') { - /* can this really happen? */ - hostname[0] = '-'; - hostname[1] = '\0'; - } - data->opened = 1; + data->log_opened = 1; } void @@ -565,7 +566,7 @@ closelog_r(struct syslog_data *data) #endif (void)close(data->log_file); data->log_file = -1; - data->connected = 0; + data->log_connected = 0; data->log_tag = NULL; #ifndef __minix if (data == &sdata) diff --git a/lib/libc/gen/time.3 b/lib/libc/gen/time.3 index 5c44f95ae..b361f4db6 100644 --- a/lib/libc/gen/time.3 +++ b/lib/libc/gen/time.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: time.3,v 1.15 2010/04/24 01:35:50 dholland Exp $ +.\" $NetBSD: time.3,v 1.16 2011/11/05 18:17:29 christos Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)time.3 8.1 (Berkeley) 6/4/93 .\" -.Dd April 23, 2010 +.Dd November 5, 2011 .Dt TIME 3 .Os .Sh NAME @@ -72,12 +72,7 @@ is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS -The following error codes may be set in -.Va errno : -.Bl -tag -width Er -.It Bq Er EFAULT -An argument address referenced invalid memory. -.El +No errors are defined. .Sh SEE ALSO .Xr gettimeofday 2 , .Xr ctime 3 diff --git a/lib/libc/gen/time.c b/lib/libc/gen/time.c index f31222408..da0db1034 100644 --- a/lib/libc/gen/time.c +++ b/lib/libc/gen/time.c @@ -1,4 +1,4 @@ -/* $NetBSD: time.c,v 1.11 2009/01/11 02:46:27 christos Exp $ */ +/* $NetBSD: time.c,v 1.12 2012/03/13 21:13:37 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: time.c,v 1.11 2009/01/11 02:46:27 christos Exp $"); +__RCSID("$NetBSD: time.c,v 1.12 2012/03/13 21:13:37 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,8 +52,8 @@ time(time_t *t) if (gettimeofday(&tt, NULL) == -1) return (time_t)-1; if (t != NULL) - *t = tt.tv_sec; - return tt.tv_sec; + *t = (time_t)tt.tv_sec; + return (time_t)tt.tv_sec; } #ifdef __minix diff --git a/lib/libc/gen/toascii.c b/lib/libc/gen/toascii.c index 7bddde11b..c8f76afad 100644 --- a/lib/libc/gen/toascii.c +++ b/lib/libc/gen/toascii.c @@ -1,4 +1,4 @@ -/* $NetBSD: toascii.c,v 1.2 2003/08/07 16:42:58 agc Exp $ */ +/* $NetBSD: toascii.c,v 1.3 2012/06/25 22:32:44 abs Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -38,15 +38,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: toascii.c,v 1.2 2003/08/07 16:42:58 agc Exp $"); +__RCSID("$NetBSD: toascii.c,v 1.3 2012/06/25 22:32:44 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include #undef toascii int -toascii(c) - int c; +toascii(int c) { return ((c) & 0177); } diff --git a/lib/libc/gen/ttyname.3 b/lib/libc/gen/ttyname.3 index a9c094122..eddfa0175 100644 --- a/lib/libc/gen/ttyname.3 +++ b/lib/libc/gen/ttyname.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: ttyname.3,v 1.21 2008/06/25 11:47:29 ad Exp $ +.\" $NetBSD: ttyname.3,v 1.24 2012/06/03 21:42:46 joerg Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)ttyname.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 25, 2008 +.Dd June 1, 2012 .Dt TTYNAME 3 .Os .Sh NAME @@ -50,7 +50,7 @@ .Fn isatty "int fd" .In stdlib.h .Ft int -.Fn ttyslot +.Fn ttyslot "void" .Sh DESCRIPTION These functions operate on the system file descriptors for terminal type devices. @@ -106,7 +106,7 @@ device without requiring one to enumerate all of them in .Sh IMPLEMENTATION NOTES As an optimisation, these functions attempt to obtain information about all devices from the -.Pa /var/run/dev.db +.Pa /var/run/dev.cdb database, if it exists. If the database exists but is out of date, then these functions may produce incorrect results. @@ -169,11 +169,11 @@ The .Fn ttyname_r function will also fail if: .Bl -tag -width Er -.It Bq Er ERANGE -The buffer provided is not large enough to fit the result. .It Bq Er ENOENT The terminal device is not found. This can happen if the device node has been removed after it was opened. +.It Bq Er ERANGE +The buffer provided is not large enough to fit the result. .El .Sh SEE ALSO .Xr ioctl 2 , @@ -193,7 +193,7 @@ and .Fn ttyslot functions appeared in .At v7 . -.\" Use of the .Pa /var/run/dev.db file was added in ???. +.\" Use of the .Pa /var/run/dev.cdb file was added in netBSD 6.0. .Sh BUGS The .Fn ttyname diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c index ad543df94..236826778 100644 --- a/lib/libc/gen/ttyname.c +++ b/lib/libc/gen/ttyname.c @@ -1,4 +1,4 @@ -/* $NetBSD: ttyname.c,v 1.24 2008/06/25 11:47:29 ad Exp $ */ +/* $NetBSD: ttyname.c,v 1.26 2012/06/12 18:17:04 joerg Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,96 +34,32 @@ #if 0 static char sccsid[] = "@(#)ttyname.c 8.2 (Berkeley) 1/27/94"; #else -__RCSID("$NetBSD: ttyname.c,v 1.24 2008/06/25 11:47:29 ad Exp $"); +__RCSID("$NetBSD: ttyname.c,v 1.26 2012/06/12 18:17:04 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include "namespace.h" -#include -#include +#include #include #include -#include -#include #include -#include +#include #include #include +#include #include #include -#include #ifdef __weak_alias __weak_alias(ttyname,_ttyname) __weak_alias(ttyname_r,_ttyname_r) #endif -static int oldttyname(const struct stat *, char *, size_t); - -int -ttyname_r(int fd, char *buf, size_t len) -{ - struct stat sb; - struct termios ttyb; - DB *db; - DBT data, key; - struct { - mode_t type; - dev_t dev; - } bkey; -#ifndef __minix - struct ptmget ptm; -#endif -#define DEVSZ (sizeof(_PATH_DEV) - 1) - - _DIAGASSERT(fd != -1); - - if (len <= DEVSZ) { - return ERANGE; - } - -#ifndef __minix - /* If it is a pty, deal with it quickly */ - if (ioctl(fd, TIOCPTSNAME, &ptm) != -1) { - if (strlcpy(buf, ptm.sn, len) >= len) { - return ERANGE; - } - return 0; - } -#endif - /* Must be a terminal. */ - if (tcgetattr(fd, &ttyb) == -1) - return errno; - - /* Must be a character device. */ - if (fstat(fd, &sb)) - return errno; - if (!S_ISCHR(sb.st_mode)) - return ENOTTY; - - (void)memcpy(buf, _PATH_DEV, DEVSZ); - if ((db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL)) != NULL) { - (void)memset(&bkey, 0, sizeof(bkey)); - bkey.type = S_IFCHR; - bkey.dev = sb.st_rdev; - key.data = &bkey; - key.size = sizeof(bkey); - if (!(db->get)(db, &key, &data, 0)) { - if (len - DEVSZ <= data.size) { - return ERANGE; - } - (void)memcpy(buf + DEVSZ, data.data, data.size); - (void)(db->close)(db); - return 0; - } - (void)(db->close)(db); - } - if (oldttyname(&sb, buf, len) == -1) - return errno; - return 0; -} - +#ifdef __minix +/* LSC: We do not have devname functionality on Minix, so re-import for now + * old, manual way of doing it.*/ +#include static int oldttyname(const struct stat *sb, char *buf, size_t len) { @@ -138,13 +74,10 @@ oldttyname(const struct stat *sb, char *buf, size_t len) return -1; while ((dirp = readdir(dp)) != NULL) { +#define DEVSZ (sizeof(_PATH_DEV) - 1) if (dirp->d_fileno != sb->st_ino) continue; -#ifdef __minix dlen = strlen(dirp->d_name); -#else - dlen = dirp->d_namlen + 1; -#endif if (len - DEVSZ <= dlen) { /* * XXX: we return an error if *any* entry does not @@ -160,6 +93,7 @@ oldttyname(const struct stat *sb, char *buf, size_t len) continue; (void)closedir(dp); return 0; +#undef DEVSZ } (void)closedir(dp); /* @@ -170,10 +104,55 @@ oldttyname(const struct stat *sb, char *buf, size_t len) return -1; } +#endif + +int +ttyname_r(int fd, char *buf, size_t len) +{ + struct stat sb; + struct termios ttyb; +#ifndef __minix + struct ptmget ptm; +#endif + + _DIAGASSERT(fd != -1); + +#ifndef __minix + /* If it is a pty, deal with it quickly */ + if (ioctl(fd, TIOCPTSNAME, &ptm) != -1) { + if (strlcpy(buf, ptm.sn, len) >= len) { + return ERANGE; + } + return 0; + } +#endif + + /* Must be a terminal. */ + if (tcgetattr(fd, &ttyb) == -1) + return errno; + + if (fstat(fd, &sb)) + return errno; + + if (strlcpy(buf, _PATH_DEV, len) >= len) + return ERANGE; + +#ifdef __minix + if (oldttyname(&sb, buf, len) == -1) + return errno; + return 0; +#else + buf += strlen(_PATH_DEV); + len -= strlen(_PATH_DEV); + return devname_r(sb.st_rdev, sb.st_mode & S_IFMT, buf, len); +#endif +} + + char * ttyname(int fd) { - static char buf[MAXPATHLEN]; + static char buf[PATH_MAX]; int rv; rv = ttyname_r(fd, buf, sizeof(buf)); diff --git a/lib/libc/gen/ualarm.3 b/lib/libc/gen/ualarm.3 index 7e5b7d357..39b91ae09 100644 --- a/lib/libc/gen/ualarm.3 +++ b/lib/libc/gen/ualarm.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: ualarm.3,v 1.18 2010/04/29 06:07:35 jruoho Exp $ +.\" $NetBSD: ualarm.3,v 1.19 2011/05/02 17:34:05 jruoho Exp $ .\" .\" Copyright (c) 1986, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)ualarm.3 8.2 (Berkeley) 4/19/94 .\" -.Dd April 29, 2010 +.Dd May 2, 2011 .Dt UALARM 3 .Os .Sh NAME @@ -91,16 +91,11 @@ returns ((useconds_t) -1). .Sh STANDARDS The .Fn ualarm -functions conforms to -.St -xpg4.2 -and +function conforms to .St -p1003.1-2001 . -The latter standard marked -.Fn ualarm -as obsolescent and a later revision, -.St -p1003.1-2008 , -removed the specification of -.Fn ualarm . +However, the later +.St -p1003.1-2008 +revision removed the function from the specification. .Sh HISTORY The .Fn ualarm diff --git a/lib/libc/gen/ualarm.c b/lib/libc/gen/ualarm.c index 2da867050..74c655bf5 100644 --- a/lib/libc/gen/ualarm.c +++ b/lib/libc/gen/ualarm.c @@ -1,4 +1,4 @@ -/* $NetBSD: ualarm.c,v 1.10 2003/08/07 16:42:58 agc Exp $ */ +/* $NetBSD: ualarm.c,v 1.11 2012/06/25 22:32:44 abs Exp $ */ /* * Copyright (c) 1985, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)ualarm.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: ualarm.c,v 1.10 2003/08/07 16:42:58 agc Exp $"); +__RCSID("$NetBSD: ualarm.c,v 1.11 2012/06/25 22:32:44 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,9 +54,7 @@ __weak_alias(ualarm,_ualarm) * every ``reload'' microseconds after the first signal. */ useconds_t -ualarm(usecs, reload) - useconds_t usecs; - useconds_t reload; +ualarm(useconds_t usecs, useconds_t reload) { struct itimerval new, old; diff --git a/lib/libc/gen/ulimit.c b/lib/libc/gen/ulimit.c index 03aa540d2..97c85b2af 100644 --- a/lib/libc/gen/ulimit.c +++ b/lib/libc/gen/ulimit.c @@ -44,9 +44,10 @@ ulimit(int cmd, ...) { va_list ap; struct rlimit rlimit; - long int result; #ifndef __minix - long int new_limit; + long int new_limit, result; +#else + long int result; #endif va_start(ap, cmd); diff --git a/lib/libc/gen/uname.3 b/lib/libc/gen/uname.3 index 33a2c0c4d..ffdd6b85a 100644 --- a/lib/libc/gen/uname.3 +++ b/lib/libc/gen/uname.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: uname.3,v 1.11 2010/04/27 15:16:28 jruoho Exp $ +.\" $NetBSD: uname.3,v 1.12 2011/03/30 16:41:00 jruoho Exp $ .\" .\" Copyright (c) 1994 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)uname.3 8.1 (Berkeley) 1/4/94 .\" -.Dd April 27, 2010 +.Dd March 30, 2011 .Dt UNAME 3 .Os .Sh NAME @@ -49,7 +49,7 @@ the current system into the structure referenced by .Fa name . .Pp The -.Li utsname +.Em utsname structure is defined in the .In sys/utsname.h header file, and contains the following members: diff --git a/lib/libc/gen/uname.c b/lib/libc/gen/uname.c index 4aa704b82..3e2f1c622 100644 --- a/lib/libc/gen/uname.c +++ b/lib/libc/gen/uname.c @@ -1,4 +1,4 @@ -/* $NetBSD: uname.c,v 1.10 2007/01/15 22:26:35 cbiere Exp $ */ +/* $NetBSD: uname.c,v 1.11 2012/03/20 16:36:05 matt Exp $ */ /*- * Copyright (c) 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)uname.c 8.1 (Berkeley) 1/4/94"; #else -__RCSID("$NetBSD: uname.c,v 1.10 2007/01/15 22:26:35 cbiere Exp $"); +__RCSID("$NetBSD: uname.c,v 1.11 2012/03/20 16:36:05 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,8 +51,7 @@ __weak_alias(uname,_uname) #endif int -uname(name) - struct utsname *name; +uname(struct utsname *name) { int mib[2]; size_t len; diff --git a/lib/libc/gen/unvis.3 b/lib/libc/gen/unvis.3 index 3f6fdc550..69e1f729a 100644 --- a/lib/libc/gen/unvis.3 +++ b/lib/libc/gen/unvis.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: unvis.3,v 1.20 2010/11/28 01:28:21 wiz Exp $ +.\" $NetBSD: unvis.3,v 1.23 2011/03/17 14:06:29 wiz Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)unvis.3 8.2 (Berkeley) 12/11/93 .\" -.Dd November 27, 2010 +.Dd March 12, 2011 .Dt UNVIS 3 .Os .Sh NAME @@ -45,7 +45,11 @@ .Ft int .Fn strunvis "char *dst" "const char *src" .Ft int +.Fn strnunvis "char *dst" "size_t dlen" "const char *src" +.Ft int .Fn strunvisx "char *dst" "const char *src" "int flag" +.Ft int +.Fn strnunvisx "char *dst" "size_t dlen" "const char *src" "int flag" .Sh DESCRIPTION The .Fn unvis , @@ -191,6 +195,32 @@ again: if (unvis(\*[Am]out, '\e0', \*[Am]state, UNVIS_END) == UNVIS_VALID) (void)putchar(out); .Ed +.Sh ERRORS +The functions +.Fn strunvis , +.Fn strnunvis , +.Fn strunvisx , +and +.Fn strnunvisx +will return \-1 on error and set +.Va errno +to: +.Bl -tag -width Er +.It Bq Er EINVAL +An invalid escape sequence was detected, or the decoder is in an unknown state. +.El +.Pp +In addition the functions +.Fn strnunvis +and +.Fn strnunvisx +will can also set +.Va errno +on error to: +.Bl -tag -width Er +.It Bq Er ENOSPC +Not enough space to perform the conversion. +.El .Sh SEE ALSO .Xr unvis 1 , .Xr vis 1 , @@ -206,3 +236,9 @@ The function first appeared in .Bx 4.4 . +The +.Fn strnunvis +and +.Fn strnunvisx +functions appeared in +.Nx 6.0 . diff --git a/lib/libc/gen/unvis.c b/lib/libc/gen/unvis.c index 13bc869fc..8d460c34b 100644 --- a/lib/libc/gen/unvis.c +++ b/lib/libc/gen/unvis.c @@ -1,4 +1,4 @@ -/* $NetBSD: unvis.c,v 1.32 2010/11/27 21:22:11 christos Exp $ */ +/* $NetBSD: unvis.c,v 1.39 2012/03/13 21:13:37 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: unvis.c,v 1.32 2010/11/27 21:22:11 christos Exp $"); +__RCSID("$NetBSD: unvis.c,v 1.39 2012/03/13 21:13:37 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -43,11 +43,13 @@ __RCSID("$NetBSD: unvis.c,v 1.32 2010/11/27 21:22:11 christos Exp $"); #include #include +#include #include +#include #include #ifdef __weak_alias -__weak_alias(strunvis,_strunvis) +__weak_alias(strnunvisx,_strnunvisx) #endif #if !HAVE_VIS @@ -61,18 +63,19 @@ __weak_alias(strunvis,_strunvis) #define S_CTRL 4 /* control char started (^) */ #define S_OCTAL2 5 /* octal digit 2 */ #define S_OCTAL3 6 /* octal digit 3 */ -#define S_HEX1 7 /* http hex digit */ -#define S_HEX2 8 /* http hex digit 2 */ -#define S_MIME1 9 /* mime hex digit 1 */ -#define S_MIME2 10 /* mime hex digit 2 */ -#define S_EATCRNL 11 /* mime eating CRNL */ -#define S_AMP 12 /* seen & */ -#define S_NUMBER 13 /* collecting number */ -#define S_STRING 14 /* collecting string */ +#define S_HEX 7 /* mandatory hex digit */ +#define S_HEX1 8 /* http hex digit */ +#define S_HEX2 9 /* http hex digit 2 */ +#define S_MIME1 10 /* mime hex digit 1 */ +#define S_MIME2 11 /* mime hex digit 2 */ +#define S_EATCRNL 12 /* mime eating CRNL */ +#define S_AMP 13 /* seen & */ +#define S_NUMBER 14 /* collecting number */ +#define S_STRING 15 /* collecting string */ #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') -#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10)) -#define XTOD(c) (isdigit(c) ? (c - '0') : ((c - 'A') + 10)) +#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10)) +#define XTOD(c) (isdigit(c) ? (c - '0') : ((c - 'A') + 10)) /* * RFC 1866 @@ -295,6 +298,9 @@ unvis(char *cp, int c, int *astate, int flag) *cp = '\033'; *astate = SS(0, S_GROUND); return UNVIS_VALID; + case 'x': + *astate = SS(0, S_HEX); + return UNVIS_NOCHAR; case '\n': /* * hidden newline @@ -358,6 +364,10 @@ unvis(char *cp, int c, int *astate, int flag) */ return UNVIS_VALIDPUSH; + case S_HEX: + if (!isxdigit(uc)) + goto bad; + /*FALLTHROUGH*/ case S_HEX1: if (isxdigit(uc)) { *cp = xtod(uc); @@ -436,7 +446,7 @@ unvis(char *cp, int c, int *astate, int flag) break; } - if (*cp == __arraycount(nv)) + if (ia == __arraycount(nv)) goto bad; if (uc != 0) { @@ -468,47 +478,76 @@ unvis(char *cp, int c, int *astate, int flag) } /* - * strunvis - decode src into dst + * strnunvisx - decode src into dst * * Number of chars decoded into dst is returned, -1 on error. * Dst is null terminated. */ int -strunvisx(char *dst, const char *src, int flag) +strnunvisx(char *dst, size_t dlen, const char *src, int flag) { char c; - char *start = dst; + char t = '\0', *start = dst; int state = 0; _DIAGASSERT(src != NULL); _DIAGASSERT(dst != NULL); +#define CHECKSPACE() \ + do { \ + if (dlen-- == 0) { \ + errno = ENOSPC; \ + return -1; \ + } \ + } while (/*CONSTCOND*/0) while ((c = *src++) != '\0') { again: - switch (unvis(dst, c, &state, flag)) { + switch (unvis(&t, c, &state, flag)) { case UNVIS_VALID: - dst++; + CHECKSPACE(); + *dst++ = t; break; case UNVIS_VALIDPUSH: - dst++; + CHECKSPACE(); + *dst++ = t; goto again; case 0: case UNVIS_NOCHAR: break; + case UNVIS_SYNBAD: + errno = EINVAL; + return -1; default: - return (-1); + _DIAGASSERT(/*CONSTCOND*/0); + errno = EINVAL; + return -1; } } - if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID) - dst++; + if (unvis(&t, c, &state, UNVIS_END) == UNVIS_VALID) { + CHECKSPACE(); + *dst++ = t; + } + CHECKSPACE(); *dst = '\0'; return (int)(dst - start); } +int +strunvisx(char *dst, const char *src, int flag) +{ + return strnunvisx(dst, (size_t)~0, src, flag); +} + int strunvis(char *dst, const char *src) { - return strunvisx(dst, src, 0); + return strnunvisx(dst, (size_t)~0, src, 0); +} + +int +strnunvis(char *dst, size_t dlen, const char *src) +{ + return strnunvisx(dst, dlen, src, 0); } #endif diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c index 8722d5da0..8a7dcfb88 100644 --- a/lib/libc/gen/usleep.c +++ b/lib/libc/gen/usleep.c @@ -1,4 +1,4 @@ -/* $NetBSD: usleep.c,v 1.19 2008/04/28 20:22:59 martin Exp $ */ +/* $NetBSD: usleep.c,v 1.20 2012/06/25 22:32:44 abs Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: usleep.c,v 1.19 2008/04/28 20:22:59 martin Exp $"); +__RCSID("$NetBSD: usleep.c,v 1.20 2012/06/25 22:32:44 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -44,8 +44,7 @@ __weak_alias(usleep,_usleep) #endif int -usleep(useconds) - useconds_t useconds; +usleep(useconds_t useconds) { struct timespec ts; diff --git a/lib/libc/gen/utime.c b/lib/libc/gen/utime.c index 46534b87a..d41aac74c 100644 --- a/lib/libc/gen/utime.c +++ b/lib/libc/gen/utime.c @@ -1,4 +1,4 @@ -/* $NetBSD: utime.c,v 1.13 2010/03/23 20:28:59 drochner Exp $ */ +/* $NetBSD: utime.c,v 1.14 2012/06/25 22:32:44 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)utime.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: utime.c,v 1.13 2010/03/23 20:28:59 drochner Exp $"); +__RCSID("$NetBSD: utime.c,v 1.14 2012/06/25 22:32:44 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -47,9 +47,7 @@ __RCSID("$NetBSD: utime.c,v 1.13 2010/03/23 20:28:59 drochner Exp $"); #include int -utime(path, times) - const char *path; - const struct utimbuf *times; +utime(const char *path, const struct utimbuf *times) { struct timeval tv[2], *tvp; diff --git a/lib/libc/gen/utmp.c b/lib/libc/gen/utmp.c index 2bd00eff9..2b3698201 100644 --- a/lib/libc/gen/utmp.c +++ b/lib/libc/gen/utmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: utmp.c,v 1.9 2009/02/05 23:52:55 lukem Exp $ */ +/* $NetBSD: utmp.c,v 1.10 2011/10/15 23:00:02 christos Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: utmp.c,v 1.9 2009/02/05 23:52:55 lukem Exp $"); +__RCSID("$NetBSD: utmp.c,v 1.10 2011/10/15 23:00:02 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -61,7 +61,7 @@ getutent(void) if (ut == NULL) { struct stat st; off_t numentries; - if ((ut = fopen(utfile, "r")) == NULL) + if ((ut = fopen(utfile, "re")) == NULL) return NULL; if (fstat(fileno(ut), &st) == -1) goto out; diff --git a/lib/libc/gen/utmpx.c b/lib/libc/gen/utmpx.c index 2ba5bd63d..43fd1f08b 100644 --- a/lib/libc/gen/utmpx.c +++ b/lib/libc/gen/utmpx.c @@ -1,4 +1,4 @@ -/* $NetBSD: utmpx.c,v 1.26 2009/01/11 02:46:27 christos Exp $ */ +/* $NetBSD: utmpx.c,v 1.30 2012/06/24 15:26:03 christos Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: utmpx.c,v 1.26 2009/01/11 02:46:27 christos Exp $"); +__RCSID("$NetBSD: utmpx.c,v 1.30 2012/06/24 15:26:03 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -76,7 +76,7 @@ old2new(struct utmpx *utx) struct timeval *tv = &utx->ut_tv; (void)memcpy(&otv, tv, sizeof(otv)); tv->tv_sec = otv.tv_sec; - tv->tv_usec = otv.tv_usec; + tv->tv_usec = (suseconds_t)otv.tv_usec; } static void @@ -90,7 +90,7 @@ new2old(struct utmpx *utx) } void -setutxent() +setutxent(void) { (void)memset(&ut, 0, sizeof(ut)); @@ -101,7 +101,7 @@ setutxent() void -endutxent() +endutxent(void) { (void)memset(&ut, 0, sizeof(ut)); @@ -114,13 +114,13 @@ endutxent() struct utmpx * -getutxent() +getutxent(void) { if (fp == NULL) { struct stat st; - if ((fp = fopen(utfile, "r+")) == NULL) + if ((fp = fopen(utfile, "re+")) == NULL) if ((fp = fopen(utfile, "w+")) == NULL) { if ((fp = fopen(utfile, "r")) == NULL) goto fail; @@ -247,9 +247,15 @@ pututxline(const struct utmpx *utx) if (utx == NULL) return NULL; - if (strcmp(_PATH_UTMPX, utfile) == 0) - if ((fp != NULL && readonly) || (fp == NULL && geteuid() != 0)) - return utmp_update(utx); + if (strcmp(_PATH_UTMPX, utfile) == 0) { + if (geteuid() == 0) { + if (fp != NULL && readonly) + endutxent(); + } else { + if (fp == NULL || readonly) + return utmp_update(utx); + } + } (void)memcpy(&temp, utx, sizeof(temp)); diff --git a/lib/libc/gen/valloc.c b/lib/libc/gen/valloc.c index e92b73b5e..6a175faf0 100644 --- a/lib/libc/gen/valloc.c +++ b/lib/libc/gen/valloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: valloc.c,v 1.10 2003/08/07 16:42:59 agc Exp $ */ +/* $NetBSD: valloc.c,v 1.11 2012/06/25 22:32:44 abs Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)valloc.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: valloc.c,v 1.10 2003/08/07 16:42:59 agc Exp $"); +__RCSID("$NetBSD: valloc.c,v 1.11 2012/06/25 22:32:44 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -47,8 +47,7 @@ __weak_alias(valloc,_valloc) #endif void * -valloc(i) - size_t i; +valloc(size_t i) { long valsiz = getpagesize(), j; void *cp = malloc((size_t)(i + (valsiz-1))); diff --git a/lib/libc/gen/verr.c b/lib/libc/gen/verr.c index d78e32ea0..2d431f0e0 100644 --- a/lib/libc/gen/verr.c +++ b/lib/libc/gen/verr.c @@ -1,4 +1,4 @@ -/* $NetBSD: verr.c,v 1.14 2007/06/18 14:13:54 ginsbach Exp $ */ +/* $NetBSD: verr.c,v 1.15 2011/07/17 20:54:34 joerg Exp $ */ /*- * Copyright (c) 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: verr.c,v 1.14 2007/06/18 14:13:54 ginsbach Exp $"); +__RCSID("$NetBSD: verr.c,v 1.15 2011/07/17 20:54:34 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -56,7 +56,7 @@ __weak_alias(verr, _verr) #if !HAVE_ERR_H __dead void -verr(int eval, const char *fmt, _BSD_VA_LIST_ ap) +verr(int eval, const char *fmt, va_list ap) { int sverrno; diff --git a/lib/libc/gen/verrx.c b/lib/libc/gen/verrx.c index 951b8629c..e220a4b5f 100644 --- a/lib/libc/gen/verrx.c +++ b/lib/libc/gen/verrx.c @@ -1,4 +1,4 @@ -/* $NetBSD: verrx.c,v 1.14 2007/06/18 14:13:54 ginsbach Exp $ */ +/* $NetBSD: verrx.c,v 1.15 2011/07/17 20:54:34 joerg Exp $ */ /*- * Copyright (c) 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: verrx.c,v 1.14 2007/06/18 14:13:54 ginsbach Exp $"); +__RCSID("$NetBSD: verrx.c,v 1.15 2011/07/17 20:54:34 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,7 +54,7 @@ __weak_alias(verrx, _verrx) #if !HAVE_ERR_H __dead void -verrx(int eval, const char *fmt, _BSD_VA_LIST_ ap) +verrx(int eval, const char *fmt, va_list ap) { (void)fprintf(stderr, "%s: ", getprogname()); if (fmt != NULL) diff --git a/lib/libc/gen/vis.3 b/lib/libc/gen/vis.3 index 68c7b84e1..6f1e9d5fa 100644 --- a/lib/libc/gen/vis.3 +++ b/lib/libc/gen/vis.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: vis.3,v 1.23 2009/02/10 23:06:31 christos Exp $ +.\" $NetBSD: vis.3,v 1.27 2011/05/17 07:10:39 joerg Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,16 +29,22 @@ .\" .\" @(#)vis.3 8.1 (Berkeley) 6/9/93 .\" -.Dd February 10, 2009 +.Dd March 12, 2011 .Dt VIS 3 .Os .Sh NAME .Nm vis , +.Nm nvis , .Nm strvis , +.Nm strnvis , .Nm strvisx , +.Nm strnvisx , .Nm svis , +.Nm snvis , .Nm strsvis , +.Nm strsnvis , .Nm strsvisx +.Nm strsnvisx .Nd visually encode characters .Sh LIBRARY .Lb libc @@ -46,16 +52,28 @@ .In vis.h .Ft char * .Fn vis "char *dst" "int c" "int flag" "int nextc" +.Ft char * +.Fn nvis "char *dst" "size_t dlen" "int c" "int flag" "int nextc" .Ft int .Fn strvis "char *dst" "const char *src" "int flag" .Ft int +.Fn strnvis "char *dst" "size_t dlen" "const char *src" "int flag" +.Ft int .Fn strvisx "char *dst" "const char *src" "size_t len" "int flag" +.Ft int +.Fn strnvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" .Ft char * .Fn svis "char *dst" "int c" "int flag" "int nextc" "const char *extra" +.Ft char * +.Fn snvis "char *dst" "size_t dlen" "int c" "int flag" "int nextc" "const char *extra" .Ft int .Fn strsvis "char *dst" "const char *src" "int flag" "const char *extra" .Ft int +.Fn strsnvis "char *dst" "size_t dlen" "const char *src" "int flag" "const char *extra" +.Ft int .Fn strsvisx "char *dst" "const char *src" "size_t len" "int flag" "const char *extra" +.Ft int +.Fn strsnvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "const char *extra" .Sh DESCRIPTION The .Fn vis @@ -86,9 +104,11 @@ is only used when selecting the encoding format (explained below). .Pp The -.Fn strvis +.Fn strvis , +.Fn strnvis , +.Fn strvisx , and -.Fn strvisx +.Fn strnvisx functions copy into .Fa dst a visual representation of @@ -96,14 +116,18 @@ the string .Fa src . The .Fn strvis -function encodes characters from +and +.Fn strnvis +functions encode characters from .Fa src up to the first .Dv NUL . The .Fn strvisx -function encodes exactly +and +.Fn strnvisx +functions encode exactly .Fa len characters from .Fa src @@ -125,17 +149,40 @@ Both forms return the number of characters in dst (not including the trailing .Dv NUL ) . +The +.Dq n +versions of the functions also take an additional argument +.Fa dlen +that indicates the length of the +.Fa dst +buffer. +If +.Fa dlen +is not large enough to fix the converted string then the +.Fn strnvis +and +.Fn strnvisx +functions return \-1 and set +.Va errno +to +.Dv ENOSPC . .Pp The functions .Fn svis , +.Fn snvis , .Fn strsvis , +.Fn strsnvis , +.Fn strsvisx , and -.Fn strsvisx +.Fn strsnvisx correspond to .Fn vis , +.Fn nvis , .Fn strvis , +.Fn strnvis , +.Fn strvisx , and -.Fn strvisx +.Fn strnvisx but have an additional argument .Fa extra , pointing to a @@ -149,17 +196,21 @@ of certain characters to shells. The encoding is a unique, invertible representation composed entirely of graphic characters; it can be decoded back into the original form using the -.Xr unvis 3 -or +.Xr unvis 3 , .Xr strunvis 3 +or +.Xr strnunvis 3 functions. .Pp There are two parameters that can be controlled: the range of characters that are encoded (applies only to .Fn vis , +.Fn nvis , .Fn strvis , +.Fn strnvis , +.Fn strvisx , and -.Fn strvisx ) , +.Fn strnvisx ) , and the type of representation used. By default, all non-graphic characters, except space, tab, and newline are encoded. @@ -191,9 +242,12 @@ return - in addition to all graphic characters - unencoded. .Pp (The above flags have no effect for .Fn svis , +.Fn snvis , .Fn strsvis , +.Fn strsnvis , +.Fn strsvisx , and -.Fn strsvisx . +.Fn strsnvisx . When using these functions, place all graphic characters to be encoded in an array pointed to by .Fa extra . @@ -328,6 +382,29 @@ meta characters as .Ql M-C ) . With this flag set, the encoding is ambiguous and non-invertible. +.Sh ERRORS +The functions +.Fn nvis +and +.Fn snvis +will return +.Dv NULL +and the functions +.Fn strnvis , +.Fn strnvisx , +.Fn strsnvis , +and +.Fn strsnvisx , +will return \-1 when the +.Fa dlen +destination buffer length size is not enough to perform the conversion while +setting +.Va errno +to: +.Bl -tag -width Er +.It Bq Er ENOSPC +The destination buffer size is not large enough to perform the conversion. +.El .Sh SEE ALSO .Xr unvis 1 , .Xr vis 1 , @@ -339,16 +416,26 @@ ambiguous and non-invertible. .Re .Sh HISTORY The -.Fa vis , -.Fa strvis , +.Fn vis , +.Fn strvis , and .Fa strvisx functions first appeared in .Bx 4.4 . The -.Fa svis , -.Fa strsvis , +.Fn svis , +.Fn strsvis , and -.Fa strsvisx +.Fn strsvisx functions appeared in .Nx 1.5 . +The buffer size limited versions of the functions +.Po Fn nvis , +.Fn strnvis , +.Fn strnvisx , +.Fn snvis , +.Fn strsnvis , +and +.Fn strsnvisx Pc +appeared in +.Nx 6.0 . diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c index 477309623..d20694410 100644 --- a/lib/libc/gen/vis.c +++ b/lib/libc/gen/vis.c @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.41 2009/11/23 10:08:47 plunky Exp $ */ +/* $NetBSD: vis.c,v 1.44 2011/03/12 19:52:48 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -57,7 +57,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: vis.c,v 1.41 2009/11/23 10:08:47 plunky Exp $"); +__RCSID("$NetBSD: vis.c,v 1.44 2011/03/12 19:52:48 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -65,15 +65,11 @@ __RCSID("$NetBSD: vis.c,v 1.41 2009/11/23 10:08:47 plunky Exp $"); #include #include +#include #include #ifdef __weak_alias -__weak_alias(strsvis,_strsvis) -__weak_alias(strsvisx,_strsvisx) -__weak_alias(strvis,_strvis) __weak_alias(strvisx,_strvisx) -__weak_alias(svis,_svis) -__weak_alias(vis,_vis) #endif #if !HAVE_VIS || !HAVE_SVIS @@ -82,7 +78,7 @@ __weak_alias(vis,_vis) #include #include -static char *do_svis(char *, int, int, int, const char *); +static char *do_svis(char *, size_t *, int, int, int, const char *); #undef BELL #define BELL '\a' @@ -118,7 +114,7 @@ do { \ * This is do_hvis, for HTTP style (RFC 1808) */ static char * -do_hvis(char *dst, int c, int flag, int nextc, const char *extra) +do_hvis(char *dst, size_t *dlen, int c, int flag, int nextc, const char *extra) { if ((isascii(c) && isalnum(c)) @@ -127,8 +123,13 @@ do_hvis(char *dst, int c, int flag, int nextc, const char *extra) /* extra */ || c == '!' || c == '*' || c == '\'' || c == '(' || c == ')' || c == ',') { - dst = do_svis(dst, c, flag, nextc, extra); + dst = do_svis(dst, dlen, c, flag, nextc, extra); } else { + if (dlen) { + if (*dlen < 3) + return NULL; + *dlen -= 3; + } *dst++ = '%'; *dst++ = xtoa(((unsigned int)c >> 4) & 0xf); *dst++ = xtoa((unsigned int)c & 0xf); @@ -142,7 +143,7 @@ do_hvis(char *dst, int c, int flag, int nextc, const char *extra) * NB: No handling of long lines or CRLF. */ static char * -do_mvis(char *dst, int c, int flag, int nextc, const char *extra) +do_mvis(char *dst, size_t *dlen, int c, int flag, int nextc, const char *extra) { if ((c != '\n') && /* Space at the end of the line */ @@ -151,11 +152,16 @@ do_mvis(char *dst, int c, int flag, int nextc, const char *extra) (!isspace(c) && (c < 33 || (c > 60 && c < 62) || c > 126)) || /* Specific char to be escaped */ strchr("#$@[\\]^`{|}~", c) != NULL)) { + if (dlen) { + if (*dlen < 3) + return NULL; + *dlen -= 3; + } *dst++ = '='; *dst++ = XTOA(((unsigned int)c >> 4) & 0xf); *dst++ = XTOA((unsigned int)c & 0xf); } else { - dst = do_svis(dst, c, flag, nextc, extra); + dst = do_svis(dst, dlen, c, flag, nextc, extra); } return dst; } @@ -170,16 +176,28 @@ do_mvis(char *dst, int c, int flag, int nextc, const char *extra) * backslash-protected. */ static char * -do_svis(char *dst, int c, int flag, int nextc, const char *extra) +do_svis(char *dst, size_t *dlen, int c, int flag, int nextc, const char *extra) { int isextra; + size_t odlen = dlen ? *dlen : 0; + isextra = strchr(extra, c) != NULL; +#define HAVE(x) \ + do { \ + if (dlen) { \ + if (*dlen < (x)) \ + goto out; \ + *dlen -= (x); \ + } \ + } while (/*CONSTCOND*/0) if (!isextra && isascii(c) && (isgraph(c) || iswhite(c) || ((flag & VIS_SAFE) && issafe(c)))) { + HAVE(1); *dst++ = c; return dst; } if (flag & VIS_CSTYLE) { + HAVE(2); switch (c) { case '\n': *dst++ = '\\'; *dst++ = 'n'; @@ -208,6 +226,7 @@ do_svis(char *dst, int c, int flag, int nextc, const char *extra) case '\0': *dst++ = '\\'; *dst++ = '0'; if (isoctal(nextc)) { + HAVE(2); *dst++ = '0'; *dst++ = '0'; } @@ -217,32 +236,46 @@ do_svis(char *dst, int c, int flag, int nextc, const char *extra) *dst++ = '\\'; *dst++ = c; return dst; } + if (dlen) + *dlen = odlen; } } if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) { + HAVE(4); *dst++ = '\\'; *dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0'; *dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0'; *dst++ = (c & 07) + '0'; } else { - if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\'; + if ((flag & VIS_NOSLASH) == 0) { + HAVE(1); + *dst++ = '\\'; + } + if (c & 0200) { + HAVE(1); c &= 0177; *dst++ = 'M'; } + if (iscntrl(c)) { + HAVE(2); *dst++ = '^'; if (c == 0177) *dst++ = '?'; else *dst++ = c + '@'; } else { + HAVE(2); *dst++ = '-'; *dst++ = c; } } return dst; +out: + *dlen = odlen; + return NULL; } -typedef char *(*visfun_t)(char *, int, int, int, const char *); +typedef char *(*visfun_t)(char *, size_t *, int, int, int, const char *); /* * Return the appropriate encoding function depending on the flags given. @@ -258,11 +291,11 @@ getvisfun(int flag) } /* - * svis - visually encode characters, also encoding the characters + * isnvis - visually encode characters, also encoding the characters * pointed to by `extra' */ -char * -svis(char *dst, int c, int flag, int nextc, const char *extra) +static char * +isnvis(char *dst, size_t *dlen, int c, int flag, int nextc, const char *extra) { char *nextra = NULL; visfun_t f; @@ -271,16 +304,36 @@ svis(char *dst, int c, int flag, int nextc, const char *extra) _DIAGASSERT(extra != NULL); MAKEEXTRALIST(flag, nextra, extra); if (!nextra) { + if (dlen && *dlen == 0) { + errno = ENOSPC; + return NULL; + } *dst = '\0'; /* can't create nextra, return "" */ return dst; } f = getvisfun(flag); - dst = (*f)(dst, c, flag, nextc, nextra); + dst = (*f)(dst, dlen, c, flag, nextc, nextra); free(nextra); + if (dst == NULL || (dlen && *dlen == 0)) { + errno = ENOSPC; + return NULL; + } *dst = '\0'; return dst; } +char * +svis(char *dst, int c, int flag, int nextc, const char *extra) +{ + return isnvis(dst, NULL, c, flag, nextc, extra); +} + +char * +snvis(char *dst, size_t dlen, int c, int flag, int nextc, const char *extra) +{ + return isnvis(dst, &dlen, c, flag, nextc, extra); +} + /* * strsvis, strsvisx - visually encode characters from src into dst @@ -297,8 +350,8 @@ svis(char *dst, int c, int flag, int nextc, const char *extra) * Strsvisx encodes exactly len bytes from src into dst. * This is useful for encoding a block of data. */ -int -strsvis(char *dst, const char *csrc, int flag, const char *extra) +static int +istrsnvis(char *dst, size_t *dlen, const char *csrc, int flag, const char *extra) { int c; char *start; @@ -315,16 +368,37 @@ strsvis(char *dst, const char *csrc, int flag, const char *extra) return 0; } f = getvisfun(flag); - for (start = dst; (c = *src++) != '\0'; /* empty */) - dst = (*f)(dst, c, flag, *src, nextra); + for (start = dst; (c = *src++) != '\0'; /* empty */) { + dst = (*f)(dst, dlen, c, flag, *src, nextra); + if (dst == NULL) { + errno = ENOSPC; + return -1; + } + } free(nextra); + if (dlen && *dlen == 0) { + errno = ENOSPC; + return -1; + } *dst = '\0'; return (int)(dst - start); } +int +strsvis(char *dst, const char *csrc, int flag, const char *extra) +{ + return istrsnvis(dst, NULL, csrc, flag, extra); +} int -strsvisx(char *dst, const char *csrc, size_t len, int flag, const char *extra) +strsnvis(char *dst, size_t dlen, const char *csrc, int flag, const char *extra) +{ + return istrsnvis(dst, &dlen, csrc, flag, extra); +} + +static int +istrsnvisx(char *dst, size_t *dlen, const char *csrc, size_t len, int flag, + const char *extra) { unsigned char c; char *start; @@ -337,6 +411,10 @@ strsvisx(char *dst, const char *csrc, size_t len, int flag, const char *extra) _DIAGASSERT(extra != NULL); MAKEEXTRALIST(flag, nextra, extra); if (! nextra) { + if (dlen && *dlen == 0) { + errno = ENOSPC; + return -1; + } *dst = '\0'; /* can't create nextra, return "" */ return 0; } @@ -344,20 +422,41 @@ strsvisx(char *dst, const char *csrc, size_t len, int flag, const char *extra) f = getvisfun(flag); for (start = dst; len > 0; len--) { c = *src++; - dst = (*f)(dst, c, flag, len > 1 ? *src : '\0', nextra); + dst = (*f)(dst, dlen, c, flag, len > 1 ? *src : '\0', nextra); + if (dst == NULL) { + errno = ENOSPC; + return -1; + } } free(nextra); + if (dlen && *dlen == 0) { + errno = ENOSPC; + return -1; + } *dst = '\0'; return (int)(dst - start); } + +int +strsvisx(char *dst, const char *csrc, size_t len, int flag, const char *extra) +{ + return istrsnvisx(dst, NULL, csrc, len, flag, extra); +} + +int +strsnvisx(char *dst, size_t dlen, const char *csrc, size_t len, int flag, + const char *extra) +{ + return istrsnvisx(dst, &dlen, csrc, len, flag, extra); +} #endif #if !HAVE_VIS /* * vis - visually encode characters */ -char * -vis(char *dst, int c, int flag, int nextc) +static char * +invis(char *dst, size_t *dlen, int c, int flag, int nextc) { char *extra = NULL; unsigned char uc = (unsigned char)c; @@ -367,16 +466,36 @@ vis(char *dst, int c, int flag, int nextc) MAKEEXTRALIST(flag, extra, ""); if (! extra) { + if (dlen && *dlen == 0) { + errno = ENOSPC; + return NULL; + } *dst = '\0'; /* can't create extra, return "" */ return dst; } f = getvisfun(flag); - dst = (*f)(dst, uc, flag, nextc, extra); + dst = (*f)(dst, dlen, uc, flag, nextc, extra); free(extra); + if (dst == NULL || (dlen && *dlen == 0)) { + errno = ENOSPC; + return NULL; + } *dst = '\0'; return dst; } +char * +vis(char *dst, int c, int flag, int nextc) +{ + return invis(dst, NULL, c, flag, nextc); +} + +char * +nvis(char *dst, size_t dlen, int c, int flag, int nextc) +{ + return invis(dst, &dlen, c, flag, nextc); +} + /* * strvis, strvisx - visually encode characters from src into dst @@ -388,36 +507,68 @@ vis(char *dst, int c, int flag, int nextc) * Strvisx encodes exactly len bytes from src into dst. * This is useful for encoding a block of data. */ -int -strvis(char *dst, const char *src, int flag) +static int +istrnvis(char *dst, size_t *dlen, const char *src, int flag) { char *extra = NULL; int rv; MAKEEXTRALIST(flag, extra, ""); if (!extra) { + if (dlen && *dlen == 0) { + errno = ENOSPC; + return -1; + } *dst = '\0'; /* can't create extra, return "" */ return 0; } - rv = strsvis(dst, src, flag, extra); + rv = istrsnvis(dst, dlen, src, flag, extra); free(extra); return rv; } +int +strvis(char *dst, const char *src, int flag) +{ + return istrnvis(dst, NULL, src, flag); +} int -strvisx(char *dst, const char *src, size_t len, int flag) +strnvis(char *dst, size_t dlen, const char *src, int flag) +{ + return istrnvis(dst, &dlen, src, flag); +} + +static int +istrnvisx(char *dst, size_t *dlen, const char *src, size_t len, int flag) { char *extra = NULL; int rv; MAKEEXTRALIST(flag, extra, ""); if (!extra) { + if (dlen && *dlen == 0) { + errno = ENOSPC; + return -1; + } *dst = '\0'; /* can't create extra, return "" */ return 0; } - rv = strsvisx(dst, src, len, flag, extra); + rv = istrsnvisx(dst, dlen, src, len, flag, extra); free(extra); return rv; } + +int +strvisx(char *dst, const char *src, size_t len, int flag) +{ + return istrnvisx(dst, NULL, src, len, flag); +} + +int +strnvisx(char *dst, size_t dlen, const char *src, size_t len, int flag) +{ + return istrnvisx(dst, &dlen, src, len, flag); +} + #endif diff --git a/lib/libc/gen/vwarn.c b/lib/libc/gen/vwarn.c index 802efdc62..ba0598d01 100644 --- a/lib/libc/gen/vwarn.c +++ b/lib/libc/gen/vwarn.c @@ -1,4 +1,4 @@ -/* $NetBSD: vwarn.c,v 1.14 2007/06/18 14:13:54 ginsbach Exp $ */ +/* $NetBSD: vwarn.c,v 1.15 2011/07/17 20:54:34 joerg Exp $ */ /*- * Copyright (c) 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vwarn.c,v 1.14 2007/06/18 14:13:54 ginsbach Exp $"); +__RCSID("$NetBSD: vwarn.c,v 1.15 2011/07/17 20:54:34 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -56,7 +56,7 @@ __weak_alias(vwarn, _vwarn) #if !HAVE_ERR_H void -vwarn(const char *fmt, _BSD_VA_LIST_ ap) +vwarn(const char *fmt, va_list ap) { int sverrno; diff --git a/lib/libc/gen/vwarnx.c b/lib/libc/gen/vwarnx.c index 60f849d9a..eedf550f0 100644 --- a/lib/libc/gen/vwarnx.c +++ b/lib/libc/gen/vwarnx.c @@ -1,4 +1,4 @@ -/* $NetBSD: vwarnx.c,v 1.14 2007/06/18 14:13:54 ginsbach Exp $ */ +/* $NetBSD: vwarnx.c,v 1.15 2011/07/17 20:54:34 joerg Exp $ */ /*- * Copyright (c) 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vwarnx.c,v 1.14 2007/06/18 14:13:54 ginsbach Exp $"); +__RCSID("$NetBSD: vwarnx.c,v 1.15 2011/07/17 20:54:34 joerg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,7 +54,7 @@ __weak_alias(vwarnx, _vwarnx) #if !HAVE_ERR_H void -vwarnx(const char *fmt, _BSD_VA_LIST_ ap) +vwarnx(const char *fmt, va_list ap) { (void)fprintf(stderr, "%s: ", getprogname()); if (fmt != NULL) diff --git a/lib/libc/gen/wait.c b/lib/libc/gen/wait.c index 2877c4de6..776e276b2 100644 --- a/lib/libc/gen/wait.c +++ b/lib/libc/gen/wait.c @@ -1,4 +1,4 @@ -/* $NetBSD: wait.c,v 1.8 2003/08/07 16:43:00 agc Exp $ */ +/* $NetBSD: wait.c,v 1.9 2012/03/20 16:36:05 matt Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)wait.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: wait.c,v 1.8 2003/08/07 16:43:00 agc Exp $"); +__RCSID("$NetBSD: wait.c,v 1.9 2012/03/20 16:36:05 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,8 +50,7 @@ __weak_alias(wait,_wait) pid_t -wait(istat) - int *istat; +wait(int *istat) { - return (wait4(WAIT_ANY, istat, 0, (struct rusage *)0)); + return (wait4(WAIT_ANY, istat, 0, (struct rusage *)NULL)); } diff --git a/lib/libc/gen/wait3.c b/lib/libc/gen/wait3.c index 3152552aa..9dfbeaa2e 100644 --- a/lib/libc/gen/wait3.c +++ b/lib/libc/gen/wait3.c @@ -1,4 +1,4 @@ -/* $NetBSD: wait3.c,v 1.9 2010/03/23 20:28:59 drochner Exp $ */ +/* $NetBSD: wait3.c,v 1.10 2012/03/20 16:36:05 matt Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)wait3.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: wait3.c,v 1.9 2010/03/23 20:28:59 drochner Exp $"); +__RCSID("$NetBSD: wait3.c,v 1.10 2012/03/20 16:36:05 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -45,10 +45,7 @@ __RCSID("$NetBSD: wait3.c,v 1.9 2010/03/23 20:28:59 drochner Exp $"); #include pid_t -wait3(istat, options, rup) - int *istat; - int options; - struct rusage *rup; +wait3(int *istat, int options, struct rusage *rup) { return (wait4(WAIT_ANY, istat, options, rup)); } diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c index d4f31b019..e4bcea208 100644 --- a/lib/libc/gmon/gmon.c +++ b/lib/libc/gmon/gmon.c @@ -1,4 +1,4 @@ -/* $NetBSD: gmon.c,v 1.33 2011/01/05 00:03:52 wiz Exp $ */ +/* $NetBSD: gmon.c,v 1.34 2012/03/13 21:13:37 christos Exp $ */ /* * Copyright (c) 2003, 2004 Wasabi Systems, Inc. @@ -69,7 +69,7 @@ #if 0 static char sccsid[] = "@(#)gmon.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: gmon.c,v 1.33 2011/01/05 00:03:52 wiz Exp $"); +__RCSID("$NetBSD: gmon.c,v 1.34 2012/03/13 21:13:37 christos Exp $"); #endif #endif @@ -228,7 +228,7 @@ _m_gmon_alloc(void) cp = mmap(NULL, (size_t)(sizeof (struct gmonparam) + _gmonparam.fromssize + _gmonparam.tossize), - PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0LL); + PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, (off_t)0); p = (void *)cp; *p = _gmonparam; p->kcount = NULL; diff --git a/lib/libc/hash/Makefile.inc b/lib/libc/hash/Makefile.inc index 3b5879abf..beecbf416 100644 --- a/lib/libc/hash/Makefile.inc +++ b/lib/libc/hash/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.11 2006/10/27 18:29:21 drochner Exp $ +# $NetBSD: Makefile.inc,v 1.12 2012/07/08 01:21:12 rmind Exp $ # $OpenBSD: Makefile.inc,v 1.5 1997/07/17 06:02:42 millert Exp $ # hash functions @@ -9,3 +9,4 @@ .include "${.CURDIR}/hash/sha1/Makefile.inc" .include "${.CURDIR}/hash/sha2/Makefile.inc" +.include "${.CURDIR}/hash/murmurhash/Makefile.inc" diff --git a/lib/libc/hash/md2/md2.c b/lib/libc/hash/md2/md2.c index 8e6367cf6..b353a7918 100644 --- a/lib/libc/hash/md2/md2.c +++ b/lib/libc/hash/md2/md2.c @@ -1,4 +1,4 @@ -/* $NetBSD: md2.c,v 1.5 2008/04/28 20:23:00 martin Exp $ */ +/* $NetBSD: md2.c,v 1.7 2012/06/25 22:32:44 abs Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: md2.c,v 1.5 2008/04/28 20:23:00 martin Exp $"); +__RCSID("$NetBSD: md2.c,v 1.7 2012/06/25 22:32:44 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -110,8 +110,7 @@ __weak_alias(MD2Transform,_MD2Transform) #endif void -MD2Init(context) - MD2_CTX *context; +MD2Init(MD2_CTX *context) { _DIAGASSERT(context != 0); @@ -121,10 +120,7 @@ MD2Init(context) } void -MD2Update(context, input, inputLen) - MD2_CTX *context; - const unsigned char *input; - unsigned int inputLen; +MD2Update(MD2_CTX *context, const unsigned char *input, unsigned int inputLen) { unsigned int idx, piece; @@ -142,9 +138,7 @@ MD2Update(context, input, inputLen) } void -MD2Final(digest, context) - unsigned char digest[16]; /* message digest */ - MD2_CTX *context; /* context */ +MD2Final(unsigned char digest[16], MD2_CTX *context) { unsigned int padlen; @@ -168,10 +162,9 @@ MD2Final(digest, context) } /*static*/ void -MD2Transform(context) - MD2_CTX *context; +MD2Transform(MD2_CTX *context) { - u_int32_t l, j, k, t; + uint32_t l, j, k, t; /* set block "3" and update "checksum" */ for (l = context->C[15], j = 0; j < 16; j++) { diff --git a/lib/libc/hash/murmurhash/Makefile.inc b/lib/libc/hash/murmurhash/Makefile.inc new file mode 100644 index 000000000..e109fc6e5 --- /dev/null +++ b/lib/libc/hash/murmurhash/Makefile.inc @@ -0,0 +1,5 @@ +# $NetBSD: Makefile.inc,v 1.1 2012/07/08 11:43:47 rmind Exp $ + +.PATH: ${.CURDIR}/hash/murmurhash + +SRCS+= murmurhash.c diff --git a/lib/libc/include/extern.h b/lib/libc/include/extern.h index 5bd012aa7..02f89ec93 100644 --- a/lib/libc/include/extern.h +++ b/lib/libc/include/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.17 2009/10/21 01:07:45 snj Exp $ */ +/* $NetBSD: extern.h,v 1.21 2012/10/11 17:09:56 christos Exp $ */ /* * Copyright (c) 1997 Christos Zoulas. All rights reserved. @@ -24,12 +24,18 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef __minix +#include +#endif +#include +#include + __BEGIN_DECLS extern char *__minbrk; int __getcwd(char *, size_t); int __getlogin(char *, size_t); int __setlogin(const char *); -void _resumecontext(void); +void _resumecontext(void) __dead; const char *__strerror(int , char *, size_t); const char *__strsignal(int , char *, size_t); char *__dtoa(double, int, int, int *, int *, char **); @@ -46,23 +52,26 @@ char *__hldtoa(long double, const char *, int, int *, int *, char **); char *__ldtoa(long double *, int, int, int *, int *, char **); #endif +#ifndef __LIBC12_SOURCE__ struct syslog_data; void syslog_ss(int, struct syslog_data *, const char *, ...) - __attribute__((__format__(__printf__,3,4))); -void vsyslog_ss(int, struct syslog_data *, const char *, _BSD_VA_LIST_); -void vsyslog_ss(int, struct syslog_data *, const char *, _BSD_VA_LIST_) - __attribute__((__format__(__printf__,3,0))); + __RENAME(__syslog_ss60) __printflike(3, 4); +void vsyslog_ss(int, struct syslog_data *, const char *, va_list) + __RENAME(__vsyslog_ss60) __printflike(3, 0); void syslogp_ss(int, struct syslog_data *, const char *, const char *, - const char *, ...) __attribute__((__format__(__printf__,5,0))); + const char *, ...) __RENAME(__syslogp_ss60) __printflike(5, 0); void vsyslogp_ss(int, struct syslog_data *, const char *, const char *, - const char *, _BSD_VA_LIST_) __attribute__((__format__(__printf__,5,0))); + const char *, va_list) __RENAME(__vsyslogp_ss60) __printflike(5, 0); +#endif int snprintf_ss(char * __restrict, size_t, const char * __restrict, ...) - __attribute__((__format__(__printf__, 3, 4))); + __printflike(3, 4); int vsnprintf_ss(char * __restrict, size_t, const char * __restrict, - _BSD_VA_LIST_) __attribute__((__format__(__printf__, 3, 0))); + va_list) __printflike(3, 0); void _malloc_prefork(void); void _malloc_postfork(void); +int _sys_setcontext(const ucontext_t *); + __END_DECLS diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h index 6c876c322..71848e06e 100644 --- a/lib/libc/include/namespace.h +++ b/lib/libc/include/namespace.h @@ -1,4 +1,4 @@ -/* $NetBSD: namespace.h,v 1.146 2010/12/16 18:38:06 christos Exp $ */ +/* $NetBSD: namespace.h,v 1.156 2012/08/20 21:38:10 dsl Exp $ */ /*- * Copyright (c) 1997-2004 The NetBSD Foundation, Inc. @@ -39,6 +39,7 @@ #define catopen _catopen #define daylight _daylight #define difftime _difftime +#define devname_r _devname_r #define err _err #define errx _errx #ifdef _REENTRANT @@ -156,6 +157,10 @@ #define alarm _alarm #define alphasort _alphasort #define arc4random _arc4random +#define arc4random_addrandom _arc4random_addrandom +#define arc4random_buf _arc4random_buf +#define arc4random_stir _arc4random_stir +#define arc4random_uniform _arc4random_uniform #define asctime_r _asctime_r #define asprintf _asprintf #define atoll _atoll @@ -267,9 +272,11 @@ #define fnmatch _fnmatch #define fparseln _fparseln #define fpgetmask _fpgetmask +#define fpgetprec _fpgetprec #define fpgetround _fpgetround #define fpgetsticky _fpgetsticky #define fpsetmask _fpsetmask +#define fpsetprec _fpsetprec #define fpsetround _fpsetround #define fpsetsticky _fpsetsticky #define freenetconfigent _freenetconfigent @@ -326,6 +333,8 @@ #define getopt_long _getopt_long #define getpagesize _getpagesize #define getpass _getpass +#define getpassfd _getpassfd +#define getpass_r _getpass_r #define getprogname _getprogname #define getprotobyname _getprotobyname #define getprotobyname_r _getprotobyname_r @@ -439,6 +448,7 @@ #define lockf _lockf #define lrand48 _lrand48 #define lseek _lseek +#define membar_producer _membar_producer #define mergesort _mergesort #define mi_vector_hash _mi_vector_hash #define mkstemp _mkstemp @@ -453,6 +463,7 @@ #define mq_timedreceive _mq_timedreceive #define mq_timedsend _mq_timedsend #define mrand48 _mrand48 +#define murmurhash2 _murmurhash2 #define nc_perror _nc_perror #define nc_sperror _nc_sperror #define nanosleep _nanosleep @@ -598,11 +609,8 @@ #define strsignal _strsignal #define strsuftoll _strsuftoll #define strsuftollx _strsuftollx -#define strsvis _strsvis -#define strsvisx _strsvisx #define strtok_r _strtok_r -#define strunvis _strunvis -#define strvis _strvis +#define strnunvisx _strnunvisx #define strvisx _strvisx #define svc_auth_reg _svc_auth_reg #define svc_create _svc_create @@ -635,7 +643,6 @@ #define svcudp_bufcreate _svcudp_bufcreate #define svcudp_create _svcudp_create #define svcudp_enablecache _svcudp_enablecache -#define svis _svis #define sysarch _sys_sysarch #define sysctl _sysctl #define sysctlbyname _sysctlbyname @@ -674,7 +681,6 @@ #define ualarm _ualarm #define uname _uname #define unsetenv _unsetenv -#define unvis _unvis #define user_from_uid _user_from_uid #define usleep _usleep #define utime _utime @@ -682,7 +688,6 @@ #define uuid_is_nil _uuid_is_nil #define valloc _valloc #define vdprintf _vdprintf -#define vis _vis #define vdprintf _vdprintf #ifndef vsnprintf #define vsnprintf _vsnprintf @@ -758,6 +763,7 @@ #define xdr_rpcbs _xdr_rpcbs #define xdr_rpcbs _xdr_rpcbs #define xdr_short _xdr_short +#define xdr_sizeof _xdr_sizeof #define xdr_string _xdr_string #define xdr_u_char _xdr_u_char #define xdr_u_hyper _xdr_u_hyper @@ -810,6 +816,7 @@ #define yp_unbind _yp_unbind #define yperr_string _yperr_string #define ypprot_err _ypprot_err +#define yp_setbindtries _yp_setbindtries #define dlopen __dlopen #define dlclose __dlclose #define dlsym __dlsym diff --git a/lib/libc/include/reentrant.h b/lib/libc/include/reentrant.h index fcfe2f9f9..fa0963eef 100644 --- a/lib/libc/include/reentrant.h +++ b/lib/libc/include/reentrant.h @@ -1,4 +1,4 @@ -/* $NetBSD: reentrant.h,v 1.14 2009/01/11 02:46:28 christos Exp $ */ +/* $NetBSD: reentrant.h,v 1.15 2012/06/03 21:27:30 joerg Exp $ */ /*- * Copyright (c) 1997, 1998, 2003 The NetBSD Foundation, Inc. @@ -254,7 +254,17 @@ __END_DECLS #define thr_getspecific(k) #define thr_keydelete(k) -#define thr_once(o, f) +#if !defined(__minix) +static inline int +thr_once(once_t *once_control, void (*routine)(void)) +{ + if (__predict_false(once_control->pto_done == 0)) { + (*routine)(); + once_control->pto_done = 1; + } + return 0; +} +#endif /* defined(__minix) */ #define thr_sigsetmask(f, n, o) #define thr_self() #define thr_errno() diff --git a/lib/libc/inet/inet.3 b/lib/libc/inet/inet.3 index 30f42d41f..d028c5e7b 100644 --- a/lib/libc/inet/inet.3 +++ b/lib/libc/inet/inet.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: inet.3,v 1.1 2004/05/20 23:13:02 christos Exp $ +.\" $NetBSD: inet.3,v 1.5 2012/07/25 14:51:15 ginsbach Exp $ .\" .\" Copyright (c) 1983, 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)inet.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 30, 2003 +.Dd July 25, 2012 .Dt INET 3 .Os .Sh NAME @@ -119,6 +119,11 @@ or some other binary form, in network byte order) to presentation format It returns NULL if a system error occurs (in which case, .Va errno will have been set), or it returns a pointer to the destination string. +The +.Ar size +parameter is the size of the +.Ar buf +argument. .Pp The routine .Fn inet_ntoa @@ -280,6 +285,33 @@ is returned by and .Fn inet_network for malformed requests. +.Sh ERRORS +The +.Fn inet_ntop +and +.Fn inet_pton +functions may fail with +.Bl -tag -width Er +.It Bq Er EAFNOSUPPORT +The value of +.Fa af +was not +.Dv AF_INET +or +.Dv AF_INET6 . +.El +.Pp +The +.Fn inet_ntop +function may fail with +.Bl -tag -width Er +.It Bq Er ENOSPC +The +.Fa size +indicated for +.Fa dst +was too small to store the presentation form of the network address. +.El .Sh SEE ALSO .Xr byteorder 3 , .Xr gethostbyname 3 , @@ -299,43 +331,44 @@ for malformed requests. .Re .Sh STANDARDS The -.Nm inet_ntop +.Fn inet_ntop and -.Nm inet_pton +.Fn inet_pton functions conform to .St -p1003.1-2001 . Note that -.Nm inet_pton -does not accept 1-, 2-, or 3-part dotted addresses; all four parts +.Fn inet_pton +does not accept 1-, 2-, or 3-part dotted addresses; all four parts must be specified. +Additionally all four parts of a dotted address must be decimal. This is a narrower input set than that accepted by -.Nm inet_aton . +.Fn inet_aton . .Sh HISTORY The -.Nm inet_addr , -.Nm inet_network , -.Nm inet_makeaddr , -.Nm inet_lnaof +.Fn inet_addr , +.Fn inet_network , +.Fn inet_makeaddr , +.Fn inet_lnaof and -.Nm inet_netof +.Fn inet_netof functions appeared in .Bx 4.2 . They were changed to use -.Va in_addr_t +.Vt in_addr_t in place of -.Va unsigned long +.Vt unsigned long in .Nx 2.0 . The -.Nm inet_aton +.Fn inet_aton and -.Nm inet_ntoa +.Fn inet_ntoa functions appeared in .Bx 4.3 . The -.Nm inet_pton +.Fn inet_pton and -.Nm inet_ntop +.Fn inet_ntop functions appeared in BIND 4.9.4 and thence .Nx 1.3 ; they were also in @@ -357,6 +390,12 @@ The string returned by .Fn inet_ntoa resides in a static memory area. .Pp +The function .Fn inet_addr should return a -.Fa "struct in_addr" . +.Vt struct in_addr . +.Pp +The function +.Fn inet_network +does not support byte rearrangement for one, two, and three +part addresses. diff --git a/lib/libc/inet/inet_cidr_ntop.c b/lib/libc/inet/inet_cidr_ntop.c index bd8877227..0f9202586 100644 --- a/lib/libc/inet/inet_cidr_ntop.c +++ b/lib/libc/inet/inet_cidr_ntop.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_cidr_ntop.c,v 1.7 2009/04/12 17:07:16 christos Exp $ */ +/* $NetBSD: inet_cidr_ntop.c,v 1.8 2012/03/13 21:13:38 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -22,7 +22,7 @@ #if 0 static const char rcsid[] = "Id: inet_cidr_ntop.c,v 1.7 2006/10/11 02:18:18 marka Exp"; #else -__RCSID("$NetBSD: inet_cidr_ntop.c,v 1.7 2009/04/12 17:07:16 christos Exp $"); +__RCSID("$NetBSD: inet_cidr_ntop.c,v 1.8 2012/03/13 21:13:38 christos Exp $"); #endif #endif @@ -35,6 +35,7 @@ __RCSID("$NetBSD: inet_cidr_ntop.c,v 1.7 2009/04/12 17:07:16 christos Exp $"); #include #include +#include #include #include #include @@ -101,7 +102,8 @@ decoct(const u_char *src, size_t bytes, char *dst, size_t size) { } size -= (size_t)(dst - t); } - return (dst - odst); + _DIAGASSERT(__type_fit(int, dst - odst)); + return (int)(dst - odst); } /*% diff --git a/lib/libc/inet/inet_cidr_pton.c b/lib/libc/inet/inet_cidr_pton.c index 1ffbc9acf..2911f45f2 100644 --- a/lib/libc/inet/inet_cidr_pton.c +++ b/lib/libc/inet/inet_cidr_pton.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_cidr_pton.c,v 1.6 2009/04/12 17:07:16 christos Exp $ */ +/* $NetBSD: inet_cidr_pton.c,v 1.8 2012/03/20 17:08:13 matt Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -22,7 +22,7 @@ #if 0 static const char rcsid[] = "Id: inet_cidr_pton.c,v 1.6 2005/04/27 04:56:19 sra Exp"; #else -__RCSID("$NetBSD: inet_cidr_pton.c,v 1.6 2009/04/12 17:07:16 christos Exp $"); +__RCSID("$NetBSD: inet_cidr_pton.c,v 1.8 2012/03/20 17:08:13 matt Exp $"); #endif #endif @@ -40,6 +40,7 @@ __RCSID("$NetBSD: inet_cidr_pton.c,v 1.6 2009/04/12 17:07:16 christos Exp $"); #include #include #include +#include #include #include "port_after.h" @@ -54,10 +55,9 @@ __RCSID("$NetBSD: inet_cidr_pton.c,v 1.6 2009/04/12 17:07:16 christos Exp $"); __weak_alias(inet_cidr_pton,_inet_cidr_pton) #endif -static int inet_cidr_pton_ipv4 __P((const char *src, u_char *dst, - int *bits, int ipv6)); -static int inet_cidr_pton_ipv6 __P((const char *src, u_char *dst, - int *bits)); +static int inet_cidr_pton_ipv4(const char *src, u_char *dst, + int *bits, int ipv6); +static int inet_cidr_pton_ipv6(const char *src, u_char *dst, int *bits); static int getbits(const char *, int ipv6); @@ -96,7 +96,8 @@ static const char digits[] = "0123456789"; static int inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits, int ipv6) { const u_char *odst = dst; - int n, ch, tmp, bits; + int ch, bits; + ptrdiff_t n, tmp; size_t size = 4; /* Get the mantissa. */ @@ -188,7 +189,7 @@ inet_cidr_pton_ipv6(const char *src, u_char *dst, int *pbits) { pch = strchr((xdigits = xdigits_u), ch); if (pch != NULL) { val <<= 4; - val |= (pch - xdigits); + val |= (int)(pch - xdigits); if (val > 0xffff) return (0); saw_xdigit = 1; @@ -237,7 +238,7 @@ inet_cidr_pton_ipv6(const char *src, u_char *dst, int *pbits) { * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; + const ptrdiff_t n = tp - colonp; int i; if (tp == endp) @@ -276,7 +277,7 @@ getbits(const char *src, int ipv6) { if (cp == NULL) /*%< syntax */ return (-2); bits *= 10; - bits += cp - digits; + bits += (int)(cp - digits); if (bits == 0 && *src != '\0') /*%< no leading zeros */ return (-2); if (bits > (ipv6 ? 128 : 32)) /*%< range error */ diff --git a/lib/libc/inet/inet_net.3 b/lib/libc/inet/inet_net.3 index 324955b6e..3d9b6ef5f 100644 --- a/lib/libc/inet/inet_net.3 +++ b/lib/libc/inet/inet_net.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: inet_net.3,v 1.2 2008/04/30 13:10:50 martin Exp $ +.\" $NetBSD: inet_net.3,v 1.5 2012/07/20 20:48:59 wiz Exp $ .\" .\" Copyright (c) 1997 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd December 8, 2001 +.Dd July 20, 2012 .Dt INET_NET 3 .Os .Sh NAME @@ -48,14 +48,17 @@ The .Fn inet_net_ntop function converts an Internet network number from network format (usually a -.Ft struct in_addr +.Vt struct in_addr or some other binary form, in network byte order) to CIDR presentation format (suitable for external display purposes). +The .Fa bits -is the number of bits in +argument is the number of bits in .Fa src that are the network number. -It returns NULL if a system error occurs (in which case, +It returns +.Dv NULL +if an error occurs (in which case .Va errno will have been set), or it returns a pointer to the destination string. .Pp @@ -63,16 +66,13 @@ The .Fn inet_net_pton function converts a presentation format Internet network number (that is, printable form as held in a character string) to network format (usually a -.Ft struct in_addr +.Vt struct in_addr or some other internal binary representation, in network byte order). It returns the number of bits (either computed based on the class, or -specified with /CIDR), or -1 if a failure occurred +specified with /CIDR), or \-1 if a failure occurred (in which case .Va errno -will have been set. -It will be set to -.Er ENOENT -if the Internet network number was not valid). +will have been set). .Pp The currently supported values for .Fa af @@ -80,8 +80,9 @@ are .Dv AF_INET and .Dv AF_INET6 . +The .Fa size -is the size of the result buffer +argument is the size of the result buffer .Fa dst . .Sh NETWORK NUMBERS (IP VERSION 4) Internet network numbers may be specified in one of the following forms: @@ -95,11 +96,11 @@ a .Pp When four parts are specified, each is interpreted as a byte of data and assigned, from left to right, -to the four bytes of an Internet network number. Note -that when an Internet network number is viewed as a 32-bit +to the four bytes of an Internet network number. +Note that when an Internet network number is viewed as a 32-bit integer quantity on a system that uses little-endian byte order (such as the -.Tn Intel 386, 486 +.Tn Intel 386 , 486 , and .Tn Pentium processors) the bytes referred to above appear as @@ -108,14 +109,14 @@ That is, little-endian bytes are ordered from right to left. .Pp When a three part number is specified, the last part is interpreted as a 16-bit quantity and placed -in the right-most two bytes of the Internet network number. +in the rightmost two bytes of the Internet network number. This makes the three part number format convenient for specifying Class B network numbers as .Dq Li 128.net.host . .Pp When a two part number is supplied, the last part is interpreted as a 24-bit quantity and placed in -the right most three bytes of the Internet network number. +the rightmost three bytes of the Internet network number. This makes the two part number format convenient for specifying Class A network numbers as .Dq Li net.host . @@ -127,7 +128,7 @@ rearrangement. All numbers supplied as .Dq parts in a -.Ql \&. +.Ql \&. notation may be decimal, octal, or hexadecimal, as specified in the C language (i.e., a leading 0x or 0X implies @@ -137,15 +138,58 @@ otherwise, the number is interpreted as decimal). .\" .Sh NETWORK NUMBERS (IP VERSION 6) .\" XXX - document this! .\" +.Sh ERRORS +The +.Fn inet_net_ntop +and +.Fn inet_net_pton +functions may fail with +.Bl -tag -width Er +.It Bq Er EAFNOSUPPORT +The value of +.Fa af +was not +.Dv AF_INET +or +.Dv AF_INET6 . +.It Bq Er EMSGSIZE +The conversion of +.Fa src +overflows +.Fa size +of +.Fa dst . +.El +.Pp +The +.Fn inet_net_ntop +function may fail with +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa bits +argument contains an invalid number of bits +for the requested address family. +.El +.Pp +The +.Fn inet_net_pton +function may fail with +.Bl -tag -width Er +.It Bq Er ENOENT +The +.Fa src +was not a valid Internet network number. +.El .Sh SEE ALSO .Xr byteorder 3 , .Xr inet 3 , .Xr networks 5 .Sh HISTORY The -.Nm inet_net_ntop +.Fn inet_net_ntop and -.Nm inet_net_pton +.Fn inet_net_pton functions appeared in BIND 4.9.4 and thence .Nx 1.3 . Support for diff --git a/lib/libc/inet/inet_net_ntop.c b/lib/libc/inet/inet_net_ntop.c index b5ef9ccfb..41b2813f5 100644 --- a/lib/libc/inet/inet_net_ntop.c +++ b/lib/libc/inet/inet_net_ntop.c @@ -20,7 +20,7 @@ #ifdef notdef static const char rcsid[] = "Id: inet_net_ntop.c,v 1.1.2.1 2002/08/02 02:17:21 marka Exp "; #else -__RCSID("$NetBSD: inet_net_ntop.c,v 1.2 2009/02/07 07:25:22 lukem Exp $"); +__RCSID("$NetBSD: inet_net_ntop.c,v 1.3 2012/03/20 17:08:13 matt Exp $"); #endif #endif @@ -49,10 +49,10 @@ __weak_alias(inet_net_ntop,_inet_net_ntop) # define SPRINTF(x) sprintf x #endif -static char * inet_net_ntop_ipv4 __P((const u_char *src, int bits, - char *dst, size_t size)); -static char * inet_net_ntop_ipv6 __P((const u_char *src, int bits, - char *dst, size_t size)); +static char * inet_net_ntop_ipv4(const u_char *src, int bits, + char *dst, size_t size); +static char * inet_net_ntop_ipv6(const u_char *src, int bits, + char *dst, size_t size); /* * char * @@ -65,12 +65,7 @@ static char * inet_net_ntop_ipv6 __P((const u_char *src, int bits, * Paul Vixie (ISC), July 1996 */ char * -inet_net_ntop(af, src, bits, dst, size) - int af; - const void *src; - int bits; - char *dst; - size_t size; +inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size) { switch (af) { case AF_INET: @@ -97,11 +92,7 @@ inet_net_ntop(af, src, bits, dst, size) * Paul Vixie (ISC), July 1996 */ static char * -inet_net_ntop_ipv4(src, bits, dst, size) - const u_char *src; - int bits; - char *dst; - size_t size; +inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) { char *odst = dst; char *t; @@ -176,7 +167,8 @@ inet_net_ntop_ipv4(src, bits, dst, size) */ static char * -inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) { +inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) +{ u_int m; int b; size_t p; diff --git a/lib/libc/inet/inet_net_pton.c b/lib/libc/inet/inet_net_pton.c index fda0cc3d1..57b978289 100644 --- a/lib/libc/inet/inet_net_pton.c +++ b/lib/libc/inet/inet_net_pton.c @@ -20,7 +20,7 @@ #if 0 static const char rcsid[] = "Id: inet_net_pton.c,v 1.4.2.1 2002/08/02 02:17:21 marka Exp "; #else -__RCSID("$NetBSD: inet_net_pton.c,v 1.1 2004/05/20 23:13:02 christos Exp $"); +__RCSID("$NetBSD: inet_net_pton.c,v 1.4 2012/03/20 17:08:13 matt Exp $"); #endif #endif @@ -34,6 +34,7 @@ __RCSID("$NetBSD: inet_net_pton.c,v 1.1 2004/05/20 23:13:02 christos Exp $"); #include #include +#include #include #include #include @@ -70,12 +71,15 @@ __weak_alias(inet_net_pton,_inet_net_pton) * Paul Vixie (ISC), June 1996 */ static int -inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { +inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) +{ static const char xdigits[] = "0123456789abcdef"; static const char digits[] = "0123456789"; - int n, ch, tmp = 0, dirty, bits; + int ch, dirty, bits; + ptrdiff_t n, tmp; const u_char *odst = dst; + tmp = 0; ch = *src++; if (ch == '0' && (src[0] == 'x' || src[0] == 'X') && isascii((u_char)(src[1])) @@ -144,13 +148,13 @@ inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { n = strchr(digits, ch) - digits; INSIST(n >= 0 && n <= 9); bits *= 10; - bits += n; + bits += (int)n; + if (bits > 32) + goto emsgsize; } while ((ch = *src++) != '\0' && isascii((u_char)ch) && isdigit((u_char)ch)); if (ch != '\0') goto enoent; - if (bits > 32) - goto emsgsize; } /* Firey death and destruction unless we prefetched EOS. */ @@ -174,7 +178,7 @@ inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { bits = 8; /* If imputed mask is narrower than specified octets, widen. */ if (bits >= 8 && bits < ((dst - odst) * 8)) - bits = (dst - odst) * 8; + bits = (int)(dst - odst) * 8; } /* Extend network to cover the actual mask. */ while (bits > ((dst - odst) * 8)) { @@ -194,7 +198,8 @@ inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { } static int -getbits(const char *src, int *bitsp) { +getbits(const char *src, int *bitsp) +{ static const char digits[] = "0123456789"; int n; int val; @@ -210,7 +215,7 @@ getbits(const char *src, int *bitsp) { if (n++ != 0 && val == 0) /* no leading zeros */ return (0); val *= 10; - val += (pch - digits); + val += (int)(pch - digits); if (val > 128) /* range */ return (0); continue; @@ -224,7 +229,8 @@ getbits(const char *src, int *bitsp) { } static int -getv4(const char *src, u_char *dst, int *bitsp) { +getv4(const char *src, u_char *dst, int *bitsp) +{ static const char digits[] = "0123456789"; u_char *odst = dst; int n; @@ -241,7 +247,7 @@ getv4(const char *src, u_char *dst, int *bitsp) { if (n++ != 0 && val == 0) /* no leading zeros */ return (0); val *= 10; - val += (pch - digits); + val += (int)(pch - digits); if (val > 255) /* range */ return (0); continue; @@ -267,7 +273,8 @@ getv4(const char *src, u_char *dst, int *bitsp) { } static int -inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { +inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) +{ static const char xdigits_l[] = "0123456789abcdef", xdigits_u[] = "0123456789ABCDEF"; u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; @@ -300,7 +307,7 @@ inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { pch = strchr((xdigits = xdigits_u), ch); if (pch != NULL) { val <<= 4; - val |= (pch - xdigits); + val |= (int)(pch - xdigits); if (++digits > 4) goto enoent; saw_xdigit = 1; @@ -356,7 +363,7 @@ inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; + const ptrdiff_t n = tp - colonp; int i; if (tp == endp) @@ -399,7 +406,8 @@ inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { * Paul Vixie (ISC), June 1996 */ int -inet_net_pton(int af, const char *src, void *dst, size_t size) { +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)); diff --git a/lib/libc/inet/inet_neta.c b/lib/libc/inet/inet_neta.c index d0b90bcd6..41692aa90 100644 --- a/lib/libc/inet/inet_neta.c +++ b/lib/libc/inet/inet_neta.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_neta.c,v 1.1 2004/05/20 23:13:02 christos Exp $ */ +/* $NetBSD: inet_neta.c,v 1.3 2012/06/25 22:32:44 abs Exp $ */ /* * Copyright (c) 1996 by Internet Software Consortium. @@ -22,7 +22,7 @@ #if 0 static const char rcsid[] = "Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp "; #else -__RCSID("$NetBSD: inet_neta.c,v 1.1 2004/05/20 23:13:02 christos Exp $"); +__RCSID("$NetBSD: inet_neta.c,v 1.3 2012/06/25 22:32:44 abs Exp $"); #endif #endif @@ -53,10 +53,7 @@ __weak_alias(inet_neta,_inet_neta) * Paul Vixie (ISC), July 1996 */ char * -inet_neta(src, dst, size) - u_long src; - char *dst; - size_t size; +inet_neta(u_long src, char *dst, size_t size) { char *odst = dst; char *ep; @@ -73,8 +70,8 @@ inet_neta(src, dst, size) ep = dst + size; if (ep <= dst) goto emsgsize; - while (src & 0xffffffff) { - u_char b = (u_char)((src & 0xff000000) >> 24); + while (src & 0xffffffffUL) { + u_char b = (u_char)((src & 0xff000000UL) >> 24); src <<= 8; if (b || src) { diff --git a/lib/libc/inet/inet_ntoa.c b/lib/libc/inet/inet_ntoa.c index df7670d0c..6ed023b41 100644 --- a/lib/libc/inet/inet_ntoa.c +++ b/lib/libc/inet/inet_ntoa.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_ntoa.c,v 1.1 2004/05/20 23:13:02 christos Exp $ */ +/* $NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: inet_ntoa.c,v 1.1 2004/05/20 23:13:02 christos Exp $"); +__RCSID("$NetBSD: inet_ntoa.c,v 1.2 2012/03/13 21:13:38 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -59,6 +59,6 @@ inet_ntoa(struct in_addr in) { static char ret[18]; strlcpy(ret, "[inet_ntoa error]", sizeof(ret)); - (void) inet_ntop(AF_INET, &in, ret, sizeof ret); - return (ret); + (void) inet_ntop(AF_INET, &in, ret, (socklen_t)sizeof ret); + return ret; } diff --git a/lib/libc/inet/inet_ntop.c b/lib/libc/inet/inet_ntop.c index ed3a95a22..00c55a8cc 100644 --- a/lib/libc/inet/inet_ntop.c +++ b/lib/libc/inet/inet_ntop.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_ntop.c,v 1.8 2009/04/12 17:07:17 christos Exp $ */ +/* $NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -22,7 +22,7 @@ #if 0 static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp"; #else -__RCSID("$NetBSD: inet_ntop.c,v 1.8 2009/04/12 17:07:17 christos Exp $"); +__RCSID("$NetBSD: inet_ntop.c,v 1.9 2012/03/20 17:08:13 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -66,11 +66,7 @@ static const char *inet_ntop6(const u_char *src, char *dst, socklen_t size); * Paul Vixie, 1996. */ const char * -inet_ntop(af, src, dst, size) - int af; - const void *src; - char *dst; - socklen_t size; +inet_ntop(int af, const void *src, char *dst, socklen_t size) { _DIAGASSERT(src != NULL); @@ -100,10 +96,7 @@ inet_ntop(af, src, dst, size) * Paul Vixie, 1996. */ static const char * -inet_ntop4(src, dst, size) - const u_char *src; - char *dst; - socklen_t size; +inet_ntop4(const u_char *src, char *dst, socklen_t size) { char tmp[sizeof "255.255.255.255"]; int l; @@ -128,10 +121,7 @@ inet_ntop4(src, dst, size) * Paul Vixie, 1996. */ static const char * -inet_ntop6(src, dst, size) - const u_char *src; - char *dst; - socklen_t size; +inet_ntop6(const u_char *src, char *dst, socklen_t size) { /* * Note that int32_t and int16_t need only be "at least" large enough diff --git a/lib/libc/inet/inet_pton.c b/lib/libc/inet/inet_pton.c index 17ae259bf..c1e9a698a 100644 --- a/lib/libc/inet/inet_pton.c +++ b/lib/libc/inet/inet_pton.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet_pton.c,v 1.7 2009/04/12 17:07:17 christos Exp $ */ +/* $NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -22,7 +22,7 @@ #if 0 static const char rcsid[] = "Id: inet_pton.c,v 1.5 2005/07/28 06:51:47 marka Exp"; #else -__RCSID("$NetBSD: inet_pton.c,v 1.7 2009/04/12 17:07:17 christos Exp $"); +__RCSID("$NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -35,6 +35,7 @@ __RCSID("$NetBSD: inet_pton.c,v 1.7 2009/04/12 17:07:17 christos Exp $"); #include #include #include +#include #include #include #include @@ -100,10 +101,10 @@ inet_pton4(const char *src, u_char *dst, int pton) { u_int32_t val; u_int digit, base; - int n; + ptrdiff_t n; unsigned char c; u_int parts[4]; - register u_int *pp = parts; + u_int *pp = parts; _DIAGASSERT(src != NULL); _DIAGASSERT(dst != NULL); @@ -248,7 +249,7 @@ inet_pton6(const char *src, u_char *dst) pch = strchr((xdigits = xdigits_u), ch); if (pch != NULL) { val <<= 4; - val |= (pch - xdigits); + val |= (int)(pch - xdigits); if (++seen_xdigits > 4) return (0); continue; @@ -289,7 +290,7 @@ inet_pton6(const char *src, u_char *dst) * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; + const ptrdiff_t n = tp - colonp; int i; if (tp == endp) diff --git a/lib/libc/isc/assertions.c b/lib/libc/isc/assertions.c index 970231dd4..5e8ee7b3f 100644 --- a/lib/libc/isc/assertions.c +++ b/lib/libc/isc/assertions.c @@ -1,4 +1,4 @@ -/* $NetBSD: assertions.c,v 1.6 2009/04/12 17:07:17 christos Exp $ */ +/* $NetBSD: assertions.c,v 1.7 2011/09/16 16:05:58 joerg Exp $ */ /* * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") @@ -22,7 +22,7 @@ #ifdef notdef static const char rcsid[] = "Id: assertions.c,v 1.5 2008/11/14 02:36:51 marka Exp"; #else -__RCSID("$NetBSD: assertions.c,v 1.6 2009/04/12 17:07:17 christos Exp $"); +__RCSID("$NetBSD: assertions.c,v 1.7 2011/09/16 16:05:58 joerg Exp $"); #endif #endif @@ -41,7 +41,7 @@ __RCSID("$NetBSD: assertions.c,v 1.6 2009/04/12 17:07:17 christos Exp $"); * Forward. */ -static void default_assertion_failed(const char *, int, assertion_type, +__dead static void default_assertion_failed(const char *, int, assertion_type, const char *, int); /* diff --git a/lib/libc/isc/ev_timers.c b/lib/libc/isc/ev_timers.c index 9a6e730db..40521a78d 100644 --- a/lib/libc/isc/ev_timers.c +++ b/lib/libc/isc/ev_timers.c @@ -1,4 +1,4 @@ -/* $NetBSD: ev_timers.c,v 1.8 2009/04/12 17:07:17 christos Exp $ */ +/* $NetBSD: ev_timers.c,v 1.11 2012/03/21 00:34:54 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -26,7 +26,7 @@ #ifdef notdef static const char rcsid[] = "Id: ev_timers.c,v 1.6 2005/04/27 04:56:36 sra Exp"; #else -__RCSID("$NetBSD: ev_timers.c,v 1.8 2009/04/12 17:07:17 christos Exp $"); +__RCSID("$NetBSD: ev_timers.c,v 1.11 2012/03/21 00:34:54 christos Exp $"); #endif #endif @@ -120,7 +120,8 @@ evCmpTime(struct timespec a, struct timespec b) { } struct timespec -evNowTime() { +evNowTime(void) +{ struct timeval now; #ifdef CLOCK_REALTIME struct timespec tsnow; @@ -136,7 +137,7 @@ evNowTime() { return (tsnow); #endif if (gettimeofday(&now, NULL) < 0) - return (evConsTime(0L, 0L)); + return (evConsTime((time_t)0, 0L)); return (evTimeSpec(now)); } @@ -149,7 +150,7 @@ evUTCTime(void) { return (tsnow); #endif if (gettimeofday(&now, NULL) < 0) - return (evConsTime(0L, 0L)); + return (evConsTime((time_t)0, 0L)); return (evTimeSpec(now)); } @@ -176,7 +177,7 @@ evTimeVal(struct timespec ts) { struct timeval tv; tv.tv_sec = ts.tv_sec; - tv.tv_usec = ts.tv_nsec / 1000; + tv.tv_usec = (suseconds_t)(ts.tv_nsec / 1000); return (tv); } diff --git a/lib/libc/locale/_wcstol.h b/lib/libc/locale/_wcstol.h index dd7a6a6c5..49c268c42 100644 --- a/lib/libc/locale/_wcstol.h +++ b/lib/libc/locale/_wcstol.h @@ -1,4 +1,4 @@ -/* $NetBSD: _wcstol.h,v 1.3 2005/11/29 03:11:59 christos Exp $ */ +/* $NetBSD: _wcstol.h,v 1.4 2012/06/25 22:32:44 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -45,10 +45,7 @@ */ __INT -_FUNCNAME(nptr, endptr, base) - const wchar_t *nptr; - wchar_t **endptr; - int base; +_FUNCNAME(const wchar_t *nptr, wchar_t **endptr, int base) { const wchar_t *s; __INT acc, cutoff; diff --git a/lib/libc/locale/_wcstoul.h b/lib/libc/locale/_wcstoul.h index a21a10b3d..33f0d1c9b 100644 --- a/lib/libc/locale/_wcstoul.h +++ b/lib/libc/locale/_wcstoul.h @@ -1,4 +1,4 @@ -/* $NetBSD: _wcstoul.h,v 1.3 2005/11/29 03:11:59 christos Exp $ */ +/* $NetBSD: _wcstoul.h,v 1.4 2012/06/25 22:32:44 abs Exp $ */ /* * Copyright (c) 1990, 1993 @@ -44,10 +44,7 @@ */ __UINT -_FUNCNAME(nptr, endptr, base) - const wchar_t *nptr; - wchar_t **endptr; - int base; +_FUNCNAME(const wchar_t *nptr, wchar_t **endptr, int base) { const wchar_t *s; __UINT acc, cutoff; diff --git a/lib/libc/locale/aliasname.c b/lib/libc/locale/aliasname.c deleted file mode 100644 index 8d3fc1136..000000000 --- a/lib/libc/locale/aliasname.c +++ /dev/null @@ -1,129 +0,0 @@ -/* $NetBSD: aliasname.c,v 1.4 2009/01/11 02:46:28 christos Exp $ */ - -/*- - * Copyright (c)2002 YAMAMOTO Takashi, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: aliasname.c,v 1.4 2009/01/11 02:46:28 christos Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include -#include -#include - -#include "aliasname_local.h" - -__inline int __is_ws(char); - -__inline int __is_ws(char ch) -{ - - return (ch == ' ' || ch == '\t'); -} - -const char * -__unaliasname(const char *dbname, const char *alias, void *buf, size_t bufsize) -{ - FILE *fp = NULL; - const char *result = NULL; - size_t resultlen; - size_t aliaslen; - const char *p; - size_t len; - - _DIAGASSERT(dbname != NULL); - _DIAGASSERT(alias != NULL); - _DIAGASSERT(buf != NULL); - - fp = fopen(dbname, "r"); - if (fp == NULL) - goto quit; - - aliaslen = strlen(alias); - - while (/*CONSTCOND*/ 1) { - p = fgetln(fp, &len); - if (p == NULL) - goto quit; /* eof or error */ - - _DIAGASSERT(len != 0); - - /* ignore terminating NL */ - if (p[len - 1] == '\n') - len--; - - /* ignore null line and comment */ - if (len == 0 || p[0] == '#') - continue; - - if (aliaslen > len) - continue; - - if (memcmp(alias, p, aliaslen)) - continue; - - p += aliaslen; - len -= aliaslen; - - if (len == 0 || !__is_ws(*p)) - continue; - - /* entry was found here */ - break; - - /* NOTREACHED */ - } - - /* skip white spaces */ - do { - p++; - len--; - } while (len != 0 && __is_ws(*p)); - - if (len == 0) - goto quit; - - /* count length of result */ - resultlen = 0; - while (resultlen < len && !__is_ws(*p)) - resultlen++; - - /* check if space is enough */ - if (bufsize < resultlen + 1) - goto quit; - - memcpy(buf, p, resultlen); - ((char *)buf)[resultlen] = 0; - result = buf; - -quit: - if (fp) - fclose(fp); - - return result; -} diff --git a/lib/libc/locale/bsdctype.c b/lib/libc/locale/bsdctype.c deleted file mode 100644 index 5e499370a..000000000 --- a/lib/libc/locale/bsdctype.c +++ /dev/null @@ -1,178 +0,0 @@ -/* $NetBSD: bsdctype.c,v 1.9 2010/06/20 02:23:15 tnozaki Exp $ */ - -/*- - * Copyright (c)2008 Citrus Project, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: bsdctype.c,v 1.9 2010/06/20 02:23:15 tnozaki Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "bsdctype_local.h" -#include "runetype_misc.h" - -const _BSDCTypeLocale _DefaultBSDCTypeLocale = { - _C_ctype_, - _C_tolower_, - _C_toupper_ -}; - -const _BSDCTypeLocale *_CurrentBSDCTypeLocale = &_DefaultBSDCTypeLocale; - -typedef struct { - _BSDCTypeLocale bl; - unsigned char blp_ctype_tab [_CTYPE_NUM_CHARS + 1]; - short blp_tolower_tab[_CTYPE_NUM_CHARS + 1]; - short blp_toupper_tab[_CTYPE_NUM_CHARS + 1]; -} _BSDCTypeLocalePriv; - -static __inline void -_bsdctype_init_priv(_BSDCTypeLocalePriv *blp) -{ -#if _CTYPE_CACHE_SIZE != _CTYPE_NUM_CHARS - int i; - - for (i = _CTYPE_CACHE_SIZE; i < _CTYPE_NUM_CHARS; ++i) { - blp->blp_ctype_tab [i + 1] = 0; - blp->blp_tolower_tab[i + 1] = i; - blp->blp_toupper_tab[i + 1] = i; - } -#endif - blp->blp_ctype_tab [0] = 0; - blp->blp_tolower_tab[0] = EOF; - blp->blp_toupper_tab[0] = EOF; - blp->bl.bl_ctype_tab = &blp->blp_ctype_tab [0]; - blp->bl.bl_tolower_tab = &blp->blp_tolower_tab[0]; - blp->bl.bl_toupper_tab = &blp->blp_toupper_tab[0]; -} - -static __inline int -_bsdctype_read_file(const char * __restrict var, size_t lenvar, - _BSDCTypeLocalePriv * __restrict blp) -{ - const _FileBSDCTypeLocale *fbl; - uint32_t value; - int i; - - _DIAGASSERT(blp != NULL); - - if (lenvar < sizeof(*fbl)) - return EFTYPE; - fbl = (const _FileBSDCTypeLocale *)(const void *)var; - if (memcmp(&fbl->fbl_id[0], _CTYPE_ID, sizeof(fbl->fbl_id))) - return EFTYPE; - value = be32toh(fbl->fbl_rev); - if (value != _CTYPE_REV) - return EFTYPE; - value = be32toh(fbl->fbl_num_chars); - if (value != _CTYPE_CACHE_SIZE) - return EFTYPE; - for (i = 0; i < _CTYPE_CACHE_SIZE; ++i) { - blp->blp_ctype_tab [i + 1] = fbl->fbl_ctype_tab[i]; - blp->blp_tolower_tab[i + 1] = be16toh(fbl->fbl_tolower_tab[i]); - blp->blp_toupper_tab[i + 1] = be16toh(fbl->fbl_toupper_tab[i]); - } - return 0; -} - -static __inline int -_bsdctype_read_runetype(const char * __restrict var, size_t lenvar, - _BSDCTypeLocalePriv * __restrict blp) -{ - const _FileRuneLocale *frl; - int i; - - _DIAGASSERT(blp != NULL); - - if (lenvar < sizeof(*frl)) - return EFTYPE; - lenvar -= sizeof(*frl); - frl = (const _FileRuneLocale *)(const void *)var; - if (memcmp(_RUNECT10_MAGIC, &frl->frl_magic[0], sizeof(frl->frl_magic))) - return EFTYPE; - if (frl->frl_encoding[0] != 'N' || frl->frl_encoding[1] != 'O' || - frl->frl_encoding[2] != 'N' || frl->frl_encoding[3] != 'E' || - frl->frl_encoding[4] != '\0') /* XXX */ - return EFTYPE; - if (be32toh(frl->frl_runetype_ext.frr_nranges) != 0 || - be32toh(frl->frl_maplower_ext.frr_nranges) != 0 || - be32toh(frl->frl_mapupper_ext.frr_nranges) != 0) - return EFTYPE; - if (lenvar < be32toh((uint32_t)frl->frl_variable_len)) - return EFTYPE; - for (i = 0; i < _CTYPE_CACHE_SIZE; ++i) { - blp->blp_ctype_tab [i + 1] = (unsigned char) - _runetype_to_ctype((_RuneType) - be32toh(frl->frl_runetype[i])); - blp->blp_tolower_tab[i + 1] = (short) - be32toh((uint32_t)frl->frl_maplower[i]); - blp->blp_toupper_tab[i + 1] = (short) - be32toh((uint32_t)frl->frl_mapupper[i]); - } - return 0; -} - -int -_bsdctype_load(const char * __restrict var, size_t lenvar, - _BSDCTypeLocale ** __restrict pbl) -{ - int ret; - _BSDCTypeLocalePriv *blp; - - _DIAGASSERT(var != NULL || lenvar < 1); - _DIAGASSERT(pbl != NULL); - - if (lenvar < 1) - return EFTYPE; - blp = malloc(sizeof(*blp)); - if (blp == NULL) - return errno; - _bsdctype_init_priv(blp); - switch (*var) { - case 'B': - _bsdctype_read_file(var, lenvar, blp); - break; - case 'R': - _bsdctype_read_runetype(var, lenvar, blp); - break; - default: - ret = EFTYPE; - } - if (ret) - free(blp); - else - *pbl = &blp->bl; - return ret; -} diff --git a/lib/libc/locale/bsdctype_local.h b/lib/libc/locale/bsdctype_local.h deleted file mode 100644 index 112c0688f..000000000 --- a/lib/libc/locale/bsdctype_local.h +++ /dev/null @@ -1,48 +0,0 @@ -/* $NetBSD: bsdctype_local.h,v 1.2 2010/06/19 13:26:52 tnozaki Exp $ */ - -/*- - * Copyright (c)2008 Citrus Project, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef _BSDCTYPE_LOCAL_H_ -#define _BSDCTYPE_LOCAL_H_ - -#include "bsdctype_file.h" - -typedef struct { - const unsigned char *bl_ctype_tab; - const short *bl_tolower_tab; - const short *bl_toupper_tab; -} _BSDCTypeLocale; - -extern const _BSDCTypeLocale _DefaultBSDCTypeLocale; -extern const _BSDCTypeLocale *_CurrentBSDCTypeLocale; - -__BEGIN_DECLS -int _bsdctype_load(const char * __restrict, size_t, - _BSDCTypeLocale ** __restrict); -__END_DECLS - -#endif /*_BSDCTYPE_LOCAL_H_*/ diff --git a/lib/libc/locale/current_locale.c b/lib/libc/locale/current_locale.c index f8bf1f663..ef6847f31 100644 --- a/lib/libc/locale/current_locale.c +++ b/lib/libc/locale/current_locale.c @@ -1,4 +1,4 @@ -/* $NetBSD: current_locale.c,v 1.2 2009/01/11 02:46:28 christos Exp $ */ +/* $NetBSD: current_locale.c,v 1.3 2012/03/20 17:44:18 matt Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: current_locale.c,v 1.2 2009/01/11 02:46:28 christos Exp $"); +__RCSID("$NetBSD: current_locale.c,v 1.3 2012/03/20 17:44:18 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -43,7 +43,7 @@ __RCSID("$NetBSD: current_locale.c,v 1.2 2009/01/11 02:46:28 christos Exp $"); static struct _locale_impl_t *__current_locale = &_global_locale; struct _locale_impl_t ** -_current_locale() +_current_locale(void) { return &__current_locale; } diff --git a/lib/libc/locale/dummy_lc_collate.c b/lib/libc/locale/dummy_lc_collate.c index 366160e6a..10c952c5f 100644 --- a/lib/libc/locale/dummy_lc_collate.c +++ b/lib/libc/locale/dummy_lc_collate.c @@ -1,4 +1,4 @@ -/* $NetBSD: dummy_lc_collate.c,v 1.2 2009/01/11 02:46:28 christos Exp $ */ +/* $NetBSD: dummy_lc_collate.c,v 1.3 2012/03/04 21:14:56 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: dummy_lc_collate.c,v 1.2 2009/01/11 02:46:28 christos Exp $"); +__RCSID("$NetBSD: dummy_lc_collate.c,v 1.3 2012/03/04 21:14:56 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -51,4 +51,3 @@ __RCSID("$NetBSD: dummy_lc_collate.c,v 1.2 2009/01/11 02:46:28 christos Exp $"); #define _CATEGORY_NAME "LC_COLLATE" #include "dummy_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_dummy_LC_COLLATE_); diff --git a/lib/libc/locale/dummy_lc_template.h b/lib/libc/locale/dummy_lc_template.h index 154bf1fa2..994897ced 100644 --- a/lib/libc/locale/dummy_lc_template.h +++ b/lib/libc/locale/dummy_lc_template.h @@ -1,4 +1,4 @@ -/* $NetBSD: dummy_lc_template.h,v 1.2 2009/01/11 02:46:28 christos Exp $ */ +/* $NetBSD: dummy_lc_template.h,v 1.3 2012/03/04 21:14:56 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -31,7 +31,7 @@ #include "generic_lc_template_decl.h" -static const char * +const char * _PREFIX(setlocale)(const char * __restrict name, struct _locale_impl_t * __restrict locale) { @@ -51,6 +51,4 @@ _PREFIX(setlocale)(const char * __restrict name, return locale->part_name[(size_t)_CATEGORY_ID]; } -#include "generic_lc_template.h" - #endif /*_DUMMY_LC_TEMPLATE_H_*/ diff --git a/lib/libc/locale/fix_grouping.c b/lib/libc/locale/fix_grouping.c index 5796491c5..8fe5911b0 100644 --- a/lib/libc/locale/fix_grouping.c +++ b/lib/libc/locale/fix_grouping.c @@ -1,4 +1,4 @@ -/* $NetBSD: fix_grouping.c,v 1.5 2010/06/01 13:52:08 tnozaki Exp $ */ +/* $NetBSD: fix_grouping.c,v 1.6 2012/03/21 14:11:24 christos Exp $ */ /* * Copyright (c) 2001 Alexey Zelkin @@ -35,7 +35,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: fix_grouping.c,v 1.5 2010/06/01 13:52:08 tnozaki Exp $"); +__RCSID("$NetBSD: fix_grouping.c,v 1.6 2012/03/21 14:11:24 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -44,7 +44,7 @@ __RCSID("$NetBSD: fix_grouping.c,v 1.5 2010/06/01 13:52:08 tnozaki Exp $"); #include "fix_grouping.h" #ifndef NBCHAR_MAX -#define NBCHAR_MAX CHAR_MAX +#define NBCHAR_MAX (char)CHAR_MAX #endif #ifndef __UNCONST diff --git a/lib/libc/locale/generic_lc_all.c b/lib/libc/locale/generic_lc_all.c index 3cf2597b0..6819471c4 100644 --- a/lib/libc/locale/generic_lc_all.c +++ b/lib/libc/locale/generic_lc_all.c @@ -1,4 +1,4 @@ -/* $NetBSD: generic_lc_all.c,v 1.3 2009/10/04 21:05:18 tnozaki Exp $ */ +/* $NetBSD: generic_lc_all.c,v 1.4 2012/03/04 21:14:56 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: generic_lc_all.c,v 1.3 2009/10/04 21:05:18 tnozaki Exp $"); +__RCSID("$NetBSD: generic_lc_all.c,v 1.4 2012/03/04 21:14:56 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -53,13 +53,13 @@ const char * _generic_LC_ALL_setlocale(const char * __restrict name, struct _locale_impl_t * __restrict locale) { - _locale_category_t *l; + _locale_set_t sl; char head[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)], *tail; const char *tokens[_LC_LAST], *s, *t; int load_locale_success, i, j; - l = _find_category(1); - _DIAGASSERT(l != NULL); + sl = _find_category(1); + _DIAGASSERT(sl != NULL); load_locale_success = 0; if (name != NULL) { strlcpy(&head[0], name, sizeof(head)); @@ -82,20 +82,20 @@ _generic_LC_ALL_setlocale(const char * __restrict name, if (tail != NULL) return NULL; } - if ((*l->setlocale)(tokens[1], locale) != NULL) + if ((*sl)(tokens[1], locale) != NULL) load_locale_success = 1; } - s = (*l->setlocale)(NULL, locale); + s = (*sl)(NULL, locale); _DIAGASSERT(s != NULL); strlcpy(&locale->query[0], s, sizeof(locale->query)); for (i = 2, j = 0; i < _LC_LAST; ++i) { - l = _find_category(i); - _DIAGASSERT(l != NULL); + sl = _find_category(i); + _DIAGASSERT(sl != NULL); if (name != NULL) { - if ((*l->setlocale)(tokens[i], locale) != NULL) + if ((*sl)(tokens[i], locale) != NULL) load_locale_success = 1; } - t = (*l->setlocale)(NULL, locale); + t = (*sl)(NULL, locale); _DIAGASSERT(t != NULL); if (j == 0) { if (!strcmp(s, t)) @@ -115,10 +115,3 @@ _generic_LC_ALL_setlocale(const char * __restrict name, return (const char *)&locale->query[0]; } -/* - * macro requrired by generic_lc_template.h - */ -#define _CATEGORY_ID LC_ALL - -#include "generic_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_generic_LC_ALL_); diff --git a/lib/libc/locale/generic_lc_template.h b/lib/libc/locale/generic_lc_template.h deleted file mode 100644 index 4278ed918..000000000 --- a/lib/libc/locale/generic_lc_template.h +++ /dev/null @@ -1,38 +0,0 @@ -/* $NetBSD: generic_lc_template.h,v 1.3 2009/03/09 02:22:25 tnozaki Exp $ */ - -/*- - * Copyright (c)2008 Citrus Project, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef _GENERIC_LC_TEMPLATE_H_ -#define _GENERIC_LC_TEMPLATE_H_ - -#define _LOCALE_CATEGORY_ENTRY(name) \ -const _locale_category_t name##desc = { \ - .category = _CATEGORY_ID, \ - .setlocale = &name##setlocale, \ -} - -#endif /*_GENERIC_LC_TEMPLATE_H_*/ diff --git a/lib/libc/locale/generic_lc_template_decl.h b/lib/libc/locale/generic_lc_template_decl.h index 2aed54c6d..2da00854e 100644 --- a/lib/libc/locale/generic_lc_template_decl.h +++ b/lib/libc/locale/generic_lc_template_decl.h @@ -1,4 +1,4 @@ -/* $NetBSD: generic_lc_template_decl.h,v 1.2 2009/01/11 02:46:28 christos Exp $ */ +/* $NetBSD: generic_lc_template_decl.h,v 1.3 2012/03/04 21:14:56 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -29,7 +29,7 @@ #ifndef _GENERIC_LC_TEMPLATE_DECL_H_ #define _GENERIC_LC_TEMPLATE_DECL_H_ -static const char * _PREFIX(setlocale)(const char * __restrict, +const char * _PREFIX(setlocale)(const char * __restrict, struct _locale_impl_t * __restrict); #endif /*_GENERIC_LC_TEMPLATE_DECL_H_*/ diff --git a/lib/libc/locale/global_locale.c b/lib/libc/locale/global_locale.c index 34370bf4c..5e2c6b3af 100644 --- a/lib/libc/locale/global_locale.c +++ b/lib/libc/locale/global_locale.c @@ -1,4 +1,4 @@ -/* $NetBSD: global_locale.c,v 1.11 2010/06/19 13:26:52 tnozaki Exp $ */ +/* $NetBSD: global_locale.c,v 1.13 2012/03/21 14:11:24 christos Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: global_locale.c,v 1.11 2010/06/19 13:26:52 tnozaki Exp $"); +__RCSID("$NetBSD: global_locale.c,v 1.13 2012/03/21 14:11:24 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -39,14 +39,14 @@ __RCSID("$NetBSD: global_locale.c,v 1.11 2010/06/19 13:26:52 tnozaki Exp $"); #define __SETLOCALE_SOURCE__ #include #include -#ifdef WITH_RUNE -#include "runetype_local.h" -#else -#include "bsdctype_local.h" -#endif +#include "runetype_local.h" #include "setlocale_local.h" +#ifndef NBCHAR_MAX +#define NBCHAR_MAX (char)CHAR_MAX +#endif + static struct lconv _global_ldata = { .decimal_point = __UNCONST("."), .thousands_sep = __UNCONST(""), @@ -58,20 +58,20 @@ static struct lconv _global_ldata = { .mon_grouping = __UNCONST(""), .positive_sign = __UNCONST(""), .negative_sign = __UNCONST(""), - .int_frac_digits = CHAR_MAX, - .frac_digits = CHAR_MAX, - .p_cs_precedes = CHAR_MAX, - .p_sep_by_space = CHAR_MAX, - .n_cs_precedes = CHAR_MAX, - .n_sep_by_space = CHAR_MAX, - .p_sign_posn = CHAR_MAX, - .n_sign_posn = CHAR_MAX, - .int_p_cs_precedes = CHAR_MAX, - .int_n_cs_precedes = CHAR_MAX, - .int_p_sep_by_space = CHAR_MAX, - .int_n_sep_by_space = CHAR_MAX, - .int_p_sign_posn = CHAR_MAX, - .int_n_sign_posn = CHAR_MAX, + .int_frac_digits = NBCHAR_MAX, + .frac_digits = NBCHAR_MAX, + .p_cs_precedes = NBCHAR_MAX, + .p_sep_by_space = NBCHAR_MAX, + .n_cs_precedes = NBCHAR_MAX, + .n_sep_by_space = NBCHAR_MAX, + .p_sign_posn = NBCHAR_MAX, + .n_sign_posn = NBCHAR_MAX, + .int_p_cs_precedes = NBCHAR_MAX, + .int_n_cs_precedes = NBCHAR_MAX, + .int_p_sep_by_space = NBCHAR_MAX, + .int_n_sep_by_space = NBCHAR_MAX, + .int_p_sign_posn = NBCHAR_MAX, + .int_n_sign_posn = NBCHAR_MAX, }; static const char *_global_items[(size_t)ALT_DIGITS + 1] = { @@ -159,11 +159,7 @@ struct _locale_impl_t _global_locale = { [(size_t)LC_ALL ] = (_locale_part_t)NULL, [(size_t)LC_COLLATE ] = (_locale_part_t)NULL, [(size_t)LC_CTYPE ] = (_locale_part_t) -#ifdef WITH_RUNE __UNCONST(&_DefaultRuneLocale), -#else - __UNCONST(&_DefaultBSDCTypeLocale), -#endif [(size_t)LC_MONETARY] = (_locale_part_t) __UNCONST(&_DefaultMonetaryLocale), [(size_t)LC_NUMERIC ] = (_locale_part_t) diff --git a/lib/libc/locale/iswctype_sb.c b/lib/libc/locale/iswctype_sb.c deleted file mode 100644 index 00863ca85..000000000 --- a/lib/libc/locale/iswctype_sb.c +++ /dev/null @@ -1,199 +0,0 @@ -/* $NetBSD: iswctype_sb.c,v 1.11 2010/06/01 18:00:28 tnozaki Exp $ */ - -/*- - * Copyright (c)2008 Citrus Project, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: iswctype_sb.c,v 1.11 2010/06/01 18:00:28 tnozaki Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" -#include -#define _CTYPE_NOINLINE -#include -#include -#include -#include -#include -#include - -#define _ISWCTYPE_FUNC(name) \ -int \ -isw##name(wint_t wc) \ -{ \ - int c; \ - \ - c = (wc == WEOF) ? EOF : (unsigned char)wc; \ - return is##name(c); \ -} -_ISWCTYPE_FUNC(alnum) -_ISWCTYPE_FUNC(alpha) -_ISWCTYPE_FUNC(blank) -_ISWCTYPE_FUNC(cntrl) -_ISWCTYPE_FUNC(digit) -_ISWCTYPE_FUNC(graph) -_ISWCTYPE_FUNC(lower) -_ISWCTYPE_FUNC(print) -_ISWCTYPE_FUNC(punct) -_ISWCTYPE_FUNC(space) -_ISWCTYPE_FUNC(upper) -_ISWCTYPE_FUNC(xdigit) - -#define _TOWCTRANS_FUNC(name) \ -wint_t \ -tow##name(wint_t wc) \ -{ \ - int c; \ - c = (wc == WEOF) ? EOF : (unsigned char)wc; \ - return to##name(c); \ -} -_TOWCTRANS_FUNC(upper) -_TOWCTRANS_FUNC(lower) - -struct _wctype_priv_t { - const char *name; - int (*iswctype)(wint_t); -}; - -static const struct _wctype_priv_t _wctype_decl[] = { - { "alnum", &iswalnum }, - { "alpha", &iswalpha }, - { "blank", &iswblank }, - { "cntrl", &iswcntrl }, - { "digit", &iswdigit }, - { "graph", &iswgraph }, - { "lower", &iswlower }, - { "print", &iswprint }, - { "punct", &iswpunct }, - { "space", &iswspace }, - { "upper", &iswupper }, - { "xdigit", &iswxdigit }, -}; -static const size_t _wctype_decl_size = - sizeof(_wctype_decl) / sizeof(struct _wctype_priv_t); - -wctype_t -wctype(const char *charclass) -{ - size_t i; - - for (i = 0; i < _wctype_decl_size; ++i) { - if (!strcmp(charclass, _wctype_decl[i].name)) - return (wctype_t)__UNCONST(&_wctype_decl[i]); - } - return (wctype_t)NULL; -} - -struct _wctrans_priv_t { - const char *name; - wint_t (*towctrans)(wint_t); -}; - -static const struct _wctrans_priv_t _wctrans_decl[] = { - { "upper", &towupper }, - { "lower", &towlower }, -}; -static const size_t _wctrans_decl_size = - sizeof(_wctrans_decl) / sizeof(struct _wctrans_priv_t); - -wctrans_t -/*ARGSUSED*/ -wctrans(const char *charmap) -{ - size_t i; - - for (i = 0; i < _wctrans_decl_size; ++i) { - if (!strcmp(charmap, _wctrans_decl[i].name)) - return (wctrans_t)__UNCONST(&_wctrans_decl[i]); - } - return (wctrans_t)NULL; -} - -int -/*ARGSUSED*/ -iswctype(wint_t wc, wctype_t charclass) -{ - const struct _wctype_priv_t *p; - - p = (const struct _wctype_priv_t *)(void *)charclass; - if (p < &_wctype_decl[0] || p > &_wctype_decl[_wctype_decl_size - 1]) { - errno = EINVAL; - return 0; - } - return (*p->iswctype)(wc); -} - -wint_t -/*ARGSUSED*/ -towctrans(wint_t wc, wctrans_t charmap) -{ - const struct _wctrans_priv_t *p; - - p = (const struct _wctrans_priv_t *)(void *)charmap; - if (p < &_wctrans_decl[0] || p > &_wctrans_decl[_wctrans_decl_size - 1]) { - errno = EINVAL; - return wc; - } - return (*p->towctrans)(wc); -} - -__weak_alias(wcwidth,_wcwidth) - -int -wcwidth(wchar_t wc) -{ - int c; - - switch (wc) { - case L'\0': - return 0; - case WEOF: - c = EOF; - break; - default: - c = (unsigned char)wc; - } - if (isprint(c)) - return 1; - return -1; -} - -int -wcswidth(const wchar_t * __restrict ws, size_t wn) -{ - const wchar_t *pws; - int c; - - pws = ws; - while (wn > 0 && *ws != L'\0') { - c = (*ws == WEOF) ? EOF : (unsigned char)*ws; - if (!isprint(c)) - return -1; - ++ws, --wn; - } - return (int)(ws - pws); -} diff --git a/lib/libc/locale/localeconv.c b/lib/libc/locale/localeconv.c index 5b6f6dba8..cbc722665 100644 --- a/lib/libc/locale/localeconv.c +++ b/lib/libc/locale/localeconv.c @@ -1,4 +1,4 @@ -/* $NetBSD: localeconv.c,v 1.18 2010/05/22 13:15:59 tnozaki Exp $ */ +/* $NetBSD: localeconv.c,v 1.19 2012/06/24 15:26:03 christos Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: localeconv.c,v 1.18 2010/05/22 13:15:59 tnozaki Exp $"); +__RCSID("$NetBSD: localeconv.c,v 1.19 2012/06/24 15:26:03 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -39,7 +39,7 @@ __RCSID("$NetBSD: localeconv.c,v 1.18 2010/05/22 13:15:59 tnozaki Exp $"); #include "setlocale_local.h" struct lconv * -localeconv() +localeconv(void) { return _current_cache()->ldata; } diff --git a/lib/libc/locale/localeio.c b/lib/libc/locale/localeio.c deleted file mode 100644 index ffd90150f..000000000 --- a/lib/libc/locale/localeio.c +++ /dev/null @@ -1,177 +0,0 @@ -/* $NetBSD: localeio.c,v 1.5 2010/06/19 13:26:52 tnozaki Exp $ */ -/* - * Copyright (c) 2008, The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Brian Ginsbach. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: localeio.c,v 1.5 2010/06/19 13:26:52 tnozaki Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "namespace.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "localeio.h" - -int -_localeio_map_file(const char * __restrict path, - void ** __restrict pvar, size_t * __restrict plenvar) -{ - int fd, ret; - struct stat st; - void *var; - size_t lenvar; - - _DIAGASSERT(path != NULL); - _DIAGASSERT(pvar != NULL); - _DIAGASSERT(plenvar != NULL); - - fd = open(path, O_RDONLY); - if (fd == -1) - return errno; - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1 || fstat(fd, &st) == 1) { - ret = errno; - goto error; - } - if (!S_ISREG(st.st_mode)) { - ret = EBADF; - goto error; - } - lenvar = (size_t)st.st_size; - if (lenvar < 1) { - ret = EFTYPE; - goto error; - } - var = mmap(NULL, lenvar, PROT_READ, - MAP_FILE|MAP_PRIVATE, fd, (off_t)0); - if (var == MAP_FAILED) { - ret = errno; - goto error; - } - *pvar = var; - *plenvar = lenvar; - return 0; -error: - return ret; -} - -void -_localeio_unmap_file(void *var, size_t lenvar) -{ - munmap(var, lenvar); -} - -int -__loadlocale(const char *name, size_t nstr, size_t nbytes, - size_t localesize, void *currentlocale) -{ - int fd, ret; - unsigned char **ap, *buf, *bp, *cp, *cbp, *ebp; - unsigned char ***locale; - struct stat st; - size_t i, bufsize; - - _DIAGASSERT(name != NULL); - _DIAGASSERT(localesize != 0); - _DIAGASSERT(currentlocale != NULL); - - if ((fd = open(name, O_RDONLY)) == -1) - return ENOENT; - - if ((fstat(fd, &st) == -1) || !S_ISREG(st.st_mode) || - (st.st_size <= 0)) { - ret = EFTYPE; - goto error1; - } - - bufsize = localesize + (size_t)st.st_size; - if ((buf = malloc(bufsize)) == NULL) { - ret = ENOMEM; - goto error1; - } - - bp = buf + localesize; - if (read(fd, bp, (size_t)st.st_size) != st.st_size) { - ret = EFTYPE; - goto error2; - } - - ap = (unsigned char **)(void *)buf; - for (i = (size_t)0, ebp = buf + bufsize; i < nstr; i++) { - ap[i] = bp; - while (bp != ebp && *bp != '\n') - bp++; - if (bp == ebp) { - ret = EFTYPE; - goto error2; - } - *bp++ = '\0'; - } - - cp = buf + (sizeof(unsigned char *) * nstr); - for (i = 0, cbp = bp; i < nbytes; i++) { - int n; - - while (bp != ebp && *bp != '\n') - bp++; - if (bp == ebp) { - ret = EFTYPE; - goto error2; - } - /* ignore overflow/underflow and bad characters */ - n = (unsigned char)strtol((char *)cbp, NULL, 0); - cp[i] = (unsigned char)(n & CHAR_MAX); - cbp = bp; - } - - locale = currentlocale; - - *locale = (unsigned char **)(void *)buf; - (void)close(fd); - return 0; - -error2: - free(buf); - -error1: - (void)close(fd); - return ret; -} diff --git a/lib/libc/locale/localeio_lc_ctype.c b/lib/libc/locale/localeio_lc_ctype.c deleted file mode 100644 index 0916f10c5..000000000 --- a/lib/libc/locale/localeio_lc_ctype.c +++ /dev/null @@ -1,122 +0,0 @@ -/* $NetBSD: localeio_lc_ctype.c,v 1.6 2010/06/19 13:26:52 tnozaki Exp $ */ - -/*- - * Copyright (c)2008 Citrus Project, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: localeio_lc_ctype.c,v 1.6 2010/06/19 13:26:52 tnozaki Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "reentrant.h" -#include -#include -#include -#include -#include -#include -#include -#define __SETLOCALE_SOURCE__ -#include -#include -#include -#include - -#include "bsdctype_local.h" -#include "aliasname_local.h" -#include "localeio.h" - -#include "setlocale_local.h" - -/* - * macro required by all template headers - */ -#define _PREFIX(name) __CONCAT(_localeio_LC_CTYPE_, name) - -/* - * macro required by nb_lc_template(_decl).h - */ -#define _CATEGORY_TYPE _BSDCTypeLocale - -#include "nb_lc_template_decl.h" - -static int -/*ARGSUSED*/ -_localeio_LC_CTYPE_create_impl(const char * __restrict root, - const char * __restrict name, _BSDCTypeLocale ** __restrict pdata) -{ - char path[PATH_MAX + 1]; - void *var; - size_t lenvar; - int ret; - - _DIAGASSERT(root != NULL); - _DIAGASSERT(name != NULL); - _DIAGASSERT(pdata != NULL); - - snprintf(path, sizeof(path), - "%s/%s/LC_CTYPE", root, name); - ret = _localeio_map_file(path, &var, &lenvar); - if (!ret) { - ret = _bsdctype_load((const char *)var, lenvar, pdata); - _localeio_unmap_file(var, lenvar); - } - return ret; -} - -static __inline void -_PREFIX(build_cache)(struct _locale_cache_t * __restrict cache, - _BSDCTypeLocale * __restrict data) -{ - _DIAGASSERT(cache != NULL); - _DIAGASSERT(data != NULL); - - cache->ctype_tab = data->bl_ctype_tab; - cache->tolower_tab = data->bl_tolower_tab; - cache->toupper_tab = data->bl_toupper_tab; - cache->mb_cur_max = (size_t)1; -} - -static __inline void -_PREFIX(fixup)(_BSDCTypeLocale *data) -{ - _DIAGASSERT(data != NULL); - - _ctype_ = data->bl_ctype_tab; - _tolower_tab_ = data->bl_tolower_tab; - _toupper_tab_ = data->bl_toupper_tab; -} - -/* - * macro required by nb_lc_template.h - */ -#define _CATEGORY_ID LC_CTYPE -#define _CATEGORY_NAME "LC_CTYPE" -#define _CATEGORY_DEFAULT _DefaultBSDCTypeLocale - -#include "nb_lc_template.h" -#include "generic_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_localeio_LC_CTYPE_); diff --git a/lib/libc/locale/localeio_lc_monetary.c b/lib/libc/locale/localeio_lc_monetary.c deleted file mode 100644 index ec5918f67..000000000 --- a/lib/libc/locale/localeio_lc_monetary.c +++ /dev/null @@ -1,95 +0,0 @@ -/* $NetBSD: localeio_lc_monetary.c,v 1.2 2009/01/11 02:46:28 christos Exp $ */ - -/* - * Copyright (c) 2008, The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Brian Ginsbach. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: localeio_lc_monetary.c,v 1.2 2009/01/11 02:46:28 christos Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include "reentrant.h" -#include -#include -#include -#include -#include -#include -#include -#define __SETLOCALE_SOURCE__ -#include -#include -#include -#include -#include - -#include "setlocale_local.h" - -#include "aliasname_local.h" -#include "fix_grouping.h" -#include "localeio.h" - -/* - * macro required by all template headers - */ -#define _PREFIX(name) __CONCAT(_localeio_LC_MONETARY_, name) - -#include "nb_lc_monetary_misc.h" -#include "nb_lc_template_decl.h" - -#define NSTRINGS \ - (offsetof(_MonetaryLocale, int_frac_digits)/sizeof(const char **)) -#define NCHARS \ - (offsetof(_MonetaryLocale, int_n_sign_posn) - \ - offsetof(_MonetaryLocale, int_frac_digits) + 1) - -static int -_localeio_LC_MONETARY_create_impl(const char * __restrict root, - const char * __restrict name, _MonetaryLocale ** __restrict pdata) -{ - char path[PATH_MAX + 1]; - int ret; - - _DIAGASSERT(root != NULL); - _DIAGASSERT(name != NULL); - _DIAGASSERT(pdata != NULL); - - snprintf(path, sizeof(path), - "%s/%s/LC_MONETARY", root, name); - ret = __loadlocale(path, NSTRINGS, NCHARS, sizeof(_MonetaryLocale), - (void *)pdata); - if (!ret) { - (*pdata)->mon_grouping = - __fix_locale_grouping_str((*pdata)->mon_grouping); - } - return ret; -} - -#include "nb_lc_template.h" -_LOCALE_CATEGORY_ENTRY(_localeio_LC_MONETARY_); diff --git a/lib/libc/locale/mbstowcs.3 b/lib/libc/locale/mbstowcs.3 index 8d2dfea3c..f0435fcae 100644 --- a/lib/libc/locale/mbstowcs.3 +++ b/lib/libc/locale/mbstowcs.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: mbstowcs.3,v 1.11 2010/12/16 17:42:27 wiz Exp $ +.\" $NetBSD: mbstowcs.3,v 1.12 2011/03/16 09:32:12 mbalmer Exp $ .\" .\" Copyright (c)2002 Citrus Project, .\" All rights reserved. @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd February 3, 2002 +.Dd March 16, 2011 .Dt MBSTOWCS 3 .Os .\" ---------------------------------------------------------------------- @@ -117,7 +117,8 @@ points to a string containing an invalid or incomplete multibyte character. .\" ---------------------------------------------------------------------- .Sh SEE ALSO .Xr mbtowc 3 , -.Xr setlocale 3 +.Xr setlocale 3 , +.Xr wcstombs 3 .\" ---------------------------------------------------------------------- .Sh STANDARDS The diff --git a/lib/libc/locale/multibyte_sb.c b/lib/libc/locale/multibyte_sb.c deleted file mode 100644 index 53b3fc417..000000000 --- a/lib/libc/locale/multibyte_sb.c +++ /dev/null @@ -1,265 +0,0 @@ -/* $NetBSD: multibyte_sb.c,v 1.5 2004/07/21 20:27:46 tshiozak Exp $ */ - -/* - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char *sccsid = "from: @(#)multibyte.c 5.1 (Berkeley) 2/18/91"; -#else -__RCSID("$NetBSD: multibyte_sb.c,v 1.5 2004/07/21 20:27:46 tshiozak Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include -#include - -/* - * Stub multibyte character functions. - * This cheezy implementation is fixed to the native single-byte - * character set. - */ - -/*ARGSUSED*/ -int -mbsinit(ps) - const mbstate_t *ps; -{ - - return 1; -} - -/*ARGSUSED*/ -size_t -mbrlen(s, n, ps) - const char *s; - size_t n; - mbstate_t *ps; -{ - - /* ps appears to be unused */ - - if (s == NULL || *s == '\0') - return 0; - if (n == 0) - return (size_t)-1; - return 1; -} - -int -mblen(s, n) - const char *s; - size_t n; -{ - - /* s may be NULL */ - - return mbrlen(s, n, NULL); -} - -/*ARGSUSED*/ -size_t -mbrtowc(pwc, s, n, ps) - wchar_t *pwc; - const char *s; - size_t n; - mbstate_t *ps; -{ - - /* pwc may be NULL */ - /* s may be NULL */ - /* ps appears to be unused */ - - if (s == NULL) - return 0; - if (n == 0) - return (size_t)-1; - if (pwc) - *pwc = (wchar_t) *s; - return (*s != '\0'); -} - -int -mbtowc(pwc, s, n) - wchar_t *pwc; - const char *s; - size_t n; -{ - - /* pwc may be NULL */ - /* s may be NULL */ - - return mbrtowc(pwc, s, n, NULL); -} - -/*ARGSUSED*/ -size_t -wcrtomb(s, wchar, ps) - char *s; - wchar_t wchar; - mbstate_t *ps; -{ - - /* s may be NULL */ - /* ps appears to be unused */ - - if (s == NULL) - return 0; - - *s = (char) wchar; - return 1; -} - -int -wctomb(s, wchar) - char *s; - wchar_t wchar; -{ - - /* s may be NULL */ - - return wcrtomb(s, wchar, NULL); -} - -/*ARGSUSED*/ -size_t -mbsrtowcs(pwcs, s, n, ps) - wchar_t *pwcs; - const char **s; - size_t n; - mbstate_t *ps; -{ - int count = 0; - - /* pwcs may be NULL */ - /* s may be NULL */ - /* ps appears to be unused */ - - if (!s || !*s) - return 0; - - if (n != 0) { - if (pwcs != NULL) { - do { - if ((*pwcs++ = (wchar_t) *(*s)++) == 0) - break; - count++; - } while (--n != 0); - } else { - do { - if (((wchar_t)*(*s)++) == 0) - break; - count++; - } while (--n != 0); - } - } - - return count; -} - -size_t -mbstowcs(pwcs, s, n) - wchar_t *pwcs; - const char *s; - size_t n; -{ - - /* pwcs may be NULL */ - /* s may be NULL */ - - return mbsrtowcs(pwcs, &s, n, NULL); -} - -/*ARGSUSED*/ -size_t -wcsrtombs(s, pwcs, n, ps) - char *s; - const wchar_t **pwcs; - size_t n; - mbstate_t *ps; -{ - int count = 0; - - /* s may be NULL */ - /* pwcs may be NULL */ - /* ps appears to be unused */ - - if (pwcs == NULL || *pwcs == NULL) - return (0); - - if (s == NULL) { - while (*(*pwcs)++ != 0) - count++; - return(count); - } - - if (n != 0) { - do { - if ((*s++ = (char) *(*pwcs)++) == 0) - break; - count++; - } while (--n != 0); - } - - return count; -} - -size_t -wcstombs(s, pwcs, n) - char *s; - const wchar_t *pwcs; - size_t n; -{ - - /* s may be NULL */ - /* pwcs may be NULL */ - - return wcsrtombs(s, &pwcs, n, NULL); -} - -wint_t -btowc(c) - int c; -{ - if (c == EOF || c & ~0xFF) - return WEOF; - return (wint_t)c; -} - -int -wctob(c) - wint_t c; -{ - if (c == WEOF || c & ~0xFF) - return EOF; - return (int)c; -} diff --git a/lib/libc/locale/nb_lc_template.h b/lib/libc/locale/nb_lc_template.h index 8721dca5c..73870c639 100644 --- a/lib/libc/locale/nb_lc_template.h +++ b/lib/libc/locale/nb_lc_template.h @@ -1,4 +1,4 @@ -/* $NetBSD: nb_lc_template.h,v 1.3 2010/05/22 13:15:59 tnozaki Exp $ */ +/* $NetBSD: nb_lc_template.h,v 1.4 2012/03/04 21:14:56 tnozaki Exp $ */ /*- * Copyright (c)1999, 2008 Citrus Project, @@ -214,7 +214,7 @@ done: return ret; } -static const char * +const char * _PREFIX(setlocale)(const char * __restrict name, struct _locale_impl_t * __restrict locale) { @@ -243,6 +243,4 @@ _PREFIX(setlocale)(const char * __restrict name, return locale->part_name[(size_t)_CATEGORY_ID]; } -#include "generic_lc_template.h" - #endif /*_NB_LC_TEMPLATE_H_*/ diff --git a/lib/libc/locale/nl_langinfo.3 b/lib/libc/locale/nl_langinfo.3 index 0f9b25d13..d58bf6b69 100644 --- a/lib/libc/locale/nl_langinfo.3 +++ b/lib/libc/locale/nl_langinfo.3 @@ -1,9 +1,9 @@ -.\" $NetBSD: nl_langinfo.3,v 1.19 2010/03/22 19:30:54 joerg Exp $ +.\" $NetBSD: nl_langinfo.3,v 1.20 2011/04/14 05:50:49 jruoho Exp $ .\" .\" Written by J.T. Conklin . .\" Public domain. .\" -.Dd February 12, 2003 +.Dd April 14, 2011 .Dt NL_LANGINFO 3 .Os .Sh NAME @@ -135,6 +135,7 @@ int main(void) .\" .Ed .Sh SEE ALSO .Xr setlocale 3 , +.Xr tm 3 , .Xr nls 7 .Sh STANDARDS The diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c index 2d423fc7e..2d4d7939d 100644 --- a/lib/libc/locale/rune.c +++ b/lib/libc/locale/rune.c @@ -1,5 +1,4 @@ -/* $NetBSD: rune.c,v 1.41 2010/11/30 15:25:05 tnozaki Exp $ */ - +/* $NetBSD: rune.c,v 1.45 2012/08/08 20:16:50 wiz Exp $ */ /*- * Copyright (c)2010 Citrus Project, * All rights reserved. @@ -47,7 +46,6 @@ #include "citrus_ctype.h" #include "runetype_local.h" -#include "bsdctype_local.h" #include "multibyte.h" @@ -163,7 +161,7 @@ _rune_read_file(const char * __restrict var, size_t lenvar, variable_len = be32toh((uint32_t)frl->frl_variable_len); - n = (len * sizeof(*fre)) + variable_len; + n = len * sizeof(*fre); if (lenvar < n) return EFTYPE; lenvar -= n; @@ -220,15 +218,15 @@ do { \ READ_RANGE(maplower); READ_RANGE(mapupper); - memcpy((void *)rune, (void const *)frune, variable_len); - rl->rl_variable_len = variable_len; - rl->rl_variable = (void *)rune; - - if (lenvar > 0) { + if (lenvar < variable_len) { ret = EFTYPE; goto err; } + memcpy((void *)rune, (void const *)frune, variable_len); + rl->rl_variable_len = variable_len; + rl->rl_variable = (void *)rune; + _rune_find_codeset(rlp->rlp_codeset, sizeof(rlp->rlp_codeset), (char *)rl->rl_variable, &rl->rl_variable_len); @@ -280,52 +278,6 @@ err: return ret; } -static __inline int -_rune_read_bsdctype(const char * __restrict var, size_t lenvar, - _RuneLocale ** __restrict prl) -{ - const _FileBSDCTypeLocale *fbl; - uint32_t value; - int i, bits; - uint16_t lower, upper; - _RuneLocalePriv *rlp; - _RuneLocale *rl; - - if (lenvar < sizeof(*fbl)) - return EFTYPE; - fbl = (const _FileBSDCTypeLocale *)(const void *)var; - if (memcmp(&fbl->fbl_id[0], _CTYPE_ID, sizeof(fbl->fbl_id))) - return EFTYPE; - value = be32toh(fbl->fbl_rev); - if (value != _CTYPE_REV) - return EFTYPE; - value = be32toh(fbl->fbl_num_chars); - if (value != _CTYPE_CACHE_SIZE) - return EFTYPE; - rlp = (_RuneLocalePriv *)malloc(sizeof(*rlp)); - if (rlp == NULL) - return ENOMEM; - _rune_init_priv(rlp); - rlp->rlp_codeset[0] = '\0'; - - rl = &rlp->rl; - for (i = 0; i < _CTYPE_CACHE_SIZE; ++i) { - bits = fbl->fbl_ctype_tab[i]; - lower = be16toh(fbl->fbl_tolower_tab[i]); - upper = be16toh(fbl->fbl_toupper_tab[i]); - - rlp->rlp_ctype_tab [i + 1] = (unsigned char)bits; - rlp->rlp_tolower_tab[i + 1] = (short)lower; - rlp->rlp_toupper_tab[i + 1] = (short)upper; - - rl->rl_runetype[i] = _runetype_from_ctype(bits, i); - rl->rl_maplower[i] = (__nbrune_t)lower; - rl->rl_mapupper[i] = (__nbrune_t)upper; - } - *prl = rl; - return 0; -} - int _rune_load(const char * __restrict var, size_t lenvar, _RuneLocale ** __restrict prl) @@ -341,9 +293,6 @@ _rune_load(const char * __restrict var, size_t lenvar, case 'R': ret = _rune_read_file(var, lenvar, prl); break; - case 'B': - ret = _rune_read_bsdctype(var, lenvar, prl); - break; default: ret = EFTYPE; } diff --git a/lib/libc/locale/runetype_misc.h b/lib/libc/locale/runetype_misc.h index df4c5b7d1..5ab5e6955 100644 --- a/lib/libc/locale/runetype_misc.h +++ b/lib/libc/locale/runetype_misc.h @@ -1,4 +1,4 @@ -/* $NetBSD: runetype_misc.h,v 1.2 2010/12/14 02:28:57 joerg Exp $ */ +/* $NetBSD: runetype_misc.h,v 1.3 2012/01/18 14:22:27 joerg Exp $ */ /*- * Copyright (c) 1993 @@ -79,52 +79,4 @@ _runetype_to_ctype(_RuneType bits) return ret; } -static __inline _RuneType -_runetype_from_ctype(int bits, int ch) -{ - _RuneType ret; - - /* - * TWEAKS! - * - old locale file declarations do not have proper _B - * in many cases. - * - isprint() declaration in ctype.h incorrectly uses _B. - * _B means "isprint but !isgraph", not "isblank" with the - * declaration. - * - _X and _RUNETYPE_X have negligible difference in meaning. - * - we don't set digit value, fearing that it would be - * too much of hardcoding. we may need to revisit it. - */ - - ret = (_RuneType)0; - if (bits & _CTYPE_U) - ret |= _RUNETYPE_U; - if (bits & _CTYPE_L) - ret |= _RUNETYPE_L; - if (bits & _CTYPE_N) - ret |= _RUNETYPE_D; - if (bits & _CTYPE_S) - ret |= _RUNETYPE_S; - if (bits & _CTYPE_P) - ret |= _RUNETYPE_P; - if (bits & _CTYPE_C) - ret |= _RUNETYPE_C; - /* derived flag bits, duplicate of ctype.h */ - if (bits & (_CTYPE_U|_CTYPE_L)) - ret |= _RUNETYPE_A; - if (bits & (_CTYPE_N|_CTYPE_X)) - ret |= _RUNETYPE_X; - if (bits & (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N)) - ret |= _RUNETYPE_G; - /* we don't really trust _B in the file. see above. */ - if (bits & _CTYPE_B) - ret |= _RUNETYPE_B; - if ((bits & (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N|_CTYPE_B)) || - ch == ' ') - ret |= (_RUNETYPE_R | _RUNETYPE_SW1); - if (ch == ' ' || ch == '\t') - ret |= _RUNETYPE_B; - return ret; -} - #endif /* !_RUNETYPE_MISC_H_ */ diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index b755dba36..469a1c063 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -1,4 +1,4 @@ -/* $NetBSD: setlocale.c,v 1.58 2010/06/07 13:52:30 tnozaki Exp $ */ +/* $NetBSD: setlocale.c,v 1.60 2012/03/04 21:14:56 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: setlocale.c,v 1.58 2010/06/07 13:52:30 tnozaki Exp $"); +__RCSID("$NetBSD: setlocale.c,v 1.60 2012/03/04 21:14:56 tnozaki Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -43,81 +43,21 @@ __RCSID("$NetBSD: setlocale.c,v 1.58 2010/06/07 13:52:30 tnozaki Exp $"); const char *_PathLocale = NULL; -__link_set_decl(all_categories, _locale_category_t); - -extern const _locale_category_t _generic_LC_ALL_desc; -extern const _locale_category_t _dummy_LC_COLLATE_desc; -#ifdef WITH_RUNE -extern const _locale_category_t _citrus_LC_CTYPE_desc; -extern const _locale_category_t _citrus_LC_MONETARY_desc; -extern const _locale_category_t _citrus_LC_NUMERIC_desc; -extern const _locale_category_t _citrus_LC_TIME_desc; -extern const _locale_category_t _citrus_LC_MESSAGES_desc; -#else -extern const _locale_category_t _localeio_LC_CTYPE_desc; -extern const _locale_category_t _localeio_LC_MONETARY_desc; -extern const _locale_category_t _localeio_LC_NUMERIC_desc; -extern const _locale_category_t _localeio_LC_TIME_desc; -extern const _locale_category_t _localeio_LC_MESSAGES_desc; -#endif - -#ifdef __minix -/* GNU binutils 2.x a.out support is rotten and link sets are not - supported. Workaround this by explicitely creating the structure - the linker was supposed to create. */ - -struct { - int __ls_length; - _locale_category_t *__ls_items[7]; -} __link_set_all_categories = { - .__ls_length = 7, - .__ls_items = { - [0] = __UNCONST(&_generic_LC_ALL_desc), - [1] = __UNCONST(&_dummy_LC_COLLATE_desc), -#ifdef WITH_RUNE - [2] = __UNCONST(&_citrus_LC_CTYPE_desc), - [3] = __UNCONST(&_citrus_LC_MONETARY_desc), - [4] = __UNCONST(&_citrus_LC_NUMERIC_desc), - [5] = __UNCONST(&_citrus_LC_TIME_desc), - [6] = __UNCONST(&_citrus_LC_MESSAGES_desc), -#else - [2] = __UNCONST(&_localeio_LC_CTYPE_desc), - [3] = __UNCONST(&_localeio_LC_MONETARY_desc), - [4] = __UNCONST(&_localeio_LC_NUMERIC_desc), - [5] = __UNCONST(&_localeio_LC_TIME_desc), - [6] = __UNCONST(&_localeio_LC_MESSAGES_desc), -#endif - }, +static _locale_set_t all_categories[_LC_LAST] = { + [LC_ALL ] = &_generic_LC_ALL_setlocale, + [LC_COLLATE ] = &_dummy_LC_COLLATE_setlocale, + [LC_CTYPE ] = &_citrus_LC_CTYPE_setlocale, + [LC_MONETARY] = &_citrus_LC_MONETARY_setlocale, + [LC_NUMERIC ] = &_citrus_LC_NUMERIC_setlocale, + [LC_TIME ] = &_citrus_LC_TIME_setlocale, + [LC_MESSAGES] = &_citrus_LC_MESSAGES_setlocale, }; -#endif /* __minix */ - - -__link_set_add_data(all_categories, _generic_LC_ALL_desc); -__link_set_add_data(all_categories, _dummy_LC_COLLATE_desc); -#ifdef WITH_RUNE -__link_set_add_data(all_categories, _citrus_LC_CTYPE_desc); -__link_set_add_data(all_categories, _citrus_LC_MONETARY_desc); -__link_set_add_data(all_categories, _citrus_LC_NUMERIC_desc); -__link_set_add_data(all_categories, _citrus_LC_TIME_desc); -__link_set_add_data(all_categories, _citrus_LC_MESSAGES_desc); -#else -__link_set_add_data(all_categories, _localeio_LC_CTYPE_desc); -__link_set_add_data(all_categories, _localeio_LC_MONETARY_desc); -__link_set_add_data(all_categories, _localeio_LC_NUMERIC_desc); -__link_set_add_data(all_categories, _localeio_LC_TIME_desc); -__link_set_add_data(all_categories, _localeio_LC_MESSAGES_desc); -#endif - -_locale_category_t * +_locale_set_t _find_category(int category) { - _locale_category_t * const *p; - - __link_set_foreach(p, all_categories) { - if ((*p)->category == category) - return *p; - } + if (category >= LC_ALL && category < _LC_LAST) + return all_categories[category]; return NULL; } @@ -145,21 +85,18 @@ _get_locale_env(const char *category) char * __setlocale(int category, const char *name) { - _locale_category_t *l; + _locale_set_t sl; struct _locale_impl_t *impl; - if (category >= LC_ALL && category < _LC_LAST) { - l = _find_category(category); - if (l != NULL) { - if (issetugid() || ((_PathLocale == NULL && - (_PathLocale = getenv("PATH_LOCALE")) == NULL) || - *_PathLocale == '\0')) - _PathLocale = _PATH_LOCALE; - impl = *_current_locale(); - return __UNCONST((*l->setlocale)(name, impl)); - } - } - return NULL; + sl = _find_category(category); + if (sl == NULL) + return NULL; + if (issetugid() || ((_PathLocale == NULL && + (_PathLocale = getenv("PATH_LOCALE")) == NULL) || + *_PathLocale == '\0')) + _PathLocale = _PATH_LOCALE; + impl = *_current_locale(); + return __UNCONST((*sl)(name, impl)); } char * diff --git a/lib/libc/locale/setlocale_local.h b/lib/libc/locale/setlocale_local.h index 15601a994..cd941c1ad 100644 --- a/lib/libc/locale/setlocale_local.h +++ b/lib/libc/locale/setlocale_local.h @@ -1,4 +1,4 @@ -/* $NetBSD: setlocale_local.h,v 1.7 2010/06/07 13:52:30 tnozaki Exp $ */ +/* $NetBSD: setlocale_local.h,v 1.8 2012/03/04 21:14:57 tnozaki Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -58,17 +58,26 @@ struct _locale_impl_t { typedef const char *(*_locale_set_t)(const char * __restrict, struct _locale_impl_t * __restrict); -typedef struct { - const char* name; - int category; - _locale_set_t setlocale; -} _locale_category_t; - __BEGIN_DECLS -_locale_category_t *_find_category(int); +_locale_set_t _find_category(int); const char *_get_locale_env(const char *); struct _locale_impl_t **_current_locale(void); char *__setlocale(int, const char *); + +const char *_generic_LC_ALL_setlocale( + const char * __restrict, struct _locale_impl_t * __restrict); +const char *_dummy_LC_COLLATE_setlocale( + const char * __restrict, struct _locale_impl_t * __restrict); +const char *_citrus_LC_CTYPE_setlocale( + const char * __restrict, struct _locale_impl_t * __restrict); +const char *_citrus_LC_MONETARY_setlocale( + const char * __restrict, struct _locale_impl_t * __restrict); +const char *_citrus_LC_NUMERIC_setlocale( + const char * __restrict, struct _locale_impl_t * __restrict); +const char *_citrus_LC_TIME_setlocale( + const char * __restrict, struct _locale_impl_t * __restrict); +const char *_citrus_LC_MESSAGES_setlocale( + const char * __restrict, struct _locale_impl_t * __restrict); __END_DECLS static __inline struct _locale_cache_t * diff --git a/lib/libc/locale/wcscoll.c b/lib/libc/locale/wcscoll.c index 2e589f390..d1fff9043 100644 --- a/lib/libc/locale/wcscoll.c +++ b/lib/libc/locale/wcscoll.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $ */ +/* $NetBSD: wcscoll.c,v 1.2 2012/06/25 22:32:44 abs Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $"); +__RCSID("$NetBSD: wcscoll.c,v 1.2 2012/06/25 22:32:44 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -40,8 +40,7 @@ __RCSID("$NetBSD: wcscoll.c,v 1.1 2003/03/02 22:18:16 tshiozak Exp $"); * Compare strings with using collating information. */ int -wcscoll(s1, s2) - const wchar_t *s1, *s2; +wcscoll(const wchar_t *s1, const wchar_t *s2) { /* XXX: LC_COLLATE should be implemented. */ return (wcscmp(s1, s2)); diff --git a/lib/libc/locale/wcsftime.3 b/lib/libc/locale/wcsftime.3 index 779593a62..4cd59849f 100644 --- a/lib/libc/locale/wcsftime.3 +++ b/lib/libc/locale/wcsftime.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: wcsftime.3,v 1.2 2005/04/06 21:39:17 kleink Exp $ +.\" $NetBSD: wcsftime.3,v 1.3 2011/04/14 05:50:49 jruoho Exp $ .\" .\" Copyright (c) 2002 Tim J. Robbins .\" All rights reserved. @@ -26,7 +26,7 @@ .\" .\" $FreeBSD: /repoman/r/ncvs/src/lib/libc/locale/wcsftime.3,v 1.2 2002/11/29 17:35:09 ru Exp $ .\" -.Dd September 8, 2002 +.Dd April 14, 2011 .Dt WCSFTIME 3 .Os .Sh NAME @@ -61,7 +61,8 @@ argument with type instead of .Vt "const wchar_t *" . .Sh SEE ALSO -.Xr strftime 3 +.Xr strftime 3 , +.Xr tm 3 .Sh STANDARDS The .Fn wcsftime diff --git a/lib/libc/locale/wcstombs.3 b/lib/libc/locale/wcstombs.3 index 3b426fec1..0a93b8354 100644 --- a/lib/libc/locale/wcstombs.3 +++ b/lib/libc/locale/wcstombs.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: wcstombs.3,v 1.12 2010/12/16 17:42:27 wiz Exp $ +.\" $NetBSD: wcstombs.3,v 1.13 2011/03/16 09:32:12 mbalmer Exp $ .\" .\" Copyright (c)2002 Citrus Project, .\" All rights reserved. @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd August 8, 2006 +.Dd March 16, 2011 .Dt WCSTOMBS 3 .Os .\" ---------------------------------------------------------------------- @@ -120,6 +120,7 @@ points to a string containing an invalid wide character. .El .\" ---------------------------------------------------------------------- .Sh SEE ALSO +.Xr mbstowcs 3 , .Xr setlocale 3 , .Xr wctomb 3 .\" ---------------------------------------------------------------------- diff --git a/lib/libc/locale/wcsxfrm.c b/lib/libc/locale/wcsxfrm.c index 87b68ec19..687931d94 100644 --- a/lib/libc/locale/wcsxfrm.c +++ b/lib/libc/locale/wcsxfrm.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcsxfrm.c,v 1.2 2006/10/15 16:14:08 christos Exp $ */ +/* $NetBSD: wcsxfrm.c,v 1.3 2012/06/25 22:32:44 abs Exp $ */ /*- * Copyright (c)2003 Citrus Project, @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcsxfrm.c,v 1.2 2006/10/15 16:14:08 christos Exp $"); +__RCSID("$NetBSD: wcsxfrm.c,v 1.3 2012/06/25 22:32:44 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -40,10 +40,7 @@ __RCSID("$NetBSD: wcsxfrm.c,v 1.2 2006/10/15 16:14:08 christos Exp $"); * Compare strings with using collating information. */ size_t -wcsxfrm(s1, s2, n) - wchar_t *s1; - const wchar_t *s2; - size_t n; +wcsxfrm(wchar_t *s1, const wchar_t *s2, size_t n) { size_t len; diff --git a/lib/libc/md/Makefile.inc b/lib/libc/md/Makefile.inc index 741799da6..56637532c 100644 --- a/lib/libc/md/Makefile.inc +++ b/lib/libc/md/Makefile.inc @@ -7,12 +7,12 @@ SRCS+= md4c.c md5c.c md4hl.c md5hl.c -#MAN+= md4.3 md5.3 +MAN+= md4.3 md5.3 -#MLINKS+=md4.3 MD4Init.3 md4.3 MD4Update.3 md4.3 MD4Final.3 -#MLINKS+=md4.3 MD4End.3 md4.3 MD4File.3 md4.3 MD4Data.3 -#MLINKS+=md5.3 MD5Init.3 md5.3 MD5Update.3 md5.3 MD5Final.3 -#MLINKS+=md5.3 MD5End.3 md5.3 MD5File.3 md5.3 MD5Data.3 +MLINKS+=md4.3 MD4Init.3 md4.3 MD4Update.3 md4.3 MD4Final.3 +MLINKS+=md4.3 MD4End.3 md4.3 MD4File.3 md4.3 MD4Data.3 +MLINKS+=md5.3 MD5Init.3 md5.3 MD5Update.3 md5.3 MD5Final.3 +MLINKS+=md5.3 MD5End.3 md5.3 MD5File.3 md5.3 MD5Data.3 CLEANFILES+= md[45]hl.c md[45].3 diff --git a/lib/libc/md/mdXhl.c b/lib/libc/md/mdXhl.c index 69e0e25ff..c6c9b389c 100644 --- a/lib/libc/md/mdXhl.c +++ b/lib/libc/md/mdXhl.c @@ -1,4 +1,4 @@ -/* $NetBSD: mdXhl.c,v 1.8 2009/03/06 18:15:24 apb Exp $ */ +/* $NetBSD: mdXhl.c,v 1.10 2012/06/25 22:32:44 abs Exp $ */ /* * ---------------------------------------------------------------------------- @@ -45,9 +45,7 @@ WA(MDNAME(Data),CONCAT(_,MDNAME(Data))) char * -MDNAME(End)(ctx, buf) - MDNAME(_CTX) *ctx; - char *buf; +MDNAME(End)(MDNAME(_CTX) *ctx, char *buf) { int i; unsigned char digest[16]; @@ -72,13 +70,12 @@ MDNAME(End)(ctx, buf) } char * -MDNAME(File)(filename, buf) - const char *filename; - char *buf; +MDNAME(File)(const char *filename, char *buf) { unsigned char buffer[BUFSIZ]; MDNAME(_CTX) ctx; - int f, i, j; + int f, j; + ssize_t i; _DIAGASSERT(filename != 0); /* buf may be NULL */ @@ -102,10 +99,7 @@ MDNAME(File)(filename, buf) } char * -MDNAME(Data)(data, len, buf) - const unsigned char *data; - unsigned int len; - char *buf; +MDNAME(Data)(const unsigned char *data, unsigned int len, char *buf) { MDNAME(_CTX) ctx; diff --git a/lib/libc/minix/minix-malloc-debug.c b/lib/libc/minix/minix-malloc-debug.c index 0fbb70410..848d0f424 100644 --- a/lib/libc/minix/minix-malloc-debug.c +++ b/lib/libc/minix/minix-malloc-debug.c @@ -32,8 +32,6 @@ struct block { static u8_t *ptr_min, *ptr_max; -#define MIN(x, y) ((x) < (y) ? (x) : (y)) - static unsigned long page_round_down(unsigned long x) { return x - x % PAGE_SIZE; diff --git a/lib/libc/misc/initfini.c b/lib/libc/misc/initfini.c index d8a6c12f9..24747373d 100644 --- a/lib/libc/misc/initfini.c +++ b/lib/libc/misc/initfini.c @@ -1,4 +1,4 @@ -/* $NetBSD: initfini.c,v 1.7 2010/11/14 18:11:42 tron Exp $ */ +/* $NetBSD: initfini.c,v 1.10 2012/02/16 23:00:39 joerg Exp $ */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. @@ -30,13 +30,20 @@ */ #include -__RCSID("$NetBSD: initfini.c,v 1.7 2010/11/14 18:11:42 tron Exp $"); +__RCSID("$NetBSD: initfini.c,v 1.10 2012/02/16 23:00:39 joerg Exp $"); #ifdef _LIBC #include "namespace.h" #endif -void __libc_init(void) __attribute__((__constructor__, __used__)); +#include +#include +#ifndef __minix +#include +#endif +#include + +void _libc_init(void) __attribute__((__constructor__, __used__)); void __guard_setup(void); void __libc_thr_init(void); @@ -44,16 +51,62 @@ void __libc_atomic_init(void); void __libc_atexit_init(void); void __libc_env_init(void); -/* LINTED used */ +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) +__dso_hidden void __libc_static_tls_setup(void); +#endif + +#ifdef __weak_alias +__weak_alias(_dlauxinfo,___dlauxinfo) +static void *__libc_dlauxinfo; + +void *___dlauxinfo(void) __pure; + +void * +___dlauxinfo(void) +{ + return __libc_dlauxinfo; +} +#endif + +static bool libc_initialised; + +void _libc_init(void); + +/* + * Declare as common symbol to allow new libc with older binaries to + * not trigger an undefined reference. + */ +struct ps_strings *__ps_strings; + +/* + * _libc_init is called twice. The first time explicitly by crt0.o + * (for newer versions) and the second time as indirectly via _init(). + */ void -__libc_init(void) +_libc_init(void) { + if (libc_initialised) + return; + + libc_initialised = 1; + + if (__ps_strings != NULL) + __libc_dlauxinfo = __ps_strings->ps_argvstr + + __ps_strings->ps_nargvstr + __ps_strings->ps_nenvstr + 2; + /* For -fstack-protector */ __guard_setup(); +#ifdef _REENTRANT /* Atomic operations */ __libc_atomic_init(); +#endif + +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + /* Initialize TLS for statically linked programs. */ + __libc_static_tls_setup(); +#endif #ifdef _REENTRANT /* Threads */ diff --git a/lib/libc/misc/stack_protector.c b/lib/libc/misc/stack_protector.c index 0f20cb9ea..ff26160c1 100644 --- a/lib/libc/misc/stack_protector.c +++ b/lib/libc/misc/stack_protector.c @@ -1,4 +1,4 @@ -/* $NetBSD: stack_protector.c,v 1.5 2010/12/07 20:10:53 joerg Exp $ */ +/* $NetBSD: stack_protector.c,v 1.8 2012/03/13 21:13:39 christos Exp $ */ /* $OpenBSD: stack_protector.c,v 1.10 2006/03/31 05:34:44 deraadt Exp $ */ /* @@ -28,7 +28,7 @@ * */ #include -__RCSID("$NetBSD: stack_protector.c,v 1.5 2010/12/07 20:10:53 joerg Exp $"); +__RCSID("$NetBSD: stack_protector.c,v 1.8 2012/03/13 21:13:39 christos Exp $"); #ifdef _LIBC #include "namespace.h" @@ -50,14 +50,14 @@ void xprintf(const char *fmt, ...); long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0}; static void __fail(const char *) __attribute__((__noreturn__)); -void __stack_chk_fail_local(void); +__dead void __stack_chk_fail_local(void); void __guard_setup(void); void __guard_setup(void) { #ifndef __minix - int mib[2]; + static const int mib[2] = { CTL_KERN, KERN_ARND }; size_t len; #endif @@ -65,12 +65,9 @@ __guard_setup(void) return; #ifndef __minix - mib[0] = CTL_KERN; - mib[1] = KERN_ARND; - len = sizeof(__stack_chk_guard); - if (__sysctl(mib, 2, __stack_chk_guard, &len, NULL, 0) == -1 || - len != sizeof(__stack_chk_guard)) { + if (__sysctl(mib, (u_int)__arraycount(mib), __stack_chk_guard, &len, + NULL, 0) == -1 || len != sizeof(__stack_chk_guard)) { #endif /* If sysctl was unsuccessful, use the "terminator canary". */ ((unsigned char *)(void *)__stack_chk_guard)[0] = 0; @@ -88,8 +85,8 @@ __fail(const char *msg) { #ifdef _LIBC struct syslog_data sdata = SYSLOG_DATA_INIT; -#endif struct sigaction sa; +#endif sigset_t mask; /* Immediately block all signal handlers from running code */ @@ -104,12 +101,14 @@ __fail(const char *msg) xprintf("%s: %s\n", getprogname(), msg); #endif +#ifdef _LIBC (void)memset(&sa, 0, sizeof(sa)); (void)sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = SIG_DFL; (void)sigaction(SIGABRT, &sa, NULL); (void)raise(SIGABRT); +#endif _exit(127); } diff --git a/lib/libc/nameser/ns_name.c b/lib/libc/nameser/ns_name.c index ec2045e58..319ece2be 100644 --- a/lib/libc/nameser/ns_name.c +++ b/lib/libc/nameser/ns_name.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_name.c,v 1.8 2009/04/12 19:43:37 christos Exp $ */ +/* $NetBSD: ns_name.c,v 1.9 2012/03/13 21:13:39 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -22,7 +22,7 @@ #ifdef notdef static const char rcsid[] = "Id: ns_name.c,v 1.11 2009/01/23 19:59:16 each Exp"; #else -__RCSID("$NetBSD: ns_name.c,v 1.8 2009/04/12 19:43:37 christos Exp $"); +__RCSID("$NetBSD: ns_name.c,v 1.9 2012/03/13 21:13:39 christos Exp $"); #endif #endif @@ -33,6 +33,7 @@ __RCSID("$NetBSD: ns_name.c,v 1.8 2009/04/12 19:43:37 christos Exp $"); #include #include +#include #include #include #include @@ -43,9 +44,9 @@ __RCSID("$NetBSD: ns_name.c,v 1.8 2009/04/12 19:43:37 christos Exp $"); #include "port_after.h" #ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) +# define SPRINTF(x) ((int)strlen(sprintf/**/x)) #else -# define SPRINTF(x) ((size_t)sprintf x) +# define SPRINTF(x) (sprintf x) #endif #define NS_TYPE_ELT 0x40 /*%< EDNS0 extended label type */ @@ -189,7 +190,8 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) return (-1); } *dn++ = '\0'; - return (dn - dst); + _DIAGASSERT(__type_fit(int, dn - dst)); + return (int)(dn - dst); } /*% @@ -256,19 +258,19 @@ ns_name_pton2(const char *src, u_char *dst, size_t dstsiz, size_t *dstlen) { continue; } else if ((cp = strchr(digits, c)) != NULL) { - n = (cp - digits) * 100; + n = (int)(cp - digits) * 100; if ((c = *src++) == 0 || (cp = strchr(digits, c)) == NULL) { errno = EMSGSIZE; return (-1); } - n += (cp - digits) * 10; + n += (int)(cp - digits) * 10; if ((c = *src++) == 0 || (cp = strchr(digits, c)) == NULL) { errno = EMSGSIZE; return (-1); } - n += (cp - digits); + n += (int)(cp - digits); if (n > 255) { errno = EMSGSIZE; return (-1); @@ -280,7 +282,7 @@ ns_name_pton2(const char *src, u_char *dst, size_t dstsiz, size_t *dstlen) { escaped = 1; continue; } else if (c == '.') { - c = (bp - label - 1); + c = (int)(bp - label - 1); if ((c & NS_CMPRSFLGS) != 0) { /*%< Label too big. */ errno = EMSGSIZE; return (-1); @@ -320,7 +322,7 @@ ns_name_pton2(const char *src, u_char *dst, size_t dstsiz, size_t *dstlen) { } *bp++ = (u_char)c; } - c = (bp - label - 1); + c = (int)(bp - label - 1); if ((c & NS_CMPRSFLGS) != 0) { /*%< Label too big. */ errno = EMSGSIZE; return (-1); @@ -398,7 +400,8 @@ ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) } } *dn++ = '\0'; - return (dn - dst); + _DIAGASSERT(__type_fit(int, dn - dst)); + return (int)(dn - dst); } /*% @@ -466,8 +469,10 @@ ns_name_unpack2(const u_char *msg, const u_char *eom, const u_char *src, errno = EMSGSIZE; return (-1); } - if (len < 0) - len = srcp - src + 1; + if (len < 0) { + _DIAGASSERT(__type_fit(int, srcp - src + 1)); + len = (int)(srcp - src + 1); + } srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff)); if (srcp < msg || srcp >= eom) { /*%< Out of range. */ errno = EMSGSIZE; @@ -493,9 +498,11 @@ ns_name_unpack2(const u_char *msg, const u_char *eom, const u_char *src, *dstp++ = 0; if (dstlen != NULL) *dstlen = dstp - dst; - if (len < 0) - len = srcp - src; - return (len); + if (len < 0) { + _DIAGASSERT(__type_fit(int, srcp - src)); + len = (int)(srcp - src); + } + return len; } /*% @@ -575,7 +582,8 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz, } *dstp++ = ((u_int32_t)l >> 8) | NS_CMPRSFLGS; *dstp++ = l % 256; - return (dstp - dst); + _DIAGASSERT(__type_fit(int, dstp - dst)); + return (int)(dstp - dst); } /* Not found, save it. */ if (lastdnptr != NULL && cpp < lastdnptr - 1 && @@ -606,7 +614,8 @@ cleanup: errno = EMSGSIZE; return (-1); } - return (dstp - dst); + _DIAGASSERT(__type_fit(int, dstp - dst)); + return (int)(dstp - dst); } /*% @@ -960,8 +969,11 @@ dn_find(const u_char *domain, const u_char *msg, mklower(*cp++)) goto next; /* Is next root for both ? */ - if (*dn == '\0' && *cp == '\0') - return (sp - msg); + if (*dn == '\0' && *cp == '\0') { + _DIAGASSERT(__type_fit(int, + sp - msg)); + return (int)(sp - msg); + } if (*dn) continue; goto next; @@ -992,7 +1004,7 @@ decode_bitstring(const unsigned char **cpp, char *dn, const char *eom) if ((blen = (*cp & 0xff)) == 0) blen = 256; plen = (blen + 3) / 4; - plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); + plen += (int)sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); if (dn + plen >= eom) return (-1); @@ -1027,7 +1039,8 @@ decode_bitstring(const unsigned char **cpp, char *dn, const char *eom) dn += i; *cpp = cp; - return (dn - beg); + _DIAGASSERT(__type_fit(int, dn - beg)); + return (int)(dn - beg); } static int diff --git a/lib/libc/nameser/ns_netint.c b/lib/libc/nameser/ns_netint.c index 7e4e77d1e..750699283 100644 --- a/lib/libc/nameser/ns_netint.c +++ b/lib/libc/nameser/ns_netint.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_netint.c,v 1.6 2009/04/12 17:07:17 christos Exp $ */ +/* $NetBSD: ns_netint.c,v 1.7 2012/03/13 21:13:39 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -22,7 +22,7 @@ #ifdef notdef static const char rcsid[] = "Id: ns_netint.c,v 1.3 2005/04/27 04:56:40 sra Exp"; #else -__RCSID("$NetBSD: ns_netint.c,v 1.6 2009/04/12 17:07:17 christos Exp $"); +__RCSID("$NetBSD: ns_netint.c,v 1.7 2012/03/13 21:13:39 christos Exp $"); #endif #endif @@ -36,29 +36,29 @@ __RCSID("$NetBSD: ns_netint.c,v 1.6 2009/04/12 17:07:17 christos Exp $"); /* Public. */ -u_int16_t +uint16_t ns_get16(const u_char *src) { - u_int dst; + uint16_t dst; NS_GET16(dst, src); - return (dst); + return dst; } -u_int32_t +uint32_t ns_get32(const u_char *src) { - u_long dst; + u_int32_t dst; NS_GET32(dst, src); - return (dst); + return dst; } void -ns_put16(u_int16_t src, u_char *dst) { +ns_put16(uint16_t src, u_char *dst) { NS_PUT16(src, dst); } void -ns_put32(u_int32_t src, u_char *dst) { +ns_put32(uint32_t src, u_char *dst) { NS_PUT32(src, dst); } diff --git a/lib/libc/nameser/ns_parse.c b/lib/libc/nameser/ns_parse.c index 007606964..0379a7d42 100644 --- a/lib/libc/nameser/ns_parse.c +++ b/lib/libc/nameser/ns_parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_parse.c,v 1.8 2009/04/12 19:43:37 christos Exp $ */ +/* $NetBSD: ns_parse.c,v 1.9 2012/03/13 21:13:39 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -22,7 +22,7 @@ #ifdef notdef static const char rcsid[] = "Id: ns_parse.c,v 1.10 2009/01/23 19:59:16 each Exp"; #else -__RCSID("$NetBSD: ns_parse.c,v 1.8 2009/04/12 19:43:37 christos Exp $"); +__RCSID("$NetBSD: ns_parse.c,v 1.9 2012/03/13 21:13:39 christos Exp $"); #endif #endif @@ -35,6 +35,7 @@ __RCSID("$NetBSD: ns_parse.c,v 1.8 2009/04/12 19:43:37 christos Exp $"); #include #include +#include #include #include #include @@ -104,7 +105,8 @@ ns_skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) { } if (ptr > eom) RETERR(EMSGSIZE); - return (ptr - optr); + _DIAGASSERT(__type_fit(int, ptr - optr)); + return (int)(ptr - optr); } int diff --git a/lib/libc/nameser/ns_print.c b/lib/libc/nameser/ns_print.c index 51fe16ee4..b6a18f5bd 100644 --- a/lib/libc/nameser/ns_print.c +++ b/lib/libc/nameser/ns_print.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_print.c,v 1.10 2009/04/12 19:43:37 christos Exp $ */ +/* $NetBSD: ns_print.c,v 1.11 2012/03/13 21:13:39 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -22,7 +22,7 @@ #ifdef notdef static const char rcsid[] = "Id: ns_print.c,v 1.12 2009/03/03 05:29:58 each Exp"; #else -__RCSID("$NetBSD: ns_print.c,v 1.10 2009/04/12 19:43:37 christos Exp $"); +__RCSID("$NetBSD: ns_print.c,v 1.11 2012/03/13 21:13:39 christos Exp $"); #endif #endif @@ -39,17 +39,19 @@ __RCSID("$NetBSD: ns_print.c,v 1.10 2009/04/12 19:43:37 christos Exp $"); #include #include +#include #include #include +#include #include #include #include "port_after.h" #ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) +# define SPRINTF(x) ((int)strlen(sprintf/**/x)) #else -# define SPRINTF(x) ((size_t)sprintf x) +# define SPRINTF(x) (sprintf x) #endif /* Forward. */ @@ -126,7 +128,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, if (name_ctx != NULL && ns_samename(name_ctx, name) == 1) { T(addstr("\t\t\t", (size_t)3, &buf, &buflen)); } else { - len = prune_origin(name, origin); + len = (int)prune_origin(name, origin); if (*name == '\0') { goto root; } else if (len == 0) { @@ -161,7 +163,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, case ns_t_a: if (rdlen != (size_t)NS_INADDRSZ) goto formerr; - (void) inet_ntop(AF_INET, rdata, buf, buflen); + (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); break; @@ -331,7 +333,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, case ns_t_aaaa: if (rdlen != (size_t)NS_IN6ADDRSZ) goto formerr; - (void) inet_ntop(AF_INET6, rdata, buf, buflen); + (void) inet_ntop(AF_INET6, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); break; @@ -422,7 +424,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, goto formerr; /* Address. */ - (void) inet_ntop(AF_INET, rdata, buf, buflen); + (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += NS_INADDRSZ; @@ -565,7 +567,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, } case ns_t_nxt: { - int n, c; + ptrdiff_t n, c; /* Next domain name. */ T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); @@ -574,7 +576,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, n = edata - rdata; for (c = 0; c < n*8; c++) if (NS_NXT_BIT_ISSET(c, rdata)) { - len = SPRINTF((tmp, " %s", p_type(c))); + len = SPRINTF((tmp, " %s", p_type((int)c))); T(addstr(tmp, (size_t)len, &buf, &buflen)); } break; @@ -583,7 +585,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, case ns_t_cert: { u_int c_type, key_tag, alg; int n; - unsigned int siz; + size_t siz; char base64_cert[8192], tmp1[40]; const char *leader; @@ -689,7 +691,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, if (rdata + pbyte >= edata) goto formerr; memset(&a, 0, sizeof(a)); memcpy(&a.s6_addr[pbyte], rdata, sizeof(a) - pbyte); - (void) inet_ntop(AF_INET6, &a, buf, buflen); + (void) inet_ntop(AF_INET6, &a, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += sizeof(a) - pbyte; } @@ -885,7 +887,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, char base64_dhcid[8192]; const char *leader; - siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ + siz = (int)(edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_dhcid) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); @@ -961,12 +963,12 @@ ns_sprintrrf(const u_char *msg, size_t msglen, T(addstr(".", 1, &buf, &buflen)); break; case 1: - (void) inet_ntop(AF_INET, rdata, buf, buflen); + (void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += 4; break; case 2: - (void) inet_ntop(AF_INET6, rdata, buf, buflen); + (void) inet_ntop(AF_INET6, rdata, buf, (socklen_t)buflen); addlen(strlen(buf), &buf, &buflen); rdata += 16; break; @@ -978,7 +980,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, if (rdata >= edata) break; - siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ + siz = (int)(edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ if (siz > sizeof(base64_key) * 3/4) { const char *str = "record too long to print"; T(addstr(str, strlen(str), &buf, &buflen)); @@ -1056,7 +1058,8 @@ ns_sprintrrf(const u_char *msg, size_t msglen, comment = "unknown RR type"; goto hexify; } - return (buf - obuf); + _DIAGASSERT(__type_fit(int, buf - obuf)); + return (int)(buf - obuf); formerr: comment = "RR format error"; hexify: { @@ -1070,7 +1073,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, p = tmp; p += SPRINTF((p, "\n\t")); spaced = 0; - n = MIN(16, edata - rdata); + n = MIN(16, (int)(edata - rdata)); for (m = 0; m < n; m++) p += SPRINTF((p, "%02x ", rdata[m])); T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen)); @@ -1087,7 +1090,8 @@ ns_sprintrrf(const u_char *msg, size_t msglen, T(addstr(tmp, (size_t)(p - tmp), &buf, &buflen)); rdata += n; } - return (buf - obuf); + _DIAGASSERT(__type_fit(int, buf - obuf)); + return (int)(buf - obuf); } } @@ -1163,7 +1167,8 @@ charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) { } if (addstr("\"", (size_t)1, buf, buflen) < 0) goto enospc; - return (rdata - odata); + _DIAGASSERT(__type_fit(int, rdata - odata)); + return (int)(rdata - odata); enospc: errno = ENOSPC; *buf = save_buf; @@ -1207,7 +1212,8 @@ addname(const u_char *msg, size_t msglen, *pp += n; addlen(newlen, buf, buflen); **buf = '\0'; - return (newlen); + _DIAGASSERT(__type_fit(int, newlen)); + return (int)newlen; enospc: errno = ENOSPC; *buf = save_buf; @@ -1238,7 +1244,7 @@ static int addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) { size_t save_buflen = *buflen; char *save_buf = *buf; - int t; + ptrdiff_t t; if (spaced || len >= target - 1) { T(addstr(" ", (size_t)2, buf, buflen)); diff --git a/lib/libc/nameser/ns_ttl.c b/lib/libc/nameser/ns_ttl.c index 2545ffda1..e895e5a5b 100644 --- a/lib/libc/nameser/ns_ttl.c +++ b/lib/libc/nameser/ns_ttl.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_ttl.c,v 1.7 2009/04/12 17:07:17 christos Exp $ */ +/* $NetBSD: ns_ttl.c,v 1.8 2012/03/13 21:13:39 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -22,7 +22,7 @@ #ifdef notdef static const char rcsid[] = "Id: ns_ttl.c,v 1.4 2005/07/28 06:51:49 marka Exp"; #else -__RCSID("$NetBSD: ns_ttl.c,v 1.7 2009/04/12 17:07:17 christos Exp $"); +__RCSID("$NetBSD: ns_ttl.c,v 1.8 2012/03/13 21:13:39 christos Exp $"); #endif #endif @@ -32,6 +32,7 @@ __RCSID("$NetBSD: ns_ttl.c,v 1.7 2009/04/12 17:07:17 christos Exp $"); #include +#include #include #include #include @@ -61,11 +62,11 @@ ns_format_ttl(u_long src, char *dst, size_t dstlen) { int secs, mins, hours, days, weeks, x; char *p; - secs = src % 60; src /= 60; - mins = src % 60; src /= 60; - hours = src % 24; src /= 24; - days = src % 7; src /= 7; - weeks = src; src = 0; + secs = (int)(src % 60); src /= 60; + mins = (int)(src % 60); src /= 60; + hours = (int)(src % 24); src /= 24; + days = (int)(src % 7); src /= 7; + weeks = (int)src; src = 0; x = 0; if (weeks) { @@ -97,7 +98,8 @@ ns_format_ttl(u_long src, char *dst, size_t dstlen) { *p = tolower(ch); } - return (dst - odst); + _DIAGASSERT(__type_fit(int, dst - odst)); + return (int)(dst - odst); } #ifndef _LIBC diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index 6a323067a..4b7c9e48a 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -7,28 +7,16 @@ .endif .PATH: ${ARCHDIR}/net ${.CURDIR}/net -.if defined(__MINIX) # Not supported by minix: iso_addr.c link_addr.c sockatmark.c -SRCS+= __cmsg_alignbytes.c base64.c ethers.c gethnamaddr.c getifaddrs.c \ - getnetnamadr.c getnetent.c getpeereid.c \ - getprotobyname.c getprotobynumber.c getprotoent.c \ - getprotobyname_r.c getprotobynumber_r.c getprotoent_r.c \ - getservbyname.c getservbyport.c getservent.c \ - getservbyname_r.c getservbyport_r.c getservent_r.c \ - nsdispatch.c nslexer.l nsparser.y nsap_addr.c \ - rcmd.c recv.c send.c sethostent.c -.else -SRCS+= __cmsg_alignbytes.c base64.c ethers.c gethnamaddr.c getifaddrs.c \ +SRCS+= base64.c ethers.c gethnamaddr.c getifaddrs.c \ getnetnamadr.c getnetent.c getpeereid.c \ getprotobyname.c getprotobynumber.c getprotoent.c \ getprotobyname_r.c getprotobynumber_r.c getprotoent_r.c \ getservbyname.c getservbyport.c getservent.c \ getservbyname_r.c getservbyport_r.c getservent_r.c \ - iso_addr.c linkaddr.c \ nsdispatch.c nslexer.l nsparser.y nsap_addr.c \ rcmd.c recv.c send.c sethostent.c \ - sockatmark.c -.endif +# sockatmark.c .if (${MKHESIOD} != "no") SRCS+= hesiod.c diff --git a/lib/libc/net/base64.c b/lib/libc/net/base64.c index 1868f7657..18b223abd 100644 --- a/lib/libc/net/base64.c +++ b/lib/libc/net/base64.c @@ -1,4 +1,4 @@ -/* $NetBSD: base64.c,v 1.12 2009/04/12 17:07:17 christos Exp $ */ +/* $NetBSD: base64.c,v 1.14 2012/06/25 22:32:44 abs Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -47,7 +47,7 @@ #if 0 static const char rcsid[] = "Id: base64.c,v 1.4 2005/04/27 04:56:34 sra Exp"; #else -__RCSID("$NetBSD: base64.c,v 1.12 2009/04/12 17:07:17 christos Exp $"); +__RCSID("$NetBSD: base64.c,v 1.14 2012/06/25 22:32:44 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -203,7 +203,8 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { if (datalength >= targsize) return (-1); target[datalength] = '\0'; /*%< Returned value doesn't count \\0. */ - return (datalength); + _DIAGASSERT(__type_fit(int, datalength)); + return (int)datalength; } /* skips all whitespace anywhere. @@ -213,10 +214,7 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { */ int -b64_pton(src, target, targsize) - char const *src; - u_char *target; - size_t targsize; +b64_pton(char const *src, u_char *target, size_t targsize) { size_t tarindex; int state, ch; @@ -244,7 +242,8 @@ b64_pton(src, target, targsize) if (target) { if ((size_t)tarindex >= targsize) return (-1); - target[tarindex] = (pos - Base64) << 2; + target[tarindex] = + (unsigned char)(pos - Base64) << 2; } state = 1; break; @@ -254,8 +253,9 @@ b64_pton(src, target, targsize) return (-1); target[tarindex] |= (u_int32_t)(pos - Base64) >> 4; - target[tarindex+1] = ((pos - Base64) & 0x0f) - << 4 ; + target[tarindex+1] = + (unsigned char) + (((pos - Base64) & 0x0f) << 4); } tarindex++; state = 2; @@ -266,8 +266,9 @@ b64_pton(src, target, targsize) return (-1); target[tarindex] |= (u_int32_t)(pos - Base64) >> 2; - target[tarindex+1] = ((pos - Base64) & 0x03) - << 6; + target[tarindex+1] = + (unsigned char) + (((pos - Base64) & 0x03) << 6); } tarindex++; state = 3; @@ -276,7 +277,8 @@ b64_pton(src, target, targsize) if (target) { if ((size_t)tarindex >= targsize) return (-1); - target[tarindex] |= (pos - Base64); + target[tarindex] |= + (unsigned char)(pos - Base64); } tarindex++; state = 0; @@ -337,7 +339,8 @@ b64_pton(src, target, targsize) return (-1); } - return (tarindex); + _DIAGASSERT(__type_fit(int, tarindex)); + return (int)tarindex; } /*! \file */ diff --git a/lib/libc/net/byteorder.3 b/lib/libc/net/byteorder.3 index bc52e511a..68502eb96 100644 --- a/lib/libc/net/byteorder.3 +++ b/lib/libc/net/byteorder.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: byteorder.3,v 1.14 2006/02/04 22:47:28 uwe Exp $ +.\" $NetBSD: byteorder.3,v 1.15 2011/05/03 04:07:39 jruoho Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 10, 2004 +.Dd May 3, 2011 .Dt BYTEORDER 3 .Os .Sh NAME @@ -64,23 +64,12 @@ addresses and ports as returned by and .Xr getservent 3 . .Sh SEE ALSO +.Xr bswap 3 , .Xr gethostbyname 3 , .Xr getservent 3 .Sh STANDARDS -The -.Fn htonl , -.Fn htons , -.Fn ntohl , -and -.Fn ntohs -functions conform to +The described functions conform to .St -p1003.1-2001 . -Their use of the fixed-width integer types -.Fa uint16_t -and -.Fa uint32_t -first appeared in -.St -xns5 . .Sh HISTORY The .Nm byteorder diff --git a/lib/libc/net/ethers.c b/lib/libc/net/ethers.c index 25a582c09..27d1e0a76 100644 --- a/lib/libc/net/ethers.c +++ b/lib/libc/net/ethers.c @@ -1,4 +1,4 @@ -/* $NetBSD: ethers.c,v 1.21 2006/10/15 10:55:01 martin Exp $ */ +/* $NetBSD: ethers.c,v 1.23 2012/03/20 17:44:18 matt Exp $ */ /* * ethers(3N) a la Sun. @@ -9,7 +9,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: ethers.c,v 1.21 2006/10/15 10:55:01 martin Exp $"); +__RCSID("$NetBSD: ethers.c,v 1.23 2012/03/20 17:44:18 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -44,8 +44,7 @@ __weak_alias(ether_ntohost,_ether_ntohost) #endif char * -ether_ntoa(e) - const struct ether_addr *e; +ether_ntoa(const struct ether_addr *e) { static char a[18]; @@ -59,8 +58,7 @@ ether_ntoa(e) } struct ether_addr * -ether_aton(s) - const char *s; +ether_aton(const char *s) { static struct ether_addr n; u_int i[6]; @@ -81,9 +79,7 @@ ether_aton(s) } int -ether_ntohost(hostname, e) - char *hostname; - const struct ether_addr *e; +ether_ntohost(char *hostname, const struct ether_addr *e) { FILE *f; char *p; @@ -143,16 +139,14 @@ ether_ntohost(hostname, e) } int -ether_hostton(hostname, e) - const char *hostname; - struct ether_addr *e; +ether_hostton(const char *hostname, struct ether_addr *e) { FILE *f; char *p; size_t len; char try[MAXHOSTNAMELEN + 1]; #ifdef YP - int hostlen = strlen(hostname); + int hostlen = (int)strlen(hostname); #endif _DIAGASSERT(hostname != NULL); @@ -197,10 +191,7 @@ ether_hostton(hostname, e) } int -ether_line(l, e, hostname) - const char *l; - struct ether_addr *e; - char *hostname; +ether_line(const char *l, struct ether_addr *e, char *hostname) { u_int i[6]; diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index eae831679..2a240c614 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -1,4 +1,4 @@ -/* $NetBSD: getaddrinfo.c,v 1.95 2009/10/02 07:41:08 wiz Exp $ */ +/* $NetBSD: getaddrinfo.c,v 1.101 2012/06/08 07:54:14 martin Exp $ */ /* $KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $ */ /* @@ -55,7 +55,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getaddrinfo.c,v 1.95 2009/10/02 07:41:08 wiz Exp $"); +__RCSID("$NetBSD: getaddrinfo.c,v 1.101 2012/06/08 07:54:14 martin Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -76,6 +76,7 @@ __RCSID("$NetBSD: getaddrinfo.c,v 1.95 2009/10/02 07:41:08 wiz Exp $"); #include #include #include +#include #include #include @@ -208,6 +209,7 @@ static int get_portmatch(const struct addrinfo *, const char *, static int get_port(const struct addrinfo *, const char *, int, struct servent_data *); static const struct afd *find_afd(int); +static int addrconfig(uint64_t *); #ifdef INET6 static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *); #endif @@ -330,8 +332,8 @@ str2number(const char *p) ep = NULL; errno = 0; v = strtoul(p, &ep, 10); - if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX) - return v; + if (errno == 0 && ep && *ep == '\0' && v <= INT_MAX) + return (int)v; else return -1; } @@ -348,6 +350,7 @@ getaddrinfo(const char *hostname, const char *servname, struct addrinfo *pai; const struct explore *ex; struct servent_data svd; + uint64_t mask = (uint64_t)~0ULL; /* hostname is allowed to be NULL */ /* servname is allowed to be NULL */ @@ -409,6 +412,9 @@ getaddrinfo(const char *hostname, const char *servname, } } + if ((pai->ai_flags & AI_ADDRCONFIG) != 0 && addrconfig(&mask) == -1) + ERR(EAI_FAIL); + /* * check for special cases. (1) numeric servname is disallowed if * socktype/protocol are left unspecified. (2) servname is disallowed @@ -430,7 +436,7 @@ getaddrinfo(const char *hostname, const char *servname, } error = get_portmatch(pai, servname, &svd); if (error) - ERR(error); + goto bad; *pai = ai0; } @@ -441,6 +447,10 @@ getaddrinfo(const char *hostname, const char *servname, for (ex = explore; ex->e_af >= 0; ex++) { *pai = ai0; + /* ADDRCONFIG check */ + if ((((uint64_t)1 << ex->e_af) & mask) == 0) + continue; + /* PF_UNSPEC entries are prepared for DNS queries only */ if (ex->e_af == PF_UNSPEC) continue; @@ -451,7 +461,6 @@ getaddrinfo(const char *hostname, const char *servname, continue; if (!MATCH(pai->ai_protocol, ex->e_protocol, WILD_PROTOCOL(ex))) continue; - if (pai->ai_family == PF_UNSPEC) pai->ai_family = ex->e_af; if (pai->ai_socktype == ANY && ex->e_socktype != ANY) @@ -494,6 +503,13 @@ getaddrinfo(const char *hostname, const char *servname, for (ex = explore; ex->e_af >= 0; ex++) { *pai = ai0; + + /* ADDRCONFIG check */ + /* PF_UNSPEC entries are prepared for DNS queries only */ + if (ex->e_af != PF_UNSPEC && + (((uint64_t)1 << ex->e_af) & mask) == 0) + continue; + /* require exact match for family field */ if (pai->ai_family != ex->e_af) continue; @@ -1011,6 +1027,30 @@ find_afd(int af) return NULL; } +/* + * AI_ADDRCONFIG check: Build a mask containing a bit set for each address + * family configured in the system. + * + */ +static int +addrconfig(uint64_t *mask) +{ + struct ifaddrs *ifaddrs, *ifa; + + if (getifaddrs(&ifaddrs) == -1) + return -1; + + *mask = 0; + for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) + if (ifa->ifa_addr && (ifa->ifa_flags & IFF_UP)) { + _DIAGASSERT(ifa->ifa_addr->sa_family < 64); + *mask |= (uint64_t)1 << ifa->ifa_addr->sa_family; + } + + freeifaddrs(ifaddrs); + return 0; +} + #ifdef INET6 /* convert a string to a scope identifier. XXX: IPv6 specific */ static int @@ -1117,7 +1157,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, h_errno = NO_RECOVERY; return (NULL); } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !(*name_ok)(bp)) { h_errno = NO_RECOVERY; return (NULL); @@ -1128,7 +1168,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, * same as the one we sent; this just gets the expanded name * (i.e., with the succeeding search-domain tacked on). */ - n = strlen(bp) + 1; /* for the \0 */ + n = (int)strlen(bp) + 1; /* for the \0 */ if (n >= MAXHOSTNAMELEN) { h_errno = NO_RECOVERY; return (NULL); @@ -1141,7 +1181,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, haveanswer = 0; had_error = 0; while (ancount-- > 0 && cp < eom && !had_error) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !(*name_ok)(bp)) { had_error++; continue; @@ -1160,14 +1200,14 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, } if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); + n = dn_expand(answer->buf, eom, cp, tbuf, (int)sizeof tbuf); if ((n < 0) || !(*name_ok)(tbuf)) { had_error++; continue; } cp += n; /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ + n = (int)strlen(tbuf) + 1; /* for the \0 */ if (n > ep - bp || n >= MAXHOSTNAMELEN) { had_error++; continue; @@ -1223,7 +1263,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, int nn; canonname = bp; - nn = strlen(bp) + 1; /* for the \0 */ + nn = (int)strlen(bp) + 1; /* for the \0 */ bp += nn; } @@ -1411,7 +1451,7 @@ _sethtent(FILE **hostf) { if (!*hostf) - *hostf = fopen(_PATH_HOSTS, "r" ); + *hostf = fopen(_PATH_HOSTS, "re"); else rewind(*hostf); } @@ -1439,10 +1479,10 @@ _gethtent(FILE **hostf, const char *name, const struct addrinfo *pai) _DIAGASSERT(name != NULL); _DIAGASSERT(pai != NULL); - if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "r" ))) + if (!*hostf && !(*hostf = fopen(_PATH_HOSTS, "re"))) return (NULL); again: - if (!(p = fgets(hostbuf, sizeof hostbuf, *hostf))) + if (!(p = fgets(hostbuf, (int)sizeof hostbuf, *hostf))) return (NULL); if (*p == '#') goto again; @@ -1711,10 +1751,10 @@ res_queryN(const char *name, /* domain name */ struct res_target *target, #endif n = res_nmkquery(res, QUERY, name, class, type, NULL, 0, NULL, - buf, sizeof(buf)); + buf, (int)sizeof(buf)); #ifdef RES_USE_EDNS0 if (n > 0 && (res->options & RES_USE_EDNS0) != 0) - n = res_nopt(res, n, buf, sizeof(buf), anslen); + n = res_nopt(res, n, buf, (int)sizeof(buf), anslen); #endif if (n <= 0) { #ifdef DEBUG diff --git a/lib/libc/net/gethnamaddr.c b/lib/libc/net/gethnamaddr.c index 1c3a68d24..5038df798 100644 --- a/lib/libc/net/gethnamaddr.c +++ b/lib/libc/net/gethnamaddr.c @@ -1,4 +1,4 @@ -/* $NetBSD: gethnamaddr.c,v 1.76 2010/08/29 15:40:35 christos Exp $ */ +/* $NetBSD: gethnamaddr.c,v 1.79 2012/09/09 16:42:23 christos Exp $ */ /* * ++Copyright++ 1985, 1988, 1993 @@ -57,7 +57,7 @@ static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp "; #else -__RCSID("$NetBSD: gethnamaddr.c,v 1.76 2010/08/29 15:40:35 christos Exp $"); +__RCSID("$NetBSD: gethnamaddr.c,v 1.79 2012/09/09 16:42:23 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -101,6 +101,12 @@ __weak_alias(gethostbyname,_gethostbyname) __weak_alias(gethostent,_gethostent) #endif +#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0U || \ + (ok)(nm) != 0) +#define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok) +#define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok) + + #define MAXALIASES 35 #define MAXADDRS 35 @@ -257,8 +263,8 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, h_errno = NO_RECOVERY; return NULL; } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); + if ((n < 0) || !maybe_ok(res, bp, name_ok)) { h_errno = NO_RECOVERY; return NULL; } @@ -268,7 +274,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, * same as the one we sent; this just gets the expanded name * (i.e., with the succeeding search-domain tacked on). */ - n = strlen(bp) + 1; /* for the \0 */ + n = (int)strlen(bp) + 1; /* for the \0 */ if (n >= MAXHOSTNAMELEN) { h_errno = NO_RECOVERY; return NULL; @@ -287,8 +293,8 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, haveanswer = 0; had_error = 0; while (ancount-- > 0 && cp < eom && !had_error) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); + if ((n < 0) || !maybe_ok(res, bp, name_ok)) { had_error++; continue; } @@ -310,8 +316,8 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { if (ap >= &host_aliases[MAXALIASES-1]) continue; - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if ((n < 0) || !(*name_ok)(tbuf)) { + n = dn_expand(answer->buf, eom, cp, tbuf, (int)sizeof tbuf); + if ((n < 0) || !maybe_ok(res, tbuf, name_ok)) { had_error++; continue; } @@ -322,14 +328,14 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, } /* Store alias. */ *ap++ = bp; - n = strlen(bp) + 1; /* for the \0 */ + n = (int)strlen(bp) + 1; /* for the \0 */ if (n >= MAXHOSTNAMELEN) { had_error++; continue; } bp += n; /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ + n = (int)strlen(tbuf) + 1; /* for the \0 */ if (n > ep - bp || n >= MAXHOSTNAMELEN) { had_error++; continue; @@ -340,8 +346,8 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, continue; } if (qtype == T_PTR && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if (n < 0 || !res_dnok(tbuf)) { + n = dn_expand(answer->buf, eom, cp, tbuf, (int)sizeof tbuf); + if (n < 0 || !maybe_dnok(res, tbuf)) { had_error++; continue; } @@ -351,7 +357,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, return NULL; } /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ + n = (int)strlen(tbuf) + 1; /* for the \0 */ if (n > ep - bp || n >= MAXHOSTNAMELEN) { had_error++; continue; @@ -378,8 +384,8 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, cp += n; continue; /* XXX - had_error++ ? */ } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !res_hnok(bp)) { + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); + if ((n < 0) || !maybe_hnok(res, bp)) { had_error++; break; } @@ -396,7 +402,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, else n = -1; if (n != -1) { - n = strlen(bp) + 1; /* for the \0 */ + n = (int)strlen(bp) + 1; /* for the \0 */ if (n >= MAXHOSTNAMELEN) { had_error++; break; @@ -442,7 +448,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, int nn; host.h_name = bp; - nn = strlen(bp) + 1; /* for the \0 */ + nn = (int)strlen(bp) + 1; /* for the \0 */ bp += nn; } @@ -487,7 +493,7 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, if (res->nsort && haveanswer > 1 && qtype == T_A) addrsort(h_addr_ptrs, haveanswer, res); if (!host.h_name) { - n = strlen(qname) + 1; /* for the \0 */ + n = (int)strlen(qname) + 1; /* for the \0 */ if (n > ep - bp || n >= MAXHOSTNAMELEN) goto no_recovery; strlcpy(bp, qname, (size_t)(ep - bp)); @@ -720,7 +726,7 @@ void _sethtent(int f) { if (!hostf) - hostf = fopen(_PATH_HOSTS, "r" ); + hostf = fopen(_PATH_HOSTS, "re"); else rewind(hostf); stayopen = f; @@ -742,12 +748,12 @@ _gethtent(void) char *cp, **q; int af, len; - if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) { + if (!hostf && !(hostf = fopen(_PATH_HOSTS, "re"))) { h_errno = NETDB_INTERNAL; return NULL; } again: - if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) { + if (!(p = fgets(hostbuf, (int)sizeof hostbuf, hostf))) { h_errno = HOST_NOT_FOUND; return NULL; } @@ -1002,7 +1008,8 @@ map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep) hp->h_addrtype = AF_INET6; hp->h_length = IN6ADDRSZ; for (ap = hp->h_addr_list; *ap; ap++) { - int i = sizeof(align) - (size_t)((u_long)*bpp % sizeof(align)); + int i = (int)(sizeof(align) - + (size_t)((u_long)*bpp % sizeof(align))); if (ep - *bpp < (i + IN6ADDRSZ)) { /* Out of memory. Truncate address list here. XXX */ @@ -1104,7 +1111,7 @@ _dns_gethtbyname(void *rv, void *cb_data, va_list ap) free(buf); return NS_NOTFOUND; } - n = res_nsearch(res, name, C_IN, type, buf->buf, sizeof(buf->buf)); + n = res_nsearch(res, name, C_IN, type, buf->buf, (int)sizeof(buf->buf)); if (n < 0) { free(buf); debugprintf("res_nsearch failed (%d)\n", res, n); @@ -1185,7 +1192,7 @@ _dns_gethtbyaddr(void *rv, void *cb_data, va_list ap) free(buf); return NS_NOTFOUND; } - n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf)); + n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int)sizeof(buf->buf)); if (n < 0) { free(buf); debugprintf("res_nquery failed (%d)\n", res, n); @@ -1370,7 +1377,7 @@ _yp_gethtbyaddr(void *rv, void *cb_data, va_list ap) * XXX unfortunately, we cannot support IPv6 extended scoped address * notation here. gethostbyaddr() is not scope-aware. too bad. */ - if (inet_ntop(af, uaddr, name, sizeof(name)) == NULL) + if (inet_ntop(af, uaddr, name, (socklen_t)sizeof(name)) == NULL) return NS_UNAVAIL; if (__ypcurrent) free(__ypcurrent); diff --git a/lib/libc/net/getifaddrs.c b/lib/libc/net/getifaddrs.c deleted file mode 100644 index 7fde5aba7..000000000 --- a/lib/libc/net/getifaddrs.c +++ /dev/null @@ -1,305 +0,0 @@ -/* $NetBSD: getifaddrs.c,v 1.13 2010/11/05 16:23:56 pooka Exp $ */ - -/* - * Copyright (c) 1995, 1999 - * Berkeley Software Design, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * BSDI getifaddrs.c,v 2.12 2000/02/23 14:51:59 dab Exp - */ - -#include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getifaddrs.c,v 1.13 2010/11/05 16:23:56 pooka Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#ifndef RUMP_ACTION -#include "namespace.h" -#endif -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#if defined(__weak_alias) && !defined(RUMP_ACTION) -__weak_alias(getifaddrs,_getifaddrs) -__weak_alias(freeifaddrs,_freeifaddrs) -#endif - -#ifdef RUMP_ACTION -#include -#define sysctl(a,b,c,d,e,f) rump_sys___sysctl(a,b,c,d,e,f) -#endif - -#define SALIGN (sizeof(long) - 1) -#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : (SALIGN + 1)) - -int -getifaddrs(struct ifaddrs **pif) -{ - int icnt = 1; - int dcnt = 0; - int ncnt = 0; - int mib[6]; - size_t needed; - char *buf; - char *next; - struct ifaddrs cif; - char *p, *p0; - struct rt_msghdr *rtm; - struct if_msghdr *ifm; - struct ifa_msghdr *ifam; - struct sockaddr *sa; - struct ifaddrs *ifa, *ift; - u_short idx = 0; - int i; - size_t len, alen; - char *data; - char *names; - - _DIAGASSERT(pif != NULL); - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; /* protocol */ - mib[3] = 0; /* wildcard address family */ - mib[4] = NET_RT_IFLIST; - mib[5] = 0; /* no flags */ - if (sysctl(mib, __arraycount(mib), NULL, &needed, NULL, 0) < 0) - return (-1); - if ((buf = malloc(needed)) == NULL) - return (-1); - if (sysctl(mib, __arraycount(mib), buf, &needed, NULL, 0) < 0) { - free(buf); - return (-1); - } - - for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)(void *)next; - if (rtm->rtm_version != RTM_VERSION) - continue; - switch (rtm->rtm_type) { - case RTM_IFINFO: - ifm = (struct if_msghdr *)(void *)rtm; - if (ifm->ifm_addrs & RTA_IFP) { - const struct sockaddr_dl *dl; - - idx = ifm->ifm_index; - ++icnt; - dl = (struct sockaddr_dl *)(void *)(ifm + 1); - dcnt += SA_RLEN((const struct sockaddr *)(const void *)dl) + - ALIGNBYTES; - dcnt += sizeof(ifm->ifm_data); - ncnt += dl->sdl_nlen + 1; - } else - idx = 0; - break; - - case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)(void *)rtm; - if (idx && ifam->ifam_index != idx) - abort(); /* this cannot happen */ - -#define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD) - if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) - break; - p = (char *)(void *)(ifam + 1); - ++icnt; - /* Scan to look for length of address */ - alen = 0; - for (p0 = p, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)(void *)p; - len = SA_RLEN(sa); - if (i == RTAX_IFA) { - alen = len; - break; - } - p += len; - } - for (p = p0, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)(void *)p; - len = SA_RLEN(sa); - if (i == RTAX_NETMASK && sa->sa_len == 0) - dcnt += alen; - else - dcnt += len; - p += len; - } - break; - } - } - - if (icnt + dcnt + ncnt == 1) { - *pif = NULL; - free(buf); - return (0); - } - data = malloc(sizeof(struct ifaddrs) * icnt + dcnt + ncnt); - if (data == NULL) { - free(buf); - return(-1); - } - - ifa = (struct ifaddrs *)(void *)data; - data += sizeof(struct ifaddrs) * icnt; - names = data + dcnt; - - memset(ifa, 0, sizeof(struct ifaddrs) * icnt); - ift = ifa; - - idx = 0; - for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)(void *)next; - if (rtm->rtm_version != RTM_VERSION) - continue; - switch (rtm->rtm_type) { - case RTM_IFINFO: - ifm = (struct if_msghdr *)(void *)rtm; - if (ifm->ifm_addrs & RTA_IFP) { - const struct sockaddr_dl *dl; - - idx = ifm->ifm_index; - dl = (struct sockaddr_dl *)(void *)(ifm + 1); - - memset(&cif, 0, sizeof(cif)); - - cif.ifa_name = names; - cif.ifa_flags = (int)ifm->ifm_flags; - memcpy(names, dl->sdl_data, - (size_t)dl->sdl_nlen); - names[dl->sdl_nlen] = 0; - names += dl->sdl_nlen + 1; - - cif.ifa_addr = (struct sockaddr *)(void *)data; - memcpy(data, dl, (size_t)dl->sdl_len); - data += SA_RLEN((const struct sockaddr *)(const void *)dl); - - /* ifm_data needs to be aligned */ - cif.ifa_data = data = (void *)ALIGN(data); - memcpy(data, &ifm->ifm_data, sizeof(ifm->ifm_data)); - data += sizeof(ifm->ifm_data); - } else - idx = 0; - break; - - case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)(void *)rtm; - if (idx && ifam->ifam_index != idx) - abort(); /* this cannot happen */ - - if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) - break; - ift->ifa_name = cif.ifa_name; - ift->ifa_flags = cif.ifa_flags; - ift->ifa_data = NULL; - p = (char *)(void *)(ifam + 1); - /* Scan to look for length of address */ - alen = 0; - for (p0 = p, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)(void *)p; - len = SA_RLEN(sa); - if (i == RTAX_IFA) { - alen = len; - break; - } - p += len; - } - for (p = p0, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)(void *)p; - len = SA_RLEN(sa); - switch (i) { - case RTAX_IFA: - ift->ifa_addr = - (struct sockaddr *)(void *)data; - memcpy(data, p, len); - data += len; - if (ift->ifa_addr->sa_family == AF_LINK) - ift->ifa_data = cif.ifa_data; - break; - - case RTAX_NETMASK: - ift->ifa_netmask = - (struct sockaddr *)(void *)data; - if (sa->sa_len == 0) { - memset(data, 0, alen); - data += alen; - break; - } - memcpy(data, p, len); - data += len; - break; - - case RTAX_BRD: - ift->ifa_broadaddr = - (struct sockaddr *)(void *)data; - memcpy(data, p, len); - data += len; - break; - } - p += len; - } - - - ift = (ift->ifa_next = ift + 1); - break; - } - } - - free(buf); - if (--ift >= ifa) { - ift->ifa_next = NULL; - *pif = ifa; - } else { - *pif = NULL; - free(ifa); - } - return (0); -} - -void -freeifaddrs(struct ifaddrs *ifp) -{ - - _DIAGASSERT(ifp != NULL); - - free(ifp); -} diff --git a/lib/libc/net/getnameinfo.3 b/lib/libc/net/getnameinfo.3 index 5cd3539f1..c1b30afaa 100644 --- a/lib/libc/net/getnameinfo.3 +++ b/lib/libc/net/getnameinfo.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getnameinfo.3,v 1.37 2010/03/22 19:30:54 joerg Exp $ +.\" $NetBSD: getnameinfo.3,v 1.39 2012/09/26 23:13:00 christos Exp $ .\" $KAME: getnameinfo.3,v 1.37 2005/01/05 03:23:05 itojun Exp $ .\" $OpenBSD: getnameinfo.3,v 1.36 2004/12/21 09:48:20 jmc Exp $ .\" @@ -17,7 +17,7 @@ .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR .\" PERFORMANCE OF THIS SOFTWARE. .\" -.Dd March 21, 2005 +.Dd September 26, 2012 .Dt GETNAMEINFO 3 .Os .Sh NAME @@ -27,8 +27,8 @@ .In netdb.h .Ft int .Fn getnameinfo "const struct sockaddr * restrict sa" "socklen_t salen" \ - "char * restrict host" "size_t hostlen" "char * restrict serv" \ - "size_t servlen" "int flags" + "char * restrict host" "socklen_t hostlen" "char * restrict serv" \ + "socklen_t servlen" "int flags" .Sh DESCRIPTION The .Fn getnameinfo @@ -47,11 +47,19 @@ The .Li sockaddr structure .Fa sa -should point to either a +should point to a .Li sockaddr_in -or +(for IPv4), .Li sockaddr_in6 -structure (for IPv4 or IPv6 respectively) that is +(for IPv6), +.Li sockaddr_atalk +(for AppleTalk), +.Li sockaddr_link +(for link layer), +or +.Li sockaddr_local +(for local/unix) +structures that are .Fa salen bytes long. .Pp diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c index 7e1e8aeb7..7234dd250 100644 --- a/lib/libc/net/getnameinfo.c +++ b/lib/libc/net/getnameinfo.c @@ -1,4 +1,4 @@ -/* $NetBSD: getnameinfo.c,v 1.50 2010/06/29 14:44:19 seanb Exp $ */ +/* $NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $ */ /* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ /* @@ -47,12 +47,13 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getnameinfo.c,v 1.50 2010/06/29 14:44:19 seanb Exp $"); +__RCSID("$NetBSD: getnameinfo.c,v 1.53 2012/09/26 23:13:00 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include #include +#include #include #ifndef __minix #include @@ -97,21 +98,22 @@ struct sockinet { u_short si_port; }; -static int getnameinfo_inet __P((const struct sockaddr *, socklen_t, char *, - socklen_t, char *, socklen_t, int)); +static int getnameinfo_inet(const struct sockaddr *, socklen_t, char *, + socklen_t, char *, socklen_t, int); #ifdef INET6 -static int ip6_parsenumeric __P((const struct sockaddr *, const char *, char *, - socklen_t, int)); -static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, - int)); +static int ip6_parsenumeric(const struct sockaddr *, const char *, char *, + socklen_t, int); +static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int); #endif #ifndef __minix -static int getnameinfo_atalk __P((const struct sockaddr *, socklen_t, char *, - socklen_t, char *, socklen_t, int)); - -static int getnameinfo_link __P((const struct sockaddr *, socklen_t, char *, - socklen_t, char *, socklen_t, int)); -static int hexname __P((const u_int8_t *, size_t, char *, socklen_t)); +static int getnameinfo_atalk(const struct sockaddr *, socklen_t, char *, + socklen_t, char *, socklen_t, int); +static int getnameinfo_local(const struct sockaddr *, socklen_t, char *, + socklen_t, char *, socklen_t, int); + +static int getnameinfo_link(const struct sockaddr *, socklen_t, char *, + socklen_t, char *, socklen_t, int); +static int hexname(const uint8_t *, size_t, char *, socklen_t); #endif /* __minix */ /* @@ -119,12 +121,10 @@ static int hexname __P((const u_int8_t *, size_t, char *, socklen_t)); * appropriate function to call. */ int -getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) - const struct sockaddr *sa; - socklen_t salen; - char *host, *serv; - socklen_t hostlen, servlen; - int flags; +getnameinfo(const struct sockaddr *sa, socklen_t salen, + char *host, socklen_t hostlen, + char *serv, socklen_t servlen, + int flags) { switch (sa->sa_family) { @@ -141,6 +141,9 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) case AF_LINK: return getnameinfo_link(sa, salen, host, hostlen, serv, servlen, flags); + case AF_LOCAL: + return getnameinfo_local(sa, salen, host, hostlen, + serv, servlen, flags); #endif /* !__minix */ default: return EAI_FAMILY; @@ -207,6 +210,29 @@ errout: return EAI_MEMORY; } + +/* + * getnameinfo_local(): + * Format an local address into a printable format. + */ +/* ARGSUSED */ +static int +getnameinfo_local(const struct sockaddr *sa, socklen_t salen, + char *host, socklen_t hostlen, char *serv, socklen_t servlen, + int flags) +{ + const struct sockaddr_un *sun = + (const struct sockaddr_un *)(const void *)sa; + + if (serv != NULL && servlen > 0) + serv[0] = '\0'; + + if (host && hostlen > 0) + strlcpy(host, sun->sun_path, + MIN(sizeof(sun->sun_path) + 1, hostlen)); + + return 0; +} #endif /* !__minix */ /* @@ -214,14 +240,10 @@ errout: * Format an IPv4 or IPv6 sockaddr into a printable string. */ static int -getnameinfo_inet(sa, salen, host, hostlen, serv, servlen, flags) - const struct sockaddr *sa; - socklen_t salen; - char *host; - socklen_t hostlen; - char *serv; - socklen_t servlen; - int flags; +getnameinfo_inet(const struct sockaddr *sa, socklen_t salen, + char *host, socklen_t hostlen, + char *serv, socklen_t servlen, + int flags) { const struct afd *afd; struct servent *sp; @@ -229,7 +251,7 @@ getnameinfo_inet(sa, salen, host, hostlen, serv, servlen, flags) u_short port; int family, i; const char *addr; - u_int32_t v4a; + uint32_t v4a; char numserv[512]; char numaddr[512]; @@ -291,7 +313,7 @@ getnameinfo_inet(sa, salen, host, hostlen, serv, servlen, flags) switch (sa->sa_family) { case AF_INET: - v4a = (u_int32_t) + v4a = (uint32_t) ntohl(((const struct sockaddr_in *) (const void *)sa)->sin_addr.s_addr); if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a)) @@ -353,8 +375,8 @@ getnameinfo_inet(sa, salen, host, hostlen, serv, servlen, flags) } #endif default: - if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) - == NULL) + if (inet_ntop(afd->a_af, addr, numaddr, + (socklen_t)sizeof(numaddr)) == NULL) return EAI_SYSTEM; numaddrlen = strlen(numaddr); if (numaddrlen + 1 > hostlen) /* don't forget terminator */ @@ -411,12 +433,8 @@ getnameinfo_inet(sa, salen, host, hostlen, serv, servlen, flags) #ifdef INET6 static int -ip6_parsenumeric(sa, addr, host, hostlen, flags) - const struct sockaddr *sa; - const char *addr; - char *host; - socklen_t hostlen; - int flags; +ip6_parsenumeric(const struct sockaddr *sa, const char *addr, char *host, + socklen_t hostlen, int flags) { size_t numaddrlen; char numaddr[512]; @@ -425,7 +443,8 @@ ip6_parsenumeric(sa, addr, host, hostlen, flags) _DIAGASSERT(addr != NULL); _DIAGASSERT(host != NULL); - if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL) + if (inet_ntop(AF_INET6, addr, numaddr, (socklen_t)sizeof(numaddr)) + == NULL) return EAI_SYSTEM; numaddrlen = strlen(numaddr); @@ -456,11 +475,7 @@ ip6_parsenumeric(sa, addr, host, hostlen, flags) /* ARGSUSED */ static int -ip6_sa2str(sa6, buf, bufsiz, flags) - const struct sockaddr_in6 *sa6; - char *buf; - size_t bufsiz; - int flags; +ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, size_t bufsiz, int flags) { unsigned int ifindex; const struct in6_addr *a6; @@ -487,7 +502,7 @@ ip6_sa2str(sa6, buf, bufsiz, flags) bufsiz >= IF_NAMESIZE) { char *p = if_indextoname(ifindex, buf); if (p) { - return(strlen(p)); + return (int)strlen(p); } } @@ -575,17 +590,13 @@ getnameinfo_link(const struct sockaddr *sa, socklen_t salen, case IFT_HIPPI: case IFT_ISO88025: default: - return hexname((const u_int8_t *)CLLADDR(sdl), + return hexname((const uint8_t *)CLLADDR(sdl), (size_t)sdl->sdl_alen, host, hostlen); } } static int -hexname(cp, len, host, hostlen) - const u_int8_t *cp; - char *host; - size_t len; - socklen_t hostlen; +hexname(const uint8_t *cp, size_t len, char *host, socklen_t hostlen) { int n; size_t i; diff --git a/lib/libc/net/getnetent.c b/lib/libc/net/getnetent.c index f685f32d2..b777d49ac 100644 --- a/lib/libc/net/getnetent.c +++ b/lib/libc/net/getnetent.c @@ -1,4 +1,4 @@ -/* $NetBSD: getnetent.c,v 1.18 2007/01/27 22:27:35 christos Exp $ */ +/* $NetBSD: getnetent.c,v 1.21 2012/03/20 17:44:18 matt Exp $ */ /* * Copyright (c) 1983, 1993 @@ -44,7 +44,7 @@ static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "Id: getnetent.c,v 8.4 1997/06/01 20:34:37 vixie Exp "; #else -__RCSID("$NetBSD: getnetent.c,v 1.18 2007/01/27 22:27:35 christos Exp $"); +__RCSID("$NetBSD: getnetent.c,v 1.21 2012/03/20 17:44:18 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -71,12 +71,11 @@ static struct netent net; static char *net_aliases[MAXALIASES]; int _net_stayopen; -static void __setnetent __P((int)); -static void __endnetent __P((void)); +static void __setnetent(int); +static void __endnetent(void); void -setnetent(stayopen) - int stayopen; +setnetent(int stayopen) { sethostent(stayopen); @@ -84,7 +83,7 @@ setnetent(stayopen) } void -endnetent() +endnetent(void) { endhostent(); @@ -92,19 +91,18 @@ endnetent() } static void -__setnetent(f) - int f; +__setnetent(int f) { if (netf == NULL) - netf = fopen(_PATH_NETWORKS, "r" ); + netf = fopen(_PATH_NETWORKS, "re"); else rewind(netf); _net_stayopen |= f; } static void -__endnetent() +__endnetent(void) { if (netf) { @@ -115,12 +113,12 @@ __endnetent() } struct netent * -getnetent() +getnetent(void) { char *p; register char *cp, **q; - if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) + if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "re")) == NULL) return (NULL); #if (defined(__sparc__) && defined(_LP64)) || \ defined(__alpha__) || \ @@ -129,7 +127,7 @@ getnetent() net.__n_pad0 = 0; #endif again: - p = fgets(line, sizeof line, netf); + p = fgets(line, (int)sizeof line, netf); if (p == NULL) return (NULL); if (*p == '#') diff --git a/lib/libc/net/getnetnamadr.c b/lib/libc/net/getnetnamadr.c index ef2e48fab..c3241c7c7 100644 --- a/lib/libc/net/getnetnamadr.c +++ b/lib/libc/net/getnetnamadr.c @@ -1,4 +1,4 @@ -/* $NetBSD: getnetnamadr.c,v 1.41 2008/05/18 22:36:15 lukem Exp $ */ +/* $NetBSD: getnetnamadr.c,v 1.42 2012/03/13 21:13:41 christos Exp $ */ /* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro * Dep. Matematica Universidade de Coimbra, Portugal, Europe @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; static char rcsid[] = "Id: getnetnamadr.c,v 8.8 1997/06/01 20:34:37 vixie Exp "; #else -__RCSID("$NetBSD: getnetnamadr.c,v 1.41 2008/05/18 22:36:15 lukem Exp $"); +__RCSID("$NetBSD: getnetnamadr.c,v 1.42 2012/03/13 21:13:41 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -153,7 +153,7 @@ parse_reversed_addr(const char *str, in_addr_t *result) /* build result from octets in reverse */ for (octidx = 3; octidx >= 0; octidx--) { *result <<= 8; - *result |= (octet[octidx] & 0xff); + *result |= (in_addr_t)(octet[octidx] & 0xff); } return 0; } @@ -215,7 +215,7 @@ getnetanswer(querybuf *answer, int anslen, int net_i) haveanswer = 0; n_name[0] = '\0'; while (--ancount >= 0 && cp < eom) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !res_dnok(bp)) break; cp += n; @@ -225,7 +225,7 @@ getnetanswer(querybuf *answer, int anslen, int net_i) cp += INT32SZ; /* TTL */ GETSHORT(n, cp); if (class == C_IN && type == T_PTR) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); + n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp)); if ((n < 0) || !res_hnok(bp)) { cp += n; return NULL; @@ -347,7 +347,8 @@ _dns_getnetbyaddr(void *cbrv, void *cbdata, va_list ap) free(buf); return NS_NOTFOUND; } - anslen = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, sizeof(buf->buf)); + anslen = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, + (int)sizeof(buf->buf)); if (anslen < 0) { free(buf); #ifdef DEBUG @@ -459,7 +460,7 @@ _dns_getnetbyname(void *cbrv, void *cbdata, va_list ap) return NS_NOTFOUND; } anslen = res_nsearch(res, qbuf, C_IN, T_PTR, buf->buf, - sizeof(buf->buf)); + (int)sizeof(buf->buf)); if (anslen < 0) { free(buf); #ifdef DEBUG diff --git a/lib/libc/net/getprotoent.3 b/lib/libc/net/getprotoent.3 index 8b8d693c7..44a3d5758 100644 --- a/lib/libc/net/getprotoent.3 +++ b/lib/libc/net/getprotoent.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getprotoent.3,v 1.11 2003/08/07 16:43:09 agc Exp $ +.\" $NetBSD: getprotoent.3,v 1.13 2011/07/14 22:12:30 wiz Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getprotoent.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 4, 1993 +.Dd July 15, 2011 .Dt GETPROTOENT 3 .Os .Sh NAME @@ -49,8 +49,10 @@ .Fn getprotobyname "const char *name" .Ft struct protoent * .Fn getprotobynumber "int proto" +.Ft void .Fn setprotoent "int stayopen" -.Fn endprotoent +.Ft void +.Fn endprotoent "void" .Sh DESCRIPTION The .Fn getprotoent , @@ -73,7 +75,7 @@ struct protoent { .Ed .Pp The members of this structure are: -.Bl -tag -width p_aliases +.Bl -tag -width p_aliases -offset indent .It Fa p_name The official name of the protocol. .It Fa p_aliases @@ -90,7 +92,8 @@ reads the next line of the file, opening the file if necessary. The .Fn setprotoent function -opens and rewinds the file. If the +opens and rewinds the file. +If the .Fa stayopen flag is non-zero, the net data base will not be closed after each call to @@ -116,8 +119,17 @@ or until .Dv EOF is encountered. .Sh RETURN VALUES -Null pointer -(0) returned on +Upon success, +.Fn getprotoent , +.Fn getprotobyname , +and +.Fn getprotobynumber +return a pointer to the +.Vt protoent +structure as described above. +A +.Dv NULL +pointer is returned on .Dv EOF or error. .Sh FILES diff --git a/lib/libc/net/getprotoent_r.c b/lib/libc/net/getprotoent_r.c index 01b0891c9..deae55075 100644 --- a/lib/libc/net/getprotoent_r.c +++ b/lib/libc/net/getprotoent_r.c @@ -1,4 +1,4 @@ -/* $NetBSD: getprotoent_r.c,v 1.5 2005/04/18 19:39:45 kleink Exp $ */ +/* $NetBSD: getprotoent_r.c,v 1.6 2011/10/15 23:00:02 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getprotoent.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getprotoent_r.c,v 1.5 2005/04/18 19:39:45 kleink Exp $"); +__RCSID("$NetBSD: getprotoent_r.c,v 1.6 2011/10/15 23:00:02 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -57,7 +57,7 @@ void setprotoent_r(int f, struct protoent_data *pd) { if (pd->fp == NULL) - pd->fp = fopen(_PATH_PROTOCOLS, "r"); + pd->fp = fopen(_PATH_PROTOCOLS, "re"); else rewind(pd->fp); pd->stayopen |= f; @@ -89,7 +89,7 @@ getprotoent_r(struct protoent *pr, struct protoent_data *pd) size_t i = 0; int oerrno; - if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "r")) == NULL) + if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "re")) == NULL) return NULL; for (;;) { diff --git a/lib/libc/net/getservbyname_r.c b/lib/libc/net/getservbyname_r.c index 62ee2dec4..35d6e4099 100644 --- a/lib/libc/net/getservbyname_r.c +++ b/lib/libc/net/getservbyname_r.c @@ -1,4 +1,4 @@ -/* $NetBSD: getservbyname_r.c,v 1.7 2010/04/25 00:54:46 joerg Exp $ */ +/* $NetBSD: getservbyname_r.c,v 1.9 2012/03/13 21:13:41 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getservbyname_r.c,v 1.7 2010/04/25 00:54:46 joerg Exp $"); +__RCSID("$NetBSD: getservbyname_r.c,v 1.9 2012/03/13 21:13:41 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -69,15 +69,17 @@ _servent_getbyname(struct servent_data *sd, struct servent *sp, namelen = strlen(name); if (namelen == 0 || namelen > 255) return NULL; - if (proto != NULL && *proto == '\0') - return NULL; - if (proto != NULL) + if (proto != NULL) { protolen = strlen(proto); - else + if (protolen == 0 || protolen > 255) + return NULL; + } else protolen = 0; + if (namelen + protolen > 255) + return NULL; - buf[0] = namelen; - buf[1] = protolen; + buf[0] = (uint8_t)namelen; + buf[1] = (uint8_t)protolen; memcpy(buf + 2, name, namelen); memcpy(buf + 2 + namelen, proto, protolen); diff --git a/lib/libc/net/getservbyport_r.c b/lib/libc/net/getservbyport_r.c index e5b7ea640..3d8f365c3 100644 --- a/lib/libc/net/getservbyport_r.c +++ b/lib/libc/net/getservbyport_r.c @@ -1,4 +1,4 @@ -/* $NetBSD: getservbyport_r.c,v 1.7 2010/04/25 00:54:46 joerg Exp $ */ +/* $NetBSD: getservbyport_r.c,v 1.9 2012/03/13 21:13:41 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getservbyport.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getservbyport_r.c,v 1.7 2010/04/25 00:54:46 joerg Exp $"); +__RCSID("$NetBSD: getservbyport_r.c,v 1.9 2012/03/13 21:13:41 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -67,17 +67,17 @@ _servent_getbyport(struct servent_data *sd, struct servent *sp, int port, port = be16toh(port); - if (proto != NULL && *proto == '\0') - return NULL; - if (proto != NULL) + if (proto != NULL) { protolen = strlen(proto); - else + if (protolen == 0 || protolen > 255) + return NULL; + } else protolen = 0; if (port < 0 || port > 65536) return NULL; buf[0] = 0; - buf[1] = protolen; + buf[1] = (uint8_t)protolen; be16enc(buf + 2, port); memcpy(buf + 4, proto, protolen); diff --git a/lib/libc/net/getservent_r.c b/lib/libc/net/getservent_r.c index 22da50f7b..fc2ca212e 100644 --- a/lib/libc/net/getservent_r.c +++ b/lib/libc/net/getservent_r.c @@ -1,4 +1,4 @@ -/* $NetBSD: getservent_r.c,v 1.10 2010/04/25 00:54:46 joerg Exp $ */ +/* $NetBSD: getservent_r.c,v 1.11 2011/10/15 23:00:02 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getservent_r.c,v 1.10 2010/04/25 00:54:46 joerg Exp $"); +__RCSID("$NetBSD: getservent_r.c,v 1.11 2011/10/15 23:00:02 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -79,7 +79,7 @@ _servent_open(struct servent_data *sd) return 0; } - sd->plainfile = fopen(_PATH_SERVICES, "r"); + sd->plainfile = fopen(_PATH_SERVICES, "re"); if (sd->plainfile != NULL) { sd->flags |= _SV_PLAINFILE; return 0; diff --git a/lib/libc/net/hesiod.c b/lib/libc/net/hesiod.c index 2e7fb9827..9663e45ee 100644 --- a/lib/libc/net/hesiod.c +++ b/lib/libc/net/hesiod.c @@ -1,4 +1,4 @@ -/* $NetBSD: hesiod.c,v 1.25 2011/01/05 00:09:43 wiz Exp $ */ +/* $NetBSD: hesiod.c,v 1.27 2012/03/20 17:44:18 matt Exp $ */ /* Copyright (c) 1996 by Internet Software Consortium. * @@ -51,7 +51,7 @@ __IDSTRING(rcsid_hesiod_p_h, "#Id: hesiod_p.h,v 1.1 1996/12/08 21:39:37 ghudson Exp #"); __IDSTRING(rcsid_hescompat_c, "#Id: hescompat.c,v 1.1.2.1 1996/12/16 08:37:45 ghudson Exp #"); -__RCSID("$NetBSD: hesiod.c,v 1.25 2011/01/05 00:09:43 wiz Exp $"); +__RCSID("$NetBSD: hesiod.c,v 1.27 2012/03/20 17:44:18 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -92,10 +92,10 @@ struct hesiod_p { #define MAX_HESRESP 1024 -static int read_config_file __P((struct hesiod_p *, const char *)); -static char **get_txt_records __P((int, const char *)); -static int init_context __P((void)); -static void translate_errors __P((void)); +static int read_config_file(struct hesiod_p *, const char *); +static char **get_txt_records(int, const char *); +static int init_context(void); +static void translate_errors(void); /* @@ -103,8 +103,7 @@ static void translate_errors __P((void)); * initialize a hesiod_p. */ int -hesiod_init(context) - void **context; +hesiod_init(void **context) { struct hesiod_p *ctx; const char *p, *configname; @@ -168,8 +167,7 @@ hesiod_init(context) * Deallocates the hesiod_p. */ void -hesiod_end(context) - void *context; +hesiod_end(void *context) { struct hesiod_p *ctx = (struct hesiod_p *) context; @@ -265,10 +263,7 @@ hesiod_to_bind(void *context, const char *name, const char *type) * by the resolver. */ char ** -hesiod_resolve(context, name, type) - void *context; - const char *name; - const char *type; +hesiod_resolve(void *context, const char *name, const char *type) { struct hesiod_p *ctx = (struct hesiod_p *) context; char *bindname, **retvec; @@ -291,9 +286,7 @@ hesiod_resolve(context, name, type) /*ARGSUSED*/ void -hesiod_free_list(context, list) - void *context; - char **list; +hesiod_free_list(void *context, char **list) { char **p; @@ -313,12 +306,9 @@ hesiod_free_list(context, list) * or ctx->rhs which need to be freed by the caller. */ static int -read_config_file(ctx, filename) - struct hesiod_p *ctx; - const char *filename; +read_config_file(struct hesiod_p *ctx, const char *filename) { - char *key, *data, *p, **which; - char buf[MAXDNAME + 7]; + char *buf, *key, *data, *p, **which; int n; FILE *fp; @@ -344,10 +334,9 @@ read_config_file(ctx, filename) } ctx->lhs = NULL; ctx->rhs = NULL; - while (fgets(buf, sizeof(buf), fp) != NULL) { + for (; (buf = fparseln(fp, NULL, NULL, NULL, FPARSELN_UNESCALL)) + != NULL; free(buf)) { p = buf; - if (*p == '#' || *p == '\n' || *p == '\r') - continue; while (*p == ' ' || *p == '\t') p++; key = p; @@ -378,6 +367,7 @@ read_config_file(ctx, filename) *which = strdup(data); if (!*which) { errno = ENOMEM; + free(buf); (void)fclose(fp); return -1; } @@ -419,9 +409,7 @@ read_config_file(ctx, filename) * return a list of them. */ static char ** -get_txt_records(qclass, name) - int qclass; - const char *name; +get_txt_records(int qclass, const char *name) { HEADER *hp; unsigned char qbuf[PACKETSZ], abuf[MAX_HESRESP], *p, *eom, *eor; @@ -551,16 +539,14 @@ static void *context; static int errval = HES_ER_UNINIT; int -hes_init() +hes_init(void) { init_context(); return errval; } char * -hes_to_bind(name, type) - const char *name; - const char *type; +hes_to_bind(const char *name, const char *type) { static char *bindname; @@ -578,9 +564,7 @@ hes_to_bind(name, type) } char ** -hes_resolve(name, type) - const char *name; - const char *type; +hes_resolve(const char *name, const char *type) { static char **list; @@ -604,20 +588,19 @@ hes_resolve(name, type) } int -hes_error() +hes_error(void) { return errval; } void -hes_free(hp) - char **hp; +hes_free(char **hp) { hesiod_free_list(context, hp); } static int -init_context() +init_context(void) { if (!inited) { inited = 1; @@ -631,7 +614,7 @@ init_context() } static void -translate_errors() +translate_errors(void) { switch (errno) { case ENOENT: diff --git a/lib/libc/net/if_nameindex.c b/lib/libc/net/if_nameindex.c index 2be5a28b6..fdc2731cf 100644 --- a/lib/libc/net/if_nameindex.c +++ b/lib/libc/net/if_nameindex.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_nameindex.c,v 1.6 2000/12/20 18:47:11 christos Exp $ */ +/* $NetBSD: if_nameindex.c,v 1.7 2012/03/13 21:13:41 christos Exp $ */ /* $KAME: if_nameindex.c,v 1.8 2000/11/24 08:20:01 itojun Exp $ */ /*- @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: if_nameindex.c,v 1.6 2000/12/20 18:47:11 christos Exp $"); +__RCSID("$NetBSD: if_nameindex.c,v 1.7 2012/03/13 21:13:41 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -88,8 +88,7 @@ struct if_nameindex * if_nameindex(void) { struct ifaddrs *ifaddrs, *ifa; - unsigned int ni; - int nbytes; + size_t nbytes, ni; struct if_nameindex *ifni, *ifni2; char *cp; diff --git a/lib/libc/net/ip6opt.c b/lib/libc/net/ip6opt.c index f7a9380f3..3173ef0cb 100644 --- a/lib/libc/net/ip6opt.c +++ b/lib/libc/net/ip6opt.c @@ -1,4 +1,4 @@ -/* $NetBSD: ip6opt.c,v 1.12 2009/01/30 23:43:30 lukem Exp $ */ +/* $NetBSD: ip6opt.c,v 1.14 2012/03/20 17:44:18 matt Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: ip6opt.c,v 1.12 2009/01/30 23:43:30 lukem Exp $"); +__RCSID("$NetBSD: ip6opt.c,v 1.14 2012/03/20 17:44:18 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -43,6 +43,7 @@ __RCSID("$NetBSD: ip6opt.c,v 1.12 2009/01/30 23:43:30 lukem Exp $"); #include #include +#include #include #include @@ -62,8 +63,8 @@ __weak_alias(inet6_opt_find, _inet6_opt_find) __weak_alias(inet6_opt_get_val, _inet6_opt_get_val) #endif -static int ip6optlen(u_int8_t *opt, u_int8_t *lim); -static void inet6_insert_padopt(u_char *p, size_t len); +static int ip6optlen(uint8_t *opt, uint8_t *lim); +static void inet6_insert_padopt(uint8_t *p, size_t len); /* * This function returns the number of bytes required to hold an option @@ -75,11 +76,13 @@ static void inet6_insert_padopt(u_char *p, size_t len); * byte, the length byte, and the option data. */ int -inet6_option_space(nbytes) - int nbytes; +inet6_option_space(int nbytes) { + size_t sp; nbytes += 2; /* we need space for nxt-hdr and length fields */ - return(CMSG_SPACE((nbytes + 7) & ~7)); + sp = CMSG_SPACE((nbytes + 7) & ~7); + _DIAGASSERT(__type_fit(int, sp)); + return (int)sp; } /* @@ -88,10 +91,7 @@ inet6_option_space(nbytes) * success or -1 on an error. */ int -inet6_option_init(bp, cmsgp, type) - void *bp; - struct cmsghdr **cmsgp; - int type; +inet6_option_init(void *bp, struct cmsghdr **cmsgp, int type) { register struct cmsghdr *ch; @@ -123,20 +123,17 @@ inet6_option_init(bp, cmsgp, type) * earlier. It must have a value between 0 and 7, inclusive. */ int -inet6_option_append(cmsg, typep, multx, plusy) - struct cmsghdr *cmsg; - const u_int8_t *typep; - int multx; - int plusy; +inet6_option_append(struct cmsghdr *cmsg, const uint8_t *typep, int multx, + int plusy) { size_t padlen, optlen, off; - register u_char *bp; + register uint8_t *bp; struct ip6_ext *eh; _DIAGASSERT(cmsg != NULL); _DIAGASSERT(typep != NULL); - bp = (u_char *)(void *)cmsg + cmsg->cmsg_len; + bp = (uint8_t *)(void *)cmsg + cmsg->cmsg_len; eh = (struct ip6_ext *)(void *)CMSG_DATA(cmsg); /* argument validation */ @@ -150,20 +147,21 @@ inet6_option_append(cmsg, typep, multx, plusy) * first 2 bytes(for next header and length fields) of * the option header. */ - if (bp == (u_char *)(void *)eh) { + if (bp == (uint8_t *)(void *)eh) { bp += 2; cmsg->cmsg_len += 2; } /* calculate pad length before the option. */ - off = bp - (u_char *)(void *)eh; + off = bp - (uint8_t *)(void *)eh; padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - (off % multx); padlen += plusy; padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ inet6_insert_padopt(bp, padlen); - cmsg->cmsg_len += padlen; + _DIAGASSERT(__type_fit(socklen_t, padlen + cmsg->cmsg_len)); + cmsg->cmsg_len += (socklen_t)padlen; bp += padlen; /* copy the option */ @@ -173,18 +171,21 @@ inet6_option_append(cmsg, typep, multx, plusy) optlen = typep[1] + 2; memcpy(bp, typep, (size_t)optlen); bp += optlen; - cmsg->cmsg_len += optlen; + _DIAGASSERT(__type_fit(socklen_t, optlen + cmsg->cmsg_len)); + cmsg->cmsg_len += (socklen_t)optlen; /* calculate pad length after the option and insert the padding */ - off = bp - (u_char *)(void *)eh; + off = bp - (uint8_t *)(void *)eh; padlen = ((off + 7) & ~7) - off; inet6_insert_padopt(bp, padlen); bp += padlen; - cmsg->cmsg_len += padlen; + _DIAGASSERT(__type_fit(socklen_t, padlen + cmsg->cmsg_len)); + cmsg->cmsg_len += (socklen_t)padlen; /* update the length field of the ip6 option header */ - off = bp - (u_char *)(void *)eh; - eh->ip6e_len = (off >> 3) - 1; + off = bp - (uint8_t *)(void *)eh; + _DIAGASSERT(__type_fit(uint8_t, (off >> 3) - 1)); + eh->ip6e_len = (uint8_t)((off >> 3) - 1); return(0); } @@ -202,21 +203,17 @@ inet6_option_append(cmsg, typep, multx, plusy) * then be built by the caller. * */ -u_int8_t * -inet6_option_alloc(cmsg, datalen, multx, plusy) - struct cmsghdr *cmsg; - int datalen; - int multx; - int plusy; +uint8_t * +inet6_option_alloc(struct cmsghdr *cmsg, int datalen, int multx, int plusy) { size_t padlen, off; - register u_int8_t *bp; - u_int8_t *retval; + register uint8_t *bp; + uint8_t *retval; struct ip6_ext *eh; _DIAGASSERT(cmsg != NULL); - bp = (u_char *)(void *)cmsg + cmsg->cmsg_len; + bp = (uint8_t *)(void *)cmsg + cmsg->cmsg_len; eh = (struct ip6_ext *)(void *)CMSG_DATA(cmsg); /* argument validation */ @@ -230,20 +227,20 @@ inet6_option_alloc(cmsg, datalen, multx, plusy) * first 2 bytes(for next header and length fields) of * the option header. */ - if (bp == (u_char *)(void *)eh) { + if (bp == (uint8_t *)(void *)eh) { bp += 2; cmsg->cmsg_len += 2; } /* calculate pad length before the option. */ - off = bp - (u_char *)(void *)eh; + off = bp - (uint8_t *)(void *)eh; padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - (off % multx); padlen += plusy; padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ inet6_insert_padopt(bp, padlen); - cmsg->cmsg_len += padlen; + cmsg->cmsg_len += (socklen_t)padlen; bp += padlen; /* keep space to store specified length of data */ @@ -252,15 +249,17 @@ inet6_option_alloc(cmsg, datalen, multx, plusy) cmsg->cmsg_len += datalen; /* calculate pad length after the option and insert the padding */ - off = bp - (u_char *)(void *)eh; + off = bp - (uint8_t *)(void *)eh; padlen = ((off + 7) & ~7) - off; inet6_insert_padopt(bp, padlen); bp += padlen; - cmsg->cmsg_len += padlen; + _DIAGASSERT(__type_fit(socklen_t, padlen + cmsg->cmsg_len)); + cmsg->cmsg_len += (socklen_t)padlen; /* update the length field of the ip6 option header */ - off = bp - (u_char *)(void *)eh; - eh->ip6e_len = (off >> 3) - 1; + off = bp - (uint8_t *)(void *)eh; + _DIAGASSERT(__type_fit(uint8_t, (off >> 3) - 1)); + eh->ip6e_len = (uint8_t)((off >> 3) - 1); return(retval); } @@ -276,13 +275,11 @@ inet6_option_alloc(cmsg, datalen, multx, plusy) * (RFC 2292, 6.3.5) */ int -inet6_option_next(cmsg, tptrp) - const struct cmsghdr *cmsg; - u_int8_t **tptrp; +inet6_option_next(const struct cmsghdr *cmsg, uint8_t **tptrp) { struct ip6_ext *ip6e; int hdrlen, optlen; - u_int8_t *lim; + uint8_t *lim; _DIAGASSERT(cmsg != NULL); _DIAGASSERT(tptrp != NULL); @@ -305,9 +302,9 @@ inet6_option_next(cmsg, tptrp) * simply return the 1st option. * Otherwise, search the option list for the next option. */ - lim = (u_int8_t *)(void *)ip6e + hdrlen; + lim = (uint8_t *)(void *)ip6e + hdrlen; if (*tptrp == NULL) - *tptrp = (u_int8_t *)(void *)(ip6e + 1); + *tptrp = (uint8_t *)(void *)(ip6e + 1); else { if ((optlen = ip6optlen(*tptrp, lim)) == 0) return(-1); @@ -333,18 +330,15 @@ inet6_option_next(cmsg, tptrp) * except this function lets the caller specify the option type to be * searched for, instead of always returning the next option in the * ancillary data object. - * Note: RFC 2292 says the type of tptrp is u_int8_t *, but we think - * it's a typo. The variable should be type of u_int8_t **. + * Note: RFC 2292 says the type of tptrp is uint8_t *, but we think + * it's a typo. The variable should be type of uint8_t **. */ int -inet6_option_find(cmsg, tptrp, type) - const struct cmsghdr *cmsg; - u_int8_t **tptrp; - int type; +inet6_option_find(const struct cmsghdr *cmsg, uint8_t **tptrp, int type) { struct ip6_ext *ip6e; int hdrlen, optlen; - u_int8_t *optp, *lim; + uint8_t *optp, *lim; _DIAGASSERT(cmsg != NULL); _DIAGASSERT(tptrp != NULL); @@ -367,9 +361,9 @@ inet6_option_find(cmsg, tptrp, type) * search from the beginning of the option list. * Otherwise, search from *the next option* of the specified point. */ - lim = (u_int8_t *)(void *)ip6e + hdrlen; + lim = (uint8_t *)(void *)ip6e + hdrlen; if (*tptrp == NULL) - *tptrp = (u_int8_t *)(void *)(ip6e + 1); + *tptrp = (uint8_t *)(void *)(ip6e + 1); else { if ((optlen = ip6optlen(*tptrp, lim)) == 0) return(-1); @@ -396,8 +390,7 @@ inet6_option_find(cmsg, tptrp, type) * calculated length and the limitation of the buffer. */ static int -ip6optlen(opt, lim) - u_int8_t *opt, *lim; +ip6optlen(uint8_t *opt, uint8_t *lim) { int optlen; @@ -419,7 +412,7 @@ ip6optlen(opt, lim) } static void -inet6_insert_padopt(u_char *p, size_t len) +inet6_insert_padopt(uint8_t *p, size_t len) { _DIAGASSERT(p != NULL); @@ -432,7 +425,8 @@ inet6_insert_padopt(u_char *p, size_t len) return; default: p[0] = IP6OPT_PADN; - p[1] = len - 2; + _DIAGASSERT(__type_fit(uint8_t, len - 2)); + p[1] = (uint8_t)(len - 2); memset(&p[2], 0, len - 2); return; } @@ -461,8 +455,8 @@ inet6_opt_init(void *extbuf, socklen_t extlen) } int -inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, - socklen_t len, u_int8_t align, void **databufp) +inet6_opt_append(void *extbuf, socklen_t extlen, int offset, uint8_t type, + socklen_t len, uint8_t align, void **databufp) { int currentlen = offset; size_t padlen = 0; @@ -496,13 +490,14 @@ inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, padlen = align - (currentlen % align); /* The option must fit in the extension header buffer. */ - currentlen += padlen; + _DIAGASSERT(__type_fit(int, currentlen + padlen)); + currentlen += (int)padlen; if (extlen && /* XXX: right? */ (socklen_t)currentlen > extlen) return (-1); if (extbuf) { - u_int8_t *optp = (u_int8_t *)extbuf + offset; + uint8_t *optp = (uint8_t *)extbuf + offset; if (padlen == 1) { /* insert a Pad1 option */ @@ -511,7 +506,8 @@ inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, } else if (padlen > 0) { /* insert a PadN option for alignment */ *optp++ = IP6OPT_PADN; - *optp++ = padlen - 2; + _DIAGASSERT(__type_fit(uint8_t, padlen - 2)); + *optp++ = (uint8_t)(padlen - 2); memset(optp, 0, padlen - 2); optp += (padlen - 2); } @@ -531,18 +527,18 @@ inet6_opt_finish(void *extbuf, socklen_t extlen, int offset) int updatelen = offset > 0 ? (1 + ((offset - 1) | 7)) : 0; if (extbuf) { - u_int8_t *padp; + uint8_t *padp; size_t padlen = updatelen - offset; - if ((socklen_t)updatelen > extlen) + if ((socklen_t)updatelen > extlen || padlen >= 256 + 2) return (-1); - padp = (u_int8_t *)extbuf + offset; + padp = (uint8_t *)extbuf + offset; if (padlen == 1) *padp = IP6OPT_PAD1; else if (padlen > 0) { *padp++ = IP6OPT_PADN; - *padp++ = (padlen - 2); + *padp++ = (uint8_t)(padlen - 2); memset(padp, 0, padlen - 2); } } @@ -554,21 +550,21 @@ int inet6_opt_set_val(void *databuf, int offset, void *val, socklen_t vallen) { - memcpy((u_int8_t *)databuf + offset, val, vallen); + memcpy((uint8_t *)databuf + offset, val, vallen); return (offset + vallen); } int -inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, +inet6_opt_next(void *extbuf, socklen_t extlen, int offset, uint8_t *typep, socklen_t *lenp, void **databufp) { - u_int8_t *optp, *lim; + uint8_t *optp, *lim; int optlen; /* Validate extlen. XXX: is the variable really necessary?? */ if (extlen == 0 || (extlen % 8)) return (-1); - lim = (u_int8_t *)extbuf + extlen; + lim = (uint8_t *)extbuf + extlen; /* * If this is the first time this function called for this options @@ -576,12 +572,13 @@ inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, * Otherwise, search the option list for the next option. */ if (offset == 0) - optp = (u_int8_t *)(void *)((struct ip6_hbh *)extbuf + 1); + optp = (uint8_t *)(void *)((struct ip6_hbh *)extbuf + 1); else - optp = (u_int8_t *)extbuf + offset; + optp = (uint8_t *)extbuf + offset; /* Find the next option skipping any padding options. */ while (optp < lim) { + ptrdiff_t rv; switch(*optp) { case IP6OPT_PAD1: optp++; @@ -597,7 +594,9 @@ inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, *typep = *optp; *lenp = optlen - 2; *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); + rv = optp + optlen - (uint8_t *)extbuf; + _DIAGASSERT(__type_fit(int, rv)); + return (int)rv; } } @@ -607,16 +606,16 @@ inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, } int -inet6_opt_find(void *extbuf, socklen_t extlen, int offset, u_int8_t type, +inet6_opt_find(void *extbuf, socklen_t extlen, int offset, uint8_t type, socklen_t *lenp, void **databufp) { - u_int8_t *optp, *lim; + uint8_t *optp, *lim; int optlen; /* Validate extlen. XXX: is the variable really necessary?? */ if (extlen == 0 || (extlen % 8)) return (-1); - lim = (u_int8_t *)extbuf + extlen; + lim = (uint8_t *)extbuf + extlen; /* * If this is the first time this function called for this options @@ -624,9 +623,9 @@ inet6_opt_find(void *extbuf, socklen_t extlen, int offset, u_int8_t type, * Otherwise, search the option list for the next option. */ if (offset == 0) - optp = (u_int8_t *)(void *)((struct ip6_hbh *)extbuf + 1); + optp = (uint8_t *)(void *)((struct ip6_hbh *)extbuf + 1); else - optp = (u_int8_t *)extbuf + offset; + optp = (uint8_t *)extbuf + offset; /* Find the specified option */ while (optp < lim) { @@ -634,9 +633,12 @@ inet6_opt_find(void *extbuf, socklen_t extlen, int offset, u_int8_t type, goto optend; if (*optp == type) { /* found */ + ptrdiff_t td; *lenp = optlen - 2; *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); + td = optp + optlen - (uint8_t *)extbuf; + _DIAGASSERT(__type_fit(int, td)); + return (int)td; } optp += optlen; @@ -652,7 +654,7 @@ inet6_opt_get_val(void *databuf, int offset, void *val, socklen_t vallen) { /* we can't assume alignment here */ - memcpy(val, (u_int8_t *)databuf + offset, vallen); + memcpy(val, (uint8_t *)databuf + offset, vallen); return (offset + vallen); } diff --git a/lib/libc/net/iso_addr.c b/lib/libc/net/iso_addr.c index cb0b7c1c2..db6c94c05 100644 --- a/lib/libc/net/iso_addr.c +++ b/lib/libc/net/iso_addr.c @@ -1,4 +1,4 @@ -/* $NetBSD: iso_addr.c,v 1.12 2005/11/29 03:11:59 christos Exp $ */ +/* $NetBSD: iso_addr.c,v 1.14 2012/03/20 17:44:18 matt Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)iso_addr.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: iso_addr.c,v 1.12 2005/11/29 03:11:59 christos Exp $"); +__RCSID("$NetBSD: iso_addr.c,v 1.14 2012/03/20 17:44:18 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,8 +54,7 @@ __RCSID("$NetBSD: iso_addr.c,v 1.12 2005/11/29 03:11:59 christos Exp $"); #define DELIM (4*2) struct iso_addr * -iso_addr(addr) - register const char *addr; +iso_addr(const char *addr) { static struct iso_addr out_addr; register char *cp = out_addr.isoa_genaddr; @@ -95,15 +94,15 @@ iso_addr(addr) } break; } while (cp < cplim); - out_addr.isoa_len = cp - out_addr.isoa_genaddr; + _DIAGASSERT(__type_fit(uint8_t, cp - out_addr.isoa_genaddr)); + out_addr.isoa_len = (uint8_t)(cp - out_addr.isoa_genaddr); return (&out_addr); } static const char hexlist[16] = "0123456789abcdef"; char * -iso_ntoa(isoa) - const struct iso_addr *isoa; +iso_ntoa(const struct iso_addr *isoa) { static char obuf[64]; char *out = obuf; diff --git a/lib/libc/net/linkaddr.c b/lib/libc/net/linkaddr.c index 401a4edfd..c807439d7 100644 --- a/lib/libc/net/linkaddr.c +++ b/lib/libc/net/linkaddr.c @@ -1,4 +1,4 @@ -/* $NetBSD: linkaddr.c,v 1.14 2005/11/29 03:11:59 christos Exp $ */ +/* $NetBSD: linkaddr.c,v 1.16 2012/03/20 17:44:18 matt Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: linkaddr.c,v 1.14 2005/11/29 03:11:59 christos Exp $"); +__RCSID("$NetBSD: linkaddr.c,v 1.16 2012/03/20 17:44:18 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -57,14 +57,12 @@ __RCSID("$NetBSD: linkaddr.c,v 1.14 2005/11/29 03:11:59 christos Exp $"); #define LETTER (4*3) void -link_addr(addr, sdl) - register const char *addr; - register struct sockaddr_dl *sdl; +link_addr(const char *addr, struct sockaddr_dl *sdl) { register char *cp = sdl->sdl_data; char *cplim = sdl->sdl_len + (char *)(void *)sdl; - register int byte = 0, state = NAMING; - register int newaddr = 0; /* pacify gcc */ + int byte = 0, state = NAMING; + size_t newaddr = 0; /* pacify gcc */ _DIAGASSERT(addr != NULL); _DIAGASSERT(sdl != NULL); @@ -95,18 +93,19 @@ link_addr(addr, sdl) continue; case NAMING | DELIM: state = RESET; - sdl->sdl_nlen = cp - sdl->sdl_data; + _DIAGASSERT(__type_fit(uint8_t, cp - sdl->sdl_data)); + sdl->sdl_nlen = (uint8_t)(cp - sdl->sdl_data); continue; case GOTTWO | DIGIT: *cp++ = byte; /* FALLTHROUGH */ case RESET | DIGIT: state = GOTONE; - byte = newaddr; + byte = (int)newaddr; continue; case GOTONE | DIGIT: state = GOTTWO; - byte = newaddr + (byte << 4); + byte = (int)newaddr + (byte << 4); continue; default: /* | DELIM */ state = RESET; @@ -122,18 +121,21 @@ link_addr(addr, sdl) } break; } while (cp < cplim); - sdl->sdl_alen = cp - LLADDR(sdl); + + _DIAGASSERT(__type_fit(uint8_t, cp - LLADDR(sdl))); + sdl->sdl_alen = (uint8_t)(cp - LLADDR(sdl)); newaddr = cp - (char *)(void *)sdl; - if ((size_t) newaddr > sizeof(*sdl)) - sdl->sdl_len = newaddr; + if (newaddr > sizeof(*sdl)) { + _DIAGASSERT(__type_fit(uint8_t, newaddr)); + sdl->sdl_len = (uint8_t)newaddr; + } return; } static const char hexlist[16] = "0123456789abcdef"; char * -link_ntoa(sdl) - register const struct sockaddr_dl *sdl; +link_ntoa(const struct sockaddr_dl *sdl) { static char obuf[64]; register char *out = obuf; diff --git a/lib/libc/net/minix/getifaddrs.c b/lib/libc/net/minix/getifaddrs.c index 5a54d9815..62caae058 100644 --- a/lib/libc/net/minix/getifaddrs.c +++ b/lib/libc/net/minix/getifaddrs.c @@ -1,19 +1,23 @@ -#include -#include -#include -#include -#include -#include +#include + #include #include #include -#include +#include #include #include #include #include +#include + +#include +#include +#include +#include +#include + int getifaddrs(struct ifaddrs **ifap) { diff --git a/lib/libc/net/nsdispatch.3 b/lib/libc/net/nsdispatch.3 index d22e8d23c..9e420a0fa 100644 --- a/lib/libc/net/nsdispatch.3 +++ b/lib/libc/net/nsdispatch.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: nsdispatch.3,v 1.29 2009/10/14 17:24:03 joerg Exp $ +.\" $NetBSD: nsdispatch.3,v 1.31 2011/04/28 16:16:23 wiz Exp $ .\" .\" Copyright (c) 1997, 1998, 1999, 2004, 2005, 2008 .\" The NetBSD Foundation, Inc. @@ -479,7 +479,8 @@ All methods for all sources are invoked for this method name. should be set to a pointer to an internal static .Ft "struct group" on success, -.Dv NULL otherwise. +.Dv NULL +otherwise. .Pp .Xr getgrent 3 returns @@ -521,7 +522,8 @@ otherwise. should be set to a pointer to an internal static .Ft "struct group" on success, -.Dv NULL otherwise. +.Dv NULL +otherwise. .Pp .Xr getgrgid 3 returns @@ -564,7 +566,8 @@ otherwise. should be set to a pointer to an internal static .Ft "struct group" on success, -.Dv NULL otherwise. +.Dv NULL +otherwise. .Pp .Xr getgrnam 3 returns @@ -703,7 +706,8 @@ should be set to 1 for a successful match and 0 otherwise. should be set to a pointer to an internal static .Ft "struct netent" on success, -.Dv NULL otherwise. +.Dv NULL +otherwise. .Pp .Xr getnetbyaddr 3 returns @@ -722,7 +726,8 @@ otherwise. should be set to a pointer to an internal static .Ft "struct netent" on success, -.Dv NULL otherwise. +.Dv NULL +otherwise. .Pp .Xr getnetbyname 3 returns @@ -749,7 +754,8 @@ All methods for all sources are invoked for this method name. should be set to a pointer to an internal static .Ft "struct passwd" on success, -.Dv NULL otherwise. +.Dv NULL +otherwise. .Pp .Xr getpwent 3 returns @@ -791,7 +797,8 @@ otherwise. should be set to a pointer to an internal static .Ft "struct passwd" on success, -.Dv NULL otherwise. +.Dv NULL +otherwise. .Pp .Xr getpwnam 3 returns @@ -834,7 +841,8 @@ otherwise. should be set to a pointer to an internal static .Ft "struct passwd" on success, -.Dv NULL otherwise. +.Dv NULL +otherwise. .Pp .Xr getpwuid 3 returns @@ -858,7 +866,7 @@ should be set to an appropriate .Xr errno 2 on failure. .Pp -.Xr getpwuid_r +.Xr getpwuid_r 3 returns 0 if .Fn nsdispatch diff --git a/lib/libc/net/nsdispatch.c b/lib/libc/net/nsdispatch.c index 2a3536af6..8bfaa3b24 100644 --- a/lib/libc/net/nsdispatch.c +++ b/lib/libc/net/nsdispatch.c @@ -1,4 +1,4 @@ -/* $NetBSD: nsdispatch.c,v 1.34 2009/02/05 13:21:11 lukem Exp $ */ +/* $NetBSD: nsdispatch.c,v 1.37 2012/03/13 21:13:42 christos Exp $ */ /*- * Copyright (c) 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: nsdispatch.c,v 1.34 2009/02/05 13:21:11 lukem Exp $"); +__RCSID("$NetBSD: nsdispatch.c,v 1.37 2012/03/13 21:13:42 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -168,16 +168,18 @@ static LIST_HEAD(, _ns_drec) _ns_drec = LIST_HEAD_INITIALIZER(&_ns_drec); static mutex_t _ns_drec_lock = MUTEX_INITIALIZER; #endif /* _REENTRANT */ + +/* + * Runtime determination of whether we are dynamically linked or not. + */ #ifndef __ELF__ #define is_dynamic() (0) /* don't bother - switch to ELF! */ -#elif __GNUC_PREREQ__(4,2) -static int rtld_DYNAMIC __attribute__((__weakref__, __alias__("_DYNAMIC"))); -#define is_dynamic() (&rtld_DYNAMIC != NULL) #else -extern int _DYNAMIC __weak_reference(_DYNAMIC); -#define is_dynamic() (&_DYNAMIC != NULL) +__weakref_visible int rtld_DYNAMIC __weak_reference(_DYNAMIC); +#define is_dynamic() (&rtld_DYNAMIC != NULL) #endif + /* * size of dynamic array chunk for _nsmap and _nsmap[x].srclist (and other * growing arrays). @@ -388,8 +390,7 @@ _nsdbtaddsrc(ns_dbt *dbt, const ns_src *src) /* dbt->srclistsize already incremented */ modkey.name = src->name; - mod = bsearch(&modkey, _nsmod, _nsmodsize, sizeof(*_nsmod), - _nsmodcmp); + mod = bsearch(&modkey, _nsmod, _nsmodsize, sizeof(*_nsmod), _nsmodcmp); if (mod == NULL) return (_nsloadmod(src->name, NULL)); diff --git a/lib/libc/net/nslexer.l b/lib/libc/net/nslexer.l index 45381d1b3..4c15aef7a 100644 --- a/lib/libc/net/nslexer.l +++ b/lib/libc/net/nslexer.l @@ -1,5 +1,5 @@ %{ -/* $NetBSD: nslexer.l,v 1.11 2010/12/08 03:19:19 christos Exp $ */ +/* $NetBSD: nslexer.l,v 1.13 2012/06/25 22:32:45 abs Exp $ */ /*- * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: nslexer.l,v 1.11 2010/12/08 03:19:19 christos Exp $"); +__RCSID("$NetBSD: nslexer.l,v 1.13 2012/06/25 22:32:45 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -94,14 +94,13 @@ STRING [a-zA-Z][a-zA-Z0-9_]* #undef _nsyywrap int -_nsyywrap() +_nsyywrap(void) { return 1; } /* _nsyywrap */ void -_nsyyerror(msg) - const char *msg; +_nsyyerror(const char *msg) { syslog(LOG_WARNING, "libc nsdispatch: %s line %d: %s at '%s'", diff --git a/lib/libc/net/nsparser.y b/lib/libc/net/nsparser.y index 5845eca4e..4156d6264 100644 --- a/lib/libc/net/nsparser.y +++ b/lib/libc/net/nsparser.y @@ -1,5 +1,5 @@ %{ -/* $NetBSD: nsparser.y,v 1.11 2009/02/05 13:21:11 lukem Exp $ */ +/* $NetBSD: nsparser.y,v 1.12 2012/03/20 17:44:18 matt Exp $ */ /*- * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: nsparser.y,v 1.11 2009/02/05 13:21:11 lukem Exp $"); +__RCSID("$NetBSD: nsparser.y,v 1.12 2012/03/20 17:44:18 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -45,7 +45,7 @@ __RCSID("$NetBSD: nsparser.y,v 1.11 2009/02/05 13:21:11 lukem Exp $"); #include -static void _nsaddsrctomap __P((const char *)); +static void _nsaddsrctomap(const char *); static ns_dbt curdbt; static ns_src cursrc; @@ -154,8 +154,7 @@ Action %% static void -_nsaddsrctomap(elem) - const char *elem; +_nsaddsrctomap(const char *elem) { unsigned int i; int lineno; diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c index e70c2f9e7..e4d11ee6d 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -1,4 +1,4 @@ -/* $NetBSD: rcmd.c,v 1.65 2007/01/03 11:46:22 ws Exp $ */ +/* $NetBSD: rcmd.c,v 1.68 2012/07/14 15:06:26 darrenr Exp $ */ /* * Copyright (c) 1983, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #else -__RCSID("$NetBSD: rcmd.c,v 1.65 2007/01/03 11:46:22 ws Exp $"); +__RCSID("$NetBSD: rcmd.c,v 1.68 2012/07/14 15:06:26 darrenr Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -72,39 +72,31 @@ __RCSID("$NetBSD: rcmd.c,v 1.65 2007/01/03 11:46:22 ws Exp $"); #include "pathnames.h" -int orcmd __P((char **, u_int, const char *, const char *, const char *, - int *)); -int orcmd_af __P((char **, u_int, const char *, const char *, const char *, - int *, int)); -int __ivaliduser __P((FILE *, u_int32_t, const char *, const char *)); -int __ivaliduser_sa __P((FILE *, const struct sockaddr *, socklen_t, - const char *, const char *)); -static int rshrcmd __P((char **, u_int32_t, const char *, const char *, - const char *, int *, const char *)); -static int resrcmd __P((struct addrinfo *, char **, u_int32_t, const char *, - const char *, const char *, int *)); -static int __icheckhost __P((const struct sockaddr *, socklen_t, - const char *)); -static char *__gethostloop __P((const struct sockaddr *, socklen_t)); +int orcmd(char **, u_int, const char *, const char *, const char *, int *); +int orcmd_af(char **, u_int, const char *, const char *, const char *, + int *, int); +int __ivaliduser(FILE *, u_int32_t, const char *, const char *); +int __ivaliduser_sa(FILE *, const struct sockaddr *, socklen_t, + const char *, const char *); +static int rshrcmd(int, char **, u_int32_t, const char *, + const char *, const char *, int *, const char *); +static int resrcmd(struct addrinfo *, char **, u_int32_t, const char *, + const char *, const char *, int *); +static int __icheckhost(const struct sockaddr *, socklen_t, + const char *); +static char *__gethostloop(const struct sockaddr *, socklen_t); int -rcmd(ahost, rport, locuser, remuser, cmd, fd2p) - char **ahost; - u_short rport; - const char *locuser, *remuser, *cmd; - int *fd2p; +rcmd(char **ahost, int rport, const char *locuser, const char *remuser, + const char *cmd, int *fd2p) { return rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, AF_INET); } int -rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) - char **ahost; - u_short rport; - const char *locuser, *remuser, *cmd; - int *fd2p; - int af; +rcmd_af(char **ahost, int rport, const char *locuser, const char *remuser, + const char *cmd, int *fd2p, int af) { static char hbuf[MAXHOSTNAMELEN]; char pbuf[NI_MAXSERV]; @@ -126,7 +118,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) error = getaddrinfo(*ahost, pbuf, &hints, &res); if (error) { warnx("%s: %s", *ahost, gai_strerror(error)); /*XXX*/ - return (-1); + return -1; } if (res->ai_canonname) { /* @@ -144,33 +136,26 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) */ sp = getservbyname("shell", "tcp"); if (sp != NULL && sp->s_port == rport) - error = rshrcmd(ahost, (u_int32_t)rport, + error = rshrcmd(af, ahost, (u_int32_t)rport, locuser, remuser, cmd, fd2p, getenv("RCMD_CMD")); else error = resrcmd(res, ahost, (u_int32_t)rport, locuser, remuser, cmd, fd2p); freeaddrinfo(res); - return (error); + return error; } /* this is simply a wrapper around hprcmd() that handles ahost first */ int -orcmd(ahost, rport, locuser, remuser, cmd, fd2p) - char **ahost; - u_int rport; - const char *locuser, *remuser, *cmd; - int *fd2p; +orcmd(char **ahost, u_int rport, const char *locuser, const char *remuser, + const char *cmd, int *fd2p) { return orcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, AF_INET); } int -orcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) - char **ahost; - u_int rport; - const char *locuser, *remuser, *cmd; - int *fd2p; - int af; +orcmd_af(char **ahost, u_int rport, const char *locuser, const char *remuser, + const char *cmd, int *fd2p, int af) { static char hbuf[MAXHOSTNAMELEN]; char pbuf[NI_MAXSERV]; @@ -191,7 +176,7 @@ orcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) error = getaddrinfo(*ahost, pbuf, &hints, &res); if (error) { warnx("%s: %s", *ahost, gai_strerror(error)); /*XXX*/ - return (-1); + return -1; } if (res->ai_canonname) { strlcpy(hbuf, res->ai_canonname, sizeof(hbuf)); @@ -200,17 +185,13 @@ orcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) error = resrcmd(res, ahost, rport, locuser, remuser, cmd, fd2p); freeaddrinfo(res); - return (error); + return error; } /*ARGSUSED*/ static int -resrcmd(res, ahost, rport, locuser, remuser, cmd, fd2p) - struct addrinfo *res; - char **ahost; - u_int32_t rport; - const char *locuser, *remuser, *cmd; - int *fd2p; +resrcmd(struct addrinfo *res, char **ahost, u_int32_t rport, + const char *locuser, const char *remuser, const char *cmd, int *fd2p) { struct addrinfo *r; struct sockaddr_storage from; @@ -258,7 +239,7 @@ resrcmd(res, ahost, rport, locuser, remuser, cmd, fd2p) #ifndef __minix (void)sigprocmask(SIG_SETMASK, &omask, NULL); #endif /* !__minix */ - return (-1); + return -1; } } #ifndef __minix @@ -280,14 +261,16 @@ resrcmd(res, ahost, rport, locuser, remuser, cmd, fd2p) hbuf[0] = '\0'; if (getnameinfo(r->ai_addr, r->ai_addrlen, - hbuf, sizeof(hbuf), NULL, 0, niflags) != 0) + hbuf, (socklen_t)sizeof(hbuf), NULL, 0, niflags) != + 0) strlcpy(hbuf, "(invalid)", sizeof(hbuf)); errno = oerrno; warn("rcmd: connect to address %s", hbuf); r = r->ai_next; hbuf[0] = '\0'; if (getnameinfo(r->ai_addr, r->ai_addrlen, - hbuf, sizeof(hbuf), NULL, 0, niflags) != 0) + hbuf, (socklen_t)sizeof(hbuf), NULL, 0, niflags) != + 0) strlcpy(hbuf, "(invalid)", sizeof(hbuf)); (void)fprintf(stderr, "Trying %s...\n", hbuf); continue; @@ -305,7 +288,7 @@ resrcmd(res, ahost, rport, locuser, remuser, cmd, fd2p) /* No OOB support in Minix. */ (void)sigprocmask(SIG_SETMASK, &omask, NULL); #endif /* !__minix */ - return (-1); + return -1; } lport--; if (fd2p == 0) { @@ -336,7 +319,8 @@ resrcmd(res, ahost, rport, locuser, remuser, cmd, fd2p) if (errno != 0) warn("poll: setting up stderr"); else - warnx("poll: protocol failure in circuit setup"); + warnx( + "poll: protocol failure in circuit setup"); (void)close(s2); goto bad; } @@ -354,10 +338,12 @@ resrcmd(res, ahost, rport, locuser, remuser, cmd, fd2p) case AF_INET6: #endif if (getnameinfo((struct sockaddr *)(void *)&from, len, - NULL, 0, num, sizeof(num), NI_NUMERICSERV) != 0 || + NULL, 0, num, (socklen_t)sizeof(num), + NI_NUMERICSERV) != 0 || (atoi(num) >= IPPORT_RESERVED || atoi(num) < IPPORT_RESERVED / 2)) { - warnx("rcmd: protocol failure in circuit setup."); + warnx( + "rcmd: protocol failure in circuit setup."); goto bad2; } break; @@ -384,7 +370,7 @@ resrcmd(res, ahost, rport, locuser, remuser, cmd, fd2p) #ifndef __minix (void)sigprocmask(SIG_SETMASK, &omask, NULL); #endif /* __minix */ - return (s); + return s; bad2: if (lport) (void)close(*fd2p); @@ -393,7 +379,7 @@ bad: #ifndef __minix (void)sigprocmask(SIG_SETMASK, &omask, NULL); #endif /* __minix */ - return (-1); + return -1; } /* @@ -401,12 +387,8 @@ bad: */ /* ARGSUSED */ static int -rshrcmd(ahost, rport, locuser, remuser, cmd, fd2p, rshcmd) - char **ahost; - u_int32_t rport; - const char *locuser, *remuser, *cmd; - int *fd2p; - const char *rshcmd; +rshrcmd(int af, char **ahost, u_int32_t rport, const char *locuser, + const char *remuser, const char *cmd, int *fd2p, const char *rshcmd) { pid_t pid; int sp[2], ep[2]; @@ -427,28 +409,28 @@ rshrcmd(ahost, rport, locuser, remuser, cmd, fd2p, rshcmd) /* locuser must exist on this host. */ if (getpwnam_r(locuser, &pwres, pwbuf, sizeof(pwbuf), &pw) != 0 || pw == NULL) { - warnx("rshrcmd: unknown user: %s", locuser); - return(-1); + warnx("%s: unknown user: %s", __func__, locuser); + return -1; } /* get a socketpair we'll use for stdin and stdout. */ if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sp) < 0) { - warn("rshrcmd: socketpair"); - return (-1); + warn("%s: socketpair", __func__); + return -1; } /* we will use this for the fd2 pointer */ if (fd2p) { if (socketpair(AF_LOCAL, SOCK_STREAM, 0, ep) < 0) { - warn("rshrcmd: socketpair"); - return (-1); + warn("%s: socketpair", __func__); + return -1; } *fd2p = ep[0]; } pid = fork(); if (pid < 0) { - warn("rshrcmd: fork"); - return (-1); + warn("%s: fork", __func__); + return -1; } if (pid == 0) { /* @@ -458,25 +440,25 @@ rshrcmd(ahost, rport, locuser, remuser, cmd, fd2p, rshcmd) */ (void)close(sp[0]); if (dup2(sp[1], 0) < 0 || dup2(0, 1) < 0) { - warn("rshrcmd: dup2"); + warn("%s: dup2", __func__); _exit(1); } (void)close(sp[1]); if (fd2p) { if (dup2(ep[1], 2) < 0) { - warn("rshrcmd: dup2"); + warn("%s: dup2", __func__); _exit(1); } (void)close(ep[0]); (void)close(ep[1]); } else if (dup2(0, 2) < 0) { - warn("rshrcmd: dup2"); + warn("%s: dup2", __func__); _exit(1); } /* fork again to lose parent. */ pid = fork(); if (pid < 0) { - warn("rshrcmd: second fork"); + warn("%s: second fork", __func__); _exit(1); } if (pid > 0) @@ -484,13 +466,13 @@ rshrcmd(ahost, rport, locuser, remuser, cmd, fd2p, rshcmd) /* Orphan. Become local user for rshprog. */ if (setuid(pw->pw_uid)) { - warn("rshrcmd: setuid(%lu)", (u_long)pw->pw_uid); + warn("%s: setuid(%lu)", __func__, (u_long)pw->pw_uid); _exit(1); } /* - * If we are rcmd'ing to "localhost" as the same user as we are, - * then avoid running remote shell for efficiency. + * If we are rcmd'ing to "localhost" as the same user as we + * are, then avoid running remote shell for efficiency. */ if (strcmp(*ahost, "localhost") == 0 && strcmp(locuser, remuser) == 0) { @@ -501,11 +483,28 @@ rshrcmd(ahost, rport, locuser, remuser, cmd, fd2p, rshcmd) p = strrchr(rshcmd, '/'); execlp(rshcmd, p ? p + 1 : rshcmd, "-c", cmd, NULL); } else { - p = strrchr(rshcmd, '/'); - execlp(rshcmd, p ? p + 1 : rshcmd, *ahost, "-l", - remuser, cmd, NULL); + const char *program; + program = strrchr(rshcmd, '/'); + program = program ? program + 1 : rshcmd; + switch (af) { + case AF_INET: + execlp(rshcmd, program, "-4", "-l", remuser, + *ahost, cmd, NULL); + break; + + case AF_INET6: + execlp(rshcmd, program, "-6", "-l", remuser, + *ahost, cmd, NULL); + break; + + default: + /* typically AF_UNSPEC, plus whatever */ + execlp(rshcmd, program, "-l", remuser, + *ahost, cmd, NULL); + break; + } } - warn("rshrcmd: exec %s", rshcmd); + warn("%s: exec %s", __func__, rshcmd); _exit(1); } /* Parent */ @@ -514,12 +513,11 @@ rshrcmd(ahost, rport, locuser, remuser, cmd, fd2p, rshcmd) (void)close(ep[1]); (void)waitpid(pid, NULL, 0); - return (sp[0]); + return sp[0]; } int -rresvport(alport) - int *alport; +rresvport(int *alport) { _DIAGASSERT(alport != NULL); @@ -528,13 +526,17 @@ rresvport(alport) } int -rresvport_af(alport, family) - int *alport; - int family; +rresvport_af(int *alport, int family) +{ + return rresvport_af_addr(alport, family, NULL); +} + +int +rresvport_af_addr(int *alport, int family, void *addr) { struct sockaddr_storage ss; struct sockaddr *sa; - int salen; + socklen_t salen; int s; u_int16_t *portp; @@ -548,6 +550,9 @@ rresvport_af(alport, family) sa->sa_len = #endif salen = sizeof(struct sockaddr_in); + if (addr) + ((struct sockaddr_in *)(void *)sa)->sin_addr = + ((struct sockaddr_in *)addr)->sin_addr; portp = &((struct sockaddr_in *)(void *)sa)->sin_port; break; #ifdef INET6 @@ -556,17 +561,20 @@ rresvport_af(alport, family) sa->sa_len = #endif salen = sizeof(struct sockaddr_in6); + if (addr) + ((struct sockaddr_in6 *)(void *)sa)->sin6_addr = + ((struct sockaddr_in6 *)addr)->sin6_addr; portp = &((struct sockaddr_in6 *)(void *)sa)->sin6_port; break; #endif default: errno = EAFNOSUPPORT; - return (-1); + return -1; } sa->sa_family = family; s = socket(family, SOCK_STREAM, 0); if (s < 0) - return (-1); + return -1; #ifdef BSD4_4 switch (family) { case AF_INET: @@ -577,10 +585,10 @@ rresvport_af(alport, family) (void)close(s); errno = sverr; - return (-1); + return -1; } *alport = (int)ntohs(*portp); - return (s); + return s; default: /* is it necessary to try keep code for other AFs? */ break; @@ -588,17 +596,17 @@ rresvport_af(alport, family) #endif for (;;) { *portp = htons((u_short)*alport); - if (bind(s, sa, (socklen_t)salen) >= 0) - return (s); + if (bind(s, sa, salen) >= 0) + return s; if (errno != EADDRINUSE) { (void)close(s); - return (-1); + return -1; } (*alport)--; if (*alport == IPPORT_RESERVED/2) { (void)close(s); errno = EAGAIN; /* close */ - return (-1); + return -1; } } } @@ -607,9 +615,7 @@ int __check_rhosts_file = 1; const char *__rcmd_errstr; int -ruserok(rhost, superuser, ruser, luser) - const char *rhost, *ruser, *luser; - int superuser; +ruserok(const char *rhost, int superuser, const char *ruser, const char *luser) { struct addrinfo hints, *res, *r; int error; @@ -623,17 +629,17 @@ ruserok(rhost, superuser, ruser, luser) hints.ai_socktype = SOCK_DGRAM; /*dummy*/ error = getaddrinfo(rhost, "0", &hints, &res); if (error) - return (-1); + return -1; for (r = res; r; r = r->ai_next) { if (iruserok_sa(r->ai_addr, (int)r->ai_addrlen, superuser, ruser, luser) == 0) { freeaddrinfo(res); - return (0); + return 0; } } freeaddrinfo(res); - return (-1); + return -1; } /* @@ -646,21 +652,18 @@ ruserok(rhost, superuser, ruser, luser) * Returns 0 if ok, -1 if not ok. */ int -iruserok(raddr, superuser, ruser, luser) - u_int32_t raddr; - int superuser; - const char *ruser, *luser; +iruserok(u_int32_t raddr, int superuser, const char *ruser, const char *luser) { struct sockaddr_in irsin; memset(&irsin, 0, sizeof(irsin)); irsin.sin_family = AF_INET; #ifdef BSD4_4 - irsin.sin_len = sizeof(struct sockaddr_in); + irsin.sin_len = sizeof(irsin); #endif memcpy(&irsin.sin_addr, &raddr, sizeof(irsin.sin_addr)); - return iruserok_sa(&irsin, sizeof(struct sockaddr_in), superuser, ruser, - luser); + return iruserok_sa(&irsin, (socklen_t)sizeof(irsin), superuser, ruser, + luser); } /* @@ -668,11 +671,8 @@ iruserok(raddr, superuser, ruser, luser) * unistd.h and sys/socket.h. There's no better way. */ int -iruserok_sa(raddr, rlen, superuser, ruser, luser) - const void *raddr; - int rlen; - int superuser; - const char *ruser, *luser; +iruserok_sa(const void *raddr, int rlen, int superuser, const char *ruser, + const char *luser) { const struct sockaddr *sa; struct stat sbuf; @@ -698,7 +698,7 @@ iruserok_sa(raddr, rlen, superuser, ruser, luser) if (__ivaliduser_sa(hostf, sa, (socklen_t)rlen, luser, ruser) == 0) { (void)fclose(hostf); - return (0); + return 0; } (void)fclose(hostf); } @@ -708,7 +708,7 @@ iruserok_sa(raddr, rlen, superuser, ruser, luser) if (getpwnam_r(luser, &pwres, pwbuf, sizeof(pwbuf), &pwd) != 0 || pwd == NULL) - return (-1); + return -1; (void)strlcpy(pbuf, pwd->pw_dir, sizeof(pbuf)); (void)strlcat(pbuf, "/.rhosts", sizeof(pbuf)); @@ -752,7 +752,7 @@ iruserok_sa(raddr, rlen, superuser, ruser, luser) (void)setegid(gid); } - return (isvaliduser); + return isvaliduser; } /* @@ -766,34 +766,29 @@ iruserok_sa(raddr, rlen, superuser, ruser, luser) static #endif int -__ivaliduser(hostf, raddr, luser, ruser) - FILE *hostf; - u_int32_t raddr; - const char *luser, *ruser; +__ivaliduser(FILE *hostf, u_int32_t raddr, const char *luser, + const char *ruser) { struct sockaddr_in ivusin; memset(&ivusin, 0, sizeof(ivusin)); ivusin.sin_family = AF_INET; #ifdef BSD4_4 - ivusin.sin_len = sizeof(struct sockaddr_in); + ivusin.sin_len = sizeof(ivusin); #endif memcpy(&ivusin.sin_addr, &raddr, sizeof(ivusin.sin_addr)); return __ivaliduser_sa(hostf, (struct sockaddr *)(void *)&ivusin, - sizeof(struct sockaddr_in), luser, ruser); + (socklen_t)sizeof(ivusin), luser, ruser); } #ifdef notdef /*_LIBC*/ static #endif int -__ivaliduser_sa(hostf, raddr, salen, luser, ruser) - FILE *hostf; - const struct sockaddr *raddr; - socklen_t salen; - const char *luser, *ruser; +__ivaliduser_sa(FILE *hostf, const struct sockaddr *raddr, socklen_t salen, + const char *luser, const char *ruser) { - register char *user, *p; + char *user, *p; int ch; char buf[MAXHOSTNAMELEN + 128]; /* host + login */ const char *auser, *ahost; @@ -808,7 +803,7 @@ __ivaliduser_sa(hostf, raddr, salen, luser, ruser) _DIAGASSERT(luser != NULL); _DIAGASSERT(ruser != NULL); - while (fgets(buf, sizeof(buf), hostf)) { + while (fgets(buf, (int)sizeof(buf), hostf)) { p = buf; /* Skip lines that are too long. */ if (strchr(p, '\n') == NULL) { @@ -880,7 +875,8 @@ __ivaliduser_sa(hostf, raddr, salen, luser, ruser) break; default: - hostok = -__icheckhost(raddr, salen, &ahost[1]); + hostok = + -__icheckhost(raddr, salen, &ahost[1]); break; } else @@ -940,10 +936,7 @@ __ivaliduser_sa(hostf, raddr, salen, luser, ruser) * Returns "true" if match, 0 if no match. */ static int -__icheckhost(raddr, salen, lhost) - const struct sockaddr *raddr; - socklen_t salen; - const char *lhost; +__icheckhost(const struct sockaddr *raddr, socklen_t salen, const char *lhost) { struct addrinfo hints, *res, *r; char h1[NI_MAXHOST], h2[NI_MAXHOST]; @@ -954,9 +947,9 @@ __icheckhost(raddr, salen, lhost) _DIAGASSERT(lhost != NULL); h1[0] = '\0'; - if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0, + if (getnameinfo(raddr, salen, h1, (socklen_t)sizeof(h1), NULL, 0, niflags) != 0) - return (0); + return 0; /* Resolve laddr into sockaddr */ memset(&hints, 0, sizeof(hints)); @@ -965,25 +958,25 @@ __icheckhost(raddr, salen, lhost) res = NULL; error = getaddrinfo(lhost, "0", &hints, &res); if (error) - return (0); + return 0; /* * Try string comparisons between raddr and laddr. */ for (r = res; r; r = r->ai_next) { h2[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, sizeof(h2), - NULL, 0, niflags) != 0) + if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, + (socklen_t)sizeof(h2), NULL, 0, niflags) != 0) continue; if (strcmp(h1, h2) == 0) { freeaddrinfo(res); - return (1); + return 1; } } /* No match. */ freeaddrinfo(res); - return (0); + return 0; } /* @@ -992,9 +985,7 @@ __icheckhost(raddr, salen, lhost) * be found, pack the numeric IP address into the string. */ static char * -__gethostloop(raddr, salen) - const struct sockaddr *raddr; - socklen_t salen; +__gethostloop(const struct sockaddr *raddr, socklen_t salen) { static char remotehost[NI_MAXHOST]; char h1[NI_MAXHOST], h2[NI_MAXHOST]; @@ -1005,12 +996,12 @@ __gethostloop(raddr, salen) _DIAGASSERT(raddr != NULL); h1[0] = remotehost[0] = '\0'; - if (getnameinfo(raddr, salen, remotehost, sizeof(remotehost), + if (getnameinfo(raddr, salen, remotehost, (socklen_t)sizeof(remotehost), NULL, 0, NI_NAMEREQD) != 0) - return (NULL); - if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0, + return NULL; + if (getnameinfo(raddr, salen, h1, (socklen_t)sizeof(h1), NULL, 0, niflags) != 0) - return (NULL); + return NULL; /* * Look up the name and check that the supplied @@ -1023,16 +1014,16 @@ __gethostloop(raddr, salen) res = NULL; error = getaddrinfo(remotehost, "0", &hints, &res); if (error) - return (NULL); + return NULL; for (r = res; r; r = r->ai_next) { h2[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, sizeof(h2), - NULL, 0, niflags) != 0) + if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, + (socklen_t)sizeof(h2), NULL, 0, niflags) != 0) continue; if (strcmp(h1, h2) == 0) { freeaddrinfo(res); - return (remotehost); + return remotehost; } } @@ -1043,5 +1034,5 @@ __gethostloop(raddr, salen) syslog(LOG_NOTICE, "rcmd: address %s not listed for host %s", h1, res->ai_canonname ? res->ai_canonname : remotehost); freeaddrinfo(res); - return (NULL); + return NULL; } diff --git a/lib/libc/net/recv.c b/lib/libc/net/recv.c index 0b1d5d7bc..deb03d096 100644 --- a/lib/libc/net/recv.c +++ b/lib/libc/net/recv.c @@ -1,4 +1,4 @@ -/* $NetBSD: recv.c,v 1.9 2003/10/22 15:40:19 drochner Exp $ */ +/* $NetBSD: recv.c,v 1.10 2012/03/20 17:44:18 matt Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)recv.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: recv.c,v 1.9 2003/10/22 15:40:19 drochner Exp $"); +__RCSID("$NetBSD: recv.c,v 1.10 2012/03/20 17:44:18 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -44,10 +44,7 @@ __RCSID("$NetBSD: recv.c,v 1.9 2003/10/22 15:40:19 drochner Exp $"); #include ssize_t -recv(s, buf, len, flags) - int s, flags; - size_t len; - void *buf; +recv(int s, void *buf, size_t len, int flags) { return (recvfrom(s, buf, len, flags, NULL, NULL)); } diff --git a/lib/libc/net/rthdr.c b/lib/libc/net/rthdr.c index f008c5898..9517cc0cc 100644 --- a/lib/libc/net/rthdr.c +++ b/lib/libc/net/rthdr.c @@ -1,4 +1,4 @@ -/* $NetBSD: rthdr.c,v 1.17 2009/02/05 23:22:39 lukem Exp $ */ +/* $NetBSD: rthdr.c,v 1.18 2012/03/13 21:13:42 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: rthdr.c,v 1.17 2009/02/05 23:22:39 lukem Exp $"); +__RCSID("$NetBSD: rthdr.c,v 1.18 2012/03/13 21:13:42 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -67,8 +67,7 @@ __weak_alias(inet6_rth_getaddr, _inet6_rth_getaddr) */ size_t -inet6_rthdr_space(type, seg) - int type, seg; +inet6_rthdr_space(int type, int seg) { switch (type) { case IPV6_RTHDR_TYPE_0: @@ -82,9 +81,7 @@ inet6_rthdr_space(type, seg) } struct cmsghdr * -inet6_rthdr_init(bp, type) - void *bp; - int type; +inet6_rthdr_init(void *bp, int type) { struct cmsghdr *ch; struct ip6_rthdr *rthdr; @@ -114,10 +111,7 @@ inet6_rthdr_init(bp, type) } int -inet6_rthdr_add(cmsg, addr, flags) - struct cmsghdr *cmsg; - const struct in6_addr *addr; - u_int flags; +inet6_rthdr_add(struct cmsghdr *cmsg, const struct in6_addr *addr, u_int flags) { struct ip6_rthdr *rthdr; @@ -129,6 +123,7 @@ inet6_rthdr_add(cmsg, addr, flags) switch (rthdr->ip6r_type) { case IPV6_RTHDR_TYPE_0: { + size_t len; struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)(void *)rthdr; if (flags != IPV6_RTHDR_LOOSE && flags != IPV6_RTHDR_STRICT) return (-1); @@ -140,7 +135,9 @@ inet6_rthdr_add(cmsg, addr, flags) (void)memcpy(((caddr_t)(void *)rt0) + ((rt0->ip6r0_len + 1) << 3), addr, sizeof(struct in6_addr)); rt0->ip6r0_len += sizeof(struct in6_addr) >> 3; - cmsg->cmsg_len = CMSG_LEN((rt0->ip6r0_len + 1) << 3); + len = CMSG_LEN((rt0->ip6r0_len + 1) << 3); + _DIAGASSERT(__type_fit(socklen_t, len)); + cmsg->cmsg_len = (socklen_t)len; break; } default: @@ -151,9 +148,7 @@ inet6_rthdr_add(cmsg, addr, flags) } int -inet6_rthdr_lasthop(cmsg, flags) - struct cmsghdr *cmsg; - unsigned int flags; +inet6_rthdr_lasthop(struct cmsghdr *cmsg, unsigned int flags) { struct ip6_rthdr *rthdr; @@ -180,9 +175,7 @@ inet6_rthdr_lasthop(cmsg, flags) #if 0 int -inet6_rthdr_reverse(in, out) - const struct cmsghdr *in; - struct cmsghdr *out; +inet6_rthdr_reverse(const struct cmsghdr *in, struct cmsghdr *out) { return (-1); @@ -190,8 +183,7 @@ inet6_rthdr_reverse(in, out) #endif int -inet6_rthdr_segments(cmsg) - const struct cmsghdr *cmsg; +inet6_rthdr_segments(const struct cmsghdr *cmsg) { const struct ip6_rthdr *rthdr; @@ -204,11 +196,14 @@ inet6_rthdr_segments(cmsg) { const struct ip6_rthdr0 *rt0 = (const struct ip6_rthdr0 *)(const void *)rthdr; + size_t len; if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) return (-1); - return (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + len = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + _DIAGASSERT(__type_fit(int, len)); + return (int)len; } default: @@ -217,9 +212,7 @@ inet6_rthdr_segments(cmsg) } struct in6_addr * -inet6_rthdr_getaddr(cmsg, idx) - struct cmsghdr *cmsg; - int idx; +inet6_rthdr_getaddr(struct cmsghdr *cmsg, int idx) { struct ip6_rthdr *rthdr; @@ -232,10 +225,13 @@ inet6_rthdr_getaddr(cmsg, idx) { struct ip6_rthdr0 *rt0 = (struct ip6_rthdr0 *)(void *)rthdr; int naddr; + size_t len; if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) return NULL; - naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + len = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + _DIAGASSERT(__type_fit(int, len)); + naddr = (int)len; if (idx <= 0 || naddr < idx) return NULL; #ifdef COMPAT_RFC2292 @@ -251,9 +247,7 @@ inet6_rthdr_getaddr(cmsg, idx) } int -inet6_rthdr_getflags(cmsg, idx) - const struct cmsghdr *cmsg; - int idx; +inet6_rthdr_getflags(const struct cmsghdr *cmsg, int idx) { const struct ip6_rthdr *rthdr; @@ -267,10 +261,13 @@ inet6_rthdr_getflags(cmsg, idx) const struct ip6_rthdr0 *rt0 = (const struct ip6_rthdr0 *) (const void *)rthdr; int naddr; + size_t len; if (rt0->ip6r0_len % 2 || 46 < rt0->ip6r0_len) return (-1); - naddr = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + len = (rt0->ip6r0_len * 8) / sizeof(struct in6_addr); + _DIAGASSERT(__type_fit(int, len)); + naddr = (int)len; if (idx < 0 || naddr < idx) return (-1); return IPV6_RTHDR_LOOSE; diff --git a/lib/libc/net/send.c b/lib/libc/net/send.c index 82c000ae8..405970952 100644 --- a/lib/libc/net/send.c +++ b/lib/libc/net/send.c @@ -1,4 +1,4 @@ -/* $NetBSD: send.c,v 1.9 2003/08/07 16:43:15 agc Exp $ */ +/* $NetBSD: send.c,v 1.10 2012/03/20 17:44:18 matt Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)send.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: send.c,v 1.9 2003/08/07 16:43:15 agc Exp $"); +__RCSID("$NetBSD: send.c,v 1.10 2012/03/20 17:44:18 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -55,10 +55,8 @@ __weak_alias(send, _send) #endif /* !__minix */ ssize_t -send(s, msg, len, flags) - int s, flags; - size_t len; - const void *msg; +send(int s, const void *msg, size_t len, int flags) { + return (sendto(s, msg, len, flags, NULL, 0)); } diff --git a/lib/libc/net/sethostent.c b/lib/libc/net/sethostent.c index e96709563..c13f51df9 100644 --- a/lib/libc/net/sethostent.c +++ b/lib/libc/net/sethostent.c @@ -1,4 +1,4 @@ -/* $NetBSD: sethostent.c,v 1.16 2007/01/27 22:27:35 christos Exp $ */ +/* $NetBSD: sethostent.c,v 1.17 2012/03/20 17:44:18 matt Exp $ */ /* * Copyright (c) 1985, 1993 @@ -35,7 +35,7 @@ static char sccsid[] = "@(#)sethostent.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "Id: sethostent.c,v 8.5 1996/09/28 06:51:07 vixie Exp "; #else -__RCSID("$NetBSD: sethostent.c,v 1.16 2007/01/27 22:27:35 christos Exp $"); +__RCSID("$NetBSD: sethostent.c,v 1.17 2012/03/20 17:44:18 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,16 +51,15 @@ __weak_alias(sethostent,_sethostent) __weak_alias(endhostent,_endhostent) #endif -void _endhtent __P((void)); +void _endhtent(void); #ifndef _REENTRANT -void res_close __P((void)); +void res_close(void); #endif -void _sethtent __P((int)); +void _sethtent(int); void /*ARGSUSED*/ -sethostent(stayopen) - int stayopen; +sethostent(int stayopen) { #ifndef _REENTRANT if ((_res.options & RES_INIT) == 0 && res_init() == -1) @@ -72,7 +71,7 @@ sethostent(stayopen) } void -endhostent() +endhostent(void) { #ifndef _REENTRANT _res.options &= ~(RES_STAYOPEN | RES_USEVC); diff --git a/lib/libc/net/sockatmark.c b/lib/libc/net/sockatmark.c index 887c2cead..40bedaa84 100644 --- a/lib/libc/net/sockatmark.c +++ b/lib/libc/net/sockatmark.c @@ -1,4 +1,4 @@ -/* $NetBSD: sockatmark.c,v 1.2 2008/04/28 20:23:00 martin Exp $ */ +/* $NetBSD: sockatmark.c,v 1.3 2012/03/20 17:44:18 matt Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: sockatmark.c,v 1.2 2008/04/28 20:23:00 martin Exp $"); +__RCSID("$NetBSD: sockatmark.c,v 1.3 2012/03/20 17:44:18 matt Exp $"); #endif #include "namespace.h" @@ -42,8 +42,7 @@ __RCSID("$NetBSD: sockatmark.c,v 1.2 2008/04/28 20:23:00 martin Exp $"); #include int -sockatmark(s) - int s; +sockatmark(int s) { int val; diff --git a/lib/libc/nls/Makefile.inc b/lib/libc/nls/Makefile.inc index 18c7e456f..bd74df7bc 100644 --- a/lib/libc/nls/Makefile.inc +++ b/lib/libc/nls/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.10 2009/01/11 02:46:29 christos Exp $ +# $NetBSD: Makefile.inc,v 1.11 2012/01/20 16:31:30 joerg Exp $ .PATH: ${.CURDIR}/nls @@ -8,5 +8,5 @@ MAN+= catclose.3 catgets.3 catopen.3 # indirect reference stubs, to be removed soon. SRCS+= _catclose.c _catgets.c _catopen.c -CPPFLAGS.catopen.c+= -DHAVE_CITRUS -I${LIBCDIR}/citrus +CPPFLAGS.catopen.c+= -I${LIBCDIR}/citrus diff --git a/lib/libc/nls/catclose.c b/lib/libc/nls/catclose.c index 54f6e77c2..f9e2a341c 100644 --- a/lib/libc/nls/catclose.c +++ b/lib/libc/nls/catclose.c @@ -1,4 +1,4 @@ -/* $NetBSD: catclose.c,v 1.13 2008/04/28 20:23:00 martin Exp $ */ +/* $NetBSD: catclose.c,v 1.14 2012/06/25 22:32:45 abs Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: catclose.c,v 1.13 2008/04/28 20:23:00 martin Exp $"); +__RCSID("$NetBSD: catclose.c,v 1.14 2012/06/25 22:32:45 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #define _NLS_PRIVATE @@ -48,8 +48,7 @@ __weak_alias(catclose, _catclose) #endif int -_catclose(catd) - nl_catd catd; +_catclose(nl_catd catd) { if (catd == (nl_catd) -1) { errno = EBADF; diff --git a/lib/libc/nls/catgets.c b/lib/libc/nls/catgets.c index acee17bd0..32eb17c74 100644 --- a/lib/libc/nls/catgets.c +++ b/lib/libc/nls/catgets.c @@ -1,4 +1,4 @@ -/* $NetBSD: catgets.c,v 1.18 2008/04/28 20:23:00 martin Exp $ */ +/* $NetBSD: catgets.c,v 1.19 2012/06/25 22:32:45 abs Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: catgets.c,v 1.18 2008/04/28 20:23:00 martin Exp $"); +__RCSID("$NetBSD: catgets.c,v 1.19 2012/06/25 22:32:45 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #define _NLS_PRIVATE @@ -47,11 +47,7 @@ __weak_alias(catgets, _catgets) #endif char * -_catgets(catd, set_id, msg_id, s) - nl_catd catd; - int set_id; - int msg_id; - const char *s; +_catgets(nl_catd catd, int set_id, int msg_id, const char *s) { struct _nls_cat_hdr *cat_hdr; struct _nls_set_hdr *set_hdr; diff --git a/lib/libc/nls/catopen.c b/lib/libc/nls/catopen.c index 48519debd..839ba28ee 100644 --- a/lib/libc/nls/catopen.c +++ b/lib/libc/nls/catopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: catopen.c,v 1.28 2009/03/10 13:15:40 joerg Exp $ */ +/* $NetBSD: catopen.c,v 1.31 2012/07/30 23:02:41 yamt Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: catopen.c,v 1.28 2009/03/10 13:15:40 joerg Exp $"); +__RCSID("$NetBSD: catopen.c,v 1.31 2012/07/30 23:02:41 yamt Exp $"); #endif /* LIBC_SCCS and not lint */ #define _NLS_PRIVATE @@ -50,15 +50,11 @@ __RCSID("$NetBSD: catopen.c,v 1.28 2009/03/10 13:15:40 joerg Exp $"); #include #include -#ifdef HAVE_CITRUS #include "citrus_namespace.h" #include "citrus_bcs.h" #include "citrus_region.h" #include "citrus_lookup.h" #include "citrus_aliasname_local.h" -#else -#include "aliasname_local.h" -#endif #define NLS_ALIAS_DB "/usr/share/nls/nls.alias" @@ -69,12 +65,10 @@ __RCSID("$NetBSD: catopen.c,v 1.28 2009/03/10 13:15:40 joerg Exp $"); __weak_alias(catopen, _catopen) #endif -static nl_catd load_msgcat __P((const char *)); +static nl_catd load_msgcat(const char *); nl_catd -_catopen(name, oflag) - const char *name; - int oflag; +_catopen(const char *name, int oflag) { char tmppath[PATH_MAX+1]; const char *nlspath; @@ -93,10 +87,13 @@ _catopen(name, oflag) if (issetugid() || (nlspath = getenv("NLSPATH")) == NULL) nlspath = NLS_DEFAULT_PATH; + /* + * histrical note: + * http://www.hauN.org/ml/b-l-j/a/800/828.html (in japanese) + */ if (oflag == NL_CAT_LOCALE) { lang = setlocale(LC_MESSAGES, NULL); - } - else { + } else { lang = getenv("LANG"); } if (lang == NULL || strchr(lang, '/')) @@ -151,8 +148,7 @@ _catopen(name, oflag) } static nl_catd -load_msgcat(path) - const char *path; +load_msgcat(const char *path) { struct stat st; nl_catd catd; diff --git a/lib/libc/quad/Makefile.inc b/lib/libc/quad/Makefile.inc index 62e53c154..9ee8cd195 100644 --- a/lib/libc/quad/Makefile.inc +++ b/lib/libc/quad/Makefile.inc @@ -1,9 +1,9 @@ -# $NetBSD: Makefile.inc,v 1.11 2009/12/06 05:34:42 uebayasi Exp $ +# $NetBSD: Makefile.inc,v 1.14 2012/08/06 08:17:58 matt Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 # Quad support SRCS.quad= cmpdi2.c divdi3.c fixdfdi.c fixsfdi.c fixunsdfdi.c \ - fixunssfdi.c floatdidf.c floatdisf.c floatunsdidf.c \ + fixunssfdi.c floatdidf.c floatdisf.c floatundisf.c floatundidf.c \ moddi3.c muldi3.c negdi2.c qdivrem.c \ ucmpdi2.c udivdi3.c umoddi3.c @@ -11,6 +11,8 @@ SRCS.quad= cmpdi2.c divdi3.c fixdfdi.c fixsfdi.c fixunsdfdi.c \ SRCS.quad+= ashldi3.S ashrdi3.S lshrdi3.S .elif (${MACHINE_ARCH} == "m68000") SRCS.quad+= ashldi3.S lshrdi3.S +.elif (${MACHINE_ARCH} == "earm" || ${MACHINE_ARCH} == "earmeb") +SRCS.quad+= ashrdi3.c lshldi3.c lshrdi3.c .else SRCS.quad+= ashldi3.c ashrdi3.c lshrdi3.c .endif diff --git a/lib/libc/quad/fixdfdi.c b/lib/libc/quad/fixdfdi.c index dd0f17f38..bcb3c1707 100644 --- a/lib/libc/quad/fixdfdi.c +++ b/lib/libc/quad/fixdfdi.c @@ -1,4 +1,4 @@ -/* $NetBSD: fixdfdi.c,v 1.4 2003/08/07 16:43:16 agc Exp $ */ +/* $NetBSD: fixdfdi.c,v 1.6 2012/08/05 04:28:58 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,10 +38,14 @@ #if 0 static char sccsid[] = "@(#)fixdfdi.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fixdfdi.c,v 1.4 2003/08/07 16:43:16 agc Exp $"); +__RCSID("$NetBSD: fixdfdi.c,v 1.6 2012/08/05 04:28:58 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + #include "quad.h" /* @@ -49,8 +53,7 @@ __RCSID("$NetBSD: fixdfdi.c,v 1.4 2003/08/07 16:43:16 agc Exp $"); * We clamp anything that is out of range. */ quad_t -__fixdfdi(x) - double x; +__fixdfdi(double x) { if (x < 0) if (x <= QUAD_MIN) diff --git a/lib/libc/quad/fixsfdi.c b/lib/libc/quad/fixsfdi.c index 56cc03e37..2cb0aa93e 100644 --- a/lib/libc/quad/fixsfdi.c +++ b/lib/libc/quad/fixsfdi.c @@ -1,4 +1,4 @@ -/* $NetBSD: fixsfdi.c,v 1.4 2003/08/07 16:43:16 agc Exp $ */ +/* $NetBSD: fixsfdi.c,v 1.5 2012/08/05 04:28:58 matt Exp $ */ /*- * Copyright (c) 1992 The Regents of the University of California. @@ -38,10 +38,14 @@ #if 0 static char sccsid[] = "@(#)fixsfdi.c 5.1 (Berkeley) 7/7/92"; #else -__RCSID("$NetBSD: fixsfdi.c,v 1.4 2003/08/07 16:43:16 agc Exp $"); +__RCSID("$NetBSD: fixsfdi.c,v 1.5 2012/08/05 04:28:58 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + #include "quad.h" /* diff --git a/lib/libc/quad/fixunsdfdi.c b/lib/libc/quad/fixunsdfdi.c index 7db43a1b5..8f3819619 100644 --- a/lib/libc/quad/fixunsdfdi.c +++ b/lib/libc/quad/fixunsdfdi.c @@ -1,4 +1,4 @@ -/* $NetBSD: fixunsdfdi.c,v 1.7 2003/08/07 16:43:16 agc Exp $ */ +/* $NetBSD: fixunsdfdi.c,v 1.10 2012/08/05 04:28:58 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,13 +38,17 @@ #if 0 static char sccsid[] = "@(#)fixunsdfdi.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fixunsdfdi.c,v 1.7 2003/08/07 16:43:16 agc Exp $"); +__RCSID("$NetBSD: fixunsdfdi.c,v 1.10 2012/08/05 04:28:58 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + #include "quad.h" -#define ONE_FOURTH ((int)1 << (INT_BITS - 2)) +#define ONE_FOURTH ((int)1 << (unsigned int)(INT_BITS - 2)) #define ONE_HALF (ONE_FOURTH * 2.0) #define ONE (ONE_FOURTH * 4.0) @@ -54,8 +58,7 @@ __RCSID("$NetBSD: fixunsdfdi.c,v 1.7 2003/08/07 16:43:16 agc Exp $"); * of range becomes UQUAD_MAX. */ u_quad_t -__fixunsdfdi(x) - double x; +__fixunsdfdi(double x) { union uu t; unsigned int tmp; diff --git a/lib/libc/quad/fixunssfdi.c b/lib/libc/quad/fixunssfdi.c index 21cfc3077..c4f29a45e 100644 --- a/lib/libc/quad/fixunssfdi.c +++ b/lib/libc/quad/fixunssfdi.c @@ -1,4 +1,4 @@ -/* $NetBSD: fixunssfdi.c,v 1.6 2003/08/07 16:43:16 agc Exp $ */ +/* $NetBSD: fixunssfdi.c,v 1.8 2012/08/05 04:28:58 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,13 +38,17 @@ #if 0 static char sccsid[] = "@(#)fixunssfdi.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fixunssfdi.c,v 1.6 2003/08/07 16:43:16 agc Exp $"); +__RCSID("$NetBSD: fixunssfdi.c,v 1.8 2012/08/05 04:28:58 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + #include "quad.h" -#define ONE_FOURTH ((int)1 << (INT_BITS - 2)) +#define ONE_FOURTH ((int)1 << (unsigned int)(INT_BITS - 2)) #define ONE_HALF (ONE_FOURTH * 2.0) #define ONE (ONE_FOURTH * 4.0) diff --git a/lib/libc/quad/floatdidf.c b/lib/libc/quad/floatdidf.c index ff60cb920..1c1278666 100644 --- a/lib/libc/quad/floatdidf.c +++ b/lib/libc/quad/floatdidf.c @@ -1,4 +1,4 @@ -/* $NetBSD: floatdidf.c,v 1.6 2003/08/07 16:43:16 agc Exp $ */ +/* $NetBSD: floatdidf.c,v 1.9 2012/08/05 04:28:58 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,18 +38,21 @@ #if 0 static char sccsid[] = "@(#)floatdidf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: floatdidf.c,v 1.6 2003/08/07 16:43:16 agc Exp $"); +__RCSID("$NetBSD: floatdidf.c,v 1.9 2012/08/05 04:28:58 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + #include "quad.h" /* * Convert (signed) quad to double. */ double -__floatdidf(x) - quad_t x; +__floatdidf(quad_t x) { double d; union uu u; @@ -70,7 +73,7 @@ __floatdidf(x) * code and does not know how to get at an exponent. Machine- * specific code may be able to do this more efficiently. */ - d = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0); + d = (double)u.ul[H] * (((int)1 << (unsigned int)(INT_BITS - 2)) * 4.0); d += u.ul[L]; return (neg ? -d : d); diff --git a/lib/libc/quad/floatdisf.c b/lib/libc/quad/floatdisf.c index 0802fb90c..db71f41ac 100644 --- a/lib/libc/quad/floatdisf.c +++ b/lib/libc/quad/floatdisf.c @@ -1,4 +1,4 @@ -/* $NetBSD: floatdisf.c,v 1.6 2003/08/07 16:43:16 agc Exp $ */ +/* $NetBSD: floatdisf.c,v 1.9 2012/08/05 04:28:58 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,18 +38,21 @@ #if 0 static char sccsid[] = "@(#)floatdisf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: floatdisf.c,v 1.6 2003/08/07 16:43:16 agc Exp $"); +__RCSID("$NetBSD: floatdisf.c,v 1.9 2012/08/05 04:28:58 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + #include "quad.h" /* * Convert (signed) quad to float. */ float -__floatdisf(x) - quad_t x; +__floatdisf(quad_t x) { float f; union uu u; @@ -72,7 +75,7 @@ __floatdisf(x) * * Using double here may be excessive paranoia. */ - f = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0); + f = (double)u.ul[H] * (((int)1 << (unsigned int)(INT_BITS - 2)) * 4.0); f += u.ul[L]; return (neg ? -f : f); diff --git a/lib/libc/quad/floatunsdidf.c b/lib/libc/quad/floatundidf.c similarity index 88% rename from lib/libc/quad/floatunsdidf.c rename to lib/libc/quad/floatundidf.c index 17d8b6ca9..d782527f8 100644 --- a/lib/libc/quad/floatunsdidf.c +++ b/lib/libc/quad/floatundidf.c @@ -1,4 +1,4 @@ -/* $NetBSD: floatunsdidf.c,v 1.6 2003/08/07 16:43:16 agc Exp $ */ +/* $NetBSD: floatundidf.c,v 1.3 2012/08/05 04:28:58 matt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -38,10 +38,14 @@ #if 0 static char sccsid[] = "@(#)floatunsdidf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: floatunsdidf.c,v 1.6 2003/08/07 16:43:16 agc Exp $"); +__RCSID("$NetBSD: floatundidf.c,v 1.3 2012/08/05 04:28:58 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + #include "quad.h" /* @@ -49,14 +53,13 @@ __RCSID("$NetBSD: floatunsdidf.c,v 1.6 2003/08/07 16:43:16 agc Exp $"); * This is exactly like floatdidf.c except that negatives never occur. */ double -__floatunsdidf(x) - u_quad_t x; +__floatundidf(u_quad_t x) { double d; union uu u; u.uq = x; - d = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0); + d = (double)u.ul[H] * (((int)1 << (unsigned int)(INT_BITS - 2)) * 4.0); d += u.ul[L]; return (d); } diff --git a/lib/libc/quad/floatundisf.c b/lib/libc/quad/floatundisf.c new file mode 100644 index 000000000..16dd93ff0 --- /dev/null +++ b/lib/libc/quad/floatundisf.c @@ -0,0 +1,75 @@ +/* $NetBSD: floatundisf.c,v 1.3 2012/08/05 04:28:58 matt Exp $ */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)floatdisf.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: floatundisf.c,v 1.3 2012/08/05 04:28:58 matt Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + +#include "quad.h" + +/* + * Convert (unsigned) quad to float. + */ +float +__floatundisf(u_quad_t x) +{ + float f; + union uu u; + + u.q = x; + + /* + * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L] + * has the units. Ideally we could just set f, add INT_BITS to + * its exponent, and then add the units, but this is portable + * code and does not know how to get at an exponent. Machine- + * specific code may be able to do this more efficiently. + * + * Using double here may be excessive paranoia. + */ + f = (double)u.ul[H] * (((int)1 << (unsigned int)(INT_BITS - 2)) * 4.0); + f += u.ul[L]; + + return f; +} diff --git a/lib/libc/quad/floatunditf_ieee754.c b/lib/libc/quad/floatunditf_ieee754.c new file mode 100644 index 000000000..0d30a9033 --- /dev/null +++ b/lib/libc/quad/floatunditf_ieee754.c @@ -0,0 +1,108 @@ +/* $NetBSD: floatunditf_ieee754.c,v 1.4 2012/08/05 04:28:58 matt Exp $ */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)floatunsdidf.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: floatunditf_ieee754.c,v 1.4 2012/08/05 04:28:58 matt Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#ifdef SOFTFLOAT +#include "softfloat/softfloat-for-gcc.h" +#endif + +#include "quad.h" +#ifdef __vax__ +#error vax does not support a distinct long double +#endif +#include + +/* + * Convert (unsigned) quad to long double. + * This is exactly like floatdidf.c except that negatives never occur. + */ +long double +__floatunditf(u_quad_t x) +{ +#if 0 + long double ld; + union uu u; + + u.uq = x; + ld = (long double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0); + ld += u.ul[L]; + return (ld); +#else + union ieee_ext_u extu; + quad_t tmp = x; /* must be signed */ + unsigned int width = 64; + unsigned int bit = 0; + quad_t mask = ~(quad_t)0; + + if (x == 0) + return 0.0L; + if (x == 1) + return 1.0L; + + while (mask != 0 && (tmp >= 0)) { + width >>= 1; + mask <<= width; + if ((tmp & mask) == 0) { + tmp <<= width; + bit += width; + } + } + + x <<= (bit + 1); + extu.extu_sign = 0; + extu.extu_exp = EXT_EXP_BIAS + (64 - (bit + 1)); + extu.extu_frach = (unsigned int)(x >> (64 - EXT_FRACHBITS)); + x <<= EXT_FRACHBITS; +#ifdef EXT_FRACHMBITS + extu.extu_frachm =(unsigned int)(x >> (64 - EXT_FRACHMBITS)); + x <<= EXT_FRACHMBITS; +#endif +#ifdef EXT_FRACLMBITS + extu.extu_fraclm =(unsigned int)(x >> (64 - EXT_FRACLMBITS)); + x <<= EXT_FRACLMBITS; +#endif + extu.extu_fracl =(unsigned int)(x >> (64 - EXT_FRACLBITS)); + + return extu.extu_ld; +#endif +} diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c index f51ff9cc3..2a800d4ff 100644 --- a/lib/libc/regex/engine.c +++ b/lib/libc/regex/engine.c @@ -1,4 +1,4 @@ -/* $NetBSD: engine.c,v 1.22 2009/02/12 05:06:54 lukem Exp $ */ +/* $NetBSD: engine.c,v 1.24 2012/03/13 21:13:42 christos Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -212,8 +212,8 @@ matcher( /* prescreening; this does wonders for this rather slow code */ if (g->must != NULL) { for (dp = start; dp < stop; dp++) - if (*dp == g->must[0] && stop - dp >= g->mlen && - memcmp(dp, g->must, (size_t)g->mlen) == 0) + if (*dp == g->must[0] && (size_t)(stop - dp) >= g->mlen && + memcmp(dp, g->must, g->mlen) == 0) break; if (dp == stop) /* we didn't find g->must */ return(REG_NOMATCH); @@ -783,7 +783,7 @@ fast( int c = (start == m->beginp) ? OUT : *(start-1); int lastc; /* previous c */ int flagch; - int i; + size_t i; const char *coldp; /* last p after which no match was underway */ _DIAGASSERT(m != NULL); @@ -878,7 +878,7 @@ slow( int c = (start == m->beginp) ? OUT : *(start-1); int lastc; /* previous c */ int flagch; - int i; + size_t i; const char *matchp; /* last p at which a match ended */ _DIAGASSERT(m != NULL); diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index fdaa6ac6f..2644a22de 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -1,4 +1,4 @@ -/* $NetBSD: regcomp.c,v 1.29 2009/02/12 05:06:54 lukem Exp $ */ +/* $NetBSD: regcomp.c,v 1.33 2012/03/13 21:13:43 christos Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -76,7 +76,7 @@ #if 0 static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94"; #else -__RCSID("$NetBSD: regcomp.c,v 1.29 2009/02/12 05:06:54 lukem Exp $"); +__RCSID("$NetBSD: regcomp.c,v 1.33 2012/03/13 21:13:43 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -112,7 +112,7 @@ struct parse { sop *strip; /* malloced strip */ sopno ssize; /* malloced strip size (allocated) */ sopno slen; /* malloced strip length (used) */ - int ncsalloc; /* number of csets allocated */ + size_t ncsalloc; /* number of csets allocated */ struct re_guts *g; # define NPAREN 10 /* we need to remember () 1-9 for back refs */ sopno pbegin[NPAREN]; /* -> ( ([0] unused) */ @@ -125,11 +125,11 @@ extern "C" { #endif /* === regcomp.c === */ -static void p_ere(struct parse *p, int stop); -static void p_ere_exp(struct parse *p); +static void p_ere(struct parse *p, int stop, size_t reclimit); +static void p_ere_exp(struct parse *p, size_t reclimit); static void p_str(struct parse *p); -static void p_bre(struct parse *p, int end1, int end2); -static int p_simp_re(struct parse *p, int starordinary); +static void p_bre(struct parse *p, int end1, int end2, size_t reclimit); +static int p_simp_re(struct parse *p, int starordinary, size_t reclimit); static int p_count(struct parse *p); static void p_bracket(struct parse *p); static void p_b_term(struct parse *p, cset *cs); @@ -141,11 +141,11 @@ static int othercase(int ch); static void bothcases(struct parse *p, int ch); static void ordinary(struct parse *p, int ch); static void nonnewline(struct parse *p); -static void repeat(struct parse *p, sopno start, int from, int to); +static void repeat(struct parse *p, sopno start, int from, int to, size_t reclimit); static int seterr(struct parse *p, int e); static cset *allocset(struct parse *p); static void freeset(struct parse *p, cset *cs); -static int freezeset(struct parse *p, cset *cs); +static sopno freezeset(struct parse *p, cset *cs); static int firstch(struct parse *p, cset *cs); static int nch(struct parse *p, cset *cs); static void mcadd(struct parse *p, cset *cs, const char *cp); @@ -163,7 +163,7 @@ static sopno dupl(struct parse *p, sopno start, sopno finish); static void doemit(struct parse *p, sop op, sopno opnd); static void doinsert(struct parse *p, sop op, sopno opnd, sopno pos); static void dofwd(struct parse *p, sopno pos, sopno value); -static void enlarge(struct parse *p, sopno size); +static int enlarge(struct parse *p, sopno size); static void stripsnug(struct parse *p, struct re_guts *g); static void findmust(struct parse *p, struct re_guts *g); static sopno pluscount(struct parse *p, struct re_guts *g); @@ -211,6 +211,13 @@ static int never = 0; /* for use in asserts; shuts lint up */ #define never 0 /* some s have bugs too */ #endif +#define MEMLIMIT 0x8000000 +#define MEMSIZE(p) \ + ((p)->ncsalloc / CHAR_BIT * (p)->g->csetsize + \ + (p)->ncsalloc * sizeof(cset) + \ + (p)->ssize * sizeof(sop)) +#define RECLIMIT 256 + /* - regcomp - interface for parser and compilation = extern int regcomp(regex_t *, const char *, int); @@ -260,7 +267,7 @@ regcomp( if (g == NULL) return(REG_ESPACE); p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ - p->strip = (sop *)malloc(p->ssize * sizeof(sop)); + p->strip = malloc(p->ssize * sizeof(sop)); p->slen = 0; if (p->strip == NULL) { free(g); @@ -297,11 +304,11 @@ regcomp( EMIT(OEND, 0); g->firststate = THERE(); if (cflags®_EXTENDED) - p_ere(p, OUT); + p_ere(p, OUT, 0); else if (cflags®_NOSPEC) p_str(p); else - p_bre(p, OUT, OUT); + p_bre(p, OUT, OUT, 0); EMIT(OEND, 0); g->laststate = THERE(); @@ -328,12 +335,13 @@ regcomp( /* - p_ere - ERE parser top level, concatenation and alternation - == static void p_ere(struct parse *p, int stop); + == static void p_ere(struct parse *p, int stop, size_t reclimit); */ static void p_ere( struct parse *p, - int stop) /* character this ERE should end at */ + int stop, /* character this ERE should end at */ + size_t reclimit) { char c; sopno prevback = 0; /* pacify gcc */ @@ -343,11 +351,16 @@ p_ere( _DIAGASSERT(p != NULL); + if (reclimit++ > RECLIMIT || p->error == REG_ESPACE) { + p->error = REG_ESPACE; + return; + } + for (;;) { /* do a bunch of concatenated expressions */ conc = HERE(); while (MORE() && (c = PEEK()) != '|' && c != stop) - p_ere_exp(p); + p_ere_exp(p, reclimit); REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */ if (!EAT('|')) @@ -376,11 +389,12 @@ p_ere( /* - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op - == static void p_ere_exp(struct parse *p); + == static void p_ere_exp(struct parse *p, size_t reclimit); */ static void p_ere_exp( - struct parse *p) + struct parse *p, + size_t reclimit) { char c; sopno pos; @@ -404,7 +418,7 @@ p_ere_exp( p->pbegin[subno] = HERE(); EMIT(OLPAREN, subno); if (!SEE(')')) - p_ere(p, ')'); + p_ere(p, ')', reclimit); if (subno < NPAREN) { p->pend[subno] = HERE(); assert(p->pend[subno] != 0); @@ -506,7 +520,7 @@ p_ere_exp( count2 = INFINITY; } else /* just a single number */ count2 = count; - repeat(p, pos, count, count2); + repeat(p, pos, count, count2, 0); if (!EAT('}')) { /* error heuristics */ while (MORE() && PEEK() != '}') NEXT(); @@ -544,7 +558,7 @@ p_str( /* - p_bre - BRE parser top level, anchoring and concatenation == static void p_bre(struct parse *p, int end1, \ - == int end2); + == int end2, size_t reclimit); * Giving end1 as OUT essentially eliminates the end1/end2 check. * * This implementation is a bit of a kludge, in that a trailing $ is first @@ -557,7 +571,8 @@ static void p_bre( struct parse *p, int end1, /* first terminating character */ - int end2) /* second terminating character */ + int end2, /* second terminating character */ + size_t reclimit) { sopno start; int first = 1; /* first subexpression? */ @@ -565,6 +580,11 @@ p_bre( _DIAGASSERT(p != NULL); + if (reclimit++ > RECLIMIT || p->error == REG_ESPACE) { + p->error = REG_ESPACE; + return; + } + start = HERE(); if (EAT('^')) { @@ -573,7 +593,7 @@ p_bre( p->g->nbol++; } while (MORE() && !SEETWO(end1, end2)) { - wasdollar = p_simp_re(p, first); + wasdollar = p_simp_re(p, first, reclimit); first = 0; } if (wasdollar) { /* oops, that was a trailing anchor */ @@ -588,18 +608,18 @@ p_bre( /* - p_simp_re - parse a simple RE, an atom possibly followed by a repetition - == static int p_simp_re(struct parse *p, int starordinary); + == static int p_simp_re(struct parse *p, int starordinary, size_t reclimit); */ static int /* was the simple RE an unbackslashed $? */ p_simp_re( struct parse *p, - int starordinary) /* is a leading * an ordinary character? */ + int starordinary, /* is a leading * an ordinary character? */ + size_t reclimit) { int c; int count; int count2; - sopno pos; - int i; + sopno pos, i; sopno subno; # define BACKSL (1<pend[subno] = HERE(); assert(p->pend[subno] != 0); @@ -693,7 +713,7 @@ p_simp_re( count2 = INFINITY; } else /* just a single number */ count2 = count; - repeat(p, pos, count, count2); + repeat(p, pos, count, count2, 0); if (!EATTWO('\\', '}')) { /* error heuristics */ while (MORE() && !SEETWO('\\', '}')) NEXT(); @@ -741,10 +761,11 @@ p_bracket( { cset *cs; int invert = 0; - _DIAGASSERT(p != NULL); cs = allocset(p); + if (cs == NULL) + return; /* Dept of Truly Sickening Special-Case Kludges */ if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", @@ -776,12 +797,12 @@ p_bracket( return; if (p->g->cflags®_ICASE) { - int i; + ssize_t i; int ci; for (i = p->g->csetsize - 1; i >= 0; i--) if (CHIN(cs, i) && isalpha(i)) { - ci = othercase(i); + ci = othercase((int)i); if (ci != i) CHadd(cs, ci); } @@ -789,13 +810,13 @@ p_bracket( mccase(p, cs); } if (invert) { - int i; + ssize_t i; for (i = p->g->csetsize - 1; i >= 0; i--) if (CHIN(cs, i)) - CHsub(cs, i); + CHsub(cs, (int)i); else - CHadd(cs, i); + CHadd(cs, (int)i); if (p->g->cflags®_NEWLINE) CHsub(cs, '\n'); if (cs->multis != NULL) @@ -1062,9 +1083,12 @@ ordinary( && othercase((unsigned char) ch) != (unsigned char) ch) bothcases(p, (unsigned char) ch); else { - EMIT(OCHAR, (unsigned char)ch); - if (cap[ch] == 0) - cap[ch] = p->g->ncategories++; + EMIT(OCHAR, (sopno)(unsigned char)ch); + if (cap[ch] == 0) { + _DIAGASSERT(__type_fit(unsigned char, + p->g->ncategories + 1)); + cap[ch] = (unsigned char)p->g->ncategories++; + } } } @@ -1101,14 +1125,16 @@ nonnewline( /* - repeat - generate code for a bounded repetition, recursively if needed - == static void repeat(struct parse *p, sopno start, int from, int to); + == static void repeat(struct parse *p, sopno start, int from, int to, + == size_t reclimit); */ static void repeat( struct parse *p, sopno start, /* operand from here to end of strip */ int from, /* repeated from this number */ - int to) /* to this number of times (maybe INFINITY) */ + int to, /* to this number of times (maybe INFINITY) */ + size_t reclimit) { sopno finish; # define N 2 @@ -1119,11 +1145,13 @@ repeat( _DIAGASSERT(p != NULL); - finish = HERE(); - - if (p->error != 0) /* head off possible runaway recursion */ + if (reclimit++ > RECLIMIT) + p->error = REG_ESPACE; + if (p->error) return; + finish = HERE(); + assert(from <= to); switch (REP(MAP(from), MAP(to))) { @@ -1135,7 +1163,7 @@ repeat( case REP(0, INF): /* as x{1,}? */ /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ INSERT(OCH_, start); /* offset is wrong... */ - repeat(p, start+1, 1, to); + repeat(p, start+1, 1, to, reclimit); ASTERN(OOR1, start); AHEAD(start); /* ... fix it */ EMIT(OOR2, 0); @@ -1155,7 +1183,7 @@ repeat( ASTERN(O_CH, THERETHERE()); copy = dupl(p, start+1, finish+1); assert(copy == finish+4); - repeat(p, copy, 1, to-1); + repeat(p, copy, 1, to-1, reclimit); break; case REP(1, INF): /* as x+ */ INSERT(OPLUS_, start); @@ -1163,11 +1191,11 @@ repeat( break; case REP(N, N): /* as xx{m-1,n-1} */ copy = dupl(p, start, finish); - repeat(p, copy, from-1, to-1); + repeat(p, copy, from-1, to-1, reclimit); break; case REP(N, INF): /* as xx{n-1,INF} */ copy = dupl(p, start, finish); - repeat(p, copy, from-1, to); + repeat(p, copy, from-1, to, reclimit); break; default: /* "can't happen" */ SETERROR(REG_ASSERT); /* just in case */ @@ -1202,12 +1230,12 @@ static cset * allocset( struct parse *p) { - int no; + size_t no; size_t nc; size_t nbytes; cset *cs; size_t css; - int i; + size_t i; _DIAGASSERT(p != NULL); @@ -1218,6 +1246,8 @@ allocset( nc = p->ncsalloc; assert(nc % CHAR_BIT == 0); nbytes = nc / CHAR_BIT * css; + if (MEMSIZE(p) > MEMLIMIT) + goto oomem; if (p->g->sets == NULL) p->g->sets = malloc(nc * sizeof(cset)); else @@ -1234,16 +1264,17 @@ allocset( (void) memset((char *)p->g->setbits + (nbytes - css), 0, css); else { +oomem: no = 0; SETERROR(REG_ESPACE); /* caller's responsibility not to do set ops */ + return NULL; } } - assert(p->g->sets != NULL); /* xxx */ cs = &p->g->sets[no]; cs->ptr = p->g->setbits + css*((no)/CHAR_BIT); - cs->mask = 1 << ((no) % CHAR_BIT); + cs->mask = 1 << (unsigned int)((no) % CHAR_BIT); cs->hash = 0; cs->smultis = 0; cs->multis = NULL; @@ -1271,7 +1302,7 @@ freeset( css = (size_t)p->g->csetsize; for (i = 0; i < css; i++) - CHsub(cs, i); + CHsub(cs, (int)i); if (cs == top-1) /* recover only the easy case */ p->g->ncsets--; } @@ -1286,7 +1317,7 @@ freeset( * is done using addition rather than xor -- all ASCII [aA] sets xor to * the same value! */ -static int /* set number */ +static sopno /* set number */ freezeset( struct parse *p, cset *cs) @@ -1320,7 +1351,7 @@ freezeset( cs = cs2; } - return((int)(cs - p->g->sets)); + return (sopno)(cs - p->g->sets); } /* @@ -1527,12 +1558,15 @@ isinsets( int c) { uch *col; - int i; - int ncols; + size_t i; + size_t ncols; unsigned uc = (unsigned char)c; _DIAGASSERT(g != NULL); + if (g->setbits == NULL) + return 0; + ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) @@ -1552,8 +1586,8 @@ samesets( int c2) { uch *col; - int i; - int ncols; + size_t i; + size_t ncols; unsigned uc1 = (unsigned char)c1; unsigned uc2 = (unsigned char)c2; @@ -1592,6 +1626,8 @@ categorize( for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (cats[c] == 0 && isinsets(g, c)) { + _DIAGASSERT(__type_fit(unsigned char, + g->ncategories + 1)); cat = g->ncategories++; cats[c] = cat; for (c2 = c+1; c2 <= CHAR_MAX; c2++) @@ -1620,8 +1656,8 @@ dupl( assert(finish >= start); if (len == 0) return(ret); - enlarge(p, p->ssize + len); /* this many unexpected additions */ - assert(p->ssize >= p->slen + len); + if (!enlarge(p, p->ssize + len))/* this many unexpected additions */ + return ret; (void)memcpy(p->strip + p->slen, p->strip + start, (size_t)len * sizeof(sop)); p->slen += len; @@ -1642,7 +1678,6 @@ doemit( sop op, sopno opnd) { - _DIAGASSERT(p != NULL); /* avoid making error situations worse */ @@ -1654,11 +1689,11 @@ doemit( /* deal with undersized strip */ if (p->slen >= p->ssize) - enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */ - assert(p->slen < p->ssize); + if (!enlarge(p, (p->ssize+1) / 2 * 3)) /* +50% */ + return; /* finally, it's all reduced to the easy case */ - p->strip[p->slen++] = SOP(op, opnd); + p->strip[p->slen++] = (sop)SOP(op, opnd); } /* @@ -1720,32 +1755,39 @@ dofwd( return; assert(value < 1<strip[pos] = OP(p->strip[pos]) | value; + p->strip[pos] = (sop)(OP(p->strip[pos]) | value); } /* - enlarge - enlarge the strip == static void enlarge(struct parse *p, sopno size); */ -static void +static int enlarge( struct parse *p, sopno size) { sop *sp; + sopno osize; _DIAGASSERT(p != NULL); if (p->ssize >= size) - return; + return 1; - sp = (sop *)realloc(p->strip, size*sizeof(sop)); + osize = p->ssize; + p->ssize = size; + if (MEMSIZE(p) > MEMLIMIT) + goto oomem; + sp = realloc(p->strip, p->ssize * sizeof(sop)); if (sp == NULL) { +oomem: + p->ssize = osize; SETERROR(REG_ESPACE); - return; + return 0; } p->strip = sp; - p->ssize = size; + return 1; } /* diff --git a/lib/libc/regex/regex.3 b/lib/libc/regex/regex.3 index dae8e173b..78ae7eaa1 100644 --- a/lib/libc/regex/regex.3 +++ b/lib/libc/regex/regex.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: regex.3,v 1.21 2010/03/22 19:30:54 joerg Exp $ +.\" $NetBSD: regex.3,v 1.22 2011/05/17 03:35:38 enami Exp $ .\" .\" Copyright (c) 1992, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -394,11 +394,11 @@ and if the error code came from it should have been the result from the most recent .Fn regcomp using that -.Fa regex_t . ( -.Fn regerror +.Fa regex_t . +.Po Fn regerror may be able to supply a more detailed message using information from the -.Fa regex_t . ) +.Fa regex_t . Pc .Fn regerror places the NUL-terminated message into the buffer pointed to by .Fa errbuf , diff --git a/lib/libc/regex/regex2.h b/lib/libc/regex/regex2.h index 0fdbe74c4..7c877ee87 100644 --- a/lib/libc/regex/regex2.h +++ b/lib/libc/regex/regex2.h @@ -1,4 +1,4 @@ -/* $NetBSD: regex2.h,v 1.12 2009/02/12 05:06:54 lukem Exp $ */ +/* $NetBSD: regex2.h,v 1.13 2011/10/09 18:23:00 christos Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -110,7 +110,7 @@ * immediately *preceding* "execution" of that operator. */ typedef u_int32_t sop; /* strip operator */ -typedef int sopno; +typedef size_t sopno; #define OPRMASK ((u_int32_t)0xf8000000UL) #define OPDMASK ((u_int32_t)0x07ffffffUL) #define OPSHIFT ((unsigned)27) @@ -179,8 +179,8 @@ struct re_guts { int magic; # define MAGIC2 ((('R'^0200)<<8)|'E') sop *strip; /* malloced area for strip */ - int csetsize; /* number of bits in a cset vector */ - int ncsets; /* number of csets in use */ + size_t csetsize; /* number of bits in a cset vector */ + size_t ncsets; /* number of csets in use */ cset *sets; /* -> cset [ncsets] */ uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */ int cflags; /* copy of regcomp() cflags argument */ @@ -191,12 +191,12 @@ struct re_guts { # define USEBOL 01 /* used ^ */ # define USEEOL 02 /* used $ */ # define BAD 04 /* something wrong */ - int nbol; /* number of ^ used */ - int neol; /* number of $ used */ - int ncategories; /* how many character categories */ + size_t nbol; /* number of ^ used */ + size_t neol; /* number of $ used */ + size_t ncategories; /* how many character categories */ cat_t *categories; /* ->catspace[-CHAR_MIN] */ char *must; /* match must contain this string */ - int mlen; /* length of must */ + size_t mlen; /* length of must */ size_t nsub; /* copy of re_nsub */ int backrefs; /* does it use back references? */ sopno nplus; /* how deep does it nest +s? */ diff --git a/lib/libc/regex/regexec.c b/lib/libc/regex/regexec.c index d0e10842f..f16e0b6b4 100644 --- a/lib/libc/regex/regexec.c +++ b/lib/libc/regex/regexec.c @@ -1,4 +1,4 @@ -/* $NetBSD: regexec.c,v 1.21 2009/02/12 05:06:54 lukem Exp $ */ +/* $NetBSD: regexec.c,v 1.22 2012/03/13 21:13:43 christos Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -76,7 +76,7 @@ #if 0 static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94"; #else -__RCSID("$NetBSD: regexec.c,v 1.21 2009/02/12 05:06:54 lukem Exp $"); +__RCSID("$NetBSD: regexec.c,v 1.22 2012/03/13 21:13:43 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -171,7 +171,7 @@ __weak_alias(regexec,_regexec) #define STATETEARDOWN(m) { free((m)->space); m->space = NULL; } #define SETUP(v) ((v) = &m->space[(size_t)(m->vn++ * m->g->nstates)]) #define onestate int -#define INIT(o, n) ((o) = (n)) +#define INIT(o, n) ((o) = (int)(n)) #define INC(o) ((o)++) #define ISSTATEIN(v, o) ((v)[o]) /* some abbreviations; note that some of these know variable names! */ diff --git a/lib/libc/resolv/herror.c b/lib/libc/resolv/herror.c index a1f0010dd..7a81af37d 100644 --- a/lib/libc/resolv/herror.c +++ b/lib/libc/resolv/herror.c @@ -1,4 +1,4 @@ -/* $NetBSD: herror.c,v 1.8 2009/04/12 17:07:17 christos Exp $ */ +/* $NetBSD: herror.c,v 1.9 2012/03/13 21:13:43 christos Exp $ */ /* * Copyright (c) 1987, 1993 @@ -56,7 +56,7 @@ static const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; static const char rcsid[] = "Id: herror.c,v 1.4 2005/04/27 04:56:41 sra Exp"; #else -__RCSID("$NetBSD: herror.c,v 1.8 2009/04/12 17:07:17 christos Exp $"); +__RCSID("$NetBSD: herror.c,v 1.9 2012/03/13 21:13:43 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -121,7 +121,7 @@ herror(const char *s) { DE_CONST("\n", t); v->iov_base = t; v->iov_len = 1; - writev(STDERR_FILENO, iov, (v - iov) + 1); + (void)writev(STDERR_FILENO, iov, (int)((v - iov) + 1)); } /*% diff --git a/lib/libc/resolv/res_comp.c b/lib/libc/resolv/res_comp.c index 216ad1078..b7a89b3a5 100644 --- a/lib/libc/resolv/res_comp.c +++ b/lib/libc/resolv/res_comp.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_comp.c,v 1.10 2009/04/12 17:07:17 christos Exp $ */ +/* $NetBSD: res_comp.c,v 1.12 2012/03/13 21:13:43 christos Exp $ */ /* * Copyright (c) 1985, 1993 @@ -75,7 +75,7 @@ static const char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; static const char rcsid[] = "Id: res_comp.c,v 1.5 2005/07/28 06:51:50 marka Exp"; #else -__RCSID("$NetBSD: res_comp.c,v 1.10 2009/04/12 17:07:17 christos Exp $"); +__RCSID("$NetBSD: res_comp.c,v 1.12 2012/03/13 21:13:43 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -86,6 +86,7 @@ __RCSID("$NetBSD: res_comp.c,v 1.10 2009/04/12 17:07:17 christos Exp $"); #include #include #include +#include #include #include #include @@ -135,8 +136,8 @@ dn_comp(const char *src, u_char *dst, int dstsiz, u_char **dnptrs, u_char **lastdnptr) { return (ns_name_compress(src, dst, (size_t)dstsiz, - (const u_char **)dnptrs, - (const u_char **)lastdnptr)); + (void *)dnptrs, + (void *)lastdnptr)); } /*% @@ -148,7 +149,8 @@ dn_skipname(const u_char *ptr, const u_char *eom) { if (ns_name_skip(&ptr, eom) == -1) return (-1); - return (ptr - saveptr); + _DIAGASSERT(__type_fit(int, ptr - saveptr)); + return (int)(ptr - saveptr); } /*% diff --git a/lib/libc/resolv/res_debug.c b/lib/libc/resolv/res_debug.c index 4d9ec37dc..0b3af8643 100644 --- a/lib/libc/resolv/res_debug.c +++ b/lib/libc/resolv/res_debug.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_debug.c,v 1.11 2009/04/12 17:07:17 christos Exp $ */ +/* $NetBSD: res_debug.c,v 1.13 2012/06/25 22:32:45 abs Exp $ */ /* * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC") @@ -101,7 +101,7 @@ static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; static const char rcsid[] = "Id: res_debug.c,v 1.19 2009/02/26 11:20:20 tbox Exp"; #else -__RCSID("$NetBSD: res_debug.c,v 1.11 2009/04/12 17:07:17 christos Exp $"); +__RCSID("$NetBSD: res_debug.c,v 1.13 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -116,6 +116,7 @@ __RCSID("$NetBSD: res_debug.c,v 1.11 2009/04/12 17:07:17 christos Exp $"); #include #include +#include #include #include #include @@ -176,7 +177,7 @@ do_section(const res_state statp, /* * Print answer records. */ - sflag = (statp->pfcode & pflag); + sflag = (int)(statp->pfcode & pflag); if (statp->pfcode && !sflag) return; @@ -207,11 +208,14 @@ do_section(const res_state statp, p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr))); else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) { - u_int16_t optcode, optlen, rdatalen = ns_rr_rdlen(rr); - u_int32_t ttl = ns_rr_ttl(rr); + size_t rdatalen, ttl; + uint16_t optcode, optlen; + + rdatalen = ns_rr_rdlen(rr); + ttl = ns_rr_ttl(rr); fprintf(file, - "; EDNS: version: %u, udp=%u, flags=%04x\n", + "; EDNS: version: %zu, udp=%u, flags=%04zx\n", (ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff); while (rdatalen >= 4) { @@ -368,7 +372,7 @@ p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) { char name[MAXDNAME]; int n; - if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0) + if ((n = dn_expand(msg, msg + len, cp, name, (int)sizeof name)) < 0) return (NULL); if (name[0] == '\0') putc('.', file); @@ -387,19 +391,17 @@ p_cdname(const u_char *cp, const u_char *msg, FILE *file) { length supplied). */ const u_char * -p_fqnname(cp, msg, msglen, name, namelen) - const u_char *cp, *msg; - int msglen; - char *name; - int namelen; +p_fqnname(const u_char *cp, const u_char *msg, int msglen, char *name, + int namelen) { - int n, newlen; + int n; + size_t newlen; if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0) return (NULL); newlen = strlen(name); if (newlen == 0 || name[newlen - 1] != '.') { - if (newlen + 1 >= namelen) /*%< Lack space for final dot */ + if ((int)newlen + 1 >= namelen) /*%< Lack space for final dot */ return (NULL); else strcpy(name + newlen, "."); @@ -414,7 +416,7 @@ p_fqname(const u_char *cp, const u_char *msg, FILE *file) { char name[MAXDNAME]; const u_char *n; - n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name); + n = p_fqnname(cp, msg, MAXCDNAME, name, (int)sizeof name); if (n == NULL) return (NULL); fputs(name, file); @@ -749,7 +751,7 @@ p_sockun(union res_sockaddr_union u, char *buf, size_t size) { switch (u.sin.sin_family) { case AF_INET: - inet_ntop(AF_INET, &u.sin.sin_addr, ret, sizeof ret); + inet_ntop(AF_INET, &u.sin.sin_addr, ret, (socklen_t)sizeof ret); break; #ifdef HAS_INET6_STRUCTS case AF_INET6: @@ -931,9 +933,7 @@ latlon2ul(const char **latlonstrptr, int *which) { * converts a zone file representation in a string to an RDATA on-the-wire * representation. */ int -loc_aton(ascii, binary) - const char *ascii; - u_char *binary; +loc_aton(const char *ascii, u_char *binary) { const char *cp, *maxcp; u_char *bcp; @@ -1042,9 +1042,7 @@ loc_aton(ascii, binary) /*% takes an on-the-wire LOC RR and formats it in a human readable format. */ const char * -loc_ntoa(binary, ascii) - const u_char *binary; - char *ascii; +loc_ntoa(const u_char *binary, char *ascii) { static const char *error = "?"; static char tmpbuf[sizeof @@ -1153,7 +1151,7 @@ loc_ntoa(binary, ascii) /*% Return the number of DNS hierarchy levels in the name. */ int dn_count_labels(const char *name) { - int i, len, count; + size_t len, i, count; len = strlen(name); for (i = 0, count = 0; i < len; i++) { @@ -1172,7 +1170,8 @@ dn_count_labels(const char *name) { /* count to include last label */ if (len > 0 && name[len-1] != '.') count++; - return (count); + _DIAGASSERT(__type_fit(int, count)); + return (int)count; } /*% diff --git a/lib/libc/resolv/res_debug.h b/lib/libc/resolv/res_debug.h index dc7e96ab0..b3231f825 100644 --- a/lib/libc/resolv/res_debug.h +++ b/lib/libc/resolv/res_debug.h @@ -1,4 +1,4 @@ -/* $NetBSD: res_debug.h,v 1.1.1.4 2009/04/12 16:35:47 christos Exp $ */ +/* $NetBSD: res_debug.h,v 1.2 2012/03/13 21:13:43 christos Exp $ */ /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -29,7 +29,7 @@ # define Dprint(cond, args) if (cond) {fprintf args;} else {} # define DprintQ(cond, args, query, size) if (cond) {\ fprintf args;\ - res_pquery(statp, query, size, stdout);\ + res_pquery(statp, (query), (int)(size), stdout);\ } else {} #endif diff --git a/lib/libc/resolv/res_init.c b/lib/libc/resolv/res_init.c index a3e65b92b..30bc904f8 100644 --- a/lib/libc/resolv/res_init.c +++ b/lib/libc/resolv/res_init.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_init.c,v 1.22 2009/10/24 17:24:01 christos Exp $ */ +/* $NetBSD: res_init.c,v 1.26 2012/09/09 18:04:26 christos Exp $ */ /* * Copyright (c) 1985, 1989, 1993 @@ -76,7 +76,7 @@ static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; static const char rcsid[] = "Id: res_init.c,v 1.26 2008/12/11 09:59:00 marka Exp"; #else -__RCSID("$NetBSD: res_init.c,v 1.22 2009/10/24 17:24:01 christos Exp $"); +__RCSID("$NetBSD: res_init.c,v 1.26 2012/09/09 18:04:26 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -149,12 +149,12 @@ __weak_alias(res_setservers,__res_setservers) #include #endif -static void res_setoptions __P((res_state, const char *, const char *)); +static void res_setoptions(res_state, const char *, const char *); #ifdef RESOLVSORT static const char sort_mask[] = "/&"; #define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL) -static u_int32_t net_mask __P((struct in_addr)); +static uint32_t net_mask(struct in_addr); #endif #if !defined(isascii) /*%< XXX - could be a function */ @@ -348,14 +348,14 @@ __res_vinit(res_state statp, int preinit) { line[sizeof(name) - 1] == '\t')) nserv = 0; - if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { + if ((fp = fopen(_PATH_RESCONF, "re")) != NULL) { struct stat st; #ifndef __minix struct kevent kc; #endif /* !__minix */ /* read the config file */ - while (fgets(buf, sizeof(buf), fp) != NULL) { + while (fgets(buf, (int)sizeof(buf), fp) != NULL) { /* skip comments */ if (*buf == ';' || *buf == '#') continue; @@ -507,9 +507,7 @@ __res_vinit(res_state statp, int preinit) { __res_conf_time = statp->_u._ext.ext->res_conf_time = st.st_mtimespec; #ifndef __minix - statp->_u._ext.ext->kq = kqueue(); - (void)fcntl(statp->_u._ext.ext->kq, F_SETFD, FD_CLOEXEC); - (void)fcntl(statp->_u._ext.ext->resfd, F_SETFD, FD_CLOEXEC); + statp->_u._ext.ext->kq = kqueue1(O_CLOEXEC); EV_SET(&kc, statp->_u._ext.ext->resfd, EVFILT_VNODE, EV_ADD|EV_ENABLE|EV_CLEAR, NOTE_DELETE|NOTE_WRITE| NOTE_EXTEND| NOTE_ATTRIB|NOTE_LINK|NOTE_RENAME|NOTE_REVOKE, 0, 0); @@ -615,6 +613,7 @@ res_setoptions(res_state statp, const char *options, const char *source) { const char *cp = options; int i; + size_t j; struct __res_state_ext *ext = statp->_u._ext.ext; #ifdef DEBUG @@ -694,6 +693,9 @@ res_setoptions(res_state statp, const char *options, const char *source) } else if (!strncmp(cp, "no-check-names", sizeof("no-check-names") - 1)) { statp->options |= RES_NOCHECKNAME; + } else if (!strncmp(cp, "check-names", + sizeof("check-names") - 1)) { + statp->options &= ~RES_NOCHECKNAME; } #ifdef RES_USE_EDNS0 else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) { @@ -707,17 +709,17 @@ res_setoptions(res_state statp, const char *options, const char *source) if (ext == NULL) goto skip; cp += sizeof("nibble:") - 1; - i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1); - strncpy(ext->nsuffix, cp, (size_t)i); - ext->nsuffix[i] = '\0'; + j = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1); + strncpy(ext->nsuffix, cp, j); + ext->nsuffix[j] = '\0'; } else if (!strncmp(cp, "nibble2:", sizeof("nibble2:") - 1)) { if (ext == NULL) goto skip; cp += sizeof("nibble2:") - 1; - i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix2) - 1); - strncpy(ext->nsuffix2, cp, (size_t)i); - ext->nsuffix2[i] = '\0'; + j = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix2) - 1); + strncpy(ext->nsuffix2, cp, j); + ext->nsuffix2[j] = '\0'; } else if (!strncmp(cp, "v6revmode:", sizeof("v6revmode:") - 1)) { cp += sizeof("v6revmode:") - 1; @@ -741,11 +743,10 @@ res_setoptions(res_state statp, const char *options, const char *source) #ifdef RESOLVSORT /* XXX - should really support CIDR which means explicit masks always. */ -static u_int32_t -net_mask(in) /*!< XXX - should really use system's version of this */ - struct in_addr in; +static uint32_t +net_mask(struct in_addr in) /*!< XXX - should really use system's version of this */ { - register u_int32_t i = ntohl(in.s_addr); + register uint32_t i = ntohl(in.s_addr); if (IN_CLASSA(i)) return (htonl(IN_CLASSA_NET)); @@ -761,30 +762,31 @@ void res_rndinit(res_state statp) { struct timeval now; - u_int32_t u32; - u_int16_t u16; + uint32_t u32; + uint16_t u16; u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd; gettimeofday(&now, NULL); - u32 = (u_int32_t)now.tv_sec; + u32 = (uint32_t)now.tv_sec; memcpy(rnd, &u32, 4); u32 = now.tv_usec; memcpy(rnd + 4, &u32, 4); - u32 += (u_int32_t)now.tv_sec; + u32 += (uint32_t)now.tv_sec; memcpy(rnd + 8, &u32, 4); u16 = getpid(); memcpy(rnd + 12, &u16, 2); } u_int -res_nrandomid(res_state statp) { +res_nrandomid(res_state statp) +{ struct timeval now; - u_int16_t u16; + uint16_t u16; MD5_CTX ctx; u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd; gettimeofday(&now, NULL); - u16 = (u_int16_t) (now.tv_sec ^ now.tv_usec); + u16 = (uint16_t) (now.tv_sec ^ now.tv_usec); memcpy(rnd + 14, &u16, 2); #ifndef HAVE_MD5 MD5_Init(&ctx); @@ -807,7 +809,8 @@ res_nrandomid(res_state statp) { * This routine is not expected to be user visible. */ void -res_nclose(res_state statp) { +res_nclose(res_state statp) +{ int ns; if (statp->_vcsock >= 0) { @@ -824,7 +827,8 @@ res_nclose(res_state statp) { } void -res_ndestroy(res_state statp) { +res_ndestroy(res_state statp) +{ res_nclose(statp); if (statp->_u._ext.ext != NULL) { if (statp->_u._ext.ext->kq != -1) @@ -842,21 +846,24 @@ res_ndestroy(res_state statp) { } const char * -res_get_nibblesuffix(res_state statp) { +res_get_nibblesuffix(res_state statp) +{ if (statp->_u._ext.ext) return (statp->_u._ext.ext->nsuffix); return ("ip6.arpa"); } const char * -res_get_nibblesuffix2(res_state statp) { +res_get_nibblesuffix2(res_state statp) +{ if (statp->_u._ext.ext) return (statp->_u._ext.ext->nsuffix2); return ("ip6.int"); } void -res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt) { +res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt) +{ int i, nserv; size_t size; @@ -907,10 +914,11 @@ res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt) { } int -res_getservers(res_state statp, union res_sockaddr_union *set, int cnt) { +res_getservers(res_state statp, union res_sockaddr_union *set, int cnt) +{ int i; size_t size; - u_int16_t family; + uint16_t family; for (i = 0; i < statp->nscount && i < cnt; i++) { if (statp->_u._ext.ext) diff --git a/lib/libc/resolv/res_mkquery.c b/lib/libc/resolv/res_mkquery.c index 43b951396..494452380 100644 --- a/lib/libc/resolv/res_mkquery.c +++ b/lib/libc/resolv/res_mkquery.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_mkquery.c,v 1.12 2009/04/12 19:43:37 christos Exp $ */ +/* $NetBSD: res_mkquery.c,v 1.13 2012/03/13 21:13:43 christos Exp $ */ /* * Portions Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") @@ -76,7 +76,7 @@ static const char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; static const char rcsid[] = "Id: res_mkquery.c,v 1.10 2008/12/11 09:59:00 marka Exp"; #else -__RCSID("$NetBSD: res_mkquery.c,v 1.12 2009/04/12 19:43:37 christos Exp $"); +__RCSID("$NetBSD: res_mkquery.c,v 1.13 2012/03/13 21:13:43 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -87,6 +87,7 @@ __RCSID("$NetBSD: res_mkquery.c,v 1.12 2009/04/12 19:43:37 christos Exp $"); #include #include #include +#include #include #include #include @@ -160,7 +161,7 @@ res_nmkquery(res_state statp, case NS_NOTIFY_OP: if (ep - cp < QFIXEDSZ) return (-1); - if ((n = dn_comp(dname, cp, ep - cp - QFIXEDSZ, dnptrs, + if ((n = dn_comp(dname, cp, (int)(ep - cp - QFIXEDSZ), dnptrs, lastdnptr)) < 0) return (-1); cp += n; @@ -176,7 +177,7 @@ res_nmkquery(res_state statp, */ if ((ep - cp) < RRFIXEDSZ) return (-1); - n = dn_comp((const char *)data, cp, ep - cp - RRFIXEDSZ, + n = dn_comp((const char *)data, cp, (int)(ep - cp - RRFIXEDSZ), dnptrs, lastdnptr); if (n < 0) return (-1); @@ -217,7 +218,8 @@ res_nmkquery(res_state statp, default: return (-1); } - return (cp - buf); + _DIAGASSERT(__type_fit(int, cp - buf)); + return (int)(cp - buf); } #ifdef RES_USE_EDNS0 @@ -269,7 +271,8 @@ res_nopt(res_state statp, hp->arcount = htons(ntohs(hp->arcount) + 1); - return (cp - buf); + _DIAGASSERT(__type_fit(int, cp - buf)); + return (int)(cp - buf); } /* @@ -312,10 +315,12 @@ res_nopt_rdata(res_state statp, memcpy(cp, data, (size_t)len); cp += len; - len = cp - rdata; + _DIAGASSERT(__type_fit(u_short, cp - rdata)); + len = (u_short)(cp - rdata); ns_put16(len, rdata - 2); /* Update RDLEN field */ - return (cp - buf); + _DIAGASSERT(__type_fit(int, cp - buf)); + return (int)(cp - buf); } #endif diff --git a/lib/libc/resolv/res_query.c b/lib/libc/resolv/res_query.c index c264efb49..9e0a4052d 100644 --- a/lib/libc/resolv/res_query.c +++ b/lib/libc/resolv/res_query.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_query.c,v 1.13 2009/10/24 21:37:57 christos Exp $ */ +/* $NetBSD: res_query.c,v 1.14 2012/03/13 21:13:44 christos Exp $ */ /* * Portions Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") @@ -93,7 +93,7 @@ static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; static const char rcsid[] = "Id: res_query.c,v 1.11 2008/11/14 02:36:51 marka Exp"; #else -__RCSID("$NetBSD: res_query.c,v 1.13 2009/10/24 21:37:57 christos Exp $"); +__RCSID("$NetBSD: res_query.c,v 1.14 2012/03/13 21:13:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -168,15 +168,15 @@ again: #endif n = res_nmkquery(statp, QUERY, name, class, type, NULL, 0, NULL, - buf, sizeof(buf)); + buf, (int)sizeof(buf)); #ifdef RES_USE_EDNS0 if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 && (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC|RES_NSID)) != 0U) { - n = res_nopt(statp, n, buf, sizeof(buf), anslen); + n = res_nopt(statp, n, buf, (int)sizeof(buf), anslen); rdata = &buf[n]; if (n > 0 && (statp->options & RES_NSID) != 0U) { - n = res_nopt_rdata(statp, n, buf, sizeof(buf), rdata, - NS_OPT_NSID, 0, NULL); + n = res_nopt_rdata(statp, n, buf, (int)sizeof(buf), + rdata, NS_OPT_NSID, 0, NULL); } } #endif @@ -402,7 +402,7 @@ res_nquerydomain(res_state statp, { char nbuf[MAXDNAME]; const char *longname = nbuf; - int n, d; + size_t n, d; #ifdef DEBUG if (statp->options & RES_DEBUG) @@ -419,9 +419,8 @@ res_nquerydomain(res_state statp, RES_SET_H_ERRNO(statp, NO_RECOVERY); return (-1); } - n--; - if (n >= 0 && name[n] == '.') { - strncpy(nbuf, name, (size_t)n); + if (n && name[--n] == '.') { + strncpy(nbuf, name, n); nbuf[n] = '\0'; } else longname = name; @@ -455,7 +454,7 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { if (file == NULL || (fp = fopen(file, "r")) == NULL) return (NULL); buf[sizeof(buf) - 1] = '\0'; - while (fgets(buf, sizeof(buf), fp)) { + while (fgets(buf, (int)sizeof(buf), fp)) { for (cp1 = buf; *cp1 && !isspace((unsigned char)*cp1); ++cp1) ; if (!*cp1) diff --git a/lib/libc/resolv/res_send.c b/lib/libc/resolv/res_send.c index 8e8bbb193..8b6fdbfa9 100644 --- a/lib/libc/resolv/res_send.c +++ b/lib/libc/resolv/res_send.c @@ -1,4 +1,4 @@ -/* $NetBSD: res_send.c,v 1.20 2009/10/24 17:24:01 christos Exp $ */ +/* $NetBSD: res_send.c,v 1.25 2012/03/21 00:34:54 christos Exp $ */ /* * Portions Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC") @@ -93,7 +93,7 @@ static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; static const char rcsid[] = "Id: res_send.c,v 1.22 2009/01/22 23:49:23 tbox Exp"; #else -__RCSID("$NetBSD: res_send.c,v 1.20 2009/10/24 17:24:01 christos Exp $"); +__RCSID("$NetBSD: res_send.c,v 1.25 2012/03/21 00:34:54 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -116,6 +116,7 @@ __RCSID("$NetBSD: res_send.c,v 1.20 2009/10/24 17:24:01 christos Exp $"); #include #include +#include #include #include #include @@ -157,14 +158,12 @@ __weak_alias(res_nsend,__res_nsend) #ifndef USE_POLL static const int highestFD = FD_SETSIZE - 1; -#else -static int highestFD = 0; #endif /* Forward. */ -static int get_salen __P((const struct sockaddr *)); -static struct sockaddr * get_nsaddr __P((res_state, size_t)); +static int get_salen(const struct sockaddr *); +static struct sockaddr * get_nsaddr(res_state, size_t); static int send_vc(res_state, const u_char *, int, u_char *, int, int *, int); static int send_dg(res_state, const u_char *, int, @@ -261,7 +260,7 @@ res_nameinquery(const char *name, int type, int class, char tname[MAXDNAME+1]; int n, ttype, tclass; - n = dn_expand(buf, eom, cp, tname, sizeof tname); + n = dn_expand(buf, eom, cp, tname, (int)sizeof tname); if (n < 0) return (-1); cp += n; @@ -312,7 +311,7 @@ res_queriesmatch(const u_char *buf1, const u_char *eom1, char tname[MAXDNAME+1]; int n, ttype, tclass; - n = dn_expand(buf1, eom1, cp, tname, sizeof tname); + n = dn_expand(buf1, eom1, cp, tname, (int)sizeof tname); if (n < 0) return (-1); cp += n; @@ -333,10 +332,6 @@ res_nsend(res_state statp, int gotsomewhere, terrno, tries, v_circuit, resplen, ns, n; char abuf[NI_MAXHOST]; -#ifdef USE_POLL - highestFD = sysconf(_SC_OPEN_MAX) - 1; -#endif - (void)res_check(statp, NULL); /* No name servers or res_init() failure */ @@ -484,8 +479,8 @@ res_nsend(res_state statp, } Dprint(((statp->options & RES_DEBUG) && - getnameinfo(nsap, (socklen_t)nsaplen, abuf, sizeof(abuf), - NULL, 0, niflags) == 0), + getnameinfo(nsap, (socklen_t)nsaplen, abuf, + (socklen_t)sizeof(abuf), NULL, 0, niflags) == 0), (stdout, ";; Querying server (# %d) address = %s\n", ns + 1, abuf)); @@ -582,8 +577,7 @@ res_nsend(res_state statp, /* Private */ static int -get_salen(sa) - const struct sockaddr *sa; +get_salen(const struct sockaddr *sa) { #ifdef HAVE_SA_LEN @@ -604,9 +598,7 @@ get_salen(sa) * pick appropriate nsaddr_list for use. see res_init() for initialization. */ static struct sockaddr * -get_nsaddr(statp, n) - res_state statp; - size_t n; +get_nsaddr(res_state statp, size_t n) { if (!statp->nsaddr_list[n].sin_family && EXT(statp).ext) { @@ -635,7 +627,8 @@ send_vc(res_state statp, HEADER *anhp = (HEADER *)(void *)ans; struct sockaddr *nsap; int nsaplen; - int truncating, connreset, resplen, n; + int truncating, connreset, resplen; + ssize_t n; struct iovec iov[2]; u_short len; u_char *cp; @@ -669,10 +662,12 @@ send_vc(res_state statp, res_nclose(statp); statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0); +#ifndef USE_POLL if (statp->_vcsock > highestFD) { res_nclose(statp); errno = ENOTSOCK; } +#endif if (statp->_vcsock < 0) { switch (errno) { case EPROTONOSUPPORT: @@ -697,7 +692,7 @@ send_vc(res_state statp, * Push on even if setsockopt(SO_NOSIGPIPE) fails. */ (void)setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on, - sizeof(on)); + (unsigned int)sizeof(on)); #endif errno = 0; if (connect(statp->_vcsock, nsap, (socklen_t)nsaplen) < 0) { @@ -731,7 +726,7 @@ send_vc(res_state statp, len = INT16SZ; while ((n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0) { cp += n; - if ((len -= n) == 0) + if ((len -= (u_short)n) == 0) break; } if (n <= 0) { @@ -777,7 +772,7 @@ send_vc(res_state statp, cp = ans; while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (size_t)len)) > 0){ cp += n; - len -= n; + len -= (u_short)n; } if (n <= 0) { *terrno = errno; @@ -797,7 +792,7 @@ send_vc(res_state statp, n = read(statp->_vcsock, junk, (len > sizeof junk) ? sizeof junk : len); if (n > 0) - len -= n; + len -= (u_short)n; else break; } @@ -836,7 +831,8 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, struct timespec now, timeout, finish; struct sockaddr_storage from; ISC_SOCKLEN_T fromlen; - int resplen, seconds, n, s; + ssize_t resplen; + int seconds, n, s; #ifdef USE_POLL int polltimeout; struct pollfd pollfd; @@ -848,10 +844,12 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, nsaplen = get_salen(nsap); if (EXT(statp).nssocks[ns] == -1) { EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM, 0); +#ifndef USE_POLL if (EXT(statp).nssocks[ns] > highestFD) { res_nclose(statp); errno = ENOTSOCK; } +#endif if (EXT(statp).nssocks[ns] < 0) { switch (errno) { case EPROTONOSUPPORT: @@ -914,7 +912,7 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, if (seconds <= 0) seconds = 1; now = evNowTime(); - timeout = evConsTime((long)seconds, 0L); + timeout = evConsTime((time_t)seconds, 0L); finish = evAddTime(now, timeout); goto nonow; wait: @@ -931,7 +929,7 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, #else timeout = evSubTime(finish, now); if (timeout.tv_sec < 0) - timeout = evConsTime(0L, 0L); + timeout = evConsTime((time_t)0, 0L); polltimeout = 1000*(int)timeout.tv_sec + (int)timeout.tv_nsec/1000000; pollfd.fd = s; @@ -970,7 +968,7 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, * Undersized message. */ Dprint(statp->options & RES_DEBUG, - (stdout, ";; undersized: %d\n", + (stdout, ";; undersized: %zd\n", resplen)); *terrno = EMSGSIZE; res_nclose(statp); @@ -1028,7 +1026,7 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, DprintQ((statp->options & RES_DEBUG) || (statp->pfcode & RES_PRF_REPLY), (stdout, ";; wrong query name:\n"), - ans, (resplen > anssiz) ? anssiz : resplen); + ans, (int)(resplen > anssiz) ? anssiz : resplen); goto wait; } if (anhp->rcode == SERVFAIL || @@ -1036,7 +1034,7 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, anhp->rcode == REFUSED) { DprintQ(statp->options & RES_DEBUG, (stdout, "server rejected query:\n"), - ans, (resplen > anssiz) ? anssiz : resplen); + ans, (int)(resplen > anssiz) ? anssiz : resplen); res_nclose(statp); /* don't retry if called from dig */ if (!statp->pfcode) @@ -1057,7 +1055,8 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, * All is well, or the error is fatal. Signal that the * next nameserver ought not be tried. */ - return (resplen); + _DIAGASSERT(__type_fit(int, resplen)); + return (int)resplen; } static void @@ -1069,8 +1068,9 @@ Aerror(const res_state statp, FILE *file, const char *string, int error, char sbuf[NI_MAXSERV]; if ((statp->options & RES_DEBUG) != 0U) { - if (getnameinfo(address, (socklen_t)alen, hbuf, sizeof(hbuf), - sbuf, sizeof(sbuf), niflags)) { + if (getnameinfo(address, (socklen_t)alen, hbuf, + (socklen_t)sizeof(hbuf), sbuf, (socklen_t)sizeof(sbuf), + niflags)) { strncpy(hbuf, "?", sizeof(hbuf) - 1); hbuf[sizeof(hbuf) - 1] = '\0'; strncpy(sbuf, "?", sizeof(sbuf) - 1); diff --git a/lib/libc/rpc/Makefile.inc b/lib/libc/rpc/Makefile.inc index 9bb274fb8..4648a78f9 100644 --- a/lib/libc/rpc/Makefile.inc +++ b/lib/libc/rpc/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.17 2008/10/25 19:07:26 mrg Exp $ +# $NetBSD: Makefile.inc,v 1.21 2012/08/10 12:20:10 joerg Exp $ # librpc sources .PATH: ${.CURDIR}/rpc @@ -14,7 +14,7 @@ SRCS+= auth_none.c auth_unix.c authunix_prot.c bindresvport.c \ svc.c svc_auth.c svc_dg.c svc_auth_unix.c svc_generic.c svc_raw.c \ svc_run.c svc_simple.c svc_vc.c \ xdr.c xdr_array.c xdr_float.c xdr_mem.c xdr_rec.c xdr_reference.c \ - xdr_stdio.c __rpc_getxid.c + xdr_stdio.c xdr_sizeof.c __rpc_getxid.c CPPFLAGS+= -DPORTMAP @@ -157,6 +157,7 @@ MLINKS+= bindresvport.3 bindresvport_sa.3 \ xdr.3 xdr_reference.3 \ xdr.3 xdr_setpos.3 \ xdr.3 xdr_short.3 \ + xdr.3 xdr_sizeof.3 \ xdr.3 xdrstdio_create.3 \ xdr.3 xdr_string.3 \ xdr.3 xdr_u_char.3 \ @@ -166,3 +167,8 @@ MLINKS+= bindresvport.3 bindresvport_sa.3 \ xdr.3 xdr_vector.3 \ xdr.3 xdr_void.3 \ xdr.3 xdr_wrapstring.3 + +# XXX +.if ${HAVE_GCC:U} == 45 || ${MACHINE} == "vax" +COPTS.xdr_float.c+= -fno-strict-aliasing +.endif diff --git a/lib/libc/rpc/auth_none.c b/lib/libc/rpc/auth_none.c index 46f739e1c..547963414 100644 --- a/lib/libc/rpc/auth_none.c +++ b/lib/libc/rpc/auth_none.c @@ -1,4 +1,4 @@ -/* $NetBSD: auth_none.c,v 1.14 2001/01/16 15:46:52 lukem Exp $ */ +/* $NetBSD: auth_none.c,v 1.15 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: auth_none.c,v 1.14 2001/01/16 15:46:52 lukem Exp $"); +__RCSID("$NetBSD: auth_none.c,v 1.15 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -66,11 +66,11 @@ __weak_alias(authnone_create,_authnone_create) * Authenticator operations routines */ -static bool_t authnone_marshal __P((AUTH *, XDR *)); -static void authnone_verf __P((AUTH *)); -static bool_t authnone_validate __P((AUTH *, struct opaque_auth *)); -static bool_t authnone_refresh __P((AUTH *)); -static void authnone_destroy __P((AUTH *)); +static bool_t authnone_marshal(AUTH *, XDR *); +static void authnone_verf(AUTH *); +static bool_t authnone_validate(AUTH *, struct opaque_auth *); +static bool_t authnone_refresh(AUTH *); +static void authnone_destroy(AUTH *); static const struct auth_ops ops = { authnone_verf, @@ -87,7 +87,7 @@ static struct authnone_private { } *authnone_private; AUTH * -authnone_create() +authnone_create(void) { struct authnone_private *ap = authnone_private; XDR xdr_stream; @@ -115,9 +115,7 @@ authnone_create() /*ARGSUSED*/ static bool_t -authnone_marshal(client, xdrs) - AUTH *client; - XDR *xdrs; +authnone_marshal(AUTH *client, XDR *xdrs) { struct authnone_private *ap = authnone_private; @@ -131,16 +129,13 @@ authnone_marshal(client, xdrs) /*ARGSUSED*/ static void -authnone_verf(client) - AUTH *client; +authnone_verf(AUTH *client) { } /*ARGSUSED*/ static bool_t -authnone_validate(client, auth) - AUTH *client; - struct opaque_auth *auth; +authnone_validate(AUTH *client, struct opaque_auth *auth) { return (TRUE); @@ -148,8 +143,7 @@ authnone_validate(client, auth) /*ARGSUSED*/ static bool_t -authnone_refresh(client) - AUTH *client; +authnone_refresh(AUTH *client) { return (FALSE); @@ -157,7 +151,6 @@ authnone_refresh(client) /*ARGSUSED*/ static void -authnone_destroy(client) - AUTH *client; +authnone_destroy(AUTH *client) { } diff --git a/lib/libc/rpc/auth_unix.c b/lib/libc/rpc/auth_unix.c index 8792eb32c..8e3f3ab4e 100644 --- a/lib/libc/rpc/auth_unix.c +++ b/lib/libc/rpc/auth_unix.c @@ -1,4 +1,4 @@ -/* $NetBSD: auth_unix.c,v 1.22 2009/01/11 02:46:29 christos Exp $ */ +/* $NetBSD: auth_unix.c,v 1.23 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)auth_unix.c 1.19 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)auth_unix.c 2.2 88/08/01 4.0 RPCSRC"; #else -__RCSID("$NetBSD: auth_unix.c,v 1.22 2009/01/11 02:46:29 christos Exp $"); +__RCSID("$NetBSD: auth_unix.c,v 1.23 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -74,13 +74,13 @@ __weak_alias(authunix_create_default,_authunix_create_default) /* auth_unix.c */ -static void authunix_nextverf __P((AUTH *)); -static bool_t authunix_marshal __P((AUTH *, XDR *)); -static bool_t authunix_validate __P((AUTH *, struct opaque_auth *)); -static bool_t authunix_refresh __P((AUTH *)); -static void authunix_destroy __P((AUTH *)); -static void marshal_new_auth __P((AUTH *)); -static const struct auth_ops *authunix_ops __P((void)); +static void authunix_nextverf(AUTH *); +static bool_t authunix_marshal(AUTH *, XDR *); +static bool_t authunix_validate(AUTH *, struct opaque_auth *); +static bool_t authunix_refresh(AUTH *); +static void authunix_destroy(AUTH *); +static void marshal_new_auth(AUTH *); +static const struct auth_ops *authunix_ops(void); /* * This struct is pointed to by the ah_private field of an auth_handle. @@ -99,12 +99,7 @@ struct audata { * Returns an auth handle with the given stuff in it. */ AUTH * -authunix_create(machname, uid, gid, len, aup_gids) - char *machname; - int uid; - int gid; - int len; - int *aup_gids; +authunix_create(char *machname, int uid, int gid, int len, int *aup_gids) { struct authunix_parms aup; char mymem[MAX_AUTH_BYTES]; @@ -190,7 +185,7 @@ authunix_create(machname, uid, gid, len, aup_gids) * syscalls. */ AUTH * -authunix_create_default() +authunix_create_default(void) { int len; char machname[MAXHOSTNAMELEN + 1]; @@ -216,16 +211,13 @@ authunix_create_default() /* ARGSUSED */ static void -authunix_nextverf(auth) - AUTH *auth; +authunix_nextverf(AUTH *auth) { /* no action necessary */ } static bool_t -authunix_marshal(auth, xdrs) - AUTH *auth; - XDR *xdrs; +authunix_marshal(AUTH *auth, XDR *xdrs) { struct audata *au; @@ -237,9 +229,7 @@ authunix_marshal(auth, xdrs) } static bool_t -authunix_validate(auth, verf) - AUTH *auth; - struct opaque_auth *verf; +authunix_validate(AUTH *auth, struct opaque_auth *verf) { struct audata *au; XDR xdrs; @@ -271,8 +261,7 @@ authunix_validate(auth, verf) } static bool_t -authunix_refresh(auth) - AUTH *auth; +authunix_refresh(AUTH *auth) { struct audata *au = AUTH_PRIVATE(auth); struct authunix_parms aup; @@ -316,8 +305,7 @@ done: } static void -authunix_destroy(auth) - AUTH *auth; +authunix_destroy(AUTH *auth) { struct audata *au; @@ -342,8 +330,7 @@ authunix_destroy(auth) * sets private data, au_marshed and au_mpos */ static void -marshal_new_auth(auth) - AUTH *auth; +marshal_new_auth(AUTH *auth) { XDR xdr_stream; XDR *xdrs = &xdr_stream; @@ -362,7 +349,7 @@ marshal_new_auth(auth) } static const struct auth_ops * -authunix_ops() +authunix_ops(void) { static struct auth_ops ops; #ifdef _REENTRANT diff --git a/lib/libc/rpc/authunix_prot.c b/lib/libc/rpc/authunix_prot.c index b90e3134a..578e50de5 100644 --- a/lib/libc/rpc/authunix_prot.c +++ b/lib/libc/rpc/authunix_prot.c @@ -1,4 +1,4 @@ -/* $NetBSD: authunix_prot.c,v 1.13 2006/05/11 17:11:57 mrg Exp $ */ +/* $NetBSD: authunix_prot.c,v 1.15 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)authunix_prot.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: authunix_prot.c,v 1.13 2006/05/11 17:11:57 mrg Exp $"); +__RCSID("$NetBSD: authunix_prot.c,v 1.15 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -63,9 +63,7 @@ __weak_alias(xdr_authunix_parms,_xdr_authunix_parms) * XDR for unix authentication parameters. */ bool_t -xdr_authunix_parms(xdrs, p) - XDR *xdrs; - struct authunix_parms *p; +xdr_authunix_parms(XDR *xdrs, struct authunix_parms *p) { _DIAGASSERT(xdrs != NULL); @@ -76,7 +74,8 @@ xdr_authunix_parms(xdrs, p) && xdr_int(xdrs, &(p->aup_uid)) && xdr_int(xdrs, &(p->aup_gid)) && xdr_array(xdrs, (char **)(void *)&(p->aup_gids), - &(p->aup_len), NGRPS, sizeof(int), (xdrproc_t)xdr_int) ) { + &(p->aup_len), NGRPS, (unsigned int)sizeof(int), + (xdrproc_t)xdr_int) ) { return (TRUE); } return (FALSE); diff --git a/lib/libc/rpc/bindresvport.c b/lib/libc/rpc/bindresvport.c index 1c8dc3eb4..b233310cc 100644 --- a/lib/libc/rpc/bindresvport.c +++ b/lib/libc/rpc/bindresvport.c @@ -1,4 +1,4 @@ -/* $NetBSD: bindresvport.c,v 1.21 2003/01/18 11:29:03 thorpej Exp $ */ +/* $NetBSD: bindresvport.c,v 1.23 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)bindresvport.c 1.8 88/02/08 SMI"; static char *sccsid = "@(#)bindresvport.c 2.2 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: bindresvport.c,v 1.21 2003/01/18 11:29:03 thorpej Exp $"); +__RCSID("$NetBSD: bindresvport.c,v 1.23 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -65,9 +65,7 @@ __weak_alias(bindresvport_sa,_bindresvport_sa) * Bind a socket to a privileged IP port */ int -bindresvport(sd, brsin) - int sd; - struct sockaddr_in *brsin; +bindresvport(int sd, struct sockaddr_in *brsin) { return bindresvport_sa(sd, (struct sockaddr *)(void *)brsin); } @@ -76,9 +74,7 @@ bindresvport(sd, brsin) * Bind a socket to a privileged IP port */ int -bindresvport_sa(sd, sa) - int sd; - struct sockaddr *sa; +bindresvport_sa(int sd, struct sockaddr *sa) { int error, old; struct sockaddr_storage myaddr; @@ -136,7 +132,7 @@ bindresvport_sa(sd, sa) if (error < 0) return (error); error = setsockopt(sd, proto, portrange, &portlow, - sizeof(portlow)); + (socklen_t)sizeof(portlow)); if (error < 0) return (error); } @@ -148,7 +144,7 @@ bindresvport_sa(sd, sa) if (error < 0) { if (setsockopt(sd, proto, portrange, &old, - sizeof(old)) < 0) + (socklen_t)sizeof(old)) < 0) errno = saved_errno; return (error); } diff --git a/lib/libc/rpc/clnt_bcast.c b/lib/libc/rpc/clnt_bcast.c index a70f411c8..e08fcae0b 100644 --- a/lib/libc/rpc/clnt_bcast.c +++ b/lib/libc/rpc/clnt_bcast.c @@ -1,4 +1,4 @@ -/* $NetBSD: clnt_bcast.c,v 1.22 2010/03/07 23:49:14 dholland Exp $ */ +/* $NetBSD: clnt_bcast.c,v 1.24 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)clnt_bcast.c 1.15 89/04/21 Copyr 1988 Sun Micro"; #else -__RCSID("$NetBSD: clnt_bcast.c,v 1.22 2010/03/07 23:49:14 dholland Exp $"); +__RCSID("$NetBSD: clnt_bcast.c,v 1.24 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -122,9 +122,9 @@ struct broadif { typedef TAILQ_HEAD(, broadif) broadlist_t; -int __rpc_getbroadifs __P((int, int, int, broadlist_t *)); -void __rpc_freebroadifs __P((broadlist_t *)); -int __rpc_broadenable __P((int, int, struct broadif *)); +int __rpc_getbroadifs(int, int, int, broadlist_t *); +void __rpc_freebroadifs(broadlist_t *); +int __rpc_broadenable(int, int, struct broadif *); int __rpc_lowvers = 0; @@ -234,7 +234,8 @@ __rpc_broadenable(int af, int s, struct broadif *bip) return -1; } else #endif - if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, sizeof o) < 0) + if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &o, + (socklen_t)sizeof(o)) == -1) return -1; return 0; @@ -242,19 +243,18 @@ __rpc_broadenable(int af, int s, struct broadif *bip) enum clnt_stat -rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, - eachresult, inittime, waittime, nettype) - rpcprog_t prog; /* program number */ - rpcvers_t vers; /* version number */ - rpcproc_t proc; /* procedure number */ - xdrproc_t xargs; /* xdr routine for args */ - const char * argsp; /* pointer to args */ - xdrproc_t xresults; /* xdr routine for results */ - caddr_t resultsp; /* pointer to results */ - resultproc_t eachresult; /* call with each result obtained */ - int inittime; /* how long to wait initially */ - int waittime; /* maximum time to wait */ - const char *nettype; /* transport type */ +rpc_broadcast_exp( + rpcprog_t prog, /* program number */ + rpcvers_t vers, /* version number */ + rpcproc_t proc, /* procedure number */ + xdrproc_t xargs, /* xdr routine for args */ + const char * argsp, /* pointer to args */ + xdrproc_t xresults, /* xdr routine for results */ + caddr_t resultsp, /* pointer to results */ + resultproc_t eachresult, /* call with each result obtained */ + int inittime, /* how long to wait initially */ + int waittime, /* maximum time to wait */ + const char * nettype) /* transport type */ { enum clnt_stat stat = RPC_SUCCESS; /* Return status */ XDR xdr_stream; /* XDR stream */ @@ -282,7 +282,7 @@ rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, broadlist_t nal; } fdlist[MAXBCAST]; struct pollfd pfd[MAXBCAST]; - size_t fdlistno = 0; + nfds_t fdlistno = 0; struct r_rpcb_rmtcallargs barg; /* Remote arguments */ struct r_rpcb_rmtcallres bres; /* Remote results */ size_t outlen; @@ -469,7 +469,7 @@ rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, if (!__rpc_lowvers) if ((size_t)sendto(fdlist[i].fd, outbuf, outlen, 0, (struct sockaddr*)addr, - (size_t)fdlist[i].asize) != + (socklen_t)fdlist[i].asize) != outlen) { warn("clnt_bcast: cannot send" " broadcast packet"); @@ -491,7 +491,7 @@ rpc_broadcast_exp(prog, vers, proc, xargs, argsp, xresults, resultsp, fdlist[i].proto == IPPROTO_UDP) { if ((size_t)sendto(fdlist[i].fd, outbuf_pmap, outlen_pmap, 0, addr, - (size_t)fdlist[i].asize) != + (socklen_t)fdlist[i].asize) != outlen_pmap) { warnx("clnt_bcast: " "Cannot send " @@ -665,17 +665,16 @@ done_broad: enum clnt_stat -rpc_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, - eachresult, nettype) - rpcprog_t prog; /* program number */ - rpcvers_t vers; /* version number */ - rpcproc_t proc; /* procedure number */ - xdrproc_t xargs; /* xdr routine for args */ - const char * argsp; /* pointer to args */ - xdrproc_t xresults; /* xdr routine for results */ - caddr_t resultsp; /* pointer to results */ - resultproc_t eachresult; /* call with each result obtained */ - const char *nettype; /* transport type */ +rpc_broadcast( + rpcprog_t prog, /* program number */ + rpcvers_t vers, /* version number */ + rpcproc_t proc, /* procedure number */ + xdrproc_t xargs, /* xdr routine for args */ + const char * argsp, /* pointer to args */ + xdrproc_t xresults, /* xdr routine for results */ + caddr_t resultsp, /* pointer to results */ + resultproc_t eachresult, /* call with each result obtained */ + const char * nettype) /* transport type */ { enum clnt_stat dummy; diff --git a/lib/libc/rpc/clnt_dg.c b/lib/libc/rpc/clnt_dg.c index d077878a0..0fd1983c6 100644 --- a/lib/libc/rpc/clnt_dg.c +++ b/lib/libc/rpc/clnt_dg.c @@ -1,4 +1,4 @@ -/* $NetBSD: clnt_dg.c,v 1.24 2010/12/08 02:06:38 joerg Exp $ */ +/* $NetBSD: clnt_dg.c,v 1.26 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)clnt_dg.c 1.19 89/03/16 Copyr 1988 Sun Micro"; #else -__RCSID("$NetBSD: clnt_dg.c,v 1.24 2010/12/08 02:06:38 joerg Exp $"); +__RCSID("$NetBSD: clnt_dg.c,v 1.26 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -71,15 +71,15 @@ __weak_alias(clnt_dg_create,_clnt_dg_create) #define RPC_MAX_BACKOFF 30 /* seconds */ -static struct clnt_ops *clnt_dg_ops __P((void)); -static bool_t time_not_ok __P((struct timeval *)); -static enum clnt_stat clnt_dg_call __P((CLIENT *, rpcproc_t, xdrproc_t, - const char *, xdrproc_t, caddr_t, struct timeval)); -static void clnt_dg_geterr __P((CLIENT *, struct rpc_err *)); -static bool_t clnt_dg_freeres __P((CLIENT *, xdrproc_t, caddr_t)); -static void clnt_dg_abort __P((CLIENT *)); -static bool_t clnt_dg_control __P((CLIENT *, u_int, char *)); -static void clnt_dg_destroy __P((CLIENT *)); +static struct clnt_ops *clnt_dg_ops(void); +static bool_t time_not_ok(struct timeval *); +static enum clnt_stat clnt_dg_call(CLIENT *, rpcproc_t, xdrproc_t, + const char *, xdrproc_t, caddr_t, struct timeval); +static void clnt_dg_geterr(CLIENT *, struct rpc_err *); +static bool_t clnt_dg_freeres(CLIENT *, xdrproc_t, caddr_t); +static void clnt_dg_abort(CLIENT *); +static bool_t clnt_dg_control(CLIENT *, u_int, char *); +static void clnt_dg_destroy(CLIENT *); @@ -153,13 +153,13 @@ struct cu_data { * If svcaddr is NULL, returns NULL. */ CLIENT * -clnt_dg_create(fd, svcaddr, program, version, sendsz, recvsz) - int fd; /* open file descriptor */ - const struct netbuf *svcaddr; /* servers address */ - rpcprog_t program; /* program number */ - rpcvers_t version; /* version number */ - u_int sendsz; /* buffer recv size */ - u_int recvsz; /* buffer send size */ +clnt_dg_create( + int fd, /* open file descriptor */ + const struct netbuf *svcaddr, /* servers address */ + rpcprog_t program, /* program number */ + rpcvers_t version, /* version number */ + u_int sendsz, /* buffer recv size */ + u_int recvsz) /* buffer send size */ { CLIENT *cl = NULL; /* client handle */ struct cu_data *cu = NULL; /* private data */ @@ -299,14 +299,14 @@ err2: } static enum clnt_stat -clnt_dg_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout) - CLIENT *cl; /* client handle */ - rpcproc_t proc; /* procedure number */ - xdrproc_t xargs; /* xdr routine for args */ - const char * argsp; /* pointer to args */ - xdrproc_t xresults; /* xdr routine for results */ - caddr_t resultsp; /* pointer to results */ - struct timeval utimeout; /* seconds to wait before giving up */ +clnt_dg_call( + CLIENT * cl, /* client handle */ + rpcproc_t proc, /* procedure number */ + xdrproc_t xargs, /* xdr routine for args */ + const char * argsp, /* pointer to args */ + xdrproc_t xresults, /* xdr routine for results */ + caddr_t resultsp, /* pointer to results */ + struct timeval utimeout) /* seconds to wait before giving up */ { struct cu_data *cu; XDR *xdrs; @@ -415,12 +415,12 @@ send_again: cu->cu_error.re_status = RPC_CANTRECV; goto out; } - if (recvlen >= (ssize_t)sizeof(uint32_t) && - (*((uint32_t *)(void *)(cu->cu_inbuf)) == - *((uint32_t *)(void *)(cu->cu_outbuf)))) { - /* We now assume we have the proper reply. */ - break; - } + if (recvlen >= (ssize_t)sizeof(uint32_t)) { + if (memcmp(cu->cu_inbuf, cu->cu_outbuf, + sizeof(uint32_t)) == 0) + /* Assume we have the proper reply. */ + break; + } } if (n == -1) { cu->cu_error.re_errno = errno; @@ -497,9 +497,7 @@ out: } static void -clnt_dg_geterr(cl, errp) - CLIENT *cl; - struct rpc_err *errp; +clnt_dg_geterr(CLIENT *cl, struct rpc_err *errp) { struct cu_data *cu; @@ -511,10 +509,7 @@ clnt_dg_geterr(cl, errp) } static bool_t -clnt_dg_freeres(cl, xdr_res, res_ptr) - CLIENT *cl; - xdrproc_t xdr_res; - caddr_t res_ptr; +clnt_dg_freeres(CLIENT *cl, xdrproc_t xdr_res, caddr_t res_ptr) { struct cu_data *cu; XDR *xdrs; @@ -543,16 +538,12 @@ clnt_dg_freeres(cl, xdr_res, res_ptr) /*ARGSUSED*/ static void -clnt_dg_abort(h) - CLIENT *h; +clnt_dg_abort(CLIENT *h) { } static bool_t -clnt_dg_control(cl, request, info) - CLIENT *cl; - u_int request; - char *info; +clnt_dg_control(CLIENT *cl, u_int request, char *info) { struct cu_data *cu; struct netbuf *addr; @@ -692,8 +683,7 @@ clnt_dg_control(cl, request, info) } static void -clnt_dg_destroy(cl) - CLIENT *cl; +clnt_dg_destroy(CLIENT *cl) { struct cu_data *cu; int cu_fd; @@ -727,7 +717,7 @@ clnt_dg_destroy(cl) } static struct clnt_ops * -clnt_dg_ops() +clnt_dg_ops(void) { static struct clnt_ops ops; #ifdef _REENTRANT @@ -758,8 +748,7 @@ clnt_dg_ops() * Make sure that the time is not garbage. -1 value is allowed. */ static bool_t -time_not_ok(t) - struct timeval *t; +time_not_ok(struct timeval *t) { _DIAGASSERT(t != NULL); diff --git a/lib/libc/rpc/clnt_generic.c b/lib/libc/rpc/clnt_generic.c index 79fb9f8e5..d46c65d99 100644 --- a/lib/libc/rpc/clnt_generic.c +++ b/lib/libc/rpc/clnt_generic.c @@ -1,4 +1,4 @@ -/* $NetBSD: clnt_generic.c,v 1.27 2008/04/25 17:44:44 christos Exp $ */ +/* $NetBSD: clnt_generic.c,v 1.28 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)clnt_generic.c 1.32 89/03/16 Copyr 1988 Sun Micro"; #else -__RCSID("$NetBSD: clnt_generic.c,v 1.27 2008/04/25 17:44:44 christos Exp $"); +__RCSID("$NetBSD: clnt_generic.c,v 1.28 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -72,13 +72,13 @@ __weak_alias(clnt_tli_create,_clnt_tli_create) * if this can not be done. */ CLIENT * -clnt_create_vers(hostname, prog, vers_out, vers_low, vers_high, nettype) - const char *hostname; - rpcprog_t prog; - rpcvers_t *vers_out; - rpcvers_t vers_low; - rpcvers_t vers_high; - const char *nettype; +clnt_create_vers( + const char * hostname, + rpcprog_t prog, + rpcvers_t * vers_out, + rpcvers_t vers_low, + rpcvers_t vers_high, + const char * nettype) { CLIENT *clnt; struct timeval to; @@ -145,11 +145,11 @@ error: * It calls clnt_tp_create(); */ CLIENT * -clnt_create(hostname, prog, vers, nettype) - const char *hostname; /* server name */ - rpcprog_t prog; /* program number */ - rpcvers_t vers; /* version number */ - const char *nettype; /* net type */ +clnt_create( + const char * hostname, /* server name */ + rpcprog_t prog, /* program number */ + rpcvers_t vers, /* version number */ + const char * nettype) /* net type */ { struct netconfig *nconf; CLIENT *clnt = NULL; @@ -218,11 +218,11 @@ clnt_create(hostname, prog, vers, nettype) * It finds out the server address from rpcbind and calls clnt_tli_create() */ CLIENT * -clnt_tp_create(hostname, prog, vers, nconf) - const char *hostname; /* server name */ - rpcprog_t prog; /* program number */ - rpcvers_t vers; /* version number */ - const struct netconfig *nconf; /* net config struct */ +clnt_tp_create( + const char * hostname, /* server name */ + rpcprog_t prog, /* program number */ + rpcvers_t vers, /* version number */ + const struct netconfig *nconf) /* net config struct */ { struct netbuf *svcaddr; /* servers address */ CLIENT *cl = NULL; /* client handle */ @@ -284,14 +284,14 @@ out: * If sizes are 0; appropriate defaults will be chosen. */ CLIENT * -clnt_tli_create(fd, nconf, svcaddr, prog, vers, sendsz, recvsz) - int fd; /* fd */ - const struct netconfig *nconf; /* netconfig structure */ - const struct netbuf *svcaddr; /* servers address */ - rpcprog_t prog; /* program number */ - rpcvers_t vers; /* version number */ - u_int sendsz; /* send size */ - u_int recvsz; /* recv size */ +clnt_tli_create( + int fd, /* fd */ + const struct netconfig *nconf, /* netconfig structure */ + const struct netbuf *svcaddr, /* servers address */ + rpcprog_t prog, /* program number */ + rpcvers_t vers, /* version number */ + u_int sendsz, /* send size */ + u_int recvsz) /* recv size */ { CLIENT *cl; /* client handle */ bool_t madefd = FALSE; /* whether fd opened here */ diff --git a/lib/libc/rpc/clnt_perror.c b/lib/libc/rpc/clnt_perror.c index 005f1d7ed..5b73552c4 100644 --- a/lib/libc/rpc/clnt_perror.c +++ b/lib/libc/rpc/clnt_perror.c @@ -1,4 +1,4 @@ -/* $NetBSD: clnt_perror.c,v 1.28 2008/04/25 17:44:44 christos Exp $ */ +/* $NetBSD: clnt_perror.c,v 1.29 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: clnt_perror.c,v 1.28 2008/04/25 17:44:44 christos Exp $"); +__RCSID("$NetBSD: clnt_perror.c,v 1.29 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -69,11 +69,11 @@ __weak_alias(clnt_sperror,_clnt_sperror) static char *buf; static size_t buflen; -static char *_buf __P((void)); -static char *auth_errmsg __P((enum auth_stat)); +static char *_buf(void); +static char *auth_errmsg(enum auth_stat); static char * -_buf() +_buf(void) { buflen = 256; @@ -86,9 +86,7 @@ _buf() * Print reply error info */ char * -clnt_sperror(rpch, s) - CLIENT *rpch; - const char *s; +clnt_sperror(CLIENT *rpch, const char *s) { struct rpc_err e; char *err; @@ -179,9 +177,7 @@ clnt_sperror(rpch, s) } void -clnt_perror(rpch, s) - CLIENT *rpch; - const char *s; +clnt_perror(CLIENT *rpch, const char *s) { _DIAGASSERT(rpch != NULL); @@ -222,8 +218,7 @@ static const char *const rpc_errlist[] = { * This interface for use by clntrpc */ char * -clnt_sperrno(stat) - enum clnt_stat stat; +clnt_sperrno(enum clnt_stat stat) { unsigned int errnum = stat; const char *msg; @@ -239,16 +234,14 @@ clnt_sperrno(stat) } void -clnt_perrno(num) - enum clnt_stat num; +clnt_perrno(enum clnt_stat num) { (void) fprintf(stderr, "%s\n", clnt_sperrno(num)); } char * -clnt_spcreateerror(s) - const char *s; +clnt_spcreateerror(const char *s) { char *str; size_t len, i; @@ -298,8 +291,7 @@ clnt_spcreateerror(s) } void -clnt_pcreateerror(s) - const char *s; +clnt_pcreateerror(const char *s) { _DIAGASSERT(s != NULL); @@ -319,12 +311,11 @@ static const char *const auth_errlist[] = { }; static char * -auth_errmsg(stat) - enum auth_stat stat; +auth_errmsg(enum auth_stat stat) { unsigned int errnum = stat; - if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0]))) + if (errnum < __arraycount(auth_errlist)) return __UNCONST(auth_errlist[errnum]); return(NULL); diff --git a/lib/libc/rpc/clnt_raw.c b/lib/libc/rpc/clnt_raw.c index 50787f5ad..f2ceaeefa 100644 --- a/lib/libc/rpc/clnt_raw.c +++ b/lib/libc/rpc/clnt_raw.c @@ -1,4 +1,4 @@ -/* $NetBSD: clnt_raw.c,v 1.29 2008/04/25 17:44:44 christos Exp $ */ +/* $NetBSD: clnt_raw.c,v 1.30 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC"; #else -__RCSID("$NetBSD: clnt_raw.c,v 1.29 2008/04/25 17:44:44 christos Exp $"); +__RCSID("$NetBSD: clnt_raw.c,v 1.30 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -85,22 +85,20 @@ static struct clntraw_private { u_int mcnt; } *clntraw_private; -static enum clnt_stat clnt_raw_call __P((CLIENT *, rpcproc_t, xdrproc_t, - const char *, xdrproc_t, caddr_t, struct timeval)); -static void clnt_raw_geterr __P((CLIENT *, struct rpc_err *)); -static bool_t clnt_raw_freeres __P((CLIENT *, xdrproc_t, caddr_t)); -static void clnt_raw_abort __P((CLIENT *)); -static bool_t clnt_raw_control __P((CLIENT *, u_int, char *)); -static void clnt_raw_destroy __P((CLIENT *)); -static struct clnt_ops *clnt_raw_ops __P((void)); +static enum clnt_stat clnt_raw_call(CLIENT *, rpcproc_t, xdrproc_t, + const char *, xdrproc_t, caddr_t, struct timeval); +static void clnt_raw_geterr(CLIENT *, struct rpc_err *); +static bool_t clnt_raw_freeres(CLIENT *, xdrproc_t, caddr_t); +static void clnt_raw_abort(CLIENT *); +static bool_t clnt_raw_control(CLIENT *, u_int, char *); +static void clnt_raw_destroy(CLIENT *); +static struct clnt_ops *clnt_raw_ops(void); /* * Create a client handle for memory based rpc. */ CLIENT * -clnt_raw_create(prog, vers) - rpcprog_t prog; - rpcvers_t vers; +clnt_raw_create(rpcprog_t prog, rpcvers_t vers) { struct clntraw_private *clp = clntraw_private; struct rpc_msg call_msg; @@ -156,14 +154,8 @@ out: /* ARGSUSED */ static enum clnt_stat -clnt_raw_call(h, proc, xargs, argsp, xresults, resultsp, timeout) - CLIENT *h; - rpcproc_t proc; - xdrproc_t xargs; - const char *argsp; - xdrproc_t xresults; - caddr_t resultsp; - struct timeval timeout; +clnt_raw_call(CLIENT *h, rpcproc_t proc, xdrproc_t xargs, const char *argsp, + xdrproc_t xresults, caddr_t resultsp, struct timeval timeout) { struct clntraw_private *clp = clntraw_private; XDR *xdrs = &clp->xdr_stream; @@ -254,19 +246,14 @@ call_again: /*ARGSUSED*/ static void -clnt_raw_geterr(cl, error) - CLIENT *cl; - struct rpc_err *error; +clnt_raw_geterr(CLIENT *cl, struct rpc_err *error) { } /* ARGSUSED */ static bool_t -clnt_raw_freeres(cl, xdr_res, res_ptr) - CLIENT *cl; - xdrproc_t xdr_res; - caddr_t res_ptr; +clnt_raw_freeres(CLIENT *cl, xdrproc_t xdr_res, caddr_t res_ptr) { struct clntraw_private *clp = clntraw_private; XDR *xdrs = &clp->xdr_stream; @@ -285,30 +272,25 @@ clnt_raw_freeres(cl, xdr_res, res_ptr) /*ARGSUSED*/ static void -clnt_raw_abort(cl) - CLIENT *cl; +clnt_raw_abort(CLIENT *cl) { } /*ARGSUSED*/ static bool_t -clnt_raw_control(cl, ui, str) - CLIENT *cl; - u_int ui; - char *str; +clnt_raw_control(CLIENT *cl, u_int ui, char *str) { return (FALSE); } /*ARGSUSED*/ static void -clnt_raw_destroy(cl) - CLIENT *cl; +clnt_raw_destroy(CLIENT *cl) { } static struct clnt_ops * -clnt_raw_ops() +clnt_raw_ops(void) { static struct clnt_ops ops; #ifdef _REENTRANT diff --git a/lib/libc/rpc/clnt_simple.c b/lib/libc/rpc/clnt_simple.c index 548078363..3ffcb120d 100644 --- a/lib/libc/rpc/clnt_simple.c +++ b/lib/libc/rpc/clnt_simple.c @@ -1,4 +1,4 @@ -/* $NetBSD: clnt_simple.c,v 1.30 2010/12/08 02:06:38 joerg Exp $ */ +/* $NetBSD: clnt_simple.c,v 1.31 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)clnt_simple.c 1.49 89/01/31 Copyr 1984 Sun Micro"; #else -__RCSID("$NetBSD: clnt_simple.c,v 1.30 2010/12/08 02:06:38 joerg Exp $"); +__RCSID("$NetBSD: clnt_simple.c,v 1.31 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -85,7 +85,7 @@ struct rpc_call_private { static struct rpc_call_private *rpc_call_private_main; #ifdef _REENTRANT -static void rpc_call_destroy __P((void *)); +static void rpc_call_destroy(void *); static void rpc_call_destroy(void *vp) @@ -118,15 +118,16 @@ rpc_call_setup(void) * The total time available is 25 seconds. */ enum clnt_stat -rpc_call(host, prognum, versnum, procnum, inproc, in, outproc, out, nettype) - const char *host; /* host name */ - rpcprog_t prognum; /* program number */ - rpcvers_t versnum; /* version number */ - rpcproc_t procnum; /* procedure number */ - xdrproc_t inproc, outproc; /* in/out XDR procedures */ - const char *in; - char *out; /* recv/send data */ - const char *nettype; /* nettype */ +rpc_call( + const char * host, /* host name */ + rpcprog_t prognum, /* program number */ + rpcvers_t versnum, /* version number */ + rpcproc_t procnum, /* procedure number */ + xdrproc_t inproc, /* in XDR procedures */ + const char * in, /* recv data */ + xdrproc_t outproc, /* out XDR procedures */ + char * out, /* send data */ + const char * nettype) /* nettype */ { struct rpc_call_private *rcp = (struct rpc_call_private *) 0; enum clnt_stat clnt_stat; diff --git a/lib/libc/rpc/clnt_vc.c b/lib/libc/rpc/clnt_vc.c index 4cb63298c..67788e794 100644 --- a/lib/libc/rpc/clnt_vc.c +++ b/lib/libc/rpc/clnt_vc.c @@ -1,4 +1,4 @@ -/* $NetBSD: clnt_vc.c,v 1.17 2010/12/08 02:06:38 joerg Exp $ */ +/* $NetBSD: clnt_vc.c,v 1.18 2012/03/13 21:13:44 christos Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -36,7 +36,7 @@ static char *sccsid = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC"; static char sccsid[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro"; #else -__RCSID("$NetBSD: clnt_vc.c,v 1.17 2010/12/08 02:06:38 joerg Exp $"); +__RCSID("$NetBSD: clnt_vc.c,v 1.18 2012/03/13 21:13:44 christos Exp $"); #endif #endif @@ -85,17 +85,17 @@ __weak_alias(clnt_vc_create,_clnt_vc_create) #define MCALL_MSG_SIZE 24 -static enum clnt_stat clnt_vc_call __P((CLIENT *, rpcproc_t, xdrproc_t, - const char *, xdrproc_t, caddr_t, struct timeval)); -static void clnt_vc_geterr __P((CLIENT *, struct rpc_err *)); -static bool_t clnt_vc_freeres __P((CLIENT *, xdrproc_t, caddr_t)); -static void clnt_vc_abort __P((CLIENT *)); -static bool_t clnt_vc_control __P((CLIENT *, u_int, char *)); -static void clnt_vc_destroy __P((CLIENT *)); -static struct clnt_ops *clnt_vc_ops __P((void)); -static bool_t time_not_ok __P((struct timeval *)); -static int read_vc __P((caddr_t, caddr_t, int)); -static int write_vc __P((caddr_t, caddr_t, int)); +static enum clnt_stat clnt_vc_call(CLIENT *, rpcproc_t, xdrproc_t, + const char *, xdrproc_t, caddr_t, struct timeval); +static void clnt_vc_geterr(CLIENT *, struct rpc_err *); +static bool_t clnt_vc_freeres(CLIENT *, xdrproc_t, caddr_t); +static void clnt_vc_abort(CLIENT *); +static bool_t clnt_vc_control(CLIENT *, u_int, char *); +static void clnt_vc_destroy(CLIENT *); +static struct clnt_ops *clnt_vc_ops(void); +static bool_t time_not_ok(struct timeval *); +static int read_vc(caddr_t, caddr_t, int); +static int write_vc(caddr_t, caddr_t, int); struct ct_data { int ct_fd; @@ -154,13 +154,14 @@ static cond_t *vc_cv; * fd should be an open socket */ CLIENT * -clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz) - int fd; - const struct netbuf *raddr; - rpcprog_t prog; - rpcvers_t vers; - u_int sendsz; - u_int recvsz; +clnt_vc_create( + int fd, + const struct netbuf *raddr, + rpcprog_t prog, + rpcvers_t vers, + u_int sendsz, + u_int recvsz +) { CLIENT *h; struct ct_data *ct = NULL; @@ -314,14 +315,15 @@ fooy: } static enum clnt_stat -clnt_vc_call(h, proc, xdr_args, args_ptr, xdr_results, results_ptr, timeout) - CLIENT *h; - rpcproc_t proc; - xdrproc_t xdr_args; - const char *args_ptr; - xdrproc_t xdr_results; - caddr_t results_ptr; - struct timeval timeout; +clnt_vc_call( + CLIENT *h, + rpcproc_t proc, + xdrproc_t xdr_args, + const char *args_ptr, + xdrproc_t xdr_results, + caddr_t results_ptr, + struct timeval timeout +) { struct ct_data *ct; XDR *xdrs; @@ -444,9 +446,10 @@ call_again: } static void -clnt_vc_geterr(h, errp) - CLIENT *h; - struct rpc_err *errp; +clnt_vc_geterr( + CLIENT *h, + struct rpc_err *errp +) { struct ct_data *ct; @@ -458,10 +461,11 @@ clnt_vc_geterr(h, errp) } static bool_t -clnt_vc_freeres(cl, xdr_res, res_ptr) - CLIENT *cl; - xdrproc_t xdr_res; - caddr_t res_ptr; +clnt_vc_freeres( + CLIENT *cl, + xdrproc_t xdr_res, + caddr_t res_ptr +) { struct ct_data *ct; XDR *xdrs; @@ -495,16 +499,16 @@ clnt_vc_freeres(cl, xdr_res, res_ptr) /*ARGSUSED*/ static void -clnt_vc_abort(cl) - CLIENT *cl; +clnt_vc_abort(CLIENT *cl) { } static bool_t -clnt_vc_control(cl, request, info) - CLIENT *cl; - u_int request; - char *info; +clnt_vc_control( + CLIENT *cl, + u_int request, + char *info +) { struct ct_data *ct; void *infop = info; @@ -631,8 +635,7 @@ clnt_vc_control(cl, request, info) static void -clnt_vc_destroy(cl) - CLIENT *cl; +clnt_vc_destroy(CLIENT *cl) { struct ct_data *ct; #ifdef _REENTRANT @@ -673,14 +676,12 @@ clnt_vc_destroy(cl) * around for the rpc level. */ static int -read_vc(ctp, buf, len) - caddr_t ctp; - caddr_t buf; - int len; +read_vc(char *ctp, char *buf, int len) { struct ct_data *ct = (struct ct_data *)(void *)ctp; struct pollfd fd; struct timespec ts; + ssize_t nread; if (len == 0) return (0); @@ -703,7 +704,7 @@ read_vc(ctp, buf, len) } break; } - switch (len = read(ct->ct_fd, buf, (size_t)len)) { + switch (nread = read(ct->ct_fd, buf, (size_t)len)) { case 0: /* premature eof */ @@ -717,30 +718,28 @@ read_vc(ctp, buf, len) ct->ct_error.re_status = RPC_CANTRECV; break; } - return (len); + return (int)nread; } static int -write_vc(ctp, buf, len) - caddr_t ctp; - caddr_t buf; - int len; +write_vc(char *ctp, char *buf, int len) { struct ct_data *ct = (struct ct_data *)(void *)ctp; - int i, cnt; + ssize_t i; + size_t cnt; for (cnt = len; cnt > 0; cnt -= i, buf += i) { - if ((i = write(ct->ct_fd, buf, (size_t)cnt)) == -1) { + if ((i = write(ct->ct_fd, buf, cnt)) == -1) { ct->ct_error.re_errno = errno; ct->ct_error.re_status = RPC_CANTSEND; return (-1); } } - return (len); + return len; } static struct clnt_ops * -clnt_vc_ops() +clnt_vc_ops(void) { static struct clnt_ops ops; #ifdef _REENTRANT @@ -772,8 +771,7 @@ clnt_vc_ops() * Note this is different from time_not_ok in clnt_dg.c */ static bool_t -time_not_ok(t) - struct timeval *t; +time_not_ok(struct timeval *t) { _DIAGASSERT(t != NULL); diff --git a/lib/libc/rpc/getnetconfig.c b/lib/libc/rpc/getnetconfig.c index 757767324..4ad6fd3a6 100644 --- a/lib/libc/rpc/getnetconfig.c +++ b/lib/libc/rpc/getnetconfig.c @@ -1,4 +1,4 @@ -/* $NetBSD: getnetconfig.c,v 1.18 2010/12/08 02:06:38 joerg Exp $ */ +/* $NetBSD: getnetconfig.c,v 1.20 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ #if 0 static char sccsid[] = "@(#)getnetconfig.c 1.12 91/12/19 SMI"; #else -__RCSID("$NetBSD: getnetconfig.c,v 1.18 2010/12/08 02:06:38 joerg Exp $"); +__RCSID("$NetBSD: getnetconfig.c,v 1.20 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -135,9 +135,9 @@ struct netconfig_vars { #define NC_INVALID 0 -static int *__nc_error __P((void)); -static int parse_ncp __P((char *, struct netconfig *)); -static struct netconfig *dup_ncp __P((struct netconfig *)); +static int *__nc_error(void); +static int parse_ncp(char *, struct netconfig *); +static struct netconfig *dup_ncp(struct netconfig *); static FILE *nc_file; /* for netconfig db */ @@ -157,7 +157,7 @@ __nc_error_setup(void) #endif static int * -__nc_error() +__nc_error(void) { #ifdef _REENTRANT int *nc_addr = NULL; @@ -207,7 +207,7 @@ __nc_error() * the netconfig database is not present). */ void * -setnetconfig() +setnetconfig(void) { struct netconfig_vars *nc_vars; @@ -220,7 +220,7 @@ setnetconfig() * handle without reopening the netconfig db. */ ni.ref++; - if ((nc_file != NULL) || (nc_file = fopen(NETCONFIG, "r")) != NULL) { + if ((nc_file != NULL) || (nc_file = fopen(NETCONFIG, "re")) != NULL) { nc_vars->valid = NC_VALID; nc_vars->flag = 0; nc_vars->nc_configs = ni.head; @@ -242,8 +242,7 @@ setnetconfig() */ struct netconfig * -getnetconfig(handlep) - void *handlep; +getnetconfig(void *handlep) { struct netconfig_vars *ncp = (struct netconfig_vars *)handlep; char *stringp; /* tmp string pointer */ @@ -361,8 +360,7 @@ getnetconfig(handlep) * previously). */ int -endnetconfig(handlep) - void *handlep; +endnetconfig(void *handlep) { struct netconfig_vars *nc_handlep = (struct netconfig_vars *)handlep; @@ -421,8 +419,7 @@ endnetconfig(handlep) */ struct netconfig * -getnetconfigent(netid) - const char *netid; +getnetconfigent(const char *netid) { FILE *file; /* NETCONFIG db's file pointer */ char *linep; /* holds current netconfig line */ @@ -498,8 +495,7 @@ getnetconfigent(netid) */ void -freenetconfigent(netconfigp) - struct netconfig *netconfigp; +freenetconfigent(struct netconfig *netconfigp) { if (netconfigp != NULL) { /* holds all netconfigp's strings */ @@ -523,9 +519,9 @@ freenetconfigent(netconfigp) */ static int -parse_ncp(stringp, ncp) - char *stringp; /* string to parse */ - struct netconfig *ncp; /* where to put results */ +parse_ncp( + char *stringp, /* string to parse */ + struct netconfig *ncp) /* where to put results */ { char *tokenp; /* for processing tokens */ char *lasts; @@ -609,7 +605,7 @@ parse_ncp(stringp, ncp) * Returns a string describing the reason for failure. */ char * -nc_sperror() +nc_sperror(void) { const char *message; @@ -636,8 +632,7 @@ nc_sperror() * Prints a message onto standard error describing the reason for failure. */ void -nc_perror(s) - const char *s; +nc_perror(const char *s) { _DIAGASSERT(s != NULL); @@ -649,8 +644,7 @@ nc_perror(s) * Duplicates the matched netconfig buffer. */ static struct netconfig * - dup_ncp(ncp) - struct netconfig *ncp; +dup_ncp(struct netconfig *ncp) { struct netconfig *p; char *tmp; diff --git a/lib/libc/rpc/getnetpath.c b/lib/libc/rpc/getnetpath.c index 2a4373759..2350c7d91 100644 --- a/lib/libc/rpc/getnetpath.c +++ b/lib/libc/rpc/getnetpath.c @@ -1,4 +1,4 @@ -/* $NetBSD: getnetpath.c,v 1.14 2008/05/24 16:04:15 christos Exp $ */ +/* $NetBSD: getnetpath.c,v 1.16 2012/06/25 22:32:45 abs Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ #if 0 static char sccsid[] = "@(#)getnetpath.c 1.11 91/12/19 SMI"; #else -__RCSID("$NetBSD: getnetpath.c,v 1.14 2008/05/24 16:04:15 christos Exp $"); +__RCSID("$NetBSD: getnetpath.c,v 1.16 2012/06/25 22:32:45 abs Exp $"); #endif #endif @@ -78,7 +78,7 @@ struct netpath_vars { #define NP_VALID 0xf00d #define NP_INVALID 0 -char *_get_next_token __P((char *, int)); +char *_get_next_token(char *, int); /* @@ -93,7 +93,7 @@ char *_get_next_token __P((char *, int)); */ void * -setnetpath() +setnetpath(void) { struct netpath_vars *np_sessionp; /* this session's variables */ char *npp; /* NETPATH env variable */ @@ -147,8 +147,7 @@ setnetpath() */ struct netconfig * -getnetpath(handlep) - void *handlep; +getnetpath(void *handlep) { struct netpath_vars *np_sessionp = (struct netpath_vars *)handlep; struct netconfig *ncp = NULL; /* temp. holds a netconfig session */ @@ -207,8 +206,7 @@ getnetpath(handlep) * (e.g. if setnetpath() was not called previously. */ int -endnetpath(handlep) - void *handlep; +endnetpath(void *handlep) { struct netpath_vars *np_sessionp = (struct netpath_vars *)handlep; struct netpath_chain *chainp, *lastp; diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c index 696893fd5..6ee813006 100644 --- a/lib/libc/rpc/getrpcent.c +++ b/lib/libc/rpc/getrpcent.c @@ -1,4 +1,4 @@ -/* $NetBSD: getrpcent.c,v 1.21 2004/08/16 02:47:54 ginsbach Exp $ */ +/* $NetBSD: getrpcent.c,v 1.22 2011/10/15 23:00:02 christos Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ #if 0 static char *sccsid = "@(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro"; #else -__RCSID("$NetBSD: getrpcent.c,v 1.21 2004/08/16 02:47:54 ginsbach Exp $"); +__RCSID("$NetBSD: getrpcent.c,v 1.22 2011/10/15 23:00:02 christos Exp $"); #endif #endif @@ -140,7 +140,7 @@ setrpcent(int f) if (d == 0) return; if (d->rpcf == NULL) - d->rpcf = fopen(RPCDB, "r"); + d->rpcf = fopen(RPCDB, "re"); else rewind(d->rpcf); d->stayopen |= f; @@ -166,7 +166,7 @@ getrpcent(void) if (d == 0) return(NULL); - if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL) + if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "re")) == NULL) return (NULL); if (fgets(d->line, BUFSIZ, d->rpcf) == NULL) return (NULL); diff --git a/lib/libc/rpc/getrpcport.c b/lib/libc/rpc/getrpcport.c index 4a44a7d47..33939d27a 100644 --- a/lib/libc/rpc/getrpcport.c +++ b/lib/libc/rpc/getrpcport.c @@ -1,4 +1,4 @@ -/* $NetBSD: getrpcport.c,v 1.16 2000/01/22 22:19:18 mycroft Exp $ */ +/* $NetBSD: getrpcport.c,v 1.17 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)getrpcport.c 1.3 87/08/11 SMI"; static char *sccsid = "@(#)getrpcport.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: getrpcport.c,v 1.16 2000/01/22 22:19:18 mycroft Exp $"); +__RCSID("$NetBSD: getrpcport.c,v 1.17 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -61,9 +61,7 @@ __weak_alias(getrpcport,_getrpcport) #endif int -getrpcport(host, prognum, versnum, proto) - char *host; - int prognum, versnum, proto; +getrpcport(char *host, int prognum, int versnum, int proto) { struct sockaddr_in addr; struct hostent *hp; diff --git a/lib/libc/rpc/mt_misc.c b/lib/libc/rpc/mt_misc.c index 269348d73..5e8bb2624 100644 --- a/lib/libc/rpc/mt_misc.c +++ b/lib/libc/rpc/mt_misc.c @@ -1,4 +1,4 @@ -/* $NetBSD: mt_misc.c,v 1.8 2010/12/08 02:06:38 joerg Exp $ */ +/* $NetBSD: mt_misc.c,v 1.9 2012/03/20 17:14:50 matt Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: mt_misc.c,v 1.8 2010/12/08 02:06:38 joerg Exp $"); +__RCSID("$NetBSD: mt_misc.c,v 1.9 2012/03/20 17:14:50 matt Exp $"); #endif #include "namespace.h" @@ -112,7 +112,7 @@ __rpc_createerr_setup(void) #endif /* _REENTRANT */ struct rpc_createerr* -__rpc_createerr() +__rpc_createerr(void) { #ifdef _REENTRANT struct rpc_createerr *rce_addr = 0; @@ -134,4 +134,3 @@ __rpc_createerr() return &rpc_createerr; #endif } - diff --git a/lib/libc/rpc/pmap_getmaps.c b/lib/libc/rpc/pmap_getmaps.c index 74c8b5e9e..e4e6370b7 100644 --- a/lib/libc/rpc/pmap_getmaps.c +++ b/lib/libc/rpc/pmap_getmaps.c @@ -1,4 +1,4 @@ -/* $NetBSD: pmap_getmaps.c,v 1.16 2000/07/06 03:10:34 christos Exp $ */ +/* $NetBSD: pmap_getmaps.c,v 1.17 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)pmap_getmaps.c 2.2 88/08/01 4.0 RPCSRC"; #else -__RCSID("$NetBSD: pmap_getmaps.c,v 1.16 2000/07/06 03:10:34 christos Exp $"); +__RCSID("$NetBSD: pmap_getmaps.c,v 1.17 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -77,8 +77,7 @@ __weak_alias(pmap_getmaps,_pmap_getmaps) * Calls the pmap service remotely to do get the maps. */ struct pmaplist * -pmap_getmaps(address) - struct sockaddr_in *address; +pmap_getmaps(struct sockaddr_in *address) { struct pmaplist *head = NULL; int sock = -1; diff --git a/lib/libc/rpc/pmap_prot.c b/lib/libc/rpc/pmap_prot.c index 85aa6136e..13779d431 100644 --- a/lib/libc/rpc/pmap_prot.c +++ b/lib/libc/rpc/pmap_prot.c @@ -1,4 +1,4 @@ -/* $NetBSD: pmap_prot.c,v 1.10 2000/01/22 22:19:18 mycroft Exp $ */ +/* $NetBSD: pmap_prot.c,v 1.11 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)pmap_prot.c 1.17 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)pmap_prot.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: pmap_prot.c,v 1.10 2000/01/22 22:19:18 mycroft Exp $"); +__RCSID("$NetBSD: pmap_prot.c,v 1.11 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -60,9 +60,7 @@ __weak_alias(xdr_pmap,_xdr_pmap) bool_t -xdr_pmap(xdrs, regs) - XDR *xdrs; - struct pmap *regs; +xdr_pmap(XDR *xdrs, struct pmap *regs) { _DIAGASSERT(xdrs != NULL); diff --git a/lib/libc/rpc/pmap_prot2.c b/lib/libc/rpc/pmap_prot2.c index 8a6bd60d6..c379f2b9b 100644 --- a/lib/libc/rpc/pmap_prot2.c +++ b/lib/libc/rpc/pmap_prot2.c @@ -1,4 +1,4 @@ -/* $NetBSD: pmap_prot2.c,v 1.15 2001/01/04 14:42:20 lukem Exp $ */ +/* $NetBSD: pmap_prot2.c,v 1.16 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)pmap_prot2.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: pmap_prot2.c,v 1.15 2001/01/04 14:42:20 lukem Exp $"); +__RCSID("$NetBSD: pmap_prot2.c,v 1.16 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -97,9 +97,7 @@ __weak_alias(xdr_pmaplist,_xdr_pmaplist) * this sounds like a job for xdr_reference! */ bool_t -xdr_pmaplist(xdrs, rp) - XDR *xdrs; - struct pmaplist **rp; +xdr_pmaplist(XDR *xdrs, struct pmaplist **rp) { /* * more_elements is pre-computed in case the direction is @@ -141,9 +139,7 @@ xdr_pmaplist(xdrs, rp) * functionality to xdr_pmaplist(). */ bool_t -xdr_pmaplist_ptr(xdrs, rp) - XDR *xdrs; - struct pmaplist *rp; +xdr_pmaplist_ptr(XDR *xdrs, struct pmaplist *rp) { _DIAGASSERT(xdrs != NULL); diff --git a/lib/libc/rpc/pmap_rmt.c b/lib/libc/rpc/pmap_rmt.c index f7e43ccf0..675717b0c 100644 --- a/lib/libc/rpc/pmap_rmt.c +++ b/lib/libc/rpc/pmap_rmt.c @@ -1,4 +1,4 @@ -/* $NetBSD: pmap_rmt.c,v 1.30 2010/03/23 20:28:59 drochner Exp $ */ +/* $NetBSD: pmap_rmt.c,v 1.33 2012/06/25 22:32:45 abs Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC"; #else -__RCSID("$NetBSD: pmap_rmt.c,v 1.30 2010/03/23 20:28:59 drochner Exp $"); +__RCSID("$NetBSD: pmap_rmt.c,v 1.33 2012/06/25 22:32:45 abs Exp $"); #endif #endif @@ -85,14 +85,9 @@ static const struct timeval timeout = { 3, 0 }; * programs to do a lookup and call in one step. */ enum clnt_stat -pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, - port_ptr) - struct sockaddr_in *addr; - u_long prog, vers, proc; - xdrproc_t xdrargs, xdrres; - caddr_t argsp, resp; - struct timeval tout; - u_long *port_ptr; +pmap_rmtcall(struct sockaddr_in *addr, u_long prog, u_long vers, u_long proc, + xdrproc_t xdrargs, caddr_t argsp, xdrproc_t xdrres, caddr_t resp, + struct timeval tout, u_long *port_ptr) { int sock = -1; CLIENT *client; @@ -131,9 +126,7 @@ pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout, * written for XDR_ENCODE direction only */ bool_t -xdr_rmtcall_args(xdrs, cap) - XDR *xdrs; - struct rmtcallargs *cap; +xdr_rmtcall_args(XDR *xdrs, struct rmtcallargs *cap) { u_int lenposition, argposition, position; @@ -165,9 +158,7 @@ xdr_rmtcall_args(xdrs, cap) * written for XDR_DECODE direction only */ bool_t -xdr_rmtcallres(xdrs, crp) - XDR *xdrs; - struct rmtcallres *crp; +xdr_rmtcallres(XDR *xdrs, struct rmtcallres *crp) { caddr_t port_ptr; @@ -175,7 +166,7 @@ xdr_rmtcallres(xdrs, crp) _DIAGASSERT(crp != NULL); port_ptr = (caddr_t)(void *)crp->port_ptr; - if (xdr_reference(xdrs, &port_ptr, sizeof (u_long), + if (xdr_reference(xdrs, &port_ptr, (u_int)sizeof(u_long), (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) { crp->port_ptr = (u_long *)(void *)port_ptr; return ((*(crp->xdr_results))(xdrs, crp->results_ptr)); diff --git a/lib/libc/rpc/rpc.3 b/lib/libc/rpc/rpc.3 index 889e676c1..f9fd7f7e9 100644 --- a/lib/libc/rpc/rpc.3 +++ b/lib/libc/rpc/rpc.3 @@ -1,6 +1,6 @@ .\" @(#)rpc.3n 1.31 93/08/31 SMI; from SVr4 .\" Copyright 1989 AT&T -.\" $NetBSD: rpc.3,v 1.22 2010/03/22 19:30:54 joerg Exp $ +.\" $NetBSD: rpc.3,v 1.24 2012/05/13 15:47:38 wiz Exp $ .Dd May 7, 1993 .Dt RPC 3 .Os @@ -254,9 +254,8 @@ enum xdr_op { * structure of the data type to be decoded. If this points to 0, * then the type routines should allocate dynamic storage of the * appropriate size and return it. - * bool_t (*xdrproc_t)(XDR *, caddr_t *); */ -typedef bool_t (*xdrproc_t)(); +typedef bool_t (*xdrproc_t)(XDR *, const void *); /* * The XDR handle. @@ -312,92 +311,92 @@ pages on which they are described: .Bl -column "authunix_create_default()" "rpc_clnt_create(3)" .It Em "RPC Routine" Ta Em "Manual Reference Page" .Pp -.It Fn auth_destroy Ta Xr rpc_clnt_auth 3 , -.It Fn authdes_create Ta Xr rpc_soc 3 , -.It Fn authnone_create Ta Xr rpc_clnt_auth 3 , -.It Fn authsys_create Ta Xr rpc_clnt_auth 3 , -.It Fn authsys_create_default Ta Xr rpc_clnt_auth 3 , -.It Fn authunix_create Ta Xr rpc_soc 3 , -.It Fn authunix_create_default Ta Xr rpc_soc 3 , -.It Fn callrpc Ta Xr rpc_soc 3 , -.It Fn clnt_broadcast Ta Xr rpc_soc 3 , -.It Fn clnt_call Ta Xr rpc_clnt_calls 3 , -.It Fn clnt_control Ta Xr rpc_clnt_create 3 , -.It Fn clnt_create Ta Xr rpc_clnt_create 3 , -.It Fn clnt_destroy Ta Xr rpc_clnt_create 3 , -.It Fn clnt_dg_create Ta Xr rpc_clnt_create 3 , -.It Fn clnt_freeres Ta Xr rpc_clnt_calls 3 , -.It Fn clnt_geterr Ta Xr rpc_clnt_calls 3 , -.It Fn clnt_pcreateerror Ta Xr rpc_clnt_create 3 , -.It Fn clnt_perrno Ta Xr rpc_clnt_calls 3 , -.It Fn clnt_perror Ta Xr rpc_clnt_calls 3 , -.It Fn clnt_raw_create Ta Xr rpc_clnt_create 3 , -.It Fn clnt_spcreateerror Ta Xr rpc_clnt_create 3 , -.It Fn clnt_sperrno Ta Xr rpc_clnt_calls 3 , -.It Fn clnt_sperror Ta Xr rpc_clnt_calls 3 , -.It Fn clnt_tli_create Ta Xr rpc_clnt_create 3 , -.It Fn clnt_tp_create Ta Xr rpc_clnt_create 3 , -.It Fn clnt_udpcreate Ta Xr rpc_soc 3 , -.It Fn clnt_vc_create Ta Xr rpc_clnt_create 3 , -.It Fn clntraw_create Ta Xr rpc_soc 3 , -.It Fn clnttcp_create Ta Xr rpc_soc 3 , -.It Fn clntudp_bufcreate Ta Xr rpc_soc 3 , -.It Fn get_myaddress Ta Xr rpc_soc 3 , -.It Fn pmap_getmaps Ta Xr rpc_soc 3 , -.It Fn pmap_getport Ta Xr rpc_soc 3 , -.It Fn pmap_rmtcall Ta Xr rpc_soc 3 , -.It Fn pmap_set Ta Xr rpc_soc 3 , -.It Fn pmap_unset Ta Xr rpc_soc 3 , -.It Fn registerrpc Ta Xr rpc_soc 3 , -.It Fn rpc_broadcast Ta Xr rpc_clnt_calls 3 , -.It Fn rpc_broadcast_exp Ta Xr rpc_clnt_calls 3 , -.It Fn rpc_call Ta Xr rpc_clnt_calls 3 , -.It Fn rpc_reg Ta Xr rpc_svc_calls 3 , -.It Fn svc_create Ta Xr rpc_svc_create 3 , -.It Fn svc_destroy Ta Xr rpc_svc_create 3 , -.It Fn svc_dg_create Ta Xr rpc_svc_create 3 , -.It Fn svc_dg_enablecache Ta Xr rpc_svc_calls 3 , -.It Fn svc_fd_create Ta Xr rpc_svc_create 3 , -.It Fn svc_fds Ta Xr rpc_soc 3 , -.It Fn svc_freeargs Ta Xr rpc_svc_reg 3 , -.It Fn svc_getargs Ta Xr rpc_svc_reg 3 , -.It Fn svc_getcaller Ta Xr rpc_soc 3 , -.It Fn svc_getreq Ta Xr rpc_soc 3 , -.It Fn svc_getreqset Ta Xr rpc_svc_calls 3 , -.It Fn svc_getrpccaller Ta Xr rpc_svc_calls 3 , -.It Fn svc_kerb_reg Ta Xr kerberos_rpc 3 , -.It Fn svc_raw_create Ta Xr rpc_svc_create 3 , -.It Fn svc_reg Ta Xr rpc_svc_calls 3 , -.It Fn svc_register Ta Xr rpc_soc 3 , -.It Fn svc_run Ta Xr rpc_svc_reg 3 , -.It Fn svc_sendreply Ta Xr rpc_svc_reg 3 , -.It Fn svc_tli_create Ta Xr rpc_svc_create 3 , -.It Fn svc_tp_create Ta Xr rpc_svc_create 3 , -.It Fn svc_unreg Ta Xr rpc_svc_calls 3 , -.It Fn svc_unregister Ta Xr rpc_soc 3 , -.It Fn svc_vc_create Ta Xr rpc_svc_create 3 , -.It Fn svcerr_auth Ta Xr rpc_svc_err 3 , -.It Fn svcerr_decode Ta Xr rpc_svc_err 3 , -.It Fn svcerr_noproc Ta Xr rpc_svc_err 3 , -.It Fn svcerr_noprog Ta Xr rpc_svc_err 3 , -.It Fn svcerr_progvers Ta Xr rpc_svc_err 3 , -.It Fn svcerr_systemerr Ta Xr rpc_svc_err 3 , -.It Fn svcerr_weakauth Ta Xr rpc_svc_err 3 , -.It Fn svcfd_create Ta Xr rpc_soc 3 , -.It Fn svcraw_create Ta Xr rpc_soc 3 , -.It Fn svctcp_create Ta Xr rpc_soc 3 , -.It Fn svcudp_bufcreate Ta Xr rpc_soc 3 , -.It Fn svcudp_create Ta Xr rpc_soc 3 , -.It Fn xdr_accepted_reply Ta Xr rpc_xdr 3 , -.It Fn xdr_authsys_parms Ta Xr rpc_xdr 3 , -.It Fn xdr_authunix_parms Ta Xr rpc_soc 3 , -.It Fn xdr_callhdr Ta Xr rpc_xdr 3 , -.It Fn xdr_callmsg Ta Xr rpc_xdr 3 , -.It Fn xdr_opaque_auth Ta Xr rpc_xdr 3 , -.It Fn xdr_rejected_reply Ta Xr rpc_xdr 3 , -.It Fn xdr_replymsg Ta Xr rpc_xdr 3 , -.It Fn xprt_register Ta Xr rpc_svc_calls 3 , -.It Fn xprt_unregister Ta Xr rpc_svc_calls 3 , +.It Fn auth_destroy Ta Xr rpc_clnt_auth 3 +.It Fn authdes_create Ta Xr rpc_soc 3 +.It Fn authnone_create Ta Xr rpc_clnt_auth 3 +.It Fn authsys_create Ta Xr rpc_clnt_auth 3 +.It Fn authsys_create_default Ta Xr rpc_clnt_auth 3 +.It Fn authunix_create Ta Xr rpc_soc 3 +.It Fn authunix_create_default Ta Xr rpc_soc 3 +.It Fn callrpc Ta Xr rpc_soc 3 +.It Fn clnt_broadcast Ta Xr rpc_soc 3 +.It Fn clnt_call Ta Xr rpc_clnt_calls 3 +.It Fn clnt_control Ta Xr rpc_clnt_create 3 +.It Fn clnt_create Ta Xr rpc_clnt_create 3 +.It Fn clnt_destroy Ta Xr rpc_clnt_create 3 +.It Fn clnt_dg_create Ta Xr rpc_clnt_create 3 +.It Fn clnt_freeres Ta Xr rpc_clnt_calls 3 +.It Fn clnt_geterr Ta Xr rpc_clnt_calls 3 +.It Fn clnt_pcreateerror Ta Xr rpc_clnt_create 3 +.It Fn clnt_perrno Ta Xr rpc_clnt_calls 3 +.It Fn clnt_perror Ta Xr rpc_clnt_calls 3 +.It Fn clnt_raw_create Ta Xr rpc_clnt_create 3 +.It Fn clnt_spcreateerror Ta Xr rpc_clnt_create 3 +.It Fn clnt_sperrno Ta Xr rpc_clnt_calls 3 +.It Fn clnt_sperror Ta Xr rpc_clnt_calls 3 +.It Fn clnt_tli_create Ta Xr rpc_clnt_create 3 +.It Fn clnt_tp_create Ta Xr rpc_clnt_create 3 +.It Fn clnt_udpcreate Ta Xr rpc_soc 3 +.It Fn clnt_vc_create Ta Xr rpc_clnt_create 3 +.It Fn clntraw_create Ta Xr rpc_soc 3 +.It Fn clnttcp_create Ta Xr rpc_soc 3 +.It Fn clntudp_bufcreate Ta Xr rpc_soc 3 +.It Fn get_myaddress Ta Xr rpc_soc 3 +.It Fn pmap_getmaps Ta Xr rpc_soc 3 +.It Fn pmap_getport Ta Xr rpc_soc 3 +.It Fn pmap_rmtcall Ta Xr rpc_soc 3 +.It Fn pmap_set Ta Xr rpc_soc 3 +.It Fn pmap_unset Ta Xr rpc_soc 3 +.It Fn registerrpc Ta Xr rpc_soc 3 +.It Fn rpc_broadcast Ta Xr rpc_clnt_calls 3 +.It Fn rpc_broadcast_exp Ta Xr rpc_clnt_calls 3 +.It Fn rpc_call Ta Xr rpc_clnt_calls 3 +.It Fn rpc_reg Ta Xr rpc_svc_calls 3 +.It Fn svc_create Ta Xr rpc_svc_create 3 +.It Fn svc_destroy Ta Xr rpc_svc_create 3 +.It Fn svc_dg_create Ta Xr rpc_svc_create 3 +.It Fn svc_dg_enablecache Ta Xr rpc_svc_calls 3 +.It Fn svc_fd_create Ta Xr rpc_svc_create 3 +.It Fn svc_fds Ta Xr rpc_soc 3 +.It Fn svc_freeargs Ta Xr rpc_svc_reg 3 +.It Fn svc_getargs Ta Xr rpc_svc_reg 3 +.It Fn svc_getcaller Ta Xr rpc_soc 3 +.It Fn svc_getreq Ta Xr rpc_soc 3 +.It Fn svc_getreqset Ta Xr rpc_svc_calls 3 +.It Fn svc_getrpccaller Ta Xr rpc_svc_calls 3 +.It Fn svc_kerb_reg Ta Xr kerberos_rpc 3 +.It Fn svc_raw_create Ta Xr rpc_svc_create 3 +.It Fn svc_reg Ta Xr rpc_svc_calls 3 +.It Fn svc_register Ta Xr rpc_soc 3 +.It Fn svc_run Ta Xr rpc_svc_reg 3 +.It Fn svc_sendreply Ta Xr rpc_svc_reg 3 +.It Fn svc_tli_create Ta Xr rpc_svc_create 3 +.It Fn svc_tp_create Ta Xr rpc_svc_create 3 +.It Fn svc_unreg Ta Xr rpc_svc_calls 3 +.It Fn svc_unregister Ta Xr rpc_soc 3 +.It Fn svc_vc_create Ta Xr rpc_svc_create 3 +.It Fn svcerr_auth Ta Xr rpc_svc_err 3 +.It Fn svcerr_decode Ta Xr rpc_svc_err 3 +.It Fn svcerr_noproc Ta Xr rpc_svc_err 3 +.It Fn svcerr_noprog Ta Xr rpc_svc_err 3 +.It Fn svcerr_progvers Ta Xr rpc_svc_err 3 +.It Fn svcerr_systemerr Ta Xr rpc_svc_err 3 +.It Fn svcerr_weakauth Ta Xr rpc_svc_err 3 +.It Fn svcfd_create Ta Xr rpc_soc 3 +.It Fn svcraw_create Ta Xr rpc_soc 3 +.It Fn svctcp_create Ta Xr rpc_soc 3 +.It Fn svcudp_bufcreate Ta Xr rpc_soc 3 +.It Fn svcudp_create Ta Xr rpc_soc 3 +.It Fn xdr_accepted_reply Ta Xr rpc_xdr 3 +.It Fn xdr_authsys_parms Ta Xr rpc_xdr 3 +.It Fn xdr_authunix_parms Ta Xr rpc_soc 3 +.It Fn xdr_callhdr Ta Xr rpc_xdr 3 +.It Fn xdr_callmsg Ta Xr rpc_xdr 3 +.It Fn xdr_opaque_auth Ta Xr rpc_xdr 3 +.It Fn xdr_rejected_reply Ta Xr rpc_xdr 3 +.It Fn xdr_replymsg Ta Xr rpc_xdr 3 +.It Fn xprt_register Ta Xr rpc_svc_calls 3 +.It Fn xprt_unregister Ta Xr rpc_svc_calls 3 .El .Sh FILES .Pa /etc/netconfig diff --git a/lib/libc/rpc/rpc_callmsg.c b/lib/libc/rpc/rpc_callmsg.c index 1010bdc8f..0da1e37e8 100644 --- a/lib/libc/rpc/rpc_callmsg.c +++ b/lib/libc/rpc/rpc_callmsg.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_callmsg.c,v 1.18 2008/04/25 17:44:44 christos Exp $ */ +/* $NetBSD: rpc_callmsg.c,v 1.19 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)rpc_callmsg.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: rpc_callmsg.c,v 1.18 2008/04/25 17:44:44 christos Exp $"); +__RCSID("$NetBSD: rpc_callmsg.c,v 1.19 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -64,9 +64,7 @@ __weak_alias(xdr_callmsg,_xdr_callmsg) * XDR a call message */ bool_t -xdr_callmsg(xdrs, cmsg) - XDR *xdrs; - struct rpc_msg *cmsg; +xdr_callmsg(XDR *xdrs, struct rpc_msg *cmsg) { int32_t *buf; struct opaque_auth *oa; diff --git a/lib/libc/rpc/rpc_clnt_create.3 b/lib/libc/rpc/rpc_clnt_create.3 index 195a8c442..0d29b30a1 100644 --- a/lib/libc/rpc/rpc_clnt_create.3 +++ b/lib/libc/rpc/rpc_clnt_create.3 @@ -2,7 +2,7 @@ .\" Copyright 1989 AT&T .\" @(#)rpc_clnt_create 1.5 89/07/24 SMI; .\" Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved. -.\" $NetBSD: rpc_clnt_create.3,v 1.11 2009/05/23 18:57:25 christos Exp $ +.\" $NetBSD: rpc_clnt_create.3,v 1.12 2011/05/17 03:35:39 enami Exp $ .Dd May 23, 2009 .Dt RPC_CLNT_CREATE 3 .Os @@ -84,8 +84,8 @@ is ignored in all subsequent calls. Note: If you set the timeout value to 0 .Fn clnt_control -immediately returns an error ( -.Dv RPC_TIMEDOUT ) . +immediately returns an error +.Pq Dv RPC_TIMEDOUT . Set the timeout parameter to 0 for batching calls. .Bl -column CLSET_FD_NCLOSE "struct timeval *" "do not close fd on destroy" .It Dv CLGET_SVC_ADDR Ta "struct netbuf *" Ta "get servers address" diff --git a/lib/libc/rpc/rpc_dtablesize.c b/lib/libc/rpc/rpc_dtablesize.c index e947154f0..43651a294 100644 --- a/lib/libc/rpc/rpc_dtablesize.c +++ b/lib/libc/rpc/rpc_dtablesize.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_dtablesize.c,v 1.14 1998/11/15 17:32:43 christos Exp $ */ +/* $NetBSD: rpc_dtablesize.c,v 1.15 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)rpc_dtablesize.c 1.2 87/08/11 Copyr 1987 Sun Micro"; static char *sccsid = "@(#)rpc_dtablesize.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: rpc_dtablesize.c,v 1.14 1998/11/15 17:32:43 christos Exp $"); +__RCSID("$NetBSD: rpc_dtablesize.c,v 1.15 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -43,14 +43,14 @@ __RCSID("$NetBSD: rpc_dtablesize.c,v 1.14 1998/11/15 17:32:43 christos Exp $"); #include -int _rpc_dtablesize __P((void)); /* XXX */ +int _rpc_dtablesize(void); /* XXX */ /* * Cache the result of sysconf(_SC_OPEN_MAX), so we don't have to do an * expensive system call every time. */ int -_rpc_dtablesize() +_rpc_dtablesize(void) { static int size; if (size == 0) diff --git a/lib/libc/rpc/rpc_generic.c b/lib/libc/rpc/rpc_generic.c index a695ab49e..9a3cd48d3 100644 --- a/lib/libc/rpc/rpc_generic.c +++ b/lib/libc/rpc/rpc_generic.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_generic.c,v 1.24 2010/12/08 02:06:38 joerg Exp $ */ +/* $NetBSD: rpc_generic.c,v 1.26 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -41,7 +41,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: rpc_generic.c,v 1.24 2010/12/08 02:06:38 joerg Exp $"); +__RCSID("$NetBSD: rpc_generic.c,v 1.26 2012/03/20 17:14:50 matt Exp $"); #endif #include "namespace.h" @@ -109,16 +109,16 @@ static const struct netid_af na_cvt[] = { }; #if 0 -static char *strlocase __P((char *)); +static char *strlocase(char *); #endif -static int getnettype __P((const char *)); +static int getnettype(const char *); /* * Cache the result of getrlimit(), so we don't have to do an * expensive call every time. */ int -__rpc_dtbsize() +__rpc_dtbsize(void) { static int tbsize; struct rlimit rl; @@ -142,9 +142,10 @@ __rpc_dtbsize() */ u_int /*ARGSUSED*/ -__rpc_get_t_size(af, proto, size) - int af, proto; - int size; /* Size requested */ +__rpc_get_t_size( + int af, + int proto, + int size) /* Size requested */ { int maxsize, defsize; @@ -171,8 +172,7 @@ __rpc_get_t_size(af, proto, size) * Find the appropriate address buffer size */ u_int -__rpc_get_a_size(af) - int af; +__rpc_get_a_size(int af) { switch (af) { case AF_INET: @@ -191,8 +191,7 @@ __rpc_get_a_size(af) #if 0 static char * -strlocase(p) - char *p; +strlocase(char *p) { char *t = p; @@ -210,8 +209,7 @@ strlocase(p) * If nettype is NULL, it defaults to NETPATH. */ static int -getnettype(nettype) - const char *nettype; +getnettype(const char *nettype) { int i; @@ -248,8 +246,7 @@ __rpc_getconfigp_setup(void) #endif struct netconfig * -__rpc_getconfip(nettype) - const char *nettype; +__rpc_getconfip(const char *nettype) { char *netid; char *netid_tcp = NULL; @@ -334,8 +331,7 @@ __rpc_getconfip(nettype) * __rpc_getconf(). */ void * -__rpc_setconf(nettype) - const char *nettype; +__rpc_setconf(const char *nettype) { struct handle *handle; @@ -380,8 +376,7 @@ __rpc_setconf(nettype) * __rpc_setconf() should have been called previously. */ struct netconfig * -__rpc_getconf(vhandle) - void *vhandle; +__rpc_getconf(void *vhandle) { struct handle *handle; struct netconfig *nconf; @@ -457,8 +452,7 @@ __rpc_getconf(vhandle) } void -__rpc_endconf(vhandle) - void * vhandle; +__rpc_endconf(void *vhandle) { struct handle *handle; @@ -479,8 +473,7 @@ __rpc_endconf(vhandle) * Returns NULL if fails, else a non-NULL pointer. */ void * -rpc_nullproc(clnt) - CLIENT *clnt; +rpc_nullproc(CLIENT *clnt) { struct timeval TIMEOUT = {25, 0}; @@ -496,8 +489,7 @@ rpc_nullproc(clnt) * one succeeds in finding the netconf for the given fd. */ struct netconfig * -__rpcgettp(fd) - int fd; +__rpcgettp(int fd) { const char *netid; struct __rpc_sockinfo si; @@ -649,8 +641,8 @@ __rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf) switch (af) { case AF_INET: sinp = nbuf->buf; - if (inet_ntop(af, &sinp->sin_addr, namebuf, sizeof namebuf) - == NULL) + if (inet_ntop(af, &sinp->sin_addr, namebuf, + (socklen_t)sizeof namebuf) == NULL) return NULL; port = ntohs(sinp->sin_port); if (asprintf(&ret, "%s.%u.%u", namebuf, ((u_int32_t)port) >> 8, @@ -660,8 +652,8 @@ __rpc_taddr2uaddr_af(int af, const struct netbuf *nbuf) #ifdef INET6 case AF_INET6: sin6 = nbuf->buf; - if (inet_ntop(af, &sin6->sin6_addr, namebuf6, sizeof namebuf6) - == NULL) + if (inet_ntop(af, &sin6->sin6_addr, namebuf6, + (socklen_t)sizeof namebuf6) == NULL) return NULL; port = ntohs(sin6->sin6_port); if (asprintf(&ret, "%s.%u.%u", namebuf6, ((u_int32_t)port) >> 8, @@ -687,6 +679,7 @@ __rpc_uaddr2taddr_af(int af, const char *uaddr) struct netbuf *ret = NULL; char *addrstr, *p; unsigned port, portlo, porthi; + size_t len; struct sockaddr_in *sinp; #ifdef INET6 struct sockaddr_in6 *sin6; @@ -765,7 +758,9 @@ __rpc_uaddr2taddr_af(int af, const char *uaddr) memset(sun, 0, sizeof *sun); sun->sun_family = AF_LOCAL; strncpy(sun->sun_path, addrstr, sizeof(sun->sun_path) - 1); - ret->len = ret->maxlen = sun->sun_len = SUN_LEN(sun); + len = SUN_LEN(sun); + _DIAGASSERT(__type_fit(uint8_t, len)); + ret->len = ret->maxlen = sun->sun_len = (uint8_t)len; ret->buf = sun; break; default: @@ -893,5 +888,6 @@ __rpc_setnodelay(int fd, const struct __rpc_sockinfo *si) int one = 1; if (si->si_proto != IPPROTO_TCP) return 0; - return setsockopt(fd, si->si_proto, TCP_NODELAY, &one, sizeof(one)); + return setsockopt(fd, si->si_proto, TCP_NODELAY, &one, + (socklen_t)sizeof(one)); } diff --git a/lib/libc/rpc/rpc_prot.c b/lib/libc/rpc/rpc_prot.c index 8f0cfb315..1b6397586 100644 --- a/lib/libc/rpc/rpc_prot.c +++ b/lib/libc/rpc/rpc_prot.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_prot.c,v 1.18 2003/05/29 18:15:25 christos Exp $ */ +/* $NetBSD: rpc_prot.c,v 1.20 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)rpc_prot.c 2.3 88/08/07 4.0 RPCSRC"; #else -__RCSID("$NetBSD: rpc_prot.c,v 1.18 2003/05/29 18:15:25 christos Exp $"); +__RCSID("$NetBSD: rpc_prot.c,v 1.20 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -69,8 +69,8 @@ __weak_alias(xdr_rejected_reply,_xdr_rejected_reply) __weak_alias(xdr_replymsg,_xdr_replymsg) #endif -static void accepted __P((enum accept_stat, struct rpc_err *)); -static void rejected __P((enum reject_stat, struct rpc_err *)); +static void accepted(enum accept_stat, struct rpc_err *); +static void rejected(enum reject_stat, struct rpc_err *); /* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */ @@ -79,9 +79,7 @@ static void rejected __P((enum reject_stat, struct rpc_err *)); * (see auth.h) */ bool_t -xdr_opaque_auth(xdrs, ap) - XDR *xdrs; - struct opaque_auth *ap; +xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap) { _DIAGASSERT(xdrs != NULL); @@ -97,15 +95,14 @@ xdr_opaque_auth(xdrs, ap) * XDR a DES block */ bool_t -xdr_des_block(xdrs, blkp) - XDR *xdrs; - des_block *blkp; +xdr_des_block(XDR *xdrs, des_block *blkp) { _DIAGASSERT(xdrs != NULL); _DIAGASSERT(blkp != NULL); - return (xdr_opaque(xdrs, (caddr_t)(void *)blkp, sizeof(des_block))); + return (xdr_opaque(xdrs, (caddr_t)(void *)blkp, + (u_int)sizeof(des_block))); } /* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */ @@ -114,9 +111,7 @@ xdr_des_block(xdrs, blkp) * XDR the MSG_ACCEPTED part of a reply message union */ bool_t -xdr_accepted_reply(xdrs, ar) - XDR *xdrs; - struct accepted_reply *ar; +xdr_accepted_reply(XDR *xdrs, struct accepted_reply *ar) { _DIAGASSERT(xdrs != NULL); @@ -150,9 +145,7 @@ xdr_accepted_reply(xdrs, ar) * XDR the MSG_DENIED part of a reply message union */ bool_t -xdr_rejected_reply(xdrs, rr) - XDR *xdrs; - struct rejected_reply *rr; +xdr_rejected_reply(XDR *xdrs, struct rejected_reply *rr) { _DIAGASSERT(xdrs != NULL); @@ -184,9 +177,7 @@ static const struct xdr_discrim reply_dscrm[3] = { * XDR a reply message */ bool_t -xdr_replymsg(xdrs, rmsg) - XDR *xdrs; - struct rpc_msg *rmsg; +xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg) { _DIAGASSERT(xdrs != NULL); _DIAGASSERT(rmsg != NULL); @@ -208,9 +199,7 @@ xdr_replymsg(xdrs, rmsg) * The rm_xid is not really static, but the user can easily munge on the fly. */ bool_t -xdr_callhdr(xdrs, cmsg) - XDR *xdrs; - struct rpc_msg *cmsg; +xdr_callhdr(XDR *xdrs, struct rpc_msg *cmsg) { _DIAGASSERT(xdrs != NULL); @@ -231,9 +220,7 @@ xdr_callhdr(xdrs, cmsg) /* ************************** Client utility routine ************* */ static void -accepted(acpt_stat, error) - enum accept_stat acpt_stat; - struct rpc_err *error; +accepted(enum accept_stat acpt_stat, struct rpc_err *error) { _DIAGASSERT(error != NULL); @@ -272,9 +259,7 @@ accepted(acpt_stat, error) } static void -rejected(rjct_stat, error) - enum reject_stat rjct_stat; - struct rpc_err *error; +rejected(enum reject_stat rjct_stat, struct rpc_err *error) { _DIAGASSERT(error != NULL); @@ -299,9 +284,7 @@ rejected(rjct_stat, error) * given a reply message, fills in the error */ void -_seterr_reply(msg, error) - struct rpc_msg *msg; - struct rpc_err *error; +_seterr_reply(struct rpc_msg *msg, struct rpc_err *error) { _DIAGASSERT(msg != NULL); diff --git a/lib/libc/rpc/rpc_soc.c b/lib/libc/rpc/rpc_soc.c index dc19ece2b..2aaaa3043 100644 --- a/lib/libc/rpc/rpc_soc.c +++ b/lib/libc/rpc/rpc_soc.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc_soc.c,v 1.13 2010/12/08 02:06:38 joerg Exp $ */ +/* $NetBSD: rpc_soc.c,v 1.16 2012/06/25 22:32:45 abs Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -43,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)rpc_soc.c 1.41 89/05/02 Copyr 1988 Sun Micro"; #else -__RCSID("$NetBSD: rpc_soc.c,v 1.13 2010/12/08 02:06:38 joerg Exp $"); +__RCSID("$NetBSD: rpc_soc.c,v 1.16 2012/06/25 22:32:45 abs Exp $"); #endif #endif @@ -97,23 +97,17 @@ __weak_alias(clnt_broadcast,_clnt_broadcast) extern mutex_t rpcsoc_lock; #endif -static CLIENT *clnt_com_create __P((struct sockaddr_in *, rpcprog_t, rpcvers_t, - int *, u_int, u_int, const char *)); -static SVCXPRT *svc_com_create __P((int, u_int, u_int, const char *)); -static bool_t rpc_wrap_bcast __P((char *, struct netbuf *, struct netconfig *)); +static CLIENT *clnt_com_create(struct sockaddr_in *, rpcprog_t, rpcvers_t, + int *, u_int, u_int, const char *); +static SVCXPRT *svc_com_create(int, u_int, u_int, const char *); +static bool_t rpc_wrap_bcast(char *, struct netbuf *, struct netconfig *); /* * A common clnt create routine */ static CLIENT * -clnt_com_create(raddr, prog, vers, sockp, sendsz, recvsz, tp) - struct sockaddr_in *raddr; - rpcprog_t prog; - rpcvers_t vers; - int *sockp; - u_int sendsz; - u_int recvsz; - const char *tp; +clnt_com_create(struct sockaddr_in *raddr, rpcprog_t prog, rpcvers_t vers, + int *sockp, u_int sendsz, u_int recvsz, const char *tp) { CLIENT *cl; int madefd = FALSE; @@ -188,14 +182,7 @@ err: if (madefd == TRUE) } CLIENT * -clntudp_bufcreate(raddr, prog, vers, wait, sockp, sendsz, recvsz) - struct sockaddr_in *raddr; - u_long prog; - u_long vers; - struct timeval wait; - int *sockp; - u_int sendsz; - u_int recvsz; +clntudp_bufcreate(struct sockaddr_in *raddr, u_long prog, u_long vers, struct timeval wait, int *sockp, u_int sendsz, u_int recvsz) { CLIENT *cl; @@ -212,34 +199,23 @@ clntudp_bufcreate(raddr, prog, vers, wait, sockp, sendsz, recvsz) } CLIENT * -clntudp_create(raddr, program, version, wait, sockp) - struct sockaddr_in *raddr; - u_long program; - u_long version; - struct timeval wait; - int *sockp; +clntudp_create(struct sockaddr_in *raddr, u_long program, u_long version, + struct timeval wait, int *sockp) { return clntudp_bufcreate(raddr, program, version, wait, sockp, UDPMSGSIZE, UDPMSGSIZE); } CLIENT * -clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) - struct sockaddr_in *raddr; - u_long prog; - u_long vers; - int *sockp; - u_int sendsz; - u_int recvsz; +clnttcp_create(struct sockaddr_in *raddr, u_long prog, u_long vers, int *sockp, + u_int sendsz, u_int recvsz) { return clnt_com_create(raddr, (rpcprog_t)prog, (rpcvers_t)vers, sockp, sendsz, recvsz, "tcp"); } CLIENT * -clntraw_create(prog, vers) - u_long prog; - u_long vers; +clntraw_create(u_long prog, u_long vers) { return clnt_raw_create((rpcprog_t)prog, (rpcvers_t)vers); } @@ -248,11 +224,7 @@ clntraw_create(prog, vers) * A common server create routine */ static SVCXPRT * -svc_com_create(fd, sendsize, recvsize, netid) - int fd; - u_int sendsize; - u_int recvsize; - const char *netid; +svc_com_create(int fd, u_int sendsize, u_int recvsize, const char *netid) { struct netconfig *nconf; SVCXPRT *svc; @@ -294,48 +266,38 @@ svc_com_create(fd, sendsize, recvsize, netid) } SVCXPRT * -svctcp_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svctcp_create(int fd, u_int sendsize, u_int recvsize) { return svc_com_create(fd, sendsize, recvsize, "tcp"); } SVCXPRT * -svcudp_bufcreate(fd, sendsz, recvsz) - int fd; - u_int sendsz, recvsz; +svcudp_bufcreate(int fd, u_int sendsz, u_int recvsz) { return svc_com_create(fd, sendsz, recvsz, "udp"); } SVCXPRT * -svcfd_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svcfd_create(int fd, u_int sendsize, u_int recvsize) { return svc_fd_create(fd, sendsize, recvsize); } SVCXPRT * -svcudp_create(fd) - int fd; +svcudp_create(int fd) { return svc_com_create(fd, UDPMSGSIZE, UDPMSGSIZE, "udp"); } SVCXPRT * -svcraw_create() +svcraw_create(void) { return svc_raw_create(); } int -get_myaddress(addr) - struct sockaddr_in *addr; +get_myaddress(struct sockaddr_in *addr) { _DIAGASSERT(addr != NULL); @@ -351,11 +313,8 @@ get_myaddress(addr) * For connectionless "udp" transport. Obsoleted by rpc_call(). */ int -callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) - char *host; - int prognum, versnum, procnum; - xdrproc_t inproc, outproc; - char *in, *out; +callrpc(char *host, int prognum, int versnum, int procnum, + xdrproc_t inproc, char *in, xdrproc_t outproc, char *out) { return (int)rpc_call(host, (rpcprog_t)prognum, (rpcvers_t)versnum, (rpcproc_t)procnum, inproc, in, outproc, out, "udp"); @@ -365,10 +324,9 @@ callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) * For connectionless kind of transport. Obsoleted by rpc_reg() */ int -registerrpc(prognum, versnum, procnum, progname, inproc, outproc) - int prognum, versnum, procnum; - char *(*progname) __P((char [UDPMSGSIZE])); - xdrproc_t inproc, outproc; +registerrpc(int prognum, int versnum, int procnum, + char *(*progname)(char [UDPMSGSIZE]), + xdrproc_t inproc, xdrproc_t outproc) { return rpc_reg((rpcprog_t)prognum, (rpcvers_t)versnum, (rpcproc_t)procnum, progname, inproc, outproc, __UNCONST("udp")); @@ -389,10 +347,10 @@ static resultproc_t clnt_broadcast_result_main; */ /* ARGSUSED */ static bool_t -rpc_wrap_bcast(resultp, addr, nconf) - char *resultp; /* results of the call */ - struct netbuf *addr; /* address of the guy who responded */ - struct netconfig *nconf; /* Netconf of the transport */ +rpc_wrap_bcast( + char *resultp, /* results of the call */ + struct netbuf *addr, /* address of the guy who responded */ + struct netconfig *nconf) /* Netconf of the transport */ { resultproc_t clnt_broadcast_result; @@ -429,15 +387,15 @@ clnt_broadcast_setup(void) * Broadcasts on UDP transport. Obsoleted by rpc_broadcast(). */ enum clnt_stat -clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) - u_long prog; /* program number */ - u_long vers; /* version number */ - u_long proc; /* procedure number */ - xdrproc_t xargs; /* xdr routine for args */ - caddr_t argsp; /* pointer to args */ - xdrproc_t xresults; /* xdr routine for results */ - caddr_t resultsp; /* pointer to results */ - resultproc_t eachresult; /* call with each result obtained */ +clnt_broadcast( + u_long prog, /* program number */ + u_long vers, /* version number */ + u_long proc, /* procedure number */ + xdrproc_t xargs, /* xdr routine for args */ + caddr_t argsp, /* pointer to args */ + xdrproc_t xresults, /* xdr routine for results */ + caddr_t resultsp, /* pointer to results */ + resultproc_t eachresult) /* call with each result obtained */ { #ifdef _REENTRANT if (__isthreaded == 0) diff --git a/lib/libc/rpc/rpcb_clnt.c b/lib/libc/rpc/rpcb_clnt.c index 82d3b763f..2398ff669 100644 --- a/lib/libc/rpc/rpcb_clnt.c +++ b/lib/libc/rpc/rpcb_clnt.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpcb_clnt.c,v 1.25 2010/03/23 20:28:58 drochner Exp $ */ +/* $NetBSD: rpcb_clnt.c,v 1.27 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)rpcb_clnt.c 1.30 89/06/21 Copyr 1988 Sun Micro"; #else -__RCSID("$NetBSD: rpcb_clnt.c,v 1.25 2010/03/23 20:28:58 drochner Exp $"); +__RCSID("$NetBSD: rpcb_clnt.c,v 1.27 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -107,15 +107,12 @@ static int cachesize; extern int __rpc_lowvers; -static struct address_cache *check_cache __P((const char *, const char *)); -static void delete_cache __P((struct netbuf *)); -static void add_cache __P((const char *, const char *, struct netbuf *, - char *)); -static CLIENT *getclnthandle __P((const char *, const struct netconfig *, - char **)); -static CLIENT *local_rpcb __P((void)); -static struct netbuf *got_entry __P((rpcb_entry_list_ptr, - const struct netconfig *)); +static struct address_cache *check_cache(const char *, const char *); +static void delete_cache(struct netbuf *); +static void add_cache(const char *, const char *, struct netbuf *, char *); +static CLIENT *getclnthandle(const char *, const struct netconfig *, char **); +static CLIENT *local_rpcb(void); +static struct netbuf *got_entry(rpcb_entry_list_ptr, const struct netconfig *); /* * This routine adjusts the timeout used for calls to the remote rpcbind. @@ -124,9 +121,7 @@ static struct netbuf *got_entry __P((rpcb_entry_list_ptr, * These are private routines that may not be provided in future releases. */ bool_t -__rpc_control(request, info) - int request; - void *info; +__rpc_control(int request, void *info) { _DIAGASSERT(info != NULL); @@ -171,8 +166,7 @@ extern rwlock_t rpcbaddr_cache_lock; */ static struct address_cache * -check_cache(host, netid) - const char *host, *netid; +check_cache(const char *host, const char *netid) { struct address_cache *cptr; @@ -195,8 +189,7 @@ check_cache(host, netid) } static void -delete_cache(addr) - struct netbuf *addr; +delete_cache(struct netbuf *addr) { struct address_cache *cptr, *prevptr = NULL; @@ -224,10 +217,8 @@ delete_cache(addr) } static void -add_cache(host, netid, taddr, uaddr) - const char *host, *netid; - char *uaddr; - struct netbuf *taddr; +add_cache(const char *host, const char *netid, struct netbuf *taddr, + char *uaddr) { struct address_cache *ad_cache, *cptr, *prevptr; @@ -313,10 +304,7 @@ out: * rpcbind. Returns NULL on error and free's everything. */ static CLIENT * -getclnthandle(host, nconf, targaddr) - const char *host; - const struct netconfig *nconf; - char **targaddr; +getclnthandle(const char *host, const struct netconfig *nconf, char **targaddr) { CLIENT *client; struct netbuf *addr, taddr; @@ -442,7 +430,7 @@ getclnthandle(host, nconf, targaddr) * rpcbind. Returns NULL on error and free's everything. */ static CLIENT * -local_rpcb() +local_rpcb(void) { CLIENT *client; static struct netconfig *loopnconf; @@ -466,13 +454,16 @@ local_rpcb() goto try_nconf; sun.sun_family = AF_LOCAL; strcpy(sun.sun_path, _PATH_RPCBINDSOCK); - nbuf.len = sun.sun_len = SUN_LEN(&sun); + tsize = SUN_LEN(&sun); + _DIAGASSERT(__type_fit(uint8_t, tsize)); + nbuf.len = sun.sun_len = (uint8_t)tsize; nbuf.maxlen = sizeof (struct sockaddr_un); nbuf.buf = &sun; tsize = __rpc_get_t_size(AF_LOCAL, 0, 0); + _DIAGASSERT(__type_fit(u_int, tsize)); client = clnt_vc_create(sock, &nbuf, (rpcprog_t)RPCBPROG, - (rpcvers_t)RPCBVERS, tsize, tsize); + (rpcvers_t)RPCBVERS, (u_int)tsize, (u_int)tsize); if (client != NULL) { /* XXX - mark the socket to be closed in destructor */ @@ -543,11 +534,9 @@ try_nconf: * Calls the rpcbind service to do the mapping. */ bool_t -rpcb_set(program, version, nconf, address) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; /* Network structure of transport */ - const struct netbuf *address; /* Services netconfig address */ +rpcb_set(rpcprog_t program, rpcvers_t version, + const struct netconfig *nconf, /* Network structure of transport */ + const struct netbuf *address) /* Services netconfig address */ { CLIENT *client; bool_t rslt = FALSE; @@ -602,10 +591,7 @@ rpcb_set(program, version, nconf, address) * only for the given transport. */ bool_t -rpcb_unset(program, version, nconf) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; +rpcb_unset(rpcprog_t program, rpcvers_t version, const struct netconfig *nconf) { CLIENT *client; bool_t rslt = FALSE; @@ -640,9 +626,7 @@ rpcb_unset(program, version, nconf) * From the merged list, find the appropriate entry */ static struct netbuf * -got_entry(relp, nconf) - rpcb_entry_list_ptr relp; - const struct netconfig *nconf; +got_entry(rpcb_entry_list_ptr relp, const struct netconfig *nconf) { struct netbuf *na = NULL; rpcb_entry_list_ptr sp; @@ -689,12 +673,8 @@ got_entry(relp, nconf) * starts working properly. Also look under clnt_vc.c. */ struct netbuf * -__rpcb_findaddr(program, version, nconf, host, clpp) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; - const char *host; - CLIENT **clpp; +__rpcb_findaddr(rpcprog_t program, rpcvers_t version, + const struct netconfig *nconf, const char *host, CLIENT **clpp) { CLIENT *client = NULL; RPCB parms; @@ -995,12 +975,9 @@ done: * Assuming that the address is all properly allocated */ int -rpcb_getaddr(program, version, nconf, address, host) - rpcprog_t program; - rpcvers_t version; - const struct netconfig *nconf; - struct netbuf *address; - const char *host; +rpcb_getaddr(rpcprog_t program, rpcvers_t version, + const struct netconfig *nconf, struct netbuf *address, + const char *host) { struct netbuf *na; @@ -1032,9 +1009,7 @@ rpcb_getaddr(program, version, nconf, address, host) * It returns NULL on failure. */ rpcblist * -rpcb_getmaps(nconf, host) - const struct netconfig *nconf; - const char *host; +rpcb_getmaps(const struct netconfig *nconf, const char *host) { rpcblist_ptr head = NULL; CLIENT *client; @@ -1084,18 +1059,18 @@ done: * programs to do a lookup and call in one step. */ enum clnt_stat -rpcb_rmtcall(nconf, host, prog, vers, proc, xdrargs, argsp, - xdrres, resp, tout, addr_ptr) - const struct netconfig *nconf; /* Netconfig structure */ - const char *host; /* Remote host name */ - rpcprog_t prog; - rpcvers_t vers; - rpcproc_t proc; /* Remote proc identifiers */ - xdrproc_t xdrargs, xdrres; /* XDR routines */ - const char *argsp; /* Argument */ - caddr_t resp; /* Result */ - struct timeval tout; /* Timeout value for this call */ - const struct netbuf *addr_ptr; /* Preallocated netbuf address */ +rpcb_rmtcall( + const struct netconfig *nconf, /* Netconfig structure */ + const char *host, /* Remote host name */ + rpcprog_t prog, + rpcvers_t vers, + rpcproc_t proc, /* Remote proc identifiers */ + xdrproc_t xdrargs, + const char *argsp, /* Argument */ + xdrproc_t xdrres, /* XDR routines */ + caddr_t resp, /* Result */ + struct timeval tout, /* Timeout value for this call */ + const struct netbuf *addr_ptr) /* Preallocated netbuf address */ { CLIENT *client; enum clnt_stat stat; @@ -1162,9 +1137,7 @@ error: * Returns 1 if succeeds else 0. */ bool_t -rpcb_gettime(host, timep) - const char *host; - time_t *timep; +rpcb_gettime(const char *host, time_t *timep) { CLIENT *client = NULL; void *handle; @@ -1223,14 +1196,11 @@ rpcb_gettime(host, timep) * really be called because local n2a libraries are always provided. */ char * -rpcb_taddr2uaddr(nconf, taddr) - struct netconfig *nconf; - struct netbuf *taddr; +rpcb_taddr2uaddr(struct netconfig *nconf, struct netbuf *taddr) { CLIENT *client; char *uaddr = NULL; - /* parameter checking */ if (nconf == NULL) { rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; @@ -1257,9 +1227,7 @@ rpcb_taddr2uaddr(nconf, taddr) * really be called because local n2a libraries are always provided. */ struct netbuf * -rpcb_uaddr2taddr(nconf, uaddr) - struct netconfig *nconf; - char *uaddr; +rpcb_uaddr2taddr(struct netconfig *nconf, char *uaddr) { CLIENT *client; struct netbuf *taddr; diff --git a/lib/libc/rpc/rpcb_prot.c b/lib/libc/rpc/rpcb_prot.c index 37c73e70d..d08ef5d3e 100644 --- a/lib/libc/rpc/rpcb_prot.c +++ b/lib/libc/rpc/rpcb_prot.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpcb_prot.c,v 1.9 2006/05/11 17:11:57 mrg Exp $ */ +/* $NetBSD: rpcb_prot.c,v 1.10 2012/06/25 22:32:45 abs Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)rpcb_prot.c 1.9 89/04/21 Copyr 1984 Sun Micro"; #else -__RCSID("$NetBSD: rpcb_prot.c,v 1.9 2006/05/11 17:11:57 mrg Exp $"); +__RCSID("$NetBSD: rpcb_prot.c,v 1.10 2012/06/25 22:32:45 abs Exp $"); #endif #endif @@ -72,9 +72,7 @@ __weak_alias(xdr_netbuf,_xdr_netbuf) bool_t -xdr_rpcb(xdrs, objp) - XDR *xdrs; - RPCB *objp; +xdr_rpcb(XDR *xdrs, RPCB *objp) { _DIAGASSERT(objp != NULL); @@ -121,9 +119,7 @@ xdr_rpcb(xdrs, objp) */ bool_t -xdr_rpcblist_ptr(xdrs, rp) - XDR *xdrs; - rpcblist_ptr *rp; +xdr_rpcblist_ptr(XDR *xdrs, rpcblist_ptr *rp) { /* * more_elements is pre-computed in case the direction is @@ -180,9 +176,7 @@ xdr_rpcblist_ptr(xdrs, rp) * functionality to xdr_rpcblist_ptr(). */ bool_t -xdr_rpcblist(xdrs, rp) - XDR *xdrs; - RPCBLIST **rp; +xdr_rpcblist(XDR *xdrs, RPCBLIST **rp) { bool_t dummy; @@ -192,9 +186,7 @@ xdr_rpcblist(xdrs, rp) bool_t -xdr_rpcb_entry(xdrs, objp) - XDR *xdrs; - rpcb_entry *objp; +xdr_rpcb_entry(XDR *xdrs, rpcb_entry *objp) { _DIAGASSERT(objp != NULL); @@ -218,9 +210,7 @@ xdr_rpcb_entry(xdrs, objp) } bool_t -xdr_rpcb_entry_list_ptr(xdrs, rp) - XDR *xdrs; - rpcb_entry_list_ptr *rp; +xdr_rpcb_entry_list_ptr(XDR *xdrs, rpcb_entry_list_ptr *rp) { /* * more_elements is pre-computed in case the direction is @@ -278,9 +268,7 @@ xdr_rpcb_entry_list_ptr(xdrs, rp) * written for XDR_ENCODE direction only */ bool_t -xdr_rpcb_rmtcallargs(xdrs, p) - XDR *xdrs; - struct rpcb_rmtcallargs *p; +xdr_rpcb_rmtcallargs(XDR *xdrs, struct rpcb_rmtcallargs *p) { struct r_rpcb_rmtcallargs *objp = (struct r_rpcb_rmtcallargs *)(void *)p; @@ -332,9 +320,7 @@ xdr_rpcb_rmtcallargs(xdrs, p) * written for XDR_DECODE direction only */ bool_t -xdr_rpcb_rmtcallres(xdrs, p) - XDR *xdrs; - struct rpcb_rmtcallres *p; +xdr_rpcb_rmtcallres(XDR *xdrs, struct rpcb_rmtcallres *p) { bool_t dummy; struct r_rpcb_rmtcallres *objp = (struct r_rpcb_rmtcallres *)(void *)p; @@ -352,9 +338,7 @@ xdr_rpcb_rmtcallres(xdrs, p) } bool_t -xdr_netbuf(xdrs, objp) - XDR *xdrs; - struct netbuf *objp; +xdr_netbuf(XDR *xdrs, struct netbuf *objp) { bool_t dummy; diff --git a/lib/libc/rpc/rpcb_st_xdr.c b/lib/libc/rpc/rpcb_st_xdr.c index ed235e3e2..8ddc5e524 100644 --- a/lib/libc/rpc/rpcb_st_xdr.c +++ b/lib/libc/rpc/rpcb_st_xdr.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpcb_st_xdr.c,v 1.7 2006/05/11 17:11:57 mrg Exp $ */ +/* $NetBSD: rpcb_st_xdr.c,v 1.9 2012/06/25 22:32:45 abs Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -40,7 +40,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: rpcb_st_xdr.c,v 1.7 2006/05/11 17:11:57 mrg Exp $"); +__RCSID("$NetBSD: rpcb_st_xdr.c,v 1.9 2012/06/25 22:32:45 abs Exp $"); #endif #include "namespace.h" @@ -61,9 +61,7 @@ __weak_alias(xdr_rpcb_stat_byvers,_xdr_rpcb_stat_byvers) #endif bool_t -xdr_rpcbs_addrlist(xdrs, objp) - XDR *xdrs; - rpcbs_addrlist *objp; +xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp) { _DIAGASSERT(objp != NULL); @@ -85,7 +83,7 @@ xdr_rpcbs_addrlist(xdrs, objp) } if (!xdr_pointer(xdrs, (char **)(void *)&objp->next, - sizeof (rpcbs_addrlist), + (u_int)sizeof (rpcbs_addrlist), (xdrproc_t)xdr_rpcbs_addrlist)) { return (FALSE); } @@ -96,9 +94,7 @@ xdr_rpcbs_addrlist(xdrs, objp) /* Link list of all the stats about rmtcall */ bool_t -xdr_rpcbs_rmtcalllist(xdrs, objp) - XDR *xdrs; - rpcbs_rmtcalllist *objp; +xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp) { int32_t *buf; @@ -138,7 +134,7 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) return (FALSE); } if (!xdr_pointer(xdrs, (char **)(void *)&objp->next, - sizeof (rpcbs_rmtcalllist), + (u_int)sizeof (rpcbs_rmtcalllist), (xdrproc_t)xdr_rpcbs_rmtcalllist)) { return (FALSE); } @@ -176,7 +172,7 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) return (FALSE); } if (!xdr_pointer(xdrs, (char **)(void *)&objp->next, - sizeof (rpcbs_rmtcalllist), + (u_int)sizeof (rpcbs_rmtcalllist), (xdrproc_t)xdr_rpcbs_rmtcalllist)) { return (FALSE); } @@ -204,7 +200,7 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) return (FALSE); } if (!xdr_pointer(xdrs, (char **)(void *)&objp->next, - sizeof (rpcbs_rmtcalllist), + (u_int)sizeof (rpcbs_rmtcalllist), (xdrproc_t)xdr_rpcbs_rmtcalllist)) { return (FALSE); } @@ -212,23 +208,19 @@ xdr_rpcbs_rmtcalllist(xdrs, objp) } bool_t -xdr_rpcbs_proc(xdrs, objp) - XDR *xdrs; - rpcbs_proc objp; +xdr_rpcbs_proc(XDR *xdrs, rpcbs_proc objp) { if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBSTAT_HIGHPROC, - sizeof (int), (xdrproc_t)xdr_int)) { + (u_int)sizeof (int), (xdrproc_t)xdr_int)) { return (FALSE); } return (TRUE); } bool_t -xdr_rpcbs_addrlist_ptr(xdrs, objp) - XDR *xdrs; - rpcbs_addrlist_ptr *objp; +xdr_rpcbs_addrlist_ptr(XDR *xdrs, rpcbs_addrlist_ptr *objp) { - if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_addrlist), + if (!xdr_pointer(xdrs, (char **)objp, (u_int)sizeof (rpcbs_addrlist), (xdrproc_t)xdr_rpcbs_addrlist)) { return (FALSE); } @@ -236,11 +228,9 @@ xdr_rpcbs_addrlist_ptr(xdrs, objp) } bool_t -xdr_rpcbs_rmtcalllist_ptr(xdrs, objp) - XDR *xdrs; - rpcbs_rmtcalllist_ptr *objp; +xdr_rpcbs_rmtcalllist_ptr(XDR *xdrs, rpcbs_rmtcalllist_ptr *objp) { - if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_rmtcalllist), + if (!xdr_pointer(xdrs, (char **)objp, (u_int)sizeof (rpcbs_rmtcalllist), (xdrproc_t)xdr_rpcbs_rmtcalllist)) { return (FALSE); } @@ -248,9 +238,7 @@ xdr_rpcbs_rmtcalllist_ptr(xdrs, objp) } bool_t -xdr_rpcb_stat(xdrs, objp) - XDR *xdrs; - rpcb_stat *objp; +xdr_rpcb_stat(XDR *xdrs, rpcb_stat *objp) { _DIAGASSERT(objp != NULL); @@ -275,12 +263,10 @@ xdr_rpcb_stat(xdrs, objp) * being monitored. */ bool_t -xdr_rpcb_stat_byvers(xdrs, objp) - XDR *xdrs; - rpcb_stat_byvers objp; +xdr_rpcb_stat_byvers(XDR *xdrs, rpcb_stat_byvers objp) { if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBVERS_STAT, - sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) { + (u_int)sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) { return (FALSE); } return (TRUE); diff --git a/lib/libc/rpc/svc.c b/lib/libc/rpc/svc.c index 67c67f5fa..b860d9f7a 100644 --- a/lib/libc/rpc/svc.c +++ b/lib/libc/rpc/svc.c @@ -1,4 +1,4 @@ -/* $NetBSD: svc.c,v 1.30 2010/07/08 20:12:37 tron Exp $ */ +/* $NetBSD: svc.c,v 1.31 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)svc.c 1.44 88/02/08 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)svc.c 2.4 88/08/11 4.0 RPCSRC"; #else -__RCSID("$NetBSD: svc.c,v 1.30 2010/07/08 20:12:37 tron Exp $"); +__RCSID("$NetBSD: svc.c,v 1.31 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -108,7 +108,7 @@ static struct svc_callout { rpcprog_t sc_prog; rpcvers_t sc_vers; char *sc_netid; - void (*sc_dispatch) __P((struct svc_req *, SVCXPRT *)); + void (*sc_dispatch)(struct svc_req *, SVCXPRT *); } *svc_head; #ifdef _REENTRANT @@ -116,9 +116,9 @@ extern rwlock_t svc_lock; extern rwlock_t svc_fd_lock; #endif -static struct svc_callout *svc_find __P((rpcprog_t, rpcvers_t, - struct svc_callout **, char *)); -static void __xprt_do_unregister __P((SVCXPRT *xprt, bool_t dolock)); +static struct svc_callout *svc_find(rpcprog_t, rpcvers_t, + struct svc_callout **, char *); +static void __xprt_do_unregister(SVCXPRT *xprt, bool_t dolock); /* *************** SVCXPRT related stuff **************** */ @@ -126,8 +126,7 @@ static void __xprt_do_unregister __P((SVCXPRT *xprt, bool_t dolock)); * Activate a transport handle. */ void -xprt_register(xprt) - SVCXPRT *xprt; +xprt_register(SVCXPRT *xprt) { int sock; @@ -169,9 +168,7 @@ __xprt_unregister_unlocked(SVCXPRT *xprt) * De-activate a transport handle. */ static void -__xprt_do_unregister(xprt, dolock) - SVCXPRT *xprt; - bool_t dolock; +__xprt_do_unregister(SVCXPRT *xprt, bool_t dolock) { int sock; @@ -200,12 +197,9 @@ __xprt_do_unregister(xprt, dolock) * program number comes in. */ bool_t -svc_reg(xprt, prog, vers, dispatch, nconf) - SVCXPRT *xprt; - const rpcprog_t prog; - const rpcvers_t vers; - void (*dispatch) __P((struct svc_req *, SVCXPRT *)); - const struct netconfig *nconf; +svc_reg(SVCXPRT *xprt, const rpcprog_t prog, const rpcvers_t vers, + void (*dispatch)(struct svc_req *, SVCXPRT *), + const struct netconfig *nconf) { bool_t dummy; struct svc_callout *prev; @@ -281,9 +275,7 @@ rpcb_it: * Remove a service program from the callout list. */ void -svc_unreg(prog, vers) - const rpcprog_t prog; - const rpcvers_t vers; +svc_unreg(const rpcprog_t prog, const rpcvers_t vers) { struct svc_callout *prev; struct svc_callout *s; @@ -314,12 +306,8 @@ svc_unreg(prog, vers) * program number comes in. */ bool_t -svc_register(xprt, prog, vers, dispatch, protocol) - SVCXPRT *xprt; - u_long prog; - u_long vers; - void (*dispatch) __P((struct svc_req *, SVCXPRT *)); - int protocol; +svc_register(SVCXPRT *xprt, u_long prog, u_long vers, + void (*dispatch)(struct svc_req *, SVCXPRT *), int protocol) { struct svc_callout *prev; struct svc_callout *s; @@ -354,9 +342,7 @@ pmap_it: * Remove a service program from the callout list. */ void -svc_unregister(prog, vers) - u_long prog; - u_long vers; +svc_unregister(u_long prog, u_long vers) { struct svc_callout *prev; struct svc_callout *s; @@ -381,11 +367,7 @@ svc_unregister(prog, vers) * struct. */ static struct svc_callout * -svc_find(prog, vers, prev, netid) - rpcprog_t prog; - rpcvers_t vers; - struct svc_callout **prev; - char *netid; +svc_find(rpcprog_t prog, rpcvers_t vers, struct svc_callout **prev, char *netid) { struct svc_callout *s, *p; @@ -410,10 +392,7 @@ svc_find(prog, vers, prev, netid) * Send a reply to an rpc request */ bool_t -svc_sendreply(xprt, xdr_results, xdr_location) - SVCXPRT *xprt; - xdrproc_t xdr_results; - const char *xdr_location; +svc_sendreply(SVCXPRT *xprt, xdrproc_t xdr_results, const char *xdr_location) { struct rpc_msg rply; @@ -432,8 +411,7 @@ svc_sendreply(xprt, xdr_results, xdr_location) * No procedure error reply */ void -svcerr_noproc(xprt) - SVCXPRT *xprt; +svcerr_noproc(SVCXPRT *xprt) { struct rpc_msg rply; @@ -450,8 +428,7 @@ svcerr_noproc(xprt) * Can't decode args error reply */ void -svcerr_decode(xprt) - SVCXPRT *xprt; +svcerr_decode(SVCXPRT *xprt) { struct rpc_msg rply; @@ -468,8 +445,7 @@ svcerr_decode(xprt) * Some system error */ void -svcerr_systemerr(xprt) - SVCXPRT *xprt; +svcerr_systemerr(SVCXPRT *xprt) { struct rpc_msg rply; @@ -490,8 +466,7 @@ svcerr_systemerr(xprt) * protocol: the portmapper (or rpc binder). */ void -__svc_versquiet_on(xprt) - SVCXPRT *xprt; +__svc_versquiet_on(SVCXPRT *xprt) { u_long tmp; @@ -502,8 +477,7 @@ __svc_versquiet_on(xprt) } void -__svc_versquiet_off(xprt) - SVCXPRT *xprt; +__svc_versquiet_off(SVCXPRT *xprt) { u_long tmp; @@ -514,15 +488,13 @@ __svc_versquiet_off(xprt) } void -svc_versquiet(xprt) - SVCXPRT *xprt; +svc_versquiet(SVCXPRT *xprt) { __svc_versquiet_on(xprt); } int -__svc_versquiet_get(xprt) - SVCXPRT *xprt; +__svc_versquiet_get(SVCXPRT *xprt) { _DIAGASSERT(xprt != NULL); @@ -535,9 +507,7 @@ __svc_versquiet_get(xprt) * Authentication error reply */ void -svcerr_auth(xprt, why) - SVCXPRT *xprt; - enum auth_stat why; +svcerr_auth(SVCXPRT *xprt, enum auth_stat why) { struct rpc_msg rply; @@ -554,8 +524,7 @@ svcerr_auth(xprt, why) * Auth too weak error reply */ void -svcerr_weakauth(xprt) - SVCXPRT *xprt; +svcerr_weakauth(SVCXPRT *xprt) { _DIAGASSERT(xprt != NULL); @@ -567,8 +536,7 @@ svcerr_weakauth(xprt) * Program unavailable error reply */ void -svcerr_noprog(xprt) - SVCXPRT *xprt; +svcerr_noprog(SVCXPRT *xprt) { struct rpc_msg rply; @@ -585,10 +553,7 @@ svcerr_noprog(xprt) * Program version mismatch error reply */ void -svcerr_progvers(xprt, low_vers, high_vers) - SVCXPRT *xprt; - rpcvers_t low_vers; - rpcvers_t high_vers; +svcerr_progvers(SVCXPRT *xprt, rpcvers_t low_vers, rpcvers_t high_vers) { struct rpc_msg rply; @@ -622,8 +587,7 @@ svcerr_progvers(xprt, low_vers, high_vers) */ void -svc_getreq(rdfds) - int rdfds; +svc_getreq(int rdfds) { fd_set readfds; @@ -633,8 +597,7 @@ svc_getreq(rdfds) } void -svc_getreqset(readfds) - fd_set *readfds; +svc_getreqset(fd_set *readfds) { uint32_t mask, *maskp; int sock, bit, fd; @@ -653,8 +616,7 @@ svc_getreqset(readfds) } void -svc_getreq_common(fd) - int fd; +svc_getreq_common(int fd) { SVCXPRT *xprt; struct svc_req r; @@ -741,9 +703,7 @@ call_done: void -svc_getreq_poll(pfdp, pollretval) - struct pollfd *pfdp; - int pollretval; +svc_getreq_poll(struct pollfd *pfdp, int pollretval) { int i; int fds_found; diff --git a/lib/libc/rpc/svc_auth.c b/lib/libc/rpc/svc_auth.c index e257d79ca..639b801cc 100644 --- a/lib/libc/rpc/svc_auth.c +++ b/lib/libc/rpc/svc_auth.c @@ -1,4 +1,4 @@ -/* $NetBSD: svc_auth.c,v 1.15 2003/09/09 03:56:40 itojun Exp $ */ +/* $NetBSD: svc_auth.c,v 1.16 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)svc_auth.c 1.26 89/02/07 Copyr 1984 Sun Micro"; #else -__RCSID("$NetBSD: svc_auth.c,v 1.15 2003/09/09 03:56:40 itojun Exp $"); +__RCSID("$NetBSD: svc_auth.c,v 1.16 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -77,7 +77,7 @@ __weak_alias(svc_auth_reg,_svc_auth_reg) /* declarations to allow servers to specify new authentication flavors */ struct authsvc { int flavor; - enum auth_stat (*handler) __P((struct svc_req *, struct rpc_msg *)); + enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *); struct authsvc *next; }; static struct authsvc *Auths = NULL; @@ -101,9 +101,7 @@ static struct authsvc *Auths = NULL; * invalid. */ enum auth_stat -_authenticate(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_authenticate(struct svc_req *rqst, struct rpc_msg *msg) { int cred_flavor; struct authsvc *asp; @@ -158,9 +156,7 @@ _authenticate(rqst, msg) /*ARGSUSED*/ enum auth_stat -_svcauth_null(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_svcauth_null(struct svc_req *rqst, struct rpc_msg *msg) { return (AUTH_OK); } @@ -180,9 +176,9 @@ _svcauth_null(rqst, msg) */ int -svc_auth_reg(cred_flavor, handler) - int cred_flavor; - enum auth_stat (*handler) __P((struct svc_req *, struct rpc_msg *)); +svc_auth_reg( + int cred_flavor, + enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *)) { struct authsvc *asp; #ifdef _REENTRANT diff --git a/lib/libc/rpc/svc_auth_unix.c b/lib/libc/rpc/svc_auth_unix.c index c454657a7..9bbf8a83f 100644 --- a/lib/libc/rpc/svc_auth_unix.c +++ b/lib/libc/rpc/svc_auth_unix.c @@ -1,4 +1,4 @@ -/* $NetBSD: svc_auth_unix.c,v 1.18 2003/01/18 11:29:06 thorpej Exp $ */ +/* $NetBSD: svc_auth_unix.c,v 1.20 2012/06/25 22:32:45 abs Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC"; #else -__RCSID("$NetBSD: svc_auth_unix.c,v 1.18 2003/01/18 11:29:06 thorpej Exp $"); +__RCSID("$NetBSD: svc_auth_unix.c,v 1.20 2012/06/25 22:32:45 abs Exp $"); #endif #endif @@ -62,9 +62,7 @@ __RCSID("$NetBSD: svc_auth_unix.c,v 1.18 2003/01/18 11:29:06 thorpej Exp $"); * Unix longhand authenticator */ enum auth_stat -_svcauth_unix(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg) { enum auth_stat stat; XDR xdrs; @@ -106,7 +104,8 @@ _svcauth_unix(rqst, msg) stat = AUTH_BADCRED; goto done; } - aup->aup_len = gid_len; + _DIAGASSERT(__type_fit(u_int, gid_len)); + aup->aup_len = (u_int)gid_len; for (i = 0; i < gid_len; i++) { aup->aup_gids[i] = (int)IXDR_GET_INT32(buf); } @@ -141,9 +140,7 @@ done: */ /*ARGSUSED*/ enum auth_stat -_svcauth_short(rqst, msg) - struct svc_req *rqst; - struct rpc_msg *msg; +_svcauth_short(struct svc_req *rqst, struct rpc_msg *msg) { return (AUTH_REJECTEDCRED); } diff --git a/lib/libc/rpc/svc_dg.c b/lib/libc/rpc/svc_dg.c index 14f19f74c..e213c57f3 100644 --- a/lib/libc/rpc/svc_dg.c +++ b/lib/libc/rpc/svc_dg.c @@ -1,4 +1,4 @@ -/* $NetBSD: svc_dg.c,v 1.12 2008/04/25 17:44:44 christos Exp $ */ +/* $NetBSD: svc_dg.c,v 1.14 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -44,7 +44,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: svc_dg.c,v 1.12 2008/04/25 17:44:44 christos Exp $"); +__RCSID("$NetBSD: svc_dg.c,v 1.14 2012/03/20 17:14:50 matt Exp $"); #endif #include "namespace.h" @@ -78,16 +78,16 @@ __weak_alias(svc_dg_create,_svc_dg_create) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif -static void svc_dg_ops __P((SVCXPRT *)); -static enum xprt_stat svc_dg_stat __P((SVCXPRT *)); -static bool_t svc_dg_recv __P((SVCXPRT *, struct rpc_msg *)); -static bool_t svc_dg_reply __P((SVCXPRT *, struct rpc_msg *)); -static bool_t svc_dg_getargs __P((SVCXPRT *, xdrproc_t, caddr_t)); -static bool_t svc_dg_freeargs __P((SVCXPRT *, xdrproc_t, caddr_t)); -static void svc_dg_destroy __P((SVCXPRT *)); -static bool_t svc_dg_control __P((SVCXPRT *, const u_int, void *)); -static int cache_get __P((SVCXPRT *, struct rpc_msg *, char **, size_t *)); -static void cache_set __P((SVCXPRT *, size_t)); +static void svc_dg_ops(SVCXPRT *); +static enum xprt_stat svc_dg_stat(SVCXPRT *); +static bool_t svc_dg_recv(SVCXPRT *, struct rpc_msg *); +static bool_t svc_dg_reply(SVCXPRT *, struct rpc_msg *); +static bool_t svc_dg_getargs(SVCXPRT *, xdrproc_t, caddr_t); +static bool_t svc_dg_freeargs(SVCXPRT *, xdrproc_t, caddr_t); +static void svc_dg_destroy(SVCXPRT *); +static bool_t svc_dg_control(SVCXPRT *, const u_int, void *); +static int cache_get(SVCXPRT *, struct rpc_msg *, char **, size_t *); +static void cache_set(SVCXPRT *, size_t); /* * Usage: @@ -104,10 +104,7 @@ static const char svc_dg_err2[] = " transport does not support data transfer"; static const char __no_mem_str[] = "out of memory"; SVCXPRT * -svc_dg_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svc_dg_create(int fd, u_int sendsize, u_int recvsize) { SVCXPRT *xprt; struct svc_dg_data *su = NULL; @@ -140,7 +137,8 @@ svc_dg_create(fd, sendsize, recvsize) su->su_iosz = ((MAX(sendsize, recvsize) + 3) / 4) * 4; if ((rpc_buffer(xprt) = malloc(su->su_iosz)) == NULL) goto freedata; - xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz, + _DIAGASSERT(__type_fit(u_int, su->su_iosz)); + xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), (u_int)su->su_iosz, XDR_DECODE); su->su_cache = NULL; xprt->xp_fd = fd; @@ -171,16 +169,13 @@ freedata: /*ARGSUSED*/ static enum xprt_stat -svc_dg_stat(xprt) - SVCXPRT *xprt; +svc_dg_stat(SVCXPRT *xprt) { return (XPRT_IDLE); } static bool_t -svc_dg_recv(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_dg_recv(SVCXPRT *xprt, struct rpc_msg *msg) { struct svc_dg_data *su; XDR *xdrs; @@ -234,9 +229,7 @@ again: } static bool_t -svc_dg_reply(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_dg_reply(SVCXPRT *xprt, struct rpc_msg *msg) { struct svc_dg_data *su; XDR *xdrs; @@ -266,19 +259,13 @@ svc_dg_reply(xprt, msg) } static bool_t -svc_dg_getargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - caddr_t args_ptr; +svc_dg_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr) { return (*xdr_args)(&(su_data(xprt)->su_xdrs), args_ptr); } static bool_t -svc_dg_freeargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - caddr_t args_ptr; +svc_dg_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr) { XDR *xdrs; @@ -290,8 +277,7 @@ svc_dg_freeargs(xprt, xdr_args, args_ptr) } static void -svc_dg_destroy(xprt) - SVCXPRT *xprt; +svc_dg_destroy(SVCXPRT *xprt) { struct svc_dg_data *su; @@ -316,17 +302,13 @@ svc_dg_destroy(xprt) static bool_t /*ARGSUSED*/ -svc_dg_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_dg_control(SVCXPRT *xprt, const u_int rq, void *in) { return (FALSE); } static void -svc_dg_ops(xprt) - SVCXPRT *xprt; +svc_dg_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; @@ -433,9 +415,7 @@ static const char alloc_err[] = "could not allocate cache "; static const char enable_err[] = "cache already enabled"; int -svc_dg_enablecache(transp, size) - SVCXPRT *transp; - u_int size; +svc_dg_enablecache(SVCXPRT *transp, u_int size) { struct svc_dg_data *su; struct cl_cache *uc; @@ -494,9 +474,7 @@ static const char cache_set_err2[] = "victim alloc failed"; static const char cache_set_err3[] = "could not allocate new rpc buffer"; static void -cache_set(xprt, replylen) - SVCXPRT *xprt; - size_t replylen; +cache_set(SVCXPRT *xprt, size_t replylen) { cache_ptr victim; cache_ptr *vicp; @@ -566,8 +544,9 @@ cache_set(xprt, replylen) victim->cache_replylen = replylen; victim->cache_reply = rpc_buffer(xprt); rpc_buffer(xprt) = newbuf; - xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), - su->su_iosz, XDR_ENCODE); + _DIAGASSERT(__type_fit(u_int, su->su_iosz)); + xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), (u_int)su->su_iosz, + XDR_ENCODE); victim->cache_xid = su->su_xid; victim->cache_proc = uc->uc_proc; victim->cache_vers = uc->uc_vers; @@ -589,11 +568,7 @@ cache_set(xprt, replylen) * return 1 if found, 0 if not found and set the stage for cache_set() */ static int -cache_get(xprt, msg, replyp, replylenp) - SVCXPRT *xprt; - struct rpc_msg *msg; - char **replyp; - size_t *replylenp; +cache_get(SVCXPRT *xprt, struct rpc_msg *msg, char **replyp, size_t *replylenp) { u_int loc; cache_ptr ent; diff --git a/lib/libc/rpc/svc_generic.c b/lib/libc/rpc/svc_generic.c index 723555712..634820269 100644 --- a/lib/libc/rpc/svc_generic.c +++ b/lib/libc/rpc/svc_generic.c @@ -1,4 +1,4 @@ -/* $NetBSD: svc_generic.c,v 1.10 2008/04/25 17:44:44 christos Exp $ */ +/* $NetBSD: svc_generic.c,v 1.12 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)svc_generic.c 1.21 89/02/28 Copyr 1988 Sun Micro"; #else -__RCSID("$NetBSD: svc_generic.c,v 1.10 2008/04/25 17:44:44 christos Exp $"); +__RCSID("$NetBSD: svc_generic.c,v 1.12 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -58,7 +58,7 @@ __RCSID("$NetBSD: svc_generic.c,v 1.10 2008/04/25 17:44:44 christos Exp $"); #include #include #include -#include +#include #include #include #include @@ -71,7 +71,7 @@ __weak_alias(svc_tp_create,_svc_tp_create) __weak_alias(svc_tli_create,_svc_tli_create) #endif -extern int __svc_vc_setflag __P((SVCXPRT *, int)); +extern int __svc_vc_setflag(SVCXPRT *, int); /* * The highest level interface for server creation. @@ -83,11 +83,11 @@ extern int __svc_vc_setflag __P((SVCXPRT *, int)); * created earlier instead of creating a new handle every time. */ int -svc_create(dispatch, prognum, versnum, nettype) - void (*dispatch) __P((struct svc_req *, SVCXPRT *)); - rpcprog_t prognum; /* Program number */ - rpcvers_t versnum; /* Version number */ - const char *nettype; /* Networktype token */ +svc_create( + void (*dispatch)(struct svc_req *, SVCXPRT *), + rpcprog_t prognum, /* Program number */ + rpcvers_t versnum, /* Version number */ + const char *nettype) /* Networktype token */ { struct xlist { SVCXPRT *xprt; /* Server handle */ @@ -157,11 +157,11 @@ svc_create(dispatch, prognum, versnum, nettype) * with the rpcbind. It calls svc_tli_create(); */ SVCXPRT * -svc_tp_create(dispatch, prognum, versnum, nconf) - void (*dispatch) __P((struct svc_req *, SVCXPRT *)); - rpcprog_t prognum; /* Program number */ - rpcvers_t versnum; /* Version number */ - const struct netconfig *nconf; /* Netconfig structure for the network */ +svc_tp_create( + void (*dispatch)(struct svc_req *, SVCXPRT *), + rpcprog_t prognum, /* Program number */ + rpcvers_t versnum, /* Version number */ + const struct netconfig *nconf) /* Netconfig structure for the network */ { SVCXPRT *xprt; @@ -197,12 +197,12 @@ svc_tp_create(dispatch, prognum, versnum, nconf) * If sendsz or recvsz are zero, their default values are chosen. */ SVCXPRT * -svc_tli_create(fd, nconf, bindaddr, sendsz, recvsz) - int fd; /* Connection end point */ - const struct netconfig *nconf; /* Netconfig struct for nettoken */ - const struct t_bind *bindaddr; /* Local bind address */ - u_int sendsz; /* Max sendsize */ - u_int recvsz; /* Max recvsize */ +svc_tli_create( + int fd, /* Connection end point */ + const struct netconfig *nconf, /* Netconfig struct for nettoken */ + const struct t_bind *bindaddr, /* Local bind address */ + u_int sendsz, /* Max sendsize */ + u_int recvsz) /* Max recvsize */ { SVCXPRT *xprt = NULL; /* service handle */ bool_t madefd = FALSE; /* whether fd opened here */ diff --git a/lib/libc/rpc/svc_raw.c b/lib/libc/rpc/svc_raw.c index ffeef609c..92520908b 100644 --- a/lib/libc/rpc/svc_raw.c +++ b/lib/libc/rpc/svc_raw.c @@ -1,4 +1,4 @@ -/* $NetBSD: svc_raw.c,v 1.21 2008/05/24 15:59:59 christos Exp $ */ +/* $NetBSD: svc_raw.c,v 1.22 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)svc_raw.c 1.25 89/01/31 Copyr 1984 Sun Micro"; #else -__RCSID("$NetBSD: svc_raw.c,v 1.21 2008/05/24 15:59:59 christos Exp $"); +__RCSID("$NetBSD: svc_raw.c,v 1.22 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -81,19 +81,19 @@ static struct svc_raw_private { extern mutex_t svcraw_lock; #endif -static enum xprt_stat svc_raw_stat __P((SVCXPRT *)); -static bool_t svc_raw_recv __P((SVCXPRT *, struct rpc_msg *)); -static bool_t svc_raw_reply __P((SVCXPRT *, struct rpc_msg *)); -static bool_t svc_raw_getargs __P((SVCXPRT *, xdrproc_t, caddr_t)); -static bool_t svc_raw_freeargs __P((SVCXPRT *, xdrproc_t, caddr_t)); -static void svc_raw_destroy __P((SVCXPRT *)); -static void svc_raw_ops __P((SVCXPRT *)); -static bool_t svc_raw_control __P((SVCXPRT *, const u_int, void *)); +static enum xprt_stat svc_raw_stat(SVCXPRT *); +static bool_t svc_raw_recv(SVCXPRT *, struct rpc_msg *); +static bool_t svc_raw_reply(SVCXPRT *, struct rpc_msg *); +static bool_t svc_raw_getargs(SVCXPRT *, xdrproc_t, caddr_t); +static bool_t svc_raw_freeargs(SVCXPRT *, xdrproc_t, caddr_t); +static void svc_raw_destroy(SVCXPRT *); +static void svc_raw_ops(SVCXPRT *); +static bool_t svc_raw_control(SVCXPRT *, const u_int, void *); char *__rpc_rawcombuf = NULL; SVCXPRT * -svc_raw_create() +svc_raw_create(void) { struct svc_raw_private *srp; /* VARIABLES PROTECTED BY svcraw_lock: svc_raw_private, srp */ @@ -129,17 +129,14 @@ out: /*ARGSUSED*/ static enum xprt_stat -svc_raw_stat(xprt) -SVCXPRT *xprt; /* args needed to satisfy ANSI-C typechecking */ +svc_raw_stat(SVCXPRT *xprt) /* args needed to satisfy ANSI-C typechecking */ { return (XPRT_IDLE); } /*ARGSUSED*/ static bool_t -svc_raw_recv(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_raw_recv(SVCXPRT *xprt, struct rpc_msg *msg) { struct svc_raw_private *srp; XDR *xdrs; @@ -163,9 +160,7 @@ svc_raw_recv(xprt, msg) /*ARGSUSED*/ static bool_t -svc_raw_reply(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_raw_reply(SVCXPRT *xprt, struct rpc_msg *msg) { struct svc_raw_private *srp; XDR *xdrs; @@ -190,10 +185,7 @@ svc_raw_reply(xprt, msg) /*ARGSUSED*/ static bool_t -svc_raw_getargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - caddr_t args_ptr; +svc_raw_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr) { struct svc_raw_private *srp; @@ -209,10 +201,7 @@ svc_raw_getargs(xprt, xdr_args, args_ptr) /*ARGSUSED*/ static bool_t -svc_raw_freeargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - caddr_t args_ptr; +svc_raw_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr) { struct svc_raw_private *srp; XDR *xdrs; @@ -232,24 +221,19 @@ svc_raw_freeargs(xprt, xdr_args, args_ptr) /*ARGSUSED*/ static void -svc_raw_destroy(xprt) -SVCXPRT *xprt; +svc_raw_destroy(SVCXPRT *xprt) { } /*ARGSUSED*/ static bool_t -svc_raw_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_raw_control(SVCXPRT *xprt, const u_int rq, void *in) { return (FALSE); } static void -svc_raw_ops(xprt) - SVCXPRT *xprt; +svc_raw_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; diff --git a/lib/libc/rpc/svc_run.c b/lib/libc/rpc/svc_run.c index 56aea552a..5688f1901 100644 --- a/lib/libc/rpc/svc_run.c +++ b/lib/libc/rpc/svc_run.c @@ -1,4 +1,4 @@ -/* $NetBSD: svc_run.c,v 1.19 2003/01/18 11:29:07 thorpej Exp $ */ +/* $NetBSD: svc_run.c,v 1.20 2012/06/24 15:26:03 christos Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)svc_run.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: svc_run.c,v 1.19 2003/01/18 11:29:07 thorpej Exp $"); +__RCSID("$NetBSD: svc_run.c,v 1.20 2012/06/24 15:26:03 christos Exp $"); #endif #endif @@ -61,7 +61,7 @@ __weak_alias(svc_exit,_svc_exit) #endif void -svc_run() +svc_run(void) { fd_set readfds, cleanfds; struct timeval timeout; @@ -98,7 +98,7 @@ svc_run() * more work to do. */ void -svc_exit() +svc_exit(void) { #ifdef _REENTRANT extern rwlock_t svc_fd_lock; diff --git a/lib/libc/rpc/svc_simple.c b/lib/libc/rpc/svc_simple.c index bf67c00d0..f67013706 100644 --- a/lib/libc/rpc/svc_simple.c +++ b/lib/libc/rpc/svc_simple.c @@ -1,4 +1,4 @@ -/* $NetBSD: svc_simple.c,v 1.30 2008/04/25 17:44:44 christos Exp $ */ +/* $NetBSD: svc_simple.c,v 1.31 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -48,7 +48,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: svc_simple.c,v 1.30 2008/04/25 17:44:44 christos Exp $"); +__RCSID("$NetBSD: svc_simple.c,v 1.31 2012/03/20 17:14:50 matt Exp $"); #endif #include "namespace.h" @@ -68,10 +68,10 @@ __RCSID("$NetBSD: svc_simple.c,v 1.30 2008/04/25 17:44:44 christos Exp $"); __weak_alias(rpc_reg,_rpc_reg) #endif -static void universal __P((struct svc_req *, SVCXPRT *)); +static void universal(struct svc_req *, SVCXPRT *); static struct proglst { - char *(*p_progname) __P((char *)); + char *(*p_progname)(char *); rpcprog_t p_prognum; rpcvers_t p_versnum; rpcproc_t p_procnum; @@ -102,13 +102,14 @@ static const char __no_mem_str[] = "out of memory"; */ int -rpc_reg(prognum, versnum, procnum, progname, inproc, outproc, nettype) - rpcprog_t prognum; /* program number */ - rpcvers_t versnum; /* version number */ - rpcproc_t procnum; /* procedure number */ - char *(*progname) __P((char *)); /* Server routine */ - xdrproc_t inproc, outproc; /* in/out XDR procedures */ - char *nettype; /* nettype */ +rpc_reg( + rpcprog_t prognum, /* program number */ + rpcvers_t versnum, /* version number */ + rpcproc_t procnum, /* procedure number */ + char *(*progname)(char *), /* Server routine */ + xdrproc_t inproc, /* in XDR procedure */ + xdrproc_t outproc, /* out XDR procedure */ + char *nettype) /* nettype */ { struct netconfig *nconf; int done = FALSE; @@ -251,9 +252,7 @@ rpc_reg(prognum, versnum, procnum, progname, inproc, outproc, nettype) */ static void -universal(rqstp, transp) - struct svc_req *rqstp; - SVCXPRT *transp; +universal(struct svc_req *rqstp, SVCXPRT *transp) { rpcprog_t prog; rpcvers_t vers; diff --git a/lib/libc/rpc/svc_vc.c b/lib/libc/rpc/svc_vc.c index 8c334c661..ecb239109 100644 --- a/lib/libc/rpc/svc_vc.c +++ b/lib/libc/rpc/svc_vc.c @@ -1,4 +1,4 @@ -/* $NetBSD: svc_vc.c,v 1.22 2009/02/12 04:38:52 lukem Exp $ */ +/* $NetBSD: svc_vc.c,v 1.26 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC"; #else -__RCSID("$NetBSD: svc_vc.c,v 1.22 2009/02/12 04:38:52 lukem Exp $"); +__RCSID("$NetBSD: svc_vc.c,v 1.26 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -79,23 +79,22 @@ __weak_alias(svc_vc_create,_svc_vc_create) extern rwlock_t svc_fd_lock; #endif -static SVCXPRT *makefd_xprt __P((int, u_int, u_int)); -static bool_t rendezvous_request __P((SVCXPRT *, struct rpc_msg *)); -static enum xprt_stat rendezvous_stat __P((SVCXPRT *)); -static void svc_vc_destroy __P((SVCXPRT *)); -static void __svc_vc_dodestroy __P((SVCXPRT *)); -static int read_vc __P((caddr_t, caddr_t, int)); -static int write_vc __P((caddr_t, caddr_t, int)); -static enum xprt_stat svc_vc_stat __P((SVCXPRT *)); -static bool_t svc_vc_recv __P((SVCXPRT *, struct rpc_msg *)); -static bool_t svc_vc_getargs __P((SVCXPRT *, xdrproc_t, caddr_t)); -static bool_t svc_vc_freeargs __P((SVCXPRT *, xdrproc_t, caddr_t)); -static bool_t svc_vc_reply __P((SVCXPRT *, struct rpc_msg *)); -static void svc_vc_rendezvous_ops __P((SVCXPRT *)); -static void svc_vc_ops __P((SVCXPRT *)); -static bool_t svc_vc_control __P((SVCXPRT *, const u_int, void *)); -static bool_t svc_vc_rendezvous_control __P((SVCXPRT *, const u_int, - void *)); +static SVCXPRT *makefd_xprt(int, u_int, u_int); +static bool_t rendezvous_request(SVCXPRT *, struct rpc_msg *); +static enum xprt_stat rendezvous_stat(SVCXPRT *); +static void svc_vc_destroy(SVCXPRT *); +static void __svc_vc_dodestroy(SVCXPRT *); +static int read_vc(caddr_t, caddr_t, int); +static int write_vc(caddr_t, caddr_t, int); +static enum xprt_stat svc_vc_stat(SVCXPRT *); +static bool_t svc_vc_recv(SVCXPRT *, struct rpc_msg *); +static bool_t svc_vc_getargs(SVCXPRT *, xdrproc_t, caddr_t); +static bool_t svc_vc_freeargs(SVCXPRT *, xdrproc_t, caddr_t); +static bool_t svc_vc_reply(SVCXPRT *, struct rpc_msg *); +static void svc_vc_rendezvous_ops(SVCXPRT *); +static void svc_vc_ops(SVCXPRT *); +static bool_t svc_vc_control(SVCXPRT *, const u_int, void *); +static bool_t svc_vc_rendezvous_control(SVCXPRT *, const u_int, void *); struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */ u_int sendsize; @@ -132,10 +131,7 @@ struct cf_conn { /* kept in xprt->xp_p1 for actual connection */ * 0 => use the system default. */ SVCXPRT * -svc_vc_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svc_vc_create(int fd, u_int sendsize, u_int recvsize) { SVCXPRT *xprt; struct cf_rendezvous *r = NULL; @@ -179,7 +175,8 @@ svc_vc_create(fd, sendsize, recvsize) * We want to be able to check credentials on local sockets. */ if (sslocal.ss_family == AF_LOCAL) - if (setsockopt(fd, 0, LOCAL_CREDS, &one, sizeof one) < 0) + if (setsockopt(fd, 0, LOCAL_CREDS, &one, (socklen_t)sizeof one) + == -1) goto cleanup_svc_vc_create; xprt->xp_ltaddr.maxlen = xprt->xp_ltaddr.len = sslocal.ss_len; @@ -192,13 +189,13 @@ svc_vc_create(fd, sendsize, recvsize) xprt->xp_rtaddr.maxlen = sizeof (struct sockaddr_storage); xprt_register(xprt); - return (xprt); + return xprt; cleanup_svc_vc_create: if (xprt) mem_free(xprt, sizeof(*xprt)); if (r != NULL) mem_free(r, sizeof(*r)); - return (NULL); + return NULL; } /* @@ -206,10 +203,7 @@ cleanup_svc_vc_create: * descriptor as its first input. */ SVCXPRT * -svc_fd_create(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +svc_fd_create(int fd, u_int sendsize, u_int recvsize) { struct sockaddr_storage ss; socklen_t slen; @@ -263,10 +257,7 @@ freedata: } static SVCXPRT * -makefd_xprt(fd, sendsize, recvsize) - int fd; - u_int sendsize; - u_int recvsize; +makefd_xprt(int fd, u_int sendsize, u_int recvsize) { SVCXPRT *xprt; struct cf_conn *cd; @@ -295,7 +286,7 @@ makefd_xprt(fd, sendsize, recvsize) goto out; xprt_register(xprt); - return (xprt); + return xprt; out: warn("svc_tcp: makefd_xprt"); if (xprt) @@ -305,9 +296,7 @@ out: /*ARGSUSED*/ static bool_t -rendezvous_request(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +rendezvous_request(SVCXPRT *xprt, struct rpc_msg *msg) { int sock, flags; struct cf_rendezvous *r; @@ -337,7 +326,7 @@ again: if (__svc_clean_idle(&cleanfds, 0, FALSE)) goto again; } - return (FALSE); + return FALSE; } /* * make a new transporter (re-uses xprt) @@ -380,24 +369,22 @@ again: (void)gettimeofday(&cd->last_recv_time, NULL); - return (FALSE); /* there is never an rpc msg to be processed */ + return FALSE; /* there is never an rpc msg to be processed */ out: (void)close(sock); - return (FALSE); /* there was an error */ + return FALSE; /* there was an error */ } /*ARGSUSED*/ static enum xprt_stat -rendezvous_stat(xprt) - SVCXPRT *xprt; +rendezvous_stat(SVCXPRT *xprt) { - return (XPRT_IDLE); + return XPRT_IDLE; } static void -svc_vc_destroy(xprt) - SVCXPRT *xprt; +svc_vc_destroy(SVCXPRT *xprt) { _DIAGASSERT(xprt != NULL); @@ -406,8 +393,7 @@ svc_vc_destroy(xprt) } static void -__svc_vc_dodestroy(xprt) - SVCXPRT *xprt; +__svc_vc_dodestroy(SVCXPRT *xprt) { struct cf_conn *cd; struct cf_rendezvous *r; @@ -439,26 +425,20 @@ __svc_vc_dodestroy(xprt) /*ARGSUSED*/ static bool_t -svc_vc_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in) { - return (FALSE); + return FALSE; } /*ARGSUSED*/ static bool_t -svc_vc_rendezvous_control(xprt, rq, in) - SVCXPRT *xprt; - const u_int rq; - void *in; +svc_vc_rendezvous_control(SVCXPRT *xprt, const u_int rq, void *in) { struct cf_rendezvous *cfp; cfp = (struct cf_rendezvous *)xprt->xp_p1; if (cfp == NULL) - return (FALSE); + return FALSE; switch (rq) { case SVCGET_CONNMAXREC: *(int *)in = cfp->maxrec; @@ -467,9 +447,9 @@ svc_vc_rendezvous_control(xprt, rq, in) cfp->maxrec = *(int *)in; break; default: - return (FALSE); + return FALSE; } - return (TRUE); + return TRUE; } /* @@ -480,10 +460,7 @@ svc_vc_rendezvous_control(xprt, rq, in) * fatal for the connection. */ static int -read_vc(xprtp, buf, len) - caddr_t xprtp; - caddr_t buf; - int len; +read_vc(caddr_t xprtp, caddr_t buf, int len) { SVCXPRT *xprt; int sock; @@ -540,7 +517,7 @@ read_vc(xprtp, buf, len) cfp = (struct cf_conn *)xprt->xp_p1; if (cfp->nonblock) { - len = read(sock, buf, (size_t)len); + len = (int)read(sock, buf, (size_t)len); if (len < 0) { if (errno == EAGAIN) len = 0; @@ -569,16 +546,16 @@ read_vc(xprtp, buf, len) } } while ((pollfd.revents & POLLIN) == 0); - if ((len = read(sock, buf, (size_t)len)) > 0) { + if ((len = (int)read(sock, buf, (size_t)len)) > 0) { gettimeofday(&cfp->last_recv_time, NULL); - return (len); + return len; } fatal_err: if (crmsg != NULL) free(crmsg); ((struct cf_conn *)(xprt->xp_p1))->strm_stat = XPRT_DIED; - return (-1); + return -1; } /* @@ -586,10 +563,7 @@ fatal_err: * Any error is fatal and the connection is closed. */ static int -write_vc(xprtp, buf, len) - caddr_t xprtp; - caddr_t buf; - int len; +write_vc(caddr_t xprtp, caddr_t buf, int len) { SVCXPRT *xprt; int i, cnt; @@ -605,12 +579,12 @@ write_vc(xprtp, buf, len) gettimeofday(&tv0, NULL); for (cnt = len; cnt > 0; cnt -= i, buf += i) { - if ((i = write(xprt->xp_fd, buf, (size_t)cnt)) < 0) { + if ((i = (int)write(xprt->xp_fd, buf, (size_t)cnt)) < 0) { if (errno != EAGAIN || !cd->nonblock) { cd->strm_stat = XPRT_DIED; - return (-1); + return -1; } - if (cd->nonblock && i != cnt) { + if (cd->nonblock) { /* * For non-blocking connections, do not * take more than 2 seconds writing the @@ -621,17 +595,17 @@ write_vc(xprtp, buf, len) gettimeofday(&tv1, NULL); if (tv1.tv_sec - tv0.tv_sec >= 2) { cd->strm_stat = XPRT_DIED; - return (-1); + return -1; } } + i = 0; } } - return (len); + return len; } static enum xprt_stat -svc_vc_stat(xprt) - SVCXPRT *xprt; +svc_vc_stat(SVCXPRT *xprt) { struct cf_conn *cd; @@ -640,16 +614,14 @@ svc_vc_stat(xprt) cd = (struct cf_conn *)(xprt->xp_p1); if (cd->strm_stat == XPRT_DIED) - return (XPRT_DIED); + return XPRT_DIED; if (! xdrrec_eof(&(cd->xdrs))) - return (XPRT_MOREREQS); - return (XPRT_IDLE); + return XPRT_MOREREQS; + return XPRT_IDLE; } static bool_t -svc_vc_recv(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_vc_recv(SVCXPRT *xprt, struct rpc_msg *msg) { struct cf_conn *cd; XDR *xdrs; @@ -670,31 +642,25 @@ svc_vc_recv(xprt, msg) if (xdr_callmsg(xdrs, msg)) { cd->x_id = msg->rm_xid; - return (TRUE); + return TRUE; } cd->strm_stat = XPRT_DIED; - return (FALSE); + return FALSE; } static bool_t -svc_vc_getargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - caddr_t args_ptr; +svc_vc_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr) { _DIAGASSERT(xprt != NULL); /* args_ptr may be NULL */ - return ((*xdr_args)(&(((struct cf_conn *)(xprt->xp_p1))->xdrs), - args_ptr)); + return (*xdr_args)(&(((struct cf_conn *)(xprt->xp_p1))->xdrs), + args_ptr); } static bool_t -svc_vc_freeargs(xprt, xdr_args, args_ptr) - SVCXPRT *xprt; - xdrproc_t xdr_args; - caddr_t args_ptr; +svc_vc_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, caddr_t args_ptr) { XDR *xdrs; @@ -704,13 +670,11 @@ svc_vc_freeargs(xprt, xdr_args, args_ptr) xdrs = &(((struct cf_conn *)(xprt->xp_p1))->xdrs); xdrs->x_op = XDR_FREE; - return ((*xdr_args)(xdrs, args_ptr)); + return (*xdr_args)(xdrs, args_ptr); } static bool_t -svc_vc_reply(xprt, msg) - SVCXPRT *xprt; - struct rpc_msg *msg; +svc_vc_reply(SVCXPRT *xprt, struct rpc_msg *msg) { struct cf_conn *cd; XDR *xdrs; @@ -726,12 +690,11 @@ svc_vc_reply(xprt, msg) msg->rm_xid = cd->x_id; rstat = xdr_replymsg(xdrs, msg); (void)xdrrec_endofrecord(xdrs, TRUE); - return (rstat); + return rstat; } static void -svc_vc_ops(xprt) - SVCXPRT *xprt; +svc_vc_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; @@ -757,29 +720,23 @@ svc_vc_ops(xprt) } static void -svc_vc_rendezvous_ops(xprt) - SVCXPRT *xprt; +svc_vc_rendezvous_ops(SVCXPRT *xprt) { static struct xp_ops ops; static struct xp_ops2 ops2; #ifdef _REENTRANT extern mutex_t ops_lock; #endif -/* XXXGCC vax compiler unhappy otherwise */ -#ifdef __vax__ -extern void abort(void); -#endif - mutex_lock(&ops_lock); if (ops.xp_recv == NULL) { ops.xp_recv = rendezvous_request; ops.xp_stat = rendezvous_stat; ops.xp_getargs = - (bool_t (*) __P((SVCXPRT *, xdrproc_t, caddr_t)))abort; + (bool_t (*)(SVCXPRT *, xdrproc_t, caddr_t))abort; ops.xp_reply = - (bool_t (*) __P((SVCXPRT *, struct rpc_msg *)))abort; + (bool_t (*)(SVCXPRT *, struct rpc_msg *))abort; ops.xp_freeargs = - (bool_t (*) __P((SVCXPRT *, xdrproc_t, caddr_t)))abort; + (bool_t (*)(SVCXPRT *, xdrproc_t, caddr_t))abort; ops.xp_destroy = svc_vc_destroy; ops2.xp_control = svc_vc_rendezvous_control; } diff --git a/lib/libc/rpc/xdr.3 b/lib/libc/rpc/xdr.3 index 4b606cabc..99c822d34 100644 --- a/lib/libc/rpc/xdr.3 +++ b/lib/libc/rpc/xdr.3 @@ -1,7 +1,7 @@ .\" @(#)xdr.3n 2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI -.\" $NetBSD: xdr.3,v 1.12 2009/10/13 21:39:55 joerg Exp $ +.\" $NetBSD: xdr.3,v 1.14 2011/07/08 19:28:22 wiz Exp $ .\" -.Dd April 17, 2003 +.Dd July 4, 2011 .Dt XDR 3 .Os .Sh NAME @@ -31,6 +31,7 @@ .Nm xdr_reference , .Nm xdr_setpos , .Nm xdr_short , +.Nm xdr_sizeof , .Nm xdrstdio_create , .Nm xdr_string , .Nm xdr_u_char , @@ -99,6 +100,8 @@ .Fn xdr_setpos "XDR *xdrs" "u_int pos" .Ft int .Fn xdr_short "XDR *xdrs" "short *sp" +.Ft nsigned long +.Fn xdr_sizeof "xdrproc_t func" "void *data" .Ft void .Fn xdrstdio_create "XDR *xdrs" "FILE *file" "enum xdr_op op" .Ft int @@ -378,6 +381,11 @@ another. A filter primitive that translates between C short integers and their external representations. This routine returns one if it succeeds, zero otherwise. +.It Fn xdr_sizeof +This routine returns the amount of memory required to encode +.Fa data +using filter +.Fa func . .It Fn xdrstdio_create This routine initializes the XDR stream object pointed to by .Fa xdrs . diff --git a/lib/libc/rpc/xdr.c b/lib/libc/rpc/xdr.c index e084d0de3..7c306057d 100644 --- a/lib/libc/rpc/xdr.c +++ b/lib/libc/rpc/xdr.c @@ -1,4 +1,4 @@ -/* $NetBSD: xdr.c,v 1.28 2006/05/14 02:15:31 christos Exp $ */ +/* $NetBSD: xdr.c,v 1.31 2012/06/25 22:32:45 abs Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)xdr.c 1.35 87/08/12"; static char *sccsid = "@(#)xdr.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: xdr.c,v 1.28 2006/05/14 02:15:31 christos Exp $"); +__RCSID("$NetBSD: xdr.c,v 1.31 2012/06/25 22:32:45 abs Exp $"); #endif #endif @@ -108,9 +108,7 @@ static const char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 }; * Not a filter, but a convenient utility nonetheless */ void -xdr_free(proc, objp) - xdrproc_t proc; - char *objp; +xdr_free(xdrproc_t proc, char *objp) { XDR x; @@ -122,10 +120,7 @@ xdr_free(proc, objp) * XDR nothing */ bool_t -xdr_void(/* xdrs, addr */) - /* XDR *xdrs; */ - /* caddr_t addr; */ -{ +xdr_void(void) { return (TRUE); } @@ -135,9 +130,7 @@ xdr_void(/* xdrs, addr */) * XDR integers */ bool_t -xdr_int(xdrs, ip) - XDR *xdrs; - int *ip; +xdr_int(XDR *xdrs, int *ip) { long l; @@ -168,9 +161,7 @@ xdr_int(xdrs, ip) * XDR unsigned integers */ bool_t -xdr_u_int(xdrs, up) - XDR *xdrs; - u_int *up; +xdr_u_int(XDR *xdrs, u_int *up) { u_long l; @@ -203,9 +194,7 @@ xdr_u_int(xdrs, up) * same as xdr_u_long - open coded to save a proc call! */ bool_t -xdr_long(xdrs, lp) - XDR *xdrs; - long *lp; +xdr_long(XDR *xdrs, long *lp) { _DIAGASSERT(xdrs != NULL); @@ -228,9 +217,7 @@ xdr_long(xdrs, lp) * same as xdr_long - open coded to save a proc call! */ bool_t -xdr_u_long(xdrs, ulp) - XDR *xdrs; - u_long *ulp; +xdr_u_long(XDR *xdrs, u_long *ulp) { _DIAGASSERT(xdrs != NULL); @@ -254,9 +241,7 @@ xdr_u_long(xdrs, ulp) * same as xdr_u_int32_t - open coded to save a proc call! */ bool_t -xdr_int32_t(xdrs, int32_p) - XDR *xdrs; - int32_t *int32_p; +xdr_int32_t(XDR *xdrs, int32_t *int32_p) { long l; @@ -288,9 +273,7 @@ xdr_int32_t(xdrs, int32_p) * same as xdr_int32_t - open coded to save a proc call! */ bool_t -xdr_u_int32_t(xdrs, u_int32_p) - XDR *xdrs; - u_int32_t *u_int32_p; +xdr_u_int32_t(XDR *xdrs, u_int32_t *u_int32_p) { u_long l; @@ -322,9 +305,7 @@ xdr_u_int32_t(xdrs, u_int32_p) * XDR short integers */ bool_t -xdr_short(xdrs, sp) - XDR *xdrs; - short *sp; +xdr_short(XDR *xdrs, short *sp) { long l; @@ -355,9 +336,7 @@ xdr_short(xdrs, sp) * XDR unsigned short integers */ bool_t -xdr_u_short(xdrs, usp) - XDR *xdrs; - u_short *usp; +xdr_u_short(XDR *xdrs, u_short *usp) { u_long l; @@ -389,9 +368,7 @@ xdr_u_short(xdrs, usp) * XDR 16-bit integers */ bool_t -xdr_int16_t(xdrs, int16_p) - XDR *xdrs; - int16_t *int16_p; +xdr_int16_t(XDR *xdrs, int16_t *int16_p) { long l; @@ -422,9 +399,7 @@ xdr_int16_t(xdrs, int16_p) * XDR unsigned 16-bit integers */ bool_t -xdr_u_int16_t(xdrs, u_int16_p) - XDR *xdrs; - u_int16_t *u_int16_p; +xdr_u_int16_t(XDR *xdrs, u_int16_t *u_int16_p) { u_long l; @@ -456,9 +431,7 @@ xdr_u_int16_t(xdrs, u_int16_p) * XDR a char */ bool_t -xdr_char(xdrs, cp) - XDR *xdrs; - char *cp; +xdr_char(XDR *xdrs, char *cp) { int i; @@ -477,9 +450,7 @@ xdr_char(xdrs, cp) * XDR an unsigned char */ bool_t -xdr_u_char(xdrs, cp) - XDR *xdrs; - u_char *cp; +xdr_u_char(XDR *xdrs, u_char *cp) { u_int u; @@ -498,9 +469,7 @@ xdr_u_char(xdrs, cp) * XDR booleans */ bool_t -xdr_bool(xdrs, bp) - XDR *xdrs; - bool_t *bp; +xdr_bool(XDR *xdrs, bool_t *bp) { long lb; @@ -531,9 +500,7 @@ xdr_bool(xdrs, bp) * XDR enumerations */ bool_t -xdr_enum(xdrs, ep) - XDR *xdrs; - enum_t *ep; +xdr_enum(XDR *xdrs, enum_t *ep) { long l; @@ -566,10 +533,7 @@ xdr_enum(xdrs, ep) * cp points to the opaque object and cnt gives the byte length. */ bool_t -xdr_opaque(xdrs, cp, cnt) - XDR *xdrs; - caddr_t cp; - u_int cnt; +xdr_opaque(XDR *xdrs, caddr_t cp, u_int cnt) { u_int rndup; static int crud[BYTES_PER_XDR_UNIT]; @@ -620,11 +584,7 @@ xdr_opaque(xdrs, cp, cnt) * If *cpp is NULL maxsize bytes are allocated */ bool_t -xdr_bytes(xdrs, cpp, sizep, maxsize) - XDR *xdrs; - char **cpp; - u_int *sizep; - u_int maxsize; +xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) { char *sp; /* sp is the actual string pointer */ u_int nodesize; @@ -682,9 +642,7 @@ xdr_bytes(xdrs, cpp, sizep, maxsize) * Implemented here due to commonality of the object. */ bool_t -xdr_netobj(xdrs, np) - XDR *xdrs; - struct netobj *np; +xdr_netobj(XDR *xdrs, struct netobj *np) { _DIAGASSERT(xdrs != NULL); @@ -705,12 +663,13 @@ xdr_netobj(xdrs, np) * If there is no specific or default routine an error is returned. */ bool_t -xdr_union(xdrs, dscmp, unp, choices, dfault) - XDR *xdrs; - enum_t *dscmp; /* enum to decide which arm to work on */ - char *unp; /* the union itself */ - const struct xdr_discrim *choices; /* [value, xdr proc] for each arm */ - xdrproc_t dfault; /* default xdr routine */ +xdr_union( + XDR *xdrs, + enum_t *dscmp, /* enum to decide which arm to work on */ + char *unp, /* the union itself */ + const struct xdr_discrim *choices, /* [value, xdr proc] for each arm */ + xdrproc_t dfault /* default xdr routine */ +) { enum_t dscm; @@ -760,14 +719,12 @@ xdr_union(xdrs, dscmp, unp, choices, dfault) * of the string as specified by a protocol. */ bool_t -xdr_string(xdrs, cpp, maxsize) - XDR *xdrs; - char **cpp; - u_int maxsize; +xdr_string(XDR *xdrs, char **cpp, u_int maxsize) { char *sp; /* sp is the actual string pointer */ u_int size = 0; /* XXX: GCC */ u_int nodesize; + size_t len; _DIAGASSERT(xdrs != NULL); _DIAGASSERT(cpp != NULL); @@ -784,7 +741,9 @@ xdr_string(xdrs, cpp, maxsize) } /* FALLTHROUGH */ case XDR_ENCODE: - size = strlen(sp); + len = strlen(sp); + _DIAGASSERT(__type_fit(u_int, len)); + size = (u_int)len; break; case XDR_DECODE: break; @@ -832,9 +791,7 @@ xdr_string(xdrs, cpp, maxsize) * routines like clnt_call */ bool_t -xdr_wrapstring(xdrs, cpp) - XDR *xdrs; - char **cpp; +xdr_wrapstring(XDR *xdrs, char **cpp) { _DIAGASSERT(xdrs != NULL); @@ -855,9 +812,7 @@ xdr_wrapstring(xdrs, cpp) * XDR 64-bit integers */ bool_t -xdr_int64_t(xdrs, llp) - XDR *xdrs; - int64_t *llp; +xdr_int64_t(XDR *xdrs, int64_t *llp) { u_long ul[2]; @@ -866,8 +821,10 @@ xdr_int64_t(xdrs, llp) switch (xdrs->x_op) { case XDR_ENCODE: - ul[0] = (u_long)((u_int64_t)*llp >> 32) & 0xffffffff; - ul[1] = (u_long)((u_int64_t)*llp) & 0xffffffff; + ul[0] = (u_long)(((uint64_t)*llp >> 32) & + (uint64_t)0xffffffffULL); + ul[1] = (u_long)(((uint64_t)*llp) & + (uint64_t)0xffffffffULL); if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE) return (FALSE); return (XDR_PUTLONG(xdrs, (long *)&ul[1])); @@ -891,9 +848,7 @@ xdr_int64_t(xdrs, llp) * XDR unsigned 64-bit integers */ bool_t -xdr_u_int64_t(xdrs, ullp) - XDR *xdrs; - u_int64_t *ullp; +xdr_u_int64_t(XDR *xdrs, u_int64_t *ullp) { u_long ul[2]; @@ -902,8 +857,8 @@ xdr_u_int64_t(xdrs, ullp) switch (xdrs->x_op) { case XDR_ENCODE: - ul[0] = (u_long)(*ullp >> 32) & 0xffffffff; - ul[1] = (u_long)(*ullp) & 0xffffffff; + ul[0] = (u_long)(*ullp >> 32) & 0xffffffffUL; + ul[1] = (u_long)(*ullp) & 0xffffffffUL; if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE) return (FALSE); return (XDR_PUTLONG(xdrs, (long *)&ul[1])); @@ -927,9 +882,7 @@ xdr_u_int64_t(xdrs, ullp) * XDR hypers */ bool_t -xdr_hyper(xdrs, llp) - XDR *xdrs; - longlong_t *llp; +xdr_hyper(XDR *xdrs, longlong_t *llp) { _DIAGASSERT(xdrs != NULL); @@ -947,9 +900,7 @@ xdr_hyper(xdrs, llp) * XDR unsigned hypers */ bool_t -xdr_u_hyper(xdrs, ullp) - XDR *xdrs; - u_longlong_t *ullp; +xdr_u_hyper(XDR *xdrs, u_longlong_t *ullp) { _DIAGASSERT(xdrs != NULL); @@ -967,9 +918,7 @@ xdr_u_hyper(xdrs, ullp) * XDR longlong_t's */ bool_t -xdr_longlong_t(xdrs, llp) - XDR *xdrs; - longlong_t *llp; +xdr_longlong_t(XDR *xdrs, longlong_t *llp) { _DIAGASSERT(xdrs != NULL); @@ -987,9 +936,7 @@ xdr_longlong_t(xdrs, llp) * XDR u_longlong_t's */ bool_t -xdr_u_longlong_t(xdrs, ullp) - XDR *xdrs; - u_longlong_t *ullp; +xdr_u_longlong_t(XDR *xdrs, u_longlong_t *ullp) { _DIAGASSERT(xdrs != NULL); diff --git a/lib/libc/rpc/xdr_array.c b/lib/libc/rpc/xdr_array.c index 2ddfd3437..113d51342 100644 --- a/lib/libc/rpc/xdr_array.c +++ b/lib/libc/rpc/xdr_array.c @@ -1,4 +1,4 @@ -/* $NetBSD: xdr_array.c,v 1.16 2005/08/05 10:39:05 wiz Exp $ */ +/* $NetBSD: xdr_array.c,v 1.17 2012/06/25 22:32:45 abs Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)xdr_array.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: xdr_array.c,v 1.16 2005/08/05 10:39:05 wiz Exp $"); +__RCSID("$NetBSD: xdr_array.c,v 1.17 2012/06/25 22:32:45 abs Exp $"); #endif #endif @@ -72,13 +72,8 @@ __weak_alias(xdr_vector,_xdr_vector) * xdr procedure to call to handle each element of the array. */ bool_t -xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc) - XDR *xdrs; - caddr_t *addrp; /* array pointer */ - u_int *sizep; /* number of elements */ - u_int maxsize; /* max numberof elements */ - u_int elsize; /* size in bytes of each element */ - xdrproc_t elproc; /* xdr routine to handle each element */ +xdr_array(XDR *xdrs, caddr_t *addrp, u_int *sizep, u_int maxsize, u_int elsize, + xdrproc_t elproc) { u_int i; caddr_t target = *addrp; @@ -149,12 +144,8 @@ xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc) * > xdr_elem: routine to XDR each element */ bool_t -xdr_vector(xdrs, basep, nelem, elemsize, xdr_elem) - XDR *xdrs; - char *basep; - u_int nelem; - u_int elemsize; - xdrproc_t xdr_elem; +xdr_vector(XDR *xdrs, char *basep, u_int nelem, u_int elemsize, + xdrproc_t xdr_elem) { u_int i; char *elptr; diff --git a/lib/libc/rpc/xdr_float.c b/lib/libc/rpc/xdr_float.c index 60d778f38..bd9a31b2a 100644 --- a/lib/libc/rpc/xdr_float.c +++ b/lib/libc/rpc/xdr_float.c @@ -1,4 +1,4 @@ -/* $NetBSD: xdr_float.c,v 1.35 2009/02/14 06:26:42 lukem Exp $ */ +/* $NetBSD: xdr_float.c,v 1.37 2012/06/25 22:32:45 abs Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)xdr_float.c 1.12 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)xdr_float.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: xdr_float.c,v 1.35 2009/02/14 06:26:42 lukem Exp $"); +__RCSID("$NetBSD: xdr_float.c,v 1.37 2012/06/25 22:32:45 abs Exp $"); #endif #endif @@ -109,9 +109,7 @@ static struct sgl_limits { #endif /* vax */ bool_t -xdr_float(xdrs, fp) - XDR *xdrs; - float *fp; +xdr_float(XDR *xdrs, float *fp) { #ifndef IEEEFP struct ieee_single is; @@ -125,7 +123,7 @@ xdr_float(xdrs, fp) #ifdef IEEEFP return (XDR_PUTINT32(xdrs, (int32_t *)(void *)fp)); #else - vs = *((struct vax_single *)fp); + vs = *((struct vax_single *)(void *)fp); for (i = 0, lim = sgl_limits; i < sizeof(sgl_limits)/sizeof(struct sgl_limits); i++, lim++) { @@ -147,7 +145,7 @@ xdr_float(xdrs, fp) #ifdef IEEEFP return (XDR_GETINT32(xdrs, (int32_t *)(void *)fp)); #else - vsp = (struct vax_single *)fp; + vsp = (struct vax_single *)(void *)fp; if (!XDR_GETINT32(xdrs, (int32_t *)(void *)&is)) return (FALSE); for (i = 0, lim = sgl_limits; @@ -161,7 +159,7 @@ xdr_float(xdrs, fp) } vsp->exp = is.exp - IEEE_SNG_BIAS + VAX_SNG_BIAS; vsp->mantissa2 = is.mantissa; - vsp->mantissa1 = (is.mantissa >> 16); + vsp->mantissa1 = ((unsigned int)is.mantissa >> 16); doneit: vsp->sign = is.sign; return (TRUE); @@ -211,9 +209,7 @@ static struct dbl_limits { bool_t -xdr_double(xdrs, dp) - XDR *xdrs; - double *dp; +xdr_double(XDR *xdrs, double *dp) { #ifdef IEEEFP int32_t *i32p; @@ -245,7 +241,7 @@ xdr_double(xdrs, dp) #endif return (rv); #else - vd = *((struct vax_double *)dp); + vd = *((struct vax_double *)(void *)dp); for (i = 0, lim = dbl_limits; i < sizeof(dbl_limits)/sizeof(struct dbl_limits); i++, lim++) { @@ -259,10 +255,11 @@ xdr_double(xdrs, dp) } } id.exp = vd.exp - VAX_DBL_BIAS + IEEE_DBL_BIAS; - id.mantissa1 = (vd.mantissa1 << 13) | (vd.mantissa2 >> 3); + id.mantissa1 = (vd.mantissa1 << 13) | + ((unsigned int)vd.mantissa2 >> 3); id.mantissa2 = ((vd.mantissa2 & MASK(3)) << 29) | (vd.mantissa3 << 13) | - ((vd.mantissa4 >> 3) & MASK(13)); + (((unsigned int)vd.mantissa4 >> 3) & MASK(13)); shipit: id.sign = vd.sign; lp = (int32_t *)(void *)&id; @@ -300,10 +297,10 @@ xdr_double(xdrs, dp) } } vd.exp = id.exp - IEEE_DBL_BIAS + VAX_DBL_BIAS; - vd.mantissa1 = (id.mantissa1 >> 13); + vd.mantissa1 = ((unsigned int)id.mantissa1 >> 13); vd.mantissa2 = ((id.mantissa1 & MASK(13)) << 3) | - (id.mantissa2 >> 29); - vd.mantissa3 = (id.mantissa2 >> 13); + ((unsigned int)id.mantissa2 >> 29); + vd.mantissa3 = ((unsigned int)id.mantissa2 >> 13); vd.mantissa4 = (id.mantissa2 << 3); doneit: vd.sign = id.sign; diff --git a/lib/libc/rpc/xdr_mem.c b/lib/libc/rpc/xdr_mem.c index 366d7c986..3f1adcfc8 100644 --- a/lib/libc/rpc/xdr_mem.c +++ b/lib/libc/rpc/xdr_mem.c @@ -1,4 +1,4 @@ -/* $NetBSD: xdr_mem.c,v 1.17 2006/10/15 16:14:46 christos Exp $ */ +/* $NetBSD: xdr_mem.c,v 1.18 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: xdr_mem.c,v 1.17 2006/10/15 16:14:46 christos Exp $"); +__RCSID("$NetBSD: xdr_mem.c,v 1.18 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -65,18 +65,18 @@ __RCSID("$NetBSD: xdr_mem.c,v 1.17 2006/10/15 16:14:46 christos Exp $"); __weak_alias(xdrmem_create,_xdrmem_create) #endif -static void xdrmem_destroy __P((XDR *)); -static bool_t xdrmem_getlong_aligned __P((XDR *, long *)); -static bool_t xdrmem_putlong_aligned __P((XDR *, const long *)); -static bool_t xdrmem_getlong_unaligned __P((XDR *, long *)); -static bool_t xdrmem_putlong_unaligned __P((XDR *, const long *)); -static bool_t xdrmem_getbytes __P((XDR *, char *, u_int)); -static bool_t xdrmem_putbytes __P((XDR *, const char *, u_int)); +static void xdrmem_destroy(XDR *); +static bool_t xdrmem_getlong_aligned(XDR *, long *); +static bool_t xdrmem_putlong_aligned(XDR *, const long *); +static bool_t xdrmem_getlong_unaligned(XDR *, long *); +static bool_t xdrmem_putlong_unaligned(XDR *, const long *); +static bool_t xdrmem_getbytes(XDR *, char *, u_int); +static bool_t xdrmem_putbytes(XDR *, const char *, u_int); /* XXX: w/64-bit pointers, u_int not enough! */ -static u_int xdrmem_getpos __P((XDR *)); -static bool_t xdrmem_setpos __P((XDR *, u_int)); -static int32_t *xdrmem_inline_aligned __P((XDR *, u_int)); -static int32_t *xdrmem_inline_unaligned __P((XDR *, u_int)); +static u_int xdrmem_getpos(XDR *); +static bool_t xdrmem_setpos(XDR *, u_int); +static int32_t *xdrmem_inline_aligned(XDR *, u_int); +static int32_t *xdrmem_inline_unaligned(XDR *, u_int); static const struct xdr_ops xdrmem_ops_aligned = { xdrmem_getlong_aligned, @@ -107,11 +107,7 @@ static const struct xdr_ops xdrmem_ops_unaligned = { * memory buffer. */ void -xdrmem_create(xdrs, addr, size, op) - XDR *xdrs; - char *addr; - u_int size; - enum xdr_op op; +xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op) { xdrs->x_op = op; @@ -123,16 +119,13 @@ xdrmem_create(xdrs, addr, size, op) /*ARGSUSED*/ static void -xdrmem_destroy(xdrs) - XDR *xdrs; +xdrmem_destroy(XDR *xdrs) { } static bool_t -xdrmem_getlong_aligned(xdrs, lp) - XDR *xdrs; - long *lp; +xdrmem_getlong_aligned(XDR *xdrs, long *lp) { if (xdrs->x_handy < sizeof(int32_t)) @@ -144,9 +137,7 @@ xdrmem_getlong_aligned(xdrs, lp) } static bool_t -xdrmem_putlong_aligned(xdrs, lp) - XDR *xdrs; - const long *lp; +xdrmem_putlong_aligned(XDR *xdrs, const long *lp) { if (xdrs->x_handy < sizeof(int32_t)) @@ -158,9 +149,7 @@ xdrmem_putlong_aligned(xdrs, lp) } static bool_t -xdrmem_getlong_unaligned(xdrs, lp) - XDR *xdrs; - long *lp; +xdrmem_getlong_unaligned(XDR *xdrs, long *lp) { u_int32_t l; @@ -174,9 +163,7 @@ xdrmem_getlong_unaligned(xdrs, lp) } static bool_t -xdrmem_putlong_unaligned(xdrs, lp) - XDR *xdrs; - const long *lp; +xdrmem_putlong_unaligned(XDR *xdrs, const long *lp) { u_int32_t l; @@ -190,10 +177,7 @@ xdrmem_putlong_unaligned(xdrs, lp) } static bool_t -xdrmem_getbytes(xdrs, addr, len) - XDR *xdrs; - char *addr; - u_int len; +xdrmem_getbytes(XDR *xdrs, char *addr, u_int len) { if (xdrs->x_handy < len) @@ -205,10 +189,7 @@ xdrmem_getbytes(xdrs, addr, len) } static bool_t -xdrmem_putbytes(xdrs, addr, len) - XDR *xdrs; - const char *addr; - u_int len; +xdrmem_putbytes(XDR *xdrs, const char *addr, u_int len) { if (xdrs->x_handy < len) @@ -220,8 +201,7 @@ xdrmem_putbytes(xdrs, addr, len) } static u_int -xdrmem_getpos(xdrs) - XDR *xdrs; +xdrmem_getpos(XDR *xdrs) { /* XXX w/64-bit pointers, u_int not enough! */ @@ -229,9 +209,7 @@ xdrmem_getpos(xdrs) } static bool_t -xdrmem_setpos(xdrs, pos) - XDR *xdrs; - u_int pos; +xdrmem_setpos(XDR *xdrs, u_int pos) { char *newaddr = xdrs->x_base + pos; char *lastaddr = (char *)xdrs->x_private + xdrs->x_handy; @@ -244,9 +222,7 @@ xdrmem_setpos(xdrs, pos) } static int32_t * -xdrmem_inline_aligned(xdrs, len) - XDR *xdrs; - u_int len; +xdrmem_inline_aligned(XDR *xdrs, u_int len) { int32_t *buf = 0; @@ -260,9 +236,7 @@ xdrmem_inline_aligned(xdrs, len) /* ARGSUSED */ static int32_t * -xdrmem_inline_unaligned(xdrs, len) - XDR *xdrs; - u_int len; +xdrmem_inline_unaligned(XDR *xdrs, u_int len) { return (0); diff --git a/lib/libc/rpc/xdr_rec.c b/lib/libc/rpc/xdr_rec.c index 6347f25b5..79d5adf40 100644 --- a/lib/libc/rpc/xdr_rec.c +++ b/lib/libc/rpc/xdr_rec.c @@ -1,4 +1,4 @@ -/* $NetBSD: xdr_rec.c,v 1.31 2010/11/23 14:02:01 christos Exp $ */ +/* $NetBSD: xdr_rec.c,v 1.33 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)xdr_rec.c 1.21 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)xdr_rec.c 2.2 88/08/01 4.0 RPCSRC"; #else -__RCSID("$NetBSD: xdr_rec.c,v 1.31 2010/11/23 14:02:01 christos Exp $"); +__RCSID("$NetBSD: xdr_rec.c,v 1.33 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -62,6 +62,7 @@ __RCSID("$NetBSD: xdr_rec.c,v 1.31 2010/11/23 14:02:01 christos Exp $"); #include +#include #include #include #include @@ -83,15 +84,15 @@ __weak_alias(xdrrec_eof,_xdrrec_eof) __weak_alias(xdrrec_skiprecord,_xdrrec_skiprecord) #endif -static bool_t xdrrec_getlong __P((XDR *, long *)); -static bool_t xdrrec_putlong __P((XDR *, const long *)); -static bool_t xdrrec_getbytes __P((XDR *, char *, u_int)); +static bool_t xdrrec_getlong(XDR *, long *); +static bool_t xdrrec_putlong(XDR *, const long *); +static bool_t xdrrec_getbytes(XDR *, char *, u_int); -static bool_t xdrrec_putbytes __P((XDR *, const char *, u_int)); -static u_int xdrrec_getpos __P((XDR *)); -static bool_t xdrrec_setpos __P((XDR *, u_int)); -static int32_t *xdrrec_inline __P((XDR *, u_int)); -static void xdrrec_destroy __P((XDR *)); +static bool_t xdrrec_putbytes(XDR *, const char *, u_int); +static u_int xdrrec_getpos(XDR *); +static bool_t xdrrec_setpos(XDR *, u_int); +static int32_t *xdrrec_inline(XDR *, u_int); +static void xdrrec_destroy(XDR *); static const struct xdr_ops xdrrec_ops = { xdrrec_getlong, @@ -118,23 +119,23 @@ static const struct xdr_ops xdrrec_ops = { * meet the needs of xdr and rpc based on tcp. */ -#define LAST_FRAG ((u_int32_t)(1 << 31)) +#define LAST_FRAG ((uint32_t)(1 << 31)) typedef struct rec_strm { char *tcp_handle; /* * out-goung bits */ - int (*writeit) __P((char *, char *, int)); + int (*writeit)(char *, char *, int); char *out_base; /* output buffer (points to frag header) */ char *out_finger; /* next output position */ char *out_boundry; /* data cannot up to this address */ - u_int32_t *frag_header; /* beginning of curren fragment */ + uint32_t *frag_header; /* beginning of curren fragment */ bool_t frag_sent; /* true if buffer sent in middle of record */ /* * in-coming bits */ - int (*readit) __P((char *, char *, int)); + int (*readit)(char *, char *, int); u_long in_size; /* fixed size of the input buffer */ char *in_base; char *in_finger; /* location of next byte to be had */ @@ -146,7 +147,7 @@ typedef struct rec_strm { bool_t nonblock; bool_t in_haveheader; - u_int32_t in_header; + uint32_t in_header; char *in_hdrp; int in_hdrlen; int in_reclen; @@ -154,13 +155,13 @@ typedef struct rec_strm { int in_maxrec; } RECSTREAM; -static u_int fix_buf_size __P((u_int)); -static bool_t flush_out __P((RECSTREAM *, bool_t)); -static bool_t fill_input_buf __P((RECSTREAM *)); -static bool_t get_input_bytes __P((RECSTREAM *, char *, u_int)); -static bool_t set_input_fragment __P((RECSTREAM *)); -static bool_t skip_input_bytes __P((RECSTREAM *, long)); -static bool_t realloc_stream __P((RECSTREAM *, int)); +static u_int fix_buf_size(u_int); +static bool_t flush_out(RECSTREAM *, bool_t); +static bool_t fill_input_buf(RECSTREAM *); +static bool_t get_input_bytes(RECSTREAM *, char *, u_int); +static bool_t set_input_fragment(RECSTREAM *); +static bool_t skip_input_bytes(RECSTREAM *, long); +static bool_t realloc_stream(RECSTREAM *, int); /* @@ -173,15 +174,15 @@ static bool_t realloc_stream __P((RECSTREAM *, int)); * calls expect that they take an opaque handle rather than an fd. */ void -xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit) - XDR *xdrs; - u_int sendsize; - u_int recvsize; - char *tcp_handle; +xdrrec_create( + XDR *xdrs, + u_int sendsize, + u_int recvsize, + char *tcp_handle, /* like read, but pass it a tcp_handle, not sock */ - int (*readit) __P((char *, char *, int)); + int (*readit)(char *, char *, int), /* like write, but pass it a tcp_handle, not sock */ - int (*writeit) __P((char *, char *, int)); + int (*writeit)(char *, char *, int)) { RECSTREAM *rstrm = mem_alloc(sizeof(RECSTREAM)); @@ -219,8 +220,8 @@ xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit) rstrm->readit = readit; rstrm->writeit = writeit; rstrm->out_finger = rstrm->out_boundry = rstrm->out_base; - rstrm->frag_header = (u_int32_t *)(void *)rstrm->out_base; - rstrm->out_finger += sizeof(u_int32_t); + rstrm->frag_header = (uint32_t *)(void *)rstrm->out_base; + rstrm->out_finger += sizeof(uint32_t); rstrm->out_boundry += sendsize; rstrm->frag_sent = FALSE; rstrm->in_size = recvsize; @@ -243,9 +244,7 @@ xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit) */ static bool_t -xdrrec_getlong(xdrs, lp) - XDR *xdrs; - long *lp; +xdrrec_getlong(XDR *xdrs, long *lp) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); int32_t *buflp = (int32_t *)(void *)(rstrm->in_finger); @@ -254,22 +253,20 @@ xdrrec_getlong(xdrs, lp) /* first try the inline, fast case */ if ((rstrm->fbtbc >= (long)sizeof(int32_t)) && (((uintptr_t)rstrm->in_boundry - (uintptr_t)buflp) >= sizeof(int32_t))) { - *lp = (long)ntohl((u_int32_t)(*buflp)); + *lp = (long)ntohl((uint32_t)(*buflp)); rstrm->fbtbc -= sizeof(int32_t); rstrm->in_finger += sizeof(int32_t); } else { if (! xdrrec_getbytes(xdrs, (char *)(void *)&mylong, - sizeof(int32_t))) + (u_int)sizeof(int32_t))) return (FALSE); - *lp = (long)ntohl((u_int32_t)mylong); + *lp = (long)ntohl((uint32_t)mylong); } return (TRUE); } static bool_t -xdrrec_putlong(xdrs, lp) - XDR *xdrs; - const long *lp; +xdrrec_putlong(XDR *xdrs, const long *lp) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); int32_t *dest_lp = ((int32_t *)(void *)(rstrm->out_finger)); @@ -286,15 +283,12 @@ xdrrec_putlong(xdrs, lp) dest_lp = ((int32_t *)(void *)(rstrm->out_finger)); rstrm->out_finger += sizeof(int32_t); } - *dest_lp = (int32_t)htonl((u_int32_t)(*lp)); + *dest_lp = (int32_t)htonl((uint32_t)(*lp)); return (TRUE); } static bool_t /* must manage buffers, fragments, and records */ -xdrrec_getbytes(xdrs, addr, len) - XDR *xdrs; - char *addr; - u_int len; +xdrrec_getbytes(XDR *xdrs, char *addr, u_int len) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); u_int current; @@ -319,10 +313,7 @@ xdrrec_getbytes(xdrs, addr, len) } static bool_t -xdrrec_putbytes(xdrs, addr, len) - XDR *xdrs; - const char *addr; - u_int len; +xdrrec_putbytes(XDR *xdrs, const char *addr, u_int len) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); size_t current; @@ -334,7 +325,8 @@ xdrrec_putbytes(xdrs, addr, len) memmove(rstrm->out_finger, addr, current); rstrm->out_finger += current; addr += current; - len -= current; + _DIAGASSERT(__type_fit(u_int, current)); + len -= (u_int)current; if (rstrm->out_finger == rstrm->out_boundry) { rstrm->frag_sent = TRUE; if (! flush_out(rstrm, FALSE)) @@ -345,8 +337,7 @@ xdrrec_putbytes(xdrs, addr, len) } static u_int -xdrrec_getpos(xdrs) - XDR *xdrs; +xdrrec_getpos(XDR *xdrs) { RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private; off_t pos; @@ -371,9 +362,7 @@ xdrrec_getpos(xdrs) } static bool_t -xdrrec_setpos(xdrs, pos) - XDR *xdrs; - u_int pos; +xdrrec_setpos(XDR *xdrs, u_int pos) { RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private; u_int currpos = xdrrec_getpos(xdrs); @@ -410,9 +399,7 @@ xdrrec_setpos(xdrs, pos) } static int32_t * -xdrrec_inline(xdrs, len) - XDR *xdrs; - u_int len; +xdrrec_inline(XDR *xdrs, u_int len) { RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private; int32_t *buf = NULL; @@ -442,8 +429,7 @@ xdrrec_inline(xdrs, len) } static void -xdrrec_destroy(xdrs) - XDR *xdrs; +xdrrec_destroy(XDR *xdrs) { RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private; @@ -462,8 +448,7 @@ xdrrec_destroy(xdrs) * this procedure to guarantee proper record alignment. */ bool_t -xdrrec_skiprecord(xdrs) - XDR *xdrs; +xdrrec_skiprecord(XDR *xdrs) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); enum xprt_stat xstat; @@ -497,8 +482,7 @@ xdrrec_skiprecord(xdrs) * after consuming the rest of the current record. */ bool_t -xdrrec_eof(xdrs) - XDR *xdrs; +xdrrec_eof(XDR *xdrs) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); @@ -521,24 +505,22 @@ xdrrec_eof(xdrs) * pipelined procedure calls.) TRUE => immmediate flush to tcp connection. */ bool_t -xdrrec_endofrecord(xdrs, sendnow) - XDR *xdrs; - bool_t sendnow; +xdrrec_endofrecord(XDR *xdrs, bool_t sendnow) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); u_long len; /* fragment length */ if (sendnow || rstrm->frag_sent || - ((u_long)rstrm->out_finger + sizeof(u_int32_t) >= + ((u_long)rstrm->out_finger + sizeof(uint32_t) >= (u_long)rstrm->out_boundry)) { rstrm->frag_sent = FALSE; return (flush_out(rstrm, TRUE)); } len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->frag_header) - - sizeof(u_int32_t); - *(rstrm->frag_header) = htonl((u_int32_t)len | LAST_FRAG); - rstrm->frag_header = (u_int32_t *)(void *)rstrm->out_finger; - rstrm->out_finger += sizeof(u_int32_t); + sizeof(uint32_t); + *(rstrm->frag_header) = htonl((uint32_t)len | LAST_FRAG); + rstrm->frag_header = (uint32_t *)(void *)rstrm->out_finger; + rstrm->out_finger += sizeof(uint32_t); return (TRUE); } @@ -547,10 +529,7 @@ xdrrec_endofrecord(xdrs, sendnow) * Return true if a record is available in the buffer, false if not. */ bool_t -__xdrrec_getrec(xdrs, statp, expectdata) - XDR *xdrs; - enum xprt_stat *statp; - bool_t expectdata; +__xdrrec_getrec(XDR *xdrs, enum xprt_stat *statp, bool_t expectdata) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); ssize_t n; @@ -568,7 +547,8 @@ __xdrrec_getrec(xdrs, statp, expectdata) return FALSE; } rstrm->in_hdrp += n; - rstrm->in_hdrlen += n; + _DIAGASSERT(__type_fit(int, n)); + rstrm->in_hdrlen += (int)n; if (rstrm->in_hdrlen < (int)sizeof(rstrm->in_header)) { *statp = XPRT_MOREREQS; return FALSE; @@ -607,7 +587,8 @@ __xdrrec_getrec(xdrs, statp, expectdata) return FALSE; } - rstrm->in_received += n; + _DIAGASSERT(__type_fit(int, n)); + rstrm->in_received += (int)n; if (rstrm->in_received == rstrm->in_reclen) { rstrm->in_haveheader = FALSE; @@ -628,9 +609,7 @@ __xdrrec_getrec(xdrs, statp, expectdata) } bool_t -__xdrrec_setnonblock(xdrs, maxrec) - XDR *xdrs; - int maxrec; +__xdrrec_setnonblock(XDR *xdrs, int maxrec) { RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private); @@ -646,39 +625,36 @@ __xdrrec_setnonblock(xdrs, maxrec) * Internal useful routines */ static bool_t -flush_out(rstrm, eor) - RECSTREAM *rstrm; - bool_t eor; +flush_out(RECSTREAM *rstrm, bool_t eor) { - u_int32_t eormask = (eor == TRUE) ? LAST_FRAG : 0; - u_int32_t len = (u_int32_t)((u_long)(rstrm->out_finger) - - (u_long)(rstrm->frag_header) - sizeof(u_int32_t)); + uint32_t eormask = (eor == TRUE) ? LAST_FRAG : 0; + uint32_t len = (uint32_t)((u_long)(rstrm->out_finger) - + (u_long)(rstrm->frag_header) - sizeof(uint32_t)); *(rstrm->frag_header) = htonl(len | eormask); - len = (u_int32_t)((u_long)(rstrm->out_finger) - + len = (uint32_t)((u_long)(rstrm->out_finger) - (u_long)(rstrm->out_base)); if ((*(rstrm->writeit))(rstrm->tcp_handle, rstrm->out_base, (int)len) != (int)len) return (FALSE); - rstrm->frag_header = (u_int32_t *)(void *)rstrm->out_base; - rstrm->out_finger = (char *)rstrm->out_base + sizeof(u_int32_t); + rstrm->frag_header = (uint32_t *)(void *)rstrm->out_base; + rstrm->out_finger = (char *)rstrm->out_base + sizeof(uint32_t); return (TRUE); } static bool_t /* knows nothing about records! Only about input buffers */ -fill_input_buf(rstrm) - RECSTREAM *rstrm; +fill_input_buf(RECSTREAM *rstrm) { char *where; - u_int32_t i; + uint32_t i; int len; if (rstrm->nonblock) return FALSE; where = rstrm->in_base; - i = (u_int32_t)((u_long)rstrm->in_boundry % BYTES_PER_XDR_UNIT); + i = (uint32_t)((u_long)rstrm->in_boundry % BYTES_PER_XDR_UNIT); where += i; - len = (u_int32_t)(rstrm->in_size - i); + len = (uint32_t)(rstrm->in_size - i); if ((len = (*(rstrm->readit))(rstrm->tcp_handle, where, len)) == -1) return (FALSE); rstrm->in_finger = where; @@ -688,10 +664,7 @@ fill_input_buf(rstrm) } static bool_t /* knows nothing about records! Only about input buffers */ -get_input_bytes(rstrm, addr, len) - RECSTREAM *rstrm; - char *addr; - u_int len; +get_input_bytes(RECSTREAM *rstrm, char *addr, u_int len) { u_int current; @@ -704,8 +677,10 @@ get_input_bytes(rstrm, addr, len) } while (len > 0) { - current = ((uintptr_t)rstrm->in_boundry - + uintptr_t d = ((uintptr_t)rstrm->in_boundry - (uintptr_t)rstrm->in_finger); + _DIAGASSERT(__type_fit(u_int, d)); + current = (u_int)d; if (current == 0) { if (! fill_input_buf(rstrm)) return (FALSE); @@ -721,14 +696,14 @@ get_input_bytes(rstrm, addr, len) } static bool_t /* next two bytes of the input stream are treated as a header */ -set_input_fragment(rstrm) - RECSTREAM *rstrm; +set_input_fragment(RECSTREAM *rstrm) { - u_int32_t header; + uint32_t header; if (rstrm->nonblock) return FALSE; - if (! get_input_bytes(rstrm, (char *)(void *)&header, sizeof(header))) + if (! get_input_bytes(rstrm, (char *)(void *)&header, + (u_int)sizeof(header))) return (FALSE); header = ntohl(header); rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE; @@ -747,21 +722,19 @@ set_input_fragment(rstrm) } static bool_t /* consumes input bytes; knows nothing about records! */ -skip_input_bytes(rstrm, cnt) - RECSTREAM *rstrm; - long cnt; +skip_input_bytes(RECSTREAM *rstrm, long cnt) { - u_int32_t current; + uint32_t current; while (cnt > 0) { - current = (size_t)((long)rstrm->in_boundry - + current = (uint32_t)((long)rstrm->in_boundry - (long)rstrm->in_finger); if (current == 0) { if (! fill_input_buf(rstrm)) return (FALSE); continue; } - current = ((u_int32_t)cnt < current) ? (u_int32_t)cnt : current; + current = ((uint32_t)cnt < current) ? (uint32_t)cnt : current; rstrm->in_finger += current; cnt -= current; } @@ -769,8 +742,7 @@ skip_input_bytes(rstrm, cnt) } static u_int -fix_buf_size(s) - u_int s; +fix_buf_size(u_int s) { if (s < 100) @@ -782,9 +754,7 @@ fix_buf_size(s) * Reallocate the input buffer for a non-block stream. */ static bool_t -realloc_stream(rstrm, size) - RECSTREAM *rstrm; - int size; +realloc_stream(RECSTREAM *rstrm, int size) { ptrdiff_t diff; char *buf; diff --git a/lib/libc/rpc/xdr_reference.c b/lib/libc/rpc/xdr_reference.c index b0f074c54..25b085ece 100644 --- a/lib/libc/rpc/xdr_reference.c +++ b/lib/libc/rpc/xdr_reference.c @@ -1,4 +1,4 @@ -/* $NetBSD: xdr_reference.c,v 1.15 2008/04/25 17:44:44 christos Exp $ */ +/* $NetBSD: xdr_reference.c,v 1.16 2012/06/25 22:32:45 abs Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)xdr_reference.c 1.11 87/08/11 SMI"; static char *sccsid = "@(#)xdr_reference.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: xdr_reference.c,v 1.15 2008/04/25 17:44:44 christos Exp $"); +__RCSID("$NetBSD: xdr_reference.c,v 1.16 2012/06/25 22:32:45 abs Exp $"); #endif #endif @@ -73,11 +73,7 @@ __weak_alias(xdr_reference,_xdr_reference) * proc is the routine to handle the referenced structure. */ bool_t -xdr_reference(xdrs, pp, size, proc) - XDR *xdrs; - caddr_t *pp; /* the pointer to work on */ - u_int size; /* size of the object pointed to */ - xdrproc_t proc; /* xdr routine to handle the object */ +xdr_reference(XDR *xdrs, caddr_t *pp, u_int size, xdrproc_t proc) { caddr_t loc = *pp; bool_t stat; @@ -130,11 +126,7 @@ xdr_reference(xdrs, pp, size, proc) * */ bool_t -xdr_pointer(xdrs,objpp,obj_size,xdr_obj) - XDR *xdrs; - char **objpp; - u_int obj_size; - xdrproc_t xdr_obj; +xdr_pointer(XDR *xdrs, char **objpp, u_int obj_size, xdrproc_t xdr_obj) { bool_t more_data; diff --git a/lib/libc/rpc/xdr_sizeof.c b/lib/libc/rpc/xdr_sizeof.c new file mode 100644 index 000000000..08eaaa4e9 --- /dev/null +++ b/lib/libc/rpc/xdr_sizeof.c @@ -0,0 +1,170 @@ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ +/* + * xdr_sizeof.c + * + * Copyright 1990 Sun Microsystems, Inc. + * + * General purpose routine to see how much space something will use + * when serialized using XDR. + */ + +#include +#if 0 +__FBSDID("$FreeBSD: src/lib/libc/xdr/xdr_sizeof.c,v 1.5.38.1 2010/12/21 17:10:29 kensmith Exp $"); +#else +__RCSID("$NetBSD: xdr_sizeof.c,v 1.4 2012/03/20 17:14:50 matt Exp $"); +#endif + +#include "namespace.h" +#include +#include +#include +#include + +#ifdef __weak_alias +__weak_alias(xdr_sizeof,_xdr_sizeof) +#endif + +static bool_t x_putlong(XDR *, const long *); +static bool_t x_putbytes(XDR *, const char *, u_int); +static u_int x_getpostn(XDR *); +static bool_t x_setpostn(XDR *, u_int); +static int32_t *x_inline(XDR *, u_int); +static int harmless(void); +static void x_destroy(XDR *); + +/* ARGSUSED */ +static bool_t +x_putlong(XDR *xdrs, const long *longp) +{ + xdrs->x_handy += BYTES_PER_XDR_UNIT; + return (TRUE); +} + +/* ARGSUSED */ +static bool_t +x_putbytes(XDR *xdrs, const char *bp, u_int len) +{ + xdrs->x_handy += len; + return (TRUE); +} + +static u_int +x_getpostn(XDR *xdrs) +{ + return (xdrs->x_handy); +} + +/* ARGSUSED */ +static bool_t +x_setpostn(XDR *xdrs, u_int pos) +{ + /* This is not allowed */ + return (FALSE); +} + +static int32_t * +x_inline(XDR *xdrs, u_int len) +{ + if (len == 0) { + return (NULL); + } + if (xdrs->x_op != XDR_ENCODE) { + return (NULL); + } + if (len < (u_int)(uintptr_t)xdrs->x_base) { + /* x_private was already allocated */ + xdrs->x_handy += len; + return ((int32_t *) xdrs->x_private); + } else { + /* Free the earlier space and allocate new area */ + if (xdrs->x_private) + free(xdrs->x_private); + if ((xdrs->x_private = malloc(len)) == NULL) { + xdrs->x_base = 0; + return (NULL); + } + xdrs->x_base = (caddr_t)(uintptr_t)len; + xdrs->x_handy += len; + return ((int32_t *) xdrs->x_private); + } +} + +static int +harmless(void) +{ + /* Always return FALSE/NULL, as the case may be */ + return (0); +} + +static void +x_destroy(XDR *xdrs) +{ + xdrs->x_handy = 0; + xdrs->x_base = 0; + if (xdrs->x_private) { + free(xdrs->x_private); + xdrs->x_private = NULL; + } + return; +} + +unsigned long +xdr_sizeof(xdrproc_t func, void *data) +{ + XDR x; + struct xdr_ops ops; + bool_t stat; + /* to stop ANSI-C compiler from complaining */ + typedef bool_t (* dummyfunc1)(XDR *, long *); + typedef bool_t (* dummyfunc2)(XDR *, caddr_t, u_int); + + ops.x_putlong = x_putlong; + ops.x_putbytes = x_putbytes; + ops.x_inline = x_inline; + ops.x_getpostn = x_getpostn; + ops.x_setpostn = x_setpostn; + ops.x_destroy = x_destroy; + + /* the other harmless ones */ + ops.x_getlong = (dummyfunc1) harmless; + ops.x_getbytes = (dummyfunc2) harmless; + + x.x_op = XDR_ENCODE; + x.x_ops = &ops; + x.x_handy = 0; + x.x_private = (caddr_t) NULL; + x.x_base = (caddr_t) 0; + + stat = func(&x, data); + if (x.x_private) + free(x.x_private); + return (stat == TRUE ? (unsigned) x.x_handy: 0); +} diff --git a/lib/libc/rpc/xdr_stdio.c b/lib/libc/rpc/xdr_stdio.c index fcf8dd85b..e2ac2375a 100644 --- a/lib/libc/rpc/xdr_stdio.c +++ b/lib/libc/rpc/xdr_stdio.c @@ -1,4 +1,4 @@ -/* $NetBSD: xdr_stdio.c,v 1.17 2006/10/15 16:14:46 christos Exp $ */ +/* $NetBSD: xdr_stdio.c,v 1.18 2012/03/20 17:14:50 matt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -35,7 +35,7 @@ static char *sccsid = "@(#)xdr_stdio.c 1.16 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)xdr_stdio.c 2.1 88/07/29 4.0 RPCSRC"; #else -__RCSID("$NetBSD: xdr_stdio.c,v 1.17 2006/10/15 16:14:46 christos Exp $"); +__RCSID("$NetBSD: xdr_stdio.c,v 1.18 2012/03/20 17:14:50 matt Exp $"); #endif #endif @@ -60,14 +60,14 @@ __RCSID("$NetBSD: xdr_stdio.c,v 1.17 2006/10/15 16:14:46 christos Exp $"); __weak_alias(xdrstdio_create,_xdrstdio_create) #endif -static void xdrstdio_destroy __P((XDR *)); -static bool_t xdrstdio_getlong __P((XDR *, long *)); -static bool_t xdrstdio_putlong __P((XDR *, const long *)); -static bool_t xdrstdio_getbytes __P((XDR *, char *, u_int)); -static bool_t xdrstdio_putbytes __P((XDR *, const char *, u_int)); -static u_int xdrstdio_getpos __P((XDR *)); -static bool_t xdrstdio_setpos __P((XDR *, u_int)); -static int32_t *xdrstdio_inline __P((XDR *, u_int)); +static void xdrstdio_destroy(XDR *); +static bool_t xdrstdio_getlong(XDR *, long *); +static bool_t xdrstdio_putlong(XDR *, const long *); +static bool_t xdrstdio_getbytes(XDR *, char *, u_int); +static bool_t xdrstdio_putbytes(XDR *, const char *, u_int); +static u_int xdrstdio_getpos(XDR *); +static bool_t xdrstdio_setpos(XDR *, u_int); +static int32_t *xdrstdio_inline(XDR *, u_int); /* * Ops vector for stdio type XDR @@ -90,10 +90,7 @@ static const struct xdr_ops xdrstdio_ops = { * Operation flag is set to op. */ void -xdrstdio_create(xdrs, file, op) - XDR *xdrs; - FILE *file; - enum xdr_op op; +xdrstdio_create(XDR *xdrs, FILE *file, enum xdr_op op) { xdrs->x_op = op; @@ -108,17 +105,14 @@ xdrstdio_create(xdrs, file, op) * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create. */ static void -xdrstdio_destroy(xdrs) - XDR *xdrs; +xdrstdio_destroy(XDR *xdrs) { (void)fflush((FILE *)xdrs->x_private); /* XXX: should we close the file ?? */ } static bool_t -xdrstdio_getlong(xdrs, lp) - XDR *xdrs; - long *lp; +xdrstdio_getlong(XDR *xdrs, long *lp) { u_int32_t temp; @@ -129,9 +123,7 @@ xdrstdio_getlong(xdrs, lp) } static bool_t -xdrstdio_putlong(xdrs, lp) - XDR *xdrs; - const long *lp; +xdrstdio_putlong(XDR *xdrs, const long *lp) { int32_t mycopy = htonl((u_int32_t)*lp); @@ -141,10 +133,7 @@ xdrstdio_putlong(xdrs, lp) } static bool_t -xdrstdio_getbytes(xdrs, addr, len) - XDR *xdrs; - char *addr; - u_int len; +xdrstdio_getbytes(XDR *xdrs, char *addr, u_int len) { if ((len != 0) && (fread(addr, (size_t)len, 1, (FILE *)xdrs->x_private) != 1)) @@ -153,10 +142,7 @@ xdrstdio_getbytes(xdrs, addr, len) } static bool_t -xdrstdio_putbytes(xdrs, addr, len) - XDR *xdrs; - const char *addr; - u_int len; +xdrstdio_putbytes(XDR *xdrs, const char *addr, u_int len) { if ((len != 0) && (fwrite(addr, (size_t)len, 1, @@ -166,17 +152,14 @@ xdrstdio_putbytes(xdrs, addr, len) } static u_int -xdrstdio_getpos(xdrs) - XDR *xdrs; +xdrstdio_getpos(XDR *xdrs) { return ((u_int) ftell((FILE *)xdrs->x_private)); } static bool_t -xdrstdio_setpos(xdrs, pos) - XDR *xdrs; - u_int pos; +xdrstdio_setpos(XDR *xdrs, u_int pos) { return ((fseek((FILE *)xdrs->x_private, (long)pos, 0) < 0) ? @@ -185,9 +168,7 @@ xdrstdio_setpos(xdrs, pos) /* ARGSUSED */ static int32_t * -xdrstdio_inline(xdrs, len) - XDR *xdrs; - u_int len; +xdrstdio_inline(XDR *xdrs, u_int len) { /* diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index 97c9f92d6..8709d4b83 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,2 +1,38 @@ +# $NetBSD: shlib_version,v 1.235 2012/08/24 06:12:52 dholland Exp $ +# Remember to update distrib/sets/lists/base/shl.* when changing +# +# things we wish to do on next major version bump: +# - libc/net/rcmd.c: make __ivaliduser() and __ivaliduser_sa() static +# - libc/net: resolver update to BIND8/9? +# - md2, md4, md5, rmd160 & sha1 functions should take the same arguments AFAP +# - Crypto hashes have name overlap with libcrypto, rename them +# - libc/gen/assert.c: __{diag,}assert13() -> __{diag,}assert() +# - libc/gen/times.c: remove; __times13() -> times() +# - libc/gen/timezone.c: remove; __timezone13 -> timezone +# - libc/net/getaddrinfo.c, netdb.h: remove __ai_pad0 +# - libc/gen/utmpx.c, utmpx.h: remove lastlogxname, __getlastlogx13 -> getlastlogx +# - libc/gen/utmpx.c, utmpx.h: add expansion space to struct lastlogx +# - infinity{,f,l}.c, math.h: __infinity -> __huge_val +# - libc/gen/is{inf,nan}d_ieee754.c: remove is{inf,nan} aliases +# - libc/arch/vax/gen/is{inf,nan}.c: remove +# - libc/db/hash/ndbm.c: remove; __ndbm13 -> ndbm +# - libc/net/getnet{ent,namadr}.c, netdb.h: remove __n_pad0 +# - libc/stdio: make _file an int, hide struct FILE, stdin, stdout, stderr impls +# - libc/stdio: make fileno() not a macro +# - libc/stdio: make stdio macro users depend on some library symbol +# - remove frexp, ldexp, modf: they belong to libm. +# - make sure we can support thread local [on arm don't use r9 for example, +# consider other risc architectures: mips, powerpc, sparc, etc] +# - rename __libc_mutex_lock and similar back to pthread_mutex_lock. +# the functions are used by third party code without prototypes. +# for example in assembler code. +# - kill sigcontext: never request version 0 or 1 signal trampoline. +# always request version 2 trampoline. (on vax, 3). +# - change _ctype_ table in ctype.h and gen/ctype_.c 8bit -> 16 or 32bit. +# it's insufficient bitwidth to implement all ctype class. +# see isblank's comment in ctype.h. +# - remove gets(); it is finally dead in c11. +# - make __cerror (spelled CERROR) hidden again +# - remove ruserok() and friends to libcompat (or entirely) major=0 minor=0 diff --git a/lib/libc/softfloat/Makefile.inc b/lib/libc/softfloat/Makefile.inc index 72a260f35..d31d18768 100644 --- a/lib/libc/softfloat/Makefile.inc +++ b/lib/libc/softfloat/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.7 2011/01/17 10:08:35 matt Exp $ +# $NetBSD: Makefile.inc,v 1.10 2011/07/04 02:53:15 mrg Exp $ SOFTFLOAT_BITS?=64 .PATH: ${ARCHDIR}/softfloat \ @@ -18,3 +18,11 @@ SRCS.softfloat+=eqsf2.c nesf2.c gtsf2.c gesf2.c ltsf2.c lesf2.c negsf2.c \ nexf2.c gtxf2.c gexf2.c negxf2.c unordsf2.c unorddf2.c SRCS+= ${SRCS.softfloat} + +# XXX +.if defined(HAVE_GCC) && ${HAVE_GCC} >= 45 && \ + (${MACHINE_CPU} == "arm" || \ + ${MACHINE_CPU} == "mips" || \ + ${MACHINE_CPU} == "sh3") +COPTS.softfloat.c+= -Wno-enum-compare +.endif diff --git a/lib/libc/softfloat/bits32/softfloat.c b/lib/libc/softfloat/bits32/softfloat.c index bf9c37e4f..2fd15f949 100644 --- a/lib/libc/softfloat/bits32/softfloat.c +++ b/lib/libc/softfloat/bits32/softfloat.c @@ -1,4 +1,4 @@ -/* $NetBSD: softfloat.c,v 1.1 2002/05/21 23:51:07 bjh21 Exp $ */ +/* $NetBSD: softfloat.c,v 1.2 2012/03/21 14:17:54 christos Exp $ */ /* * This version hacked for use with gcc -msoft-float by bjh21. @@ -53,7 +53,7 @@ this code that are retained. #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: softfloat.c,v 1.1 2002/05/21 23:51:07 bjh21 Exp $"); +__RCSID("$NetBSD: softfloat.c,v 1.2 2012/03/21 14:17:54 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #ifdef SOFTFLOAT_FOR_GCC @@ -237,7 +237,7 @@ static float32 roundAndPackFloat32( flag zSign, int16 zExp, bits32 zSig ) isTiny = ( float_detect_tininess == float_tininess_before_rounding ) || ( zExp < -1 ) - || ( zSig + roundIncrement < 0x80000000 ); + || ( zSig + roundIncrement < (uint32)0x80000000 ); shift32RightJamming( zSig, - zExp, &zSig ); zExp = 0; roundBits = zSig & 0x7F; @@ -281,7 +281,7 @@ floating-point value `a'. INLINE bits32 extractFloat64Frac1( float64 a ) { - return FLOAT64_DEMANGLE(a) & LIT64( 0x00000000FFFFFFFF ); + return (bits32)(FLOAT64_DEMANGLE(a) & LIT64(0x00000000FFFFFFFF)); } @@ -294,7 +294,7 @@ floating-point value `a'. INLINE bits32 extractFloat64Frac0( float64 a ) { - return ( FLOAT64_DEMANGLE(a)>>32 ) & 0x000FFFFF; + return (bits32)((FLOAT64_DEMANGLE(a) >> 32) & 0x000FFFFF); } @@ -306,7 +306,7 @@ Returns the exponent bits of the double-precision floating-point value `a'. INLINE int16 extractFloat64Exp( float64 a ) { - return ( FLOAT64_DEMANGLE(a)>>52 ) & 0x7FF; + return (int16)((FLOAT64_DEMANGLE(a) >> 52) & 0x7FF); } @@ -318,7 +318,7 @@ Returns the sign bit of the double-precision floating-point value `a'. INLINE flag extractFloat64Sign( float64 a ) { - return FLOAT64_DEMANGLE(a)>>63; + return (flag)(FLOAT64_DEMANGLE(a) >> 63); } @@ -535,7 +535,7 @@ float32 int32_to_float32( int32 a ) if ( a == 0 ) return 0; if ( a == (sbits32) 0x80000000 ) return packFloat32( 1, 0x9E, 0 ); zSign = ( a < 0 ); - return normalizeRoundAndPackFloat32( zSign, 0x9C, zSign ? - a : a ); + return normalizeRoundAndPackFloat32(zSign, 0x9C, (uint32)(zSign ? - a : a)); } diff --git a/lib/libc/softfloat/bits64/softfloat-macros b/lib/libc/softfloat/bits64/softfloat-macros index 731941b49..21a26f7f7 100644 --- a/lib/libc/softfloat/bits64/softfloat-macros +++ b/lib/libc/softfloat/bits64/softfloat-macros @@ -1,4 +1,4 @@ -/* $NetBSD: softfloat-macros,v 1.2 2009/02/16 10:23:35 tron Exp $ */ +/* $NetBSD: softfloat-macros,v 1.3 2012/03/21 02:32:26 christos Exp $ */ /* =============================================================================== @@ -464,10 +464,10 @@ INLINE void mul64To128( bits64 a, bits64 b, bits64 *z0Ptr, bits64 *z1Ptr ) bits32 aHigh, aLow, bHigh, bLow; bits64 z0, zMiddleA, zMiddleB, z1; - aLow = a; - aHigh = a>>32; - bLow = b; - bHigh = b>>32; + aLow = (bits32)a; + aHigh = (bits32)(a>>32); + bLow = (bits32)b; + bHigh = (bits32)(b>>32); z1 = ( (bits64) aLow ) * bLow; zMiddleA = ( (bits64) aLow ) * bHigh; zMiddleB = ( (bits64) aHigh ) * bLow; @@ -616,7 +616,7 @@ static bits32 estimateSqrt32( int16 aExp, bits32 a ) z = 0x8000 + ( a>>17 ) - sqrtEvenAdjustments[ idx ]; z = a / z + z; z = ( 0x20000 <= z ) ? 0xFFFF8000 : ( z<<15 ); - if ( z <= a ) return (bits32) ( ( (sbits32) a )>>1 ); + if ( z <= a ) return (bits32) ( ( (bits32) a )>>1 ); } return ( (bits32) ( ( ( (bits64) a )<<31 ) / z ) ) + ( z>>1 ); @@ -682,7 +682,7 @@ static int8 countLeadingZeros64( bits64 a ) else { a >>= 32; } - shiftCount += countLeadingZeros32( a ); + shiftCount += (int8)countLeadingZeros32( (bits32)a ); return shiftCount; } diff --git a/lib/libc/softfloat/bits64/softfloat.c b/lib/libc/softfloat/bits64/softfloat.c index b0d2bdf13..75d86d25d 100644 --- a/lib/libc/softfloat/bits64/softfloat.c +++ b/lib/libc/softfloat/bits64/softfloat.c @@ -1,4 +1,4 @@ -/* $NetBSD: softfloat.c,v 1.5 2007/11/08 21:31:04 martin Exp $ */ +/* $NetBSD: softfloat.c,v 1.11 2012/03/24 00:06:20 matt Exp $ */ /* * This version hacked for use with gcc -msoft-float by bjh21. @@ -46,7 +46,7 @@ this code that are retained. #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: softfloat.c,v 1.5 2007/11/08 21:31:04 martin Exp $"); +__RCSID("$NetBSD: softfloat.c,v 1.11 2012/03/24 00:06:20 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #ifdef SOFTFLOAT_FOR_GCC @@ -137,10 +137,10 @@ static int32 roundAndPackInt32( flag zSign, bits64 absZ ) } } } - roundBits = absZ & 0x7F; + roundBits = (int8)(absZ & 0x7F); absZ = ( absZ + roundIncrement )>>7; absZ &= ~ ( ( ( roundBits ^ 0x40 ) == 0 ) & roundNearestEven ); - z = absZ; + z = (int32)absZ; if ( zSign ) z = - z; if ( ( absZ>>32 ) || ( z && ( ( z < 0 ) ^ zSign ) ) ) { float_raise( float_flag_invalid ); @@ -340,7 +340,7 @@ static float32 roundAndPackFloat32( flag zSign, int16 zExp, bits32 zSig ) isTiny = ( float_detect_tininess == float_tininess_before_rounding ) || ( zExp < -1 ) - || ( zSig + roundIncrement < 0x80000000 ); + || ( zSig + roundIncrement < 0x80000000U ); shift32RightJamming( zSig, - zExp, &zSig ); zExp = 0; roundBits = zSig & 0x7F; @@ -395,7 +395,7 @@ Returns the exponent bits of the double-precision floating-point value `a'. INLINE int16 extractFloat64Exp( float64 a ) { - return ( FLOAT64_DEMANGLE(a)>>52 ) & 0x7FF; + return (int16)((FLOAT64_DEMANGLE(a) >> 52) & 0x7FF); } @@ -407,7 +407,7 @@ Returns the sign bit of the double-precision floating-point value `a'. INLINE flag extractFloat64Sign( float64 a ) { - return FLOAT64_DEMANGLE(a)>>63; + return (flag)(FLOAT64_DEMANGLE(a) >> 63); } @@ -497,7 +497,7 @@ static float64 roundAndPackFloat64( flag zSign, int16 zExp, bits64 zSig ) } } } - roundBits = zSig & 0x3FF; + roundBits = (int16)(zSig & 0x3FF); if ( 0x7FD <= (bits16) zExp ) { if ( ( 0x7FD < zExp ) || ( ( zExp == 0x7FD ) @@ -512,10 +512,10 @@ static float64 roundAndPackFloat64( flag zSign, int16 zExp, bits64 zSig ) isTiny = ( float_detect_tininess == float_tininess_before_rounding ) || ( zExp < -1 ) - || ( zSig + roundIncrement < LIT64( 0x8000000000000000 ) ); + || ( zSig + roundIncrement < (bits64)LIT64( 0x8000000000000000 ) ); shift64RightJamming( zSig, - zExp, &zSig ); zExp = 0; - roundBits = zSig & 0x3FF; + roundBits = (int16)(zSig & 0x3FF); if ( isTiny && roundBits ) float_raise( float_flag_underflow ); } } @@ -876,7 +876,7 @@ Returns the exponent bits of the quadruple-precision floating-point value INLINE int32 extractFloat128Exp( float128 a ) { - return ( a.high>>48 ) & 0x7FFF; + return (int32)((a.high >> 48) & 0x7FFF); } @@ -888,7 +888,7 @@ Returns the sign bit of the quadruple-precision floating-point value `a'. INLINE flag extractFloat128Sign( float128 a ) { - return a.high>>63; + return (flag)(a.high >> 63); } @@ -1124,10 +1124,19 @@ float32 int32_to_float32( int32 a ) if ( a == 0 ) return 0; if ( a == (sbits32) 0x80000000 ) return packFloat32( 1, 0x9E, 0 ); zSign = ( a < 0 ); - return normalizeRoundAndPackFloat32( zSign, 0x9C, zSign ? - a : a ); + return normalizeRoundAndPackFloat32(zSign, 0x9C, (uint32)(zSign ? - a : a)); } +float32 uint32_to_float32( uint32 a ) +{ + if ( a == 0 ) return 0; + if ( a & (bits32) 0x80000000 ) + return normalizeRoundAndPackFloat32( 0, 0x9D, a >> 1 ); + return normalizeRoundAndPackFloat32( 0, 0x9C, a ); +} + + /* ------------------------------------------------------------------------------- Returns the result of converting the 32-bit two's complement integer `a' @@ -1151,6 +1160,17 @@ float64 int32_to_float64( int32 a ) } +float64 uint32_to_float64( uint32 a ) +{ + int8 shiftCount; + bits64 zSig = a; + + if ( a == 0 ) return 0; + shiftCount = countLeadingZeros32( a ) + 21; + return packFloat64( 0, 0x432 - shiftCount, zSig<>= 1; ++zExp; } - zSig = ( ( (bits64) aSig )<<32 ) / bSig; + zSig = (bits32)((((bits64) aSig) << 32) / bSig); if ( ( zSig & 0x3F ) == 0 ) { zSig |= ( (bits64) bSig * zSig != ( (bits64) aSig )<<32 ); } @@ -2337,7 +2379,7 @@ int32 float64_to_int32_round_to_zero( float64 a ) shiftCount = 0x433 - aExp; savedASig = aSig; aSig >>= shiftCount; - z = aSig; + z = (int32)aSig; if ( aSign ) z = - z; if ( ( z < 0 ) ^ aSign ) { invalid: @@ -2472,7 +2514,7 @@ float32 float64_to_float32( float64 a ) return packFloat32( aSign, 0xFF, 0 ); } shift64RightJamming( aSig, 22, &aSig ); - zSig = aSig; + zSig = (bits32)aSig; if ( aExp || zSig ) { zSig |= 0x40000000; aExp -= 0x381; @@ -4320,7 +4362,7 @@ int32 float128_to_int32_round_to_zero( float128 a ) shiftCount = 0x402F - aExp; savedASig = aSig0; aSig0 >>= shiftCount; - z = aSig0; + z = (int32)aSig0; if ( aSign ) z = - z; if ( ( z < 0 ) ^ aSign ) { invalid: @@ -4440,6 +4482,8 @@ int64 float128_to_int64_round_to_zero( float128 a ) } +#if (defined(SOFTFLOATSPARC64_FOR_GCC) || defined(SOFTFLOAT_FOR_GCC)) \ + && defined(SOFTFLOAT_NEED_FIXUNS) /* * just like above - but do not care for overflow of signed results */ @@ -4489,6 +4533,7 @@ uint64 float128_to_uint64_round_to_zero( float128 a ) return z; } +#endif /* (SOFTFLOATSPARC64_FOR_GCC || SOFTFLOAT_FOR_GCC) && SOFTFLOAT_NEED_FIXUNS */ /* ------------------------------------------------------------------------------- @@ -4517,7 +4562,7 @@ float32 float128_to_float32( float128 a ) } aSig0 |= ( aSig1 != 0 ); shift64RightJamming( aSig0, 18, &aSig0 ); - zSig = aSig0; + zSig = (bits32)aSig0; if ( aExp || zSig ) { zSig |= 0x40000000; aExp -= 0x3F81; @@ -5073,7 +5118,7 @@ according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. */ float128 float128_rem( float128 a, float128 b ) { - flag aSign, bSign, zSign; + flag aSign, zSign; int32 aExp, bExp, expDiff; bits64 aSig0, aSig1, bSig0, bSig1, q, term0, term1, term2; bits64 allZero, alternateASig0, alternateASig1, sigMean1; @@ -5087,7 +5132,6 @@ float128 float128_rem( float128 a, float128 b ) bSig1 = extractFloat128Frac1( b ); bSig0 = extractFloat128Frac0( b ); bExp = extractFloat128Exp( b ); - bSign = extractFloat128Sign( b ); if ( aExp == 0x7FFF ) { if ( ( aSig0 | aSig1 ) || ( ( bExp == 0x7FFF ) && ( bSig0 | bSig1 ) ) ) { @@ -5211,9 +5255,9 @@ float128 float128_sqrt( float128 a ) if ( ( aSig0 | aSig1 ) == 0 ) return packFloat128( 0, 0, 0, 0 ); normalizeFloat128Subnormal( aSig0, aSig1, &aExp, &aSig0, &aSig1 ); } - zExp = ( ( aExp - 0x3FFF )>>1 ) + 0x3FFE; + zExp = ( (unsigned int)(aExp - 0x3FFF) >> 1) + 0x3FFE; aSig0 |= LIT64( 0x0001000000000000 ); - zSig0 = estimateSqrt32( aExp, aSig0>>17 ); + zSig0 = estimateSqrt32((int16)aExp, (bits32)(aSig0>>17)); shortShift128Left( aSig0, aSig1, 13 - ( aExp & 1 ), &aSig0, &aSig1 ); zSig0 = estimateDiv128To64( aSig0, aSig1, zSig0<<32 ) + ( zSig0<<30 ); doubleZSig0 = zSig0<<1; @@ -5498,7 +5542,7 @@ uint32 float64_to_uint32_round_to_zero( float64 a ) shiftCount = 0x433 - aExp; savedASig = aSig; aSig >>= shiftCount; - z = aSig; + z = (uint32)aSig; if ( ( aSig< +#include +#include /* ------------------------------------------------------------------------------- @@ -53,16 +55,35 @@ substitute a result value. If traps are not implemented, this routine should be simply `float_exception_flags |= flags;'. ------------------------------------------------------------------------------- */ +#ifdef SOFTFLOAT_FOR_GCC +#define float_exception_mask _softfloat_float_exception_mask +#endif fp_except float_exception_mask = 0; void float_raise( fp_except flags ) { + siginfo_t info; float_exception_flags |= flags; if ( flags & float_exception_mask ) { - raise( SIGFPE ); + memset(&info, 0, sizeof info); + info.si_signo = SIGFPE; + info.si_pid = getpid(); + info.si_uid = geteuid(); + if (flags & float_flag_underflow) + info.si_code = FPE_FLTUND; + else if (flags & float_flag_overflow) + info.si_code = FPE_FLTOVF; + else if (flags & float_flag_divbyzero) + info.si_code = FPE_FLTDIV; + else if (flags & float_flag_invalid) + info.si_code = FPE_FLTINV; + else if (flags & float_flag_inexact) + info.si_code = FPE_FLTRES; + sigqueueinfo(getpid(), &info); } } +#undef float_exception_mask /* ------------------------------------------------------------------------------- @@ -93,7 +114,7 @@ static flag float32_is_nan( float32 a ) { - return ( 0xFF000000 < (bits32) ( a<<1 ) ); + return ( (bits32)0xFF000000 < (bits32) ( a<<1 ) ); } @@ -142,7 +163,7 @@ precision floating-point format. static float32 commonNaNToFloat32( commonNaNT a ) { - return ( ( (bits32) a.sign )<<31 ) | 0x7FC00000 | ( a.high>>41 ); + return ( ( (bits32) a.sign )<<31 ) | 0x7FC00000 | (bits32)( a.high>>41 ); } @@ -192,7 +213,7 @@ static flag float64_is_nan( float64 a ) { - return ( LIT64( 0xFFE0000000000000 ) < + return ( (bits64)LIT64( 0xFFE0000000000000 ) < (bits64) ( FLOAT64_DEMANGLE(a)<<1 ) ); } @@ -228,7 +249,7 @@ static commonNaNT float64ToCommonNaN( float64 a ) commonNaNT z; if ( float64_is_signaling_nan( a ) ) float_raise( float_flag_invalid ); - z.sign = FLOAT64_DEMANGLE(a)>>63; + z.sign = (flag)(FLOAT64_DEMANGLE(a)>>63); z.low = 0; z.high = FLOAT64_DEMANGLE(a)<<12; return z; @@ -406,7 +427,7 @@ flag float128_is_nan( float128 a ) { return - ( LIT64( 0xFFFE000000000000 ) <= (bits64) ( a.high<<1 ) ) + ( (bits64)LIT64( 0xFFFE000000000000 ) <= (bits64) ( a.high<<1 ) ) && ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) ); } @@ -438,7 +459,7 @@ static commonNaNT float128ToCommonNaN( float128 a ) commonNaNT z; if ( float128_is_signaling_nan( a ) ) float_raise( float_flag_invalid ); - z.sign = a.high>>63; + z.sign = (flag)(a.high>>63); shortShift128Left( a.high, a.low, 16, &z.high, &z.low ); return z; diff --git a/lib/libc/ssp/__builtin_object_size.3 b/lib/libc/ssp/__builtin_object_size.3 index 9590d4f08..8645daee4 100644 --- a/lib/libc/ssp/__builtin_object_size.3 +++ b/lib/libc/ssp/__builtin_object_size.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: __builtin_object_size.3,v 1.8 2010/12/19 09:33:52 jruoho Exp $ +.\" $NetBSD: __builtin_object_size.3,v 1.10 2012/07/19 06:44:12 wiz Exp $ .\" .\" Copyright (c) 2007 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -28,7 +28,7 @@ .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" -.Dd December 19, 2010 +.Dd July 18, 2012 .Dt __BUILTIN_OBJECT_SIZE 3 .Os .Sh NAME @@ -50,8 +50,8 @@ effects. If the size of the object is not known or it has side effects the .Fn __builtin_object_size function returns: -.Bl -tag -width (size_t)-1 -offset indent -.It Dv (size_t)-1 +.Bl -tag -width (size_t)\-1 -offset indent +.It Dv (size_t)\-1 for .Fa type .Dv 0 @@ -88,3 +88,14 @@ appeared in .Tn GCC 4.1 . .Sh CAVEATS This is a non-standard, compiler-specific extension. +.Pp +Note that currently the object size calculation pass is only done at -O1 +or above, meaning that this function always returns \-1 when the optimizer +is off. +.Pp +There are some discussions about always doing the object size pass, but +the issue is that without the optimization pass data sizes are not going +to be correct. +.Pp +For that reason currently code fortification (size-checked replacement +functions) is disabled when optimization is off. diff --git a/lib/libc/ssp/memcpy_chk.c b/lib/libc/ssp/memcpy_chk.c index ac2b1ca3a..2ebc97628 100644 --- a/lib/libc/ssp/memcpy_chk.c +++ b/lib/libc/ssp/memcpy_chk.c @@ -35,12 +35,11 @@ __RCSID("$NetBSD: memcpy_chk.c,v 1.4 2008/04/28 20:23:00 martin Exp $"); #include #include -#include - -#undef memcpy #if __SSP_FORTIFY_LEVEL > 0 +#undef memcpy + void * __memcpy_chk(void * __restrict dst, const void * __restrict src, size_t len, size_t slen) diff --git a/lib/libc/ssp/memmove_chk.c b/lib/libc/ssp/memmove_chk.c index a90243d9d..c898a8151 100644 --- a/lib/libc/ssp/memmove_chk.c +++ b/lib/libc/ssp/memmove_chk.c @@ -36,10 +36,10 @@ __RCSID("$NetBSD: memmove_chk.c,v 1.4 2008/04/28 20:23:00 martin Exp $"); #include #include -#undef memmove - #if __SSP_FORTIFY_LEVEL > 0 +#undef memmove + void * __memmove_chk(void *dst, void *src, size_t len, size_t slen) diff --git a/lib/libc/ssp/memset_chk.c b/lib/libc/ssp/memset_chk.c index 37c1a53f7..7be8da1ab 100644 --- a/lib/libc/ssp/memset_chk.c +++ b/lib/libc/ssp/memset_chk.c @@ -36,10 +36,10 @@ __RCSID("$NetBSD: memset_chk.c,v 1.4 2008/04/28 20:23:00 martin Exp $"); #include #include -#undef memset - #if __SSP_FORTIFY_LEVEL > 0 +#undef memset + void * __memset_chk(void * __restrict dst, int val, size_t len, size_t slen) { diff --git a/lib/libc/ssp/ssp.3 b/lib/libc/ssp/ssp.3 index 35ca1bdbe..7347e5367 100644 --- a/lib/libc/ssp/ssp.3 +++ b/lib/libc/ssp/ssp.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: ssp.3,v 1.5 2010/12/19 08:28:40 jruoho Exp $ +.\" $NetBSD: ssp.3,v 1.6 2011/03/21 04:42:50 jruoho Exp $ .\" .\" Copyright (c) 2007 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -28,7 +28,7 @@ .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" -.Dd December 19, 2010 +.Dd March 21, 2011 .Dt SSP 3 .Os .Sh NAME @@ -113,7 +113,7 @@ it will compute the minimum buffer size. .Xr __builtin_object_size 3 , .Xr stdio 3 , .Xr string 3 , -.Xr security 8 +.Xr security 7 .Sh HISTORY The .Nm ssp diff --git a/lib/libc/ssp/strncpy_chk.c b/lib/libc/ssp/strncpy_chk.c index af876feda..ef485071a 100644 --- a/lib/libc/ssp/strncpy_chk.c +++ b/lib/libc/ssp/strncpy_chk.c @@ -36,10 +36,10 @@ __RCSID("$NetBSD: strncpy_chk.c,v 1.4 2008/04/28 20:23:00 martin Exp $"); #include #include -#undef strncpy - #if __SSP_FORTIFY_LEVEL > 0 +#undef strncpy + char * __strncpy_chk(char * __restrict dst, const char * __restrict src, size_t len, size_t slen) diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc index 231436068..65e6762a3 100644 --- a/lib/libc/stdio/Makefile.inc +++ b/lib/libc/stdio/Makefile.inc @@ -1,5 +1,5 @@ # from: @(#)Makefile.inc 5.7 (Berkeley) 6/27/91 -# $NetBSD: Makefile.inc,v 1.40 2010/12/22 16:59:10 christos Exp $ +# $NetBSD: Makefile.inc,v 1.41 2012/03/27 15:05:42 christos Exp $ # stdio sources .PATH: ${.CURDIR}/stdio @@ -45,6 +45,7 @@ MLINKS+=fread.3 fwrite.3 MLINKS+=fseek.3 fgetpos.3 fseek.3 fseeko.3 fseek.3 fsetpos.3 fseek.3 ftell.3 \ fseek.3 ftello.3 fseek.3 rewind.3 MLINKS+=funopen.3 fropen.3 funopen.3 fwopen.3 +MLINKS+=funopen.3 funopen2.3 funopen.3 fropen2.3 funopen.3 fwopen2.3 MLINKS+=getc.3 fgetc.3 getc.3 getc_unlocked.3 getc.3 getchar.3 \ getc.3 getchar_unlocked.3 getc.3 getw.3 MLINKS+=getdelim.3 getline.3 diff --git a/lib/libc/stdio/asprintf.c b/lib/libc/stdio/asprintf.c index f537637bb..6d3ec1232 100644 --- a/lib/libc/stdio/asprintf.c +++ b/lib/libc/stdio/asprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: asprintf.c,v 1.18 2009/10/25 20:44:13 christos Exp $ */ +/* $NetBSD: asprintf.c,v 1.19 2012/03/15 18:22:30 christos Exp $ */ /* * Copyright (c) 1997 Todd C. Miller @@ -29,7 +29,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: asprintf.c,v 1.18 2009/10/25 20:44:13 christos Exp $"); +__RCSID("$NetBSD: asprintf.c,v 1.19 2012/03/15 18:22:30 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -74,12 +74,12 @@ asprintf(char **str, char const *fmt, ...) if (_base == NULL) goto err; *str = (char *)_base; - return (ret); + return ret; err: if (f._bf._base) free(f._bf._base); *str = NULL; errno = ENOMEM; - return (-1); + return -1; } diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c index d5cfef071..2cec89244 100644 --- a/lib/libc/stdio/clrerr.c +++ b/lib/libc/stdio/clrerr.c @@ -1,4 +1,4 @@ -/* $NetBSD: clrerr.c,v 1.10 2003/08/07 16:43:21 agc Exp $ */ +/* $NetBSD: clrerr.c,v 1.11 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93"; #endif -__RCSID("$NetBSD: clrerr.c,v 1.10 2003/08/07 16:43:21 agc Exp $"); +__RCSID("$NetBSD: clrerr.c,v 1.11 2012/03/15 18:22:30 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -48,8 +48,7 @@ __RCSID("$NetBSD: clrerr.c,v 1.10 2003/08/07 16:43:21 agc Exp $"); #undef clearerr void -clearerr(fp) - FILE *fp; +clearerr(FILE *fp) { _DIAGASSERT(fp != NULL); diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c index c1e0d249e..49bf491be 100644 --- a/lib/libc/stdio/fclose.c +++ b/lib/libc/stdio/fclose.c @@ -1,4 +1,4 @@ -/* $NetBSD: fclose.c,v 1.17 2010/01/11 20:39:29 joerg Exp $ */ +/* $NetBSD: fclose.c,v 1.18 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93"; #endif -__RCSID("$NetBSD: fclose.c,v 1.17 2010/01/11 20:39:29 joerg Exp $"); +__RCSID("$NetBSD: fclose.c,v 1.18 2012/03/15 18:22:30 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -49,8 +49,7 @@ __RCSID("$NetBSD: fclose.c,v 1.17 2010/01/11 20:39:29 joerg Exp $"); #include "local.h" int -fclose(fp) - FILE *fp; +fclose(FILE *fp) { int r; @@ -58,7 +57,7 @@ fclose(fp) if (fp->_flags == 0) { /* not open! */ errno = EBADF; - return (EOF); + return EOF; } FLOCKFILE(fp); WCIO_FREE(fp); @@ -74,5 +73,5 @@ fclose(fp) fp->_file = -1; fp->_flags = 0; /* Release this FILE for reuse. */ fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ - return (r); + return r; } diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index d579b2016..e161ffffb 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: fdopen.c,v 1.15 2008/03/13 15:40:00 christos Exp $ */ +/* $NetBSD: fdopen.c,v 1.16 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fdopen.c,v 1.15 2008/03/13 15:40:00 christos Exp $"); +__RCSID("$NetBSD: fdopen.c,v 1.16 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -59,9 +59,7 @@ __weak_alias(fdopen,_fdopen) #endif FILE * -fdopen(fd, mode) - int fd; - const char *mode; +fdopen(int fd, const char *mode) { FILE *fp; int flags, oflags, fdflags, tmp; @@ -81,30 +79,30 @@ fdopen(fd, mode) } if ((flags = __sflags(mode, &oflags)) == 0) - return (NULL); + return NULL; /* Make sure the mode the user wants is a subset of the actual mode. */ if ((fdflags = fcntl(fd, F_GETFL, 0)) < 0) - return (NULL); + return NULL; tmp = fdflags & O_ACCMODE; if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) { errno = EINVAL; - return (NULL); + return NULL; } if (oflags & O_NONBLOCK) { struct stat st; if (fstat(fd, &st) == -1) { - return (NULL); + return NULL; } if (!S_ISREG(st.st_mode)) { errno = EFTYPE; - return (NULL); + return NULL; } } if ((fp = __sfp()) == NULL) - return (NULL); + return NULL; fp->_flags = flags; /* * If opened for appending, but underlying descriptor does not have @@ -119,5 +117,5 @@ fdopen(fd, mode) fp->_write = __swrite; fp->_seek = __sseek; fp->_close = __sclose; - return (fp); + return fp; } diff --git a/lib/libc/stdio/feof.c b/lib/libc/stdio/feof.c index 904b9b403..1d25eae90 100644 --- a/lib/libc/stdio/feof.c +++ b/lib/libc/stdio/feof.c @@ -1,4 +1,4 @@ -/* $NetBSD: feof.c,v 1.11 2003/08/07 16:43:22 agc Exp $ */ +/* $NetBSD: feof.c,v 1.12 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: feof.c,v 1.11 2003/08/07 16:43:22 agc Exp $"); +__RCSID("$NetBSD: feof.c,v 1.12 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,8 +52,7 @@ __RCSID("$NetBSD: feof.c,v 1.11 2003/08/07 16:43:22 agc Exp $"); #undef feof int -feof(fp) - FILE *fp; +feof(FILE *fp) { int r; diff --git a/lib/libc/stdio/ferror.c b/lib/libc/stdio/ferror.c index 97b58a79a..2e4beaef9 100644 --- a/lib/libc/stdio/ferror.c +++ b/lib/libc/stdio/ferror.c @@ -1,4 +1,4 @@ -/* $NetBSD: ferror.c,v 1.11 2003/08/07 16:43:22 agc Exp $ */ +/* $NetBSD: ferror.c,v 1.12 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: ferror.c,v 1.11 2003/08/07 16:43:22 agc Exp $"); +__RCSID("$NetBSD: ferror.c,v 1.12 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,8 +52,7 @@ __RCSID("$NetBSD: ferror.c,v 1.11 2003/08/07 16:43:22 agc Exp $"); #undef ferror int -ferror(fp) - FILE *fp; +ferror(FILE *fp) { int r; diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c index a78ad5e4d..c9a317ed8 100644 --- a/lib/libc/stdio/fflush.c +++ b/lib/libc/stdio/fflush.c @@ -1,4 +1,4 @@ -/* $NetBSD: fflush.c,v 1.15 2003/08/07 16:43:22 agc Exp $ */ +/* $NetBSD: fflush.c,v 1.18 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,10 +37,11 @@ #if 0 static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fflush.c,v 1.15 2003/08/07 16:43:22 agc Exp $"); +__RCSID("$NetBSD: fflush.c,v 1.18 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#include #include #include #include @@ -53,8 +54,7 @@ extern rwlock_t __sfp_lock; /* Flush a single file, or (if fp is NULL) all files. */ int -fflush(fp) - FILE *fp; +fflush(FILE *fp) { int r; @@ -77,22 +77,24 @@ fflush(fp) } int -__sflush(fp) - FILE *fp; +__sflush(FILE *fp) { unsigned char *p; - int n, t; + size_t n; + ssize_t t; _DIAGASSERT(fp != NULL); t = fp->_flags; if ((t & __SWR) == 0) - return (0); + return 0; if ((p = fp->_bf._base) == NULL) - return (0); + return 0; - n = fp->_p - p; /* write this much */ + ptrdiff_t tp = fp->_p - p; + _DIAGASSERT(__type_fit(ssize_t, tp)); + n = (ssize_t)tp; /* write this much */ /* * Set these immediately to avoid problems with longjmp and to allow @@ -105,8 +107,10 @@ __sflush(fp) t = (*fp->_write)(fp->_cookie, (char *)p, n); if (t <= 0) { fp->_flags |= __SERR; - return (EOF); + return EOF; } } - return (0); + if (fp->_flush) + return (*fp->_flush)(fp->_cookie); + return 0; } diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c index 4783cfe78..20159a25f 100644 --- a/lib/libc/stdio/fgetc.c +++ b/lib/libc/stdio/fgetc.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgetc.c,v 1.11 2003/08/07 16:43:22 agc Exp $ */ +/* $NetBSD: fgetc.c,v 1.12 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fgetc.c,v 1.11 2003/08/07 16:43:22 agc Exp $"); +__RCSID("$NetBSD: fgetc.c,v 1.12 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,8 +48,7 @@ __RCSID("$NetBSD: fgetc.c,v 1.11 2003/08/07 16:43:22 agc Exp $"); #include "local.h" int -fgetc(fp) - FILE *fp; +fgetc(FILE *fp) { int r; diff --git a/lib/libc/stdio/fgetpos.c b/lib/libc/stdio/fgetpos.c index e0c97e977..b4183a0f3 100644 --- a/lib/libc/stdio/fgetpos.c +++ b/lib/libc/stdio/fgetpos.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgetpos.c,v 1.11 2003/08/07 16:43:23 agc Exp $ */ +/* $NetBSD: fgetpos.c,v 1.12 2012/01/22 18:36:17 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fgetpos.c,v 1.11 2003/08/07 16:43:23 agc Exp $"); +__RCSID("$NetBSD: fgetpos.c,v 1.12 2012/01/22 18:36:17 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -45,14 +45,23 @@ __RCSID("$NetBSD: fgetpos.c,v 1.11 2003/08/07 16:43:23 agc Exp $"); #include #include #include +#include "reentrant.h" +#include "local.h" int -fgetpos(fp, pos) - FILE *fp; - fpos_t *pos; +fgetpos(FILE * __restrict fp, fpos_t * __restrict pos) { + struct wchar_io_data *wcio; + _DIAGASSERT(fp != NULL); _DIAGASSERT(pos != NULL); - return((*pos = (off_t)ftello(fp)) == (off_t)-1); + wcio = WCIO_GET(fp); + if (wcio != NULL && wcio->wcio_mode > 0) { + if (fp->_write) + pos->_mbstate_in = wcio->wcio_mbstate_in; + if (fp->_read) + pos->_mbstate_out = wcio->wcio_mbstate_out; + } + return (pos->_pos = ftello(fp)) == (off_t)-1; } diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c index 15a737059..de9f10242 100644 --- a/lib/libc/stdio/fgets.c +++ b/lib/libc/stdio/fgets.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgets.c,v 1.27 2009/10/25 20:44:13 christos Exp $ */ +/* $NetBSD: fgets.c,v 1.28 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93"; #else -__RCSID("$NetBSD: fgets.c,v 1.27 2009/10/25 20:44:13 christos Exp $"); +__RCSID("$NetBSD: fgets.c,v 1.28 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -57,10 +57,7 @@ __RCSID("$NetBSD: fgets.c,v 1.27 2009/10/25 20:44:13 christos Exp $"); * Return first argument, or NULL if no characters were read. */ char * -fgets(buf, n, fp) - char *buf; - int n; - FILE *fp; +fgets(char *buf, int n, FILE *fp) { int len; char *s; @@ -120,7 +117,7 @@ fgets(buf, n, fp) (void)memcpy(s, p, (size_t)len); s[len] = 0; FUNLOCKFILE(fp); - return (buf); + return buf; } fp->_r -= len; fp->_p += len; @@ -130,5 +127,5 @@ fgets(buf, n, fp) } while (n != 0); *s = 0; FUNLOCKFILE(fp); - return (buf); + return buf; } diff --git a/lib/libc/stdio/fgetwc.c b/lib/libc/stdio/fgetwc.c index f875e34c9..e330db9fe 100644 --- a/lib/libc/stdio/fgetwc.c +++ b/lib/libc/stdio/fgetwc.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgetwc.c,v 1.11 2009/10/25 20:44:13 christos Exp $ */ +/* $NetBSD: fgetwc.c,v 1.13 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c)2001 Citrus Project, @@ -30,7 +30,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: fgetwc.c,v 1.11 2009/10/25 20:44:13 christos Exp $"); +__RCSID("$NetBSD: fgetwc.c,v 1.13 2012/03/15 18:22:30 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -80,7 +80,8 @@ restart: nr = 1; } fp->_p += nr; - fp->_r -= nr; + _DIAGASSERT(__type_fit(int, fp->_r - nr)); + fp->_r -= (int)nr; return wc; } @@ -96,6 +97,6 @@ fgetwc(FILE *fp) r = __fgetwc_unlock(fp); FUNLOCKFILE(fp); - return (r); + return r; } diff --git a/lib/libc/stdio/fgetwln.c b/lib/libc/stdio/fgetwln.c index 71ae0f182..81d4f9459 100644 --- a/lib/libc/stdio/fgetwln.c +++ b/lib/libc/stdio/fgetwln.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgetwln.c,v 1.4 2010/01/11 20:39:29 joerg Exp $ */ +/* $NetBSD: fgetwln.c,v 1.5 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 2002-2004 Tim J. Robbins. @@ -31,7 +31,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdio/fgetwln.c,v 1.2 2004/08/06 17:00:09 tjr Exp $"); #else -__RCSID("$NetBSD: fgetwln.c,v 1.4 2010/01/11 20:39:29 joerg Exp $"); +__RCSID("$NetBSD: fgetwln.c,v 1.5 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -67,12 +67,12 @@ __slbexpand(FILE *fp, size_t newsize) _DIAGASSERT(fp != NULL); if (_EXT(fp)->_fgetstr_len >= newsize) - return (0); + return 0; if ((p = realloc(_EXT(fp)->_fgetstr_buf, newsize)) == NULL) - return (-1); + return -1; _EXT(fp)->_fgetstr_buf = p; _EXT(fp)->_fgetstr_len = newsize; - return (0); + return 0; } wchar_t * @@ -99,10 +99,10 @@ fgetwln(FILE * __restrict fp, size_t *lenp) FUNLOCKFILE(fp); *lenp = len; - return ((wchar_t *)(void *)_EXT(fp)->_fgetstr_buf); + return (wchar_t *)(void *)_EXT(fp)->_fgetstr_buf; error: FUNLOCKFILE(fp); *lenp = 0; - return (NULL); + return NULL; } diff --git a/lib/libc/stdio/fgetws.c b/lib/libc/stdio/fgetws.c index c78ee5a79..60012b786 100644 --- a/lib/libc/stdio/fgetws.c +++ b/lib/libc/stdio/fgetws.c @@ -1,4 +1,4 @@ -/* $NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $ */ +/* $NetBSD: fgetws.c,v 1.3 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins. @@ -32,7 +32,7 @@ #include #if defined(LIB_SCCS) && !defined(lint) -__RCSID("$NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $"); +__RCSID("$NetBSD: fgetws.c,v 1.3 2012/03/15 18:22:30 christos Exp $"); #endif #include @@ -43,10 +43,7 @@ __RCSID("$NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $"); #include "local.h" wchar_t * -fgetws(ws, n, fp) - wchar_t * __restrict ws; - int n; - FILE * __restrict fp; +fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp) { wchar_t *wsp; wint_t wc; @@ -83,9 +80,9 @@ fgetws(ws, n, fp) *wsp++ = L'\0'; FUNLOCKFILE(fp); - return (ws); + return ws; error: FUNLOCKFILE(fp); - return (NULL); + return NULL; } diff --git a/lib/libc/stdio/fileno.c b/lib/libc/stdio/fileno.c index 6550a28c8..0b6e7ba3f 100644 --- a/lib/libc/stdio/fileno.c +++ b/lib/libc/stdio/fileno.c @@ -1,4 +1,4 @@ -/* $NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp $ */ +/* $NetBSD: fileno.c,v 1.13 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp $"); +__RCSID("$NetBSD: fileno.c,v 1.13 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,13 +52,12 @@ __RCSID("$NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp $"); * A subroutine version of the macro fileno. */ #undef fileno -int _fileno __P((FILE *)); /* XXX */ +int _fileno(FILE *); /* XXX */ __weak_alias(fileno,_fileno) int -_fileno(fp) - FILE *fp; +_fileno(FILE *fp) { int r; diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c index 4b311189a..356279750 100644 --- a/lib/libc/stdio/findfp.c +++ b/lib/libc/stdio/findfp.c @@ -1,4 +1,4 @@ -/* $NetBSD: findfp.c,v 1.25 2010/09/06 14:52:55 christos Exp $ */ +/* $NetBSD: findfp.c,v 1.28 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)findfp.c 8.2 (Berkeley) 1/4/94"; #else -__RCSID("$NetBSD: findfp.c,v 1.25 2010/09/06 14:52:55 christos Exp $"); +__RCSID("$NetBSD: findfp.c,v 1.28 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -56,18 +56,66 @@ int __sdidinit; #define NDYNAMIC 10 /* add ten more whenever necessary */ -#define std(flags, file) \ -/* p r w flags file bf lfbsize cookie close */ \ - { NULL, 0, 0, flags, file, { NULL, 0 }, 0, __sF + file, __sclose, \ -/* read seek write ext up */ \ - __sread, __sseek, __swrite, { (void *)(__sFext + file), 0 }, NULL, \ -/* ur ubuf, nbuf lb blksize offset */ \ - 0, { '\0', '\0', '\0' }, { '\0' }, { NULL, 0 }, 0, (fpos_t)0 } +#if !defined(_LIBMINC) && !defined(__kernel__) +#define std(flags, file) { \ + ._p = NULL, \ + ._r = 0, \ + ._w = 0, \ + ._flags = (flags), \ + ._file = (file), \ + ._bf = { ._base = NULL, ._size = 0 }, \ + ._lbfsize = 0, \ + ._cookie = __sF + (file), \ + ._close = __sclose, \ + ._read = __sread, \ + ._seek = __sseek, \ + ._write = __swrite, \ + ._ext = { ._base = (void *)(__sFext + (file)), ._size = 0 }, \ + ._up = NULL, \ + ._ur = 0, \ + ._ubuf = { [0] = '\0', [1] = '\0', [2] = '\0' }, \ + ._nbuf = { [0] = '\0' }, \ + ._flush = NULL, \ + ._lb_unused = { '\0' }, \ + ._blksize = 0, \ + ._offset = (off_t)0, \ +} + +#else + +#define std(flags, file) { \ + ._p = NULL, \ + ._r = 0, \ + ._w = 0, \ + ._flags = (flags), \ + ._file = (file), \ + ._bf = { ._base = NULL, ._size = 0 }, \ + ._lbfsize = 0, \ + ._cookie = __sF + (file), \ + ._close = NULL, \ + ._read = NULL, \ + ._seek = NULL, \ + ._write = NULL, \ + ._ext = { ._base = (void *)(__sFext + (file)), ._size = 0 }, \ + ._up = NULL, \ + ._ur = 0, \ + ._ubuf = { [0] = '\0', [1] = '\0', [2] = '\0' }, \ + ._nbuf = { [0] = '\0' }, \ + ._flush = NULL, \ + ._lb_unused = { '\0' }, \ + ._blksize = 0, \ + ._offset = (off_t)0, \ +} + +#endif /* !defined(_LIBMINC) && !defined(__kernel__) */ + +#if !defined(__kernel__) /* the usual - (stdin + stdout + stderr) */ static FILE usual[FOPEN_MAX - 3]; static struct __sfileext usualext[FOPEN_MAX - 3]; static struct glue uglue = { 0, FOPEN_MAX - 3, usual }; +#endif /* !defined(__kernel__) */ #if defined(_REENTRANT) && !defined(__lint__) /* XXX lint is busted */ #define STDEXT { ._lock = MUTEX_INITIALIZER, ._lockcond = COND_INITIALIZER } @@ -83,28 +131,28 @@ FILE __sF[3] = { std(__SWR, STDOUT_FILENO), /* stdout */ std(__SWR|__SNBF, STDERR_FILENO) /* stderr */ }; + +#if !defined(__kernel__) struct glue __sglue = { &uglue, 3, __sF }; -static struct glue *moreglue __P((int)); -void f_prealloc __P((void)); +void f_prealloc(void); #ifdef _REENTRANT rwlock_t __sfp_lock = RWLOCK_INITIALIZER; #endif static struct glue * -moreglue(n) - int n; +moreglue(int n) { struct glue *g; FILE *p; struct __sfileext *pext; static FILE empty; - g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE) - + n * sizeof(struct __sfileext)); + g = malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE) + + n * sizeof(struct __sfileext)); if (g == NULL) - return (NULL); + return NULL; p = (FILE *)ALIGN((u_long)(g + 1)); g->next = NULL; g->niobs = n; @@ -116,7 +164,7 @@ moreglue(n) p++; pext++; } - return (g); + return g; } void @@ -131,6 +179,7 @@ __sfpinit(FILE *fp) fp->_lbfsize = 0; /* not line buffered */ fp->_file = -1; /* no file */ /* fp->_cookie = ; */ /* caller sets cookie, _read/_write etc */ + fp->_flush = NULL; /* default flush */ _UB(fp)._base = NULL; /* no ungetc buffer */ _UB(fp)._size = 0; memset(WCIO_GET(fp), 0, sizeof(struct wchar_io_data)); @@ -140,7 +189,7 @@ __sfpinit(FILE *fp) * Find a free FILE for fopen et al. */ FILE * -__sfp() +__sfp(void) { FILE *fp; int n; @@ -158,11 +207,11 @@ __sfp() break; } rwlock_unlock(&__sfp_lock); - return (NULL); + return NULL; found: __sfpinit(fp); rwlock_unlock(&__sfp_lock); - return (fp); + return fp; } /* @@ -170,16 +219,18 @@ found: * but documented historically for certain applications. Bad applications. */ void -f_prealloc() +f_prealloc(void) { +#if !defined(_LIBMINC) struct glue *g; int n; n = (int)sysconf(_SC_OPEN_MAX) - FOPEN_MAX + 20; /* 20 for slop. */ for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next) - /* void */; + continue; if (n > 0) g->next = moreglue(n); +#endif /* !defined(_LIBMINC) */ } /* @@ -190,17 +241,19 @@ f_prealloc() * The name `_cleanup' is, alas, fairly well known outside stdio. */ void -_cleanup() +_cleanup(void) { +#if !defined(_LIBMINC) /* (void) _fwalk(fclose); */ (void) fflush(NULL); /* `cheating' */ +#endif /* !defined(_LIBMINC) */ } /* * __sinit() is called whenever stdio's internal variables must be set up. */ void -__sinit() +__sinit(void) { int i; @@ -211,3 +264,4 @@ __sinit() __cleanup = _cleanup; /* conservative */ __sdidinit = 1; } +#endif /* !defined(__kernel__) */ diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c index d9772672e..a0a2d5a4a 100644 --- a/lib/libc/stdio/flags.c +++ b/lib/libc/stdio/flags.c @@ -1,4 +1,4 @@ -/* $NetBSD: flags.c,v 1.14 2003/08/07 16:43:23 agc Exp $ */ +/* $NetBSD: flags.c,v 1.16 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)flags.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: flags.c,v 1.14 2003/08/07 16:43:23 agc Exp $"); +__RCSID("$NetBSD: flags.c,v 1.16 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,15 +49,17 @@ __RCSID("$NetBSD: flags.c,v 1.14 2003/08/07 16:43:23 agc Exp $"); #include "reentrant.h" #include "local.h" +#if defined(__minix) && !defined(O_CLOEXEC) +#define O_CLOEXEC 0 +#endif + /* * Return the (stdio) flags for a given mode. Store the flags * to be passed to an open() syscall through *optr. * Return 0 on error. */ int -__sflags(mode, optr) - const char *mode; - int *optr; +__sflags(const char *mode, int *optr) { int ret, m, o; @@ -85,12 +87,13 @@ __sflags(mode, optr) default: /* illegal mode */ errno = EINVAL; - return (0); + return 0; } /* * [rwa]\+ or [rwa]b\+ means read and write - * f means open only plain files. + * f means open only plain files, + * e means set close on exec. */ for (; *mode; mode++) switch (*mode) { @@ -101,6 +104,9 @@ __sflags(mode, optr) case 'f': o |= O_NONBLOCK; break; + case 'e': + o |= O_CLOEXEC; + break; case 'b': break; default: /* We could produce a warning here */ @@ -108,5 +114,5 @@ __sflags(mode, optr) } *optr = m | o; - return (ret); + return ret; } diff --git a/lib/libc/stdio/flockfile.3 b/lib/libc/stdio/flockfile.3 index d14099fe0..1a3ef6295 100644 --- a/lib/libc/stdio/flockfile.3 +++ b/lib/libc/stdio/flockfile.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: flockfile.3,v 1.4 2008/04/30 13:10:51 martin Exp $ +.\" $NetBSD: flockfile.3,v 1.6 2011/10/15 21:43:19 wiz Exp $ .\" .\" Copyright (c) 2003 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd January 28, 2003 +.Dd October 15, 2011 .Dt FLOCKFILE 3 .Os .Sh NAME @@ -103,8 +103,10 @@ If successful, the function returns 0. Otherwise, it returns non-zero to indicate that the lock cannot be acquired. .Sh SEE ALSO +.Xr flock 2 , .Xr getc_unlocked 3 , .Xr getchar_unlocked 3 , +.Xr lockf 3 , .Xr putc_unlocked 3 , .Xr putchar_unlocked 3 .Sh STANDARDS @@ -115,6 +117,11 @@ and .Fn funlockfile functions conform to .St -p1003.1-2001 . +.Sh HISTORY +The +.Fn flockfile +function first appeared in +.Fx 2.0 . .Sh BUGS The design of these interfaces does not allow for addressing the problem of priority inversion. diff --git a/lib/libc/stdio/flockfile.c b/lib/libc/stdio/flockfile.c index f06d8069a..5a14731c9 100644 --- a/lib/libc/stdio/flockfile.c +++ b/lib/libc/stdio/flockfile.c @@ -1,4 +1,4 @@ -/* $NetBSD: flockfile.c,v 1.10 2010/12/08 02:07:03 joerg Exp $ */ +/* $NetBSD: flockfile.c,v 1.11 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: flockfile.c,v 1.10 2010/12/08 02:07:03 joerg Exp $"); +__RCSID("$NetBSD: flockfile.c,v 1.11 2012/03/15 18:22:30 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -168,7 +168,7 @@ ftrylockfile(FILE *fp) /* LINTED deliberate lack of effect */ (void)fp; - return (0); + return 0; } void diff --git a/lib/libc/stdio/fmemopen.3 b/lib/libc/stdio/fmemopen.3 index e028315f3..7973ba5fe 100644 --- a/lib/libc/stdio/fmemopen.3 +++ b/lib/libc/stdio/fmemopen.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: fmemopen.3,v 1.5 2010/10/07 00:14:14 enami Exp $ +.\" $NetBSD: fmemopen.3,v 1.7 2012/10/08 18:15:09 njoly Exp $ .\" .\" Copyright (c) 2010 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -14,11 +14,7 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the NetBSD -.\" Foundation, Inc. and its contributors. -.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" 3. Neither the name of The NetBSD Foundation nor the names of its .\" contributors may be used to endorse or promote products derived .\" from this software without specific prior written permission. .\" @@ -34,7 +30,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd September 24, 2010 +.Dd October 15, 2011 .Dt FMEMOPEN 3 .Os .Sh NAME @@ -45,7 +41,7 @@ .Sh SYNOPSIS .In stdio.h .Ft FILE * -.Fn fmemopen "void *restrict buffer" "size_t size" "const char *restrict mode" +.Fn fmemopen "void *restrict buffer" "size_t size" "const char *restrict mode" .Sh DESCRIPTION The .Fn fmemopen @@ -186,6 +182,11 @@ specified for the routine .Xr fflush 3 , .Xr fopen 3 , .Xr malloc 3 +.Sh STANDARDS +The +.Fn fmemopen +function conforms to +.St -p1003.1-2008 . .Sh HISTORY The .Fn fmemopen diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c index 33840e367..474c798ad 100644 --- a/lib/libc/stdio/fmemopen.c +++ b/lib/libc/stdio/fmemopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: fmemopen.c,v 1.5 2010/09/27 17:08:29 tnozaki Exp $ */ +/* $NetBSD: fmemopen.c,v 1.8 2012/03/29 14:27:33 christos Exp $ */ /*- * Copyright (c)2007, 2010 Takehiko NOZAKI, @@ -29,7 +29,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: fmemopen.c,v 1.5 2010/09/27 17:08:29 tnozaki Exp $"); +__RCSID("$NetBSD: fmemopen.c,v 1.8 2012/03/29 14:27:33 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -46,11 +46,11 @@ struct fmemopen_cookie { char *head, *tail, *cur, *eob; }; -static int -fmemopen_read(void *cookie, char *buf, int nbytes) +static ssize_t +fmemopen_read(void *cookie, void *buf, size_t nbytes) { struct fmemopen_cookie *p; - char *s; + char *s, *b = buf; _DIAGASSERT(cookie != NULL); _DIAGASSERT(buf != NULL && nbytes > 0); @@ -60,17 +60,18 @@ fmemopen_read(void *cookie, char *buf, int nbytes) do { if (p->cur == p->tail) break; - *buf++ = *p->cur++; + *b++ = *p->cur++; } while (--nbytes > 0); - return (int)(p->cur - s); + return (ssize_t)(p->cur - s); } -static int -fmemopen_write(void *cookie, const char *buf, int nbytes) +static ssize_t +fmemopen_write(void *cookie, const void *buf, size_t nbytes) { struct fmemopen_cookie *p; char *s; + const char *b = buf; _DIAGASSERT(cookie != NULL); _DIAGASSERT(buf != NULL && nbytes > 0); @@ -81,24 +82,40 @@ fmemopen_write(void *cookie, const char *buf, int nbytes) s = p->cur; do { if (p->cur == p->tail - 1) { - if (*buf == '\0') { + if (*b == '\0') { *p->cur++ = '\0'; goto ok; } break; } - *p->cur++ = *buf++; + *p->cur++ = *b++; } while (--nbytes > 0); *p->cur = '\0'; ok: if (p->cur > p->eob) p->eob = p->cur; - return (int)(p->cur - s); + return (ssize_t)(p->cur - s); +} + +#ifdef notyet +static int +fmemopen_flush(void *cookie) +{ + struct fmemopen_cookie *p; + + _DIAGASSERT(cookie != NULL); + + p = (struct fmemopen_cookie *)cookie; + if (p->cur >= p->tail) + return -1; + *p->cur = '\0'; + return 0; } +#endif -static fpos_t -fmemopen_seek(void *cookie, fpos_t offset, int whence) +static off_t +fmemopen_seek(void *cookie, off_t offset, int whence) { struct fmemopen_cookie *p; @@ -118,12 +135,12 @@ fmemopen_seek(void *cookie, fpos_t offset, int whence) errno = EINVAL; goto error; } - if (offset >= (fpos_t)0 && offset <= p->tail - p->head) { + if (offset >= (off_t)0 && offset <= p->tail - p->head) { p->cur = p->head + (ptrdiff_t)offset; - return (fpos_t)(p->cur - p->head); + return (off_t)(p->cur - p->head); } error: - return (fpos_t)-1; + return (off_t)-1; } static int @@ -184,12 +201,12 @@ fmemopen(void * __restrict buf, size_t size, const char * __restrict mode) goto release; } *cookie->head = '\0'; - fp->_close = &fmemopen_close1; + fp->_close = fmemopen_close1; } else { cookie->head = (char *)buf; if (oflags & O_TRUNC) *cookie->head = '\0'; - fp->_close = &fmemopen_close0; + fp->_close = fmemopen_close0; } cookie->tail = cookie->head + size; @@ -203,9 +220,12 @@ fmemopen(void * __restrict buf, size_t size, const char * __restrict mode) cookie->cur = (oflags & O_APPEND) ? cookie->eob : cookie->head; fp->_flags = flags; - fp->_write = (flags & __SRD) ? NULL : &fmemopen_write; - fp->_read = (flags & __SWR) ? NULL : &fmemopen_read; - fp->_seek = &fmemopen_seek; + fp->_write = (flags & __SRD) ? NULL : fmemopen_write; + fp->_read = (flags & __SWR) ? NULL : fmemopen_read; + fp->_seek = fmemopen_seek; +#ifdef notyet + fp->_flush = fmemopen_flush; +#endif fp->_cookie = (void *)cookie; return fp; diff --git a/lib/libc/stdio/fopen.3 b/lib/libc/stdio/fopen.3 index ad897b6ab..ec6db6435 100644 --- a/lib/libc/stdio/fopen.3 +++ b/lib/libc/stdio/fopen.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: fopen.3,v 1.24 2010/04/05 21:34:47 joerg Exp $ +.\" $NetBSD: fopen.3,v 1.28 2012/07/02 20:02:43 wiz Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)fopen.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 4, 1993 +.Dd July 18, 2011 .Dt FOPEN 3 .Os .Sh NAME @@ -63,7 +63,13 @@ The argument .Fa mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): -.Bl -tag -width indent +.Bl -tag -width 4n +.It Dq Li a +Append; open for writing. +The file is created if it does not exist. +.It Dq Li a+ +Append; open for reading and writing. +The file is created if it does not exist. .It Dq Li r Open for reading. .It Dq Li r+ @@ -74,30 +80,44 @@ Truncate file to zero length or create file. .It Dq Li w+ Open for reading and writing. Truncate file to zero length or create file. -.It Dq Li a -Append; open for writing. -The file is created if it does not exist. -.It Dq Li a+ -Append; open for reading and writing. -The file is created if it does not exist. .El .Pp -The +Additionally, the .Fa mode -string can also include the letter ``b'' either as a last character or -as a character between the characters in any of the two-character strings -described above. +string can also include one of the following letters: +.Bl -tag -width 4n +.It Sq b +The letter +.Sq b +may appear either as a last character or as a character between the +characters in any of the two-character strings described above. This is strictly for compatibility with .St -ansiC -and has no effect; the ``b'' is ignored. -.Pp -The letter ``f'' in the mode string restricts fopen to regular -files; if the file opened is not a regular file, +and has no effect; the +.Sq b +is ignored. +.It Sq e +The letter +.Sq e +in the mode string sets the close-on-exec flag in the file descriptors of +the newly opened file files; if the operation fails, +.Fn fopen +will fail. +This is a non +.St -ansiC +extension. +.It Sq f +The letter +.Sq f +in the mode string restricts +.Fn fopen +to regular files; if the file opened is not a regular file, .Fn fopen will fail. This is a non .St -ansiC extension. +.El .Pp Any created files will have mode .Pf \*q Dv S_IRUSR @@ -113,8 +133,8 @@ Any created files will have mode .Dv S_IWOTH Ns \*q .Pq Li 0666 , as modified by the process' -umask value (see -.Xr umask 2 ) . +.Xr umask 2 +value. .Pp Opening a file with append mode causes all subsequent writes to it to be forced to the then current end of file, regardless of intervening @@ -185,19 +205,15 @@ is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS +The functions may fail if: .Bl -tag -width Er -.It Bq Er EINVAL -The -.Fa mode -provided to -.Fn fopen , -.Fn fdopen , -or -.Fn freopen -was invalid. .It Bq Er EFTYPE The file is not a regular file and the character ``f'' is specified in the mode. +.It Bq Er EINVAL +The specified +.Fa mode +was invalid. .El .Pp The @@ -248,13 +264,10 @@ The .Fn fopen and .Fn freopen -functions -conform to +functions conform to .St -ansiC . -The -.Fn fdopen -function conforms to -.St -p1003.1-90 . +All three functions are specified in +.St -p1003.1-2008 . .Sh CAVEATS Proper code using .Fn fdopen diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index c75e1c03e..c1792ebd8 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: fopen.c,v 1.13 2008/03/13 15:40:00 christos Exp $ */ +/* $NetBSD: fopen.c,v 1.15 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fopen.c,v 1.13 2008/03/13 15:40:00 christos Exp $"); +__RCSID("$NetBSD: fopen.c,v 1.15 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,9 +53,7 @@ __RCSID("$NetBSD: fopen.c,v 1.13 2008/03/13 15:40:00 christos Exp $"); #include "local.h" FILE * -fopen(file, mode) - const char *file; - const char *mode; +fopen(const char *file, const char *mode) { FILE *fp; int f; @@ -63,9 +61,9 @@ fopen(file, mode) _DIAGASSERT(file != NULL); if ((flags = __sflags(mode, &oflags)) == 0) - return (NULL); + return NULL; if ((fp = __sfp()) == NULL) - return (NULL); + return NULL; if ((f = open(file, oflags, DEFFILEMODE)) < 0) goto release; if (oflags & O_NONBLOCK) { @@ -111,9 +109,9 @@ fopen(file, mode) * fseek and ftell.) */ if (oflags & O_APPEND) - (void) __sseek((void *)fp, (fpos_t)0, SEEK_END); - return (fp); + (void) __sseek((void *)fp, (off_t)0, SEEK_END); + return fp; release: fp->_flags = 0; /* release */ - return (NULL); + return NULL; } diff --git a/lib/libc/stdio/fprintf.c b/lib/libc/stdio/fprintf.c index 54e4f3338..48021f034 100644 --- a/lib/libc/stdio/fprintf.c +++ b/lib/libc/stdio/fprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: fprintf.c,v 1.11 2003/08/07 16:43:24 agc Exp $ */ +/* $NetBSD: fprintf.c,v 1.12 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fprintf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fprintf.c,v 1.11 2003/08/07 16:43:24 agc Exp $"); +__RCSID("$NetBSD: fprintf.c,v 1.12 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -58,5 +58,5 @@ fprintf(FILE *fp, const char *fmt, ...) va_start(ap, fmt); ret = vfprintf(fp, fmt, ap); va_end(ap); - return (ret); + return ret; } diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c index 3e0706db8..87abc3823 100644 --- a/lib/libc/stdio/fpurge.c +++ b/lib/libc/stdio/fpurge.c @@ -1,4 +1,4 @@ -/* $NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp $ */ +/* $NetBSD: fpurge.c,v 1.14 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp $"); +__RCSID("$NetBSD: fpurge.c,v 1.14 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,15 +54,14 @@ __RCSID("$NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp $"); * given FILE's buffer empty. */ int -fpurge(fp) - FILE *fp; +fpurge(FILE *fp) { _DIAGASSERT(fp != NULL); if (fp->_flags == 0) { errno = EBADF; - return (EOF); + return EOF; } FLOCKFILE(fp); if (HASUB(fp)) @@ -72,5 +71,5 @@ fpurge(fp) fp->_r = 0; fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; FUNLOCKFILE(fp); - return (0); + return 0; } diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c index 1bc81e3f4..e077a5ccd 100644 --- a/lib/libc/stdio/fputc.c +++ b/lib/libc/stdio/fputc.c @@ -1,4 +1,4 @@ -/* $NetBSD: fputc.c,v 1.12 2003/08/07 16:43:24 agc Exp $ */ +/* $NetBSD: fputc.c,v 1.13 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fputc.c,v 1.12 2003/08/07 16:43:24 agc Exp $"); +__RCSID("$NetBSD: fputc.c,v 1.13 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,9 +48,7 @@ __RCSID("$NetBSD: fputc.c,v 1.12 2003/08/07 16:43:24 agc Exp $"); #include "local.h" int -fputc(c, fp) - int c; - FILE *fp; +fputc(int c, FILE *fp) { int r; diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c index 546359596..d8852caf4 100644 --- a/lib/libc/stdio/fputs.c +++ b/lib/libc/stdio/fputs.c @@ -1,4 +1,4 @@ -/* $NetBSD: fputs.c,v 1.14 2005/06/22 19:45:22 christos Exp $ */ +/* $NetBSD: fputs.c,v 1.15 2012/03/13 21:13:46 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fputs.c,v 1.14 2005/06/22 19:45:22 christos Exp $"); +__RCSID("$NetBSD: fputs.c,v 1.15 2012/03/13 21:13:46 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,9 +53,7 @@ __RCSID("$NetBSD: fputs.c,v 1.14 2005/06/22 19:45:22 christos Exp $"); * Write the given string to the given file. */ int -fputs(s, fp) - const char *s; - FILE *fp; +fputs(const char *s, FILE *fp) { struct __suio uio; struct __siov iov; @@ -68,7 +66,7 @@ fputs(s, fp) s = "(null)"; iov.iov_base = __UNCONST(s); - iov.iov_len = uio.uio_resid = strlen(s); + uio.uio_resid = iov.iov_len = strlen(s); uio.uio_iov = &iov; uio.uio_iovcnt = 1; FLOCKFILE(fp); diff --git a/lib/libc/stdio/fputwc.c b/lib/libc/stdio/fputwc.c index 3c9b35a26..02eb8309c 100644 --- a/lib/libc/stdio/fputwc.c +++ b/lib/libc/stdio/fputwc.c @@ -1,4 +1,4 @@ -/* $NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $ */ +/* $NetBSD: fputwc.c,v 1.5 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c)2001 Citrus Project, @@ -30,7 +30,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $"); +__RCSID("$NetBSD: fputwc.c,v 1.5 2012/03/15 18:22:30 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -96,5 +96,5 @@ fputwc(wchar_t wc, FILE *fp) r = __fputwc_unlock(wc, fp); FUNLOCKFILE(fp); - return (r); + return r; } diff --git a/lib/libc/stdio/fputws.c b/lib/libc/stdio/fputws.c index f1599b964..9f6664b02 100644 --- a/lib/libc/stdio/fputws.c +++ b/lib/libc/stdio/fputws.c @@ -1,4 +1,4 @@ -/* $NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $ */ +/* $NetBSD: fputws.c,v 1.2 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $"); +__RCSID("$NetBSD: fputws.c,v 1.2 2012/03/15 18:22:30 christos Exp $"); #endif #include @@ -42,9 +42,7 @@ __RCSID("$NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $"); #include "local.h" int -fputws(ws, fp) - const wchar_t * __restrict ws; - FILE * __restrict fp; +fputws(const wchar_t * __restrict ws, FILE * __restrict fp) { _DIAGASSERT(fp != NULL); _DIAGASSERT(ws != NULL); @@ -55,11 +53,11 @@ fputws(ws, fp) while (*ws != '\0') { if (__fputwc_unlock(*ws++, fp) == WEOF) { FUNLOCKFILE(fp); - return (-1); + return -1; } } FUNLOCKFILE(fp); - return (0); + return 0; } diff --git a/lib/libc/stdio/fread.3 b/lib/libc/stdio/fread.3 index dc9a91d44..ba68cf71a 100644 --- a/lib/libc/stdio/fread.3 +++ b/lib/libc/stdio/fread.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: fread.3,v 1.14 2009/01/11 02:46:29 christos Exp $ +.\" $NetBSD: fread.3,v 1.15 2011/09/11 04:55:48 jruoho Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)fread.3 8.2 (Berkeley) 3/8/94 .\" -.Dd December 19, 2008 +.Dd September 11, 2011 .Dt FREAD 3 .Os .Sh NAME @@ -76,7 +76,7 @@ Mixing and .Fn fwrite calls without setting the file position explicitly using -.Fn fsetpos +.Xr fsetpos 3 between read and write or write and read operations will lead to unexpected results because of buffering the file pointer not being set to the expected position after each operation completes. diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c index d61fa816b..ef3b5ef11 100644 --- a/lib/libc/stdio/fread.c +++ b/lib/libc/stdio/fread.c @@ -1,4 +1,4 @@ -/* $NetBSD: fread.c,v 1.20 2009/10/25 20:44:13 christos Exp $ */ +/* $NetBSD: fread.c,v 1.22 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; #else -__RCSID("$NetBSD: fread.c,v 1.20 2009/10/25 20:44:13 christos Exp $"); +__RCSID("$NetBSD: fread.c,v 1.22 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,10 +49,7 @@ __RCSID("$NetBSD: fread.c,v 1.20 2009/10/25 20:44:13 christos Exp $"); #include "local.h" size_t -fread(buf, size, count, fp) - void *buf; - size_t size, count; - FILE *fp; +fread(void *buf, size_t size, size_t count, FILE *fp) { size_t resid; char *p; @@ -66,7 +63,7 @@ fread(buf, size, count, fp) * fwrite, the SUSv2 does. */ if ((resid = count * size) == 0) - return (0); + return 0; _DIAGASSERT(buf != NULL); @@ -84,12 +81,14 @@ fread(buf, size, count, fp) if (__srefill(fp)) { /* no more input: return partial result */ FUNLOCKFILE(fp); - return ((total - resid) / size); + return (total - resid) / size; } } (void)memcpy(p, fp->_p, resid); - fp->_r -= resid; + + _DIAGASSERT(__type_fit(int, fp->_r - resid)); + fp->_r -= (int)resid; fp->_p += resid; FUNLOCKFILE(fp); - return (count); + return count; } diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c index 5b370faee..f83f51aad 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: freopen.c,v 1.16 2010/01/11 20:39:29 joerg Exp $ */ +/* $NetBSD: freopen.c,v 1.19 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)freopen.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: freopen.c,v 1.16 2010/01/11 20:39:29 joerg Exp $"); +__RCSID("$NetBSD: freopen.c,v 1.19 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -61,9 +61,7 @@ __RCSID("$NetBSD: freopen.c,v 1.16 2010/01/11 20:39:29 joerg Exp $"); * all possible, no matter what. */ FILE * -freopen(file, mode, fp) - const char *file, *mode; - FILE *fp; +freopen(const char *file, const char *mode, FILE *fp) { int f; int flags, isopen, oflags, sverrno, wantfd; @@ -74,7 +72,7 @@ freopen(file, mode, fp) if ((flags = __sflags(mode, &oflags)) == 0) { (void) fclose(fp); - return (NULL); + return NULL; } if (!__sdidinit) @@ -95,7 +93,7 @@ freopen(file, mode, fp) } else { /* flush the stream; ANSI doesn't require this. */ if (fp->_flags & __SWR) - (void) __sflush(fp); + (void)__sflush(fp); /* if close is NULL, closing is a no-op, hence pointless */ isopen = fp->_close != NULL; if ((wantfd = __sfileno(fp)) == -1 && isopen) { @@ -140,7 +138,7 @@ freopen(file, mode, fp) if (f < 0) { /* did not get it after all */ fp->_flags = 0; /* set it free */ errno = sverrno; /* restore in case _close clobbered */ - return (NULL); + return NULL; } if (oflags & O_NONBLOCK) { @@ -149,12 +147,12 @@ freopen(file, mode, fp) sverrno = errno; (void)close(f); errno = sverrno; - return (NULL); + return NULL; } if (!S_ISREG(st.st_mode)) { (void)close(f); errno = EFTYPE; - return (NULL); + return NULL; } } @@ -200,6 +198,6 @@ freopen(file, mode, fp) * fseek and ftell.) */ if (oflags & O_APPEND) - (void) __sseek((void *)fp, (fpos_t)0, SEEK_END); - return (fp); + (void) __sseek((void *)fp, (off_t)0, SEEK_END); + return fp; } diff --git a/lib/libc/stdio/fscanf.c b/lib/libc/stdio/fscanf.c index 817e9a143..ca46c939f 100644 --- a/lib/libc/stdio/fscanf.c +++ b/lib/libc/stdio/fscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: fscanf.c,v 1.12 2003/08/07 16:43:25 agc Exp $ */ +/* $NetBSD: fscanf.c,v 1.13 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fscanf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fscanf.c,v 1.12 2003/08/07 16:43:25 agc Exp $"); +__RCSID("$NetBSD: fscanf.c,v 1.13 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -58,5 +58,5 @@ fscanf(FILE *fp, char const *fmt, ...) va_start(ap, fmt); ret = __svfscanf(fp, fmt, ap); va_end(ap); - return (ret); + return ret; } diff --git a/lib/libc/stdio/fseek.3 b/lib/libc/stdio/fseek.3 index 9b776db07..2569a17c0 100644 --- a/lib/libc/stdio/fseek.3 +++ b/lib/libc/stdio/fseek.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: fseek.3,v 1.25 2010/10/22 21:29:31 christos Exp $ +.\" $NetBSD: fseek.3,v 1.27 2012/01/22 19:13:42 wiz Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)fseek.3 8.1 (Berkeley) 6/4/93 .\" -.Dd October 22, 2010 +.Dd January 21, 2012 .Dt FSEEK 3 .Os .Sh NAME @@ -127,26 +127,18 @@ except that the error indicator for the stream is also cleared (see .Xr clearerr 3 ) . .Pp -In this implementation, the -.Fn fgetpos -and -.Fn fsetpos -functions -are alternative interfaces equivalent to -.Fn ftell , -.Fn ftello , -.Fn fseek , -and -.Fn fseeko -(with whence set to -.Dv SEEK_SET ) , -setting and storing the current value of -the file offset into or from the object referenced by -.Fa pos . -In others implementations, an +In this implementations, an .Dq Fa fpos_t -object may be a complex object -and these routines may be the only way to portably reposition a text stream. +object is a complex object that represents both the position and the parse +state of the stream making these routines are the only way to portably +reposition a text stream. +The +.Ar pos +argument of +.Fn fsetpos +must always be initialized by +a call to +.Fn fgetpos . .Sh RETURN VALUES The .Fn rewind diff --git a/lib/libc/stdio/fseeko.c b/lib/libc/stdio/fseeko.c index d1ed157e9..1973a23b9 100644 --- a/lib/libc/stdio/fseeko.c +++ b/lib/libc/stdio/fseeko.c @@ -1,4 +1,4 @@ -/* $NetBSD: fseeko.c,v 1.8 2009/01/31 00:08:05 lukem Exp $ */ +/* $NetBSD: fseeko.c,v 1.12 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: fseeko.c,v 1.8 2009/01/31 00:08:05 lukem Exp $"); +__RCSID("$NetBSD: fseeko.c,v 1.12 2012/03/27 15:05:42 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -53,7 +53,7 @@ __RCSID("$NetBSD: fseeko.c,v 1.8 2009/01/31 00:08:05 lukem Exp $"); __weak_alias(fseeko, _fseeko) #endif -#define POS_ERR (-(fpos_t)1) +#define POS_ERR ((off_t)-1) /* * Seek the given file to the given offset. @@ -62,8 +62,8 @@ __weak_alias(fseeko, _fseeko) int fseeko(FILE *fp, off_t offset, int whence) { - fpos_t (*seekfn)(void *, fpos_t, int); - fpos_t target, curoff; + off_t (*seekfn)(void *, off_t, int); + off_t target, curoff; size_t n; struct stat st; int havepos; @@ -82,7 +82,7 @@ fseeko(FILE *fp, off_t offset, int whence) if ((seekfn = fp->_seek) == NULL) { errno = ESPIPE; /* historic practice */ FUNLOCKFILE(fp); - return (-1); + return -1; } /* @@ -97,14 +97,14 @@ fseeko(FILE *fp, off_t offset, int whence) * we have to first find the current stream offset a la * ftell (see ftell for details). */ - __sflush(fp); /* may adjust seek offset on append stream */ + (void)__sflush(fp); /* may adjust seek offset on append stream */ if (fp->_flags & __SOFF) curoff = fp->_offset; else { - curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); + curoff = (*seekfn)(fp->_cookie, (off_t)0, SEEK_CUR); if (curoff == POS_ERR) { FUNLOCKFILE(fp); - return (-1); + return -1; } } if (fp->_flags & __SRD) { @@ -128,7 +128,7 @@ fseeko(FILE *fp, off_t offset, int whence) default: errno = EINVAL; FUNLOCKFILE(fp); - return (-1); + return -1; } /* @@ -179,7 +179,7 @@ fseeko(FILE *fp, off_t offset, int whence) if (fp->_flags & __SOFF) curoff = fp->_offset; else { - curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); + curoff = (*seekfn)(fp->_cookie, (off_t)0, SEEK_CUR); if (curoff == POS_ERR) goto dumb; } @@ -212,16 +212,17 @@ fseeko(FILE *fp, off_t offset, int whence) * skip this; see fgetln.c.) */ if ((fp->_flags & __SMOD) == 0 && - target >= curoff && target < (fpos_t)(curoff + n)) { + target >= curoff && target < curoff + (off_t)n) { int o = (int)(target - curoff); fp->_p = fp->_bf._base + o; - fp->_r = n - o; + _DIAGASSERT(__type_fit(int, n - o)); + fp->_r = (int)(n - o); if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; FUNLOCKFILE(fp); - return (0); + return 0; } /* @@ -245,10 +246,11 @@ fseeko(FILE *fp, off_t offset, int whence) if (__srefill(fp) || (size_t)fp->_r < n) goto dumb; fp->_p += n; - fp->_r -= n; + _DIAGASSERT(__type_fit(int, fp->_r - n)); + fp->_r -= (int)n; } FUNLOCKFILE(fp); - return (0); + return 0; /* * We get here if we cannot optimise the seek ... just @@ -256,9 +258,9 @@ fseeko(FILE *fp, off_t offset, int whence) */ dumb: if (__sflush(fp) || - (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { + (*seekfn)(fp->_cookie, offset, whence) == POS_ERR) { FUNLOCKFILE(fp); - return (-1); + return -1; } /* success: clear EOF indicator and discard ungetc() data */ if (HASUB(fp)) @@ -268,5 +270,5 @@ dumb: /* fp->_w = 0; */ /* unnecessary (I think...) */ fp->_flags &= ~__SEOF; FUNLOCKFILE(fp); - return (0); + return 0; } diff --git a/lib/libc/stdio/fsetpos.c b/lib/libc/stdio/fsetpos.c index 6fbd3e24b..f0c1cf438 100644 --- a/lib/libc/stdio/fsetpos.c +++ b/lib/libc/stdio/fsetpos.c @@ -1,4 +1,4 @@ -/* $NetBSD: fsetpos.c,v 1.10 2003/08/07 16:43:25 agc Exp $ */ +/* $NetBSD: fsetpos.c,v 1.11 2012/01/22 18:36:17 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fsetpos.c,v 1.10 2003/08/07 16:43:25 agc Exp $"); +__RCSID("$NetBSD: fsetpos.c,v 1.11 2012/01/22 18:36:17 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -45,17 +45,26 @@ __RCSID("$NetBSD: fsetpos.c,v 1.10 2003/08/07 16:43:25 agc Exp $"); #include #include #include +#include "reentrant.h" +#include "local.h" /* * fsetpos: like fseek. */ int -fsetpos(iop, pos) - FILE *iop; - const fpos_t *pos; +fsetpos(FILE * __restrict fp, const fpos_t * __restrict pos) { - _DIAGASSERT(iop != NULL); + struct wchar_io_data *wcio; + + _DIAGASSERT(fp != NULL); _DIAGASSERT(pos != NULL); - return (fseeko(iop, (off_t)*pos, SEEK_SET)); + wcio = WCIO_GET(fp); + if (wcio != NULL && wcio->wcio_mode > 0) { + if (fp->_write) + wcio->wcio_mbstate_in = pos->_mbstate_in; + if (fp->_read) + wcio->wcio_mbstate_out = pos->_mbstate_out; + } + return fseeko(fp, pos->_pos, SEEK_SET) == (off_t)-1; } diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 828a23a3b..3e545f938 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -1,4 +1,4 @@ -/* $NetBSD: ftell.c,v 1.17 2010/10/24 17:44:32 tron Exp $ */ +/* $NetBSD: ftell.c,v 1.20 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: ftell.c,v 1.17 2010/10/24 17:44:32 tron Exp $"); +__RCSID("$NetBSD: ftell.c,v 1.20 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,10 +51,9 @@ __RCSID("$NetBSD: ftell.c,v 1.17 2010/10/24 17:44:32 tron Exp $"); * ftell: return current offset. */ long -ftell(fp) - FILE *fp; +ftell(FILE *fp) { - fpos_t pos; + off_t pos; FLOCKFILE(fp); @@ -69,14 +68,14 @@ ftell(fp) * Find offset of underlying I/O object, then * adjust for buffered bytes. */ - __sflush(fp); /* may adjust seek offset on append stream */ + (void)__sflush(fp); /* may adjust seek offset on append stream */ if (fp->_flags & __SOFF) pos = fp->_offset; else { - pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); + pos = (*fp->_seek)(fp->_cookie, (off_t)0, SEEK_CUR); if (pos == -1L) { FUNLOCKFILE(fp); - return (long)(pos); + return (long)pos; } } if (fp->_flags & __SRD) { @@ -98,10 +97,10 @@ ftell(fp) } FUNLOCKFILE(fp); - if (__fpos_overflow(pos)) { + if (__long_overflow(pos)) { errno = EOVERFLOW; return -1L; } - return (long)(pos); + return (long)pos; } diff --git a/lib/libc/stdio/ftello.c b/lib/libc/stdio/ftello.c index 6c1bd1ac0..07578098f 100644 --- a/lib/libc/stdio/ftello.c +++ b/lib/libc/stdio/ftello.c @@ -1,4 +1,4 @@ -/* $NetBSD: ftello.c,v 1.4 2003/08/07 16:43:26 agc Exp $ */ +/* $NetBSD: ftello.c,v 1.7 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: ftello.c,v 1.4 2003/08/07 16:43:26 agc Exp $"); +__RCSID("$NetBSD: ftello.c,v 1.7 2012/03/27 15:05:42 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -52,10 +52,9 @@ __weak_alias(ftello, _ftello) * ftell: return current offset. */ off_t -ftello(fp) - FILE *fp; +ftello(FILE *fp) { - fpos_t pos; + off_t pos; FLOCKFILE(fp); @@ -63,21 +62,21 @@ ftello(fp) if (fp->_seek == NULL) { FUNLOCKFILE(fp); errno = ESPIPE; /* historic practice */ - return ((off_t)-1); + return (off_t)-1; } /* * Find offset of underlying I/O object, then * adjust for buffered bytes. */ - __sflush(fp); /* may adjust seek offset on append stream */ + (void)__sflush(fp); /* may adjust seek offset on append stream */ if (fp->_flags & __SOFF) pos = fp->_offset; else { - pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (pos == (fpos_t)-1) { + pos = (*fp->_seek)(fp->_cookie, (off_t)0, SEEK_CUR); + if (pos == (off_t)-1) { FUNLOCKFILE(fp); - return (pos); + return pos; } } if (fp->_flags & __SRD) { @@ -98,5 +97,5 @@ ftello(fp) pos += fp->_p - fp->_bf._base; } FUNLOCKFILE(fp); - return (pos); + return pos; } diff --git a/lib/libc/stdio/funopen.3 b/lib/libc/stdio/funopen.3 index 376a56196..852f02be2 100644 --- a/lib/libc/stdio/funopen.3 +++ b/lib/libc/stdio/funopen.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: funopen.3,v 1.15 2010/03/22 19:30:54 joerg Exp $ +.\" $NetBSD: funopen.3,v 1.22 2012/10/08 18:15:09 njoly Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -31,24 +31,32 @@ .\" .\" @(#)funopen.3 8.1 (Berkeley) 6/9/93 .\" -.Dd June 9, 1993 +.Dd March 16, 2012 .Dt FUNOPEN 3 .Os .Sh NAME .Nm funopen , +.Nm funopen2 , .Nm fropen , -.Nm fwopen +.Nm fropen2 , +.Nm fwopen , +.Nm fwopen2 .Nd open a stream .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In stdio.h .Ft FILE * -.Fn funopen "void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "fpos_t (*seekfn)(void *, fpos_t, int)" "int (*closefn)(void *)" +.Fn funopen "void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "off_t (*seekfn)(void *, off_t, int)" "int (*closefn)(void *)" +.Fn funopen2 "void *cookie" "ssize_t (*readfn)(void *, void *, size_t)" "ssize_t (*writefn)(void *, const void *, size_t)" "off_t (*seekfn)(void *, off_t, int)" "int (*flushfn)(void *)" "int (*closefn)(void *)" .Ft FILE * -.Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)" +.Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)" .Ft FILE * -.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)" +.Fn fropen2 "void *cookie" "ssize_t (*readfn)(void *, void *, size_t)" +.Ft FILE * +.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)" +.Ft FILE * +.Fn fwopen2 "void *cookie" "ssize_t (*writefn)(void *, const void *, size_t)" .Sh DESCRIPTION The .Fn funopen @@ -68,6 +76,14 @@ These functions will be used to read, write, seek and close the new stream. .Pp +The +.Fn funopen2 +function provides sightly different read and write signatures, which match +better the corresponding system calls, plus the ability to augment the +streams default flushing function. +If a flushing function is provided, then it is called after all data has +been written to the stream. +.Pp In general, omitting a function means that any attempt to perform the associated operation on the resulting stream will fail. If the close function is omitted, closing the stream will flush @@ -89,13 +105,7 @@ except that they are passed the .Fa cookie argument specified to .Fn funopen -in place of the traditional file descriptor argument, -and -.Fa seekfn -uses -.Li fpos_t -instead of -.Li off_t . +in place of the traditional file descriptor argument. .Pp Read and write .Tn I/O @@ -167,9 +177,11 @@ The .Fn funopen functions first appeared in .Bx 4.4 . -.Sh BUGS The -.Fn funopen -function -may not be portable to systems other than -.Bx . +.Fn funopen2 +functions first appeared in +.Nx 7.0 . +.Sh CAVEATS +All three functions are specific to +.Nx +and thus unportable. diff --git a/lib/libc/stdio/funopen.c b/lib/libc/stdio/funopen.c index c308d9099..268d18e40 100644 --- a/lib/libc/stdio/funopen.c +++ b/lib/libc/stdio/funopen.c @@ -1,4 +1,4 @@ -/* $NetBSD: funopen.c,v 1.10 2005/11/29 03:12:00 christos Exp $ */ +/* $NetBSD: funopen.c,v 1.14 2012/03/28 15:21:11 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,22 +37,24 @@ #if 0 static char sccsid[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: funopen.c,v 1.10 2005/11/29 03:12:00 christos Exp $"); +__RCSID("$NetBSD: funopen.c,v 1.14 2012/03/28 15:21:11 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include #include +#include +#include #include "reentrant.h" #include "local.h" FILE * -funopen(cookie, readfn, writefn, seekfn, closefn) - const void *cookie; - int (*readfn) __P((void *, char *, int)); - int (*writefn) __P((void *, const char *, int)); - fpos_t (*seekfn) __P((void *, fpos_t, int)); - int (*closefn) __P((void *)); +funopen2(const void *cookie, + ssize_t (*readfn)(void *, void *, size_t), + ssize_t (*writefn)(void *, const void *, size_t), + off_t (*seekfn)(void *, off_t, int), + int (*flushfn)(void *), + int (*closefn)(void *)) { FILE *fp; int flags; @@ -60,7 +62,7 @@ funopen(cookie, readfn, writefn, seekfn, closefn) if (readfn == NULL) { if (writefn == NULL) { /* illegal */ errno = EINVAL; - return (NULL); + return NULL; } else flags = __SWR; /* write only */ } else { @@ -70,13 +72,101 @@ funopen(cookie, readfn, writefn, seekfn, closefn) flags = __SRW; /* read-write */ } if ((fp = __sfp()) == NULL) - return (NULL); + return NULL; fp->_flags = flags; fp->_file = -1; fp->_cookie = __UNCONST(cookie); fp->_read = readfn; fp->_write = writefn; fp->_seek = seekfn; + fp->_flush = flushfn; fp->_close = closefn; - return (fp); + return fp; } + +typedef struct { + void *cookie; + int (*readfn)(void *, char *, int); + int (*writefn)(void *, const char *, int); + off_t (*seekfn)(void *, off_t, int); + int (*closefn)(void *); +} dookie_t; + +static ssize_t +creadfn(void *dookie, void *buf, size_t len) +{ + dookie_t *d = dookie; + if (len > INT_MAX) + len = INT_MAX; + return (*d->readfn)(d->cookie, buf, (int)len); +} + +static ssize_t +cwritefn(void *dookie, const void *buf, size_t len) +{ + dookie_t *d = dookie; + ssize_t nr; + size_t l = len; + const char *b = buf; + + while (l) { + size_t nw = l > INT_MAX ? INT_MAX : l; + nr = (*d->writefn)(d->cookie, buf, (int)nw); + if (nr == -1) { + if (len == l) + return -1; + else + return len - l; + } + b += nr; + l -= nr; + } + return len; +} + +static off_t +cseekfn(void *dookie, off_t off, int whence) +{ + dookie_t *d = dookie; + return (*d->seekfn)(d->cookie, off, whence); +} + +static int +cclosefn(void *dookie) +{ + dookie_t *d = dookie; + void *c = d->cookie; + int (*cf)(void *) = d->closefn; + free(dookie); + return (*cf)(c); +} + +FILE * +funopen(const void *cookie, + int (*readfn)(void *, char *, int), + int (*writefn)(void *, const char *, int), + off_t (*seekfn)(void *, off_t, int), + int (*closefn)(void *)) +{ + dookie_t *d; + FILE *fp; + + if ((d = malloc(sizeof(*d))) == NULL) + return NULL; + + d->cookie = __UNCONST(cookie); + d->readfn = readfn; + d->writefn = writefn; + d->seekfn = seekfn; + d->closefn = closefn; + fp = funopen2(d, + d->readfn ? creadfn : NULL, + d->writefn ? cwritefn : NULL, + d->seekfn ? cseekfn : NULL, + NULL, + d->closefn ? cclosefn : NULL); + if (fp != NULL) + return fp; + free(d); + return NULL; + } diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c index 557b3b38d..a2619ac3d 100644 --- a/lib/libc/stdio/fvwrite.c +++ b/lib/libc/stdio/fvwrite.c @@ -1,4 +1,4 @@ -/* $NetBSD: fvwrite.c,v 1.21 2009/10/25 20:44:13 christos Exp $ */ +/* $NetBSD: fvwrite.c,v 1.25 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,11 +37,12 @@ #if 0 static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fvwrite.c,v 1.21 2009/10/25 20:44:13 christos Exp $"); +__RCSID("$NetBSD: fvwrite.c,v 1.25 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include +#include #include #include #include @@ -57,30 +58,29 @@ __RCSID("$NetBSD: fvwrite.c,v 1.21 2009/10/25 20:44:13 christos Exp $"); * to the three different kinds of output buffering is handled here. */ int -__sfvwrite(fp, uio) - FILE *fp; - struct __suio *uio; +__sfvwrite(FILE *fp, struct __suio *uio) { - int len; + size_t len; char *p; struct __siov *iov; - int w, s; + int s; + ssize_t w; char *nl; - int nlknown, nldist; + size_t nlknown, nldist; _DIAGASSERT(fp != NULL); _DIAGASSERT(uio != NULL); - if ((int)uio->uio_resid < 0) { + if ((ssize_t)uio->uio_resid < 0) { errno = EINVAL; - return (EOF); + return EOF; } - if ((len = uio->uio_resid) == 0) - return (0); + if (uio->uio_resid == 0) + return 0; /* make sure we can write */ if (cantwrite(fp)) { errno = EBADF; - return (EOF); + return EOF; } #define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -103,8 +103,7 @@ __sfvwrite(fp, uio) */ do { GETIOV(;); - w = (*fp->_write)(fp->_cookie, p, - (int)MIN(len, BUFSIZ)); + w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ)); if (w <= 0) goto err; p += w; @@ -125,8 +124,8 @@ __sfvwrite(fp, uio) do { GETIOV(;); if ((fp->_flags & (__SALC | __SSTR)) == - (__SALC | __SSTR) && fp->_w < len) { - int blen = fp->_p - fp->_bf._base; + (__SALC | __SSTR) && (size_t)fp->_w < len) { + ptrdiff_t blen = fp->_p - fp->_bf._base; unsigned char *_base; int _size; @@ -134,7 +133,7 @@ __sfvwrite(fp, uio) _size = fp->_bf._size; do { _size = (_size << 1) + 1; - } while (_size < blen + len); + } while ((size_t)_size < blen + len); _base = realloc(fp->_bf._base, (size_t)(_size + 1)); if (_base == NULL) @@ -146,29 +145,29 @@ __sfvwrite(fp, uio) } w = fp->_w; if (fp->_flags & __SSTR) { - if (len < w) + if (len < (size_t)w) w = len; COPY(w); /* copy MIN(fp->_w,len), */ - fp->_w -= w; + fp->_w -= (int)w; fp->_p += w; w = len; /* but pretend copied all */ - } else if (fp->_p > fp->_bf._base && len > w) { + } else if (fp->_p > fp->_bf._base && len > (size_t)w) { /* fill and flush */ COPY(w); /* fp->_w -= w; */ /* unneeded */ fp->_p += w; if (fflush(fp)) goto err; - } else if (len >= (w = fp->_bf._size)) { + } else if (len >= (size_t)(w = fp->_bf._size)) { /* write directly */ - w = (*fp->_write)(fp->_cookie, p, w); + w = (*fp->_write)(fp->_cookie, p, (size_t)w); if (w <= 0) goto err; } else { /* fill and done */ w = len; COPY(w); - fp->_w -= w; + fp->_w -= (int)w; fp->_p += w; } p += w; @@ -187,11 +186,11 @@ __sfvwrite(fp, uio) do { GETIOV(nlknown = 0); if (!nlknown) { - nl = memchr(p, '\n', (size_t)len); - nldist = nl ? nl + 1 - p : len + 1; + nl = memchr(p, '\n', len); + nldist = nl ? (size_t)(nl + 1 - p) : len + 1; nlknown = 1; } - s = MIN(len, nldist); + s = (int)MIN(len, nldist); w = fp->_w + fp->_bf._size; if (fp->_p > fp->_bf._base && s > w) { COPY(w); @@ -200,13 +199,13 @@ __sfvwrite(fp, uio) if (fflush(fp)) goto err; } else if (s >= (w = fp->_bf._size)) { - w = (*fp->_write)(fp->_cookie, p, w); + w = (*fp->_write)(fp->_cookie, p, (size_t)w); if (w <= 0) goto err; } else { w = s; COPY(w); - fp->_w -= w; + fp->_w -= (int)w; fp->_p += w; } if ((nldist -= w) == 0) { @@ -219,9 +218,9 @@ __sfvwrite(fp, uio) len -= w; } while ((uio->uio_resid -= w) != 0); } - return (0); + return 0; err: fp->_flags |= __SERR; - return (EOF); + return EOF; } diff --git a/lib/libc/stdio/fvwrite.h b/lib/libc/stdio/fvwrite.h index 844d9ab52..c3209b11a 100644 --- a/lib/libc/stdio/fvwrite.h +++ b/lib/libc/stdio/fvwrite.h @@ -1,4 +1,4 @@ -/* $NetBSD: fvwrite.h,v 1.7 2003/08/07 16:43:26 agc Exp $ */ +/* $NetBSD: fvwrite.h,v 1.8 2012/03/13 21:13:46 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -43,8 +43,8 @@ struct __siov { }; struct __suio { struct __siov *uio_iov; - int uio_iovcnt; - int uio_resid; + size_t uio_iovcnt; + size_t uio_resid; }; extern int __sfvwrite(FILE *, struct __suio *); diff --git a/lib/libc/stdio/fwalk.c b/lib/libc/stdio/fwalk.c index b06edd1d3..d81de36be 100644 --- a/lib/libc/stdio/fwalk.c +++ b/lib/libc/stdio/fwalk.c @@ -1,4 +1,4 @@ -/* $NetBSD: fwalk.c,v 1.11 2003/08/07 16:43:26 agc Exp $ */ +/* $NetBSD: fwalk.c,v 1.12 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fwalk.c,v 1.11 2003/08/07 16:43:26 agc Exp $"); +__RCSID("$NetBSD: fwalk.c,v 1.12 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,8 +49,7 @@ __RCSID("$NetBSD: fwalk.c,v 1.11 2003/08/07 16:43:26 agc Exp $"); #include "glue.h" int -_fwalk(function) - int (*function) __P((FILE *)); +_fwalk(int (*function)(FILE *)) { FILE *fp; int n, ret; @@ -63,5 +62,5 @@ _fwalk(function) for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) if (fp->_flags != 0) ret |= (*function)(fp); - return (ret); + return ret; } diff --git a/lib/libc/stdio/fwprintf.c b/lib/libc/stdio/fwprintf.c index 5360687d9..9efc80c09 100644 --- a/lib/libc/stdio/fwprintf.c +++ b/lib/libc/stdio/fwprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: fwprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */ +/* $NetBSD: fwprintf.c,v 1.2 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins @@ -31,7 +31,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdio/fwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $"); #else -__RCSID("$NetBSD: fwprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $"); +__RCSID("$NetBSD: fwprintf.c,v 1.2 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,5 +49,5 @@ fwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...) ret = vfwprintf(fp, fmt, ap); va_end(ap); - return (ret); + return ret; } diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c index c48a47c6d..0004eb990 100644 --- a/lib/libc/stdio/fwrite.c +++ b/lib/libc/stdio/fwrite.c @@ -1,4 +1,4 @@ -/* $NetBSD: fwrite.c,v 1.16 2005/11/29 03:12:00 christos Exp $ */ +/* $NetBSD: fwrite.c,v 1.17 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fwrite.c,v 1.16 2005/11/29 03:12:00 christos Exp $"); +__RCSID("$NetBSD: fwrite.c,v 1.17 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,10 +53,7 @@ __RCSID("$NetBSD: fwrite.c,v 1.16 2005/11/29 03:12:00 christos Exp $"); * Return the number of whole objects written. */ size_t -fwrite(buf, size, count, fp) - const void *buf; - size_t size, count; - FILE *fp; +fwrite(const void *buf, size_t size, size_t count, FILE *fp) { size_t n; struct __suio uio; @@ -67,7 +64,7 @@ fwrite(buf, size, count, fp) * SUSv2 requires a return value of 0 for a count or a size of 0. */ if ((n = count * size) == 0) - return (0); + return 0; _DIAGASSERT(buf != NULL); iov.iov_base = __UNCONST(buf); @@ -84,5 +81,5 @@ fwrite(buf, size, count, fp) if (__sfvwrite(fp, &uio) != 0) count = ((n - uio.uio_resid) / size); FUNLOCKFILE(fp); - return (count); + return count; } diff --git a/lib/libc/stdio/fwscanf.c b/lib/libc/stdio/fwscanf.c index 4595c330a..84ea204ae 100644 --- a/lib/libc/stdio/fwscanf.c +++ b/lib/libc/stdio/fwscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: fwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */ +/* $NetBSD: fwscanf.c,v 1.2 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins @@ -31,7 +31,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdio/fwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $"); #else -__RCSID("$NetBSD: fwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $"); +__RCSID("$NetBSD: fwscanf.c,v 1.2 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,5 +49,5 @@ fwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, ...) r = vfwscanf(fp, fmt, ap); va_end(ap); - return (r); + return r; } diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c index 55bef64c9..7a487f332 100644 --- a/lib/libc/stdio/getc.c +++ b/lib/libc/stdio/getc.c @@ -1,4 +1,4 @@ -/* $NetBSD: getc.c,v 1.11 2003/08/07 16:43:26 agc Exp $ */ +/* $NetBSD: getc.c,v 1.12 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getc.c,v 1.11 2003/08/07 16:43:26 agc Exp $"); +__RCSID("$NetBSD: getc.c,v 1.12 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,8 +54,7 @@ __RCSID("$NetBSD: getc.c,v 1.11 2003/08/07 16:43:26 agc Exp $"); #undef getc_unlocked int -getc(fp) - FILE *fp; +getc(FILE *fp) { int r; @@ -68,11 +67,10 @@ getc(fp) } int -getc_unlocked(fp) - FILE *fp; +getc_unlocked(FILE *fp) { _DIAGASSERT(fp != NULL); - return (__sgetc(fp)); + return __sgetc(fp); } diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c index 75cae92cd..bd692d141 100644 --- a/lib/libc/stdio/getchar.c +++ b/lib/libc/stdio/getchar.c @@ -1,4 +1,4 @@ -/* $NetBSD: getchar.c,v 1.9 2003/08/07 16:43:27 agc Exp $ */ +/* $NetBSD: getchar.c,v 1.10 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getchar.c,v 1.9 2003/08/07 16:43:27 agc Exp $"); +__RCSID("$NetBSD: getchar.c,v 1.10 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,7 +52,7 @@ __RCSID("$NetBSD: getchar.c,v 1.9 2003/08/07 16:43:27 agc Exp $"); #undef getchar_unlocked int -getchar() +getchar(void) { FILE *fp = stdin; int r; @@ -64,7 +64,7 @@ getchar() } int -getchar_unlocked() +getchar_unlocked(void) { - return (__sgetc(stdin)); + return __sgetc(stdin); } diff --git a/lib/libc/stdio/getdelim.3 b/lib/libc/stdio/getdelim.3 index 121c96dff..1c13a5275 100644 --- a/lib/libc/stdio/getdelim.3 +++ b/lib/libc/stdio/getdelim.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getdelim.3,v 1.8 2010/06/30 13:38:10 jruoho Exp $ +.\" $NetBSD: getdelim.3,v 1.9 2011/04/20 23:37:51 enami Exp $ .\" .\" Copyright (c) 2009 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -108,6 +108,7 @@ standard output. char *line = NULL; size_t linesize = 0; ssize_t linelen; + while ((linelen = getline(\*[Am]line, \*[Am]linesize, fp)) != -1) fwrite(line, linelen, 1, stdout); @@ -117,9 +118,9 @@ if (ferror(fp)) .Sh ERRORS .Bl -tag -width [EOVERFLOW] .It Bq Er EINVAL -.Fa *lineptr +.Fa lineptr or -.Fa *n +.Fa n is a .Dv NULL pointer. diff --git a/lib/libc/stdio/getdelim.c b/lib/libc/stdio/getdelim.c index c3ab8773e..acce3764b 100644 --- a/lib/libc/stdio/getdelim.c +++ b/lib/libc/stdio/getdelim.c @@ -1,4 +1,4 @@ -/* $NetBSD: getdelim.c,v 1.12 2009/12/07 21:31:43 roy Exp $ */ +/* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ */ #include -__RCSID("$NetBSD: getdelim.c,v 1.12 2009/12/07 21:31:43 roy Exp $"); +__RCSID("$NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $"); #include "namespace.h" @@ -65,7 +65,7 @@ __getdelim(char **__restrict buf, size_t *__restrict buflen, if (buf == NULL || buflen == NULL) { errno = EINVAL; - return -1; + goto error; } /* If buf is NULL, we have to assume a size of zero */ diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c index 8526d8a69..e61e1bdc7 100644 --- a/lib/libc/stdio/gets.c +++ b/lib/libc/stdio/gets.c @@ -1,4 +1,4 @@ -/* $NetBSD: gets.c,v 1.16 2007/06/03 17:39:26 christos Exp $ */ +/* $NetBSD: gets.c,v 1.17 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)gets.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: gets.c,v 1.16 2007/06/03 17:39:26 christos Exp $"); +__RCSID("$NetBSD: gets.c,v 1.17 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,8 +53,7 @@ __RCSID("$NetBSD: gets.c,v 1.16 2007/06/03 17:39:26 christos Exp $"); __warn_references(gets, "warning: this program uses gets(), which is unsafe.") char * -gets(buf) - char *buf; +gets(char *buf) { int c; char *s; @@ -66,7 +65,7 @@ gets(buf) if (c == EOF) { if (s == buf) { FUNLOCKFILE(stdin); - return (NULL); + return NULL; } else { break; } @@ -76,5 +75,5 @@ gets(buf) } *s = 0; FUNLOCKFILE(stdin); - return (buf); + return buf; } diff --git a/lib/libc/stdio/gettemp.c b/lib/libc/stdio/gettemp.c index b5b8e93b7..fa27249a0 100644 --- a/lib/libc/stdio/gettemp.c +++ b/lib/libc/stdio/gettemp.c @@ -1,4 +1,4 @@ -/* $NetBSD: gettemp.c,v 1.14 2008/10/20 10:28:38 apb Exp $ */ +/* $NetBSD: gettemp.c,v 1.15 2012/03/15 18:22:30 christos Exp $ */ /* * Copyright (c) 1987, 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: gettemp.c,v 1.14 2008/10/20 10:28:38 apb Exp $"); +__RCSID("$NetBSD: gettemp.c,v 1.15 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -64,10 +64,7 @@ __RCSID("$NetBSD: gettemp.c,v 1.14 2008/10/20 10:28:38 apb Exp $"); #endif int -GETTEMP(path, doopen, domkdir) - char *path; - int *doopen; - int domkdir; +GETTEMP(char *path, int *doopen, int domkdir) { char *start, *trv; struct stat sbuf; @@ -124,10 +121,10 @@ GETTEMP(path, doopen, domkdir) if (*trv == '/') { *trv = '\0'; if (stat(path, &sbuf)) - return (0); + return 0; if (!S_ISDIR(sbuf.st_mode)) { errno = ENOTDIR; - return (0); + return 0; } *trv = '/'; break; @@ -138,21 +135,21 @@ GETTEMP(path, doopen, domkdir) if (doopen) { if ((*doopen = open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0) - return (1); + return 1; if (errno != EEXIST) - return (0); + return 0; } else if (domkdir) { if (mkdir(path, 0700) >= 0) - return (1); + return 1; if (errno != EEXIST) - return (0); + return 0; } else if (lstat(path, &sbuf)) - return (errno == ENOENT ? 1 : 0); + return errno == ENOENT ? 1 : 0; /* tricky little algorithm for backward compatibility */ for (trv = start;;) { if (!*trv) - return (0); + return 0; if (*trv == 'z') *trv++ = 'a'; else { diff --git a/lib/libc/stdio/getw.c b/lib/libc/stdio/getw.c index 6ccd8cebc..29ef059de 100644 --- a/lib/libc/stdio/getw.c +++ b/lib/libc/stdio/getw.c @@ -1,4 +1,4 @@ -/* $NetBSD: getw.c,v 1.9 2003/08/07 16:43:27 agc Exp $ */ +/* $NetBSD: getw.c,v 1.10 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)getw.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getw.c,v 1.9 2003/08/07 16:43:27 agc Exp $"); +__RCSID("$NetBSD: getw.c,v 1.10 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -46,12 +46,11 @@ __RCSID("$NetBSD: getw.c,v 1.9 2003/08/07 16:43:27 agc Exp $"); #include int -getw(fp) - FILE *fp; +getw(FILE *fp) { int x; _DIAGASSERT(fp != NULL); - return (fread((void *)&x, sizeof(x), 1, fp) == 1 ? x : EOF); + return fread((void *)&x, sizeof(x), 1, fp) == 1 ? x : EOF; } diff --git a/lib/libc/stdio/getwchar.c b/lib/libc/stdio/getwchar.c index 74b8d7032..4ba38b42d 100644 --- a/lib/libc/stdio/getwchar.c +++ b/lib/libc/stdio/getwchar.c @@ -1,4 +1,4 @@ -/* $NetBSD: getwchar.c,v 1.3 2005/06/12 05:21:27 lukem Exp $ */ +/* $NetBSD: getwchar.c,v 1.4 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c)2001 Citrus Project, @@ -30,7 +30,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getwchar.c,v 1.3 2005/06/12 05:21:27 lukem Exp $"); +__RCSID("$NetBSD: getwchar.c,v 1.4 2012/03/15 18:22:30 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -42,7 +42,7 @@ __RCSID("$NetBSD: getwchar.c,v 1.3 2005/06/12 05:21:27 lukem Exp $"); #undef getwchar wint_t -getwchar() +getwchar(void) { return fgetwc(stdin); diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h index 7a03bc96e..42cd30fd0 100644 --- a/lib/libc/stdio/local.h +++ b/lib/libc/stdio/local.h @@ -1,4 +1,4 @@ -/* $NetBSD: local.h,v 1.29 2010/10/24 17:44:32 tron Exp $ */ +/* $NetBSD: local.h,v 1.34 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,6 +38,7 @@ #include "fileext.h" #include +#include #include /* @@ -45,47 +46,44 @@ * in particular, macros and private variables. */ -extern int __sflush __P((FILE *)); -extern FILE *__sfp __P((void)); -extern void __sfpinit __P((FILE *)); -extern int __srefill __P((FILE *)); -extern int __sread __P((void *, char *, int)); -extern int __swrite __P((void *, char const *, int)); -extern fpos_t __sseek __P((void *, fpos_t, int)); -extern int __sclose __P((void *)); -extern void __sinit __P((void)); -extern void _cleanup __P((void)); -extern void (*__cleanup) __P((void)); -extern void __smakebuf __P((FILE *)); -extern int __swhatbuf __P((FILE *, size_t *, int *)); -extern int _fwalk __P((int (*)(FILE *))); -extern char *_mktemp __P((char *)); -extern int __swsetup __P((FILE *)); -extern int __sflags __P((const char *, int *)); -extern int __svfscanf __P((FILE * __restrict, const char * __restrict, - _BSD_VA_LIST_)) - __attribute__((__format__(__scanf__, 2, 0))); -extern int __svfscanf_unlocked __P((FILE * __restrict, const char * __restrict, - _BSD_VA_LIST_)) - __attribute__((__format__(__scanf__, 2, 0))); -extern int __vfprintf_unlocked __P((FILE * __restrict, const char * __restrict, - _BSD_VA_LIST_)); +extern int __sflush(FILE *); +extern FILE *__sfp(void); +extern void __sfpinit(FILE *); +extern int __srefill(FILE *); +extern ssize_t __sread(void *, void *, size_t); +extern ssize_t __swrite(void *, const void *, size_t); +extern off_t __sseek(void *, off_t, int); +extern int __sclose(void *); +extern void __sinit(void); +extern void _cleanup(void); +extern void (*__cleanup)(void); +extern void __smakebuf(FILE *); +extern int __swhatbuf(FILE *, size_t *, int *); +extern int _fwalk(int (*)(FILE *)); +extern char *_mktemp(char *); +extern int __swsetup(FILE *); +extern int __sflags(const char *, int *); +extern int __svfscanf(FILE * __restrict, const char * __restrict, + va_list) __scanflike(2, 0); +extern int __svfscanf_unlocked(FILE * __restrict, const char * __restrict, + va_list) __scanflike(2, 0); +extern int __vfprintf_unlocked(FILE * __restrict, const char * __restrict, + va_list) __printflike(2, 0); extern int __sdidinit; -extern int __gettemp __P((char *, int *, int)); +extern int __gettemp(char *, int *, int); -extern wint_t __fgetwc_unlock __P((FILE *)); -extern wint_t __fputwc_unlock __P((wchar_t, FILE *)); +extern wint_t __fgetwc_unlock(FILE *); +extern wint_t __fputwc_unlock(wchar_t, FILE *); extern ssize_t __getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict); -extern char *__fgetstr __P((FILE * __restrict, size_t * __restrict, int)); -extern int __vfwprintf_unlocked __P((FILE *, const wchar_t *, - _BSD_VA_LIST_)); -extern int __vfwscanf_unlocked __P((FILE * __restrict, - const wchar_t * __restrict, _BSD_VA_LIST_)); +extern char *__fgetstr(FILE * __restrict, size_t * __restrict, int); +extern int __vfwprintf_unlocked(FILE *, const wchar_t *, va_list); +extern int __vfwscanf_unlocked(FILE * __restrict, + const wchar_t * __restrict, va_list); /* * Return true iff the given FILE cannot be written now. @@ -114,15 +112,15 @@ extern int __vfwscanf_unlocked __P((FILE * __restrict, _EXT(fp)->_fgetstr_len = 0; \ } -extern void __flockfile_internal __P((FILE *, int)); -extern void __funlockfile_internal __P((FILE *, int)); +extern void __flockfile_internal(FILE *, int); +extern void __funlockfile_internal(FILE *, int); /* * Detect if the current file position fits in a long int. */ static __inline bool -__fpos_overflow(fpos_t pos) +__long_overflow(off_t pos) { - return (pos < LONG_MIN) || (pos > LONG_MAX); + return (pos < LONG_MIN) || (pos > LONG_MAX); } diff --git a/lib/libc/stdio/makebuf.c b/lib/libc/stdio/makebuf.c index 93fdd558f..cd0a5bf2b 100644 --- a/lib/libc/stdio/makebuf.c +++ b/lib/libc/stdio/makebuf.c @@ -1,4 +1,4 @@ -/* $NetBSD: makebuf.c,v 1.15 2008/03/13 15:40:00 christos Exp $ */ +/* $NetBSD: makebuf.c,v 1.17 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)makebuf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: makebuf.c,v 1.15 2008/03/13 15:40:00 christos Exp $"); +__RCSID("$NetBSD: makebuf.c,v 1.17 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -60,8 +60,7 @@ __RCSID("$NetBSD: makebuf.c,v 1.15 2008/03/13 15:40:00 christos Exp $"); * optimisation) right after the fstat() that finds the buffer size. */ void -__smakebuf(fp) - FILE *fp; +__smakebuf(FILE *fp) { void *p; int flags; @@ -85,7 +84,8 @@ __smakebuf(fp) __cleanup = _cleanup; flags |= __SMBF; fp->_bf._base = fp->_p = p; - fp->_bf._size = size; + _DIAGASSERT(__type_fit(int, size)); + fp->_bf._size = (int)size; if (couldbetty && isatty(__sfileno(fp))) flags |= __SLBF; fp->_flags |= flags; @@ -95,10 +95,7 @@ __smakebuf(fp) * Internal routine to determine `proper' buffering for a file. */ int -__swhatbuf(fp, bufsize, couldbetty) - FILE *fp; - size_t *bufsize; - int *couldbetty; +__swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty) { struct stat st; @@ -109,11 +106,15 @@ __swhatbuf(fp, bufsize, couldbetty) if (__sfileno(fp) == -1 || fstat(__sfileno(fp), &st) < 0) { *couldbetty = 0; *bufsize = BUFSIZ; - return (__SNPT); + return __SNPT; } /* could be a tty iff it is a character device */ *couldbetty = S_ISCHR(st.st_mode); + if (st.st_blksize == 0) { + *bufsize = BUFSIZ; + return __SNPT; + } /* * Optimise fseek() only if it is a regular file. (The test for @@ -129,7 +130,6 @@ __swhatbuf(fp, bufsize, couldbetty) } else #endif *bufsize = fp->_blksize = st.st_blksize; - - return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ? - __SOPT : __SNPT); + return (st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ? + __SOPT : __SNPT; } diff --git a/lib/libc/stdio/mkdtemp.c b/lib/libc/stdio/mkdtemp.c index 914f8576f..39aef6969 100644 --- a/lib/libc/stdio/mkdtemp.c +++ b/lib/libc/stdio/mkdtemp.c @@ -1,4 +1,4 @@ -/* $NetBSD: mkdtemp.c,v 1.10 2008/10/20 10:28:38 apb Exp $ */ +/* $NetBSD: mkdtemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $ */ /* * Copyright (c) 1987, 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: mkdtemp.c,v 1.10 2008/10/20 10:28:38 apb Exp $"); +__RCSID("$NetBSD: mkdtemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -58,12 +58,11 @@ __RCSID("$NetBSD: mkdtemp.c,v 1.10 2008/10/20 10:28:38 apb Exp $"); #endif char * -mkdtemp(path) - char *path; +mkdtemp(char *path) { _DIAGASSERT(path != NULL); - return (GETTEMP(path, (int *)NULL, 1) ? path : (char *)NULL); + return GETTEMP(path, NULL, 1) ? path : NULL; } #endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKDTEMP */ diff --git a/lib/libc/stdio/mkstemp.c b/lib/libc/stdio/mkstemp.c index 241deae7b..0d69eb6f4 100644 --- a/lib/libc/stdio/mkstemp.c +++ b/lib/libc/stdio/mkstemp.c @@ -1,4 +1,4 @@ -/* $NetBSD: mkstemp.c,v 1.10 2008/10/20 10:28:38 apb Exp $ */ +/* $NetBSD: mkstemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $ */ /* * Copyright (c) 1987, 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: mkstemp.c,v 1.10 2008/10/20 10:28:38 apb Exp $"); +__RCSID("$NetBSD: mkstemp.c,v 1.11 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -64,14 +64,13 @@ __weak_alias(mkstemp,_mkstemp) #endif int -mkstemp(path) - char *path; +mkstemp(char *path) { int fd; _DIAGASSERT(path != NULL); - return (GETTEMP(path, &fd, 0) ? fd : -1); + return GETTEMP(path, &fd, 0) ? fd : -1; } #endif /* !HAVE_NBTOOL_CONFIG_H || !HAVE_MKSTEMP */ diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c index 6eb71b01d..662a9ae53 100644 --- a/lib/libc/stdio/mktemp.c +++ b/lib/libc/stdio/mktemp.c @@ -1,4 +1,4 @@ -/* $NetBSD: mktemp.c,v 1.19 2003/08/07 16:43:28 agc Exp $ */ +/* $NetBSD: mktemp.c,v 1.20 2012/03/15 18:22:30 christos Exp $ */ /* * Copyright (c) 1987, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: mktemp.c,v 1.19 2003/08/07 16:43:28 agc Exp $"); +__RCSID("$NetBSD: mktemp.c,v 1.20 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -47,24 +47,22 @@ __RCSID("$NetBSD: mktemp.c,v 1.19 2003/08/07 16:43:28 agc Exp $"); #include "local.h" char * -_mktemp(path) - char *path; +_mktemp(char *path) { _DIAGASSERT(path != NULL); - return (__gettemp(path, (int *)NULL, 0) ? path : (char *)NULL); + return __gettemp(path, NULL, 0) ? path : NULL; } __warn_references(mktemp, "warning: mktemp() possibly used unsafely, use mkstemp() or mkdtemp()") char * -mktemp(path) - char *path; +mktemp(char *path) { _DIAGASSERT(path != NULL); - return (__gettemp(path, (int *)NULL, 0) ? path : (char *)NULL); + return __gettemp(path, NULL, 0) ? path : NULL; } diff --git a/lib/libc/stdio/printf.c b/lib/libc/stdio/printf.c index 1c195ffa0..e297c2670 100644 --- a/lib/libc/stdio/printf.c +++ b/lib/libc/stdio/printf.c @@ -1,4 +1,4 @@ -/* $NetBSD: printf.c,v 1.11 2003/08/07 16:43:29 agc Exp $ */ +/* $NetBSD: printf.c,v 1.12 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)printf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: printf.c,v 1.11 2003/08/07 16:43:29 agc Exp $"); +__RCSID("$NetBSD: printf.c,v 1.12 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -55,5 +55,5 @@ printf(char const *fmt, ...) va_start(ap, fmt); ret = vfprintf(stdout, fmt, ap); va_end(ap); - return (ret); + return ret; } diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c index b3d6a5aac..858c76ce2 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -1,4 +1,4 @@ -/* $NetBSD: putc.c,v 1.11 2003/08/07 16:43:29 agc Exp $ */ +/* $NetBSD: putc.c,v 1.12 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: putc.c,v 1.11 2003/08/07 16:43:29 agc Exp $"); +__RCSID("$NetBSD: putc.c,v 1.12 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,9 +54,7 @@ __RCSID("$NetBSD: putc.c,v 1.11 2003/08/07 16:43:29 agc Exp $"); #undef putc_unlocked int -putc(c, fp) - int c; - FILE *fp; +putc(int c, FILE *fp) { int r; @@ -69,12 +67,10 @@ putc(c, fp) } int -putc_unlocked(c, fp) - int c; - FILE *fp; +putc_unlocked(int c, FILE *fp) { _DIAGASSERT(fp != NULL); - return (__sputc(c, fp)); + return __sputc(c, fp); } diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c index 4f7aca95f..86aa6bf30 100644 --- a/lib/libc/stdio/putchar.c +++ b/lib/libc/stdio/putchar.c @@ -1,4 +1,4 @@ -/* $NetBSD: putchar.c,v 1.9 2003/08/07 16:43:29 agc Exp $ */ +/* $NetBSD: putchar.c,v 1.10 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: putchar.c,v 1.9 2003/08/07 16:43:29 agc Exp $"); +__RCSID("$NetBSD: putchar.c,v 1.10 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,8 +52,7 @@ __RCSID("$NetBSD: putchar.c,v 1.9 2003/08/07 16:43:29 agc Exp $"); * A subroutine version of the macro putchar */ int -putchar(c) - int c; +putchar(int c) { FILE *fp = stdout; int r; @@ -65,8 +64,7 @@ putchar(c) } int -putchar_unlocked(c) - int c; +putchar_unlocked(int c) { - return (__sputc(c, stdout)); + return __sputc(c, stdout); } diff --git a/lib/libc/stdio/puts.c b/lib/libc/stdio/puts.c index 810b96cfc..0ffa7d1cd 100644 --- a/lib/libc/stdio/puts.c +++ b/lib/libc/stdio/puts.c @@ -1,4 +1,4 @@ -/* $NetBSD: puts.c,v 1.15 2006/03/17 02:25:23 chris Exp $ */ +/* $NetBSD: puts.c,v 1.16 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)puts.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: puts.c,v 1.15 2006/03/17 02:25:23 chris Exp $"); +__RCSID("$NetBSD: puts.c,v 1.16 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,8 +53,7 @@ __RCSID("$NetBSD: puts.c,v 1.15 2006/03/17 02:25:23 chris Exp $"); * Write the given string to stdout, appending a newline. */ int -puts(s) - char const *s; +puts(char const *s) { size_t c; struct __suio uio; @@ -78,5 +77,5 @@ puts(s) FLOCKFILE(stdout); r = __sfvwrite(stdout, &uio); FUNLOCKFILE(stdout); - return (r ? EOF : '\n'); + return r ? EOF : '\n'; } diff --git a/lib/libc/stdio/putw.c b/lib/libc/stdio/putw.c index 728959ba7..3ebd0302e 100644 --- a/lib/libc/stdio/putw.c +++ b/lib/libc/stdio/putw.c @@ -1,4 +1,4 @@ -/* $NetBSD: putw.c,v 1.11 2003/08/07 16:43:29 agc Exp $ */ +/* $NetBSD: putw.c,v 1.12 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)putw.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: putw.c,v 1.11 2003/08/07 16:43:29 agc Exp $"); +__RCSID("$NetBSD: putw.c,v 1.12 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,9 +49,7 @@ __RCSID("$NetBSD: putw.c,v 1.11 2003/08/07 16:43:29 agc Exp $"); #include "local.h" int -putw(w, fp) - int w; - FILE *fp; +putw(int w, FILE *fp) { struct __suio uio; struct __siov iov; diff --git a/lib/libc/stdio/refill.c b/lib/libc/stdio/refill.c index ebedd3c0c..7988e7407 100644 --- a/lib/libc/stdio/refill.c +++ b/lib/libc/stdio/refill.c @@ -1,4 +1,4 @@ -/* $NetBSD: refill.c,v 1.14 2010/09/10 10:29:23 drochner Exp $ */ +/* $NetBSD: refill.c,v 1.16 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: refill.c,v 1.14 2010/09/10 10:29:23 drochner Exp $"); +__RCSID("$NetBSD: refill.c,v 1.16 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,18 +52,15 @@ __RCSID("$NetBSD: refill.c,v 1.14 2010/09/10 10:29:23 drochner Exp $"); extern rwlock_t __sfp_lock; #endif -static int lflush __P((FILE *)); - static int -lflush(fp) - FILE *fp; +lflush(FILE *fp) { _DIAGASSERT(fp != NULL); if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) - return (__sflush(fp)); - return (0); + return __sflush(fp); + return 0; } /* @@ -71,8 +68,7 @@ lflush(fp) * Return EOF on eof or error, 0 otherwise. */ int -__srefill(fp) - FILE *fp; +__srefill(FILE *fp) { _DIAGASSERT(fp != NULL); @@ -85,19 +81,19 @@ __srefill(fp) /* SysV does not make this test; take it out for compatibility */ if (fp->_flags & __SEOF) - return (EOF); + return EOF; /* if not already reading, have to be reading and writing */ if ((fp->_flags & __SRD) == 0) { if ((fp->_flags & __SRW) == 0) { errno = EBADF; fp->_flags |= __SERR; - return (EOF); + return EOF; } /* switch to reading */ if (fp->_flags & __SWR) { if (__sflush(fp)) - return (EOF); + return EOF; fp->_flags &= ~__SWR; fp->_w = 0; fp->_lbfsize = 0; @@ -114,7 +110,7 @@ __srefill(fp) FREEUB(fp); if ((fp->_r = fp->_ur) != 0) { fp->_p = fp->_up; - return (0); + return 0; } } } @@ -133,7 +129,8 @@ __srefill(fp) rwlock_unlock(&__sfp_lock); } fp->_p = fp->_bf._base; - fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size); + fp->_r = (int)(*fp->_read)(fp->_cookie, (char *)fp->_p, + (size_t)fp->_bf._size); fp->_flags &= ~__SMOD; /* buffer contents are again pristine */ if (fp->_r <= 0) { if (fp->_r == 0) @@ -142,7 +139,7 @@ __srefill(fp) fp->_r = 0; fp->_flags |= __SERR; } - return (EOF); + return EOF; } - return (0); + return 0; } diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c index f006cd543..2573b0eaa 100644 --- a/lib/libc/stdio/remove.c +++ b/lib/libc/stdio/remove.c @@ -1,4 +1,4 @@ -/* $NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $ */ +/* $NetBSD: remove.c,v 1.14 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $"); +__RCSID("$NetBSD: remove.c,v 1.14 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,22 +50,21 @@ __RCSID("$NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $"); #include int -remove(file) - const char *file; +remove(const char *file) { struct stat sb; _DIAGASSERT(file != NULL); if (lstat(file, &sb) < 0) - return (-1); + return -1; /* * The file system may prohibit using unlink(2) on directories, * so always use rmdir(2) in that case. */ if (S_ISDIR(sb.st_mode)) - return (rmdir(file)); + return rmdir(file); else - return (unlink(file)); + return unlink(file); } diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c index 899ec58ef..3d1f09d35 100644 --- a/lib/libc/stdio/rewind.c +++ b/lib/libc/stdio/rewind.c @@ -1,4 +1,4 @@ -/* $NetBSD: rewind.c,v 1.13 2003/08/07 16:43:30 agc Exp $ */ +/* $NetBSD: rewind.c,v 1.14 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)rewind.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: rewind.c,v 1.13 2003/08/07 16:43:30 agc Exp $"); +__RCSID("$NetBSD: rewind.c,v 1.14 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,8 +48,7 @@ __RCSID("$NetBSD: rewind.c,v 1.13 2003/08/07 16:43:30 agc Exp $"); #include "local.h" void -rewind(fp) - FILE *fp; +rewind(FILE *fp) { _DIAGASSERT(fp != NULL); diff --git a/lib/libc/stdio/rget.c b/lib/libc/stdio/rget.c index 26a871d4a..3e2cd60cc 100644 --- a/lib/libc/stdio/rget.c +++ b/lib/libc/stdio/rget.c @@ -1,4 +1,4 @@ -/* $NetBSD: rget.c,v 1.12 2003/08/07 16:43:30 agc Exp $ */ +/* $NetBSD: rget.c,v 1.13 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)rget.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: rget.c,v 1.12 2003/08/07 16:43:30 agc Exp $"); +__RCSID("$NetBSD: rget.c,v 1.13 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,8 +53,7 @@ __RCSID("$NetBSD: rget.c,v 1.12 2003/08/07 16:43:30 agc Exp $"); * in the newly-filled buffer. */ int -__srget(fp) - FILE *fp; +__srget(FILE *fp) { _DIAGASSERT(fp != NULL); @@ -62,7 +61,7 @@ __srget(fp) _SET_ORIENTATION(fp, -1); if (__srefill(fp) == 0) { fp->_r--; - return (*fp->_p++); + return *fp->_p++; } - return (EOF); + return EOF; } diff --git a/lib/libc/stdio/scanf.c b/lib/libc/stdio/scanf.c index 1fbf753d5..20a00eaec 100644 --- a/lib/libc/stdio/scanf.c +++ b/lib/libc/stdio/scanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: scanf.c,v 1.12 2003/08/07 16:43:31 agc Exp $ */ +/* $NetBSD: scanf.c,v 1.13 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: scanf.c,v 1.12 2003/08/07 16:43:31 agc Exp $"); +__RCSID("$NetBSD: scanf.c,v 1.13 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -60,5 +60,5 @@ scanf(char const *fmt, ...) va_start(ap, fmt); ret = __svfscanf(stdin, fmt, ap); va_end(ap); - return (ret); + return ret; } diff --git a/lib/libc/stdio/setbuf.c b/lib/libc/stdio/setbuf.c index 08c23c01e..e2ce106f0 100644 --- a/lib/libc/stdio/setbuf.c +++ b/lib/libc/stdio/setbuf.c @@ -1,4 +1,4 @@ -/* $NetBSD: setbuf.c,v 1.9 2003/08/07 16:43:31 agc Exp $ */ +/* $NetBSD: setbuf.c,v 1.10 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)setbuf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: setbuf.c,v 1.9 2003/08/07 16:43:31 agc Exp $"); +__RCSID("$NetBSD: setbuf.c,v 1.10 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,13 +48,11 @@ __RCSID("$NetBSD: setbuf.c,v 1.9 2003/08/07 16:43:31 agc Exp $"); #include "local.h" void -setbuf(fp, buf) - FILE *fp; - char *buf; +setbuf(FILE *fp, char *buf) { _DIAGASSERT(fp != NULL); /* buf may be NULL */ - (void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ); + (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ); } diff --git a/lib/libc/stdio/setbuffer.c b/lib/libc/stdio/setbuffer.c index 6ef5b3524..eb10c9a00 100644 --- a/lib/libc/stdio/setbuffer.c +++ b/lib/libc/stdio/setbuffer.c @@ -1,4 +1,4 @@ -/* $NetBSD: setbuffer.c,v 1.12 2009/10/25 20:44:13 christos Exp $ */ +/* $NetBSD: setbuffer.c,v 1.13 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)setbuffer.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: setbuffer.c,v 1.12 2009/10/25 20:44:13 christos Exp $"); +__RCSID("$NetBSD: setbuffer.c,v 1.13 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -46,10 +46,7 @@ __RCSID("$NetBSD: setbuffer.c,v 1.12 2009/10/25 20:44:13 christos Exp $"); #include void -setbuffer(fp, buf, size) - FILE *fp; - char *buf; - int size; +setbuffer(FILE *fp, char *buf, int size) { _DIAGASSERT(fp != NULL); @@ -62,11 +59,10 @@ setbuffer(fp, buf, size) * set line buffering */ int -setlinebuf(fp) - FILE *fp; +setlinebuf(FILE *fp) { _DIAGASSERT(fp != NULL); - return (setvbuf(fp, NULL, _IOLBF, (size_t)0)); + return setvbuf(fp, NULL, _IOLBF, (size_t)0); } diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c index 957e04366..4fe57722a 100644 --- a/lib/libc/stdio/setvbuf.c +++ b/lib/libc/stdio/setvbuf.c @@ -1,4 +1,4 @@ -/* $NetBSD: setvbuf.c,v 1.17 2003/08/07 16:43:31 agc Exp $ */ +/* $NetBSD: setvbuf.c,v 1.19 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)setvbuf.c 8.2 (Berkeley) 11/16/93"; #else -__RCSID("$NetBSD: setvbuf.c,v 1.17 2003/08/07 16:43:31 agc Exp $"); +__RCSID("$NetBSD: setvbuf.c,v 1.19 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,11 +54,7 @@ __RCSID("$NetBSD: setvbuf.c,v 1.17 2003/08/07 16:43:31 agc Exp $"); * a buffer. */ int -setvbuf(fp, buf, mode, size) - FILE *fp; - char *buf; - int mode; - size_t size; +setvbuf(FILE *fp, char *buf, int mode, size_t size) { int ret, flags; size_t iosize; @@ -74,7 +70,7 @@ setvbuf(fp, buf, mode, size) */ if (mode != _IONBF) if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0) - return (-1); + return -1; FLOCKFILE(fp); /* @@ -130,7 +126,7 @@ nbf: fp->_bf._base = fp->_p = fp->_nbuf; fp->_bf._size = 1; FUNLOCKFILE(fp); - return (ret); + return ret; } flags |= __SMBF; } @@ -152,7 +148,8 @@ nbf: flags |= __SLBF; fp->_flags = flags; fp->_bf._base = fp->_p = (unsigned char *)buf; - fp->_bf._size = size; + _DIAGASSERT(__type_fit(int, size)); + fp->_bf._size = (int)size; /* fp->_lbfsize is still 0 */ if (flags & __SWR) { /* @@ -162,8 +159,10 @@ nbf: if (flags & __SLBF) { fp->_w = 0; fp->_lbfsize = -fp->_bf._size; - } else - fp->_w = size; + } else { + _DIAGASSERT(__type_fit(int, size)); + fp->_w = (int)size; + } } else { /* begin/continue reading, or stay in intermediate state */ fp->_w = 0; @@ -171,5 +170,5 @@ nbf: __cleanup = _cleanup; FUNLOCKFILE(fp); - return (ret); + return ret; } diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c index a3f59fe48..e31cbbbe5 100644 --- a/lib/libc/stdio/snprintf.c +++ b/lib/libc/stdio/snprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: snprintf.c,v 1.22 2007/10/26 19:48:14 christos Exp $ */ +/* $NetBSD: snprintf.c,v 1.24 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: snprintf.c,v 1.22 2007/10/26 19:48:14 christos Exp $"); +__RCSID("$NetBSD: snprintf.c,v 1.24 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -74,7 +74,7 @@ snprintf(char *str, size_t n, char const *fmt, ...) if ((int)n < 0) { errno = EINVAL; - return (-1); + return -1; } va_start(ap, fmt); _FILEEXT_SETUP(&f, &fext); @@ -85,10 +85,11 @@ snprintf(char *str, size_t n, char const *fmt, ...) f._bf._size = f._w = 0; } else { f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = n - 1; + _DIAGASSERT(__type_fit(int, n - 1)); + f._bf._size = f._w = (int)(n - 1); } ret = __vfprintf_unlocked(&f, fmt, ap); *f._p = 0; va_end(ap); - return (ret); + return ret; } diff --git a/lib/libc/stdio/sprintf.c b/lib/libc/stdio/sprintf.c index 8045e9c45..8ac2cc29d 100644 --- a/lib/libc/stdio/sprintf.c +++ b/lib/libc/stdio/sprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: sprintf.c,v 1.15 2007/06/03 17:39:26 christos Exp $ */ +/* $NetBSD: sprintf.c,v 1.16 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)sprintf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: sprintf.c,v 1.15 2007/06/03 17:39:26 christos Exp $"); +__RCSID("$NetBSD: sprintf.c,v 1.16 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -74,5 +74,5 @@ sprintf(char *str, char const *fmt, ...) ret = __vfprintf_unlocked(&f, fmt, ap); va_end(ap); *f._p = 0; - return (ret); + return ret; } diff --git a/lib/libc/stdio/sscanf.c b/lib/libc/stdio/sscanf.c index 42463ff61..fe339c99b 100644 --- a/lib/libc/stdio/sscanf.c +++ b/lib/libc/stdio/sscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: sscanf.c,v 1.17 2010/01/11 20:39:29 joerg Exp $ */ +/* $NetBSD: sscanf.c,v 1.20 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)sscanf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: sscanf.c,v 1.17 2010/01/11 20:39:29 joerg Exp $"); +__RCSID("$NetBSD: sscanf.c,v 1.20 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,17 +50,12 @@ __RCSID("$NetBSD: sscanf.c,v 1.17 2010/01/11 20:39:29 joerg Exp $"); #include "reentrant.h" #include "local.h" -static int eofread __P((void *, char *, int)); - /* ARGSUSED */ -static int -eofread(cookie, buf, len) - void *cookie; - char *buf; - int len; +static ssize_t +eofread(void *cookie, void *buf, size_t len) { - return (0); + return 0; } int @@ -69,6 +64,7 @@ sscanf(const char *str, char const *fmt, ...) int ret; va_list ap; FILE f; + size_t len; struct __sfileext fext; _DIAGASSERT(str != NULL); @@ -77,11 +73,13 @@ sscanf(const char *str, char const *fmt, ...) _FILEEXT_SETUP(&f, &fext); f._flags = __SRD; f._bf._base = f._p = __UNCONST(str); - f._bf._size = f._r = strlen(str); + len = strlen(str); + _DIAGASSERT(__type_fit(int, len)); + f._bf._size = f._r = (int)len; f._read = eofread; _UB(&f)._base = NULL; va_start(ap, fmt); ret = __svfscanf_unlocked(&f, fmt, ap); va_end(ap); - return (ret); + return ret; } diff --git a/lib/libc/stdio/stdio.c b/lib/libc/stdio/stdio.c index 8c1849e5c..bf5bb095b 100644 --- a/lib/libc/stdio/stdio.c +++ b/lib/libc/stdio/stdio.c @@ -1,4 +1,4 @@ -/* $NetBSD: stdio.c,v 1.16 2009/10/25 20:44:13 christos Exp $ */ +/* $NetBSD: stdio.c,v 1.21 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: stdio.c,v 1.16 2009/10/25 20:44:13 christos Exp $"); +__RCSID("$NetBSD: stdio.c,v 1.21 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -56,71 +56,68 @@ __RCSID("$NetBSD: stdio.c,v 1.16 2009/10/25 20:44:13 christos Exp $"); * Small standard I/O/seek/close functions. * These maintain the `known seek offset' for seek optimisation. */ -int -__sread(cookie, buf, n) - void *cookie; - char *buf; - int n; +ssize_t +__sread(void *cookie, void *buf, size_t n) { FILE *fp = cookie; - int ret; + ssize_t ret; - _DIAGASSERT(fp != NULL); + _DIAGASSERT(cookie != NULL); + _DIAGASSERT(cookie == fp->_cookie); _DIAGASSERT(buf != NULL); - ret = read(__sfileno(fp), buf, (size_t)n); + ret = read(__sfileno(fp), buf, n); /* if the read succeeded, update the current offset */ if (ret >= 0) fp->_offset += ret; else fp->_flags &= ~__SOFF; /* paranoia */ - return (ret); + + return ret; } -int -__swrite(cookie, buf, n) - void *cookie; - char const *buf; - int n; +ssize_t +__swrite(void *cookie, const void *buf, size_t n) { FILE *fp = cookie; _DIAGASSERT(cookie != NULL); + _DIAGASSERT(cookie == fp->_cookie); _DIAGASSERT(buf != NULL); if (fp->_flags & __SAPP) - (void) lseek(__sfileno(fp), (off_t)0, SEEK_END); + if (lseek(__sfileno(fp), (off_t)0, SEEK_END) == (off_t)-1) + return -1; fp->_flags &= ~__SOFF; /* in case FAPPEND mode is set */ - return write(__sfileno(fp), buf, (size_t)n); + return write(__sfileno(fp), buf, n); } -fpos_t -__sseek(cookie, offset, whence) - void *cookie; - fpos_t offset; - int whence; +off_t +__sseek(void *cookie, off_t offset, int whence) { FILE *fp = cookie; off_t ret; - _DIAGASSERT(fp != NULL); + _DIAGASSERT(cookie != NULL); + _DIAGASSERT(cookie == fp->_cookie); - ret = lseek(__sfileno(fp), (off_t)offset, whence); - if (ret == -1L) + ret = lseek(__sfileno(fp), offset, whence); + if (ret == (off_t)-1L) fp->_flags &= ~__SOFF; else { fp->_flags |= __SOFF; fp->_offset = ret; } - return (ret); + return ret; } int -__sclose(cookie) - void *cookie; +__sclose(void *cookie) { + FILE *fp = cookie; _DIAGASSERT(cookie != NULL); + _DIAGASSERT(cookie == fp->_cookie); - return close(__sfileno((FILE *)cookie)); + return close(__sfileno(fp)); } diff --git a/lib/libc/stdio/swprintf.c b/lib/libc/stdio/swprintf.c index b769b3186..488ce4266 100644 --- a/lib/libc/stdio/swprintf.c +++ b/lib/libc/stdio/swprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: swprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */ +/* $NetBSD: swprintf.c,v 1.2 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins @@ -31,7 +31,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdio/swprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $"); #else -__RCSID("$NetBSD: swprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $"); +__RCSID("$NetBSD: swprintf.c,v 1.2 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,5 +49,5 @@ swprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, ...) ret = vswprintf(s, n, fmt, ap); va_end(ap); - return (ret); + return ret; } diff --git a/lib/libc/stdio/swscanf.c b/lib/libc/stdio/swscanf.c index 9e7eecddc..c4b5cbf52 100644 --- a/lib/libc/stdio/swscanf.c +++ b/lib/libc/stdio/swscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: swscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */ +/* $NetBSD: swscanf.c,v 1.2 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins @@ -31,7 +31,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdio/swscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $"); #else -__RCSID("$NetBSD: swscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $"); +__RCSID("$NetBSD: swscanf.c,v 1.2 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,5 +49,5 @@ swscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, ...) r = vswscanf(str, fmt, ap); va_end(ap); - return (r); + return r; } diff --git a/lib/libc/stdio/tempnam.c b/lib/libc/stdio/tempnam.c index 9fd5dbf0a..2a55a5c2b 100644 --- a/lib/libc/stdio/tempnam.c +++ b/lib/libc/stdio/tempnam.c @@ -1,4 +1,4 @@ -/* $NetBSD: tempnam.c,v 1.21 2009/10/25 20:44:13 christos Exp $ */ +/* $NetBSD: tempnam.c,v 1.22 2012/03/15 18:22:30 christos Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tempnam.c,v 1.21 2009/10/25 20:44:13 christos Exp $"); +__RCSID("$NetBSD: tempnam.c,v 1.22 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -98,5 +98,5 @@ tempnam(const char *dir, const char *pfx) sverrno = errno; free(name); errno = sverrno; - return(NULL); + return NULL; } diff --git a/lib/libc/stdio/tmpfile.c b/lib/libc/stdio/tmpfile.c index 86b685367..a62e8f288 100644 --- a/lib/libc/stdio/tmpfile.c +++ b/lib/libc/stdio/tmpfile.c @@ -1,4 +1,4 @@ -/* $NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp $ */ +/* $NetBSD: tmpfile.c,v 1.12 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp $"); +__RCSID("$NetBSD: tmpfile.c,v 1.12 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,7 +52,7 @@ __RCSID("$NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp $"); #include FILE * -tmpfile() +tmpfile(void) { sigset_t set, oset; FILE *fp; @@ -73,13 +73,13 @@ tmpfile() (void)sigprocmask(SIG_SETMASK, &oset, NULL); if (fd == -1) - return (NULL); + return NULL; if ((fp = fdopen(fd, "w+")) == NULL) { sverrno = errno; (void)close(fd); errno = sverrno; - return (NULL); + return NULL; } - return (fp); + return fp; } diff --git a/lib/libc/stdio/tmpnam.c b/lib/libc/stdio/tmpnam.c index ac42baf35..9bb7858ea 100644 --- a/lib/libc/stdio/tmpnam.c +++ b/lib/libc/stdio/tmpnam.c @@ -1,4 +1,4 @@ -/* $NetBSD: tmpnam.c,v 1.14 2003/08/07 16:43:33 agc Exp $ */ +/* $NetBSD: tmpnam.c,v 1.15 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)tmpnam.c 8.3 (Berkeley) 3/28/94"; #else -__RCSID("$NetBSD: tmpnam.c,v 1.14 2003/08/07 16:43:33 agc Exp $"); +__RCSID("$NetBSD: tmpnam.c,v 1.15 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,8 +52,7 @@ __warn_references(tmpnam, "warning: tmpnam() possibly used unsafely, use mkstemp() or mkdtemp()") char * -tmpnam(s) - char *s; +tmpnam(char *s) { static u_long tmpcount; static char buf[L_tmpnam]; @@ -62,5 +61,5 @@ tmpnam(s) s = buf; (void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXXXXXX", P_tmpdir, tmpcount); ++tmpcount; - return (_mktemp(s)); + return _mktemp(s); } diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c index 10eb301bb..c7a2f7629 100644 --- a/lib/libc/stdio/ungetc.c +++ b/lib/libc/stdio/ungetc.c @@ -1,7 +1,7 @@ -/* $NetBSD: ungetc.c,v 1.16 2009/10/25 20:44:13 christos Exp $ */ +/* $NetBSD: ungetc.c,v 1.17 2012/03/15 18:22:30 christos Exp $ */ /*- - * Copyright (c) 1990, 1993 + * Copyright c 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93"; #else -__RCSID("$NetBSD: ungetc.c,v 1.16 2009/10/25 20:44:13 christos Exp $"); +__RCSID("$NetBSD: ungetc.c,v 1.17 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,7 +49,6 @@ __RCSID("$NetBSD: ungetc.c,v 1.16 2009/10/25 20:44:13 christos Exp $"); #include "reentrant.h" #include "local.h" -static int __submore __P((FILE *)); /* * Expand the ungetc buffer `in place'. That is, adjust fp->_p when * the buffer moves, so that it points the same distance from the end, @@ -57,8 +56,7 @@ static int __submore __P((FILE *)); * are all at the end (stack-style). */ static int -__submore(fp) - FILE *fp; +__submore(FILE *fp) { int i; unsigned char *p; @@ -70,37 +68,35 @@ __submore(fp) * Get a new buffer (rather than expanding the old one). */ if ((p = malloc((size_t)BUFSIZ)) == NULL) - return (EOF); + return EOF; _UB(fp)._base = p; _UB(fp)._size = BUFSIZ; p += BUFSIZ - sizeof(fp->_ubuf); for (i = sizeof(fp->_ubuf); --i >= 0;) p[i] = fp->_ubuf[i]; fp->_p = p; - return (0); + return 0; } i = _UB(fp)._size; p = realloc(_UB(fp)._base, (size_t)(i << 1)); if (p == NULL) - return (EOF); + return EOF; /* no overlap (hence can use memcpy) because we doubled the size */ (void)memcpy((p + i), p, (size_t)i); fp->_p = p + i; _UB(fp)._base = p; _UB(fp)._size = i << 1; - return (0); + return 0; } int -ungetc(c, fp) - int c; - FILE *fp; +ungetc(int c, FILE *fp) { _DIAGASSERT(fp != NULL); if (c == EOF) - return (EOF); + return EOF; if (!__sdidinit) __sinit(); FLOCKFILE(fp); @@ -112,12 +108,12 @@ ungetc(c, fp) */ if ((fp->_flags & __SRW) == 0) { FUNLOCKFILE(fp); - return (EOF); + return EOF; } if (fp->_flags & __SWR) { if (__sflush(fp)) { FUNLOCKFILE(fp); - return (EOF); + return EOF; } fp->_flags &= ~__SWR; fp->_w = 0; @@ -134,12 +130,12 @@ ungetc(c, fp) if (HASUB(fp)) { if (fp->_r >= _UB(fp)._size && __submore(fp)) { FUNLOCKFILE(fp); - return (EOF); + return EOF; } *--fp->_p = c; fp->_r++; FUNLOCKFILE(fp); - return (c); + return c; } fp->_flags &= ~__SEOF; @@ -153,7 +149,7 @@ ungetc(c, fp) fp->_p--; fp->_r++; FUNLOCKFILE(fp); - return (c); + return c; } /* @@ -168,5 +164,5 @@ ungetc(c, fp) fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1]; fp->_r = 1; FUNLOCKFILE(fp); - return (c); + return c; } diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c index 3664d7ba1..f38854af0 100644 --- a/lib/libc/stdio/vasprintf.c +++ b/lib/libc/stdio/vasprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vasprintf.c,v 1.12 2009/10/25 20:44:13 christos Exp $ */ +/* $NetBSD: vasprintf.c,v 1.14 2012/03/15 18:22:30 christos Exp $ */ /* * Copyright (c) 1997 Todd C. Miller @@ -29,7 +29,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: vasprintf.c,v 1.12 2009/10/25 20:44:13 christos Exp $"); +__RCSID("$NetBSD: vasprintf.c,v 1.14 2012/03/15 18:22:30 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -40,10 +40,7 @@ __RCSID("$NetBSD: vasprintf.c,v 1.12 2009/10/25 20:44:13 christos Exp $"); #include "local.h" int -vasprintf(str, fmt, ap) - char **str; - const char *fmt; - _BSD_VA_LIST_ ap; +vasprintf(char **str, const char *fmt, va_list ap) { int ret; FILE f; @@ -68,12 +65,12 @@ vasprintf(str, fmt, ap) if (_base == NULL) goto err; *str = (char *)_base; - return (ret); + return ret; err: if (f._bf._base) free(f._bf._base); *str = NULL; errno = ENOMEM; - return (-1); + return -1; } diff --git a/lib/libc/stdio/vdprintf.c b/lib/libc/stdio/vdprintf.c index 98bf40078..247607c1e 100644 --- a/lib/libc/stdio/vdprintf.c +++ b/lib/libc/stdio/vdprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vdprintf.c,v 1.1 2010/09/06 14:52:55 christos Exp $ */ +/* $NetBSD: vdprintf.c,v 1.2 2011/07/17 20:54:34 joerg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: vdprintf.c,v 1.1 2010/09/06 14:52:55 christos Exp $"); +__RCSID("$NetBSD: vdprintf.c,v 1.2 2011/07/17 20:54:34 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -55,7 +55,7 @@ __weak_alias(vdprintf,_vdprintf) #endif int -vdprintf(int fd, const char * __restrict fmt, _BSD_VA_LIST_ ap) +vdprintf(int fd, const char * __restrict fmt, va_list ap) { FILE f; struct __sfileext fext; diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c index c7f89067e..899883288 100644 --- a/lib/libc/stdio/vfscanf.c +++ b/lib/libc/stdio/vfscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfscanf.c,v 1.41 2010/12/16 17:42:27 wiz Exp $ */ +/* $NetBSD: vfscanf.c,v 1.43 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.41 2007/01/09 00:28:07 imp Exp $"); #else -__RCSID("$NetBSD: vfscanf.c,v 1.41 2010/12/16 17:42:27 wiz Exp $"); +__RCSID("$NetBSD: vfscanf.c,v 1.43 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -109,7 +109,7 @@ __weak_alias(vfscanf,__svfscanf) static const u_char *__sccl(char *, const u_char *); #ifndef NO_FLOATING_POINT -static int parsefloat(FILE *, char *, char *); +static size_t parsefloat(FILE *, char *, char *); #endif int __scanfdebug = 0; @@ -137,7 +137,7 @@ __svfscanf(FILE *fp, char const *fmt0, va_list ap) FLOCKFILE(fp); ret = __svfscanf_unlocked(fp, fmt0, ap); FUNLOCKFILE(fp); - return (ret); + return ret; } #define SCANF_SKIP_SPACE() \ @@ -161,7 +161,7 @@ __svfscanf_unlocked(FILE *fp, const char *fmt0, va_list ap) char *p0; /* saves original value of p when necessary */ int nassigned; /* number of fields assigned */ int nconversions; /* number of conversions */ - int nread; /* number of characters consumed from fp */ + size_t nread; /* number of characters consumed from fp */ int base; /* base argument to conversion function */ char ccltab[256]; /* character class table for %[...] */ char buf[BUF]; /* buffer for numeric and mb conversions */ @@ -186,7 +186,7 @@ __svfscanf_unlocked(FILE *fp, const char *fmt0, va_list ap) for (;;) { c = (unsigned char)*fmt++; if (c == 0) - return (nassigned); + return nassigned; if (isspace(c)) { while ((fp->_r > 0 || __srefill(fp) == 0) && isspace(*fp->_p)) @@ -325,9 +325,9 @@ literal: if (flags & SUPPRESS) /* ??? */ continue; if (flags & SHORTSHORT) - *va_arg(ap, char *) = nread; + *va_arg(ap, char *) = (char)nread; else if (flags & SHORT) - *va_arg(ap, short *) = nread; + *va_arg(ap, short *) = (short)nread; else if (flags & LONG) *va_arg(ap, long *) = nread; else if (flags & LONGLONG) @@ -339,7 +339,7 @@ literal: else if (flags & PTRDIFFT) *va_arg(ap, ptrdiff_t *) = nread; else - *va_arg(ap, int *) = nread; + *va_arg(ap, int *) = (int)nread; continue; default: @@ -349,7 +349,7 @@ literal: * Disgusting backwards compatibility hack. XXX */ case '\0': /* compat */ - return (EOF); + return EOF; } /* @@ -439,7 +439,9 @@ literal: } } else { sum += width; - fp->_r -= width; + _DIAGASSERT(__type_fit(int, + fp->_r - width)); + fp->_r -= (int)width; fp->_p += width; break; } @@ -829,9 +831,9 @@ literal: } } input_failure: - return (nconversions != 0 ? nassigned : EOF); + return nconversions != 0 ? nassigned : EOF; match_failure: - return (nassigned); + return nassigned; } /* @@ -841,9 +843,7 @@ match_failure: * considered part of the scanset. */ static const u_char * -__sccl(tab, fmt) - char *tab; - const u_char *fmt; +__sccl(char *tab, const u_char *fmt) { int c, n, v, i; @@ -861,7 +861,7 @@ __sccl(tab, fmt) (void)memset(tab, v, 256); if (c == 0) - return (fmt - 1);/* format ended before closing ] */ + return fmt - 1;/* format ended before closing ] */ /* * Now set the entries corresponding to the actual scanset @@ -878,7 +878,7 @@ doswitch: switch (n) { case 0: /* format ended too soon */ - return (fmt - 1); + return fmt - 1; case '-': /* @@ -928,13 +928,13 @@ doswitch: #else c = *fmt++; if (c == 0) - return (fmt - 1); + return fmt - 1; if (c == ']') - return (fmt); + return fmt; #endif case ']': /* end of scanset */ - return (fmt); + return fmt; default: /* just another character */ c = n; @@ -945,7 +945,7 @@ doswitch: } #ifndef NO_FLOATING_POINT -static int +static size_t parsefloat(FILE *fp, char *buf, char *end) { char *commit, *p; @@ -1093,6 +1093,6 @@ parsedone: while (commit < --p) (void)ungetc(*(u_char *)p, fp); *++commit = '\0'; - return (commit - buf); + return commit - buf; } #endif diff --git a/lib/libc/stdio/vfwprintf.c b/lib/libc/stdio/vfwprintf.c index 143afc03a..e814253c0 100644 --- a/lib/libc/stdio/vfwprintf.c +++ b/lib/libc/stdio/vfwprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfwprintf.c,v 1.23 2010/12/16 17:42:27 wiz Exp $ */ +/* $NetBSD: vfwprintf.c,v 1.30 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwprintf.c,v 1.27 2007/01/09 00:28:08 imp Exp $"); #else -__RCSID("$NetBSD: vfwprintf.c,v 1.23 2010/12/16 17:42:27 wiz Exp $"); +__RCSID("$NetBSD: vfwprintf.c,v 1.30 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -124,7 +124,7 @@ union arg { * Type ids for argument type table. */ enum typeid { - T_UNUSED, TP_SHORT, T_INT, T_U_INT, TP_INT, + T_UNUSED = 0, TP_SHORT, T_INT, T_U_INT, TP_INT, T_LONG, T_U_LONG, TP_LONG, T_LLONG, T_U_LLONG, TP_LLONG, T_PTRDIFFT, TP_PTRDIFFT, T_SSIZET, T_SIZET, TP_SIZET, T_INTMAXT, T_UINTMAXT, TP_INTMAXT, TP_VOID, TP_CHAR, TP_SCHAR, @@ -144,7 +144,7 @@ static char *__wcsconv(wchar_t *, int); static int __sprint(FILE *, struct __suio *); #endif static int __find_arguments(const CHAR_T *, va_list, union arg **); -static int __grow_type_table(int, enum typeid **, int *); +static int __grow_type_table(size_t, enum typeid **, size_t *); /* * Helper function for `fprintf to unbuffered unix file': creates a @@ -170,6 +170,7 @@ __sbprintf(FILE *fp, const CHAR_T *fmt, va_list ap) fake._file = fp->_file; fake._cookie = fp->_cookie; fake._write = fp->_write; + fake._flush = fp->_flush; /* set up the buffer */ fake._bf._base = fake._p = buf; @@ -182,7 +183,7 @@ __sbprintf(FILE *fp, const CHAR_T *fmt, va_list ap) ret = END_OF_FILE; if (fake._flags & __SERR) fp->_flags |= __SERR; - return (ret); + return ret; } #ifndef NARROW @@ -201,19 +202,19 @@ __xfputwc(wchar_t wc, FILE *fp) size_t len; if ((fp->_flags & __SSTR) == 0) - return (__fputwc_unlock(wc, fp)); + return __fputwc_unlock(wc, fp); mbs = initial; if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) { fp->_flags |= __SERR; - return (END_OF_FILE); + return END_OF_FILE; } uio.uio_iov = &iov; uio.uio_resid = len; uio.uio_iovcnt = 1; iov.iov_base = buf; iov.iov_len = len; - return (__sfvwrite(fp, &uio) != EOF ? (wint_t)wc : END_OF_FILE); + return __sfvwrite(fp, &uio) != EOF ? (wint_t)wc : END_OF_FILE; } #else /* @@ -230,12 +231,12 @@ __sprint(FILE *fp, struct __suio *uio) if (uio->uio_resid == 0) { uio->uio_iovcnt = 0; - return (0); + return 0; } err = __sfvwrite(fp, uio); uio->uio_resid = 0; uio->uio_iovcnt = 0; - return (err); + return err; } #endif @@ -254,7 +255,7 @@ __sprint(FILE *fp, struct __suio *uio) */ static CHAR_T * __ultoa(u_long val, CHAR_T *endp, int base, int octzero, const char *xdigs, - int needgrp, char thousep, const char *grp) + int needgrp, char thousep, const char *grp) { CHAR_T *cp = endp; long sval; @@ -268,7 +269,7 @@ __ultoa(u_long val, CHAR_T *endp, int base, int octzero, const char *xdigs, case 10: if (val < 10) { /* many numbers are 1 digit */ *--cp = to_char(val); - return (cp); + return cp; } ndig = 0; /* @@ -290,8 +291,9 @@ __ultoa(u_long val, CHAR_T *endp, int base, int octzero, const char *xdigs, * If (*grp == CHAR_MAX) then no more grouping * should be performed. */ - if (needgrp && ndig == *grp && *grp != CHAR_MAX - && sval > 9) { + if (needgrp && ndig == *grp + && (unsigned char)*grp != (unsigned char)CHAR_MAX + && sval > 9) { *--cp = thousep; ndig = 0; /* @@ -325,13 +327,13 @@ __ultoa(u_long val, CHAR_T *endp, int base, int octzero, const char *xdigs, default: /* oops */ abort(); } - return (cp); + return cp; } /* Identical to __ultoa, but for intmax_t. */ static CHAR_T * __ujtoa(uintmax_t val, CHAR_T *endp, int base, int octzero, - const char *xdigs, int needgrp, char thousep, const char *grp) + const char *xdigs, int needgrp, char thousep, const char *grp) { CHAR_T *cp = endp; intmax_t sval; @@ -340,13 +342,13 @@ __ujtoa(uintmax_t val, CHAR_T *endp, int base, int octzero, /* quick test for small values; __ultoa is typically much faster */ /* (perhaps instead we should run until small, then call __ultoa?) */ if (val <= ULONG_MAX) - return (__ultoa((u_long)val, endp, base, octzero, xdigs, - needgrp, thousep, grp)); + return __ultoa((u_long)val, endp, base, octzero, xdigs, + needgrp, thousep, grp); switch (base) { case 10: if (val < 10) { *--cp = to_char(val % 10); - return (cp); + return cp; } ndig = 0; if (val > INTMAX_MAX) { @@ -362,8 +364,10 @@ __ujtoa(uintmax_t val, CHAR_T *endp, int base, int octzero, * If (*grp == CHAR_MAX) then no more grouping * should be performed. */ - if (needgrp && *grp != CHAR_MAX && ndig == *grp - && sval > 9) { + if (needgrp + && (unsigned char)*grp != (unsigned char)CHAR_MAX + && ndig == *grp + && sval > 9) { *--cp = thousep; ndig = 0; /* @@ -397,7 +401,7 @@ __ujtoa(uintmax_t val, CHAR_T *endp, int base, int octzero, default: abort(); } - return (cp); + return cp; } #ifndef NARROW @@ -417,7 +421,7 @@ __mbsconv(char *mbsarg, int prec) size_t insize, nchars, nconv; if (mbsarg == NULL) - return (NULL); + return NULL; /* * Supplied argument is a multibyte string; convert it to wide @@ -441,7 +445,7 @@ __mbsconv(char *mbsarg, int prec) insize += nconv; } if (nconv == (size_t)-1 || nconv == (size_t)-2) - return (NULL); + return NULL; } else insize = strlen(mbsarg); @@ -452,7 +456,7 @@ __mbsconv(char *mbsarg, int prec) */ convbuf = malloc((insize + 1) * sizeof(*convbuf)); if (convbuf == NULL) - return (NULL); + return NULL; wcp = convbuf; p = mbsarg; mbs = initial; @@ -467,11 +471,11 @@ __mbsconv(char *mbsarg, int prec) } if (nconv == (size_t)-1 || nconv == (size_t)-2) { free(convbuf); - return (NULL); + return NULL; } *wcp = L'\0'; - return (convbuf); + return convbuf; } #else /* @@ -494,9 +498,9 @@ __wcsconv(wchar_t *wcsarg, int prec) if (prec < 0) { p = wcsarg; mbs = initial; - nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, &mbs); + nbytes = wcsrtombs(NULL, (void *)&p, 0, &mbs); if (nbytes == (size_t)-1) - return (NULL); + return NULL; } else { /* * Optimisation: if the output precision is small enough, @@ -519,18 +523,18 @@ __wcsconv(wchar_t *wcsarg, int prec) } } if ((convbuf = malloc(nbytes + 1)) == NULL) - return (NULL); + return NULL; /* Fill the output buffer. */ p = wcsarg; mbs = initial; - if ((nbytes = wcsrtombs(convbuf, (const wchar_t **)&p, + if ((nbytes = wcsrtombs(convbuf, (void *)&p, nbytes, &mbs)) == (size_t)-1) { free(convbuf); - return (NULL); + return NULL; } convbuf[nbytes] = '\0'; - return (convbuf); + return convbuf; } #endif @@ -545,7 +549,7 @@ WDECL(vf,printf)(FILE * __restrict fp, const CHAR_T * __restrict fmt0, va_list a FLOCKFILE(fp); ret = WDECL(__vf,printf_unlocked)(fp, fmt0, ap); FUNLOCKFILE(fp); - return (ret); + return ret; } #ifndef NO_FLOATING_POINT @@ -724,7 +728,9 @@ WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap) } \ } while (/*CONSTCOND*/0) #define PRINTANDPAD(p, ep, len, with) do { \ - n2 = (ep) - (p); \ + ptrdiff_t td = (ep) - (p); \ + _DIAGASSERT(__type_fit(int, td)); \ + n2 = (int)td; \ if (n2 > (len)) \ n2 = (len); \ if (n2 > 0) \ @@ -810,13 +816,13 @@ WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap) /* sorry, f{w,}printf(read_only_file, L"") returns {W,}EOF, not 0 */ if (cantwrite(fp)) { errno = EBADF; - return (END_OF_FILE); + return END_OF_FILE; } /* optimise fprintf(stderr) (and other unbuffered Unix files) */ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && __sfileno(fp) != -1) - return (__sbprintf(fp, fmt0, ap)); + return __sbprintf(fp, fmt0, ap); fmt = (CHAR_T *)__UNCONST(fmt0); argtable = NULL; @@ -837,7 +843,8 @@ WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap) for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) continue; - if ((n = fmt - cp) != 0) { + _DIAGASSERT(__type_fit(int, fmt - cp)); + if ((n = (int)(fmt - cp)) != 0) { if ((unsigned)ret + n > INT_MAX) { ret = END_OF_FILE; goto error; @@ -1055,11 +1062,15 @@ reswitch: switch (ch) { if (dtoaresult == NULL) goto oomem; - if (prec < 0) - prec = dtoaend - dtoaresult; + if (prec < 0) { + _DIAGASSERT(__type_fit(int, + dtoaend - dtoaresult)); + prec = (int)(dtoaend - dtoaresult); + } if (expt == INT_MAX) ox[1] = '\0'; - ndig = dtoaend - dtoaresult; + _DIAGASSERT(__type_fit(int, dtoaend - dtoaresult)); + ndig = (int)(dtoaend - dtoaresult); if (convbuf != NULL) free(convbuf); #ifndef NARROW @@ -1107,7 +1118,8 @@ fp_begin: } if (dtoaresult == NULL) goto oomem; - ndig = dtoaend - dtoaresult; + _DIAGASSERT(__type_fit(int, dtoaend - dtoaresult)); + ndig = (int)(dtoaend - dtoaresult); if (convbuf != NULL) free(convbuf); #ifndef NARROW @@ -1232,7 +1244,8 @@ fp_common: /* space for thousands' grouping */ nseps = nrepeats = 0; lead = expt; - while (*grouping != CHAR_MAX) { + while ((unsigned char)*grouping + != (unsigned char)CHAR_MAX) { if (lead <= *grouping) break; lead -= *grouping; @@ -1328,13 +1341,18 @@ fp_common: CHAR_T *p = MEMCHR(result, 0, (size_t)prec); if (p != NULL) { - size = p - result; + _DIAGASSERT(__type_fit(int, + p - result)); + size = (int)(p - result); if (size > prec) size = prec; } else size = prec; - } else - size = STRLEN(result); + } else { + size_t rlen = STRLEN(result); + _DIAGASSERT(__type_fit(int, rlen)); + size = (int)rlen; + } sign = '\0'; break; case 'U': @@ -1399,7 +1417,8 @@ number: if ((dprec = prec) >= 0) flags & GROUPING, thousands_sep, grouping); } - size = buf + BUF - result; + _DIAGASSERT(__type_fit(int, buf + BUF - result)); + size = (int)(buf + BUF - result); if (size > BUF) /* should never happen */ abort(); break; @@ -1535,7 +1554,7 @@ error: ret = END_OF_FILE; if ((argtable != NULL) && (argtable != statargtable)) free (argtable); - return (ret); + return ret; /* NOTREACHED */ oomem: errno = ENOMEM; @@ -1554,20 +1573,27 @@ __find_arguments(const CHAR_T *fmt0, va_list ap, union arg **argtable) { CHAR_T *fmt; /* format string */ int ch; /* character from fmt */ - int n, n2; /* handy integer (short term usage) */ + size_t n, n2; /* handy index (short term usage) */ CHAR_T *cp; /* handy char pointer (short term usage) */ int flags; /* flags as above */ enum typeid *typetable; /* table of types */ enum typeid stattypetable [STATIC_ARG_TBL_SIZE]; - int tablesize; /* current size of type table */ - int tablemax; /* largest used index in table */ - int nextarg; /* 1-based argument index */ + size_t tablesize; /* current size of type table */ + size_t tablemax; /* largest used index in table */ + size_t nextarg; /* 1-based argument index */ + size_t nitems; /* number of items we picked from the stack */ /* * Add an argument type to the table, expanding if necessary. + * Check for overflow. */ #define ADDTYPE(type) \ do { \ + if (nextarg > SIZE_MAX / sizeof(**argtable)) { \ + if (typetable != stattypetable) \ + free(typetable); \ + return -1; \ + } \ if (nextarg >= tablesize) \ if (__grow_type_table(nextarg, &typetable, \ &tablesize) == -1) \ @@ -1575,6 +1601,7 @@ __find_arguments(const CHAR_T *fmt0, va_list ap, union arg **argtable) if (nextarg > tablemax) \ tablemax = nextarg; \ typetable[nextarg++] = type; \ + nitems++; \ } while (/*CONSTCOND*/0) #define ADDSARG() \ @@ -1619,7 +1646,7 @@ __find_arguments(const CHAR_T *fmt0, va_list ap, union arg **argtable) cp++; \ } \ if (*cp == '$') { \ - int hold = nextarg; \ + size_t hold = nextarg; \ nextarg = n2; \ ADDTYPE(T_INT); \ nextarg = hold; \ @@ -1628,12 +1655,12 @@ __find_arguments(const CHAR_T *fmt0, va_list ap, union arg **argtable) ADDTYPE(T_INT); \ } fmt = (CHAR_T *)__UNCONST(fmt0); + memset(stattypetable, 0, sizeof(stattypetable)); typetable = stattypetable; tablesize = STATIC_ARG_TBL_SIZE; tablemax = 0; nextarg = 1; - for (n = 0; n < STATIC_ARG_TBL_SIZE; n++) - typetable[n] = T_UNUSED; + nitems = 1; /* * Scan the format for conversions (`%' character). @@ -1794,14 +1821,31 @@ reswitch: switch (ch) { } } done: + /* + * nitems contains the number of arguments we picked from the stack. + * If tablemax is larger, this means that some positional argument, + * tried to pick an argument the number of arguments possibly supplied. + * Since positional arguments are typically used to swap the order of + * the printf arguments and not to pick random arguments from strange + * positions in the stack, we assume that if the positional argument + * is trying to pick beyond the end of arguments, then this is wrong. + * Alternatively we could find a way to figure out when va_arg() runs + * out, but how to do that? + */ + if (nitems < tablemax) { + if (typetable != stattypetable) + free(typetable); + return -1; + } /* * Build the argument table. */ if (tablemax >= STATIC_ARG_TBL_SIZE) { - *argtable = (union arg *) - malloc (sizeof (union arg) * (tablemax + 1)); - if (*argtable == NULL) + *argtable = malloc(sizeof(**argtable) * (tablemax + 1)); + if (*argtable == NULL) { + free(typetable); return -1; + } } (*argtable) [0].intarg = 0; @@ -1892,7 +1936,7 @@ done: } } - if ((typetable != NULL) && (typetable != stattypetable)) + if (typetable != stattypetable) free (typetable); return 0; } @@ -1901,28 +1945,27 @@ done: * Increase the size of the type table. */ static int -__grow_type_table (int nextarg, enum typeid **typetable, int *tablesize) +__grow_type_table (size_t nextarg, enum typeid **typetable, size_t *tablesize) { enum typeid *const oldtable = *typetable; - const int oldsize = *tablesize; + const size_t oldsize = *tablesize; enum typeid *newtable; - int n, newsize = oldsize * 2; + size_t newsize = oldsize * 2; if (newsize < nextarg + 1) newsize = nextarg + 1; if (oldsize == STATIC_ARG_TBL_SIZE) { - if ((newtable = malloc(newsize * sizeof(enum typeid))) == NULL) + if ((newtable = malloc(newsize * sizeof(*newtable))) == NULL) return -1; - memcpy(newtable, oldtable, oldsize * sizeof(enum typeid)); + memcpy(newtable, oldtable, oldsize * sizeof(*newtable)); } else { - newtable = realloc(oldtable, newsize * sizeof(enum typeid)); + newtable = realloc(oldtable, newsize * sizeof(*newtable)); if (newtable == NULL) { free(oldtable); return -1; } } - for (n = oldsize; n < newsize; n++) - newtable[n] = T_UNUSED; + memset(&newtable[oldsize], 0, (newsize - oldsize) * sizeof(*newtable)); *typetable = newtable; *tablesize = newsize; @@ -2014,6 +2057,7 @@ exponent(CHAR_T *p0, int expo, int fmtch) *p++ = '0'; *p++ = to_char(expo); } - return (p - p0); + _DIAGASSERT(__type_fit(int, p - p0)); + return (int)(p - p0); } #endif /* !NO_FLOATING_POINT */ diff --git a/lib/libc/stdio/vfwscanf.c b/lib/libc/stdio/vfwscanf.c index cda05ebf2..d620cddff 100644 --- a/lib/libc/stdio/vfwscanf.c +++ b/lib/libc/stdio/vfwscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfwscanf.c,v 1.6 2009/02/21 17:20:01 christos Exp $ */ +/* $NetBSD: vfwscanf.c,v 1.8 2012/03/15 18:22:30 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -42,13 +42,14 @@ static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95"; __FBSDID("$FreeBSD: src/lib/libc/stdio/vfwscanf.c,v 1.12 2004/05/02 20:13:29 obrien Exp $"); #else -__RCSID("$NetBSD: vfwscanf.c,v 1.6 2009/02/21 17:20:01 christos Exp $"); +__RCSID("$NetBSD: vfwscanf.c,v 1.8 2012/03/15 18:22:30 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include #include +#include #include #include #include @@ -120,7 +121,7 @@ vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap) _SET_ORIENTATION(fp, 1); ret = __vfwscanf_unlocked(fp, fmt, ap); FUNLOCKFILE(fp); - return (ret); + return ret; } #define SCANF_SKIP_SPACE() \ @@ -147,7 +148,7 @@ __vfwscanf_unlocked(FILE * __restrict fp, const wchar_t * __restrict fmt, va_lis wchar_t *p0; /* saves original value of p when necessary */ int nassigned; /* number of fields assigned */ int nconversions; /* number of conversions */ - int nread; /* number of characters consumed from fp */ + size_t nread; /* number of characters consumed from fp */ int base; /* base argument to conversion function */ wchar_t buf[BUF]; /* buffer for numeric conversions */ const wchar_t *ccls; /* character class start */ @@ -174,7 +175,7 @@ __vfwscanf_unlocked(FILE * __restrict fp, const wchar_t * __restrict fmt, va_lis for (;;) { c = *fmt++; if (c == 0) - return (nassigned); + return nassigned; if (iswspace(c)) { while ((c = __fgetwc_unlock(fp)) != WEOF && iswspace(c)) @@ -327,9 +328,9 @@ literal: if (flags & SUPPRESS) /* ??? */ continue; if (flags & SHORTSHORT) - *va_arg(ap, char *) = nread; + *va_arg(ap, char *) = (char)nread; else if (flags & SHORT) - *va_arg(ap, short *) = nread; + *va_arg(ap, short *) = (short)nread; else if (flags & LONG) *va_arg(ap, long *) = nread; else if (flags & LONGLONG) @@ -341,7 +342,7 @@ literal: else if (flags & PTRDIFFT) *va_arg(ap, ptrdiff_t *) = nread; else - *va_arg(ap, int *) = nread; + *va_arg(ap, int *) = (int)nread; continue; default: @@ -351,7 +352,7 @@ literal: * Disgusting backwards compatibility hack. XXX */ case '\0': /* compat */ - return (EOF); + return EOF; } /* @@ -450,7 +451,8 @@ literal: *p++ = (wchar_t)wi; if (wi != WEOF) ungetwc(wi, fp); - n = p - p0; + _DIAGASSERT(__type_fit(int, p - p0)); + n = (int)(p - p0); if (n == 0) goto match_failure; *p = 0; @@ -699,7 +701,8 @@ literal: *va_arg(ap, int *) = (int)res; nassigned++; } - nread += p - buf; + _DIAGASSERT(__type_fit(int, p - buf)); + nread += (int)(p - buf); nconversions++; break; @@ -736,9 +739,9 @@ literal: } } input_failure: - return (nconversions != 0 ? nassigned : EOF); + return nconversions != 0 ? nassigned : EOF; match_failure: - return (nassigned); + return nassigned; } #ifndef NO_FLOATING_POINT @@ -891,6 +894,7 @@ parsedone: while (commit < --p) ungetwc(*p, fp); *++commit = '\0'; - return (commit - buf); + _DIAGASSERT(__type_fit(int, commit - buf)); + return (int)(commit - buf); } #endif diff --git a/lib/libc/stdio/vprintf.c b/lib/libc/stdio/vprintf.c index 711884035..c48946584 100644 --- a/lib/libc/stdio/vprintf.c +++ b/lib/libc/stdio/vprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vprintf.c,v 1.10 2003/08/07 16:43:34 agc Exp $ */ +/* $NetBSD: vprintf.c,v 1.12 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,21 +37,20 @@ #if 0 static char sccsid[] = "@(#)vprintf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vprintf.c,v 1.10 2003/08/07 16:43:34 agc Exp $"); +__RCSID("$NetBSD: vprintf.c,v 1.12 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include #include +#include #include int -vprintf(fmt, ap) - char const *fmt; - _BSD_VA_LIST_ ap; +vprintf(const char *fmt, va_list ap) { _DIAGASSERT(fmt != NULL); - return (vfprintf(stdout, fmt, ap)); + return vfprintf(stdout, fmt, ap); } diff --git a/lib/libc/stdio/vscanf.c b/lib/libc/stdio/vscanf.c index 6959b5e2c..1e4b66dd5 100644 --- a/lib/libc/stdio/vscanf.c +++ b/lib/libc/stdio/vscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vscanf.c,v 1.12 2003/08/07 16:43:35 agc Exp $ */ +/* $NetBSD: vscanf.c,v 1.14 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)vscanf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vscanf.c,v 1.12 2003/08/07 16:43:35 agc Exp $"); +__RCSID("$NetBSD: vscanf.c,v 1.14 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,12 +49,10 @@ __RCSID("$NetBSD: vscanf.c,v 1.12 2003/08/07 16:43:35 agc Exp $"); #include "local.h" int -vscanf(fmt, ap) - const char *fmt; - _BSD_VA_LIST_ ap; +vscanf(const char *fmt, va_list ap) { _DIAGASSERT(fmt != NULL); - return (__svfscanf(stdin, fmt, ap)); + return __svfscanf(stdin, fmt, ap); } diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index e9678470e..c9911d9c3 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vsnprintf.c,v 1.22 2007/10/26 19:48:14 christos Exp $ */ +/* $NetBSD: vsnprintf.c,v 1.25 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vsnprintf.c,v 1.22 2007/10/26 19:48:14 christos Exp $"); +__RCSID("$NetBSD: vsnprintf.c,v 1.25 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -59,11 +59,7 @@ __weak_alias(vsnprintf,_vsnprintf) #endif int -vsnprintf(str, n, fmt, ap) - char *str; - size_t n; - const char *fmt; - _BSD_VA_LIST_ ap; +vsnprintf(char *str, size_t n, const char *fmt, va_list ap) { int ret; FILE f; @@ -75,7 +71,7 @@ vsnprintf(str, n, fmt, ap) if ((int)n < 0) { errno = EINVAL; - return (-1); + return -1; } _FILEEXT_SETUP(&f, &fext); @@ -86,9 +82,10 @@ vsnprintf(str, n, fmt, ap) f._bf._size = f._w = 0; } else { f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = n - 1; + _DIAGASSERT(__type_fit(int, n - 1)); + f._bf._size = f._w = (int)(n - 1); } ret = __vfprintf_unlocked(&f, fmt, ap); *f._p = 0; - return (ret); + return ret; } diff --git a/lib/libc/stdio/vsnprintf_ss.c b/lib/libc/stdio/vsnprintf_ss.c index 6ca525974..da81f134d 100644 --- a/lib/libc/stdio/vsnprintf_ss.c +++ b/lib/libc/stdio/vsnprintf_ss.c @@ -1,4 +1,4 @@ -/* $NetBSD: vsnprintf_ss.c,v 1.9 2009/12/17 15:19:48 christos Exp $ */ +/* $NetBSD: vsnprintf_ss.c,v 1.12 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vsnprintf_ss.c,v 1.9 2009/12/17 15:19:48 christos Exp $"); +__RCSID("$NetBSD: vsnprintf_ss.c,v 1.12 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -116,7 +116,7 @@ __weak_alias(vsnprintf_ss,_vsnprintf_ss) } while (/*CONSTCOND*/0) int -vsnprintf_ss(char *sbuf, size_t slen, const char *fmt0, _BSD_VA_LIST_ ap) +vsnprintf_ss(char *sbuf, size_t slen, const char *fmt0, va_list ap) { const char *fmt; /* format string */ int ch; /* character from fmt */ @@ -136,6 +136,7 @@ vsnprintf_ss(char *sbuf, size_t slen, const char *fmt0, _BSD_VA_LIST_ ap) const char *xdigs; /* digits for [xX] conversion */ char bf[128]; /* space for %c, %[diouxX] */ char *tailp; /* tail pointer for snprintf */ + size_t len; static const char xdigs_lower[16] = "0123456789abcdef"; static const char xdigs_upper[16] = "0123456789ABCDEF"; @@ -145,7 +146,7 @@ vsnprintf_ss(char *sbuf, size_t slen, const char *fmt0, _BSD_VA_LIST_ ap) if ((int)slen < 0) { errno = EINVAL; - return (-1); + return -1; } tailp = sbuf + slen; @@ -330,13 +331,17 @@ reswitch: switch (ch) { char *p = memchr(cp, 0, (size_t)prec); if (p != NULL) { - size = p - cp; + _DIAGASSERT(__type_fit(int, p - cp)); + size = (int)(p - cp); if (size > prec) size = prec; } else size = prec; - } else - size = strlen(cp); + } else { + len = strlen(cp); + _DIAGASSERT(__type_fit(int, len)); + size = (int)len; + } sign = '\0'; break; case 'U': @@ -409,11 +414,14 @@ number: if ((dprec = prec) >= 0) default: /*XXXUNCONST*/ cp = __UNCONST("bug bad base"); - size = strlen(cp); + len = strlen(cp); + _DIAGASSERT(__type_fit(int, len)); + size = (int)len; goto skipsize; } } - size = bf + sizeof(bf) - cp; + _DIAGASSERT(__type_fit(int, bf + sizeof(bf) - cp)); + size = (int)(bf + sizeof(bf) - cp); skipsize: break; default: /* "%?" prints ?, unless ? is NUL */ @@ -493,6 +501,6 @@ done: sbuf[-1] = '\0'; else *sbuf = '\0'; - return (ret); + return ret; /* NOTREACHED */ } diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c index ad0fb5b73..43f5474bf 100644 --- a/lib/libc/stdio/vsprintf.c +++ b/lib/libc/stdio/vsprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vsprintf.c,v 1.15 2007/06/03 17:39:27 christos Exp $ */ +/* $NetBSD: vsprintf.c,v 1.17 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)vsprintf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vsprintf.c,v 1.15 2007/06/03 17:39:27 christos Exp $"); +__RCSID("$NetBSD: vsprintf.c,v 1.17 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,10 +53,7 @@ __RCSID("$NetBSD: vsprintf.c,v 1.15 2007/06/03 17:39:27 christos Exp $"); #endif int -vsprintf(str, fmt, ap) - char *str; - const char *fmt; - _BSD_VA_LIST_ ap; +vsprintf(char *str, const char *fmt, va_list ap) { int ret; FILE f; @@ -72,5 +69,5 @@ vsprintf(str, fmt, ap) f._bf._size = f._w = INT_MAX; ret = __vfprintf_unlocked(&f, fmt, ap); *f._p = 0; - return (ret); + return ret; } diff --git a/lib/libc/stdio/vsscanf.c b/lib/libc/stdio/vsscanf.c index 1069fc793..9fb68a0ac 100644 --- a/lib/libc/stdio/vsscanf.c +++ b/lib/libc/stdio/vsscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vsscanf.c,v 1.15 2010/01/11 20:39:29 joerg Exp $ */ +/* $NetBSD: vsscanf.c,v 1.19 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vsscanf.c,v 1.15 2010/01/11 20:39:29 joerg Exp $"); +__RCSID("$NetBSD: vsscanf.c,v 1.19 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,26 +48,19 @@ __RCSID("$NetBSD: vsscanf.c,v 1.15 2010/01/11 20:39:29 joerg Exp $"); #include "reentrant.h" #include "local.h" -static int eofread __P((void *, char *, int)); - /* ARGSUSED */ -static int -eofread(cookie, buf, len) - void *cookie; - char *buf; - int len; +static ssize_t +eofread(void *cookie, void *buf, size_t len) { - return (0); + return 0; } int -vsscanf(str, fmt, ap) - const char *str; - const char *fmt; - _BSD_VA_LIST_ ap; +vsscanf(const char *str, const char *fmt, va_list ap) { FILE f; struct __sfileext fext; + size_t len; _DIAGASSERT(str != NULL); _DIAGASSERT(fmt != NULL); @@ -75,8 +68,10 @@ vsscanf(str, fmt, ap) _FILEEXT_SETUP(&f, &fext); f._flags = __SRD; f._bf._base = f._p = __UNCONST(str); - f._bf._size = f._r = strlen(str); + len = strlen(str); + _DIAGASSERT(__type_fit(int, len)); + f._bf._size = f._r = (int)len; f._read = eofread; _UB(&f)._base = NULL; - return (__svfscanf_unlocked(&f, fmt, ap)); + return __svfscanf_unlocked(&f, fmt, ap); } diff --git a/lib/libc/stdio/vswprintf.c b/lib/libc/stdio/vswprintf.c index caa89ade7..10f5e1c66 100644 --- a/lib/libc/stdio/vswprintf.c +++ b/lib/libc/stdio/vswprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vswprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */ +/* $NetBSD: vswprintf.c,v 1.3 2012/03/15 18:22:31 christos Exp $ */ /* * Copyright (c) 1997 Todd C. Miller @@ -32,7 +32,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdio/vswprintf.c,v 1.6 2005/02/21 19:41:44 fjoe Exp $"); #else -__RCSID("$NetBSD: vswprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $"); +__RCSID("$NetBSD: vswprintf.c,v 1.3 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -58,7 +58,7 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, if (n == 0) { errno = EINVAL; - return (-1); + return -1; } _FILEEXT_SETUP(&f, &fext); @@ -67,7 +67,7 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, f._bf._base = f._p = (unsigned char *)malloc(128); if (f._bf._base == NULL) { errno = ENOMEM; - return (-1); + return -1; } f._bf._size = f._w = 127; /* Leave room for the NUL */ ret = __vfwprintf_unlocked(&f, fmt, ap); @@ -75,7 +75,7 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, sverrno = errno; free(f._bf._base); errno = sverrno; - return (-1); + return -1; } *f._p = '\0'; mbp = (char *)f._bf._base; @@ -84,17 +84,17 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, * fputwc() did in __vfwprintf(). */ mbs = initial; - nwc = mbsrtowcs(s, (const char **)&mbp, n, &mbs); + nwc = mbsrtowcs(s, (void *)&mbp, n, &mbs); free(f._bf._base); if (nwc == (size_t)-1) { errno = EILSEQ; - return (-1); + return -1; } if (nwc == n) { s[n - 1] = L'\0'; errno = EOVERFLOW; - return (-1); + return -1; } - return (ret); + return ret; } diff --git a/lib/libc/stdio/vswscanf.c b/lib/libc/stdio/vswscanf.c index c01aa23c5..cb295e62c 100644 --- a/lib/libc/stdio/vswscanf.c +++ b/lib/libc/stdio/vswscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vswscanf.c,v 1.6 2010/01/11 20:39:29 joerg Exp $ */ +/* $NetBSD: vswscanf.c,v 1.9 2012/03/27 15:05:42 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -42,10 +42,11 @@ static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD: src/lib/libc/stdio/vswscanf.c,v 1.3 2004/04/07 09:55:05 tjr Exp $"); #else -__RCSID("$NetBSD: vswscanf.c,v 1.6 2010/01/11 20:39:29 joerg Exp $"); +__RCSID("$NetBSD: vswscanf.c,v 1.9 2012/03/27 15:05:42 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ +#include #include #include #include @@ -55,14 +56,12 @@ __RCSID("$NetBSD: vswscanf.c,v 1.6 2010/01/11 20:39:29 joerg Exp $"); #include "reentrant.h" #include "local.h" -static int eofread(void *, char *, int); - -static int +static ssize_t /*ARGSUSED*/ -eofread(void *cookie, char *buf, int len) +eofread(void *cookie, void *buf, size_t len) { - return (0); + return 0; } int @@ -83,22 +82,23 @@ vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict fmt, * __vfwscanf() will convert back to wide characters. */ if ((mbstr = malloc(wcslen(str) * MB_CUR_MAX + 1)) == NULL) - return (EOF); + return EOF; mbs = initial; if ((mlen = wcsrtombs(mbstr, &rstr, SIZE_T_MAX, &mbs)) == (size_t)-1) { free(mbstr); - return (EOF); + return EOF; } _FILEEXT_SETUP(&f, &fext); (void)memset(WCIO_GET(&f), 0, sizeof(struct wchar_io_data)); f._file = -1; f._flags = __SRD; f._bf._base = f._p = (unsigned char *)mbstr; - f._bf._size = f._r = mlen; + _DIAGASSERT(__type_fit(int, mlen)); + f._bf._size = f._r = (int)mlen; f._read = eofread; _UB(&f)._base = NULL; r = __vfwscanf_unlocked(&f, fmt, ap); free(mbstr); - return (r); + return r; } diff --git a/lib/libc/stdio/vwprintf.c b/lib/libc/stdio/vwprintf.c index aa7db0e1c..f59a0ce5c 100644 --- a/lib/libc/stdio/vwprintf.c +++ b/lib/libc/stdio/vwprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vwprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */ +/* $NetBSD: vwprintf.c,v 1.2 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins @@ -31,7 +31,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdio/vwprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $"); #else -__RCSID("$NetBSD: vwprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $"); +__RCSID("$NetBSD: vwprintf.c,v 1.2 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -43,5 +43,5 @@ int vwprintf(const wchar_t * __restrict fmt, va_list ap) { - return (vfwprintf(stdout, fmt, ap)); + return vfwprintf(stdout, fmt, ap); } diff --git a/lib/libc/stdio/vwscanf.c b/lib/libc/stdio/vwscanf.c index e908cbf44..26f01f0c4 100644 --- a/lib/libc/stdio/vwscanf.c +++ b/lib/libc/stdio/vwscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: vwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */ +/* $NetBSD: vwscanf.c,v 1.2 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins @@ -31,7 +31,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdio/vwscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $"); #else -__RCSID("$NetBSD: vwscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $"); +__RCSID("$NetBSD: vwscanf.c,v 1.2 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -43,5 +43,5 @@ int vwscanf(const wchar_t * __restrict fmt, va_list ap) { - return (vfwscanf(stdin, fmt, ap)); + return vfwscanf(stdin, fmt, ap); } diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c index 35f9aee36..52456a25d 100644 --- a/lib/libc/stdio/wbuf.c +++ b/lib/libc/stdio/wbuf.c @@ -1,4 +1,4 @@ -/* $NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp $ */ +/* $NetBSD: wbuf.c,v 1.15 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp $"); +__RCSID("$NetBSD: wbuf.c,v 1.15 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,9 +53,7 @@ __RCSID("$NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp $"); * or if c=='\n' and the file is line buffered. */ int -__swbuf(c, fp) - int c; - FILE *fp; +__swbuf(int c, FILE *fp) { int n; @@ -73,7 +71,7 @@ __swbuf(c, fp) fp->_w = fp->_lbfsize; if (cantwrite(fp)) { errno = EBADF; - return (EOF); + return EOF; } c = (unsigned char)c; @@ -86,16 +84,17 @@ __swbuf(c, fp) * guarantees that putc() will always call wbuf() by setting _w * to 0, so we need not do anything else. */ - n = fp->_p - fp->_bf._base; + _DIAGASSERT(__type_fit(int, fp->_p - fp->_bf._base)); + n = (int)(fp->_p - fp->_bf._base); if (n >= fp->_bf._size) { if (fflush(fp)) - return (EOF); + return EOF; n = 0; } fp->_w--; *fp->_p++ = c; if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) if (fflush(fp)) - return (EOF); - return (c); + return EOF; + return c; } diff --git a/lib/libc/stdio/wprintf.c b/lib/libc/stdio/wprintf.c index 6f6cd7b87..4add15517 100644 --- a/lib/libc/stdio/wprintf.c +++ b/lib/libc/stdio/wprintf.c @@ -1,4 +1,4 @@ -/* $NetBSD: wprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */ +/* $NetBSD: wprintf.c,v 1.2 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins @@ -31,7 +31,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdio/wprintf.c,v 1.1 2002/09/21 13:00:30 tjr Exp $"); #else -__RCSID("$NetBSD: wprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $"); +__RCSID("$NetBSD: wprintf.c,v 1.2 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,5 +49,5 @@ wprintf(const wchar_t * __restrict fmt, ...) ret = vfwprintf(stdout, fmt, ap); va_end(ap); - return (ret); + return ret; } diff --git a/lib/libc/stdio/wscanf.c b/lib/libc/stdio/wscanf.c index 7bf3f333e..ad9f71c43 100644 --- a/lib/libc/stdio/wscanf.c +++ b/lib/libc/stdio/wscanf.c @@ -1,4 +1,4 @@ -/* $NetBSD: wscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */ +/* $NetBSD: wscanf.c,v 1.2 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 2002 Tim J. Robbins @@ -31,7 +31,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdio/wscanf.c,v 1.1 2002/09/23 12:40:06 tjr Exp $"); #else -__RCSID("$NetBSD: wscanf.c,v 1.1 2005/05/14 23:51:02 christos Exp $"); +__RCSID("$NetBSD: wscanf.c,v 1.2 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,5 +49,5 @@ wscanf(const wchar_t * __restrict fmt, ...) r = vfwscanf(stdin, fmt, ap); va_end(ap); - return (r); + return r; } diff --git a/lib/libc/stdio/wsetup.c b/lib/libc/stdio/wsetup.c index f30e4233d..da1f3713d 100644 --- a/lib/libc/stdio/wsetup.c +++ b/lib/libc/stdio/wsetup.c @@ -1,4 +1,4 @@ -/* $NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp $ */ +/* $NetBSD: wsetup.c,v 1.12 2012/03/15 18:22:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp $"); +__RCSID("$NetBSD: wsetup.c,v 1.12 2012/03/15 18:22:31 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,8 +54,7 @@ __RCSID("$NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp $"); * _wsetup returns 0 if OK to write, nonzero otherwise. */ int -__swsetup(fp) - FILE *fp; +__swsetup(FILE *fp) { _DIAGASSERT(fp != NULL); @@ -69,7 +68,7 @@ __swsetup(fp) */ if ((fp->_flags & __SWR) == 0) { if ((fp->_flags & __SRW) == 0) - return (EOF); + return EOF; if (fp->_flags & __SRD) { /* clobber any ungetc data */ if (HASUB(fp)) @@ -96,5 +95,5 @@ __swsetup(fp) fp->_lbfsize = -fp->_bf._size; } else fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size; - return (0); + return 0; } diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc index b2e884cc1..0b3b4833e 100644 --- a/lib/libc/stdlib/Makefile.inc +++ b/lib/libc/stdlib/Makefile.inc @@ -1,11 +1,10 @@ -# $NetBSD: Makefile.inc,v 1.75 2010/11/14 18:11:43 tron Exp $ +# $NetBSD: Makefile.inc,v 1.78 2011/09/14 23:33:51 christos Exp $ # from: @(#)Makefile.inc 8.3 (Berkeley) 2/4/95 # stdlib sources .PATH: ${ARCHDIR}/stdlib ${.CURDIR}/stdlib -.if defined(__MINIX) -# pty.c not compiled +#LSC: MINIX: pty.c not compiled SRCS+= _env.c _rand48.c \ a64l.c abort.c atexit.c atof.c atoi.c atol.c atoll.c \ bsearch.c drand48.c exit.c \ @@ -18,20 +17,6 @@ SRCS+= _env.c _rand48.c \ strtoimax.c strtol.c strtoll.c strtoq.c strtoul.c strtoull.c \ strtoumax.c strtouq.c system.c tdelete.c tfind.c tsearch.c twalk.c \ unsetenv.c strfmon.c -.else -SRCS+= _env.c _rand48.c \ - a64l.c abort.c atexit.c atof.c atoi.c atol.c atoll.c \ - bsearch.c drand48.c exit.c \ - getenv.c getopt.c getopt_long.c getsubopt.c \ - hcreate.c heapsort.c imaxdiv.c insque.c jrand48.c l64a.c lldiv.c \ - lcong48.c lrand48.c lsearch.c merge.c mi_vector_hash.c mrand48.c \ - nrand48.c putenv.c qabs.c qdiv.c qsort.c posix_openpt.c pty.c \ - radixsort.c rand.c rand_r.c random.c remque.c \ - seed48.c setenv.c srand48.c strsuftoll.c \ - strtoimax.c strtol.c strtoll.c strtoq.c strtoul.c strtoull.c \ - strtoumax.c strtouq.c system.c tdelete.c tfind.c tsearch.c twalk.c \ - unsetenv.c strfmon.c -.endif # These are often replaced by MD .S versions SRCS+= abs.c labs.c llabs.c imaxabs.c @@ -42,7 +27,7 @@ SRCS+= erand48_ieee754.c .if (${USE_JEMALLOC} != "no") SRCS+= jemalloc.c -.elif (${USE_MINIXMALLOC} != "no") +.elif (${USE_MINIXMALLOC:Uno} != "no") .include "../minix/Makefile.inc" .else SRCS+= malloc.c @@ -61,9 +46,9 @@ MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \ exit.3 \ getenv.3 getopt.3 getopt_long.3 getsubopt.3 grantpt.3 \ hcreate.3 \ - imaxabs.3 imaxdiv.3 insque.3 \ + insque.3 \ jemalloc.3 \ - labs.3 ldiv.3 llabs.3 lldiv.3 lsearch.3 \ + lsearch.3 \ malloc.3 memory.3 mi_vector_hash.3 \ posix_memalign.3 posix_openpt.3 ptsname.3 \ qabs.3 qdiv.3 qsort.3 \ @@ -74,9 +59,16 @@ MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \ MLINKS+=a64l.3 l64a.3 MLINKS+=a64l.3 l64a_r.3 +MLINKS+=abs.3 labs.3 \ + abs.3 llabs.3 \ + abs.3 imaxabs.3 +MLINKS+=div.3 ldiv.3 \ + div.3 lldiv.3 \ + div.3 imaxdiv.3 MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3 MLINKS+=getenv.3 getenv_r.3 MLINKS+=hcreate.3 hdestroy.3 hcreate.3 hsearch.3 +MLINKS+=hcreate.3 hcreate_r.3 hcreate.3 hdestroy_r.3 hcreate.3 hsearch_r.3 MLINKS+=insque.3 remque.3 MLINKS+=lsearch.3 lfind.3 MLINKS+=malloc.3 calloc.3 malloc.3 realloc.3 malloc.3 free.3 diff --git a/lib/libc/stdlib/_env.c b/lib/libc/stdlib/_env.c index a84c36a87..9883bf2ad 100644 --- a/lib/libc/stdlib/_env.c +++ b/lib/libc/stdlib/_env.c @@ -1,4 +1,4 @@ -/* $NetBSD: _env.c,v 1.5 2010/11/17 13:25:53 tron Exp $ */ +/* $NetBSD: _env.c,v 1.6 2011/10/06 20:31:41 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -29,11 +29,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -static int inited = 0; - #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _env.c,v 1.5 2010/11/17 13:25:53 tron Exp $"); +__RCSID("$NetBSD: _env.c,v 1.6 2011/10/06 20:31:41 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -97,6 +95,8 @@ __warn_references(__findenv, /* Our initialization function. */ void __libc_env_init(void); +char **environ; + /*ARGSUSED*/ static signed int env_tree_compare_nodes(void *ctx, const void *node_a, const void *node_b) @@ -159,7 +159,6 @@ __freeenvvar(char *envvar) env_node_t *node; _DIAGASSERT(envvar != NULL); - assert(inited); node = rb_tree_find_node(&env_tree, envvar); if (node != NULL) { rb_tree_remove_node(&env_tree, node); @@ -176,7 +175,6 @@ __allocenvvar(size_t length) { env_node_t *node; - assert(inited); node = malloc(sizeof(*node) + length); if (node != NULL) { node->length = length; @@ -198,8 +196,6 @@ __canoverwriteenvvar(char *envvar, size_t length) { env_node_t *node; - assert(inited); - _DIAGASSERT(envvar != NULL); node = rb_tree_find_node(&env_tree, envvar); @@ -214,7 +210,6 @@ __scrubenv(void) size_t num_entries; env_node_t *node, *next; - assert(inited); while (++marker == 0); /* Mark all nodes which are currently used. */ @@ -408,7 +403,5 @@ __unlockenv(void) void __libc_env_init(void) { - assert(!inited); rb_tree_init(&env_tree, &env_tree_ops); - inited = 1; } diff --git a/lib/libc/stdlib/a64l.c b/lib/libc/stdlib/a64l.c index 2e616b98c..d7d004212 100644 --- a/lib/libc/stdlib/a64l.c +++ b/lib/libc/stdlib/a64l.c @@ -5,7 +5,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: a64l.c,v 1.9 2003/07/26 19:24:53 salo Exp $"); +__RCSID("$NetBSD: a64l.c,v 1.10 2012/06/08 11:15:26 abs Exp $"); #endif #include "namespace.h" @@ -18,8 +18,7 @@ __weak_alias(a64l,_a64l) #endif long -a64l(s) - const char *s; +a64l(const char *s) { long value, digit, shift; int i; diff --git a/lib/libc/stdlib/abort.3 b/lib/libc/stdlib/abort.3 index 1fca505cd..c75aeb6ce 100644 --- a/lib/libc/stdlib/abort.3 +++ b/lib/libc/stdlib/abort.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: abort.3,v 1.12 2003/08/07 16:43:37 agc Exp $ +.\" $NetBSD: abort.3,v 1.13 2012/06/12 21:16:17 jdf Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -59,7 +59,7 @@ function results in temporary files being removed. Any open streams are flushed and closed. .Sh RETURN VALUES The -.Nm abort +.Fn abort function never returns. .Sh SEE ALSO diff --git a/lib/libc/stdlib/abort.c b/lib/libc/stdlib/abort.c index 577bec167..7f46b9ea0 100644 --- a/lib/libc/stdlib/abort.c +++ b/lib/libc/stdlib/abort.c @@ -1,4 +1,4 @@ -/* $NetBSD: abort.c,v 1.13 2009/01/30 23:21:03 ad Exp $ */ +/* $NetBSD: abort.c,v 1.15 2012/06/08 11:15:26 abs Exp $ */ /* * Copyright (c) 1985, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)abort.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: abort.c,v 1.13 2009/01/30 23:21:03 ad Exp $"); +__RCSID("$NetBSD: abort.c,v 1.15 2012/06/08 11:15:26 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -43,11 +43,11 @@ __RCSID("$NetBSD: abort.c,v 1.13 2009/01/30 23:21:03 ad Exp $"); #include #include -extern void (*__cleanup) __P((void)); +extern void (*__cleanup)(void); static int aborting = 0; void -abort() +abort(void) { sigset_t mask; diff --git a/lib/libc/stdlib/abs.3 b/lib/libc/stdlib/abs.3 index d9a8238f9..e3cb9e124 100644 --- a/lib/libc/stdlib/abs.3 +++ b/lib/libc/stdlib/abs.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: abs.3,v 1.13 2008/08/04 21:29:27 matt Exp $ +.\" $NetBSD: abs.3,v 1.14 2011/04/13 06:56:50 jruoho Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,44 +33,41 @@ .\" .\" from: @(#)abs.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 4, 1993 +.Dd April 13, 2011 .Dt ABS 3 .Os .Sh NAME -.Nm abs -.Nd integer absolute value function +.Nm abs , +.Nm labs , +.Nm llabs , +.Nm imaxabs +.Nd functions for integer absolute value .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In stdlib.h .Ft int -.Fn abs "int j" +.Fn abs "int x" +.Ft long int +.Fn labs "long int x" +.Ft long long int +.Fn llabs "long long int x" +.In inttypes.h +.Ft intmax_t +.Fn imaxabs "intmax_t x" .Sh DESCRIPTION -The -.Fn abs -function -computes -the absolute value of the integer -.Ar j . -.Sh RETURN VALUES -The -.Fn abs -function -returns -the absolute value. +These functions return the absolute value of the integer +.Fa x . +The listed functions differ only with respect +to the type of the return value and +.Fa x . .Sh SEE ALSO .Xr cabs 3 , .Xr fabs 3 , .Xr floor 3 , -.Xr hypot 3 , -.Xr imaxabs 3 , -.Xr labs 3 , -.Xr llabs 3 , .Xr math 3 .Sh STANDARDS -The -.Fn abs -function conforms to -.St -ansiC . +The described functions conform to +.St -isoC-99 . .Sh BUGS The absolute value of the most negative integer remains negative. diff --git a/lib/libc/stdlib/abs.c b/lib/libc/stdlib/abs.c index 52bd8b4c6..2b5333c30 100644 --- a/lib/libc/stdlib/abs.c +++ b/lib/libc/stdlib/abs.c @@ -1,4 +1,4 @@ -/* $NetBSD: abs.c,v 1.7 2003/08/07 16:43:37 agc Exp $ */ +/* $NetBSD: abs.c,v 1.8 2012/06/08 11:15:26 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,15 +34,14 @@ #if 0 static char sccsid[] = "@(#)abs.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: abs.c,v 1.7 2003/08/07 16:43:37 agc Exp $"); +__RCSID("$NetBSD: abs.c,v 1.8 2012/06/08 11:15:26 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include int -abs(j) - int j; +abs(int j) { return(j < 0 ? -j : j); } diff --git a/lib/libc/stdlib/alloca.3 b/lib/libc/stdlib/alloca.3 index e61c9274e..3bc193352 100644 --- a/lib/libc/stdlib/alloca.3 +++ b/lib/libc/stdlib/alloca.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: alloca.3,v 1.13 2010/05/03 06:11:38 jruoho Exp $ +.\" $NetBSD: alloca.3,v 1.14 2011/03/21 04:42:50 jruoho Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)alloca.3 8.1 (Berkeley) 6/4/93 .\" -.Dd May 3, 2010 +.Dd March 21, 2011 .Dt ALLOCA 3 .Os .Sh NAME @@ -89,7 +89,7 @@ Since modifies the stack at runtime, it causes problems to certain security features. See -.Xr security 8 +.Xr security 7 for a discussion. .El .\" .Sh HISTORY diff --git a/lib/libc/stdlib/atof.c b/lib/libc/stdlib/atof.c index 0a89197d0..ae143b6fa 100644 --- a/lib/libc/stdlib/atof.c +++ b/lib/libc/stdlib/atof.c @@ -1,4 +1,4 @@ -/* $NetBSD: atof.c,v 1.12 2003/08/07 16:43:38 agc Exp $ */ +/* $NetBSD: atof.c,v 1.13 2012/06/25 22:32:45 abs Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)atof.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: atof.c,v 1.12 2003/08/07 16:43:38 agc Exp $"); +__RCSID("$NetBSD: atof.c,v 1.13 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -42,8 +42,7 @@ __RCSID("$NetBSD: atof.c,v 1.12 2003/08/07 16:43:38 agc Exp $"); #include double -atof(ascii) - const char *ascii; +atof(const char *ascii) { _DIAGASSERT(ascii != NULL); diff --git a/lib/libc/stdlib/atoi.c b/lib/libc/stdlib/atoi.c index 06c9fee3f..bf70b67ca 100644 --- a/lib/libc/stdlib/atoi.c +++ b/lib/libc/stdlib/atoi.c @@ -1,4 +1,4 @@ -/* $NetBSD: atoi.c,v 1.11 2003/08/07 16:43:38 agc Exp $ */ +/* $NetBSD: atoi.c,v 1.12 2012/06/25 22:32:45 abs Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)atoi.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: atoi.c,v 1.11 2003/08/07 16:43:38 agc Exp $"); +__RCSID("$NetBSD: atoi.c,v 1.12 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -42,8 +42,7 @@ __RCSID("$NetBSD: atoi.c,v 1.11 2003/08/07 16:43:38 agc Exp $"); #include int -atoi(str) - const char *str; +atoi(const char *str) { _DIAGASSERT(str != NULL); diff --git a/lib/libc/stdlib/atol.c b/lib/libc/stdlib/atol.c index 41d3aae8e..92d4b8ee0 100644 --- a/lib/libc/stdlib/atol.c +++ b/lib/libc/stdlib/atol.c @@ -1,4 +1,4 @@ -/* $NetBSD: atol.c,v 1.10 2003/08/07 16:43:38 agc Exp $ */ +/* $NetBSD: atol.c,v 1.11 2012/06/25 22:32:45 abs Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)atol.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: atol.c,v 1.10 2003/08/07 16:43:38 agc Exp $"); +__RCSID("$NetBSD: atol.c,v 1.11 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -42,8 +42,7 @@ __RCSID("$NetBSD: atol.c,v 1.10 2003/08/07 16:43:38 agc Exp $"); #include long -atol(str) - const char *str; +atol(const char *str) { _DIAGASSERT(str != NULL); diff --git a/lib/libc/stdlib/atoll.c b/lib/libc/stdlib/atoll.c index 46f138360..2f2a7528d 100644 --- a/lib/libc/stdlib/atoll.c +++ b/lib/libc/stdlib/atoll.c @@ -1,4 +1,4 @@ -/* $NetBSD: atoll.c,v 1.5 2003/10/27 00:12:42 lukem Exp $ */ +/* $NetBSD: atoll.c,v 1.6 2012/06/25 22:32:45 abs Exp $ */ /* * Copyright (c) 1988, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "from: @(#)atol.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: atoll.c,v 1.5 2003/10/27 00:12:42 lukem Exp $"); +__RCSID("$NetBSD: atoll.c,v 1.6 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -57,8 +57,7 @@ __weak_alias(atoll, _atoll) #if !HAVE_ATOLL /* LONGLONG */ long long int -atoll(str) - const char *str; +atoll(const char *str) { return (strtoll(str, (char **)NULL, 10)); } diff --git a/lib/libc/stdlib/bsearch.c b/lib/libc/stdlib/bsearch.c index a8ab2994e..2b0e0d86f 100644 --- a/lib/libc/stdlib/bsearch.c +++ b/lib/libc/stdlib/bsearch.c @@ -1,4 +1,4 @@ -/* $NetBSD: bsearch.c,v 1.14 2010/11/27 18:33:54 christos Exp $ */ +/* $NetBSD: bsearch.c,v 1.15 2012/03/04 20:01:45 christos Exp $ */ /* * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)bsearch.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: bsearch.c,v 1.14 2010/11/27 18:33:54 christos Exp $"); +__RCSID("$NetBSD: bsearch.c,v 1.15 2012/03/04 20:01:45 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -68,7 +68,7 @@ bsearch(const void *key, const void *base0, size_t nmemb, size_t size, const void *p; _DIAGASSERT(key != NULL); - _DIAGASSERT(base0 != NULL); + _DIAGASSERT(base0 != NULL || nmemb == 0); _DIAGASSERT(compar != NULL); for (lim = nmemb; lim != 0; lim >>= 1) { diff --git a/lib/libc/stdlib/div.3 b/lib/libc/stdlib/div.3 index 062837d42..0e38edec2 100644 --- a/lib/libc/stdlib/div.3 +++ b/lib/libc/stdlib/div.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: div.3,v 1.12 2008/08/04 21:29:27 matt Exp $ +.\" $NetBSD: div.3,v 1.14 2011/05/03 09:36:24 wiz Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -31,41 +31,57 @@ .\" .\" from: @(#)div.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 4, 1993 +.Dd April 13, 2011 .Dt DIV 3 .Os .Sh NAME -.Nm div -.Nd return quotient and remainder from division +.Nm div , +.Nm ldiv , +.Nm lldiv , +.Nm imaxdiv +.Nd quotient and remainder from division .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In stdlib.h .Ft div_t .Fn div "int num" "int denom" +.Ft ldiv_t +.Fn ldiv "long int num" "long int denom" +.Ft lldiv_t +.Fn lldiv "long long int num" "long long int denom" +.In inttypes.h +.Ft imaxdiv_t +.Fn imaxdiv "intmax_t num" "intmax_t denom" .Sh DESCRIPTION -The -.Fn div -function -computes the value -.Fa num/denom -and returns the quotient and remainder in a structure named -.Fa div_t -that contains two -.Em int -members named -.Fa quot +These functions compute the value of +.Fa num / denom +and return the quotient and remainder in a specific divison structure. +The functions differ only with respect to the type of the return value and +the parameters. +.Pp +The returned structure always contains two members named +.Vt quot and -.Fa rem . +.Vt rem , +denoting the quotient and the remainder. +The type of these correspond with the underlying type of the function. +.Sh EXAMPLES +The following example demonstrate the basic usage of the functions. +.Bd -literal -offset indent +div_t d; + +int a = 4321; +int b = 1234; + +d = div(a, b); + +(void)printf("%d %d\en", d.quot, d.rem); +.Ed .Sh SEE ALSO -.Xr imaxdiv 3 , -.Xr ldiv 3 , -.Xr lldiv 3 , +.Xr fast_divide32 3 , .Xr math 3 , .Xr qdiv 3 .Sh STANDARDS -The -.Fn div -function -conforms to -.St -ansiC . +All described functions conform to +.St -isoC-99 . diff --git a/lib/libc/stdlib/div.c b/lib/libc/stdlib/div.c index 262f59461..f3bd32f26 100644 --- a/lib/libc/stdlib/div.c +++ b/lib/libc/stdlib/div.c @@ -1,4 +1,4 @@ -/* $NetBSD: div.c,v 1.7 2003/08/07 16:43:39 agc Exp $ */ +/* $NetBSD: div.c,v 1.8 2012/06/25 22:32:45 abs Exp $ */ /* * Copyright (c) 1990, 1993 @@ -37,15 +37,14 @@ #if 0 static char sccsid[] = "@(#)div.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: div.c,v 1.7 2003/08/07 16:43:39 agc Exp $"); +__RCSID("$NetBSD: div.c,v 1.8 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include /* div_t */ div_t -div(num, denom) - int num, denom; +div(int num, int denom) { div_t r; diff --git a/lib/libc/stdlib/exit.3 b/lib/libc/stdlib/exit.3 index 27ee4d931..7668f62a3 100644 --- a/lib/libc/stdlib/exit.3 +++ b/lib/libc/stdlib/exit.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: exit.3,v 1.14 2003/08/07 16:43:39 agc Exp $ +.\" $NetBSD: exit.3,v 1.15 2012/01/02 15:55:29 dholland Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" from: @(#)exit.3 8.1 (Berkeley) 6/4/93 .\" -.Dd August 11, 2002 +.Dd January 2, 2012 .Dt EXIT 3 .Os .Sh NAME @@ -78,11 +78,19 @@ Following this, .Fn exit calls .Xr _exit 2 . -Note that typically -.Xr _exit 2 -only passes the lower 8 bits of +.Sh RESTRICTIONS +Standard C guarantees only that the values zero, +.Dv EXIT_SUCCESS , +and +.Dv EXIT_FAILURE +produce meaningful results. +POSIX extends this to guarantee that the +least significant 8 bits of .Fa status -on to the parent, thus negative values have less meaning. +are preserved and returned to the parent via +.Xr wait 2 . +Values outside the supported range 0-255 are bitwise-truncated; therefore, +negative values should not be used. .Sh RETURN VALUES The .Fn exit diff --git a/lib/libc/stdlib/exit.c b/lib/libc/stdlib/exit.c index c5bcd6725..67e6adf1b 100644 --- a/lib/libc/stdlib/exit.c +++ b/lib/libc/stdlib/exit.c @@ -1,4 +1,4 @@ -/* $NetBSD: exit.c,v 1.13 2010/09/09 10:19:31 skrll Exp $ */ +/* $NetBSD: exit.c,v 1.15 2011/05/18 19:36:36 dsl Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)exit.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: exit.c,v 1.13 2010/09/09 10:19:31 skrll Exp $"); +__RCSID("$NetBSD: exit.c,v 1.15 2011/05/18 19:36:36 dsl Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -45,14 +45,7 @@ __RCSID("$NetBSD: exit.c,v 1.13 2010/09/09 10:19:31 skrll Exp $"); #include "atexit.h" #endif -#ifdef _LIBC -extern void __libc_init(void); -#ifndef __lint -static void (*force_ref)(void) __used = __libc_init; -#endif -#endif - -void (*__cleanup) __P((void)); +void (*__cleanup)(void); /* * Exit, flushing stdio buffers if necessary. diff --git a/lib/libc/stdlib/getsubopt.c b/lib/libc/stdlib/getsubopt.c index 3590a671b..d8481b1cd 100644 --- a/lib/libc/stdlib/getsubopt.c +++ b/lib/libc/stdlib/getsubopt.c @@ -1,4 +1,4 @@ -/* $NetBSD: getsubopt.c,v 1.8 2004/05/09 19:34:11 kleink Exp $ */ +/* $NetBSD: getsubopt.c,v 1.9 2012/06/25 22:32:45 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getsubopt.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getsubopt.c,v 1.8 2004/05/09 19:34:11 kleink Exp $"); +__RCSID("$NetBSD: getsubopt.c,v 1.9 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -58,9 +58,7 @@ __weak_alias(getsubopt,_getsubopt) char *suboptarg; int -getsubopt(optionp, tokens, valuep) - char **optionp, **valuep; - char * const *tokens; +getsubopt(char **optionp, char * const *tokens, char **valuep) { int cnt; char *p; diff --git a/lib/libc/stdlib/hcreate.3 b/lib/libc/stdlib/hcreate.3 index 0bc844fee..a108c7eb6 100644 --- a/lib/libc/stdlib/hcreate.3 +++ b/lib/libc/stdlib/hcreate.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: hcreate.3,v 1.8 2010/05/01 06:18:03 jruoho Exp $ +.\" $NetBSD: hcreate.3,v 1.10 2011/09/15 09:14:54 wiz Exp $ .\" .\" Copyright (c) 1999 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,13 +27,16 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd May 1, 2010 +.Dd September 14, 2011 .Dt HCREATE 3 .Os .Sh NAME .Nm hcreate , +.Nm hcreate_r , .Nm hdestroy , -.Nm hsearch +.Nm hdestroy_r , +.Nm hsearch , +.Nm hsearch_r .Nd manage hash search table .Sh LIBRARY .Lb libc @@ -41,16 +44,25 @@ .In search.h .Ft int .Fn hcreate "size_t nel" +.Ft int +.Fn hcreate_r "size_t nel" "struct hsearch_data *table" .Ft void .Fn hdestroy "void" +.Ft void +.Fn hdestroy_r "struct hsearch_data *table" .Ft ENTRY * .Fn hsearch "ENTRY item" "ACTION action" +.Ft int +.Fn hsearch_r "ENTRY item" "ACTION action" "ENTRY ** itemp" "struct hsearch_data *table" .Sh DESCRIPTION The .Fn hcreate , -.Fn hdestroy +.Fn hcreate_r , +.Fn hdestroy , +.Fn hdestroy_r +.Fn hsearch , and -.Fn hsearch +.Fn hsearch_r functions manage hash search tables. .Pp The @@ -152,18 +164,46 @@ Typically the comparison .Fa key is allocated by using .Xr strdup 3 . +.Pp +The +.Fn hcreate_r , +.Fn hdestroy_r , +and +.Fn hsearch_r +functions are re-entrant versions of the above functions that can +operate on a table supplied by the user. +The +.Fn hsearch_r +function returns +.Dv 0 +if the action is +.Dv ENTER +and the element cannot be created, +.Dv 1 +otherwise. +If the element exists or can be created, it will be placed in +.Fa itemp , +otherwise +.Fa itemp +will be set to +.Dv NULL . .Sh RETURN VALUES If successful, the .Fn hcreate -function returns a non-zero value. -Otherwise, a value of 0 is returned and +and +.Fn hcreate_r +functions return a non-zero value. +Otherwise, a value of +.Dv 0 +is returned and .Va errno is set to indicate the error. .Pp The .Fn hdestroy -functions -returns no value. +and +.Fn hdestroy_r +functions return no value. .Pp If successful, the .Fn hsearch @@ -182,16 +222,46 @@ If the action is .Dv ENTER and an entry already existed in the table matching the given key, the existing entry is returned and is not replaced. +.Pp +The +.Fn hsearch_r +function returns +.Dv 1 +unless the table is full, when it returns +.Dv 0 . +If +.Fn hsearch +returns +.Dv 0 +or the element is not found, +.Va errno +is set to indicate the error. .Sh ERRORS The -.Fn hcreate -and +.Fn hcreate , +.Fn hcreate_r , .Fn hsearch +and +.Fn hsearch_r functions will fail if: .Bl -tag -width Er .It Bq Er ENOMEM Insufficient memory is available. .El +.Pp +The +.Fn hsearch +and +.Fn hsearch_r +functions will also fail if the action is +.Dv SEARCH +and the element is not found: +.Bl -tag -width Er +.It Bq Er ESRCH +The +.Fa item +given is not found. +.El .Sh SEE ALSO .Xr bsearch 3 , .Xr lsearch 3 , @@ -213,11 +283,21 @@ and .Fn hsearch functions first appeared in .At V . +The +.Fn hcreate_r , +.Fn hdestroy_r +and +.Fn hsearch_r +functions are +.Tn GNU +extensions. .Sh CAVEATS At least the following limitations can be mentioned: .Bl -bullet .It -The interface permits the use of only one hash table at a time. +The original, +.Pf non- Tn GNU +interface permits the use of only one hash table at a time. .It Individual hash table entries can be added, but not deleted. .It diff --git a/lib/libc/stdlib/hcreate.c b/lib/libc/stdlib/hcreate.c index 8f06fdf5d..73afb5d26 100644 --- a/lib/libc/stdlib/hcreate.c +++ b/lib/libc/stdlib/hcreate.c @@ -1,4 +1,4 @@ -/* $NetBSD: hcreate.c,v 1.6 2008/07/21 12:05:43 lukem Exp $ */ +/* $NetBSD: hcreate.c,v 1.8 2011/09/17 16:54:39 christos Exp $ */ /* * Copyright (c) 2001 Christopher G. Demetriou @@ -12,12 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the - * NetBSD Project. See http://www.NetBSD.org/ for - * information about NetBSD. - * 4. The name of the author may not be used to endorse or promote products + * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR @@ -48,7 +43,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: hcreate.c,v 1.6 2008/07/21 12:05:43 lukem Exp $"); +__RCSID("$NetBSD: hcreate.c,v 1.8 2011/09/17 16:54:39 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #if !defined(lint) @@ -88,21 +83,28 @@ SLIST_HEAD(internal_head, internal_entry); /* Default hash function, from db/hash/hash_func.c */ extern u_int32_t (*__default_hash)(const void *, size_t); -static struct internal_head *htable; -static size_t htablesize; +static struct hsearch_data htable; int hcreate(size_t nel) { - size_t idx; - unsigned int p2; + _DIAGASSERT(htable.table == NULL); /* Make sure this isn't called when a table already exists. */ - _DIAGASSERT(htable == NULL); - if (htable != NULL) { + if (htable.table != NULL) { errno = EINVAL; return 0; } + return hcreate_r(nel, &htable); +} + +int +hcreate_r(size_t nel, struct hsearch_data *head) +{ + struct internal_head *table; + size_t idx; + unsigned int p2; + void *p; /* If nel is too small, make it min sized. */ if (nel < MIN_BUCKETS) @@ -121,76 +123,108 @@ hcreate(size_t nel) } /* Allocate the table. */ - htablesize = nel; - htable = malloc(htablesize * sizeof htable[0]); - if (htable == NULL) { + head->size = nel; + head->filled = 0; + p = malloc(nel * sizeof table[0]); + if (p == NULL) { errno = ENOMEM; return 0; } + head->table = p; + table = p; /* Initialize it. */ - for (idx = 0; idx < htablesize; idx++) - SLIST_INIT(&htable[idx]); + for (idx = 0; idx < nel; idx++) + SLIST_INIT(&table[idx]); return 1; } void hdestroy(void) +{ + _DIAGASSERT(htable.table != NULL); + hdestroy_r(&htable); +} + +void +hdestroy_r(struct hsearch_data *head) { struct internal_entry *ie; size_t idx; + void *p; + struct internal_head *table; - _DIAGASSERT(htable != NULL); - if (htable == NULL) + if (head == NULL) return; - for (idx = 0; idx < htablesize; idx++) { - while (!SLIST_EMPTY(&htable[idx])) { - ie = SLIST_FIRST(&htable[idx]); - SLIST_REMOVE_HEAD(&htable[idx], link); + p = head->table; + head->table = NULL; + table = p; + + for (idx = 0; idx < head->size; idx++) { + while (!SLIST_EMPTY(&table[idx])) { + ie = SLIST_FIRST(&table[idx]); + SLIST_REMOVE_HEAD(&table[idx], link); free(ie->ent.key); free(ie); } } - free(htable); - htable = NULL; + free(table); } ENTRY * hsearch(ENTRY item, ACTION action) { - struct internal_head *head; + ENTRY *ep; + _DIAGASSERT(htable.table != NULL); + (void)hsearch_r(item, action, &ep, &htable); + return ep; +} + +int +hsearch_r(ENTRY item, ACTION action, ENTRY **itemp, struct hsearch_data *head) +{ + struct internal_head *table, *chain; struct internal_entry *ie; uint32_t hashval; size_t len; + void *p; - _DIAGASSERT(htable != NULL); _DIAGASSERT(item.key != NULL); _DIAGASSERT(action == ENTER || action == FIND); + p = head->table; + table = p; + len = strlen(item.key); hashval = (*__default_hash)(item.key, len); - head = &htable[hashval & (htablesize - 1)]; - ie = SLIST_FIRST(head); + chain = &table[hashval & (head->size - 1)]; + ie = SLIST_FIRST(chain); while (ie != NULL) { if (strcmp(ie->ent.key, item.key) == 0) break; ie = SLIST_NEXT(ie, link); } - if (ie != NULL) - return &ie->ent; - else if (action == FIND) - return NULL; + if (ie != NULL) { + *itemp = &ie->ent; + return 1; + } else if (action == FIND) { + *itemp = NULL; + errno = ESRCH; + return 1; + } ie = malloc(sizeof *ie); if (ie == NULL) - return NULL; + return 0; ie->ent.key = item.key; ie->ent.data = item.data; - SLIST_INSERT_HEAD(head, ie, link); - return &ie->ent; + SLIST_INSERT_HEAD(chain, ie, link); + *itemp = &ie->ent; + head->filled++; + return 1; } diff --git a/lib/libc/stdlib/imaxabs.3 b/lib/libc/stdlib/imaxabs.3 deleted file mode 100644 index 0f4302689..000000000 --- a/lib/libc/stdlib/imaxabs.3 +++ /dev/null @@ -1,70 +0,0 @@ -.\" $NetBSD: imaxabs.3,v 1.2 2010/03/21 13:39:51 jruoho Exp $ -.\" -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" the American National Standards Committee X3, on Information -.\" Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)labs.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd March 6, 2000 -.Dt IMAXABS 3 -.Os -.Sh NAME -.Nm imaxabs -.Nd return the absolute value of a imaxint_t -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In inttypes.h -.Ft intmax_t -.Fn imaxabs "intmax_t i" -.Sh DESCRIPTION -The -.Fn imaxabs -function -returns the absolute value of the -.Vt imaxint_t -integer -.Ar j . -.Sh SEE ALSO -.Xr abs 3 , -.Xr cabs 3 , -.Xr floor 3 , -.Xr labs 3 , -.Xr llabs 3 , -.Xr math 3 -.Sh STANDARDS -The -.Fn imaxabs -function -conforms to -.St -isoC-99 . -.Sh BUGS -The absolute value of the most negative integer remains negative. diff --git a/lib/libc/stdlib/imaxdiv.3 b/lib/libc/stdlib/imaxdiv.3 deleted file mode 100644 index ebfd7f1ea..000000000 --- a/lib/libc/stdlib/imaxdiv.3 +++ /dev/null @@ -1,75 +0,0 @@ -.\" $NetBSD: imaxdiv.3,v 1.1 2008/08/04 21:29:27 matt Exp $ -.\" -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)ldiv.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd March 6, 2000 -.Dt IMAXDIV 3 -.Os -.Sh NAME -.Nm imaxdiv -.Nd return quotient and remainder from division -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In inttypes.h -.Ft imaxdiv_t -.Fn imaxdiv "intmax_t num" "intmax_t denom" -.Sh DESCRIPTION -The -.Fn imaxdiv -function -divides -.Ar num -by -.Ar denom -and returns the resulting quotient and remainder in a structure named -.Ar imaxdiv_t -that contains two -.Em imaxint_t -members named -.Ar quot -and -.Ar rem . -.Sh SEE ALSO -.Xr div 3 , -.Xr ldiv 3 , -.Xr lldiv 3 , -.Xr math 3 , -.Xr qdiv 3 -.Sh STANDARDS -The -.Fn imaxdiv -function -conforms to -.St -isoC-99 . diff --git a/lib/libc/stdlib/insque.c b/lib/libc/stdlib/insque.c index 20633e8bb..09020ae2a 100644 --- a/lib/libc/stdlib/insque.c +++ b/lib/libc/stdlib/insque.c @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: insque.c,v 1.2 2005/07/06 17:17:15 drochner Exp $"); +__RCSID("$NetBSD: insque.c,v 1.3 2012/06/25 22:32:45 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -40,9 +40,7 @@ struct qelem { }; void -insque(entry, pred) - void *entry; - void *pred; +insque(void *entry, void *pred) { struct qelem *e = (struct qelem *) entry; struct qelem *p = (struct qelem *) pred; diff --git a/lib/libc/stdlib/jemalloc.3 b/lib/libc/stdlib/jemalloc.3 index 524448a42..540e3a11e 100644 --- a/lib/libc/stdlib/jemalloc.3 +++ b/lib/libc/stdlib/jemalloc.3 @@ -34,9 +34,9 @@ .\" @(#)malloc.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.73 2007/06/15 22:32:33 jasone Exp $ .\" -.Dd May 14, 2010 -.Os +.Dd June 21, 2011 .Dt JEMALLOC 3 +.Os .Sh NAME .Nm jemalloc .Nd the default system allocator @@ -172,8 +172,11 @@ does not zero memory that was previously allocated. This is intended for debugging and will impact performance negatively. .El .Pp +Extra care should be taken when enabling +any of the options in production environments. The -.Em J +.Em A , +.Em J , and .Em Z options are intended for testing and debugging. @@ -291,6 +294,28 @@ the performance impact for storing such information would be prohibitive. There are a number of allocator implementations available on the Internet which focus on detecting and pinpointing problems by trading performance for extra sanity checks and detailed diagnostics. +.Sh ENVIRONMENT +The following environment variables affect the execution of the allocation +functions: +.Bl -tag -width ".Ev MALLOC_OPTIONS" +.It Ev MALLOC_OPTIONS +If the environment variable +.Ev MALLOC_OPTIONS +is set, the characters it contains will be interpreted as flags to the +allocation functions. +.El +.Sh EXAMPLES +To dump core whenever a problem occurs: +.Pp +.Bd -literal -offset indent +ln -s 'A' /etc/malloc.conf +.Ed +.Pp +To specify in the source that a program does no return value checking +on calls to these functions: +.Bd -literal -offset indent +_malloc_options = "X"; +.Ed .Sh DIAGNOSTICS If any of the memory allocation/deallocation functions detect an error or warning condition, a message will be printed to file descriptor @@ -316,28 +341,6 @@ this function is likely to result in a crash or deadlock. .Pp All messages are prefixed by .Dq Ao Ar progname Ac Ns Li \&: Pq malloc . -.Sh ENVIRONMENT -The following environment variables affect the execution of the allocation -functions: -.Bl -tag -width ".Ev MALLOC_OPTIONS" -.It Ev MALLOC_OPTIONS -If the environment variable -.Ev MALLOC_OPTIONS -is set, the characters it contains will be interpreted as flags to the -allocation functions. -.El -.Sh EXAMPLES -To dump core whenever a problem occurs: -.Pp -.Bd -literal -offset indent -ln -s 'A' /etc/malloc.conf -.Ed -.Pp -To specify in the source that a program does no return value checking -on calls to these functions: -.Bd -literal -offset indent -_malloc_options = "X"; -.Ed .Sh SEE ALSO .Xr emalloc 3 , .Xr malloc 3 , diff --git a/lib/libc/stdlib/jemalloc.c b/lib/libc/stdlib/jemalloc.c index d01327a74..b3c6f7385 100644 --- a/lib/libc/stdlib/jemalloc.c +++ b/lib/libc/stdlib/jemalloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: jemalloc.c,v 1.21 2010/03/04 22:48:31 enami Exp $ */ +/* $NetBSD: jemalloc.c,v 1.28 2012/03/21 14:32:22 christos Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . @@ -118,7 +118,7 @@ #include /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ -__RCSID("$NetBSD: jemalloc.c,v 1.21 2010/03/04 22:48:31 enami Exp $"); +__RCSID("$NetBSD: jemalloc.c,v 1.28 2012/03/21 14:32:22 christos Exp $"); #ifdef __FreeBSD__ #include "libc_private.h" @@ -319,20 +319,25 @@ __strerror_r(int e, char *s, size_t l) #define SMALL_MAX_DEFAULT (1 << SMALL_MAX_2POW_DEFAULT) /* - * Maximum desired run header overhead. Runs are sized as small as possible - * such that this setting is still honored, without violating other constraints. - * The goal is to make runs as small as possible without exceeding a per run - * external fragmentation threshold. + * RUN_MAX_OVRHD indicates maximum desired run header overhead. Runs are sized + * as small as possible such that this setting is still honored, without + * violating other constraints. The goal is to make runs as small as possible + * without exceeding a per run external fragmentation threshold. * - * Note that it is possible to set this low enough that it cannot be honored - * for some/all object sizes, since there is one bit of header overhead per - * object (plus a constant). In such cases, this constraint is relaxed. + * We use binary fixed point math for overhead computations, where the binary + * point is implicitly RUN_BFP bits to the left. * - * RUN_MAX_OVRHD_RELAX specifies the maximum number of bits per region of - * overhead for which RUN_MAX_OVRHD is relaxed. + * Note that it is possible to set RUN_MAX_OVRHD low enough that it cannot be + * honored for some/all object sizes, since there is one bit of header overhead + * per object (plus a constant). This constraint is relaxed (ignored) for runs + * that are so small that the per-region overhead is greater than: + * + * (RUN_MAX_OVRHD / (reg_size << (3+RUN_BFP)) */ -#define RUN_MAX_OVRHD 0.015 -#define RUN_MAX_OVRHD_RELAX 1.5 +#define RUN_BFP 12 +/* \/ Implicit binary fixed point. */ +#define RUN_MAX_OVRHD 0x0000003dU +#define RUN_MAX_OVRHD_RELAX 0x00001800U /* Put a cap on small object run size. This overrides RUN_MAX_OVRHD. */ #define RUN_MAX_SMALL_2POW 15 @@ -811,7 +816,7 @@ static void wrtmessage(const char *p1, const char *p2, const char *p3, #ifdef MALLOC_STATS static void malloc_printf(const char *format, ...); #endif -static char *umax2s(uintmax_t x, char *s); +static char *size_t2s(size_t x, char *s); static bool base_pages_alloc(size_t minsize); static void *base_alloc(size_t size); static chunk_node_t *base_chunk_node_alloc(void); @@ -973,19 +978,19 @@ malloc_printf(const char *format, ...) /* * We don't want to depend on vsnprintf() for production builds, since that can - * cause unnecessary bloat for static binaries. umax2s() provides minimal + * cause unnecessary bloat for static binaries. size_t2s() provides minimal * integer printing functionality, so that malloc_printf() use can be limited to * MALLOC_STATS code. */ #define UMAX2S_BUFSIZE 21 static char * -umax2s(uintmax_t x, char *s) +size_t2s(size_t x, char *s) { unsigned i; /* Make sure UMAX2S_BUFSIZE is large enough. */ /* LINTED */ - assert(sizeof(uintmax_t) <= 8); + assert(sizeof(size_t) <= 8); i = UMAX2S_BUFSIZE - 1; s[i] = '\0'; @@ -2143,7 +2148,6 @@ arena_bin_run_size_calc(arena_bin_t *bin, size_t min_run_size) size_t try_run_size, good_run_size; unsigned good_nregs, good_mask_nelms, good_reg0_offset; unsigned try_nregs, try_mask_nelms, try_reg0_offset; - float max_ovrhd = RUN_MAX_OVRHD; assert(min_run_size >= pagesize); assert(min_run_size <= arena_maxclass); @@ -2161,7 +2165,7 @@ arena_bin_run_size_calc(arena_bin_t *bin, size_t min_run_size) */ try_run_size = min_run_size; try_nregs = (unsigned)(((try_run_size - sizeof(arena_run_t)) / - bin->reg_size) + 1); /* Counter-act the first line of the loop. */ + bin->reg_size) + 1); /* Counter-act try_nregs-- in loop. */ do { try_nregs--; try_mask_nelms = (try_nregs >> (SIZEOF_INT_2POW + 3)) + @@ -2195,9 +2199,8 @@ arena_bin_run_size_calc(arena_bin_t *bin, size_t min_run_size) } while (sizeof(arena_run_t) + (sizeof(unsigned) * (try_mask_nelms - 1)) > try_reg0_offset); } while (try_run_size <= arena_maxclass && try_run_size <= RUN_MAX_SMALL - && max_ovrhd > RUN_MAX_OVRHD_RELAX / ((float)(bin->reg_size << 3)) - && ((float)(try_reg0_offset)) / ((float)(try_run_size)) > - max_ovrhd); + && RUN_MAX_OVRHD * (bin->reg_size << 3) > RUN_MAX_OVRHD_RELAX + && (try_reg0_offset << RUN_BFP) > RUN_MAX_OVRHD * try_run_size); assert(sizeof(arena_run_t) + (sizeof(unsigned) * (good_mask_nelms - 1)) <= good_reg0_offset); @@ -3215,16 +3218,17 @@ malloc_print_stats(void) opt_xmalloc ? "X" : "x", opt_zero ? "Z\n" : "z\n"); - _malloc_message("CPUs: ", umax2s(ncpus, s), "\n", ""); - _malloc_message("Max arenas: ", umax2s(narenas, s), "\n", ""); - _malloc_message("Pointer size: ", umax2s(sizeof(void *), s), + _malloc_message("CPUs: ", size_t2s(ncpus, s), "\n", ""); + _malloc_message("Max arenas: ", size_t2s(narenas, s), "\n", ""); + _malloc_message("Pointer size: ", size_t2s(sizeof(void *), s), "\n", ""); - _malloc_message("Quantum size: ", umax2s(quantum, s), "\n", ""); - _malloc_message("Max small size: ", umax2s(small_max, s), "\n", + _malloc_message("Quantum size: ", size_t2s(quantum, s), "\n", ""); + _malloc_message("Max small size: ", size_t2s(small_max, s), "\n", ""); - _malloc_message("Chunk size: ", umax2s(chunksize, s), "", ""); - _malloc_message(" (2^", umax2s(opt_chunk_2pow, s), ")\n", ""); + _malloc_message("Chunk size: ", size_t2s(chunksize, s), "", ""); + _malloc_message(" (2^", size_t2s((size_t)opt_chunk_2pow, s), + ")\n", ""); #ifdef MALLOC_STATS { @@ -3322,6 +3326,7 @@ malloc_init_hard(void) ssize_t linklen; char buf[PATH_MAX + 1]; const char *opts = ""; + int serrno; malloc_mutex_lock(&init_lock); if (malloc_initialized) { @@ -3333,6 +3338,7 @@ malloc_init_hard(void) return (false); } + serrno = errno; /* Get number of CPUs. */ { int mib[2]; @@ -3512,6 +3518,7 @@ malloc_init_hard(void) } } } + errno = serrno; /* Take care to call atexit() only once. */ if (opt_print_stats) { diff --git a/lib/libc/stdlib/l64a.c b/lib/libc/stdlib/l64a.c index 68f625126..bc78ab1ea 100644 --- a/lib/libc/stdlib/l64a.c +++ b/lib/libc/stdlib/l64a.c @@ -1,4 +1,4 @@ -/* $NetBSD: l64a.c,v 1.13 2003/07/26 19:24:54 salo Exp $ */ +/* $NetBSD: l64a.c,v 1.14 2012/03/13 21:13:48 christos Exp $ */ /* * Written by J.T. Conklin . @@ -7,7 +7,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: l64a.c,v 1.13 2003/07/26 19:24:54 salo Exp $"); +__RCSID("$NetBSD: l64a.c,v 1.14 2012/03/13 21:13:48 christos Exp $"); #endif #include "namespace.h" @@ -22,20 +22,16 @@ __weak_alias(l64a_r,_l64a_r) #endif char * -l64a (value) - long value; +l64a(long value) { static char buf[8]; - (void)l64a_r(value, buf, sizeof (buf)); + (void)l64a_r(value, buf, (int)sizeof (buf)); return buf; } int -l64a_r (value, buffer, buflen) - long value; - char *buffer; - int buflen; +l64a_r(long value, char *buffer, int buflen) { char *s = buffer; int digit; diff --git a/lib/libc/stdlib/labs.3 b/lib/libc/stdlib/labs.3 deleted file mode 100644 index 3d07816a2..000000000 --- a/lib/libc/stdlib/labs.3 +++ /dev/null @@ -1,68 +0,0 @@ -.\" $NetBSD: labs.3,v 1.11 2008/08/04 21:29:27 matt Exp $ -.\" -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" the American National Standards Committee X3, on Information -.\" Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)labs.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt LABS 3 -.Os -.Sh NAME -.Nm labs -.Nd return the absolute value of a long integer -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In stdlib.h -.Ft long int -.Fn labs "long int j" -.Sh DESCRIPTION -The -.Fn labs -function -returns the absolute value of the long integer -.Ar j . -.Sh SEE ALSO -.Xr abs 3 , -.Xr cabs 3 , -.Xr floor 3 , -.Xr imaxabs 3 , -.Xr llabs 3 , -.Xr math 3 -.Sh STANDARDS -The -.Fn labs -function -conforms to -.St -ansiC . -.Sh BUGS -The absolute value of the most negative integer remains negative. diff --git a/lib/libc/stdlib/labs.c b/lib/libc/stdlib/labs.c index a69622820..72e2cce97 100644 --- a/lib/libc/stdlib/labs.c +++ b/lib/libc/stdlib/labs.c @@ -1,4 +1,4 @@ -/* $NetBSD: labs.c,v 1.7 2003/08/07 16:43:41 agc Exp $ */ +/* $NetBSD: labs.c,v 1.8 2012/06/25 22:32:45 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,15 +34,14 @@ #if 0 static char sccsid[] = "@(#)labs.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: labs.c,v 1.7 2003/08/07 16:43:41 agc Exp $"); +__RCSID("$NetBSD: labs.c,v 1.8 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include long -labs(j) - long j; +labs(long j) { return(j < 0 ? -j : j); } diff --git a/lib/libc/stdlib/ldiv.3 b/lib/libc/stdlib/ldiv.3 deleted file mode 100644 index 95852ce71..000000000 --- a/lib/libc/stdlib/ldiv.3 +++ /dev/null @@ -1,73 +0,0 @@ -.\" $NetBSD: ldiv.3,v 1.13 2008/08/04 21:29:27 matt Exp $ -.\" -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)ldiv.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt LDIV 3 -.Os -.Sh NAME -.Nm ldiv -.Nd return quotient and remainder from division -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In stdlib.h -.Ft ldiv_t -.Fn ldiv "long int num" "long int denom" -.Sh DESCRIPTION -The -.Fn ldiv -function -computes the value -.Ar num/denom -and returns the quotient and remainder in a structure named -.Ar ldiv_t -that contains two -.Em long integer -members named -.Ar quot -and -.Ar rem . -.Sh SEE ALSO -.Xr div 3 , -.Xr imaxdiv 3 , -.Xr lldiv 3 , -.Xr math 3 , -.Xr qdiv 3 -.Sh STANDARDS -The -.Fn ldiv -function -conforms to -.St -ansiC . diff --git a/lib/libc/stdlib/ldiv.c b/lib/libc/stdlib/ldiv.c index 4c7254756..507c831bf 100644 --- a/lib/libc/stdlib/ldiv.c +++ b/lib/libc/stdlib/ldiv.c @@ -1,4 +1,4 @@ -/* $NetBSD: ldiv.c,v 1.7 2003/08/07 16:43:41 agc Exp $ */ +/* $NetBSD: ldiv.c,v 1.8 2012/06/25 22:32:45 abs Exp $ */ /* * Copyright (c) 1990, 1993 @@ -37,15 +37,14 @@ #if 0 static char sccsid[] = "@(#)ldiv.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: ldiv.c,v 1.7 2003/08/07 16:43:41 agc Exp $"); +__RCSID("$NetBSD: ldiv.c,v 1.8 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include /* ldiv_t */ ldiv_t -ldiv(num, denom) - long num, denom; +ldiv(long num, long denom) { ldiv_t r; diff --git a/lib/libc/stdlib/llabs.3 b/lib/libc/stdlib/llabs.3 deleted file mode 100644 index f36619b92..000000000 --- a/lib/libc/stdlib/llabs.3 +++ /dev/null @@ -1,68 +0,0 @@ -.\" $NetBSD: llabs.3,v 1.7 2008/08/04 21:29:27 matt Exp $ -.\" -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" the American National Standards Committee X3, on Information -.\" Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)labs.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd March 6, 2000 -.Dt LLABS 3 -.Os -.Sh NAME -.Nm llabs -.Nd return the absolute value of a long long integer -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In stdlib.h -.Ft long long int -.Fn llabs "long long int j" -.Sh DESCRIPTION -The -.Fn llabs -function -returns the absolute value of the long long integer -.Ar j . -.Sh SEE ALSO -.Xr abs 3 , -.Xr cabs 3 , -.Xr floor 3 , -.Xr imaxabs 3 , -.Xr labs 3 , -.Xr math 3 -.Sh STANDARDS -The -.Fn llabs -function -conforms to -.St -isoC-99 . -.Sh BUGS -The absolute value of the most negative integer remains negative. diff --git a/lib/libc/stdlib/llabs.c b/lib/libc/stdlib/llabs.c index 32b5ae230..089281471 100644 --- a/lib/libc/stdlib/llabs.c +++ b/lib/libc/stdlib/llabs.c @@ -1,4 +1,4 @@ -/* $NetBSD: llabs.c,v 1.3 2003/08/07 16:43:41 agc Exp $ */ +/* $NetBSD: llabs.c,v 1.4 2012/06/25 22:32:45 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "from: @(#)labs.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: llabs.c,v 1.3 2003/08/07 16:43:41 agc Exp $"); +__RCSID("$NetBSD: llabs.c,v 1.4 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -47,8 +47,7 @@ __weak_alias(llabs, _llabs) /* LONGLONG */ long long int -llabs(j) - long long int j; +llabs(long long int j) { return (j < 0 ? -j : j); } diff --git a/lib/libc/stdlib/lldiv.3 b/lib/libc/stdlib/lldiv.3 deleted file mode 100644 index 4d2ccb0fd..000000000 --- a/lib/libc/stdlib/lldiv.3 +++ /dev/null @@ -1,73 +0,0 @@ -.\" $NetBSD: lldiv.3,v 1.7 2008/08/04 21:29:27 matt Exp $ -.\" -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)ldiv.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd March 6, 2000 -.Dt LLDIV 3 -.Os -.Sh NAME -.Nm lldiv -.Nd return quotient and remainder from division -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In stdlib.h -.Ft lldiv_t -.Fn lldiv "long long int num" "long long int denom" -.Sh DESCRIPTION -The -.Fn lldiv -function -computes the value -.Ar num/denom -and returns the quotient and remainder in a structure named -.Ar lldiv_t -that contains two -.Em long long integer -members named -.Ar quot -and -.Ar rem . -.Sh SEE ALSO -.Xr div 3 , -.Xr imaxdiv 3 , -.Xr ldiv 3 , -.Xr math 3 , -.Xr qdiv 3 -.Sh STANDARDS -The -.Fn lldiv -function -conforms to -.St -isoC-99 . diff --git a/lib/libc/stdlib/lldiv.c b/lib/libc/stdlib/lldiv.c index 589db7e12..47104b378 100644 --- a/lib/libc/stdlib/lldiv.c +++ b/lib/libc/stdlib/lldiv.c @@ -1,4 +1,4 @@ -/* $NetBSD: lldiv.c,v 1.3 2003/08/07 16:43:41 agc Exp $ */ +/* $NetBSD: lldiv.c,v 1.4 2012/06/25 22:32:45 abs Exp $ */ /* * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "from: @(#)ldiv.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: lldiv.c,v 1.3 2003/08/07 16:43:41 agc Exp $"); +__RCSID("$NetBSD: lldiv.c,v 1.4 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,8 +50,7 @@ __weak_alias(lldiv, _lldiv) /* LONGLONG */ lldiv_t -lldiv(num, denom) - long long int num, denom; +lldiv(long long int num, long long int denom) { lldiv_t r; diff --git a/lib/libc/stdlib/lsearch.c b/lib/libc/stdlib/lsearch.c index 81d4e398b..e17130b63 100644 --- a/lib/libc/stdlib/lsearch.c +++ b/lib/libc/stdlib/lsearch.c @@ -35,7 +35,7 @@ #if 0 static char sccsid[] = "@(#)lsearch.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: lsearch.c,v 1.4 2005/07/16 17:32:09 christos Exp $"); +__RCSID("$NetBSD: lsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -46,16 +46,13 @@ __RCSID("$NetBSD: lsearch.c,v 1.4 2005/07/16 17:32:09 christos Exp $"); #include #include -typedef int (*cmp_fn_t) __P((const void *, const void *)); -static void *linear_base __P((const void *, void *, size_t *, size_t, - cmp_fn_t, int)); +typedef int (*cmp_fn_t)(const void *, const void *); +static void *linear_base(const void *, void *, size_t *, size_t, + cmp_fn_t, int); void * -lsearch(key, base, nelp, width, compar) - const void *key; - void *base; - size_t *nelp, width; - cmp_fn_t compar; +lsearch(const void *key, void *base, size_t *nelp, size_t width, + cmp_fn_t compar) { _DIAGASSERT(key != NULL); @@ -66,10 +63,8 @@ lsearch(key, base, nelp, width, compar) } void * -lfind(key, base, nelp, width, compar) - const void *key, *base; - size_t *nelp, width; - cmp_fn_t compar; +lfind(const void *key, const void *base, size_t *nelp, size_t width, + cmp_fn_t compar) { _DIAGASSERT(key != NULL); @@ -80,12 +75,8 @@ lfind(key, base, nelp, width, compar) } static void * -linear_base(key, base, nelp, width, compar, add_flag) - const void *key; - void *base; - size_t *nelp, width; - cmp_fn_t compar; - int add_flag; +linear_base(const void *key, void *base, size_t *nelp, size_t width, + cmp_fn_t compar, int add_flag) { char *element, *end; diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index a07a57216..71052948f 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: malloc.c,v 1.52 2008/02/03 22:56:53 christos Exp $ */ +/* $NetBSD: malloc.c,v 1.54 2011/05/18 01:59:39 christos Exp $ */ /* * ---------------------------------------------------------------------------- @@ -76,10 +76,8 @@ # define malloc_pageshift 12U # define malloc_minsize 16U # endif -#ifndef __minix # define HAS_UTRACE # define UTRACE_LABEL -#endif /* __minix */ #include void utrace(struct ut *, int); @@ -102,8 +100,6 @@ void utrace(struct ut *, int); #undef minix_mmap #undef minix_munmap -#include - #include #if defined(__NetBSD__) # define malloc_minsize 16U @@ -112,7 +108,7 @@ void utrace(struct ut *, int); #include #include "extern.h" #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: malloc.c,v 1.52 2008/02/03 22:56:53 christos Exp $"); +__RCSID("$NetBSD: malloc.c,v 1.54 2011/05/18 01:59:39 christos Exp $"); #endif /* LIBC_SCCS and not lint */ int utrace(const char *, void *, size_t); @@ -469,12 +465,14 @@ extend_pgdir(size_t idx) static void malloc_init(void) { - int save_errno = errno; #ifndef MALLOC_NO_SYSCALLS const char *p; char b[64]; size_t i; ssize_t j; +#endif + int serrno = errno; +#ifndef MALLOC_NO_SYSCALLS /* * Compute page-size related variables. @@ -499,7 +497,7 @@ malloc_init(void) for (i = 0; i < 3; i++) { if (i == 0) { j = readlink("/etc/malloc.conf", b, sizeof b - 1); - if (j <= 0) + if (j == -1) continue; b[j] = '\0'; p = b; @@ -581,7 +579,7 @@ malloc_init(void) */ px = imalloc(sizeof *px); - errno = save_errno; + errno = serrno; } /* @@ -1039,7 +1037,7 @@ free_pages(void *ptr, size_t idx, struct pginfo *info) pf->size > malloc_cache && /* ..and the cache is full, */ pf->end == malloc_brk && /* ..and none behind us, */ malloc_brk == sbrk((intptr_t)0)) { /* ..and it's OK to do... */ - int r; + /* * Keep the cache intact. Notice that the '>' above guarantees that * the pf will always have at least one page afterwards. @@ -1047,8 +1045,7 @@ free_pages(void *ptr, size_t idx, struct pginfo *info) pf->end = (char *)pf->page + malloc_cache; pf->size = malloc_cache; - r = brk(pf->end); - assert(r >= 0); + brk(pf->end); malloc_brk = pf->end; idx = ptr2idx(pf->end); diff --git a/lib/libc/stdlib/memory.3 b/lib/libc/stdlib/memory.3 index 3cef2b8bc..563073060 100644 --- a/lib/libc/stdlib/memory.3 +++ b/lib/libc/stdlib/memory.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: memory.3,v 1.10 2003/08/07 16:43:42 agc Exp $ +.\" $NetBSD: memory.3,v 1.11 2011/09/11 10:05:23 jruoho Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)memory.3 8.1 (Berkeley) 6/4/93 .\" -.Dd June 4, 1993 +.Dd September 11, 2011 .Dt MEMORY 3 .Os .Sh NAME @@ -57,6 +57,8 @@ These functions allocate and free memory for the calling process. They are described in the individual manual pages. +The memory allocators used in the kernel are described in +.Xr memoryallocators 9 . .Sh SEE ALSO .Xr alloca 3 , .Xr calloc 3 , diff --git a/lib/libc/stdlib/merge.c b/lib/libc/stdlib/merge.c index fb425f7ef..22c3292db 100644 --- a/lib/libc/stdlib/merge.c +++ b/lib/libc/stdlib/merge.c @@ -1,4 +1,4 @@ -/* $NetBSD: merge.c,v 1.12 2009/02/12 03:12:36 lukem Exp $ */ +/* $NetBSD: merge.c,v 1.14 2012/03/13 21:13:48 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "from: @(#)merge.c 8.2 (Berkeley) 2/14/94"; #else -__RCSID("$NetBSD: merge.c,v 1.12 2009/02/12 03:12:36 lukem Exp $"); +__RCSID("$NetBSD: merge.c,v 1.14 2012/03/13 21:13:48 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -67,10 +67,10 @@ __RCSID("$NetBSD: merge.c,v 1.12 2009/02/12 03:12:36 lukem Exp $"); __weak_alias(mergesort,_mergesort) #endif -static void setup __P((u_char *, u_char *, size_t, size_t, - int (*)(const void *, const void *))); -static void insertionsort __P((u_char *, size_t, size_t, - int (*)(const void *, const void *))); +static void setup(u_char *, u_char *, size_t, size_t, + int (*)(const void *, const void *)); +static void insertionsort(u_char *, size_t, size_t, + int (*)(const void *, const void *)); #define ISIZE sizeof(int) #define PSIZE sizeof(u_char *) @@ -108,11 +108,8 @@ static void insertionsort __P((u_char *, size_t, size_t, * Arguments are as for qsort. */ int -mergesort(base, nmemb, size, cmp) - void *base; - size_t nmemb; - size_t size; - int (*cmp) __P((const void *, const void *)); +mergesort(void *base, size_t nmemb, size_t size, + int (*cmp)(const void *, const void *)) { size_t i; int sense; @@ -281,13 +278,12 @@ COPY: b = t; /* XXX: shouldn't this function be static? - lukem 990810 */ void -setup(list1, list2, n, size, cmp) - size_t n, size; - int (*cmp) __P((const void *, const void *)); - u_char *list1, *list2; +setup(u_char *list1, u_char *list2, size_t n, size_t size, + int (*cmp)(const void *, const void *)) { - int i, length, size2, tmp, sense; + int length, tmp, sense; u_char *f1, *f2, *s, *l2, *last, *p2; + size_t size2, i; _DIAGASSERT(cmp != NULL); _DIAGASSERT(list1 != NULL); @@ -304,7 +300,7 @@ setup(list1, list2, n, size, cmp) * for simplicity. */ i = 4 + (n & 1); - insertionsort(list1 + (n - i) * size, (size_t)i, size, cmp); + insertionsort(list1 + (n - i) * size, i, size, cmp); last = list1 + size * (n - i); *EVAL(list2 + (last - list1)) = list2 + n * size; @@ -332,12 +328,12 @@ setup(list1, list2, n, size, cmp) if ((cmp(f2-size, f2) > 0) != sense) { p2 = *EVAL(p2) = f2 - list1 + list2; if (sense > 0) - reverse(f1, f2-size); + reverse(f1, f2 - size); f1 = f2; } } if (sense > 0) - reverse (f1, f2-size); + reverse(f1, f2 - size); f1 = f2; if (f2 < last || cmp(f2 - size, f2) > 0) p2 = *EVAL(p2) = f2 - list1 + list2; @@ -359,13 +355,11 @@ setup(list1, list2, n, size, cmp) * last 4 elements. */ static void -insertionsort(a, n, size, cmp) - u_char *a; - size_t n, size; - int (*cmp) __P((const void *, const void *)); +insertionsort(u_char *a, size_t n, size_t size, + int (*cmp)(const void *, const void *)) { u_char *ai, *s, *t, *u, tmp; - int i; + size_t i; _DIAGASSERT(a != NULL); _DIAGASSERT(cmp != NULL); diff --git a/lib/libc/stdlib/mi_vector_hash.c b/lib/libc/stdlib/mi_vector_hash.c index b867ebe85..0cd75f206 100644 --- a/lib/libc/stdlib/mi_vector_hash.c +++ b/lib/libc/stdlib/mi_vector_hash.c @@ -1,4 +1,4 @@ -/* $NetBSD: mi_vector_hash.c,v 1.3 2010/03/19 18:11:30 joerg Exp $ */ +/* $NetBSD: mi_vector_hash.c,v 1.4 2011/10/21 23:45:56 joerg Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. * All rights reserved. @@ -43,11 +43,13 @@ #endif #include -__RCSID("$NetBSD: mi_vector_hash.c,v 1.3 2010/03/19 18:11:30 joerg Exp $"); +__RCSID("$NetBSD: mi_vector_hash.c,v 1.4 2011/10/21 23:45:56 joerg Exp $"); #include "namespace.h" +#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H #include +#endif #include #include diff --git a/lib/libc/stdlib/posix_openpt.3 b/lib/libc/stdlib/posix_openpt.3 index 3d5acb6b6..12d976e82 100644 --- a/lib/libc/stdlib/posix_openpt.3 +++ b/lib/libc/stdlib/posix_openpt.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: posix_openpt.3,v 1.4 2008/04/30 13:10:51 martin Exp $ +.\" $NetBSD: posix_openpt.3,v 1.6 2011/05/05 07:36:44 wiz Exp $ .\" .\" Copyright (c) 2004 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -41,9 +41,11 @@ .Ft int .Fn posix_openpt "int oflag" .Sh DESCRIPTION +The .Fn posix_openpt -Searches for an unused master pseudo-terminal device, opens it, and returns -a file descriptor associated the now used pseudo-terminal device. +function searches for an unused master pseudo-terminal device, +opens it, and returns a file descriptor associated with the now +used pseudo-terminal device. The .Fa oflag argument has the same meaning as in the diff --git a/lib/libc/stdlib/putenv.c b/lib/libc/stdlib/putenv.c index 1f617b4f7..695e4bed6 100644 --- a/lib/libc/stdlib/putenv.c +++ b/lib/libc/stdlib/putenv.c @@ -51,6 +51,9 @@ __RCSID("$NetBSD: putenv.c,v 1.19 2010/11/14 18:11:43 tron Exp $"); #ifdef __weak_alias __weak_alias(putenv,_putenv) +#if defined(__minix) +__weak_alias(__putenv50,_putenv) +#endif /* defined(__minix) */ #endif int diff --git a/lib/libc/stdlib/qabs.c b/lib/libc/stdlib/qabs.c index f19fefe9e..1a2af10f8 100644 --- a/lib/libc/stdlib/qabs.c +++ b/lib/libc/stdlib/qabs.c @@ -1,4 +1,4 @@ -/* $NetBSD: qabs.c,v 1.6 2003/08/07 16:43:42 agc Exp $ */ +/* $NetBSD: qabs.c,v 1.7 2012/06/25 22:32:45 abs Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -34,7 +34,7 @@ #if 0 static char *sccsid = "from: @(#)labs.c 5.2 (Berkeley) 5/17/90"; #else -__RCSID("$NetBSD: qabs.c,v 1.6 2003/08/07 16:43:42 agc Exp $"); +__RCSID("$NetBSD: qabs.c,v 1.7 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -46,8 +46,7 @@ __weak_alias(qabs,_qabs) #endif quad_t -qabs(j) - quad_t j; +qabs(quad_t j) { return(j < 0 ? -j : j); } diff --git a/lib/libc/stdlib/qdiv.c b/lib/libc/stdlib/qdiv.c index 34e8c5c88..ff61db8f0 100644 --- a/lib/libc/stdlib/qdiv.c +++ b/lib/libc/stdlib/qdiv.c @@ -1,4 +1,4 @@ -/* $NetBSD: qdiv.c,v 1.6 2003/08/07 16:43:42 agc Exp $ */ +/* $NetBSD: qdiv.c,v 1.7 2012/06/25 22:32:45 abs Exp $ */ /* * Copyright (c) 1990 Regents of the University of California. @@ -37,7 +37,7 @@ #if 0 static char *sccsid = "from: @(#)ldiv.c 5.2 (Berkeley) 4/16/91"; #else -__RCSID("$NetBSD: qdiv.c,v 1.6 2003/08/07 16:43:42 agc Exp $"); +__RCSID("$NetBSD: qdiv.c,v 1.7 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,8 +49,7 @@ __weak_alias(qdiv,_qdiv) #endif qdiv_t -qdiv(num, denom) - quad_t num, denom; +qdiv(quad_t num, quad_t denom) { qdiv_t r; diff --git a/lib/libc/stdlib/qsort.c b/lib/libc/stdlib/qsort.c index 9652aafb6..91b359c29 100644 --- a/lib/libc/stdlib/qsort.c +++ b/lib/libc/stdlib/qsort.c @@ -1,4 +1,4 @@ -/* $NetBSD: qsort.c,v 1.20 2009/06/01 06:37:40 yamt Exp $ */ +/* $NetBSD: qsort.c,v 1.22 2012/05/26 21:47:05 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)qsort.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: qsort.c,v 1.20 2009/06/01 06:37:40 yamt Exp $"); +__RCSID("$NetBSD: qsort.c,v 1.22 2012/05/26 21:47:05 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -44,9 +44,9 @@ __RCSID("$NetBSD: qsort.c,v 1.20 2009/06/01 06:37:40 yamt Exp $"); #include #include -static inline char *med3 __P((char *, char *, char *, - int (*)(const void *, const void *))); -static inline void swapfunc __P((char *, char *, size_t, int)); +static inline char *med3(char *, char *, char *, + int (*)(const void *, const void *)); +static inline void swapfunc(char *, char *, size_t, int); #define min(a, b) (a) < (b) ? a : b @@ -89,7 +89,7 @@ swapfunc(char *a, char *b, size_t n, int swaptype) static inline char * med3(char *a, char *b, char *c, - int (*cmp) __P((const void *, const void *))) + int (*cmp)(const void *, const void *)) { return cmp(a, b) < 0 ? @@ -99,13 +99,13 @@ med3(char *a, char *b, char *c, void qsort(void *a, size_t n, size_t es, - int (*cmp) __P((const void *, const void *))) + int (*cmp)(const void *, const void *)) { char *pa, *pb, *pc, *pd, *pl, *pm, *pn; size_t d, r; int swaptype, cmp_result; - _DIAGASSERT(a != NULL); + _DIAGASSERT(a != NULL || n == 0 || es == 0); _DIAGASSERT(cmp != NULL); loop: SWAPINIT(a, es); diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c index b2e4544b7..4909d1434 100644 --- a/lib/libc/stdlib/rand.c +++ b/lib/libc/stdlib/rand.c @@ -1,4 +1,4 @@ -/* $NetBSD: rand.c,v 1.10 2003/08/07 16:43:43 agc Exp $ */ +/* $NetBSD: rand.c,v 1.12 2012/06/25 22:32:45 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)rand.c 8.1 (Berkeley) 6/14/93"; #else -__RCSID("$NetBSD: rand.c,v 1.10 2003/08/07 16:43:43 agc Exp $"); +__RCSID("$NetBSD: rand.c,v 1.12 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -44,15 +44,14 @@ __RCSID("$NetBSD: rand.c,v 1.10 2003/08/07 16:43:43 agc Exp $"); static u_long next = 1; int -rand() +rand(void) { /* LINTED integer overflow */ return (int)((next = next * 1103515245 + 12345) % ((u_long)RAND_MAX + 1)); } void -srand(seed) - u_int seed; +srand(u_int seed) { next = seed; } diff --git a/lib/libc/stdlib/rand48.h b/lib/libc/stdlib/rand48.h index f652c9df5..1ad8b0d21 100644 --- a/lib/libc/stdlib/rand48.h +++ b/lib/libc/stdlib/rand48.h @@ -1,4 +1,4 @@ -/* $NetBSD: rand48.h,v 1.5 2006/03/22 20:52:16 drochner Exp $ */ +/* $NetBSD: rand48.h,v 1.6 2011/05/18 19:36:36 dsl Exp $ */ /* * Copyright (c) 1993 Martin Birgmeier @@ -18,7 +18,7 @@ #include -extern void __dorand48 __P((unsigned short[3])); +extern void __dorand48(unsigned short[3]); extern unsigned short __rand48_seed[3]; extern unsigned short __rand48_mult[3]; extern unsigned short __rand48_add; diff --git a/lib/libc/stdlib/rand_r.c b/lib/libc/stdlib/rand_r.c index 7b2e9d7af..272b2bdcd 100644 --- a/lib/libc/stdlib/rand_r.c +++ b/lib/libc/stdlib/rand_r.c @@ -1,4 +1,4 @@ -/* $NetBSD: rand_r.c,v 1.5 2003/08/07 16:43:43 agc Exp $ */ +/* $NetBSD: rand_r.c,v 1.6 2012/06/25 22:32:45 abs Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -34,7 +34,7 @@ #if 0 static char *sccsid = "from: @(#)rand.c 5.6 (Berkeley) 6/24/91"; #else -__RCSID("$NetBSD: rand_r.c,v 1.5 2003/08/07 16:43:43 agc Exp $"); +__RCSID("$NetBSD: rand_r.c,v 1.6 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -43,8 +43,7 @@ __RCSID("$NetBSD: rand_r.c,v 1.5 2003/08/07 16:43:43 agc Exp $"); #include int -rand_r(seed) - unsigned int *seed; +rand_r(unsigned int *seed) { _DIAGASSERT(seed != NULL); diff --git a/lib/libc/stdlib/random.3 b/lib/libc/stdlib/random.3 index 48eb01b53..3f089da95 100644 --- a/lib/libc/stdlib/random.3 +++ b/lib/libc/stdlib/random.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: random.3,v 1.19 2008/02/28 16:16:35 christos Exp $ +.\" $NetBSD: random.3,v 1.20 2011/10/15 21:35:49 rmind Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)random.3 8.1 (Berkeley) 6/4/93 .\" -.Dd February 28, 2008 +.Dd October 15, 2011 .Dt RANDOM 3 .Os .Sh NAME @@ -171,6 +171,15 @@ messages are printed on the standard error output. .Xr srand 3 , .Xr rnd 4 , .Xr rnd 9 +.Sh STANDARDS +The +.Fn random , +.Fn srandom , +.Fn initstate +and +.Fn setstate +functions conform to +.St -p1003.1-2008 . .Sh HISTORY These functions appeared in diff --git a/lib/libc/stdlib/remque.c b/lib/libc/stdlib/remque.c index 0ebfc07f7..6060ad84b 100644 --- a/lib/libc/stdlib/remque.c +++ b/lib/libc/stdlib/remque.c @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: remque.c,v 1.2 2005/07/06 17:17:15 drochner Exp $"); +__RCSID("$NetBSD: remque.c,v 1.3 2012/06/25 22:32:45 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -40,8 +40,7 @@ struct qelem { }; void -remque(element) - void *element; +remque(void *element) { struct qelem *e = (struct qelem *) element; diff --git a/lib/libc/stdlib/strfmon.c b/lib/libc/stdlib/strfmon.c index 8ce598bcd..e92053cb8 100644 --- a/lib/libc/stdlib/strfmon.c +++ b/lib/libc/stdlib/strfmon.c @@ -1,4 +1,4 @@ -/* $NetBSD: strfmon.c,v 1.7 2009/01/30 23:46:03 lukem Exp $ */ +/* $NetBSD: strfmon.c,v 1.10 2012/03/21 14:19:15 christos Exp $ */ /*- * Copyright (c) 2001 Alexey Zelkin @@ -32,7 +32,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); #else -__RCSID("$NetBSD: strfmon.c,v 1.7 2009/01/30 23:46:03 lukem Exp $"); +__RCSID("$NetBSD: strfmon.c,v 1.10 2012/03/21 14:19:15 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -42,6 +42,7 @@ __RCSID("$NetBSD: strfmon.c,v 1.7 2009/01/30 23:46:03 lukem Exp $"); #endif #include +#include #include #include #include @@ -62,6 +63,10 @@ __RCSID("$NetBSD: strfmon.c,v 1.7 2009/01/30 23:46:03 lukem Exp $"); #define USE_INTL_CURRENCY 0x40 /* use international currency symbol */ #define IS_NEGATIVE 0x80 /* is argument value negative ? */ +#ifndef NBCHAR_MAX +#define NBCHAR_MAX ((unsigned char)CHAR_MAX) +#endif + /* internal macros */ #define PRINT(CH) do { \ if (dst >= s + maxsize) \ @@ -376,7 +381,8 @@ strfmon(char * __restrict s, size_t maxsize, const char * __restrict format, while (dst - tmpptr < width) PRINT(' '); } else { - pad_size = dst-tmpptr; + _DIAGASSERT(__type_fit(int, dst - tmpptr)); + pad_size = dst - tmpptr; memmove(tmpptr + width-pad_size, tmpptr, (size_t) pad_size); memset(tmpptr, ' ', (size_t) width-pad_size); @@ -441,9 +447,9 @@ __setup_vars(int flags, char *cs_precedes, char *sep_by_space, /* Set defult values for unspecified information. */ if (*cs_precedes != 0) *cs_precedes = 1; - if (*sep_by_space == CHAR_MAX) + if ((unsigned char)*sep_by_space == NBCHAR_MAX) *sep_by_space = 0; - if (*sign_posn == CHAR_MAX) + if ((unsigned char)*sign_posn == NBCHAR_MAX) *sign_posn = 0; } @@ -452,7 +458,7 @@ __calc_left_pad(int flags, char *cur_symb) { char cs_precedes, sep_by_space, sign_posn; const char *signstr; - int left_chars = 0; + size_t left_chars = 0; __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr); @@ -471,7 +477,8 @@ __calc_left_pad(int flags, char *cur_symb) { if (cs_precedes != 0) left_chars += strlen(signstr); } - return (left_chars); + _DIAGASSERT(__type_fit(int, left_chars)); + return (int)left_chars; } static int @@ -479,14 +486,14 @@ get_groups(int size, char *grouping) { int chars = 0; - if (*grouping == CHAR_MAX || *grouping <= 0) /* no grouping ? */ + if ((unsigned char)*grouping == NBCHAR_MAX || *grouping <= 0) /* no grouping ? */ return (0); while (size > (int)*grouping) { chars++; size -= (int)*grouping++; /* no more grouping ? */ - if (*grouping == CHAR_MAX) + if ((unsigned char)*grouping == NBCHAR_MAX) break; /* rest grouping with same value ? */ if (*grouping == 0) { @@ -505,7 +512,6 @@ __format_grouped_double(double value, int *flags, char *rslt; char *avalue; int avalue_size; - char fmt[32]; size_t bufsize; char *bufend; @@ -546,14 +552,13 @@ __format_grouped_double(double value, int *flags, left_prec += get_groups(left_prec, grouping); /* convert to string */ - snprintf(fmt, sizeof(fmt), "%%%d.%df", left_prec + right_prec + 1, - right_prec); - avalue_size = asprintf(&avalue, fmt, value); + avalue_size = asprintf(&avalue, "%*.*f", left_prec + right_prec + 1, + right_prec, value); if (avalue_size < 0) return (NULL); /* make sure that we've enough space for result string */ - bufsize = strlen(avalue)*2+1; + bufsize = avalue_size * 2 + 1; rslt = malloc(bufsize); if (rslt == NULL) { free(avalue); @@ -577,9 +582,10 @@ __format_grouped_double(double value, int *flags, avalue_size -= (right_prec + 1); } + /* XXX: Why not use %' instead? */ if ((*flags & NEED_GROUPING) && thousands_sep != '\0' && /* XXX: need investigation */ - *grouping != CHAR_MAX && + (unsigned char)*grouping != NBCHAR_MAX && *grouping > 0) { while (avalue_size > (int)*grouping) { GRPCPY(*grouping); @@ -587,7 +593,7 @@ __format_grouped_double(double value, int *flags, grouping++; /* no more grouping ? */ - if (*grouping == CHAR_MAX) + if ((unsigned char)*grouping == NBCHAR_MAX) break; /* rest grouping with same value ? */ diff --git a/lib/libc/stdlib/strsuftoll.c b/lib/libc/stdlib/strsuftoll.c index 0e29a6d62..80fc52fc9 100644 --- a/lib/libc/stdlib/strsuftoll.c +++ b/lib/libc/stdlib/strsuftoll.c @@ -1,4 +1,4 @@ -/* $NetBSD: strsuftoll.c,v 1.8 2008/04/28 20:23:00 martin Exp $ */ +/* $NetBSD: strsuftoll.c,v 1.9 2011/10/22 22:08:47 christos Exp $ */ /*- * Copyright (c) 2001-2002,2004 The NetBSD Foundation, Inc. * All rights reserved. @@ -67,7 +67,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: strsuftoll.c,v 1.8 2008/04/28 20:23:00 martin Exp $"); +__RCSID("$NetBSD: strsuftoll.c,v 1.9 2011/10/22 22:08:47 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #ifdef _LIBC @@ -121,8 +121,8 @@ strsuftoll(const char *desc, const char *val, result = strsuftollx(desc, val, min, max, errbuf, sizeof(errbuf)); if (*errbuf != '\0') - errx(1, "%s", errbuf); - return (result); + errx(EXIT_FAILURE, "%s", errbuf); + return result; } /* @@ -130,9 +130,9 @@ strsuftoll(const char *desc, const char *val, * rather than exiting with it. */ /* LONGLONG */ -long long -strsuftollx(const char *desc, const char *val, - long long min, long long max, char *ebuf, size_t ebuflen) +static long long +__strsuftollx(const char *desc, const char *val, + long long min, long long max, char *ebuf, size_t ebuflen, size_t depth) { long long num, t; char *expr; @@ -141,12 +141,15 @@ strsuftollx(const char *desc, const char *val, _DIAGASSERT(val != NULL); _DIAGASSERT(ebuf != NULL); - errno = 0; - ebuf[0] = '\0'; + if (depth > 16) { + snprintf(ebuf, ebuflen, "%s: Recursion limit exceeded", desc); + return 0; + } while (isspace((unsigned char)*val)) /* Skip leading space */ val++; + errno = 0; num = strtoll(val, &expr, 10); if (errno == ERANGE) goto erange; /* Overflow */ @@ -205,36 +208,42 @@ strsuftollx(const char *desc, const char *val, case '*': /* Backward compatible */ case 'x': t = num; - num *= strsuftollx(desc, expr + 1, min, max, ebuf, ebuflen); + num *= __strsuftollx(desc, expr + 1, min, max, ebuf, ebuflen, + depth + 1); if (*ebuf != '\0') - return (0); + return 0; if (t > num) { erange: - snprintf(ebuf, ebuflen, - "%s: %s", desc, strerror(ERANGE)); - return (0); + errno = ERANGE; + snprintf(ebuf, ebuflen, "%s: %s", desc, strerror(errno)); + return 0; } break; default: - badnum: snprintf(ebuf, ebuflen, - "%s `%s': illegal number", desc, val); - return (0); + badnum: + snprintf(ebuf, ebuflen, "%s `%s': illegal number", desc, val); + return 0; } if (num < min) { - /* LONGLONG */ + /* LONGLONG */ snprintf(ebuf, ebuflen, "%s %lld is less than %lld.", desc, (long long)num, (long long)min); - return (0); + return 0; } if (num > max) { - /* LONGLONG */ - snprintf(ebuf, ebuflen, - "%s %lld is greater than %lld.", + /* LONGLONG */ + snprintf(ebuf, ebuflen, "%s %lld is greater than %lld.", desc, (long long)num, (long long)max); - return (0); + return 0; } *ebuf = '\0'; - return (num); + return num; } +long long +strsuftollx(const char *desc, const char *val, + long long min, long long max, char *ebuf, size_t ebuflen) +{ + return __strsuftollx(desc, val, min, max, ebuf, ebuflen, 0); +} #endif /* !HAVE_STRSUFTOLL */ diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c index f0fc1207e..a6cff2f05 100644 --- a/lib/libc/stdlib/system.c +++ b/lib/libc/stdlib/system.c @@ -1,4 +1,4 @@ -/* $NetBSD: system.c,v 1.23 2010/11/14 18:11:43 tron Exp $ */ +/* $NetBSD: system.c,v 1.24 2012/06/25 22:32:45 abs Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)system.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: system.c,v 1.23 2010/11/14 18:11:43 tron Exp $"); +__RCSID("$NetBSD: system.c,v 1.24 2012/06/25 22:32:45 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,8 +51,7 @@ __RCSID("$NetBSD: system.c,v 1.23 2010/11/14 18:11:43 tron Exp $"); #include "reentrant.h" int -system(command) - const char *command; +system(const char *command) { pid_t pid; struct sigaction intsa, quitsa, sa; diff --git a/lib/libc/stdlib/tdelete.c b/lib/libc/stdlib/tdelete.c index 5c806682f..84017dc0e 100644 --- a/lib/libc/stdlib/tdelete.c +++ b/lib/libc/stdlib/tdelete.c @@ -1,4 +1,4 @@ -/* $NetBSD: tdelete.c,v 1.4 2006/03/19 01:12:08 christos Exp $ */ +/* $NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $ */ /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like @@ -13,7 +13,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tdelete.c,v 1.4 2006/03/19 01:12:08 christos Exp $"); +__RCSID("$NetBSD: tdelete.c,v 1.6 2012/06/25 22:32:45 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -22,12 +22,10 @@ __RCSID("$NetBSD: tdelete.c,v 1.4 2006/03/19 01:12:08 christos Exp $"); #include -/* delete node with given key */ +/* find a node with key "vkey" in tree "vrootp" */ void * -tdelete(vkey, vrootp, compar) - const void *vkey; /* key to be deleted */ - void **vrootp; /* address of the root of tree */ - int (*compar) __P((const void *, const void *)); +tdelete(const void *vkey, void **vrootp, + int (*compar)(const void *, const void *)) { node_t **rootp = (node_t **)vrootp; node_t *p, *q, *r; diff --git a/lib/libc/stdlib/tfind.c b/lib/libc/stdlib/tfind.c index c6273208d..fd3f362a7 100644 --- a/lib/libc/stdlib/tfind.c +++ b/lib/libc/stdlib/tfind.c @@ -1,4 +1,4 @@ -/* $NetBSD: tfind.c,v 1.5 2005/03/23 08:16:53 kleink Exp $ */ +/* $NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs Exp $ */ /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like @@ -13,7 +13,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tfind.c,v 1.5 2005/03/23 08:16:53 kleink Exp $"); +__RCSID("$NetBSD: tfind.c,v 1.7 2012/06/25 22:32:45 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -21,12 +21,10 @@ __RCSID("$NetBSD: tfind.c,v 1.5 2005/03/23 08:16:53 kleink Exp $"); #include #include -/* find a node, or return 0 */ +/* find a node by key "vkey" in tree "vrootp", or return 0 */ void * -tfind(vkey, vrootp, compar) - const void *vkey; /* key to be found */ - void * const *vrootp; /* address of the tree root */ - int (*compar) __P((const void *, const void *)); +tfind(const void *vkey, void * const *vrootp, + int (*compar)(const void *, const void *)) { node_t * const *rootp = (node_t * const*)vrootp; diff --git a/lib/libc/stdlib/tsearch.c b/lib/libc/stdlib/tsearch.c index b2f1a9373..af2fe9c22 100644 --- a/lib/libc/stdlib/tsearch.c +++ b/lib/libc/stdlib/tsearch.c @@ -1,4 +1,4 @@ -/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */ +/* $NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $ */ /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like @@ -13,7 +13,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $"); +__RCSID("$NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -23,10 +23,8 @@ __RCSID("$NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $"); /* find or insert datum into search tree */ void * -tsearch(vkey, vrootp, compar) - const void *vkey; /* key to be located */ - void **vrootp; /* address of tree root */ - int (*compar) __P((const void *, const void *)); +tsearch(const void *vkey, void **vrootp, + int (*compar)(const void *, const void *)) { node_t *q; node_t **rootp = (node_t **)vrootp; diff --git a/lib/libc/stdlib/twalk.c b/lib/libc/stdlib/twalk.c index b4298a6e1..0e239a18e 100644 --- a/lib/libc/stdlib/twalk.c +++ b/lib/libc/stdlib/twalk.c @@ -1,4 +1,4 @@ -/* $NetBSD: twalk.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ +/* $NetBSD: twalk.c,v 1.4 2012/03/20 16:38:45 matt Exp $ */ /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like @@ -13,7 +13,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: twalk.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); +__RCSID("$NetBSD: twalk.c,v 1.4 2012/03/20 16:38:45 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -21,15 +21,12 @@ __RCSID("$NetBSD: twalk.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); #include #include -static void trecurse __P((const node_t *, - void (*action)(const void *, VISIT, int), int level)); +typedef void (*cmp_fn_t)(const void *, VISIT, int); /* Walk the nodes of a tree */ static void -trecurse(root, action, level) - const node_t *root; /* Root of the tree to be walked */ - void (*action) __P((const void *, VISIT, int)); - int level; +trecurse(const node_t *root, /* Root of the tree to be walked */ + cmp_fn_t action, int level) { _DIAGASSERT(root != NULL); _DIAGASSERT(action != NULL); @@ -49,9 +46,7 @@ trecurse(root, action, level) /* Walk the nodes of a tree */ void -twalk(vroot, action) - const void *vroot; /* Root of the tree to be walked */ - void (*action) __P((const void *, VISIT, int)); +twalk(const void *vroot, cmp_fn_t action) /* Root of the tree to be walked */ { if (vroot != NULL && action != NULL) trecurse(vroot, action, 0); diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index ed2c67e97..857672db1 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -1,5 +1,5 @@ # from: @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $NetBSD: Makefile.inc,v 1.75 2009/07/30 20:57:15 dsl Exp $ +# $NetBSD: Makefile.inc,v 1.76 2012/08/30 12:16:48 drochner Exp $ # string sources .PATH: ${ARCHDIR}/string ${.CURDIR}/string @@ -19,6 +19,7 @@ SRCS+= bcmp.c bcopy.c bzero.c ffs.c memchr.c memcmp.c memset.c SRCS+= strcat.c strcmp.c strcpy.c strcspn.c strlen.c SRCS+= strncat.c strncmp.c strncpy.c strpbrk.c strsep.c SRCS+= strspn.c strstr.c swab.c +SRCS+= explicit_bzero.c consttime_bcmp.c SRCS+= memccpy.c memcpy.c memmem.c memmove.c SRCS+= strchr.c strrchr.c diff --git a/lib/libc/string/__strsignal.c b/lib/libc/string/__strsignal.c index 2c5d1e56b..3d874667b 100644 --- a/lib/libc/string/__strsignal.c +++ b/lib/libc/string/__strsignal.c @@ -1,4 +1,4 @@ -/* $NetBSD: __strsignal.c,v 1.24 2003/08/07 16:43:46 agc Exp $ */ +/* $NetBSD: __strsignal.c,v 1.25 2012/03/20 17:44:18 matt Exp $ */ /* * Copyright (c) 1988 Regents of the University of California. @@ -34,7 +34,7 @@ #if 0 static char *sccsid = "@(#)strerror.c 5.6 (Berkeley) 5/4/91"; #else -__RCSID("$NetBSD: __strsignal.c,v 1.24 2003/08/07 16:43:46 agc Exp $"); +__RCSID("$NetBSD: __strsignal.c,v 1.25 2012/03/20 17:44:18 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -56,10 +56,7 @@ __RCSID("$NetBSD: __strsignal.c,v 1.24 2003/08/07 16:43:46 agc Exp $"); /* ARGSUSED */ const char * -__strsignal(num, buf, buflen) - int num; - char *buf; - size_t buflen; +__strsignal(int num, char *buf, size_t buflen) { #define UPREFIX "Unknown signal: %u" #define RPREFIX "Real time signal %u" diff --git a/lib/libc/string/bcmp.3 b/lib/libc/string/bcmp.3 index b9ffe6cf5..c78c2571a 100644 --- a/lib/libc/string/bcmp.3 +++ b/lib/libc/string/bcmp.3 @@ -28,9 +28,9 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)bcmp.3 8.1 (Berkeley) 6/4/93 -.\" $NetBSD: bcmp.3,v 1.13 2010/04/29 06:54:26 jruoho Exp $ +.\" $NetBSD: bcmp.3,v 1.14 2012/05/05 21:24:19 dholland Exp $ .\" -.Dd April 29, 2010 +.Dd May 5, 2012 .Dt BCMP 3 .Os .Sh NAME @@ -57,6 +57,11 @@ bytes long. Zero-length strings are always identical. .Pp The strings may overlap. +.Pp +This function is obsolete. +The equivalent function +.Xr memcmp 3 +should be used instead. .Sh SEE ALSO .Xr memcmp 3 , .Xr strcasecmp 3 , diff --git a/lib/libc/string/bcopy.3 b/lib/libc/string/bcopy.3 index 6fa914d0c..5b01f8815 100644 --- a/lib/libc/string/bcopy.3 +++ b/lib/libc/string/bcopy.3 @@ -29,9 +29,9 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)bcopy.3 8.1 (Berkeley) 6/4/93 -.\" $NetBSD: bcopy.3,v 1.13 2010/04/29 07:27:30 wiz Exp $ +.\" $NetBSD: bcopy.3,v 1.14 2012/05/05 21:24:19 dholland Exp $ .\" -.Dd April 29, 2010 +.Dd May 5, 2012 .Dt BCOPY 3 .Os .Sh NAME @@ -57,6 +57,20 @@ The two strings may overlap. If .Fa len is zero, no bytes are copied. +.Pp +This function is obsolete. +The functions +.Xr memcpy 3 +and/or +.Xr memmove 3 +should be used instead. +Note that +.Fn bcopy +takes its +.Fa src +and +.Fa dst +arguments in the opposite order from these. .Sh SEE ALSO .Xr memccpy 3 , .Xr memcpy 3 , diff --git a/lib/libc/string/bm.c b/lib/libc/string/bm.c index e38fe7db6..aa60bead7 100644 --- a/lib/libc/string/bm.c +++ b/lib/libc/string/bm.c @@ -1,4 +1,4 @@ -/* $NetBSD: bm.c,v 1.11 2003/08/07 16:43:47 agc Exp $ */ +/* $NetBSD: bm.c,v 1.12 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1994 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)bm.c 8.7 (Berkeley) 6/21/94"; #else -__RCSID("$NetBSD: bm.c,v 1.11 2003/08/07 16:43:47 agc Exp $"); +__RCSID("$NetBSD: bm.c,v 1.12 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS && not lint */ @@ -100,10 +100,7 @@ static u_char const freq_def[256] = { }; bm_pat * -bm_comp(pb, len, freq) - u_char const *pb; - size_t len; - u_char const *freq; +bm_comp(u_char const *pb, size_t len, u_char const *freq) { u_char const *pe, *p; size_t *d, r; @@ -160,8 +157,7 @@ mem: sv_errno = errno; } void -bm_free(pat) - bm_pat *pat; +bm_free(bm_pat *pat) { _DIAGASSERT(pat != NULL); @@ -174,10 +170,7 @@ bm_free(pat) } u_char * -bm_exec(pat, base, n) - bm_pat *pat; - u_char *base; - size_t n; +bm_exec(bm_pat *pat, u_char *base, size_t n) { u_char *e, *ep, *p, *q, *s; size_t *d0, k, md2, n1, ro; diff --git a/lib/libc/string/index.3 b/lib/libc/string/index.3 index f69555539..a1a0f41e3 100644 --- a/lib/libc/string/index.3 +++ b/lib/libc/string/index.3 @@ -28,9 +28,9 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)index.3 8.1 (Berkeley) 6/4/93 -.\" $NetBSD: index.3,v 1.13 2010/04/29 06:54:26 jruoho Exp $ +.\" $NetBSD: index.3,v 1.15 2012/05/05 21:18:43 dholland Exp $ .\" -.Dd April 29, 2010 +.Dd May 5, 2012 .Dt INDEX 3 .Os .Sh NAME @@ -52,6 +52,11 @@ locates the first character matching .Em char ) in the nul-terminated string .Fa s . +.Pp +This function is obsolete. +The equivalent function +.Xr strchr 3 +should be used instead. .Sh RETURN VALUES A pointer to the character is returned if it is found; otherwise .Dv NULL diff --git a/lib/libc/string/memccpy.c b/lib/libc/string/memccpy.c index 556969200..c08624161 100644 --- a/lib/libc/string/memccpy.c +++ b/lib/libc/string/memccpy.c @@ -1,4 +1,4 @@ -/* $NetBSD: memccpy.c,v 1.12 2003/08/07 16:43:48 agc Exp $ */ +/* $NetBSD: memccpy.c,v 1.13 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: memccpy.c,v 1.12 2003/08/07 16:43:48 agc Exp $"); +__RCSID("$NetBSD: memccpy.c,v 1.13 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -42,11 +42,7 @@ __RCSID("$NetBSD: memccpy.c,v 1.12 2003/08/07 16:43:48 agc Exp $"); #include void * -memccpy(t, f, c, n) - void *t; - const void *f; - int c; - size_t n; +memccpy(void *t, const void *f, int c, size_t n) { _DIAGASSERT(t != 0); diff --git a/lib/libc/string/popcount.3 b/lib/libc/string/popcount.3 index 3648960c9..fae5916bb 100644 --- a/lib/libc/string/popcount.3 +++ b/lib/libc/string/popcount.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: popcount.3,v 1.4 2009/07/22 07:07:27 wiz Exp $ +.\" $NetBSD: popcount.3,v 1.5 2011/08/22 01:36:04 dholland Exp $ .\" .\" Copyright (c) 2009 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd July 13, 2009 +.Dd August 22, 2011 .Dt POPCOUNT 3 .Os .Sh NAME @@ -47,6 +47,7 @@ .Fn popcountl "unsigned long value" .Ft unsigned int .Fn popcountll "unsigned long long value" +.In stdint.h .Ft unsigned int .Fn popcount32 "uint32_t value" .Ft unsigned int diff --git a/lib/libc/string/rindex.3 b/lib/libc/string/rindex.3 index f5f91fb5f..0b9b33f65 100644 --- a/lib/libc/string/rindex.3 +++ b/lib/libc/string/rindex.3 @@ -28,9 +28,9 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)rindex.3 8.1 (Berkeley) 6/4/93 -.\" $NetBSD: rindex.3,v 1.12 2010/04/29 06:54:26 jruoho Exp $ +.\" $NetBSD: rindex.3,v 1.14 2012/05/05 21:18:43 dholland Exp $ .\" -.Dd April 29, 2010 +.Dd May 5, 2012 .Dt RINDEX 3 .Os .Sh NAME @@ -53,6 +53,11 @@ matching .Em char ) in the nul-terminated string .Fa s . +.Pp +This function is obsolete. +The equivalent function +.Xr strrchr 3 +should be used instead. .Sh RETURN VALUES A pointer to the character is returned if it is found; otherwise .Dv NULL diff --git a/lib/libc/string/strcoll.c b/lib/libc/string/strcoll.c index 1feda446a..77a094250 100644 --- a/lib/libc/string/strcoll.c +++ b/lib/libc/string/strcoll.c @@ -1,4 +1,4 @@ -/* $NetBSD: strcoll.c,v 1.9 2003/08/07 16:43:50 agc Exp $ */ +/* $NetBSD: strcoll.c,v 1.10 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)strcoll.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: strcoll.c,v 1.9 2003/08/07 16:43:50 agc Exp $"); +__RCSID("$NetBSD: strcoll.c,v 1.10 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,8 +48,7 @@ __RCSID("$NetBSD: strcoll.c,v 1.9 2003/08/07 16:43:50 agc Exp $"); * Compare strings according to LC_COLLATE category of current locale. */ int -strcoll(s1, s2) - const char *s1, *s2; +strcoll(const char *s1, const char *s2) { _DIAGASSERT(s1 != NULL); diff --git a/lib/libc/string/strcspn.c b/lib/libc/string/strcspn.c index cc40093c1..132f67cfe 100644 --- a/lib/libc/string/strcspn.c +++ b/lib/libc/string/strcspn.c @@ -1,4 +1,4 @@ -/* $NetBSD: strcspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $ */ +/* $NetBSD: strcspn.c,v 1.18 2012/03/21 00:35:50 christos Exp $ */ /*- * Copyright (c) 2008 Joerg Sonnenberger @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: strcspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $"); +__RCSID("$NetBSD: strcspn.c,v 1.18 2012/03/21 00:35:50 christos Exp $"); #include #include @@ -39,7 +39,7 @@ __RCSID("$NetBSD: strcspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $"); size_t strcspn(const char *s, const char *charset) { - static const size_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; + static const uint8_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; const char *t; uint8_t set[32]; #define UC(a) ((unsigned int)(unsigned char)(a)) diff --git a/lib/libc/string/strdup.c b/lib/libc/string/strdup.c index b56e27244..d07d876ad 100644 --- a/lib/libc/string/strdup.c +++ b/lib/libc/string/strdup.c @@ -1,4 +1,4 @@ -/* $NetBSD: strdup.c,v 1.13 2003/08/07 16:43:50 agc Exp $ */ +/* $NetBSD: strdup.c,v 1.14 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: strdup.c,v 1.13 2003/08/07 16:43:50 agc Exp $"); +__RCSID("$NetBSD: strdup.c,v 1.14 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,8 +50,7 @@ __weak_alias(strdup,_strdup) #endif char * -strdup(str) - const char *str; +strdup(const char *str) { size_t len; char *copy; diff --git a/lib/libc/string/strmode.c b/lib/libc/string/strmode.c index 40b81a1f3..e7335c862 100644 --- a/lib/libc/string/strmode.c +++ b/lib/libc/string/strmode.c @@ -1,4 +1,4 @@ -/* $NetBSD: strmode.c,v 1.18 2006/10/07 22:04:18 apb Exp $ */ +/* $NetBSD: strmode.c,v 1.19 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94"; #else -__RCSID("$NetBSD: strmode.c,v 1.18 2006/10/07 22:04:18 apb Exp $"); +__RCSID("$NetBSD: strmode.c,v 1.19 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ diff --git a/lib/libc/string/strncat.c b/lib/libc/string/strncat.c index 709fa3074..6023d60af 100644 --- a/lib/libc/string/strncat.c +++ b/lib/libc/string/strncat.c @@ -1,4 +1,4 @@ -/* $NetBSD: strncat.c,v 1.11 2007/06/03 17:39:27 christos Exp $ */ +/* $NetBSD: strncat.c,v 1.12 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)strncat.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: strncat.c,v 1.11 2007/06/03 17:39:27 christos Exp $"); +__RCSID("$NetBSD: strncat.c,v 1.12 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,10 +53,7 @@ __RCSID("$NetBSD: strncat.c,v 1.11 2007/06/03 17:39:27 christos Exp $"); * are written at dst (at most n+1 bytes being appended). Return dst. */ char * -strncat(dst, src, n) - char *dst; - const char *src; - size_t n; +strncat(char *dst, const char *src, size_t n) { _DIAGASSERT(dst != NULL); diff --git a/lib/libc/string/strpbrk.c b/lib/libc/string/strpbrk.c index 095b9b266..7f4f822eb 100644 --- a/lib/libc/string/strpbrk.c +++ b/lib/libc/string/strpbrk.c @@ -1,4 +1,4 @@ -/* $NetBSD: strpbrk.c,v 1.19 2008/09/24 16:58:53 christos Exp $ */ +/* $NetBSD: strpbrk.c,v 1.20 2011/11/22 00:37:09 joerg Exp $ */ /*- * Copyright (c) 2008 Joerg Sonnenberger @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: strpbrk.c,v 1.19 2008/09/24 16:58:53 christos Exp $"); +__RCSID("$NetBSD: strpbrk.c,v 1.20 2011/11/22 00:37:09 joerg Exp $"); #include #include @@ -60,6 +60,11 @@ strpbrk(const char *s, const char *charset) _DIAGASSERT(s != NULL); _DIAGASSERT(charset != NULL); + if (charset[0] == '\0') + return NULL; + if (charset[1] == '\0') + return strchr(s, charset[0]); + for (; *charset != '\0'; ++charset) ADD_TO_SET(UC(*charset)); diff --git a/lib/libc/string/strsignal.c b/lib/libc/string/strsignal.c index c0a95cef2..1bc7b9f0a 100644 --- a/lib/libc/string/strsignal.c +++ b/lib/libc/string/strsignal.c @@ -1,4 +1,4 @@ -/* $NetBSD: strsignal.c,v 1.14 2009/07/22 19:48:27 kleink Exp $ */ +/* $NetBSD: strsignal.c,v 1.15 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1988 Regents of the University of California. @@ -34,7 +34,7 @@ #if 0 static char *sccsid = "@(#)strerror.c 5.6 (Berkeley) 5/4/91"; #else -__RCSID("$NetBSD: strsignal.c,v 1.14 2009/07/22 19:48:27 kleink Exp $"); +__RCSID("$NetBSD: strsignal.c,v 1.15 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,8 +48,7 @@ __weak_alias(strsignal,_strsignal) #endif __aconst char * -strsignal(sig) - int sig; +strsignal(int sig) { static char buf[NL_TEXTMAX]; diff --git a/lib/libc/string/strspn.c b/lib/libc/string/strspn.c index 9526cde8b..ffd6515ba 100644 --- a/lib/libc/string/strspn.c +++ b/lib/libc/string/strspn.c @@ -1,4 +1,4 @@ -/* $NetBSD: strspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $ */ +/* $NetBSD: strspn.c,v 1.18 2012/03/21 00:35:50 christos Exp $ */ /*- * Copyright (c) 2008 Joerg Sonnenberger @@ -26,7 +26,7 @@ */ #include -__RCSID("$NetBSD: strspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $"); +__RCSID("$NetBSD: strspn.c,v 1.18 2012/03/21 00:35:50 christos Exp $"); #include #include @@ -38,7 +38,7 @@ __RCSID("$NetBSD: strspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $"); size_t strspn(const char *s, const char *charset) { - static const size_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; + static const uint8_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; uint8_t set[32]; const char *t; #define UC(a) ((unsigned int)(unsigned char)(a)) diff --git a/lib/libc/string/strtok_r.c b/lib/libc/string/strtok_r.c index 88065f2d8..9ed168b5c 100644 --- a/lib/libc/string/strtok_r.c +++ b/lib/libc/string/strtok_r.c @@ -1,4 +1,4 @@ -/* $NetBSD: strtok_r.c,v 1.9 2003/08/07 16:43:53 agc Exp $ */ +/* $NetBSD: strtok_r.c,v 1.10 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1988 Regents of the University of California. @@ -34,7 +34,7 @@ #if 0 static char *sccsid = "@(#)strtok.c 5.8 (Berkeley) 2/24/91"; #else -__RCSID("$NetBSD: strtok_r.c,v 1.9 2003/08/07 16:43:53 agc Exp $"); +__RCSID("$NetBSD: strtok_r.c,v 1.10 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -48,10 +48,7 @@ __weak_alias(strtok_r,_strtok_r) #endif char * -strtok_r(s, delim, lasts) - char *s; - const char *delim; - char **lasts; +strtok_r(char *s, const char *delim, char **lasts) { const char *spanp; int c, sc; diff --git a/lib/libc/string/strxfrm.c b/lib/libc/string/strxfrm.c index 4e25cf810..42c2a244b 100644 --- a/lib/libc/string/strxfrm.c +++ b/lib/libc/string/strxfrm.c @@ -1,4 +1,4 @@ -/* $NetBSD: strxfrm.c,v 1.11 2003/08/07 16:43:53 agc Exp $ */ +/* $NetBSD: strxfrm.c,v 1.12 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)strxfrm.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: strxfrm.c,v 1.11 2003/08/07 16:43:53 agc Exp $"); +__RCSID("$NetBSD: strxfrm.c,v 1.12 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,10 +50,7 @@ __RCSID("$NetBSD: strxfrm.c,v 1.11 2003/08/07 16:43:53 agc Exp $"); * on the original untransformed strings would return. */ size_t -strxfrm(dst, src, n) - char *dst; - const char *src; - size_t n; +strxfrm(char *dst, const char *src, size_t n) { size_t srclen, copysize; diff --git a/lib/libc/string/wcscat.c b/lib/libc/string/wcscat.c index d3e6eb8f2..61ad4ea3c 100644 --- a/lib/libc/string/wcscat.c +++ b/lib/libc/string/wcscat.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcscat.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ +/* $NetBSD: wcscat.c,v 1.3 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,16 +30,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcscat.c,v 1.2 2001/01/03 14:29:36 lukem Exp $"); +__RCSID("$NetBSD: wcscat.c,v 1.3 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include #include wchar_t * -wcscat(s1, s2) - wchar_t *s1; - const wchar_t *s2; +wcscat(wchar_t *s1, const wchar_t *s2) { wchar_t *p; wchar_t *q; diff --git a/lib/libc/string/wcscmp.c b/lib/libc/string/wcscmp.c index deb870dbe..5cd31b065 100644 --- a/lib/libc/string/wcscmp.c +++ b/lib/libc/string/wcscmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcscmp.c,v 1.8 2009/01/11 02:46:30 christos Exp $ */ +/* $NetBSD: wcscmp.c,v 1.9 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: wcscmp.c,v 1.8 2009/01/11 02:46:30 christos Exp $"); +__RCSID("$NetBSD: wcscmp.c,v 1.9 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,8 +49,7 @@ __RCSID("$NetBSD: wcscmp.c,v 1.8 2009/01/11 02:46:30 christos Exp $"); * Compare strings. */ int -wcscmp(s1, s2) - const wchar_t *s1, *s2; +wcscmp(const wchar_t *s1, const wchar_t *s2) { _DIAGASSERT(s1 != NULL); diff --git a/lib/libc/string/wcscpy.c b/lib/libc/string/wcscpy.c index aabb6d667..292554da9 100644 --- a/lib/libc/string/wcscpy.c +++ b/lib/libc/string/wcscpy.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcscpy.c,v 1.3 2005/10/13 21:13:05 tnozaki Exp $ */ +/* $NetBSD: wcscpy.c,v 1.4 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,16 +30,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcscpy.c,v 1.3 2005/10/13 21:13:05 tnozaki Exp $"); +__RCSID("$NetBSD: wcscpy.c,v 1.4 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include #include wchar_t * -wcscpy(s1, s2) - wchar_t *s1; - const wchar_t *s2; +wcscpy(wchar_t *s1, const wchar_t *s2) { wchar_t *p; diff --git a/lib/libc/string/wcscspn.c b/lib/libc/string/wcscspn.c index 2fa09895a..bac9c23a5 100644 --- a/lib/libc/string/wcscspn.c +++ b/lib/libc/string/wcscspn.c @@ -1,7 +1,8 @@ -/* $NetBSD: wcscspn.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ +/* $NetBSD: wcscspn.c,v 1.4 2011/11/24 18:44:25 joerg Exp $ */ /*- - * Copyright (c)1999 Citrus Project, + * Copyright (c) 1999 Citrus Project, + * Copyright (c) 2011 Joerg Sonnenberger, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,33 +30,45 @@ */ #include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcscspn.c,v 1.2 2001/01/03 14:29:36 lukem Exp $"); -#endif /* LIBC_SCCS and not lint */ +__RCSID("$NetBSD: wcscspn.c,v 1.4 2011/11/24 18:44:25 joerg Exp $"); #include +#include +#include #include +#include "wcscspn_bloom.h" + size_t -wcscspn(s, set) - const wchar_t *s; - const wchar_t *set; +wcscspn(const wchar_t *s, const wchar_t *set) { + size_t bloom[BLOOM_ARRAY_SIZE]; const wchar_t *p; const wchar_t *q; _DIAGASSERT(s != NULL); _DIAGASSERT(set != NULL); - p = s; - while (*p) { + if (set[0] == '\0') + return wcslen(s); + if (set[1] == '\0') { + for (p = s; *p; ++p) + if (*p == set[0]) + break; + return p - s; + } + + wcsspn_bloom_init(bloom, set); + + for (p = s; *p; ++p) { + if (!wcsspn_in_bloom(bloom, *p)) + continue; + q = set; - while (*q) { + do { if (*p == *q) goto done; - q++; - } - p++; + } while (*++q); } done: diff --git a/lib/libc/string/wcscspn_bloom.h b/lib/libc/string/wcscspn_bloom.h new file mode 100644 index 000000000..dc7d16e67 --- /dev/null +++ b/lib/libc/string/wcscspn_bloom.h @@ -0,0 +1,86 @@ +/* $NetBSD: wcscspn_bloom.h,v 1.4 2011/11/25 17:48:22 joerg Exp $ */ + +/*- + * Copyright (c) 2011 Joerg Sonnenberger, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Bloom filter for fast test if a given character is part of the reject set. + * The test may have false positives, but doesn't have false negatives. + * The first hash function is designed to be very fast to evaluate. + * It is collision free if the input is part of the same European language + * and shouldn't be too bad even other input. The second hash function + * tries to provide a much better mixing, but involves the slower + * multiplication. + */ + +#include + +#define BLOOM_SIZE 64 +#define BLOOM_ARRAY_SIZE (BLOOM_SIZE / sizeof(size_t)) +#define BLOOM_BITS (BLOOM_SIZE * CHAR_BIT) +#define BLOOM_DIV (sizeof(size_t) * CHAR_BIT) + +static inline size_t +wcscspn_bloom1(size_t x) +{ + return x % BLOOM_BITS; +} + +static inline size_t +wcscspn_bloom2(size_t x) +{ + return (size_t)((uint32_t)(x * 2654435761U) / + (0x100000000ULL / BLOOM_BITS)); +} + +static inline void +wcsspn_bloom_init(size_t *bloom, const wchar_t *charset) +{ + size_t val; + + memset(bloom, 0, BLOOM_SIZE); + do { + val = wcscspn_bloom1((size_t)*charset); + bloom[val / BLOOM_DIV] |= (size_t)1 << (val % BLOOM_DIV); + val = wcscspn_bloom2((size_t)*charset); + bloom[val / BLOOM_DIV] |= (size_t)1 << (val % BLOOM_DIV); + } + while (*++charset); +} + +static inline int +wcsspn_in_bloom(const size_t *bloom, wchar_t ch) +{ + size_t val; + + val = wcscspn_bloom1((size_t)ch); + if (bloom[val / BLOOM_DIV] & ((size_t)1 << (val % BLOOM_DIV))) + return 1; + val = wcscspn_bloom2((size_t)ch); + if (bloom[val / BLOOM_DIV] & ((size_t)1 << (val % BLOOM_DIV))) + return 1; + return 0; +} diff --git a/lib/libc/string/wcslcat.c b/lib/libc/string/wcslcat.c index a6d05e747..a62a9c17a 100644 --- a/lib/libc/string/wcslcat.c +++ b/lib/libc/string/wcslcat.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcslcat.c,v 1.2 2001/01/03 14:33:02 lukem Exp $ */ +/* $NetBSD: wcslcat.c,v 1.3 2012/06/25 22:32:46 abs Exp $ */ /* from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp */ /* @@ -30,7 +30,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcslcat.c,v 1.2 2001/01/03 14:33:02 lukem Exp $"); +__RCSID("$NetBSD: wcslcat.c,v 1.3 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -45,10 +45,7 @@ __RCSID("$NetBSD: wcslcat.c,v 1.2 2001/01/03 14:33:02 lukem Exp $"); * truncation occurred. */ size_t -wcslcat(dst, src, siz) - wchar_t *dst; - const wchar_t *src; - size_t siz; +wcslcat(wchar_t *dst, const wchar_t *src, size_t siz) { wchar_t *d = dst; const wchar_t *s = src; diff --git a/lib/libc/string/wcslcpy.c b/lib/libc/string/wcslcpy.c index 92c857d05..9421ad824 100644 --- a/lib/libc/string/wcslcpy.c +++ b/lib/libc/string/wcslcpy.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcslcpy.c,v 1.2 2001/01/03 14:33:02 lukem Exp $ */ +/* $NetBSD: wcslcpy.c,v 1.3 2012/06/25 22:32:46 abs Exp $ */ /* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp */ /* @@ -30,7 +30,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcslcpy.c,v 1.2 2001/01/03 14:33:02 lukem Exp $"); +__RCSID("$NetBSD: wcslcpy.c,v 1.3 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -43,10 +43,7 @@ __RCSID("$NetBSD: wcslcpy.c,v 1.2 2001/01/03 14:33:02 lukem Exp $"); * Returns wcslen(src); if retval >= siz, truncation occurred. */ size_t -wcslcpy(dst, src, siz) - wchar_t *dst; - const wchar_t *src; - size_t siz; +wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) { wchar_t *d = dst; const wchar_t *s = src; diff --git a/lib/libc/string/wcslen.c b/lib/libc/string/wcslen.c index c62c45941..703d6ec41 100644 --- a/lib/libc/string/wcslen.c +++ b/lib/libc/string/wcslen.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcslen.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ +/* $NetBSD: wcslen.c,v 1.3 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,15 +30,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcslen.c,v 1.2 2001/01/03 14:29:36 lukem Exp $"); +__RCSID("$NetBSD: wcslen.c,v 1.3 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include #include size_t -wcslen(s) - const wchar_t *s; +wcslen(const wchar_t *s) { const wchar_t *p; diff --git a/lib/libc/string/wcsncat.c b/lib/libc/string/wcsncat.c index 1fdca1164..e76421f32 100644 --- a/lib/libc/string/wcsncat.c +++ b/lib/libc/string/wcsncat.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcsncat.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ +/* $NetBSD: wcsncat.c,v 1.3 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,17 +30,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcsncat.c,v 1.2 2001/01/03 14:29:36 lukem Exp $"); +__RCSID("$NetBSD: wcsncat.c,v 1.3 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include #include wchar_t * -wcsncat(s1, s2, n) - wchar_t *s1; - const wchar_t *s2; - size_t n; +wcsncat(wchar_t *s1, const wchar_t *s2, size_t n) { wchar_t *p; wchar_t *q; diff --git a/lib/libc/string/wcsncmp.c b/lib/libc/string/wcsncmp.c index eec477f41..9703ddaaf 100644 --- a/lib/libc/string/wcsncmp.c +++ b/lib/libc/string/wcsncmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcsncmp.c,v 1.8 2009/01/11 02:46:30 christos Exp $ */ +/* $NetBSD: wcsncmp.c,v 1.9 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: wcsncmp.c,v 1.8 2009/01/11 02:46:30 christos Exp $"); +__RCSID("$NetBSD: wcsncmp.c,v 1.9 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -43,9 +43,7 @@ __RCSID("$NetBSD: wcsncmp.c,v 1.8 2009/01/11 02:46:30 christos Exp $"); #include "runetype_local.h" int -wcsncmp(s1, s2, n) - const wchar_t *s1, *s2; - size_t n; +wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n) { _DIAGASSERT(s1 != NULL); diff --git a/lib/libc/string/wcsncpy.c b/lib/libc/string/wcsncpy.c index 978ff48a5..586f805f2 100644 --- a/lib/libc/string/wcsncpy.c +++ b/lib/libc/string/wcsncpy.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcsncpy.c,v 1.3 2005/10/13 21:13:05 tnozaki Exp $ */ +/* $NetBSD: wcsncpy.c,v 1.4 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,17 +30,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcsncpy.c,v 1.3 2005/10/13 21:13:05 tnozaki Exp $"); +__RCSID("$NetBSD: wcsncpy.c,v 1.4 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include #include wchar_t * -wcsncpy(s1, s2, n) - wchar_t *s1; - const wchar_t *s2; - size_t n; +wcsncpy(wchar_t *s1, const wchar_t *s2, size_t n) { wchar_t *p; diff --git a/lib/libc/string/wcspbrk.c b/lib/libc/string/wcspbrk.c index b87a47a23..c2894c22e 100644 --- a/lib/libc/string/wcspbrk.c +++ b/lib/libc/string/wcspbrk.c @@ -1,7 +1,8 @@ -/* $NetBSD: wcspbrk.c,v 1.3 2005/11/29 03:12:00 christos Exp $ */ +/* $NetBSD: wcspbrk.c,v 1.5 2011/11/24 18:44:25 joerg Exp $ */ /*- - * Copyright (c)1999 Citrus Project, + * Copyright (c) 1999 Citrus Project, + * Copyright (c) 2011 Joerg Sonnenberger, * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,33 +30,41 @@ */ #include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcspbrk.c,v 1.3 2005/11/29 03:12:00 christos Exp $"); -#endif /* LIBC_SCCS and not lint */ +__RCSID("$NetBSD: wcspbrk.c,v 1.5 2011/11/24 18:44:25 joerg Exp $"); #include +#include +#include #include +#include "wcscspn_bloom.h" + wchar_t * -wcspbrk(s, set) - const wchar_t *s; - const wchar_t *set; +wcspbrk(const wchar_t *s, const wchar_t *set) { + size_t bloom[BLOOM_ARRAY_SIZE]; const wchar_t *p; const wchar_t *q; _DIAGASSERT(s != NULL); _DIAGASSERT(set != NULL); - p = s; - while (*p) { + if (set[0] == '\0') + return NULL; + if (set[1] == '\0') + return wcschr(s, set[0]); + + wcsspn_bloom_init(bloom, set); + + for (p = s; *p; ++p) { + if (!wcsspn_in_bloom(bloom, *p)) + continue; + q = set; - while (*q) { + do { if (*p == *q) return __UNCONST(p); - q++; - } - p++; + } while (*++q); } return NULL; } diff --git a/lib/libc/string/wcsrchr.c b/lib/libc/string/wcsrchr.c index f062cd2a4..65fca34c4 100644 --- a/lib/libc/string/wcsrchr.c +++ b/lib/libc/string/wcsrchr.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcsrchr.c,v 1.3 2005/11/29 03:12:00 christos Exp $ */ +/* $NetBSD: wcsrchr.c,v 1.4 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,16 +30,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcsrchr.c,v 1.3 2005/11/29 03:12:00 christos Exp $"); +__RCSID("$NetBSD: wcsrchr.c,v 1.4 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include #include wchar_t * -wcsrchr(s, c) - const wchar_t *s; - wchar_t c; +wcsrchr(const wchar_t *s, wchar_t c) { const wchar_t *p; diff --git a/lib/libc/string/wcsspn.c b/lib/libc/string/wcsspn.c index 84f2a10ef..cb33ec53a 100644 --- a/lib/libc/string/wcsspn.c +++ b/lib/libc/string/wcsspn.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcsspn.c,v 1.3 2001/09/21 16:09:15 yamt Exp $ */ +/* $NetBSD: wcsspn.c,v 1.4 2011/11/21 15:02:48 joerg Exp $ */ /*- * Copyright (c)1999,2001 Citrus Project, @@ -29,17 +29,13 @@ */ #include -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcsspn.c,v 1.3 2001/09/21 16:09:15 yamt Exp $"); -#endif /* LIBC_SCCS and not lint */ +__RCSID("$NetBSD: wcsspn.c,v 1.4 2011/11/21 15:02:48 joerg Exp $"); #include #include size_t -wcsspn(s, set) - const wchar_t *s; - const wchar_t *set; +wcsspn(const wchar_t *s, const wchar_t *set) { const wchar_t *p; const wchar_t *q; @@ -47,19 +43,14 @@ wcsspn(s, set) _DIAGASSERT(s != NULL); _DIAGASSERT(set != NULL); - p = s; - while (*p) { - q = set; - while (*q) { + for (p = s; *p; ++p) { + for (q = set; *q; ++q) { if (*p == *q) break; - q++; } if (!*q) - goto done; - p++; + break; } -done: return (p - s); } diff --git a/lib/libc/string/wcsstr.c b/lib/libc/string/wcsstr.c index b136c4497..99ae107ff 100644 --- a/lib/libc/string/wcsstr.c +++ b/lib/libc/string/wcsstr.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcsstr.c,v 1.4 2005/11/29 03:12:00 christos Exp $ */ +/* $NetBSD: wcsstr.c,v 1.5 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,7 +30,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcsstr.c,v 1.4 2005/11/29 03:12:00 christos Exp $"); +__RCSID("$NetBSD: wcsstr.c,v 1.5 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -38,12 +38,10 @@ __RCSID("$NetBSD: wcsstr.c,v 1.4 2005/11/29 03:12:00 christos Exp $"); wchar_t * #ifdef WCSWCS -wcswcs(big, little) +wcswcs(const wchar_t *big, const wchar_t *little) #else -wcsstr(big, little) +wcsstr(const wchar_t *big, const wchar_t *little) #endif - const wchar_t *big; - const wchar_t *little; { const wchar_t *p; const wchar_t *q; diff --git a/lib/libc/string/wcstok.c b/lib/libc/string/wcstok.c index ee97cb48f..7580e677f 100644 --- a/lib/libc/string/wcstok.c +++ b/lib/libc/string/wcstok.c @@ -1,4 +1,4 @@ -/* $NetBSD: wcstok.c,v 1.3 2003/07/10 08:50:48 tshiozak Exp $ */ +/* $NetBSD: wcstok.c,v 1.4 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1998 Softweyr LLC. All rights reserved. @@ -43,17 +43,15 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wcstok.c,v 1.3 2003/07/10 08:50:48 tshiozak Exp $"); +__RCSID("$NetBSD: wcstok.c,v 1.4 2012/06/25 22:32:46 abs Exp $"); #endif #include #include wchar_t * -wcstok(s, delim, last) - wchar_t * __restrict s; - const wchar_t * __restrict delim; - wchar_t ** __restrict last; +wcstok(wchar_t * __restrict s, const wchar_t * __restrict delim, + wchar_t ** __restrict last) { const wchar_t *spanp; wchar_t c, sc; diff --git a/lib/libc/string/wmemchr.c b/lib/libc/string/wmemchr.c index 899c1ae58..72735a7cd 100644 --- a/lib/libc/string/wmemchr.c +++ b/lib/libc/string/wmemchr.c @@ -1,4 +1,4 @@ -/* $NetBSD: wmemchr.c,v 1.3 2005/11/29 03:12:00 christos Exp $ */ +/* $NetBSD: wmemchr.c,v 1.4 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,17 +30,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemchr.c,v 1.3 2005/11/29 03:12:00 christos Exp $"); +__RCSID("$NetBSD: wmemchr.c,v 1.4 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include #include wchar_t * -wmemchr(s, c, n) - const wchar_t *s; - wchar_t c; - size_t n; +wmemchr(const wchar_t *s, wchar_t c, size_t n) { size_t i; diff --git a/lib/libc/string/wmemcmp.c b/lib/libc/string/wmemcmp.c index d9c6eec4a..f0055a556 100644 --- a/lib/libc/string/wmemcmp.c +++ b/lib/libc/string/wmemcmp.c @@ -1,4 +1,4 @@ -/* $NetBSD: wmemcmp.c,v 1.6 2009/01/11 02:46:30 christos Exp $ */ +/* $NetBSD: wmemcmp.c,v 1.7 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,7 +30,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemcmp.c,v 1.6 2009/01/11 02:46:30 christos Exp $"); +__RCSID("$NetBSD: wmemcmp.c,v 1.7 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -38,10 +38,7 @@ __RCSID("$NetBSD: wmemcmp.c,v 1.6 2009/01/11 02:46:30 christos Exp $"); #include "runetype_local.h" int -wmemcmp(s1, s2, n) - const wchar_t *s1; - const wchar_t *s2; - size_t n; +wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n) { size_t i; diff --git a/lib/libc/string/wmemcpy.c b/lib/libc/string/wmemcpy.c index 07a3f6f2e..b648fb886 100644 --- a/lib/libc/string/wmemcpy.c +++ b/lib/libc/string/wmemcpy.c @@ -1,4 +1,4 @@ -/* $NetBSD: wmemcpy.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ +/* $NetBSD: wmemcpy.c,v 1.3 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,7 +30,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemcpy.c,v 1.2 2001/01/03 14:29:37 lukem Exp $"); +__RCSID("$NetBSD: wmemcpy.c,v 1.3 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -38,10 +38,7 @@ __RCSID("$NetBSD: wmemcpy.c,v 1.2 2001/01/03 14:29:37 lukem Exp $"); #include wchar_t * -wmemcpy(d, s, n) - wchar_t *d; - const wchar_t *s; - size_t n; +wmemcpy(wchar_t *d, const wchar_t *s, size_t n) { _DIAGASSERT(d != NULL); diff --git a/lib/libc/string/wmemmove.c b/lib/libc/string/wmemmove.c index d193e6919..e05746769 100644 --- a/lib/libc/string/wmemmove.c +++ b/lib/libc/string/wmemmove.c @@ -1,4 +1,4 @@ -/* $NetBSD: wmemmove.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ +/* $NetBSD: wmemmove.c,v 1.3 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,7 +30,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemmove.c,v 1.2 2001/01/03 14:29:37 lukem Exp $"); +__RCSID("$NetBSD: wmemmove.c,v 1.3 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -38,10 +38,7 @@ __RCSID("$NetBSD: wmemmove.c,v 1.2 2001/01/03 14:29:37 lukem Exp $"); #include wchar_t * -wmemmove(d, s, n) - wchar_t *d; - const wchar_t *s; - size_t n; +wmemmove(wchar_t *d, const wchar_t *s, size_t n) { _DIAGASSERT(d != NULL); diff --git a/lib/libc/string/wmemset.c b/lib/libc/string/wmemset.c index c35e1d495..597da33ad 100644 --- a/lib/libc/string/wmemset.c +++ b/lib/libc/string/wmemset.c @@ -1,4 +1,4 @@ -/* $NetBSD: wmemset.c,v 1.2 2001/01/03 14:29:37 lukem Exp $ */ +/* $NetBSD: wmemset.c,v 1.3 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -30,17 +30,14 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: wmemset.c,v 1.2 2001/01/03 14:29:37 lukem Exp $"); +__RCSID("$NetBSD: wmemset.c,v 1.3 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include #include wchar_t * -wmemset(s, c, n) - wchar_t *s; - wchar_t c; - size_t n; +wmemset(wchar_t *s, wchar_t c, size_t n) { size_t i; wchar_t *p; diff --git a/lib/libc/sys-minix/mount.c b/lib/libc/sys-minix/mount.c index 29f8b0b0a..3bfd98cb8 100644 --- a/lib/libc/sys-minix/mount.c +++ b/lib/libc/sys-minix/mount.c @@ -87,7 +87,7 @@ int mountflags; */ rslabel = find_rslabel(args); if (rslabel != NULL){ - snprintf(label,16,rslabel); + snprintf(label,16,"%s",rslabel); free(rslabel); } else { if (stat(name, &statbuf) < 0) return -1; @@ -204,8 +204,7 @@ int flags; return r; } -char *find_rslabel(args_line) -char *args_line; +char *find_rslabel(char *args_line) { /** * Find and return the rslabel as given as optional diff --git a/lib/libc/sys-minix/stat.c b/lib/libc/sys-minix/stat.c index f84f45c00..d30ad7d30 100644 --- a/lib/libc/sys-minix/stat.c +++ b/lib/libc/sys-minix/stat.c @@ -30,6 +30,10 @@ static void prev_stat2new_stat(struct stat *new, struct minix_prev_stat *prev) new->st_ctimespec.tv_sec = prev->st_ctime; } +int _stat(const char *name, struct stat *buffer); +int _lstat(const char *name, struct stat *buffer); +int _fstat(int fd, struct stat *buffer); + __weak_alias(_stat, __stat50); __weak_alias(_lstat, __lstat50); __weak_alias(_fstat, __fstat50); diff --git a/lib/libc/sys-minix/stime.c b/lib/libc/sys-minix/stime.c index 024e23b41..c2d2323be 100644 --- a/lib/libc/sys-minix/stime.c +++ b/lib/libc/sys-minix/stime.c @@ -8,10 +8,10 @@ __weak_alias(stime, _stime) #endif -int stime(long *top) +int stime(time_t *top) { message m; - m.m2_l1 = *top; + m.m2_l1 = (long)*top; return(_syscall(PM_PROC_NR, STIME, &m)); } diff --git a/lib/libc/sys/Lint___vfork14.c b/lib/libc/sys/Lint___vfork14.c index badeb4060..c3eb792c6 100644 --- a/lib/libc/sys/Lint___vfork14.c +++ b/lib/libc/sys/Lint___vfork14.c @@ -1,4 +1,4 @@ -/* $NetBSD: Lint___vfork14.c,v 1.2 2000/06/14 06:49:10 cgd Exp $ */ +/* $NetBSD: Lint___vfork14.c,v 1.3 2012/06/24 15:26:03 christos Exp $ */ /* * This file placed in the public domain. @@ -9,7 +9,7 @@ /*ARGSUSED*/ pid_t -__vfork14() +__vfork14(void) { return (0); } diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 8d3b27986..d591e23a9 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.204 2011/01/10 04:41:27 christos Exp $ +# $NetBSD: Makefile.inc,v 1.217 2012/10/02 01:46:40 christos Exp $ # @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 # sys sources @@ -75,58 +75,68 @@ SRCS+= _brk.c _fork.c _getcontext.c _pipe.c _sbrk.c # modules with default implementations on all architectures: ASM= access.S acct.S \ bind.S \ - chdir.S chflags.S chmod.S chown.S chroot.S __clock_getres50.S \ - __clock_gettime50.S \ - dup.S dup2.S \ + chdir.S chflags.S chmod.S chown.S chroot.S clock_nanosleep.S \ + __clock_getres50.S __clock_gettime50.S \ + dup.S dup2.S dup3.S \ extattrctl.S \ extattr_delete_fd.S extattr_delete_file.S \ extattr_delete_link.S extattr_get_fd.S extattr_get_file.S \ extattr_get_link.S extattr_list_fd.S extattr_list_file.S \ extattr_list_link.S extattr_set_fd.S extattr_set_file.S \ extattr_set_link.S \ - fchdir.S fchflags.S fchmod.S fchown.S fchroot.S \ - __fhopen40.S __fhstat50.S __fhstatvfs140.S fktrace.S \ - flock.S fpathconf.S __fstat50.S fstatvfs1.S __futimes50.S \ + setxattr.S getxattr.S listxattr.S removexattr.S \ + lsetxattr.S lgetxattr.S llistxattr.S lremovexattr.S \ + fsetxattr.S fgetxattr.S flistxattr.S fremovexattr.S \ + faccessat.S fchdir.S fchflags.S fchmod.S fchmodat.S fchown.S \ + fchownat.S fchroot.S fexecve.S __fhopen40.S __fhstat50.S \ + __fhstatvfs140.S fktrace.S flock.S fpathconf.S __fstat50.S \ + fstatvfs1.S fstatat.S __futimes50.S futimens.S \ __getcwd.S __getdents30.S __getfh30.S getvfsstat.S getgroups.S\ __getitimer50.S __getlogin.S getpeername.S getpgid.S getpgrp.S \ getpriority.S getrlimit.S __getrusage50.S getsid.S \ getsockname.S getsockopt.S __gettimeofday50.S \ ioctl.S \ - kqueue.S ktrace.S \ + kqueue.S kqueue1.S ktrace.S \ _ksem_close.S _ksem_destroy.S _ksem_getvalue.S _ksem_init.S \ - _ksem_post.S _ksem_trywait.S _ksem_unlink.S _ksem_wait.S \ - _ksem_open.S \ + _ksem_post.S _ksem_timedwait.S _ksem_trywait.S _ksem_unlink.S \ + _ksem_wait.S _ksem_open.S \ lchflags.S lchmod.S lchown.S lfs_bmapv.S lfs_markv.S lfs_segclean.S \ - __lfs_segwait50.S link.S listen.S __lstat50.S __lutimes50.S \ - _lwp_create.S _lwp_exit.S _lwp_kill.S ___lwp_park50.S \ - _lwp_self.S _lwp_wait.S _lwp_unpark.S _lwp_unpark_all.S \ - _lwp_suspend.S _lwp_continue.S _lwp_wakeup.S _lwp_detach.S \ - _lwp_setprivate.S \ + __lfs_segwait50.S link.S linkat.S listen.S __lstat50.S \ + __lutimes50.S _lwp_create.S _lwp_exit.S _lwp_kill.S \ + ___lwp_park50.S _lwp_self.S _lwp_wait.S _lwp_unpark.S \ + _lwp_unpark_all.S _lwp_suspend.S _lwp_continue.S \ + _lwp_wakeup.S _lwp_detach.S _lwp_setprivate.S \ _lwp_setname.S _lwp_getname.S _lwp_ctl.S \ - madvise.S mincore.S minherit.S mkdir.S mkfifo.S __mknod50.S \ - mlock.S mlockall.S modctl.S __mount50.S mprotect.S \ - __msgctl50.S msgget.S munlock.S munlockall.S munmap.S \ + madvise.S mincore.S minherit.S mkdir.S mkdirat.S mkfifo.S mkfifoat.S \ + __mknod50.S mknodat.S mlock.S mlockall.S modctl.S __mount50.S \ + mprotect.S __msgctl50.S msgget.S munlock.S munlockall.S \ + munmap.S \ nfssvc.S __ntp_gettime50.S \ - pathconf.S pmc_get_info.S pmc_control.S __posix_chown.S \ - __posix_fchown.S __posix_lchown.S __posix_rename.S profil.S \ - quotactl.S \ - rasctl.S reboot.S recvfrom.S recvmsg.S rename.S revoke.S \ - rmdir.S \ - sa_register.S sa_stacks.S sa_enable.S sa_setconcurrency.S sa_yield.S \ - sa_preempt.S semconfig.S semget.S semop.S \ - sendmsg.S sendto.S setegid.S setcontext.S seteuid.S setgid.S \ - setgroups.S __setitimer50.S __setlogin.S setpgid.S \ + openat.S \ + paccept.S pathconf.S pipe2.S pmc_get_info.S pmc_control.S \ + __posix_chown.S __posix_fchown.S __posix_lchown.S \ + __posix_rename.S profil.S \ + __quotactl.S \ + rasctl.S readlinkat.S reboot.S recvfrom.S recvmmsg.S recvmsg.S rename.S \ + renameat.S revoke.S rmdir.S \ + semconfig.S semget.S semop.S \ + sendmmsg.S sendmsg.S sendto.S setegid.S seteuid.S \ + setgid.S setgroups.S __setitimer50.S __setlogin.S setpgid.S \ setpriority.S \ setregid.S setreuid.S setrlimit.S setsid.S setsockopt.S \ setuid.S __shmctl50.S shmdt.S shmget.S shutdown.S \ sigqueueinfo.S \ __sigaltstack14.S __sigpending14.S __sigaction_sigtramp.S \ ____sigtimedwait50.S __socket30.S socketpair.S __stat50.S \ - statvfs1.S swapctl.S symlink.S __sysctl.S \ + statvfs1.S swapctl.S symlink.S symlinkat.S __sysctl.S \ timer_create.S timer_delete.S __timer_gettime50.S timer_getoverrun.S \ ____semctl50.S __timer_settime50.S \ - umask.S undelete.S unlink.S unmount.S __utimes50.S utrace.S uuidgen.S \ - vadvise.S + umask.S undelete.S unlink.S unlinkat.S unmount.S __utimes50.S \ + utimensat.S utrace.S uuidgen.S vadvise.S + +# sa compat syscalls +SAASM+= sa_register.S sa_stacks.S sa_enable.S sa_setconcurrency.S sa_yield.S \ + sa_preempt.S # modules with potentially non default implementations ASM_MD= _lwp_getprivate.S mremap.S @@ -146,11 +156,11 @@ WEAKASM= accept.S __aio_suspend50.S close.S connect.S execve.S \ __pollts50.S __pselect50.S read.S readlink.S \ readv.S _sched_setparam.S _sched_getparam.S _sched_setaffinity.S \ _sched_getaffinity.S sched_yield.S \ - __select50.S __sigprocmask14.S __sigsuspend14.S sysarch.S \ + __select50.S setcontext.S __sigprocmask14.S __sigsuspend14.S sysarch.S \ __wait450.S write.S writev.S NOERR= getegid.S geteuid.S getgid.S getpid.S getppid.S getuid.S \ - issetugid.S sync.S __posix_fadvise50.S + issetugid.S posix_spawn.S sync.S __posix_fadvise50.S PSEUDONOERR= _exit.S @@ -174,6 +184,10 @@ ${WEAKASM}: ${ASMDEPS} ${_MKTARGET_CREATE} printf '#include "SYS.h"\nWSYSCALL(${.PREFIX},_sys_${.PREFIX})\nWEAK_ALIAS(_${.PREFIX},_sys_${.PREFIX})\n' >${.TARGET} +${SAASM}: ${ASMDEPS} + ${_MKTARGET_CREATE} + printf '#include "SYS.h"\n_SYSCALL(${.PREFIX:S/tmp_//},${.PREFIX:S/tmp_//:S/sa_/compat_60_sa_/})\n' >${.TARGET} + ${NOERR}: ${ASMDEPS} ${_MKTARGET_CREATE} printf '#include "SYS.h"\nRSYSCALL_NOERROR(${.PREFIX})\n' >${.TARGET} @@ -224,7 +238,7 @@ MAN+= accept.2 access.2 acct.2 adjtime.2 bind.2 brk.2 chdir.2 \ mount.2 \ mprotect.2 mremap.2 msgctl.2 msgget.2 msgrcv.2 msgsnd.2 msync.2 \ munmap.2 nanosleep.2 nfssvc.2 ntp_adjtime.2 open.2 pathconf.2 pipe.2 \ - pmc_control.2 poll.2 posix_fadvise.2 profil.2 ptrace.2 quotactl.2 \ + pmc_control.2 poll.2 posix_fadvise.2 profil.2 ptrace.2 __quotactl.2 \ rasctl.2 read.2 readlink.2 \ reboot.2 recv.2 rename.2 revoke.2 rmdir.2 \ select.2 semctl.2 \ @@ -242,6 +256,7 @@ MLINKS+=_exit.2 _Exit.2 MLINKS+=brk.2 sbrk.2 MLINKS+=clone.2 __clone.2 MLINKS+=dup.2 dup2.2 +MLINKS+=dup.2 dup3.2 MLINKS+=chdir.2 fchdir.2 MLINKS+=chflags.2 fchflags.2 chflags.2 lchflags.2 MLINKS+=chmod.2 fchmod.2 chmod.2 lchmod.2 @@ -278,6 +293,7 @@ MLINKS+=intro.2 errno.2 MLINKS+=kqueue.2 kevent.2 MLINKS+=ktrace.2 fktrace.2 MLINKS+=lseek.2 seek.2 +MLINKS+=link.2 linkat.2 MLINKS+=_lwp_suspend.2 _lwp_continue.2 MLINKS+=_lwp_getprivate.2 _lwp_setprivate.2 MLINKS+=madvise.2 posix_madvise.2 @@ -289,9 +305,9 @@ MLINKS+=pathconf.2 fpathconf.2 MLINKS+=pmc_control.2 pmc_get_info.2 MLINKS+=poll.2 pollts.2 MLINKS+=read.2 readv.2 read.2 pread.2 read.2 preadv.2 -MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 +MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 recv.2 recvmmsg.2 MLINKS+=select.2 pselect.2 -MLINKS+=send.2 sendmsg.2 send.2 sendto.2 +MLINKS+=send.2 sendmsg.2 send.2 sendto.2 send.2 sendmmsg.2 MLINKS+=setpgid.2 setpgrp.2 MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2 MLINKS+=shmat.2 shmdt.2 @@ -306,5 +322,9 @@ MLINKS+=statvfs.2 fstatvfs1.2 MLINKS+=syscall.2 __syscall.2 MLINKS+=truncate.2 ftruncate.2 MLINKS+=utimes.2 futimes.2 utimes.2 lutimes.2 +MLINKS+=utimes.2 futimens.2 utimes.2 utimensat.2 MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2 MLINKS+=write.2 writev.2 write.2 pwrite.2 write.2 pwritev.2 +MLINKS+=pipe.2 pipe2.2 +MLINKS+=accept.2 paccept.2 +MLINKS+=nanosleep.2 clock_nanosleep.2 diff --git a/lib/libc/sys/__quotactl.2 b/lib/libc/sys/__quotactl.2 new file mode 100644 index 000000000..006cb82ba --- /dev/null +++ b/lib/libc/sys/__quotactl.2 @@ -0,0 +1,355 @@ +.\" $NetBSD: __quotactl.2,v 1.3 2012/02/13 19:50:15 dholland Exp $ +.\" +.\" Copyright (c) 1983, 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Robert Elz at The University of Melbourne. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)quotactl.2 8.2 (Berkeley) 3/10/95 +.\" +.Dd February 11, 2012 +.Dt __QUOTACTL 2 +.Os +.Sh NAME +.Nm __quotactl +.Nd manipulate file system quotas +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/quota.h +.In sys/quotactl.h +.Ft int +.Fn __quotactl "const char *path" "struct quotactl_args *args" +.Sh DESCRIPTION +The +.Fn __quotactl +call manipulates file system quotas. +This is an internal interface and is documented for reference purposes +only. +All application and utility code should use the +.Xr libquota 3 +interface. +.Pp +The +.Fn __quotactl +function performs one of several quota-related operations on the file +system named by +.Fa path . +The operation and arguments to that operation are passed in the +.Fa args +argument. +The operation is stored in the +.Fa qc_op +member of +.Fa args . +The arguments are placed in a union such that the first and second +arguments of the operation +.Dv QUOTACTL_EXAMPLE +are found as the members +.Fa u.example.qc_arg1 +and +.Fa u.example.qc_arg2 . +The descriptions below will refer to the operations as functions of +the form +.Fn QUOTACTL_EXAMPLE "int arg1" "int arg2" +and elide the encoding of these arguments into the +.Fa args +structure. +Explicit mention of the +.Fa path +argument is also omitted. +.Pp +There are fourteen quota control operations. +These are: +.Bl -tag -width abcdef +.\" ************************************************************ +.It Fn QUOTACTL_STAT "struct quotastat *info" +Information about the quota implementation on the selected volume is +returned in +.Fa info . +The +.Dv quotastat +structure contains the following members: +.Bl -tag -width qs_restrictions +.It qs_implname +A human-readable string describing the underlying implementation of +quotas. +This is suitable for display to users +.Pq and system administrators +but should not be interpreted by software. +See +.Xr quota_getimplname 3 . +.It qs_numidtypes +The number of ID types supported by this implementation. +See +.Xr quota_getnumidtypes 3 . +.It qs_numobjtypes +The number of object types supported by this implementation. +See +.Xr quota_getnumobjtypes 3 . +.It qs_restrictions +Flags identifying specific semantic limitations of the implementation. +See +.Xr quota_getrestrictions 3 . +.El +.\" ************************************************************ +.It Fn QUOTACTL_IDTYPESTAT "int idtype" "struct quotaidtypestat *info" +Information about a particular ID type on the selected volume is +returned in +.Fa info . +The +.Dv quotaidtypestat +structure contains the following members: +.Bl -tag -width qs_restrictions +.It qis_name +The name of the ID type. +See +.Xr quota_idtype_getname 3 . +.El +.\" ************************************************************ +.It Fn QUOTACTL_OBJYPESTAT "int objtype" "struct quotaobjtypestat *info" +Information about a particular object type on the selected volume is +returned in +.Fa info . +The +.Dv quotaobjtypestat +structure contains the following members: +.Bl -tag -width qs_restrictions +.It qos_name +The name of the object type. +See +.Xr quota_objtype_getname 3 . +.It qos_isbytes +A flag that is nonzero if the object type is something measured in +bytes. +See +.Xr quota_objtype_isbytes 3 . +.El +.\" ************************************************************ +.It Fn QUOTACTL_GET "const struct quotakey *key" "struct quotaval *val" +Return in +.Fa val +the quota information selected by +.Fa key . +See +.Xr quota_get 3 . +.\" ************************************************************ +.It Fn QUOTACTL_PUT "const struct quotakey *key" "const struct quotaval *val" +The quota information selected by +.Fa key +is updated to the values provided in +.Fa val . +Note that the current usage information, which is file system +meta-data, cannot be updated via this interface. +If the usage information is incorrect a tool such as +.Xr fsck 8 +or +.Xr quotacheck 8 +with file-system-specific knowledge must be used to repair the +on-disk information. +See +.Xr quota_put 3 . +.\" ************************************************************ +.It Fn QUOTACTL_DELETE "const struct quotakey *key" +The quota information selected by +.Fa key +is removed. +See +.Xr quota_delete 3 . +.\" ************************************************************ +.It Fn QUOTACTL_CURSOROPEN "struct quotakcursor *cursor" +A cursor for iterating the quota information is created. +The +.Dv quotakcursor +structure is a semi-opaque type holding the iteration state used by +the quota implementation. +The caller is responsible for allocating and maintaining storage for +the cursor. +Every cursor that is opened should be closed. +It is not specified whether a cursor remains valid if +.Xr memcpy 3 +is used to move it to a different location in user memory. +It is not specified whether or how a cursor may be duplicated. +Passing an uninitialized, corrupted, or closed cursor to operations +other than +.Fn QUOTACTL_CURSOROPEN +will produce unspecified behavior. +As per general standards for system calls such actions must not +produce undefined or materially adverse behavior in the kernel; +however, the effect on a user process may be arbitrary. +The +.Xr libquota 3 +interface wraps the system call level quota cursors in a friendlier +interface. +See +.Xr quota_opencursor 3 . +.\" ************************************************************ +.It Fn QUOTACTL_CURSORCLOSE "struct quotakcursor *cursor" +The cursor passed in is closed. +See +.Xr quotacursor_close 3 . +.\" ************************************************************ +.It Fn QUOTACTL_CURSORSKIPIDTYPE "struct quotakcursor *cursor" "int idtype" +This operation provides a hint that iteration can skip over a +particular ID type. +The implementation is not obliged to honor the hint. +See +.Xr quotacursor_skipidtype 3 . +.\" ************************************************************ +.It Fn QUOTACTL_CURSORGET "struct quotakcursor *cursor" "struct quotakey *keys" "struct quotaval *vals" "unsigned maxnum" "unsigned *ret" +This operation retrieves data at the current cursor position and +advances it. +Up to +.Fa maxnum +quota records are retrieved and stored into the arrays named by +.Fa keys +and +.Fa vals . +The number of records retrieved is stored into the variable pointed to +by +.Fa ret . +See +.Xr quotacursor_get 3 +and +.Xr quotacursor_getn 3 . +.\" ************************************************************ +.It Fn QUOTACTL_CURSORATEND "struct quotakcursor *cursor" "int *ret" +This operation generates a nonzero value if the cursor has reached the +end of the available quota information and zero otherwise. +The generated value is stored into the variable pointed to by +.Fa ret . +See +.Xr quotacursor_atend 3 . +.\" ************************************************************ +.It Fn QUOTACTL_CURSORREWIND "struct quotakcursor *cursor" +This operation updates the cursor state so that further calls to +.Fn QUOTACTL_CURSORGET +will begin again at the start of the iteration. +See +.Xr quotacursor_rewind 3 . +.\" ************************************************************ +.It Fn QUOTACTL_QUOTAON "int idtype" "const char *quotafile" +This operation is accepted only by old-style +.Pq Dq quota1 +quota implementations. +Quotas for the ID type named by +.Fa idtype +are switched on, and the file +.Fa quotafile +is used to hold the quota information. +This operation can also be used when quotas are already switched on +to change the file used to hold the quota information. +Note however that as the current usage information in the file must be +consistent with the current state of the file system, in general it is +not safe to call +.Fn QUOTACTL_QUOTAON +except in single-user mode. +See +.Xr quotaon 8 +for more information. +Normally +quotaon 8 +is run during the boot sequence after +quotacheck 8 . +Also see +.Xr quota_quotaon 3 . +.\" ************************************************************ +.It Fn QUOTACTL_QUOTAOFF "int idtype" +This operation is accepted only by old-style +.Pq Dq quota1 +quota implementations. +Quotas for the ID type named by +.Fa idtype +are switched off. +Once quotas are switched off the file system behaves as if no quotas +are present. +Normally +quotaoff 8 +is run during the shutdown sequence. +Also see +.Xr quota_quotaoff 3 . +.\" ************************************************************ +.El +.Sh RETURN VALUES +On success, +.Fn __quotactl +returns 0. +Otherwise the value \-1 is returned and an error code reflecting the +reason for the failure is placed in +.Va errno . +.Sh ERRORS +.Fn __quotactl +failures include: +.Bl -tag -width Er +.It Bq Er EFAULT +A pointer points outside the process's allocated address space. +.It Bq Er EINVAL +The operation code was out of range; or +a requested ID or object type was out of range; or +a corrupted or invalid cursor was passed in. +.It Bq Er ENODEV +The requested action was inappropriate for +.Pq or not supported by +the selected volume. +.It Bq Er ENOENT +No quota information exists for the requested key. +.It Bq Er ENOMEM +Memory could not be allocated within the kernel. +.It Bq Er ENXIO +The target file system type is capable of supporting quotas, but +quotas are not enabled on the selected volume. +.It Bq Er EOPNOTSUPP +The target file system does not support quotas. +.El +.Sh SEE ALSO +.Xr quota 1 , +.Xr libquota 3 , +.Xr fstab 5 , +.Xr edquota 8 , +.Xr quotacheck 8 , +.Xr quotaon 8 , +.Xr quotarestore 8 , +.Xr repquota 8 +.Sh HISTORY +The original +.Fn quotactl +function call appeared in +.Bx 4.3 Reno . +The current +.Fn __quotactl +interface appeared in +.Nx 6.0 . +.Sh BUGS +As of this writing the error returns that occur in practice are not +always completely consistent with the intent documented above. +.Pp +There should be some way to integrate this call with the resource +limit interface provided by +.Xr setrlimit 2 +and +.Xr getrlimit 2 . diff --git a/lib/libc/sys/_lwp_create.2 b/lib/libc/sys/_lwp_create.2 index 708cac15d..d1c79fd34 100644 --- a/lib/libc/sys/_lwp_create.2 +++ b/lib/libc/sys/_lwp_create.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: _lwp_create.2,v 1.4 2008/04/30 13:10:51 martin Exp $ +.\" $NetBSD: _lwp_create.2,v 1.5 2012/05/21 14:15:16 martin Exp $ .\" .\" Copyright (c) 2003 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -47,6 +47,10 @@ The .Fa context argument specifies the initial execution context for the new LWP including signal mask, stack, and machine registers. +If this context specifies invalid register values (for example priviledge +escalation by setting machine dependend bits forbidden for user processes), +or does not specify cpu register values (uc_flags does not have the +_UC_CPU bit set), the call will fail and errno will be set to EINVAL. .Pp The following flags affect the creation of the new LWP: .Bl -tag -width LWP_SUSPENDED @@ -70,7 +74,8 @@ The LWP ID of the new LWP is stored in the location pointed to by Upon successful completion, .Fn _lwp_create returns a value of 0. -Otherwise, an error code is returned to indicate the error. +Otherwise, a value of -1 is returned and errno is set to one of the values +documented below. .Sh ERRORS .Fn _lwp_create will fail and no LWP will be created if: @@ -87,6 +92,8 @@ The address pointed to by or .Fa new_lwp is outside the process's allocated address space. +.It Bq Er EINVAL +The ucontext_t passed is invalid. .El .Sh SEE ALSO .Xr _lwp_continue 2 , diff --git a/lib/libc/sys/_lwp_ctl.2 b/lib/libc/sys/_lwp_ctl.2 index cb6e066af..f1ef6e993 100644 --- a/lib/libc/sys/_lwp_ctl.2 +++ b/lib/libc/sys/_lwp_ctl.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: _lwp_ctl.2,v 1.3 2009/02/17 18:51:56 njoly Exp $ +.\" $NetBSD: _lwp_ctl.2,v 1.5 2012/04/13 15:14:58 yamt Exp $ .\" .\" Copyright (c)2007 YAMAMOTO Takashi, .\" All rights reserved. @@ -25,7 +25,7 @@ .\" SUCH DAMAGE. .\" .\" ------------------------------------------------------------ -.Dd May 5, 2008 +.Dd April 13, 2012 .Dt _LWP_CTL 2 .Os .Sh NAME @@ -36,6 +36,7 @@ .Lb libc .\" ------------------------------------------------------------ .Sh SYNOPSIS +.In sys/lwpctl.h .In lwp.h .Ft int .Fn _lwp_ctl "int features" "struct lwpctl **address" @@ -50,19 +51,25 @@ It takes the following arguments. The bitwise-OR of the following flags. .Bl -tag -width LWPCTL_FEATURE_CURCPU .It Dv LWPCTL_FEATURE_CURCPU -Request lc_curcpu. +Request +.Vt lc_curcpu . .It Dv LWPCTL_FEATURE_PCTR -Request lc_pctr. +Request +.Vt lc_pctr . .El .It Fa address -The address to store a pointer to lwpctl structure for the calling LWP. +The address to store a pointer to +.Vt lwpctl +structure for the calling LWP. .El .Pp -The per-LWP communication area is described by an lwpctl structure. +The per-LWP communication area is described by an +.Vt lwpctl +structure. It has following members, depending on .Fa features . .Bl -tag -width int_lc_curcpu -.It int lc_curcpu +.It Vt int lc_curcpu The integral identifier of the CPU on which the LWP is running, or .Dv LWPCTL_CPU_NONE @@ -72,7 +79,7 @@ userland. It's available only if requested with the .Dv LWPCTL_FEATURE_CURCPU flag. -.It int lc_pctr +.It Vt int lc_pctr The integer which is incremented on every context switches to the LWP. It can be used to detect preemption of the LWP. (thus its name "preemption counter".) diff --git a/lib/libc/sys/accept.2 b/lib/libc/sys/accept.2 index 61f25cb94..fda197648 100644 --- a/lib/libc/sys/accept.2 +++ b/lib/libc/sys/accept.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: accept.2,v 1.25 2006/11/17 23:59:33 rillig Exp $ +.\" $NetBSD: accept.2,v 1.29 2012/03/19 09:34:36 plunky Exp $ .\" .\" Copyright (c) 1983, 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,11 +29,12 @@ .\" .\" @(#)accept.2 8.2 (Berkeley) 12/11/93 .\" -.Dd November 18, 2006 +.Dd March 19, 2012 .Dt ACCEPT 2 .Os .Sh NAME -.Nm accept +.Nm accept , +.Nm paccept .Nd accept a connection on a socket .Sh LIBRARY .Lb libc @@ -41,6 +42,8 @@ .In sys/socket.h .Ft int .Fn accept "int s" "struct sockaddr * restrict addr" "socklen_t * restrict addrlen" +.Ft int +.Fn paccept "int s" "struct sockaddr * restrict addr" "socklen_t * restrict addrlen" "const sigset_t * restrict sigmask" "int flags" .Sh DESCRIPTION The argument .Fa s @@ -131,10 +134,51 @@ by issuing a call with providing only the control information, or by calling .Xr setsockopt 2 . +.Pp +The +.Fn paccept +function behaves exactly like +.Fn accept , +but it also allows to set the following +.Fa flags +on the returned file descriptor: +.Bl -column SOCK_NONBLOCK -offset indent +.It Dv SOCK_CLOEXEC +Set the close on exec property. +.It Dv SOCK_NONBLOCK +Sets non-blocking I/O. +.El +.Pp +It can also temporarily replace the signal mask of the calling thread if +.Fa sigmask +is a +.Pf non- Dv NULL +pointer, then the +.Fn paccept +function shall replace the signal mask of the caller by the set of +signals pointed to by +.Fa sigmask +before waiting for a connection, and shall restore the signal mask +of the calling thread before returning. .Sh RETURN VALUES -The call returns \-1 on error. -If it succeeds, it returns a non-negative +The +.Fn accept +and +.Fn paccept +calls return \-1 on error. +If they succeed, they return a non-negative integer that is a descriptor for the accepted socket. +.Sh COMPATIBILITY +The +.Fn accept +implementation makes the new file descriptor inherit file flags +(like +.Dv O_NONBLOCK ) +from the listening socket. +It's a traditional behaviour for BSD derivative systems. +On the other hand, there are implementations which don't do so. +Linux is an example of such implementations. +Portable programs should not rely on either of the behaviours. .Sh ERRORS The .Fn accept @@ -183,3 +227,7 @@ The .Fn accept function appeared in .Bx 4.2 . +The +.Fn paccept +function is inspired from Linux and appeared in +.Nx 6.0 . diff --git a/lib/libc/sys/adjtime.c b/lib/libc/sys/adjtime.c index ecc6d6e34..b45f516b5 100644 --- a/lib/libc/sys/adjtime.c +++ b/lib/libc/sys/adjtime.c @@ -1,4 +1,4 @@ -/* $NetBSD: adjtime.c,v 1.11 2009/01/11 02:46:30 christos Exp $ */ +/* $NetBSD: adjtime.c,v 1.12 2011/10/15 23:00:02 christos Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: adjtime.c,v 1.11 2009/01/11 02:46:30 christos Exp $"); +__RCSID("$NetBSD: adjtime.c,v 1.12 2011/10/15 23:00:02 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -49,6 +49,10 @@ __RCSID("$NetBSD: adjtime.c,v 1.11 2009/01/11 02:46:30 christos Exp $"); #include +#if defined(__minix) && !defined(O_CLOEXEC) +#define O_CLOEXEC 0 +#endif + extern int __clockctl_fd; int ____adjtime50(const struct timeval *, struct timeval *); @@ -76,14 +80,12 @@ adjtime(const struct timeval *delta, struct timeval *olddelta) * If this fails, it means that we are not root * and we cannot open clockctl. This is a failure. */ - __clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY, 0); + __clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY | O_CLOEXEC, 0); if (__clockctl_fd == -1) { /* original error was EPERM - don't leak open errors */ errno = EPERM; return -1; } - - (void) fcntl(__clockctl_fd, F_SETFD, FD_CLOEXEC); } /* diff --git a/lib/libc/sys/chflags.2 b/lib/libc/sys/chflags.2 index 875e2d762..f4d69d5bf 100644 --- a/lib/libc/sys/chflags.2 +++ b/lib/libc/sys/chflags.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: chflags.2,v 1.26 2010/05/31 12:16:20 njoly Exp $ +.\" $NetBSD: chflags.2,v 1.27 2011/08/06 11:28:24 jruoho Exp $ .\" .\" Copyright (c) 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)chflags.2 8.3 (Berkeley) 5/2/95 .\" -.Dd May 2, 1995 +.Dd August 6, 2011 .Dt CHFLAGS 2 .Os .Sh NAME @@ -172,6 +172,7 @@ error occurred while reading from or writing to the file system. .Sh SEE ALSO .Xr chflags 1 , .Xr stat 2 , +.Xr stat_flags 3 , .Xr init 8 , .Xr mount_union 8 .Sh HISTORY diff --git a/lib/libc/sys/chmod.2 b/lib/libc/sys/chmod.2 index 2f347541b..0e2fd524c 100644 --- a/lib/libc/sys/chmod.2 +++ b/lib/libc/sys/chmod.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: chmod.2,v 1.37 2010/05/31 12:16:20 njoly Exp $ +.\" $NetBSD: chmod.2,v 1.40 2012/03/04 11:58:31 wiz Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)chmod.2 8.1 (Berkeley) 6/4/93 .\" -.Dd January 4, 2009 +.Dd March 3, 2012 .Dt CHMOD 2 .Os .Sh NAME @@ -101,24 +101,15 @@ defined in #define S_ISUID 0004000 /* set user id on execution */ #define S_ISGID 0002000 /* set group id on execution */ -#define S_ISVTX 0001000 /* save swapped text even after use */ +#define S_ISVTX 0001000 /* sticky bit */ .Ed .Pp -If mode +The mode .Dv ISVTX (the .Sq sticky bit ) -is set on a regular file, it historically meant that the system should -save a shareable copy of the program text in the swap area. -When applied to commonly used programs like the shell or editor, this -would decrease memory usage and startup time. -In -.Nx , -the sticky bit may still be set on regular files by the super-user, -but has no effect. -The historical meaning became obsolete in the 1980s with the advent of -memory-mapped executables, and is only documented as a matter of -historical interest. +can be set on regular files, but has no effect. +For historical reasons this can be done only by the super-user. .Pp If mode .Dv ISVTX @@ -130,7 +121,7 @@ files of other users in that directory. The sticky bit may be set by any user on a directory which the user owns or has appropriate permissions. .Pp -For more information about the properties of the sticky bit, see +For more information about the history and properties of the sticky bit, see .Xr sticky 7 . .Pp Changing the owner of a file @@ -153,8 +144,23 @@ and .Fn lchmod will fail and the file mode will be unchanged if: .Bl -tag -width Er -.It Bq Er ENOTDIR -A component of the path prefix is not a directory. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er EFAULT +.Fa path +points outside the process's allocated address space. +.It Bq Er EFTYPE +The effective user ID is not the super-user, the +.Fa mode +includes the sticky bit +.Pq Dv S_ISVTX , +and +.Fa path +does not refer to a directory. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. .It Bq Er ENAMETOOLONG A component of a pathname exceeded .Brq Dv NAME_MAX @@ -163,33 +169,17 @@ characters, or an entire path name exceeded characters. .It Bq Er ENOENT The named file does not exist. -.It Bq Er EACCES -Search permission is denied for a component of the path prefix. -.It Bq Er ELOOP -Too many symbolic links were encountered in translating the pathname. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. .It Bq Er EPERM The effective user ID does not match the owner of the file and -the effective user ID is not the super-user. -.It Bq Er EPERM -The mode includes the setgid bit +the effective user ID is not the super-user; or +the mode includes the setgid bit .Pq Dv S_ISGID but the file's group is neither the effective group ID nor is it in the group access list. .It Bq Er EROFS The named file resides on a read-only file system. -.It Bq Er EFAULT -.Fa path -points outside the process's allocated address space. -.It Bq Er EIO -An I/O error occurred while reading from or writing to the file system. -.It Bq Er EFTYPE -The effective user ID is not the super-user, the -.Fa mode -includes the sticky bit -.Pq Dv S_ISVTX , -and -.Fa path -does not refer to a directory. .El .Pp .Fn fchmod @@ -197,29 +187,28 @@ will fail if: .Bl -tag -width Er .It Bq Er EBADF The descriptor is not valid. +.It Bq Er EFTYPE +The effective user ID is not the super-user, the +.Fa mode +includes the sticky bit +.Pq Dv S_ISVTX , +and +.Fa fd +does not refer to a directory. .It Bq Er EINVAL .Fa fd refers to a socket, not to a file. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. .It Bq Er EPERM The effective user ID does not match the owner of the file and -the effective user ID is not the super-user. -.It Bq Er EPERM -The mode includes the setgid bit +the effective user ID is not the super-user; or +the mode includes the setgid bit .Pq Dv S_ISGID but the file's group is neither the effective group ID nor is it in the group access list. .It Bq Er EROFS The file resides on a read-only file system. -.It Bq Er EIO -An I/O error occurred while reading from or writing to the file system. -.It Bq Er EFTYPE -The effective user ID is not the super-user, the -.Fa mode -includes the sticky bit -.Pq Dv S_ISVTX , -and -.Fa fd -does not refer to a directory. .El .Sh SEE ALSO .Xr chmod 1 , diff --git a/lib/libc/sys/clock_settime.c b/lib/libc/sys/clock_settime.c index 5c0bd72f9..203347dbd 100644 --- a/lib/libc/sys/clock_settime.c +++ b/lib/libc/sys/clock_settime.c @@ -1,4 +1,4 @@ -/* $NetBSD: clock_settime.c,v 1.11 2009/01/11 02:46:30 christos Exp $ */ +/* $NetBSD: clock_settime.c,v 1.12 2011/10/15 23:00:02 christos Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: clock_settime.c,v 1.11 2009/01/11 02:46:30 christos Exp $"); +__RCSID("$NetBSD: clock_settime.c,v 1.12 2011/10/15 23:00:02 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -51,6 +51,10 @@ __RCSID("$NetBSD: clock_settime.c,v 1.11 2009/01/11 02:46:30 christos Exp $"); #include +#if defined(__minix) && !defined(O_CLOEXEC) +#define O_CLOEXEC 0 +#endif + extern int __clockctl_fd; int ____clock_settime50(clockid_t, const struct timespec *); @@ -78,14 +82,12 @@ clock_settime(clockid_t clock_id, const struct timespec *tp) * If this fails, it means that we are not root * and we cannot open clockctl. This is a failure. */ - __clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY, 0); + __clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY | O_CLOEXEC, 0); if (__clockctl_fd == -1) { /* original error was EPERM - don't leak open errors */ errno = EPERM; return -1; } - - (void) fcntl(__clockctl_fd, F_SETFD, FD_CLOEXEC); } /* diff --git a/lib/libc/sys/clone.2 b/lib/libc/sys/clone.2 index 9ef070bb0..dbdaf5aad 100644 --- a/lib/libc/sys/clone.2 +++ b/lib/libc/sys/clone.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: clone.2,v 1.12 2010/05/04 06:13:43 jruoho Exp $ +.\" $NetBSD: clone.2,v 1.13 2012/01/29 11:44:54 wiz Exp $ .\" .\" Copyright (c) 2001 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -31,7 +31,8 @@ .Dt CLONE 2 .Os .Sh NAME -.Nm clone +.Nm clone , +.Nm __clone .Nd spawn new process with options .Sh LIBRARY .Lb libc diff --git a/lib/libc/sys/dup.2 b/lib/libc/sys/dup.2 index 6cf0d5184..fb77ec16b 100644 --- a/lib/libc/sys/dup.2 +++ b/lib/libc/sys/dup.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: dup.2,v 1.21 2009/01/11 02:46:30 christos Exp $ +.\" $NetBSD: dup.2,v 1.28 2012/01/25 00:28:35 christos Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,12 +29,13 @@ .\" .\" @(#)dup.2 8.1 (Berkeley) 6/4/93 .\" -.Dd December 2, 2008 +.Dd January 23, 2012 .Dt DUP 2 .Os .Sh NAME .Nm dup , -.Nm dup2 +.Nm dup2 , +.Nm dup3 .Nd duplicate an existing file descriptor .Sh LIBRARY .Lb libc @@ -44,6 +45,8 @@ .Fn dup "int oldd" .Ft int .Fn dup2 "int oldd" "int newd" +.Ft int +.Fn dup3 "int oldd" "int newd" "int flags" .Sh DESCRIPTION .Fn dup duplicates an existing object descriptor and returns its value to @@ -100,16 +103,34 @@ If and .Fa oldd are the same, the call has no effect. +.Pp +.Fn dup3 +behaves exactly like +.Fn dup2 +only it allows extra +.Fa flags +to be set on the returned file descriptor. +The following flags are valid: +.Bl -tag -width O_NONBLOCK -offset indent +.It Dv O_CLOEXEC +Set the +.Dq close-on-exec +property. +.It Dv O_NONBLOCK +Sets non-blocking I/O. +.It Dv O_NOSIGPIPE +Return +.Er EPIPE +instead of raising +.Dv SIGPIPE . +.El .Sh RETURN VALUES The value \-1 is returned if an error occurs in either call. The external variable .Va errno indicates the cause of the error. .Sh ERRORS -.Fn dup -and -.Fn dup2 -fail if: +All three functions may fail if: .Bl -tag -width Er .It Bq Er EBADF .Fa oldd @@ -117,9 +138,27 @@ is not a valid active descriptor or .Fa newd is not in the range of valid file descriptors. +.El +.Pp +The +.Fn dup +function may also fail if: +.Bl -tag -width Er .It Bq Er EMFILE Too many descriptors are active. .El +.Pp +The +.Fn dup3 +function will also fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa flags +is other than +.Dv O_NONBLOCK +or +.Dv O_CLOEXEC . +.El .Sh SEE ALSO .Xr accept 2 , .Xr close 2 , @@ -136,3 +175,8 @@ and .Fn dup2 functions conform to .St -p1003.1-90 . +.Sh HISTORY +The +.Fn dup3 +function is inspired from Linux and appeared in +.Nx 6.0 . diff --git a/lib/libc/sys/extattr_get_file.2 b/lib/libc/sys/extattr_get_file.2 index df37b9cba..211b44394 100644 --- a/lib/libc/sys/extattr_get_file.2 +++ b/lib/libc/sys/extattr_get_file.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: extattr_get_file.2,v 1.3 2005/01/02 18:28:48 wiz Exp $ +.\" $NetBSD: extattr_get_file.2,v 1.5 2011/08/03 09:48:12 wiz Exp $ .\" .\" Copyright (c) 2001 Dima Dorfman .\" Copyright (c) 2003 Robert Watson @@ -27,7 +27,7 @@ .\" .\" FreeBSD: src/lib/libc/sys/extattr_get_file.2,v 1.14 2004/07/05 17:12:52 ru Exp .\" -.Dd January 2, 2004 +.Dd August 3, 2011 .Dt EXTATTR_GET_FILE 2 .Os .Sh NAME @@ -97,8 +97,10 @@ The system call deletes the extended attribute specified. The .Fn extattr_list_file -returns a list of attributes present in the requested namespace, separated -by ASCII 0 (nul) characters. +returns a list of attributes present in the requested namespace. +Each list entry consists of a single byte containing the length +of the attribute name, followed by the attribute name. +The attribute name is not terminated by ASCII 0 (nul). The .Fn extattr_get_file and @@ -226,15 +228,15 @@ and .Fn extattr_delete_file calls may also fail due to the following errors: .Bl -tag -width Er -.It Bq Er ENOTDIR -A component of the path prefix is not a directory. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. .It Bq Er ENAMETOOLONG A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. .It Bq Er ENOENT A component of the path name that must exist does not exist. -.It Bq Er EACCES -Search permission is denied for a component of the path prefix. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. .\" XXX are any missing? .El .Sh SEE ALSO @@ -254,3 +256,7 @@ to be associated with each file or directory. This interface is under active development, and as such is subject to change as applications are adapted to use it. Developers are discouraged from relying on its stability. +.Pp +Note that previous versions of this man page incorrectly stated that +.Fn extattr_list_file +returned a list of attribute names separated by ASCII 0 (nul). diff --git a/lib/libc/sys/fcntl.2 b/lib/libc/sys/fcntl.2 index a22fe0496..4d3f7799c 100644 --- a/lib/libc/sys/fcntl.2 +++ b/lib/libc/sys/fcntl.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: fcntl.2,v 1.37 2010/05/17 12:16:43 jruoho Exp $ +.\" $NetBSD: fcntl.2,v 1.40 2012/01/25 00:28:35 christos Exp $ .\" .\" Copyright (c) 1983, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)fcntl.2 8.2 (Berkeley) 1/12/94 .\" -.Dd May 17, 2010 +.Dd January 23, 2012 .Dt FCNTL 2 .Os .Sh NAME @@ -55,7 +55,7 @@ and is technically a pointer to void, but it is interpreted as an int by some commands and ignored by others. .Pp Commands are: -.Bl -tag -width F_GETOWNX +.Bl -tag -width F_DUPFD_CLOEXEC .It Dv F_DUPFD Return a new descriptor as follows: .Pp @@ -80,6 +80,10 @@ is cleared to remain open across .Xr execve 2 system calls. .El +.It Dv F_DUPFD_CLOEXEC +Same as +.Dv F_DUPFD , +but sets the close-on-exec property on the file descriptor created. .It Dv F_GETFD Get the close-on-exec flag associated with the file descriptor .Fa fd @@ -142,35 +146,32 @@ Close all file descriptors greater than or equal to .Ar fd . .It Dv F_MAXFD Return the maximum file descriptor number currently open by the process. +.It Dv F_GETNOSIGPIPE +Return if the +.Dv O_NOSIGPIPE +flag is set in the file descriptor. +.It Dv F_SETNOSIGPIPE +Set or clear the +.Dv O_NOSIGPIPE +in the file descriptor. .El .Pp -The flags for the +The set of valid flags for the .Dv F_GETFL and .Dv F_SETFL flags are as follows: -.Bl -tag -width O_NONBLOCKX -.It Dv O_NONBLOCK -Non-blocking I/O; if no data is available to a -.Xr read 2 -call, or if a -.Xr write 2 -operation would block, -the read or write call returns \-1 with the error -.Er EAGAIN . -.It Dv O_APPEND -Force each write to append at the end of file; -corresponds to the -.Dv O_APPEND -flag of +.Dv O_APPEND , +.Dv O_ASYNC , +.Dv O_FSYNC , +.Dv O_NONBLOCK , +.Dv O_DSYNC , +.Dv O_RSYNC , +.Dv O_ALT_IO , +.Dv O_DIRECT , +.Dv O_NOSIGPIPE . +These flags are described in .Xr open 2 . -.It Dv O_ASYNC -Enable the -.Dv SIGIO -signal to be sent to the process group -when I/O is possible, e.g., -upon availability of data to be read. -.El .Pp Several commands are available for doing advisory file locking; they all operate on the following structure: @@ -315,6 +316,28 @@ or an request fails or blocks respectively when another process has existing locks on bytes in the specified region and the type of any of those locks conflicts with the type specified in the request. +.Sh RETURN VALUES +Upon successful completion, the value returned depends on +.Fa cmd +as follows: +.Bl -tag -width F_GETOWNX -offset indent +.It Dv F_DUPFD +A new file descriptor. +.It Dv F_GETFD +Value of flag (only the low-order bit is defined). +.It Dv F_GETFL +Value of flags. +.It Dv F_GETOWN +Value of file descriptor owner. +.It Dv F_MAXFD +Value of the highest file descriptor open by the process. +.It other +Value other than \-1. +.El +.Pp +Otherwise, a value of \-1 is returned and +.Va errno +is set to indicate the error. .Sh COMPATIBILITY This interface follows the completely stupid semantics of .At V @@ -363,28 +386,6 @@ This implementation detects that sleeping until a locked region is unlocked would cause a deadlock and fails with an .Er EDEADLK error. -.Sh RETURN VALUES -Upon successful completion, the value returned depends on -.Fa cmd -as follows: -.Bl -tag -width F_GETOWNX -offset indent -.It Dv F_DUPFD -A new file descriptor. -.It Dv F_GETFD -Value of flag (only the low-order bit is defined). -.It Dv F_GETFL -Value of flags. -.It Dv F_GETOWN -Value of file descriptor owner. -.It Dv F_MAXFD -Value of the highest file descriptor open by the process. -.It other -Value other than \-1. -.El -.Pp -Otherwise, a value of \-1 is returned and -.Va errno -is set to indicate the error. .Sh ERRORS .Fn fcntl will fail if: diff --git a/lib/libc/sys/flock.2 b/lib/libc/sys/flock.2 index 946342250..3d47e7dac 100644 --- a/lib/libc/sys/flock.2 +++ b/lib/libc/sys/flock.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: flock.2,v 1.21 2009/10/29 01:52:01 wiz Exp $ +.\" $NetBSD: flock.2,v 1.22 2011/10/15 21:35:50 rmind Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)flock.2 8.2 (Berkeley) 12/11/93 .\" -.Dd October 26, 2009 +.Dd October 15, 2011 .Dt FLOCK 2 .Os .Sh NAME @@ -147,7 +147,9 @@ refers to an object other than a file. .Xr dup 2 , .Xr execve 2 , .Xr fork 2 , -.Xr open 2 +.Xr open 2 , +.Xr flockfile 3 , +.Xr lockf 3 .Sh HISTORY The .Fn flock diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c index 8436be5f5..5b23d8331 100644 --- a/lib/libc/sys/ftruncate.c +++ b/lib/libc/sys/ftruncate.c @@ -1,4 +1,4 @@ -/* $NetBSD: ftruncate.c,v 1.13 2007/11/23 12:39:15 uebayasi Exp $ */ +/* $NetBSD: ftruncate.c,v 1.14 2012/03/20 16:26:12 matt Exp $ */ /* * Copyright (c) 1992, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)ftruncate.c 8.1 (Berkeley) 6/17/93"; #else -__RCSID("$NetBSD: ftruncate.c,v 1.13 2007/11/23 12:39:15 uebayasi Exp $"); +__RCSID("$NetBSD: ftruncate.c,v 1.14 2012/03/20 16:26:12 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,9 +54,7 @@ int __ftruncate(int, int, off_t); * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ int -ftruncate(fd, length) - int fd; - off_t length; +ftruncate(int fd, off_t length) { return __ftruncate(fd, 0, length); diff --git a/lib/libc/sys/getdents.2 b/lib/libc/sys/getdents.2 index 1d5807996..4bd01ceb6 100644 --- a/lib/libc/sys/getdents.2 +++ b/lib/libc/sys/getdents.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: getdents.2,v 1.22 2010/06/04 05:42:24 jruoho Exp $ +.\" $NetBSD: getdents.2,v 1.23 2011/07/20 17:51:25 njoly Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -111,7 +111,6 @@ will fail if: .Fa fd is not a valid file descriptor open for reading. .It Bq Er EFAULT -Either .Fa buf points outside the allocated address space. .It Bq Er EINVAL diff --git a/lib/libc/sys/getitimer.2 b/lib/libc/sys/getitimer.2 index e0cf51ffd..66c73415c 100644 --- a/lib/libc/sys/getitimer.2 +++ b/lib/libc/sys/getitimer.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: getitimer.2,v 1.24 2010/04/30 04:17:45 jruoho Exp $ +.\" $NetBSD: getitimer.2,v 1.28 2011/10/27 16:10:37 christos Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getitimer.2 8.3 (Berkeley) 5/16/95 .\" -.Dd April 30, 2010 +.Dd October 27, 2011 .Dt GETITIMER 2 .Os .Sh NAME @@ -40,9 +40,6 @@ .Lb libc .Sh SYNOPSIS .In sys/time.h -.Fd #define ITIMER_REAL 0 -.Fd #define ITIMER_VIRTUAL 1 -.Fd #define ITIMER_PROF 2 .Ft int .Fn getitimer "int which" "struct itimerval *value" .Ft int @@ -60,10 +57,11 @@ in the structure at The .Fn setitimer call sets a timer to the specified -.Fa value -(returning the previous value of the timer if +.Fa value , +returning the previous value of the timer if .Fa ovalue -is non-nil). +is not +.Dv NULL . .Pp A timer value is defined by the .Fa itimerval @@ -92,29 +90,28 @@ to 0 causes a timer to be disabled after its next expiration (assuming .Fa it_value is non-zero). .Pp -Time values smaller than the resolution of the -system clock are rounded up to this resolution -(typically 10 milliseconds). -.Pp The -.Dv ITIMER_REAL +.Fa which +parameter specifies the type of the timer: +.Bl -tag -width "ITIMER_MONOTONIC " -offset indent +.It Dv ITIMER_REAL timer decrements in real time. +This timer is affected by +.Xr adjtime 2 +and +.Xr settimeofday 2 . A .Dv SIGALRM signal is delivered when this timer expires. -.Pp -The -.Dv ITIMER_VIRTUAL +.It Dv ITIMER_VIRTUAL timer decrements in process virtual time. It runs only when the process is executing. A .Dv SIGVTALRM signal is delivered when it expires. -.Pp -The -.Dv ITIMER_PROF +.It Dv ITIMER_PROF timer decrements both in process virtual time and when the system is running on behalf of the process. It is designed to be used by interpreters in statistically profiling @@ -128,58 +125,64 @@ delivered. Because this signal may interrupt in-progress system calls, programs using this timer must be prepared to restart interrupted system calls. -.Sh NOTES -Macros for manipulating time values are defined in the -.In sys/time.h -header; -.Fn timerclear -sets a time value to zero, -.Fn timerisset -tests if a time value is non-zero, -.Fn timercmp -compares two time values, -.Fn timeradd -adds a time value to another time value, -.Fn timersub -computes the time difference between two time values. -For additional details, see -.Xr timeradd 3 . +.It Dv ITIMER_MONOTONIC +timer decrements in monotonic time. +This timer is not affected by +.Xr adjtime 2 +and +.Xr settimeofday 2 . +A +.Dv SIGALRM +signal is +delivered when this timer expires. +.El +Note that: +.Bl -bullet -offset indent +.It +Time values smaller than the resolution of the +system clock are rounded up to this resolution +(typically 10 milliseconds). +.It +The interaction between +.Fn setitimer +and +.Xr alarm 3 +or +.Xr sleep 3 +is unspecified by the specification. +.El .Sh RETURN VALUES If the calls succeed, a value of 0 is returned. If an error occurs, the value \-1 is returned, and a more precise error code is placed in the global variable .Va errno . .Sh ERRORS -.Fn getitimer -and -.Fn setitimer -will fail if: +Both functions may fail if: .Bl -tag -width Er .It Bq Er EFAULT The .Fa value parameter specified a bad address. .It Bq Er EINVAL -A +The +.Fa which +parameter was not a known timer type, or the .Fa value parameter specified a time that was too large to be handled. .El .Sh SEE ALSO .Xr gettimeofday 2 , -.Xr poll 2 , .Xr select 2 , -.Xr sigaction 2 +.Xr sigaction 2 , +.Xr itimerval 3 , +.Xr timeradd 3 .Sh STANDARDS -The -.Fn getitimer -and -.Fn setitimer -functions conform to +The functions conform to .St -p1003.1-2001 . The later .St -p1003.1-2008 -revision however marked both functions as obsolescent, +revision however marked both as obsolescent, recommending the use of .Xr timer_gettime 2 and @@ -190,3 +193,7 @@ The .Fn getitimer function call appeared in .Bx 4.2 . +The +.Dv ITIMER_MONOTONIC +functionality appeared in +.Nx 6.0 . diff --git a/lib/libc/sys/getpeername.2 b/lib/libc/sys/getpeername.2 index 48c08a061..2dbbd16b1 100644 --- a/lib/libc/sys/getpeername.2 +++ b/lib/libc/sys/getpeername.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: getpeername.2,v 1.19 2006/03/05 22:06:08 agc Exp $ +.\" $NetBSD: getpeername.2,v 1.21 2011/06/03 08:07:48 wiz Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getpeername.2 8.1 (Berkeley) 6/4/93 .\" -.Dd March 5, 2006 +.Dd June 3, 2011 .Dt GETPEERNAME 2 .Os .Sh NAME @@ -40,11 +40,12 @@ .Sh SYNOPSIS .In sys/socket.h .Ft int -.Fn getpeername "int s" "struct sockaddr * restrict name" "socklen_t * restrict namelen" +.Fn getpeername \ +"int s" "struct sockaddr * restrict name" "socklen_t * restrict namelen" .Sh DESCRIPTION +The .Fn getpeername -returns the name of the peer connected to -socket +function returns the name of the peer connected to the socket .Fa s . One common use occurs when a process inherits an open socket, such as TCP servers forked from @@ -53,13 +54,11 @@ In this scenario, .Fn getpeername is used to determine the connecting client's IP address. .Pp -.Fn getpeername -takes three parameters: -.Pp -.Fa s +The function takes three parameters: +.Bl -tag -width namelen -offset indent +.It Fa s contains the file descriptor of the socket whose peer should be looked up. -.Pp -.Fa name +.It Fa name points to a .Li sockaddr structure that will hold the address information for the connected peer. @@ -77,11 +76,11 @@ should be used. is large enough to hold any of the other sockaddr_* variants. On return, it can be cast to the correct sockaddr type, based on the protocol family contained in its ss_family field. -.Pp -.Fa namelen +.It Fa namelen indicates the amount of space pointed to by .Fa name , in bytes. +.El .Pp If address information for the local end of the socket is required, the .Xr getsockname 2 @@ -108,26 +107,29 @@ The call succeeds unless: The argument .Fa s is not a valid descriptor. -.It Bq Er ENOTSOCK -The argument -.Fa s -is a file, not a socket. -.It Bq Er ENOTCONN -The socket is not connected. -.It Bq Er ENOBUFS -Insufficient resources were available in the system -to perform the operation. .It Bq Er EFAULT The .Fa name parameter points to memory not in a valid part of the process address space. +.It Bq Er ENOBUFS +Insufficient resources were available in the system +to perform the operation. +.It Bq Er ENOTCONN +The socket is not connected. +.It Bq Er ENOTSOCK +The argument +.Fa s +is a file, not a socket. .El .Sh SEE ALSO .Xr accept 2 , .Xr bind 2 , .Xr getsockname 2 , .Xr socket 2 +.Sh STANDARDS +The function conforms to +.St -p1003.1-2008 . .Sh HISTORY The .Fn getpeername diff --git a/lib/libc/sys/getpriority.2 b/lib/libc/sys/getpriority.2 index 3969f5df5..ff8326f3a 100644 --- a/lib/libc/sys/getpriority.2 +++ b/lib/libc/sys/getpriority.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: getpriority.2,v 1.18 2009/03/11 13:39:14 joerg Exp $ +.\" $NetBSD: getpriority.2,v 1.20 2012/04/13 16:32:15 wiz Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getpriority.2 8.1 (Berkeley) 6/4/93 .\" -.Dd April 25, 2004 +.Dd April 13, 2012 .Dt GETPRIORITY 2 .Os .Sh NAME @@ -55,6 +55,12 @@ is obtained with the call and set with the .Fn setpriority call. +.Pp +The priority is maintained in a per-process basis and +affects scheduling of LWPs which belong to the process and use the +.Dv SCHED_OTHER +scheduling class. +.Pp .Fa which is one of .Dv PRIO_PROCESS , @@ -78,7 +84,7 @@ denotes the current process, process group, or user. .Fa prio is a value in the range -20 to 20. The default priority is 0; -lower priorities cause more favorable scheduling. +numerically lower priority values cause more favorable scheduling. A value of 19 or 20 will schedule a process only when nothing at priority \*(Le 0 is runnable. .Pp @@ -90,7 +96,7 @@ The .Fn setpriority call sets the priorities of all of the specified processes to the specified value. -Only the super-user may lower priorities. +Only the super-user may lower priority values. .Sh RETURN VALUES Since .Fn getpriority @@ -110,12 +116,6 @@ and .Fn setpriority will fail if: .Bl -tag -width Er -.It Bq Er ESRCH -No process was located using the -.Fa which -and -.Fa who -values specified. .It Bq Er EINVAL .Fa which was not one of @@ -123,21 +123,28 @@ was not one of .Dv PRIO_PGRP , or .Dv PRIO_USER . +.It Bq Er ESRCH +No process was located using the +.Fa which +and +.Fa who +values specified. .El .Pp In addition to the errors indicated above, .Fn setpriority will fail if: .Bl -tag -width Er +.It Bq Er EACCES +A non super-user attempted to lower a process priority value. .It Bq Er EPERM A process was located, but neither its effective nor real user ID matched the effective user ID of the caller. -.It Bq Er EACCES -A non super-user attempted to lower a process priority. .El .Sh SEE ALSO .Xr nice 1 , .Xr fork 2 , +.Xr sched 3 , .Xr renice 8 .Sh HISTORY The diff --git a/lib/libc/sys/getrlimit.2 b/lib/libc/sys/getrlimit.2 index 9e6d5bd44..c3cbffdb2 100644 --- a/lib/libc/sys/getrlimit.2 +++ b/lib/libc/sys/getrlimit.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: getrlimit.2,v 1.32 2009/07/01 11:25:50 wiz Exp $ +.\" $NetBSD: getrlimit.2,v 1.36 2012/06/09 02:36:25 christos Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getrlimit.2 8.1 (Berkeley) 6/4/93 .\" -.Dd July 1, 2009 +.Dd June 8, 2012 .Dt GETRLIMIT 2 .Os .Sh NAME @@ -83,6 +83,11 @@ function. The maximum number of open files for this process. .It Li RLIMIT_NPROC The maximum number of simultaneous processes for this user id. +.It Li RLIMIT_NTHR +The maximum number of simultaneous threads (Lightweight Processes) for this +user id. +Kernel threads and the first thread of each process are not counted against +this limit. .It Li RLIMIT_RSS The maximum size (in bytes) to which a process's resident set size may grow. @@ -183,9 +188,7 @@ is invalid. .It Bq Er EINVAL Specified .Fa resource -was invalid. -.It Bq Er EINVAL -In the +was invalid; or, in the .Fn setrlimit call, the specified .Fa rlim_cur @@ -211,10 +214,10 @@ cannot be lowered, because current usage is already higher than the limit. .Xr csh 1 , .Xr sh 1 , .Xr mlock 2 , -.Xr quotactl 2 , .Xr setsockopt 2 , .Xr sigaction 2 , .Xr sigaltstack 2 , +.Xr libquota 3 , .Xr sysctl 3 .\" Sh STANDARDS .\" With exception of @@ -230,3 +233,9 @@ The .Fn getrlimit function call appeared in .Bx 4.2 . +.Sh BUGS +The resource limit +.Dv RLIMIT_RSS +is not implemented in +.Xr uvm 9 +which means that process memory size limits are not enforced. diff --git a/lib/libc/sys/getsid.2 b/lib/libc/sys/getsid.2 index 910599e9f..62b612fb7 100644 --- a/lib/libc/sys/getsid.2 +++ b/lib/libc/sys/getsid.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: getsid.2,v 1.10 2006/10/07 21:03:51 elad Exp $ +.\" $NetBSD: getsid.2,v 1.11 2011/04/04 08:00:53 jruoho Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getpgrp.2 8.1 (Berkeley) 6/4/93 .\" -.Dd October 7, 2006 +.Dd April 4, 2011 .Dt GETSID 2 .Os .Sh NAME @@ -43,7 +43,7 @@ .Fn getsid "pid_t pid" .Sh DESCRIPTION The -.Nm +.Fn getsid function returns the session ID of the process specified by .Ar pid . If @@ -53,7 +53,7 @@ The session ID is defined as the process group ID of the process that is the session leader. .Sh ERRORS If an error occurs, -.Nm +.Fn getsid returns \-1 and the global variable .Va errno is set to indicate the error, as follows: diff --git a/lib/libc/sys/getsockname.2 b/lib/libc/sys/getsockname.2 index 6411615f7..4443e9526 100644 --- a/lib/libc/sys/getsockname.2 +++ b/lib/libc/sys/getsockname.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: getsockname.2,v 1.23 2003/08/07 16:43:59 agc Exp $ +.\" $NetBSD: getsockname.2,v 1.24 2012/07/09 21:22:21 jdf Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getsockname.2 8.1 (Berkeley) 6/4/93 .\" -.Dd August 11, 2002 +.Dd July 9, 2012 .Dt GETSOCKNAME 2 .Os .Sh NAME @@ -134,6 +134,8 @@ is a file, not a socket. The socket has been shut down. .It Bq Er ENOBUFS Insufficient resources were available in the system to perform the operation. +.It Bq Er ENOTCONN +The socket is not connected. .It Bq Er EFAULT The .Fa name diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2 index 677049dcc..9dc123c27 100644 --- a/lib/libc/sys/getsockopt.2 +++ b/lib/libc/sys/getsockopt.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: getsockopt.2,v 1.34 2009/06/29 08:38:07 wiz Exp $ +.\" $NetBSD: getsockopt.2,v 1.35 2012/01/25 00:28:35 christos Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getsockopt.2 8.4 (Berkeley) 5/2/95 .\" -.Dd June 28, 2009 +.Dd January 23, 2012 .Dt GETSOCKOPT 2 .Os .Sh NAME @@ -167,6 +167,10 @@ and set with .It Dv SO_RCVTIMEO Ta "set timeout value for input" .It Dv SO_TIMESTAMP Ta "enables reception of a timestamp with datagrams" .It Dv SO_ACCEPTFILTER Ta "set accept filter on listening socket" +.It Dv SO_NOSIGPIPE Ta +controls generation of +.Dv SIGPIPE +for the socket .It Dv SO_TYPE Ta "get the type of the socket (get only)" .It Dv SO_ERROR Ta "get and clear error on the socket (get only)" .El diff --git a/lib/libc/sys/issetugid.2 b/lib/libc/sys/issetugid.2 index becbdcba9..4857d2239 100644 --- a/lib/libc/sys/issetugid.2 +++ b/lib/libc/sys/issetugid.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: issetugid.2,v 1.11 2003/08/07 16:44:00 agc Exp $ +.\" $NetBSD: issetugid.2,v 1.12 2012/04/21 12:27:27 roy Exp $ .\" OpenBSD: issetugid.2,v 1.7 1997/02/18 00:16:09 deraadt Exp .\" FreeBSD: src/lib/libc/sys/issetugid.2,v 1.5.2.2 1999/09/18 16:18:59 phantom Exp .\" @@ -31,7 +31,7 @@ .\" .\" FreeBSD: src/lib/libc/sys/issetugid.2,v 1.5.2.2 1999/09/18 16:18:59 phantom Exp .\" -.Dd April 22, 2000 +.Dd April 5, 2012 .Dt ISSETUGID 2 .Os .Sh NAME @@ -55,7 +55,7 @@ system call which had either of the setuid or setgid bits set (and extra privileges were given as a result) or if it has changed any of its real, effective or saved user or group ID's since it began execution. .Pp -This system call exists so that library routines (e.g., libc, libtermcap) +This system call exists so that library routines (e.g., libc) can reliably determine if it is safe to use information that was obtained from the user, in particular the results from .Xr getenv 3 diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index 2a81ccdfe..fa0347cf3 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: kqueue.2,v 1.29 2010/04/13 10:45:46 wiz Exp $ +.\" $NetBSD: kqueue.2,v 1.32 2012/01/25 00:28:35 christos Exp $ .\" .\" Copyright (c) 2000 Jonathan Lemon .\" All rights reserved. @@ -32,11 +32,12 @@ .\" .\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.22 2001/06/27 19:55:57 dd Exp $ .\" -.Dd April 13, 2010 +.Dd January 23, 2012 .Dt KQUEUE 2 .Os .Sh NAME .Nm kqueue , +.Nm kqueue1 , .Nm kevent .Nd kernel event notification mechanism .Sh LIBRARY @@ -47,6 +48,8 @@ .Ft int .Fn kqueue "void" .Ft int +.Fn kqueue1 "int flags" +.Ft int .Fn kevent "int kq" "const struct kevent *changelist" "size_t nchanges" "struct kevent *eventlist" "size_t nevents" "const struct timespec *timeout" .Fn EV_SET "\*[Am]kev" ident filter flags fflags data udata .Sh DESCRIPTION @@ -78,6 +81,23 @@ on a file descriptor will remove any kevents that reference the descriptor. .Pp .Fn kqueue creates a new kernel event queue and returns a descriptor. +.Pp +The +.Fn kqueue1 +also allows to set the following +.Fa flags +on the returned file descriptor: +.Bl -column O_NONBLOCK -offset indent +.It Dv O_CLOEXEC +Set the close on exec property. +.It Dv O_NONBLOCK +Sets non-blocking I/O. +.It Dv O_NOSIGPIPE +Return +.Er EPIPE +instead of raising +.Dv SIGPIPE . +.El The queue is not inherited by a child created with .Xr fork 2 . .\" However, if @@ -508,8 +528,8 @@ main(int argc, char *argv[]) EV_SET(\*[Am]ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK| NOTE_RENAME|NOTE_REVOKE, 0, 0); - if (kevent(kq, \*[Am]ch, 1, NULL, 0, \*[Am]tout) == -1) - err(1, "kevent"); + if (kevent(kq, \*[Am]ev, 1, NULL, 0, \*[Am]tout) == -1) + err(1, "kevent"); for (;;) { nev = kevent(kq, NULL, 0, \*[Am]ev, 1, \*[Am]tout); if (nev == -1) @@ -617,3 +637,7 @@ functions first appeared in .Fx 4.1 , and then in .Nx 2.0 . +The +.Fn kqueue1 +function first appeared in +.Nx 6.0 . diff --git a/lib/libc/sys/link.2 b/lib/libc/sys/link.2 index 7887dfa18..031c3f5ba 100644 --- a/lib/libc/sys/link.2 +++ b/lib/libc/sys/link.2 @@ -1,6 +1,6 @@ -.\" $NetBSD: link.2,v 1.24 2010/05/31 12:16:20 njoly Exp $ +.\" $NetBSD: link.2,v 1.26 2011/08/08 19:50:17 wiz Exp $ .\" -.\" Copyright (c) 1980, 1991, 1993 +.\" Copyright (c) 1980, 1991, 1993, 2011 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -41,6 +41,8 @@ .In unistd.h .Ft int .Fn link "const char *name1" "const char *name2" +.Ft int +.Fn linkat "int fd1" "const char *name1" "int fd2" "const char *name2" "int flags" .Sh DESCRIPTION The .Fn link @@ -77,6 +79,28 @@ must be in the same file system. .Fa name1 may not be a directory unless the caller is the super-user and the file system containing it supports linking to directories. +.Pp +When operating on a symlink, +.Fn link +resolves the symlink and creates a hard link on the target. +.Fn linkat +will do the same if +.Dv AT_SYMLINK_FOLLOW +is set in +.Fa flags , +but it will link on the symlink itself if the flag is clear. +.Pp +At the moment, +.Fn linkat +is partially implemented. +It will return +.Er ENOSYS +for +.Fa fd1 +and +.Fa fd2 +values different than +.Dv AT_FDCWD . .Sh RETURN VALUES Upon successful completion, a value of 0 is returned. Otherwise, a value of \-1 is returned and @@ -86,39 +110,53 @@ is set to indicate the error. .Fn link will fail and no link will be created if: .Bl -tag -width Er -.It Bq Er ENOTDIR -A component of either path prefix is not a directory. -.It Bq Er ENAMETOOLONG -A component of a pathname exceeded -.Brq Dv NAME_MAX -characters, or an entire path name exceeded -.Brq Dv PATH_MAX -characters. -.It Bq Er ENOENT -A component of either path prefix does not exist. .It Bq Er EACCES A component of either path prefix denies search permission, or the requested link requires writing in a directory with a mode that denies write permission. +.It Bq Er EDQUOT +The directory in which the entry for the new link +is being placed cannot be extended because the +user's quota of disk blocks on the file system +containing the directory has been exhausted. +.It Bq Er EEXIST +The link named by +.Fa name2 +does exist. +.It Bq Er EFAULT +One of the pathnames specified +is outside the process's allocated address space. +.It Bq Er EIO +An I/O error occurred while reading from or writing to +the file system to make the directory entry. .It Bq Er ELOOP Too many symbolic links were encountered in translating one of the pathnames. +.It Bq Er EMLINK +The link count of the file named by +.Fa name1 +would exceed +.Dv {LINK_MAX} . +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Brq Dv NAME_MAX +characters, or an entire path name exceeded +.Brq Dv PATH_MAX +characters. .It Bq Er ENOENT -The file named by +A component of either path prefix does not exist, or the file named +by .Fa name1 does not exist. +.It Bq Er ENOSPC +The directory in which the entry for the new link is being placed +cannot be extended because there is no space left on the file +system containing the directory. +.It Bq Er ENOTDIR +A component of either path prefix is not a directory. .It Bq Er EOPNOTSUPP The file system containing the file named by .Fa name1 does not support links. -.It Bq Er EMLINK -The link count of the file named by -.Fa name1 -would exceed -.Dv {LINK_MAX} . -.It Bq Er EEXIST -The link named by -.Fa name2 -does exist. .It Bq Er EPERM The file named by .Fa name1 @@ -127,30 +165,15 @@ user ID is not super-user, or the file system containing the file does not permit the use of .Fn link on a directory. +.It Bq Er EROFS +The requested link requires writing in a directory on a read-only file +system. .It Bq Er EXDEV The link named by .Fa name2 and the file named by .Fa name1 are on different file systems. -.It Bq Er ENOSPC -The directory in which the entry for the new link is being placed -cannot be extended because there is no space left on the file -system containing the directory. -.It Bq Er EDQUOT -The directory in which the entry for the new link -is being placed cannot be extended because the -user's quota of disk blocks on the file system -containing the directory has been exhausted. -.It Bq Er EIO -An I/O error occurred while reading from or writing to -the file system to make the directory entry. -.It Bq Er EROFS -The requested link requires writing in a directory on a read-only file -system. -.It Bq Er EFAULT -One of the pathnames specified -is outside the process's allocated address space. .El .Sh SEE ALSO .Xr symlink 2 , @@ -160,3 +183,6 @@ The .Fn link function conforms to .St -p1003.1-90 . +.Sh BUGS +.Fn linkat +is partially implemented. diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c index 96d4dc30e..0b97e45d1 100644 --- a/lib/libc/sys/lseek.c +++ b/lib/libc/sys/lseek.c @@ -1,4 +1,4 @@ -/* $NetBSD: lseek.c,v 1.10 2007/11/23 12:39:15 uebayasi Exp $ */ +/* $NetBSD: lseek.c,v 1.11 2012/03/20 16:26:12 matt Exp $ */ /* * Copyright (c) 1992, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)lseek.c 8.1 (Berkeley) 6/17/93"; #else -__RCSID("$NetBSD: lseek.c,v 1.10 2007/11/23 12:39:15 uebayasi Exp $"); +__RCSID("$NetBSD: lseek.c,v 1.11 2012/03/20 16:26:12 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -54,10 +54,7 @@ off_t __lseek(int, int, off_t, int); * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ off_t -lseek(fd, offset, whence) - int fd; - off_t offset; - int whence; +lseek(int fd, off_t offset, int whence) { return __lseek(fd, 0, offset, whence); diff --git a/lib/libc/sys/madvise.2 b/lib/libc/sys/madvise.2 index 2744bc6db..96df48c0f 100644 --- a/lib/libc/sys/madvise.2 +++ b/lib/libc/sys/madvise.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: madvise.2,v 1.26 2009/06/03 09:04:18 wiz Exp $ +.\" $NetBSD: madvise.2,v 1.27 2011/03/29 18:54:54 jruoho Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)madvise.2 8.1 (Berkeley) 6/9/93 .\" -.Dd June 2, 2009 +.Dd March 29, 2011 .Dt MADVISE 2 .Os .Sh NAME @@ -54,7 +54,7 @@ The interface is identical and is provided for standards conformance. .Pp The known behaviors are: -.Bl -tag -width MADV_NORMAL +.Bl -tag -width MADV_SEQUENTIAL .It Dv MADV_NORMAL Tells the system to revert to the default paging behavior. diff --git a/lib/libc/sys/makelintstub b/lib/libc/sys/makelintstub old mode 100755 new mode 100644 index e07388116..84b02d0e8 --- a/lib/libc/sys/makelintstub +++ b/lib/libc/sys/makelintstub @@ -1,5 +1,5 @@ #!/bin/sh - -# $NetBSD: makelintstub,v 1.23 2008/08/05 02:08:13 lukem Exp $ +# $NetBSD: makelintstub,v 1.25 2012/02/12 01:46:05 martin Exp $ # # Copyright (c) 1996, 1997 Christopher G. Demetriou # All rights reserved. @@ -74,11 +74,13 @@ header() #include #include #include + #include #include #include #include #include #include + #include #ifdef __STDC__ #include #else diff --git a/lib/libc/sys/mknod.2 b/lib/libc/sys/mknod.2 index 373a44bfe..befe96888 100644 --- a/lib/libc/sys/mknod.2 +++ b/lib/libc/sys/mknod.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: mknod.2,v 1.20 2010/05/31 12:16:20 njoly Exp $ +.\" $NetBSD: mknod.2,v 1.22 2011/07/08 19:25:51 wiz Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)mknod.2 8.1 (Berkeley) 6/4/93 .\" -.Dd January 18, 2007 +.Dd July 3, 2011 .Dt MKNOD 2 .Os .Sh NAME @@ -66,8 +66,30 @@ is set to indicate the error. .Fn mknod will fail and the file will be not created if: .Bl -tag -width Er -.It Bq Er ENOTDIR -A component of the path prefix is not a directory. +.It Bq Er EACCES +Search permission is denied for a component of the path prefix. +.It Bq Er EDQUOT +The directory in which the entry for the new node +is being placed cannot be extended because the +user's quota of disk blocks on the file system +containing the directory has been exhausted; or +the user's quota of inodes on the file system on +which the node is being created has been exhausted. +.It Bq Er EEXIST +The named file exists. +.It Bq Er EFAULT +.Fa path +points outside the process's allocated address space. +.It Bq Er EINVAL +The supplied +.Fa mode +or +.Fa dev +is invalid. +.It Bq Er EIO +An I/O error occurred while making the directory entry or allocating the inode. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. .It Bq Er ENAMETOOLONG A component of a pathname exceeded .Brq Dv NAME_MAX @@ -76,36 +98,18 @@ characters, or an entire path name exceeded characters. .It Bq Er ENOENT A component of the path prefix does not exist. -.It Bq Er EACCES -Search permission is denied for a component of the path prefix. -.It Bq Er ELOOP -Too many symbolic links were encountered in translating the pathname. -.It Bq Er EPERM -The process's effective user ID is not super-user. -.It Bq Er EIO -An I/O error occurred while making the directory entry or allocating the inode. .It Bq Er ENOSPC The directory in which the entry for the new node is being placed cannot be extended because there is no space left on the file -system containing the directory. -.It Bq Er ENOSPC -There are no free inodes on the file system on which the +system containing the directory; or +there are no free inodes on the file system on which the node is being created. -.It Bq Er EDQUOT -The directory in which the entry for the new node -is being placed cannot be extended because the -user's quota of disk blocks on the file system -containing the directory has been exhausted. -.It Bq Er EDQUOT -The user's quota of inodes on the file system on -which the node is being created has been exhausted. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. +.It Bq Er EPERM +The process's effective user ID is not super-user. .It Bq Er EROFS The named file resides on a read-only file system. -.It Bq Er EEXIST -The named file exists. -.It Bq Er EFAULT -.Fa path -points outside the process's allocated address space. .El .Sh SEE ALSO .Xr chmod 2 , diff --git a/lib/libc/sys/mlock.2 b/lib/libc/sys/mlock.2 index 51c4b2563..0f0ea2070 100644 --- a/lib/libc/sys/mlock.2 +++ b/lib/libc/sys/mlock.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: mlock.2,v 1.18 2004/05/13 10:20:58 wiz Exp $ +.\" $NetBSD: mlock.2,v 1.20 2011/02/28 07:17:02 wiz Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)mlock.2 8.2 (Berkeley) 12/11/93 .\" -.Dd June 2, 1993 +.Dd February 28, 2011 .Dt MLOCK 2 .Os .Sh NAME @@ -59,14 +59,7 @@ The call unlocks pages previously locked by one or more .Nm mlock calls. -For both, the -.Fa addr -parameter should be aligned to a multiple of the page size. -If the -.Fa len -parameter is not a multiple of the page size, it will be rounded up -to be so. -The entire range must be allocated. +The entire range of memory must be allocated. .Pp After an .Nm mlock @@ -99,6 +92,14 @@ a system-wide ``wired pages'' limit and the per-process .Li RLIMIT_MEMLOCK resource limit. +.Pp +Portable code should ensure that the +.Fa addr +and +.Fa len +parameters are aligned to a multiple of the page size, even though the +.Nx +implementation will round as necessary. .Sh RETURN VALUES A return value of 0 indicates that the call succeeded and all pages in the range have either been locked or unlocked. @@ -111,11 +112,12 @@ is set to indicate the error. .Fn mlock will fail if: .Bl -tag -width Er -.It Bq Er EINVAL -The address given is not page aligned or the length is negative. .It Bq Er EAGAIN Locking the indicated range would exceed either the system or per-process limit for locked memory. +.It Bq Er EINVAL +The length is negative; or the address or length given is not page +aligned and the implementation does not round. .It Bq Er ENOMEM Some portion of the indicated address range is not allocated. There was an error faulting/mapping a page. @@ -129,7 +131,8 @@ is not implemented. will fail if: .Bl -tag -width Er .It Bq Er EINVAL -The address given is not page aligned or the length is negative. +The length is negative; or the address or length given is not page +aligned and the implementation does not round. .It Bq Er ENOMEM Some portion of the indicated address range is not allocated. Some portion of the indicated address range is not locked. diff --git a/lib/libc/sys/mmap.2 b/lib/libc/sys/mmap.2 index 30e38c2cc..2b09be199 100644 --- a/lib/libc/sys/mmap.2 +++ b/lib/libc/sys/mmap.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: mmap.2,v 1.41 2009/02/27 16:48:02 wiz Exp $ +.\" $NetBSD: mmap.2,v 1.47 2012/01/05 15:19:52 reinoud Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)mmap.2 8.4 (Berkeley) 5/11/95 .\" -.Dd February 27, 2009 +.Dd December 20, 2011 .Dt MMAP 2 .Os .Sh NAME @@ -77,7 +77,7 @@ argument by .Em OR Ns 'ing the following values: .Pp -.Bl -tag -width PROT_WRITEXX +.Bl -tag -width PROT_WRITEXX -offset indent .It Dv PROT_EXEC Pages may be executed. .It Dv PROT_READ @@ -117,7 +117,7 @@ argument by .Em OR Ns 'ing the following values: .Pp -.Bl -tag -width MAP_HASSEMAPHOREXX +.Bl -tag -width MAP_HASSEMAPHOREXX -offset indent .It Dv MAP_ALIGNED(n) Request that the allocation be aligned to the given boundary. The parameter @@ -287,3 +287,13 @@ would exceed the offset maximum established in its open file description. .Xr munmap 2 , .Xr getpagesize 3 , .Xr sysconf 3 +.Sh STANDARDS +The +.Fn mmap +function conforms to +.St -p1003.1b-93 . +.Sh HISTORY +The +.Fn mmap +interface was first designed in +.Bx 4.2 . diff --git a/lib/libc/sys/mmap.c b/lib/libc/sys/mmap.c index 9b60fcd0f..a7dfc36b5 100644 --- a/lib/libc/sys/mmap.c +++ b/lib/libc/sys/mmap.c @@ -1,4 +1,4 @@ -/* $NetBSD: mmap.c,v 1.14 2007/11/23 12:39:15 uebayasi Exp $ */ +/* $NetBSD: mmap.c,v 1.15 2012/03/20 16:26:12 matt Exp $ */ /* * Copyright (c) 1992, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)mmap.c 8.1 (Berkeley) 6/17/93"; #else -__RCSID("$NetBSD: mmap.c,v 1.14 2007/11/23 12:39:15 uebayasi Exp $"); +__RCSID("$NetBSD: mmap.c,v 1.15 2012/03/20 16:26:12 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -55,13 +55,7 @@ void *__mmap(void *, size_t, int, int, int, int, off_t); * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ void * -mmap(addr, len, prot, flags, fd, offset) - void *addr; - size_t len; - int prot; - int flags; - int fd; - off_t offset; +mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { return __mmap(addr, len, prot, flags, fd, 0, offset); diff --git a/lib/libc/sys/modctl.2 b/lib/libc/sys/modctl.2 index d967e0da7..4c8e1ca0f 100644 --- a/lib/libc/sys/modctl.2 +++ b/lib/libc/sys/modctl.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: modctl.2,v 1.8 2010/12/14 16:23:59 jruoho Exp $ +.\" $NetBSD: modctl.2,v 1.9 2012/08/07 01:19:05 jnemeth Exp $ .\" .\" Copyright (c) 2009 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -24,7 +24,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd December 14, 2010 +.Dd August 3, 2012 .Dt MODCTL 2 .Os .Sh NAME @@ -44,8 +44,9 @@ The argument is one of .Dv MODCTL_LOAD , .Dv MODCTL_UNLOAD , +.Dv MODCTL_STAT , or -.Dv MODCTL_STAT . +.Dv MODCTL_EXISTS . The argument .Fa argp depends on the @@ -84,6 +85,24 @@ member of the .Em iovec to reflect the size of the complete report, regardless of whether this is larger or smaller than the size passed in. +.It Dv MODCTL_EXISTS +Test to see if the kernel was compiled with +.Dq options MODULAR +and whether or +not modules may be loaded at the moment. +In this case, +.Fa argp +should be an integer. +It should be +.Dq 0 +to test if a user can load a module via +.Dv MODCTL_LOAD , +or it should be +.Dq 1 +to test if the system can autoload modules. +Note that this +test does not consider the sysctl +.Li kern.module.autoload . .El .Ss Data Types The @@ -98,7 +117,8 @@ The name/path of the module to load. Zero or more of the following flag values: .Bl -tag -compact -width "MODCTL_LOAD_FORCE" .It Dv MODCTL_NO_PROP -Don't load \*[Lt]module\*[Gt].plist. +Don't load +.Ao module Ac Ns Pa .plist . .It Dv MODCTL_LOAD_FORCE Ignore kernel version mismatch. .El @@ -271,6 +291,7 @@ information. .El .Sh SEE ALSO .Xr module 7 , +.Xr sysctl 7 , .Xr module 9 .Sh HISTORY The diff --git a/lib/libc/sys/mount.2 b/lib/libc/sys/mount.2 index da131fde4..815124ebc 100644 --- a/lib/libc/sys/mount.2 +++ b/lib/libc/sys/mount.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: mount.2,v 1.45 2010/05/31 12:16:20 njoly Exp $ +.\" $NetBSD: mount.2,v 1.49 2011/11/18 21:04:21 christos Exp $ .\" .\" Copyright (c) 1980, 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)mount.2 8.3 (Berkeley) 5/24/95 .\" -.Dd April 10, 2009 +.Dd November 18, 2011 .Dt MOUNT 2 .Os .Sh NAME @@ -98,6 +98,10 @@ Do not interpret special files on the file system. Do not allow programs to dump core files on the file system. .It Dv MNT_NOATIME Never update access time in the file system. +.It Dv MNT_RELATIME +Update access time on write and change. +This helps programs that verify that the file has been read after written +to work. .It Dv MNT_NODEVMTIME Never update modification time of device files. .It Dv MNT_SYMPERM @@ -119,6 +123,10 @@ causes a journal (or log) to be created in the filesystem, creating a record of meta-data writes to be performed, allowing the actual writes to be deferred. This improves performance in most cases. +.It MNT_EXTATTR +Enable extended attributes, if the filesystem supports them and +does not enable them by default. +Currently this is only the case for UFS1. .El .Pp The diff --git a/lib/libc/sys/mprotect.2 b/lib/libc/sys/mprotect.2 index 7b0a4d4d6..bbf6adc0e 100644 --- a/lib/libc/sys/mprotect.2 +++ b/lib/libc/sys/mprotect.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: mprotect.2,v 1.22 2009/01/11 02:46:30 christos Exp $ +.\" $NetBSD: mprotect.2,v 1.24 2011/04/03 06:54:30 jruoho Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)mprotect.2 8.1 (Berkeley) 6/9/93 .\" -.Dd January 6, 2009 +.Dd April 3, 2011 .Dt MPROTECT 2 .Os .Sh NAME @@ -56,7 +56,7 @@ argument by .Tn OR Ns 'ing the following values: .Pp -.Bl -tag -width MAP_FIXEDX +.Bl -tag -width MAP_FIXEDX -offset indent .It Dv PROT_EXEC Pages may be executed. .It Dv PROT_READ @@ -84,7 +84,7 @@ flag. An invalid memory range, or invalid parameters were provided. .It Bq Er ENOMEM A resource shortage occurred while internally calling -.Fn uvm_map_protect . +.Xr uvm_map_protect 9 . .El .Sh SEE ALSO .Xr madvise 2 , diff --git a/lib/libc/sys/mremap.2 b/lib/libc/sys/mremap.2 index ef13e72a8..bbd2b0c84 100644 --- a/lib/libc/sys/mremap.2 +++ b/lib/libc/sys/mremap.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: mremap.2,v 1.3 2008/02/16 17:45:39 tnn Exp $ +.\" $NetBSD: mremap.2,v 1.4 2011/04/28 12:00:55 wiz Exp $ .\" .\" Copyright (c) 2007 Thomas Klausner and Joerg Sonnenberger .\" All rights reserved. @@ -88,14 +88,6 @@ are used as hints for the position, factoring in the given alignment. returns the new address or .Dv MAP_FAILED , if the remap failed. -.Sh HISTORY -The -.Fn mremap -system call appeared in -.Nx 5.0 . -It was based on the code that supports -.Fn mremap -compatibility for Linux binaries. .Sh COMPATIBILITY The semantics of .Fn mremap @@ -107,3 +99,11 @@ are implemented. .Sh SEE ALSO .Xr mmap 2 , .Xr munmap 2 +.Sh HISTORY +The +.Fn mremap +system call appeared in +.Nx 5.0 . +It was based on the code that supports +.Fn mremap +compatibility for Linux binaries. diff --git a/lib/libc/sys/msgrcv.2 b/lib/libc/sys/msgrcv.2 index ce594db0a..7538eeb51 100644 --- a/lib/libc/sys/msgrcv.2 +++ b/lib/libc/sys/msgrcv.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: msgrcv.2,v 1.19 2009/01/28 08:57:02 wiz Exp $ +.\" $NetBSD: msgrcv.2,v 1.20 2012/05/15 11:37:01 reinoud Exp $ .\" .\" Copyright (c) 1995 Frank van der Linden .\" All rights reserved. @@ -153,7 +153,7 @@ is decremented by 1. .Sh RETURN VALUES Upon successful completion, .Fn msgrcv -returns the number of bytes received into the +returns the number of bytes received and placed into the .Va mtext field of the structure pointed to by .Fa msgp . diff --git a/lib/libc/sys/msync.2 b/lib/libc/sys/msync.2 index 144c631e0..04a7fa053 100644 --- a/lib/libc/sys/msync.2 +++ b/lib/libc/sys/msync.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: msync.2,v 1.23 2005/10/18 03:18:16 chs Exp $ +.\" $NetBSD: msync.2,v 1.24 2011/10/15 21:35:50 rmind Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -120,6 +120,11 @@ which are unmapped. .Xr mlock 2 , .Xr mmap 2 , .Xr munlock 2 +.Sh STANDARDS +The +.Fn msync +function conforms to +.St -p1003.1b-93 .Sh HISTORY The .Fn msync diff --git a/lib/libc/sys/munmap.2 b/lib/libc/sys/munmap.2 index b8bc741e1..0325042e2 100644 --- a/lib/libc/sys/munmap.2 +++ b/lib/libc/sys/munmap.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: munmap.2,v 1.19 2004/05/13 10:20:58 wiz Exp $ +.\" $NetBSD: munmap.2,v 1.20 2011/10/15 21:35:50 rmind Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -76,6 +76,11 @@ valid address range for a process. .Xr mprotect 2 , .Xr msync 2 , .Xr getpagesize 3 +.Sh STANDARDS +The +.Fn munmap +function conforms to +.St -p1003.1b-93 . .Sh HISTORY The .Fn munmap diff --git a/lib/libc/sys/nanosleep.2 b/lib/libc/sys/nanosleep.2 index 1838e2976..cb13cb89b 100644 --- a/lib/libc/sys/nanosleep.2 +++ b/lib/libc/sys/nanosleep.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: nanosleep.2,v 1.11 2010/05/17 07:22:03 jruoho Exp $ +.\" $NetBSD: nanosleep.2,v 1.13 2012/10/08 18:08:40 njoly Exp $ .\" .\" Copyright (c) 1986, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)sleep.3 8.1 (Berkeley) 6/4/93 .\" -.Dd May 17, 2010 +.Dd October 1, 2012 .Dt NANOSLEEP 2 .Os .Sh NAME @@ -40,31 +40,78 @@ .Sh SYNOPSIS .In time.h .Ft int +.Fn clock_nanosleep "clockid_t clock_id" "int flags" "const struct timespec *rqtp" "struct timespec *rmtp" +.Ft int .Fn nanosleep "const struct timespec *rqtp" "struct timespec *rmtp" .Sh DESCRIPTION -The -.Fn nanosleep -suspends execution of the calling process until either the number of -seconds and nanoseconds specified by +If the +.Dv TIMER_ABSTIME +flag is not set in the +.Fa flags +argument, then +.Fn clock_nanosleep +suspends execution of the calling thread until either the number of +seconds and nanoseconds specified in the +.Fa rqtp +argument have elapsed using the clock in the +.Fa clock_id +argument, or a signal is delivered to the calling process and its +action is to invoke a signal catching function or to terminate the +process. +.Pp +If the +.Dv TIMER_ABSTIME +flag is set in the +.Fa flags +argument, then +.Fn clock_nanosleep +suspends execution of the calling thread until either the value +of the clock specified in the +.Fa clock_id +argument reaches the value of the .Fa rqtp -have elapsed or a signal is delivered to the calling process and its +argument in seconds and nanoseconds, +or a signal is delivered to the calling process and its action is to invoke a signal catching function or to terminate the process. +.Pp The suspension time may be longer than requested due to the scheduling of other activity by the system. +.Pp +The +.Fn nanosleep +function behaves like +.Fn clock_nanosleep +with the +.Fa clock_id +argument equal to +.Dv CLOCK_MONOTONIC +and the +.Fa flags +argument having +.Dv TIMER_ABSTIME +not set. +.Pp The .Em struct timespec is described in .Xr timespec 3 . +The +.Fa clock_id +specified is the time source. .Sh RETURN VALUES If the +.Fn clock_nanosleep +or the .Fn nanosleep -function returns because the requested time has elapsed, the value +functions return because the requested time has elapsed, the value returned will be zero. .Pp If the +.Fn clock_nanosleep +or the .Fn nanosleep -function returns due to the delivery of a signal, the value returned +functions return due to the delivery of a signal, the value returned will be the \-1, and the global variable .Va errno will be set to indicate the interruption. @@ -97,6 +144,12 @@ specified a nanosecond value less than zero or greater than 1000 million. .It Bq Er ENOSYS .Nm is not supported by this implementation. +.It Bq Er ENOTSUP +for +.Fn clock_nanosleep , +the clock specified in the +.Fa clock_id +argument is not supported. .El .Sh SEE ALSO .Xr sleep 3 , @@ -106,3 +159,7 @@ The .Fn nanosleep function conforms to .St -p1003.1b-93 . +The +.Fn clock_nanosleep +function conforms to +.St -p1003.1j-2000 . diff --git a/lib/libc/sys/ntp_adjtime.c b/lib/libc/sys/ntp_adjtime.c index a7d8fb892..d0ef35fb9 100644 --- a/lib/libc/sys/ntp_adjtime.c +++ b/lib/libc/sys/ntp_adjtime.c @@ -1,4 +1,4 @@ -/* $NetBSD: ntp_adjtime.c,v 1.11 2007/11/23 12:39:15 uebayasi Exp $ */ +/* $NetBSD: ntp_adjtime.c,v 1.13 2012/03/20 16:26:12 matt Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: ntp_adjtime.c,v 1.11 2007/11/23 12:39:15 uebayasi Exp $"); +__RCSID("$NetBSD: ntp_adjtime.c,v 1.13 2012/03/20 16:26:12 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -55,13 +55,16 @@ __RCSID("$NetBSD: ntp_adjtime.c,v 1.11 2007/11/23 12:39:15 uebayasi Exp $"); __weak_alias(ntp_adjtime,_ntp_adjtime) #endif +#if defined(__minix) && !defined(O_CLOEXEC) +#define O_CLOEXEC 0 +#endif + extern int __clockctl_fd; int __ntp_adjtime(struct timex *); int -ntp_adjtime(tp) - struct timex *tp; +ntp_adjtime(struct timex *tp) { struct clockctl_ntp_adjtime args; int error; @@ -87,14 +90,12 @@ ntp_adjtime(tp) * and we cannot open clockctl. This is a true * failure. */ - __clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY, 0); + __clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY | O_CLOEXEC, 0); if (__clockctl_fd == -1) { /* original error was EPERM - don't leak open errors */ errno = EPERM; return -1; } - - (void) fcntl(__clockctl_fd, F_SETFD, FD_CLOEXEC); } /* diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2 index 1e5fb444f..5556ac890 100644 --- a/lib/libc/sys/open.2 +++ b/lib/libc/sys/open.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: open.2,v 1.47 2010/09/22 17:58:09 wiz Exp $ +.\" $NetBSD: open.2,v 1.51 2012/01/25 00:28:35 christos Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)open.2 8.2 (Berkeley) 11/16/93 .\" -.Dd September 22, 2010 +.Dd January 23, 2012 .Dt OPEN 2 .Os .Sh NAME @@ -40,7 +40,7 @@ .Sh SYNOPSIS .In fcntl.h .Ft int -.Fn open "const char *path" "int flags" "mode_t mode" +.Fn open "const char *path" "int flags" "..." .Sh DESCRIPTION The file name specified by .Fa path @@ -56,7 +56,7 @@ are specified by the values listed below. Applications must specify exactly one of the first three values (file access methods): -.Bl -tag -offset indent -width O_NONBLOCK +.Bl -tag -offset indent -width O_DIRECTORY .It Dv O_RDONLY Open for reading only. .It Dv O_WRONLY @@ -66,16 +66,16 @@ Open for reading and writing. .El .Pp Any combination of the following may be used: -.Bl -tag -offset indent -width O_NONBLOCK +.Bl -tag -offset indent -width O_DIRECTORY .It Dv O_NONBLOCK Do not block on open or for data to become available. .It Dv O_APPEND Append to the file on each write. .It Dv O_CREAT -Create the file if it does not exist, in which case the file is -created with mode -.Ar mode -as described in +Create the file if it does not exist. +The third argument of type +.Ft mode_t +is used to compute the mode bits of the file as described in .Xr chmod 2 and modified by the process' umask value (see .Xr umask 2 ) . @@ -93,6 +93,17 @@ Atomically obtain an exclusive lock. If last path element is a symlink, don't follow it. This option is provided for compatibility with other operating systems, but its security value is questionable. +.It Dv O_CLOEXEC +Set the +.Xr close 2 +on +.Xr exec 3 +flag. +.It Dv O_NOSIGPIPE +Return +.Er EPIPE +instead of raising +.Dv SIGPIPE . .It Dv O_DSYNC If set, write operations will be performed according to synchronized I/O data integrity completion: @@ -147,6 +158,12 @@ using an interface that supports scatter/gather via struct iovec, each element of the request must meet the above alignment constraints. .It Dv O_DIRECTORY Fail if the file is not a directory. +.It Dv O_ASYNC +Enable the +.Dv SIGIO +signal to be sent to the process group +when I/O is possible, e.g., +upon availability of data to be read. .El .Pp Opening a file with diff --git a/lib/libc/sys/pipe.2 b/lib/libc/sys/pipe.2 index 98dac5a51..a3e3e330a 100644 --- a/lib/libc/sys/pipe.2 +++ b/lib/libc/sys/pipe.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: pipe.2,v 1.22 2004/05/13 10:20:58 wiz Exp $ +.\" $NetBSD: pipe.2,v 1.28 2012/01/25 00:28:35 christos Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)pipe.2 8.1 (Berkeley) 6/4/93 .\" -.Dd July 17, 1994 +.Dd January 23, 2012 .Dt PIPE 2 .Os .Sh NAME @@ -41,6 +41,8 @@ .In unistd.h .Ft int .Fn pipe "int fildes[2]" +.Ft int +.Fn pipe2 "int fildes[2]" "int flags" .Sh DESCRIPTION The .Fn pipe @@ -78,6 +80,29 @@ signal. Widowing a pipe is the only way to deliver end-of-file to a reader: after the reader consumes any buffered data, reading a widowed pipe returns a zero count. +.Pp +The +.Fn pipe2 +function +behaves exactly like +.Fn pipe +only it allows extra +.Fa flags +to be set on the returned file descriptor. +The following flags are valid: +.Bl -tag -width O_NONBLOCK -offset indent +.It Dv O_CLOEXEC +Set the +.Dq close-on-exec +property. +.It Dv O_NONBLOCK +Sets non-blocking I/O. +.It Dv O_NOSIGPIPE +Return +.Er EPIPE +instead of raising +.Dv SIGPIPE . +.El .Sh RETURN VALUES On successful creation of the pipe, zero is returned. Otherwise, a value of \-1 is returned and the variable @@ -87,12 +112,10 @@ error. .Sh ERRORS The .Fn pipe -call will fail if: +and +.Fn pipe2 +calls will fail if: .Bl -tag -width Er -.It Bq Er EMFILE -Too many descriptors are active. -.It Bq Er ENFILE -The system file table is full. .It Bq Er EFAULT The .Fa fildes @@ -100,6 +123,21 @@ buffer is in an invalid area of the process's address space. The reliable detection of this error cannot be guaranteed; when not detected, a signal may be delivered to the process, indicating an address violation. +.It Bq Er EMFILE +Too many descriptors are active. +.It Bq Er ENFILE +The system file table is full. +.El +.Pp +.Fn pipe2 +will also fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +.Fa flags +is other than +.Dv O_NONBLOCK +or +.Dv O_CLOEXEC . .El .Sh SEE ALSO .Xr sh 1 , @@ -117,3 +155,7 @@ A .Fn pipe function call appeared in .At v6 . +The +.Fn pipe2 +function is inspired from Linux and appeared in +.Nx 6.0 . diff --git a/lib/libc/sys/preadv.c b/lib/libc/sys/preadv.c index e09d1731a..dbe8a010d 100644 --- a/lib/libc/sys/preadv.c +++ b/lib/libc/sys/preadv.c @@ -1,4 +1,4 @@ -/* $NetBSD: preadv.c,v 1.6 2007/11/23 12:39:15 uebayasi Exp $ */ +/* $NetBSD: preadv.c,v 1.7 2012/03/20 16:26:12 matt Exp $ */ /* * Copyright (c) 1992, 1993 @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: preadv.c,v 1.6 2007/11/23 12:39:15 uebayasi Exp $"); +__RCSID("$NetBSD: preadv.c,v 1.7 2012/03/20 16:26:12 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -46,11 +46,7 @@ ssize_t __preadv(int, const struct iovec *, int, int, off_t); * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ ssize_t -preadv(fd, iovp, iovcnt, offset) - int fd; - const struct iovec *iovp; - int iovcnt; - off_t offset; +preadv(int fd, const struct iovec *iovp, int iovcnt, off_t offset) { return __preadv(fd, iovp, iovcnt, 0, offset); diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2 index 25c501ba1..7548e92bd 100644 --- a/lib/libc/sys/ptrace.2 +++ b/lib/libc/sys/ptrace.2 @@ -1,7 +1,7 @@ -.\" $NetBSD: ptrace.2,v 1.34 2010/04/14 08:57:21 jruoho Exp $ +.\" $NetBSD: ptrace.2,v 1.35 2011/08/31 23:04:33 jmcneill Exp $ .\" .\" This file is in the public domain. -.Dd April 14, 2010 +.Dd August 31, 2011 .Dt PTRACE 2 .Os .Sh NAME @@ -301,6 +301,9 @@ argument should contain .Dq Li "sizeof(struct ptrace_lwpinfo)" . .It Dv PT_SYSCALL Stops a process before and after executing each system call. +.It Dv PT_SYSCALLEMU +Intercept and ignore a system call before it has been executed, for use with +.Dv PT_SYSCALL . .El .Pp Additionally, the following requests exist but are diff --git a/lib/libc/sys/pwritev.c b/lib/libc/sys/pwritev.c index bb7918b31..fd627be0a 100644 --- a/lib/libc/sys/pwritev.c +++ b/lib/libc/sys/pwritev.c @@ -1,4 +1,4 @@ -/* $NetBSD: pwritev.c,v 1.6 2007/11/23 12:39:16 uebayasi Exp $ */ +/* $NetBSD: pwritev.c,v 1.7 2012/03/20 16:26:12 matt Exp $ */ /* * Copyright (c) 1992, 1993 @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: pwritev.c,v 1.6 2007/11/23 12:39:16 uebayasi Exp $"); +__RCSID("$NetBSD: pwritev.c,v 1.7 2012/03/20 16:26:12 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -46,11 +46,7 @@ ssize_t __pwritev(int, const struct iovec *, int, int, off_t); * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ ssize_t -pwritev(fd, iovp, iovcnt, offset) - int fd; - const struct iovec *iovp; - int iovcnt; - off_t offset; +pwritev(int fd, const struct iovec *iovp, int iovcnt, off_t offset) { return __pwritev(fd, iovp, iovcnt, 0, offset); diff --git a/lib/libc/sys/quotactl.2 b/lib/libc/sys/quotactl.2 deleted file mode 100644 index b84777e45..000000000 --- a/lib/libc/sys/quotactl.2 +++ /dev/null @@ -1,213 +0,0 @@ -.\" $NetBSD: quotactl.2,v 1.26 2010/05/31 12:16:20 njoly Exp $ -.\" -.\" Copyright (c) 1983, 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Robert Elz at The University of Melbourne. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)quotactl.2 8.2 (Berkeley) 3/10/95 -.\" -.Dd October 9, 2008 -.Dt QUOTACTL 2 -.Os -.Sh NAME -.Nm quotactl -.Nd manipulate filesystem quotas -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In ufs/ufs/quota.h -.Ft int -.Fn quotactl "const char *path" "int cmd" "int id" "void *addr" -.Sh DESCRIPTION -The -.Fn quotactl -call enables, disables and -manipulates filesystem quotas. -A quota control command -given by -.Fa cmd -operates on the given filename -.Fa path -for the given user -.Fa id . -The address of an optional command specific data structure, -.Fa addr , -may be given; its interpretation -is discussed below with each command. -.Pp -Currently quotas are supported only for the ``ffs'' -and ``lfs'' filesystem. -For both of them, -a command is composed of a primary command (see below) -and a command type used to interpret the -.Fa id . -Types are supported for interpretation of user identifiers -and group identifiers. -The ``ffs'' and ``lfs'' specific commands are: -.Bl -tag -width Q_QUOTAON -.It Dv Q_QUOTAON -Enable disk quotas for the filesystem specified by -.Fa path . -The command type specifies the type of the quotas being enabled. -The -.Fa addr -argument specifies a file from which to take the quotas. -The quota file must exist; -it is normally created with the -.Xr quotacheck 8 -program. -The -.Fa id -argument is unused. -Only the super-user may turn quotas on. -.It Dv Q_QUOTAOFF -Disable disk quotas for the filesystem specified by -.Fa path . -The command type specifies the type of the quotas being disabled. -The -.Fa addr -and -.Fa id -arguments are unused. -Only the super-user may turn quotas off. -.It Dv Q_GETQUOTA -Get disk quota limits and current usage for the user or group -(as determined by the command type) with identifier -.Fa id . -.Fa addr -is a pointer to a -.Fa struct dqblk -structure (defined in -.In ufs/ufs/quota.h ) . -.It Dv Q_SETQUOTA -Set disk quota limits for the user or group -(as determined by the command type) with identifier -.Fa id . -.Fa addr -is a pointer to a -.Fa struct dqblk -structure (defined in -.In ufs/ufs/quota.h ) . -The usage fields of the -.Fa dqblk -structure are ignored. -This call is restricted to the super-user. -.It Dv Q_SETUSE -Set disk usage for the user or group -(as determined by the command type) with identifier -.Fa id . -.Fa addr -is a pointer to a -.Fa struct dqblk -structure (defined in -.In ufs/ufs/quota.h ) . -Only the usage fields are used. -This call is restricted to the super-user. -.It Dv Q_SYNC -Update the on-disk copy of quota usages. -The command type specifies which type of quotas are to be updated. -The -.Fa id -and -.Fa addr -parameters are ignored. -.El -.Sh RETURN VALUES -A successful call returns 0, -otherwise the value \-1 is returned and the global variable -.Va errno -indicates the reason for the failure. -.Sh ERRORS -A -.Fn quotactl -call will fail if: -.Bl -tag -width Er -.It Bq Er EOPNOTSUPP -The kernel has not been compiled with the -.Dv QUOTA -option. -.It Bq Er EUSERS -The quota table cannot be expanded. -.It Bq Er EINVAL -.Fa cmd -or the command type is invalid. -.It Bq Er EACCES -In -.Dv Q_QUOTAON , -the quota file is not a plain file, or -search permission is denied for a component of a path prefix. -.It Bq Er ENOTDIR -A component of a path prefix was not a directory. -.It Bq Er ENAMETOOLONG -A component of a pathname exceeded -.Brq Dv NAME_MAX -characters, or an entire path name exceeded -.Brq Dv PATH_MAX -characters. -.It Bq Er ENOENT -A filename does not exist. -.It Bq Er ELOOP -Too many symbolic links were encountered in translating a pathname. -.It Bq Er EROFS -In -.Dv Q_QUOTAON , -the quota file resides on a read-only filesystem. -.It Bq Er EIO -An -.Tn I/O -error occurred while reading from or writing -to a file containing quotas. -.It Bq Er EFAULT -.Fa path -points outside the process's allocated address space, or -an invalid -.Fa addr -was supplied; the associated structure could not be copied in or out -of the kernel. -.It Bq Er EPERM -The call was privileged and the caller was not the super-user. -.El -.Sh SEE ALSO -.Xr quota 1 , -.Xr fstab 5 , -.Xr edquota 8 , -.Xr quotacheck 8 , -.Xr quotaon 8 , -.Xr repquota 8 -.Sh HISTORY -The -.Fn quotactl -function call appeared in -.Bx 4.3 Reno . -.Sh BUGS -There should be some way to integrate this call with the resource -limit interface provided by -.Xr setrlimit 2 -and -.Xr getrlimit 2 . diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2 index 88915040b..4a8d9a28d 100644 --- a/lib/libc/sys/read.2 +++ b/lib/libc/sys/read.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: read.2,v 1.33 2010/04/05 07:53:47 wiz Exp $ +.\" $NetBSD: read.2,v 1.34 2011/12/12 19:11:21 njoly Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)read.2 8.4 (Berkeley) 2/26/94 .\" -.Dd April 3, 2010 +.Dd December 12, 2011 .Dt READ 2 .Os .Sh NAME @@ -161,6 +161,16 @@ the total length of the I/O is more than can be expressed by the ssize_t return value. .It Bq Er EIO An I/O error occurred while reading from the file system. +.It Bq Er EISDIR +.Fa d +refers to a directory and the implementation does not allow the directory +to be read using +.Fn read +or +.Fn pread . +The +.Fn readdir +function should be used instead. .El .Pp In addition, diff --git a/lib/libc/sys/recv.2 b/lib/libc/sys/recv.2 index 134cdb17d..e0724ca26 100644 --- a/lib/libc/sys/recv.2 +++ b/lib/libc/sys/recv.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: recv.2,v 1.27 2006/04/23 19:06:59 wiz Exp $ +.\" $NetBSD: recv.2,v 1.35 2012/06/23 05:47:50 dholland Exp $ .\" .\" Copyright (c) 1983, 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,13 +29,14 @@ .\" .\" @(#)recv.2 8.3 (Berkeley) 2/21/94 .\" -.Dd April 23, 2006 +.Dd June 22, 2012 .Dt RECV 2 .Os .Sh NAME .Nm recv , .Nm recvfrom , -.Nm recvmsg +.Nm recvmsg , +.Nm recvmmsg .Nd receive a message from a socket .Sh LIBRARY .Lb libc @@ -47,10 +48,13 @@ .Fn recvfrom "int s" "void * restrict buf" "size_t len" "int flags" "struct sockaddr * restrict from" "socklen_t * restrict fromlen" .Ft ssize_t .Fn recvmsg "int s" "struct msghdr *msg" "int flags" +.Ft int +.Fn recvmmsg "int s" "struct mmsghdr *mmsg" "unsigned int vlen" "unsigned int flags" "struct timespec *timeout" .Sh DESCRIPTION -.Fn recvfrom -and +.Fn recvfrom , .Fn recvmsg +and +.Fn recvmmsg are used to receive messages from a socket, and may be used to receive data on a socket whether or not it is connection-oriented. @@ -67,6 +71,52 @@ and modified on return to indicate the actual size of the address stored there. .Pp The +.Fn recvmmsg +call be used to receive multiple messages in the same call using an array of +.Fa mmsghdr +elements with the following form, as defined in +.Ao Pa sys/socket.h Ac : +.Pp +.Bd -literal +struct mmsghdr { + struct msghdr msg_hdr; /* the message to be sent */ + unsigned int msg_len; /* number of bytes received */ +}; +.Ed +.Pp +The +.Fa msg_len +member contains the number of bytes received for each +.Fa msg_hdr +member. +The array has +.Fa vlen +elements, which is limited to +.Dv 1024 . +If there is an error, a number fewer than +.Fa vlen +may be returned, and the error may be retrieved using +.Xr getsockopt 2 +with +.Dv SO_ERROR . +If the flag +.Dv MSG_WAITFORONE +is set in +.Fa flags +then the +.Fn recvmmsg +call will wait for one message, and set +.Dv MSG_DONTWAIT +for the rest. +If the +.Fa timeout +parameter is not +.Dv NULL , +then +.Fn recvmmsg +will return if that time is exceeded. +.Pp +The .Fn recv call is normally used only on a .Em connected @@ -79,8 +129,14 @@ with a nil parameter. As it is redundant, it may not be supported in future releases. .Pp -All three routines return the length of the message on successful +.Fn recv , +.Fn recvfrom +and +.Fn recvmsg +routines return the length of the message on successful completion. +.Fn recvmmsg +returns the number of messages received. If a message is too long to fit in the supplied buffer, excess bytes may be discarded depending on the type of socket the message is received from (see @@ -95,6 +151,8 @@ in which case the value .Va errno set to .Er EAGAIN . +If no data is available and the remote peer was shut down, +0 is returned. The receive calls normally return any data available, up to the requested amount, rather than waiting for receipt of the full amount requested; @@ -116,7 +174,8 @@ The argument to a recv call is formed by .Em or Ap ing one or more of the values: -.Bl -column MSG_WAITALL -offset indent +.Bl -column MSG_CMSG_CLOEXEC -offset indent +.It Dv MSG_CMSG_CLOEXEC Ta set the close on exec property for passed file descriptors .It Dv MSG_OOB Ta process out-of-band data .It Dv MSG_PEEK Ta peek at incoming message .It Dv MSG_WAITALL Ta wait for full request or error @@ -228,15 +287,40 @@ for ancillary data. .Dv MSG_OOB is returned to indicate that expedited or out-of-band data were received. .Sh RETURN VALUES -These calls return the number of bytes received, or \-1 +The +.Fn recv , +.Fn recvfrom +and +.Fn recvmsg +calls return the number of bytes received, or \-1 +if an error occurred. +For connected sockets whose remote peer was shut down, +0 is returned when no more data is available. +The +.Fn recvmmsg +calls return the number of messages received, or \-1 if an error occurred. .Sh ERRORS The calls fail if: .Bl -tag -width Er +.It Bq Er EAGAIN +The socket is marked non-blocking, and the receive operation +would block, or +a receive timeout had been set, +and the timeout expired before data were received. .It Bq Er EBADF The argument .Fa s is an invalid descriptor. +.It Bq Er EFAULT +The receive buffer pointer(s) point outside the process's +address space. +.It Bq Er EINTR +The receive was interrupted by delivery of a signal before +any data were available. +.It Bq Er EINVAL +The total length of the I/O is more than can be expressed by the ssize_t +return value. .It Bq Er ENOTCONN The socket is associated with a connection-oriented protocol and has not been connected (see @@ -247,20 +331,6 @@ and The argument .Fa s does not refer to a socket. -.It Bq Er EAGAIN -The socket is marked non-blocking, and the receive operation -would block, or -a receive timeout had been set, -and the timeout expired before data were received. -.It Bq Er EINTR -The receive was interrupted by delivery of a signal before -any data were available. -.It Bq Er EFAULT -The receive buffer pointer(s) point outside the process's -address space. -.It Bq Er EINVAL -The total length of the I/O is more than can be expressed by the ssize_t -return value. .El .Pp .Fn recvmsg @@ -287,3 +357,9 @@ The .Fn recv function call appeared in .Bx 4.2 . +The +.Fn recvmmsg +function call appeared in +.Tn Linux 2.6.32 +and +.Nx 7.0 . diff --git a/lib/libc/sys/revoke.2 b/lib/libc/sys/revoke.2 index b7f3e28da..2ea279c6f 100644 --- a/lib/libc/sys/revoke.2 +++ b/lib/libc/sys/revoke.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: revoke.2,v 1.12 2003/08/07 16:44:05 agc Exp $ +.\" $NetBSD: revoke.2,v 1.15 2011/07/08 19:26:19 wiz Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)revoke.2 8.1 (Berkeley) 6/4/93 .\" -.Dd March 22, 1999 +.Dd July 3, 2011 .Dt REVOKE 2 .Os .Sh NAME @@ -46,17 +46,17 @@ .Fn revoke "const char *path" .Sh DESCRIPTION The -.Nm revoke +.Fn revoke function invalidates all current open file descriptors in the system for the file named by .Fa path . Subsequent operations on any such descriptors fail, with the exceptions that a -.Fn read +.Xr read 2 from a character device file which has been revoked returns a count of zero (end of file), and a -.Fn close +.Xr close 2 call will succeed. If the file is a special file for a device which is open, the device close function @@ -64,8 +64,9 @@ is called as if all open references to the file had been closed. .Pp Access to a file may be revoked only by its owner or the super user. .Pp -.Nm revoke -is normally used to prepare a terminal device for a new login session, +The +.Fn revoke +function is normally used to prepare a terminal device for a new login session, preventing any access by a previous user of the terminal. .Sh RETURN VALUES A 0 value indicates that the call succeeded. @@ -75,20 +76,20 @@ is set to indicate the reason. .Sh ERRORS Access to the named file is revoked unless one of the following: .Bl -tag -width Er -.It Bq Er ENOTDIR -A component of the path prefix is not a directory. -.It Bq Er ENAMETOOLONG -A component of a pathname exceeded 255 characters, -or an entire path name exceeded 1024 characters. -.It Bq Er ENOENT -The named file or a component of the path name does not exist. .It Bq Er EACCES Search permission is denied for a component of the path prefix. -.It Bq Er ELOOP -Too many symbolic links were encountered in translating the pathname. .It Bq Er EFAULT .Fa path points outside the process's allocated address space. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded 255 characters, +or an entire path name exceeded 1024 characters. +.It Bq Er ENOENT +The named file or a component of the path name does not exist. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. .It Bq Er EPERM The caller is neither the owner of the file nor the super user. .El @@ -102,6 +103,6 @@ The caller is neither the owner of the file nor the super user. .Xr write 2 .Sh HISTORY The -.Nm revoke +.Fn revoke function was introduced in .Bx 4.3 Reno . diff --git a/lib/libc/sys/sched.c b/lib/libc/sys/sched.c index 3d143db16..51553b35b 100644 --- a/lib/libc/sys/sched.c +++ b/lib/libc/sys/sched.c @@ -1,4 +1,4 @@ -/* $NetBSD: sched.c,v 1.2 2008/10/31 00:29:19 rmind Exp $ */ +/* $NetBSD: sched.c,v 1.4 2012/03/18 02:04:39 christos Exp $ */ /* * Copyright (c) 2008, Mindaugas Rasiukevicius @@ -27,12 +27,13 @@ */ #include -__RCSID("$NetBSD: sched.c,v 1.2 2008/10/31 00:29:19 rmind Exp $"); +__RCSID("$NetBSD: sched.c,v 1.4 2012/03/18 02:04:39 christos Exp $"); #include #include #include #include +#include #include #include @@ -104,7 +105,7 @@ sched_get_priority_max(int policy) errno = EINVAL; return -1; } - return sysconf(_SC_SCHED_PRI_MAX); + return (int)sysconf(_SC_SCHED_PRI_MAX); } int @@ -115,7 +116,7 @@ sched_get_priority_min(int policy) errno = EINVAL; return -1; } - return sysconf(_SC_SCHED_PRI_MIN); + return (int)sysconf(_SC_SCHED_PRI_MIN); } int @@ -123,6 +124,8 @@ int sched_rr_get_interval(pid_t pid, struct timespec *interval) { + if (pid && kill(pid, 0) == -1) + return -1; interval->tv_sec = 0; interval->tv_nsec = sysconf(_SC_SCHED_RT_TS) * 1000; return 0; diff --git a/lib/libc/sys/send.2 b/lib/libc/sys/send.2 index fe468af7a..937102598 100644 --- a/lib/libc/sys/send.2 +++ b/lib/libc/sys/send.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: send.2,v 1.27 2008/05/09 15:52:50 christos Exp $ +.\" $NetBSD: send.2,v 1.30 2012/06/22 22:54:26 wiz Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,13 +29,14 @@ .\" .\" @(#)send.2 8.2 (Berkeley) 2/21/94 .\" -.Dd May 9, 2008 +.Dd June 22, 2012 .Dt SEND 2 .Os .Sh NAME .Nm send , .Nm sendto , -.Nm sendmsg +.Nm sendmsg , +.Nm sendmmsg .Nd send a message from a socket .Sh LIBRARY .Lb libc @@ -47,21 +48,55 @@ .Fn sendto "int s" "const void *msg" "size_t len" "int flags" "const struct sockaddr *to" "socklen_t tolen" .Ft ssize_t .Fn sendmsg "int s" "const struct msghdr *msg" "int flags" +.Ft int +.Fn sendmmsg "int s" "struct mmsghdr *mmsg" "unsigned int vlen" "unsigned int flags" .Sh DESCRIPTION .Fn send , .Fn sendto , +.Fn sendmsg , and -.Fn sendmsg +.Fn sendmmsg are used to transmit a message to another socket. .Fn send may be used only when the socket is in a .Em connected state, while -.Fn sendto -and +.Fn sendto , .Fn sendmsg +and +.Fn sendmmsg may be used at any time. .Pp +The +.Fn sendmmsg +call be used to send multiple messages in the same call using an array of +.Fa mmsghdr +elements with the following form, as defined in +.Ao Pa sys/socket.h Ac : +.Pp +.Bd -literal +struct mmsghdr { + struct msghdr msg_hdr; /* the message to be sent */ + unsigned int msg_len; /* number of bytes transmitted */ +}; +.Ed +.Pp +The +.Fa msg_len +member contains the number of bytes sent for each +.Fa msg_hdr +member. +The array has +.Fa vlen +elements, which is limited to +.Dv 1024 . +If there is an error, a number fewer than +.Fa vlen +may be returned, and the error may be retrieved using +.Xr getsockopt 2 +with +.Dv SO_ERROR . +.Pp The address of the target is given by .Fa to with @@ -90,6 +125,9 @@ or .Xr poll 2 call may be used to determine when it is possible to send more data. +Unfortunately this does not work when the interface queue which is used to +send the message is full, and the call returns +.Er ENOBUFS . .Pp The .Fa flags @@ -139,53 +177,63 @@ is used to prevent generation when writing a socket that may be closed. .Sh RETURN VALUES -The call returns the number of characters sent, or \-1 +The +.Fn send , +.Fn sendto , +and +.Fn sendmsg +calls return the number of characters sent, or \-1 if an error occurred. +The +.Fn sendmmsg +call returns the number of messages sent, or \-1 +if an error occured. .Sh ERRORS .Fn send , .Fn sendto , +.Fn sendmsg , and -.Fn sendmsg +.Fn sendmmsg fail if: .Bl -tag -width Er +.It Bq Er EACCES +The SO_BROADCAST option is not set on the socket, and a broadcast address +was given as the destination. +.It Bq Er EAFNOSUPPORT +Addresses in the specified address family cannot be used with this socket. +.It Bq Er EAGAIN|EWOULDBLOCK +The socket is marked non-blocking and the requested operation +would block. .It Bq Er EBADF An invalid descriptor was specified. -.It Bq Er ENOTSOCK -The argument -.Fa s -is not a socket. +.It Bq Er EDSTADDRREQ +In a non-connected socket a destination address has not been specified. .It Bq Er EFAULT An invalid user space address was specified for a parameter. +.It Bq Er EHOSTDOWN +The destination is a host on the local subnet and does not respond to +.Xr arp 4 . +.It Bq Er EHOSTUNREACH +The destination for the message is unreachable. +.It Bq Er EINVAL +The total length of the I/O is more than can be expressed by the ssize_t +return value. .It Bq Er EMSGSIZE The socket requires that message be sent atomically, and the size of the message to be sent made this impossible. -.It Bq Er EPIPE -In a connected socket the connection has been broken. -.It Bq Er EDSTADDRREQ -In a non-connected socket a destination address has not been specified. -.It Bq Er EAGAIN|EWOULDBLOCK -The socket is marked non-blocking and the requested operation -would block. .It Bq Er ENOBUFS The system was unable to allocate an internal buffer. The operation may succeed when buffers become available. -.It Bq Er ENOBUFS -The output queue for a network interface was full. +.Pp +An alternative reason: the output queue for a network interface was full. This generally indicates that the interface has stopped sending, but may be caused by transient congestion. -.It Bq Er EACCES -The SO_BROADCAST option is not set on the socket, and a broadcast address -was given as the destination. -.It Bq Er EHOSTUNREACH -The destination for the message is unreachable. -.It Bq Er EHOSTDOWN -The destination is a host on the local subnet and does not respond to -.Xr arp 4 . -.It Bq Er EINVAL -The total length of the I/O is more than can be expressed by the ssize_t -return value. -.It Bq Er EAFNOSUPPORT -Addresses in the specified address family cannot be used with this socket. +.It Bq Er ENOTSOCK +The argument +.Fa s +is not a socket. +.It Bq Er EPIPE +In a connected socket the connection has been broken. .El .Pp .Fn sendto @@ -196,6 +244,8 @@ A destination address was specified and the socket is already connected. .El .Pp .Fn sendmsg +and +.Fn sendmmsg will also fail if: .Bl -tag -width Er .It Bq Er EMSGSIZE @@ -219,3 +269,9 @@ The .Fn send function call appeared in .Bx 4.2 . +The +.Fn sendmmsg +function call appeared in +.Tn Linux 3.0 +and +.Nx 7.0 . diff --git a/lib/libc/sys/setsid.2 b/lib/libc/sys/setsid.2 index 1338585a1..0e7394191 100644 --- a/lib/libc/sys/setsid.2 +++ b/lib/libc/sys/setsid.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: setsid.2,v 1.14 2006/10/07 21:03:51 elad Exp $ +.\" $NetBSD: setsid.2,v 1.15 2011/04/04 08:00:53 jruoho Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)setsid.2 8.1 (Berkeley) 6/4/93 .\" -.Dd October 7, 2006 +.Dd April 4, 2011 .Dt SETSID 2 .Os .Sh NAME @@ -43,7 +43,7 @@ .Fn setsid "void" .Sh DESCRIPTION The -.Nm setsid +.Fn setsid function creates a new session. The calling process is the session leader of the new session, is the process group leader of a new process group and has no controlling @@ -52,12 +52,12 @@ The calling process is the only process in either the session or the process group. .Pp Upon successful completion, the -.Nm setsid +.Fn setsid function returns the value of the process group ID of the new process group, which is the same as the process ID of the calling process. .Sh ERRORS If an error occurs, -.Nm setsid +.Fn setsid returns \-1 and the global variable .Va errno is set to indicate the error, as follows: @@ -74,6 +74,6 @@ ID of the calling process. .Xr tcsetpgrp 3 .Sh STANDARDS The -.Nm setsid +.Fn setsid function conforms to .St -p1003.1-90 . diff --git a/lib/libc/sys/settimeofday.c b/lib/libc/sys/settimeofday.c index 999127184..12f131b75 100644 --- a/lib/libc/sys/settimeofday.c +++ b/lib/libc/sys/settimeofday.c @@ -1,4 +1,4 @@ -/* $NetBSD: settimeofday.c,v 1.13 2009/01/11 02:46:30 christos Exp $ */ +/* $NetBSD: settimeofday.c,v 1.14 2011/10/15 23:00:02 christos Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: settimeofday.c,v 1.13 2009/01/11 02:46:30 christos Exp $"); +__RCSID("$NetBSD: settimeofday.c,v 1.14 2011/10/15 23:00:02 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -51,6 +51,10 @@ __RCSID("$NetBSD: settimeofday.c,v 1.13 2009/01/11 02:46:30 christos Exp $"); #include #include +#if defined(__minix) && !defined(O_CLOEXEC) +#define O_CLOEXEC 0 +#endif + int __clockctl_fd = -1; int ____settimeofday50(const struct timeval *, const void *); @@ -77,14 +81,12 @@ settimeofday(const struct timeval *tv, const void *tzp) if (rv != -1 || errno != EPERM) return rv; - __clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY, 0); + __clockctl_fd = open(_PATH_CLOCKCTL, O_WRONLY | O_CLOEXEC, 0); if (__clockctl_fd == -1) { /* original error was EPERM - don't leak open errors */ errno = EPERM; return -1; } - - (void) fcntl(__clockctl_fd, F_SETFD, FD_CLOEXEC); } /* diff --git a/lib/libc/sys/sigaction.2 b/lib/libc/sys/sigaction.2 index e33f6c984..a056c53ef 100644 --- a/lib/libc/sys/sigaction.2 +++ b/lib/libc/sys/sigaction.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: sigaction.2,v 1.43 2006/06/03 18:23:52 christos Exp $ +.\" $NetBSD: sigaction.2,v 1.44 2012/10/14 08:49:28 dholland Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -288,7 +288,7 @@ flag in .El .Pp Only functions that are async-signal-safe can safely be used in signal -handlers, see +handlers; see .Xr signal 7 for a complete list. .Sh NOTES diff --git a/lib/libc/sys/sigaltstack.2 b/lib/libc/sys/sigaltstack.2 index e9cb57d33..08bc39880 100644 --- a/lib/libc/sys/sigaltstack.2 +++ b/lib/libc/sys/sigaltstack.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: sigaltstack.2,v 1.22 2009/04/16 18:37:29 wiz Exp $ +.\" $NetBSD: sigaltstack.2,v 1.23 2012/03/02 18:07:17 joerg Exp $ .\" .\" Copyright (c) 1983, 1991, 1992, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)sigaltstack.2 8.2 (Berkeley) 5/1/95 .\" -.Dd April 16, 2009 +.Dd March 2, 2012 .Dt SIGALTSTACK 2 .Os .Sh NAME @@ -170,9 +170,3 @@ the .Fn sigstack system call, appeared in .Bx 4.2 . -.Sh CAVEATS -Due to limitations in the current pthread implementation, -.Nm -should not be used in programs which link against the -.Xr pthread 3 -library (whether threads are used or not). diff --git a/lib/libc/sys/sigtimedwait.2 b/lib/libc/sys/sigtimedwait.2 index c7a410ccf..80962bd6d 100644 --- a/lib/libc/sys/sigtimedwait.2 +++ b/lib/libc/sys/sigtimedwait.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: sigtimedwait.2,v 1.7 2010/05/31 11:02:24 drochner Exp $ +.\" $NetBSD: sigtimedwait.2,v 1.8 2012/04/02 22:06:47 agc Exp $ .\" .\" Copyright (c) 2003 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd May 30, 2010 +.Dd April 2, 2012 .Dt SIGTIMEDWAIT 2 .Os .Sh NAME @@ -100,8 +100,8 @@ indicates the error. Upon successful completion of .Fn sigwait .Fa sig -is updated with ihe signal number, and the function returns 0. -Otherwise, a non-zero error code is returned, +is updated with the signal number, and the function returns 0. +Otherwise, a non-zero error code is returned. .Sh ERRORS .Fn sigwaitinfo and diff --git a/lib/libc/sys/sigwait.c b/lib/libc/sys/sigwait.c index fbdef15dd..10902ba74 100644 --- a/lib/libc/sys/sigwait.c +++ b/lib/libc/sys/sigwait.c @@ -1,4 +1,4 @@ -/* $NetBSD: sigwait.c,v 1.4 2010/05/31 11:02:24 drochner Exp $ */ +/* $NetBSD: sigwait.c,v 1.5 2012/03/20 16:26:12 matt Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: sigwait.c,v 1.4 2010/05/31 11:02:24 drochner Exp $"); +__RCSID("$NetBSD: sigwait.c,v 1.5 2012/03/20 16:26:12 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -45,7 +45,7 @@ __RCSID("$NetBSD: sigwait.c,v 1.4 2010/05/31 11:02:24 drochner Exp $"); __weak_alias(sigwait,_sigwait) #endif -int _sigwait __P((const sigset_t * __restrict, int * __restrict)); +int _sigwait(const sigset_t * __restrict, int * __restrict); /* * This is wrapper around sigtimedwait(2), providing sigwait() diff --git a/lib/libc/sys/sigwaitinfo.c b/lib/libc/sys/sigwaitinfo.c index de668259a..6ab27a274 100644 --- a/lib/libc/sys/sigwaitinfo.c +++ b/lib/libc/sys/sigwaitinfo.c @@ -1,4 +1,4 @@ -/* $NetBSD: sigwaitinfo.c,v 1.2 2008/04/28 20:23:00 martin Exp $ */ +/* $NetBSD: sigwaitinfo.c,v 1.3 2012/03/20 16:26:12 matt Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: sigwaitinfo.c,v 1.2 2008/04/28 20:23:00 martin Exp $"); +__RCSID("$NetBSD: sigwaitinfo.c,v 1.3 2012/03/20 16:26:12 matt Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -44,8 +44,7 @@ __RCSID("$NetBSD: sigwaitinfo.c,v 1.2 2008/04/28 20:23:00 martin Exp $"); __weak_alias(sigwaitinfo,_sigwaitinfo) #endif -int _sigwaitinfo __P((const sigset_t * __restrict, - siginfo_t * __restrict info)); +int _sigwaitinfo(const sigset_t * __restrict, siginfo_t * __restrict info); /* * This is wrapper around sigtimedwait(2), providing sigwaitinfo() diff --git a/lib/libc/sys/socket.2 b/lib/libc/sys/socket.2 index e13148b63..788f0310d 100644 --- a/lib/libc/sys/socket.2 +++ b/lib/libc/sys/socket.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: socket.2,v 1.36 2007/09/06 09:32:52 jnemeth Exp $ +.\" $NetBSD: socket.2,v 1.39 2012/01/25 09:18:52 wiz Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)socket.2 8.1 (Berkeley) 6/4/93 .\" -.Dd September 6, 2007 +.Dd January 23, 2012 .Dt SOCKET 2 .Os .Sh NAME @@ -78,6 +78,21 @@ SOCK_SEQPACKET SOCK_RDM .Ed .Pp +The following flags can be or'ed to the type to condition the returned +file descriptor: +The following flags are valid: +.Bl -column SOCK_NONBLOCK -offset indent +.It Dv SOCK_CLOEXEC +Set the close on exec property. +.It Dv SOCK_NONBLOCK +Sets non-blocking I/O. +.It Dv SOCK_NOSIGPIPE +Return +.Er EPIPE +instead of raising +.Dv SIGPIPE . +.El +.Pp A .Dv SOCK_STREAM type provides sequenced, reliable, diff --git a/lib/libc/sys/socketpair.2 b/lib/libc/sys/socketpair.2 index ac64b0cf9..27dee9529 100644 --- a/lib/libc/sys/socketpair.2 +++ b/lib/libc/sys/socketpair.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: socketpair.2,v 1.21 2009/12/20 02:16:40 wiz Exp $ +.\" $NetBSD: socketpair.2,v 1.23 2011/06/27 08:21:08 wiz Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)socketpair.2 8.1 (Berkeley) 6/4/93 .\" -.Dd December 20, 2009 +.Dd June 24, 2011 .Dt SOCKETPAIR 2 .Os .Sh NAME @@ -53,10 +53,17 @@ and using the optionally specified .Fa protocol . The descriptors used in referencing the new sockets are returned in -.Fa sv Ns [0] +.Fa sv[0] and -.Fa sv Ns [1] . +.Fa sv[1] . The two sockets are indistinguishable. +.Pp +The +.Fa type +and +.Fa protocol +argument values are described in +.Xr socket 2 . .Sh RETURN VALUES A 0 is returned if the call succeeds, \-1 if it fails. .Sh ERRORS @@ -81,6 +88,7 @@ The specified protocol is not supported on this machine. .Sh SEE ALSO .Xr pipe 2 , .Xr read 2 , +.Xr socket 2 , .Xr write 2 .Sh HISTORY The diff --git a/lib/libc/sys/stat.2 b/lib/libc/sys/stat.2 index f15aae51b..7f51600d2 100644 --- a/lib/libc/sys/stat.2 +++ b/lib/libc/sys/stat.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: stat.2,v 1.47 2010/11/25 20:53:23 dholland Exp $ +.\" $NetBSD: stat.2,v 1.50 2012/01/04 10:53:39 wiz Exp $ .\" .\" Copyright (c) 1980, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)stat.2 8.4 (Berkeley) 5/1/95 .\" -.Dd November 25, 2010 +.Dd September 14, 2011 .Dt STAT 2 .Os .Sh NAME @@ -98,7 +98,7 @@ The following standards-compliant fields are defined in the structure: .It Vt time_t Ta st_mtime Ta time of last data modification .It Vt time_t Ta st_ctime Ta time of last file status change .It Vt blksize_t Ta st_blksize Ta preferred I/O block size (fs-specific) -.It Vt blkcnt_t Ta st_block Ta blocks allocated for the file +.It Vt blkcnt_t Ta st_blocks Ta blocks allocated for the file .El .Pp These are specified in the @@ -108,7 +108,7 @@ The .Va st_ino and .Va st_dev -fields taken together to uniquely identify the file within the system. +fields taken together uniquely identify the file within the system. Most of the types are defined in .Xr types 3 . .Pp @@ -292,7 +292,7 @@ will fail if: .It Bq Er EACCES Search permission is denied for a component of the path prefix. .It Bq Er EBADF -A badly formed v-node was encountered. +A badly formed vnode was encountered. This can happen if a file system information node is incorrect. .It Bq Er EFAULT .Fa sb diff --git a/lib/libc/sys/swapctl.2 b/lib/libc/sys/swapctl.2 index 7c6234400..ace74b029 100644 --- a/lib/libc/sys/swapctl.2 +++ b/lib/libc/sys/swapctl.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: swapctl.2,v 1.37 2010/05/31 12:16:20 njoly Exp $ +.\" $NetBSD: swapctl.2,v 1.38 2011/04/28 11:58:50 wiz Exp $ .\" .\" Copyright (c) 1997 Matthew R. Green .\" All rights reserved. @@ -212,49 +212,48 @@ to indicate the error. .Fn swapctl succeeds unless: .Bl -tag -width Er -.It Bq Er ENOTDIR -A component of the path prefix is not a directory. -.It Bq Er ENAMETOOLONG -A component of a pathname exceeded -.Brq Dv NAME_MAX -characters, or an entire path name exceeded -.Brq Dv PATH_MAX -characters. -.It Bq Er ENOENT -The named device does not exist. -For the -.Dv SWAP_CTL -command, the named device is not currently enabled for swapping. .It Bq Er EACCES Search permission is denied for a component of the path prefix. -.It Bq Er ELOOP -Too many symbolic links were encountered in translating the pathname. -.It Bq Er EPERM -The caller is not the super-user. .It Bq Er EBUSY The device specified by .Fa arg has already been made available for swapping. +.It Bq Er EFAULT +.Fa arg +points outside the process' allocated address space. .It Bq Er EINVAL The device configured by .Fa arg has no associated size, or the .Fa cmd was unknown. +.It Bq Er EIO +An I/O error occurred while opening the swap device. +.It Bq Er ELOOP +Too many symbolic links were encountered in translating the pathname. +.It Bq Er ENAMETOOLONG +A component of a pathname exceeded +.Brq Dv NAME_MAX +characters, or an entire path name exceeded +.Brq Dv PATH_MAX +characters. +.It Bq Er ENOENT +The named device does not exist. +For the +.Dv SWAP_CTL +command, the named device is not currently enabled for swapping. +.It Bq Er ENOTDIR +A component of the path prefix is not a directory. .It Bq Er ENXIO The major device number of .Fa arg is out of range (this indicates no device driver exists -for the associated hardware). -.It Bq Er ENXIO -The block device specified by +for the associated hardware); or +the block device specified by .Fa arg is not marked as a swap partition in the disklabel. -.It Bq Er EIO -An I/O error occurred while opening the swap device. -.It Bq Er EFAULT -.Fa arg -points outside the process' allocated address space. +.It Bq Er EPERM +The caller is not the super-user. .El .Sh SEE ALSO .Xr swapctl 8 diff --git a/lib/libc/sys/swapon.c b/lib/libc/sys/swapon.c index a62440908..be6622d8f 100644 --- a/lib/libc/sys/swapon.c +++ b/lib/libc/sys/swapon.c @@ -1,4 +1,4 @@ -/* $NetBSD: swapon.c,v 1.10 2008/05/29 14:51:25 mrg Exp $ */ +/* $NetBSD: swapon.c,v 1.11 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1997 Matthew R. Green @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: swapon.c,v 1.10 2008/05/29 14:51:25 mrg Exp $"); +__RCSID("$NetBSD: swapon.c,v 1.11 2012/06/25 22:32:46 abs Exp $"); #endif /* LIBC_SCCS and not lint */ #include @@ -36,8 +36,7 @@ __RCSID("$NetBSD: swapon.c,v 1.10 2008/05/29 14:51:25 mrg Exp $"); #include int -swapon(name) - const char *name; +swapon(const char *name) { return (swapctl(SWAP_ON, __UNCONST(name), 0)); diff --git a/lib/libc/sys/truncate.c b/lib/libc/sys/truncate.c index 475d04787..63e4550ae 100644 --- a/lib/libc/sys/truncate.c +++ b/lib/libc/sys/truncate.c @@ -1,4 +1,4 @@ -/* $NetBSD: truncate.c,v 1.12 2007/11/23 12:39:16 uebayasi Exp $ */ +/* $NetBSD: truncate.c,v 1.13 2012/03/20 16:26:12 matt Exp $ */ /* * Copyright (c) 1992, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)truncate.c 8.1 (Berkeley) 6/17/93"; #else -__RCSID("$NetBSD: truncate.c,v 1.12 2007/11/23 12:39:16 uebayasi Exp $"); +__RCSID("$NetBSD: truncate.c,v 1.13 2012/03/20 16:26:12 matt Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,9 +49,7 @@ int __truncate(const char *, int, off_t); * is not supplied by GCC 1.X but is supplied by GCC 2.X. */ int -truncate(path, length) - const char *path; - off_t length; +truncate(const char *path, off_t length) { return __truncate(path, 0, length); diff --git a/lib/libc/sys/utimes.2 b/lib/libc/sys/utimes.2 index 1d25a300c..e989aeb2a 100644 --- a/lib/libc/sys/utimes.2 +++ b/lib/libc/sys/utimes.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: utimes.2,v 1.26 2010/04/29 17:02:38 jruoho Exp $ +.\" $NetBSD: utimes.2,v 1.30 2011/10/25 09:26:53 wiz Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,13 +29,15 @@ .\" .\" @(#)utimes.2 8.1 (Berkeley) 6/4/93 .\" -.Dd April 29, 2010 +.Dd August 17, 2011 .Dt UTIMES 2 .Os .Sh NAME .Nm utimes , .Nm lutimes , -.Nm futimes +.Nm futimes , +.Nm futimens , +.Nm utimensat .Nd set file access and modification times .Sh LIBRARY .Lb libc @@ -47,6 +49,10 @@ .Fn lutimes "const char *path" "const struct timeval times[2]" .Ft int .Fn futimes "int fd" "const struct timeval times[2]" +.Ft int +.Fn futimens "int fd" "const struct timespec times[2]" +.Ft int +.Fn utimensat "int fd" "const char *path" "const struct timespec times[2]" "int flag" .Sh DESCRIPTION The access and modification times of the file named by .Fa path @@ -93,15 +99,52 @@ changes the access and modification times of the link, while .Fn utimes changes the times of the file the link references. +.Pp +.Fn futimens +is like +.Fn futimes +except that time is specified with nanosecond instead of microseconds. +.Pp +.Fn utimensat +also allows time to be specifed with nanoseconds. +When it operates on a symbolic link, it will change the target's time if +.Ar follow +is unset. +If +.Ar follow +is set to +.Dv AT_SYMLINK_NOFOLLOW , +the symbolic link's dates are changed. +.Pp +The nanosecond fields for +.Fn futimens +and +.Fn utimensat +can be set to the special value +.Dv UTIME_NOW +to set the current time, or to +.Dv UTIME_OMIT +to let the time unchanged (this allows changing access time but not +modification time, and vice-versa). +.Pp +.Fn utimensat +is partially implemented. +It will return +.Er ENOSYS +for +.Fa fd +values different than +.Dv AT_FDCWD . .Sh RETURN VALUES Upon successful completion, a value of 0 is returned. Otherwise, a value of \-1 is returned and .Va errno is set to indicate the error. .Sh ERRORS -.Fn utimes +.Fn utimes , +.Fn lutimes , and -.Fn lutimes +.Fn utimensat will fail if: .Bl -tag -width Er .It Bq Er EACCES @@ -144,6 +187,8 @@ The file system containing the file is mounted read-only. .El .Pp .Fn futimes +and +.Fn futimens will fail if: .Bl -tag -width Er .It Bq Er EACCES @@ -184,6 +229,11 @@ function conforms to It was however marked as legacy in the .St -p1003.1-2004 revision. +.Fn futimens +and +.Fn utimensat +functions conform to +.St -p1003.1-2008 . .Sh HISTORY The .Fn utimes @@ -199,3 +249,11 @@ function call appeared in .Nx 1.3 . Birthtime setting support was added in .Nx 5.0 . +.Fn futimens +and +.Fn utimensat +functions calls appreared in +.Nx 6.0 . +.Sh BUGS +.Fn utimensat +is partially implemented. diff --git a/lib/libc/termios/Makefile.inc b/lib/libc/termios/Makefile.inc index 14122306f..f590ece90 100644 --- a/lib/libc/termios/Makefile.inc +++ b/lib/libc/termios/Makefile.inc @@ -11,9 +11,7 @@ SRCS+= cfgetispeed.c cfgetospeed.c cfmakeraw.c cfsetispeed.c cfsetospeed.c \ SRCS+= cfgetispeed.c cfgetospeed.c cfmakeraw.c cfsetispeed.c cfsetospeed.c \ cfsetspeed.c tcdrain.c tcflow.c tcflush.c tcgetattr.c tcgetpgrp.c \ tcgetsid.c tcsendbreak.c tcsetattr.c tcsetpgrp.c -.endif - - +.endif # defined(__MINIX) MAN+= tcgetpgrp.3 tcgetsid.3 tcsendbreak.3 tcsetattr.3 tcsetpgrp.3 diff --git a/lib/libc/termios/cfgetispeed.c b/lib/libc/termios/cfgetispeed.c index 1dc8be943..65e74ac7f 100644 --- a/lib/libc/termios/cfgetispeed.c +++ b/lib/libc/termios/cfgetispeed.c @@ -1,4 +1,4 @@ -/* $NetBSD: cfgetispeed.c,v 1.7 2003/08/07 16:44:12 agc Exp $ */ +/* $NetBSD: cfgetispeed.c,v 1.8 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: cfgetispeed.c,v 1.7 2003/08/07 16:44:12 agc Exp $"); +__RCSID("$NetBSD: cfgetispeed.c,v 1.8 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,8 +49,7 @@ __weak_alias(cfgetispeed,_cfgetispeed) #endif speed_t -cfgetispeed(t) - const struct termios *t; +cfgetispeed(const struct termios *t) { _DIAGASSERT(t != NULL); diff --git a/lib/libc/termios/cfgetospeed.c b/lib/libc/termios/cfgetospeed.c index 746313f16..fe6cd23f6 100644 --- a/lib/libc/termios/cfgetospeed.c +++ b/lib/libc/termios/cfgetospeed.c @@ -1,4 +1,4 @@ -/* $NetBSD: cfgetospeed.c,v 1.7 2003/08/07 16:44:12 agc Exp $ */ +/* $NetBSD: cfgetospeed.c,v 1.8 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: cfgetospeed.c,v 1.7 2003/08/07 16:44:12 agc Exp $"); +__RCSID("$NetBSD: cfgetospeed.c,v 1.8 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,8 +49,7 @@ __weak_alias(cfgetospeed,_cfgetospeed) #endif speed_t -cfgetospeed(t) - const struct termios *t; +cfgetospeed(const struct termios *t) { _DIAGASSERT(t != NULL); diff --git a/lib/libc/termios/cfmakeraw.c b/lib/libc/termios/cfmakeraw.c index 987dc1062..2a36738ed 100644 --- a/lib/libc/termios/cfmakeraw.c +++ b/lib/libc/termios/cfmakeraw.c @@ -1,4 +1,4 @@ -/* $NetBSD: cfmakeraw.c,v 1.9 2003/08/07 16:44:12 agc Exp $ */ +/* $NetBSD: cfmakeraw.c,v 1.10 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: cfmakeraw.c,v 1.9 2003/08/07 16:44:12 agc Exp $"); +__RCSID("$NetBSD: cfmakeraw.c,v 1.10 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -53,8 +53,7 @@ __weak_alias(cfmakeraw,_cfmakeraw) * mode with no characters interpreted, 8-bit data path. */ void -cfmakeraw(t) - struct termios *t; +cfmakeraw(struct termios *t) { _DIAGASSERT(t != NULL); diff --git a/lib/libc/termios/cfsetispeed.c b/lib/libc/termios/cfsetispeed.c index d59db9023..44ff18449 100644 --- a/lib/libc/termios/cfsetispeed.c +++ b/lib/libc/termios/cfsetispeed.c @@ -1,4 +1,4 @@ -/* $NetBSD: cfsetispeed.c,v 1.7 2003/08/07 16:44:12 agc Exp $ */ +/* $NetBSD: cfsetispeed.c,v 1.8 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: cfsetispeed.c,v 1.7 2003/08/07 16:44:12 agc Exp $"); +__RCSID("$NetBSD: cfsetispeed.c,v 1.8 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,9 +49,7 @@ __weak_alias(cfsetispeed,_cfsetispeed) #endif int -cfsetispeed(t, speed) - struct termios *t; - speed_t speed; +cfsetispeed(struct termios *t, speed_t speed) { _DIAGASSERT(t != NULL); diff --git a/lib/libc/termios/cfsetospeed.c b/lib/libc/termios/cfsetospeed.c index 98797ab26..a61042fac 100644 --- a/lib/libc/termios/cfsetospeed.c +++ b/lib/libc/termios/cfsetospeed.c @@ -1,4 +1,4 @@ -/* $NetBSD: cfsetospeed.c,v 1.7 2003/08/07 16:44:12 agc Exp $ */ +/* $NetBSD: cfsetospeed.c,v 1.8 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: cfsetospeed.c,v 1.7 2003/08/07 16:44:12 agc Exp $"); +__RCSID("$NetBSD: cfsetospeed.c,v 1.8 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,9 +49,7 @@ __weak_alias(cfsetospeed,_cfsetospeed) #endif int -cfsetospeed(t, speed) - struct termios *t; - speed_t speed; +cfsetospeed(struct termios *t, speed_t speed) { _DIAGASSERT(t != NULL); diff --git a/lib/libc/termios/cfsetspeed.c b/lib/libc/termios/cfsetspeed.c index 8105969c6..85a030acb 100644 --- a/lib/libc/termios/cfsetspeed.c +++ b/lib/libc/termios/cfsetspeed.c @@ -1,4 +1,4 @@ -/* $NetBSD: cfsetspeed.c,v 1.7 2003/08/07 16:44:13 agc Exp $ */ +/* $NetBSD: cfsetspeed.c,v 1.8 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: cfsetspeed.c,v 1.7 2003/08/07 16:44:13 agc Exp $"); +__RCSID("$NetBSD: cfsetspeed.c,v 1.8 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -49,9 +49,7 @@ __weak_alias(cfsetspeed,_cfsetspeed) #endif int -cfsetspeed(t, speed) - struct termios *t; - speed_t speed; +cfsetspeed(struct termios *t, speed_t speed) { _DIAGASSERT(t != NULL); diff --git a/lib/libc/termios/tcdrain.c b/lib/libc/termios/tcdrain.c index 155d3d374..6782e0a86 100644 --- a/lib/libc/termios/tcdrain.c +++ b/lib/libc/termios/tcdrain.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcdrain.c,v 1.8 2003/08/07 16:44:13 agc Exp $ */ +/* $NetBSD: tcdrain.c,v 1.9 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: tcdrain.c,v 1.8 2003/08/07 16:44:13 agc Exp $"); +__RCSID("$NetBSD: tcdrain.c,v 1.9 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -50,8 +50,7 @@ __weak_alias(tcdrain,_tcdrain) #endif int -tcdrain(fd) - int fd; +tcdrain(int fd) { _DIAGASSERT(fd != -1); diff --git a/lib/libc/termios/tcflow.c b/lib/libc/termios/tcflow.c index a8fbc056c..9ddb8eb2b 100644 --- a/lib/libc/termios/tcflow.c +++ b/lib/libc/termios/tcflow.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcflow.c,v 1.8 2003/08/07 16:44:13 agc Exp $ */ +/* $NetBSD: tcflow.c,v 1.9 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: tcflow.c,v 1.8 2003/08/07 16:44:13 agc Exp $"); +__RCSID("$NetBSD: tcflow.c,v 1.9 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,8 +51,7 @@ __weak_alias(tcflow,_tcflow) #endif int -tcflow(fd, action) - int fd, action; +tcflow(int fd, int action) { #ifdef __minix _DIAGASSERT(fd != -1); diff --git a/lib/libc/termios/tcflush.c b/lib/libc/termios/tcflush.c index 5e8fd3240..1a75bcbd0 100644 --- a/lib/libc/termios/tcflush.c +++ b/lib/libc/termios/tcflush.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcflush.c,v 1.9 2003/08/07 16:44:13 agc Exp $ */ +/* $NetBSD: tcflush.c,v 1.10 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: tcflush.c,v 1.9 2003/08/07 16:44:13 agc Exp $"); +__RCSID("$NetBSD: tcflush.c,v 1.10 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,8 +51,7 @@ __weak_alias(tcflush,_tcflush) #endif int -tcflush(fd, which) - int fd, which; +tcflush(int fd, int which) { #ifdef __minix _DIAGASSERT(fd != -1); diff --git a/lib/libc/termios/tcgetattr.c b/lib/libc/termios/tcgetattr.c index 6583ba557..b0218365b 100644 --- a/lib/libc/termios/tcgetattr.c +++ b/lib/libc/termios/tcgetattr.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcgetattr.c,v 1.9 2003/08/07 16:44:13 agc Exp $ */ +/* $NetBSD: tcgetattr.c,v 1.10 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: tcgetattr.c,v 1.9 2003/08/07 16:44:13 agc Exp $"); +__RCSID("$NetBSD: tcgetattr.c,v 1.10 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,9 +51,7 @@ __weak_alias(tcgetattr,_tcgetattr) #endif int -tcgetattr(fd, t) - int fd; - struct termios *t; +tcgetattr(int fd, struct termios *t) { _DIAGASSERT(t != NULL); diff --git a/lib/libc/termios/tcgetpgrp.c b/lib/libc/termios/tcgetpgrp.c index 8694c8093..e977ab562 100644 --- a/lib/libc/termios/tcgetpgrp.c +++ b/lib/libc/termios/tcgetpgrp.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcgetpgrp.c,v 1.9 2004/12/01 21:37:15 dsl Exp $ */ +/* $NetBSD: tcgetpgrp.c,v 1.10 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: tcgetpgrp.c,v 1.9 2004/12/01 21:37:15 dsl Exp $"); +__RCSID("$NetBSD: tcgetpgrp.c,v 1.10 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,8 +52,7 @@ __weak_alias(tcgetpgrp,_tcgetpgrp) #endif pid_t -tcgetpgrp(fd) - int fd; +tcgetpgrp(int fd) { int s; diff --git a/lib/libc/termios/tcgetsid.c b/lib/libc/termios/tcgetsid.c index e6a79690f..53b3c4d02 100644 --- a/lib/libc/termios/tcgetsid.c +++ b/lib/libc/termios/tcgetsid.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcgetsid.c,v 1.6 2003/08/07 16:44:13 agc Exp $ */ +/* $NetBSD: tcgetsid.c,v 1.7 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: tcgetsid.c,v 1.6 2003/08/07 16:44:13 agc Exp $"); +__RCSID("$NetBSD: tcgetsid.c,v 1.7 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -52,8 +52,7 @@ __weak_alias(tcgetsid,_tcgetsid) #endif pid_t -tcgetsid(fd) - int fd; +tcgetsid(int fd) { int s; diff --git a/lib/libc/termios/tcsendbreak.c b/lib/libc/termios/tcsendbreak.c index 521426ee3..dfb6e9c56 100644 --- a/lib/libc/termios/tcsendbreak.c +++ b/lib/libc/termios/tcsendbreak.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcsendbreak.c,v 1.9 2003/08/07 16:44:14 agc Exp $ */ +/* $NetBSD: tcsendbreak.c,v 1.10 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: tcsendbreak.c,v 1.9 2003/08/07 16:44:14 agc Exp $"); +__RCSID("$NetBSD: tcsendbreak.c,v 1.10 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -56,8 +56,7 @@ __weak_alias(tcsendbreak,_tcsendbreak) /*ARGSUSED*/ int -tcsendbreak(fd, len) - int fd, len; +tcsendbreak(int fd, int len) { #ifdef __minix _DIAGASSERT(fd != -1); diff --git a/lib/libc/termios/tcsetattr.c b/lib/libc/termios/tcsetattr.c index b72e197cf..1079da160 100644 --- a/lib/libc/termios/tcsetattr.c +++ b/lib/libc/termios/tcsetattr.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcsetattr.c,v 1.8 2003/08/07 16:44:14 agc Exp $ */ +/* $NetBSD: tcsetattr.c,v 1.9 2012/06/25 22:32:46 abs Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #else -__RCSID("$NetBSD: tcsetattr.c,v 1.8 2003/08/07 16:44:14 agc Exp $"); +__RCSID("$NetBSD: tcsetattr.c,v 1.9 2012/06/25 22:32:46 abs Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -51,9 +51,7 @@ __weak_alias(tcsetattr,_tcsetattr) #endif int -tcsetattr(fd, opt, t) - int fd, opt; - const struct termios *t; +tcsetattr(int fd, int opt, const struct termios *t) { #ifndef __minix struct termios localterm; diff --git a/lib/libc/thread-stub/thread-stub.c b/lib/libc/thread-stub/thread-stub.c index 29f49824f..bd296e415 100644 --- a/lib/libc/thread-stub/thread-stub.c +++ b/lib/libc/thread-stub/thread-stub.c @@ -1,4 +1,4 @@ -/* $NetBSD: thread-stub.c,v 1.21 2009/01/30 23:21:03 ad Exp $ */ +/* $NetBSD: thread-stub.c,v 1.22 2011/09/16 16:05:59 joerg Exp $ */ /*- * Copyright (c) 2003, 2009 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: thread-stub.c,v 1.21 2009/01/30 23:21:03 ad Exp $"); +__RCSID("$NetBSD: thread-stub.c,v 1.22 2011/09/16 16:05:59 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ /* @@ -343,7 +343,7 @@ thr_t __libc_thr_self_stub(void); int __libc_thr_yield_stub(void); int __libc_thr_create_stub(thr_t *, const thrattr_t *, void *(*)(void *), void *); -void __libc_thr_exit_stub(void *); +__dead void __libc_thr_exit_stub(void *); int *__libc_thr_errno_stub(void); int __libc_thr_setcancelstate_stub(int, int *); int __libc_thr_equal_stub(pthread_t, pthread_t); diff --git a/lib/libc/time/Makefile b/lib/libc/time/Makefile index 689bdde33..5a8f12ec9 100644 --- a/lib/libc/time/Makefile +++ b/lib/libc/time/Makefile @@ -1,8 +1,10 @@ #
-# @(#)Makefile	8.8
 # This file is in the public domain, so clarified as of
 # 2009-05-17 by Arthur David Olson.
 
+# Version numbers of the code and data distributions.
+VERSION = 2012e
+
 # Change the line below for your time zone (after finding the zone you want in
 # the time zone files, or adding it to a time zone file).
 # Alternately, if you discover you've got the wrong time zone, you can just
@@ -12,7 +14,7 @@
 #	make zonenames
 # to get a list of the values you can use for LOCALTIME.
 
-LOCALTIME=	Factory
+LOCALTIME=	GMT
 
 # If you want something other than Eastern United States time as a template
 # for handling POSIX-style time zone environment variables,
@@ -113,10 +115,12 @@ LDLIBS=
 #  -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU=1
 #	if you do not want run time warnings about formats that may cause
 #	year 2000 grief
+#  -DNO_ERROR_IN_DST_GAP=1
+#	if you want mktime() not to return an error in the DST gap.
 #  -DZIC_MAX_ABBR_LEN_WO_WARN=3
 #	(or some other number) to set the maximum time zone abbreviation length
 #	that zic will accept without a warning (the default is 6)
-GCC_DEBUG_FLAGS = -Dlint -g -O -fno-common \
+GCC_DEBUG_FLAGS = -Dlint -g -O3 -fno-common \
 	-Wall -Wcast-qual -Wconversion -Wmissing-prototypes \
 	-Wnested-externs -Wpointer-arith -Wshadow \
 	-Wtraditional # -Wstrict-prototypes -Wwrite-strings
@@ -224,7 +228,9 @@ ZIC=		$(zic) $(ZFLAGS)
 AWK=		nawk
 
 # The path where SGML DTDs are kept.
-SGML_SEARCH_PATH= $(TOPDIR)/share/doc/sgml-lib/REC-html401-19991224/
+# The default is appropriate for Ubuntu.
+SGML_TOPDIR= /usr
+SGML_SEARCH_PATH= $(SGML_TOPDIR)/share/xml/xhtml/schema/dtd/REC-html401-19991224
 
 # The catalog file(s) to use when validating.
 SGML_CATALOG_FILES= HTML4.cat
@@ -240,6 +246,17 @@ VALIDATE_ENV = \
   SP_CHARSET_FIXED=YES \
   SP_ENCODING=UTF-8
 
+# Flags to give 'tar' when making a distribution.
+# Try to use flags appropriate for GNU tar.
+GNUTARFLAGS=	--numeric-owner --owner=0 --group=0 --mode=go+u,go-w
+TARFLAGS=	`if tar $(GNUTARFLAGS) --version >/dev/null 2>&1; \
+		 then echo $(GNUTARFLAGS); \
+		 else :; \
+		 fi`
+
+# Flags to give 'gzip' when making a distribution.
+GZIPFLAGS=	-9n
+
 ###############################################################################
 
 cc=		cc
@@ -262,15 +279,15 @@ MANS=		newctime.3 newstrftime.3 newtzset.3 time2posix.3 \
 DOCS=		README Theory $(MANS) date.1 Makefile
 PRIMARY_YDATA=	africa antarctica asia australasia \
 		europe northamerica southamerica
-YDATA=		$(PRIMARY_YDATA) pacificnew etcetera factory backward
-NDATA=		systemv
+YDATA=		$(PRIMARY_YDATA) pacificnew etcetera backward
+NDATA=		systemv factory
 SDATA=		solar87 solar88 solar89
 TDATA=		$(YDATA) $(NDATA) $(SDATA)
 TABDATA=	iso3166.tab zone.tab
 DATA=		$(YDATA) $(NDATA) $(SDATA) $(TABDATA) leapseconds yearistype.sh
 WEB_PAGES=	tz-art.htm tz-link.htm
 MISC=		usno1988 usno1989 usno1989a usno1995 usno1997 usno1998 \
-			itca.jpg $(WEB_PAGES) checktab.awk workman.sh \
+			$(WEB_PAGES) checktab.awk workman.sh \
 			zoneinfo2tdf.pl
 ENCHILADA=	$(DOCS) $(SOURCES) $(DATA) $(MISC)
 
@@ -309,6 +326,10 @@ INSTALL:	ALL install date.1
 		-rm -f $(MANDIR)/man1/date.1
 		cp date.1 $(MANDIR)/man1/.
 
+version.h:
+		echo >$@ \
+		  'static char const TZVERSION[]="tz$(VERSION)";'
+
 zdump:		$(TZDOBJS)
 		$(CC) $(CFLAGS) $(LFLAGS) $(TZDOBJS) $(LDLIBS) -o $@
 
@@ -359,6 +380,7 @@ tzselect:	tzselect.ksh
 		sed \
 			-e 's|AWK=[^}]*|AWK=$(AWK)|g' \
 			-e 's|TZDIR=[^}]*|TZDIR=$(TZDIR)|' \
+			-e 's|\(TZVERSION\)=.*|\1=tz$(VERSION)|' \
 			<$? >$@
 		chmod +x $@
 
@@ -371,31 +393,55 @@ check_web:	$(WEB_PAGES)
 		$(VALIDATE_ENV) $(VALIDATE) $(VALIDATE_FLAGS) $(WEB_PAGES)
 
 clean:
-		rm -f core *.o *.out tzselect zdump zic yearistype date
+		rm -f core *.o *.out \
+		  date tzselect version.h zdump zic yearistype
 
 maintainer-clean: clean
 		@echo 'This command is intended for maintainers to use; it'
 		@echo 'deletes files that may need special tools to rebuild.'
-		rm -f *.[1-8].txt tzcode.tar.gz tzdata.tar.gz
+		rm -f *.[1-8].txt tzcode*.tar.gz tzdata*.tar.gz
 
 names:
 		@echo $(ENCHILADA)
 
+# Set the time stamps to those of the git repository, if available,
+# and if the files have not changed since then.
+# This uses GNU 'touch' syntax 'touch -d@N FILE',
+# where N is the number of seconds since 1970.
+# If git or GNU 'touch' is absent, do nothing.
+set-timestamps:
+		-TZ=UTC0 && export TZ && files=`git ls-files` && \
+		touch -d @1 test.out && rm -f test.out && \
+		for file in $$files; do \
+		  test -z "`git diff --name-only $$file`" || continue; \
+		  cmd="touch -d @`git log -1 --format='format:%ct' $$file \
+			` $$file" && \
+		  echo "$$cmd" && \
+		  $$cmd || exit; \
+		done
+
 # The zics below ensure that each data file can stand on its own.
 # We also do an all-files run to catch links to links.
 
-public:		$(ENCHILADA)
+public:		$(ENCHILADA) set-timestamps
 		make maintainer-clean
 		make "CFLAGS=$(GCC_DEBUG_FLAGS)"
-		-mkdir /tmp/,tzpublic
+		mkdir -m go-rwx /tmp/,tzpublic
 		-for i in $(TDATA) ; do zic -v -d /tmp/,tzpublic $$i 2>&1 | grep -v "starting year" ; done
 		for i in $(TDATA) ; do zic -d /tmp/,tzpublic $$i || exit; done
 		zic -v -d /tmp/,tzpublic $(TDATA) || exit
 		rm -f -r /tmp/,tzpublic
-		for i in *.[1-8] ; do sh workman.sh $$i > $$i.txt || exit; done
+		for i in *.[1-8] ; do \
+		  LC_ALL=C sh workman.sh $$i > $$i.txt && \
+		  touch -r $$i $$i.txt || exit; \
+		done
 		$(AWK) -f checktab.awk $(PRIMARY_YDATA)
-		tar cf - $(DOCS) $(SOURCES) $(MISC) *.[1-8].txt | gzip -9 > tzcode.tar.gz
-		tar cf - $(DATA) | gzip -9 > tzdata.tar.gz
+		LC_ALL=C && export LC_ALL && \
+		tar $(TARFLAGS) -cf - $(DOCS) $(SOURCES) $(MISC) *.[1-8].txt | \
+		  gzip $(GZIPFLAGS) > tzcode$(VERSION).tar.gz
+		LC_ALL=C && export LC_ALL && \
+		tar $(TARFLAGS) -cf - $(DATA) | \
+		  gzip $(GZIPFLAGS) > tzdata$(VERSION).tar.gz
 
 typecheck:
 		make clean
@@ -416,6 +462,7 @@ ialloc.o:	private.h
 localtime.o:	private.h tzfile.h
 scheck.o:	private.h
 strftime.o:	tzfile.h
-zic.o:		private.h tzfile.h
+zdump.o:	version.h
+zic.o:		private.h tzfile.h version.h
 
 .KEEP_STATE:
diff --git a/lib/libc/time/Makefile.inc b/lib/libc/time/Makefile.inc
index 31899a94d..cc6f1f88e 100644
--- a/lib/libc/time/Makefile.inc
+++ b/lib/libc/time/Makefile.inc
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.16 2010/12/16 22:18:37 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.17 2011/08/14 09:07:37 christos Exp $
 
 .PATH: ${.CURDIR}/time
 
@@ -34,3 +34,5 @@ MLINKS+=ctime.3 ctime_r.3	\
 	tzset.3 daylight.3	\
 	tzset.3 tzsetwall.3	\
 	strftime.3 strftime_z.3
+
+COPTS.strftime.c = -Wno-format-nonliteral
diff --git a/lib/libc/time/README b/lib/libc/time/README
index 427b6a015..091384c87 100644
--- a/lib/libc/time/README
+++ b/lib/libc/time/README
@@ -1,4 +1,5 @@
-@(#)README	8.3
+README for the tz distribution
+
 This file is in the public domain, so clarified as of
 2009-05-17 by Arthur David Olson.
 
@@ -40,9 +41,9 @@ tz distribution on a GNU/Linux or similar host.
 
 	mkdir tz
 	cd tz
-	wget 'ftp://elsie.nci.nih.gov/pub/tz*.tar.gz'
-	gzip -dc tzcode*.tar.gz | tar -xf -
-	gzip -dc tzdata*.tar.gz | tar -xf -
+	wget --retr-symlinks 'ftp://ftp.iana.org/tz/tz*-latest.tar.gz'
+	gzip -dc tzcode-latest.tar.gz | tar -xf -
+	gzip -dc tzdata-latest.tar.gz | tar -xf -
 
 Be sure to read the comments in "Makefile" and make any changes needed
 to make things right for your system, especially if you are using some
@@ -71,7 +72,7 @@ the files currently do not even attempt to cover all time stamps before
 1970, and there are undoubtedly errors even for time stamps since 1970.
 If you know that the rules are different from those in a file, by all means
 feel free to change file (and please send the changed version to
-tz@elsie.nci.nih.gov for use in the future).  Europeans take note!
+tz@iana.org for use in the future).  Europeans take note!
 
 Thanks to these Timezone Caballeros who've made major contributions to the
 time conversion package:  Keith Bostic; Bob Devine; Paul Eggert; Robert Elz;
@@ -80,7 +81,13 @@ Michael Bloom, Art Neilson, Stephen Prince, John Sovereign, and Frank Wales
 for testing work, and to Gwillim Law for checking local mean time data.
 None of them are responsible for remaining errors.
 
-Look in the ~ftp/pub directory of elsie.nci.nih.gov
+Look in 
 for updated versions of these files.
 
-Please send comments or information to tz@elsie.nci.nih.gov.
+Please send comments or information to tz@iana.org.
+
+Postscript:  The README above is largely unmodified (aside from details
+of mailing list and ftp archive addresses) from that prepared many years
+ago by Arthur David Olson, to whom the timezone community owes the
+greatest debt of all.  Arthur is not currently maintaining this data or
+code (though he remains involved).
diff --git a/lib/libc/time/Theory b/lib/libc/time/Theory
index 605a62a59..e442bcdcc 100644
--- a/lib/libc/time/Theory
+++ b/lib/libc/time/Theory
@@ -1,12 +1,11 @@
-#	$NetBSD: Theory,v 1.9 2009/12/31 22:49:15 mlelstv Exp $
-@(#)Theory	8.3
 This file is in the public domain, so clarified as of
 2009-05-17 by Arthur David Olson.
 
 ----- Outline -----
 
 	Time and date functions
-	Names of time zone regions
+	Scope of the tz database
+	Names of time zone rule files
 	Time zone abbreviations
 	Calendrical issues
 	Time and time zones on Mars
@@ -193,6 +192,31 @@ more powerful time conversion functions can be standardized, so much the
 better.
 
 
+----- Scope of the tz database -----
+
+The tz database attempts to record the history and predicted future of
+all computer-based clocks that track civil time.  To represent this
+data, the world is partitioned into regions whose clocks all agree
+about time stamps that occur after the somewhat-arbitrary cutoff point
+of the POSIX Epoch (1970-01-01 00:00:00 UTC).  For each such region,
+the database records all known clock transitions, and labels the region
+with a notable location.
+
+Clock transitions before 1970 are recorded for each such location,
+because most POSIX-compatible systems support negative time stamps and
+could misbehave if data were omitted for pre-1970 transitions.
+However, the database is not designed for and does not suffice for
+applications requiring accurate handling of all past times everywhere,
+as it would take far too much effort and guesswork to record all
+details of pre-1970 civil timekeeping.
+
+As noted in the README file, the tz database is not authoritative
+(particularly not for pre-1970 time stamps), and it surely has errors.
+Corrections are welcome and encouraged.  Users requiring authoritative
+data should consult national standards bodies and the references cited
+in the database's comments.
+
+
 ----- Names of time zone rule files -----
 
 The time zone rule file naming conventions attempt to strike a balance
@@ -288,8 +312,7 @@ and these older names are still supported.
 See the file `backward' for most of these older names
 (e.g. `US/Eastern' instead of `America/New_York').
 The other old-fashioned names still supported are
-`WET', `CET', `MET', `EET' (see the file `europe'),
-and `Factory' (see the file `factory').
+`WET', `CET', `MET', and `EET' (see the file `europe').
 
 
 ----- Time zone abbreviations -----
@@ -361,10 +384,10 @@ abbreviations like `EST'; this avoids the ambiguity.
 Calendrical issues are a bit out of scope for a time zone database,
 but they indicate the sort of problems that we would run into if we
 extended the time zone database further into the past.  An excellent
-resource in this area is Edward M. Reingold and Nachum Dershowitz,
-
-Calendrical Calculations: The Millennium Edition
-, Cambridge University Press (2001).  Other information and
+resource in this area is Nachum Dershowitz and Edward M. Reingold,
+
+Calendrical Calculations: Third Edition
+, Cambridge University Press (2008).  Other information and
 sources are given below.  They sometimes disagree.
 
 
diff --git a/lib/libc/time/asctime.c b/lib/libc/time/asctime.c
index 8dc5c483d..989c47248 100644
--- a/lib/libc/time/asctime.c
+++ b/lib/libc/time/asctime.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: asctime.c,v 1.13 2009/12/31 22:49:16 mlelstv Exp $	*/
+/*	$NetBSD: asctime.c,v 1.15 2012/06/25 22:32:46 abs Exp $	*/
 
 /*
 ** This file is in the public domain, so clarified as of
@@ -14,9 +14,9 @@
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
-static char	elsieid[] = "@(#)asctime.c	8.2";
+static char	elsieid[] = "@(#)asctime.c	8.5";
 #else
-__RCSID("$NetBSD: asctime.c,v 1.13 2009/12/31 22:49:16 mlelstv Exp $");
+__RCSID("$NetBSD: asctime.c,v 1.15 2012/06/25 22:32:46 abs Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -94,9 +94,7 @@ static char	buf_asctime[MAX_ASCTIME_BUF_SIZE];
 #define	ASCTIME_BUFLEN	(3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + 3 + 2 + 1 + 1)
 
 char *
-asctime_r(timeptr, buf)
-register const struct tm *	timeptr;
-char *				buf;
+asctime_r(const struct tm * timeptr, char * buf)
 {
 	static const char	*wday_name[7] = {
 		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
@@ -110,6 +108,10 @@ char *				buf;
 	char			year[INT_STRLEN_MAXIMUM(int) + 2];
 	char			result[MAX_ASCTIME_BUF_SIZE];
 
+	if (timeptr == NULL) {
+		errno = EINVAL;
+		return strcpy(buf, "??? ??? ?? ??:??:?? ????\n");
+	}
 	if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
 		wn = "???";
 	else	wn = wday_name[timeptr->tm_wday];
@@ -130,10 +132,9 @@ char *				buf;
 		timeptr->tm_mday, timeptr->tm_hour,
 		timeptr->tm_min, timeptr->tm_sec,
 		year);
-	if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime) {
-		(void) strcpy(buf, result);
-		return buf;
-	} else {
+	if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime)
+		return strcpy(buf, result);
+	else {
 #ifdef EOVERFLOW
 		errno = EOVERFLOW;
 #else /* !defined EOVERFLOW */
@@ -148,8 +149,7 @@ char *				buf;
 */
 
 char *
-asctime(timeptr)
-register const struct tm *	timeptr;
+asctime(const struct tm *timeptr)
 {
 	return asctime_r(timeptr, buf_asctime);
 }
diff --git a/lib/libc/time/checktab.awk b/lib/libc/time/checktab.awk
index 1263a3bb2..9a36811c3 100644
--- a/lib/libc/time/checktab.awk
+++ b/lib/libc/time/checktab.awk
@@ -1,9 +1,7 @@
-#	$NetBSD: checktab.awk,v 1.4 2009/12/31 22:49:16 mlelstv Exp $
+#	$NetBSD: checktab.awk,v 1.5 2012/08/09 12:38:25 christos Exp $
 
 # Check tz tables for consistency.
 
-# @(#)checktab.awk	8.1
-
 # Contributed by Paul Eggert.
 
 BEGIN {
diff --git a/lib/libc/time/ctime.3 b/lib/libc/time/ctime.3
index 0399e57a6..f9591c905 100644
--- a/lib/libc/time/ctime.3
+++ b/lib/libc/time/ctime.3
@@ -1,5 +1,8 @@
-.\" $NetBSD: ctime.3,v 1.37 2010/12/17 01:30:50 wiz Exp $
-.Dd December 14, 2010
+.\" $NetBSD: ctime.3,v 1.46 2011/11/02 23:06:08 christos Exp $
+.\"
+.\" XXX: License missing?
+.\"
+.Dd November 2, 2011
 .Dt CTIME 3
 .Os
 .Sh NAME
@@ -24,7 +27,11 @@
 .Lb libc
 .Sh SYNOPSIS
 .In time.h
-.Dv extern char *tzname[2];
+.Vt extern char *tzname[2];
+.Ft char *
+.Fn asctime "const struct tm *tm"
+.Ft char *
+.Fn asctime_r "const struct tm restrict tm" "char * restrict buf"
 .Ft char *
 .Fn ctime "const time_t *clock"
 .Ft char *
@@ -33,130 +40,169 @@
 .Fn ctime_rz "const timezone_t tz" "const time_t *clock"  "char *buf"
 .Ft double
 .Fn difftime "time_t time1" "time_t time0"
-.Ft char *
-.Fn asctime "const struct tm *tm"
-.Ft char *
-.Fn asctime_r "const struct tm restrict tm" "char * restrict buf"
+.Ft struct tm *
+.Fn gmtime "const time_t *clock"
+.Ft struct tm *
+.Fn gmtime_r "const time_t * restrict clock" "struct tm * restrict result"
 .Ft struct tm *
 .Fn localtime "const time_t *clock"
 .Ft struct tm *
 .Fn localtime_r "const time_t * restrict clock" "struct tm * restrict result"
 .Ft struct tm *
 .Fn localtime_rz "const timezone_t tz" "const time_t * restrict clock" "struct tm * restrict result"
-.Ft struct tm *
-.Fn gmtime "const time_t *clock"
-.Ft struct tm *
-.Fn gmtime_r "const time_t * restrict clock" "struct tm * restrict result"
 .Ft time_t
 .Fn mktime "struct tm *tm"
 .Ft time_t
 .Fn mktime_z "const timezone_t tz" "struct tm *tm"
 .Ft timezone_t
 .Fn tzalloc "const char *zone"
-.Ft const char *
-.Fn tzgetname "const timezone_t tz" "int isdst"
 .Ft void
 .Fn tzfree "const timezone_t tz"
+.Ft const char *
+.Fn tzgetname "const timezone_t tz" "int isdst"
 .Sh DESCRIPTION
+The
+.Nm
+family of functions provide various standard library routines
+to operate with time and conversions related to time.
+.Sh FUNCTIONS
+.Bl -tag -width abcd
+.It Fn asctime "tm"
+The
+.Fn asctime
+function converts a time value contained in the
+.Fa tm
+structure to a string with the following general format:
+.Bd -literal -offset indent
+.D1 Thu Nov 24 18:22:48 1986\en\e0
+.Ed
+.Pp
+The
+.Fa tm
+structure is described in
+.Xr tm 3 .
+.It Fn asctime_r "tm" "buf"
+The
+.Fn asctime_r
+has the same behavior as
+.Fn asctime ,
+but the result is stored to
+.Fa buf ,
+which should have a size of at least 26 bytes.
+.It Fn ctime "clock"
+The
 .Fn ctime
-converts a
-.Tp time_t ,
+function converts a
+.Vt time_t ,
 pointed to by
 .Fa clock ,
-representing the time in seconds since
-00:00:00 UTC, 1970-01-01,
-and returns a pointer to a
-string of the form
-.D1 Thu Nov 24 18:22:48 1986\en\e0
+representing the time in seconds since 00:00:00 UTC, 1970-01-01,
+and returns a pointer to a string with the format described above.
 Years requiring fewer than four characters are padded with leading zeroes.
 For years longer than four characters, the string is of the form
-.D1 Thu Nov 24 18:22:48     81986\en\e0
+.Bd -literal -offset indent
+.D1 "Thu Nov 24 18:22:48     81986\en\e0"
+.Ed
+.Pp
 with five spaces before the year.
 These unusual formats are designed to make it less likely that older
 software that expects exactly 26 bytes of output will mistakenly output
 misleading values for out-of-range years.
-.Pp
+.It Fn ctime_r "clock" "buf"
+The
 .Fn ctime_r
 is similar to
 .Fn ctime ,
 except it places the result of the conversion on the
 .Fa buf
-argument which should be 26 or more bytes long, instead of using a global
-static buffer.
-.Pp
+argument, which should be 26 or more bytes long,
+instead of using a global static buffer.
+.It Fn ctime_rz "tz" "clock" "buf"
+The
 .Fn ctime_rz
-is similar to
+function is similar to
 .Fn ctime_r ,
 but it also takes a
 .Ft "const timezone_t"
-argument, returned by a previous call to
+argument, as returned by a previous call to
 .Fn tzalloc .
-.Pp
-.Fn localtime
-and
+.It Fn difftime "time1" "time2"
+The
+.Fn difftime
+function returns the difference between two calendar times,
+.Fa ( time1 No - Fa time0 ) ,
+expressed in seconds.
+.It Fn gmtime "clock"
+The
 .Fn gmtime
-return pointers to
+function converts to Coordinated Universal Time
+.Pq Tn UTC
+and returns a pointer to the
 .Va tm
-structures, described below.
+structure described in
+.Xr tm 3 .
+.It Fn gmtime_r "clock" "result"
+The
+.Fn gmtime_r
+provides the same functionality as
+.Fn gmtime ,
+differing in that the caller must supply a buffer area
+.Fa result
+to which the result is stored.
+.It Fn localtime "clock"
+Also
+.Fn localtime
+is comparable to
+.Fn gmtime .
+However,
 .Fn localtime
 corrects for the time zone and any time zone adjustments
 (such as Daylight Saving Time in the U.S.A.).
 After filling in the
 .Va tm
-structure,
-.Fn localtime
-sets the
+structure, the function sets the
 .Fa tm_isdst Ns 'th
 element of
 .Fa tzname
 to a pointer to an
-ASCII string that's the time zone abbreviation to be used with
+ASCII string that is the time zone abbreviation to be used with
 .Fn localtime Ns 's
 return value.
-.Pp
-.Fn gmtime
-converts to Coordinated Universal Time.
-.Pp
-The
-.Fn gmtime_r
-and
+.It Fn localtime_r "clock" "result"
+As
+.Fn gmtime_r ,
+the
 .Fn localtime_r
-functions provide the same functionality as
-.Fn gmtime
-and
-.Fn localtime
-differing in that the caller must supply a buffer area
+takes an additional buffer
 .Fa result
-in which the result is stored; also,
+as a parameter and stores the result to it.
+Note however that
 .Fn localtime_r
 does not imply initialization of the local time conversion information;
 the application may need to do so by calling
 .Xr tzset 3 .
-.Pp
+.It Fn localtime_rz "tz" "clock" "result"
+The
 .Fn localtime_rz
-is similar to
+function is similar to
 .Fn localtime_r ,
 but it also takes a
 .Ft "const timezone_t"
 argument, returned by a previous call to
 .Fn tzalloc .
-.Pp
-.Fn asctime
-converts a time value contained in a
-.Dq tm
-structure to a string,
-as shown in the above example,
-and returns a pointer to the string.
-.Pp
+.It Fn mktime "tm"
+The
 .Fn mktime
-converts the broken-down time,
-expressed as local time,
-in the structure pointed to by
-.Fa tm
-into a calendar time value with the same encoding as that of the values
-returned by the
+function converts the broken-down time,
+expressed as local time in the
+.Xr tm 3
+structure, into a calendar time value with
+the same encoding as that of the values returned by the
 .Xr time 3
 function.
+The following remarks should be taken into account.
+.Bl -bullet
+.It
 The original values of the
 .Fa tm_wday
 and
@@ -171,6 +217,7 @@ causes
 to presume initially that summer time (for example, Daylight Saving Time
 in the U.S.A.) respectively,
 is or is not in effect for the specified time.
+.It
 A negative value for
 .Fa tm_isdst
 causes the
@@ -178,7 +225,8 @@ causes the
 function to attempt to divine whether summer time is in effect
 for the specified time; in this case it does not use a consistent
 rule and may give a different answer when later
-presented with the same argument.)
+presented with the same argument.
+.It
 On successful completion, the values of the
 .Fa tm_wday
 and
@@ -192,33 +240,46 @@ is not set until
 and
 .Fa tm_year
 are determined.
-.Fn mktime
-returns the specified calendar time; if the calendar time cannot be
-represented, it returns
-.Va "(time_t)-1" .
+.El
 .Pp
+The function returns the specified calendar time;
+if the calendar time cannot be represented, it returns
+.Va "(time_t)-1" .
+This can happen either because the resulting conversion would not fit
+in a
+.Vt time_t
+variable, or because the time specified happens to be in the daylight
+savings gap and
+.Fa tm_isdst
+was set to
+.Dv \-1 .
+Other
+.Fn mktime
+implementations do not return an error in the second case and return
+the appropriate time offset after the daylight savings gap.
+There is code to mimick this behavior, but it is not enabled by default.
+.It Fn mktime_z "tz" "tm"
+The
 .Fn mktime_z
-is similar to
+function is similar to
 .Fn mktime
 but it also takes a
 .Ft "const timezone_t"
 argument, returned by a previous call to
 .Fn tzalloc .
-.Pp
-.Fn difftime
-returns the difference between two calendar times,
-.Fa ( time1 No - Fa time0 ) ,
-expressed in seconds.
-.Pp
+.It Fn tzalloc "zone"
+The
 .Fn tzalloc
-takes as an argument a timezone name and returns a
+function takes as an argument a timezone name and returns a
 .Ft timezone_t
-object suitable to be used in
+object suitable to be used in the
 .Fn ctime_rz ,
 .Fn localtime_rz ,
 and
-.Fn mktime_z .
-Instead of setting the environment variable
+.Fn mktime_z
+functions.
+.Pp
+Note that instead of setting the environment variable
 .Va TZ ,
 and globally changing the behavior of the calling program, one can use
 multiple timezones at the same time by using separate
@@ -228,7 +289,15 @@ objects allocated by
 and calling the
 .Dq z
 variants of the functions.
-.Pp
+.It Fn tzfree "tz"
+The
+.Fn tzfree
+function deallocates
+.Fa tz ,
+which was previously allocated by
+.Fn tzalloc .
+.It Fn "tzgetname"
+Finally,
 .Fn tzgetname
 returns the name for the given
 .Fa tz .
@@ -244,59 +313,10 @@ is set to
 .Va 1
 the call is equivalent to
 .Va tzname[1] .
-.Pp
-.Fn tzfree
-frees the
-.Fa tz
-argument previously returned by
-.Fa tzalloc .
-.Pp
-The structure (of type)
-.Va "struct tm"
-includes the following fields:
-.Bd -literal -offset indent
-int tm_sec;	/* seconds after the minute [0,61] */
-int tm_min;	/* minutes after the hour [0,59] */
-int tm_hour;	/* hours since midnight [0,23] */
-int tm_mday;	/* day of the month [1,31] */
-int tm_mon;	/* months since January [0,11] */
-int tm_year;	/* years since 1900 */
-int tm_wday;	/* day of week [0,6] (Sunday = 0) */
-int tm_yday;	/* day of year [0,365] (Jan 1 = 0) */
-int tm_isdst;	/* daylight savings flag */
-long tm_gmtoff;	/* offset from UTC in seconds */
-char *tm_zone;	/* abbreviation of timezone name */
-.Ed
-.Pp
-The
-.Fa tm_zone
-and
-.Fa tm_gmtoff
-fields exist, and are filled in, only if arrangements to do
-so were made when the library containing these functions was
-created.
-There is no guarantee that these fields will continue to exist
-in this form in future releases of this code.
-The
-.Fa tm_zone
-field will become invalid and point to freed storage if the corresponding
-.Va "struct tm"
-was returned by
-.Fn localtime_rz
-and the
-.Ft "const timezone_t"
-.Fa tz
-argument has been freed by
-.Fn tzfree .
-.Pp
-.Fa tm_isdst
-is non-zero if summer time is in effect.
-.Pp
-.Fa tm_gmtoff
-is the offset (in seconds) of the time represented
-from UTC, with positive values indicating east
-of the Prime Meridian.
+.El
 .Sh RETURN VALUES
+.Bl -bullet
+.It
 On success the
 .Fn asctime
 and
@@ -310,6 +330,7 @@ function return a pointer to the user-supplied buffer.
 On failure they all return
 .Dv NULL
 and no errors are defined for them.
+.It
 On success the
 .Fn gmtime ,
 and
@@ -328,12 +349,13 @@ On failure they all return
 and the global variable
 .Va errno
 is set to indicate the error.
+.It
 The
 .Fn mktime
 and
 .Fn mktime_z
 function returns the specified time since the Epoch as a
-.Va time_t
+.Vt time_t
 type value.
 If the time cannot be represented, then
 .Fn mktime
@@ -344,6 +366,7 @@ return
 setting the global variable
 .Va errno
 to indicate the error.
+.It
 The
 .Fn tzalloc
 function returns a pointer to a
@@ -353,9 +376,11 @@ object or
 on failure, setting
 .Va errno
 to indicate the error.
+.It
 .Fn tzgetzone
 function returns string containing the name of the timezone given in
 .Fa tz .
+.El
 .Sh FILES
 .Bl -tag -width /usr/share/zoneinfo/posixrules -compact
 .It Pa /etc/localtime
@@ -373,25 +398,18 @@ If
 is absent, UTC leap seconds are loaded from
 .Pa /usr/share/zoneinfo/posixrules .
 .Sh ERRORS
-The
-.Fn gmtime_r ,
-.Fn localtime_r ,
-.Fn localtime_rz ,
-.Fn gmtime ,
-.Fn localtime ,
-and
-.Fn mktime ,
-and
-.Fn mktime_z
-will fail when:
+The described functions may fail with
 .Bl -tag -width Er
 .It Bq Er EINVAL
-The result cannot be represented.
+The result cannot be represented because a parameter is incorrect, or
+the conversion failed because no such time exists (for example a time
+in the DST gap).
 .It Bq Er EOVERFLOW
-The result cannot be represented.
+The result cannot be represented because the time requested is out of bounds
+and the time calculation resulted in overflow.
 .El
 .Pp
-All functions that return values except their
+All functions that return values, except their
 .Dq z
 variants, can also return the same errors as
 .Xr open 2
@@ -401,6 +419,7 @@ and
 .Xr getenv 3 ,
 .Xr strftime 3 ,
 .Xr time 3 ,
+.Xr tm 3 ,
 .Xr tzset 3 ,
 .Xr tzfile 5
 .Sh STANDARDS
@@ -413,19 +432,15 @@ The
 and
 .Fn mktime
 functions conform to
-.St -ansiC
-The
-.Fn ctime_r ,
-.Fn asctime_r ,
-.Fn localtime_r
-and
-.Fn gmtime_r
-functions conform to
-.St -p1003.1c-95 .
-.Sh NOTES
-The return values point to static data; the data is overwritten by
+.St -ansiC .
+Rest of the functions conform to
+.St -p1003.1-2008 .
+.Sh CAVEATS
+The functions that do not take an explicit
+.Ft timezone_t
+argument return values point to static data; the data is overwritten by
 each call.
-The
+For the above functions the
 .Fa tm_zone
 field of a returned
 .Va "struct tm"
@@ -433,11 +448,24 @@ points to a static array of characters, which
 will also be overwritten at the next call
 (and by calls to
 .Xr tzset 3 ) .
+The functions that do take an explicit
+.Ft timezone_t
+argument and set the fields of a supplied
+.Va "struct tm"
+should not call
+.Fn tzfree
+since the
+.Fa tm_zone
+field of the
+.Va "struct tm"
+points to data allocated by
+.Fn tzalloc .
 .Pp
+The
 .Fn asctime
 and
 .Fn ctime
-behave strangely for years before 1000 or after 9999.
+functions behave strangely for years before 1000 or after 9999.
 The 1989 and 1999 editions of the C Standard say
 that years from \-99 through 999 are converted without
 extra spaces, but this conflicts with longstanding
diff --git a/lib/libc/time/difftime.c b/lib/libc/time/difftime.c
index 75cb18e51..2f55eb2f7 100644
--- a/lib/libc/time/difftime.c
+++ b/lib/libc/time/difftime.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: difftime.c,v 1.10 2009/12/31 22:49:16 mlelstv Exp $	*/
+/*	$NetBSD: difftime.c,v 1.11 2012/03/20 16:39:08 matt Exp $	*/
 
 /*
 ** This file is in the public domain, so clarified as of
@@ -10,7 +10,7 @@
 #if 0
 static char	elsieid[] = "@(#)difftime.c	8.1";
 #else
-__RCSID("$NetBSD: difftime.c,v 1.10 2009/12/31 22:49:16 mlelstv Exp $");
+__RCSID("$NetBSD: difftime.c,v 1.11 2012/03/20 16:39:08 matt Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -19,9 +19,7 @@ __RCSID("$NetBSD: difftime.c,v 1.10 2009/12/31 22:49:16 mlelstv Exp $");
 #include "private.h"	/* for time_t, TYPE_INTEGRAL, and TYPE_SIGNED */
 
 double
-difftime(time1, time0)
-const time_t	time1;
-const time_t	time0;
+difftime(const time_t time1, const time_t time0)
 {
 	/*
 	** If (sizeof (double) > sizeof (time_t)) simply convert and subtract
diff --git a/lib/libc/time/getdate.3 b/lib/libc/time/getdate.3
index c501ad733..b304f94fc 100644
--- a/lib/libc/time/getdate.3
+++ b/lib/libc/time/getdate.3
@@ -1,4 +1,4 @@
-.\"	$NetBSD: getdate.3,v 1.1 2009/05/14 02:37:36 ginsbach Exp $
+.\"	$NetBSD: getdate.3,v 1.2 2011/04/14 05:50:49 jruoho Exp $
 .\"
 .\" Copyright (c) 2009, The NetBSD Foundation.
 .\" All Rights Reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 8, 2009
+.Dd April 14, 2011
 .Dt GETDATE 3
 .Os
 .Sh NAME
@@ -50,7 +50,8 @@ function converts a date or time character string pointed to by
 .Fa str
 into a static
 .Va tm
-structure.
+structure described in
+.Xr tm 3 .
 .Pp
 The input string is parsed and interpreted using templates.
 A text file containing templates is specified by the
diff --git a/lib/libc/time/localtime.c b/lib/libc/time/localtime.c
index 9323a78fd..ba092bbd7 100644
--- a/lib/libc/time/localtime.c
+++ b/lib/libc/time/localtime.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: localtime.c,v 1.54 2011/01/15 15:42:10 christos Exp $	*/
+/*	$NetBSD: localtime.c,v 1.67 2012/03/20 16:39:08 matt Exp $	*/
 
 /*
 ** This file is in the public domain, so clarified as of
@@ -8,9 +8,9 @@
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
 #if 0
-static char	elsieid[] = "@(#)localtime.c	8.9";
+static char	elsieid[] = "@(#)localtime.c	8.17";
 #else
-__RCSID("$NetBSD: localtime.c,v 1.54 2011/01/15 15:42:10 christos Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.67 2012/03/20 16:39:08 matt Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -28,14 +28,7 @@ __RCSID("$NetBSD: localtime.c,v 1.54 2011/01/15 15:42:10 christos Exp $");
 #include "reentrant.h"
 
 #if defined(__weak_alias)
-__weak_alias(ctime_r,__ctime_r50)
-__weak_alias(ctime_rz,__ctime_rz50)
 __weak_alias(daylight,_daylight)
-__weak_alias(mktime_z,__mktime_z50)
-__weak_alias(localtime_r,__localtime_r50)
-__weak_alias(localtime_rz,__localtime_rz50)
-__weak_alias(posix2time,__posix2time50)
-__weak_alias(posix2time_z,__posix2time_z50)
 __weak_alias(tzname,_tzname)
 #endif
 
@@ -338,6 +331,9 @@ settzname(void)
 		tzname[0] = tzname[1] = (__aconst char *)__UNCONST(gmt);
 		return;
 	}
+	/*
+	** And to get the latest zone names into tzname. . .
+	*/
 	for (i = 0; i < sp->typecnt; ++i) {
 		const struct ttinfo * const	ttisp = &sp->ttis[i];
 
@@ -346,7 +342,7 @@ settzname(void)
 #ifdef USG_COMPAT
 		if (ttisp->tt_isdst)
 			daylight = 1;
-		if (i == 0 || !ttisp->tt_isdst)
+		if (!ttisp->tt_isdst)
 			timezone = -(ttisp->tt_gmtoff);
 #endif /* defined USG_COMPAT */
 #ifdef ALTZONE
@@ -354,17 +350,6 @@ settzname(void)
 			altzone = -(ttisp->tt_gmtoff);
 #endif /* defined ALTZONE */
 	}
-	/*
-	** And to get the latest zone names into tzname. . .
-	*/
-	for (i = 0; i < sp->timecnt; ++i) {
-		register const struct ttinfo * const	ttisp =
-							&sp->ttis[
-								sp->types[i]];
-
-		tzname[ttisp->tt_isdst] =
-			&sp->chars[ttisp->tt_abbrind];
-	}
 	settzname_z(sp);
 }
 
@@ -385,17 +370,22 @@ tzload(timezone_t sp, const char *name, const int doextend)
 	int			i;
 	int			fid;
 	int			stored;
-	int			nread;
-	union {
+	ssize_t			nread;
+	typedef union {
 		struct tzhead	tzhead;
 		char		buf[2 * sizeof(struct tzhead) +
 					2 * sizeof *sp +
 					4 * TZ_MAX_TIMES];
-	} u;
+	} u_t;
+	u_t *			up;
+
+	up = calloc(1, sizeof *up);
+	if (up == NULL)
+		return -1;
 
 	sp->goback = sp->goahead = FALSE;
 	if (name == NULL && (name = TZDEFAULT) == NULL)
-		return -1;
+		goto oops;
 	{
 		int	doaccess;
 		/*
@@ -412,9 +402,9 @@ tzload(timezone_t sp, const char *name, const int doextend)
 		doaccess = name[0] == '/';
 		if (!doaccess) {
 			if ((p = TZDIR) == NULL)
-				return -1;
+				goto oops;
 			if ((strlen(p) + strlen(name) + 1) >= sizeof fullname)
-				return -1;
+				goto oops;
 			(void) strcpy(fullname, p);	/* XXX strcpy is safe */
 			(void) strcat(fullname, "/");	/* XXX strcat is safe */
 			(void) strcat(fullname, name);	/* XXX strcat is safe */
@@ -426,7 +416,7 @@ tzload(timezone_t sp, const char *name, const int doextend)
 			name = fullname;
 		}
 		if (doaccess && access(name, R_OK) != 0)
-			return -1;
+			goto oops;
 		/*
 		 * XXX potential security problem here if user of a set-id
 		 * program has set TZ (which is passed in as name) here,
@@ -434,30 +424,30 @@ tzload(timezone_t sp, const char *name, const int doextend)
 		 * above.
 		 */
 		if ((fid = open(name, OPEN_MODE)) == -1)
-			return -1;
+			goto oops;
 	}
-	nread = read(fid, u.buf, sizeof u.buf);
+	nread = read(fid, up->buf, sizeof up->buf);
 	if (close(fid) < 0 || nread <= 0)
-		return -1;
+		goto oops;
 	for (stored = 4; stored <= 8; stored *= 2) {
 		int		ttisstdcnt;
 		int		ttisgmtcnt;
 
-		ttisstdcnt = (int) detzcode(u.tzhead.tzh_ttisstdcnt);
-		ttisgmtcnt = (int) detzcode(u.tzhead.tzh_ttisgmtcnt);
-		sp->leapcnt = (int) detzcode(u.tzhead.tzh_leapcnt);
-		sp->timecnt = (int) detzcode(u.tzhead.tzh_timecnt);
-		sp->typecnt = (int) detzcode(u.tzhead.tzh_typecnt);
-		sp->charcnt = (int) detzcode(u.tzhead.tzh_charcnt);
-		p = u.tzhead.tzh_charcnt + sizeof u.tzhead.tzh_charcnt;
+		ttisstdcnt = (int) detzcode(up->tzhead.tzh_ttisstdcnt);
+		ttisgmtcnt = (int) detzcode(up->tzhead.tzh_ttisgmtcnt);
+		sp->leapcnt = (int) detzcode(up->tzhead.tzh_leapcnt);
+		sp->timecnt = (int) detzcode(up->tzhead.tzh_timecnt);
+		sp->typecnt = (int) detzcode(up->tzhead.tzh_typecnt);
+		sp->charcnt = (int) detzcode(up->tzhead.tzh_charcnt);
+		p = up->tzhead.tzh_charcnt + sizeof up->tzhead.tzh_charcnt;
 		if (sp->leapcnt < 0 || sp->leapcnt > TZ_MAX_LEAPS ||
 			sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES ||
 			sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES ||
 			sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS ||
 			(ttisstdcnt != sp->typecnt && ttisstdcnt != 0) ||
 			(ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
-				return -1;
-		if (nread - (p - u.buf) <
+				goto oops;
+		if (nread - (p - up->buf) <
 			sp->timecnt * stored +		/* ats */
 			sp->timecnt +			/* types */
 			sp->typecnt * 6 +		/* ttinfos */
@@ -465,16 +455,16 @@ tzload(timezone_t sp, const char *name, const int doextend)
 			sp->leapcnt * (stored + 4) +	/* lsinfos */
 			ttisstdcnt +			/* ttisstds */
 			ttisgmtcnt)			/* ttisgmts */
-				return -1;
+				goto oops;
 		for (i = 0; i < sp->timecnt; ++i) {
-			sp->ats[i] = (stored == 4) ?
-				detzcode(p) : detzcode64(p);
+			sp->ats[i] = (time_t)((stored == 4) ?
+				detzcode(p) : detzcode64(p));
 			p += stored;
 		}
 		for (i = 0; i < sp->timecnt; ++i) {
 			sp->types[i] = (unsigned char) *p++;
 			if (sp->types[i] >= sp->typecnt)
-				return -1;
+				goto oops;
 		}
 		for (i = 0; i < sp->typecnt; ++i) {
 			struct ttinfo *	ttisp;
@@ -484,11 +474,11 @@ tzload(timezone_t sp, const char *name, const int doextend)
 			p += 4;
 			ttisp->tt_isdst = (unsigned char) *p++;
 			if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1)
-				return -1;
+				goto oops;
 			ttisp->tt_abbrind = (unsigned char) *p++;
 			if (ttisp->tt_abbrind < 0 ||
 				ttisp->tt_abbrind > sp->charcnt)
-					return -1;
+					goto oops;
 		}
 		for (i = 0; i < sp->charcnt; ++i)
 			sp->chars[i] = *p++;
@@ -497,8 +487,8 @@ tzload(timezone_t sp, const char *name, const int doextend)
 			struct lsinfo *	lsisp;
 
 			lsisp = &sp->lsis[i];
-			lsisp->ls_trans = (stored == 4) ?
-				detzcode(p) : detzcode64(p);
+			lsisp->ls_trans = (time_t)((stored == 4) ?
+			    detzcode(p) : detzcode64(p));
 			p += stored;
 			lsisp->ls_corr = detzcode(p);
 			p += 4;
@@ -513,7 +503,7 @@ tzload(timezone_t sp, const char *name, const int doextend)
 				ttisp->tt_ttisstd = *p++;
 				if (ttisp->tt_ttisstd != TRUE &&
 					ttisp->tt_ttisstd != FALSE)
-						return -1;
+						goto oops;
 			}
 		}
 		for (i = 0; i < sp->typecnt; ++i) {
@@ -526,7 +516,7 @@ tzload(timezone_t sp, const char *name, const int doextend)
 				ttisp->tt_ttisgmt = *p++;
 				if (ttisp->tt_ttisgmt != TRUE &&
 					ttisp->tt_ttisgmt != FALSE)
-						return -1;
+						goto oops;
 			}
 		}
 		/*
@@ -560,11 +550,11 @@ tzload(timezone_t sp, const char *name, const int doextend)
 		/*
 		** If this is an old file, we're done.
 		*/
-		if (u.tzhead.tzh_version[0] == '\0')
+		if (up->tzhead.tzh_version[0] == '\0')
 			break;
-		nread -= p - u.buf;
+		nread -= p - up->buf;
 		for (i = 0; i < nread; ++i)
-			u.buf[i] = p[i];
+			up->buf[i] = p[i];
 		/*
 		** If this is a narrow integer time_t system, we're done.
 		*/
@@ -574,13 +564,13 @@ tzload(timezone_t sp, const char *name, const int doextend)
 			break;
 	}
 	if (doextend && nread > 2 &&
-		u.buf[0] == '\n' && u.buf[nread - 1] == '\n' &&
+		up->buf[0] == '\n' && up->buf[nread - 1] == '\n' &&
 		sp->typecnt + 2 <= TZ_MAX_TYPES) {
 			struct __state ts;
 			int	result;
 
-			u.buf[nread - 1] = '\0';
-			result = tzparse(&ts, &u.buf[1], FALSE);
+			up->buf[nread - 1] = '\0';
+			result = tzparse(&ts, &up->buf[1], FALSE);
 			if (result == 0 && ts.typecnt == 2 &&
 				sp->charcnt + ts.charcnt <= TZ_MAX_CHARS) {
 					for (i = 0; i < 2; ++i)
@@ -624,7 +614,11 @@ tzload(timezone_t sp, const char *name, const int doextend)
 					break;
 		}
 	}
+	free(up);
 	return 0;
+oops:
+	free(up);
+	return -1;
 }
 
 static int
@@ -665,8 +659,7 @@ static const int	year_lengths[2] = {
 */
 
 static const char *
-getzname(strp)
-const char *	strp;
+getzname(const char *strp)
 {
 	char	c;
 
@@ -703,11 +696,7 @@ getqzname(const char *strp, const int delim)
 */
 
 static const char *
-getnum(strp, nump, min, max)
-const char *	strp;
-int * const		nump;
-const int		min;
-const int		max;
+getnum(const char *strp, int * const nump, const int min, const int max)
 {
 	char	c;
 	int	num;
@@ -879,7 +868,7 @@ transtime(const time_t janfirst, const int year, const struct rule *const rulep,
 		** add SECSPERDAY times the day number-1 to the time of
 		** January 1, midnight, to get the day.
 		*/
-		value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
+		value = (time_t)(janfirst + (rulep->r_day - 1) * SECSPERDAY);
 		if (leapyear && rulep->r_day >= 60)
 			value += SECSPERDAY;
 		break;
@@ -890,7 +879,7 @@ transtime(const time_t janfirst, const int year, const struct rule *const rulep,
 		** Just add SECSPERDAY times the day number to the time of
 		** January 1, midnight, to get the day.
 		*/
-		value = janfirst + rulep->r_day * SECSPERDAY;
+		value = (time_t)(janfirst + rulep->r_day * SECSPERDAY);
 		break;
 
 	case MONTH_NTH_DAY_OF_WEEK:
@@ -899,7 +888,7 @@ transtime(const time_t janfirst, const int year, const struct rule *const rulep,
 		*/
 		value = janfirst;
 		for (i = 0; i < rulep->r_mon - 1; ++i)
-			value += mon_lengths[leapyear][i] * SECSPERDAY;
+			value += (time_t)(mon_lengths[leapyear][i] * SECSPERDAY);
 
 		/*
 		** Use Zeller's Congruence to get day-of-week of first day of
@@ -932,7 +921,7 @@ transtime(const time_t janfirst, const int year, const struct rule *const rulep,
 		/*
 		** "d" is the day-of-month (zero-origin) of the day we want.
 		*/
-		value += d * SECSPERDAY;
+		value += (time_t)(d * SECSPERDAY);
 		break;
 	}
 
@@ -942,7 +931,7 @@ transtime(const time_t janfirst, const int year, const struct rule *const rulep,
 	** time on that day, add the transition time and the current offset
 	** from UTC.
 	*/
-	return value + rulep->r_time + offset;
+	return (time_t)(value + rulep->r_time + offset);
 }
 
 /*
@@ -1035,9 +1024,10 @@ tzparse(timezone_t sp, const char *name, const int lastditch)
 			/*
 			** Two transitions per year, from EPOCH_YEAR forward.
 			*/
+			memset(sp->ttis, 0, sizeof(sp->ttis));
 			sp->ttis[0].tt_gmtoff = -dstoffset;
 			sp->ttis[0].tt_isdst = 1;
-			sp->ttis[0].tt_abbrind = stdlen + 1;
+			sp->ttis[0].tt_abbrind = (int)(stdlen + 1);
 			sp->ttis[1].tt_gmtoff = -stdoffset;
 			sp->ttis[1].tt_isdst = 0;
 			sp->ttis[1].tt_abbrind = 0;
@@ -1067,8 +1057,8 @@ tzparse(timezone_t sp, const char *name, const int lastditch)
 				}
 				sp->timecnt += 2;
 				newfirst = janfirst;
-				newfirst += year_lengths[isleap(year)] *
-					SECSPERDAY;
+				newfirst += (time_t)
+				    (year_lengths[isleap(year)] * SECSPERDAY);
 				if (newfirst <= janfirst)
 					break;
 				janfirst = newfirst;
@@ -1134,11 +1124,11 @@ tzparse(timezone_t sp, const char *name, const int lastditch)
 					** offset.
 					*/
 					if (isdst && !sp->ttis[j].tt_ttisstd) {
-						sp->ats[i] += dstoffset -
-							theirdstoffset;
+						sp->ats[i] += (time_t)
+						    (dstoffset - theirdstoffset);
 					} else {
-						sp->ats[i] += stdoffset -
-							theirstdoffset;
+						sp->ats[i] += (time_t)
+						    (stdoffset - theirstdoffset);
 					}
 				}
 				theiroffset = -sp->ttis[j].tt_gmtoff;
@@ -1148,27 +1138,28 @@ tzparse(timezone_t sp, const char *name, const int lastditch)
 			}
 			/*
 			** Finally, fill in ttis.
-			** ttisstd and ttisgmt need not be handled.
 			*/
+			memset(sp->ttis, 0, sizeof(sp->ttis));
 			sp->ttis[0].tt_gmtoff = -stdoffset;
 			sp->ttis[0].tt_isdst = FALSE;
 			sp->ttis[0].tt_abbrind = 0;
 			sp->ttis[1].tt_gmtoff = -dstoffset;
 			sp->ttis[1].tt_isdst = TRUE;
-			sp->ttis[1].tt_abbrind = stdlen + 1;
+			sp->ttis[1].tt_abbrind = (int)(stdlen + 1);
 			sp->typecnt = 2;
 		}
 	} else {
 		dstlen = 0;
 		sp->typecnt = 1;		/* only standard time */
 		sp->timecnt = 0;
+		memset(sp->ttis, 0, sizeof(sp->ttis));
 		sp->ttis[0].tt_gmtoff = -stdoffset;
 		sp->ttis[0].tt_isdst = 0;
 		sp->ttis[0].tt_abbrind = 0;
 	}
-	sp->charcnt = stdlen + 1;
+	sp->charcnt = (int)(stdlen + 1);
 	if (dstlen != 0)
-		sp->charcnt += dstlen + 1;
+		sp->charcnt += (int)(dstlen + 1);
 	if ((size_t) sp->charcnt > sizeof sp->chars)
 		return -1;
 	cp = sp->chars;
@@ -1336,7 +1327,8 @@ localsub(const timezone_t sp, const time_t * const timep, const long offset,
 				seconds = sp->ats[0] - t;
 			else	seconds = t - sp->ats[sp->timecnt - 1];
 			--seconds;
-			tcycles = seconds / YEARSPERREPEAT / AVGSECSPERYEAR;
+			tcycles = (time_t)
+			    (seconds / YEARSPERREPEAT / AVGSECSPERYEAR);
 			++tcycles;
 			icycles = tcycles;
 			if (tcycles - icycles >= 1 || icycles - tcycles >= 1)
@@ -1393,7 +1385,8 @@ localsub(const timezone_t sp, const time_t * const timep, const long offset,
 	*/
 	result = timesub(sp, &t, ttisp->tt_gmtoff, tmp);
 	tmp->tm_isdst = ttisp->tt_isdst;
-	tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];
+	if (sp == lclptr)
+		tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];
 #ifdef TM_ZONE
 	tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind];
 #endif /* defined TM_ZONE */
@@ -1477,7 +1470,12 @@ gmtsub(const timezone_t sp, const time_t * const timep, const long offset,
 struct tm *
 gmtime(const time_t *const timep)
 {
-	return gmtsub(NULL, timep, 0L, &tm);
+	struct tm *tmp = gmtsub(NULL, timep, 0L, &tm);
+
+	if (tmp == NULL)
+		errno = EOVERFLOW;
+
+	return tmp;
 }
 
 /*
@@ -1487,7 +1485,12 @@ gmtime(const time_t *const timep)
 struct tm *
 gmtime_r(const time_t * const timep, struct tm *tmp)
 {
-	return gmtsub(NULL, timep, 0L, tmp);
+	tmp = gmtsub(NULL, timep, 0L, tmp);
+
+	if (tmp == NULL)
+		errno = EOVERFLOW;
+
+	return tmp;
 }
 
 #ifdef STD_INSPIRED
@@ -1495,13 +1498,23 @@ gmtime_r(const time_t * const timep, struct tm *tmp)
 struct tm *
 offtime(const time_t *const timep, long offset)
 {
-	return gmtsub(NULL, timep, offset, &tm);
+	struct tm *tmp = gmtsub(NULL, timep, offset, &tm);
+
+	if (tmp == NULL)
+		errno = EOVERFLOW;
+
+	return tmp;
 }
 
 struct tm *
 offtime_r(const time_t *timep, long offset, struct tm *tmp)
 {
-	return gmtsub(NULL, timep, offset, tmp);
+	tmp = gmtsub(NULL, timep, offset, tmp);
+
+	if (tmp == NULL)
+		errno = EOVERFLOW;
+
+	return tmp;
 }
 
 #endif /* defined STD_INSPIRED */
@@ -1556,7 +1569,7 @@ timesub(const timezone_t sp, const time_t *const timep, const long offset,
 		}
 	}
 	y = EPOCH_YEAR;
-	tdays = *timep / SECSPERDAY;
+	tdays = (time_t)(*timep / SECSPERDAY);
 	rem = (long) (*timep - tdays * SECSPERDAY);
 	while (tdays < 0 || tdays >= year_lengths[isleap(y)]) {
 		int		newy;
@@ -1583,7 +1596,7 @@ timesub(const timezone_t sp, const time_t *const timep, const long offset,
 		long	seconds;
 
 		seconds = tdays * SECSPERDAY + 0.5;
-		tdays = seconds / SECSPERDAY;
+		tdays = (time_t)(seconds / SECSPERDAY);
 		rem += (long) (seconds - tdays * SECSPERDAY);
 	}
 	/*
@@ -1699,27 +1712,31 @@ ctime_rz(const timezone_t sp, const time_t * timep, char *buf)
 */
 
 static int
-increment_overflow(int *number, int delta)
+increment_overflow(int *ip, int j)
 {
-	int	number0;
+	int	i = *ip;
 
-	number0 = *number;
-	if (delta < 0 ? number0 < INT_MIN - delta : INT_MAX - delta < number0)
-		  return 1;
-	*number += delta;
-	return 0;
+	/*
+	** If i >= 0 there can only be overflow if i + j > INT_MAX
+	** or if j > INT_MAX - i; given i >= 0, INT_MAX - i cannot overflow.
+	** If i < 0 there can only be overflow if i + j < INT_MIN
+	** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow.
+	*/
+	if ((i >= 0) ? (j > INT_MAX - i) : (j < INT_MIN - i))
+		return TRUE;
+	*ip += j;
+	return FALSE;
 }
 
 static int
-long_increment_overflow(long *number, int delta)
+long_increment_overflow(long *lp, int m)
 {
-	long	number0;
+	long l = *lp;
 
-	number0 = *number;
-	if (delta < 0 ? number0 < LONG_MIN - delta : LONG_MAX - delta < number0)
-		  return 1;
-	*number += delta;
-	return 0;
+	if ((l >= 0) ? (m > LONG_MAX - l) : (m < LONG_MIN - l))
+		return TRUE;
+	*lp += m;
+	return FALSE;
 }
 
 static int
@@ -1771,6 +1788,9 @@ time2sub(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 	long			li;
 	time_t			lo;
 	time_t			hi;
+#ifdef NO_ERROR_IN_DST_GAP
+	time_t			ilo;
+#endif
 	long				y;
 	time_t				newt;
 	time_t				t;
@@ -1778,27 +1798,30 @@ time2sub(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 
 	*okayp = FALSE;
 	yourtm = *tmp;
+#ifdef NO_ERROR_IN_DST_GAP
+again:
+#endif
 	if (do_norm_secs) {
 		if (normalize_overflow(&yourtm.tm_min, &yourtm.tm_sec,
-			SECSPERMIN))
-				return WRONG;
+		    SECSPERMIN))
+			goto overflow;
 	}
 	if (normalize_overflow(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR))
-		return WRONG;
+		goto overflow;
 	if (normalize_overflow(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY))
-		return WRONG;
+		goto overflow;
 	y = yourtm.tm_year;
 	if (long_normalize_overflow(&y, &yourtm.tm_mon, MONSPERYEAR))
-		return WRONG;
+		goto overflow;
 	/*
 	** Turn y into an actual year number for now.
 	** It is converted back to an offset from TM_YEAR_BASE later.
 	*/
 	if (long_increment_overflow(&y, TM_YEAR_BASE))
-		return WRONG;
+		goto overflow;
 	while (yourtm.tm_mday <= 0) {
 		if (long_increment_overflow(&y, -1))
-			return WRONG;
+			goto overflow;
 		li = y + (1 < yourtm.tm_mon);
 		yourtm.tm_mday += year_lengths[isleap(li)];
 	}
@@ -1806,7 +1829,7 @@ time2sub(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 		li = y + (1 < yourtm.tm_mon);
 		yourtm.tm_mday -= year_lengths[isleap(li)];
 		if (long_increment_overflow(&y, 1))
-			return WRONG;
+			goto overflow;
 	}
 	for ( ; ; ) {
 		i = mon_lengths[isleap(y)][yourtm.tm_mon];
@@ -1816,14 +1839,14 @@ time2sub(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 		if (++yourtm.tm_mon >= MONSPERYEAR) {
 			yourtm.tm_mon = 0;
 			if (long_increment_overflow(&y, 1))
-				return WRONG;
+				goto overflow;
 		}
 	}
 	if (long_increment_overflow(&y, -TM_YEAR_BASE))
-		return WRONG;
-	yourtm.tm_year = y;
+		goto overflow;
+	yourtm.tm_year = (int)y;
 	if (yourtm.tm_year != y)
-		return WRONG;
+		goto overflow;
 	if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN)
 		saved_seconds = 0;
 	else if (y + TM_YEAR_BASE < EPOCH_YEAR) {
@@ -1836,7 +1859,7 @@ time2sub(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 		** which is a safer assumption than using 58 would be.
 		*/
 		if (increment_overflow(&yourtm.tm_sec, 1 - SECSPERMIN))
-			return WRONG;
+			goto overflow;
 		saved_seconds = yourtm.tm_sec;
 		yourtm.tm_sec = SECSPERMIN - 1;
 	} else {
@@ -1865,6 +1888,9 @@ time2sub(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 			lo *= 2;
 		hi = -(lo + 1);
 	}
+#ifdef NO_ERROR_IN_DST_GAP
+	ilo = lo;
+#endif
 	for ( ; ; ) {
 		t = lo / 2 + hi / 2;
 		if (t < lo)
@@ -1883,16 +1909,34 @@ time2sub(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 			if (t == lo) {
 				++t;
 				if (t <= lo)
-					return WRONG;
+					goto overflow;
 				++lo;
 			} else if (t == hi) {
 				--t;
 				if (t >= hi)
-					return WRONG;
+					goto overflow;
 				--hi;
 			}
+#ifdef NO_ERROR_IN_DST_GAP
+			if (ilo != lo && lo - 1 == hi && yourtm.tm_isdst < 0 &&
+			    do_norm_secs) {
+				for (i = sp->typecnt - 1; i >= 0; --i) {
+					for (j = sp->typecnt - 1; j >= 0; --j) {
+						time_t off;
+						if (sp->ttis[j].tt_isdst ==
+						    sp->ttis[i].tt_isdst)
+							continue;
+						off = sp->ttis[j].tt_gmtoff -
+						    sp->ttis[i].tt_gmtoff;
+						yourtm.tm_sec += off < 0 ?
+						    -off : off;
+						goto again;
+					}
+				}
+			}
+#endif
 			if (lo > hi)
-				return WRONG;
+				goto invalid;
 			if (dir > 0)
 				hi = t;
 			else	lo = t;
@@ -1907,15 +1951,15 @@ time2sub(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 		** gets checked.
 		*/
 		if (sp == NULL)
-			return WRONG;
+			goto invalid;
 		for (i = sp->typecnt - 1; i >= 0; --i) {
 			if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
 				continue;
 			for (j = sp->typecnt - 1; j >= 0; --j) {
 				if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
 					continue;
-				newt = t + sp->ttis[j].tt_gmtoff -
-					sp->ttis[i].tt_gmtoff;
+				newt = (time_t)(t + sp->ttis[j].tt_gmtoff -
+				    sp->ttis[i].tt_gmtoff);
 				if ((*funcp)(sp, &newt, offset, &mytm) == NULL)
 					continue;
 				if (tmcomp(&mytm, &yourtm) != 0)
@@ -1929,18 +1973,23 @@ time2sub(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 				goto label;
 			}
 		}
-		return WRONG;
+		goto invalid;
 	}
 label:
 	newt = t + saved_seconds;
 	if ((newt < t) != (saved_seconds < 0))
-		return WRONG;
+		goto overflow;
 	t = newt;
 	if ((*funcp)(sp, &t, offset, tmp)) {
 		*okayp = TRUE;
 		return t;
-	} else
-		return WRONG;
+	}
+overflow:
+	errno = EOVERFLOW;
+	return WRONG;
+invalid:
+	errno = EINVAL;
+	return WRONG;
 }
 
 static time_t
@@ -1971,6 +2020,10 @@ time1(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 	int				types[TZ_MAX_TYPES];
 	int				okay;
 
+	if (tmp == NULL) {
+		errno = EINVAL;
+		return WRONG;
+	}
 	if (tmp->tm_isdst > 1)
 		tmp->tm_isdst = 1;
 	t = time2(sp, tmp, funcp, offset, &okay);
@@ -1993,8 +2046,10 @@ time1(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 	** We try to divine the type they started from and adjust to the
 	** type they need.
 	*/
-	if (sp == NULL)
+	if (sp == NULL) {
+		errno = EINVAL;
 		return WRONG;
+	}
 	for (i = 0; i < sp->typecnt; ++i)
 		seen[i] = FALSE;
 	nseen = 0;
@@ -2022,6 +2077,7 @@ time1(const timezone_t sp, struct tm *const tmp, subfun_t funcp,
 			tmp->tm_isdst = !tmp->tm_isdst;
 		}
 	}
+	errno = EOVERFLOW;
 	return WRONG;
 }
 
@@ -2033,8 +2089,6 @@ mktime_z(const timezone_t sp, struct tm *tmp)
 		t = time1(NULL, tmp, gmtsub, 0L);
 	else
 		t = time1(sp, tmp, localsub, 0L);
-	if (t == WRONG)
-		errno = EOVERFLOW;
 	return t;
 }
 
@@ -2063,7 +2117,8 @@ timelocal_z(const timezone_t sp, struct tm *tmp)
 time_t
 timelocal(struct tm *const tmp)
 {
-	tmp->tm_isdst = -1;	/* in case it wasn't initialized */
+	if (tmp != NULL)
+		tmp->tm_isdst = -1;	/* in case it wasn't initialized */
 	return mktime(tmp);
 }
 
@@ -2072,10 +2127,9 @@ timegm(struct tm *const tmp)
 {
 	time_t t;
 
-	tmp->tm_isdst = 0;
+	if (tmp != NULL)
+		tmp->tm_isdst = 0;
 	t = time1(gmtptr, tmp, gmtsub, 0L);
-	if (t == WRONG)
-		errno = EOVERFLOW;
 	return t;
 }
 
@@ -2084,10 +2138,9 @@ timeoff(struct tm *const tmp, const long offset)
 {
 	time_t t;
 
-	tmp->tm_isdst = 0;
+	if (tmp != NULL)
+		tmp->tm_isdst = 0;
 	t = time1(gmtptr, tmp, gmtsub, offset);
-	if (t == WRONG)
-		errno = EOVERFLOW;
 	return t;
 }
 
@@ -2144,7 +2197,7 @@ leapcorr(const timezone_t sp, time_t *timep)
 time_t
 time2posix_z(const timezone_t sp, time_t t)
 {
-	return t - leapcorr(sp, &t);
+	return (time_t)(t - leapcorr(sp, &t));
 }
 
 time_t
@@ -2153,7 +2206,7 @@ time2posix(time_t t)
 	time_t result;
 	rwlock_wrlock(&lcl_lock);
 	tzset_unlocked();
-	result = t - leapcorr(lclptr, &t);
+	result = (time_t)(t - leapcorr(lclptr, &t));
 	rwlock_unlock(&lcl_lock);
 	return (result);
 }
@@ -2170,12 +2223,12 @@ posix2time_z(const timezone_t sp, time_t t)
 	** hit, the corresponding time doesn't exist,
 	** so we return an adjacent second.
 	*/
-	x = t + leapcorr(sp, &t);
-	y = x - leapcorr(sp, &x);
+	x = (time_t)(t + leapcorr(sp, &t));
+	y = (time_t)(x - leapcorr(sp, &x));
 	if (y < t) {
 		do {
 			x++;
-			y = x - leapcorr(sp, &x);
+			y = (time_t)(x - leapcorr(sp, &x));
 		} while (y < t);
 		if (t != y) {
 			return x - 1;
@@ -2183,7 +2236,7 @@ posix2time_z(const timezone_t sp, time_t t)
 	} else if (y > t) {
 		do {
 			--x;
-			y = x - leapcorr(sp, &x);
+			y = (time_t)(x - leapcorr(sp, &x));
 		} while (y > t);
 		if (t != y) {
 			return x + 1;
diff --git a/lib/libc/time/offtime.3 b/lib/libc/time/offtime.3
index 3e706eb31..ecfc7648c 100644
--- a/lib/libc/time/offtime.3
+++ b/lib/libc/time/offtime.3
@@ -1,7 +1,7 @@
-.\"	$NetBSD: offtime.3,v 1.2 2010/12/16 18:38:07 christos Exp $
+.\"	$NetBSD: offtime.3,v 1.3 2011/04/14 05:50:50 jruoho Exp $
 .\" Written by Klaus Klein, May 10, 2004.
 .\" Public domain.
-.Dd December 14, 2010
+.Dd April 14, 2011
 .Dt OFFTIME 3
 .Os
 .Sh NAME
@@ -71,4 +71,5 @@ It is equivalent to the C standard function
 and is provided for symmetry only.
 .Sh SEE ALSO
 .Xr ctime 3 ,
+.Xr tm 3 ,
 .Xr tzset 3
diff --git a/lib/libc/time/private.h b/lib/libc/time/private.h
index 5f31d68d6..e493831a2 100644
--- a/lib/libc/time/private.h
+++ b/lib/libc/time/private.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: private.h,v 1.25 2009/12/31 22:49:16 mlelstv Exp $	*/
+/*	$NetBSD: private.h,v 1.26 2012/08/09 12:38:25 christos Exp $	*/
 
 #ifndef PRIVATE_H
 #define PRIVATE_H
@@ -27,18 +27,6 @@
 ** Thank you!
 */
 
-/*
-** ID
-*/
-
-#ifndef lint
-#ifndef NOID
-#if 0
-static char	privatehid[] = "@(#)private.h	8.6";
-#endif
-#endif /* !defined NOID */
-#endif /* !defined lint */
-
 #define GRANDPARENTED	"Local time zone must be set--see zic manual page"
 
 /*
diff --git a/lib/libc/time/strftime.3 b/lib/libc/time/strftime.3
index d72e8e729..d039b52f3 100644
--- a/lib/libc/time/strftime.3
+++ b/lib/libc/time/strftime.3
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     from: @(#)strftime.3	5.12 (Berkeley) 6/29/91
-.\"	$NetBSD: strftime.3,v 1.27 2010/12/16 18:38:07 christos Exp $
+.\"	$NetBSD: strftime.3,v 1.29 2012/04/06 11:35:39 wiz Exp $
 .\"
-.Dd December 14, 2010
+.Dd April 14, 2011
 .Dt STRFTIME 3
 .Os
 .Sh NAME
@@ -190,7 +190,7 @@ is replaced by the year without century as a decimal number [00,99].
 .It Cm \&%Z
 is replaced by the time zone name.
 .It Cm \&%z
-is replaced by the offset from ITC in the ISO 8601 format
+is replaced by the offset from UTC in the ISO 8601 format
 .Dq Li [-]hhmm .
 .It Cm %%
 is replaced by
@@ -210,7 +210,8 @@ argument.
 .Xr printf 1 ,
 .Xr ctime 3 ,
 .Xr printf 3 ,
-.Xr strptime 3
+.Xr strptime 3 ,
+.Xr tm 3
 .Sh STANDARDS
 The
 .Fn strftime
diff --git a/lib/libc/time/strftime.c b/lib/libc/time/strftime.c
index 62020d6c2..6676db411 100644
--- a/lib/libc/time/strftime.c
+++ b/lib/libc/time/strftime.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: strftime.c,v 1.21 2010/12/16 18:38:07 christos Exp $	*/
+/*	$NetBSD: strftime.c,v 1.22 2012/03/20 16:39:08 matt Exp $	*/
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
@@ -6,7 +6,7 @@
 static char	elsieid[] = "@(#)strftime.c	7.64";
 static char	elsieid[] = "@(#)strftime.c	8.3";
 #else
-__RCSID("$NetBSD: strftime.c,v 1.21 2010/12/16 18:38:07 christos Exp $");
+__RCSID("$NetBSD: strftime.c,v 1.22 2012/03/20 16:39:08 matt Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -590,11 +590,8 @@ strftime(char * const s, const size_t maxsize,
 }
 
 static char *
-_conv(n, format, pt, ptlim)
-const int		n;
-const char * const	format;
-char * const		pt;
-const char * const	ptlim;
+_conv(const int	n, const char * const format, char * const pt,
+    const char * const ptlim)
 {
 	char	buf[INT_STRLEN_MAXIMUM(int) + 1];
 
@@ -603,10 +600,7 @@ const char * const	ptlim;
 }
 
 static char *
-_add(str, pt, ptlim)
-const char *		str;
-char *			pt;
-const char * const	ptlim;
+_add(const char *str, char *pt, const char * const ptlim)
 {
 	while (pt < ptlim && (*pt = *str++) != '\0')
 		++pt;
@@ -622,13 +616,8 @@ const char * const	ptlim;
 */
 
 static char *
-_yconv(a, b, convert_top, convert_yy, pt, ptlim)
-const int		a;
-const int		b;
-const int		convert_top;
-const int		convert_yy;
-char *			pt;
-const char * const	ptlim;
+_yconv(const int a, const int b, const int convert_top, const int convert_yy,
+    char *pt, const char * const ptlim)
 {
 	register int	lead;
 	register int	trail;
diff --git a/lib/libc/time/strptime.3 b/lib/libc/time/strptime.3
index 95843accc..da92efa6f 100644
--- a/lib/libc/time/strptime.3
+++ b/lib/libc/time/strptime.3
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strptime.3,v 1.27 2009/05/24 02:30:17 ginsbach Exp $
+.\"	$NetBSD: strptime.3,v 1.29 2011/04/12 08:40:34 jruoho Exp $
 .\"
 .\" Copyright (c) 1997, 1998, 2008 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 24, 2009
+.Dd April 12, 2011
 .Dt STRPTIME 3
 .Os
 .Sh NAME
@@ -316,12 +316,15 @@ If successful, the
 .Fn strptime
 function returns a pointer to the character following the last character
 parsed.
-Otherwise, a null pointer is returned.
+Otherwise, a
+.Dv NULL
+pointer is returned.
 .Sh SEE ALSO
 .Xr ctime 3 ,
 .Xr isspace 3 ,
 .Xr localtime 3 ,
-.Xr strftime 3
+.Xr strftime 3 ,
+.Xr tm 3
 .Sh STANDARDS
 The
 .Fn strptime
diff --git a/lib/libc/time/strptime.c b/lib/libc/time/strptime.c
index f043c52b9..86074e880 100644
--- a/lib/libc/time/strptime.c
+++ b/lib/libc/time/strptime.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: strptime.c,v 1.35 2009/12/14 20:45:02 matt Exp $	*/
+/*	$NetBSD: strptime.c,v 1.36 2012/03/13 21:13:48 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: strptime.c,v 1.35 2009/12/14 20:45:02 matt Exp $");
+__RCSID("$NetBSD: strptime.c,v 1.36 2012/03/13 21:13:48 christos Exp $");
 #endif
 
 #include "namespace.h"
@@ -554,7 +554,7 @@ find_string(const u_char *bp, int *tgt, const char * const *n1,
 		const char * const *n2, int c)
 {
 	int i;
-	unsigned int len;
+	size_t len;
 
 	/* check full name - then abbreviated ones */
 	for (; n1 != NULL; n1 = n2, n2 = NULL) {
diff --git a/lib/libc/time/tz-art.htm b/lib/libc/time/tz-art.htm
index cba330e0b..8c2aca4da 100644
--- a/lib/libc/time/tz-art.htm
+++ b/lib/libc/time/tz-art.htm
@@ -8,16 +8,13 @@ PUBLIC "-//W3C//DTD HTML 4.01//EN"
 
 
 

Time and the Arts

-
-@(#)tz-art.htm 8.13 -

This file is in the public domain, so clarified as of 2009-05-17 by Arthur David Olson.

Please send corrections to this web page to the -time zone mailing list.

+time zone mailing list.

See also Sources for Time Zone and Daylight Saving Time Data.


@@ -227,7 +224,30 @@ Supernaw. AMG Rating4.5 stars ADO Rating1.5 stars NotesThe title song is also available on "Bob Dylan's Greatest Hits" and "The Essential Bob Dylan." - +  + +ArtistLuciana Souza +CDTide +Copyright Date2009 +LabelUniversal Jazz France +IDB0012688-02 +Total Time42:31 +AMG Rating3.5 stars +ADO Rating2.5 stars +NotesIncludes the song "Fire and Wood" with the lyric +"The clocks were turned back you remeber/Think it's still November." + +  +ArtistKen Nordine +CDYou're Getting Better: The Word Jazz Dot Masters +Copyright Date2005 +LabelGeffen +IDB0005171-02 +Total Time156:22 +ADO Rating1 star +AMG Rating4.5 stars +NotesIncludes the piece "What Time Is It" +("He knew what time it was everywhere...that counted").   TV episode titleThe Lost Hour @@ -354,7 +374,13 @@ premonition in the "We Had a Dream" episode of "Medium" (originally aired 2007-02-28).
  • -In the 1946 "A Matter of Life and Death," +In the "30 Rock" episode "Anna Howard Shaw Day" (first broadcast 2010-02-11), +Jack Donaghy's date realizes that a Geneva-to-New-York business phone call +received in the evening must be fake given the difference in local times. +
  • +
  • +In the 1946 movie "A Matter of Life and Death" +(U.S. title "Stairway to Heaven") there is a reference to British Double Summer Time. The time does not play a large part in the plot; it's just a passing reference to the time when one of the @@ -363,6 +389,36 @@ The IMDb page is at http://us.imdb.com/title/tt0038733/ . (Dave Cantor) +
  • +The 1953 railway comedy movie "The Titfield Thunderbolt" includes a +play on words on British Double Summer Time. Valentine's wife wants +him to leave the pub and asks him, "Do you know what time it is?" +And he, happy where he is, replies: "Yes, my love. Summer double time." +IMDB page: + +http://us.imdb.com/title/tt0046436/ +. (Mark Brader, 2009-10-02) +
  • +
  • +The premise of the 1999 caper movie "Entrapment" involves computers +in an international banking network being shut down briefly at +midnight in each time zone to avoid any problems at the transition +from the year 1999 to 2000 in that zone. (Hmmmm.) If this shutdown +is extended by 10 seconds, it will create a one-time opportunity for +a gigantic computerized theft. To achieve this, at one location the +crooks interfere with the microwave system supplying time signals to +the computer, advancing the time by 0.1 second each minute over the +last hour of 1999. (So this movie teaches us that 0.1 x 60 = 10.) +IMDB page: + +http://us.imdb.com/title/tt0137494/ +. (Mark Brader, 2009-10-02) +
  • +
  • +In "The Todd Couple" episode of "Outsourced" (first aired 2011-02-10), +Manmeet sets up teledates for 6:00 and 9:00; +since one is with a New Yorker and the other with a San Franciscan, +hilarity ensues.

  • @@ -374,6 +430,18 @@ Now that's pretty near 100 years, daylight savings [sic]." as noted by Will Fitzerald)
  • +Brady: "...[Bishop Usher] determined that the Lord began the Creation +on the 23rd of October in the Year 4004 B.C. at -- uh, at 9 A.M.!" +
    +Drummond: "That Eastern Standard Time? (Laughter) Or Rocky Mountain +Time? (More laughter) It wasn't daylight-saving time, was it? Because +the Lord didn't make the sun until the fourth day!" +
    +(From the play "Inherit the Wind" by Jerome Lawrence and Robert E. Lee, +filmed in 1960 with Spencer Tracy as Drummond and Fredric March as +Brady, and several other times. Thanks to Mark Brader.) +
  • +
  • "Good news." "What did they do? Extend Daylight Saving Time year round?" (Professional tanner George Hamilton, in dialog from a @@ -412,6 +480,13 @@ or are you trying to dazzle me with your command of time zones?" It is already tomorrow in Australia." (Charles M. Schulz, provided by Steve Summit)
  • +
  • +"I put myself and my staff through this crazy, huge ordeal, all because +I refused to go on at midnight, okay? And so I work, you know, and +then I get this job at eleven, supposed to be a big deal. Then +yesterday daylight [saving] time ended. Right now it's basically +midnight." (Conan O'Brien on the 2010-11-08 premier of "Conan.") +
  • diff --git a/lib/libc/time/tz-link.htm b/lib/libc/time/tz-link.htm index fe58bf785..9d5a7a0dd 100644 --- a/lib/libc/time/tz-link.htm +++ b/lib/libc/time/tz-link.htm @@ -8,7 +8,7 @@ - + @@ -17,16 +17,13 @@

    Sources for Time Zone and Daylight Saving Time Data

    -
    -@(#)tz-link.htm 8.22 -

    This file is in the public domain, so clarified as of 2009-05-17 by Arthur David Olson.

    Please send corrections to this web page to the -time zone mailing list.

    +time zone mailing list.

    The tz database

    The public-domain @@ -40,8 +37,8 @@ href="http://en.wikipedia.org/wiki/Coordinated_Universal_Time">UTC offsets, and daylight-saving rules. -This database (often called tz or zoneinfo) +This database (often called zoneinfo or tz) is used by several implementations, including the @@ -83,37 +80,50 @@ implementation set the TZ environment variable to the location's full name, e.g., TZ="America/New_York".

    In the tz database's -FTP distribution +FTP releases the code is in the file tzcodeC.tar.gz, where C is the code's version; similarly, the data are in tzdataD.tar.gz, where D is the data's version. +Each version is a four-digit year followed by lower-case letters +(a through z, then za through zz, then zza through zzz, and so on). +Convenience links to +the latest +code and +latest data revisions The following shell commands download these files to a GNU/Linux or similar host; see the downloaded README file for what to do next.

    -
    wget 'ftp://elsie.nci.nih.gov/pub/tz*.tar.gz'
    -gzip -dc tzcode*.tar.gz | tar -xf -
    -gzip -dc tzdata*.tar.gz | tar -xf -
    +
    mkdir tz
    +cd tz
    +wget --retr-symlinks 'ftp://ftp.iana.org/tz/tz*-latest.tar.gz'
    +gzip -dc tzcode-latest.tar.gz | tar -xf -
    +gzip -dc tzdata-latest.tar.gz | tar -xf -
     

    +The code and data files can also be obtained from the +IANA +timezone web page. +

    The code lets you compile the tz source files into machine-readable binary files, one for each location. It also lets you read a tz binary file and interpret time stamps for that location.

    The data are by no means authoritative. If you find errors, please -send changes to the time zone +send changes to the time zone mailing list. You can also browse recent messages sent to the mailing list, subscribe to it, -retrieve the full archive of old -messages (in gzip compressed format), or retrieve archived older versions of code +href="https://mm.icann.org/mailman/listinfo/tz">subscribe to it. +browse the archive of old +messages (message by message or in gzip compressed format), +or retrieve archived older versions of code and data.

    The Web has several other sources for time zone and daylight saving time data. @@ -124,6 +134,14 @@ Here are some recent links that may be of interest. These are listed roughly in ascending order of complexity and fanciness.

      +
    • + +Permatime +is a service for generating and viewing links that refer to a +particular point in time and can be displayed in multiple timezones. +It uses the ruby tzinfo gem. +(From Tim Diggins, 2009-11-03.) +
    • Date and Time Gateway lets you see the TZ values directly.
    • The World Time Engine also contains data about time zone boundaries; it supports queries via place names and shows location maps.
    • +
    • Simple Timer + Clocks +is a Firefox add-on which uses a timezone data file generated from the +tz data files.

    Other time zone database formats

      @@ -242,6 +263,11 @@ files. Tcl is freely available under a BSD-style license.

    Other tz binary file readers

    +
  • +DateTime::TimeZone::Tzfile +is a tz binary file reader written in Perl. +It is freely available under the same terms as Perl +(dual GPL and Artistic license).
    • The GNU C @@ -297,6 +323,23 @@ licenses to tz contributors.
    • World Time Explorer is a Microsoft Windows program.
    • +
    • + +WorldClock for Windows and Windows Mobile +lets users "see the time in up to 25 locations in the world at once." +(From Hans Nieuwenhuis, 2009-11-02.) +
    • +
    • + +Time Zone Master Basic + "allows people to display multiple desktop clocks, and to +research current and historical time information, as well as times of +astronomical events (sunrise/transit/set, moonrise/transit/set, phases, +season starts) for user-selected dates in the past and future. It can +automatically download, compile and use the tzdata**.gz database files +as they are released to keep the data up to date. The software is +free." (Davie Patte) +

    Other time zone databases

      @@ -332,6 +375,17 @@ href="http://unicode.org/cldr/data/diff/supplemental/windows_tzid.html">Windows → Tzid table maintained by the CLDR data mentioned below. +
    • + +http://code.google.com/p/tzdata/ + +provides programming-language-specific representations of timezone +data. Currently this includes XML, PHP, Ruby, Javascript, JSON and CSV +formatted data. The repository is updated as soon as the FTP +distribution is updated. All data can be downloaded as a zip and/or it +can be obtained/synced via anonymous SVN. Data is made available under +the MIT license. (From Rich Tibbett.) +

    Maps

      diff --git a/lib/libc/time/tzfile.5 b/lib/libc/time/tzfile.5 index efb8d52e1..efa877825 100644 --- a/lib/libc/time/tzfile.5 +++ b/lib/libc/time/tzfile.5 @@ -1,6 +1,5 @@ -.\" $NetBSD: tzfile.5,v 1.15 2010/01/08 23:14:13 joerg Exp $ +.\" $NetBSD: tzfile.5,v 1.18 2012/08/09 12:38:25 christos Exp $ .\" -.\" @(#)tzfile.5 7.11 .\" This file is in the public domain, so clarified as of .\" 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). .Dd September 16, 2001 @@ -153,7 +152,8 @@ such instants). .Sh SEE ALSO .Xr ctime 3 , .Xr localtime 3 , -.Xr time 3 -.\" @(#)tzfile.5 8.2 +.Xr time 3 , +.Xr zdump 8 +.\" @(#)tzfile.5 8.3 .\" This file is in the public domain, so clarified as of .\" 1996-06-05 by Arthur David Olson. diff --git a/lib/libc/time/tzfile.h b/lib/libc/time/tzfile.h index 2b4b421df..9a8bf8eb4 100644 --- a/lib/libc/time/tzfile.h +++ b/lib/libc/time/tzfile.h @@ -1,4 +1,4 @@ -/* $NetBSD: tzfile.h,v 1.9 2009/12/31 22:49:16 mlelstv Exp $ */ +/* $NetBSD: tzfile.h,v 1.10 2012/08/09 12:38:25 christos Exp $ */ #ifndef TZFILE_H #define TZFILE_H @@ -16,18 +16,6 @@ ** Thank you! */ -/* -** ID -*/ - -#ifndef lint -#ifndef NOID -#if 0 -static char tzfilehid[] = "@(#)tzfile.h 8.1"; -#endif -#endif /* !defined NOID */ -#endif /* !defined lint */ - /* ** Information about time zone files. */ diff --git a/lib/libc/time/tzselect.ksh b/lib/libc/time/tzselect.ksh index 86db644e6..adf11dabc 100644 --- a/lib/libc/time/tzselect.ksh +++ b/lib/libc/time/tzselect.ksh @@ -1,8 +1,8 @@ #! /bin/ksh # -# $NetBSD: tzselect.ksh,v 1.6 2009/12/31 22:49:16 mlelstv Exp $ +# $NetBSD: tzselect.ksh,v 1.7 2012/08/09 12:38:26 christos Exp $ # -VERSION='@(#)tzselect.ksh 8.2' +VERSION=see_Makefile # Ask the user about the time zone, and output the resulting TZ value to stdout. # Interact with the user via stderr and stdin. @@ -57,7 +57,7 @@ EOF exit 0 elif [ "$1" = "--version" ]; then cat < #ifndef lint -#ifndef NOID -__RCSID("$NetBSD: zdump.c,v 1.19 2011/01/15 12:31:57 martin Exp $"); -#endif /* !defined NOID */ +__RCSID("$NetBSD: zdump.c,v 1.25 2012/08/09 12:38:26 christos Exp $"); #endif /* !defined lint */ -static char elsieid[] = "@(#)zdump.c 8.9"; - +#include "version.h" /* ** This code has been made independent of the rest of the time ** conversion package to increase confidence in the verification it provides. @@ -138,7 +135,7 @@ static char elsieid[] = "@(#)zdump.c 8.9"; #if HAVE_GETTEXT #define _(msgid) gettext(msgid) #else /* !HAVE_GETTEXT */ -#define _(msgid) __UNCONST(msgid) +#define _(msgid) msgid #endif /* !HAVE_GETTEXT */ #endif /* !defined _ */ @@ -212,7 +209,7 @@ const char * const abbrp; const char * const zone; { register const char * cp; - register char * wp; + register const char * wp; if (warned) return; @@ -244,14 +241,14 @@ const char * const zone; warned = TRUE; } -static void -usage(const char *xprogname, FILE *stream, int status) +__dead static void +usage(FILE *stream, int status) { (void) fprintf(stream, _("%s: usage is %s [ --version ] [ --help ] [ -v ] [ -c [loyear,]hiyear ] zonename ...\n\ \n\ Report bugs to tz@elsie.nci.nih.gov.\n"), - xprogname, xprogname); + progname, progname); exit(status); } @@ -289,10 +286,10 @@ char * argv[]; progname = argv[0]; for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { - (void) printf("%s\n", elsieid); + (void) printf("%s\n", TZVERSION); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "--help") == 0) { - usage(progname, stdout, EXIT_SUCCESS); + usage(stdout, EXIT_SUCCESS); } vflag = 0; cutarg = NULL; @@ -302,7 +299,7 @@ char * argv[]; else cutarg = optarg; if ((c != EOF && c != -1) || (optind == argc - 1 && strcmp(argv[optind], "=") == 0)) { - usage(progname, stderr, EXIT_FAILURE); + usage(stderr, EXIT_FAILURE); } if (vflag) { if (cutarg != NULL) { @@ -410,6 +407,15 @@ char * argv[]; return EXIT_FAILURE; } +static time_t +ovfl_check(time_t t) +{ + if (t < 0 && t - 1 >= 0) + return t; + else + return t - 1; +} + static void setabsolutes(void) { @@ -443,9 +449,7 @@ _("%s: use of -v on system with floating time_t other than float or double\n"), absolute_max_time = t; t = -t; - absolute_min_time = t - 1; - if (t < absolute_min_time) - absolute_min_time = t; + absolute_min_time = ovfl_check(t); } else { /* ** time_t is unsigned. diff --git a/lib/libc/time/zic.8 b/lib/libc/time/zic.8 index f1e00e01b..1e24112b6 100644 --- a/lib/libc/time/zic.8 +++ b/lib/libc/time/zic.8 @@ -1,5 +1,4 @@ -.\" $NetBSD: zic.8,v 1.18 2010/05/30 07:57:08 wiz Exp $ -.\" @(#)zic.8 7.22 +.\" $NetBSD: zic.8,v 1.20 2012/08/09 12:38:26 christos Exp $ .Dd December 20, 2003 .Dt ZIC 8 .Os @@ -82,6 +81,9 @@ Any line that is blank (after comment stripping) is ignored. Non-blank lines are expected to be of one of three types: rule lines, zone lines, and link lines. .Pp +Names (such as month names) must be in English and are case insensitive. +Abbreviations, if used, must be unambiguous in context. +.Pp A rule line has the form .Dl Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S For example: @@ -422,6 +424,6 @@ specifying transition instants using universal time. .Xr ctime 3 , .Xr tzfile 5 , .Xr zdump 8 -.\" @(#)zic.8 8.5 +.\" @(#)zic.8 8.6 .\" This file is in the public domain, so clarified as of .\" 2009-05-17 by Arthur David Olson. diff --git a/lib/libc/time/zic.c b/lib/libc/time/zic.c index 3b59b6cd1..bb4eaa018 100644 --- a/lib/libc/time/zic.c +++ b/lib/libc/time/zic.c @@ -1,4 +1,4 @@ -/* $NetBSD: zic.c,v 1.28 2011/01/15 12:31:57 martin Exp $ */ +/* $NetBSD: zic.c,v 1.30 2012/08/09 12:38:26 christos Exp $ */ /* ** This file is in the public domain, so clarified as of ** 2006-07-17 by Arthur David Olson. @@ -10,11 +10,10 @@ #include #ifndef lint -__RCSID("$NetBSD: zic.c,v 1.28 2011/01/15 12:31:57 martin Exp $"); +__RCSID("$NetBSD: zic.c,v 1.30 2012/08/09 12:38:26 christos Exp $"); #endif /* !defined lint */ -static char elsieid[] = "@(#)zic.c 8.20"; - +#include "version.h" #include "private.h" #include "locale.h" #include "tzfile.h" @@ -514,7 +513,7 @@ char * argv[]; } for (i = 1; i < argc; ++i) if (strcmp(argv[i], "--version") == 0) { - (void) printf("%s\n", elsieid); + (void) printf("%s\n", TZVERSION); exit(EXIT_SUCCESS); } else if (strcmp(argv[i], "--help") == 0) { usage(stdout, EXIT_SUCCESS); @@ -1637,6 +1636,53 @@ const char * const string; if (thistimei == 0) writetype[0] = TRUE; } +#ifndef LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH + /* + ** For some pre-2011 systems: if the last-to-be-written + ** standard (or daylight) type has an offset different from the + ** most recently used offset, + ** append an (unused) copy of the most recently used type + ** (to help get global "altzone" and "timezone" variables + ** set correctly). + */ + { + register int mrudst, mrustd, hidst, histd, type; + + hidst = histd = mrudst = mrustd = -1; + for (i = thistimei; i < thistimelim; ++i) + if (isdsts[types[i]]) + mrudst = types[i]; + else mrustd = types[i]; + for (i = 0; i < typecnt; ++i) + if (writetype[i]) { + if (isdsts[i]) + hidst = i; + else histd = i; + } + if (hidst >= 0 && mrudst >= 0 && hidst != mrudst && + gmtoffs[hidst] != gmtoffs[mrudst]) { + isdsts[mrudst] = -1; + type = addtype(gmtoffs[mrudst], + &chars[abbrinds[mrudst]], + TRUE, + ttisstds[mrudst], + ttisgmts[mrudst]); + isdsts[mrudst] = TRUE; + writetype[type] = TRUE; + } + if (histd >= 0 && mrustd >= 0 && histd != mrustd && + gmtoffs[histd] != gmtoffs[mrustd]) { + isdsts[mrustd] = -1; + type = addtype(gmtoffs[mrustd], + &chars[abbrinds[mrustd]], + FALSE, + ttisstds[mrustd], + ttisgmts[mrustd]); + isdsts[mrustd] = FALSE; + writetype[type] = TRUE; + } + } +#endif /* !defined LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH */ thistypecnt = 0; for (i = 0; i < typecnt; ++i) typemap[i] = writetype[i] ? thistypecnt++ : -1; @@ -1852,16 +1898,16 @@ const long gmtoff; register int week; if (rp->r_dycode == DC_DOWGEQ) { - week = 1 + rp->r_dayofmonth / DAYSPERWEEK; - if ((week - 1) * DAYSPERWEEK + 1 != rp->r_dayofmonth) + if ((rp->r_dayofmonth % DAYSPERWEEK) != 1) return -1; + week = 1 + rp->r_dayofmonth / DAYSPERWEEK; } else if (rp->r_dycode == DC_DOWLEQ) { if (rp->r_dayofmonth == len_months[1][rp->r_month]) week = 5; else { - week = 1 + rp->r_dayofmonth / DAYSPERWEEK; - if (week * DAYSPERWEEK - 1 != rp->r_dayofmonth) + if ((rp->r_dayofmonth % DAYSPERWEEK) != 0) return -1; + week = rp->r_dayofmonth / DAYSPERWEEK; } } else return -1; /* "cannot happen" */ (void) sprintf(result, "M%d.%d.%d", @@ -1991,6 +2037,7 @@ const int zonecount; register char * envvar; register int max_abbr_len; register int max_envvar_len; + register int prodstic; /* all rules are min to max */ max_abbr_len = 2 + max_format_len + max_abbrvar_len; max_envvar_len = 2 * max_abbr_len + 5 * 9; @@ -2005,6 +2052,7 @@ const int zonecount; timecnt = 0; typecnt = 0; charcnt = 0; + prodstic = zonecount == 1; /* ** Thanks to Earl Chew ** for noting the need to unconditionally initialize startttisstd. @@ -2048,6 +2096,16 @@ wp = ecpyalloc(_("no POSIX environment variable for zone")); if (max_year <= INT_MAX - YEARSPERREPEAT) max_year += YEARSPERREPEAT; else max_year = INT_MAX; + /* + ** Regardless of any of the above, + ** for a "proDSTic" zone which specifies that its rules + ** always have and always will be in effect, + ** we only need one cycle to define the zone. + */ + if (prodstic) { + min_year = 1900; + max_year = min_year + YEARSPERREPEAT; + } } /* ** For the benefit of older systems, diff --git a/lib/libc/tls/Makefile.inc b/lib/libc/tls/Makefile.inc new file mode 100644 index 000000000..3d536995b --- /dev/null +++ b/lib/libc/tls/Makefile.inc @@ -0,0 +1,9 @@ +# $NetBSD: Makefile.inc,v 1.2 2011/03/12 07:55:09 matt Exp $ + +.include + +# Our sources +.PATH: ${.PARSEDIR} ${ARCHDIR}/tls + +SRCS+= tls.c +CPPFLAGS.tls.c+= -D_LIBC_SOURCE diff --git a/lib/libc/tls/tls.c b/lib/libc/tls/tls.c new file mode 100644 index 000000000..87488b4e0 --- /dev/null +++ b/lib/libc/tls/tls.c @@ -0,0 +1,180 @@ +/* $NetBSD: tls.c,v 1.6 2011/04/07 02:19:28 matt Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__RCSID("$NetBSD: tls.c,v 1.6 2011/04/07 02:19:28 matt Exp $"); + +#include "namespace.h" + +#define _rtld_tls_allocate __libc_rtld_tls_allocate +#define _rtld_tls_free __libc_rtld_tls_free + +#include + +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + +#include +#include +#include +#include +#include +#include +#include +#include + +__dso_hidden void __libc_static_tls_setup(void); + +static const void *tls_initaddr; +static size_t tls_initsize; +static size_t tls_size; +static size_t tls_allocation; +static void *initial_thread_tcb; + +void * __libc_tls_get_addr(void); + +__weak_alias(__tls_get_addr, __libc_tls_get_addr) +#ifdef __i386__ +__weak_alias(___tls_get_addr, __libc_tls_get_addr) +#endif + +void * +__libc_tls_get_addr(void) +{ + + abort(); + /* NOTREACHED */ +} + +__weak_alias(_rtld_tls_allocate, __libc_rtld_tls_allocate) + +struct tls_tcb * +_rtld_tls_allocate(void) +{ + struct tls_tcb *tcb; + uint8_t *p; + + if (initial_thread_tcb == NULL) { +#ifdef __HAVE_TLS_VARIANT_II + tls_size = roundup2(tls_size, sizeof(void *)); +#endif + tls_allocation = tls_size + sizeof(*tcb); + + initial_thread_tcb = p = mmap(NULL, tls_allocation, + PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + } else { + p = calloc(1, tls_allocation); + } + if (p == NULL) { + static const char msg[] = "TLS allocation failed, terminating\n"; + write(STDERR_FILENO, msg, sizeof(msg)); + _exit(127); + } +#ifdef __HAVE_TLS_VARIANT_I + /* LINTED */ + tcb = (struct tls_tcb *)p; + p += sizeof(struct tls_tcb); +#else + /* LINTED tls_size is rounded above */ + tcb = (struct tls_tcb *)(p + tls_size); + tcb->tcb_self = tcb; +#endif + memcpy(p, tls_initaddr, tls_initsize); + + return tcb; +} + +__weak_alias(_rtld_tls_free, __libc_rtld_tls_free) + +void +_rtld_tls_free(struct tls_tcb *tcb) +{ + uint8_t *p; + +#ifdef __HAVE_TLS_VARIANT_I + /* LINTED */ + p = (uint8_t *)tcb; +#else + /* LINTED */ + p = (uint8_t *)tcb - tls_size; +#endif + if (p == initial_thread_tcb) + munmap(p, tls_allocation); + else + free(p); +} + +__weakref_visible int rtld_DYNAMIC __weak_reference(_DYNAMIC); + +static int +__libc_static_tls_setup_cb(struct dl_phdr_info *data, size_t len, void *cookie) +{ + const Elf_Phdr *phdr = data->dlpi_phdr; + const Elf_Phdr *phlimit = data->dlpi_phdr + data->dlpi_phnum; + + for (; phdr < phlimit; ++phdr) { + if (phdr->p_type != PT_TLS) + continue; + tls_initaddr = (void *)(phdr->p_vaddr + data->dlpi_addr); + tls_initsize = phdr->p_filesz; + tls_size = phdr->p_memsz; + } + return 0; +} + +void +__libc_static_tls_setup(void) +{ + struct tls_tcb *tcb; + + if (&rtld_DYNAMIC != NULL) { +#ifdef __powerpc__ + /* + * Old powerpc crt0's are going to overwrite r2 so we need to + * restore it but only do so if the saved value isn't NULL (if + * it is NULL, ld.elf_so doesn't have the matching change). + */ + if ((tcb = _lwp_getprivate()) != NULL) + __lwp_settcb(tcb); +#endif + return; + } + + dl_iterate_phdr(__libc_static_tls_setup_cb, NULL); + + tcb = _rtld_tls_allocate(); +#ifdef __HAVE___LWP_SETTCB + __lwp_settcb(tcb); +#else + _lwp_setprivate(tcb); +#endif +} + +#endif /* __HAVE_TLS_VARIANT_I || __HAVE_TLS_VARIANT_II */ diff --git a/lib/libc/uuid/uuid_create.c b/lib/libc/uuid/uuid_create.c index da1fe28e1..25c87d6cf 100644 --- a/lib/libc/uuid/uuid_create.c +++ b/lib/libc/uuid/uuid_create.c @@ -41,6 +41,8 @@ __RCSID("$NetBSD: uuid_create.c,v 1.1 2004/09/13 21:44:54 thorpej Exp $"); #ifdef __minix #include #include +#include + /* Fake a uuidgen() syscall */ int uuidgen(struct uuid *store, int count) { diff --git a/lib/libc/yp/Makefile.inc b/lib/libc/yp/Makefile.inc index 2f687f498..59d3666af 100644 --- a/lib/libc/yp/Makefile.inc +++ b/lib/libc/yp/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.14 1999/02/24 15:05:21 drochner Exp $ +# $NetBSD: Makefile.inc,v 1.15 2012/03/02 17:27:49 christos Exp $ # yp sources .PATH: ${ARCHDIR}/yp ${.CURDIR}/yp @@ -10,4 +10,5 @@ MAN+= ypclnt.3 MLINKS+=ypclnt.3 yp_all.3 ypclnt.3 yp_bind.3 ypclnt.3 yp_first.3 \ ypclnt.3 yp_get_default_domain.3 ypclnt.3 yp_master.3 \ ypclnt.3 yp_match.3 ypclnt.3 yp_next.3 ypclnt.3 yp_order.3 \ - ypclnt.3 yp_unbind.3 ypclnt.3 yperr_string.3 ypclnt.3 ypprot_err.3 + ypclnt.3 yp_unbind.3 ypclnt.3 yperr_string.3 ypclnt.3 ypprot_err.3 \ + ypclnt.3 yp_setbindtries.3 diff --git a/lib/libc/yp/local.h b/lib/libc/yp/local.h index de72df0c0..80240748f 100644 --- a/lib/libc/yp/local.h +++ b/lib/libc/yp/local.h @@ -1,4 +1,4 @@ -/* $NetBSD: local.h,v 1.3 2009/10/21 01:07:46 snj Exp $ */ +/* $NetBSD: local.h,v 1.4 2012/03/20 16:30:26 matt Exp $ */ /* * Copyright (c) 1996 Christos Zoulas. All rights reserved. @@ -25,6 +25,6 @@ */ __BEGIN_DECLS -void __yp_unbind __P((struct dom_binding *)); -int _yp_invalid_domain __P((const char *)); +void __yp_unbind(struct dom_binding *); +int _yp_invalid_domain(const char *); __END_DECLS diff --git a/lib/libc/yp/xdryp.c b/lib/libc/yp/xdryp.c index 05f301ad9..368ce9488 100644 --- a/lib/libc/yp/xdryp.c +++ b/lib/libc/yp/xdryp.c @@ -1,4 +1,4 @@ -/* $NetBSD: xdryp.c,v 1.30 2006/05/11 17:11:57 mrg Exp $ */ +/* $NetBSD: xdryp.c,v 1.32 2012/03/20 16:30:26 matt Exp $ */ /* * Copyright (c) 1996 Jason R. Thorpe . @@ -61,7 +61,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: xdryp.c,v 1.30 2006/05/11 17:11:57 mrg Exp $"); +__RCSID("$NetBSD: xdryp.c,v 1.32 2012/03/20 16:30:26 matt Exp $"); #endif /* @@ -115,18 +115,16 @@ __weak_alias(xdr_ypresp_val,_xdr_ypresp_val) /* * Functions used only within this file. */ -static bool_t xdr_ypbind_binding __P((XDR *, struct ypbind_binding *)); -static bool_t xdr_ypbind_resptype __P((XDR *, enum ypbind_resptype *)); -static bool_t xdr_ypstat __P((XDR *, enum ypbind_resptype *)); -static bool_t xdr_ypmaplist_str __P((XDR *, char *)); +static bool_t xdr_ypbind_binding(XDR *, struct ypbind_binding *); +static bool_t xdr_ypbind_resptype(XDR *, enum ypbind_resptype *); +static bool_t xdr_ypstat(XDR *, enum ypbind_resptype *); +static bool_t xdr_ypmaplist_str(XDR *, char *); __warn_references(xdr_domainname, "warning: this program uses xdr_domainname(), which is deprecated and buggy.") bool_t -xdr_domainname(xdrs, objp) - XDR *xdrs; - char *objp; +xdr_domainname(XDR *xdrs, char *objp) { _DIAGASSERT(xdrs != NULL); @@ -139,9 +137,7 @@ __warn_references(xdr_peername, "warning: this program uses xdr_peername(), which is deprecated and buggy.") bool_t -xdr_peername(xdrs, objp) - XDR *xdrs; - char *objp; +xdr_peername(XDR *xdrs, char *objp) { _DIAGASSERT(xdrs != NULL); @@ -154,9 +150,7 @@ __warn_references(xdr_mapname, "warning: this program uses xdr_mapname(), which is deprecated and buggy.") bool_t -xdr_mapname(xdrs, objp) - XDR *xdrs; - char *objp; +xdr_mapname(XDR *xdrs, char *objp) { _DIAGASSERT(xdrs != NULL); @@ -166,9 +160,7 @@ xdr_mapname(xdrs, objp) } bool_t -xdr_ypdomain_wrap_string(xdrs, objp) - XDR *xdrs; - char **objp; +xdr_ypdomain_wrap_string(XDR *xdrs, char **objp) { _DIAGASSERT(xdrs != NULL); @@ -178,9 +170,7 @@ xdr_ypdomain_wrap_string(xdrs, objp) } bool_t -xdr_ypmap_wrap_string(xdrs, objp) - XDR *xdrs; - char **objp; +xdr_ypmap_wrap_string(XDR *xdrs, char **objp) { _DIAGASSERT(xdrs != NULL); @@ -190,9 +180,7 @@ xdr_ypmap_wrap_string(xdrs, objp) } bool_t -xdr_ypowner_wrap_string(xdrs, objp) - XDR *xdrs; - char **objp; +xdr_ypowner_wrap_string(XDR *xdrs, char **objp) { _DIAGASSERT(xdrs != NULL); @@ -202,9 +190,7 @@ xdr_ypowner_wrap_string(xdrs, objp) } bool_t -xdr_datum(xdrs, objp) - XDR *xdrs; - datum *objp; +xdr_datum(XDR *xdrs, datum *objp) { _DIAGASSERT(xdrs != NULL); @@ -215,9 +201,7 @@ xdr_datum(xdrs, objp) } bool_t -xdr_ypreq_key(xdrs, objp) - XDR *xdrs; - struct ypreq_key *objp; +xdr_ypreq_key(XDR *xdrs, struct ypreq_key *objp) { _DIAGASSERT(xdrs != NULL); @@ -236,9 +220,7 @@ xdr_ypreq_key(xdrs, objp) } bool_t -xdr_ypreq_nokey(xdrs, objp) - XDR *xdrs; - struct ypreq_nokey *objp; +xdr_ypreq_nokey(XDR *xdrs, struct ypreq_nokey *objp) { _DIAGASSERT(xdrs != NULL); @@ -254,22 +236,18 @@ xdr_ypreq_nokey(xdrs, objp) } bool_t -xdr_yp_inaddr(xdrs, objp) - XDR *xdrs; - struct in_addr *objp; +xdr_yp_inaddr(XDR *xdrs, struct in_addr *objp) { _DIAGASSERT(xdrs != NULL); _DIAGASSERT(objp != NULL); return xdr_opaque(xdrs, (caddr_t)(void *)&objp->s_addr, - sizeof objp->s_addr); + (u_int)sizeof objp->s_addr); } static bool_t -xdr_ypbind_binding(xdrs, objp) - XDR *xdrs; - struct ypbind_binding *objp; +xdr_ypbind_binding(XDR *xdrs, struct ypbind_binding *objp) { _DIAGASSERT(xdrs != NULL); @@ -279,16 +257,14 @@ xdr_ypbind_binding(xdrs, objp) return FALSE; if (!xdr_opaque(xdrs, (void *)&objp->ypbind_binding_port, - sizeof objp->ypbind_binding_port)) + (u_int)sizeof objp->ypbind_binding_port)) return FALSE; return TRUE; } static bool_t -xdr_ypbind_resptype(xdrs, objp) - XDR *xdrs; - enum ypbind_resptype *objp; +xdr_ypbind_resptype(XDR *xdrs, enum ypbind_resptype *objp) { _DIAGASSERT(xdrs != NULL); @@ -298,9 +274,7 @@ xdr_ypbind_resptype(xdrs, objp) } static bool_t -xdr_ypstat(xdrs, objp) - XDR *xdrs; - enum ypbind_resptype *objp; +xdr_ypstat(XDR *xdrs, enum ypbind_resptype *objp) { _DIAGASSERT(xdrs != NULL); @@ -310,9 +284,7 @@ xdr_ypstat(xdrs, objp) } bool_t -xdr_ypbind_resp(xdrs, objp) - XDR *xdrs; - struct ypbind_resp *objp; +xdr_ypbind_resp(XDR *xdrs, struct ypbind_resp *objp) { _DIAGASSERT(xdrs != NULL); @@ -337,9 +309,7 @@ xdr_ypbind_resp(xdrs, objp) } bool_t -xdr_ypresp_val(xdrs, objp) - XDR *xdrs; - struct ypresp_val *objp; +xdr_ypresp_val(XDR *xdrs, struct ypresp_val *objp) { _DIAGASSERT(xdrs != NULL); @@ -355,9 +325,7 @@ xdr_ypresp_val(xdrs, objp) } bool_t -xdr_ypbind_setdom(xdrs, objp) - XDR *xdrs; - struct ypbind_setdom *objp; +xdr_ypbind_setdom(XDR *xdrs, struct ypbind_setdom *objp) { char *cp; @@ -379,9 +347,7 @@ xdr_ypbind_setdom(xdrs, objp) } bool_t -xdr_ypresp_key_val(xdrs, objp) - XDR *xdrs; - struct ypresp_key_val *objp; +xdr_ypresp_key_val(XDR *xdrs, struct ypresp_key_val *objp) { _DIAGASSERT(xdrs != NULL); @@ -400,9 +366,7 @@ xdr_ypresp_key_val(xdrs, objp) } bool_t -xdr_ypall(xdrs, incallback) - XDR *xdrs; - struct ypall_callback *incallback; +xdr_ypall(XDR *xdrs, struct ypall_callback *incallback) { struct ypresp_key_val out; char key[YPMAXRECORD], val[YPMAXRECORD]; @@ -448,9 +412,7 @@ xdr_ypall(xdrs, incallback) } bool_t -xdr_ypresp_master(xdrs, objp) - XDR *xdrs; - struct ypresp_master *objp; +xdr_ypresp_master(XDR *xdrs, struct ypresp_master *objp) { _DIAGASSERT(xdrs != NULL); @@ -466,9 +428,7 @@ xdr_ypresp_master(xdrs, objp) } static bool_t -xdr_ypmaplist_str(xdrs, objp) - XDR *xdrs; - char *objp; +xdr_ypmaplist_str(XDR *xdrs, char *objp) { _DIAGASSERT(xdrs != NULL); @@ -478,9 +438,7 @@ xdr_ypmaplist_str(xdrs, objp) } bool_t -xdr_ypmaplist(xdrs, objp) - XDR *xdrs; - struct ypmaplist *objp; +xdr_ypmaplist(XDR *xdrs, struct ypmaplist *objp) { _DIAGASSERT(xdrs != NULL); @@ -490,16 +448,14 @@ xdr_ypmaplist(xdrs, objp) return FALSE; if (!xdr_pointer(xdrs, (char **)(void *)&objp->ypml_next, - sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist)) + (u_int)sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist)) return FALSE; return TRUE; } bool_t -xdr_ypresp_maplist(xdrs, objp) - XDR *xdrs; - struct ypresp_maplist *objp; +xdr_ypresp_maplist(XDR *xdrs, struct ypresp_maplist *objp) { _DIAGASSERT(xdrs != NULL); @@ -509,16 +465,14 @@ xdr_ypresp_maplist(xdrs, objp) return FALSE; if (!xdr_pointer(xdrs, (char **)(void *)&objp->list, - sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist)) + (u_int)sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist)) return FALSE; return TRUE; } bool_t -xdr_ypresp_order(xdrs, objp) - XDR *xdrs; - struct ypresp_order *objp; +xdr_ypresp_order(XDR *xdrs, struct ypresp_order *objp) { _DIAGASSERT(xdrs != NULL); @@ -534,9 +488,7 @@ xdr_ypresp_order(xdrs, objp) } bool_t -xdr_ypreq_xfr(xdrs, objp) - XDR *xdrs; - struct ypreq_xfr *objp; +xdr_ypreq_xfr(XDR *xdrs, struct ypreq_xfr *objp) { _DIAGASSERT(xdrs != NULL); @@ -558,9 +510,7 @@ xdr_ypreq_xfr(xdrs, objp) } bool_t -xdr_ypmap_parms(xdrs, objp) - XDR *xdrs; - struct ypmap_parms *objp; +xdr_ypmap_parms(XDR *xdrs, struct ypmap_parms *objp) { _DIAGASSERT(xdrs != NULL); @@ -582,9 +532,7 @@ xdr_ypmap_parms(xdrs, objp) } bool_t -xdr_yppushresp_xfr(xdrs, objp) - XDR *xdrs; - struct yppushresp_xfr *objp; +xdr_yppushresp_xfr(XDR *xdrs, struct yppushresp_xfr *objp) { _DIAGASSERT(xdrs != NULL); diff --git a/lib/libc/yp/yp_all.c b/lib/libc/yp/yp_all.c index 6d97ce73d..41c1ec32a 100644 --- a/lib/libc/yp/yp_all.c +++ b/lib/libc/yp/yp_all.c @@ -1,4 +1,4 @@ -/* $NetBSD: yp_all.c,v 1.12 2003/12/10 12:06:25 agc Exp $ */ +/* $NetBSD: yp_all.c,v 1.13 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: yp_all.c,v 1.12 2003/12/10 12:06:25 agc Exp $"); +__RCSID("$NetBSD: yp_all.c,v 1.13 2012/06/25 22:32:46 abs Exp $"); #endif #include "namespace.h" @@ -46,10 +46,8 @@ __weak_alias(yp_all,_yp_all) #endif int -yp_all(indomain, inmap, incallback) - const char *indomain; - const char *inmap; - struct ypall_callback *incallback; +yp_all(const char *indomain, const char *inmap, + struct ypall_callback *incallback) { struct ypreq_nokey yprnk; struct dom_binding *ysd; diff --git a/lib/libc/yp/yp_first.c b/lib/libc/yp/yp_first.c index 482faafaa..fa6dccad5 100644 --- a/lib/libc/yp/yp_first.c +++ b/lib/libc/yp/yp_first.c @@ -1,4 +1,4 @@ -/* $NetBSD: yp_first.c,v 1.14 2003/12/10 12:06:25 agc Exp $ */ +/* $NetBSD: yp_first.c,v 1.16 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: yp_first.c,v 1.14 2003/12/10 12:06:25 agc Exp $"); +__RCSID("$NetBSD: yp_first.c,v 1.16 2012/06/25 22:32:46 abs Exp $"); #endif #include "namespace.h" @@ -41,6 +41,7 @@ __RCSID("$NetBSD: yp_first.c,v 1.14 2003/12/10 12:06:25 agc Exp $"); extern struct timeval _yplib_timeout; extern int _yplib_nerrs; +extern int _yplib_bindtries; #ifdef __weak_alias __weak_alias(yp_first,_yp_first) @@ -48,13 +49,8 @@ __weak_alias(yp_next,_yp_next) #endif int -yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen) - const char *indomain; - const char *inmap; - char **outkey; - int *outkeylen; - char **outval; - int *outvallen; +yp_first(const char *indomain, const char *inmap, char **outkey, + int *outkeylen, char **outval, int *outvallen) { struct ypresp_key_val yprkv; struct ypreq_nokey yprnk; @@ -84,10 +80,11 @@ again: (xdrproc_t)xdr_ypreq_nokey, &yprnk, (xdrproc_t)xdr_ypresp_key_val, &yprkv, _yplib_timeout); if (r != RPC_SUCCESS) { - if (++nerrs == _yplib_nerrs) { + if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) { clnt_perror(ysd->dom_client, "yp_first: clnt_call"); nerrs = 0; - } + } else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries) + return YPERR_YPSERV; ysd->dom_vers = -1; goto again; } @@ -125,15 +122,8 @@ again: } int -yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen) - const char *indomain; - const char *inmap; - const char *inkey; - int inkeylen; - char **outkey; - int *outkeylen; - char **outval; - int *outvallen; +yp_next(const char *indomain, const char *inmap, const char *inkey, + int inkeylen, char **outkey, int *outkeylen, char **outval, int *outvallen) { struct ypresp_key_val yprkv; struct ypreq_key yprk; @@ -167,10 +157,11 @@ again: (xdrproc_t)xdr_ypreq_key, &yprk, (xdrproc_t)xdr_ypresp_key_val, &yprkv, _yplib_timeout); if (r != RPC_SUCCESS) { - if (++nerrs == _yplib_nerrs) { + if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) { clnt_perror(ysd->dom_client, "yp_next: clnt_call"); nerrs = 0; - } + } else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries) + return YPERR_YPSERV; ysd->dom_vers = -1; goto again; } diff --git a/lib/libc/yp/yp_maplist.c b/lib/libc/yp/yp_maplist.c index b8143127c..3de820b71 100644 --- a/lib/libc/yp/yp_maplist.c +++ b/lib/libc/yp/yp_maplist.c @@ -1,4 +1,4 @@ -/* $NetBSD: yp_maplist.c,v 1.11 2003/12/10 12:06:25 agc Exp $ */ +/* $NetBSD: yp_maplist.c,v 1.13 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: yp_maplist.c,v 1.11 2003/12/10 12:06:25 agc Exp $"); +__RCSID("$NetBSD: yp_maplist.c,v 1.13 2012/06/25 22:32:46 abs Exp $"); #endif #include "namespace.h" @@ -40,15 +40,14 @@ __RCSID("$NetBSD: yp_maplist.c,v 1.11 2003/12/10 12:06:25 agc Exp $"); extern struct timeval _yplib_timeout; extern int _yplib_nerrs; +extern int _yplib_bindtries; #ifdef __weak_alias __weak_alias(yp_maplist,_yp_maplist) #endif int -yp_maplist(indomain, outmaplist) - const char *indomain; - struct ypmaplist **outmaplist; +yp_maplist( const char *indomain, struct ypmaplist **outmaplist) { struct dom_binding *ysd; struct ypresp_maplist ypml; @@ -68,10 +67,11 @@ again: (xdrproc_t)xdr_ypdomain_wrap_string, &indomain, (xdrproc_t)xdr_ypresp_maplist, &ypml, _yplib_timeout); if (r != RPC_SUCCESS) { - if (++nerrs == _yplib_nerrs) { + if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) { clnt_perror(ysd->dom_client, "yp_maplist: clnt_call"); nerrs = 0; - } + } else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries) + return YPERR_YPSERV; ysd->dom_vers = -1; goto again; } diff --git a/lib/libc/yp/yp_master.c b/lib/libc/yp/yp_master.c index 7eaa96f5f..97510d9f8 100644 --- a/lib/libc/yp/yp_master.c +++ b/lib/libc/yp/yp_master.c @@ -1,4 +1,4 @@ -/* $NetBSD: yp_master.c,v 1.13 2003/12/10 12:06:25 agc Exp $ */ +/* $NetBSD: yp_master.c,v 1.15 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: yp_master.c,v 1.13 2003/12/10 12:06:25 agc Exp $"); +__RCSID("$NetBSD: yp_master.c,v 1.15 2012/06/25 22:32:46 abs Exp $"); #endif #include "namespace.h" @@ -41,16 +41,14 @@ __RCSID("$NetBSD: yp_master.c,v 1.13 2003/12/10 12:06:25 agc Exp $"); extern struct timeval _yplib_timeout; extern int _yplib_nerrs; +extern int _yplib_bindtries; #ifdef __weak_alias __weak_alias(yp_master,_yp_master) #endif int -yp_master(indomain, inmap, outname) - const char *indomain; - const char *inmap; - char **outname; +yp_master(const char *indomain, const char *inmap, char **outname) { struct dom_binding *ysd; struct ypresp_master yprm; @@ -80,10 +78,11 @@ again: (xdrproc_t)xdr_ypreq_nokey, &yprnk, (xdrproc_t)xdr_ypresp_master, &yprm, _yplib_timeout); if (r != RPC_SUCCESS) { - if (++nerrs == _yplib_nerrs) { + if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) { clnt_perror(ysd->dom_client, "yp_master: clnt_call"); nerrs = 0; - } + } else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries) + return YPERR_YPSERV; ysd->dom_vers = -1; goto again; } diff --git a/lib/libc/yp/yp_match.c b/lib/libc/yp/yp_match.c index ce3ffdd66..fec7fd152 100644 --- a/lib/libc/yp/yp_match.c +++ b/lib/libc/yp/yp_match.c @@ -1,4 +1,4 @@ -/* $NetBSD: yp_match.c,v 1.17 2005/11/29 03:12:01 christos Exp $ */ +/* $NetBSD: yp_match.c,v 1.19 2012/03/20 16:30:26 matt Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: yp_match.c,v 1.17 2005/11/29 03:12:01 christos Exp $"); +__RCSID("$NetBSD: yp_match.c,v 1.19 2012/03/20 16:30:26 matt Exp $"); #endif #include "namespace.h" @@ -47,6 +47,7 @@ __RCSID("$NetBSD: yp_match.c,v 1.17 2005/11/29 03:12:01 christos Exp $"); extern struct timeval _yplib_timeout; extern int _yplib_nerrs; +extern int _yplib_bindtries; extern char _yp_domain[]; #ifdef __weak_alias @@ -64,17 +65,12 @@ static struct ypmatch_ent { time_t expire_t; } *ypmc; -static bool_t ypmatch_add __P((const char *, const char *, int, char *, int)); -static bool_t ypmatch_find __P((const char *, const char *, int, const char **, - int *)); +static bool_t ypmatch_add(const char *, const char *, int, char *, int); +static bool_t ypmatch_find(const char *, const char *, int, const char **, + int *); static bool_t -ypmatch_add(map, key, keylen, val, vallen) - const char *map; - const char *key; - int keylen; - char *val; - int vallen; +ypmatch_add(const char *map, const char *key, int keylen, char *val, int vallen) { struct ypmatch_ent *ep; time_t t; @@ -137,12 +133,8 @@ ypmatch_add(map, key, keylen, val, vallen) } static bool_t -ypmatch_find(map, key, keylen, val, vallen) - const char *map; - const char *key; - int keylen; - const char **val; - int *vallen; +ypmatch_find(const char *map, const char *key, int keylen, const char **val, + int *vallen) { struct ypmatch_ent *ep; time_t t; @@ -175,13 +167,8 @@ ypmatch_find(map, key, keylen, val, vallen) #endif int -yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen) - const char *indomain; - const char *inmap; - const char *inkey; - int inkeylen; - char **outval; - int *outvallen; +yp_match(const char *indomain, const char *inmap, const char *inkey, + int inkeylen, char **outval, int *outvallen) { struct dom_binding *ysd; struct ypresp_val yprv; @@ -229,10 +216,13 @@ again: (xdrproc_t)xdr_ypresp_val, &yprv, _yplib_timeout); if (r != RPC_SUCCESS) { - if (++nerrs == _yplib_nerrs) { + if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) { clnt_perror(ysd->dom_client, "yp_match: clnt_call"); nerrs = 0; } + else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries) { + return YPERR_YPSERV; + } ysd->dom_vers = -1; goto again; } diff --git a/lib/libc/yp/yp_order.c b/lib/libc/yp/yp_order.c index ad7d963ac..6e0c11690 100644 --- a/lib/libc/yp/yp_order.c +++ b/lib/libc/yp/yp_order.c @@ -1,4 +1,4 @@ -/* $NetBSD: yp_order.c,v 1.12 2003/12/10 12:06:25 agc Exp $ */ +/* $NetBSD: yp_order.c,v 1.14 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: yp_order.c,v 1.12 2003/12/10 12:06:25 agc Exp $"); +__RCSID("$NetBSD: yp_order.c,v 1.14 2012/06/25 22:32:46 abs Exp $"); #endif #include "namespace.h" @@ -40,16 +40,14 @@ __RCSID("$NetBSD: yp_order.c,v 1.12 2003/12/10 12:06:25 agc Exp $"); extern struct timeval _yplib_timeout; extern int _yplib_nerrs; +extern int _yplib_bindtries; #ifdef __weak_alias __weak_alias(yp_order,_yp_order) #endif int -yp_order(indomain, inmap, outorder) - const char *indomain; - const char *inmap; - int *outorder; +yp_order(const char *indomain, const char *inmap, int *outorder) { struct dom_binding *ysd; struct ypresp_order ypro; @@ -78,10 +76,11 @@ again: (xdrproc_t)xdr_ypresp_order, &ypro, _yplib_timeout); if (r != RPC_SUCCESS) { - if (++nerrs == _yplib_nerrs) { + if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) { clnt_perror(ysd->dom_client, "yp_order: clnt_call"); nerrs = 0; - } + } else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries) + return YPERR_YPSERV; if (r == RPC_PROCUNAVAIL) { /* Case of NIS+ server in NIS compat mode */ r = YPERR_YPERR; diff --git a/lib/libc/yp/ypclnt.3 b/lib/libc/yp/ypclnt.3 index a39547724..d24e0801a 100644 --- a/lib/libc/yp/ypclnt.3 +++ b/lib/libc/yp/ypclnt.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: ypclnt.3,v 1.24 2010/03/22 19:30:55 joerg Exp $ +.\" $NetBSD: ypclnt.3,v 1.26 2012/03/04 11:52:32 wiz Exp $ .\" .\" Copyright (c) 1996 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd May 21, 1997 +.Dd March 2, 2012 .Dt YPCLNT 3 .Os .Sh NAME @@ -42,6 +42,7 @@ .Nm yp_unbind , .Nm yperr_string , .Nm ypprot_err +.Nm yp_setbindtries .Nd Interface to the YP subsystem .Sh LIBRARY .Lb libc @@ -72,6 +73,8 @@ .Fn yperr_string "int incode" .Ft int .Fn ypprot_err "unsigned int incode" +.Ft int +.Fn yp_setbindtries "int ntries" .Sh DESCRIPTION The .Nm ypclnt @@ -196,7 +199,7 @@ is returned and control given back to the user code. The .Nm ypclnt suite provides the following functionality: -.Bl -tag -width yp_match()xx +.Bl -tag -width yp_matchxxxx .It Fn yp_match Provides the value associated with the given key. .It Fn yp_first @@ -348,6 +351,17 @@ protocol error code to a .Nm ypclnt error code suitable for .Fn yperr_string . +.It Fn yp_setbindtries +Set the number of tries to attempt to bind to the domain before returning +an error. +The default is +.Dv 0 +which means wait forever if no ypserver is not found of if the RPC +communication with the yp server fails. +If the number passed is negative, the current number of tries is not modified. +.Pp +This function is an extention to the client library that allows application +to catch communication problems with the ypserver without blocking forever. .El .Sh RETURN VALUES All functions in the diff --git a/lib/libc/yp/yperr_string.c b/lib/libc/yp/yperr_string.c index 66046967b..a99f98b81 100644 --- a/lib/libc/yp/yperr_string.c +++ b/lib/libc/yp/yperr_string.c @@ -1,4 +1,4 @@ -/* $NetBSD: yperr_string.c,v 1.7 2005/11/29 03:12:01 christos Exp $ */ +/* $NetBSD: yperr_string.c,v 1.8 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: yperr_string.c,v 1.7 2005/11/29 03:12:01 christos Exp $"); +__RCSID("$NetBSD: yperr_string.c,v 1.8 2012/06/25 22:32:46 abs Exp $"); #endif #include "namespace.h" @@ -42,8 +42,7 @@ __weak_alias(yperr_string,_yperr_string) #endif char * -yperr_string(incode) - int incode; +yperr_string(int incode) { static char err[80]; diff --git a/lib/libc/yp/yplib.c b/lib/libc/yp/yplib.c index ceb8251ea..f30a37bce 100644 --- a/lib/libc/yp/yplib.c +++ b/lib/libc/yp/yplib.c @@ -1,4 +1,4 @@ -/* $NetBSD: yplib.c,v 1.43 2006/11/03 20:18:49 christos Exp $ */ +/* $NetBSD: yplib.c,v 1.45 2012/03/20 16:30:26 matt Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: yplib.c,v 1.43 2006/11/03 20:18:49 christos Exp $"); +__RCSID("$NetBSD: yplib.c,v 1.45 2012/03/20 16:30:26 matt Exp $"); #endif #include "namespace.h" @@ -67,11 +67,13 @@ struct timeval _yplib_timeout = { YPLIB_TIMEOUT, 0 }; struct timeval _yplib_rpc_timeout = { YPLIB_TIMEOUT / YPLIB_RPC_RETRIES, 1000000 * (YPLIB_TIMEOUT % YPLIB_RPC_RETRIES) / YPLIB_RPC_RETRIES }; int _yplib_nerrs = 5; +int _yplib_bindtries = 0; #ifdef __weak_alias __weak_alias(yp_bind, _yp_bind) __weak_alias(yp_unbind, _yp_unbind) __weak_alias(yp_get_default_domain, _yp_get_default_domain) +__weak_alias(yp_setbindtries, _yp_setbindtries) #endif #ifdef _REENTRANT @@ -84,9 +86,17 @@ static mutex_t _ypmutex = MUTEX_INITIALIZER; #endif int -_yp_dobind(dom, ypdb) - const char *dom; - struct dom_binding **ypdb; +yp_setbindtries(int ntries) +{ + int old_val = _yplib_bindtries; + + if (ntries >= 0) + _yplib_bindtries = ntries; + return old_val; +} + +int +_yp_dobind(const char *dom, struct dom_binding **ypdb) { static int pid = -1; char path[MAXPATHLEN]; @@ -218,12 +228,18 @@ trynet: (xdrproc_t)xdr_ypdomain_wrap_string, &dom, (xdrproc_t)xdr_ypbind_resp, &ypbr, _yplib_timeout); if (r != RPC_SUCCESS) { - if (new == 0 && ++nerrs == _yplib_nerrs) { + if (_yplib_bindtries <= 0 && new == 0 && + ++nerrs == _yplib_nerrs) { nerrs = 0; fprintf(stderr, "YP server for domain %s not responding, still trying\n", dom); } + else if (_yplib_bindtries > 0 && + ++nerrs == _yplib_bindtries) { + free(ysd); + return YPERR_YPBIND; + } clnt_destroy(client); ysd->dom_vers = -1; goto again; @@ -270,8 +286,7 @@ gotit: } void -__yp_unbind(ypb) - struct dom_binding *ypb; +__yp_unbind(struct dom_binding *ypb) { _DIAGASSERT(ypb != NULL); @@ -282,8 +297,7 @@ __yp_unbind(ypb) } int -yp_bind(dom) - const char *dom; +yp_bind(const char *dom) { if (_yp_invalid_domain(dom)) return YPERR_BADARGS; @@ -292,8 +306,7 @@ yp_bind(dom) } void -yp_unbind(dom) - const char *dom; +yp_unbind(const char *dom) { struct dom_binding *ypb, *ypbp; @@ -317,8 +330,7 @@ yp_unbind(dom) } int -yp_get_default_domain(domp) - char **domp; +yp_get_default_domain(char **domp) { if (domp == NULL) return YPERR_BADARGS; @@ -331,8 +343,7 @@ yp_get_default_domain(domp) } int -_yp_check(dom) - char **dom; +_yp_check(char **dom) { char *unused; int good; @@ -358,8 +369,7 @@ done: * returns non-zero if invalid */ int -_yp_invalid_domain(dom) - const char *dom; +_yp_invalid_domain(const char *dom) { if (dom == NULL || *dom == '\0') return 1; diff --git a/lib/libc/yp/ypprot_err.c b/lib/libc/yp/ypprot_err.c index 84cb119a1..af42f059d 100644 --- a/lib/libc/yp/ypprot_err.c +++ b/lib/libc/yp/ypprot_err.c @@ -1,4 +1,4 @@ -/* $NetBSD: ypprot_err.c,v 1.5 2003/12/10 12:06:25 agc Exp $ */ +/* $NetBSD: ypprot_err.c,v 1.6 2012/06/25 22:32:46 abs Exp $ */ /* * Copyright (c) 1992, 1993 Theo de Raadt @@ -28,7 +28,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: ypprot_err.c,v 1.5 2003/12/10 12:06:25 agc Exp $"); +__RCSID("$NetBSD: ypprot_err.c,v 1.6 2012/06/25 22:32:46 abs Exp $"); #endif #include "namespace.h" @@ -41,8 +41,7 @@ __weak_alias(ypprot_err,_ypprot_err) #endif int -ypprot_err(incode) - unsigned int incode; +ypprot_err(unsigned int incode) { switch (incode) { case YP_TRUE: diff --git a/lib/libexec/exec_elf.c b/lib/libexec/exec_elf.c index e149d818a..a2096f1de 100644 --- a/lib/libexec/exec_elf.c +++ b/lib/libexec/exec_elf.c @@ -129,7 +129,7 @@ int libexec_load_elf(struct exec_info *execi) Elf_Phdr *phdr = NULL; int e, i = 0; int first = 1; - vir_bytes startv, stacklow; + vir_bytes startv = 0, stacklow; assert(execi != NULL); assert(execi->hdr != NULL); diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index a60ac86c0..5ff7da749 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -68,8 +68,10 @@ #define _GNU_SOURCE #endif +#ifndef __minix /* Needed for gmtime_r on Interix */ #define _REENTRANT +#endif #if HAVE_CONFIG_H #include "config.h" diff --git a/lib/libminc/Makefile b/lib/libminc/Makefile index b4909dc0d..b04001e91 100644 --- a/lib/libminc/Makefile +++ b/lib/libminc/Makefile @@ -8,29 +8,42 @@ LIB= minc CPPFLAGS.sched_start.c+= -I${NETBSDSRCDIR} -LIBCSRCDIR=${NETBSDSRCDIR}/lib/libc +LIBCSRCDIR= ${NETBSDSRCDIR}/lib/libc +CPPFLAGS+= -I${LIBCSRCDIR}/include -I${LIBCSRCDIR} +CPPFLAGS+= -D_LIBMINC + +# +# Customized versions of libc functions. +# +SRCS+= fputs.c # # Shared libc with userspace (/common/lib/libc) # .include "${NETBSDSRCDIR}/common/lib/libc/Makefile.inc" .include "${.CURDIR}/arch/${MACHINE_ARCH}/Makefile.libc.inc" + .if empty(SRCS:Mbyte_swap_8.*) SRCS+= bswap64.c .endif +.if empty(SRCS:Mmemset2.*) +SRCS+= memset.c +.endif + +# Quad support .if (${MACHINE_ARCH} != "alpha") && \ (${MACHINE_ARCH} != "mips64eb") && \ (${MACHINE_ARCH} != "mips64el") && \ (${MACHINE_ARCH} != "powerpc64") && \ (${MACHINE_ARCH} != "sparc64") && \ (${MACHINE_ARCH} != "x86_64") -# Quad support SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c \ iordi3.c lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c \ notdi2.c qdivrem.c subdi3.c ucmpdi2.c udivdi3.c umoddi3.c \ xordi3.c .endif + .for i in \ random.c strtoll.c strtoul.c strtoull.c strtoumax.c \ memchr.c memcmp.c memcpy.c memmove.c popcount32.c popcount64.c \ @@ -38,42 +51,42 @@ SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c \ strlcpy.c strlen.c strncasecmp.c strncmp.c strncpy.c strnlen.c \ strrchr.c strsep.c strstr.c ptree.c rb.c sha1.c sha2.c SRCS+= ${i} -CPPFLAGS.${i}+= -D_LIBC -I${LIBCSRCDIR}/include .endfor -.if empty(SRCS:Mmemset2.*) -SRCS+= memset.c -.endif - -# -# Customized versions of libc functions. -# -SRCS+= fputs.c _stdfile.c -CPPFLAGS.fputs.c+= -I${LIBCSRCDIR}/include - +CPPFLAGS.sha2.c+= -D_LIBC +CPPFLAGS.rb.c+= -D_LIBC +CPPFLAGS.strlcpy.c+= -D_LIBC # # Functions imported directly from the libc. # +# Import from misc (_libc_init symbols) +.for i in initfini.c stack_protector.c +.PATH.c: ${LIBCSRCDIR}/misc +SRCS+= ${i} +CPPFLAGS.${i}+= -Dxprintf=printf +.endfor + # Import from stdio -.for i in sprintf.c fprintf.c perror.c vsnprintf.c snprintf.c \ +.for i in findfp.c sprintf.c fprintf.c perror.c vsnprintf.c snprintf.c \ _rand48.c lrand48.c srand48.c .PATH.c: ${LIBCSRCDIR}/stdio -CPPFLAGS.${i}= -I${LIBCSRCDIR}/stdio -I${LIBCSRCDIR}/include +CPPFLAGS.${i}= -I${LIBCSRCDIR}/stdio SRCS+= ${i} .endfor + # Import from stdlib .for i in abort.c atexit.c atoi.c exit.c getenv.c \ getopt.c ldiv.c malloc.c .PATH.c: ${LIBCSRCDIR}/stdlib SRCS+= ${i} -CPPFLAGS.${i}+= -I${LIBCSRCDIR}/stdlib -I${LIBCSRCDIR}/include +CPPFLAGS.${i}+= -I${LIBCSRCDIR}/stdlib .endfor -# Import from gen +# Import from gen errlist.c: ${LIBCSRCDIR}/gen/errlist.awk \ - ${NETBSDSRCDIR}/include/sys/errno.h - cat ${NETBSDSRCDIR}/include/sys/errno.h | ${TOOL_SED} 's/(_SIGN//' | ${TOOL_AWK} -f ${LIBCSRCDIR}/gen/errlist.awk > ${.TARGET} + ${NETBSDSRCDIR}/sys/sys/errno.h + ${TOOL_CAT} ${NETBSDSRCDIR}/sys/sys/errno.h | ${TOOL_SED} 's/(_SIGN//' | ${TOOL_AWK} -f ${LIBCSRCDIR}/gen/errlist.awk > ${.TARGET} CLEANFILES+= errlist.c .for i in assert.c _errno.c errno.c _env.c errlist.c \ @@ -86,42 +99,44 @@ CLEANFILES+= errlist.c isfinitef_ieee754.c isfinited_ieee754.c \ signbitf_ieee754.c signbitd_ieee754.c \ nanf.c -.PATH.c: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/gen ${LIBCSRCDIR}/gen/minix \ +.PATH.c .PATH.S: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/gen ${LIBCSRCDIR}/gen/minix \ ${LIBCSRCDIR}/gen ${LIBCSRCDIR} SRCS+= ${i} -CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include .endfor CPPFLAGS.ctype_.c+= -I${LIBCSRCDIR}/locale CPPFLAGS.isctype.c+= -I${LIBCSRCDIR}/locale CPPFLAGS.tolower_.c+= -I${LIBCSRCDIR}/locale CPPFLAGS.toupper_.c+= -I${LIBCSRCDIR}/locale + # Import from regex .for i in regcomp.c regerror.c regexec.c regfree.c .PATH.c: ${LIBCSRCDIR}/regex SRCS+= ${i} -CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include .endfor + # Import from string .for i in strcspn.c strerror.c strerror_r.c strtol.c \ bcopy.S bzero.S .PATH.S: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string .PATH.c: ${LIBCSRCDIR}/string SRCS+= ${i} -CPPFLAGS.${i}+= -D_LIBC -I${LIBCSRCDIR}/include +CPPFLAGS.${i}+= -D_LIBC .endfor CPPFLAGS.strtol.c+= -I${LIBCSRCDIR}/../../common/lib/libc/stdlib + # Import from time .for i in asctime.c localtime.c strftime.c .PATH.c: ${LIBCSRCDIR}/time SRCS+= ${i} -CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include .endfor + # Import from locale .for i in _def_time.c .PATH.c: ${LIBCSRCDIR}/locale SRCS+= ${i} -CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include -I${LIBCSRCDIR}/locale +CPPFLAGS.${i}+= -I${LIBCSRCDIR}/locale .endfor + # Import from sys-minix .for i in access.c brk.c close.c environ.c execve.c fork.c \ getgid.c getpid.c getuid.c gettimeofday.c loadname.c \ @@ -132,7 +147,6 @@ CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include -I${LIBCSRCDIR}/locale .PATH.c: ${LIBCSRCDIR}/sys-minix .PATH.S: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/sys-minix SRCS+= ${i} -CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include .endfor CPPFLAGS+= -D_LIBSYS diff --git a/lib/libminc/abort.c b/lib/libminc/abort.c deleted file mode 100644 index 1210f920e..000000000 --- a/lib/libminc/abort.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -void abort() -{ - panic("Abort."); -} diff --git a/lib/libminc/arch/i386/Makefile.libc.inc b/lib/libminc/arch/i386/Makefile.libc.inc index 63d72ab71..c22501b4b 100644 --- a/lib/libminc/arch/i386/Makefile.libc.inc +++ b/lib/libminc/arch/i386/Makefile.libc.inc @@ -6,11 +6,10 @@ SRCS+= memchr.S memcmp.S memcpy.S memmove.S memset.S \ .for i in infinityl.c .PATH.c: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/gen SRCS+= ${i} -CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include .endfor # Import from string .for i in bcmp.S .PATH.S: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string SRCS+= ${i} -CPPFLAGS.${i}+= -D_LIBC -I${LIBCSRCDIR}/include +CPPFLAGS.${i}+= -D_LIBC .endfor diff --git a/lib/librmt/Makefile b/lib/librmt/Makefile index f518f54bd..d0323f896 100644 --- a/lib/librmt/Makefile +++ b/lib/librmt/Makefile @@ -11,6 +11,8 @@ LIB= rmt SRCS= rmtlib.c MAN= rmtops.3 +.ifndef __MINIX CPPFLAGS+= -D_REENTRANT +.endif .include diff --git a/lib/libsys/Makefile b/lib/libsys/Makefile index 9ffe70e52..5de363a20 100644 --- a/lib/libsys/Makefile +++ b/lib/libsys/Makefile @@ -1,9 +1,6 @@ # Makefile for libsys .include -# LSC For now -NOGCCERROR:= yes - LIB= sys SRCS= \ @@ -151,7 +148,6 @@ CPPFLAGS+= -DUSE_SYSDEBUG .endif CPPFLAGS.sched_start.c+= -I${NETBSDSRCDIR} -CPPFLAGS.vprintf.c+= -D__NBSD_LIBC .if (${CC} == "gcc") || (${CC} == "clang") LDADD+= -lminc diff --git a/lib/libsys/panic.c b/lib/libsys/panic.c index 711859bf9..79c47bce2 100644 --- a/lib/libsys/panic.c +++ b/lib/libsys/panic.c @@ -41,10 +41,8 @@ void panic(const char *fmt, ...) /* Try exit */ _exit(1); -#ifndef __NBSD_LIBC /* Try to signal ourself */ abort(); -#endif /* If exiting nicely through PM fails for some reason, try to * commit suicide. E.g., message to PM might fail due to deadlock. diff --git a/lib/libsys/tickdelay.c b/lib/libsys/tickdelay.c index d7f98450d..c47a2cf65 100644 --- a/lib/libsys/tickdelay.c +++ b/lib/libsys/tickdelay.c @@ -4,8 +4,7 @@ /*===========================================================================* * tickdelay * *===========================================================================*/ -int tickdelay(ticks) -long ticks; /* number of ticks to wait */ +int tickdelay(clock_t ticks) { /* This function uses the synchronous alarm to delay for a while. This works * even if a previous synchronous alarm was scheduled, because the remaining diff --git a/lib/libsys/vprintf.c b/lib/libsys/vprintf.c index 00198065c..8c4163492 100644 --- a/lib/libsys/vprintf.c +++ b/lib/libsys/vprintf.c @@ -8,15 +8,9 @@ /* vprintf() uses kputc() to print characters. */ void kputc(int c); -#ifdef __NBSD_LIBC #define count_kputc(c) do { charcount++; putf((c), farg); } while(0) int __fvprintf(void (*putf)(int, void *), const char *fmt, va_list argp, void *farg) -#else /* !NBSD_LIBC */ -#define count_kputc(c) do { charcount++; kputc(c); } while(0) - -int vprintf(const char *fmt, va_list argp) -#endif /* NBSD_LIBC */ { int c, charcount = 0; enum { LEFT, RIGHT } adjust; @@ -186,15 +180,11 @@ int vprintf(const char *fmt, va_list argp) } /* Mark the end with a null (should be something else, like -1). */ -#ifdef __NBDS_LIBC - putf(0, farg); -#else kputc(0); -#endif + return charcount; } -#ifdef __NBSD_LIBC #include #include #include @@ -230,7 +220,6 @@ int _vfprintf(FILE *fp, const char *fmt, va_list argp) { return __fvprintf(__xfputc, fmt, argp, fp); } -#endif /* * $PchId: kprintf.c,v 1.5 1996/04/11 06:59:05 philip Exp $ diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile index 87092b565..601fc4d81 100644 --- a/lib/libutil/Makefile +++ b/lib/libutil/Makefile @@ -8,8 +8,6 @@ USE_SHLIBDIR= yes .include "${NETBSDSRCDIR}/common/lib/libutil/Makefile.inc" WARNS?= 5 -# LSC MINIX Does not compile with -Werror -NOGCCERROR=yes LIB= util CPPFLAGS+=-DLIBC_SCCS -I${.CURDIR} LINTFLAGS+=-w @@ -37,8 +35,8 @@ MAN= efun.3 getbootfile.3 getfstypename.3 getlabelsector.3 \ ttymsg.3 util.3 .else -SRCS+= efun.c getbootfile.c \ - getmntopts.c sockaddr_snprintf.c\ +SRCS+= efun.c \ + getmntopts.c sockaddr_snprintf.c\ login.c loginx.c login_cap.c login_tty.c logout.c logoutx.c \ logwtmp.c logwtmpx.c opendisk.c \ passwd.c pw_scan.c pidfile.c pidlock.c pty.c \ @@ -46,7 +44,7 @@ SRCS+= efun.c getbootfile.c \ secure_path.c stat_flags.c \ ttyaction.c \ -MAN= efun.3 getbootfile.3 \ +MAN= efun.3 \ getmntopts.3 \ login.3 login_cap.3 loginx.3 \ opendisk.3 openpty.3 pidfile.3 pidlock.3 \ diff --git a/lib/libutil/opendisk.c b/lib/libutil/opendisk.c index de924e4e5..18a314f4f 100644 --- a/lib/libutil/opendisk.c +++ b/lib/libutil/opendisk.c @@ -48,7 +48,11 @@ static int __opendisk(const char *path, int flags, char *buf, size_t buflen, int iscooked, int (*ofn)(const char *, int, ...)) { +#ifndef __minix int f, rawpart; +#else + int f; +#endif if (buf == NULL) { errno = EFAULT; diff --git a/lib/libutil/sockaddr_snprintf.c b/lib/libutil/sockaddr_snprintf.c index 29a7c061e..ab2c748ed 100644 --- a/lib/libutil/sockaddr_snprintf.c +++ b/lib/libutil/sockaddr_snprintf.c @@ -54,14 +54,20 @@ sockaddr_snprintf(char * const sbuf, const size_t len, const char * const fmt, const struct sockaddr * const sa) { const void *a = NULL; +#ifndef __minix char abuf[1024], nbuf[1024], *addr = NULL, *w = NULL; +#else + char abuf[1024], nbuf[1024], *addr = NULL; +#endif char Abuf[1024], pbuf[32], *name = NULL, *port = NULL; char *ebuf = &sbuf[len - 1], *buf = sbuf; const char *ptr, *s; int p = -1; - const struct sockaddr_in *sin4 = NULL; #ifndef __minix const struct sockaddr_at *sat = NULL; +#endif + const struct sockaddr_in *sin4 = NULL; +#ifndef __minix const struct sockaddr_in6 *sin6 = NULL; const struct sockaddr_un *sun = NULL; const struct sockaddr_dl *sdl = NULL; diff --git a/lib/libvtreefs/inc.h b/lib/libvtreefs/inc.h index a2d23fe70..7e7b85072 100644 --- a/lib/libvtreefs/inc.h +++ b/lib/libvtreefs/inc.h @@ -1,6 +1,4 @@ -#ifndef __NBSD_LIBC #define _POSIX_SOURCE 1 /* tell headers to include POSIX stuff */ -#endif #define _MINIX 1 /* tell headers to include MINIX stuff */ #define _SYSTEM 1 /* tell headers that this is the kernel */ diff --git a/libexec/ld.elf_so/Makefile b/libexec/ld.elf_so/Makefile index 3378bbe13..0ca15ffcd 100644 --- a/libexec/ld.elf_so/Makefile +++ b/libexec/ld.elf_so/Makefile @@ -1,20 +1,14 @@ -# $NetBSD: Makefile,v 1.112 2012/08/04 15:17:16 matt Exp $ +# $NetBSD: Makefile,v 1.114 2012/08/23 21:21:15 joerg Exp $ # # NOTE: when changing ld.so, ensure that ldd still compiles. # WARNS?=4 -#LSC MINIX until warnings get fixed... -NOGCCERROR:=yes - -# This executable needs to be linked dynamically -LDSTATIC= -dynamic - -# And the minix gcc currently references /libexec/ld-elf.so.1 -SYMLINKS+= ${SHLINKINSTALLDIR}/${PROG} /libexec/ld-elf.so.1 # Minix Clang binaries references /libexec/ld.elf_so SYMLINKS+= ${SHLINKINSTALLDIR}/${PROG} /libexec/ld.elf_so +# And the minix gcc currently references /libexec/ld-elf.so.1 +SYMLINKS+= ${SHLINKINSTALLDIR}/${PROG} /libexec/ld-elf.so.1 # This needs to be before bsd.init.mk .if defined(BSD_MK_COMPAT_FILE) @@ -73,7 +67,8 @@ PROG= ld.elf_so CLIBOBJ!= cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR} SRCS+= rtld.c reloc.c symbol.c xmalloc.c xprintf.c debug.c \ - map_object.c load.c search.c headers.c paths.c expand.c + map_object.c load.c search.c headers.c paths.c expand.c \ + tls.c symver.c diagassert.c .if ${USE_FORT} == "yes" .PATH.c: ${NETBSDSRCDIR}/lib/libc/misc @@ -83,7 +78,7 @@ SRCS+= stack_protector.c .PATH.c: ${NETBSDSRCDIR}/lib/libc/stdlib SRCS+= exit.c -errlist_concat.h: ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk ${NETBSDSRCDIR}/include/sys/errno.h +errlist_concat.h: ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h ${TOOL_AWK} -v concat=1 -f ${.ALLSRC} > ${.TARGET}.tmp && \ mv -f ${.TARGET}.tmp ${.TARGET} @@ -101,8 +96,8 @@ CPPFLAGS+= -DCOMBRELOC #CPPFLAGS+= -DDEBUG #CPPFLAGS+= -DRTLD_DEBUG #CPPFLAGS+= -DRTLD_DEBUG_RELOC -DBG= -g -#COPTS= -O3 -fomit-frame-pointer +#DBG= -g +COPTS= -O3 -fomit-frame-pointer .if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64" COPTS+= -mno-3dnow -mno-mmx -mno-sse -mno-sse2 -mno-sse3 diff --git a/libexec/ld.elf_so/README.TLS b/libexec/ld.elf_so/README.TLS new file mode 100644 index 000000000..c8b7b94b4 --- /dev/null +++ b/libexec/ld.elf_so/README.TLS @@ -0,0 +1,67 @@ +Steps for adding TLS support for a new platform: + +(1) Declare TLS variant in machine/types.h by defining either +__HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II. + +(2) _lwp_makecontext has to set the reserved register or kernel transfer +variable in uc_mcontext to the provided value of 'private'. See +src/lib/libc/arch/$PLATFORM/gen/_lwp.c. + +This is not possible on the VAX as there is no free space in ucontext_t. +This requires either a special version of _lwp_create or versioning +everything using ucontext_t. Debug support depends on getting the data from +ucontext_t, so the second option is possibly required. + +(3) _lwp_setprivate(2) has to update the same register as +_lwp_makecontext uses for the private area pointer. Normally +cpu_lwp_setprivate is provided by MD to reflect the kernel view and +enabled by defining __HAVE_CPU_LWP_SETPRIVATE in machine/types.h. +cpu_setmcontext is responsible for keeping the MI l_private field +synchronised by calling lwp_setprivate as needed. + +cpu_switchto has to update the mapping. + +_lwp_setprivate is used for the initial thread, all other threads +created by libpthread use _lwp_makecontext for this purpose. + +(4) Provide __tls_get_addr and possible other MD functions for dynamic +TLS offset computation. If such alternative entry points exist (currently +only i386), also add a weak reference to 0 in src/lib/libc/tls/tls.c. + +The generic implementation can be found in tls.c and is used with +__HAVE_COMMON___TLS_GET_ADDR. It depends on ___lwp_getprivate_fast +(see below). + +(5) Implement the necessary relocation records in mdreloc.c. There are +typically three relocation types found in dynamic binaries: + +(a) R_TYPE(TLS_DTPOFF): Offset inside the module. The common TLS code +ensures that the DTV vector points to offset 0 inside the module TLS block. +This is normally def->st_value + rela->r_addend. + +(b) R_TYPE(TLS_DTPMOD): Module index. + +(c) R_TYPE(TLS_TPOFF): Static TLS offset. The code has to check whether +the static TLS offset for this module has been allocated +(defobj->tls_done) and otherwise call _rtld_tls_offset_allocate(). This +may fail if no static space is available and the object has been pulled +in via dlopen(3). + +For TLS Variant I, this is typically: + +def->st_value + rela->r_addend + defobj->tlsoffset + sizeof(struct tls_tcb) + +e.g. the relocation doesn't include the fixed TCB. + +For TLS Variant II, this is typically: + +def->st_value - defobj->tlsoffset + rela->r_addend + +e.g. starting offset is counting down from the TCB. + +(6) Implement _lwp_getprivate_fast() in machine/mcontext.h and set +__HAVE___LWP_GETPRIVATE_FAST in machine/types.h. + +(7) Test using src/tests/lib/libc/tls. Make sure with "objdump -R" that +t_tls_dynamic has two TPOFF relocations and h_tls_dlopen.so.1 and +libh_tls_dynamic.so.1 have both two DTPMOD and DTPOFF relocations. diff --git a/libexec/ld.elf_so/TODO b/libexec/ld.elf_so/TODO index 55ecf74a5..03800bf08 100644 --- a/libexec/ld.elf_so/TODO +++ b/libexec/ld.elf_so/TODO @@ -1,6 +1,10 @@ rtld: * resolve MIPS binding lossage +TLS: +* implement proper allocator for static TLS and support for actively + freeing DTV entries. + binutils/gcc: * alpha: why are there GLOB_DAT relocs in ld.elf_so? * alpha: bogus textrels in rtti info diff --git a/libexec/ld.elf_so/arch/alpha/alpha_reloc.c b/libexec/ld.elf_so/arch/alpha/alpha_reloc.c index 357adc78e..713eb8191 100644 --- a/libexec/ld.elf_so/arch/alpha/alpha_reloc.c +++ b/libexec/ld.elf_so/arch/alpha/alpha_reloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: alpha_reloc.c,v 1.38 2010/09/30 09:11:18 skrll Exp $ */ +/* $NetBSD: alpha_reloc.c,v 1.40 2011/03/31 15:30:31 skrll Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -62,10 +62,11 @@ #include #ifndef lint -__RCSID("$NetBSD: alpha_reloc.c,v 1.38 2010/09/30 09:11:18 skrll Exp $"); +__RCSID("$NetBSD: alpha_reloc.c,v 1.40 2011/03/31 15:30:31 skrll Exp $"); #endif /* not lint */ #include +#include #include #include "rtld.h" @@ -261,6 +262,64 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) rdbg(("COPY (avoid in main)")); break; + case R_TYPE(TPREL64): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && + _rtld_tls_offset_allocate(obj)) + return -1; + + tmp = (Elf64_Addr)(def->st_value + + sizeof(struct tls_tcb) + defobj->tlsoffset + + rela->r_addend); + + if (__predict_true(RELOC_ALIGNED_P(where))) + *where = tmp; + else + store_ptr(where, tmp); + + rdbg(("TPREL64 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + + case R_TYPE(DTPMOD64): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + tmp = (Elf64_Addr)defobj->tlsindex; + if (__predict_true(RELOC_ALIGNED_P(where))) + *where = tmp; + else + store_ptr(where, tmp); + + rdbg(("DTPMOD64 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + + case R_TYPE(DTPREL64): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + tmp = (Elf64_Addr)(def->st_value + rela->r_addend); + if (__predict_true(RELOC_ALIGNED_P(where))) + *where = tmp; + else + store_ptr(where, tmp); + + rdbg(("DTPREL64 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + default: rdbg(("sym = %lu, type = %lu, offset = %p, " "addend = %p, contents = %p, symbol = %s", @@ -483,9 +542,11 @@ _rtld_bind(const Obj_Entry *obj, Elf_Addr reloff) Elf_Addr result = 0; /* XXX gcc */ int err; + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, rela, &result); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)result; } diff --git a/libexec/ld.elf_so/arch/arm/mdreloc.c b/libexec/ld.elf_so/arch/arm/mdreloc.c index d62c6902c..533826d42 100644 --- a/libexec/ld.elf_so/arch/arm/mdreloc.c +++ b/libexec/ld.elf_so/arch/arm/mdreloc.c @@ -1,8 +1,8 @@ -/* $NetBSD: mdreloc.c,v 1.34 2010/08/06 16:33:17 joerg Exp $ */ +/* $NetBSD: mdreloc.c,v 1.37 2011/11/18 16:10:03 joerg Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.34 2010/08/06 16:33:17 joerg Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.37 2011/11/18 16:10:03 joerg Exp $"); #endif /* not lint */ #include @@ -179,6 +179,59 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) rdbg(("COPY (avoid in main)")); break; + case R_TYPE(TLS_DTPOFF32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + tmp = (Elf_Addr)(def->st_value); + if (__predict_true(RELOC_ALIGNED_P(where))) + *where = tmp; + else + store_ptr(where, tmp); + + rdbg(("TLS_DTPOFF32 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)tmp)); + + break; + case R_TYPE(TLS_DTPMOD32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + tmp = (Elf_Addr)(defobj->tlsindex); + if (__predict_true(RELOC_ALIGNED_P(where))) + *where = tmp; + else + store_ptr(where, tmp); + + rdbg(("TLS_DTPMOD32 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)tmp)); + + break; + + case R_TYPE(TLS_TPOFF32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && + _rtld_tls_offset_allocate(obj)) + return -1; + + tmp = (Elf_Addr)def->st_value + defobj->tlsoffset + + sizeof(struct tls_tcb); + if (__predict_true(RELOC_ALIGNED_P(where))) + *where = tmp; + else + store_ptr(where, tmp); + rdbg(("TLS_TPOFF32 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)tmp)); + break; + default: rdbg(("sym = %lu, type = %lu, offset = %p, " "contents = %p, symbol = %s", @@ -254,9 +307,11 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff) Elf_Addr new_value = 0; /* XXX gcc */ int err; + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, rel, &new_value); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)new_value; } diff --git a/libexec/ld.elf_so/arch/arm/rtld_start.S b/libexec/ld.elf_so/arch/arm/rtld_start.S index 41a599c19..031586061 100644 --- a/libexec/ld.elf_so/arch/arm/rtld_start.S +++ b/libexec/ld.elf_so/arch/arm/rtld_start.S @@ -1,4 +1,4 @@ -/* $NetBSD: rtld_start.S,v 1.10 2009/11/11 14:15:41 skrll Exp $ */ +/* $NetBSD: rtld_start.S,v 1.11 2012/08/13 02:53:25 matt Exp $ */ /*- * Copyright (c) 1998, 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include -RCSID("$NetBSD: rtld_start.S,v 1.10 2009/11/11 14:15:41 skrll Exp $") +RCSID("$NetBSD: rtld_start.S,v 1.11 2012/08/13 02:53:25 matt Exp $") .text .align 0 @@ -58,9 +58,8 @@ _rtld_start: bl _rtld /* call the shared loader */ mov r3, r0 /* save entry point */ - ldr r2, [sp, #0] /* r2 = cleanup */ - ldr r1, [sp, #4] /* r1 = obj_main */ - add sp, sp, #8 /* restore stack */ + ldr r2, [sp], #4 /* pop r2 = cleanup */ + ldr r1, [sp], #4 /* pop r1 = obj_main */ mov r0, r4 /* restore ps_strings */ #ifdef _ARM_ARCH_4T bx r3 /* jump to the entry point */ @@ -81,7 +80,7 @@ _rtld_start: * lr = &GOT[2] */ _rtld_bind_start: - stmdb sp!,{r0-r4,sl,fp} + stmdb sp!,{r0-r4,sl,fp} /* 8 byte aligned (lr already saved) */ sub r1, ip, lr /* r1 = 4 * (n + 1) */ sub r1, r1, #4 /* r1 = 4 * n */ diff --git a/libexec/ld.elf_so/arch/hppa/hppa_reloc.c b/libexec/ld.elf_so/arch/hppa/hppa_reloc.c index ef1cdf1fb..3c29280ab 100644 --- a/libexec/ld.elf_so/arch/hppa/hppa_reloc.c +++ b/libexec/ld.elf_so/arch/hppa/hppa_reloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: hppa_reloc.c,v 1.34 2010/09/24 11:41:46 skrll Exp $ */ +/* $NetBSD: hppa_reloc.c,v 1.42 2012/01/06 10:38:57 skrll Exp $ */ /*- * Copyright (c) 2002, 2004 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: hppa_reloc.c,v 1.34 2010/09/24 11:41:46 skrll Exp $"); +__RCSID("$NetBSD: hppa_reloc.c,v 1.42 2012/01/06 10:38:57 skrll Exp $"); #endif /* not lint */ #include @@ -82,6 +82,30 @@ store_ptr(void *where, Elf_Addr val) (void)memcpy(where, &val, sizeof(val)); } +static __inline void +fdc(void *addr) +{ + __asm volatile("fdc %%r0(%%sr0, %0)" : : "r" (addr)); +} + +static __inline void +fic(void *addr) +{ + __asm volatile("fic %%r0(%%sr0,%0)" : : "r" (addr)); +} + +static __inline void +sync(void) +{ + __asm volatile("sync" : : : "memory"); +} + +#define PLT_STUB_MAGIC1 0x00c0ffee +#define PLT_STUB_MAGIC2 0xdeadbeef + +#define PLT_STUB_INSN1 0x0e801081 /* ldw 0(%r20), %r1 */ +#define PLT_STUB_INSN2 0xe820c000 /* bv %r0(%r1) */ + /* * In the runtime architecture (ABI), PLABEL function pointers are * distinguished from normal function pointers by having the next-least- @@ -114,7 +138,7 @@ static SLIST_HEAD(hppa_plabel_head, _hppa_plabel) hppa_plabel_list * Because I'm hesitant to use NEW while relocating self, * this is a small pool of preallocated PLABELs. */ -#define HPPA_PLABEL_PRE (14) +#define HPPA_PLABEL_PRE (32) static hppa_plabel hppa_plabel_pre[HPPA_PLABEL_PRE]; static int hppa_plabel_pre_next = 0; @@ -177,7 +201,7 @@ _rtld_relocate_nonplt_self(Elf_Dyn *dynp, Elf_Addr relocbase) case DT_PLTGOT: pltgot = (Elf_Addr *) (relocbase + dynp->d_un.d_ptr); - break; + break; } } relalim = (const Elf_Rela *)((const char *)relafirst + relasz); @@ -230,11 +254,11 @@ _rtld_relocate_nonplt_self(Elf_Dyn *dynp, Elf_Addr relocbase) plabel = &hppa_plabel_pre[hppa_plabel_pre_next++]; - plabel->hppa_plabel_pc = (Elf_Addr) + plabel->hppa_plabel_pc = (Elf_Addr) (relocbase + sym->st_value + rela->r_addend); - plabel->hppa_plabel_sl = (Elf_Addr)pltgot; + plabel->hppa_plabel_sl = (Elf_Addr)pltgot; - SLIST_INSERT_HEAD(&hppa_plabel_list, plabel, hppa_plabel_next); + SLIST_INSERT_HEAD(&hppa_plabel_list, plabel, hppa_plabel_next); *((Elf_Addr *)where) = (Elf_Addr)(RTLD_MAKE_PLABEL(plabel)); } @@ -355,7 +379,34 @@ _rtld_function_descriptor_function(const void *addr) void _rtld_setup_pltgot(const Obj_Entry *obj) { - __rtld_setup_hppa_pltgot(obj, obj->pltgot); + Elf_Word *got = obj->pltgot; + + assert(got[-2] == PLT_STUB_MAGIC1); + assert(got[-1] == PLT_STUB_MAGIC2); + + __rtld_setup_hppa_pltgot(obj, got); + + fdc(&got[-2]); + fdc(&got[-1]); + fdc(&got[1]); + sync(); + fic(&got[-2]); + fic(&got[-1]); + fic(&got[1]); + sync(); + + /* + * libc makes use of %t1 (%r22) to pass errno values to __cerror. Fixup + * the PLT stub to not use %r22. + */ + got[-7] = PLT_STUB_INSN1; + got[-6] = PLT_STUB_INSN2; + fdc(&got[-7]); + fdc(&got[-6]); + sync(); + fic(&got[-7]); + fic(&got[-6]); + sync(); } int @@ -473,6 +524,48 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) rdbg(("COPY (avoid in main)")); break; + case R_TYPE(TLS_TPREL32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && _rtld_tls_offset_allocate(obj)) + return -1; + + *where = (Elf_Addr)(defobj->tlsoffset + def->st_value + + rela->r_addend + sizeof(struct tls_tcb)); + + rdbg(("TPREL32 %s in %s --> %p in %s", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where, defobj->path)); + break; + + case R_TYPE(TLS_DTPMOD32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf_Addr)(defobj->tlsindex); + + rdbg(("TLS_DTPMOD32 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + + case R_TYPE(TLS_DTPOFF32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf_Addr)(def->st_value); + + rdbg(("TLS_DTPOFF32 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + default: rdbg(("sym = %lu, type = %lu, offset = %p, " "addend = %p, contents = %p, symbol = %s", @@ -597,9 +690,11 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff) assert(ELF_R_SYM(rela->r_info) != 0); + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, rela, &new_value); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)new_value; } diff --git a/libexec/ld.elf_so/arch/hppa/rtld_start.S b/libexec/ld.elf_so/arch/hppa/rtld_start.S index ce2f229e3..230fc4271 100644 --- a/libexec/ld.elf_so/arch/hppa/rtld_start.S +++ b/libexec/ld.elf_so/arch/hppa/rtld_start.S @@ -1,4 +1,4 @@ -/* $NetBSD: rtld_start.S,v 1.9 2010/09/30 19:32:40 skrll Exp $ */ +/* $NetBSD: rtld_start.S,v 1.12 2012/01/06 10:38:57 skrll Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -46,7 +46,7 @@ ENTRY($rtld_start,HPPA_FRAME_SIZE) * twice later: once to call _rtld, and again to transfer to the * program's entry point. */ - stw %arg0, HPPA_FRAME_ARG(0)(%r3) + stw %arg0, HPPA_FRAME_ARG(0)(%r3) /* * We can't move to C until we relocate at least the @@ -139,7 +139,7 @@ L$lpc2: addil L'_rtld_bind_start - ($PIC_pcrel$0 - 8), %arg0 stw %arg0, -8(%arg1) bv %r0(%rp) stw %r19, -4(%arg1) -EXIT(__rtld_hppa_setup_pltgot) +EXIT(__rtld_setup_hppa_pltgot) /* * In order to support lazy binding, this implementation of _rtld_bind_start is @@ -181,6 +181,7 @@ ENTRY(_rtld_bind_start,HPPA_FRAME_SIZE) /* 0(%r3) is filled with the saved %r3 above */ stw %ret0, 4(%r3) stw %ret1, 8(%r3) + stw %t1, 12(%r3) /* %r22 */ /* * The linker PLT stub loads %r20 with (GOT - 8) for the object that @@ -220,6 +221,7 @@ ENTRY(_rtld_bind_start,HPPA_FRAME_SIZE) ldw HPPA_FRAME_ARG(3)(%r3), %arg3 ldw 4(%r3), %ret0 ldw 8(%r3), %ret1 + ldw 12(%r3), %t1 /* %r22 */ /* End stack calling convention. */ ldo HPPA_FRAME_SIZE(%r3), %sp diff --git a/libexec/ld.elf_so/arch/i386/mdreloc.c b/libexec/ld.elf_so/arch/i386/mdreloc.c index b1657c682..feb50a1df 100644 --- a/libexec/ld.elf_so/arch/i386/mdreloc.c +++ b/libexec/ld.elf_so/arch/i386/mdreloc.c @@ -1,11 +1,12 @@ -/* $NetBSD: mdreloc.c,v 1.32 2010/08/06 16:33:18 joerg Exp $ */ +/* $NetBSD: mdreloc.c,v 1.34 2011/03/25 18:07:05 joerg Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.32 2010/08/06 16:33:18 joerg Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.34 2011/03/25 18:07:05 joerg Exp $"); #endif /* not lint */ #include +#include #include "debug.h" #include "rtld.h" @@ -119,6 +120,49 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) rdbg(("COPY (avoid in main)")); break; +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + case R_TYPE(TLS_TPOFF): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && + _rtld_tls_offset_allocate(obj)) + return -1; + + *where = (Elf_Addr)(def->st_value - defobj->tlsoffset); + + rdbg(("TLS_TPOFF %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + break; + + case R_TYPE(TLS_DTPMOD32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf_Addr)(defobj->tlsindex); + + rdbg(("TLS_DTPMOD32 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + break; + + case R_TYPE(TLS_DTPOFF32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf_Addr)(def->st_value); + + rdbg(("TLS_DTPOFF32 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; +#endif + default: rdbg(("sym = %lu, type = %lu, offset = %p, " "contents = %p, symbol = %s", @@ -194,9 +238,11 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff) new_value = 0; /* XXX gcc */ + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, rel, &new_value); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)new_value; } @@ -214,3 +260,27 @@ _rtld_relocate_plt_objects(const Obj_Entry *obj) } return err; } + +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) +/* + * i386 specific GNU variant of __tls_get_addr using register based + * argument passing. + */ +#define DTV_MAX_INDEX(dtv) ((size_t)((dtv)[-1])) + +__dso_public __attribute__((__regparm__(1))) void * +___tls_get_addr(void *arg_) +{ + size_t *arg = (size_t *)arg_; + void **dtv; + struct tls_tcb *tcb = __lwp_getprivate_fast(); + size_t idx = arg[0], offset = arg[1]; + + dtv = tcb->tcb_dtv; + + if (__predict_true(idx < DTV_MAX_INDEX(dtv) && dtv[idx] != NULL)) + return (uint8_t *)dtv[idx] + offset; + + return _rtld_tls_get_addr(tcb, idx, offset); +} +#endif diff --git a/libexec/ld.elf_so/arch/m68k/mdreloc.c b/libexec/ld.elf_so/arch/m68k/mdreloc.c index ea18f0330..69ad8737f 100644 --- a/libexec/ld.elf_so/arch/m68k/mdreloc.c +++ b/libexec/ld.elf_so/arch/m68k/mdreloc.c @@ -1,13 +1,13 @@ -/* $NetBSD: mdreloc.c,v 1.27 2010/08/06 16:33:18 joerg Exp $ */ +/* $NetBSD: mdreloc.c,v 1.29 2011/11/22 15:25:28 joerg Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.27 2010/08/06 16:33:18 joerg Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.29 2011/11/22 15:25:28 joerg Exp $"); #endif /* not lint */ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.27 2010/08/06 16:33:18 joerg Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.29 2011/11/22 15:25:28 joerg Exp $"); #endif /* not lint */ #include @@ -126,6 +126,47 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) rdbg(("COPY (avoid in main)")); break; + case R_TYPE(TLS_DTPMOD32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf_Addr)defobj->tlsindex; + rdbg(("DTPMOD32 %s in %s --> %p in %s", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where, defobj->path)); + break; + + case R_TYPE(TLS_DTPREL32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && _rtld_tls_offset_allocate(obj)) + return -1; + + *where = (Elf_Addr)(def->st_value + rela->r_addend + - TLS_DTV_OFFSET); + rdbg(("DTPREL32 %s in %s --> %p in %s", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where, defobj->path)); + break; + + case R_TYPE(TLS_TPREL32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && _rtld_tls_offset_allocate(obj)) + return -1; + + *where = (Elf_Addr)(def->st_value + rela->r_addend + + defobj->tlsoffset - TLS_TP_OFFSET); + rdbg(("TPREL32 %s in %s --> %p in %s", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where, defobj->path)); + break; + default: rdbg(("sym = %lu, type = %lu, offset = %p, " "addend = %p, contents = %p, symbol = %s", @@ -204,9 +245,11 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff) result = 0; /* XXX gcc */ + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, rela, &result); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)result; } diff --git a/libexec/ld.elf_so/arch/mips/mips_reloc.c b/libexec/ld.elf_so/arch/mips/mips_reloc.c index a77e5a923..775e8dee9 100644 --- a/libexec/ld.elf_so/arch/mips/mips_reloc.c +++ b/libexec/ld.elf_so/arch/mips/mips_reloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: mips_reloc.c,v 1.60 2010/09/24 15:20:52 matt Exp $ */ +/* $NetBSD: mips_reloc.c,v 1.62 2011/03/25 18:07:05 joerg Exp $ */ /* * Copyright 1997 Michael L. Hitch @@ -30,11 +30,12 @@ #include #ifndef lint -__RCSID("$NetBSD: mips_reloc.c,v 1.60 2010/09/24 15:20:52 matt Exp $"); +__RCSID("$NetBSD: mips_reloc.c,v 1.62 2011/03/25 18:07:05 joerg Exp $"); #endif /* not lint */ #include #include +#include #include #include @@ -375,6 +376,79 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) break; } +#if ELFSIZE == 64 + case R_TYPE(TLS_DTPMOD64): +#else + case R_TYPE(TLS_DTPMOD32): +#endif + { + Elf_Addr old = load_ptr(where, ELFSIZE / 8); + Elf_Addr val = old; + + def = _rtld_find_symdef(r_symndx, obj, &defobj, false); + if (def == NULL) + return -1; + + val += (Elf_Addr)defobj->tlsindex; + + store_ptr(where, val, ELFSIZE / 8); + rdbg(("DTPMOD %s in %s --> %p in %s", + obj->strtab + obj->symtab[r_symndx].st_name, + obj->path, (void *)old, defobj->path)); + break; + } + +#if ELFSIZE == 64 + case R_TYPE(TLS_DTPREL64): +#else + case R_TYPE(TLS_DTPREL32): +#endif + { + Elf_Addr old = load_ptr(where, ELFSIZE / 8); + Elf_Addr val = old; + + def = _rtld_find_symdef(r_symndx, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && _rtld_tls_offset_allocate(obj)) + return -1; + + val += (Elf_Addr)def->st_value - TLS_DTV_OFFSET; + store_ptr(where, val, ELFSIZE / 8); + + rdbg(("DTPREL %s in %s --> %p in %s", + obj->strtab + obj->symtab[r_symndx].st_name, + obj->path, (void *)old, defobj->path)); + break; + } + +#if ELFSIZE == 64 + case R_TYPE(TLS_TPREL64): +#else + case R_TYPE(TLS_TPREL32): +#endif + { + Elf_Addr old = load_ptr(where, ELFSIZE / 8); + Elf_Addr val = old; + + def = _rtld_find_symdef(r_symndx, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && _rtld_tls_offset_allocate(obj)) + return -1; + + val += (Elf_Addr)(def->st_value + defobj->tlsoffset + - TLS_TP_OFFSET); + store_ptr(where, val, ELFSIZE / 8); + + rdbg(("TPREL %s in %s --> %p in %s", + obj->strtab + obj->symtab[r_symndx].st_name, + obj->path, (void *)*where, defobj->path)); + break; + } + default: rdbg(("sym = %lu, type = %lu, offset = %p, " "contents = %p, symbol = %s", @@ -431,9 +505,11 @@ _rtld_bind(Elf_Word a0, Elf_Addr a1, Elf_Addr a2, Elf_Addr a3) Elf_Addr new_value = 0; /* XXX gcc */ int err; + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, a0, &new_value); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)new_value; } diff --git a/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c b/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c index 88b93a76e..c1bffdaa1 100644 --- a/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c +++ b/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: ppc_reloc.c,v 1.46 2011/01/16 01:22:29 matt Exp $ */ +/* $NetBSD: ppc_reloc.c,v 1.49 2011/03/25 18:07:06 joerg Exp $ */ /*- * Copyright (C) 1998 Tsubai Masanari @@ -30,7 +30,7 @@ #include #ifndef lint -__RCSID("$NetBSD: ppc_reloc.c,v 1.46 2011/01/16 01:22:29 matt Exp $"); +__RCSID("$NetBSD: ppc_reloc.c,v 1.49 2011/03/25 18:07:06 joerg Exp $"); #endif /* not lint */ #include @@ -82,6 +82,9 @@ _rtld_setup_pltgot(const Obj_Entry *obj) if (obj->gotptr != NULL) { obj->gotptr[1] = (Elf_Addr) _rtld_bind_secureplt_start; obj->gotptr[2] = (Elf_Addr) obj; + dbg(("obj %s secure-plt gotptr=%p start=%p obj=%p", + obj->path, obj->gotptr, + (void *) obj->gotptr[1], (void *) obj->gotptr[2])); } else { Elf_Word *pltcall, *pltresolve; Elf_Word *jmptab; @@ -91,6 +94,10 @@ _rtld_setup_pltgot(const Obj_Entry *obj) if (N > 8192) N += N-8192; + dbg(("obj %s bss-plt pltgot=%p jmptab=%u start=%p obj=%p", + obj->path, obj->pltgot, 18 + N * 2, + _rtld_bind_bssplt_start, obj)); + pltcall = obj->pltgot; jmptab = pltcall + 18 + N * 2; @@ -197,6 +204,47 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) rdbg(("COPY (avoid in main)")); break; + case R_TYPE(DTPMOD32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf_Addr)defobj->tlsindex; + rdbg(("DTPMOD32 %s in %s --> %p in %s", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where, defobj->path)); + break; + + case R_TYPE(DTPREL32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && _rtld_tls_offset_allocate(obj)) + return -1; + + *where = (Elf_Addr)(def->st_value + rela->r_addend + - TLS_DTV_OFFSET); + rdbg(("DTPREL32 %s in %s --> %p in %s", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where, defobj->path)); + break; + + case R_TYPE(TPREL32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && _rtld_tls_offset_allocate(obj)) + return -1; + + *where = (Elf_Addr)(def->st_value + rela->r_addend + + defobj->tlsoffset - TLS_TP_OFFSET); + rdbg(("TPREL32 %s in %s --> %p in %s", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where, defobj->path)); + break; + default: rdbg(("sym = %lu, type = %lu, offset = %p, " "addend = %p, contents = %p, symbol = %s", @@ -343,15 +391,17 @@ _rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rela *rela, int reloff caddr_t _rtld_bind(const Obj_Entry *obj, Elf_Word reloff) { - const Elf_Rela *rela = (const void *)((const char *)obj->pltrela + reloff); + const Elf_Rela *rela = obj->pltrela + reloff; Elf_Addr new_value; int err; new_value = 0; /* XXX gcc */ + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, rela, reloff, &new_value); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)new_value; } diff --git a/libexec/ld.elf_so/arch/powerpc/rtld_start.S b/libexec/ld.elf_so/arch/powerpc/rtld_start.S index aa57681ac..af8e9fd25 100644 --- a/libexec/ld.elf_so/arch/powerpc/rtld_start.S +++ b/libexec/ld.elf_so/arch/powerpc/rtld_start.S @@ -1,4 +1,4 @@ -/* $NetBSD: rtld_start.S,v 1.14 2011/01/16 01:22:29 matt Exp $ */ +/* $NetBSD: rtld_start.S,v 1.17 2011/09/26 01:52:22 mrg Exp $ */ /*- * Copyright (C) 1998 Tsubai Masanari @@ -84,14 +84,26 @@ END(_rtld_start) * bss-plt expects %r11 to be index of the rela entry. * So for bss-plt, we multiply the index by 12 to get the offset. */ -ENTRY_NOPROFILE(_rtld_bind_bssplt_start) - slwi %r11,%r11,2 - add %r0,%r11,%r11 - add %r11,%r11,%r0 ENTRY_NOPROFILE(_rtld_bind_secureplt_start) stwu %r1,-160(%r1) + stw %r0,20(%r1) + + /* + * Instead of division which is costly we will use multiplicative + * inverse. a / n = ((a * inv(n)) >> 32) + * where inv(n) = (0x100000000 + n - 1) / n + */ + mr %r0,%r11 + lis %r11,0x15555556@h # load multiplicative inverse of 12 + ori %r11,%r11,0x15555556@l + mulhwu %r11,%r11,%r0 # get high half of multiplication + + b 1f +ENTRY_NOPROFILE(_rtld_bind_bssplt_start) + stwu %r1,-160(%r1) stw %r0,20(%r1) +1: mflr %r0 stw %r0,16(%r1) # save lr mfcr %r0 @@ -112,7 +124,7 @@ ENTRY_NOPROFILE(_rtld_bind_secureplt_start) addi %r1,%r1,160 bctr -END(_rtld_bind_start) +END(_rtld_bind_secureplt_start) .globl _rtld_powerpc_pltcall .globl _rtld_powerpc_pltresolve diff --git a/libexec/ld.elf_so/arch/sh3/mdreloc.c b/libexec/ld.elf_so/arch/sh3/mdreloc.c index 6ceb4ca0a..3f9e04f91 100644 --- a/libexec/ld.elf_so/arch/sh3/mdreloc.c +++ b/libexec/ld.elf_so/arch/sh3/mdreloc.c @@ -1,16 +1,17 @@ -/* $NetBSD: mdreloc.c,v 1.28 2010/08/06 16:33:18 joerg Exp $ */ +/* $NetBSD: mdreloc.c,v 1.30 2011/03/25 18:07:06 joerg Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.28 2010/08/06 16:33:18 joerg Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.30 2011/03/25 18:07:06 joerg Exp $"); #endif /* not lint */ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.28 2010/08/06 16:33:18 joerg Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.30 2011/03/25 18:07:06 joerg Exp $"); #endif /* not lint */ #include +#include #include "debug.h" #include "rtld.h" @@ -154,6 +155,49 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) rdbg(("COPY (avoid in main)")); break; + case R_TYPE(TLS_DTPOFF32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf_Addr)(def->st_value); + + rdbg(("TLS_DTPOFF32 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + case R_TYPE(TLS_DTPMOD32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf_Addr)(defobj->tlsindex); + + rdbg(("TLS_DTPMOD32 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + + case R_TYPE(TLS_TPOFF32): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && + _rtld_tls_offset_allocate(obj)) + return -1; + + *where = (Elf_Addr)def->st_value + + rela->r_addend + defobj->tlsoffset + + sizeof(struct tls_tcb); + + rdbg(("TLS_TPOFF32 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + break; + default: rdbg(("sym = %lu, type = %lu, offset = %p, " "addend = %p, contents = %p, symbol = %s", @@ -200,9 +244,11 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff) new_value = 0; /* XXX gcc */ + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, rela, &new_value); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)new_value; } diff --git a/libexec/ld.elf_so/arch/sparc/mdreloc.c b/libexec/ld.elf_so/arch/sparc/mdreloc.c index 6b10b5861..a7fe54d58 100644 --- a/libexec/ld.elf_so/arch/sparc/mdreloc.c +++ b/libexec/ld.elf_so/arch/sparc/mdreloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: mdreloc.c,v 1.44 2010/08/06 16:33:18 joerg Exp $ */ +/* $NetBSD: mdreloc.c,v 1.47 2011/03/31 12:47:01 nakayama Exp $ */ /*- * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.44 2010/08/06 16:33:18 joerg Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.47 2011/03/31 12:47:01 nakayama Exp $"); #endif /* not lint */ #include @@ -66,7 +66,7 @@ __RCSID("$NetBSD: mdreloc.c,v 1.44 2010/08/06 16:33:18 joerg Exp $"); #define _RF_U 0x04000000 /* Unaligned */ #define _RF_SZ(s) (((s) & 0xff) << 8) /* memory target size */ #define _RF_RS(s) ( (s) & 0xff) /* right shift */ -static const int reloc_target_flags[] = { +static const int reloc_target_flags[R_TYPE(TLS_TPOFF64)+1] = { 0, /* NONE */ _RF_S|_RF_A| _RF_SZ(8) | _RF_RS(0), /* RELOC_8 */ _RF_S|_RF_A| _RF_SZ(16) | _RF_RS(0), /* RELOC_16 */ @@ -91,6 +91,8 @@ static const int reloc_target_flags[] = { _RF_SZ(32) | _RF_RS(0), /* JMP_SLOT */ _RF_A| _RF_B| _RF_SZ(32) | _RF_RS(0), /* RELATIVE */ _RF_S|_RF_A| _RF_U| _RF_SZ(32) | _RF_RS(0), /* UA_32 */ + + /* TLS and 64 bit relocs not listed here... */ }; #ifdef RTLD_DEBUG_RELOC @@ -99,7 +101,22 @@ static const char *reloc_names[] = { "DISP_16", "DISP_32", "WDISP_30", "WDISP_22", "HI22", "22", "13", "LO10", "GOT10", "GOT13", "GOT22", "PC10", "PC22", "WPLT30", "COPY", - "GLOB_DAT", "JMP_SLOT", "RELATIVE", "UA_32" + "GLOB_DAT", "JMP_SLOT", "RELATIVE", "UA_32", + + /* not used with 32bit userland, besides a few of the TLS ones */ + "PLT32", + "HIPLT22", "LOPLT10", "LOPLT10", "PCPLT22", "PCPLT32", + "10", "11", "64", "OLO10", "HH22", + "HM10", "LM22", "PC_HH22", "PC_HM10", "PC_LM22", + "WDISP16", "WDISP19", "GLOB_JMP", "7", "5", "6", + "DISP64", "PLT64", "HIX22", "LOX10", "H44", "M44", + "L44", "REGISTER", "UA64", "UA16", + "TLS_GD_HI22", "TLS_GD_LO10", "TLS_GD_ADD", "TLS_GD_CALL", + "TLS_LDM_HI22", "TLS_LDM_LO10", "TLS_LDM_ADD", "TLS_LDM_CALL", + "TLS_LDO_HIX22", "TLS_LDO_LOX10", "TLS_LDO_ADD", "TLS_IE_HI22", + "TLS_IE_LO10", "TLS_IE_LD", "TLS_IE_LDX", "TLS_IE_ADD", "TLS_LE_HIX22", + "TLS_LE_LOX10", "TLS_DTPMOD32", "TLS_DTPMOD64", "TLS_DTPOFF32", + "TLS_DTPOFF64", "TLS_TPOFF32", "TLS_TPOFF64", }; #endif @@ -110,6 +127,7 @@ static const char *reloc_names[] = { #define RELOC_USE_ADDEND(t) ((reloc_target_flags[t] & _RF_A) != 0) #define RELOC_TARGET_SIZE(t) ((reloc_target_flags[t] >> 8) & 0xff) #define RELOC_VALUE_RIGHTSHIFT(t) (reloc_target_flags[t] & 0xff) +#define RELOC_TLS(t) (t >= R_TYPE(TLS_GD_HI22)) static const int reloc_target_bitmask[] = { #define _BM(x) (~(-(1ULL << (x)))) @@ -208,13 +226,80 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) /* * We use the fact that relocation types are an `enum' - * Note: R_SPARC_6 is currently numerically largest. + * Note: R_SPARC_TLS_TPOFF64 is currently numerically largest. */ - if (type > R_TYPE(6)) + if (type > R_TYPE(TLS_TPOFF64)) return (-1); value = rela->r_addend; + /* + * Handle TLS relocations here, they are different. + */ + if (RELOC_TLS(type)) { + switch (type) { + case R_TYPE(TLS_DTPMOD32): + def = _rtld_find_symdef(symnum, obj, + &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf_Addr)defobj->tlsindex; + + rdbg(("TLS_DTPMOD32 %s in %s --> %p", + obj->strtab + + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + + case R_TYPE(TLS_DTPOFF32): + def = _rtld_find_symdef(symnum, obj, + &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf_Addr)(def->st_value + + rela->r_addend); + + rdbg(("TLS_DTPOFF32 %s in %s --> %p", + obj->strtab + + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + + case R_TYPE(TLS_TPOFF32): + def = _rtld_find_symdef(symnum, obj, + &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && + _rtld_tls_offset_allocate(obj)) + return -1; + + *where = (Elf_Addr)(def->st_value - + defobj->tlsoffset + + rela->r_addend); + + rdbg(("TLS_TPOFF32 %s in %s --> %p", + obj->strtab + + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + } + continue; + } + + /* + * If it is no TLS relocation (handled above), we can not + * deal with it if it is beyound R_SPARC_6. + */ + if (type > R_TYPE(6)) + return (-1); + /* * Handle relative relocs here, as an optimization. */ @@ -325,9 +410,11 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff) value = 0; /* XXX gcc */ + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, rela, &value); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)value; } diff --git a/libexec/ld.elf_so/arch/sparc64/mdreloc.c b/libexec/ld.elf_so/arch/sparc64/mdreloc.c index 0dc7e821d..f36cd02f6 100644 --- a/libexec/ld.elf_so/arch/sparc64/mdreloc.c +++ b/libexec/ld.elf_so/arch/sparc64/mdreloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: mdreloc.c,v 1.50 2010/09/24 12:00:10 skrll Exp $ */ +/* $NetBSD: mdreloc.c,v 1.53 2012/07/22 09:21:03 martin Exp $ */ /*- * Copyright (c) 2000 Eduardo Horvath. @@ -32,7 +32,7 @@ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.50 2010/09/24 12:00:10 skrll Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.53 2012/07/22 09:21:03 martin Exp $"); #endif /* not lint */ #include @@ -67,7 +67,7 @@ __RCSID("$NetBSD: mdreloc.c,v 1.50 2010/09/24 12:00:10 skrll Exp $"); #define _RF_U 0x04000000 /* Unaligned */ #define _RF_SZ(s) (((s) & 0xff) << 8) /* memory target size */ #define _RF_RS(s) ( (s) & 0xff) /* right shift */ -static const int reloc_target_flags[] = { +static const int reloc_target_flags[R_TYPE(TLS_TPOFF64)+1] = { 0, /* NONE */ _RF_S|_RF_A| _RF_SZ(8) | _RF_RS(0), /* RELOC_8 */ _RF_S|_RF_A| _RF_SZ(16) | _RF_RS(0), /* RELOC_16 */ @@ -125,6 +125,7 @@ static const int reloc_target_flags[] = { _RF_S|_RF_A| _RF_SZ(64) | _RF_RS(0), /* REGISTER */ _RF_S|_RF_A| _RF_U| _RF_SZ(64) | _RF_RS(0), /* UA64 */ _RF_S|_RF_A| _RF_U| _RF_SZ(16) | _RF_RS(0), /* UA16 */ +/* TLS relocs not represented here! */ }; #ifdef RTLD_DEBUG_RELOC @@ -139,7 +140,13 @@ static const char *reloc_names[] = { "HM10", "LM22", "PC_HH22", "PC_HM10", "PC_LM22", "WDISP16", "WDISP19", "GLOB_JMP", "7", "5", "6", "DISP64", "PLT64", "HIX22", "LOX10", "H44", "M44", - "L44", "REGISTER", "UA64", "UA16" + "L44", "REGISTER", "UA64", "UA16", + "TLS_GD_HI22", "TLS_GD_LO10", "TLS_GD_ADD", "TLS_GD_CALL", + "TLS_LDM_HI22", "TLS_LDM_LO10", "TLS_LDM_ADD", "TLS_LDM_CALL", + "TLS_LDO_HIX22", "TLS_LDO_LOX10", "TLS_LDO_ADD", "TLS_IE_HI22", + "TLS_IE_LO10", "TLS_IE_LD", "TLS_IE_LDX", "TLS_IE_ADD", "TLS_LE_HIX22", + "TLS_LE_LOX10", "TLS_DTPMOD32", "TLS_DTPMOD64", "TLS_DTPOFF32", + "TLS_DTPOFF64", "TLS_TPOFF32", "TLS_TPOFF64", }; #endif @@ -150,6 +157,7 @@ static const char *reloc_names[] = { #define RELOC_USE_ADDEND(t) ((reloc_target_flags[t] & _RF_A) != 0) #define RELOC_TARGET_SIZE(t) ((reloc_target_flags[t] >> 8) & 0xff) #define RELOC_VALUE_RIGHTSHIFT(t) (reloc_target_flags[t] & 0xff) +#define RELOC_TLS(t) (t >= R_TYPE(TLS_GD_HI22)) static const long reloc_target_bitmask[] = { #define _BM(x) (~(-(1ULL << (x)))) @@ -315,6 +323,10 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) if (type == R_TYPE(NONE)) continue; + /* OLO10 relocations have extra info */ + if ((type & 0x00ff) == R_SPARC_OLO10) + type = R_SPARC_OLO10; + /* We do JMP_SLOTs in _rtld_bind() below */ if (type == R_TYPE(JMP_SLOT)) continue; @@ -325,13 +337,75 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) /* * We use the fact that relocation types are an `enum' - * Note: R_SPARC_UA16 is currently numerically largest. + * Note: R_SPARC_TLS_TPOFF64 is currently numerically largest. */ - if (type > R_TYPE(UA16)) - return (-1); + if (type > R_TYPE(TLS_TPOFF64)) { + dbg(("unknown relocation type %x at %p", type, rela)); + return -1; + } value = rela->r_addend; + /* + * Handle TLS relocations here, they are different. + */ + if (RELOC_TLS(type)) { + switch (type) { + case R_TYPE(TLS_DTPMOD64): + def = _rtld_find_symdef(symnum, obj, + &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf64_Addr)defobj->tlsindex; + + rdbg(("TLS_DTPMOD64 %s in %s --> %p", + obj->strtab + + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + + case R_TYPE(TLS_DTPOFF64): + def = _rtld_find_symdef(symnum, obj, + &defobj, false); + if (def == NULL) + return -1; + + *where = (Elf64_Addr)(def->st_value + + rela->r_addend); + + rdbg(("DTPOFF64 %s in %s --> %p", + obj->strtab + + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + + case R_TYPE(TLS_TPOFF64): + def = _rtld_find_symdef(symnum, obj, + &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && + _rtld_tls_offset_allocate(obj)) + return -1; + + *where = (Elf64_Addr)(def->st_value - + defobj->tlsoffset + + rela->r_addend); + + rdbg(("TLS_TPOFF64 %s in %s --> %p", + obj->strtab + + obj->symtab[symnum].st_name, + obj->path, (void *)*where)); + + break; + } + continue; + } + /* * Handle relative relocs here, as an optimization. */ @@ -354,6 +428,11 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) value += (Elf_Addr)(defobj->relocbase + def->st_value); } + if (type == R_SPARC_OLO10) { + value = (value & 0x3ff) + + (((Elf64_Xword)rela->r_info<<32)>>40); + } + if (RELOC_PC_RELATIVE(type)) { value -= (Elf_Addr)where; } @@ -471,9 +550,11 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff) rela -= 4; } + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, rela, &result); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)result; } diff --git a/libexec/ld.elf_so/arch/vax/mdreloc.c b/libexec/ld.elf_so/arch/vax/mdreloc.c index a7b99e6cd..7b979005e 100644 --- a/libexec/ld.elf_so/arch/vax/mdreloc.c +++ b/libexec/ld.elf_so/arch/vax/mdreloc.c @@ -1,13 +1,13 @@ -/* $NetBSD: mdreloc.c,v 1.27 2010/08/06 16:33:19 joerg Exp $ */ +/* $NetBSD: mdreloc.c,v 1.28 2011/03/25 18:07:07 joerg Exp $ */ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.27 2010/08/06 16:33:19 joerg Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.28 2011/03/25 18:07:07 joerg Exp $"); #endif /* not lint */ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.27 2010/08/06 16:33:19 joerg Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.28 2011/03/25 18:07:07 joerg Exp $"); #endif /* not lint */ #include @@ -187,9 +187,11 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff) result = 0; /* XXX gcc */ + _rtld_shared_enter(); err = _rtld_relocate_plt_object(obj, rela, &result); if (err) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)result; } diff --git a/libexec/ld.elf_so/arch/x86_64/mdreloc.c b/libexec/ld.elf_so/arch/x86_64/mdreloc.c index b0ea28588..9dbe98c2c 100644 --- a/libexec/ld.elf_so/arch/x86_64/mdreloc.c +++ b/libexec/ld.elf_so/arch/x86_64/mdreloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: mdreloc.c,v 1.38 2010/08/06 16:33:19 joerg Exp $ */ +/* $NetBSD: mdreloc.c,v 1.40 2011/03/25 18:07:07 joerg Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -68,7 +68,7 @@ #include #ifndef lint -__RCSID("$NetBSD: mdreloc.c,v 1.38 2010/08/06 16:33:19 joerg Exp $"); +__RCSID("$NetBSD: mdreloc.c,v 1.40 2011/03/25 18:07:07 joerg Exp $"); #endif /* not lint */ #include @@ -161,7 +161,7 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) *where32 = tmp32; rdbg(("32/32S %s in %s --> %p in %s", obj->strtab + obj->symtab[symnum].st_name, - obj->path, (void *)(unsigned long)*where32, + obj->path, (void *)(uintptr_t)*where32, defobj->path)); break; case R_TYPE(64): /* word64 S + A */ @@ -211,6 +211,50 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj) (void *)*where64)); break; + case R_TYPE(TPOFF64): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + if (!defobj->tls_done && + _rtld_tls_offset_allocate(obj)) + return -1; + + *where64 = (Elf64_Addr)(def->st_value - + defobj->tlsoffset + rela->r_addend); + + rdbg(("TPOFF64 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where64)); + + break; + + case R_TYPE(DTPMOD64): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + *where64 = (Elf64_Addr)defobj->tlsindex; + + rdbg(("DTPMOD64 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where64)); + + break; + + case R_TYPE(DTPOFF64): + def = _rtld_find_symdef(symnum, obj, &defobj, false); + if (def == NULL) + return -1; + + *where64 = (Elf64_Addr)(def->st_value + rela->r_addend); + + rdbg(("DTPOFF64 %s in %s --> %p", + obj->strtab + obj->symtab[symnum].st_name, + obj->path, (void *)*where64)); + + break; + case R_TYPE(COPY): rdbg(("COPY")); break; @@ -291,9 +335,11 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff) new_value = 0; /* XXX GCC4 */ + _rtld_shared_enter(); error = _rtld_relocate_plt_object(obj, rela, &new_value); if (error) _rtld_die(); + _rtld_shared_exit(); return (caddr_t)new_value; } diff --git a/libexec/ld.elf_so/arch/x86_64/rtld_start.S b/libexec/ld.elf_so/arch/x86_64/rtld_start.S index d154e9475..038d6f5e9 100644 --- a/libexec/ld.elf_so/arch/x86_64/rtld_start.S +++ b/libexec/ld.elf_so/arch/x86_64/rtld_start.S @@ -1,4 +1,4 @@ -/* $NetBSD: rtld_start.S,v 1.8 2010/12/05 00:56:07 joerg Exp $ */ +/* $NetBSD: rtld_start.S,v 1.9 2011/12/11 22:07:26 joerg Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -47,6 +47,8 @@ movq %rsp,%r12 # stack pointer arg to _rtld pushq %rbx # save ps_strings + andq $~15,%rsp # align rsp, to be restored from r12 + leaq _GLOBAL_OFFSET_TABLE_(%rip),%rax leaq _DYNAMIC(%rip),%rdi # &_DYNAMIC movq %rdi,%rbx @@ -59,6 +61,7 @@ movq %rbx,%rsi call _rtld # _rtld(sp, relocbase) + leaq -8(%r12),%rsp # restore saved rsp, including %rbx popq %rbx # %rbx = ps_strings popq %rdx # %rdx = cleanup popq %rcx # %rcx = obj_main diff --git a/libexec/ld.elf_so/diagassert.c b/libexec/ld.elf_so/diagassert.c new file mode 100644 index 000000000..6ec4beb07 --- /dev/null +++ b/libexec/ld.elf_so/diagassert.c @@ -0,0 +1,9 @@ +#include +#include + +__dead void +/*ARGSUSED*/ +__diagassert13(const char *fn, int fl, const char *fu, const char *m) +{ + abort(); +} diff --git a/libexec/ld.elf_so/expand.c b/libexec/ld.elf_so/expand.c index 88503201d..1a180718a 100644 --- a/libexec/ld.elf_so/expand.c +++ b/libexec/ld.elf_so/expand.c @@ -75,8 +75,10 @@ expand(char *buf, const char *execname, int what, size_t bl) { const char *p, *ep; char *bp = buf; +#if !defined(__minix) size_t len; char name[32]; +#endif /* !defined(__minix) */ switch (what) { case 0: /* HWCAP XXX: Not yet */ diff --git a/libexec/ld.elf_so/headers.c b/libexec/ld.elf_so/headers.c index 0725530c0..d2cefabf7 100644 --- a/libexec/ld.elf_so/headers.c +++ b/libexec/ld.elf_so/headers.c @@ -1,4 +1,4 @@ -/* $NetBSD: headers.c,v 1.39 2011/01/16 01:22:29 matt Exp $ */ +/* $NetBSD: headers.c,v 1.43 2012/08/15 03:46:06 matt Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -40,7 +40,7 @@ #include #ifndef lint -__RCSID("$NetBSD: headers.c,v 1.39 2011/01/16 01:22:29 matt Exp $"); +__RCSID("$NetBSD: headers.c,v 1.43 2012/08/15 03:46:06 matt Exp $"); #endif /* not lint */ #include @@ -136,6 +136,29 @@ _rtld_digest_dynamic(const char *execname, Obj_Entry *obj) obj->strsize = dynp->d_un.d_val; break; + case DT_VERNEED: + obj->verneed = (const Elf_Verneed *) + (obj->relocbase + dynp->d_un.d_ptr); + break; + + case DT_VERNEEDNUM: + obj->verneednum = dynp->d_un.d_val; + break; + + case DT_VERDEF: + obj->verdef = (const Elf_Verdef *) + (obj->relocbase + dynp->d_un.d_ptr); + break; + + case DT_VERDEFNUM: + obj->verdefnum = dynp->d_un.d_val; + break; + + case DT_VERSYM: + obj->versyms = (const Elf_Versym *) + (obj->relocbase + dynp->d_un.d_ptr); + break; + case DT_HASH: { const Elf_Symindx *hashtab = (const Elf_Symindx *) @@ -204,10 +227,32 @@ _rtld_digest_dynamic(const char *execname, Obj_Entry *obj) init = dynp->d_un.d_ptr; break; +#ifdef HAVE_INITFINI_ARRAY + case DT_INIT_ARRAY: + obj->init_array = + (fptr_t *)(obj->relocbase + dynp->d_un.d_ptr); + break; + + case DT_INIT_ARRAYSZ: + obj->init_arraysz = dynp->d_un.d_val / sizeof(fptr_t); + break; +#endif + case DT_FINI: fini = dynp->d_un.d_ptr; break; +#ifdef HAVE_INITFINI_ARRAY + case DT_FINI_ARRAY: + obj->fini_array = + (fptr_t *)(obj->relocbase + dynp->d_un.d_ptr); + break; + + case DT_FINI_ARRAYSZ: + obj->fini_arraysz = dynp->d_un.d_val / sizeof(fptr_t); + break; +#endif + /* * Don't process DT_DEBUG on MIPS as the dynamic section * is mapped read-only. DT_MIPS_RLD_MAP is used instead. @@ -333,7 +378,6 @@ _rtld_digest_phdr(const Elf_Phdr *phdr, int phnum, caddr_t entry) obj->phsize, (long)obj->relocbase)); break; } - assert(obj->phdr == phdr); for (ph = phdr; ph < phlimit; ++ph) { vaddr = (Elf_Addr)(uintptr_t)(obj->relocbase + ph->p_vaddr); @@ -360,6 +404,16 @@ _rtld_digest_phdr(const Elf_Phdr *phdr, int phnum, caddr_t entry) case PT_DYNAMIC: obj->dynamic = (Elf_Dyn *)(uintptr_t)vaddr; break; + +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + case PT_TLS: + obj->tlsindex = 1; + obj->tlssize = ph->p_memsz; + obj->tlsalign = ph->p_align; + obj->tlsinitsize = ph->p_filesz; + obj->tlsinit = (void *)(uintptr_t)ph->p_vaddr; + break; +#endif } } assert(nsegs == 2); diff --git a/libexec/ld.elf_so/load.c b/libexec/ld.elf_so/load.c index 493c29553..4ddf854f3 100644 --- a/libexec/ld.elf_so/load.c +++ b/libexec/ld.elf_so/load.c @@ -202,22 +202,24 @@ static bool _rtld_load_by_name(const char *name, Obj_Entry *obj, Needed_Entry **needed, int flags) { +#if !defined(__minix) Library_Xform *x = _rtld_xforms; Obj_Entry *o = NULL; size_t j; ssize_t i; +#endif /* !defined(__minix) */ bool got = false; +#if !defined(__minix) union { int i; u_quad_t q; char s[16]; } val; +#endif /* !defined(__minix) */ +#if !defined(__minix) dbg(("load by name %s %p", name, x)); for (; x; x = x->next) { -#ifdef __minix - continue; -#else if (strcmp(x->name, name) != 0) continue; @@ -281,8 +283,8 @@ _rtld_load_by_name(const char *name, Obj_Entry *obj, Needed_Entry **needed, } -#endif } +#endif /* !defined(__minix) */ if (got) return true; diff --git a/libexec/ld.elf_so/map_object.c b/libexec/ld.elf_so/map_object.c index 409cf51c9..027deeca3 100644 --- a/libexec/ld.elf_so/map_object.c +++ b/libexec/ld.elf_so/map_object.c @@ -1,4 +1,4 @@ -/* $NetBSD: map_object.c,v 1.41 2010/10/16 10:27:07 skrll Exp $ */ +/* $NetBSD: map_object.c,v 1.45 2012/10/13 21:13:07 dholland Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -34,11 +34,10 @@ #include #ifndef lint -__RCSID("$NetBSD: map_object.c,v 1.41 2010/10/16 10:27:07 skrll Exp $"); +__RCSID("$NetBSD: map_object.c,v 1.45 2012/10/13 21:13:07 dholland Exp $"); #endif /* not lint */ #include -#include #include #include #include @@ -56,6 +55,10 @@ __RCSID("$NetBSD: map_object.c,v 1.41 2010/10/16 10:27:07 skrll Exp $"); #define MINIXVERBOSE 0 +#if MINIXVERBOSE +#include +#endif + static int protflags(int); /* Elf flags -> mmap protection */ #define EA_UNDEF (~(Elf_Addr)0) @@ -86,13 +89,15 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb) Obj_Entry *obj; Elf_Ehdr *ehdr; Elf_Phdr *phdr; +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + Elf_Phdr *phtls; +#endif size_t phsize; Elf_Phdr *phlimit; Elf_Phdr *segs[2]; int nsegs; caddr_t mapbase = MAP_FAILED; size_t mapsize = 0; - size_t bsssize = 0; int mapflags; Elf_Off base_offset; #ifdef MAP_ALIGNED @@ -108,10 +113,15 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb) Elf_Addr data_vlimit; int data_flags; caddr_t data_addr; +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + Elf_Addr tls_vaddr = 0; /* Noise GCC */ +#endif Elf_Addr phdr_vaddr; size_t phdr_memsz; +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) caddr_t gap_addr; size_t gap_size; +#endif int i; #ifdef RTLD_LOADER Elf_Addr clear_vaddr; @@ -120,7 +130,7 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb) #endif if (sb != NULL && sb->st_size < (off_t)sizeof (Elf_Ehdr)) { - _rtld_error("%s: unrecognized file format1", path); + _rtld_error("%s: not ELF file (too short)", path); return NULL; } @@ -149,9 +159,12 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb) goto bad; } /* Make sure the file is valid */ - if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0 || - ehdr->e_ident[EI_CLASS] != ELFCLASS) { - _rtld_error("%s: unrecognized file format2 [%x != %x]", path, + if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0) { + _rtld_error("%s: not ELF file (magic number bad)", path); + goto bad; + } + if (ehdr->e_ident[EI_CLASS] != ELFCLASS) { + _rtld_error("%s: invalid ELF class %x; expected %x", path, ehdr->e_ident[EI_CLASS], ELFCLASS); goto bad; } @@ -189,6 +202,9 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb) * in that order. */ phdr = (Elf_Phdr *) ((caddr_t)ehdr + ehdr->e_phoff); +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + phtls = NULL; +#endif phsize = ehdr->e_phnum * sizeof(phdr[0]); obj->phdr = NULL; phdr_vaddr = EA_UNDEF; @@ -206,20 +222,36 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb) if (nsegs < 2) segs[nsegs] = phdr; ++nsegs; - dbg(("%s: PT_LOAD %p", obj->path, phdr)); + +#if ELFSIZE == 64 +#define PRImemsz PRIu64 +#else +#define PRImemsz PRIu32 +#endif + dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_LOAD", + (void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz)); break; case PT_PHDR: phdr_vaddr = phdr->p_vaddr; phdr_memsz = phdr->p_memsz; - dbg(("%s: PT_PHDR %p phsize %zu", obj->path, - (void *)(uintptr_t)phdr_vaddr, phdr_memsz)); + dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_PHDR", + (void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz)); break; case PT_DYNAMIC: obj->dynamic = (void *)(uintptr_t)phdr->p_vaddr; - dbg(("%s: PT_DYNAMIC %p", obj->path, obj->dynamic)); + dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_DYNAMIC", + (void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz)); + break; + +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + case PT_TLS: + phtls = phdr; + dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_TLS", + (void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz)); break; +#endif } ++phdr; @@ -268,6 +300,17 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb) obj->vaddrbase = base_vaddr; obj->isdynamic = ehdr->e_type == ET_DYN; +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + if (phtls != NULL) { + ++_rtld_tls_dtv_generation; + obj->tlsindex = ++_rtld_tls_max_index; + obj->tlssize = phtls->p_memsz; + obj->tlsalign = phtls->p_align; + obj->tlsinitsize = phtls->p_filesz; + tls_vaddr = phtls->p_vaddr; + } +#endif + obj->phdr_loaded = false; for (i = 0; i < nsegs; i++) { if (phdr_vaddr != EA_UNDEF && @@ -355,25 +398,18 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb) _rtld_error("mmap of data failed: %s", xstrerror(errno)); goto bad; } -#endif -#ifndef __minix - bsssize= base_vlimit - data_vlimit; - if(bsssize > 0) { /* Overlay the bss segment onto the proper region. */ - if (mmap(mapbase + data_vlimit - base_vaddr, bsssize, + if (mmap(mapbase + data_vlimit - base_vaddr, base_vlimit - data_vlimit, data_flags, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) == MAP_FAILED) { - _rtld_error("mmap of bss (at 0x%lx, 0x%lx bytes) failed: %s", - mapbase + data_vlimit - base_vaddr, bsssize, xstrerror(errno)); + _rtld_error("mmap of bss failed: %s", xstrerror(errno)); goto bad; } - } /* Unmap the gap between the text and data. */ gap_addr = mapbase + round_up(text_vlimit - base_vaddr); gap_size = data_addr - gap_addr; - if (gap_size != 0 && mprotect(gap_addr, gap_size, PROT_NONE) == -1) { _rtld_error("mprotect of text -> data gap failed: %s", xstrerror(errno)); @@ -390,6 +426,11 @@ _rtld_map_object(const char *path, int fd, const struct stat *sb) /* Non-file portion of BSS mapped above. */ #endif +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + if (phtls != NULL) + obj->tlsinit = mapbase + tls_vaddr; +#endif + obj->mapbase = mapbase; obj->mapsize = mapsize; obj->relocbase = mapbase - base_vaddr; @@ -419,6 +460,10 @@ _rtld_obj_free(Obj_Entry *obj) { Objlist_Entry *elm; +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + if (obj->tls_done) + _rtld_tls_offset_free(obj); +#endif xfree(obj->path); while (obj->needed != NULL) { Needed_Entry *needed = obj->needed; diff --git a/libexec/ld.elf_so/paths.c b/libexec/ld.elf_so/paths.c index 70865da2e..799e2983f 100644 --- a/libexec/ld.elf_so/paths.c +++ b/libexec/ld.elf_so/paths.c @@ -61,13 +61,17 @@ __RCSID("$NetBSD: paths.c,v 1.40 2009/05/19 20:44:52 christos Exp $"); static Search_Path *_rtld_find_path(Search_Path *, const char *, size_t); static Search_Path **_rtld_append_path(Search_Path **, Search_Path **, const char *, const char *, const char *); +#if !defined(__minix) static void _rtld_process_mapping(Library_Xform **, const char *, const char *); +#endif /* !defined(__minix) */ static char *exstrdup(const char *, const char *); +#if !defined(__minix) static const char *getstr(const char **, const char *, const char *); static const char *getcstr(const char **, const char *, const char *); static const char *getword(const char **, const char *, const char *); static int matchstr(const char *, const char *, const char *); +#endif /* !defined(__minix) */ static const char WS[] = " \t\n"; @@ -86,6 +90,7 @@ exstrdup(const char *bp, const char *ep) return (cp); } +#if !defined(__minix) /* * Like strsep(), but takes end of string and doesn't put any NUL. To * detect empty string, compare `*p' and return value. @@ -158,6 +163,7 @@ matchstr(const char *p, const char *bp, const char *ep) return (*p == 0); } +#endif /* !defined(__minix) */ static Search_Path * _rtld_find_path(Search_Path *path, const char *pathstr, size_t pathlen) @@ -228,6 +234,7 @@ _rtld_add_paths(const char *execname, Search_Path **path_p, const char *pathstr) } } +#if !defined(__minix) /* * Process library mappings of the form: * ... @@ -333,6 +340,7 @@ cleanup: xfree(hwptr->name); xfree(hwptr); } +#endif /* !defined(__minix) */ void _rtld_process_hints(const char *execname, Search_Path **path_p, @@ -349,6 +357,7 @@ _rtld_process_hints(const char *execname, Search_Path **path_p, struct stat st; ssize_t sz; Search_Path **head_p = path_p; + if ((fd = open(fname, O_RDONLY)) == -1) { /* Don't complain */ return; diff --git a/libexec/ld.elf_so/reloc.c b/libexec/ld.elf_so/reloc.c index 14c180948..db8955de8 100644 --- a/libexec/ld.elf_so/reloc.c +++ b/libexec/ld.elf_so/reloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: reloc.c,v 1.103 2010/12/24 12:41:43 skrll Exp $ */ +/* $NetBSD: reloc.c,v 1.106 2012/01/06 10:38:56 skrll Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -39,7 +39,7 @@ #include #ifndef lint -__RCSID("$NetBSD: reloc.c,v 1.103 2010/12/24 12:41:43 skrll Exp $"); +__RCSID("$NetBSD: reloc.c,v 1.106 2012/01/06 10:38:56 skrll Exp $"); #endif /* not lint */ #include @@ -73,9 +73,12 @@ _rtld_do_copy_relocation(const Obj_Entry *dstobj, const Elf_Rela *rela) const Elf_Sym *srcsym = NULL; Obj_Entry *srcobj; - for (srcobj = dstobj->next; srcobj != NULL; srcobj = srcobj->next) - if ((srcsym = _rtld_symlook_obj(name, hash, srcobj, false)) != NULL) + for (srcobj = dstobj->next; srcobj != NULL; srcobj = srcobj->next) { + srcsym = _rtld_symlook_obj(name, hash, srcobj, 0, + _rtld_fetch_ventry(dstobj, ELF_R_SYM(rela->r_info))); + if (srcsym != NULL) break; + } if (srcobj == NULL) { _rtld_error("Undefined symbol \"%s\" referenced from COPY" @@ -199,9 +202,6 @@ _rtld_relocate_objects(Obj_Entry *first, bool bind_now) dbg(("doing lazy PLT binding")); if (_rtld_relocate_plt_lazy(obj) < 0) ok = 0; -#if defined(__hppa__) - bind_now = 1; -#endif if (obj->z_now || bind_now) { dbg(("doing immediate PLT binding")); if (_rtld_relocate_plt_objects(obj) < 0) @@ -214,7 +214,11 @@ _rtld_relocate_objects(Obj_Entry *first, bool bind_now) obj->magic = RTLD_MAGIC; obj->version = RTLD_VERSION; - /* Fill in the dynamic linker entry points. */ + /* + * Fill in the backwards compatibility dynamic linker entry points. + * + * DO NOT ADD TO THIS LIST + */ obj->dlopen = dlopen; obj->dlsym = dlsym; obj->dlerror = dlerror; diff --git a/libexec/ld.elf_so/rtld.c b/libexec/ld.elf_so/rtld.c index b1a5462fb..1cd8cccb6 100644 --- a/libexec/ld.elf_so/rtld.c +++ b/libexec/ld.elf_so/rtld.c @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.c,v 1.137 2010/12/24 12:41:43 skrll Exp $ */ +/* $NetBSD: rtld.c,v 1.159 2012/10/01 03:03:46 riastradh Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -44,19 +44,23 @@ #include #ifndef lint -__RCSID("$NetBSD: rtld.c,v 1.137 2010/12/24 12:41:43 skrll Exp $"); +__RCSID("$NetBSD: rtld.c,v 1.159 2012/10/01 03:03:46 riastradh Exp $"); #endif /* not lint */ +#include +#include +#include #include #include #include +#if !defined(__minix) +#include +#endif /* !defined(__minix) */ #include #include #include #include #include -#include -#include #include #include @@ -91,6 +95,7 @@ Obj_Entry *_rtld_objmain; /* The main program shared object */ Obj_Entry _rtld_objself; /* The dynamic linker shared object */ u_int _rtld_objcount; /* Number of objects in _rtld_objlist */ u_int _rtld_objloads; /* Number of objects loaded in _rtld_objlist */ +u_int _rtld_objgen; /* Generation count for _rtld_objlist */ const char _rtld_path[] = _PATH_RTLD; /* Initialize a fake symbol for resolving undefined weak references. */ @@ -104,6 +109,7 @@ Search_Path *_rtld_default_paths; Search_Path *_rtld_paths; Library_Xform *_rtld_xforms; +static void *auxinfo; /* * Global declarations normally provided by crt0. @@ -111,6 +117,10 @@ Library_Xform *_rtld_xforms; char *__progname; char **environ; +#if !defined(__minix) +static volatile bool _rtld_mutex_may_recurse; +#endif /* !defined(__minix) */ + #if defined(RTLD_DEBUG) #ifndef __sh__ extern Elf_Addr _GLOBAL_OFFSET_TABLE_[]; @@ -120,8 +130,8 @@ register Elf_Addr *_GLOBAL_OFFSET_TABLE_ asm("r12"); #endif /* RTLD_DEBUG */ extern Elf_Dyn _DYNAMIC; -static void _rtld_call_fini_functions(int); -static void _rtld_call_init_functions(void); +static void _rtld_call_fini_functions(sigset_t *, int); +static void _rtld_call_init_functions(sigset_t *); static void _rtld_initlist_visit(Objlist *, Obj_Entry *, int); static void _rtld_initlist_tsort(Objlist *, int); static Obj_Entry *_rtld_dlcheck(void *); @@ -129,88 +139,169 @@ static void _rtld_init_dag(Obj_Entry *); static void _rtld_init_dag1(Obj_Entry *, Obj_Entry *); static void _rtld_objlist_remove(Objlist *, Obj_Entry *); static void _rtld_objlist_clear(Objlist *); -static void _rtld_unload_object(Obj_Entry *, bool); +static void _rtld_unload_object(sigset_t *, Obj_Entry *, bool); static void _rtld_unref_dag(Obj_Entry *); static Obj_Entry *_rtld_obj_from_addr(const void *); +static inline void +_rtld_call_initfini_function(fptr_t func, sigset_t *mask) +{ + _rtld_exclusive_exit(mask); + (*func)(); + _rtld_exclusive_enter(mask); +} + +static void +_rtld_call_fini_function(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen) +{ + if (obj->fini_arraysz == 0 && (obj->fini == NULL || obj->fini_called)) { + return; + } + if (obj->fini != NULL && !obj->fini_called) { + dbg (("calling fini function %s at %p%s", obj->path, + (void *)obj->fini, + obj->z_initfirst ? " (DF_1_INITFIRST)" : "")); + obj->fini_called = 1; + _rtld_call_initfini_function(obj->fini, mask); + } +#ifdef HAVE_INITFINI_ARRAY + /* + * Now process the fini_array if it exists. Simply go from + * start to end. We need to make restartable so just advance + * the array pointer and decrement the size each time through + * the loop. + */ + while (obj->fini_arraysz > 0 && _rtld_objgen == cur_objgen) { + fptr_t fini = *obj->fini_array++; + obj->fini_arraysz--; + dbg (("calling fini array function %s at %p%s", obj->path, + (void *)fini, + obj->z_initfirst ? " (DF_1_INITFIRST)" : "")); + _rtld_call_initfini_function(fini, mask); + } +#endif /* HAVE_INITFINI_ARRAY */ +} + static void -_rtld_call_fini_functions(int force) +_rtld_call_fini_functions(sigset_t *mask, int force) { Objlist_Entry *elm; Objlist finilist; - Obj_Entry *obj; + u_int cur_objgen; dbg(("_rtld_call_fini_functions(%d)", force)); +restart: + cur_objgen = ++_rtld_objgen; SIMPLEQ_INIT(&finilist); _rtld_initlist_tsort(&finilist, 1); /* First pass: objects _not_ marked with DF_1_INITFIRST. */ SIMPLEQ_FOREACH(elm, &finilist, link) { - obj = elm->obj; - if (obj->refcount > 0 && !force) { - continue; + Obj_Entry * const obj = elm->obj; + if (!obj->z_initfirst) { + if (obj->refcount > 0 && !force) { + continue; + } + /* + * XXX This can race against a concurrent dlclose(). + * XXX In that case, the object could be unmapped before + * XXX the fini() call or the fini_array has completed. + */ + _rtld_call_fini_function(obj, mask, cur_objgen); + if (_rtld_objgen != cur_objgen) { + dbg(("restarting fini iteration")); + _rtld_objlist_clear(&finilist); + goto restart; } - if (obj->fini == NULL || obj->fini_called || obj->z_initfirst) { - continue; } - dbg (("calling fini function %s at %p", obj->path, - (void *)obj->fini)); - obj->fini_called = 1; - (*obj->fini)(); } /* Second pass: objects marked with DF_1_INITFIRST. */ SIMPLEQ_FOREACH(elm, &finilist, link) { - obj = elm->obj; + Obj_Entry * const obj = elm->obj; if (obj->refcount > 0 && !force) { continue; } - if (obj->fini == NULL || obj->fini_called) { - continue; + /* XXX See above for the race condition here */ + _rtld_call_fini_function(obj, mask, cur_objgen); + if (_rtld_objgen != cur_objgen) { + dbg(("restarting fini iteration")); + _rtld_objlist_clear(&finilist); + goto restart; } - dbg (("calling fini function %s at %p (DF_1_INITFIRST)", - obj->path, (void *)obj->fini)); - obj->fini_called = 1; - (*obj->fini)(); } _rtld_objlist_clear(&finilist); } static void -_rtld_call_init_functions() +_rtld_call_init_function(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen) +{ + if (obj->init_arraysz == 0 && (obj->init_called || obj->init == NULL)) { + return; + } + if (!obj->init_called && obj->init != NULL) { + dbg (("calling init function %s at %p%s", + obj->path, (void *)obj->init, + obj->z_initfirst ? " (DF_1_INITFIRST)" : "")); + obj->init_called = 1; + _rtld_call_initfini_function(obj->init, mask); + } + +#ifdef HAVE_INITFINI_ARRAY + /* + * Now process the init_array if it exists. Simply go from + * start to end. We need to make restartable so just advance + * the array pointer and decrement the size each time through + * the loop. + */ + while (obj->init_arraysz > 0 && _rtld_objgen == cur_objgen) { + fptr_t init = *obj->init_array++; + obj->init_arraysz--; + dbg (("calling init_array function %s at %p%s", + obj->path, (void *)init, + obj->z_initfirst ? " (DF_1_INITFIRST)" : "")); + _rtld_call_initfini_function(init, mask); + } +#endif /* HAVE_INITFINI_ARRAY */ +} + +static void +_rtld_call_init_functions(sigset_t *mask) { Objlist_Entry *elm; Objlist initlist; - Obj_Entry *obj; + u_int cur_objgen; dbg(("_rtld_call_init_functions()")); + +restart: + cur_objgen = ++_rtld_objgen; SIMPLEQ_INIT(&initlist); _rtld_initlist_tsort(&initlist, 0); /* First pass: objects marked with DF_1_INITFIRST. */ SIMPLEQ_FOREACH(elm, &initlist, link) { - obj = elm->obj; - if (obj->init == NULL || obj->init_called || !obj->z_initfirst) { - continue; + Obj_Entry * const obj = elm->obj; + if (obj->z_initfirst) { + _rtld_call_init_function(obj, mask, cur_objgen); + if (_rtld_objgen != cur_objgen) { + dbg(("restarting init iteration")); + _rtld_objlist_clear(&initlist); + goto restart; + } } - dbg (("calling init function %s at %p (DF_1_INITFIRST)", - obj->path, (void *)obj->init)); - obj->init_called = 1; - (*obj->init)(); } /* Second pass: all other objects. */ SIMPLEQ_FOREACH(elm, &initlist, link) { - obj = elm->obj; - if (obj->init == NULL || obj->init_called) { - continue; + _rtld_call_init_function(elm->obj, mask, cur_objgen); + if (_rtld_objgen != cur_objgen) { + dbg(("restarting init iteration")); + _rtld_objlist_clear(&initlist); + goto restart; } - dbg (("calling init function %s at %p", obj->path, - (void *)obj->init)); - obj->init_called = 1; - (*obj->init)(); } _rtld_objlist_clear(&initlist); @@ -290,9 +381,21 @@ _rtld_init(caddr_t mapbase, caddr_t relocbase, const char *execname) static void _rtld_exit(void) { + sigset_t mask; + dbg(("rtld_exit()")); - _rtld_call_fini_functions(1); + _rtld_exclusive_enter(&mask); + + _rtld_call_fini_functions(&mask, 1); + + _rtld_exclusive_exit(&mask); +} + +__dso_public void * +_dlauxinfo(void) +{ + return auxinfo; } /* @@ -317,8 +420,8 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase) *pAUX_ruid, *pAUX_rgid; const AuxInfo *pAUX_pagesz; char **env, **oenvp; - const AuxInfo *aux; const AuxInfo *auxp; + Obj_Entry *obj; Elf_Addr *const osp = sp; bool bind_now = 0; const char *ld_bind_now, *ld_preload, *ld_library_path; @@ -328,10 +431,13 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase) const char **real___progname; const Obj_Entry **real___mainprog_obj; char ***real_environ; + sigset_t mask; #ifdef DEBUG - int i = 0; const char *ld_debug; #endif +#ifdef RTLD_DEBUG + int i = 0; +#endif /* * On entry, the dynamic linker itself has not been relocated yet. @@ -345,8 +451,10 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase) debug = 1; dbg(("sp = %p, argc = %ld, argv = %p <%s> relocbase %p", sp, (long)sp[2], &sp[3], (char *) sp[3], (void *)relocbase)); +#if 0 dbg(("got is at %p, dynamic is at %p", _GLOBAL_OFFSET_TABLE_, &_DYNAMIC)); +#endif dbg(("_ctype_ is %p", _ctype_)); #endif @@ -361,7 +469,7 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase) dbg(("env[%d] = %p %s", i++, (void *)sp[-1], (char *)sp[-1])); #endif } - aux = (const AuxInfo *) sp; + auxinfo = (AuxInfo *) sp; pAUX_base = pAUX_entry = pAUX_execfd = NULL; pAUX_phdr = pAUX_phent = pAUX_phnum = NULL; @@ -371,7 +479,7 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase) execname = NULL; /* Digest the auxiliary vector. */ - for (auxp = aux; auxp->a_type != AT_NULL; ++auxp) { + for (auxp = auxinfo; auxp->a_type != AT_NULL; ++auxp) { switch (auxp->a_type) { case AT_BASE: pAUX_base = auxp; @@ -575,6 +683,21 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase) if (_rtld_load_needed_objects(_rtld_objmain, _RTLD_MAIN) == -1) _rtld_die(); + dbg(("checking for required versions")); + for (obj = _rtld_objlist; obj != NULL; obj = obj->next) { + if (_rtld_verify_object_versions(obj) == -1) + _rtld_die(); + } + +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + dbg(("initializing initial Thread Local Storage offsets")); + /* + * All initial objects get the TLS space from the static block. + */ + for (obj = _rtld_objlist; obj != NULL; obj = obj->next) + _rtld_tls_offset_allocate(obj); +#endif + dbg(("relocating objects")); if (_rtld_relocate_objects(_rtld_objmain, bind_now) == -1) _rtld_die(); @@ -583,6 +706,16 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase) if (_rtld_do_copy_relocations(_rtld_objmain) == -1) _rtld_die(); +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + dbg(("initializing Thread Local Storage for main thread")); + /* + * Set up TLS area for the main thread. + * This has to be done after all relocations are processed, + * since .tdata may contain relocations. + */ + _rtld_tls_initial_allocation(); +#endif + /* * Set the __progname, environ and, __mainprog_obj before * calling anything that might use them. @@ -608,12 +741,16 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase) if (real___mainprog_obj) *real___mainprog_obj = _rtld_objmain; + _rtld_exclusive_enter(&mask); + dbg(("calling _init functions")); - _rtld_call_init_functions(); + _rtld_call_init_functions(&mask); dbg(("control at program entry point = %p, obj = %p, exit = %p", _rtld_objmain->entry, _rtld_objmain, _rtld_exit)); + _rtld_exclusive_exit(&mask); + /* * Return with the entry point and the exit procedure in at the top * of stack. @@ -646,7 +783,7 @@ _rtld_dlcheck(void *handle) break; if (obj == NULL || obj->dl_refcount == 0) { - xwarnx("Invalid shared object handle %p", handle); + _rtld_error("Invalid shared object handle %p", handle); return NULL; } return obj; @@ -721,7 +858,7 @@ _rtld_init_dag1(Obj_Entry *root, Obj_Entry *obj) * Note, this is called only for objects loaded by dlopen(). */ static void -_rtld_unload_object(Obj_Entry *root, bool do_fini_funcs) +_rtld_unload_object(sigset_t *mask, Obj_Entry *root, bool do_fini_funcs) { _rtld_unref_dag(root); @@ -732,7 +869,7 @@ _rtld_unload_object(Obj_Entry *root, bool do_fini_funcs) /* Finalize objects that are about to be unmapped. */ if (do_fini_funcs) - _rtld_call_fini_functions(0); + _rtld_call_fini_functions(mask, 0); /* Remove the DAG from all objects' DAG lists. */ SIMPLEQ_FOREACH(elm, &root->dagmembers, link) @@ -808,20 +945,31 @@ __strong_alias(__dlclose,dlclose) int dlclose(void *handle) { - Obj_Entry *root = _rtld_dlcheck(handle); + Obj_Entry *root; + sigset_t mask; + + dbg(("dlclose of %p", handle)); + + _rtld_exclusive_enter(&mask); - if (root == NULL) + root = _rtld_dlcheck(handle); + + if (root == NULL) { + _rtld_exclusive_exit(&mask); return -1; + } _rtld_debug.r_state = RT_DELETE; _rtld_debug_state(); --root->dl_refcount; - _rtld_unload_object(root, true); + _rtld_unload_object(&mask, root, true); _rtld_debug.r_state = RT_CONSISTENT; _rtld_debug_state(); + _rtld_exclusive_exit(&mask); + return 0; } @@ -844,6 +992,12 @@ dlopen(const char *name, int mode) int flags = _RTLD_DLOPEN; bool nodelete; bool now; + sigset_t mask; + int result; + + dbg(("dlopen of %s %d", name, mode)); + + _rtld_exclusive_enter(&mask); flags |= (mode & RTLD_GLOBAL) ? _RTLD_GLOBAL : 0; flags |= (mode & RTLD_NOLOAD) ? _RTLD_NOLOAD : 0; @@ -866,15 +1020,23 @@ dlopen(const char *name, int mode) if (*old_obj_tail != NULL) { /* We loaded something new. */ assert(*old_obj_tail == obj); - if (_rtld_load_needed_objects(obj, flags) == -1 || - (_rtld_init_dag(obj), - _rtld_relocate_objects(obj, - (now || obj->z_now))) == -1) { - _rtld_unload_object(obj, false); + result = _rtld_load_needed_objects(obj, flags); + if (result != -1) { + Objlist_Entry *entry; + _rtld_init_dag(obj); + SIMPLEQ_FOREACH(entry, &obj->dagmembers, link) { + result = _rtld_verify_object_versions(entry->obj); + if (result == -1) + break; + } + } + if (result == -1 || _rtld_relocate_objects(obj, + (now || obj->z_now)) == -1) { + _rtld_unload_object(&mask, obj, false); obj->dl_refcount--; obj = NULL; } else { - _rtld_call_init_functions(); + _rtld_call_init_functions(&mask); } } if (obj != NULL) { @@ -888,6 +1050,8 @@ dlopen(const char *name, int mode) _rtld_debug.r_state = RT_CONSISTENT; _rtld_debug_state(); + _rtld_exclusive_exit(&mask); + return obj; } @@ -906,8 +1070,8 @@ _rtld_objmain_sym(const char *name) obj = _rtld_objmain; _rtld_donelist_init(&donelist); - def = _rtld_symlook_list(name, hash, &_rtld_list_main, &obj, false, - &donelist); + def = _rtld_symlook_list(name, hash, &_rtld_list_main, &obj, 0, + NULL, &donelist); if (def != NULL) return obj->relocbase + def->st_value; @@ -922,17 +1086,29 @@ hackish_return_address(void) } #endif -__strong_alias(__dlsym,dlsym) -void * -dlsym(void *handle, const char *name) +#ifdef __HAVE_FUNCTION_DESCRIPTORS +#define lookup_mutex_enter() _rtld_exclusive_enter(&mask) +#define lookup_mutex_exit() _rtld_exclusive_exit(&mask) +#else +#define lookup_mutex_enter() _rtld_shared_enter() +#define lookup_mutex_exit() _rtld_shared_exit() +#endif + +static void * +do_dlsym(void *handle, const char *name, const Ver_Entry *ventry, void *retaddr) { const Obj_Entry *obj; unsigned long hash; const Elf_Sym *def; const Obj_Entry *defobj; - void *retaddr; - DoneList donelist; - + DoneList donelist; + const u_int flags = SYMLOOK_DLSYM | SYMLOOK_IN_PLT; +#ifdef __HAVE_FUNCTION_DESCRIPTORS + sigset_t mask; +#endif + + lookup_mutex_enter(); + hash = _rtld_elf_hash(name); def = NULL; defobj = NULL; @@ -942,19 +1118,15 @@ dlsym(void *handle, const char *name) case (intptr_t)RTLD_NEXT: case (intptr_t)RTLD_DEFAULT: case (intptr_t)RTLD_SELF: -#ifdef __powerpc__ - retaddr = hackish_return_address(); -#else - retaddr = __builtin_return_address(0); -#endif if ((obj = _rtld_obj_from_addr(retaddr)) == NULL) { _rtld_error("Cannot determine caller's shared object"); + lookup_mutex_exit(); return NULL; } switch ((intptr_t)handle) { case (intptr_t)NULL: /* Just the caller's shared object. */ - def = _rtld_symlook_obj(name, hash, obj, false); + def = _rtld_symlook_obj(name, hash, obj, flags, ventry); defobj = obj; break; @@ -965,7 +1137,7 @@ dlsym(void *handle, const char *name) case (intptr_t)RTLD_SELF: /* Caller included */ for (; obj; obj = obj->next) { if ((def = _rtld_symlook_obj(name, hash, obj, - false)) != NULL) { + flags, ventry)) != NULL) { defobj = obj; break; } @@ -974,7 +1146,7 @@ dlsym(void *handle, const char *name) case (intptr_t)RTLD_DEFAULT: def = _rtld_symlook_default(name, hash, obj, &defobj, - false); + flags, ventry); break; default: @@ -983,15 +1155,17 @@ dlsym(void *handle, const char *name) break; default: - if ((obj = _rtld_dlcheck(handle)) == NULL) + if ((obj = _rtld_dlcheck(handle)) == NULL) { + lookup_mutex_exit(); return NULL; - + } + _rtld_donelist_init(&donelist); if (obj->mainprog) { /* Search main program and all libraries loaded by it */ def = _rtld_symlook_list(name, hash, &_rtld_list_main, - &defobj, false, &donelist); + &defobj, flags, ventry, &donelist); } else { Needed_Entry fake; DoneList depth; @@ -1003,25 +1177,73 @@ dlsym(void *handle, const char *name) _rtld_donelist_init(&depth); def = _rtld_symlook_needed(name, hash, &fake, &defobj, - false, &donelist, &depth); + flags, ventry, &donelist, &depth); } break; } if (def != NULL) { + void *p; #ifdef __HAVE_FUNCTION_DESCRIPTORS - if (ELF_ST_TYPE(def->st_info) == STT_FUNC) - return (void *)_rtld_function_descriptor_alloc(defobj, + if (ELF_ST_TYPE(def->st_info) == STT_FUNC) { + p = (void *)_rtld_function_descriptor_alloc(defobj, def, 0); + lookup_mutex_exit(); + return p; + } #endif /* __HAVE_FUNCTION_DESCRIPTORS */ - return defobj->relocbase + def->st_value; + p = defobj->relocbase + def->st_value; + lookup_mutex_exit(); + return p; } _rtld_error("Undefined symbol \"%s\"", name); + lookup_mutex_exit(); return NULL; } +__strong_alias(__dlsym,dlsym) +void * +dlsym(void *handle, const char *name) +{ + void *retaddr; + + dbg(("dlsym of %s in %p", name, handle)); + +#ifdef __powerpc__ + retaddr = hackish_return_address(); +#else + retaddr = __builtin_return_address(0); +#endif + return do_dlsym(handle, name, NULL, retaddr); +} + +__strong_alias(__dlvsym,dlvsym) +void * +dlvsym(void *handle, const char *name, const char *version) +{ + Ver_Entry *ventry = NULL; + Ver_Entry ver_entry; + void *retaddr; + + dbg(("dlvsym of %s@%s in %p", name, version ? version : NULL, handle)); + + if (version != NULL) { + ver_entry.name = version; + ver_entry.file = NULL; + ver_entry.hash = _rtld_elf_hash(version); + ver_entry.flags = 0; + ventry = &ver_entry; + } +#ifdef __powerpc__ + retaddr = hackish_return_address(); +#else + retaddr = __builtin_return_address(0); +#endif + return do_dlsym(handle, name, ventry, retaddr); +} + __strong_alias(__dladdr,dladdr) int dladdr(const void *addr, Dl_info *info) @@ -1030,7 +1252,14 @@ dladdr(const void *addr, Dl_info *info) const Elf_Sym *def, *best_def; void *symbol_addr; unsigned long symoffset; - +#ifdef __HAVE_FUNCTION_DESCRIPTORS + sigset_t mask; +#endif + + dbg(("dladdr of %p", addr)); + + lookup_mutex_enter(); + #ifdef __HAVE_FUNCTION_DESCRIPTORS addr = _rtld_function_descriptor_function(addr); #endif /* __HAVE_FUNCTION_DESCRIPTORS */ @@ -1038,6 +1267,7 @@ dladdr(const void *addr, Dl_info *info) obj = _rtld_obj_from_addr(addr); if (obj == NULL) { _rtld_error("No shared object contains address"); + lookup_mutex_enter(); return 0; } info->dli_fname = obj->path; @@ -1085,6 +1315,7 @@ dladdr(const void *addr, Dl_info *info) best_def, 0); #endif /* __HAVE_FUNCTION_DESCRIPTORS */ + lookup_mutex_exit(); return 1; } @@ -1095,6 +1326,10 @@ dlinfo(void *handle, int req, void *v) const Obj_Entry *obj; void *retaddr; + dbg(("dlinfo for %p %d", handle, req)); + + _rtld_shared_enter(); + if (handle == RTLD_SELF) { #ifdef __powerpc__ retaddr = hackish_return_address(); @@ -1103,11 +1338,12 @@ dlinfo(void *handle, int req, void *v) #endif if ((obj = _rtld_obj_from_addr(retaddr)) == NULL) { _rtld_error("Cannot determine caller's shared object"); + _rtld_shared_exit(); return -1; } } else { if ((obj = _rtld_dlcheck(handle)) == NULL) { - _rtld_error("Invalid handle"); + _rtld_shared_exit(); return -1; } } @@ -1123,9 +1359,11 @@ dlinfo(void *handle, int req, void *v) default: _rtld_error("Invalid request"); + _rtld_shared_exit(); return -1; } + _rtld_shared_exit(); return 0; } @@ -1137,27 +1375,33 @@ dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *), void *pa const Obj_Entry *obj; int error = 0; + dbg(("dl_iterate_phdr")); + + _rtld_shared_enter(); + for (obj = _rtld_objlist; obj != NULL; obj = obj->next) { phdr_info.dlpi_addr = (Elf_Addr)obj->relocbase; phdr_info.dlpi_name = STAILQ_FIRST(&obj->names) ? STAILQ_FIRST(&obj->names)->name : obj->path; phdr_info.dlpi_phdr = obj->phdr; phdr_info.dlpi_phnum = obj->phsize / sizeof(obj->phdr[0]); -#if 1 - phdr_info.dlpi_tls_modid = 0; - phdr_info.dlpi_tls_data = 0; -#else +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) phdr_info.dlpi_tls_modid = obj->tlsindex; phdr_info.dlpi_tls_data = obj->tlsinit; +#else + phdr_info.dlpi_tls_modid = 0; + phdr_info.dlpi_tls_data = 0; #endif phdr_info.dlpi_adds = _rtld_objloads; phdr_info.dlpi_subs = _rtld_objloads - _rtld_objcount; + /* XXXlocking: exit point */ error = callback(&phdr_info, sizeof(phdr_info), param); if (error) break; } + _rtld_shared_exit(); return error; } @@ -1182,7 +1426,8 @@ void _rtld_debug_state(void) { - /* do nothing */ + /* Prevent optimizer from removing calls to this function */ + __insn_barrier(); } void @@ -1267,3 +1512,130 @@ _rtld_objlist_remove(Objlist *list, Obj_Entry *obj) xfree(elm); } } + +#if defined(__minix) +void _rtld_shared_enter(void) {} +void _rtld_shared_exit(void) {} +void _rtld_exclusive_enter(sigset_t *mask) {} +void _rtld_exclusive_exit(sigset_t *mask) {} +#else +#define RTLD_EXCLUSIVE_MASK 0x80000000U +static volatile unsigned int _rtld_mutex; +static volatile unsigned int _rtld_waiter_exclusive; +static volatile unsigned int _rtld_waiter_shared; + +void +_rtld_shared_enter(void) +{ + unsigned int cur; + lwpid_t waiter, self = 0; + + membar_enter(); + + for (;;) { + cur = _rtld_mutex; + /* + * First check if we are currently not exclusively locked. + */ + if ((cur & RTLD_EXCLUSIVE_MASK) == 0) { + /* Yes, so increment use counter */ + if (atomic_cas_uint(&_rtld_mutex, cur, cur + 1) != cur) + continue; + return; + } + /* + * Someone has an exclusive lock. Puts us on the waiter list. + */ + if (!self) + self = _lwp_self(); + if (cur == (self | RTLD_EXCLUSIVE_MASK)) { + if (_rtld_mutex_may_recurse) + return; + _rtld_error("dead lock detected"); + _rtld_die(); + } + waiter = atomic_swap_uint(&_rtld_waiter_shared, self); + /* + * Check for race against _rtld_exclusive_exit before sleeping. + */ + if ((_rtld_mutex & RTLD_EXCLUSIVE_MASK) || + _rtld_waiter_exclusive) + _lwp_park(NULL, -1, __UNVOLATILE(&_rtld_mutex), NULL); + /* Try to remove us from the waiter list. */ + atomic_cas_uint(&_rtld_waiter_shared, self, 0); + if (waiter) + _lwp_unpark(waiter, __UNVOLATILE(&_rtld_mutex)); + } +} + +void +_rtld_shared_exit(void) +{ + lwpid_t waiter; + + /* + * Shared lock taken after an exclusive lock. + * Just assume this is a partial recursion. + */ + if (_rtld_mutex & RTLD_EXCLUSIVE_MASK) + return; + + /* + * Wakeup LWPs waiting for an exclusive lock if this is the last + * LWP on the shared lock. + */ + if (atomic_dec_uint_nv(&_rtld_mutex)) + return; + if ((waiter = _rtld_waiter_exclusive) != 0) + _lwp_unpark(waiter, __UNVOLATILE(&_rtld_mutex)); + + membar_exit(); +} + +void +_rtld_exclusive_enter(sigset_t *mask) +{ + lwpid_t waiter, self = _lwp_self(); + unsigned int locked_value = (unsigned int)self | RTLD_EXCLUSIVE_MASK; + unsigned int cur; + sigset_t blockmask; + + sigfillset(&blockmask); + sigdelset(&blockmask, SIGTRAP); /* Allow the debugger */ + sigprocmask(SIG_BLOCK, &blockmask, mask); + + membar_enter(); + + for (;;) { + if (atomic_cas_uint(&_rtld_mutex, 0, locked_value) == 0) + break; + waiter = atomic_swap_uint(&_rtld_waiter_exclusive, self); + cur = _rtld_mutex; + if (cur == locked_value) { + _rtld_error("dead lock detected"); + _rtld_die(); + } + if (cur) + _lwp_park(NULL, -1, __UNVOLATILE(&_rtld_mutex), NULL); + atomic_cas_uint(&_rtld_waiter_exclusive, self, 0); + if (waiter) + _lwp_unpark(waiter, __UNVOLATILE(&_rtld_mutex)); + } +} + +void +_rtld_exclusive_exit(sigset_t *mask) +{ + lwpid_t waiter; + + _rtld_mutex = 0; + if ((waiter = _rtld_waiter_exclusive) != 0) + _lwp_unpark(waiter, __UNVOLATILE(&_rtld_mutex)); + + if ((waiter = _rtld_waiter_shared) != 0) + _lwp_unpark(waiter, __UNVOLATILE(&_rtld_mutex)); + + membar_exit(); + sigprocmask(SIG_SETMASK, mask, NULL); +} +#endif /* !defined(__minix) */ diff --git a/libexec/ld.elf_so/rtld.h b/libexec/ld.elf_so/rtld.h index ecf005df0..0d3253dc9 100644 --- a/libexec/ld.elf_so/rtld.h +++ b/libexec/ld.elf_so/rtld.h @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.h,v 1.99 2011/01/16 15:56:37 matt Exp $ */ +/* $NetBSD: rtld.h,v 1.110 2012/08/15 03:46:06 matt Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -35,12 +35,14 @@ #define RTLD_H #include +#include #include #include #include #include #include #include +#include #include "rtldenv.h" #include "link.h" @@ -102,6 +104,15 @@ typedef struct _rtld_search_path_t { size_t sp_pathlen; } Search_Path; +typedef struct Struct_Ver_Entry { + Elf_Word hash; + u_int flags; + const char *name; + const char *file; +} Ver_Entry; + +/* Ver_Entry.flags */ +#define VER_INFO_HIDDEN 0x01 #define RTLD_MAX_ENTRY 10 #define RTLD_MAX_LIBRARY 4 @@ -129,6 +140,8 @@ typedef struct _rtld_library_xform_t { #define RTLD_MAGIC 0xd550b87a #define RTLD_VERSION 1 +typedef void (*fptr_t)(void); + typedef struct Struct_Obj_Entry { Elf32_Word magic; /* Magic number (sanity check) */ Elf32_Word version; /* Version number of struct format */ @@ -176,10 +189,15 @@ typedef struct Struct_Obj_Entry { Search_Path *rpaths; /* Search path specified in object */ Needed_Entry *needed; /* Shared objects needed by this (%) */ - void (*init)(void); /* Initialization function to call */ - void (*fini)(void); /* Termination function to call */ + fptr_t init; /* Initialization function to call */ + fptr_t fini; /* Termination function to call */ - /* Entry points for dlopen() and friends. */ + /* + * BACKWARDS COMPAT Entry points for dlopen() and friends. + * + * DO NOT MOVE OR ADD TO THE LIST + * + */ void *(*dlopen)(const char *, int); void *(*dlsym)(void *, const char *); char *(*dlerror)(void); @@ -211,6 +229,10 @@ typedef struct Struct_Obj_Entry { dlopen'ed */ phdr_loaded:1, /* Phdr is loaded and doesn't need to * be freed. */ +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + tls_done:1, /* True if static TLS offset + * has been allocated */ +#endif ref_nodel:1; /* Refcount increased to prevent dlclose */ struct link_map linkmap; /* for GDB */ @@ -231,9 +253,37 @@ typedef struct Struct_Obj_Entry { size_t pathlen; /* Pathname length */ STAILQ_HEAD(, Struct_Name_Entry) names; /* List of names for this object we know about. */ + #ifdef __powerpc__ Elf_Addr *gotptr; /* GOT table (secure-plt only) */ #endif + +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + /* Thread Local Storage support for this module */ + size_t tlsindex; /* Index in DTV */ + void *tlsinit; /* Base address of TLS init block */ + size_t tlsinitsize; /* Size of TLS init block */ + size_t tlssize; /* Size of TLS block */ + size_t tlsoffset; /* Offset in the static TLS block */ + size_t tlsalign; /* Needed alignment for static TLS */ +#endif + + /* symbol versioning */ + const Elf_Verneed *verneed; /* Required versions. */ + Elf_Word verneednum; /* Number of entries in verneed table */ + const Elf_Verdef *verdef; /* Provided versions. */ + Elf_Word verdefnum; /* Number of entries in verdef table */ + const Elf_Versym *versyms; /* Symbol versions table */ + + Ver_Entry *vertab; /* Versions required/defined by this + * object */ + int vertabnum; /* Number of entries in vertab */ + + /* init_array/fini_array */ + fptr_t *init_array; /* start of init array */ + size_t init_arraysz; /* # of entries in it */ + fptr_t *fini_array; /* start of fini array */ + size_t fini_arraysz; /* # of entries in it */ } Obj_Entry; typedef struct Struct_DoneList { @@ -262,12 +312,20 @@ extern Elf_Sym _rtld_sym_zero; #define RTLD_MODEMASK 0x3 +/* Flags to be passed into _rtld_symlook_ family of functions. */ +#define SYMLOOK_IN_PLT 0x01 /* Lookup for PLT symbol */ +#define SYMLOOK_DLSYM 0x02 /* Return newes versioned symbol. + Used by dlsym. */ + /* Flags for _rtld_load_object() and friends. */ #define _RTLD_GLOBAL 0x01 /* Add object to global DAG. */ #define _RTLD_MAIN 0x02 #define _RTLD_NOLOAD 0x04 /* dlopen() specified RTLD_NOLOAD. */ #define _RTLD_DLOPEN 0x08 /* Load_object() called from dlopen(). */ +/* Preallocation for static TLS model */ +#define RTLD_STATIC_TLS_RESERVATION 64 + /* rtld.c */ /* We export these symbols using _rtld_symbol_lookup and is_exported. */ @@ -280,12 +338,14 @@ __dso_public int dlinfo(void *, int, void *); __dso_public int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *); +__dso_public void *_dlauxinfo(void) __pure; + /* These aren't exported */ void _rtld_error(const char *, ...) __attribute__((__format__(__printf__,1,2))); void _rtld_die(void) __attribute__((__noreturn__)); void *_rtld_objmain_sym(const char *); -void _rtld_debug_state(void); +__dso_public void _rtld_debug_state(void) __noinline; void _rtld_linkmap_add(Obj_Entry *); void _rtld_linkmap_delete(Obj_Entry *); void _rtld_objlist_push_head(Objlist *, Obj_Entry *); @@ -293,6 +353,11 @@ void _rtld_objlist_push_tail(Objlist *, Obj_Entry *); Objlist_Entry *_rtld_objlist_find(Objlist *, const Obj_Entry *); void _rtld_ref_dag(Obj_Entry *); +void _rtld_shared_enter(void); +void _rtld_shared_exit(void); +void _rtld_exclusive_enter(sigset_t *); +void _rtld_exclusive_exit(sigset_t *); + /* expand.c */ size_t _rtld_expand_path(char *, size_t, const char *, const char *,\ const char *); @@ -327,23 +392,62 @@ Obj_Entry *_rtld_load_library(const char *, const Obj_Entry *, int); /* symbol.c */ unsigned long _rtld_elf_hash(const char *); const Elf_Sym *_rtld_symlook_obj(const char *, unsigned long, - const Obj_Entry *, bool); + const Obj_Entry *, u_int, const Ver_Entry *); const Elf_Sym *_rtld_find_symdef(unsigned long, const Obj_Entry *, - const Obj_Entry **, bool); + const Obj_Entry **, u_int); const Elf_Sym *_rtld_find_plt_symdef(unsigned long, const Obj_Entry *, const Obj_Entry **, bool); const Elf_Sym *_rtld_symlook_list(const char *, unsigned long, - const Objlist *, const Obj_Entry **, bool, DoneList *); + const Objlist *, const Obj_Entry **, u_int, const Ver_Entry *, DoneList *); const Elf_Sym *_rtld_symlook_default(const char *, unsigned long, - const Obj_Entry *, const Obj_Entry **, bool); + const Obj_Entry *, const Obj_Entry **, u_int, const Ver_Entry *); const Elf_Sym *_rtld_symlook_needed(const char *, unsigned long, - const Needed_Entry *, const Obj_Entry **, bool, + const Needed_Entry *, const Obj_Entry **, u_int, const Ver_Entry *, DoneList *, DoneList *); #ifdef COMBRELOC void _rtld_combreloc_reset(const Obj_Entry *); #endif +/* symver.c */ +int _rtld_object_match_name(const Obj_Entry *, const char *); +int _rtld_verify_object_versions(Obj_Entry *); + +static __inline const Ver_Entry * +_rtld_fetch_ventry(const Obj_Entry *obj, unsigned long symnum) +{ + Elf_Half vernum; + + if (obj->vertab) { + vernum = VER_NDX(obj->versyms[symnum].vs_vers); + if (vernum >= obj->vertabnum) { + _rtld_error("%s: symbol %s has wrong verneed value %d", + obj->path, &obj->strtab[symnum], vernum); + } else if (obj->vertab[vernum].hash) { + return &obj->vertab[vernum]; + } + } + return NULL; +} + +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) +/* tls.c */ +void *_rtld_tls_get_addr(void *, size_t, size_t); +void _rtld_tls_initial_allocation(void); +void *_rtld_tls_module_allocate(size_t index); +int _rtld_tls_offset_allocate(Obj_Entry *); +void _rtld_tls_offset_free(Obj_Entry *); + +extern size_t _rtld_tls_dtv_generation; +extern size_t _rtld_tls_max_index; + +__dso_public extern void *__tls_get_addr(void *); +#ifdef __i386__ +__dso_public extern void *___tls_get_addr(void *) + __attribute__((__regparm__(1))); +#endif +#endif + /* map_object.c */ struct stat; Obj_Entry *_rtld_map_object(const char *, int, const struct stat *); diff --git a/libexec/ld.elf_so/rtldenv.h b/libexec/ld.elf_so/rtldenv.h index a1b3ba939..7ce02393d 100644 --- a/libexec/ld.elf_so/rtldenv.h +++ b/libexec/ld.elf_so/rtldenv.h @@ -1,4 +1,4 @@ -/* $NetBSD: rtldenv.h,v 1.10 2010/10/29 15:08:17 christos Exp $ */ +/* $NetBSD: rtldenv.h,v 1.11 2011/12/11 11:05:11 joerg Exp $ */ /* * Copyright 1996 Matt Thomas @@ -57,7 +57,7 @@ void xerr(int, const char *, ...) void xerrx(int, const char *, ...) __attribute__((__noreturn__, __format__(__printf__, 2, 3))); -void xassert(const char *, int, const char *); +void xassert(const char *, int, const char *) __dead; const char *xstrerror(int); int xunsetenv(const char *); diff --git a/libexec/ld.elf_so/symbol.c b/libexec/ld.elf_so/symbol.c index f4979bbd3..f4eea1197 100644 --- a/libexec/ld.elf_so/symbol.c +++ b/libexec/ld.elf_so/symbol.c @@ -1,4 +1,4 @@ -/* $NetBSD: symbol.c,v 1.54 2010/10/16 10:27:07 skrll Exp $ */ +/* $NetBSD: symbol.c,v 1.61 2012/08/15 03:46:07 matt Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -40,7 +40,7 @@ #include #ifndef lint -__RCSID("$NetBSD: symbol.c,v 1.54 2010/10/16 10:27:07 skrll Exp $"); +__RCSID("$NetBSD: symbol.c,v 1.61 2012/08/15 03:46:07 matt Exp $"); #endif /* not lint */ #include @@ -59,8 +59,6 @@ __RCSID("$NetBSD: symbol.c,v 1.54 2010/10/16 10:27:07 skrll Exp $"); #include "debug.h" #include "rtld.h" -typedef void (*fptr_t)(void); - /* * If the given object is already in the donelist, return true. Otherwise * add the object to the list and return false. @@ -89,10 +87,20 @@ _rtld_is_exported(const Elf_Sym *def) (fptr_t)dlopen, (fptr_t)dlclose, (fptr_t)dlsym, + (fptr_t)dlvsym, (fptr_t)dlerror, (fptr_t)dladdr, (fptr_t)dlinfo, (fptr_t)dl_iterate_phdr, + (fptr_t)_dlauxinfo, +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + (fptr_t)_rtld_tls_allocate, + (fptr_t)_rtld_tls_free, + (fptr_t)__tls_get_addr, +#ifdef __i386__ + (fptr_t)___tls_get_addr, +#endif +#endif NULL }; int i; @@ -131,7 +139,8 @@ _rtld_elf_hash(const char *name) const Elf_Sym * _rtld_symlook_list(const char *name, unsigned long hash, const Objlist *objlist, - const Obj_Entry **defobj_out, bool in_plt, DoneList *dlp) + const Obj_Entry **defobj_out, u_int flags, const Ver_Entry *ventry, + DoneList *dlp) { const Elf_Sym *symp; const Elf_Sym *def; @@ -145,8 +154,8 @@ _rtld_symlook_list(const char *name, unsigned long hash, const Objlist *objlist, continue; rdbg(("search object %p (%s) for %s", elm->obj, elm->obj->path, name)); - if ((symp = _rtld_symlook_obj(name, hash, elm->obj, in_plt)) - != NULL) { + symp = _rtld_symlook_obj(name, hash, elm->obj, flags, ventry); + if (symp != NULL) { if ((def == NULL) || (ELF_ST_BIND(symp->st_info) != STB_WEAK)) { def = symp; @@ -168,8 +177,8 @@ _rtld_symlook_list(const char *name, unsigned long hash, const Objlist *objlist, */ const Elf_Sym * _rtld_symlook_needed(const char *name, unsigned long hash, - const Needed_Entry *needed, const Obj_Entry **defobj_out, bool inplt, - DoneList *breadth, DoneList *depth) + const Needed_Entry *needed, const Obj_Entry **defobj_out, u_int flags, + const Ver_Entry *ventry, DoneList *breadth, DoneList *depth) { const Elf_Sym *def, *def_w; const Needed_Entry *n; @@ -182,7 +191,8 @@ _rtld_symlook_needed(const char *name, unsigned long hash, continue; if (_rtld_donelist_check(breadth, obj)) continue; - if ((def = _rtld_symlook_obj(name, hash, obj, inplt)) == NULL) + def = _rtld_symlook_obj(name, hash, obj, flags, ventry); + if (def == NULL) continue; defobj = obj; if (ELF_ST_BIND(def->st_info) != STB_WEAK) { @@ -201,7 +211,7 @@ _rtld_symlook_needed(const char *name, unsigned long hash, if (_rtld_donelist_check(depth, obj)) continue; def_w = _rtld_symlook_needed(name, hash, obj->needed, &defobj1, - inplt, breadth, depth); + flags, ventry, breadth, depth); if (def_w == NULL) continue; if (def == NULL || ELF_ST_BIND(def_w->st_info) != STB_WEAK) { @@ -227,9 +237,12 @@ _rtld_symlook_needed(const char *name, unsigned long hash, */ const Elf_Sym * _rtld_symlook_obj(const char *name, unsigned long hash, - const Obj_Entry *obj, bool in_plt) + const Obj_Entry *obj, u_int flags, const Ver_Entry *ventry) { unsigned long symnum; + const Elf_Sym *vsymp = NULL; + Elf_Half verndx; + int vcount = 0; for (symnum = obj->buckets[fast_remainder32(hash, obj->nbuckets, obj->nbuckets_m, obj->nbuckets_s1, obj->nbuckets_s2)]; @@ -241,30 +254,106 @@ _rtld_symlook_obj(const char *name, unsigned long hash, assert(symnum < obj->nchains); symp = obj->symtab + symnum; strp = obj->strtab + symp->st_name; - rdbg(("check \"%s\" vs \"%s\" in %p", name, strp, obj)); - if (name[1] == strp[1] && !strcmp(name, strp)) { - if (symp->st_shndx != SHN_UNDEF) - return symp; -#ifndef __mips__ - /* - * XXX DANGER WILL ROBINSON! - * If we have a function pointer in the executable's - * data section, it points to the executable's PLT - * slot, and there is NO relocation emitted. To make - * the function pointer comparable to function pointers - * in shared libraries, we must resolve data references - * in the libraries to point to PLT slots in the - * executable, if they exist. - */ - else if (!in_plt && symp->st_value != 0 && - ELF_ST_TYPE(symp->st_info) == STT_FUNC) - return symp; + rdbg(("check \"%s\" vs \"%s\" in %s", name, strp, obj->path)); + if (name[1] != strp[1] || strcmp(name, strp)) + continue; +#ifdef __mips__ + if (symp->st_shndx == SHN_UNDEF) + continue; +#else + /* + * XXX DANGER WILL ROBINSON! + * If we have a function pointer in the executable's + * data section, it points to the executable's PLT + * slot, and there is NO relocation emitted. To make + * the function pointer comparable to function pointers + * in shared libraries, we must resolve data references + * in the libraries to point to PLT slots in the + * executable, if they exist. + */ + if (symp->st_shndx == SHN_UNDEF && + ((flags & SYMLOOK_IN_PLT) || + symp->st_value == 0 || + ELF_ST_TYPE(symp->st_info) != STT_FUNC)) + continue; #endif - else - return NULL; + + if (ventry == NULL) { + if (obj->versyms != NULL) { + verndx = VER_NDX(obj->versyms[symnum].vs_vers); + if (verndx > obj->vertabnum) { + _rtld_error("%s: symbol %s references " + "wrong version %d", obj->path, + &obj->strtab[symnum], verndx); + continue; + } + + /* + * If we are not called from dlsym (i.e. this + * is a normal relocation from unversioned + * binary), accept the symbol immediately + * if it happens to have first version after + * this shared object became versioned. + * Otherwise, if symbol is versioned and not + * hidden, remember it. If it is the only + * symbol with this name exported by the shared + * object, it will be returned as a match at the + * end of the function. If symbol is global + * (verndx < 2) accept it unconditionally. + */ + if (!(flags & SYMLOOK_DLSYM) && + verndx == VER_NDX_GIVEN) { + return symp; + } else if (verndx >= VER_NDX_GIVEN) { + if (!(obj->versyms[symnum].vs_vers & VER_NDX_HIDDEN)) { + if (vsymp == NULL) + vsymp = symp; + vcount++; + } + continue; + } + } + return symp; + } else { + if (obj->versyms == NULL) { + if (_rtld_object_match_name(obj, ventry->name)){ + _rtld_error("%s: object %s should " + "provide version %s for symbol %s", + _rtld_objself.path, obj->path, + ventry->name, &obj->strtab[symnum]); + continue; + } + } else { + verndx = VER_NDX(obj->versyms[symnum].vs_vers); + if (verndx > obj->vertabnum) { + _rtld_error("%s: symbol %s references " + "wrong version %d", obj->path, + &obj->strtab[symnum], verndx); + continue; + } + if (obj->vertab[verndx].hash != ventry->hash || + strcmp(obj->vertab[verndx].name, ventry->name)) { + /* + * Version does not match. Look if this + * is a global symbol and if it is not + * hidden. If global symbol (verndx < 2) + * is available, use it. Do not return + * symbol if we are called by dlvsym, + * because dlvsym looks for a specific + * version and default one is not what + * dlvsym wants. + */ + if ((flags & SYMLOOK_DLSYM) || + (obj->versyms[symnum].vs_vers & VER_NDX_HIDDEN) || + (verndx >= VER_NDX_GIVEN)) + continue; + } + } + return symp; } } - + if (vcount == 1) + return vsymp; return NULL; } @@ -291,7 +380,7 @@ _rtld_combreloc_reset(const Obj_Entry *obj) */ const Elf_Sym * _rtld_find_symdef(unsigned long symnum, const Obj_Entry *refobj, - const Obj_Entry **defobj_out, bool in_plt) + const Obj_Entry **defobj_out, u_int flags) { const Elf_Sym *ref; const Elf_Sym *def; @@ -312,7 +401,7 @@ _rtld_find_symdef(unsigned long symnum, const Obj_Entry *refobj, static const Elf_Sym *last_def; if (symnum == last_symnum && refobj == _rtld_last_refobj - && in_plt == false) { + && !(flags & SYMLOOK_IN_PLT)) { *defobj_out = last_defobj; return last_def; } @@ -334,7 +423,8 @@ _rtld_find_symdef(unsigned long symnum, const Obj_Entry *refobj, hash = _rtld_elf_hash(name); defobj = NULL; - def = _rtld_symlook_default(name, hash, refobj, &defobj, in_plt); + def = _rtld_symlook_default(name, hash, refobj, &defobj, flags, + _rtld_fetch_ventry(refobj, symnum)); } else { rdbg(("STB_LOCAL symbol %s in %s", name, refobj->path)); def = ref; @@ -354,7 +444,7 @@ _rtld_find_symdef(unsigned long symnum, const Obj_Entry *refobj, if (def != NULL) { *defobj_out = defobj; #ifdef COMBRELOC - if (in_plt == false) { + if (!(flags & SYMLOOK_IN_PLT)) { /* * Cache the lookup arguments and results if this was * non-PLT lookup. @@ -368,7 +458,8 @@ _rtld_find_symdef(unsigned long symnum, const Obj_Entry *refobj, } else { rdbg(("lookup failed")); _rtld_error("%s: Undefined %ssymbol \"%s\" (symnum = %ld)", - refobj->path, in_plt ? "PLT " : "", name, symnum); + refobj->path, (flags & SYMLOOK_IN_PLT) ? "PLT " : "", + name, symnum); } return def; } @@ -377,7 +468,8 @@ const Elf_Sym * _rtld_find_plt_symdef(unsigned long symnum, const Obj_Entry *obj, const Obj_Entry **defobj, bool imm) { - const Elf_Sym *def = _rtld_find_symdef(symnum, obj, defobj, true); + const Elf_Sym *def = _rtld_find_symdef(symnum, obj, defobj, + SYMLOOK_IN_PLT); if (__predict_false(def == NULL)) return NULL; @@ -404,7 +496,8 @@ _rtld_find_plt_symdef(unsigned long symnum, const Obj_Entry *obj, */ const Elf_Sym * _rtld_symlook_default(const char *name, unsigned long hash, - const Obj_Entry *refobj, const Obj_Entry **defobj_out, bool in_plt) + const Obj_Entry *refobj, const Obj_Entry **defobj_out, u_int flags, + const Ver_Entry *ventry) { const Elf_Sym *def; const Elf_Sym *symp; @@ -420,7 +513,7 @@ _rtld_symlook_default(const char *name, unsigned long hash, /* Look first in the referencing object if linked symbolically. */ if (refobj->symbolic && !_rtld_donelist_check(&donelist, refobj)) { rdbg(("search referencing object for %s", name)); - symp = _rtld_symlook_obj(name, hash, refobj, in_plt); + symp = _rtld_symlook_obj(name, hash, refobj, flags, ventry); if (symp != NULL) { def = symp; defobj = refobj; @@ -431,7 +524,7 @@ _rtld_symlook_default(const char *name, unsigned long hash, if (def == NULL || ELF_ST_BIND(def->st_info) == STB_WEAK) { rdbg(("search _rtld_list_main for %s", name)); symp = _rtld_symlook_list(name, hash, &_rtld_list_main, &obj, - in_plt, &donelist); + flags, ventry, &donelist); if (symp != NULL && (def == NULL || ELF_ST_BIND(symp->st_info) != STB_WEAK)) { def = symp; @@ -443,7 +536,7 @@ _rtld_symlook_default(const char *name, unsigned long hash, if (def == NULL || ELF_ST_BIND(def->st_info) == STB_WEAK) { rdbg(("search _rtld_list_global for %s", name)); symp = _rtld_symlook_list(name, hash, &_rtld_list_global, - &obj, in_plt, &donelist); + &obj, flags, ventry, &donelist); if (symp != NULL && (def == NULL || ELF_ST_BIND(symp->st_info) != STB_WEAK)) { def = symp; @@ -458,7 +551,7 @@ _rtld_symlook_default(const char *name, unsigned long hash, rdbg(("search DAG with root %p (%s) for %s", elm->obj, elm->obj->path, name)); symp = _rtld_symlook_list(name, hash, &elm->obj->dagmembers, - &obj, in_plt, &donelist); + &obj, flags, ventry, &donelist); if (symp != NULL && (def == NULL || ELF_ST_BIND(symp->st_info) != STB_WEAK)) { def = symp; @@ -475,7 +568,8 @@ _rtld_symlook_default(const char *name, unsigned long hash, */ if (def == NULL || ELF_ST_BIND(def->st_info) == STB_WEAK) { rdbg(("Search the dynamic linker itself.")); - symp = _rtld_symlook_obj(name, hash, &_rtld_objself, in_plt); + symp = _rtld_symlook_obj(name, hash, &_rtld_objself, flags, + ventry); if (symp != NULL && _rtld_is_exported(symp)) { def = symp; defobj = &_rtld_objself; diff --git a/libexec/ld.elf_so/symver.c b/libexec/ld.elf_so/symver.c new file mode 100644 index 000000000..4d4e46364 --- /dev/null +++ b/libexec/ld.elf_so/symver.c @@ -0,0 +1,317 @@ +/* $NetBSD: symver.c,v 1.1 2011/06/25 05:45:12 nonaka Exp $ */ + +/*- + * Copyright 1996, 1997, 1998, 1999, 2000 John D. Polstra. + * Copyright 2003 Alexander Kabaev . + * Copyright 2009, 2010, 2011 Konstantin Belousov . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: head/libexec/rtld-elf/rtld.c 220004 2011-03-25 18:23:10Z avg $ + */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by NONAKA Kimihiro. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__RCSID("$NetBSD: symver.c,v 1.1 2011/06/25 05:45:12 nonaka Exp $"); + +#include +#include +#include + +#include "debug.h" +#include "rtld.h" + + +int +_rtld_object_match_name(const Obj_Entry *obj, const char *name) +{ + Name_Entry *entry; + + STAILQ_FOREACH(entry, &obj->names, link) { + dbg(("name: %s, entry->name: %s", name, entry->name)); + if (strcmp(name, entry->name) == 0) + return 1; + } + return 0; +} + +static Obj_Entry * +locate_dependency(const Obj_Entry *obj, const char *name) +{ + const Objlist_Entry *entry; + const Needed_Entry *needed; + + SIMPLEQ_FOREACH(entry, &_rtld_list_main, link) { + if (_rtld_object_match_name(entry->obj, name)) + return entry->obj; + } + + for (needed = obj->needed; needed != NULL; needed = needed->next) { + dbg(("needed: name: %s, str: %s", name, + &obj->strtab[needed->name])); + if (strcmp(name, &obj->strtab[needed->name]) == 0 || + (needed->obj != NULL && _rtld_object_match_name(needed->obj, name))) { + /* + * If there is DT_NEEDED for the name we are looking + * for, we are all set. Note that object might not be + * found if dependency was not loaded yet, so the + * function can return NULL here. This is expected + * and handled properly by the caller. + */ + return needed->obj; + } + } + + _rtld_error("%s: Unexpected inconsistency: dependency %s not found", + obj->path, name); + return NULL; +} + +static int +check_object_provided_version(Obj_Entry *refobj, const Obj_Entry *depobj, + const Elf_Vernaux *vna) +{ + const char *vername = &refobj->strtab[vna->vna_name]; + const char *depstrtab = depobj->strtab; + const Elf_Verdef *vd = depobj->verdef; + const Elf_Word hash = vna->vna_hash; + + if (vd == NULL) { + _rtld_error("%s: version %s required by %s not defined", + depobj->path, vername, refobj->path); + return -1; + } + + for (;; vd = (const Elf_Verdef *)((const char *)vd + vd->vd_next)) { + if (vd->vd_version != VER_DEF_CURRENT) { + _rtld_error( + "%s: Unsupported version %d of Elf_Verdef entry", + depobj->path, vd->vd_version); + return -1; + } + dbg(("hash: 0x%x, vd_hash: 0x%x", hash, vd->vd_hash)); + if (hash == vd->vd_hash) { + const Elf_Verdaux *vda = (const Elf_Verdaux *) + ((const char *)vd + vd->vd_aux); + dbg(("vername: %s, str: %s", vername, + &depstrtab[vda->vda_name])); + if (strcmp(vername, &depstrtab[vda->vda_name]) == 0) + return 0; + } + if (vd->vd_next == 0) + break; + } + if (vna->vna_flags & VER_FLG_WEAK) + return 0; + + _rtld_error("%s: version %s required by %s not found", depobj->path, + vername, refobj->path); + return -1; +} + +int +_rtld_verify_object_versions(Obj_Entry *obj) +{ + const char *strtab = obj->strtab; + const Elf_Verneed *vn; + const Elf_Vernaux *vna; + const Elf_Verdef *vd; + const Elf_Verdaux *vda; + const Obj_Entry *depobj; + int maxvertab, vernum; + + dbg(("obj->path: %s", obj->path)); + + /* + * If we don't have string table or objects that have their version + * requirements already checked, we must be ok. + */ + if (strtab == NULL || obj->vertab != NULL) + return 0; + + maxvertab = 0; + + /* + * Walk over defined and required version records and figure out + * max index used by any of them. Do very basic sanity checking + * while there. + */ + for (vn = obj->verneed; + vn != NULL; + vn = (const Elf_Verneed *)((const char *)vn + vn->vn_next)) { + + if (vn->vn_version != VER_NEED_CURRENT) { + _rtld_error( + "%s: Unsupported version %d of Elf_Verneed entry", + obj->path, vn->vn_version); + return -1; + } + + dbg(("verneed: vn_file: %d, str: %s", + vn->vn_file, &strtab[vn->vn_file])); + depobj = locate_dependency(obj, &strtab[vn->vn_file]); + assert(depobj != NULL); + + for (vna = (const Elf_Vernaux *)((const char *)vn + vn->vn_aux); + /*CONSTCOND*/1; + vna = (const Elf_Vernaux *)((const char *)vna + vna->vna_next)) { + + if (check_object_provided_version(obj, depobj, vna) == -1) + return -1; + + vernum = VER_NEED_IDX(vna->vna_other); + if (vernum > maxvertab) + maxvertab = vernum; + + if (vna->vna_next == 0) { + /* No more symbols. */ + break; + } + } + + if (vn->vn_next == 0) { + /* No more dependencies. */ + break; + } + } + + for (vd = obj->verdef; + vd != NULL; + vd = (const Elf_Verdef *)((const char *)vd + vd->vd_next)) { + + if (vd->vd_version != VER_DEF_CURRENT) { + _rtld_error( + "%s: Unsupported version %d of Elf_Verdef entry", + obj->path, vd->vd_version); + return -1; + } + + dbg(("verdef: vn_ndx: 0x%x", vd->vd_ndx)); + vernum = VER_DEF_IDX(vd->vd_ndx); + if (vernum > maxvertab) + maxvertab = vernum; + + if (vd->vd_next == 0) { + /* No more definitions. */ + break; + } + } + + dbg(("maxvertab: %d", maxvertab)); + if (maxvertab == 0) + return 0; + + /* + * Store version information in array indexable by version index. + * Verify that object version requirements are satisfied along the + * way. + */ + obj->vertabnum = maxvertab + 1; + obj->vertab = (Ver_Entry *)xcalloc(obj->vertabnum * sizeof(Ver_Entry)); + + for (vn = obj->verneed; + vn != NULL; + vn = (const Elf_Verneed *)((const char *)vn + vn->vn_next)) { + + for (vna = (const Elf_Vernaux *)((const char *)vn + vn->vn_aux); + /*CONSTCOND*/1; + vna = (const Elf_Vernaux *)((const char *)vna + vna->vna_next)) { + + vernum = VER_NEED_IDX(vna->vna_other); + assert(vernum <= maxvertab); + obj->vertab[vernum].hash = vna->vna_hash; + obj->vertab[vernum].name = &strtab[vna->vna_name]; + obj->vertab[vernum].file = &strtab[vn->vn_file]; + obj->vertab[vernum].flags = + (vna->vna_other & VER_NEED_HIDDEN) + ? VER_INFO_HIDDEN : 0; + dbg(("verneed: vernum: %d, hash: 0x%x, name: %s, " + "file: %s, flags: 0x%x", vernum, + obj->vertab[vernum].hash, obj->vertab[vernum].name, + obj->vertab[vernum].file, + obj->vertab[vernum].flags)); + + if (vna->vna_next == 0) { + /* No more symbols. */ + break; + } + } + if (vn->vn_next == 0) { + /* No more dependencies. */ + break; + } + } + + for (vd = obj->verdef; + vd != NULL; + vd = (const Elf_Verdef *)((const char *)vd + vd->vd_next)) { + + if ((vd->vd_flags & VER_FLG_BASE) == 0) { + vernum = VER_DEF_IDX(vd->vd_ndx); + assert(vernum <= maxvertab); + vda = (const Elf_Verdaux *) + ((const char *)vd + vd->vd_aux); + obj->vertab[vernum].hash = vd->vd_hash; + obj->vertab[vernum].name = &strtab[vda->vda_name]; + obj->vertab[vernum].file = NULL; + obj->vertab[vernum].flags = 0; + dbg(("verdef: vernum: %d, hash: 0x%x, name: %s", + vernum, obj->vertab[vernum].hash, + obj->vertab[vernum].name)); + } + + if (vd->vd_next == 0) { + /* No more definitions. */ + break; + } + } + + return 0; +} diff --git a/libexec/ld.elf_so/tls.c b/libexec/ld.elf_so/tls.c new file mode 100644 index 000000000..4bfaaba2a --- /dev/null +++ b/libexec/ld.elf_so/tls.c @@ -0,0 +1,304 @@ +/* $NetBSD: tls.c,v 1.7 2011/04/23 16:40:08 joerg Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__RCSID("$NetBSD: tls.c,v 1.7 2011/04/23 16:40:08 joerg Exp $"); + +#include +#include +#include +#include +#include "rtld.h" + +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + +static struct tls_tcb *_rtld_tls_allocate_locked(void); + +#ifndef TLS_DTV_OFFSET +#define TLS_DTV_OFFSET 0 +#endif + +static size_t _rtld_tls_static_space; /* Static TLS space allocated */ +static size_t _rtld_tls_static_offset; /* Next offset for static TLS to use */ +size_t _rtld_tls_dtv_generation = 1; +size_t _rtld_tls_max_index = 1; + +#define DTV_GENERATION(dtv) ((size_t)((dtv)[0])) +#define DTV_MAX_INDEX(dtv) ((size_t)((dtv)[-1])) +#define SET_DTV_GENERATION(dtv, val) (dtv)[0] = (void *)(size_t)(val) +#define SET_DTV_MAX_INDEX(dtv, val) (dtv)[-1] = (void *)(size_t)(val) + +void * +_rtld_tls_get_addr(void *tls, size_t idx, size_t offset) +{ + struct tls_tcb *tcb = tls; + void **dtv, **new_dtv; + sigset_t mask; + + _rtld_exclusive_enter(&mask); + + dtv = tcb->tcb_dtv; + + if (__predict_false(DTV_GENERATION(dtv) != _rtld_tls_dtv_generation)) { + size_t to_copy = DTV_MAX_INDEX(dtv); + + new_dtv = xcalloc((2 + _rtld_tls_max_index) * sizeof(*dtv)); + ++new_dtv; + if (to_copy > _rtld_tls_max_index) + to_copy = _rtld_tls_max_index; + memcpy(new_dtv + 1, dtv + 1, to_copy * sizeof(*dtv)); + xfree(dtv - 1); + dtv = tcb->tcb_dtv = new_dtv; + SET_DTV_MAX_INDEX(dtv, _rtld_tls_max_index); + SET_DTV_GENERATION(dtv, _rtld_tls_dtv_generation); + } + + if (__predict_false(dtv[idx] == NULL)) + dtv[idx] = _rtld_tls_module_allocate(idx); + + _rtld_exclusive_exit(&mask); + + return (uint8_t *)dtv[idx] + offset; +} + +void +_rtld_tls_initial_allocation(void) +{ + struct tls_tcb *tcb; + + _rtld_tls_static_space = _rtld_tls_static_offset + + RTLD_STATIC_TLS_RESERVATION; + +#ifndef __HAVE_TLS_VARIANT_I + _rtld_tls_static_space = roundup2(_rtld_tls_static_space, + sizeof(void *)); +#endif + + tcb = _rtld_tls_allocate_locked(); +#ifdef __HAVE___LWP_SETTCB + __lwp_settcb(tcb); +#ifdef __powerpc__ + /* + * Save the tcb pointer so that libc can retrieve it. Older + * crt0 will obliterate r2 so there is code in libc to restore it. + */ + _lwp_setprivate(tcb); +#endif +#else + _lwp_setprivate(tcb); +#endif +} + +static struct tls_tcb * +_rtld_tls_allocate_locked(void) +{ + Obj_Entry *obj; + struct tls_tcb *tcb; + uint8_t *p, *q; + + p = xcalloc(_rtld_tls_static_space + sizeof(struct tls_tcb)); +#ifdef __HAVE_TLS_VARIANT_I + tcb = (struct tls_tcb *)p; + p += sizeof(struct tls_tcb); +#else + p += _rtld_tls_static_space; + tcb = (struct tls_tcb *)p; + tcb->tcb_self = tcb; +#endif + tcb->tcb_dtv = xcalloc(sizeof(*tcb->tcb_dtv) * (2 + _rtld_tls_max_index)); + ++tcb->tcb_dtv; + SET_DTV_MAX_INDEX(tcb->tcb_dtv, _rtld_tls_max_index); + SET_DTV_GENERATION(tcb->tcb_dtv, _rtld_tls_dtv_generation); + + for (obj = _rtld_objlist; obj != NULL; obj = obj->next) { + if (obj->tlssize) { +#ifdef __HAVE_TLS_VARIANT_I + q = p + obj->tlsoffset; +#else + q = p - obj->tlsoffset; +#endif + memcpy(q, obj->tlsinit, obj->tlsinitsize); + tcb->tcb_dtv[obj->tlsindex] = q; + } + } + + return tcb; +} + +struct tls_tcb * +_rtld_tls_allocate(void) +{ + struct tls_tcb *tcb; + sigset_t mask; + + _rtld_exclusive_enter(&mask); + tcb = _rtld_tls_allocate_locked(); + _rtld_exclusive_exit(&mask); + + return tcb; +} + +void +_rtld_tls_free(struct tls_tcb *tcb) +{ + size_t i, max_index; + uint8_t *p; + sigset_t mask; + + _rtld_exclusive_enter(&mask); + + max_index = DTV_MAX_INDEX(tcb->tcb_dtv); + for (i = 1; i <= max_index; ++i) + xfree(tcb->tcb_dtv[i]); + xfree(tcb->tcb_dtv - 1); + +#ifdef __HAVE_TLS_VARIANT_I + p = (uint8_t *)tcb; +#else + p = (uint8_t *)tcb - _rtld_tls_static_space; +#endif + xfree(p); + + _rtld_exclusive_exit(&mask); +} + +void * +_rtld_tls_module_allocate(size_t idx) +{ + Obj_Entry *obj; + uint8_t *p; + + for (obj = _rtld_objlist; obj != NULL; obj = obj->next) { + if (obj->tlsindex == idx) + break; + } + if (obj == NULL) { + _rtld_error("Module for TLS index %zu missing", idx); + _rtld_die(); + } + + p = xmalloc(obj->tlssize); + memcpy(p, obj->tlsinit, obj->tlsinitsize); + memset(p + obj->tlsinitsize, 0, obj->tlssize - obj->tlsinitsize); + + return p; +} + +int +_rtld_tls_offset_allocate(Obj_Entry *obj) +{ + size_t offset, next_offset; + + if (obj->tls_done) + return 0; + if (obj->tlssize == 0) { + obj->tlsoffset = 0; + obj->tls_done = 1; + return 0; + } + +#ifdef __HAVE_TLS_VARIANT_I + offset = roundup2(_rtld_tls_static_offset, obj->tlsalign); + next_offset = offset + obj->tlssize; +#else + offset = roundup2(_rtld_tls_static_offset + obj->tlssize, + obj->tlsalign); + next_offset = offset; +#endif + + /* + * Check if the static allocation was already done. + * This happens if dynamically loaded modules want to use + * static TLS space. + * + * XXX Keep an actual free list and callbacks for initialisation. + */ + if (_rtld_tls_static_space) { + if (obj->tlsinitsize) { + _rtld_error("%s: Use of initialized " + "Thread Local Storage with model initial-exec " + "and dlopen is not supported", + obj->path); + return -1; + } + if (next_offset > _rtld_tls_static_space) { + _rtld_error("%s: No space available " + "for static Thread Local Storage", + obj->path); + return -1; + } + } + obj->tlsoffset = offset; + _rtld_tls_static_offset = next_offset; + obj->tls_done = 1; + + return 0; +} + +void +_rtld_tls_offset_free(Obj_Entry *obj) +{ + + /* + * XXX See above. + */ + obj->tls_done = 0; + return; +} + +#ifdef __HAVE_COMMON___TLS_GET_ADDR +/* + * The fast path is access to an already allocated DTV entry. + * This checks the current limit and the entry without needing any + * locking. Entries are only freed on dlclose() and it is an application + * bug if code of the module is still running at that point. + */ +void * +__tls_get_addr(void *arg_) +{ + size_t *arg = (size_t *)arg_; + void **dtv; +#ifdef __HAVE___LWP_GETTCB_FAST + struct tls_tcb * const tcb = __lwp_gettcb_fast(); +#else + struct tls_tcb * const tcb = __lwp_getprivate_fast(); +#endif + size_t idx = arg[0], offset = arg[1] + TLS_DTV_OFFSET; + + dtv = tcb->tcb_dtv; + + if (__predict_true(idx < DTV_MAX_INDEX(dtv) && dtv[idx] != NULL)) + return (uint8_t *)dtv[idx] + offset; + + return _rtld_tls_get_addr(tcb, idx, offset); +} +#endif + +#endif /* __HAVE_TLS_VARIANT_I || __HAVE_TLS_VARIANT_II */ diff --git a/libexec/ld.elf_so/xmalloc.c b/libexec/ld.elf_so/xmalloc.c index 626378dab..ac516becf 100644 --- a/libexec/ld.elf_so/xmalloc.c +++ b/libexec/ld.elf_so/xmalloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: xmalloc.c,v 1.10 2010/12/03 23:07:49 joerg Exp $ */ +/* $NetBSD: xmalloc.c,v 1.11 2011/05/25 14:41:46 christos Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -61,6 +61,8 @@ */ #ifdef __minix +/* Minix mmap can do this. */ +#define mmap minix_mmap #define munmap minix_munmap #endif @@ -81,7 +83,7 @@ #include #ifndef lint -__RCSID("$NetBSD: xmalloc.c,v 1.10 2010/12/03 23:07:49 joerg Exp $"); +__RCSID("$NetBSD: xmalloc.c,v 1.11 2011/05/25 14:41:46 christos Exp $"); #endif /* not lint */ #include @@ -152,6 +154,7 @@ static union overhead *nextf[NBUCKETS]; static size_t pagesz; /* page size */ static size_t pagebucket; /* page size bucket */ +static size_t pageshift; /* page size shift */ #ifdef MSTATS /* @@ -207,6 +210,7 @@ imalloc(size_t nbytes) bucket++; } pagebucket = bucket; + pageshift = ffs(pagesz) - 1; } /* * Convert amount of memory requested into closest block size @@ -281,13 +285,13 @@ morecore(size_t bucket) #endif if (sz < pagesz) { amt = pagesz; - nblks = amt / sz; + nblks = amt >> (bucket + 3); } else { amt = sz + pagesz; nblks = 1; } if (amt > PAGEPOOL_SIZE) - if (morepages(amt/pagesz + NPOOLPAGES) == 0) + if (morepages((amt >> pageshift) + NPOOLPAGES) == 0) return; op = (union overhead *)pagepool_start; pagepool_start += amt; @@ -413,10 +417,6 @@ mstats(char *s) } #endif -/* Minix mmap can do this. */ -#ifdef __minix -#define mmap minix_mmap -#endif static int morepages(int n) diff --git a/servers/devman/buf.c b/servers/devman/buf.c index 88c4c5cd9..a6af6aa47 100755 --- a/servers/devman/buf.c +++ b/servers/devman/buf.c @@ -46,8 +46,6 @@ static char buf[BUF_SIZE + 1]; static size_t off, left, used; static off_t skip; -#define MIN(x,y) (xi_blocks counter. */ - int index1, index2, index3; /* indexes in single..triple indirect blocks */ + int index1 = 0, index2 = 0, index3 = 0; /* indexes in single..triple indirect blocks */ long excess, block_pos; char new_ind = 0, new_dbl = 0, new_triple = 0; int single = 0, triple = 0; diff --git a/servers/inet/clock.c b/servers/inet/clock.c index a869e684d..42f59ce75 100644 --- a/servers/inet/clock.c +++ b/servers/inet/clock.c @@ -54,7 +54,7 @@ time_t tim; } else if (!curr_time) { - DBLOCK(0x20, printf("set_time: new time %ld < prev_time %ld\n", + DBLOCK(0x20, printf("set_time: new time %i < prev_time %i\n", tim, prev_time)); } } diff --git a/servers/inet/generic/tcp_send.c b/servers/inet/generic/tcp_send.c index ad7fa36ed..c03a0d9ce 100644 --- a/servers/inet/generic/tcp_send.c +++ b/servers/inet/generic/tcp_send.c @@ -603,13 +603,13 @@ void tcp_release_retrans( rtt= TCP_RTT_MAX; } DBLOCK(0x10, printf( - "tcp_release_retrans, conn[%d]: retrans_time= %ld ms, rtt = %ld ms\n", + "tcp_release_retrans, conn[%i]: retrans_time= %i ms, rtt = %i ms\n", tcp_conn-tcp_conn_table, retrans_time*1000/HZ, rtt*1000/HZ)); DBLOCK(0x10, printf( - "tcp_release_retrans: artt= %ld -> %ld, drtt= %ld -> %ld\n", + "tcp_release_retrans: artt= %i -> %i, drtt= %i -> %i\n", tcp_conn->tc_artt, artt, tcp_conn->tc_drtt, drtt)); @@ -864,7 +864,7 @@ struct timer *timer; tcp_conn->tc_ka_snd= tcp_conn->tc_SND_NXT; tcp_conn->tc_ka_rcv= tcp_conn->tc_RCV_NXT; DBLOCK(0x20, printf( -"tcp_send_timeout: conn[%d] setting keepalive timer (+%ld ms)\n", +"tcp_send_timeout: conn[%i] setting keepalive timer (+%i ms)\n", tcp_conn-tcp_conn_table, tcp_conn->tc_ka_time*1000/HZ)); clck_timer(&tcp_conn->tc_transmit_timer, @@ -919,7 +919,7 @@ struct timer *timer; tcp_conn->tc_0wnd_to= 0; DBLOCK(0x20, printf( - "tcp_send_timeout: conn[%d] setting timer to %ld ms (+%ld ms)\n", + "tcp_send_timeout: conn[%i] setting timer to %i ms (+%i ms)\n", tcp_conn-tcp_conn_table, (curr_time+rtt)*1000/HZ, rtt*1000/HZ)); @@ -954,7 +954,7 @@ struct timer *timer; tcp_conn->tc_rt_seq= 0; DBLOCK(0x10, printf( - "tcp_send_timeout: conn[%d] setting timer to %ld ms (+%ld ms)\n", + "tcp_send_timeout: conn[%i] setting timer to %i ms (+%i ms)\n", tcp_conn-tcp_conn_table, (curr_time+tcp_conn->tc_0wnd_to)*1000/HZ, tcp_conn->tc_0wnd_to*1000/HZ)); @@ -974,7 +974,7 @@ struct timer *timer; * probe, which is almost the same. */ - DBLOCK(0x20, printf("tcp_send_timeout: conn[%d] una= %lu, rtt= %ldms\n", + DBLOCK(0x20, printf("tcp_send_timeout: conn[%i] una= %lu, rtt= %ims\n", tcp_conn-tcp_conn_table, (unsigned long)tcp_conn->tc_SND_UNA, rtt*1000/HZ)); @@ -1030,7 +1030,7 @@ struct timer *timer; timeout += curr_time; DBLOCK(0x20, printf( - "tcp_send_timeout: conn[%d] setting timer to %ld ms (+%ld ms)\n", + "tcp_send_timeout: conn[%i] setting timer to %i ms (+%i ms)\n", tcp_conn-tcp_conn_table, timeout*1000/HZ, (timeout-curr_time)*1000/HZ)); @@ -1285,7 +1285,7 @@ tcp_conn_t *tcp_conn; rtt= tcp_conn->tc_rtt; DBLOCK(0x20, printf( - "tcp_set_send_timer: conn[%d] setting timer to %ld ms (+%ld ms)\n", + "tcp_set_send_timer: conn[%i] setting timer to %i ms (+%i ms)\n", tcp_conn-tcp_conn_table, (curr_time+rtt)*1000/HZ, rtt*1000/HZ)); diff --git a/servers/ipc/sem.c b/servers/ipc/sem.c index b723529a1..5b1876a52 100644 --- a/servers/ipc/sem.c +++ b/servers/ipc/sem.c @@ -280,7 +280,7 @@ static void update_semaphores(void) int do_semctl(message *m) { int r, i; - long opt; + long opt = 0; uid_t uid; int id, num, cmd, val; unsigned short *buf; diff --git a/servers/is/dmp_kernel.c b/servers/is/dmp_kernel.c index 830bcb8cd..abda65d8f 100644 --- a/servers/is/dmp_kernel.c +++ b/servers/is/dmp_kernel.c @@ -330,7 +330,7 @@ void proctab_dmp() PROCLOOP(rp, oldrp) printf(" %5d %10d ", _ENDPOINT_G(rp->p_endpoint), rp->p_endpoint); - printf("%-8.8s %5u %5u %6lu %6lu ", + printf("%-8.8s %5u %5u %6u %6u ", rp->p_name, rp->p_priority, rp->p_quantum_size_ms, diff --git a/servers/is/dmp_pm.c b/servers/is/dmp_pm.c index d30c9bbf7..4799b588a 100644 --- a/servers/is/dmp_pm.c +++ b/servers/is/dmp_pm.c @@ -95,7 +95,7 @@ void sigaction_dmp() printf(" %08lx %08lx %08lx ", mp->mp_ignore, mp->mp_catch, mp->mp_sigmask); printf("%08lx ", mp->mp_sigpending); - if (mp->mp_flags & ALARM_ON) printf("%8ld", mp->mp_timer.tmr_exp_time-uptime); + if (mp->mp_flags & ALARM_ON) printf("%8d", mp->mp_timer.tmr_exp_time-uptime); else printf(" -"); printf("\n"); } diff --git a/servers/is/dmp_rs.c b/servers/is/dmp_rs.c index 362dd81ae..9fcdbee96 100644 --- a/servers/is/dmp_rs.c +++ b/servers/is/dmp_rs.c @@ -42,7 +42,7 @@ void rproc_dmp() rpub = &rprocpub[i]; if (! (rp->r_flags & RS_IN_USE)) continue; if (++n > 22) break; - printf("%13s %9d %5d %6s %3d/%1d %3ld %8ld %5dx %s", + printf("%13s %9d %5d %6s %3d/%1d %3ld %8d %5dx %s", rpub->label, rpub->endpoint, rp->r_pid, s_flags_str(rp->r_flags, rpub->sys_flags), rpub->dev_nr, rpub->dev_style, rp->r_period, rp->r_alive_tm, rp->r_restarts, diff --git a/servers/iso9660fs/path.c b/servers/iso9660fs/path.c index cc720a5e4..07867b081 100644 --- a/servers/iso9660fs/path.c +++ b/servers/iso9660fs/path.c @@ -196,7 +196,7 @@ size_t *offsetp; /* Find starting inode inode according to the request message */ if ((start_dir = get_dir_record(dir_ino)) == NULL) { - printf("ISOFS: couldn't find starting inode %lu\n", dir_ino); + printf("ISOFS: couldn't find starting inode %u\n", dir_ino); return(ENOENT); } diff --git a/servers/mfs/inode.c b/servers/mfs/inode.c index 8ae695faa..1ad314c6c 100644 --- a/servers/mfs/inode.c +++ b/servers/mfs/inode.c @@ -46,7 +46,7 @@ int fs_putnode(void) rip = find_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR); if(!rip) { - printf("%s:%d put_inode: inode #%lu dev: %d not found\n", __FILE__, + printf("%s:%d put_inode: inode #%u dev: %d not found\n", __FILE__, __LINE__, (ino_t) fs_m_in.REQ_INODE_NR, fs_dev); panic("fs_putnode failed"); } diff --git a/servers/rs/exec.c b/servers/rs/exec.c index bb9d2b822..7dd908de1 100644 --- a/servers/rs/exec.c +++ b/servers/rs/exec.c @@ -206,7 +206,7 @@ size_t seg_bytes /* how much is to be transferred? */ if (off+seg_bytes > execi->hdr_len) return ENOEXEC; if((r= sys_vircopy(SELF, ((vir_bytes)execi->hdr)+off, execi->proc_e, seg_addr, seg_bytes)) != OK) { - printf("RS: exec read_seg: copy 0x%x bytes into %d at 0x%lx failed: %d\n", + printf("RS: exec read_seg: copy 0x%x bytes into %i at 0x%08x failed: %i\n", seg_bytes, execi->proc_e, seg_addr, r); } return r; diff --git a/servers/vfs/device.c b/servers/vfs/device.c index 7461abc00..0a7df83fc 100644 --- a/servers/vfs/device.c +++ b/servers/vfs/device.c @@ -899,7 +899,7 @@ int clone_opcl( */ /* Device number of the new device. */ - dev = (dev & ~(BYTE << MINOR)) | (dev_mess.REP_STATUS << MINOR); + dev = makedev(major(dev), minor(dev_mess.REP_STATUS)); /* Issue request */ r = req_newnode(PFS_PROC_NR, fp->fp_effuid, fp->fp_effgid, diff --git a/share/mk/minix.bootprog.mk b/share/mk/minix.bootprog.mk index 36f7397b2..a19becbae 100644 --- a/share/mk/minix.bootprog.mk +++ b/share/mk/minix.bootprog.mk @@ -1,4 +1,21 @@ # MINIX-specific boot program options .include -.include +# LSC Static linking, order matters! +# 1. No default libs +LDADD+= -nodefaultlibs + +# 2. Compiler-specific libs +.if !empty(CC:M*gcc) +LDADD+= -lgcc -lsys -lgcc +.elif !empty(CC:M*clang) +LDADD+= -L/usr/pkg/compiler-rt/lib -lCompilerRT-Generic -lsys -lCompilerRT-Generic +.endif + +# 3. Minimal C library +LDADD+= -lminc + +# Some define still needed, hopefully will go away soon +CPPFLAGS+= -D__NBSD_LIBC + +.include diff --git a/share/mk/minix.service.mk b/share/mk/minix.service.mk index d906f6697..cfdf9cbc7 100644 --- a/share/mk/minix.service.mk +++ b/share/mk/minix.service.mk @@ -1,12 +1,4 @@ # MINIX-specific servers/drivers options .include -CPPFLAGS+= -D__NBSD_LIBC - -.if !empty(CC:M*gcc) -LDADD+= -nodefaultlibs -lgcc -lsys -lgcc -lminc -.elif !empty(CC:M*clang) -LDADD+= -nodefaultlibs -L/usr/pkg/compiler-rt/lib -lCompilerRT-Generic -lsys -lCompilerRT-Generic -lminc -.endif - -.include +.include diff --git a/sys/arch/i386/include/ansi.h b/sys/arch/i386/include/ansi.h index e26337e64..cbcaaa186 100644 --- a/sys/arch/i386/include/ansi.h +++ b/sys/arch/i386/include/ansi.h @@ -1,4 +1,4 @@ -/* $NetBSD: ansi.h,v 1.24 2010/03/27 22:14:09 tnozaki Exp $ */ +/* $NetBSD: ansi.h,v 1.25 2011/07/17 20:54:41 joerg Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -49,23 +49,15 @@ * #undef _BSD_SIZE_T_ * #endif */ - -#define _BSD_CLOCK_T_ long - -#define _BSD_PTRDIFF_T_ int - -#define _BSD_SIZE_T_ unsigned int -#define _BSD_SSIZE_T_ int -#define _BSD_TIME_T_ long /* time() */ -#if __GNUC_PREREQ__(2, 96) -#define _BSD_VA_LIST_ __builtin_va_list /* GCC built-in type */ -#else -#define _BSD_VA_LIST_ char * /* va_list */ -#endif +#define _BSD_CLOCK_T_ int /* clock() */ +#define _BSD_PTRDIFF_T_ int /* ptr1 - ptr2 */ +#define _BSD_SIZE_T_ unsigned int /* sizeof() */ +#define _BSD_SSIZE_T_ int /* byte count or error */ +#define _BSD_TIME_T_ int /* time() */ #define _BSD_CLOCKID_T_ int /* clockid_t */ #define _BSD_TIMER_T_ int /* timer_t */ -#define _BSD_SUSECONDS_T_ long /* suseconds_t */ -#define _BSD_USECONDS_T_ long /* useconds_t */ +#define _BSD_SUSECONDS_T_ int /* suseconds_t */ +#define _BSD_USECONDS_T_ int /* useconds_t */ #define _BSD_WCHAR_T_ int /* wchar_t */ #define _BSD_WINT_T_ int /* wint_t */ diff --git a/sys/arch/i386/include/cdefs.h b/sys/arch/i386/include/cdefs.h index 3da516304..6002b786f 100644 --- a/sys/arch/i386/include/cdefs.h +++ b/sys/arch/i386/include/cdefs.h @@ -1,22 +1,17 @@ -/* $NetBSD: cdefs.h,v 1.8 2011/06/16 13:27:59 joerg Exp $ */ +/* $NetBSD: cdefs.h,v 1.9 2012/01/20 14:08:06 joerg Exp $ */ #ifndef _I386_CDEFS_H_ #define _I386_CDEFS_H_ #if defined(_STANDALONE) -#ifdef __PCC__ -#define __compactcall -#else #define __compactcall __attribute__((__regparm__(3))) #endif -#endif -#ifdef __minix +#define __ALIGNBYTES (sizeof(int) - 1) + +#if defined(__minix) #ifndef __ELF__ #define __LEADING_UNDERSCORE #endif -#else /* !__minix */ -/* No arch-specific cdefs. */ -#endif - +#endif /* defined(__minix) */ #endif /* !_I386_CDEFS_H_ */ diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h index ff885b32c..f57a0efd8 100644 --- a/sys/arch/i386/include/cpu.h +++ b/sys/arch/i386/include/cpu.h @@ -16,4 +16,6 @@ #define X86_FLAGS_USER (X86_FLAG_C | X86_FLAG_P | X86_FLAG_A | X86_FLAG_Z | \ X86_FLAG_S | X86_FLAG_D | X86_FLAG_O) +#include + #endif diff --git a/sys/arch/i386/include/limits.h b/sys/arch/i386/include/limits.h index 2e78d7bae..bb1f5aab6 100644 --- a/sys/arch/i386/include/limits.h +++ b/sys/arch/i386/include/limits.h @@ -1,4 +1,4 @@ -/* $NetBSD: limits.h,v 1.22 2010/06/07 13:52:30 tnozaki Exp $ */ +/* $NetBSD: limits.h,v 1.23 2012/03/28 17:03:29 christos Exp $ */ /* * Copyright (c) 1988 The Regents of the University of California. @@ -38,13 +38,10 @@ #define CHAR_BIT 8 /* number of bits in a char */ +#define UCHAR_MAX 0xff /* max value for an unsigned char */ #define SCHAR_MAX 0x7f /* max value for a signed char */ #define SCHAR_MIN (-0x7f-1) /* min value for a signed char */ -#define UCHAR_MAX 0xff /* max value for an unsigned char */ -#define CHAR_MAX 0x7f /* max value for a char */ -#define CHAR_MIN (-0x7f-1) /* min value for a char */ - #define USHRT_MAX 0xffff /* max value for an unsigned short */ #define SHRT_MAX 0x7fff /* max value for a short */ #define SHRT_MIN (-0x7fff-1) /* min value for a short */ diff --git a/sys/arch/i386/include/multiboot.h b/sys/arch/i386/include/multiboot.h index 4b8ac1a3a..19291b283 100644 --- a/sys/arch/i386/include/multiboot.h +++ b/sys/arch/i386/include/multiboot.h @@ -1,6 +1,213 @@ +/* $NetBSD: multiboot.h,v 1.8 2009/02/22 18:05:42 ahoka Exp $ */ + +/*- + * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julio M. Merino Vidal. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef __MULTIBOOT_H__ #define __MULTIBOOT_H__ +#if !defined(_KERNEL) && defined(_STANDALONE) + +/* --------------------------------------------------------------------- */ + +/* + * Multiboot header structure. + */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 +#define MULTIBOOT_HEADER_MODS_ALIGNED 0x00000001 +#define MULTIBOOT_HEADER_WANT_MEMORY 0x00000002 +#define MULTIBOOT_HEADER_HAS_VBE 0x00000004 +#define MULTIBOOT_HEADER_HAS_ADDR 0x00010000 + +#if !defined(_LOCORE) +struct multiboot_header { + uint32_t mh_magic; + uint32_t mh_flags; + uint32_t mh_checksum; + + /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ + paddr_t mh_header_addr; + paddr_t mh_load_addr; + paddr_t mh_load_end_addr; + paddr_t mh_bss_end_addr; + paddr_t mh_entry_addr; + + /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */ + uint32_t mh_mode_type; + uint32_t mh_width; + uint32_t mh_height; + uint32_t mh_depth; +}; +#endif /* !defined(_LOCORE) */ + +/* + * Symbols defined in locore.S. + */ +#if !defined(_LOCORE) && defined(_KERNEL) +extern struct multiboot_header *Multiboot_Header; +#endif /* !defined(_LOCORE) && defined(_KERNEL) */ + +/* --------------------------------------------------------------------- */ + +/* + * Multiboot information structure. + */ +#define MULTIBOOT_INFO_MAGIC 0x2BADB002 +#define MULTIBOOT_INFO_HAS_MEMORY 0x00000001 +#define MULTIBOOT_INFO_HAS_BOOT_DEVICE 0x00000002 +#define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004 +#define MULTIBOOT_INFO_HAS_MODS 0x00000008 +#define MULTIBOOT_INFO_HAS_AOUT_SYMS 0x00000010 +#define MULTIBOOT_INFO_HAS_ELF_SYMS 0x00000020 +#define MULTIBOOT_INFO_HAS_MMAP 0x00000040 +#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080 +#define MULTIBOOT_INFO_HAS_CONFIG_TABLE 0x00000100 +#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200 +#define MULTIBOOT_INFO_HAS_APM_TABLE 0x00000400 +#define MULTIBOOT_INFO_HAS_VBE 0x00000800 + +#if !defined(_LOCORE) +struct multiboot_info { + uint32_t mi_flags; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */ + uint32_t mi_mem_lower; + uint32_t mi_mem_upper; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */ + uint8_t mi_boot_device_part3; + uint8_t mi_boot_device_part2; + uint8_t mi_boot_device_part1; + uint8_t mi_boot_device_drive; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */ + char * mi_cmdline; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */ + uint32_t mi_mods_count; + vaddr_t mi_mods_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */ + uint32_t mi_elfshdr_num; + uint32_t mi_elfshdr_size; + vaddr_t mi_elfshdr_addr; + uint32_t mi_elfshdr_shndx; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */ + uint32_t mi_mmap_length; + vaddr_t mi_mmap_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */ + uint32_t mi_drives_length; + vaddr_t mi_drives_addr; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */ + void * unused_mi_config_table; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */ + char * mi_loader_name; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */ + void * unused_mi_apm_table; + + /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */ + void * unused_mi_vbe_control_info; + void * unused_mi_vbe_mode_info; + paddr_t unused_mi_vbe_interface_seg; + paddr_t unused_mi_vbe_interface_off; + uint32_t unused_mi_vbe_interface_len; +}; + +/* --------------------------------------------------------------------- */ + +/* + * Drive information. This describes an entry in the drives table as + * pointed to by mi_drives_addr. + */ +struct multiboot_drive { + uint32_t md_length; + uint8_t md_number; + uint8_t md_mode; + uint16_t md_cylinders; + uint8_t md_heads; + uint8_t md_sectors; + + /* The variable-sized 'ports' field comes here, so this structure + * can be longer. */ +}; + +/* --------------------------------------------------------------------- */ + +/* + * Memory mapping. This describes an entry in the memory mappings table + * as pointed to by mi_mmap_addr. + * + * Be aware that mm_size specifies the size of all other fields *except* + * for mm_size. In order to jump between two different entries, you + * have to count mm_size + 4 bytes. + */ +struct multiboot_mmap { + uint32_t mm_size; + uint64_t mm_base_addr; + uint64_t mm_length; + uint32_t mm_type; +}; + +/* + * Modules. This describes an entry in the modules table as pointed + * to by mi_mods_addr. + */ + +struct multiboot_module { + uint32_t mmo_start; + uint32_t mmo_end; + char * mmo_string; + uint32_t mmo_reserved; +}; + +#endif /* !defined(_LOCORE) */ + +/* --------------------------------------------------------------------- */ + +/* + * Prototypes for public functions defined in multiboot.c. + */ +#if !defined(_LOCORE) && defined(_KERNEL) +void multiboot_pre_reloc(struct multiboot_info *); +void multiboot_post_reloc(void); +void multiboot_print_info(void); +bool multiboot_ksyms_addsyms_elf(void); +#endif /* !defined(_LOCORE) */ + +/* --------------------------------------------------------------------- */ +#else /* !defined(_KERNEL) && defined(_STANDALONE) */ +/* LSC FIXME: OLD MINIX DEFINITION: should be removed and replace with + definition above... */ #define MULTIBOOT_HEADER_MAGIC 0x1BADB002 #define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 @@ -140,4 +347,5 @@ struct multiboot_mmap_entry typedef struct multiboot_mmap_entry multiboot_memory_map_t; #endif /* __ASSEMBLY__ */ +#endif /* !defined(_KERNEL) && defined(_STANDALONE) */ #endif /* __MULTIBOOT_H__ */ diff --git a/sys/arch/i386/include/types.h b/sys/arch/i386/include/types.h index e33bb2c21..a3f34b1b1 100644 --- a/sys/arch/i386/include/types.h +++ b/sys/arch/i386/include/types.h @@ -1,4 +1,4 @@ -/* $NetBSD: types.h,v 1.70 2010/12/22 04:15:02 christos Exp $ */ +/* $NetBSD: types.h,v 1.74 2011/07/06 18:46:04 dyoung Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -101,7 +101,7 @@ typedef volatile unsigned char __cpu_simple_lock_t; /* The x86 does not have strict alignment requirements. */ #define __NO_STRICT_ALIGNMENT -#define __HAVE_DEVICE_REGISTER +#define __HAVE_NEW_STYLE_BUS_H #define __HAVE_CPU_DATA_FIRST #define __HAVE_CPU_COUNTER #define __HAVE_MD_CPU_OFFLINE @@ -112,6 +112,12 @@ typedef volatile unsigned char __cpu_simple_lock_t; #define __HAVE_ATOMIC_AS_MEMBAR #define __HAVE_CPU_LWP_SETPRIVATE #define __HAVE_INTR_CONTROL +#define __HAVE_MM_MD_OPEN +#define __HAVE___LWP_GETPRIVATE_FAST +#if !defined(__minix) +#define __HAVE_TLS_VARIANT_II +#endif /* !defined(__minix) */ +#define __HAVE_COMMON___TLS_GET_ADDR #if defined(_KERNEL) #define __HAVE_RAS diff --git a/sys/arch/i386/stand/boot/Makefile.boot b/sys/arch/i386/stand/boot/Makefile.boot index e3abdb857..7c29dba74 100644 --- a/sys/arch/i386/stand/boot/Makefile.boot +++ b/sys/arch/i386/stand/boot/Makefile.boot @@ -33,11 +33,13 @@ BINMODE=444 .PATH: ${.CURDIR}/.. ${.CURDIR}/../../lib -# MINIX LSC seems to be still needed -#LDFLAGS+= -nostdlib -Wl,-N -Wl,-e,boot_start -LDFLAGS+= -nostdlib -Wl,-N -Wl,-e,boot_start -L${DESTDIR}/${LIBDIR} +LDFLAGS+= -nostdlib -Wl,-N -Wl,-e,boot_start CPPFLAGS+= -I ${.CURDIR}/.. -I ${.CURDIR}/../../lib -I ${S}/lib/libsa CPPFLAGS+= -I ${.OBJDIR} +.if defined(__MINIX) +CPPFLAGS+=-isystem ${DESTDIR}/usr/include +CPPFLAGS+= -D_MINIX +.endif # defined(__MINIX) # Make sure we override any optimization options specified by the user COPTS= -Os @@ -57,10 +59,6 @@ COPTS+= -ffreestanding CFLAGS+= -Wall -Wmissing-prototypes -Wstrict-prototypes CPPFLAGS+= -nostdinc -D_STANDALONE CPPFLAGS+= -I$S -.if defined(__MINIX) -CPPFLAGS+= -I${DESTDIR}/usr/include -CPPFLAGS+= -I${.CURDIR}/../../../../../../ -.endif CPPFLAGS+= -DSUPPORT_PS2 CPPFLAGS+= -DDIRECT_SERIAL @@ -127,8 +125,8 @@ KERN_AS= library .include "${S}/lib/libkern/Makefile.inc" LIBKERN= ${KERNLIB} .else -# MINIX -LIBKERN= # use MINIX minc +# use MINIX minc +LIBKERN= ${DESTDIR}/usr/lib/libminc.a .endif ### find out what to use for libz @@ -153,11 +151,10 @@ vers.c: ${VERSIONFILE} ${SOURCES} ${LIBLIST} ${.CURDIR}/../Makefile.boot # Anything that calls 'real_to_prot' must have a %pc < 0x10000. # We link the program, find the callers (all in libi386), then # explicitly pull in the required objects before any other library code. -# MINIX (LSC adding LDADD still needed?) ${PROG}: ${OBJS} ${LIBLIST} ${.CURDIR}/../Makefile.boot ${_MKTARGET_LINK} bb="$$( ${CC} -o ${PROG}.syms ${LDFLAGS} -Wl,-Ttext,0 -Wl,-cref \ - ${OBJS} ${LIBLIST} ${LDADD} | ( \ + ${OBJS} ${LIBLIST} | ( \ while read symbol file; do \ [ -z "$$file" ] && continue; \ [ "$$symbol" = real_to_prot ] && break; \ @@ -173,7 +170,7 @@ ${PROG}: ${OBJS} ${LIBLIST} ${.CURDIR}/../Makefile.boot done; \ ) )"; \ ${CC} -o ${PROG}.syms ${LDFLAGS} -Wl,-Ttext,0 \ - -Wl,-Map,${PROG}.map -Wl,-cref ${OBJS} $$bb ${LIBLIST} ${LDADD} + -Wl,-Map,${PROG}.map -Wl,-cref ${OBJS} $$bb ${LIBLIST} ${OBJCOPY} -O binary ${PROG}.syms ${PROG} .ifndef __MINIX diff --git a/sys/arch/i386/stand/boot/biosboot/Makefile b/sys/arch/i386/stand/boot/biosboot/Makefile index 2239257ff..135d44c39 100644 --- a/sys/arch/i386/stand/boot/biosboot/Makefile +++ b/sys/arch/i386/stand/boot/biosboot/Makefile @@ -1,10 +1,6 @@ # $NetBSD: Makefile,v 1.3 2005/12/11 12:17:48 christos Exp $ -# MINIX (LSC this still needed?) -# Adding cleaning of specific target? -D_MINIX is not defined at top level ? +# LSC FIXME: Why change the name? PROG= boot_monitor -CLEANFILES= lib - -CPPFLAGS+= -D_MINIX .include <../Makefile.boot> diff --git a/sys/arch/i386/stand/boot/boot2.c b/sys/arch/i386/stand/boot/boot2.c index 695f6215c..b7d244db6 100644 --- a/sys/arch/i386/stand/boot/boot2.c +++ b/sys/arch/i386/stand/boot/boot2.c @@ -1,4 +1,4 @@ -/* $NetBSD: boot2.c,v 1.57 2011/12/25 06:09:09 tsutsui Exp $ */ +/* $NetBSD: boot2.c,v 1.58 2012/08/04 03:51:27 riastradh Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -122,7 +122,9 @@ void command_dev(char *); void command_consdev(char *); void command_modules(char *); void command_multiboot(char *); +#ifdef __minix void command_load_mods(char *); +#endif const struct bootblk_command commands[] = { { "help", command_help }, @@ -134,7 +136,9 @@ const struct bootblk_command commands[] = { { "consdev", command_consdev }, { "modules", command_modules }, { "load", module_add }, +#ifdef __minix { "load_mods", command_load_mods }, +#endif { "multiboot", command_multiboot }, { "vesa", command_vesa }, { "splash", splash_add }, @@ -405,7 +409,9 @@ command_help(char *arg) "vesa {modenum|on|off|enabled|disabled|list}\n" "modules {on|off|enabled|disabled}\n" "load {path_to_module}\n" +#ifdef __minix "load_mods {path_to_modules}, pattern might be used\n" +#endif "multiboot [xdNx:][filename] []\n" "userconf {command}\n" "rndseed {path_to_rndseed_file}\n" @@ -419,10 +425,15 @@ command_ls(char *arg) const char *save = default_filename; default_filename = "/"; +#ifndef __minix + ls(arg); +#else ls(arg, NULL); +#endif default_filename = save; } +#ifdef __minix void command_load_mods(char *arg) { @@ -432,6 +443,7 @@ command_load_mods(char *arg) ls(arg, module_add); default_filename = save; } +#endif /* ARGSUSED */ void @@ -449,10 +461,21 @@ void command_boot(char *arg) { char *filename; - int howto; + int howto, tell; + + if (!parseboot(arg, &filename, &howto)) + return; - if (parseboot(arg, &filename, &howto)) - bootit(filename, howto, (howto & AB_VERBOSE) != 0); + tell = ((howto & AB_VERBOSE) != 0); + if (filename != NULL) { + bootit(filename, howto, tell); + } else { + int i; + for (i = 0; i < NUMNAMES; i++) { + bootit(names[i][0], howto, tell); + bootit(names[i][1], howto, tell); + } + } } void diff --git a/sys/arch/i386/stand/boot/conf.c b/sys/arch/i386/stand/boot/conf.c index fa45ac269..dccc9dfa8 100644 --- a/sys/arch/i386/stand/boot/conf.c +++ b/sys/arch/i386/stand/boot/conf.c @@ -1,4 +1,4 @@ -/* $NetBSD: conf.c,v 1.5 2008/04/05 18:21:34 tsutsui Exp $ */ +/* $NetBSD: conf.c,v 1.6 2012/01/16 18:46:20 christos Exp $ */ /* * Copyright (c) 1997 diff --git a/sys/arch/i386/stand/bootxx/Makefile b/sys/arch/i386/stand/bootxx/Makefile index 7eb3730f6..2704f05f5 100644 --- a/sys/arch/i386/stand/bootxx/Makefile +++ b/sys/arch/i386/stand/bootxx/Makefile @@ -1,20 +1,16 @@ # $NetBSD: Makefile,v 1.14 2010/12/29 17:44:03 jakllsch Exp $ -SUBDIR= -#SUBDIR= bootxx_ffsv1 .WAIT bootxx_ffsv2 bootxx_lfsv1 bootxx_lfsv2 -#SUBDIR+=bootxx_msdos bootxx_ustarfs +.if defined(__MINIX) +SUBDIR= bootxx_minixfs3 +.else +SUBDIR= bootxx_ffsv1 .WAIT bootxx_ffsv2 bootxx_lfsv1 bootxx_lfsv2 +SUBDIR+=bootxx_msdos bootxx_ustarfs +.endif # defined(__MINIX) # Ext2fs doesn't have enough free space (it has only 1KB) # to store this primary bootloader, but we can put it into # an independent small 'boot' partition as NetBSD/hp300 does. -# -# However MINIX implements a solution using the empty space before subpartition -.if !empty(CC:M*pcc) -# PCC cannot compile bootxx_ext2fs because it lacks regparm aka compactcall -SUBDIR+=bootxx_minixfs3 -.else -SUBDIR+=bootxx_ext2fs bootxx_minixfs3 -.endif +SUBDIR+=bootxx_ext2fs LIBOBJ= ${.OBJDIR} .MAKEOVERRIDES+= LIBOBJ diff --git a/sys/arch/i386/stand/bootxx/Makefile.bootxx b/sys/arch/i386/stand/bootxx/Makefile.bootxx index 269c9b55e..37d4a6186 100644 --- a/sys/arch/i386/stand/bootxx/Makefile.bootxx +++ b/sys/arch/i386/stand/bootxx/Makefile.bootxx @@ -38,7 +38,7 @@ BINMODE=444 .PATH: ${.CURDIR}/.. ${.CURDIR}/../../lib -LDFLAGS+= -nostdlib -Wl,-N -Wl,-e,start -L${DESTDIR}/${LIBDIR} +LDFLAGS+= -nostdlib -Wl,-N -Wl,-e,start CPPFLAGS+= -DBOOTXX # CPPFLAGS+= -D__daddr_t=int32_t CPPFLAGS+= -I ${.CURDIR}/../../lib -I ${.OBJDIR} @@ -50,16 +50,12 @@ CPPFLAGS+= -DXXfs_close=${FS}_close CPPFLAGS+= -DXXfs_read=${FS}_read CPPFLAGS+= -DXXfs_stat=${FS}_stat CPPFLAGS+= -DFS=${FS} -# clang generates too big bootxx_xxx -.if !empty(CC:M*clang) -CPPFLAGS+= -Os -.endif # CPPFLAGS+= -DBOOT_MSG_COM0 # Make sure we override any optimization options specified by the user -#.include "${.PARSEDIR}/../Makefile.inc" -#COPTS= ${OPT_SIZE.${ACTIVE_CC}} -#DBG= +.include "${.PARSEDIR}/../Makefile.inc" +COPTS= ${OPT_SIZE.${ACTIVE_CC}} +DBG= CPPFLAGS+= -DNO_LBA_CHECK @@ -77,10 +73,6 @@ CPUFLAGS= -march=i386 -mtune=i386 CFLAGS+= -Wall -Wmissing-prototypes -Wstrict-prototypes CPPFLAGS+= -nostdinc -D_STANDALONE CPPFLAGS+= -I$S -.if defined(__MINIX) -CPPFLAGS+= -I${DESTDIR}/usr/include -CPPFLAGS+= -I${.CURDIR}/../../../../../../ -.endif CPPFLAGS+= -DLIBSA_SINGLE_FILESYSTEM=xxfs \ -DLIBSA_NO_TWIDDLE \ @@ -123,6 +115,9 @@ SA_AS= library SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes" .if defined(__MINIX) SAMISCMAKEFLAGS+="SA_INCLUDE_NET=no" +CPPFLAGS+= -isystem ${DESTDIR}/usr/include +CPPFLAGS+= -D_MINIX +AFLAGS+= -Wa,--divide .endif .include "${S}/lib/libsa/Makefile.inc" LIBSA= ${SALIB} @@ -133,10 +128,11 @@ KERN_AS= library .include "${S}/lib/libkern/Makefile.inc" LIBKERN= ${KERNLIB} .else -# MINIX -LIBKERN= # use MINIX minc +# use MINIX minc +LIBKERN= ${DESTDIR}/usr/lib/libminc.a .endif + cleandir distclean: .WAIT cleanlibdir cleanlibdir: @@ -149,7 +145,7 @@ CLEANFILES+= ${PROG}.sym ${PROG}.map ${PROG}: ${OBJS} ${LIBLIST} ${_MKTARGET_LINK} ${CC} -o ${PROG}.sym ${LDFLAGS} -Wl,-Ttext,${PRIMARY_LOAD_ADDRESS} \ - -Wl,-Map,${PROG}.map -Wl,-cref ${OBJS} ${LIBLIST} ${LDADD} + -Wl,-Map,${PROG}.map -Wl,-cref ${OBJS} ${LIBLIST} ${OBJCOPY} -O binary ${PROG}.sym ${PROG} @ sz=$$(${TOOL_STAT} -f '%z' ${PROG}); \ if [ "$$sz" -gt "${BOOTXX_MAXSIZE}" ]; then \ diff --git a/sys/arch/i386/stand/bootxx/boot1.c b/sys/arch/i386/stand/bootxx/boot1.c index 8e1d73903..e2bee21c0 100644 --- a/sys/arch/i386/stand/bootxx/boot1.c +++ b/sys/arch/i386/stand/bootxx/boot1.c @@ -130,13 +130,12 @@ boot1(uint32_t biosdev, uint64_t *sector) done: /* if we fail here, so will fstat, so keep going */ - if (fd == -1 || fstat(fd, &sb) == -1) { + if (fd == -1 || fstat(fd, &sb) == -1) #ifndef __minix return "Can't open /boot\r\n"; #else return "Can't open /boot_monitor\r\n"; #endif - } biosdev = (uint32_t)sb.st_size; #if 0 @@ -144,21 +143,19 @@ done: return "/boot too large\r\n"; #endif - if (read(fd, (void *)SECONDARY_LOAD_ADDRESS, biosdev) != biosdev) { + if (read(fd, (void *)SECONDARY_LOAD_ADDRESS, biosdev) != biosdev) #ifndef __minix return "/boot load failed\r\n"; #else return "/boot_monitor load failed\r\n"; #endif - } - if (*(uint32_t *)(SECONDARY_LOAD_ADDRESS + 4) != X86_BOOT_MAGIC_2) { + if (*(uint32_t *)(SECONDARY_LOAD_ADDRESS + 4) != X86_BOOT_MAGIC_2) #ifndef __minix return "Invalid /boot file format\r\n"; #else return "Invalid /boot_monitor file format\r\n"; #endif - } /* We need to jump to the secondary bootstrap in realmode */ return 0; diff --git a/sys/arch/i386/stand/bootxx/bootxx.S b/sys/arch/i386/stand/bootxx/bootxx.S index 3bed04f6e..ead430c41 100644 --- a/sys/arch/i386/stand/bootxx/bootxx.S +++ b/sys/arch/i386/stand/bootxx/bootxx.S @@ -90,7 +90,7 @@ boot_params: /* space for patchable variables */ pop %ecx movl $boot_params, %esi orb $X86_BP_FLAGS_LBA64VALID, 4(%esi) - lcall $SECONDARY_LOAD_ADDRESS >> 4, $0 + lcall $SECONDARY_LOAD_ADDRESS/16, $0 boot_fail: push %ax /* error string from boot1 */ diff --git a/sys/arch/i386/stand/bootxx/bootxx_ext2fs/Makefile b/sys/arch/i386/stand/bootxx/bootxx_ext2fs/Makefile index f84710be3..6486276ac 100644 --- a/sys/arch/i386/stand/bootxx/bootxx_ext2fs/Makefile +++ b/sys/arch/i386/stand/bootxx/bootxx_ext2fs/Makefile @@ -1,8 +1,5 @@ # $NetBSD: Makefile,v 1.1 2010/09/11 13:06:37 tsutsui Exp $ FS=ext2fs -CLEANFILES= lib -CPPFLAGS+= -D_MINIX -CFLAGS+= -Os .include <../Makefile.bootxx> diff --git a/sys/arch/i386/stand/bootxx/bootxx_minixfs3/Makefile b/sys/arch/i386/stand/bootxx/bootxx_minixfs3/Makefile index 6efd05e92..4519c4c51 100644 --- a/sys/arch/i386/stand/bootxx/bootxx_minixfs3/Makefile +++ b/sys/arch/i386/stand/bootxx/bootxx_minixfs3/Makefile @@ -2,7 +2,6 @@ PROG=bootxx_minixfs3 FS=minixfs3 -CLEANFILES= lib MINIX3_FIRST_SUBP_OFFSET=32 diff --git a/sys/arch/i386/stand/cdboot/Makefile b/sys/arch/i386/stand/cdboot/Makefile index c2fafa4ca..09704f161 100644 --- a/sys/arch/i386/stand/cdboot/Makefile +++ b/sys/arch/i386/stand/cdboot/Makefile @@ -7,6 +7,10 @@ AFLAGS.cdboot.S= ${${ACTIVE_CC} == "clang":?-no-integrated-as:} NOMAN= # defined .include +.if defined(__MINIX) +AFLAGS+= -Wa,--divide +.endif + STRIPFLAG= # nothing LIBCRT0= # nothing @@ -41,8 +45,6 @@ BUILDSYMLINKS+= $S/arch/i386/include machine \ DPSRCS+= machine x86 -AFLAGS+= -Wa,--divide - CLEANFILES+= ${PROG}.tmp ${PROG}: ${OBJS} diff --git a/sys/arch/i386/stand/lib/biosdisk.c b/sys/arch/i386/stand/lib/biosdisk.c index 13701c722..1f75e0f2e 100644 --- a/sys/arch/i386/stand/lib/biosdisk.c +++ b/sys/arch/i386/stand/lib/biosdisk.c @@ -1,4 +1,4 @@ -/* $NetBSD: biosdisk.c,v 1.39 2011/09/21 08:57:12 gsutre Exp $ */ +/* $NetBSD: biosdisk.c,v 1.42 2012/07/03 15:24:37 tsutsui Exp $ */ /* * Copyright (c) 1996, 1998 @@ -316,7 +316,9 @@ read_gpt(struct biosdisk *d) gptsector[0] = GPT_HDR_BLKNO; if (set_geometry(&d->ll, &ed) == 0 && d->ll.flags & BIOSDISK_INT13EXT) { gptsector[1] = ed.totsec - 1; - d->ll.secsize = ed.sbytes; + /* Sanity check values returned from BIOS */ + if (ed.sbytes >= 512 && (ed.sbytes & (ed.sbytes - 1)) == 0) + d->ll.secsize = ed.sbytes; } else { #ifdef DISK_DEBUG printf("Unable to determine extended disk geometry - " @@ -414,7 +416,7 @@ read_minix_subp(struct biosdisk *d, struct disklabel* dflt_lbl, if (readsects(&d->ll, sector, 1, d->buf, 0)) { #ifdef DISK_DEBUG - printf("Error reading MFS sector %d\n", sector); + printf("Error reading MFS sector %"PRId64"\n", sector); #endif return EIO; } @@ -443,10 +445,11 @@ read_label(struct biosdisk *d) struct disklabel dflt_lbl; struct mbr_partition mbr[MBR_PART_COUNT]; struct partition *p; - int sector, i; + uint32_t sector; + int i; int error; int typ; - int ext_base, this_ext, next_ext; + uint32_t ext_base, this_ext, next_ext; #ifdef COMPAT_386BSD_MBRPART int sector_386bsd = -1; #endif @@ -471,7 +474,7 @@ read_label(struct biosdisk *d) next_ext = 0; if (readsects(&d->ll, this_ext, 1, d->buf, 0)) { #ifdef DISK_DEBUG - printf("error reading MBR sector %d\n", this_ext); + printf("error reading MBR sector %u\n", this_ext); #endif return EIO; } @@ -484,7 +487,7 @@ read_label(struct biosdisk *d) continue; sector = this_ext + mbr[i].mbrp_start; #ifdef DISK_DEBUG - printf("ptn type %d in sector %d\n", typ, sector); + printf("ptn type %d in sector %u\n", typ, sector); #endif if (typ == MBR_PTYPE_MINIX_14B) { if (!read_minix_subp(d, &dflt_lbl, diff --git a/sys/arch/i386/stand/lib/conio.S b/sys/arch/i386/stand/lib/conio.S index 3f62ec15f..7b8ea82b5 100644 --- a/sys/arch/i386/stand/lib/conio.S +++ b/sys/arch/i386/stand/lib/conio.S @@ -45,6 +45,7 @@ ENTRY(conputc) call _C_LABEL(prot_to_real) # enter real mode .code16 +#if defined(__minix) cmp $0x08, %al # backspace? jne print_char @@ -65,10 +66,13 @@ ENTRY(conputc) jmp do_int print_char: +#endif /* defined(__minix) */ movw $1,%bx - movb $0x0e,%ah # print character + movb $0x0e,%ah movb %al, %cl +#if defined(__minix) do_int: +#endif /* defined(__minix) */ int $0x10 calll _C_LABEL(real_to_prot) # back to protected mode @@ -89,12 +93,12 @@ ENTRY(congetc) movb $0x0,%ah int $0x16 - movw %ax,%bx + movb %al,%bl calll _C_LABEL(real_to_prot) # back to protected mode .code32 - movw %bx, 28(%esp) + movb %bl, 28(%esp) popa ret diff --git a/sys/arch/i386/stand/lib/exec.c b/sys/arch/i386/stand/lib/exec.c index 8a283557b..537dedf17 100644 --- a/sys/arch/i386/stand/lib/exec.c +++ b/sys/arch/i386/stand/lib/exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.49 2011/11/28 07:56:54 tls Exp $ */ +/* $NetBSD: exec.c,v 1.50 2012/05/21 21:34:16 dsl Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -297,11 +297,13 @@ common_load_kernel(const char *file, u_long *basemem, u_long *extmem, close(fd); - /* Now we know the root fs type, load modules for it. */ + /* If the root fs type is unusual, load its module. */ if (fsmod != NULL) module_add(fsmod); +#if defined(__minix) if (fsmod !=NULL && fsmod2 != NULL && strcmp(fsmod, fsmod2) != 0) module_add(fsmod2); +#endif /* defined(__minix) */ /* * Gather some information for the kernel. Do this after the diff --git a/sys/arch/i386/stand/lib/libi386.h b/sys/arch/i386/stand/lib/libi386.h index 6f28e6274..a0a8cccf7 100644 --- a/sys/arch/i386/stand/lib/libi386.h +++ b/sys/arch/i386/stand/lib/libi386.h @@ -91,9 +91,11 @@ struct bootblk_command { void (*c_fn)(char *); }; void bootmenu(void); -void prompt(int); void docommand(char *); +#if defined(__minix) void editline(char *, size_t, char *); +void prompt(int); +#endif /* in "user code": */ void command_help(char *); @@ -116,7 +118,9 @@ int coniskey(void); __compactcall void conputc(int); void conclr(void); +#if defined(__minix) int getchar_ex(void); +#endif int getextmem2(int *); __compactcall int getextmemps2(void *); diff --git a/sys/arch/i386/stand/lib/menuutils.c b/sys/arch/i386/stand/lib/menuutils.c index f613e3054..a80e52a42 100644 --- a/sys/arch/i386/stand/lib/menuutils.c +++ b/sys/arch/i386/stand/lib/menuutils.c @@ -69,6 +69,7 @@ prompt(int allowreturn) for (;;) { char *c = input; + input[0] = '\0'; printf("> "); editline(input, sizeof(input), NULL); diff --git a/sys/arch/i386/stand/libsa/getopt.c b/sys/arch/i386/stand/libsa/getopt.c new file mode 100644 index 000000000..62b726c65 --- /dev/null +++ b/sys/arch/i386/stand/libsa/getopt.c @@ -0,0 +1,106 @@ +/* $NetBSD: getopt.c,v 1.5 2009/03/14 15:36:08 dsl Exp $ */ + +/* + * Copyright (c) 1987, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* from: netbsd:lib/libc/stdlib/getopt.c */ + +#include +#include + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int +getopt(int nargc, char * const *nargv, const char *ostr) +{ + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (-1); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (optopt == (int)'-') + return (-1); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + printf("illegal option -- %c\n", optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + printf("option requires an argument -- %c\n", + optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} diff --git a/sys/arch/i386/stand/libsa/nfs.c b/sys/arch/i386/stand/libsa/nfs.c new file mode 100644 index 000000000..49e59371a --- /dev/null +++ b/sys/arch/i386/stand/libsa/nfs.c @@ -0,0 +1,641 @@ +/* $NetBSD: nfs.c,v 1.19 2011/12/25 06:09:09 tsutsui Exp $ */ + +/*- + * Copyright (c) 1993 John Brezak + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#ifdef _STANDALONE +#include +#else +#include +#endif + +#include +#include + +#include "rpcv2.h" +#include "nfsv2.h" + +#include +#include "net.h" +#include "netif.h" +#include "nfs.h" +#include "rpc.h" + +/* Define our own NFS attributes. */ +struct nfsv2_fattrs { + n_long fa_type; + n_long fa_mode; + n_long fa_nlink; + n_long fa_uid; + n_long fa_gid; + n_long fa_size; + n_long fa_blocksize; + n_long fa_rdev; + n_long fa_blocks; + n_long fa_fsid; + n_long fa_fileid; + struct nfsv2_time fa_atime; + struct nfsv2_time fa_mtime; + struct nfsv2_time fa_ctime; +}; + + +struct nfs_read_args { + u_char fh[NFS_FHSIZE]; + n_long off; + n_long len; + n_long xxx; /* XXX what's this for? */ +}; + +/* Data part of nfs rpc reply (also the largest thing we receive) */ +#define NFSREAD_SIZE 1024 +struct nfs_read_repl { + n_long errno; + struct nfsv2_fattrs fa; + n_long count; + u_char data[NFSREAD_SIZE]; +}; + +#ifndef NFS_NOSYMLINK +struct nfs_readlnk_repl { + n_long errno; + n_long len; + char path[NFS_MAXPATHLEN]; +}; +#endif + +struct nfs_iodesc { + struct iodesc *iodesc; + off_t off; + u_char fh[NFS_FHSIZE]; + struct nfsv2_fattrs fa; /* all in network order */ +}; + +int nfs_getrootfh(struct iodesc *, char *, u_char *); +int nfs_lookupfh(struct nfs_iodesc *, const char *, int, + struct nfs_iodesc *); +#ifndef NFS_NOSYMLINK +int nfs_readlink(struct nfs_iodesc *, char *); +#endif +ssize_t nfs_readdata(struct nfs_iodesc *, off_t, void *, size_t); + +/* + * Fetch the root file handle (call mount daemon) + * Return zero or error number. + */ +int +nfs_getrootfh(struct iodesc *d, char *path, u_char *fhp) +{ + size_t len; + struct args { + n_long len; + char path[FNAME_SIZE]; + } *args; + struct repl { + n_long errno; + u_char fh[NFS_FHSIZE]; + } *repl; + struct { + n_long h[RPC_HEADER_WORDS]; + struct args d; + } sdata; + struct { + n_long h[RPC_HEADER_WORDS]; + struct repl d; + } rdata; + ssize_t cc; + +#ifdef NFS_DEBUG + if (debug) + printf("nfs_getrootfh: %s\n", path); +#endif + + args = &sdata.d; + repl = &rdata.d; + + memset(args, 0, sizeof(*args)); + len = strlen(path); + if (len > sizeof(args->path)) + len = sizeof(args->path); + args->len = htonl(len); + memcpy(args->path, path, len); + len = 4 + roundup(len, 4); + + cc = rpc_call(d, RPCPROG_MNT, RPCMNT_VER1, RPCMNT_MOUNT, + args, len, repl, sizeof(*repl)); + if (cc == -1) { + /* errno was set by rpc_call */ + return (errno); + } + if (cc < 4) + return (EBADRPC); + if (repl->errno) + return (ntohl(repl->errno)); + memcpy(fhp, repl->fh, sizeof(repl->fh)); + return (0); +} + +/* + * Lookup a file. Store handle and attributes. + * Return zero or error number. + */ +int +nfs_lookupfh(struct nfs_iodesc *d, const char *name, int len, struct nfs_iodesc *newfd) +{ + int rlen; + struct args { + u_char fh[NFS_FHSIZE]; + n_long len; + char name[FNAME_SIZE]; + } *args; + struct repl { + n_long errno; + u_char fh[NFS_FHSIZE]; + struct nfsv2_fattrs fa; + } *repl; + struct { + n_long h[RPC_HEADER_WORDS]; + struct args d; + } sdata; + struct { + n_long h[RPC_HEADER_WORDS]; + struct repl d; + } rdata; + ssize_t cc; + +#ifdef NFS_DEBUG + if (debug) + printf("lookupfh: called\n"); +#endif + + args = &sdata.d; + repl = &rdata.d; + + memset(args, 0, sizeof(*args)); + memcpy(args->fh, d->fh, sizeof(args->fh)); + if ((size_t)len > sizeof(args->name)) + len = sizeof(args->name); + memcpy(args->name, name, len); + args->len = htonl(len); + len = 4 + roundup(len, 4); + len += NFS_FHSIZE; + + rlen = sizeof(*repl); + + cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_LOOKUP, + args, len, repl, rlen); + if (cc == -1) + return (errno); /* XXX - from rpc_call */ + if (cc < 4) + return (EIO); + if (repl->errno) { + /* saerrno.h now matches NFS error numbers. */ + return (ntohl(repl->errno)); + } + memcpy(&newfd->fh, repl->fh, sizeof(newfd->fh)); + memcpy(&newfd->fa, &repl->fa, sizeof(newfd->fa)); + return (0); +} + +#ifndef NFS_NOSYMLINK +/* + * Get the destination of a symbolic link. + */ +int +nfs_readlink(struct nfs_iodesc *d, char *buf) +{ + struct { + n_long h[RPC_HEADER_WORDS]; + u_char fh[NFS_FHSIZE]; + } sdata; + struct { + n_long h[RPC_HEADER_WORDS]; + struct nfs_readlnk_repl d; + } rdata; + ssize_t cc; + +#ifdef NFS_DEBUG + if (debug) + printf("readlink: called\n"); +#endif + + memcpy(sdata.fh, d->fh, NFS_FHSIZE); + cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READLINK, + sdata.fh, NFS_FHSIZE, + &rdata.d, sizeof(rdata.d)); + if (cc == -1) + return (errno); + + if (cc < 4) + return (EIO); + + if (rdata.d.errno) + return (ntohl(rdata.d.errno)); + + rdata.d.len = ntohl(rdata.d.len); + if (rdata.d.len > NFS_MAXPATHLEN) + return (ENAMETOOLONG); + + memcpy(buf, rdata.d.path, rdata.d.len); + buf[rdata.d.len] = 0; + return (0); +} +#endif + +/* + * Read data from a file. + * Return transfer count or -1 (and set errno) + */ +ssize_t +nfs_readdata(struct nfs_iodesc *d, off_t off, void *addr, size_t len) +{ + struct nfs_read_args *args; + struct nfs_read_repl *repl; + struct { + n_long h[RPC_HEADER_WORDS]; + struct nfs_read_args d; + } sdata; + struct { + n_long h[RPC_HEADER_WORDS]; + struct nfs_read_repl d; + } rdata; + ssize_t cc; + long x; + int hlen, rlen; + + args = &sdata.d; + repl = &rdata.d; + + memcpy(args->fh, d->fh, NFS_FHSIZE); + args->off = htonl((n_long)off); + if (len > NFSREAD_SIZE) + len = NFSREAD_SIZE; + args->len = htonl((n_long)len); + args->xxx = htonl((n_long)0); + hlen = sizeof(*repl) - NFSREAD_SIZE; + + cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READ, + args, sizeof(*args), + repl, sizeof(*repl)); + if (cc == -1) { + /* errno was already set by rpc_call */ + return (-1); + } + if (cc < hlen) { + errno = EBADRPC; + return (-1); + } + if (repl->errno) { + errno = ntohl(repl->errno); + return (-1); + } + rlen = cc - hlen; + x = ntohl(repl->count); + if (rlen < x) { + printf("nfsread: short packet, %d < %ld\n", rlen, x); + errno = EBADRPC; + return (-1); + } + memcpy(addr, repl->data, x); + return (x); +} + +/* + * Open a file. + * return zero or error number + */ +__compactcall int +nfs_open(const char *path, struct open_file *f) +{ + static struct nfs_iodesc nfs_root_node; + struct iodesc *desc; + struct nfs_iodesc *currfd; + const char *cp; +#ifndef NFS_NOSYMLINK + struct nfs_iodesc *newfd; + struct nfsv2_fattrs *fa; + const char *ncp; + int c; + char namebuf[NFS_MAXPATHLEN + 1]; + char linkbuf[NFS_MAXPATHLEN + 1]; + int nlinks = 0; +#endif + int error; + +#ifdef NFS_DEBUG + if (debug) + printf("nfs_open: %s\n", path); +#endif + if (!rootpath[0]) { + printf("no rootpath, no nfs\n"); + return (ENXIO); + } + + if (!(desc = socktodesc(*(int *)(f->f_devdata)))) + return (EINVAL); + + /* Bind to a reserved port. */ + desc->myport = htons(--rpc_port); + desc->destip = rootip; + if ((error = nfs_getrootfh(desc, rootpath, nfs_root_node.fh))) + return (error); + nfs_root_node.iodesc = desc; + +#ifndef NFS_NOSYMLINK + /* Fake up attributes for the root dir. */ + fa = &nfs_root_node.fa; + fa->fa_type = htonl(NFDIR); + fa->fa_mode = htonl(0755); + fa->fa_nlink = htonl(2); + + currfd = &nfs_root_node; + newfd = 0; + + cp = path; + while (*cp) { + /* + * Remove extra separators + */ + while (*cp == '/') + cp++; + + if (*cp == '\0') + break; + /* + * Check that current node is a directory. + */ + if (currfd->fa.fa_type != htonl(NFDIR)) { + error = ENOTDIR; + goto out; + } + + /* allocate file system specific data structure */ + newfd = alloc(sizeof(*newfd)); + newfd->iodesc = currfd->iodesc; + newfd->off = 0; + + /* + * Get next component of path name. + */ + { + int len = 0; + + ncp = cp; + while ((c = *cp) != '\0' && c != '/') { + if (++len > NFS_MAXNAMLEN) { + error = ENOENT; + goto out; + } + cp++; + } + } + + /* lookup a file handle */ + error = nfs_lookupfh(currfd, ncp, cp - ncp, newfd); + if (error) + goto out; + + /* + * Check for symbolic link + */ + if (newfd->fa.fa_type == htonl(NFLNK)) { + int link_len, len; + + error = nfs_readlink(newfd, linkbuf); + if (error) + goto out; + + link_len = strlen(linkbuf); + len = strlen(cp); + + if (link_len + len > MAXPATHLEN + || ++nlinks > MAXSYMLINKS) { + error = ENOENT; + goto out; + } + + memcpy(&namebuf[link_len], cp, len + 1); + memcpy(namebuf, linkbuf, link_len); + + /* + * If absolute pathname, restart at root. + * If relative pathname, restart at parent directory. + */ + cp = namebuf; + if (*cp == '/') { + if (currfd != &nfs_root_node) + dealloc(currfd, sizeof(*currfd)); + currfd = &nfs_root_node; + } + + dealloc(newfd, sizeof(*newfd)); + newfd = 0; + + continue; + } + + if (currfd != &nfs_root_node) + dealloc(currfd, sizeof(*currfd)); + currfd = newfd; + newfd = 0; + } + + error = 0; + +out: + if (newfd) + dealloc(newfd, sizeof(*newfd)); +#else + /* allocate file system specific data structure */ + currfd = alloc(sizeof(*currfd)); + currfd->iodesc = desc; + currfd->off = 0; + + cp = path; + /* + * Remove extra separators + */ + while (*cp == '/') + cp++; + + /* XXX: Check for empty path here? */ + + error = nfs_lookupfh(&nfs_root_node, cp, strlen(cp), currfd); +#endif + if (!error) { + f->f_fsdata = (void *)currfd; + fsmod = "nfs"; + return (0); + } + +#ifdef NFS_DEBUG + if (debug) + printf("nfs_open: %s lookupfh failed: %s\n", + path, strerror(error)); +#endif +#ifndef NFS_NOSYMLINK + if (currfd != &nfs_root_node) +#endif + dealloc(currfd, sizeof(*currfd)); + + return (error); +} + +__compactcall int +nfs_close(struct open_file *f) +{ + struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata; + +#ifdef NFS_DEBUG + if (debug) + printf("nfs_close: fp=0x%lx\n", (u_long)fp); +#endif + + if (fp) + dealloc(fp, sizeof(struct nfs_iodesc)); + f->f_fsdata = (void *)0; + + return (0); +} + +/* + * read a portion of a file + */ +__compactcall int +nfs_read(struct open_file *f, void *buf, size_t size, size_t *resid) + /* resid: out */ +{ + struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata; + ssize_t cc; + char *addr = buf; + +#ifdef NFS_DEBUG + if (debug) + printf("nfs_read: size=%lu off=%d\n", (u_long)size, + (int)fp->off); +#endif + while ((int)size > 0) { +#if !defined(LIBSA_NO_TWIDDLE) + twiddle(); +#endif + cc = nfs_readdata(fp, fp->off, (void *)addr, size); + /* XXX maybe should retry on certain errors */ + if (cc == -1) { +#ifdef NFS_DEBUG + if (debug) + printf("nfs_read: read: %s", strerror(errno)); +#endif + return (errno); /* XXX - from nfs_readdata */ + } + if (cc == 0) { +#ifdef NFS_DEBUG + if (debug) + printf("nfs_read: hit EOF unexpectantly"); +#endif + goto ret; + } + fp->off += cc; + addr += cc; + size -= cc; + } +ret: + if (resid) + *resid = size; + + return (0); +} + +/* + * Not implemented. + */ +__compactcall int +nfs_write(struct open_file *f, void *buf, size_t size, size_t *resid) + /* resid: out */ +{ + + return (EROFS); +} + +__compactcall off_t +nfs_seek(struct open_file *f, off_t offset, int where) +{ + struct nfs_iodesc *d = (struct nfs_iodesc *)f->f_fsdata; + n_long size = ntohl(d->fa.fa_size); + + switch (where) { + case SEEK_SET: + d->off = offset; + break; + case SEEK_CUR: + d->off += offset; + break; + case SEEK_END: + d->off = size - offset; + break; + default: + return (-1); + } + + return (d->off); +} + +/* NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5 */ +const int nfs_stat_types[8] = { + 0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, 0 }; + +__compactcall int +nfs_stat(struct open_file *f, struct stat *sb) +{ + struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata; + n_long ftype, mode; + + ftype = ntohl(fp->fa.fa_type); + mode = ntohl(fp->fa.fa_mode); + mode |= nfs_stat_types[ftype & 7]; + + sb->st_mode = mode; + sb->st_nlink = ntohl(fp->fa.fa_nlink); + sb->st_uid = ntohl(fp->fa.fa_uid); + sb->st_gid = ntohl(fp->fa.fa_gid); + sb->st_size = ntohl(fp->fa.fa_size); + + return (0); +} + +#if defined(LIBSA_ENABLE_LS_OP) +__compactcall void +nfs_ls(struct open_file *f, const char *pattern) +{ + printf("Currently ls command is unsupported by nfs\n"); + return; +} +#endif diff --git a/sys/arch/i386/stand/mbr/Makefile.mbr b/sys/arch/i386/stand/mbr/Makefile.mbr index 141545b64..a814751a6 100644 --- a/sys/arch/i386/stand/mbr/Makefile.mbr +++ b/sys/arch/i386/stand/mbr/Makefile.mbr @@ -25,25 +25,21 @@ BINMODE= 444 .PATH: ${.CURDIR}/.. LDFLAGS+= -nostdlib -Wl,-e,start -# MINIX LSC DO we need to remove the includes?? -CPPFLAGS+= -I. -I${.CURDIR}/../../lib #-I${S} +CPPFLAGS+= -I. -I${.CURDIR}/../../lib -I${S} +.if defined(__MINIX) CPPFLAGS+= -DLOADADDR=${LOADADDR} +AFLAGS+= -Wa,--divide +.endif .if ${MACHINE_ARCH} == "x86_64" LDFLAGS+= -Wl,-m,elf_i386 AFLAGS+= -m32 .endif -AFLAGS+= "-Wa,--divide" +BUILDSYMLINKS+= $S/arch/i386/include machine \ + $S/arch/x86/include x86 -# NetBSD can be compiled from a foreign host, MINIX do not. So commented out. -# Make sys/ a local thing for benefit of cross-compilers -#S= ${.CURDIR}/../../../../.. -#CPPFLAGS+= -I${S} -# And same for machine/; need a bit more work because of symlink -#BUILDSYMLINKS+= $S/arch/i386/include machine \ -# $S/arch/x86/include x86 -#DPSRCS+= machine x86 +DPSRCS+= machine x86 CLEANFILES+= ${PROG}.tmp diff --git a/sys/compat/sys/syslog.h b/sys/compat/sys/syslog.h new file mode 100644 index 000000000..9b0c2f068 --- /dev/null +++ b/sys/compat/sys/syslog.h @@ -0,0 +1,73 @@ +/* $NetBSD: syslog.h,v 1.1 2012/10/10 22:51:12 christos Exp $ */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _COMPAT_SYS_SYSLOG_H_ +#define _COMPAT_SYS_SYSLOG_H_ + +struct syslog_data60 { + int log_file; + int connected; + int opened; + int log_stat; + const char *log_tag; + int log_fac; + int log_mask; +}; + +__BEGIN_DECLS +#ifdef __LIBC12_SOURCE__ +void closelog_r(struct syslog_data60 *); +void openlog_r(const char *, int, int, struct syslog_data60 *); +int setlogmask_r(int, struct syslog_data60 *); +void syslog_r(int, struct syslog_data60 *, const char *, ...) + __printflike(3, 4); +void vsyslog_r(int, struct syslog_data60 *, const char *, __va_list) + __printflike(3, 0); +void syslogp_r(int, struct syslog_data60 *, const char *, const char *, + const char *, ...) __printflike(5, 6); +void vsyslogp_r(int, struct syslog_data60 *, const char *, const char *, + const char *, __va_list) __printflike(5, 0); + +struct syslog_data; +void __closelog_r60(struct syslog_data *); +void __openlog_r60(const char *, int, int, struct syslog_data *); +int __setlogmask_r60(int, struct syslog_data *); +void __syslog_r60(int, struct syslog_data *, const char *, ...) + __printflike(3, 4); +void __vsyslog_r60(int, struct syslog_data *, const char *, __va_list) + __printflike(3, 0); +void __syslogp_r60(int, struct syslog_data *, const char *, const char *, + const char *, ...) __printflike(5, 6); +void __vsyslogp_r60(int, struct syslog_data *, const char *, const char *, + const char *, __va_list) __printflike(5, 0); +#endif +__END_DECLS + +#endif /* !_COMPAT_SYS_SYSLOG_H_ */ diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile index cc6a7f780..8b8bec0ed 100644 --- a/sys/lib/libsa/Makefile +++ b/sys/lib/libsa/Makefile @@ -21,9 +21,8 @@ CPPFLAGS= -I${SADIR} ${SACPPFLAGS} ${SAMISCCPPFLAGS} \ .include -.ifndef __MINIX .PATH.c: ${SADIR} ${.PARSEDIR}/../../../common/lib/libc/string -.else +.ifdef __MINIX .PATH.c: ${SADIR} ${.PARSEDIR}/../../../common/lib/libc/md .endif @@ -87,6 +86,7 @@ SRCS+= ustarfs.c SRCS+= dosfs.c SRCS+= ext2fs.c SRCS+= minixfs3.c +SRCS+= fnmatch.c # for historic compatibility ufs == ffsv1 SRCS+= ufs.c diff --git a/sys/lib/libsa/cd9660.c b/sys/lib/libsa/cd9660.c index 1333c8c43..f0f122328 100644 --- a/sys/lib/libsa/cd9660.c +++ b/sys/lib/libsa/cd9660.c @@ -1,4 +1,4 @@ -/* $NetBSD: cd9660.c,v 1.28 2011/12/25 06:09:08 tsutsui Exp $ */ +/* $NetBSD: cd9660.c,v 1.29 2012/07/23 00:49:20 mhitch Exp $ */ /* * Copyright (C) 1996 Wolfgang Solfrank. @@ -318,6 +318,7 @@ cd9660_read(struct open_file *f, void *start, size_t size, size_t *resid) break; bno = fp->off / ISO_DEFAULT_BLOCK_SIZE + fp->bno; if (fp->off & (ISO_DEFAULT_BLOCK_SIZE - 1) + || (fp->off + ISO_DEFAULT_BLOCK_SIZE) > fp->size || size < ISO_DEFAULT_BLOCK_SIZE) dp = buf; else @@ -336,6 +337,8 @@ cd9660_read(struct open_file *f, void *start, size_t size, size_t *resid) if (nread > off + size) nread = off + size; nread -= off; + if (nread > fp->size - fp->off) + nread = fp->size - fp->off; memcpy(start, buf + off, nread); start = (char *)start + nread; fp->off += nread; diff --git a/sys/lib/libsa/cread.c b/sys/lib/libsa/cread.c index 2eac7b2b1..808690cef 100644 --- a/sys/lib/libsa/cread.c +++ b/sys/lib/libsa/cread.c @@ -95,12 +95,8 @@ void zmemcpy(unsigned char *, unsigned char *, unsigned int); #ifndef ETHER_CRC_POLY_LE #define ETHER_CRC_POLY_LE 0xedb88320 #endif -#ifndef __minix uint32_t crc32(uint32_t crc, const uint8_t *const buf, size_t len) -#else -uLong crc32(uLong crc, const Bytef *buf, uInt len) -#endif { uint32_t c, carry; size_t i, j; diff --git a/sys/lib/libsa/ext2fs.c b/sys/lib/libsa/ext2fs.c index 53f94795d..bb9edfd94 100644 --- a/sys/lib/libsa/ext2fs.c +++ b/sys/lib/libsa/ext2fs.c @@ -1,4 +1,4 @@ -/* $NetBSD: ext2fs.c,v 1.11 2011/12/25 06:09:08 tsutsui Exp $ */ +/* $NetBSD: ext2fs.c,v 1.13 2012/05/21 21:34:16 dsl Exp $ */ /* * Copyright (c) 1997 Manuel Bouyer. @@ -169,34 +169,6 @@ static const char *const typestr[] = { "LNK" }; -static int -fn_match(const char *fname, const char *pattern) -{ - char fc, pc; - - do { - fc = *fname++; - pc = *pattern++; - if (!fc && !pc) - return 1; - if (pc == '?' && fc) - pc = fc; - } while (fc == pc); - - if (pc != '*') - return 0; - /* - * Too hard (and unnecessary really) too check for "*?name" etc.... - * "**" will look for a '*' and "*?" a '?' - */ - pc = *pattern++; - if (!pc) - return 1; - while ((fname = strchr(fname, pc))) - if (fn_match(++fname, pattern)) - return 1; - return 0; -} #endif /* LIBSA_ENABLE_LS_OP */ static int read_inode(ino32_t, struct open_file *); @@ -904,7 +876,7 @@ ext2fs_ls(struct open_file *f, const char *pattern, printf("bad dir entry\n"); goto out; } - if (pattern && !fn_match(dp->e2d_name, pattern)) + if (pattern && !fnmatch(dp->e2d_name, pattern)) continue; n = alloc(sizeof *n + strlen(dp->e2d_name)); if (!n) { diff --git a/sys/lib/libsa/ffsv1.c b/sys/lib/libsa/ffsv1.c index 6fb1caaf8..c02b769eb 100644 --- a/sys/lib/libsa/ffsv1.c +++ b/sys/lib/libsa/ffsv1.c @@ -1,4 +1,4 @@ -/* $NetBSD: ffsv1.c,v 1.5 2011/12/25 06:09:08 tsutsui Exp $ */ +/* $NetBSD: ffsv1.c,v 1.6 2012/05/21 21:34:16 dsl Exp $ */ #define LIBSA_FFSv1 diff --git a/sys/lib/libsa/ffsv2.c b/sys/lib/libsa/ffsv2.c index a5e5585ea..a8ae0c6f3 100644 --- a/sys/lib/libsa/ffsv2.c +++ b/sys/lib/libsa/ffsv2.c @@ -1,4 +1,4 @@ -/* $NetBSD: ffsv2.c,v 1.5 2011/12/25 06:09:08 tsutsui Exp $ */ +/* $NetBSD: ffsv2.c,v 1.6 2012/05/21 21:34:16 dsl Exp $ */ #define LIBSA_FFSv2 diff --git a/sys/lib/libsa/fnmatch.c b/sys/lib/libsa/fnmatch.c new file mode 100644 index 000000000..0c6e89fe5 --- /dev/null +++ b/sys/lib/libsa/fnmatch.c @@ -0,0 +1,93 @@ +/* $NetBSD: fnmatch.c,v 1.1 2012/01/16 18:44:13 christos Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * + * Copyright (c) 1990, 1991 Carnegie Mellon University + * All Rights Reserved. + * + * Author: David Golub + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +#include "stand.h" +#include + +#if defined(LIBSA_ENABLE_LS_OP) +int +fnmatch(const char *fname, const char *pattern) +{ + char fc, pc; + + do { + fc = *fname++; + pc = *pattern++; + if (!fc && !pc) + return 1; + if (pc == '?' && fc) + pc = fc; + } while (fc == pc); + + if (pc != '*') + return 0; + /* + * Too hard (and unnecessary really) too check for "*?name" etc.... + * "**" will look for a '*' and "*?" a '?' + */ + pc = *pattern++; + if (!pc) + return 1; + while ((fname = strchr(fname, pc))) + if (fnmatch(++fname, pattern)) + return 1; + return 0; +} +#endif /* LIBSA_ENABLE_LS_OP */ diff --git a/sys/lib/libsa/globals.c b/sys/lib/libsa/globals.c index bdd2061b4..8230e1434 100644 --- a/sys/lib/libsa/globals.c +++ b/sys/lib/libsa/globals.c @@ -1,4 +1,4 @@ -/* $NetBSD: globals.c,v 1.8 2008/11/19 12:36:41 ad Exp $ */ +/* $NetBSD: globals.c,v 1.9 2012/05/21 21:34:16 dsl Exp $ */ /* * globals.c: @@ -19,11 +19,7 @@ u_char bcea[6] = BA; /* broadcast ethernet address */ char rootpath[FNAME_SIZE]; /* root mount path */ char bootfile[FNAME_SIZE]; /* bootp says to boot this */ char hostname[FNAME_SIZE]; /* our hostname */ -#ifdef __minix -char *fsmod = NULL; -#else -char *fsmod = "ffs"; /* guessed file system module name */ -#endif +char *fsmod = NULL; /* file system module name to load */ char *fsmod2; /* a requisite module */ struct in_addr myip; /* my ip address */ struct in_addr rootip; /* root ip address */ diff --git a/sys/lib/libsa/lfsv1.c b/sys/lib/libsa/lfsv1.c index 7dfc10735..9000b1cdc 100644 --- a/sys/lib/libsa/lfsv1.c +++ b/sys/lib/libsa/lfsv1.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfsv1.c,v 1.4 2011/12/25 06:09:08 tsutsui Exp $ */ +/* $NetBSD: lfsv1.c,v 1.5 2012/05/21 21:34:16 dsl Exp $ */ #define LIBSA_LFS #define REQUIRED_LFS_VERSION 1 diff --git a/sys/lib/libsa/lfsv2.c b/sys/lib/libsa/lfsv2.c index 498a9389b..328a72786 100644 --- a/sys/lib/libsa/lfsv2.c +++ b/sys/lib/libsa/lfsv2.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfsv2.c,v 1.4 2011/12/25 06:09:08 tsutsui Exp $ */ +/* $NetBSD: lfsv2.c,v 1.5 2012/05/21 21:34:16 dsl Exp $ */ #define LIBSA_LFS #define REQUIRED_LFS_VERSION 2 diff --git a/sys/lib/libsa/ls.c b/sys/lib/libsa/ls.c index b2169d15a..04916d4e5 100644 --- a/sys/lib/libsa/ls.c +++ b/sys/lib/libsa/ls.c @@ -157,6 +157,7 @@ ls(const char *path, void (*funcp)(char* arg)) printf("no ls support for this file system\n"); out: + /* LSC: MINIX Modification for correct glob support, beware! */ if (p != NULL) dealloc(p, size + 1); close(fd); diff --git a/sys/lib/libsa/minixfs3.c b/sys/lib/libsa/minixfs3.c index 15396df81..144fbe3f1 100644 --- a/sys/lib/libsa/minixfs3.c +++ b/sys/lib/libsa/minixfs3.c @@ -1,4 +1,4 @@ -/* $NetBSD$ */ +/* $NetBSD: minixfs3.c,v 1.1 2012/01/16 18:44:13 christos Exp $ */ /*- * Copyright (c) 2012 @@ -180,40 +180,12 @@ struct entry_t { char e_name[1]; }; -static int -fn_match(const char *fname, const char *pattern) -{ - char fc, pc; - - do { - fc = *fname++; - pc = *pattern++; - if (!fc && !pc) - return 1; - if (pc == '?' && fc) - pc = fc; - } while (fc == pc); - - if (pc != '*') - return 0; - /* - * Too hard (and unnecessary really) too check for "*?name" etc.... - * "**" will look for a '*' and "*?" a '?' - */ - pc = *pattern++; - if (!pc) - return 1; - while ((fname = strchr(fname, pc))) - if (fn_match(++fname, pattern)) - return 1; - return 0; -} #endif /* LIBSA_ENABLE_LS_OP */ static int read_inode(ino32_t, struct open_file *); static int block_map(struct open_file *, block_t, block_t *); -static int buf_read_file(struct open_file *, char **, size_t *); +static int buf_read_file(struct open_file *, void *, size_t *); static int search_directory(const char *, int, struct open_file *, ino32_t *); static int read_sblock(struct open_file *, struct mfs_sblock *); @@ -375,8 +347,9 @@ block_map(struct open_file *f, block_t file_block, block_t *disk_block_p) * Return the location in the buffer and the amount in the buffer. */ static int -buf_read_file(struct open_file *f, char **buf_p, size_t *size_p) +buf_read_file(struct open_file *f, void *v, size_t *size_p) { + char **buf_p = v; struct file *fp = (struct file *)f->f_fsdata; struct mfs_sblock *fs = fp->f_fs; long off; @@ -445,7 +418,7 @@ search_directory(const char *name, int length, struct open_file *f, fp->f_seekp = 0; while (fp->f_seekp < (off_t)fp->f_di.mdi_size) { - rc = buf_read_file(f, (char**)&dbuf, &buf_size); + rc = buf_read_file(f, (void *)&dbuf, &buf_size); if (rc) return rc; if (buf_size == 0) @@ -873,7 +846,7 @@ minixfs3_ls(struct open_file *f, const char *pattern, fp->f_seekp = 0; while (fp->f_seekp < (off_t)fp->f_di.mdi_size) { - int rc = buf_read_file(f, (char**)&dbuf, &buf_size); + int rc = buf_read_file(f, &dbuf, &buf_size); if (rc) goto out; @@ -892,7 +865,7 @@ minixfs3_ls(struct open_file *f, const char *pattern, if (fs2h32(dp->mfsd_ino) == 0) continue; - if (pattern && !fn_match(dp->mfsd_name, pattern)) + if (pattern && !fnmatch(dp->mfsd_name, pattern)) continue; /* Compute the length of the name, diff --git a/sys/lib/libsa/minixfs3.h b/sys/lib/libsa/minixfs3.h index 0a9ca0353..59f989544 100644 --- a/sys/lib/libsa/minixfs3.h +++ b/sys/lib/libsa/minixfs3.h @@ -1,4 +1,4 @@ -/* $NetBSD$ */ +/* $NetBSD: minixfs3.h,v 1.1 2012/01/16 18:44:13 christos Exp $ */ /*- * Copyright (c) 2012 diff --git a/sys/lib/libsa/stand.h b/sys/lib/libsa/stand.h index 0e1ae7379..bec5791e1 100644 --- a/sys/lib/libsa/stand.h +++ b/sys/lib/libsa/stand.h @@ -1,4 +1,4 @@ -/* $NetBSD: stand.h,v 1.74 2011/12/25 06:09:08 tsutsui Exp $ */ +/* $NetBSD: stand.h,v 1.76 2012/05/21 21:34:16 dsl Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -322,6 +322,8 @@ off_t olseek(int, off_t, int); extern const char hexdigits[]; +int fnmatch(const char *, const char *); + /* XXX: These should be removed eventually. */ void bcopy(const void *, void *, size_t); void bzero(void *, size_t); diff --git a/sys/lib/libsa/ufs.c b/sys/lib/libsa/ufs.c index f491c9821..e69b5d60c 100644 --- a/sys/lib/libsa/ufs.c +++ b/sys/lib/libsa/ufs.c @@ -1,4 +1,4 @@ -/* $NetBSD: ufs.c,v 1.56 2011/12/25 06:09:08 tsutsui Exp $ */ +/* $NetBSD: ufs.c,v 1.58 2012/05/21 21:34:16 dsl Exp $ */ /*- * Copyright (c) 1993 @@ -208,35 +208,6 @@ static const char *const typestr[] = { 0, "WHT" }; - -static int -fn_match(const char *fname, const char *pattern) -{ - char fc, pc; - - do { - fc = *fname++; - pc = *pattern++; - if (!fc && !pc) - return 1; - if (pc == '?' && fc) - pc = fc; - } while (fc == pc); - - if (pc != '*') - return 0; - /* - * Too hard (and unnecessary really) too check for "*?name" etc.... - * "**" will look for a '*' and "*?" a '?' - */ - pc = *pattern++; - if (!pc) - return 1; - while ((fname = strchr(fname, pc))) - if (fn_match(++fname, pattern)) - return 1; - return 0; -} #endif /* LIBSA_ENABLE_LS_OP */ #ifdef LIBSA_LFS @@ -955,7 +926,7 @@ ufs_ls(struct open_file *f, const char *pattern, printf("bad dir entry\n"); goto out; } - if (pattern && !fn_match(dp->d_name, pattern)) + if (pattern && !fnmatch(dp->d_name, pattern)) continue; n = alloc(sizeof *n + strlen(dp->d_name)); if (!n) { diff --git a/sys/sys/Makefile b/sys/sys/Makefile index 900624a17..962ec0dfb 100644 --- a/sys/sys/Makefile +++ b/sys/sys/Makefile @@ -36,7 +36,7 @@ INCS= ansi.h atomic.h \ statvfs.h sysctl.h stdarg.h stdint.h \ syslimits.h syslog.h \ termios.h time.h times.h \ - tree.h ttycom.h \ + tls.h tree.h ttycom.h \ ttydefaults.h types.h \ ucontext.h ucred.h uio.h un.h unistd.h utsname.h uuid.h \ \ diff --git a/sys/sys/ansi.h b/sys/sys/ansi.h index c17ca9e2a..d96dcf123 100644 --- a/sys/sys/ansi.h +++ b/sys/sys/ansi.h @@ -1,4 +1,4 @@ -/* $NetBSD: ansi.h,v 1.13 2010/03/27 22:14:10 tnozaki Exp $ */ +/* $NetBSD: ansi.h,v 1.14 2011/07/17 20:54:54 joerg Exp $ */ /*- * Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc. @@ -35,17 +35,17 @@ #include typedef char * __caddr_t; /* core address */ -typedef __uint32_t __gid_t; /* group id */ +typedef __uint32_t __gid_t; /* group id */ typedef __uint32_t __in_addr_t; /* IP(v4) address */ typedef __uint16_t __in_port_t; /* "Internet" port number */ -typedef unsigned short __mode_t; /* file permissions */ -typedef long __off_t; /* file offset */ -typedef int __pid_t; /* process id */ +typedef __uint16_t __mode_t; /* file permissions */ +typedef __int32_t __off_t; /* file offset */ +typedef __int32_t __pid_t; /* process id */ typedef __uint8_t __sa_family_t; /* socket address family */ typedef __int32_t __socklen_t; /* socket-related datum length */ -typedef __uint32_t __uid_t; /* user id */ -typedef unsigned long __fsblkcnt_t; /* fs block count (statvfs) */ -typedef unsigned long __fsfilcnt_t; /* fs file count */ +typedef __uint32_t __uid_t; /* user id */ +typedef __uint32_t __fsblkcnt_t; /* fs block count (statvfs) */ +typedef __uint32_t __fsfilcnt_t; /* fs file count */ struct __tag_wctrans_t; typedef struct __tag_wctrans_t *__wctrans_t; @@ -66,4 +66,10 @@ typedef union { #define _BSD_WCTYPE_T_ __wctype_t /* wctype_t */ #define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */ +#ifdef __lint__ +typedef char *__va_list; +#else +typedef __builtin_va_list __va_list; +#endif + #endif /* !_SYS_ANSI_H_ */ diff --git a/sys/sys/bitops.h b/sys/sys/bitops.h index f3b3ba193..6a086300f 100644 --- a/sys/sys/bitops.h +++ b/sys/sys/bitops.h @@ -1,4 +1,4 @@ -/* $NetBSD: bitops.h,v 1.7 2010/03/21 14:28:15 christos Exp $ */ +/* $NetBSD: bitops.h,v 1.9 2011/07/30 16:35:58 christos Exp $ */ /*- * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. @@ -255,7 +255,7 @@ fls64(uint64_t _n) _ilog2_helper(_n, 2) \ _ilog2_helper(_n, 1) \ _ilog2_helper(_n, 0) \ - -1) : ((sizeof(_n) >= 4 ? fls64(_n) : fls32(_n)) - 1) \ + -1) : ((sizeof(_n) > 4 ? fls64(_n) : fls32(_n)) - 1) \ ) static __inline void @@ -266,7 +266,7 @@ fast_divide32_prepare(uint32_t _div, uint32_t * __restrict _m, int _l; _l = fls32(_div - 1); - _mt = 0x100000000ULL * ((1ULL << _l) - _div); + _mt = (uint64_t)(0x100000000ULL * ((1ULL << _l) - _div)); *_m = (uint32_t)(_mt / _div + 1); *_s1 = (_l > 1) ? 1 : _l; *_s2 = (_l == 0) ? 0 : _l - 1; @@ -274,7 +274,7 @@ fast_divide32_prepare(uint32_t _div, uint32_t * __restrict _m, /* ARGSUSED */ static __inline uint32_t -fast_divide32(uint32_t _v, uint32_t _div, uint32_t _m, uint8_t _s1, +fast_divide32(uint32_t _v, uint32_t _div __unused, uint32_t _m, uint8_t _s1, uint8_t _s2) { uint32_t _t; diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index d73762697..1805b41c2 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -1,4 +1,4 @@ -/* $NetBSD: cdefs.h,v 1.81 2010/12/25 22:30:52 joerg Exp $ */ +/* $NetBSD: cdefs.h,v 1.100 2012/08/24 05:47:51 dholland Exp $ */ /* * Copyright (c) 1991, 1993 @@ -63,6 +63,21 @@ #include #endif +#ifdef __GNUC__ +#define __strict_weak_alias(alias,sym) \ + __unused static __typeof__(alias) *__weak_alias_##alias = &sym; \ + __weak_alias(alias,sym) +#else +#define __strict_weak_alias(alias,sym) __weak_alias(alias,sym) +#endif + +/* + * Optional marker for size-optimised MD calling convention. + */ +#ifndef __compactcall +#define __compactcall +#endif + /* * The __CONCAT macro is used to concatenate parts of symbol names, e.g. * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. @@ -125,6 +140,17 @@ #define __aconst #endif +/* + * Compile Time Assertion. + */ +#ifdef __COUNTER__ +#define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__) +#else +#define __CTASSERT(x) __CTASSERT0(x, __ctassert, __LINE__) +#endif +#define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z) +#define __CTASSERT1(x, y, z) typedef char y ## z[/*CONSTCOND*/(x) ? 1 : -1] + /* * The following macro is used to remove const cast-away warnings * from gcc -Wcast-qual; it should be used with caution because it @@ -206,6 +232,24 @@ #define __noinline /* nothing */ #endif +#if __GNUC_PREREQ__(3, 0) +#define __always_inline __attribute__((__always_inline__)) +#else +#define __always_inline /* nothing */ +#endif + +#if __GNUC_PREREQ__(4, 1) +#define __returns_twice __attribute__((__returns_twice__)) +#else +#define __returns_twice /* nothing */ +#endif + +#if __GNUC_PREREQ__(4, 5) +#define __noclone __attribute__((__noclone__)) +#else +#define __noclone /* nothing */ +#endif + #if __GNUC_PREREQ__(2, 7) #define __unused __attribute__((__unused__)) #else @@ -218,6 +262,12 @@ #define __used __unused #endif +#if __GNUC_PREREQ__(3, 1) +#define __noprofile __attribute__((__no_instrument_function__)) +#else +#define __noprofile /* nothing */ +#endif + #if defined(__cplusplus) #define __BEGIN_EXTERN_C extern "C" { #define __END_EXTERN_C } @@ -278,6 +328,8 @@ #define __packed _Pragma("packed 1") #define __aligned(x) _Pragma("aligned " __STRING(x)) #define __section(x) _Pragma("section " ## x) +#elif defined(_MSC_VER) +#define __packed /* ignore */ #else #define __packed error: no __packed for this compiler #define __aligned(x) error: no __aligned for this compiler @@ -292,7 +344,9 @@ #define __restrict /* delete __restrict when not supported */ #elif __STDC_VERSION__ >= 199901L #define __restrict restrict -#elif !__GNUC_PREREQ__(2, 92) +#elif __GNUC_PREREQ__(2, 92) +#define __restrict __restrict__ +#else #define __restrict /* delete __restrict when not supported */ #endif @@ -320,12 +374,10 @@ #if !defined(_STANDALONE) && !defined(_KERNEL) #if defined(__GNUC__) || defined(__PCC__) #define __RENAME(x) ___RENAME(x) -#else -#ifdef __lint__ +#elif defined(__lint__) #define __RENAME(x) __symbolrename(x) #else #error "No function renaming possible" -#endif /* __lint__ */ #endif /* __GNUC__ */ #else /* _STANDALONE || _KERNEL */ #define __RENAME(x) no renaming in kernel or standalone environment @@ -443,7 +495,7 @@ #define __link_set_foreach(pvar, set) \ for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) -#define __link_set_entry(set, idx) (__link_set_begin(set)[idx]) +#define __link_set_entry(set, idx) (__link_set_start(set)[idx]) /* * Return the number of elements in a statically-allocated array, @@ -482,8 +534,37 @@ #define __CAST(__dt, __st) ((__dt)(__st)) #endif -#ifdef _MINIX -/* If compiling in Minix tree, Minix ANSI definitions are always useful. */ +#define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \ + (~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL) + +#ifndef __ASSEMBLER__ +static __inline long long __zeroll(void) { return 0; } +static __inline int __negative_p(double x) { return x < 0; } +#else +#define __zeroll() (0LL) +#define __negative_p(x) ((x) < 0) #endif +#define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1)))) +#define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1)))) +#define __type_min_u(t) ((t)0ULL) +#define __type_max_u(t) ((t)~0ULL) +#define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1) +#define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t)) +#define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t)) + + +#define __type_fit_u(t, a) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \ + (((a) & __type_mask(t)) == 0) : !__negative_p(a)) + +#define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \ + ((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \ + ((intmax_t)((a) + __zeroll()) <= (intmax_t)__type_max_s(t))) + +/* + * return true if value 'a' fits in type 't' + */ +#define __type_fit(t, a) (__type_is_signed(t) ? \ + __type_fit_s(t, a) : __type_fit_u(t, a)) + #endif /* !_SYS_CDEFS_H_ */ diff --git a/sys/sys/cdefs_aout.h b/sys/sys/cdefs_aout.h index b9035cd28..b58e72f6d 100644 --- a/sys/sys/cdefs_aout.h +++ b/sys/sys/cdefs_aout.h @@ -110,17 +110,11 @@ #define __link_set_add_data(set, sym) __link_set_make_entry(set, sym, 25) #define __link_set_add_bss(set, sym) __link_set_make_entry(set, sym, 27) -#ifdef __minix -/* GNU binutils 2.x doesn't support a.out link sets. We need to workaround - * this by explicitely creating the N_SETV structure. */ -#define __link_set_decl(set, ptype) -#else #define __link_set_decl(set, ptype) \ extern struct { \ int __ls_length; \ ptype *__ls_items[1]; \ } __link_set_##set -#endif /* !__minix */ #define __link_set_start(set) (&(__link_set_##set).__ls_items[0]) #define __link_set_end(set) \ diff --git a/sys/sys/cdefs_elf.h b/sys/sys/cdefs_elf.h index 4872136b6..96cec8e24 100644 --- a/sys/sys/cdefs_elf.h +++ b/sys/sys/cdefs_elf.h @@ -1,4 +1,4 @@ -/* $NetBSD: cdefs_elf.h,v 1.34 2010/12/08 01:18:55 joerg Exp $ */ +/* $NetBSD: cdefs_elf.h,v 1.40 2012/03/04 16:14:48 tron Exp $ */ /* * Copyright (c) 1995, 1996 Carnegie-Mellon University. @@ -65,21 +65,21 @@ __asm(".weak " _C_LABEL_STRING(#sym)); #if __GNUC_PREREQ__(4, 0) -#define __weak_reference(sym) __attribute__((__weakref__)) +#define __weak_reference(sym) __attribute__((__weakref__(#sym))) #else #define __weak_reference(sym) ; __asm(".weak " _C_LABEL_STRING(#sym)) #endif -#if defined(__clang__) -#define __warn_references(sym,msg) \ - static __attribute__((__used__, __section__(".gnu.warning." #sym))) \ - const char ___CONCAT(__warn_reference_##sym,__COUNTER__)[] = msg; +#if __GNUC_PREREQ__(4, 2) +#define __weakref_visible static #else +#define __weakref_visible extern +#endif + #define __warn_references(sym,msg) \ __asm(".pushsection .gnu.warning." #sym "\n" \ ".ascii \"" msg "\"\n" \ ".popsection"); -#endif #else /* !__STDC__ */ @@ -106,11 +106,7 @@ #endif /* !__STDC__ */ -#if defined(__clang__) -#define __SECTIONSTRING(_sec, _str) \ - static __attribute__((__used__, __section__(#_sec))) const char \ - ___CONCAT(__sectstr,__COUNTER__)[] = _str -#elif __STDC__ +#if __STDC__ #define __SECTIONSTRING(_sec, _str) \ __asm(".pushsection " #_sec "\n" \ ".asciz \"" _str "\"\n" \ @@ -157,8 +153,8 @@ #define __link_set_add_bss2(set, sym, n) __link_set_make_entry2(set, sym, n) #define __link_set_decl(set, ptype) \ - extern ptype * const __start_link_set_##set[]; \ - extern ptype * const __stop_link_set_##set[] \ + extern ptype * const __start_link_set_##set[] __dso_hidden; \ + extern ptype * const __stop_link_set_##set[] __dso_hidden \ #define __link_set_start(set) (__start_link_set_##set) #define __link_set_end(set) (__stop_link_set_##set) @@ -200,7 +196,7 @@ __attribute__((__section__(".data.read_mostly"))) #define __cacheline_aligned \ - __attribute__((__aligned__(COHERENCY_UNIT) \ + __attribute__((__aligned__(COHERENCY_UNIT), \ __section__(".data.cacheline_aligned"))) #endif /* _KERNEL */ diff --git a/sys/sys/ctype_inline.h b/sys/sys/ctype_inline.h index 9cdc6e045..d416a4591 100644 --- a/sys/sys/ctype_inline.h +++ b/sys/sys/ctype_inline.h @@ -44,7 +44,7 @@ #include #include - +/* LSC: cast to unsigned char in order to prevent char as indice errors. */ #define isdigit(c) ((int)((_ctype_ + 1)[(unsigned char)(c)] & _CTYPE_N)) #define islower(c) ((int)((_ctype_ + 1)[(unsigned char)(c)] & _CTYPE_L)) #define isspace(c) ((int)((_ctype_ + 1)[(unsigned char)(c)] & _CTYPE_S)) diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h index 42e38f73d..1e6db347d 100644 --- a/sys/sys/disklabel.h +++ b/sys/sys/disklabel.h @@ -41,6 +41,10 @@ #include #endif +#if defined(__minix) && !defined(_STANDALONE) +#include +#endif + /* * Each disk has a label which includes information about the hardware * disk geometry, filesystem partitions, and drive specific information. @@ -180,6 +184,10 @@ struct disklabel { uint16_t d_npartitions; /* number of partitions in following */ uint32_t d_bbsize; /* size of boot area at sn0, bytes */ uint32_t d_sbsize; /* max size of fs superblock, bytes */ +#if defined(__minix) && !defined(_STANDALONE) + struct partition /* the partition table */ + d_partitions[MAXPARTITIONS]; /* actually may be more */ +#else struct partition { /* the partition table */ uint32_t p_size; /* number of sectors in partition */ uint32_t p_offset; /* starting sector */ @@ -199,6 +207,7 @@ struct disklabel { #define p_cpg __partition_u1.cpg #define p_sgs __partition_u1.sgs } d_partitions[MAXPARTITIONS]; /* actually may be more */ +#endif /* defined(__minix) */ }; #if defined(__HAVE_OLD_DISKLABEL) && !HAVE_NBTOOL_CONFIG_H diff --git a/sys/sys/errno.h b/sys/sys/errno.h index b1b5d6a49..d8f1b5b7b 100644 --- a/sys/sys/errno.h +++ b/sys/sys/errno.h @@ -17,8 +17,8 @@ * file is included in an ordinary user program, EPERM has the value ( 1). */ -#ifndef _ERRNO_H /* check if is already included */ -# define _ERRNO_H /* it is not included; note that fact */ +#ifndef _SYS_ERRNO_H_ +#define _SYS_ERRNO_H_ /* Now define _SIGN as "" or "-" depending on _SYSTEM. */ #ifdef _SYSTEM @@ -173,4 +173,4 @@ #define EDEADEPT (_SIGN 302 ) /* specified endpoint is not alive */ #define EBADCPU (_SIGN 303 ) /* requested CPU does not work */ -#endif /* _ERRNO_H */ +#endif /* !_SYS_ERRNO_H_ */ diff --git a/sys/sys/featuretest.h b/sys/sys/featuretest.h index c5738a763..967f09bcf 100644 --- a/sys/sys/featuretest.h +++ b/sys/sys/featuretest.h @@ -71,7 +71,7 @@ /* Never define _REENTRANT on Minix */ -#ifdef __minix +#ifndef __minix #if ((_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500) && \ !defined(_REENTRANT) diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 31f1c15ce..9a734a2ca 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -450,10 +450,15 @@ int getfh(const char *, void *, size_t *) __RENAME(__getfh30); #endif +#if !defined(__minix) int unmount(const char *, int); +#endif /* !defined(__minix) */ #if defined(_NETBSD_SOURCE) #ifndef __LIBC12_SOURCE__ +#if !defined(__minix) +/* LSC FIXME: we should remove our definition, and make sure all the tools uses the new one*/ int mount(const char *, const char *, int, void *, size_t) __RENAME(__mount50); +#endif /* !defined(__minix) */ int fhopen(const void *, size_t, int) __RENAME(__fhopen40); int fhstat(const void *, size_t, struct stat *) __RENAME(__fhstat50); #endif diff --git a/sys/sys/ptree.h b/sys/sys/ptree.h index 03f9930de..e7977ad68 100644 --- a/sys/sys/ptree.h +++ b/sys/sys/ptree.h @@ -1,4 +1,5 @@ -/* $NetBSD: ptree.h,v 1.3 2008/11/25 15:13:47 ad Exp $ */ +/* $NetBSD: ptree.h,v 1.8 2012/10/06 22:15:09 matt Exp $ */ + /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. * All rights reserved. @@ -27,6 +28,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ + #ifndef _SYS_PTREE_H_ #define _SYS_PTREE_H_ @@ -46,42 +48,42 @@ typedef unsigned int pt_bitlen_t; typedef struct pt_node { uintptr_t ptn_slots[2]; /* must be first */ -#define PT_SLOT_LEFT 0 -#define PT_SLOT_RIGHT 1 +#define PT_SLOT_LEFT 0u +#define PT_SLOT_RIGHT 1u #ifdef _PT_PRIVATE -#define PT_SLOT_ROOT 0 -#define PT_SLOT_OTHER 1 -#define PT_SLOT_ODDMAN 1 -#define PT_TYPE_LEAF 0x00000000 -#define PT_TYPE_BRANCH 0x00000001 -#define PT_TYPE_MASK 0x00000001 +#define PT_SLOT_ROOT 0u +#define PT_SLOT_OTHER 1u +#define PT_SLOT_ODDMAN 1u +#define PT_TYPE_LEAF ((uintptr_t)0x00000000u) +#define PT_TYPE_BRANCH ((uintptr_t)0x00000001u) +#define PT_TYPE_MASK ((uintptr_t)0x00000001u) #endif /* _PT_PRIVATE */ uint32_t ptn_nodedata; #ifdef _PT_PRIVATE -#define PTN_LEAF_POSITION_BITS 8 -#define PTN_LEAF_POSITION_SHIFT 0 -#define PTN_BRANCH_POSITION_BITS 8 -#define PTN_BRANCH_POSITION_SHIFT 8 +#define PTN_LEAF_POSITION_BITS 8u +#define PTN_LEAF_POSITION_SHIFT 0u +#define PTN_BRANCH_POSITION_BITS 8u +#define PTN_BRANCH_POSITION_SHIFT 8u #ifndef PTNOMASK -#define PTN_MASK_BITLEN_BITS 15 -#define PTN_MASK_BITLEN_SHIFT 16 -#define PTN_MASK_FLAG 0x80000000 +#define PTN_MASK_BITLEN_BITS 15u +#define PTN_MASK_BITLEN_SHIFT 16u +#define PTN_MASK_FLAG 0x80000000u #endif #endif /* _PT_PRIVATE */ uint32_t ptn_branchdata; #ifdef _PT_PRIVATE -#define PTN_BRANCH_BITOFF_BITS 15 -#define PTN_BRANCH_BITOFF_SHIFT 0 -#define PTN_BRANCH_BITLEN_BITS 8 -#define PTN_BRANCH_BITLEN_SHIFT 16 +#define PTN_BRANCH_BITOFF_BITS 15u +#define PTN_BRANCH_BITOFF_SHIFT 0u +#define PTN_BRANCH_BITLEN_BITS 8u +#define PTN_BRANCH_BITLEN_SHIFT 16u #if 0 -#define PTN_ORIENTATION_BITS 1 -#define PTN_ORIENTATION_SHIFT 30 +#define PTN_ORIENTATION_BITS 1u +#define PTN_ORIENTATION_SHIFT 30u #endif -#define PTN_BRANCH_UNUSED 0x3f000000 -#define PTN_XBRANCH_FLAG 0x80000000 +#define PTN_BRANCH_UNUSED 0x3f000000u +#define PTN_XBRANCH_FLAG 0x80000000u #endif /* _PT_PRIVATE */ } pt_node_t; @@ -155,12 +157,14 @@ typedef struct pt_node { #endif /* _PT_PRIVATE */ typedef struct pt_tree_ops { - bool (*ptto_matchnode)(const void *, const void *, pt_bitoff_t, - pt_bitoff_t *, pt_slot_t *); - bool (*ptto_matchkey)(const void *, const void *, pt_bitoff_t, - pt_bitlen_t); - pt_slot_t (*ptto_testnode)(const void *, pt_bitoff_t, pt_bitlen_t); - pt_slot_t (*ptto_testkey)(const void *, pt_bitoff_t, pt_bitlen_t); + bool (*ptto_matchnode)(const void *, const void *, + pt_bitoff_t, pt_bitoff_t *, pt_slot_t *, void *); + bool (*ptto_matchkey)(const void *, const void *, + pt_bitoff_t, pt_bitlen_t, void *); + pt_slot_t (*ptto_testnode)(const void *, + pt_bitoff_t, pt_bitlen_t, void *); + pt_slot_t (*ptto_testkey)(const void *, + pt_bitoff_t, pt_bitlen_t, void *); } pt_tree_ops_t; typedef struct pt_tree { @@ -170,16 +174,18 @@ typedef struct pt_tree { const pt_tree_ops_t *pt_ops; size_t pt_node_offset; size_t pt_key_offset; - uintptr_t pt_spare[4]; + void *pt_context; + uintptr_t pt_spare[3]; } pt_tree_t; #define PT_FILTER_MASK 0x00000001 /* node is a mask */ typedef bool (*pt_filter_t)(void *, const void *, int); -void ptree_init(pt_tree_t *, const pt_tree_ops_t *, size_t, size_t); +void ptree_init(pt_tree_t *, const pt_tree_ops_t *, void *, size_t, size_t); bool ptree_insert_node(pt_tree_t *, void *); bool ptree_insert_mask_node(pt_tree_t *, void *, pt_bitlen_t); -void * ptree_find_filtered_node(pt_tree_t *, void *, pt_filter_t, void *); +bool ptree_mask_node_p(pt_tree_t *, const void *, pt_bitlen_t *); +void * ptree_find_filtered_node(pt_tree_t *, const void *, pt_filter_t, void *); #define ptree_find_node(pt,key) \ ptree_find_filtered_node((pt), (key), NULL, NULL) void ptree_remove_node(pt_tree_t *, void *); diff --git a/sys/sys/reboot.h b/sys/sys/reboot.h index 57dca07bd..6661e354b 100644 --- a/sys/sys/reboot.h +++ b/sys/sys/reboot.h @@ -39,10 +39,11 @@ #define RBT_HALT 0 /* shutdown and return to monitor */ #define RBT_REBOOT 1 /* reboot the system through the monitor */ #define RBT_PANIC 2 /* a server panics */ -#define RBT_MONITOR 3 /* let the monitor do this */ +#define RBT_POWEROFF 3 /* power off, reset if not possible */ #define RBT_RESET 4 /* hard reset the system */ #define RBT_DEFAULT 5 /* return to monitor, reset if not possible */ #define RBT_INVALID 6 /* first invalid reboot flag */ + /* * Arguments to reboot system call. These are passed to the boot program, * and then on to init. diff --git a/sys/sys/socket.h b/sys/sys/socket.h index cf3839322..89a435933 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -1,3 +1,65 @@ +/* $NetBSD: socket.h,v 1.107 2012/06/22 18:26:35 christos Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)socket.h 8.6 (Berkeley) 5/3/95 + */ + #ifndef _SYS_SOCKET_H_ #define _SYS_SOCKET_H_ @@ -73,7 +135,6 @@ typedef _BSD_SSIZE_T_ ssize_t; /* SO_OSNDTIMEO 0x1005 */ /* SO_ORCVTIMEO 0x1006 */ #define SO_ERROR 0x1007 /* get error status and clear */ -#define SO_TYPE 0x1008 /* get socket type */ #define SO_OVERFLOWED 0x1009 /* datagrams: return packets dropped */ @@ -238,6 +299,10 @@ struct msghdr { int msg_flags; /* flags on received message */ }; +#define MSG_OOB 0x0001 /* process out-of-band data */ +#define MSG_PEEK 0x0002 /* peek at incoming message */ +#define MSG_DONTROUTE 0x0004 /* send without using routing tables */ +#define MSG_EOR 0x0008 /* complete record */ /* * Header for ancillary data objects in msg_control buffer. * Used for additional information with/about a datagram @@ -319,9 +384,5 @@ int socket(int, int, int); int socketpair(int, int, int, int *); __END_DECLS -#define MSG_OOB 0x0001 /* process out-of-band data */ -#define MSG_PEEK 0x0002 /* peek at incoming message */ -#define MSG_DONTROUTE 0x0004 /* send without using routing tables */ -#define MSG_EOR 0x0008 /* complete record */ #endif /* !_SYS_SOCKET_H_ */ diff --git a/sys/sys/stat.h b/sys/sys/stat.h index 8eff1f6ab..06a5a347e 100644 --- a/sys/sys/stat.h +++ b/sys/sys/stat.h @@ -220,6 +220,7 @@ struct minix_prev_stat { #define MINIX_ST_BLKSIZE PAGE_SIZE #endif +#if !defined(_KERNEL) && !defined(_STANDALONE) #include __BEGIN_DECLS @@ -240,4 +241,5 @@ int mknod(const char *, mode_t, dev_t) __RENAME(__mknod50); #endif /* defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) */ __END_DECLS +#endif /* !_KERNEL && !_STANDALONE */ #endif /* !_SYS_STAT_H_ */ diff --git a/sys/sys/syslog.h b/sys/sys/syslog.h index 39f6d9d3c..83af95142 100644 --- a/sys/sys/syslog.h +++ b/sys/sys/syslog.h @@ -1,4 +1,4 @@ -/* $NetBSD: syslog.h,v 1.32 2008/10/31 16:12:18 christos Exp $ */ +/* $NetBSD: syslog.h,v 1.35 2012/10/10 22:51:55 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1988, 1993 @@ -170,70 +170,67 @@ CODE facilitynames[] = { /* Used by reentrant functions */ struct syslog_data { + int log_version; int log_file; - int connected; - int opened; + int log_connected; + int log_opened; int log_stat; const char *log_tag; + char log_hostname[256]; /* MAXHOSTNAMELEN */ int log_fac; int log_mask; }; #define SYSLOG_DATA_INIT { \ + .log_version = 1, \ .log_file = -1, \ + .log_connected = 0, \ + .log_opened = 0, \ + .log_stat = 0, \ + .log_tag = 0, \ + .log_hostname = { '\0' }, \ .log_fac = LOG_USER, \ .log_mask = 0xff, \ } -/* - * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd in two - * places ( and ), so if we include one - * of them here we may collide with the utility's includes. It's unreasonable - * for utilities to have to include one of them to include syslog.h, so we get - * _BSD_VA_LIST_ from and use it. - */ -#include #include #include +#include __BEGIN_DECLS void closelog(void); void openlog(const char *, int, int); int setlogmask(int); -void syslog(int, const char *, ...) - __attribute__((__format__(__printf__,2,3))); +void syslog(int, const char *, ...) __printflike(2, 3); #if defined(_NETBSD_SOURCE) -void vsyslog(int, const char *, _BSD_VA_LIST_) - __attribute__((__format__(__printf__,2,0))); -void closelog_r(struct syslog_data *); -void openlog_r(const char *, int, int, struct syslog_data *); -int setlogmask_r(int, struct syslog_data *); +void vsyslog(int, const char *, __va_list) __printflike(2, 0); +#ifndef __LIBC12_SOURCE__ +void closelog_r(struct syslog_data *) __RENAME(__closelog_r60); +void openlog_r(const char *, int, int, struct syslog_data *) + __RENAME(__openlog_r60); +int setlogmask_r(int, struct syslog_data *) __RENAME(__setlogmask_r60); void syslog_r(int, struct syslog_data *, const char *, ...) - __attribute__((__format__(__printf__,3,4))); -void vsyslog_r(int, struct syslog_data *, const char *, _BSD_VA_LIST_) - __attribute__((__format__(__printf__,3,0))); -void syslogp(int, const char *, const char *, const char *, ...) - __attribute__((__format__(__printf__,4,5))); -void vsyslogp(int, const char *, const char *, const char *, _BSD_VA_LIST_) - __attribute__((__format__(__printf__,4,0))); -void syslogp_r(int, struct syslog_data *, const char *, const char *, - const char *, ...) - __attribute__((__format__(__printf__,5,6))); -void vsyslogp_r(int, struct syslog_data *, const char *, const char *, - const char *, _BSD_VA_LIST_) - __attribute__((__format__(__printf__,5,0))); + __RENAME(__syslog_r60) __printflike(3, 4); +void vsyslog_r(int, struct syslog_data *, const char *, __va_list) + __RENAME(__vsyslog_r60) __printflike(3, 0); +void syslogp_r(int, struct syslog_data *, const char *, const char *, + const char *, ...) __RENAME(__syslogp_r60) __printflike(5, 6); +void vsyslogp_r(int, struct syslog_data *, const char *, const char *, + const char *, __va_list) __RENAME(__vsyslogp_r60) __printflike(5, 0); +#endif +void syslogp(int, const char *, const char *, const char *, ...) + __printflike(4, 5); +void vsyslogp(int, const char *, const char *, const char *, __va_list) + __printflike(4, 0); #endif __END_DECLS #else /* !_KERNEL */ void logpri(int); -void log(int, const char *, ...) - __attribute__((__format__(__printf__,2,3))); -void vlog(int, const char *, _BSD_VA_LIST_) - __attribute__((__format__(__printf__,2,0))); -void addlog(const char *, ...) - __attribute__((__format__(__printf__,1,2))); +void log(int, const char *, ...) __printflike(2, 3); +void vlog(int, const char *, __va_list) __printflike(2, 0); +void addlog(const char *, ...) __printflike(1, 2); void logwakeup(void); #endif /* !_KERNEL */ diff --git a/sys/sys/tls.h b/sys/sys/tls.h new file mode 100644 index 000000000..4978d6ed8 --- /dev/null +++ b/sys/sys/tls.h @@ -0,0 +1,61 @@ +/* $NetBSD: tls.h,v 1.1 2011/03/09 23:10:07 joerg Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_TLS_H_ +#define _SYS_TLS_H_ + +#include +#include + +#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) + +#if defined(__HAVE_TLS_VARIANT_I) && defined(__HAVE_TLS_VARIANT_II) +#error Only one TLS variant can be supported at a time +#endif + +struct tls_tcb { +#ifdef __HAVE_TLS_VARIANT_I + void **tcb_dtv; + void *tcb_pthread; +#else + void *tcb_self; + void **tcb_dtv; + void *tcb_pthread; +#endif +}; + +__BEGIN_PUBLIC_DECLS +struct tls_tcb *_rtld_tls_allocate(void); +void _rtld_tls_free(struct tls_tcb *); +void _rtld_tls_static_setup(void); +__END_PUBLIC_DECLS +#endif /* __HAVE_TLS_VARIANT_I || __HAVE_TLS_VARIANT_II */ + +#endif /* _SYS_TLS_H_ */ diff --git a/sys/sys/types.h b/sys/sys/types.h index c8799507f..d7c8ffb86 100644 --- a/sys/sys/types.h +++ b/sys/sys/types.h @@ -117,11 +117,11 @@ typedef u32_t big_uid_t; #ifdef _MINIX /* some Minix specific types that do not conflict with posix */ -typedef u32_t zone_t; /* zone number */ -typedef u32_t block_t; /* block number */ -typedef u32_t bit_t; /* bit number in a bit map */ -typedef u16_t zone1_t; /* zone number for V1 file systems */ -typedef u32_t bitchunk_t; /* collection of bits in a bitmap */ +typedef uint32_t zone_t; /* zone number */ +typedef uint32_t block_t; /* block number */ +typedef uint32_t bit_t; /* bit number in a bit map */ +typedef uint16_t zone1_t; /* zone number for V1 file systems */ +typedef uint32_t bitchunk_t; /* collection of bits in a bitmap */ #endif /* ANSI C makes writing down the promotion of unsigned types very messy. When diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h index ac0a887ca..27e713379 100644 --- a/sys/sys/ucred.h +++ b/sys/sys/ucred.h @@ -50,6 +50,16 @@ struct ucred gid_t gid; }; +#ifdef __minix +/* LSC FIXME: Remove this! Compatibility thing, only used in pfs/uds.c */ +struct ucred_old +{ + pid_t pid; + short uid; + char gid; +}; +#endif /* def __minix */ + /* Userland's view of credentials. This should not change */ struct uucred { unsigned short cr_unused; /* not used, compat */ diff --git a/usr.sbin/installboot/install_master.c b/usr.sbin/installboot/install_master.c index 45f60038f..1e8edf309 100644 --- a/usr.sbin/installboot/install_master.c +++ b/usr.sbin/installboot/install_master.c @@ -16,6 +16,8 @@ #include #include +#include "installboot.h" + #define BOOTBLOCK 0 /* Of course */ #define BOOT_BLOCK_SIZE 1024 #define SIGNATURE 0xAA55 /* Boot block signature. */ diff --git a/usr.sbin/installboot/minixfs3.c b/usr.sbin/installboot/minixfs3.c index ab7607ee4..1951b89bf 100644 --- a/usr.sbin/installboot/minixfs3.c +++ b/usr.sbin/installboot/minixfs3.c @@ -8,6 +8,8 @@ #include #include +#include "installboot.h" + #ifndef DFL_SECSIZE #define DFL_SECSIZE 512 #endif diff --git a/usr.sbin/mkfs.mfs/mkfs.c b/usr.sbin/mkfs.mfs/mkfs.c index f5c7bc6ad..c21d50d9d 100644 --- a/usr.sbin/mkfs.mfs/mkfs.c +++ b/usr.sbin/mkfs.mfs/mkfs.c @@ -641,17 +641,17 @@ ino_t inode; incr_link(inode); } -void enter_symlink(ino_t inode, char *link) +void enter_symlink(ino_t inode, char *lnk) { zone_t z; char *buf; buf = alloc_block(); z = alloc_zone(); - strcpy(buf, link); + strcpy(buf, lnk); put_block(z, buf); - add_zone(inode, z, (size_t) strlen(link), current_time); + add_zone(inode, z, (size_t) strlen(lnk), current_time); free(buf); } @@ -728,7 +728,7 @@ ino_t inode; int f; { int ct, k; - zone_t z; + zone_t z = 0; char *buf; uint32_t timeval; @@ -842,7 +842,7 @@ void enter_dir(ino_t parent, char const *name, ino_t child) } } - printf("Directory-inode %lu beyond direct blocks. Could not enter %s\n", + printf("Directory-inode %u beyond direct blocks. Could not enter %s\n", parent, name); pexit("Halt"); } @@ -1340,7 +1340,7 @@ void print_fs() if (k > nrinodes) break; { if (inode2[i].d2_mode != 0) { - printf("Inode %2lu: mode=", k); + printf("Inode %2u: mode=", k); printf("%06o", inode2[i].d2_mode); printf(" uid=%2d gid=%2d size=", inode2[i].d2_uid, inode2[i].d2_gid);