logo

utils-std

Collection of commonly available Unix tools
commit: 3957e385eaa266651e852fd52dacd7b1f887e682
parent ee3a29fbf94556f9ea83d486578797d5b9cbabf7
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  6 May 2024 06:01:31 +0200

.clang-format: AlignConsecutiveAssignments: false

Would often create really weird alignment, pushing things out way too much.

Diffstat:

M.clang-format2+-
Mcmd/base64.c10+++++-----
Mcmd/basename.c2+-
Mcmd/chmod.c2+-
Mcmd/chown.c4++--
Mcmd/chroot.c2+-
Mcmd/cmp.c2+-
Mcmd/date.c8++++----
Mcmd/df.c16++++++++--------
Mcmd/echo.c2+-
Mcmd/env.c2+-
Mcmd/id.c20++++++++++----------
Mcmd/install.c4++--
Mcmd/ln.c6+++---
Mcmd/pathchk.c4++--
Mcmd/printf.c36++++++++++++++++++------------------
Mcmd/realpath.c4++--
Mcmd/rm.c2+-
Mcmd/seq.c14+++++++-------
Mcmd/strings.c8++++----
Mcmd/tee.c6+++---
Mcmd/test.c20++++++++++----------
Mcmd/timeout.c6+++---
Mcmd/touch.c6+++---
Mcmd/tr.c2+-
Mcmd/truncate.c4++--
Mcmd/uname.c10+++++-----
Mcmd/uniq.c16++++++++--------
Mcmd/wc.c6+++---
Mlib/consent.c8++++----
Mlib/humanize.c8++++----
Mlib/iso_parse.c28++++++++++++++--------------
Mlib/mode.c20++++++++++----------
Mlib/path.c4++--
Mlib/tr_str.c12++++++------
Mlib/truncation.c4++--
Mlib/user_group_parse.c4++--
37 files changed, 157 insertions(+), 157 deletions(-)

diff --git a/.clang-format b/.clang-format @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> # SPDX-License-Identifier: MPL-2.0 AlignAfterOpenBracket: true -AlignConsecutiveAssignments: true +AlignConsecutiveAssignments: false AlignOperands: true AlignTrailingComments: true AllowShortCaseLabelsOnASingleLine: false diff --git a/cmd/base64.c b/cmd/base64.c @@ -16,7 +16,7 @@ // 64(26+26+10+2) static char b64_encmap[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static size_t c_out = 0; +static size_t c_out = 0; // 76 is lowest of all base64 related RFCs static long wrap_nl = 76; @@ -66,7 +66,7 @@ encode(FILE *fin, const char *name) { uint8_t obuf[4] = "----"; uint8_t ibuf[3] = {0, 0, 0}; - uint8_t pad = 0; + uint8_t pad = 0; size_t c = 0; for(; c < 3; c++) @@ -150,9 +150,9 @@ encode(FILE *fin, const char *name) static int decode(FILE *fin, const char *name) { - int c = 0; + int c = 0; uint8_t out = 0; - int state = 0; + int state = 0; while((c = getc(fin)) != EOF) { @@ -269,7 +269,7 @@ main(int argc, char *argv[]) process = &decode; break; case 'w': - errno = 0; + errno = 0; char *e = ""; wrap_nl = strtol(optarg, &e, 10); diff --git a/cmd/basename.c b/cmd/basename.c @@ -17,7 +17,7 @@ suffix_basename(char *name, char *suffix) char *string = basename(name); size_t suflen = suffix ? strlen(suffix) : 0; - size_t len = strlen(string); + size_t len = strlen(string); if(suflen < len && strcmp(&string[len - suflen], suffix) == 0) { diff --git a/cmd/chmod.c b/cmd/chmod.c @@ -39,7 +39,7 @@ do_fchmodat(int fd, char *mode_arg, char *name, char *acc_path, bool recursive) } const char *errstr = NULL; - mode_t mode = new_mode(mode_arg, stats.st_mode, &errstr); + mode_t mode = new_mode(mode_arg, stats.st_mode, &errstr); if(errstr != NULL) { fprintf(stderr, "chmod: Failed parsing mode '%s': %s\n", mode_arg, errstr); diff --git a/cmd/chown.c b/cmd/chown.c @@ -26,7 +26,7 @@ char *argv0 = NULL; -static uid_t user = (uid_t)-1; +static uid_t user = (uid_t)-1; static uid_t group = (uid_t)-1; static bool opt_v = false, opt_R = false; @@ -45,7 +45,7 @@ do_fchownat(int fd, char *name, char *acc_path, enum chown_follow_symlinks follo struct stat stats; int err = 0; - int stat_opts = (follow_symlinks == CHOWN_FOLLOW_NO_SYMLINK) ? AT_SYMLINK_NOFOLLOW : 0; + int stat_opts = (follow_symlinks == CHOWN_FOLLOW_NO_SYMLINK) ? AT_SYMLINK_NOFOLLOW : 0; int chown_opts = (follow_symlinks == CHOWN_FOLLOW_NO_SYMLINK) ? AT_SYMLINK_NOFOLLOW : 0; assert(errno == 0); diff --git a/cmd/chroot.c b/cmd/chroot.c @@ -36,7 +36,7 @@ main(int argc, char *argv[]) } int ret = 0; - errno = 0; + errno = 0; if(argc == 2) { char *shell = getenv("SHELL"); diff --git a/cmd/cmp.c b/cmd/cmp.c @@ -100,7 +100,7 @@ main(int argc, char *argv[]) opt_s = true; break; case 'n': - errno = 0; + errno = 0; max_bytes = strtoul(optarg, &endptr, 0); if(errno != 0) { diff --git a/cmd/date.c b/cmd/date.c @@ -28,10 +28,10 @@ main(int argc, char *argv[]) char outstr[BUFSIZ]; struct tm *tm; time_t now; - char *format = "%c"; + char *format = "%c"; char *input_format = NULL; - int uflag = 0; - int dflag = 0; + int uflag = 0; + int dflag = 0; int c; setlocale(LC_ALL, ""); @@ -54,7 +54,7 @@ main(int argc, char *argv[]) fprintf(stderr, "date: Cannot both use '-d' and '-f'\n"); exit(EXIT_FAILURE); } - now = iso_parse(optarg, &errstr).tv_sec; + now = iso_parse(optarg, &errstr).tv_sec; dflag = 1; if(errstr != NULL) { diff --git a/cmd/df.c b/cmd/df.c @@ -67,7 +67,7 @@ main(int argc, char *argv[]) forced_bsize = 1024; break; case 'h': - opt_h = true; + opt_h = true; fs_col_width = 30; break; case 'l': @@ -104,12 +104,12 @@ main(int argc, char *argv[]) int args_left = argc != 0 ? argc : 1; - bool tty_out = isatty(1); + bool tty_out = isatty(1); int col_width = tty_out ? 10 : 0; if(!tty_out) { - errno = 0; + errno = 0; fs_col_width = 0; } @@ -300,9 +300,9 @@ main(int argc, char *argv[]) static_escape(mntent->mnt_dir); off_t percent = 0; - off_t total = stats.f_frsize * (stats.f_blocks != 0 ? stats.f_blocks : 1); - off_t free = stats.f_bfree * (stats.f_bsize != 0 ? stats.f_bsize : 1); - off_t used = total - free; + off_t total = stats.f_frsize * (stats.f_blocks != 0 ? stats.f_blocks : 1); + off_t free = stats.f_bfree * (stats.f_bsize != 0 ? stats.f_bsize : 1); + off_t used = total - free; if(used + free) { @@ -324,8 +324,8 @@ main(int argc, char *argv[]) if(opt_h && !opt_P) { struct si_scale total_scl = dtosi(total, true); - struct si_scale used_scl = dtosi(used, true); - struct si_scale free_scl = dtosi(free, true); + struct si_scale used_scl = dtosi(used, true); + struct si_scale free_scl = dtosi(free, true); int width_num = tty_out ? col_width - 3 : 0; int width_pre = tty_out ? 3 : 0; diff --git a/cmd/echo.c b/cmd/echo.c @@ -15,7 +15,7 @@ main(int argc, char *argv[]) { size_t arg_len = 0; char *buffer, *buffer_p; - int err = 0; + int err = 0; bool opt_n = false; if((argc >= 2) && (strncmp(argv[1], "-n", 3) == 0)) diff --git a/cmd/env.c b/cmd/env.c @@ -91,7 +91,7 @@ main(int argc, char *argv[]) if(flag_i) { - environ = envclear; + environ = envclear; envclear[0] = NULL; } diff --git a/cmd/id.c b/cmd/id.c @@ -140,11 +140,11 @@ main(int argc, char *argv[]) { int ret = 0, c = 0; enum id_modes mode = ID_NORMAL; - bool real_flag = false; + bool real_flag = false; - int ngroups = 0; + int ngroups = 0; int ngroups_max = (int)sysconf(_SC_NGROUPS_MAX) + 1; - gid_t *groups = malloc(sizeof(gid_t) * ngroups_max); + gid_t *groups = malloc(sizeof(gid_t) * ngroups_max); if(groups == NULL) { perror("id: malloc(groups)"); @@ -152,12 +152,12 @@ main(int argc, char *argv[]) } // geteuid, getuid, getegid, getgid shall always be successful - uid_t uid = getuid(); + uid_t uid = getuid(); uid_t euid = geteuid(); - gid_t gid = getgid(); + gid_t gid = getgid(); gid_t egid = getegid(); - struct passwd pw = {.pw_uid = uid, .pw_gid = gid}; + struct passwd pw = {.pw_uid = uid, .pw_gid = gid}; struct passwd epw = {.pw_uid = euid, .pw_gid = egid}; while((c = getopt(argc, argv, ":Ggunr")) != EOF) @@ -210,12 +210,12 @@ main(int argc, char *argv[]) { goto failure; } - pw = *pw_n; + pw = *pw_n; epw = *pw_n; - uid = pw.pw_uid; + uid = pw.pw_uid; euid = epw.pw_uid; - gid = pw.pw_gid; + gid = pw.pw_gid; egid = epw.pw_gid; // Can only get groups from configuration @@ -231,7 +231,7 @@ main(int argc, char *argv[]) usage(); } - struct group *gr = getgrgid(gid); + struct group *gr = getgrgid(gid); struct group *egr = getgrgid(egid); if(mode == ID_GID) diff --git a/cmd/install.c b/cmd/install.c @@ -28,7 +28,7 @@ bool mkdir_parents_verbose = false; mode_t mkdir_parents_filemask; mode_t mode = 00755; -uid_t user = (uid_t)-1; +uid_t user = (uid_t)-1; gid_t group = (gid_t)-1; char *argv0 = "install"; @@ -141,7 +141,7 @@ do_install(char *src, char *dest, bool is_dir) if(is_dir) { char target[PATH_MAX] = ""; - char *src_basename = static_basename(src); + char *src_basename = static_basename(src); if(snprintf(target, PATH_MAX, "%s/%s", dest, src_basename) < 0) { diff --git a/cmd/ln.c b/cmd/ln.c @@ -22,7 +22,7 @@ #include <unistd.h> // getopt, symlink, link static bool opt_s = false, force = false; -static int link_flags = 0; +static int link_flags = 0; static int open_dir_flags = O_RDONLY | O_DIRECTORY; static int @@ -177,14 +177,14 @@ main(int argc, char *argv[]) } else { - char *dest = argv[argc - 1]; + char *dest = argv[argc - 1]; char target[PATH_MAX] = ""; for(int i = 0; i < argc - 1; i++) { char *src = argv[i]; - char *src_sep = strrchr(src, '/'); + char *src_sep = strrchr(src, '/'); char *src_basename = src_sep != NULL ? src_sep + 1 : src; if(snprintf(target, PATH_MAX, "%s/%s", dest, src_basename) < 0) diff --git a/cmd/pathchk.c b/cmd/pathchk.c @@ -52,7 +52,7 @@ main(int argc, char *argv[]) opt_P = true; break; case 'p': - opt_p = true; + opt_p = true; path_max = _POSIX_PATH_MAX; name_max = _POSIX_NAME_MAX; break; @@ -130,7 +130,7 @@ main(int argc, char *argv[]) path, strerror(errno)); errno = 0; - err = 1; + err = 1; } } else diff --git a/cmd/printf.c b/cmd/printf.c @@ -140,7 +140,7 @@ main(int argc, char *argv[]) fmt = format = *argv; escape(fmt, 1, &len); /* backslash interpretation */ rval = end = 0; - gargv = ++argv; + gargv = ++argv; for(;;) { @@ -215,9 +215,9 @@ printf_doformat(char *fmt, int *rval) char *dptr; int l; - dptr = start; + dptr = start; *dptr++ = '%'; - *dptr = 0; + *dptr = 0; fmt++; @@ -249,7 +249,7 @@ printf_doformat(char *fmt, int *rval) while(*fmt && strchr(skip1, *fmt) != NULL) { *dptr++ = *fmt++; - *dptr = 0; + *dptr = 0; } if(*fmt == '*') @@ -286,7 +286,7 @@ printf_doformat(char *fmt, int *rval) havewidth = 1; *dptr++ = '*'; - *dptr = 0; + *dptr = 0; } else { @@ -296,7 +296,7 @@ printf_doformat(char *fmt, int *rval) while(isdigit(*fmt)) { *dptr++ = *fmt++; - *dptr = 0; + *dptr = 0; } } @@ -338,8 +338,8 @@ printf_doformat(char *fmt, int *rval) if(getint(&precision)) return (NULL); if(gargv > maxargv) maxargv = gargv; haveprec = 1; - *dptr++ = '*'; - *dptr = 0; + *dptr++ = '*'; + *dptr = 0; } else { @@ -349,7 +349,7 @@ printf_doformat(char *fmt, int *rval) while(isdigit(*fmt)) { *dptr++ = *fmt++; - *dptr = 0; + *dptr = 0; } } } @@ -361,7 +361,7 @@ printf_doformat(char *fmt, int *rval) return (NULL); } *dptr++ = *fmt; - *dptr = 0; + *dptr = 0; /* * Look for a length modifier. POSIX doesn't have these, so @@ -502,7 +502,7 @@ mknum(char *str, char ch) warnx("%s", strerror(ENOMEM)); return (NULL); } - copy = newcopy; + copy = newcopy; copy_size = newlen; } @@ -529,9 +529,9 @@ escape(char *fmt, int percent, size_t *len) switch(*++fmt) { case '\0': /* EOS, user error */ - *store = '\\'; + *store = '\\'; *++store = '\0'; - *len = store - save; + *len = store - save; return (0); case '\\': /* backslash */ case '\'': /* single quote */ @@ -547,7 +547,7 @@ escape(char *fmt, int percent, size_t *len) if(!percent) { *store = '\0'; - *len = store - save; + *len = store - save; return (1); } *store = 'c'; @@ -586,7 +586,7 @@ escape(char *fmt, int percent, size_t *len) if(percent && value == '%') { *store++ = '%'; - *store = '%'; + *store = '%'; } else *store = (char)value; @@ -597,7 +597,7 @@ escape(char *fmt, int percent, size_t *len) } } *store = '\0'; - *len = store - save; + *len = store - save; return (0); } @@ -652,7 +652,7 @@ getnum(intmax_t *ip, uintmax_t *uip, int signedconv) *uip = asciicode(); return (0); } - rval = 0; + rval = 0; errno = 0; if(signedconv) *ip = strtoimax(*gargv, &ep, 0); @@ -693,7 +693,7 @@ getfloating(long double *dp, int mod_ldbl) *dp = asciicode(); return (0); } - rval = 0; + rval = 0; errno = 0; if(mod_ldbl) *dp = strtold(*gargv, &ep); diff --git a/cmd/realpath.c b/cmd/realpath.c @@ -18,7 +18,7 @@ static bool must_exists = false; static char *argv0 = NULL; -static char sep = '\n'; +static char sep = '\n'; static int print_realpath(char *path) @@ -160,7 +160,7 @@ main_readlink(int argc, char *argv[]) { case 'f': canonicalize = true; - must_exists = false; + must_exists = false; break; case 'e': must_exists = true; diff --git a/cmd/rm.c b/cmd/rm.c @@ -107,7 +107,7 @@ do_unlinkat(int fd, char *name, char *acc_path) name, acc_path, strerror(errno)); - err = 1; + err = 1; errno = 0; continue; } diff --git a/cmd/seq.c b/cmd/seq.c @@ -12,12 +12,12 @@ #include <string.h> // strerror #include <unistd.h> // getopt, optarg, optind -char *sep = "\n"; +char *sep = "\n"; char *term = "\n"; int len = 0; -bool opt_w = false; +bool opt_w = false; double g_last = 1.0; static void @@ -115,8 +115,8 @@ getopt_end: argv += optind; double first = 1.0; - double step = 1.0; - double last = 1.0; + double step = 1.0; + double last = 1.0; switch(argc) { @@ -125,12 +125,12 @@ getopt_end: break; case 2: first = get_num(argv[0]); - last = get_num(argv[1]); + last = get_num(argv[1]); break; case 3: first = get_num(argv[0]); - step = fabs(get_num(argv[1])); - last = get_num(argv[2]); + step = fabs(get_num(argv[1])); + last = get_num(argv[2]); break; default: usage(); diff --git a/cmd/strings.c b/cmd/strings.c @@ -13,7 +13,7 @@ #include <string.h> /* strerror(), strncmp(), memset() */ #include <unistd.h> /* read(), write(), close(), getopt(), optarg, optind */ -size_t opt_min_strlen = 4; +size_t opt_min_strlen = 4; char *opt_offset_format = NULL; static int @@ -49,14 +49,14 @@ concat(int fd, const char *fdname) char read_buf[4096]; char write_buf[4096]; size_t write_pos = 0; - size_t offset = 0; + size_t offset = 0; memset(write_buf, 0, sizeof(write_buf)); while((c = read(fd, read_buf, sizeof(read_buf))) > 0) { int read_pos = 0; - char b = 0; + char b = 0; for(; read_pos < c; read_pos++) { @@ -115,7 +115,7 @@ main(int argc, char *argv[]) break; case 'n': assert(errno == 0); - char *endptr = ""; + char *endptr = ""; opt_min_strlen = strtol(optarg, &endptr, 10); if(*endptr != 0) { diff --git a/cmd/tee.c b/cmd/tee.c @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) { const char *mode = "w"; - FILE **fds = {NULL}; // Shut up GCC + FILE **fds = {NULL}; // Shut up GCC int c; while((c = getopt(argc, argv, ":ai")) != -1) @@ -77,7 +77,7 @@ main(int argc, char *argv[]) if(fputc(c, stdout) == EOF) { fprintf(stderr, "tee: Error writing ‘<stdout>’: %s\n", strerror(errno)); - err = 1; + err = 1; errno = 0; } @@ -86,7 +86,7 @@ main(int argc, char *argv[]) if(fputc(c, fds[argi]) == EOF) { fprintf(stderr, "tee: Error writing to argument %d: %s\n", argi, strerror(errno)); - err = 1; + err = 1; errno = 0; } } diff --git a/cmd/test.c b/cmd/test.c @@ -55,11 +55,11 @@ error(const char *msg, ...) enum token_types { - UNOP = 0x100, - BINOP = 0x200, - BUNOP = 0x300, + UNOP = 0x100, + BINOP = 0x200, + BUNOP = 0x300, BBINOP = 0x400, - PAREN = 0x500 + PAREN = 0x500 }; enum token @@ -203,8 +203,8 @@ main(int argc, char **argv) if(--argc <= 0) return 1; (void)setlocale(LC_CTYPE, ""); - nargc = argc; - t_wp = &argv[1]; + nargc = argc; + t_wp = &argv[1]; parenlevel = 0; if(nargc == 4 && strcmp(*t_wp, "!") == 0) { @@ -314,7 +314,7 @@ binop(enum token n) const char *opnd1, *op, *opnd2; opnd1 = *t_wp; - op = nargc > 0 ? (--nargc, *++t_wp) : NULL; + op = nargc > 0 ? (--nargc, *++t_wp) : NULL; if((opnd2 = nargc > 0 ? (--nargc, *++t_wp) : NULL) == NULL) { @@ -471,7 +471,7 @@ isunopoperand(void) if(nargc == 1) return 1; s = *(t_wp + 1); if(nargc == 2) return parenlevel == 1 && strcmp(s, ")") == 0; - t = *(t_wp + 2); + t = *(t_wp + 2); num = find_op(s); return TOKEN_TYPE(num) == BINOP && (parenlevel == 0 || t[0] != ')' || t[1] != '\0'); } @@ -509,7 +509,7 @@ getn(const char *s) long r; errno = 0; - r = strtol(s, &p, 10); + r = strtol(s, &p, 10); if(s == p) error("%s: bad number", s); @@ -531,7 +531,7 @@ getq(const char *s) intmax_t r; errno = 0; - r = strtoimax(s, &p, 10); + r = strtoimax(s, &p, 10); if(s == p) error("%s: bad number", s); diff --git a/cmd/timeout.c b/cmd/timeout.c @@ -47,8 +47,8 @@ int main(int argc, char *argv[]) { struct timespec time_kill = {.tv_sec = 0, .tv_nsec = 0}; - int term_sig = SIGTERM; - char *term_signame = "SIGTERM"; + int term_sig = SIGTERM; + char *term_signame = "SIGTERM"; char *arg = NULL; @@ -113,7 +113,7 @@ main(int argc, char *argv[]) if(util_sys_signame[i] == NULL) continue; if(strcmp(arg, util_sys_signame[i]) == 0) { - term_sig = i; + term_sig = i; term_signame = optarg; break; } diff --git a/cmd/touch.c b/cmd/touch.c @@ -22,14 +22,14 @@ int main(int argc, char *argv[]) { bool ch_atime = false, ch_mtime = false; - char *ref_file = NULL; + char *ref_file = NULL; struct timespec times[2] = { {.tv_sec = 0, .tv_nsec = UTIME_OMIT}, // access {.tv_sec = 0, .tv_nsec = UTIME_OMIT} // modification }; struct timespec target = {0, UTIME_NOW}; - int open_flags = O_WRONLY | O_CREAT | O_NOCTTY; - int utimensat_flags = 0; + int open_flags = O_WRONLY | O_CREAT | O_NOCTTY; + int utimensat_flags = 0; int c = 0; while((c = getopt(argc, argv, ":achmr:t:d:")) != -1) diff --git a/cmd/tr.c b/cmd/tr.c @@ -173,7 +173,7 @@ main(int argc, char *argv[]) while(next(&s1)) { translate[s1.lastch] = ch = s2.lastch; - squeeze[ch] = 1; + squeeze[ch] = 1; (void)next(&s2); } else diff --git a/cmd/truncate.c b/cmd/truncate.c @@ -29,10 +29,10 @@ int main(int argc, char *argv[]) { int open_flags = O_WRONLY | O_CREAT | O_NONBLOCK; - bool size_set = false; + bool size_set = false; struct truncation tr = { - .op = OP_SET, + .op = OP_SET, .size = 0, }; char *ref_file = NULL; diff --git a/cmd/uname.c b/cmd/uname.c @@ -14,16 +14,16 @@ enum uname_names { - CMD_UNAME_SYSNAME = 1 << 1, + CMD_UNAME_SYSNAME = 1 << 1, CMD_UNAME_NODENAME = 1 << 2, - CMD_UNAME_RELEASE = 1 << 3, - CMD_UNAME_VERSION = 1 << 4, - CMD_UNAME_MACHINE = 1 << 5, + CMD_UNAME_RELEASE = 1 << 3, + CMD_UNAME_VERSION = 1 << 4, + CMD_UNAME_MACHINE = 1 << 5, CMD_UNAME_ALL = CMD_UNAME_SYSNAME | CMD_UNAME_NODENAME | CMD_UNAME_RELEASE | CMD_UNAME_VERSION | CMD_UNAME_MACHINE, }; -const char *fmt = "%s"; +const char *fmt = "%s"; enum uname_names names = 0; static void diff --git a/cmd/uniq.c b/cmd/uniq.c @@ -98,7 +98,7 @@ main(int argc, char *argv[]) assert(errno == 0); - FILE *input = stdin; + FILE *input = stdin; FILE *output = stdout; switch(argc) @@ -134,16 +134,16 @@ main(int argc, char *argv[]) assert(errno == 0); - char *first = NULL; - ssize_t first_len = 0; + char *first = NULL; + ssize_t first_len = 0; size_t first_shift = 0; - unsigned counter = 1; + unsigned counter = 1; errno = 0; while(true) { assert(errno == 0); - char *cur = NULL; + char *cur = NULL; size_t cur_size = 0; ssize_t cur_len = getline(&cur, &cur_size, input); @@ -175,7 +175,7 @@ main(int argc, char *argv[]) { free(cur); cur_size = 0; - cur = NULL; + cur = NULL; break; } @@ -227,8 +227,8 @@ main(int argc, char *argv[]) if(counter == 1) { - first = cur; - first_len = cur_len; + first = cur; + first_len = cur_len; first_shift = cur_shift; } } diff --git a/cmd/wc.c b/cmd/wc.c @@ -22,9 +22,9 @@ static char *argv0 = "wc"; static enum { - WC_OPT_C = 1 << 0, - WC_OPT_L = 1 << 1, - WC_OPT_W = 1 << 2, + WC_OPT_C = 1 << 0, + WC_OPT_L = 1 << 1, + WC_OPT_W = 1 << 2, WC_OPT_ALL = WC_OPT_C | WC_OPT_L | WC_OPT_W, } wc_opts = 0; diff --git a/lib/consent.c b/lib/consent.c @@ -22,7 +22,7 @@ regex_t consent_noexpr_r; void consent_init() { - char *yesexpr = nl_langinfo(YESEXPR); + char *yesexpr = nl_langinfo(YESEXPR); int yesexpr_ret = regcomp(&consent_yesexpr_r, yesexpr, REG_EXTENDED | REG_NOSUB); if(yesexpr_ret != 0) { @@ -38,7 +38,7 @@ consent_init() } assert(errno == 0); - char *noexpr = nl_langinfo(NOEXPR); + char *noexpr = nl_langinfo(NOEXPR); int noexpr_ret = regcomp(&consent_noexpr_r, noexpr, REG_EXTENDED | REG_NOSUB); if(noexpr_ret != 0) { @@ -67,8 +67,8 @@ bool consentf(const char *restrict fmt, ...) { bool result = false; - char *line = NULL; - size_t len = 0; + char *line = NULL; + size_t len = 0; va_list ap; diff --git a/lib/humanize.c b/lib/humanize.c @@ -12,16 +12,16 @@ struct si_scale dtosi(double num, bool iec) { #define PFX 11 - char *si_prefixes[PFX] = {"", "k", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q"}; + char *si_prefixes[PFX] = {"", "k", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q"}; char *iec_prefixes[PFX] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", "RiB", "QiB"}; - int div = iec ? 1024 : 1000; + int div = iec ? 1024 : 1000; char **prefixes = iec ? iec_prefixes : si_prefixes; struct si_scale ret = { - .number = num, - .prefix = "", + .number = num, + .prefix = "", .exponant = 0, }; diff --git a/lib/iso_parse.c b/lib/iso_parse.c @@ -32,19 +32,19 @@ iso_parse(char *arg, char **errstr) if(errno != 0) { *errstr = strerror(errno); - errno = 0; + errno = 0; return time; } return time; } struct tm tm = { - .tm_year = 0, - .tm_mon = 0, - .tm_mday = 0, - .tm_hour = 0, - .tm_min = 0, - .tm_sec = 0, + .tm_year = 0, + .tm_mon = 0, + .tm_mday = 0, + .tm_hour = 0, + .tm_min = 0, + .tm_sec = 0, .tm_isdst = -1, // unknown if DST is in effect }; @@ -54,13 +54,13 @@ iso_parse(char *arg, char **errstr) if(s == NULL) { *errstr = "strptime(…, \"%Y-%m-%d\", …) returned NULL"; - errno = 0; + errno = 0; return time; } if(s[0] != 'T' && s[0] != ' ') { *errstr = "Couldn't find time-separator (T or space) after date (Y-m-d)"; - errno = 0; + errno = 0; return time; } s++; @@ -69,14 +69,14 @@ iso_parse(char *arg, char **errstr) if(s == NULL) { *errstr = "strptime(…, \"%H:%M:%S\", …) returned NULL"; - errno = 0; + errno = 0; return time; } if(s[0] == ',' || s[0] == '.') { double fraction = 0.0; - int parsed = 0; + int parsed = 0; if(s[0] == ',') s[0] = '.'; @@ -90,7 +90,7 @@ iso_parse(char *arg, char **errstr) else { *errstr = strerror(errno); - errno = 0; + errno = 0; } return time; } @@ -109,7 +109,7 @@ iso_parse(char *arg, char **errstr) if(s != NULL && s[0] == 'Z') { tm.tm_gmtoff = 0; - tm.tm_zone = "UTC"; + tm.tm_zone = "UTC"; } assert(errno == 0); @@ -117,7 +117,7 @@ iso_parse(char *arg, char **errstr) if(time.tv_sec == (time_t)-1) { *errstr = strerror(errno); - errno = 0; + errno = 0; return time; } // As observed on FreeBSD 14.0, non-errorneous mktime can still end up setting errno diff --git a/lib/mode.c b/lib/mode.c @@ -19,11 +19,11 @@ enum perm_who_e { - WHO_RST = 0, // 0b000 - WHO_USER = 1, // 0b001 + WHO_RST = 0, // 0b000 + WHO_USER = 1, // 0b001 WHO_GROUP = 2, // 0b010 WHO_OTHER = 4, // 0b100 - WHO_ALL = 7, // 0b111 + WHO_ALL = 7, // 0b111 }; enum operation_e @@ -86,7 +86,7 @@ apply(struct meta_t *meta, int8_t mode) case OP_SET: if(meta->dest == WHO_RST) { - meta->new_modes.user = mode & ((mask >> 6) & 07); + meta->new_modes.user = mode & ((mask >> 6) & 07); meta->new_modes.group = mode & ((mask >> 3) & 07); meta->new_modes.other = mode & ((mask >> 0) & 07); } @@ -134,7 +134,7 @@ new_mode(const char *mode, mode_t old, const char **errstr) if(errno != 0) { *errstr = strerror(errno); - errno = 0; + errno = 0; return old; } @@ -154,11 +154,11 @@ new_mode(const char *mode, mode_t old, const char **errstr) } // ((^|,)[ugoa]*([+-=]|[ugo]|[rwxXst]+)+)+ - struct meta_t meta = {.dest = WHO_RST, - .op = OP_RST, + struct meta_t meta = {.dest = WHO_RST, + .op = OP_RST, .new_modes = { - .set = (old & 07000) >> 9, - .user = (old & 00700) >> 6, + .set = (old & 07000) >> 9, + .user = (old & 00700) >> 6, .group = (old & 00070) >> 3, .other = (old & 00007) >> 0, }}; @@ -172,7 +172,7 @@ new_mode(const char *mode, mode_t old, const char **errstr) // separator case ',': meta.dest = WHO_RST; - meta.op = OP_RST; + meta.op = OP_RST; break; // who diff --git a/lib/path.c b/lib/path.c @@ -17,7 +17,7 @@ static_basename(char *path) char * path_split_static(char *path, bool trim) { - char *child = NULL; + char *child = NULL; size_t path_len = strlen(path); // delete trailing slashes @@ -29,7 +29,7 @@ path_split_static(char *path, bool trim) if(path[i] == '/') { path[i] = 0; - child = &path[i + 1]; + child = &path[i + 1]; break; } diff --git a/lib/tr_str.c b/lib/tr_str.c @@ -205,9 +205,9 @@ genclass(STR *s) if(cp->set == NULL) err(1, NULL); } - s->cnt = 0; + s->cnt = 0; s->state = SET; - s->set = cp->set; + s->set = cp->set; } static int @@ -234,9 +234,9 @@ genequiv(STR *s) if(s->str[1] != '=') errx(1, "misplaced equivalence equals sign"); } s->str += 2; - s->cnt = 0; + s->cnt = 0; s->state = SET; - s->set = s->equiv; + s->set = s->equiv; } static int @@ -246,13 +246,13 @@ genrange(STR *s) unsigned char *savestart; savestart = s->str; - stopval = *++s->str == '\\' ? backslash(s) : *s->str++; + stopval = *++s->str == '\\' ? backslash(s) : *s->str++; if(stopval < (u_char)s->lastch) { s->str = savestart; return (0); } - s->cnt = stopval - s->lastch + 1; + s->cnt = stopval - s->lastch + 1; s->state = RANGE; --s->lastch; return (1); diff --git a/lib/truncation.c b/lib/truncation.c @@ -141,7 +141,7 @@ parse_size(char *arg, struct truncation *buf) assert(errno == 0); char *endptr = NULL; - long size = strtol(arg, &endptr, 10); + long size = strtol(arg, &endptr, 10); if(errno != 0) { fprintf(stderr, "%s: Failed parsing '%s' as a number: %s\n", argv0, arg, strerror(errno)); @@ -154,6 +154,6 @@ parse_size(char *arg, struct truncation *buf) } buf->size = size; - buf->op = op; + buf->op = op; return 0; } diff --git a/lib/user_group_parse.c b/lib/user_group_parse.c @@ -21,7 +21,7 @@ parse_user(char *str, uid_t *user) if(str[0] == 0) return 0; assert(errno == 0); - char *endptr = NULL; + char *endptr = NULL; unsigned int id = strtoul(str, &endptr, 0); if(errno == 0) { @@ -54,7 +54,7 @@ parse_group(char *str, gid_t *group) if(str[0] == 0) return 0; assert(errno == 0); - char *endptr = NULL; + char *endptr = NULL; unsigned int id = strtoul(str, &endptr, 0); if(errno == 0) {