From: guenther Date: Sun, 14 Aug 2016 04:47:52 +0000 (+0000) Subject: Replace u_quad_t with unsigned long long and replace "uqd" with "ull" in X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f37d86feae0fe3e332dc020fbda1ee0e30077c1c;p=openbsd Replace u_quad_t with unsigned long long and replace "uqd" with "ull" in function names to match. Pull some tangled assignments out of conditions and use >>= where possible. ok millert@ --- diff --git a/bin/pax/cpio.c b/bin/pax/cpio.c index 8ff8836b80f..c4c26bb6519 100644 --- a/bin/pax/cpio.c +++ b/bin/pax/cpio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpio.c,v 1.27 2015/03/19 05:14:24 guenther Exp $ */ +/* $OpenBSD: cpio.c,v 1.28 2016/08/14 04:47:52 guenther Exp $ */ /* $NetBSD: cpio.c,v 1.5 1995/03/21 09:07:13 cgd Exp $ */ /*- @@ -270,7 +270,7 @@ int cpio_rd(ARCHD *arcn, char *buf) { int nsz; - u_quad_t val; + unsigned long long val; HD_CPIO *hd; /* @@ -293,14 +293,14 @@ cpio_rd(ARCHD *arcn, char *buf) arcn->sb.st_nlink = (nlink_t)asc_ul(hd->c_nlink, sizeof(hd->c_nlink), OCT); arcn->sb.st_rdev = (dev_t)asc_ul(hd->c_rdev, sizeof(hd->c_rdev), OCT); - val = asc_uqd(hd->c_mtime, sizeof(hd->c_mtime), OCT); + val = asc_ull(hd->c_mtime, sizeof(hd->c_mtime), OCT); if ((time_t)val < 0 || (time_t)val != val) arcn->sb.st_mtime = INT_MAX; /* XXX 2038 */ else arcn->sb.st_mtime = val; arcn->sb.st_mtim.tv_nsec = 0; arcn->sb.st_ctim = arcn->sb.st_atim = arcn->sb.st_mtim; - arcn->sb.st_size = (off_t)asc_uqd(hd->c_filesize,sizeof(hd->c_filesize), + arcn->sb.st_size = (off_t)asc_ull(hd->c_filesize,sizeof(hd->c_filesize), OCT); /* @@ -396,7 +396,7 @@ cpio_wr(ARCHD *arcn) /* * set data size for file data */ - if (uqd_asc((u_quad_t)arcn->sb.st_size, hd->c_filesize, + if (ull_asc(arcn->sb.st_size, hd->c_filesize, sizeof(hd->c_filesize), OCT)) { paxwarn(1,"File is too large for cpio format %s", arcn->org_name); @@ -439,7 +439,7 @@ cpio_wr(ARCHD *arcn) OCT) || ul_asc((u_long)arcn->sb.st_rdev, hd->c_rdev, sizeof(hd->c_rdev), OCT) || - uqd_asc(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->c_mtime, + ull_asc(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->c_mtime, sizeof(hd->c_mtime), OCT) || ul_asc((u_long)nsz, hd->c_namesize, sizeof(hd->c_namesize), OCT)) goto out; @@ -575,7 +575,7 @@ vcpio_rd(ARCHD *arcn, char *buf) arcn->sb.st_mtime = (time_t)asc_ul(hd->c_mtime,sizeof(hd->c_mtime),HEX); arcn->sb.st_mtim.tv_nsec = 0; arcn->sb.st_ctim = arcn->sb.st_atim = arcn->sb.st_mtim; - arcn->sb.st_size = (off_t)asc_uqd(hd->c_filesize, + arcn->sb.st_size = (off_t)asc_ull(hd->c_filesize, sizeof(hd->c_filesize), HEX); arcn->sb.st_nlink = (nlink_t)asc_ul(hd->c_nlink, sizeof(hd->c_nlink), HEX); @@ -711,7 +711,7 @@ vcpio_wr(ARCHD *arcn) * much to pad. */ arcn->pad = VCPIO_PAD(arcn->sb.st_size); - if (uqd_asc((u_quad_t)arcn->sb.st_size, hd->c_filesize, + if (ull_asc(arcn->sb.st_size, hd->c_filesize, sizeof(hd->c_filesize), HEX)) { paxwarn(1,"File is too large for sv4cpio format %s", arcn->org_name); diff --git a/bin/pax/extern.h b/bin/pax/extern.h index d2d413baf3f..80c7dc7be8a 100644 --- a/bin/pax/extern.h +++ b/bin/pax/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.54 2016/01/01 15:56:03 tedu Exp $ */ +/* $OpenBSD: extern.h,v 1.55 2016/08/14 04:47:52 guenther Exp $ */ /* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */ /*- @@ -174,8 +174,8 @@ void ls_tty(ARCHD *); void safe_print(const char *, FILE *); u_long asc_ul(char *, int, int); int ul_asc(u_long, char *, int, int); -u_quad_t asc_uqd(char *, int, int); -int uqd_asc(u_quad_t, char *, int, int); +unsigned long long asc_ull(char *, int, int); +int ull_asc(unsigned long long, char *, int, int); size_t fieldcpy(char *, size_t, const char *, size_t); /* diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c index cd857dc4761..5e05a201b70 100644 --- a/bin/pax/gen_subs.c +++ b/bin/pax/gen_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gen_subs.c,v 1.28 2015/03/17 03:23:17 guenther Exp $ */ +/* $OpenBSD: gen_subs.c,v 1.29 2016/08/14 04:47:52 guenther Exp $ */ /* $NetBSD: gen_subs.c,v 1.5 1995/03/21 09:07:26 cgd Exp $ */ /*- @@ -251,13 +251,15 @@ ul_asc(u_long val, char *str, int len, int base) *pt-- = '0' + (char)digit; else *pt-- = 'a' + (char)(digit - 10); - if ((val = (val >> 4)) == (u_long)0) + val >>= 4; + if (val == 0) break; } } else { while (pt >= str) { *pt-- = '0' + (char)(val & 0x7); - if ((val = (val >> 3)) == (u_long)0) + val >>= 3; + if (val == 0) break; } } @@ -267,26 +269,26 @@ ul_asc(u_long val, char *str, int len, int base) */ while (pt >= str) *pt-- = '0'; - if (val != (u_long)0) + if (val != 0) return(-1); return(0); } /* - * asc_uqd() - * convert hex/octal character string into a u_quad_t. We do not have to - * check for overflow! (the headers in all supported formats are not large - * enough to create an overflow). + * asc_ull() + * Convert hex/octal character string into a unsigned long long. + * We do not have to check for overflow! (The headers in all + * supported formats are not large enough to create an overflow). * NOTE: strings passed to us are NOT TERMINATED. * Return: - * u_quad_t value + * unsigned long long value */ -u_quad_t -asc_uqd(char *str, int len, int base) +unsigned long long +asc_ull(char *str, int len, int base) { char *stop; - u_quad_t tval = 0; + unsigned long long tval = 0; stop = str + len; @@ -319,17 +321,17 @@ asc_uqd(char *str, int len, int base) } /* - * uqd_asc() - * convert an u_quad_t into a hex/oct ascii string. pads with LEADING - * ascii 0's to fill string completely + * ull_asc() + * Convert an unsigned long long into a hex/oct ascii string. + * Pads with LEADING ascii 0's to fill string completely * NOTE: the string created is NOT TERMINATED. */ int -uqd_asc(u_quad_t val, char *str, int len, int base) +ull_asc(unsigned long long val, char *str, int len, int base) { char *pt; - u_quad_t digit; + unsigned long long digit; /* * WARNING str is not '\0' terminated by this routine @@ -347,13 +349,15 @@ uqd_asc(u_quad_t val, char *str, int len, int base) *pt-- = '0' + (char)digit; else *pt-- = 'a' + (char)(digit - 10); - if ((val = (val >> 4)) == (u_quad_t)0) + val >>= 4; + if (val == 0) break; } } else { while (pt >= str) { *pt-- = '0' + (char)(val & 0x7); - if ((val = (val >> 3)) == (u_quad_t)0) + val >>= 3; + if (val == 0) break; } } @@ -363,7 +367,7 @@ uqd_asc(u_quad_t val, char *str, int len, int base) */ while (pt >= str) *pt-- = '0'; - if (val != (u_quad_t)0) + if (val != 0) return(-1); return(0); } diff --git a/bin/pax/options.c b/bin/pax/options.c index 8721eaa9f4b..2ee50db71b7 100644 --- a/bin/pax/options.c +++ b/bin/pax/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.93 2016/04/19 03:26:11 guenther Exp $ */ +/* $OpenBSD: options.c,v 1.94 2016/08/14 04:47:52 guenther Exp $ */ /* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */ /*- @@ -1373,7 +1373,7 @@ printflg(unsigned int flg) (void)fprintf(stderr,"%s: Invalid combination of options:", argv0); while ((nxt = ffs(flg)) != 0) { - flg = flg >> nxt; + flg >>= nxt; pos += nxt; (void)fprintf(stderr, " -%c", flgch[pos-1]); } diff --git a/bin/pax/tar.c b/bin/pax/tar.c index 3a8b2600f63..0c0bb1554c9 100644 --- a/bin/pax/tar.c +++ b/bin/pax/tar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tar.c,v 1.59 2016/02/15 02:38:53 guenther Exp $ */ +/* $OpenBSD: tar.c,v 1.60 2016/08/14 04:47:52 guenther Exp $ */ /* $NetBSD: tar.c,v 1.5 1995/03/21 09:07:49 cgd Exp $ */ /*- @@ -56,7 +56,7 @@ static size_t expandname(char *, size_t, char **, const char *, size_t); static u_long tar_chksm(char *, int); static char *name_split(char *, int); static int ul_oct(u_long, char *, int, int); -static int uqd_oct(u_quad_t, char *, int, int); +static int ull_oct(unsigned long long, char *, int, int); #ifndef SMALL static int rd_xheader(ARCHD *arcn, int, off_t); #endif @@ -186,30 +186,31 @@ ul_oct(u_long val, char *str, int len, int term) */ while (pt >= str) { *pt-- = '0' + (char)(val & 0x7); - if ((val = val >> 3) == (u_long)0) + val >>= 3; + if (val == 0) break; } while (pt >= str) *pt-- = '0'; - if (val != (u_long)0) + if (val != 0) return(-1); return(0); } /* - * uqd_oct() - * convert an u_quad_t to an octal string. one of many oddball field - * termination characters are used by the various versions of tar in the - * different fields. term selects which kind to use. str is '0' padded - * at the front to len. we are unable to use only one format as many old - * tar readers are very cranky about this. + * ull_oct() + * Convert an unsigned long long to an octal string. One of many oddball + * field termination characters are used by the various versions of tar + * in the different fields. term selects which kind to use. str is + * '0' padded at the front to len. We are unable to use only one format + * as many old tar readers are very cranky about this. * Return: * 0 if the number fit into the string, -1 otherwise */ static int -uqd_oct(u_quad_t val, char *str, int len, int term) +ull_oct(unsigned long long val, char *str, int len, int term) { char *pt; @@ -240,13 +241,14 @@ uqd_oct(u_quad_t val, char *str, int len, int term) */ while (pt >= str) { *pt-- = '0' + (char)(val & 0x7); - if ((val = val >> 3) == 0) + val >>= 3; + if (val == 0) break; } while (pt >= str) *pt-- = '0'; - if (val != (u_quad_t)0) + if (val != 0) return(-1); return(0); } @@ -378,7 +380,7 @@ int tar_rd(ARCHD *arcn, char *buf) { HD_TAR *hd; - u_quad_t val; + unsigned long long val; char *pt; /* @@ -404,8 +406,8 @@ tar_rd(ARCHD *arcn, char *buf) 0xfff); arcn->sb.st_uid = (uid_t)asc_ul(hd->uid, sizeof(hd->uid), OCT); arcn->sb.st_gid = (gid_t)asc_ul(hd->gid, sizeof(hd->gid), OCT); - arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT); - val = asc_uqd(hd->mtime, sizeof(hd->mtime), OCT); + arcn->sb.st_size = (off_t)asc_ull(hd->size, sizeof(hd->size), OCT); + val = asc_ull(hd->mtime, sizeof(hd->mtime), OCT); if ((time_t)val < 0 || (time_t)val != val) arcn->sb.st_mtime = INT_MAX; /* XXX 2038 */ else @@ -615,9 +617,9 @@ tar_wr(ARCHD *arcn) * data follows this file, so set the pad */ hd->linkflag = AREGTYPE; - if (uqd_oct((u_quad_t)arcn->sb.st_size, hd->size, - sizeof(hd->size), 1)) { - paxwarn(1,"File is too large for tar %s", arcn->org_name); + if (ull_oct(arcn->sb.st_size, hd->size, sizeof(hd->size), 1)) { + paxwarn(1, "File is too large for tar %s", + arcn->org_name); return(1); } arcn->pad = TAR_PAD(arcn->sb.st_size); @@ -627,7 +629,7 @@ tar_wr(ARCHD *arcn) * copy those fields that are independent of the type */ if (ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 0) || - uqd_oct(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->mtime, + ull_oct(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->mtime, sizeof(hd->mtime), 1) || ul_oct((u_long)arcn->sb.st_uid, hd->uid, sizeof(hd->uid), 0) || ul_oct((u_long)arcn->sb.st_gid, hd->gid, sizeof(hd->gid), 0)) @@ -739,7 +741,7 @@ ustar_rd(ARCHD *arcn, char *buf) int cnt = 0; dev_t devmajor; dev_t devminor; - u_quad_t val; + unsigned long long val; /* * we only get proper sized buffers @@ -809,8 +811,8 @@ reset: */ arcn->sb.st_mode = (mode_t)(asc_ul(hd->mode, sizeof(hd->mode), OCT) & 0xfff); - arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT); - val = asc_uqd(hd->mtime, sizeof(hd->mtime), OCT); + arcn->sb.st_size = (off_t)asc_ull(hd->size, sizeof(hd->size), OCT); + val = asc_ull(hd->mtime, sizeof(hd->mtime), OCT); if ((time_t)val < 0 || (time_t)val != val) arcn->sb.st_mtime = INT_MAX; /* XXX 2038 */ else @@ -1044,9 +1046,9 @@ ustar_wr(ARCHD *arcn) else hd->typeflag = REGTYPE; arcn->pad = TAR_PAD(arcn->sb.st_size); - if (uqd_oct((u_quad_t)arcn->sb.st_size, hd->size, - sizeof(hd->size), 3)) { - paxwarn(1,"File is too long for ustar %s",arcn->org_name); + if (ull_oct(arcn->sb.st_size, hd->size, sizeof(hd->size), 3)) { + paxwarn(1, "File is too long for ustar %s", + arcn->org_name); return(1); } break; @@ -1087,7 +1089,7 @@ ustar_wr(ARCHD *arcn) if (ul_oct((u_long)gid_nobody, hd->gid, sizeof(hd->gid), 3)) goto out; } - if (uqd_oct(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->mtime, + if (ull_oct(arcn->sb.st_mtime < 0 ? 0 : arcn->sb.st_mtime, hd->mtime, sizeof(hd->mtime), 3) || ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 3)) goto out;