Use the standardized CHAR_BIT constant instead of NBBY in userland.

This commit is contained in:
Mike Barcroft 2002-09-25 04:06:37 +00:00
parent df93d794dc
commit 89fdc4e117
26 changed files with 72 additions and 45 deletions

View File

@ -83,6 +83,7 @@ __FBSDID("$FreeBSD$");
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <ctype.h>
#include <limits.h>
#include <resolv.h>
#include <stdio.h>
#include <stdlib.h>
@ -414,7 +415,7 @@ res_init()
}
/*FALLTHROUGH*/
default:
m = sizeof(struct in6_addr) * NBBY;
m = sizeof(struct in6_addr) * CHAR_BIT;
break;
}
if (m >= 0) {
@ -422,7 +423,7 @@ res_init()
if (m <= 0) {
*u = 0;
} else {
m -= NBBY;
m -= CHAR_BIT;
*u = (u_char)~0;
if (m < 0)
*u <<= -m;

View File

@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
*/
#include <sys/types.h>
#include <limits.h>
#include <string.h>
#include "stand.h"
@ -109,7 +110,7 @@ ksprintn(ul, base, lenp)
u_long ul;
int base, *lenp;
{ /* A long in base 8, plus NULL. */
static char buf[sizeof(long) * NBBY / 3 + 2];
static char buf[sizeof(long) * CHAR_BIT / 3 + 2];
char *p;
p = buf;

View File

@ -393,16 +393,16 @@ cmd
break;
case TYPE_L:
#if NBBY == 8
#if CHAR_BIT == 8
if (cmd_bytesz == 8) {
reply(200,
"Type set to L (byte size 8).");
type = cmd_type;
} else
reply(504, "Byte size must be 8.");
#else /* NBBY == 8 */
UNIMPLEMENTED for NBBY != 8
#endif /* NBBY == 8 */
#else /* CHAR_BIT == 8 */
UNIMPLEMENTED for CHAR_BIT != 8
#endif /* CHAR_BIT == 8 */
}
}
}
@ -692,12 +692,12 @@ cmd
#ifdef unix
#ifdef BSD
reply(215, "UNIX Type: L%d Version: BSD-%d",
NBBY, BSD);
CHAR_BIT, BSD);
#else /* BSD */
reply(215, "UNIX Type: L%d", NBBY);
reply(215, "UNIX Type: L%d", CHAR_BIT);
#endif /* BSD */
#else /* unix */
reply(215, "UNKNOWN Type: L%d", NBBY);
reply(215, "UNKNOWN Type: L%d", CHAR_BIT);
#endif /* unix */
}
@ -916,7 +916,7 @@ type_code
| L
{
cmd_type = TYPE_L;
cmd_bytesz = NBBY;
cmd_bytesz = CHAR_BIT;
}
| L SP byte_size
{

View File

@ -2148,8 +2148,8 @@ statcmd(void)
if (type == TYPE_A || type == TYPE_E)
printf(", FORM: %s", formnames[form]);
if (type == TYPE_L)
#if NBBY == 8
printf(" %d", NBBY);
#if CHAR_BIT == 8
printf(" %d", CHAR_BIT);
#else
printf(" %d", bytesize); /* need definition! */
#endif

View File

@ -46,11 +46,14 @@ char *dumpinomap; /* map of files to be dumped */
* Map manipulation macros.
*/
#define SETINO(ino, map) \
map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY)
map[(u_int)((ino) - 1) / CHAR_BIT] |= \
1 << ((u_int)((ino) - 1) % CHAR_BIT)
#define CLRINO(ino, map) \
map[(u_int)((ino) - 1) / NBBY] &= ~(1 << ((u_int)((ino) - 1) % NBBY))
map[(u_int)((ino) - 1) / CHAR_BIT] &= \
~(1 << ((u_int)((ino) - 1) % CHAR_BIT))
#define TSTINO(ino, map) \
(map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY)))
(map[(u_int)((ino) - 1) / CHAR_BIT] & \
(1 << ((u_int)((ino) - 1) % CHAR_BIT)))
/*
* All calculations done in 0.1" units!

View File

@ -57,6 +57,7 @@ static const char rcsid[] =
#include <netdb.h>
#include <pwd.h>
#include <stdio.h>
#include <limits.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>

View File

@ -49,6 +49,7 @@ static const char rcsid[] =
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -60,6 +60,7 @@ static const char rcsid[] =
#include <fcntl.h>
#include <fstab.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -365,7 +366,7 @@ main(int argc, char *argv[])
if (TP_BSIZE != (1 << tp_bshift))
quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE);
maxino = sblock->fs_ipg * sblock->fs_ncg;
mapsize = roundup(howmany(maxino, NBBY), TP_BSIZE);
mapsize = roundup(howmany(maxino, CHAR_BIT), TP_BSIZE);
usedinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
dumpdirmap = (char *)calloc((unsigned) mapsize, sizeof(char));
dumpinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
@ -454,7 +455,7 @@ main(int argc, char *argv[])
msg("dumping (Pass III) [directories]\n");
dirty = 0; /* XXX just to get gcc to shut up */
for (map = dumpdirmap, ino = 1; ino < maxino; ino++) {
if (((ino - 1) % NBBY) == 0) /* map is offset by 1 */
if (((ino - 1) % CHAR_BIT) == 0) /* map is offset by 1 */
dirty = *map++;
else
dirty >>= 1;
@ -473,7 +474,7 @@ main(int argc, char *argv[])
setproctitle("%s: pass 4: regular files", disk);
msg("dumping (Pass IV) [regular files]\n");
for (map = dumpinomap, ino = 1; ino < maxino; ino++) {
if (((ino - 1) % NBBY) == 0) /* map is offset by 1 */
if (((ino - 1) % CHAR_BIT) == 0) /* map is offset by 1 */
dirty = *map++;
else
dirty >>= 1;

View File

@ -49,6 +49,7 @@ static const char rcsid[] =
#include <errno.h>
#include <fstab.h>
#include <grp.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -52,6 +52,7 @@ static const char rcsid[] =
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>

View File

@ -51,6 +51,7 @@ static const char rcsid[] =
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -203,7 +204,7 @@ mapdirs(ino_t maxino, long *tapesize)
isdir = 0; /* XXX just to get gcc to shut up */
for (map = dumpdirmap, ino = 1; ino < maxino; ino++) {
if (((ino - 1) % NBBY) == 0) /* map is offset by 1 */
if (((ino - 1) % CHAR_BIT) == 0) /* map is offset by 1 */
isdir = *map++;
else
isdir >>= 1;

View File

@ -48,6 +48,7 @@ static const char rcsid[] =
#include <ufs/ffs/fs.h>
#include <err.h>
#include <limits.h>
#include <stdint.h>
#include <string.h>
@ -116,11 +117,11 @@ pass1(void)
if (preen && usedsoftdep) {
if (!cg_chkmagic(&cgrp))
pfatal("CG %d: BAD MAGIC NUMBER\n", c);
cp = &cg_inosused(&cgrp)[(inosused - 1) / NBBY];
for ( ; inosused > 0; inosused -= NBBY, cp--) {
cp = &cg_inosused(&cgrp)[(inosused - 1) / CHAR_BIT];
for ( ; inosused > 0; inosused -= CHAR_BIT, cp--) {
if (*cp == 0)
continue;
for (i = 1 << (NBBY - 1); i > 0; i >>= 1) {
for (i = 1 << (CHAR_BIT - 1); i > 0; i >>= 1) {
if (*cp & i)
break;
inosused--;

View File

@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
#include <ufs/ffs/fs.h>
#include <err.h>
#include <limits.h>
#include <string.h>
#include "fsck.h"
@ -127,9 +128,9 @@ pass5(void)
fs->fs_old_cpg * fs->fs_old_nrpos * sizeof(u_int16_t);
memset(&newcg->cg_space[0], 0, newcg->cg_iusedoff - basesize);
}
inomapsize = howmany(fs->fs_ipg, NBBY);
inomapsize = howmany(fs->fs_ipg, CHAR_BIT);
newcg->cg_freeoff = newcg->cg_iusedoff + inomapsize;
blkmapsize = howmany(fs->fs_fpg, NBBY);
blkmapsize = howmany(fs->fs_fpg, CHAR_BIT);
newcg->cg_nextfreeoff = newcg->cg_freeoff + blkmapsize;
if (fs->fs_contigsumsize > 0) {
newcg->cg_clustersumoff = newcg->cg_nextfreeoff -
@ -139,7 +140,7 @@ pass5(void)
newcg->cg_clusteroff = newcg->cg_clustersumoff +
(fs->fs_contigsumsize + 1) * sizeof(u_int32_t);
newcg->cg_nextfreeoff = newcg->cg_clusteroff +
howmany(fragstoblks(fs, fs->fs_fpg), NBBY);
howmany(fragstoblks(fs, fs->fs_fpg), CHAR_BIT);
}
newcg->cg_magic = CG_MAGIC;
mapsize = newcg->cg_nextfreeoff - newcg->cg_iusedoff;
@ -273,7 +274,7 @@ pass5(void)
sump[run]++;
run = 0;
}
if ((i & (NBBY - 1)) != (NBBY - 1)) {
if ((i & (CHAR_BIT - 1)) != (CHAR_BIT - 1)) {
bit <<= 1;
} else {
map = *mapp++;
@ -370,10 +371,10 @@ check_maps(
k = *map2++;
if (j == k)
continue;
for (m = 0, l = 1; m < NBBY; m++, l <<= 1) {
for (m = 0, l = 1; m < CHAR_BIT; m++, l <<= 1) {
if ((j & l) == (k & l))
continue;
n = startvalue + i * NBBY + m;
n = startvalue + i * CHAR_BIT + m;
if ((j & l) != 0) {
if (astart == -1) {
astart = aend = n;

View File

@ -52,6 +52,7 @@ static const char rcsid[] =
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <stdint.h>
#include <string.h>
@ -243,7 +244,7 @@ setup(char *dev)
/*
* allocate and initialize the necessary maps
*/
bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(short));
bmapsize = roundup(howmany(maxfsblock, CHAR_BIT), sizeof(short));
blockmap = calloc((unsigned)bmapsize, sizeof (char));
if (blockmap == NULL) {
printf("cannot alloc %u bytes for blockmap\n",

View File

@ -47,6 +47,7 @@ static const char rcsid[] =
/* ********************************************************** INCLUDES ***** */
#include <sys/param.h>
#include <limits.h>
#include <stdio.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
@ -456,7 +457,7 @@ dbg_dump_frmap(struct fs *sb, const char *comment, struct cg *cgr)
indent++;
cp=(unsigned char *)cg_blksfree(cgr);
e=howmany((sb->fs_cpg * sb->fs_spc / NSPF(sb)), NBBY);
e=howmany((sb->fs_cpg * sb->fs_spc / NSPF(sb)), CHAR_BIT);
for(j=0; j<e; j+=32) {
fprintf(dbg_log, "%08x: ", j);
for(k=0; k<32; k+=8) {
@ -500,7 +501,7 @@ dbg_dump_clmap(struct fs *sb, const char *comment, struct cg *cgr)
indent++;
cp=(unsigned char *)cg_clustersfree(cgr);
e=howmany(sb->fs_cpg * sb->fs_spc / NSPB(sb), NBBY);
e=howmany(sb->fs_cpg * sb->fs_spc / NSPB(sb), CHAR_BIT);
for(j=0; j<e; j+=32) {
fprintf(dbg_log, "%08x: ", j);
for(k=0; k<32; k+=8) {

View File

@ -62,6 +62,7 @@ static const char rcsid[] =
#include <ctype.h>
#include <err.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -410,8 +411,8 @@ initcg(int cylno, time_t utime, int fso, unsigned int Nflag)
acg.cg_iusedoff = acg.cg_old_boff +
sblock.fs_old_cpg * sizeof(u_int16_t);
}
acg.cg_freeoff = acg.cg_iusedoff + howmany(sblock.fs_ipg, NBBY);
acg.cg_nextfreeoff = acg.cg_freeoff + howmany(sblock.fs_fpg, NBBY);
acg.cg_freeoff = acg.cg_iusedoff + howmany(sblock.fs_ipg, CHAR_BIT);
acg.cg_nextfreeoff = acg.cg_freeoff + howmany(sblock.fs_fpg, CHAR_BIT);
if (sblock.fs_contigsumsize > 0) {
acg.cg_clustersumoff =
roundup(acg.cg_nextfreeoff, sizeof(u_int32_t));
@ -419,7 +420,7 @@ initcg(int cylno, time_t utime, int fso, unsigned int Nflag)
acg.cg_clusteroff = acg.cg_clustersumoff +
(sblock.fs_contigsumsize + 1) * sizeof(u_int32_t);
acg.cg_nextfreeoff = acg.cg_clusteroff +
howmany(fragstoblks(&sblock, sblock.fs_fpg), NBBY);
howmany(fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT);
}
if (acg.cg_nextfreeoff > sblock.fs_cgsize) {
/*
@ -504,7 +505,7 @@ initcg(int cylno, time_t utime, int fso, unsigned int Nflag)
sump[run]++;
run = 0;
}
if ((i & (NBBY - 1)) != NBBY - 1)
if ((i & (CHAR_BIT - 1)) != CHAR_BIT - 1)
bit <<= 1;
else {
map = *mapp++;

View File

@ -52,6 +52,7 @@ static const char rcsid[] =
#endif /* not lint */
#include <err.h>
#include <limits.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
@ -544,8 +545,8 @@ initcg(int cylno, time_t utime)
acg.cg_iusedoff = acg.cg_old_boff +
sblock.fs_old_cpg * sizeof(u_int16_t);
}
acg.cg_freeoff = acg.cg_iusedoff + howmany(sblock.fs_ipg, NBBY);
acg.cg_nextfreeoff = acg.cg_freeoff + howmany(sblock.fs_fpg, NBBY);
acg.cg_freeoff = acg.cg_iusedoff + howmany(sblock.fs_ipg, CHAR_BIT);
acg.cg_nextfreeoff = acg.cg_freeoff + howmany(sblock.fs_fpg, CHAR_BIT);
if (sblock.fs_contigsumsize > 0) {
acg.cg_clustersumoff =
roundup(acg.cg_nextfreeoff, sizeof(u_int32_t));
@ -553,7 +554,7 @@ initcg(int cylno, time_t utime)
acg.cg_clusteroff = acg.cg_clustersumoff +
(sblock.fs_contigsumsize + 1) * sizeof(u_int32_t);
acg.cg_nextfreeoff = acg.cg_clusteroff +
howmany(fragstoblks(&sblock, sblock.fs_fpg), NBBY);
howmany(fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT);
}
if (acg.cg_nextfreeoff > sblock.fs_cgsize) {
printf("Panic: cylinder group too big\n");
@ -616,7 +617,7 @@ initcg(int cylno, time_t utime)
sump[run]++;
run = 0;
}
if ((i & (NBBY - 1)) != NBBY - 1)
if ((i & (CHAR_BIT - 1)) != CHAR_BIT - 1)
bit <<= 1;
else {
map = *mapp++;
@ -1024,7 +1025,7 @@ ilog2(int val)
{
u_int n;
for (n = 0; n < sizeof(n) * NBBY; n++)
for (n = 0; n < sizeof(n) * CHAR_BIT; n++)
if (1 << n == val)
return (n);
errx(1, "ilog2: %d is not a power of 2\n", val);

View File

@ -55,6 +55,7 @@ static const char rcsid[] =
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -48,6 +48,7 @@ static const char rcsid[] =
#include <setjmp.h>
#include <glob.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -52,6 +52,7 @@ static const char rcsid[] =
#include <protocols/dumprestore.h>
#include <err.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -41,6 +41,7 @@ static const char rcsid[] =
#include <sys/types.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>

View File

@ -139,9 +139,11 @@ typedef struct rstdirdesc RST_DIR;
* Useful macros
*/
#define TSTINO(ino, map) \
(map[(u_int)((ino) - 1) / NBBY] & (1 << ((u_int)((ino) - 1) % NBBY)))
(map[(u_int)((ino) - 1) / CHAR_BIT] & \
(1 << ((u_int)((ino) - 1) % CHAR_BIT)))
#define SETINO(ino, map) \
map[(u_int)((ino) - 1) / NBBY] |= 1 << ((u_int)((ino) - 1) % NBBY)
map[(u_int)((ino) - 1) / CHAR_BIT] |= \
1 << ((u_int)((ino) - 1) % CHAR_BIT)
#define dprintf if (dflag) fprintf
#define vprintf if (vflag) fprintf

View File

@ -55,6 +55,7 @@ static const char rcsid[] =
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -54,6 +54,7 @@ static const char rcsid[] =
#include <protocols/dumprestore.h>
#include <errno.h>
#include <limits.h>
#include <paths.h>
#include <setjmp.h>
#include <stdio.h>

View File

@ -46,6 +46,7 @@ static const char rcsid[] =
#include <ufs/ufs/dir.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -75,6 +75,7 @@ static const char rcsid[] =
#include <err.h>
#include <errno.h>
#include <grp.h>
#include <limits.h>
#include <netdb.h>
#include <pwd.h>
#include <signal.h>
@ -2362,11 +2363,11 @@ makemask(struct sockaddr_storage *ssp, int bitlen)
if ((p = sa_rawaddr((struct sockaddr *)ssp, &len)) == NULL)
return (-1);
if (bitlen > len * NBBY)
if (bitlen > len * CHAR_BIT)
return (-1);
for (i = 0; i < len; i++) {
bits = (bitlen > NBBY) ? NBBY : bitlen;
bits = (bitlen > CHAR_BIT) ? CHAR_BIT : bitlen;
*p++ = (1 << bits) - 1;
bitlen -= bits;
}