aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;