diff options
Diffstat (limited to '')
-rw-r--r-- | src/input/file_input_plugin.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/input/file_input_plugin.c b/src/input/file_input_plugin.c index c8a5053f8..6dc815df9 100644 --- a/src/input/file_input_plugin.c +++ b/src/input/file_input_plugin.c @@ -35,12 +35,23 @@ input_file_open(struct input_stream *is, const char *filename) int fd, ret; struct stat st; + char* pathname = g_strdup(filename); + if (filename[0] != '/') + { + g_free(pathname); return false; + } - fd = open(filename, O_RDONLY); + if (stat(filename, &st) < 0) { + char* slash = strrchr(pathname, '/'); + *slash = '\0'; + } + + fd = open(pathname, O_RDONLY); if (fd < 0) { is->error = errno; + g_free(pathname); return false; } @@ -50,13 +61,15 @@ input_file_open(struct input_stream *is, const char *filename) if (ret < 0) { is->error = errno; close(fd); + g_free(pathname); return false; } if (!S_ISREG(st.st_mode)) { - g_debug("Not a regular file: %s\n", filename); + g_debug("Not a regular file: %s", pathname); is->error = EINVAL; close(fd); + g_free(pathname); return false; } @@ -70,6 +83,8 @@ input_file_open(struct input_stream *is, const char *filename) is->data = GINT_TO_POINTER(fd); is->ready = true; + g_free(pathname); + return true; } |