commit ae8a971403588e0ee3da09e752a5748a8b8cf067
parent 8b1ca971f1f986b1388c2cc43f6286330cbccc45
Author: finwo <finwo@pm.me>
Date: Sat, 14 Mar 2026 02:11:47 +0100
Dealing with windows non-posix-compliance
Diffstat:
5 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/src/command/add/main.c b/src/command/add/main.c
@@ -7,6 +7,10 @@
#include <time.h>
#include <unistd.h>
+#ifndef LINE_MAX
+#define LINE_MAX 4096
+#endif
+
#include "cofyc/argparse.h"
#include "command/command.h"
#include "common/fs-utils.h"
diff --git a/src/command/install/main.c b/src/command/install/main.c
@@ -5,6 +5,10 @@
#include <sys/stat.h>
#include <unistd.h>
+#ifndef LINE_MAX
+#define LINE_MAX 4096
+#endif
+
#include "command/command.h"
#include "common/github-utils.h"
#include "common/net-utils.h"
@@ -34,11 +38,19 @@ static int mkdir_recursive(const char *path) {
for (p = tmp + 1; *p; p++) {
if (*p == '/') {
*p = '\0';
+#ifdef _WIN32
+ mkdir(tmp);
+#else
mkdir(tmp, 0755);
+#endif
*p = '/';
}
}
+#ifdef _WIN32
+ return mkdir(tmp);
+#else
return mkdir(tmp, 0755);
+#endif
}
static char *trim_whitespace(char *str) {
@@ -375,7 +387,11 @@ static int cmd_install(int argc, const char **argv) {
}
if (!dir_exists("lib")) {
+#ifdef _WIN32
+ if (mkdir("lib") != 0) {
+#else
if (mkdir("lib", 0755) != 0) {
+#endif
fprintf(stderr, "Error: could not create lib directory\n");
fclose(f);
return 1;
diff --git a/src/command/repository/main.c b/src/command/repository/main.c
@@ -6,6 +6,10 @@
#include <sys/stat.h>
#include <unistd.h>
+#ifndef LINE_MAX
+#define LINE_MAX 4096
+#endif
+
#include "../command.h"
#include "cofyc/argparse.h"
#include "common/fs-utils.h"
diff --git a/src/common/fs-utils.c b/src/common/fs-utils.c
@@ -53,11 +53,19 @@ int mkdir_recursive(const char *path) {
for (p = tmp + 1; *p; p++) {
if (*p == '/') {
*p = '\0';
+#ifdef _WIN32
+ mkdir(tmp);
+#else
mkdir(tmp, 0755);
+#endif
*p = '/';
}
}
+#ifdef _WIN32
+ return mkdir(tmp);
+#else
return mkdir(tmp, 0755);
+#endif
}
char *trim_whitespace(char *str) {
diff --git a/src/common/net-utils.c b/src/common/net-utils.c
@@ -41,11 +41,19 @@ static int mkdir_recursive(const char *path) {
for (p = tmp + 1; *p; p++) {
if (*p == '/') {
*p = '\0';
+#ifdef _WIN32
+ mkdir(tmp);
+#else
mkdir(tmp, 0755);
+#endif
*p = '/';
}
}
+#ifdef _WIN32
+ return mkdir(tmp);
+#else
return mkdir(tmp, 0755);
+#endif
}
/* Static helper for downloading with retries */