Skip to content

Commit 167730f

Browse files
committed
Applied early exit on is_writable_path().
1 parent 4c4e3b7 commit 167730f

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/options.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,8 @@ read_option_args (int argc, char **argv) {
833833
case 'o':
834834
if (!valid_output_type (optarg))
835835
FATAL ("Invalid filename extension. It must be any of .csv, .json, or .html\n");
836-
if (!is_writable_path(optarg))
837-
FATAL("Invalid or unwritable path.");
836+
if (!is_writable_path (optarg))
837+
FATAL ("Invalid or unwritable path.");
838838
if (conf.output_format_idx < MAX_OUTFORMATS)
839839
conf.output_formats[conf.output_format_idx++] = optarg;
840840
break;

src/util.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,22 +1225,22 @@ unescape_str (const char *src) {
12251225

12261226
int
12271227
is_writable_path (const char *path) {
1228-
if (access (path, W_OK) == 0) {
1229-
return 1; // Path is writable
1230-
} else {
1231-
switch (errno) {
1232-
case ENOENT:
1233-
fprintf (stderr, "Path does not exist: %s\n", path);
1234-
return 0;
1235-
case EACCES:
1236-
fprintf (stderr, "No write permission for path: %s\n", path);
1237-
return 0;
1238-
case EROFS:
1239-
fprintf (stderr, "Path is on a read-only file system: %s\n", path);
1240-
return 0;
1241-
default:
1242-
fprintf (stderr, "Unknown error (errno %d) for path: %s\n", errno, path);
1243-
return 0;
1244-
}
1228+
/* Path is writable */
1229+
if (access (path, W_OK) == 0)
1230+
return 1;
1231+
1232+
switch (errno) {
1233+
case ENOENT:
1234+
fprintf (stderr, "Path does not exist: %s\n", path);
1235+
return 0;
1236+
case EACCES:
1237+
fprintf (stderr, "No write permission for path: %s\n", path);
1238+
return 0;
1239+
case EROFS:
1240+
fprintf (stderr, "Path is on a read-only file system: %s\n", path);
1241+
return 0;
1242+
default:
1243+
fprintf (stderr, "Unknown error (errno %d) for path: %s\n", errno, path);
1244+
return 0;
12451245
}
12461246
}

0 commit comments

Comments
 (0)