From b4df6f859a2c0804069a7c2fe26656d982828b1a Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 26 Dec 2024 11:44:15 +0100 Subject: file: rename syscall wrappers --- src/ci.c | 4 ++-- src/cmd_line.c | 2 +- src/file.c | 4 ++-- src/file.h | 8 ++++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/ci.c b/src/ci.c index 0e40548..cdb2f21 100644 --- a/src/ci.c +++ b/src/ci.c @@ -86,7 +86,7 @@ int ci_run_git_repo(const char *url, const char *rev, struct proc_output *output if (ret < 0) goto exit; - ret = my_chdir(git_repository_workdir(repo), &oldpwd); + ret = chdir_wrapper(git_repository_workdir(repo), &oldpwd); if (ret < 0) goto free_repo; @@ -95,7 +95,7 @@ int ci_run_git_repo(const char *url, const char *rev, struct proc_output *output goto oldpwd; oldpwd: - my_chdir(oldpwd, NULL); + chdir_wrapper(oldpwd, NULL); free(oldpwd); free_repo: diff --git a/src/cmd_line.c b/src/cmd_line.c index 35b27a7..bf3aa24 100644 --- a/src/cmd_line.c +++ b/src/cmd_line.c @@ -16,7 +16,7 @@ static char *get_current_binary_path(void) { - return my_readlink("/proc/self/exe"); + return readlink_wrapper("/proc/self/exe"); } static char *get_current_binary_name(void) diff --git a/src/file.c b/src/file.c index a0a8f8a..90ee905 100644 --- a/src/file.c +++ b/src/file.c @@ -36,7 +36,7 @@ int rm_rf(const char *dir) return nftw(dir, unlink_cb, 64, FTW_DEPTH | FTW_PHYS); } -int my_chdir(const char *dir, char **old) +int chdir_wrapper(const char *dir, char **old) { int ret = 0; @@ -63,7 +63,7 @@ free_old: return ret; } -char *my_readlink(const char *path) +char *readlink_wrapper(const char *path) { size_t current_size = 256; char *buf = NULL; diff --git a/src/file.h b/src/file.h index 54bb5fb..9c228a4 100644 --- a/src/file.h +++ b/src/file.h @@ -12,8 +12,12 @@ int rm_rf(const char *dir); -int my_chdir(const char *dir, char **old); -char *my_readlink(const char *path); +/* This chdir(2) wrapper optionally saves the previous working directory in the + * `old` pointer, allowing the user to switch back to it if necessary. */ +int chdir_wrapper(const char *dir, char **old); + +/* This readlink(2) wrapper allocates enough memory dynamically. */ +char *readlink_wrapper(const char *path); int file_dup(int fd); void file_close(int fd); -- cgit v1.2.3