diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-04-06 17:17:41 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-04-06 17:17:41 +0200 |
commit | dd0c92b8abbab708f419f1cb39ff3bb9926039cb (patch) | |
tree | 00e55f06fc08688b936a9745fdcf3e2bf2dfe607 | |
parent | 309996daa538127610af25926a0973d5558c1dff (diff) |
Handle case when path is not symlinked in resolving path
-rw-r--r-- | main.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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; |