aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-05-20 10:07:16 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-05-20 10:11:29 -0400
commit67975a5944706e382fe1e7b00d226715c6242358 (patch)
treee93dd37df57f49d4327567479521014f380206e5 /src/utils.c
parent30c9945e0da19305ebad88a2835653ff4f409313 (diff)
downloadstasis-67975a5944706e382fe1e7b00d226715c6242358.tar.gz
Mass attempt at windows portability
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c
index ea79f10..c62af08 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -52,8 +52,16 @@ int rmtree(char *_path) {
continue;
}
+ int is_dir = 0;
+#if defined(OMC_OS_WINDOWS)
+ struct stat st;
+ stat(d_entity->d_name, &st);
+ is_dir = S_ISDIR(st.st_mode);
+#else
+ is_dir = DT_DIR == rec->d_type;
+#endif
// Push directories on to the stack first
- if (d_entity->d_type == DT_DIR) {
+ if (is_dir) {
rmtree(abspath);
} else {
remove(abspath);
@@ -385,12 +393,21 @@ char *git_rev_parse(const char *path, char *args) {
return version;
}
+#if defined(OMC_OS_WINDOWS)
+#define OMC_COLOR_RED ""
+#define OMC_COLOR_GREEN ""
+#define OMC_COLOR_YELLOW ""
+#define OMC_COLOR_BLUE ""
+#define OMC_COLOR_WHITE ""
+#define OMC_COLOR_RESET ""
+#else
#define OMC_COLOR_RED "\e[1;91m"
#define OMC_COLOR_GREEN "\e[1;92m"
#define OMC_COLOR_YELLOW "\e[1;93m"
#define OMC_COLOR_BLUE "\e[1;94m"
#define OMC_COLOR_WHITE "\e[1;97m"
#define OMC_COLOR_RESET "\e[0;37m\e[0m"
+#endif
void msg(unsigned type, char *fmt, ...) {
FILE *stream = NULL;
@@ -763,3 +780,51 @@ struct StrList *listdir(const char *path) {
return node;
}
+#if defined(OMC_OS_WINDOWS)
+char *realpath(const char *path, char **dest) {
+ char cwd_start[PATH_MAX] = {0};
+ char cwd[PATH_MAX] = {0};
+ char where[PATH_MAX] = {0};
+ char bname[PATH_MAX] = {0};
+ char *w = where;
+ getcwd(cwd_start, sizeof(cwd) - 1);
+ strcpy(w, path);
+ w = path_dirname(w);
+ if (chdir(w)) {
+ getcwd(cwd, sizeof(cwd) - 1);
+ path_basename(bname);
+ strcat(cwd, bname);
+ chdir(cwd_start);
+ }
+
+ char *result;
+ result = strdup(cwd);
+ if (!result) {
+ return NULL;
+ }
+
+ if (dest) {
+ *dest = result;
+ }
+
+ return result;
+}
+
+int setenv(const char *key, const char *value, int overwrite) {
+ size_t len = 0;
+ char *data = NULL;
+ len = strlen(key) + strlen(value) + 2;
+ data = calloc(len, sizeof(*data));
+ if (!data) {
+ return -1;
+ }
+ sprintf(data, "%s=%s", key, value);
+ if (_putenv(data)) {
+ free(data);
+ return 1;
+ }
+
+ free(data);
+ return 0;
+}
+#endif