]> git.mdlowis.com Git - proto/labwc.git/commitdiff
common/file-helpers.c: share file_exists() to reduce duplication
authorJohan Malm <jgm323@gmail.com>
Mon, 21 Aug 2023 20:07:28 +0000 (21:07 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 17 Sep 2023 18:26:41 +0000 (19:26 +0100)
include/common/file-helpers.h [new file with mode: 0644]
src/button/button-png.c
src/common/file-helpers.c [new file with mode: 0644]
src/common/meson.build
src/config/session.c

diff --git a/include/common/file-helpers.h b/include/common/file-helpers.h
new file mode 100644 (file)
index 0000000..b9b1a22
--- /dev/null
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef LABWC_FILE_HELPERS_H
+#define LABWC_FILE_HELPERS_H
+#include <stdbool.h>
+
+/**
+ * file_exists() - Test if file exists.
+ * @filename: Name of file to test.
+ */
+bool file_exists(const char *filename);
+
+#endif /* LABWC_FILE_HELPERS_H */
index cc45594f70027cdeb9111151b35745b8d6c93dc5..66cf55352bbbd23a4811c7c02b6474d6e687f085 100644 (file)
@@ -8,22 +8,14 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/stat.h>
 #include <wlr/util/log.h>
 #include "buffer.h"
 #include "button/button-png.h"
 #include "button/common.h"
+#include "common/file-helpers.h"
 #include "labwc.h"
 #include "theme.h"
 
-/* Share with session.c:isfile() */
-static bool
-file_exists(const char *path)
-{
-       struct stat st;
-       return (!stat(path, &st));
-}
-
 /*
  * cairo_image_surface_create_from_png() does not gracefully handle non-png
  * files, so we verify the header before trying to read the rest of the file.
diff --git a/src/common/file-helpers.c b/src/common/file-helpers.c
new file mode 100644 (file)
index 0000000..2361b54
--- /dev/null
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <sys/stat.h>
+#include "common/file-helpers.h"
+
+bool
+file_exists(const char *filename)
+{
+       struct stat st;
+       return (!stat(filename, &st));
+}
index 7007b061831389e20b420400ca6a7dc09108b885..72ad6f2ba77efa2790067210942dfc1e5163fc80 100644 (file)
@@ -2,6 +2,7 @@ labwc_sources += files(
   'buf.c',
   'dir.c',
   'fd_util.c',
+  'file-helpers.c',
   'font.c',
   'grab-file.c',
   'graphic-helpers.c',
index 06f8556a85455b27d440f51e3199a0f8ed46525b..1a528d18eb6861216be31bf77f4cec579782abbd 100644 (file)
@@ -8,18 +8,12 @@
 #include <sys/stat.h>
 #include <wlr/util/log.h>
 #include "common/buf.h"
+#include "common/file-helpers.h"
 #include "common/mem.h"
 #include "common/spawn.h"
 #include "common/string-helpers.h"
 #include "config/session.h"
 
-static bool
-isfile(const char *path)
-{
-       struct stat st;
-       return (!stat(path, &st));
-}
-
 static bool
 string_empty(const char *s)
 {
@@ -130,7 +124,7 @@ session_autostart_init(const char *dir)
        if (!autostart) {
                return;
        }
-       if (!isfile(autostart)) {
+       if (!file_exists(autostart)) {
                wlr_log(WLR_ERROR, "no autostart file");
                goto out;
        }