aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2021-03-09 03:58:07 -0600
committerRob Landley <rob@landley.net>2021-03-09 03:58:07 -0600
commit5f9d1f5bb59b1f129596bccb1928ce22d351f7c9 (patch)
treef4691ee004c37fd441bf5742c183f16bc58008f7
parent5c6628e724e9d3625f161db077b15b232e2ca096 (diff)
downloadtoybox-5f9d1f5bb59b1f129596bccb1928ce22d351f7c9.tar.gz
Minor tweaks: #define -> inlineable function, while() -> for(;;)
-rw-r--r--toys/posix/tar.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/toys/posix/tar.c b/toys/posix/tar.c
index 25dfc167..c4fb4fa2 100644
--- a/toys/posix/tar.c
+++ b/toys/posix/tar.c
@@ -86,17 +86,17 @@ struct tar_hdr {
};
// Tar uses ASCII octal when it fits, base-256 otherwise.
-#define ASCII_FITS(val, len) (!(val>>(3*(len-1))))
+static int ascii_fits(unsigned long long val, int len)
+{
+ return !(val>>(3*(len-1)));
+}
+
// convert from int to octal (or base-256)
static void itoo(char *str, int len, unsigned long long val)
{
- if (ASCII_FITS(val, len)) sprintf(str, "%0*llo", len-1, val);
+ if (ascii_fits(val, len)) sprintf(str, "%0*llo", len-1, val);
else {
- str += len;
- while (len--) {
- *--str = val;
- val >>= 8;
- }
+ for (str += len; len--; val >>= 8) *--str = val;
*str = 128;
}
}
@@ -294,10 +294,10 @@ static int add_to_tar(struct dirtree *node)
if (!FLAG(numeric_owner)) {
if ((TT.owner || (pw = bufgetpwuid(st->st_uid))) &&
- ASCII_FITS(st->st_uid, sizeof(hdr.uid)))
+ ascii_fits(st->st_uid, sizeof(hdr.uid)))
strncpy(hdr.uname, TT.owner ? TT.owner : pw->pw_name, sizeof(hdr.uname));
if ((TT.group || (gr = bufgetgrgid(st->st_gid))) &&
- ASCII_FITS(st->st_gid, sizeof(hdr.gid)))
+ ascii_fits(st->st_gid, sizeof(hdr.gid)))
strncpy(hdr.gname, TT.group ? TT.group : gr->gr_name, sizeof(hdr.gname));
}