summaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorabs <abs@NetBSD.org>2002-08-22 17:24:08 +0000
committerabs <abs@NetBSD.org>2002-08-22 17:24:08 +0000
commita086fb2909f41c19cc09269920031a067cc3836b (patch)
tree8fae8996fd47e1ba9afd756f200368ba98c38932 /lib/libutil
parent949583590ffa6c24307e57310d53ec661d495cd5 (diff)
Move humanize_number(3) from libutil to libc as per discussion on tech-misc
Revert minor number bump on libutil (with note to skip it next update), and bump libc.
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/Makefile14
-rw-r--r--lib/libutil/humanize_number.3134
-rw-r--r--lib/libutil/humanize_number.c136
-rw-r--r--lib/libutil/shlib_version5
-rw-r--r--lib/libutil/util.33
5 files changed, 11 insertions, 281 deletions
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile
index 582a107e2dd..092d74ee935 100644
--- a/lib/libutil/Makefile
+++ b/lib/libutil/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.35 2002/08/19 14:55:18 lukem Exp $
+# $NetBSD: Makefile,v 1.36 2002/08/22 17:24:10 abs Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
USE_SHLIBDIR= yes
@@ -8,14 +8,14 @@ USE_SHLIBDIR= yes
LIB= util
CPPFLAGS+=-DLIBC_SCCS
SRCS= fparseln.c getbootfile.c getmaxpartitions.c getrawpartition.c \
- humanize_number.c login.c login_cap.c login_tty.c \
- logout.c logwtmp.c opendisk.c passwd.c pw_scan.c pidfile.c pidlock.c \
- pty.c secure_path.c ttyaction.c ttymsg.c
+ login.c login_cap.c login_tty.c logout.c logwtmp.c opendisk.c \
+ passwd.c pw_scan.c pidfile.c pidlock.c pty.c secure_path.c \
+ ttyaction.c ttymsg.c
MAN= fparseln.3 getbootfile.3 getmaxpartitions.3 getrawpartition.3 \
- humanize_number.3 login.3 login_cap.3 opendisk.3 \
- openpty.3 pidfile.3 pidlock.3 pw_getconf.3 pw_init.3 pw_lock.3 \
- secure_path.3 ttyaction.3 ttymsg.3 util.3
+ login.3 login_cap.3 opendisk.3 openpty.3 pidfile.3 pidlock.3 \
+ pw_getconf.3 pw_init.3 pw_lock.3 secure_path.3 ttyaction.3 \
+ ttymsg.3 util.3
.PATH: ${NETBSDSRCDIR}/lib/libc/gen
diff --git a/lib/libutil/humanize_number.3 b/lib/libutil/humanize_number.3
deleted file mode 100644
index a771abf8630..00000000000
--- a/lib/libutil/humanize_number.3
+++ /dev/null
@@ -1,134 +0,0 @@
-.\" $NetBSD: humanize_number.3,v 1.2 2002/08/08 17:03:46 wiz Exp $
-.\"
-.\" Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
-.\" All rights reserved.
-.\"
-.\" This code is derived from software contributed to The NetBSD Foundation
-.\" by Luke Mewburn and by Tomas Svensson.
-.\"
-.\" 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.
-.\"
-.Dd March 14, 2002
-.Dt HUMANIZE_NUMBER 3
-.Os
-.Sh NAME
-.Nm humanize_number
-.Nd format a number into a human readable form
-.Sh SYNOPSIS
-.Fd #include \*[Lt]util.h\*[Gt]
-.Ft int
-.Fn humanize_number "char *buf" "size_t len" "int64_t number" "const char *suffix" "int scale" "int flags"
-.Sh DESCRIPTION
-The
-.Fn humanize_number
-function formats the signed 64 bit quantity given in
-.Fa number
-into
-.Fa buffer .
-A space and then
-.Fa suffix
-is appended to the end.
-.Fa buffer
-must be at least
-.Fa len
-bytes bytes long.
-.Pp
-If the formatted number (including
-.Fa suffix )
-would be too long to fit into
-.Fa buffer ,
-then divide
-.Fa number
-by 1024 until it will.
-In this case, prefix
-.Fa suffix
-with the appropriate SI designator.
-.Pp
-The prefixes are:
-.Bl -column "Prefix" "Description" "Multiplier" -offset indent
-.It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier"
-.It K kilo 1024
-.It M mega 1048576
-.It G giga 1073741824
-.It T tera 1099511627776
-.It P peta 1125899906842624
-.It E exa 1152921504606846976
-.El
-.Pp
-.Fa len
-must be at least 4 plus the length of
-.Fa suffix ,
-in order to ensure a useful result is generated into
-.Fa buffer .
-To use a specific prefix, specify this as
-.Fa scale
-(Multiplier = 1024 ^ scale). This can not be combined with any of the
-.Fa scale
-flags below.
-.Pp
-The following flags may be passed in
-.Pa scale :
-.Bl -tag -width Dv -offset indent
-.It Dv HN_AUTOSCALE
-Format the buffer using the lowest multiplier possible.
-.It Dv HN_GETSCALE
-Return the prefix index number (the number of times
-.Fa number
-must be divided to fit) instead of formatting it to the buffer.
-.El
-.Pp
-The following flags may be passed in
-.Pa flags :
-.Bl -tag -width Dv -offset indent
-.It Dv HN_DECIMAL
-If the final result is less than 10, display it using one digit.
-.It Dv HN_NOSPACE
-Do not put a space between
-.Fa number
-and the prefix.
-.It Dv HN_B
-Use 'B' (bytes) as prefix if the original result does not have a prefix.
-.It Dv HN_DIVISOR_1000
-Divide
-.Fa number
-with 1000 instead of 1024.
-.El
-.Sh RETURN VALUES
-.Fn humanize_number
-returns the number of characters stored in
-.Fa buffer
-(excluding the terminating NUL) upon success, or \-1 upon failure. If
-.Dv HN_GETSCALE
-is specified, the prefix index number will be returned instead.
-.Sh SEE ALSO
-.Xr humanize_number 9
-.Sh HISTORY
-.Fn humanize_number
-first appeared in
-.Nx 2.0 .
diff --git a/lib/libutil/humanize_number.c b/lib/libutil/humanize_number.c
deleted file mode 100644
index 189527a2f1a..00000000000
--- a/lib/libutil/humanize_number.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/* $NetBSD: humanize_number.c,v 1.3 2002/08/15 04:47:13 enami Exp $ */
-
-/*
- * Copyright (c) 1997, 1998, 1999, 2002 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, by Luke Mewburn and by Tomas Svensson.
- *
- * 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.
- */
-
-#include <sys/cdefs.h>
-#ifndef __lint
-__COPYRIGHT("@(#) Copyright (c) 2002\n\
- The NetBSD Foundation, inc. All rights reserved.\n");
-__RCSID("$NetBSD: humanize_number.c,v 1.3 2002/08/15 04:47:13 enami Exp $");
-#endif /* !__lint */
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <locale.h>
-#include <util.h>
-
-int
-humanize_number(char *buf, size_t len, int64_t bytes,
- const char *suffix, int scale, int flags)
-{
- static const char prefixes[] = " KMGTPE";
-
- int i, r;
- int64_t divisor, max, s1, s2, sign;
- size_t baselen, suffixlen;
-
- _DIAGASSERT(buf != NULL);
- _DIAGASSERT(suffix != NULL);
-
- if (scale >= sizeof(prefixes) && scale != HN_AUTOSCALE &&
- scale != HN_GETSCALE)
- return (-1);
-
- if (buf == NULL || suffix == NULL)
- return (-1);
-
- if (len > 0)
- buf[0] = '\0';
- if (bytes < 0) {
- sign = -1;
- bytes *= -100;
- baselen = 4;
- } else {
- sign = 1;
- bytes *= 100;
- baselen = 3;
- }
-
- suffixlen = strlen(suffix);
-
- /* check if enough room for `x y' + suffix + `\0' */
- if (len < baselen + suffixlen + 1)
- return (-1);
-
- if (flags & HN_DIVISOR_1000)
- divisor = 1000;
- else
- divisor = 1024;
-
- max = 100;
- for (i = 0; i < len - suffixlen - baselen + ((flags & HN_NOSPACE) ?
- 1 : 0); i++)
- max *= 10;
-
- if ((scale & HN_AUTOSCALE) || (scale & HN_GETSCALE)) {
- for (i = 0; bytes >= max && i < sizeof(prefixes); i++)
- bytes /= divisor;
- } else {
- for (i = 0; i < scale && i < sizeof(prefixes); i++)
- bytes /= divisor;
- }
-
- if (scale & HN_GETSCALE)
- return (i);
-
- if (bytes < 1000 && flags & HN_DECIMAL) {
- if (len < (baselen + 2 + ((flags & HN_NOSPACE) || (i == 0 &&
- !(flags & HN_B)) ? 0 : 1)))
- return (-1);
- s1 = bytes / 100;
- if ((s2 = (((bytes % 100) + 5) / 10)) == 10) {
- s1++;
- s2 = 0;
- }
- r = snprintf(buf, len, "%lld%s%lld%s%c%s",
- (long long)(sign * s1),
- localeconv()->decimal_point, (long long)s2,
- (i == 0 && !(flags & HN_B)) || flags & HN_NOSPACE ?
- "" : " ", (i == 0 && (flags & HN_B)) ? 'B' :
- prefixes[i], suffix);
-
- } else
- r = snprintf(buf, len, "%lld%s%c%s",
- (long long)(sign * ((bytes + 50) / 100)),
- i == 0 || flags & HN_NOSPACE ? "" : " ", (i == 0 &&
- (flags & HN_B)) ? 'B' : prefixes[i], suffix);
-
- return (r);
-}
diff --git a/lib/libutil/shlib_version b/lib/libutil/shlib_version
index 6527f096eff..881ede4995c 100644
--- a/lib/libutil/shlib_version
+++ b/lib/libutil/shlib_version
@@ -1,5 +1,6 @@
-# $NetBSD: shlib_version,v 1.26 2002/08/10 01:51:43 thorpej Exp $
+# $NetBSD: shlib_version,v 1.27 2002/08/22 17:24:11 abs Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
+# Note: Skip minor number 2 when updating
major=6
-minor=2
+minor=1
diff --git a/lib/libutil/util.3 b/lib/libutil/util.3
index fabbf75474f..9cb12470ba1 100644
--- a/lib/libutil/util.3
+++ b/lib/libutil/util.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: util.3,v 1.8 2002/08/12 20:03:05 gmcgarry Exp $
+.\" $NetBSD: util.3,v 1.9 2002/08/22 17:24:11 abs Exp $
.\"
.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -65,7 +65,6 @@ fparseln.3 return the next logical line from a stream
getbootfile.3 get the name of the booted kernel file
getmaxpartitions.3 get the maximum number of partitions allowed per disk
getrawpartition.3 get the system ``raw'' partition
-humanize_number.3 format a number into a human readable form
login.3 login utility function
login_close.3 query login.conf database about a user class
login_getcapbool.3 query login.conf database about a user class