Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/bouyer-quota2]: src/usr.bin/quota Allow to pass HN_PRIV_UNLIMITED flag (...
details: https://anonhg.NetBSD.org/src/rev/ed36305134d5
branches: bouyer-quota2
changeset: 761079:ed36305134d5
user: bouyer <bouyer%NetBSD.org@localhost>
date: Sat Jan 29 17:42:37 2011 +0000
description:
Allow to pass HN_PRIV_UNLIMITED flag (private to printquota consumers),
which cause it to return "unlimited" instead of "-" of UQUAD_MAX.
Introduce intrd(), which parses a string and return a value appropriate
for quota limits. The string can be a decimal number, a value in
understandable by dehumanize_number(), "-" or "unlimited".
diffstat:
usr.bin/quota/printquota.c | 47 ++++++++++++++++++++++++++++++++++++++++++---
usr.bin/quota/printquota.h | 7 ++++-
2 files changed, 48 insertions(+), 6 deletions(-)
diffs (96 lines):
diff -r 7726fece2b9f -r ed36305134d5 usr.bin/quota/printquota.c
--- a/usr.bin/quota/printquota.c Sat Jan 29 11:04:43 2011 +0000
+++ b/usr.bin/quota/printquota.c Sat Jan 29 17:42:37 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: printquota.c,v 1.1.2.1 2011/01/21 16:58:06 bouyer Exp $ */
+/* $NetBSD: printquota.c,v 1.1.2.2 2011/01/29 17:42:37 bouyer Exp $ */
/*
* Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)quota.c 8.4 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: printquota.c,v 1.1.2.1 2011/01/21 16:58:06 bouyer Exp $");
+__RCSID("$NetBSD: printquota.c,v 1.1.2.2 2011/01/29 17:42:37 bouyer Exp $");
#endif
#endif /* not lint */
@@ -55,6 +55,9 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
+#include <inttypes.h>
#include <printquota.h>
@@ -62,12 +65,14 @@
* convert 64bit value to a printable string
*/
const char *
-intprt(uint64_t val, int flags, int hflag)
+intprt(uint64_t val, u_int flags, int hflag)
{
static char buf[21];
if (val == UQUAD_MAX)
- return("-");
+ return((flags & HN_PRIV_UNLIMITED) ? "unlimited" : "-");
+
+ flags &= ~HN_PRIV_UNLIMITED;
if (flags & HN_B)
val = dbtob(val);
@@ -114,3 +119,37 @@
(void)snprintf(buf, sizeof buf, "%2d", (int)minutes);
return (buf);
}
+
+/*
+ * convert a string to a uint64 value
+ */
+int
+intrd(char *str, uint64_t *val, u_int flags)
+{
+ char *last = &str[strlen(str) - 1];
+ int ret;
+
+ if (*last >= '0' && *last <= '9') {
+ /* no unit provided, use default */
+ errno = 0;
+ *val = strtoumax(str, NULL, 10);
+ if (flags & HN_B) {
+ /* in kb, convert to disk blocks */
+ *val = btodb(*val * 1024);
+ }
+
+ return errno;
+ }
+ if (strcmp(str, "-") == 0 || strcmp(str, "unlimited") == 0) {
+ *val = UQUAD_MAX;
+ return 0;
+ }
+ if (flags & HN_B) {
+ if (*last == 'B' || *last == 'b')
+ *last = '\0';
+ }
+ ret = dehumanize_number(str, (int64_t *)val);
+ if (flags & HN_B)
+ *val = btodb(*val);
+ return ret;
+}
diff -r 7726fece2b9f -r ed36305134d5 usr.bin/quota/printquota.h
--- a/usr.bin/quota/printquota.h Sat Jan 29 11:04:43 2011 +0000
+++ b/usr.bin/quota/printquota.h Sat Jan 29 17:42:37 2011 +0000
@@ -1,4 +1,7 @@
-/* $NetBSD: printquota.h,v 1.1.2.2 2011/01/28 22:15:36 bouyer Exp $ */
+/* $NetBSD: printquota.h,v 1.1.2.3 2011/01/29 17:42:37 bouyer Exp $ */
-const char *intprt(uint64_t, int, int);
+const char *intprt(uint64_t, u_int, int);
+#define HN_PRIV_UNLIMITED 0x80000000 /* print "unlimited" instead of "-" */
const char *timeprt(time_t);
+int intrd(char *str, uint64_t *val, u_int);
+
Home |
Main Index |
Thread Index |
Old Index