From 15f6e433432a6ba8e021c74b0f28ecd545721d42 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 25 Sep 2022 20:57:16 +0200 Subject: [PATCH] fd: Open-code para_chdir(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Another public trivial wrapper that can go away because it has only a single caller. POSIX says Upon successful completion, 0 shall be returned. Otherwise, −1 shall be returned, the current working directory shall remain unchanged, and errno shall be set to indicate the error. So the new check against zero is equivalent to the old code which checked whether the return value is non-negative. --- fd.c | 21 +++------------------ fd.h | 1 - 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/fd.c b/fd.c index 112f1835..cc38f1af 100644 --- a/fd.c +++ b/fd.c @@ -392,22 +392,6 @@ int para_open(const char *path, int flags, mode_t mode) return -ERRNO_TO_PARA_ERROR(errno); } -/** - * Wrapper for chdir(2). - * - * \param path The specified directory. - * - * \return Standard. - */ -int para_chdir(const char *path) -{ - int ret = chdir(path); - - if (ret >= 0) - return 1; - return -ERRNO_TO_PARA_ERROR(errno); -} - /** * Save the cwd and open a given directory. * @@ -443,9 +427,10 @@ static int para_opendir(const char *dirname, DIR **dir, int *cwd) return ret; *cwd = ret; } - ret = para_chdir(dirname); - if (ret < 0) + if (chdir(dirname) != 0) { + ret = -ERRNO_TO_PARA_ERROR(errno); goto close_cwd; + } *dir = opendir("."); if (*dir) return 1; diff --git a/fd.h b/fd.h index 64850652..9f11dc85 100644 --- a/fd.h +++ b/fd.h @@ -11,7 +11,6 @@ __must_check int mark_fd_blocking(int fd); int para_mmap(size_t length, int prot, int flags, int fd, void *map); int para_open(const char *path, int flags, mode_t mode); int para_mkdir(const char *path, mode_t mode); -int para_chdir(const char *path); int mmap_full_file(const char *filename, int open_mode, void **map, size_t *size, int *fd_ptr); int para_munmap(void *start, size_t length); -- 2.39.2