sbase

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

commit 953ebf35730c986ca68b0cf7d97f22dceccb08a0
parent 97ca7c8b6df0c90e600cbbd258b74bd524d78aef
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  1 Jun 2014 14:59:47 +0200

code style

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Mbasename.c | 1-
Mcal.c | 1-
Mchroot.c | 1-
Mcksum.c | 3+--
Mcomm.c | 7+++----
Mdate.c | 1-
Mdirname.c | 1-
Mecho.c | 1-
Menv.c | 3+--
Mfold.c | 4++--
Mhead.c | 2+-
Mkill.c | 1-
Mln.c | 1-
Mls.c | 13++++++-------
Mmkdir.c | 3+--
Mmkfifo.c | 1-
Mmv.c | 5++---
Mnice.c | 1-
Mnl.c | 1-
Mnohup.c | 1-
Mpaste.c | 41+++++++++++++++++------------------------
Mpwd.c | 3+--
Mrenice.c | 1-
Mrm.c | 1-
Msleep.c | 1-
Mtail.c | 4++--
Mtar.c | 15+++++++--------
Mtee.c | 3+--
Mtest.c | 5++---
Mtouch.c | 3+--
Muname.c | 1-
Muniq.c | 12++++++------
Mutil/cp.c | 3+--
Mutil/mode.c | 6+++---
Myes.c | 1-
35 files changed, 58 insertions(+), 94 deletions(-)

diff --git a/basename.c b/basename.c @@ -39,4 +39,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/cal.c b/cal.c @@ -189,4 +189,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/chroot.c b/chroot.c @@ -46,4 +46,3 @@ main(int argc, char *argv[]) _exit(savederrno == ENOENT ? 127 : 126); return EXIT_FAILURE; } - diff --git a/cksum.c b/cksum.c @@ -93,7 +93,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -void +static void cksum(FILE *fp, const char *s) { unsigned char buf[BUFSIZ]; @@ -117,4 +117,3 @@ cksum(FILE *fp, const char *s) printf(" %s", s); putchar('\n'); } - diff --git a/comm.c b/comm.c @@ -66,7 +66,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -void +static void printline(int pos, char *line) { int i; @@ -81,7 +81,7 @@ printline(int pos, char *line) printf("%s", line); } -char * +static char * nextline(char *buf, int n, FILE *f, char *name) { buf = fgets(buf, n, f); @@ -93,7 +93,7 @@ nextline(char *buf, int n, FILE *f, char *name) return buf; } -void +static void finish(int pos, FILE *f, char *name) { char buf[LINE_MAX+1]; @@ -103,4 +103,3 @@ finish(int pos, FILE *f, char *name) exit(EXIT_FAILURE); } - diff --git a/date.c b/date.c @@ -43,4 +43,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/dirname.c b/dirname.c @@ -26,4 +26,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/echo.c b/echo.c @@ -31,4 +31,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/env.c b/env.c @@ -34,7 +34,7 @@ main(int argc, char *argv[]) if(*argv) { execvp(*argv, argv); - enprintf(127-(errno!=EEXIST), "env: '%s':", *argv); + enprintf(127 - (errno != EEXIST), "env: '%s':", *argv); } while(environ && *environ) @@ -42,4 +42,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/fold.c b/fold.c @@ -58,7 +58,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -void +static void fold(FILE *fp, long width) { char *buf = NULL; @@ -69,7 +69,7 @@ fold(FILE *fp, long width) free(buf); } -void +static void foldline(const char *str, long width) { bool space; diff --git a/head.c b/head.c @@ -46,7 +46,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -void +static void head(FILE *fp, const char *str, long n) { char buf[BUFSIZ]; diff --git a/kill.c b/kill.c @@ -76,4 +76,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/ln.c b/ln.c @@ -41,4 +41,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/ls.c b/ls.c @@ -96,7 +96,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -int +static int entcmp(const void *va, const void *vb) { const Entry *a = va, *b = vb; @@ -107,7 +107,7 @@ entcmp(const void *va, const void *vb) return strcmp(a->name, b->name); } -void +static void ls(Entry *ent) { if(S_ISDIR(ent->mode) && !dflag) { @@ -117,7 +117,7 @@ ls(Entry *ent) } } -void +static void lsdir(const char *path) { char *cwd, *p; @@ -169,7 +169,7 @@ lsdir(const char *path) free(cwd); } -void +static void mkent(Entry *ent, char *path, bool dostat) { struct stat st; @@ -188,7 +188,7 @@ mkent(Entry *ent, char *path, bool dostat) ent->ino = st.st_ino; } -char * +static char * indicator(mode_t mode) { if(!Fflag) @@ -210,7 +210,7 @@ indicator(mode_t mode) return ""; } -void +static void output(Entry *ent) { char buf[BUFSIZ], *fmt; @@ -290,4 +290,3 @@ output(Entry *ent) } putchar('\n'); } - diff --git a/mkdir.c b/mkdir.c @@ -53,7 +53,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -void +static void mkdirp(char *path) { char *p = path; @@ -67,4 +67,3 @@ mkdirp(char *path) *p = '/'; } while(p); } - diff --git a/mkfifo.c b/mkfifo.c @@ -33,4 +33,3 @@ main(int argc, char *argv[]) eprintf("mkfifo %s:", argv[0]); return EXIT_SUCCESS; } - diff --git a/mv.c b/mv.c @@ -7,7 +7,7 @@ #include "fs.h" #include "util.h" -int mv(const char *, const char *); +static int mv(const char *, const char *); static void usage(void) @@ -37,7 +37,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -int +static int mv(const char *s1, const char *s2) { if (rename(s1, s2) == 0) @@ -51,4 +51,3 @@ mv(const char *s1, const char *s2) } return -1; } - diff --git a/nice.c b/nice.c @@ -46,4 +46,3 @@ main(int argc, char *argv[]) weprintf("execvp %s:", argv[0]); return (savederrno == ENOENT)? 127 : 126; } - diff --git a/nl.c b/nl.c @@ -80,4 +80,3 @@ nl(FILE *fp) } free(buf); } - diff --git a/nohup.c b/nohup.c @@ -49,4 +49,3 @@ main(int argc, char *argv[]) return Error; } - diff --git a/paste.c b/paste.c @@ -30,9 +30,9 @@ main(int argc, char *argv[]) { const char *adelim = NULL; bool seq = false; - wchar_t *delim; + wchar_t *delim = NULL; size_t len; - Fdescr *dsc; + Fdescr *dsc = NULL; int i; setlocale(LC_CTYPE, ""); @@ -59,8 +59,7 @@ main(int argc, char *argv[]) if(len == (size_t)-1) eprintf("invalid delimiter\n"); - delim = malloc((len + 1) * sizeof(*delim)); - if(!delim) + if(!(delim = malloc((len + 1) * sizeof(*delim)))) eprintf("out of memory\n"); mbstowcs(delim, adelim, len); @@ -69,22 +68,19 @@ main(int argc, char *argv[]) eprintf("no delimiters specified\n"); /* populate file list */ - dsc = malloc(argc * sizeof(*dsc)); - if(!dsc) + if(!(dsc = malloc(argc * sizeof(*dsc)))) eprintf("out of memory\n"); for(i = 0; i < argc; i++) { - const char *name = argv[i]; - - if(strcmp(name, "-") == 0) + if(strcmp(argv[i], "-") == 0) dsc[i].fp = stdin; else - dsc[i].fp = fopen(name, "r"); + dsc[i].fp = fopen(argv[i], "r"); if(!dsc[i].fp) - eprintf("can't open '%s':", name); + eprintf("can't open '%s':", argv[i]); - dsc[i].name = name; + dsc[i].name = argv[i]; } if(seq) @@ -160,10 +156,12 @@ static void sequential(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt) { int i; + size_t d; + wint_t c, last; for(i = 0; i < len; i++) { - size_t d = 0; - wint_t c, last = WEOF; + d = 0; + last = WEOF; while((c = in(&dsc[i])) != WEOF) { if(last == '\n') { @@ -188,19 +186,17 @@ sequential(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt) static void parallel(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt) { - int last; + int last, i; + wint_t c, o; + wchar_t d; do { - int i; - last = 0; for(i = 0; i < len; i++) { - wint_t c; - wchar_t d = delim[i % cnt]; + d = delim[i % cnt]; do { - wint_t o = in(&dsc[i]); - + o = in(&dsc[i]); c = o; switch(c) { case WEOF: @@ -212,7 +208,6 @@ parallel(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt) case '\n': if(i != len - 1) o = d; - break; default: break; @@ -224,11 +219,9 @@ parallel(Fdescr *dsc, int len, const wchar_t *delim, size_t cnt) if(d != '\0') out(d); } - out((wchar_t)o); } } while(c != '\n' && c != WEOF); } } while(last > 0); } - diff --git a/pwd.c b/pwd.c @@ -34,7 +34,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -const char * +static const char * getpwd(const char *cwd) { const char *pwd; @@ -49,4 +49,3 @@ getpwd(const char *cwd) else return cwd; } - diff --git a/renice.c b/renice.c @@ -114,4 +114,3 @@ renice(int which, int who, long adj) return true; } - diff --git a/rm.c b/rm.c @@ -36,4 +36,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/sleep.c b/sleep.c @@ -27,4 +27,3 @@ main(int argc, char *argv[]) ; return EXIT_SUCCESS; } - diff --git a/tail.c b/tail.c @@ -52,7 +52,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -void +static void dropinit(FILE *fp, const char *str, long n) { char buf[BUFSIZ]; @@ -64,7 +64,7 @@ dropinit(FILE *fp, const char *str, long n) concat(fp, str, stdout, "<stdout>"); } -void +static void taketail(FILE *fp, const char *str, long n) { char **ring; diff --git a/tar.c b/tar.c @@ -61,6 +61,7 @@ usage(void) int main(int argc, char *argv[]) { + struct stat st; char *file = NULL, *dir = ".", *ap; char mode = '\0'; @@ -118,8 +119,6 @@ main(int argc, char *argv[]) usage(); if(file) { - struct stat st; - tarfile = fopen(file, (mode == 'c') ? "wb" : "rb"); if(!tarfile) eprintf("tar: open '%s':", file); @@ -142,13 +141,13 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -void +static void putoctal(char *dst, unsigned num, int n) { snprintf(dst, n, "%.*o", n-1, num); } -int +static int archive(const char* path) { unsigned char b[Blksiz]; @@ -220,7 +219,7 @@ archive(const char* path) return 0; } -int +static int unarchive(char *fname, int l, char b[Blksiz]) { char lname[101]; @@ -279,7 +278,7 @@ unarchive(char *fname, int l, char b[Blksiz]) return 0; } -int +static int print(char * fname, int l, char b[Blksiz]) { puts(fname); @@ -288,14 +287,14 @@ print(char * fname, int l, char b[Blksiz]) return 0; } -void +static void c(const char * path) { archive(path); recurse(path, c); } -void +static void xt(int (*fn)(char*, int, char[Blksiz])) { char b[Blksiz], fname[101]; diff --git a/tee.c b/tee.c @@ -18,7 +18,7 @@ main(int argc, char *argv[]) char buf[BUFSIZ]; int i, nfps = 1; size_t n; - FILE **fps; + FILE **fps = NULL; ARGBEGIN { case 'a': @@ -50,4 +50,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/test.c b/test.c @@ -55,7 +55,7 @@ main(int argc, char *argv[]) return ret ? EXIT_SUCCESS : EXIT_FAILURE; } -bool +static bool unary(const char *op, const char *arg) { struct stat st; @@ -112,7 +112,7 @@ unary(const char *op, const char *arg) return false; /* should not reach */ } -bool +static bool binary(const char *arg1, const char *op, const char *arg2) { int i; @@ -156,4 +156,3 @@ binary(const char *arg1, const char *op, const char *arg2) } return false; } - diff --git a/touch.c b/touch.c @@ -45,7 +45,7 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -void +static void touch(const char *str) { int fd; @@ -69,4 +69,3 @@ touch(const char *str) close(fd); touch(str); } - diff --git a/uname.c b/uname.c @@ -61,4 +61,3 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } - diff --git a/uniq.c b/uniq.c @@ -60,14 +60,14 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } -void +static void uniqline(char *l) { - bool linesequal = ((l == NULL) || (prevline == NULL)) + bool linesequel = ((l == NULL) || (prevline == NULL)) ? l == prevline : !strcmp(l, prevline); - if(linesequal) { + if(linesequel) { ++prevlinecount; return; } @@ -87,7 +87,7 @@ uniqline(char *l) prevlinecount = 1; } -void +static void uniq(FILE *fp, const char *str) { char *buf = NULL; @@ -97,8 +97,8 @@ uniq(FILE *fp, const char *str) uniqline(buf); } -void -uniqfinish() +static void +uniqfinish(void) { uniqline(NULL); } diff --git a/util/cp.c b/util/cp.c @@ -26,9 +26,8 @@ cp(const char *s1, const char *s2) DIR *dp; if (stat(s1, &st) == 0 && S_ISDIR(st.st_mode)) { - if (!cp_rflag) { + if (!cp_rflag) eprintf("%s: is a directory\n", s1); - } if(!(dp = opendir(s1))) eprintf("opendir %s:", s1); diff --git a/util/mode.c b/util/mode.c @@ -7,9 +7,9 @@ mode_t getumask(void) { - mode_t mask = umask(0); - umask(mask); - return mask; + mode_t mask = umask(0); + umask(mask); + return mask; } mode_t diff --git a/yes.c b/yes.c @@ -21,4 +21,3 @@ main(int argc, char *argv[]) puts(argc >= 1 ? argv[0] : "y"); return EXIT_FAILURE; /* should not reach */ } -