aboutsummaryrefslogtreecommitdiff
path: root/src/hotload.c
diff options
context:
space:
mode:
authorkoekeishiya <aasvi93@hotmail.com>2017-12-12 14:42:09 +0100
committerkoekeishiya <aasvi93@hotmail.com>2017-12-12 14:42:09 +0100
commit925320065202f6a4b234171ba6b3311e811f72d3 (patch)
treeab8b0ba475abc810e4b66728411d27a46c309b62 /src/hotload.c
parent518927fbde35947a163c7a4800b298e16c50867e (diff)
downloadskhd-925320065202f6a4b234171ba6b3311e811f72d3.tar.gz
skhd-925320065202f6a4b234171ba6b3311e811f72d3.zip
#19 - cleanup code for resolving symlinks
Diffstat (limited to 'src/hotload.c')
-rw-r--r--src/hotload.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/hotload.c b/src/hotload.c
index 28d7e72..ad02d21 100644
--- a/src/hotload.c
+++ b/src/hotload.c
@@ -41,17 +41,16 @@ file_name(const char *file)
return name;
}
-internal bool
-resolve_symlink(char *file, char **real_path)
+internal char *
+resolve_symlink(char *file)
{
struct stat buffer;
if (lstat(file, &buffer) != 0) {
- return false;
+ return NULL;
}
if (!S_ISLNK(buffer.st_mode)) {
- *real_path = file;
- return true;
+ return file;
}
ssize_t size = buffer.st_size + 1;
@@ -60,12 +59,11 @@ resolve_symlink(char *file, char **real_path)
if (read != -1) {
result[read] = '\0';
- *real_path = result;
- return true;
+ return result;
}
free(result);
- return false;
+ return NULL;
}
internal struct watched_file *
@@ -109,16 +107,13 @@ internal FSEVENT_CALLBACK(hotloader_handler)
void hotloader_add_file(struct hotloader *hotloader, char *file)
{
if (!hotloader->enabled) {
- char *real_path;
- bool success = resolve_symlink(file, &real_path);
-
- if (success) {
+ char *real_path = resolve_symlink(file);
+ if (real_path) {
struct watched_file watch_info;
watch_info.directory = file_directory(real_path);
watch_info.filename = file_name(real_path);
if (real_path != file) {
- printf("hotload: symlink resolved, '%s' -> '%s'\n", file, real_path);
free(real_path);
}