aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-04-06 17:17:41 +0200
committerdec05eba <dec05eba@protonmail.com>2024-04-06 17:17:41 +0200
commitdd0c92b8abbab708f419f1cb39ff3bb9926039cb (patch)
tree00e55f06fc08688b936a9745fdcf3e2bf2dfe607
parent309996daa538127610af25926a0973d5558c1dff (diff)
Handle case when path is not symlinked in resolving path
-rw-r--r--main.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/main.c b/main.c
index 4113c98..9dd0eec 100644
--- a/main.c
+++ b/main.c
@@ -12,10 +12,13 @@
static int readlink_realpath(const char *filepath, char *buffer) {
char symlinked_path[PATH_MAX];
ssize_t bytes_written = readlink(filepath, symlinked_path, sizeof(symlinked_path) - 1);
- if(bytes_written == -1)
- return 0;
+ if(bytes_written == -1 && errno == EINVAL) {
+ /* Not a symlink */
+ strncpy(symlinked_path, filepath, sizeof(symlinked_path));
+ } else {
+ symlinked_path[bytes_written] = '\0';
+ }
- symlinked_path[bytes_written] = '\0';
if(!realpath(symlinked_path, buffer))
return 0;