aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-01-02 11:53:21 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-01-02 11:53:21 +0100
commit56caeb540795fb92f3289bbc4744e94da0c20654 (patch)
treeb8e0e2dffd87835dabe377aab53e5c1d89810233
parent31cf3ac5ac7054890810190d6f526ec1eb38c64d (diff)
downloaduwu-lang-56caeb540795fb92f3289bbc4744e94da0c20654.tar.xz
Turn common back into a normal directory (instead of a submodule)
-rw-r--r--.gitmodules3
m---------common0
-rw-r--r--common/dir.h28
-rw-r--r--common/dl.h14
-rw-r--r--common/err.h27
-rw-r--r--common/file.h19
-rw-r--r--common/str.h17
7 files changed, 105 insertions, 3 deletions
diff --git a/.gitmodules b/.gitmodules
index ef80cf6..6f6110a 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -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
-Subproject a636a960a0866a94719aff01774b9533743ee07
diff --git a/common/dir.h b/common/dir.h
new file mode 100644
index 0000000..3e1ca41
--- /dev/null
+++ b/common/dir.h
@@ -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
index 0000000..04a2cd7
--- /dev/null
+++ b/common/dl.h
@@ -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
index 0000000..9db3e23
--- /dev/null
+++ b/common/err.h
@@ -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
index 0000000..5d875c9
--- /dev/null
+++ b/common/file.h
@@ -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
index 0000000..e6ed70a
--- /dev/null
+++ b/common/str.h
@@ -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