]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
fd: Remove file_exists().
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 25 Sep 2022 18:45:40 +0000 (20:45 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 26 Mar 2023 14:30:56 +0000 (16:30 +0200)
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".

client_common.c
fd.c
fd.h

index 2a6b47d6b2b095daadf05659eafd52abfb218b35..642852ec6b8751454538ac9f3a021970f5cfbdef 100644 (file)
@@ -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 d0de66f41be6008c2d3be5afe6dae002fb06ceb5..112f1835d3e228b9ce9ef9b1c515a067752017ae 100644 (file)
--- 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 270d0ce200df30f16333fcfbdb47173500cacddc..64850652ade120499759d4bf65a8b27169f32813 100644 (file)
--- 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);