Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src - new test for strtoi
details: https://anonhg.NetBSD.org/src/rev/f96fc599fe56
branches: trunk
changeset: 337856:f96fc599fe56
user: christos <christos%NetBSD.org@localhost>
date: Fri May 01 14:17:56 2015 +0000
description:
- new test for strtoi
- namespace protection for strto{i,u}
- separate manpages for strto{i,u} from the ones for strto{u,}l
From: Kamil Rytarowski
diffstat:
common/lib/libc/stdlib/strtoi.c | 13 +-
common/lib/libc/stdlib/strtou.c | 13 +-
distrib/sets/lists/debug/mi | 3 +-
distrib/sets/lists/tests/mi | 3 +-
lib/libc/include/namespace.h | 6 +-
lib/libc/stdlib/Makefile.inc | 8 +-
lib/libc/stdlib/strtoi.3 | 223 ++++++++++++++++++++++++++++
lib/libc/stdlib/strtol.3 | 99 +----------
lib/libc/stdlib/strtou.3 | 222 ++++++++++++++++++++++++++++
lib/libc/stdlib/strtoul.3 | 100 ++----------
tests/lib/libc/stdlib/Makefile | 3 +-
tests/lib/libc/stdlib/t_strtoi.c | 304 +++++++++++++++++++++++++++++++++++++++
12 files changed, 819 insertions(+), 178 deletions(-)
diffs (truncated from 1300 to 300 lines):
diff -r 7c6395404ba1 -r f96fc599fe56 common/lib/libc/stdlib/strtoi.c
--- a/common/lib/libc/stdlib/strtoi.c Fri May 01 13:48:05 2015 +0000
+++ b/common/lib/libc/stdlib/strtoi.c Fri May 01 14:17:56 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: strtoi.c,v 1.1 2015/01/16 18:35:28 christos Exp $ */
+/* $NetBSD: strtoi.c,v 1.2 2015/05/01 14:17:56 christos Exp $ */
/*-
* Copyright (c) 2005 The DragonFly Project. All rights reserved.
@@ -35,7 +35,11 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: strtoi.c,v 1.1 2015/01/16 18:35:28 christos Exp $");
+__RCSID("$NetBSD: strtoi.c,v 1.2 2015/05/01 14:17:56 christos Exp $");
+
+#ifdef _LIBC
+#include "namespace.h"
+#endif
#if defined(_KERNEL)
#include <sys/param.h>
@@ -57,6 +61,9 @@
#define __TYPE intmax_t
#define __WRAPPED strtoimax
-#if !HAVE_STRTOI
#include "_strtoi.h"
+
+#ifdef _LIBC
+__weak_alias(strtoi, _strtoi)
+__weak_alias(strtoi_l, _strtoi_l)
#endif
diff -r 7c6395404ba1 -r f96fc599fe56 common/lib/libc/stdlib/strtou.c
--- a/common/lib/libc/stdlib/strtou.c Fri May 01 13:48:05 2015 +0000
+++ b/common/lib/libc/stdlib/strtou.c Fri May 01 14:17:56 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: strtou.c,v 1.1 2015/01/16 18:35:28 christos Exp $ */
+/* $NetBSD: strtou.c,v 1.2 2015/05/01 14:17:56 christos Exp $ */
/*-
* Copyright (c) 2005 The DragonFly Project. All rights reserved.
@@ -35,7 +35,11 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: strtou.c,v 1.1 2015/01/16 18:35:28 christos Exp $");
+__RCSID("$NetBSD: strtou.c,v 1.2 2015/05/01 14:17:56 christos Exp $");
+
+#ifdef _LIBC
+#include "namespace.h"
+#endif
#if defined(_KERNEL)
#include <sys/param.h>
@@ -57,6 +61,9 @@
#define __TYPE uintmax_t
#define __WRAPPED strtoumax
-#if !HAVE_STRTOU
#include "_strtoi.h"
+
+#ifdef _LIBC
+__weak_alias(strtou, _strtou)
+__weak_alias(strtou_l, _strtou_l)
#endif
diff -r 7c6395404ba1 -r f96fc599fe56 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi Fri May 01 13:48:05 2015 +0000
+++ b/distrib/sets/lists/debug/mi Fri May 01 14:17:56 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.112 2015/04/17 10:00:02 pgoyette Exp $
+# $NetBSD: mi,v 1.113 2015/05/01 14:17:56 christos Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib
@@ -1947,6 +1947,7 @@
./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_posix_memalign.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_random.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_strtod.debug tests-lib-debug debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_strtoi.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_strtol.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_strtox.debug tests-obsolete obsolete
./usr/libdata/debug/usr/tests/lib/libc/stdlib/t_system.debug tests-lib-debug debug,atf
diff -r 7c6395404ba1 -r f96fc599fe56 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Fri May 01 13:48:05 2015 +0000
+++ b/distrib/sets/lists/tests/mi Fri May 01 14:17:56 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.616 2015/04/09 16:47:57 ginsbach Exp $
+# $NetBSD: mi,v 1.617 2015/05/01 14:17:56 christos Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -2610,6 +2610,7 @@
./usr/tests/lib/libc/stdlib/t_posix_memalign tests-lib-tests atf
./usr/tests/lib/libc/stdlib/t_random tests-lib-tests atf
./usr/tests/lib/libc/stdlib/t_strtod tests-lib-tests atf
+./usr/tests/lib/libc/stdlib/t_strtoi tests-lib-tests atf
./usr/tests/lib/libc/stdlib/t_strtol tests-lib-tests atf
./usr/tests/lib/libc/stdlib/t_strtox tests-obsolete obsolete
./usr/tests/lib/libc/stdlib/t_system tests-lib-tests atf
diff -r 7c6395404ba1 -r f96fc599fe56 lib/libc/include/namespace.h
--- a/lib/libc/include/namespace.h Fri May 01 13:48:05 2015 +0000
+++ b/lib/libc/include/namespace.h Fri May 01 14:17:56 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: namespace.h,v 1.177 2015/02/17 20:29:21 joerg Exp $ */
+/* $NetBSD: namespace.h,v 1.178 2015/05/01 14:17:56 christos Exp $ */
/*-
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -65,12 +65,16 @@
#define strtod_l _strtod_l
#define strtof _strtof
#define strtof_l _strtof_l
+#define strtoi _strtoi
+#define strtoi_l _strtoi_l
#define strtoimax _strtoimax
#define strtoimax_l _strtoimax_l
#define strtold _strtold
#define strtold_l _strtold_l
#define strtoll _strtoll
#define strtoll_l _strtoll_l
+#define strtou _strtou
+#define strtou_l _strtou_l
#define strtoull _strtoull
#define strtoull_l _strtoull_l
#define strtoumax _strtoumax
diff -r 7c6395404ba1 -r f96fc599fe56 lib/libc/stdlib/Makefile.inc
--- a/lib/libc/stdlib/Makefile.inc Fri May 01 13:48:05 2015 +0000
+++ b/lib/libc/stdlib/Makefile.inc Fri May 01 14:17:56 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.89 2015/02/17 20:29:21 joerg Exp $
+# $NetBSD: Makefile.inc,v 1.90 2015/05/01 14:17:56 christos Exp $
# from: @(#)Makefile.inc 8.3 (Berkeley) 2/4/95
# stdlib sources
@@ -53,8 +53,8 @@
posix_memalign.3 posix_openpt.3 ptsname.3 \
qabs.3 qdiv.3 quick_exit.3 qsort.3 \
radixsort.3 rand48.3 rand.3 random.3 reallocarr.3 reallocarray.3 \
- strfmon.3 strsuftoll.3 strtod.3 strtol.3 strtoul.3 strtonum.3 \
- system.3 \
+ strfmon.3 strsuftoll.3 strtod.3 strtoi.3 strtol.3 strtou.3 strtoul.3 \
+ strtonum.3 system.3 \
tsearch.3 \
unlockpt.3
@@ -88,9 +88,7 @@
MLINKS+=strtol.3 strtoimax.3
MLINKS+=strtol.3 strtoll.3
MLINKS+=strtol.3 strtoq.3
-MLINKS+=strtol.3 strtoi.3
MLINKS+=strtoul.3 strtoull.3
MLINKS+=strtoul.3 strtoumax.3
MLINKS+=strtoul.3 strtouq.3
-MLINKS+=strtoul.3 strtou.3
MLINKS+=tsearch.3 tfind.3 tsearch.3 twalk.3 tsearch.3 tdelete.3
diff -r 7c6395404ba1 -r f96fc599fe56 lib/libc/stdlib/strtoi.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/stdlib/strtoi.3 Fri May 01 14:17:56 2015 +0000
@@ -0,0 +1,223 @@
+.\" $NetBSD: strtoi.3,v 1.1 2015/05/01 14:17:56 christos 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: @(#)strtol.3 8.1 (Berkeley) 6/4/93
+.\"
+.\" Created by Kamil Rytarowski, based on ID:
+.\" NetBSD: strtol.3,v 1.31 2015/03/11 09:57:35 wiz Exp
+.\"
+.Dd April 30, 2015
+.Dt STRTOI 3
+.Os
+.Sh NAME
+.Nm strtoi
+.Nd convert string value to an intmax_t integer
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In inttypes.h
+.Ft intmax_t
+.Fo strtoi
+.Fa "const char * restrict nptr"
+.Fa "char ** restrict endptr"
+.Fa "int base"
+.Fa "intmax_t lo"
+.Fa "intmax_t hi"
+.Fa "int *rstatus"
+.Sh DESCRIPTION
+The
+.Fn strtoi
+function
+converts the string in
+.Fa nptr
+to an
+.Ft intmax_t
+value.
+The
+.Fn strtoi
+function uses internally
+.Xr strtoimax 3
+and ensures that the result is always in the range [
+.Fa lo ..
+.Fa hi
+].
+In adddition it always places
+.Dv 0
+on success or a conversion status in the
+.Fa rstatus
+argument, avoiding the
+.Dv errno
+gymnastics the other functions require.
+The
+.Fa rstatus
+argument can be
+.Dv NULL
+if conversion status is to be ignored.
+.Pp
+The string may begin with an arbitrary amount of white space
+(as determined by
+.Xr isspace 3 )
+followed by a single optional
+.Ql +
+or
+.Ql -
+sign.
+If
+.Fa base
+is zero or 16,
+the string may then include a
+.Ql 0x
+prefix,
+and the number will be read in base 16; otherwise, a zero
+.Fa base
+is taken as 10 (decimal) unless the next character is
+.Ql 0 ,
+in which case it is taken as 8 (octal).
+.Pp
+The remainder of the string is converted to a
+.Em intmax_t
+value in the obvious manner,
+stopping at the first character which is not a valid digit
+in the given base.
+(In bases above 10, the letter
+.Ql A
+in either upper or lower case
+represents 10,
+.Ql B
+represents 11, and so forth, with
+.Ql Z
+representing 35.)
+.Pp
+If
+.Fa endptr
+is non-nil,
+.Fn strtoi
+stores the address of the first invalid character in
+.Fa *endptr .
+If there were no digits at all, however,
+.Fn strtoi
+stores the original value of
+.Fa nptr
+in
+.Fa *endptr .
+(Thus, if
+.Fa *nptr
+is not
+.Ql \e0
+but
+.Fa **endptr
+is
+.Ql \e0
Home |
Main Index |
Thread Index |
Old Index