diff options
| author | Roy Marples <roy@marples.name> | 2017-03-22 15:27:45 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2017-03-22 15:27:45 +0000 |
| commit | ae90db9e04c7adb8ce2d56c60b28bc22fd08ce45 (patch) | |
| tree | 9b8d4a16fbfb152f14035745de0ae459681f7f1a /compat | |
| parent | 5dde1f30e4d2b30a1ba789ad5f8441e010e817b1 (diff) | |
| download | dhcpcd-ae90db9e04c7adb8ce2d56c60b28bc22fd08ce45.tar.xz | |
Use new strtoi changes.
Diffstat (limited to 'compat')
| -rw-r--r-- | compat/strtoi.c | 122 | ||||
| -rw-r--r-- | compat/strtoi.h | 22 |
2 files changed, 53 insertions, 91 deletions
diff --git a/compat/strtoi.c b/compat/strtoi.c index 701d57b3..e1cd972c 100644 --- a/compat/strtoi.c +++ b/compat/strtoi.c @@ -1,8 +1,10 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2015 Roy Marples <roy@marples.name> - * All rights reserved +/* $NetBSD: strtoi.c,v 1.2 2015/05/01 14:17:56 christos Exp $ */ +/*- + * Copyright (c) 2005 The DragonFly Project. All rights reserved. + * Copyright (c) 2003 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: @@ -23,90 +25,42 @@ * 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. + * + * Created by Kamil Rytarowski, based on ID: + * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp */ -#include <errno.h> -#include <inttypes.h> -#include <stdlib.h> - -#include "strtoi.h" - -intmax_t -strtoi(const char * __restrict nptr, char ** __restrict endptr, int base, - intmax_t lo, intmax_t hi, int *rstatus) -{ - int serrno; - intmax_t r; - char *ep; - int rep; +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif - if (endptr == NULL) - endptr = &ep; - if (rstatus == NULL) - rstatus = &rep; +#ifdef _LIBC +#include "namespace.h" +#endif - serrno = errno; - errno = 0; - r = strtoimax(nptr, endptr, base); - *rstatus = errno; - errno = serrno; - - if (*rstatus == 0) { - if (nptr == *endptr) - *rstatus = ECANCELED; - else if (**endptr != '\0') - *rstatus = ENOTSUP; - } - - if (r < lo) { - if (*rstatus == 0) - *rstatus = ERANGE; - return lo; - } - if (r > hi) { - if (*rstatus == 0) - *rstatus = ERANGE; - return hi; - } - return r; -} - -uintmax_t -strtou(const char * __restrict nptr, char ** __restrict endptr, int base, - uintmax_t lo, uintmax_t hi, int *rstatus) -{ - int serrno; - uintmax_t r; - char *ep; - int rep; - - if (endptr == NULL) - endptr = &ep; - if (rstatus == NULL) - rstatus = &rep; +#if defined(_KERNEL) +#include <sys/param.h> +#include <sys/types.h> +#include <lib/libkern/libkern.h> +#elif defined(_STANDALONE) +#include <sys/param.h> +#include <sys/types.h> +#include <lib/libkern/libkern.h> +#include <lib/libsa/stand.h> +#else +#include <stddef.h> +#include <assert.h> +#include <errno.h> +#include <inttypes.h> +#endif - serrno = errno; - errno = 0; - r = strtoumax(nptr, endptr, base); - *rstatus = errno; - errno = serrno; +#define _FUNCNAME strtoi +#define __TYPE intmax_t +#define __WRAPPED strtoimax - if (*rstatus == 0) { - if (nptr == *endptr) - *rstatus = ECANCELED; - else if (**endptr != '\0') - *rstatus = ENOTSUP; - } +#include "_strtoi.h" - if (r < lo) { - if (*rstatus == 0) - *rstatus = ERANGE; - return lo; - } - if (r > hi) { - if (*rstatus == 0) - *rstatus = ERANGE; - return hi; - } - return r; -} +#ifdef _LIBC +__weak_alias(strtoi, _strtoi) +__weak_alias(strtoi_l, _strtoi_l) +#endif diff --git a/compat/strtoi.h b/compat/strtoi.h index 4b0c878c..bd976fcf 100644 --- a/compat/strtoi.h +++ b/compat/strtoi.h @@ -1,8 +1,7 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2015 Roy Marples <roy@marples.name> - * All rights reserved - +/*- + * 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: @@ -11,11 +10,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) @@ -23,6 +25,12 @@ * 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: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp + * + * Created by Kamil Rytarowski, based on ID: + * NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joerg Exp */ #ifndef STRTOI_H |
