Move strtoumax.c from libc/stdlib to common/libc/stdlib and include it
in libkern. Required for new code coming soon.
This commit is contained in:
parent
94cc274ebe
commit
7d3d66c90e
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: strtoumax.c,v 1.6 2005/11/29 03:12:00 christos Exp $ */
|
/* $NetBSD: strtoumax.c,v 1.1 2006/04/22 15:33:33 thorpej Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1990, 1993
|
* Copyright (c) 1990, 1993
|
||||||
@ -29,12 +29,13 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if !defined(_KERNEL) && !defined(_STANDALONE)
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "from: @(#)strtoul.c 8.1 (Berkeley) 6/4/93";
|
static char sccsid[] = "from: @(#)strtoul.c 8.1 (Berkeley) 6/4/93";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: strtoumax.c,v 1.6 2005/11/29 03:12:00 christos Exp $");
|
__RCSID("$NetBSD: strtoumax.c,v 1.1 2006/04/22 15:33:33 thorpej Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
@ -50,6 +51,11 @@ __RCSID("$NetBSD: strtoumax.c,v 1.6 2005/11/29 03:12:00 christos Exp $");
|
|||||||
__weak_alias(strtoumax, _strtoumax)
|
__weak_alias(strtoumax, _strtoumax)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#else /* !_KERNEL && !_STANDALONE */
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <lib/libkern/libkern.h>
|
||||||
|
#endif /* !_KERNEL && !_STANDALONE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert a string to an uintmax_t.
|
* Convert a string to an uintmax_t.
|
||||||
*
|
*
|
||||||
@ -57,7 +63,7 @@ __weak_alias(strtoumax, _strtoumax)
|
|||||||
* alphabets and digits are each contiguous.
|
* alphabets and digits are each contiguous.
|
||||||
*/
|
*/
|
||||||
uintmax_t
|
uintmax_t
|
||||||
_strtoumax(nptr, endptr, base)
|
strtoumax(nptr, endptr, base)
|
||||||
const char *nptr;
|
const char *nptr;
|
||||||
char **endptr;
|
char **endptr;
|
||||||
int base;
|
int base;
|
||||||
@ -99,18 +105,28 @@ _strtoumax(nptr, endptr, base)
|
|||||||
for (acc = 0, any = 0;; c = (unsigned char) *s++) {
|
for (acc = 0, any = 0;; c = (unsigned char) *s++) {
|
||||||
if (isdigit(c))
|
if (isdigit(c))
|
||||||
c -= '0';
|
c -= '0';
|
||||||
else if (isalpha(c))
|
else if (isalpha(c)) {
|
||||||
|
#if defined(_KERNEL) || defined(_STANDALONE)
|
||||||
|
c = toupper(c) - 'A' + 10;
|
||||||
|
#else
|
||||||
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
||||||
else
|
#endif
|
||||||
|
} else
|
||||||
break;
|
break;
|
||||||
if (c >= base)
|
if (c >= base)
|
||||||
break;
|
break;
|
||||||
if (any < 0)
|
if (any < 0)
|
||||||
continue;
|
continue;
|
||||||
if (acc > cutoff || (acc == cutoff && c > cutlim)) {
|
if (acc > cutoff || (acc == cutoff && c > cutlim)) {
|
||||||
|
#if defined(_KERNEL) || defined(_STANDALONE)
|
||||||
|
if (endptr)
|
||||||
|
*endptr = __UNCONST(nptr);
|
||||||
|
return UINTMAX_MAX;
|
||||||
|
#else
|
||||||
any = -1;
|
any = -1;
|
||||||
acc = UINTMAX_MAX;
|
acc = UINTMAX_MAX;
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
any = 1;
|
any = 1;
|
||||||
acc *= (uintmax_t)base;
|
acc *= (uintmax_t)base;
|
@ -1,4 +1,4 @@
|
|||||||
# $NetBSD: Makefile,v 1.78 2006/03/11 15:40:07 kleink Exp $
|
# $NetBSD: Makefile,v 1.79 2006/04/22 15:33:33 thorpej Exp $
|
||||||
|
|
||||||
LIB= kern
|
LIB= kern
|
||||||
NOPIC= # defined
|
NOPIC= # defined
|
||||||
@ -47,6 +47,8 @@ SRCS+= _que.c arc4random.c bcd.c mcount.c
|
|||||||
|
|
||||||
SRCS+= strstr.c strlcpy.c strlcat.c
|
SRCS+= strstr.c strlcpy.c strlcat.c
|
||||||
|
|
||||||
|
SRCS+= strtoumax.c
|
||||||
|
|
||||||
SRCS+= xlat_mbr_fstype.c
|
SRCS+= xlat_mbr_fstype.c
|
||||||
|
|
||||||
# Files to clean up
|
# Files to clean up
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: libkern.h,v 1.61 2006/04/15 01:09:34 christos Exp $ */
|
/* $NetBSD: libkern.h,v 1.62 2006/04/22 15:33:33 thorpej Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1992, 1993
|
* Copyright (c) 1992, 1993
|
||||||
@ -35,6 +35,7 @@
|
|||||||
#define _LIB_LIBKERN_LIBKERN_H_
|
#define _LIB_LIBKERN_LIBKERN_H_
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/inttypes.h>
|
||||||
#include <sys/null.h>
|
#include <sys/null.h>
|
||||||
|
|
||||||
#ifndef LIBKERN_INLINE
|
#ifndef LIBKERN_INLINE
|
||||||
@ -330,4 +331,5 @@ size_t strlcpy __P((char *, const char *, size_t));
|
|||||||
size_t strlcat __P((char *, const char *, size_t));
|
size_t strlcat __P((char *, const char *, size_t));
|
||||||
int strncasecmp __P((const char *, const char *, size_t));
|
int strncasecmp __P((const char *, const char *, size_t));
|
||||||
u_long strtoul __P((const char *, char **, int));
|
u_long strtoul __P((const char *, char **, int));
|
||||||
|
uintmax_t strtoumax __P((const char *, char **, int));
|
||||||
#endif /* !_LIB_LIBKERN_LIBKERN_H_ */
|
#endif /* !_LIB_LIBKERN_LIBKERN_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user