From: Andre Noll Date: Sun, 25 Sep 2022 18:45:40 +0000 (+0200) Subject: fd: Remove file_exists(). X-Git-Tag: v0.7.3~13^2~6 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=a25f6bb7169f0ea86522a0c613a8ec1dad358103;p=paraslash.git fd: Remove file_exists(). Open-coding this function actually improves code readability. The function name was a misnomer anyway because any error from the stat() call (such as EACCES) was reported as "file does not exist". --- diff --git a/client_common.c b/client_common.c index 2a6b47d6..642852ec 100644 --- a/client_common.c +++ b/client_common.c @@ -578,8 +578,9 @@ int client_parse_config(int argc, char *argv[], struct client_task **ct_ptr, if (CLIENT_OPT_GIVEN(KEY_FILE, lpr)) kf = para_strdup(CLIENT_OPT_STRING_VAL(KEY_FILE, lpr)); else { + struct stat statbuf; kf = make_message("%s/.paraslash/key.%s", home, user); - if (!file_exists(kf)) { + if (stat(kf, &statbuf) != 0) { /* assume file does not exist */ free(kf); kf = make_message("%s/.ssh/id_rsa", home); } diff --git a/fd.c b/fd.c index d0de66f4..112f1835 100644 --- a/fd.c +++ b/fd.c @@ -304,20 +304,6 @@ out: return ret; } -/** - * Check whether a file exists. - * - * \param fn The file name. - * - * \return True iff file exists. - */ -bool file_exists(const char *fn) -{ - struct stat statbuf; - - return !stat(fn, &statbuf); -} - /** * Set a file descriptor to blocking mode. * diff --git a/fd.h b/fd.h index 270d0ce2..64850652 100644 --- a/fd.h +++ b/fd.h @@ -5,7 +5,6 @@ int xrename(const char *oldpath, const char *newpath); int write_all(int fd, const char *buf, size_t len); __printf_2_3 int write_va_buffer(int fd, const char *fmt, ...); -bool file_exists(const char *); int xpoll(struct pollfd *fds, nfds_t nfds, int timeout); __must_check int mark_fd_nonblocking(int fd); __must_check int mark_fd_blocking(int fd);