Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libutil add estro{i,u} (Kamil Rytarowski)
details: https://anonhg.NetBSD.org/src/rev/08430d51b7b8
branches: trunk
changeset: 335646:08430d51b7b8
user: christos <christos%NetBSD.org@localhost>
date: Sun Jan 18 18:09:36 2015 +0000
description:
add estro{i,u} (Kamil Rytarowski)
diffstat:
lib/libutil/Makefile | 4 +++-
lib/libutil/efun.3 | 19 ++++++++++++++++++-
lib/libutil/efun.c | 33 +++++++++++++++++++++++++++++++--
3 files changed, 52 insertions(+), 4 deletions(-)
diffs (125 lines):
diff -r e1533c5ba176 -r 08430d51b7b8 lib/libutil/Makefile
--- a/lib/libutil/Makefile Sun Jan 18 18:09:10 2015 +0000
+++ b/lib/libutil/Makefile Sun Jan 18 18:09:36 2015 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.75 2013/06/20 20:42:30 christos Exp $
+# $NetBSD: Makefile,v 1.76 2015/01/18 18:09:36 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
USE_SHLIBDIR= yes
@@ -77,6 +77,8 @@
MLINKS+=efun.3 estrlcat.3
MLINKS+=efun.3 estrdup.3
MLINKS+=efun.3 estrndup.3
+MLINKS+=efun.3 estrtoi.3
+MLINKS+=efun.3 estrtou.3
MLINKS+=efun.3 emalloc.3
MLINKS+=efun.3 ecalloc.3
MLINKS+=efun.3 erealloc.3
diff -r e1533c5ba176 -r 08430d51b7b8 lib/libutil/efun.3
--- a/lib/libutil/efun.3 Sun Jan 18 18:09:10 2015 +0000
+++ b/lib/libutil/efun.3 Sun Jan 18 18:09:36 2015 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: efun.3,v 1.10 2010/05/03 05:40:37 jruoho Exp $
+.\" $NetBSD: efun.3,v 1.11 2015/01/18 18:09:36 christos Exp $
.\"
.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -41,6 +41,8 @@
.Nm estrndup ,
.Nm estrlcat ,
.Nm estrlcpy ,
+.Nm estrtoi ,
+.Nm estrtou ,
.Nm evasprintf
.Nd error-checked utility functions
.Sh LIBRARY
@@ -67,6 +69,10 @@
.Fn estrlcat "char *dst" "const char *src" "size_t len"
.Ft size_t
.Fn estrlcpy "char *dst" "const char *src" "size_t len"
+.Ft intmax_t
+.Fn estrtoi "const char * nptr" "int base" "intmax_t lo" "intmax_t hi"
+.Ft uintmax_t
+.Fn estrtou "const char * nptr" "int base" "uintmax_t lo" "uintmax_t hi"
.Ft int
.Fn evasprintf "char ** restrict str" "const char * restrict fmt" "..."
.Sh DESCRIPTION
@@ -80,6 +86,8 @@
.Fn estrndup ,
.Fn estrlcat ,
.Fn estrlcpy ,
+.Fn estrtoi ,
+.Fn estrtou ,
and
.Fn evasprintf
functions
@@ -114,4 +122,13 @@
.Xr strlcat 3 ,
.Xr strlcpy 3 ,
.Xr strndup 3 ,
+.Xr strtoi 3 ,
+.Xr strtou 3 ,
.Xr vasprintf 3
+.Sh HISTORY
+The
+.Fn estrtoi
+and
+.Fn estrtou
+functions were added in
+.Nx 8 .
diff -r e1533c5ba176 -r 08430d51b7b8 lib/libutil/efun.c
--- a/lib/libutil/efun.c Sun Jan 18 18:09:10 2015 +0000
+++ b/lib/libutil/efun.c Sun Jan 18 18:09:36 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efun.c,v 1.8 2012/12/30 17:37:13 dholland Exp $ */
+/* $NetBSD: efun.c,v 1.9 2015/01/18 18:09:36 christos Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -35,11 +35,12 @@
#include <sys/cdefs.h>
#ifdef __RCSID
-__RCSID("$NetBSD: efun.c,v 1.8 2012/12/30 17:37:13 dholland Exp $");
+__RCSID("$NetBSD: efun.c,v 1.9 2015/01/18 18:09:36 christos Exp $");
#endif
#include <err.h>
#include <errno.h>
+#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -156,3 +157,31 @@
(*efunc)(1, "Cannot format string");
return rv;
}
+
+intmax_t
+estrtoi(const char * nptr, int base, intmax_t lo, intmax_t hi)
+{
+ int e;
+ intmax_t rv = strtoi(nptr, NULL, base, lo, hi, &e);
+ if (e != 0) {
+ errno = e;
+ (*efunc)(1,
+ "Cannot convert string value '%s' with base %d to a number in range [%jd .. %jd]",
+ nptr, base, lo, hi);
+ }
+ return rv;
+}
+
+uintmax_t
+estrtou(const char * nptr, int base, uintmax_t lo, uintmax_t hi)
+{
+ int e;
+ uintmax_t rv = strtou(nptr, NULL, base, lo, hi, &e);
+ if (e != 0) {
+ errno = e;
+ (*efunc)(1,
+ "Cannot convert string value '%s' with base %d to a number in range [%ju .. %ju]",
+ nptr, base, lo, hi);
+ }
+ return rv;
+}
Home |
Main Index |
Thread Index |
Old Index