sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 7d2683ddf2a9c5a308b21f7073a75d8b4d31b512
parent 0810c611549427b67d3baa05b0503a3bbd231242
Author: FRIGN <dev@frign.de>
Date:   Thu, 13 Nov 2014 19:54:28 +0100

Sort includes and more cleanup and fixes in util/

Diffstat:
Mchgrp.c | 6+++---
Mchmod.c | 3++-
Mcksum.c | 2+-
Mcols.c | 2+-
Mcomm.c | 2+-
Mdu.c | 12++++++------
Menv.c | 4++--
Mkill.c | 2+-
Mls.c | 2+-
Mmd5sum.c | 2+-
Mmkdir.c | 3+--
Mmkfifo.c | 2+-
Mmv.c | 2+-
Mrmdir.c | 2+-
Msetsid.c | 2+-
Msha1sum.c | 4++--
Msha256sum.c | 4++--
Msha512sum.c | 4++--
Msplit.c | 6+++---
Mstrings.c | 2+-
Mtar.c | 14+++++++-------
Mtest.c | 2+-
Mtouch.c | 2+-
Mtr.c | 2+-
Mtty.c | 2+-
Muname.c | 2+-
Munlink.c | 3++-
Mutil/agetcwd.c | 2+-
Mutil/apathmax.c | 6+++---
Mutil/cp.c | 46+++++++++++++++++++++++-----------------------
Mutil/crypt.c | 51++++++++++++++++++++++++++-------------------------
Mutil/enmasse.c | 10+++++-----
Mutil/eprintf.c | 2+-
Mutil/estrtod.c | 2+-
Mutil/estrtol.c | 6+++---
Mutil/fnck.c | 4++--
Mutil/getlines.c | 8++++----
Mutil/human.c | 5+++--
Mutil/md5.c | 1+
Mutil/mode.c | 75++++++++++++++++++++++++++++++++++++++-------------------------------------
Mutil/putword.c | 3+--
Mutil/rm.c | 5++---
Mutil/sha1.c | 1+
Mutil/sha256.c | 5+++--
Mutil/sha512.c | 5+++--
Mutil/strlcat.c | 3++-
Mutil/strlcpy.c | 3++-
Muudecode.c | 8++++----
48 files changed, 177 insertions(+), 169 deletions(-)

diff --git a/chgrp.c b/chgrp.c @@ -1,12 +1,12 @@ /* See LICENSE file for copyright and license details. */ -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> #include <errno.h> #include <grp.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> #include "util.h" diff --git a/chmod.c b/chmod.c @@ -2,8 +2,9 @@ #include <stdbool.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> #include <sys/stat.h> +#include <unistd.h> + #include "util.h" static void chmodr(const char *); diff --git a/cksum.c b/cksum.c @@ -1,6 +1,6 @@ /* See LICENSE file for copyright and license details. */ -#include <stdint.h> #include <inttypes.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/cols.c b/cols.c @@ -4,8 +4,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> #include <sys/ioctl.h> +#include <unistd.h> #include "text.h" #include "util.h" diff --git a/comm.c b/comm.c @@ -1,9 +1,9 @@ /* See LICENSE file for copyright and license details. */ +#include <limits.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <limits.h> #include "util.h" diff --git a/du.c b/du.c @@ -1,13 +1,13 @@ /* See LICENSE file for copyright and license details. */ -#include <sys/types.h> -#include <sys/stat.h> #include <dirent.h> -#include <unistd.h> +#include <limits.h> +#include <stdbool.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> -#include <stdbool.h> -#include <limits.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> #include "util.h" diff --git a/env.c b/env.c @@ -1,9 +1,9 @@ /* See LICENSE file for copyright and license details. */ -#include <unistd.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <errno.h> +#include <unistd.h> #include "util.h" diff --git a/kill.c b/kill.c @@ -1,5 +1,4 @@ /* See LICENSE file for copyright and license details. */ -#include <sys/wait.h> #include <ctype.h> #include <errno.h> #include <signal.h> @@ -8,6 +7,7 @@ #include <stdlib.h> #include <string.h> #include <strings.h> +#include <sys/wait.h> #include <unistd.h> #include "util.h" diff --git a/ls.c b/ls.c @@ -7,9 +7,9 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> #include <time.h> #include <unistd.h> -#include <sys/stat.h> #include "util.h" diff --git a/md5sum.c b/md5sum.c @@ -4,9 +4,9 @@ #include <stdlib.h> #include <stdint.h> -#include "util.h" #include "crypt.h" #include "md5.h" +#include "util.h" struct md5 s; struct crypt_ops md5_ops = { diff --git a/mkdir.c b/mkdir.c @@ -1,12 +1,11 @@ /* See LICENSE file for copyright and license details. */ -#include <sys/stat.h> #include <errno.h> #include <fcntl.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> #include <sys/stat.h> +#include <unistd.h> #include "util.h" diff --git a/mkfifo.c b/mkfifo.c @@ -1,8 +1,8 @@ /* See LICENSE file for copyright and license details. */ #include <fcntl.h> #include <stdlib.h> -#include <unistd.h> #include <sys/stat.h> +#include <unistd.h> #include "util.h" diff --git a/mv.c b/mv.c @@ -2,8 +2,8 @@ #include <errno.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <sys/stat.h> +#include <unistd.h> #include "fs.h" #include "util.h" diff --git a/rmdir.c b/rmdir.c @@ -1,9 +1,9 @@ /* See LICENSE file for copyright and license details. */ +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> -#include <errno.h> #include "util.h" diff --git a/setsid.c b/setsid.c @@ -1,9 +1,9 @@ /* See LICENSE file for copyright and license details. */ #include <errno.h> #include <stdio.h> -#include <unistd.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include "util.h" diff --git a/sha1sum.c b/sha1sum.c @@ -1,12 +1,12 @@ /* See LICENSE file for copyright and license details. */ #include <stdbool.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> -#include "util.h" #include "crypt.h" #include "sha1.h" +#include "util.h" struct sha1 s; struct crypt_ops sha1_ops = { diff --git a/sha256sum.c b/sha256sum.c @@ -1,12 +1,12 @@ /* See LICENSE file for copyright and license details. */ #include <stdbool.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> -#include "util.h" #include "crypt.h" #include "sha256.h" +#include "util.h" struct sha256 s; struct crypt_ops sha256_ops = { diff --git a/sha512sum.c b/sha512sum.c @@ -1,12 +1,12 @@ /* See LICENSE file for copyright and license details. */ #include <stdbool.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> -#include "util.h" #include "crypt.h" #include "sha512.h" +#include "util.h" struct sha512 s; struct crypt_ops sha512_ops = { diff --git a/split.c b/split.c @@ -1,10 +1,10 @@ /* See LICENSE file for copyright and license details. */ +#include <ctype.h> +#include <limits.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> #include <string.h> -#include <ctype.h> -#include <limits.h> #include "util.h" diff --git a/strings.c b/strings.c @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ +#include <ctype.h> #include <stdio.h> #include <stdlib.h> -#include <ctype.h> #include "util.h" diff --git a/tar.c b/tar.c @@ -1,15 +1,15 @@ /* See LICENSE file for copyright and license details. */ -#include <stdlib.h> -#include <unistd.h> -#include <stdio.h> +#include <grp.h> +#include <limits.h> +#include <pwd.h> #include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <sys/types.h> #include <sys/stat.h> #include <sys/time.h> -#include <limits.h> -#include <grp.h> -#include <pwd.h> +#include <sys/types.h> +#include <unistd.h> #include "util.h" diff --git a/test.c b/test.c @@ -1,10 +1,10 @@ /* See LICENSE file for copyright and license details. */ -#include <sys/stat.h> #include <errno.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> #include <unistd.h> #include "util.h" diff --git a/touch.c b/touch.c @@ -3,10 +3,10 @@ #include <fcntl.h> #include <stdbool.h> #include <stdlib.h> +#include <sys/stat.h> #include <time.h> #include <unistd.h> #include <utime.h> -#include <sys/stat.h> #include "util.h" diff --git a/tr.c b/tr.c @@ -1,9 +1,9 @@ /* See LICENSE file for copyright and license details. */ +#include <locale.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <locale.h> #include <wchar.h> #include "text.h" diff --git a/tty.c b/tty.c @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ -#include <unistd.h> #include <stdio.h> #include <stdlib.h> +#include <unistd.h> #include "util.h" diff --git a/uname.c b/uname.c @@ -2,8 +2,8 @@ #include <stdbool.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <sys/utsname.h> +#include <unistd.h> #include "util.h" diff --git a/unlink.c b/unlink.c @@ -1,6 +1,7 @@ /* See LICENSE file for copyright and license details. */ -#include <unistd.h> #include <stdlib.h> +#include <unistd.h> + #include "util.h" static void diff --git a/util/agetcwd.c b/util/agetcwd.c @@ -10,7 +10,7 @@ agetcwd(void) long size; apathmax(&buf, &size); - if(!getcwd(buf, size)) + if (!getcwd(buf, size)) eprintf("getcwd:"); return buf; diff --git a/util/apathmax.c b/util/apathmax.c @@ -11,14 +11,14 @@ apathmax(char **p, long *size) { errno = 0; - if((*size = pathconf("/", _PC_PATH_MAX)) == -1) { - if(errno == 0) { + if ((*size = pathconf("/", _PC_PATH_MAX)) == -1) { + if (errno == 0) { *size = BUFSIZ; } else { eprintf("pathconf:"); } } - if(!(*p = malloc(*size))) + if (!(*p = malloc(*size))) eprintf("malloc:"); } diff --git a/util/cp.c b/util/cp.c @@ -37,20 +37,20 @@ cp(const char *s1, const char *s2) DIR *dp; int r; - if(cp_vflag) + if (cp_vflag) printf("'%s' -> '%s'\n", s1, s2); - if(cp_dflag == true) + if (cp_dflag == true) r = lstat(s1, &st); else r = stat(s1, &st); - if(r == 0) { - if(cp_dflag == true && S_ISLNK(st.st_mode)) { - if(readlink(s1, buf, sizeof(buf) - 1) >= 0) { - if(cp_fflag == true); + if (r == 0) { + if (cp_dflag == true && S_ISLNK(st.st_mode)) { + if (readlink(s1, buf, sizeof(buf) - 1) >= 0) { + if (cp_fflag == true); unlink(s2); - if(symlink(buf, s2) != 0) { + if (symlink(buf, s2) != 0) { weprintf("%s: can't create '%s'\n", argv0, s2); cp_status = 1; return 0; @@ -58,11 +58,11 @@ cp(const char *s1, const char *s2) } goto preserve; } - if(S_ISDIR(st.st_mode)) { + if (S_ISDIR(st.st_mode)) { if (!cp_rflag) eprintf("%s: is a directory\n", s1); - if(!(dp = opendir(s1))) + if (!(dp = opendir(s1))) eprintf("opendir %s:", s1); if (mkdir(s2, st.st_mode) == -1 && errno != EEXIST) @@ -70,15 +70,15 @@ cp(const char *s1, const char *s2) apathmax(&ns1, &size1); apathmax(&ns2, &size2); - while((d = readdir(dp))) { - if(strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) { + while ((d = readdir(dp))) { + if (strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) { r = snprintf(ns1, size1, "%s/%s", s1, d->d_name); - if(r >= size1 || r < 0) { + if (r >= size1 || r < 0) { eprintf("%s/%s: filename too long\n", s1, d->d_name); } r = snprintf(ns2, size2, "%s/%s", s2, d->d_name); - if(r >= size2 || r < 0) { + if (r >= size2 || r < 0) { eprintf("%s/%s: filename too long\n", s2, d->d_name); } @@ -92,11 +92,11 @@ cp(const char *s1, const char *s2) } } - if(cp_aflag == true) { - if(S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode) || + if (cp_aflag == true) { + if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode) || S_ISSOCK(st.st_mode) || S_ISFIFO(st.st_mode)) { unlink(s2); - if(mknod(s2, st.st_mode, st.st_rdev) < 0) { + if (mknod(s2, st.st_mode, st.st_rdev) < 0) { weprintf("%s: can't create '%s':", argv0, s2); cp_status = 1; return 0; @@ -105,16 +105,16 @@ cp(const char *s1, const char *s2) } } - if(!(f1 = fopen(s1, "r"))) { + if (!(f1 = fopen(s1, "r"))) { weprintf("fopen %s:", s1); cp_status = 1; return 0; } - if(!(f2 = fopen(s2, "w"))) { + if (!(f2 = fopen(s2, "w"))) { if (cp_fflag == true) { unlink(s2); - if(!(f2 = fopen(s2, "w"))) { + if (!(f2 = fopen(s2, "w"))) { weprintf("fopen %s:", s2); cp_status = 1; return 0; @@ -131,19 +131,19 @@ cp(const char *s1, const char *s2) fclose(f1); preserve: - if(cp_aflag == true || cp_pflag == true) { - if(!(S_ISLNK(st.st_mode))) { + if (cp_aflag == true || cp_pflag == true) { + if (!(S_ISLNK(st.st_mode))) { /* timestamp */ ut.actime = st.st_atime; ut.modtime = st.st_mtime; utime(s2, &ut); } /* preserve owner ? */ - if(S_ISLNK(st.st_mode)) + if (S_ISLNK(st.st_mode)) r = lchown(s2, st.st_uid, st.st_gid); else r = chown(s2, st.st_uid, st.st_gid); - if(r == -1) { + if (r == -1) { weprintf("cp: can't preserve ownership of '%s':", s2); cp_status = 1; } diff --git a/util/crypt.c b/util/crypt.c @@ -1,20 +1,21 @@ /* See LICENSE file for copyright and license details. */ +#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> #include <string.h> -#include "../util.h" -#include "../text.h" + #include "../crypt.h" +#include "../text.h" +#include "../util.h" static int hexdec(int c) { - if(c >= '0' && c <= '9') + if (c >= '0' && c <= '9') return c - '0'; - else if(c >= 'A' && c <= 'F') + else if (c >= 'A' && c <= 'F') return c - 'A' + 10; - else if(c >= 'a' && c <= 'f') + else if (c >= 'a' && c <= 'f') return c - 'a' + 10; return -1; /* unknown character */ } @@ -25,12 +26,12 @@ mdcheckline(const char *s, uint8_t *md, size_t sz) size_t i; int b1, b2; - for(i = 0; i < sz; i++) { - if(!*s || (b1 = hexdec(*s++)) < 0) + for (i = 0; i < sz; i++) { + if (!*s || (b1 = hexdec(*s++)) < 0) return -1; /* invalid format */ - if(!*s || (b2 = hexdec(*s++)) < 0) + if (!*s || (b2 = hexdec(*s++)) < 0) return -1; /* invalid format */ - if((uint8_t)((b1 << 4) | b2) != md[i]) + if ((uint8_t)((b1 << 4) | b2) != md[i]) return 0; /* value mismatch */ } return (i == sz) ? 1 : 0; @@ -45,34 +46,34 @@ cryptcheck(char *sumfile, int argc, char *argv[], int r, nonmatch = 0, formatsucks = 0, noread = 0, ret = 0; size_t bufsiz = 0; - if(sumfile == NULL) + if (sumfile == NULL) cfp = stdin; - else if(!(cfp = fopen(sumfile, "r"))) + else if (!(cfp = fopen(sumfile, "r"))) eprintf("fopen %s:", sumfile); - while(agetline(&line, &bufsiz, cfp) != -1) { - if(!(file = strstr(line, " "))) { + while (agetline(&line, &bufsiz, cfp) != -1) { + if (!(file = strstr(line, " "))) { formatsucks++; continue; } - if((file - line) / 2 != sz) { + if ((file - line) / 2 != sz) { formatsucks++; /* checksum length mismatch */ continue; } *file = '\0'; file += 2; - for(p = file; *p && *p != '\n' && *p != '\r'; p++); /* strip newline */ + for (p = file; *p && *p != '\n' && *p != '\r'; p++); /* strip newline */ *p = '\0'; - if(!(fp = fopen(file, "r"))) { + if (!(fp = fopen(file, "r"))) { weprintf("fopen %s:", file); noread++; continue; } cryptsum(ops, fp, file, md); r = mdcheckline(line, md, sz); - if(r == 1) { + if (r == 1) { printf("%s: OK\n", file); - } else if(r == 0) { + } else if (r == 0) { printf("%s: FAILED\n", file); nonmatch++; } else { @@ -80,18 +81,18 @@ cryptcheck(char *sumfile, int argc, char *argv[], } fclose(fp); } - if(sumfile != NULL) + if (sumfile != NULL) fclose(cfp); free(line); - if(formatsucks > 0) { + if (formatsucks > 0) { weprintf("%d lines are improperly formatted\n", formatsucks); ret = 1; } - if(noread > 0) { + if (noread > 0) { weprintf("%d listed file could not be read\n", noread); ret = 1; } - if(nonmatch > 0) { + if (nonmatch > 0) { weprintf("%d computed checksums did NOT match\n", nonmatch); ret = 1; } @@ -110,12 +111,12 @@ cryptmain(int argc, char *argv[], mdprint(md, "<stdin>", sz); } else { for (; argc > 0; argc--) { - if((fp = fopen(*argv, "r")) == NULL) { + if ((fp = fopen(*argv, "r")) == NULL) { weprintf("fopen %s:", *argv); ret = 1; continue; } - if(cryptsum(ops, fp, *argv, md) == 1) + if (cryptsum(ops, fp, *argv, md) == 1) ret = 1; else mdprint(md, *argv, sz); diff --git a/util/enmasse.c b/util/enmasse.c @@ -3,8 +3,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> #include <sys/stat.h> +#include <unistd.h> #include "../util.h" @@ -17,7 +17,7 @@ enmasse(int argc, char *argv[], int (*fn)(const char *, const char *)) struct stat st; size_t dlen; - if(argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) { + if (argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) { fnck(argv[0], argv[1], fn); return; } else { @@ -25,13 +25,13 @@ enmasse(int argc, char *argv[], int (*fn)(const char *, const char *)) } apathmax(&buf, &size); - for(i = 0; i < argc; i++) { + for (i = 0; i < argc; i++) { dlen = strlen(dir); - if(dlen > 0 && dir[dlen - 1] == '/') + if (dlen > 0 && dir[dlen - 1] == '/') len = snprintf(buf, size, "%s%s", dir, basename(argv[i])); else len = snprintf(buf, size, "%s/%s", dir, basename(argv[i])); - if(len < 0 || len >= size) { + if (len < 0 || len >= size) { eprintf("%s/%s: filename too long\n", dir, basename(argv[i])); } diff --git a/util/eprintf.c b/util/eprintf.c @@ -39,7 +39,7 @@ venprintf(int status, const char *fmt, va_list ap) vfprintf(stderr, fmt, ap); - if(fmt[0] && fmt[strlen(fmt)-1] == ':') { + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { fputc(' ', stderr); perror(NULL); } diff --git a/util/estrtod.c b/util/estrtod.c @@ -12,7 +12,7 @@ estrtod(const char *s) double d; d = strtod(s, &end); - if(end == s || *end != '\0') + if (end == s || *end != '\0') eprintf("%s: not a real number\n", s); return d; } diff --git a/util/estrtol.c b/util/estrtol.c @@ -13,13 +13,13 @@ estrtol(const char *s, int base) errno = 0; n = strtol(s, &end, base); - if(*end != '\0') { - if(base == 0) + if (*end != '\0') { + if (base == 0) eprintf("%s: not an integer\n", s); else eprintf("%s: not a base %d integer\n", s, base); } - if(errno != 0) + if (errno != 0) eprintf("%s:", s); return n; diff --git a/util/fnck.c b/util/fnck.c @@ -8,13 +8,13 @@ fnck(const char *a, const char *b, int (*fn)(const char *, const char *)) { struct stat sta, stb; - if(stat(a, &sta) == 0 + if (stat(a, &sta) == 0 && stat(b, &stb) == 0 && sta.st_dev == stb.st_dev && sta.st_ino == stb.st_ino) { eprintf("%s -> %s: same file\n", a, b); } - if(fn(a, b) == -1) + if (fn(a, b) == -1) eprintf("%s -> %s:", a, b); } diff --git a/util/getlines.c b/util/getlines.c @@ -13,16 +13,16 @@ getlines(FILE *fp, struct linebuf *b) size_t size = 0, linelen; ssize_t len; - while((len = agetline(&line, &size, fp)) != -1) { - if(++b->nlines > b->capacity) { + while ((len = agetline(&line, &size, fp)) != -1) { + if (++b->nlines > b->capacity) { b->capacity += 512; nline = realloc(b->lines, b->capacity * sizeof(*b->lines)); - if(nline == NULL) + if (nline == NULL) eprintf("realloc:"); b->lines = nline; } linelen = len + 1; - if(!(b->lines[b->nlines-1] = malloc(linelen))) + if (!(b->lines[b->nlines-1] = malloc(linelen))) eprintf("malloc:"); memcpy(b->lines[b->nlines-1], line, linelen); } diff --git a/util/human.c b/util/human.c @@ -1,3 +1,4 @@ +/* See LICENSE file for copyright and license details. */ #include <stdio.h> #include <string.h> @@ -10,10 +11,10 @@ humansize(double n) const char postfixes[] = "BKMGTPE"; size_t i; - for(i = 0; n >= 1024 && i < strlen(postfixes); i++) + for (i = 0; n >= 1024 && i < strlen(postfixes); i++) n /= 1024; - if(!i) + if (!i) snprintf(buf, sizeof(buf), "%lu", (unsigned long)n); else snprintf(buf, sizeof(buf), "%.1f%c", n, postfixes[i]); diff --git a/util/md5.c b/util/md5.c @@ -1,6 +1,7 @@ /* public domain md5 implementation based on rfc1321 and libtomcrypt */ #include <stdint.h> #include <string.h> + #include "../md5.h" static uint32_t rol(uint32_t n, int k) { return (n << k) | (n >> (32-k)); } diff --git a/util/mode.c b/util/mode.c @@ -1,7 +1,8 @@ -#include <unistd.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #include <sys/stat.h> +#include <unistd.h> + #include "../util.h" mode_t @@ -21,30 +22,30 @@ parsemode(const char *str, mode_t mode, mode_t mask) mode_t who, perm, clear; octal = strtol(str, &end, 8); - if(*end == '\0') { - if(octal < 0 || octal > 07777) { + if (*end == '\0') { + if (octal < 0 || octal > 07777) { eprintf("%s: invalid mode\n", str); return -1; } mode = 0; - if(octal & 04000) mode |= S_ISUID; - if(octal & 02000) mode |= S_ISGID; - if(octal & 01000) mode |= S_ISVTX; - if(octal & 00400) mode |= S_IRUSR; - if(octal & 00200) mode |= S_IWUSR; - if(octal & 00100) mode |= S_IXUSR; - if(octal & 00040) mode |= S_IRGRP; - if(octal & 00020) mode |= S_IWGRP; - if(octal & 00010) mode |= S_IXGRP; - if(octal & 00004) mode |= S_IROTH; - if(octal & 00002) mode |= S_IWOTH; - if(octal & 00001) mode |= S_IXOTH; + if (octal & 04000) mode |= S_ISUID; + if (octal & 02000) mode |= S_ISGID; + if (octal & 01000) mode |= S_ISVTX; + if (octal & 00400) mode |= S_IRUSR; + if (octal & 00200) mode |= S_IWUSR; + if (octal & 00100) mode |= S_IXUSR; + if (octal & 00040) mode |= S_IRGRP; + if (octal & 00020) mode |= S_IWGRP; + if (octal & 00010) mode |= S_IXGRP; + if (octal & 00004) mode |= S_IROTH; + if (octal & 00002) mode |= S_IWOTH; + if (octal & 00001) mode |= S_IXOTH; return mode; } next: /* first, determine which bits we will be modifying */ - for(who = 0; *p; p++) { - switch(*p) { + for (who = 0; *p; p++) { + switch (*p) { /* masks */ case 'u': who |= S_IRWXU|S_ISUID; @@ -61,14 +62,14 @@ next: } break; } - if(who) { + if (who) { clear = who; } else { clear = S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO; who = ~mask; } - while(*p) { - switch(*p) { + while (*p) { + switch (*p) { /* opers */ case '=': case '+': @@ -81,42 +82,42 @@ next: } perm = 0; - switch(*++p) { + switch (*++p) { /* copy */ case 'u': - if(mode & S_IRUSR) + if (mode & S_IRUSR) perm |= S_IRUSR|S_IRGRP|S_IROTH; - if(mode & S_IWUSR) + if (mode & S_IWUSR) perm |= S_IWUSR|S_IWGRP|S_IWOTH; - if(mode & S_IXUSR) + if (mode & S_IXUSR) perm |= S_IXUSR|S_IXGRP|S_IXOTH; - if(mode & S_ISUID) + if (mode & S_ISUID) perm |= S_ISUID|S_ISGID; p++; break; case 'g': - if(mode & S_IRGRP) + if (mode & S_IRGRP) perm |= S_IRUSR|S_IRGRP|S_IROTH; - if(mode & S_IWGRP) + if (mode & S_IWGRP) perm |= S_IWUSR|S_IWGRP|S_IWOTH; - if(mode & S_IXGRP) + if (mode & S_IXGRP) perm |= S_IXUSR|S_IXGRP|S_IXOTH; - if(mode & S_ISGID) + if (mode & S_ISGID) perm |= S_ISUID|S_ISGID; p++; break; case 'o': - if(mode & S_IROTH) + if (mode & S_IROTH) perm |= S_IRUSR|S_IRGRP|S_IROTH; - if(mode & S_IWOTH) + if (mode & S_IWOTH) perm |= S_IWUSR|S_IWGRP|S_IWOTH; - if(mode & S_IXOTH) + if (mode & S_IXOTH) perm |= S_IXUSR|S_IXGRP|S_IXOTH; p++; break; default: - for(; *p; p++) { - switch(*p) { + for (; *p; p++) { + switch (*p) { /* modes */ case 'r': perm |= S_IRUSR|S_IRGRP|S_IROTH; @@ -141,7 +142,7 @@ next: apply: /* apply */ - switch(op) { + switch (op) { case '=': mode &= ~clear; /* fallthrough */ @@ -153,7 +154,7 @@ next: break; } /* if we hit a comma, move on to the next clause */ - if(*p == ',') { + if (*p == ',') { p++; goto next; } diff --git a/util/putword.c b/util/putword.c @@ -9,10 +9,9 @@ putword(const char *s) { static bool first = true; - if(!first) + if (!first) putchar(' '); fputs(s, stdout); first = false; } - diff --git a/util/rm.c b/util/rm.c @@ -10,9 +10,8 @@ bool rm_fflag = false, rm_rflag = false; void rm(const char *path) { - if(rm_rflag) + if (rm_rflag) recurse(path, rm); - if(remove(path) == -1 && !rm_fflag) + if (remove(path) == -1 && !rm_fflag) eprintf("remove %s:", path); } - diff --git a/util/sha1.c b/util/sha1.c @@ -1,6 +1,7 @@ /* public domain sha1 implementation based on rfc3174 and libtomcrypt */ #include <stdint.h> #include <string.h> + #include "../sha1.h" static uint32_t rol(uint32_t n, int k) { return (n << k) | (n >> (32-k)); } diff --git a/util/sha256.c b/util/sha256.c @@ -1,9 +1,10 @@ /* public domain sha256 implementation based on fips180-3 */ #include <ctype.h> -#include <stdlib.h> +#include <stdint.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <stdint.h> + #include "../sha256.h" static uint32_t ror(uint32_t n, int k) { return (n >> k) | (n << (32-k)); } diff --git a/util/sha512.c b/util/sha512.c @@ -1,10 +1,11 @@ /* public domain sha256 implementation based on fips180-3 */ #include <ctype.h> -#include <stdlib.h> +#include <stdint.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <stdint.h> + #include "../sha512.h" static uint64_t ror(uint64_t n, int k) { return (n >> k) | (n << (64-k)); } diff --git a/util/strlcat.c b/util/strlcat.c @@ -14,8 +14,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/types.h> #include <string.h> +#include <sys/types.h> + #include "../util.h" /* diff --git a/util/strlcpy.c b/util/strlcpy.c @@ -14,8 +14,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/types.h> #include <string.h> +#include <sys/types.h> + #include "../util.h" /* diff --git a/uudecode.c b/uudecode.c @@ -1,15 +1,15 @@ /* See LICENSE file for copyright and license details. */ +#include <errno.h> +#include <limits.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> -#include <errno.h> -#include <limits.h> -#include "util.h" #include "text.h" +#include "util.h" static void uudecode(FILE *, FILE *); static void parseheader(FILE *, const char *, const char *, mode_t *, char **);