Module Name: src Committed By: bouyer Date: Sat Jan 29 17:42:38 UTC 2011
Modified Files: src/usr.bin/quota [bouyer-quota2]: printquota.c printquota.h Log Message: 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". To generate a diff of this commit: cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/usr.bin/quota/printquota.c cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/usr.bin/quota/printquota.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/quota/printquota.c diff -u src/usr.bin/quota/printquota.c:1.1.2.1 src/usr.bin/quota/printquota.c:1.1.2.2 --- src/usr.bin/quota/printquota.c:1.1.2.1 Fri Jan 21 16:58:06 2011 +++ src/usr.bin/quota/printquota.c Sat Jan 29 17:42:37 2011 @@ -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; +} Index: src/usr.bin/quota/printquota.h diff -u src/usr.bin/quota/printquota.h:1.1.2.2 src/usr.bin/quota/printquota.h:1.1.2.3 --- src/usr.bin/quota/printquota.h:1.1.2.2 Fri Jan 28 22:15:36 2011 +++ src/usr.bin/quota/printquota.h Sat Jan 29 17:42:37 2011 @@ -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); +