Type and naming cleanup

Do not use Hi prefic for things that shouldn't be visible to outside code
This commit is contained in:
2025-05-02 00:15:51 +03:00
parent 3baa45c32e
commit 5539596929
21 changed files with 263 additions and 242 deletions

View File

@@ -46,7 +46,7 @@ static inline struct WatchMaskParams inode_watch_masks_create(u32 flags) {
.parent_mask = parent_mask};
}
static void file_watch_destroy(int fd, hiFileWatch *fw) {
static void file_watch_destroy(int fd, FileWatch *fw) {
inotify_rm_watch(fd, fw->wd);
free((void *)fw->path);
@@ -54,20 +54,20 @@ static void file_watch_destroy(int fd, hiFileWatch *fw) {
fw->path = NULL;
}
void file_watch_destroy_watches(struct hiFileWatcherContext *ctx) {
void file_watch_destroy_watches(FileWatcherContext *ctx) {
for (size_t i = 0; i < sc_array_size(&ctx->watches); i++) {
hiFileWatch *fw = &sc_array_at(&ctx->watches, i);
FileWatch *fw = &sc_array_at(&ctx->watches, i);
file_watch_destroy(ctx->fd, fw);
}
sc_array_term(&ctx->watches);
}
hiFileWatch *file_watch_find_by_wd(struct hiFileWatcherContext *ctx, int wd,
FileWatch *file_watch_find_by_wd(FileWatcherContext *ctx, int wd,
size_t *index) {
struct sc_array_fwatch *watches = &ctx->watches;
for (size_t i = 0; i < sc_array_size(watches); ++i) {
hiFileWatch *fw = &sc_array_at(watches, i);
FileWatch *fw = &sc_array_at(watches, i);
if (fw->wd == wd) {
if (index) {
*index = i;
@@ -78,10 +78,10 @@ hiFileWatch *file_watch_find_by_wd(struct hiFileWatcherContext *ctx, int wd,
return NULL;
}
hiFileWatch *file_watch_find_by_path(struct hiFileWatcherContext *ctx,
FileWatch *file_watch_find_by_path(FileWatcherContext *ctx,
const char *path, size_t *index) {
for (size_t i = 0; i < sc_array_size(&ctx->watches); i++) {
hiFileWatch *watch = &sc_array_at(&ctx->watches, i);
FileWatch *watch = &sc_array_at(&ctx->watches, i);
if (strcmp(watch->path, path) == 0) {
if (index) {
*index = i;
@@ -110,22 +110,22 @@ static char *get_parent_folder(const char path[static 1]) {
return parent;
}
HiloadResult file_watch_add(hiFileWatcherContext *ctx, u32 mask,
HiResult file_watch_add(FileWatcherContext *ctx, u32 mask,
const char *path) {
if (!ctx || ctx->fd == -1) {
sc_log_error("Invalid inotify context\n");
return HILOAD_FAIL;
log_error("Invalid inotify context\n");
return HI_FAIL;
}
struct WatchMaskParams params = inode_watch_masks_create(mask);
hiFileWatch *watch = file_watch_find_by_path(ctx, path, NULL);
FileWatch *watch = file_watch_find_by_path(ctx, path, NULL);
if (!watch) {
int wd = inotify_add_watch(ctx->fd, path, params.file_mask);
if (wd == -1) {
sc_log_error("Couldn't watch: %s: %s\n", path, strerror(errno));
return HILOAD_FAIL;
log_error("Couldn't watch: %s: %s\n", path, strerror(errno));
return HI_FAIL;
}
hiFileWatch wp = {.wd = wd, .mask = mask, .path = strdup(path)};
FileWatch wp = {.wd = wd, .mask = mask, .path = strdup(path)};
sc_array_add(&ctx->watches, wp);
watch = &sc_array_last(&ctx->watches);
} else {
@@ -134,11 +134,11 @@ HiloadResult file_watch_add(hiFileWatcherContext *ctx, u32 mask,
if (!has_mask(HI_FILE_PARENT, mask)) {
char *parent_name = get_parent_folder(path);
hiFileWatch *parent_watch = file_watch_find_by_path(ctx, parent_name, NULL);
FileWatch *parent_watch = file_watch_find_by_path(ctx, parent_name, NULL);
if (!parent_watch) {
// parent not yet watched
int wd = inotify_add_watch(ctx->fd, parent_name, params.parent_mask);
hiFileWatch wp = {.wd = wd, .mask = HI_FILE_PARENT, .path = parent_name};
FileWatch wp = {.wd = wd, .mask = HI_FILE_PARENT, .path = parent_name};
sc_array_init(&wp.files);
sc_array_add(&wp.files, strdup(watch->path));
sc_array_add(&ctx->watches, wp);
@@ -163,19 +163,19 @@ HiloadResult file_watch_add(hiFileWatcherContext *ctx, u32 mask,
}
}
return HILOAD_OK;
return HI_OK;
}
HiloadResult file_watch_remove(hiFileWatcherContext *ctx, const char *path) {
HiResult file_watch_remove(FileWatcherContext *ctx, const char *path) {
size_t i = 0;
hiFileWatch *watch = file_watch_find_by_path(ctx, path, &i);
FileWatch *watch = file_watch_find_by_path(ctx, path, &i);
if (watch) {
// destroy parent reference. We assume it will only have one.
// Destroy parent reference. We assume it will only have one.
char *parent = get_parent_folder(path);
if (parent) {
hiFileWatch *pw = file_watch_find_by_path(ctx, parent, NULL);
FileWatch *pw = file_watch_find_by_path(ctx, parent, NULL);
if (pw) {
for (size_t i = 0; i < sc_array_size(&pw->files); i++) {
const char *fn = sc_array_at(&pw->files, i);
@@ -189,7 +189,7 @@ HiloadResult file_watch_remove(hiFileWatcherContext *ctx, const char *path) {
}
file_watch_destroy(ctx->fd, watch);
sc_array_del(&ctx->watches, i);
return HILOAD_OK;
return HI_OK;
}
return HILOAD_FAIL;
return HI_FAIL;
}