]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj-list: use err(3) when possible
authorBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 21 Oct 2021 14:04:29 +0000 (16:04 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 21 Oct 2021 14:04:29 +0000 (16:04 +0200)
src/mlmmj-list.c

index de7db5485f0cfc920b6b3fbf483cdd70689cba12..24e50b1497607c65f8be46f664a1a69de2a1c622 100644 (file)
@@ -21,6 +21,7 @@
  * IN THE SOFTWARE.
  */
 
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -137,15 +138,11 @@ int main(int argc, char **argv)
                }
        }
 
-       if(listdir == NULL) {
-               fprintf(stderr, "You have to specify -L\n"
-                               "%s -h for help\n", argv[0]);
-               exit(EXIT_FAILURE);
-       }
+       if (listdir == NULL)
+               errx(EXIT_FAILURE, "You have to specify -L");
        listfd = open(listdir, O_DIRECTORY);
        if (listfd == -1) {
-               fprintf(stderr, "Unable to open '%s' directory\n", listdir);
-               exit(EXIT_FAILURE);
+               err(EXIT_FAILURE, "Unable to open '%s' directory", listdir);
        }
 
        switch(typesub) {
@@ -165,20 +162,16 @@ int main(int argc, char **argv)
        }
 
        if(subdir) {
-               if ((dirfd = openat(listfd, subdir, O_DIRECTORY)) == -1) {
-                       fprintf(stderr, "Count not open(%s/%s);\n", listdir,
+               if ((dirfd = openat(listfd, subdir, O_DIRECTORY)) == -1)
+                       err(EXIT_FAILURE, "Count not open(%s/%s);\n", listdir,
                            subdir);
-                       exit(EXIT_FAILURE);
-               }
        }
 
        if (dirfd != -1) {
                dirp = fdopendir(dirfd);
-               if(dirp == NULL) {
-                       fprintf(stderr, "Could not opendir(%s/%s);\n", listdir,
+               if(dirp == NULL)
+                       err(EXIT_FAILURE, "Could not opendir(%s/%s);\n", listdir,
                            subdir);
-                       exit(EXIT_FAILURE);
-               }
                while((dp = readdir(dirp)) != NULL) {
                        if((strcmp(dp->d_name, "..") == 0) ||
                                        (strcmp(dp->d_name, ".") == 0))
@@ -196,6 +189,5 @@ int main(int argc, char **argv)
        if(docount)
                printf("%d\n", count);
 
-
        return 0;
 }