]> git.mdlowis.com Git - proto/labwc.git/commitdiff
s/xbm_read_file()/grab_file/()
authorJohan Malm <jgm323@gmail.com>
Thu, 6 Aug 2020 14:01:08 +0000 (15:01 +0100)
committerJohan Malm <jgm323@gmail.com>
Thu, 6 Aug 2020 14:01:08 +0000 (15:01 +0100)
include/common/grab-file.h [new file with mode: 0644]
src/common/grab-file.c [new file with mode: 0644]
src/common/meson.build
src/theme/xbm/parse.c
src/theme/xbm/xbm.c

diff --git a/include/common/grab-file.h b/include/common/grab-file.h
new file mode 100644 (file)
index 0000000..38aaddc
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Read file into memory
+ *
+ * Copyright Johan Malm 2020
+ */
+
+#ifndef __LABWC_GRAB_FILE_H
+#define __LABWC_GRAB_FILE_H
+
+/**
+ * grab_file - read file into memory buffer
+ * @filename: file to read
+ * Returns pointer to buffer. Free with free().
+ */
+char *grab_file(const char *filename);
+
+#endif /* __LABWC_GRAB_FILE_H */
diff --git a/src/common/grab-file.c b/src/common/grab-file.c
new file mode 100644 (file)
index 0000000..ad3f9d2
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Read file into memory
+ *
+ * Copyright Johan Malm 2020
+ */
+
+#define _POSIX_C_SOURCE 200809L
+#include "common/grab-file.h"
+#include "common/buf.h"
+
+#include <stdio.h>
+
+char *grab_file(const char *filename)
+{
+       char *line = NULL;
+       size_t len = 0;
+       FILE *stream = fopen(filename, "r");
+       if (!stream)
+               return NULL;
+       struct buf buffer;
+       buf_init(&buffer);
+       while ((getline(&line, &len, stream) != -1)) {
+               char *p = strrchr(line, '\n');
+               if (p)
+                       *p = '\0';
+               buf_add(&buffer, line);
+       }
+       free(line);
+       fclose(stream);
+       return (buffer.buf);
+}
index fe8e710dbc924866122921c1cf9242a1b032e835..4a471ab1a83ee79762184c9b52a2576c669e3b62 100644 (file)
@@ -1,5 +1,6 @@
 labwc_sources += files(
   'buf.c',
   'font.c',
+  'grab-file.c',
   'spawn.c',
 )
index 89bbbcf04338ee4901c42e2923ffcb6888eef1d0..491ef269d8e182f3cbf3d1383f715fdaeaf9c9ad 100644 (file)
@@ -11,7 +11,6 @@
 #include <stdint.h>
 #include <stdbool.h>
 
-#include "common/buf.h"
 #include "theme/xbm/parse.h"
 
 /* TODO: should be window.active.button.unpressed.image.color */
@@ -85,23 +84,3 @@ struct pixmap xbm_create_pixmap_builtin(const char *button)
        process_bytes(&pixmap, t);
        return pixmap;
 }
-
-char *xbm_read_file(const char *filename)
-{
-       char *line = NULL;
-       size_t len = 0;
-       FILE *stream = fopen(filename, "r");
-       if (!stream)
-               return NULL;
-       struct buf buffer;
-       buf_init(&buffer);
-       while ((getline(&line, &len, stream) != -1)) {
-               char *p = strrchr(line, '\n');
-               if (p)
-                       *p = '\0';
-               buf_add(&buffer, line);
-       }
-       free(line);
-       fclose(stream);
-       return (buffer.buf);
-}
index 6f37462b2cde70cb4e58aa3b724c88e098252300..6fa9893385aee50be7fc5929895a5d5d79ea1686 100644 (file)
@@ -12,6 +12,7 @@
 #include "theme/xbm/parse.h"
 #include "theme/theme-dir.h"
 #include "config/rcxml.h"
+#include "common/grab-file.h"
 
 /* built-in 6x6 buttons */
 char close_button_normal[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
@@ -50,7 +51,7 @@ static char *xbm_path(const char *button)
 static void load_button(struct wlr_renderer *renderer, const char *filename,
                        struct wlr_texture **texture, char *button)
 {
-       char *buffer = xbm_read_file(xbm_path(filename));
+       char *buffer = grab_file(xbm_path(filename));
        if (!buffer)
                goto out;
        fprintf(stderr, "loading %s\n", filename);