[hackers] [sbase] Minor cleanup for pathchk(1) || sin

From: <git_AT_suckless.org>
Date: Thu, 11 Feb 2016 11:02:03 +0100 (CET)

commit efabd56535a00456434b909ce5709866a910a28c
Author: sin <sin_AT_2f30.org>
AuthorDate: Thu Feb 11 10:00:00 2016 +0000
Commit: sin <sin_AT_2f30.org>
CommitDate: Thu Feb 11 10:01:58 2016 +0000

    Minor cleanup for pathchk(1)

diff --git a/pathchk.c b/pathchk.c
index 780490c..6bf4d11 100644
--- a/pathchk.c
+++ b/pathchk.c
_AT_@ -8,28 +8,13 @@
 #include <sys/stat.h>
 
 #include "util.h"
-#include "arg.h"
 
 #define PORTABLE_CHARACTER_SET "0123456789._-qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
 /* If your system supports more other characters, but not all non-NUL characters, define SYSTEM_CHARACTER_SET. */
 
-#ifndef PATH_MAX
-# define PATH_MAX SIZE_MAX
-#endif
-#ifndef NAME_MAX
-# define NAME_MAX SIZE_MAX
-#endif
-
 static int most = 0;
 static int extra = 0;
 
-static void
-usage(void)
-{
- fprintf(stderr, "usage: %s [-pP] filename...\n", argv0);
- exit(1);
-}
-
 static int
 pathchk(char *filename)
 {
_AT_@ -40,13 +25,13 @@ pathchk(char *filename)
 
         /* Empty? */
         if (extra && !*filename) {
- fprintf(stderr, "%s: empty filename\n", argv0);
+ weprintf("%s: empty filename\n", argv0);
                 return 1;
         }
 
         /* Leading hyphen? */
         if (extra && ((*filename == '-') || strstr(filename, "/-"))) {
- fprintf(stderr, "%s: %s: leading '-' in component of filename\n", argv0, filename);
+ weprintf("%s: %s: leading '-' in component of filename\n", argv0, filename);
                 return 1;
         }
 
_AT_@ -60,9 +45,9 @@ pathchk(char *filename)
                 character_set = "/"PORTABLE_CHARACTER_SET;
         if (character_set && *(invalid = filename + strspn(filename, character_set))) {
                 for (invalid_end = invalid + 1; *invalid_end & 0x80; invalid_end++);
- fprintf(stderr, "%s: %s: ", argv0, filename);
+ weprintf("%s: %s: ", argv0, filename);
                 *invalid_end = 0;
- fprintf(stderr, "nonportable character '%s'\n", invalid);
+ weprintf("nonportable character '%s'\n", invalid);
                 return 1;
         }
 
_AT_@ -70,15 +55,15 @@ pathchk(char *filename)
         if (lstat(filename, &_attr) && errno != ENOENT) {
                 /* lstat rather than stat, so that if filename is a bad symlink, but
                  * all parents are OK, no error will be detected. */
- fprintf(stderr, "%s: %s: %s\n", argv0, filename, strerror(errno));
+ weprintf("%s: %s:", argv0, filename);
                 return 1;
         }
 
         /* Too long pathname? */
         maxlen = most ? _POSIX_PATH_MAX : PATH_MAX;
         if (strlen(filename) >= maxlen) {
- fprintf(stderr, "%s: %s: is longer than %zu bytes\n",
- argv0, filename, maxlen);
+ weprintf("%s: %s: is longer than %zu bytes\n",
+ argv0, filename, maxlen);
                 return 1;
         }
 
_AT_@ -88,8 +73,8 @@ pathchk(char *filename)
                 q = strchr(p, '/');
                 len = q ? (size_t)(q++ - p) : strlen(p);
                 if (len > maxlen) {
- fprintf(stderr, "%s: %s: includes component longer than %zu bytes\n",
- argv0, filename, maxlen);
+ weprintf("%s: %s: includes component longer than %zu bytes\n",
+ argv0, filename, maxlen);
                         return 1;
                 }
         }
_AT_@ -97,6 +82,12 @@ pathchk(char *filename)
         return 0;
 }
 
+static void
+usage(void)
+{
+ eprintf("usage: %s [-pP] filename...\n", argv0);
+}
+
 int
 main(int argc, char *argv[])
 {
Received on Thu Feb 11 2016 - 11:02:03 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 11 2016 - 11:12:26 CET