[hackers] [sbase] Style inquistion for util and some tools. || Christoph Lohmann

From: <git_AT_suckless.org>
Date: Tue, 05 Mar 2013 21:49:12 +0100

commit f8dc6883a313911170c759bf0d1240c8a0ac2fb5
Author: Christoph Lohmann <20h_AT_r-36.net>
Date: Tue Mar 5 21:46:48 2013 +0100

    Style inquistion for util and some tools.

diff --git a/cat.c b/cat.c
index a07edf1..48b84c8 100644
--- a/cat.c
+++ b/cat.c
_AT_@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+
 #include "text.h"
 #include "util.h"
 
_AT_@ -16,13 +17,15 @@ main(int argc, char *argv[])
                 eprintf("usage: %s [files...]
", argv0);
         } ARGEND;
 
- if(argc == 0)
+ if(argc == 0) {
                 concat(stdin, "<stdin>", stdout, "<stdout>");
- else for(i = 0; i < argc; i++) {
+ } else for(i = 0; i < argc; i++) {
                 if(!(fp = fopen(argv[i], "r")))
                         eprintf("fopen %s:", argv[i]);
+
                 concat(fp, argv[i], stdout, "<stdout>");
                 fclose(fp);
         }
- return EXIT_SUCCESS;
+
+ return 0;
 }
diff --git a/config.mk b/config.mk
index 6ce5cb7..5054e8d 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -8,7 +8,7 @@ MANPREFIX = $(PREFIX)/share/man
 #CC = gcc
 #CC = musl-gcc
 LD = $(CC)
-CPPFLAGS = -D_POSIX_C_SOURCE=200112L
+CPPFLAGS = -D_BSD_SOURCE -D_GNU_SOURCE
 CFLAGS = -g -ansi -Wall -pedantic $(CPPFLAGS)
 LDFLAGS = -g
 
diff --git a/util/afgets.c b/util/afgets.c
index cad05b8..e1d719d 100644
--- a/util/afgets.c
+++ b/util/afgets.c
_AT_@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "../text.h"
 #include "../util.h"
 
_AT_@ -15,10 +16,12 @@ afgets(char **p, size_t *size, FILE *fp)
                 len += (n = strlen(buf));
                 if(len+1 > *size && !(*p = realloc(*p, len+1)))
                         eprintf("realloc:");
+
                 strcpy(&(*p)[len-n], buf);
 
                 if(buf[n-1] == '
' || feof(fp))
                         break;
         }
+
         return (len > 0) ? *p : NULL;
 }
diff --git a/util/agetcwd.c b/util/agetcwd.c
index 4d34e94..a672bcf 100644
--- a/util/agetcwd.c
+++ b/util/agetcwd.c
_AT_@ -1,5 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 #include <unistd.h>
+
 #include "../util.h"
 
 char *
_AT_@ -11,5 +12,7 @@ agetcwd(void)
         apathmax(&buf, &size);
         if(!getcwd(buf, size))
                 eprintf("getcwd:");
+
         return buf;
 }
+
diff --git a/util/apathmax.c b/util/apathmax.c
index f2b4e4a..4e1b71e 100644
--- a/util/apathmax.c
+++ b/util/apathmax.c
_AT_@ -3,18 +3,23 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+
 #include "../util.h"
 
 void
 apathmax(char **p, long *size)
 {
         errno = 0;
+
         if((*size = pathconf(".", _PC_PATH_MAX)) == -1) {
- if(errno == 0)
+ if(errno == 0) {
                         *size = BUFSIZ;
- else
+ } else {
                         eprintf("pathconf:");
+ }
         }
+
         if(!(*p = malloc(*size)))
                 eprintf("malloc:");
 }
+
diff --git a/util/concat.c b/util/concat.c
index 6dd923a..f172903 100644
--- a/util/concat.c
+++ b/util/concat.c
_AT_@ -1,5 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 #include <stdio.h>
+
 #include "../text.h"
 #include "../util.h"
 
_AT_@ -9,9 +10,12 @@ concat(FILE *fp1, const char *s1, FILE *fp2, const char *s2)
         char buf[BUFSIZ];
         size_t n;
 
- while((n = fread(buf, 1, sizeof buf, fp1)) > 0)
+ while((n = fread(buf, 1, sizeof buf, fp1)) > 0) {
                 if(fwrite(buf, 1, n, fp2) != n)
                         eprintf("%s: write error:", s2);
+ }
+
         if(ferror(fp1))
                 eprintf("%s: read error:", s1);
 }
+
diff --git a/util/cp.c b/util/cp.c
index 3d4eff8..416985d 100644
--- a/util/cp.c
+++ b/util/cp.c
_AT_@ -7,6 +7,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/stat.h>
+
 #include "../fs.h"
 #include "../text.h"
 #include "../util.h"
_AT_@ -26,22 +27,32 @@ cp(const char *s1, const char *s2)
         if (stat(s1, &st) == 0 && S_ISDIR(st.st_mode)) {
                 if (!cp_rflag) {
                         eprintf("%s: is a directory
", s1);
- }
- else {
+ } else {
                         if(!(dp = opendir(s1)))
                                 eprintf("opendir %s:", s1);
+
                         if (mkdir(s2, st.st_mode) == -1 && errno != EEXIST)
                                 eprintf("mkdir %s:", s2);
+
                         apathmax(&ns1, &size1);
                         apathmax(&ns2, &size2);
- while((d = readdir(dp)))
- if(strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) {
- if(snprintf(ns1, size1, "%s/%s", s1, d->d_name) > size1)
- eprintf("%s/%s: filename too long
", s1, d->d_name);
- if(snprintf(ns2, size2, "%s/%s", s2, d->d_name) > size2)
- eprintf("%s/%s: filename too long
", s2, d->d_name);
+ while((d = readdir(dp))) {
+ if(strcmp(d->d_name, ".")
+ && strcmp(d->d_name, "..")) {
+ if(snprintf(ns1, size1, "%s/%s", s1,
+ d->d_name) > size1) {
+ eprintf("%s/%s: filename too long
",
+ s1, d->d_name);
+ }
+
+ if(snprintf(ns2, size2, "%s/%s", s2,
+ d->d_name) > size2) {
+ eprintf("%s/%s: filename too long
",
+ s2, d->d_name);
+ }
                                         fnck(ns1, ns2, cp);
                                 }
+ }
                         closedir(dp);
                         free(ns1);
                         free(ns2);
_AT_@ -50,10 +61,14 @@ cp(const char *s1, const char *s2)
         }
         if(!(f1 = fopen(s1, "r")))
                 eprintf("fopen %s:", s1);
+
         if(!(f2 = fopen(s2, "w")))
                 eprintf("fopen %s:", s2);
+
         concat(f1, s1, f2, s2);
         fclose(f2);
         fclose(f1);
+
         return 0;
 }
+
diff --git a/util/enmasse.c b/util/enmasse.c
index 5099368..acf9ba6 100644
--- a/util/enmasse.c
+++ b/util/enmasse.c
_AT_@ -5,6 +5,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/stat.h>
+
 #include "../util.h"
 
 void
_AT_@ -17,16 +18,20 @@ enmasse(int argc, char **argv, int (*fn)(const char *, const char *))
 
         if(argc == 2 && !(stat(argv[1], &st) == 0 && S_ISDIR(st.st_mode))) {
                 fnck(argv[0], argv[1], fn);
+
                 return;
- }
- else
+ } else {
                 dir = (argc == 1) ? "." : argv[--argc];
+ }
 
         apathmax(&buf, &size);
         for(i = 0; i < argc; i++) {
- if(snprintf(buf, size, "%s/%s", dir, basename(argv[i])) > size)
- eprintf("%s/%s: filename too long
", dir, basename(argv[i]));
+ if(snprintf(buf, size, "%s/%s", dir, basename(argv[i])) > size) {
+ eprintf("%s/%s: filename too long
", dir,
+ basename(argv[i]));
+ }
                 fnck(argv[i], buf, fn);
         }
         free(buf);
 }
+
diff --git a/util/eprintf.c b/util/eprintf.c
index fc651d7..a21fe42 100644
--- a/util/eprintf.c
+++ b/util/eprintf.c
_AT_@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "../util.h"
 
 char *argv0;
_AT_@ -40,5 +41,7 @@ venprintf(int status, const char *fmt, va_list ap)
                 fputc(' ', stderr);
                 perror(NULL);
         }
+
         exit(status);
 }
+
diff --git a/util/estrtol.c b/util/estrtol.c
index 431b40c..d481445 100644
--- a/util/estrtol.c
+++ b/util/estrtol.c
_AT_@ -2,6 +2,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+
 #include "../util.h"
 
 long
_AT_@ -9,14 +10,17 @@ estrtol(const char *s, int base)
 {
         char *end;
         long n;
-
+
         errno = 0;
         n = strtol(s, &end, base);
         if(*end != '
Received on Tue Mar 05 2013 - 21:49:12 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 05 2013 - 22:00:08 CET