Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/quota - WARNS=4
details: https://anonhg.NetBSD.org/src/rev/a1a600714184
branches: trunk
changeset: 762970:a1a600714184
user: christos <christos%NetBSD.org@localhost>
date: Sun Mar 06 20:47:59 2011 +0000
description:
- WARNS=4
- KNF
- don't cast malloc
- don't use static buffers
- fix types
- remove extra \n's from errors
- fix prototypes
diffstat:
usr.bin/quota/Makefile | 3 +-
usr.bin/quota/getvfsquota.c | 43 ++----
usr.bin/quota/getvfsquota.h | 4 +-
usr.bin/quota/printquota.c | 87 ++++++-------
usr.bin/quota/printquota.h | 8 +-
usr.bin/quota/quota.c | 275 ++++++++++++++++++++-----------------------
6 files changed, 192 insertions(+), 228 deletions(-)
diffs (truncated from 858 to 300 lines):
diff -r 92c628b5ee36 -r a1a600714184 usr.bin/quota/Makefile
--- a/usr.bin/quota/Makefile Sun Mar 06 20:36:29 2011 +0000
+++ b/usr.bin/quota/Makefile Sun Mar 06 20:47:59 2011 +0000
@@ -1,6 +1,7 @@
-# $NetBSD: Makefile,v 1.7 2011/03/06 17:08:42 bouyer Exp $
+# $NetBSD: Makefile,v 1.8 2011/03/06 20:47:59 christos Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
+WARNS ?= 4
.include <bsd.own.mk>
PROG= quota
SRCS= quota.c printquota.c getvfsquota.c
diff -r 92c628b5ee36 -r a1a600714184 usr.bin/quota/getvfsquota.c
--- a/usr.bin/quota/getvfsquota.c Sun Mar 06 20:36:29 2011 +0000
+++ b/usr.bin/quota/getvfsquota.c Sun Mar 06 20:47:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getvfsquota.c,v 1.2 2011/03/06 17:08:42 bouyer Exp $ */
+/* $NetBSD: getvfsquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $ */
/*-
* Copyright (c) 2011 Manuel Bouyer
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: getvfsquota.c,v 1.2 2011/03/06 17:08:42 bouyer Exp $");
+__RCSID("$NetBSD: getvfsquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $");
#include <stdio.h>
#include <stdlib.h>
@@ -49,13 +49,12 @@
/* retrieve quotas from vfs, for the given user id */
int
getvfsquota(const char *mp, struct quota2_entry *q2e, int8_t *versp,
- long id, int type, int defaultq, int debug)
+ uint32_t id, int type, int defaultq, int debug)
{
prop_dictionary_t dict, data, cmd;
prop_array_t cmds, datas;
prop_object_iterator_t iter;
struct plistref pref;
- int error;
int8_t error8;
bool ret;
int retval = 0;
@@ -95,17 +94,14 @@
if (quotactl(mp, &pref) != 0)
err(1, "quotactl");
- if ((error = prop_dictionary_recv_syscall(&pref, &dict)) != 0) {
- errx(1, "prop_dictionary_recv_syscall: %s\n",
- strerror(error));
- }
+ if ((errno = prop_dictionary_recv_syscall(&pref, &dict)) != 0)
+ err(1, "prop_dictionary_recv_syscall");
if (debug)
printf("reply from kernel:\n%s\n",
prop_dictionary_externalize(dict));
- if ((error = quota2_get_cmds(dict, &cmds)) != 0) {
- errx(1, "quota2_get_cmds: %s\n",
- strerror(error));
- }
+ if ((errno = quota2_get_cmds(dict, &cmds)) != 0)
+ err(1, "quota2_get_cmds");
+
iter = prop_array_iterator(cmds);
if (iter == NULL)
err(1, "prop_array_iterator(cmds)");
@@ -120,20 +116,17 @@
if (error8) {
if (error8 != ENOENT && error8 != ENODEV) {
+ errno = error8;
if (defaultq) {
- fprintf(stderr,
- "get default %s quota: %s\n",
- qfextension[type],
- strerror(error8));
+ warn("get default %s quota",
+ qfextension[type]);
} else {
- fprintf(stderr,
- "get %s quota for %ld: %s\n",
- qfextension[type], id,
- strerror(error8));
+ warn("get %s quota for %u",
+ qfextension[type], id);
}
}
prop_object_release(dict);
- return (0);
+ return 0;
}
datas = prop_dictionary_get(cmd, "data");
if (datas == NULL)
@@ -156,11 +149,9 @@
if (data == NULL)
err(1, "prop_array_get(data)");
- error = quota2_dict_get_q2e_usage(data, q2e);
- if (error) {
- errx(1, "quota2_dict_get_q2e_usage: %s\n",
- strerror(error));
- }
+ errno = quota2_dict_get_q2e_usage(data, q2e);
+ if (errno)
+ err(1, "quota2_dict_get_q2e_usage");
retval = 1;
}
}
diff -r 92c628b5ee36 -r a1a600714184 usr.bin/quota/getvfsquota.h
--- a/usr.bin/quota/getvfsquota.h Sun Mar 06 20:36:29 2011 +0000
+++ b/usr.bin/quota/getvfsquota.h Sun Mar 06 20:47:59 2011 +0000
@@ -1,6 +1,6 @@
-/* $NetBSD: getvfsquota.h,v 1.2 2011/03/06 17:08:42 bouyer Exp $ */
+/* $NetBSD: getvfsquota.h,v 1.3 2011/03/06 20:47:59 christos Exp $ */
int getvfsquota(const char *, struct quota2_entry *, int8_t *,
- long, int, int, int);
+ uint32_t, int, int, int);
extern const char *qfextension[];
diff -r 92c628b5ee36 -r a1a600714184 usr.bin/quota/printquota.c
--- a/usr.bin/quota/printquota.c Sun Mar 06 20:36:29 2011 +0000
+++ b/usr.bin/quota/printquota.c Sun Mar 06 20:47:59 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: printquota.c,v 1.2 2011/03/06 17:08:42 bouyer Exp $ */
+/* $NetBSD: printquota.c,v 1.3 2011/03/06 20:47:59 christos 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.2 2011/03/06 17:08:42 bouyer Exp $");
+__RCSID("$NetBSD: printquota.c,v 1.3 2011/03/06 20:47:59 christos Exp $");
#endif
#endif /* not lint */
@@ -65,32 +65,24 @@
* convert 64bit value to a printable string
*/
const char *
-intprt(uint64_t val, u_int flags, int hflag, int space)
+intprt(char *buf, size_t len, uint64_t val, int flags, int hflag)
{
-#define NBUFS 3
- static char bufs[NBUFS][21];
- char *buf;
- static int i = 0;
-
- buf = bufs[i++];
- if (i == NBUFS)
- i = 0;
-#undef NBUFS
if (val == UQUAD_MAX)
- return ((u_int)space > strlen("unlimited")) ? "unlimited" : "-";
+ return (len >= sizeof("unlimited")) ? "unlimited" : "-";
if (flags & HN_B)
val = dbtob(val);
if (hflag) {
- humanize_number(buf, space + 1, val, "", HN_AUTOSCALE, flags);
+ (void)humanize_number(buf, len, (int64_t)val, "", HN_AUTOSCALE,
+ flags);
return buf;
}
if (flags & HN_B) {
/* traditionnal display: blocks are in kilobytes */
val = val / 1024;
}
- snprintf(buf, space + 1, "%" PRIu64, val);
+ (void)snprintf(buf, len, "%" PRId64, val);
return buf;
}
@@ -105,13 +97,12 @@
#define YEAR (DAY * 355)
const char *
-timeprt(time_t now, time_t seconds, int space)
+timeprt(char *buf, size_t len, time_t now, time_t seconds)
{
time_t years, months, weeks, days, hours, minutes;
- static char buf[20];
if (now > seconds)
- return ("none");
+ return "none";
seconds -= now;
@@ -123,81 +114,80 @@
weeks = (seconds + WEEK / 2) / WEEK;
if (years >= 2) {
- (void)snprintf(buf, space+1, "%" PRId64 "years", years);
+ (void)snprintf(buf, len, "%" PRId64 "years", years);
return buf;
}
if (weeks > 9) {
- (void)snprintf(buf, space+1, "%" PRId64 "months", months);
+ (void)snprintf(buf, len, "%" PRId64 "months", months);
return buf;
}
if (days > 9) {
- (void)snprintf(buf, space+1, "%" PRId64 "weeks", weeks);
+ (void)snprintf(buf, len, "%" PRId64 "weeks", weeks);
return buf;
}
if (hours > 36) {
- (void)snprintf(buf, space+1, "%" PRId64 "days", days);
+ (void)snprintf(buf, len, "%" PRId64 "days", days);
return buf;
}
if (minutes > 60) {
- (void)snprintf(buf, space+1, "%2d:%d",
+ (void)snprintf(buf, len, "%2d:%d",
(int)(minutes / 60), (int)(minutes % 60));
return buf;
}
- (void)snprintf(buf, sizeof buf, "%2d", (int)minutes);
+ (void)snprintf(buf, len, "%2d", (int)minutes);
return buf;
}
+#if 0
/*
* Calculate the grace period and return a precise string for it,
* either in seconds or in format xWyDzHtMuS
*/
const char *
-timepprt(time_t seconds, int hflag, int space)
+timepprt(char *buf, size_t len, time_t seconds, int hflag, int space)
{
- static char buf[20], *append;
- int i, remain = space + 1;
+ ssize_t i = 0;
if (hflag == 0) {
- snprintf(buf, remain, "%" PRId64, seconds);
+ (void)snprintf(buf, len, "%" PRId64, seconds);
return buf;
}
- append = &buf[0];
if ((seconds / WEEK) > 0) {
- i = snprintf(append, remain, "%" PRId64 "W", (seconds / WEEK));
- append += i;
- remain -=i;
+ i += snprintf(buf + i, len - i, "%" PRId64 "W", seconds / WEEK);
seconds = seconds % WEEK;
}
+
if (remain < 3 || seconds == 0)
- return (buf);
+ return buf;
+
if ((seconds / DAY) > 0) {
- i = snprintf(append, remain, "%" PRId64 "D", (seconds / DAY));
- append += i;
- remain -=i;
+ i += snprintf(buf + i, len - i, "%" PRId64 "D", seconds / DAY);
seconds = seconds % DAY;
}
+
if (remain < 4 || seconds == 0)
- return (buf);
+ return buf;
+
if ((seconds / HOUR) > 0) {
- i = snprintf(append, remain, "%" PRId64 "H", (seconds / HOUR));
- append += i;
- remain -=i;
+ i += snprintf(buf + i, len - i, "%" PRId64 "H", seconds / HOUR);
seconds = seconds % HOUR;
}
+
if (remain < 4 || seconds == 0)
- return (buf);
+ return buf;
+
if ((seconds / MINUTE) > 0) {
- i = snprintf(append, remain, "%" PRId64 "M",
- (seconds / MINUTE));
- append += i;
- remain -=i;
+ i += snprintf(buf + i , len - i, "%" PRId64 "M",
+ seconds / MINUTE);
seconds = seconds % MINUTE;
}
+
if (remain < 4 || seconds == 0)
- return (buf);
- i = snprintf(append, remain, "%" PRId64 "S", seconds);
- return (buf);
+ return buf;
+
Home |
Main Index |
Thread Index |
Old Index