Subject: small getbsize(3) change
To: None <tech-userlevel@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-userlevel
Date: 05/29/2003 14:10:24
--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
We've got a couple of places in our source tree where we use a dummy
variable just so that getbsize(3) can stuff a value in that is ignored.
The following patch changes getbsize(3) so that if either parameter is
NULL it is ignored.
Any problems with this?
Simon.
--
Simon Burge <simonb@wasabisystems.com>
NetBSD Development, Support and Service: http://www.wasabisystems.com/
--KsGdsel6WgEHnImy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="getbsize.diff"
Index: bin/ls/ls.c
===================================================================
RCS file: /cvsroot/src/bin/ls/ls.c,v
retrieving revision 1.48
diff -d -p -u -r1.48 ls.c
--- bin/ls/ls.c 2003/05/11 08:06:01 1.48
+++ bin/ls/ls.c 2003/05/29 03:59:33
@@ -115,7 +115,7 @@ ls_main(int argc, char *argv[])
{
static char dot[] = ".", *dotav[] = { dot, NULL };
struct winsize win;
- int ch, fts_options, notused;
+ int ch, fts_options;
int kflag = 0;
const char *p;
@@ -283,7 +283,7 @@ ls_main(int argc, char *argv[])
/* If -l or -s, figure out block size. */
if (f_inode || f_longform || f_size) {
if (!kflag)
- (void)getbsize(¬used, &blocksize);
+ (void)getbsize(NULL, &blocksize);
blocksize /= 512;
}
Index: lib/libc/gen/getbsize.3
===================================================================
RCS file: /cvsroot/src/lib/libc/gen/getbsize.3,v
retrieving revision 1.6
diff -d -p -u -r1.6 getbsize.3
--- lib/libc/gen/getbsize.3 2003/04/16 13:34:36 1.6
+++ lib/libc/gen/getbsize.3 2003/05/29 03:59:33
@@ -33,7 +33,7 @@
.\"
.\" @(#)getbsize.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd June 4, 1993
+.Dd May 10, 2003
.Dt GETBSIZE 3
.Os
.Sh NAME
@@ -59,11 +59,15 @@ The
function returns a pointer to a null-terminated string describing
the block size, something like
.Dq 1K-blocks .
-The memory referenced by
+If the
+.Fa headerlenp
+parameter is not NULL the memory referenced by
.Fa headerlenp
is filled in with the length of the string (not including the
terminating null).
-The memory referenced by
+If the
+.Fa blocksizep
+parameter is not NULL the memory referenced by
.Fa blocksizep
is filled in with block size, in bytes.
.Pp
Index: lib/libc/gen/getbsize.c
===================================================================
RCS file: /cvsroot/src/lib/libc/gen/getbsize.c,v
retrieving revision 1.13
diff -d -p -u -r1.13 getbsize.c
--- lib/libc/gen/getbsize.c 2000/01/22 22:19:10 1.13
+++ lib/libc/gen/getbsize.c 2003/05/29 03:59:33
@@ -63,9 +63,6 @@ getbsize(headerlenp, blocksizep)
long n, max, mul, blocksize;
char *ep, *p, *form;
- _DIAGASSERT(headerlenp != NULL);
- _DIAGASSERT(blocksizep != NULL);
-
#define KB (1024L)
#define MB (1024L * 1024L)
#define GB (1024L * 1024L * 1024L)
@@ -117,7 +114,10 @@ underflow: warnx("%s: minimum blocksize
} else
blocksize = n = 512;
- *headerlenp = snprintf(header, sizeof(header), "%ld%s-blocks", n, form);
- *blocksizep = blocksize;
+ if (headerlenp)
+ *headerlenp =
+ snprintf(header, sizeof(header), "%ld%s-blocks", n, form);
+ if (blocksizep)
+ *blocksizep = blocksize;
return (header);
}
Index: usr.bin/du/du.c
===================================================================
RCS file: /cvsroot/src/usr.bin/du/du.c,v
retrieving revision 1.21
diff -d -p -u -r1.21 du.c
--- usr.bin/du/du.c 2003/05/10 02:09:39 1.21
+++ usr.bin/du/du.c 2003/05/29 03:59:34
@@ -79,7 +79,7 @@ main(argc, argv)
FTS *fts;
FTSENT *p;
int64_t totalblocks;
- int ftsoptions, listdirs, listfiles, notused;
+ int ftsoptions, listdirs, listfiles;
int Hflag, Lflag, Pflag, aflag, ch, cflag, gkmflag, rval, sflag;
char *noargv[2];
@@ -173,7 +173,7 @@ main(argc, argv)
}
if (!gkmflag)
- (void)getbsize(¬used, &blocksize);
+ (void)getbsize(NULL, &blocksize);
blocksize /= 512;
if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL)
Index: usr.sbin/quot/quot.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/quot/quot.c,v
retrieving revision 1.18
diff -d -p -u -r1.18 quot.c
--- usr.sbin/quot/quot.c 2003/04/02 10:39:50 1.18
+++ usr.sbin/quot/quot.c 2003/05/29 03:59:34
@@ -58,7 +58,6 @@ static char unused;
static void (*func) __P((int, struct fs *, char *));
static long blocksize;
static char *header;
-static int headerlen;
/*
* Original BSD quot doesn't round to number of frags/blocks,
@@ -618,7 +617,7 @@ main(argc, argv)
func = douser;
#ifndef COMPAT
- header = getbsize(&headerlen, &blocksize);
+ header = getbsize(NULL, &blocksize);
#endif
while (--argc > 0 && **++argv == '-') {
while (*++*argv) {
--KsGdsel6WgEHnImy--