* IN THE SOFTWARE.
*/
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
}
}
- 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) {
}
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))
if(docount)
printf("%d\n", count);
-
return 0;
}