OSDN Git Service

Check if file is accessible before trying to open.
authorLoRd_MuldeR <mulder2@gmx.de>
Sun, 21 Jan 2018 18:06:23 +0000 (19:06 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Sun, 21 Jan 2018 18:06:23 +0000 (19:06 +0100)
src/main++.cpp
src/main.c
src/utilities.h

index baf905e..ee02305 100644 (file)
@@ -47,7 +47,7 @@ static int process_file(const int multi_file, const param_t *const param, uint64
        if (file_name && (!is_file_readable(file_name)))
        {
                print_logo();
-               FPRINTF(stderr, T("Input file is not accessible:\n%s\n\n%s\n\n"), file_name ? file_name : T("<STDIN>"), STRERROR(errno));
+               FPRINTF(stderr, T("Given input file is not readable:\n%s\n\n%s\n\n"), file_name ? file_name : T("<STDIN>"), STRERROR(errno));
                return 0;
        }
 
index 062471a..6e946fb 100644 (file)
@@ -48,7 +48,7 @@ static int process_file(const int multi_file, const param_t *const param, uint64
        if (file_name && (!is_file_readable(file_name)))
        {
                print_logo();
-               FPRINTF(stderr, T("Input file is not accessible:\n%s\n\n%s\n\n"), file_name ? file_name : T("<STDIN>"), STRERROR(errno));
+               FPRINTF(stderr, T("Given input file is not readable:\n%s\n\n%s\n\n"), file_name ? file_name : T("<STDIN>"), STRERROR(errno));
                return 0;
        }
 
index c97467a..9df8154 100644 (file)
@@ -235,23 +235,16 @@ static int parse_arguments(param_t *const param, int argc, CHAR *argv[])
 static int is_file_readable(const CHAR *const filename)
 {
        struct stat64 info;
-       if (ACCESS(filename, R_OK))
-       {
-               return 0;
-       }
        if (!STAT64(filename, &info))
        {
                if ((info.st_mode & S_IFMT) == S_IFDIR)
                {
+                       FPUTS(T("IFMT == S_IFDIR"), stderr);
                        errno = EISDIR;
                        return 0;
                }
        }
-       else
-       {
-               errno = 0; /*ignore error here*/
-       }
-       return 1;
+       return (!ACCESS(filename, R_OK));
 }
 
 /*file size*/