]> git.lizzy.rs Git - uwu-lang.git/commitdiff
Turn common back into a normal directory (instead of a submodule)
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 2 Jan 2022 10:53:21 +0000 (11:53 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 2 Jan 2022 10:53:21 +0000 (11:53 +0100)
.gitmodules
common [deleted submodule]
common/dir.h [new file with mode: 0644]
common/dl.h [new file with mode: 0644]
common/err.h [new file with mode: 0644]
common/file.h [new file with mode: 0644]
common/str.h [new file with mode: 0644]

index ef80cf6ecf3fb32b2fad0377639da46fcc2466c2..6f6110a07b3d11992931e2169f7128084d121f2c 100644 (file)
@@ -1,6 +1,3 @@
-[submodule "common"]
-       path = common
-       url = git@github.com:EliasFleckenstein03/uwu-common
 [submodule "std"]
        path = std
        url = git@github.com:EliasFleckenstein03/uwu-std
diff --git a/common b/common
deleted file mode 160000 (submodule)
index a636a96..0000000
--- a/common
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit a636a960a0866a94719aff01774b9533743ee072
diff --git a/common/dir.h b/common/dir.h
new file mode 100644 (file)
index 0000000..3e1ca41
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef _UWU_COMMON_DIR_H_
+#define _UWU_COMMON_DIR_H_
+
+#include <stdlib.h>
+#include <libgen.h>
+#include <string.h>
+
+static char *wrap_name_func(const char *name, char *(*fn)(char *))
+{
+       char *copy = strdup(name);
+       char *result = fn(copy);
+       char *result_copy = strdup(result);
+
+       free(copy);
+       return result_copy;
+}
+
+static inline char *basename_wrapper(const char *name)
+{
+       return wrap_name_func(name, &basename);
+}
+
+static inline char *dirname_wrapper(const char *name)
+{
+       return wrap_name_func(name, &dirname);
+}
+
+#endif
diff --git a/common/dl.h b/common/dl.h
new file mode 100644 (file)
index 0000000..04a2cd7
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _UWU_COMMON_DL_H_
+#define _UWU_COMMON_DL_H_
+
+#include <dlfcn.h>
+#include "err.h"
+
+inline static void check_dlerror()
+{
+       char *err = dlerror();
+       if (err)
+               error("library error: %s\n", err);
+}
+
+#endif
diff --git a/common/err.h b/common/err.h
new file mode 100644 (file)
index 0000000..9db3e23
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef _UWU_COMMON_ERR_H_
+#define _UWU_COMMON_ERR_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+static inline void error(const char *format, ...)
+{
+       va_list args;
+       va_start(args, format);
+       vfprintf(stderr, format, args);
+       va_end(args);
+       exit(1);
+}
+
+static inline void syserror(const char *call, FILE *file)
+{
+       perror(call);
+
+       if (file)
+               fclose(file);
+
+       exit(1);
+}
+
+#endif
diff --git a/common/file.h b/common/file.h
new file mode 100644 (file)
index 0000000..5d875c9
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _UWU_COMMON_FILE_H_
+#define _UWU_COMMON_FILE_H_
+
+#include <stdio.h>
+#include <stdbool.h>
+
+inline static bool file_exists(const char *filename)
+{
+       FILE *f = fopen(filename, "r");
+
+       if (f) {
+               fclose(f);
+               return true;
+       }
+
+       return false;
+}
+
+#endif
diff --git a/common/str.h b/common/str.h
new file mode 100644 (file)
index 0000000..e6ed70a
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef _UWU_COMMON_STR_H_
+#define _UWU_COMMON_STR_H_
+
+#include <stdio.h>
+#include <stdarg.h>
+
+static inline char *asprintf_wrapper(const char *format, ...)
+{
+       va_list args;
+       va_start(args, format);
+       char *ptr;
+       vasprintf(&ptr, format, args);
+       va_end(args);
+       return ptr;
+}
+
+#endif