Fix Windows errors on mingw64.

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
Slendi 2023-03-21 21:32:32 +02:00
parent 86f69004e5
commit 8b885fdb28
No known key found for this signature in database
GPG Key ID: D4F62D3533AB5EA1
2 changed files with 19 additions and 10 deletions

1
.gitignore vendored
View File

@ -2,4 +2,5 @@ build
out
*.o
tbuild
tbuild.exe
test

28
main.c
View File

@ -4,7 +4,6 @@
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>
#include <unistd.h>
#include <libgen.h>
#include <dirent.h>
@ -77,7 +76,11 @@ bool copy_directory(const char *src_path, const char *dest_path) {
}
// Create destination directory if it doesn't exist
#if defined(_WIN32)
mkdir(dest_path);
#else
mkdir(dest_path, 0755);
#endif
// Copy files and directories from source to destination
struct dirent *entry;
@ -355,14 +358,15 @@ char *get_username(void) {
#if defined(_WIN32)
// FIXME: This leaks memory.
TCHAR infoBuf[105];
DWORD bufCharCount = 105;
if( !GetUserName( infoBuf, &bufCharCount ) )
printError( TEXT("GetUserName") );
// TCHAR infoBuf[105];
// DWORD bufCharCount = 105;
// if(!GetUserName( infoBuf, &bufCharCount ))
// fputs("Error: Cannot get username: GetUserName failed.\n", stderr);
char *c_szText[105];
wcstombs(c_szText, infoBuf, wcslen(infoBuf) + 1);
return c_szText;
// char *c_szText[105];
// wcstombs(c_szText, infoBuf, wcslen(infoBuf) + 1);
// return c_szText;
return getenv("USERNAME");
#else
uid_t uid = geteuid();
struct passwd *pw = getpwuid(uid);
@ -425,7 +429,11 @@ bool makedir(char const *path) {
struct stat st = {0};
if (stat(path, &st) == -1) {
#if defined(_WIN32)
mkdir(path);
#else
mkdir(path, 0700);
#endif
} else {
fprintf(stderr, YELLOW "Warning: File already exists. Continuing anyway." RESET);
return false;
@ -499,7 +507,7 @@ void convert_to_zealos(char const *path) {
int len = snprintf(fpath, sizeof(fpath)-1, "%s/%s", path, entry->d_name);
fpath[len] = 0;
if (lstat(fpath, &s) == 0 && S_ISDIR(s.st_mode)) { // Is directory?
if (stat(fpath, &s) == 0 && S_ISDIR(s.st_mode)) { // Is directory?
convert_to_zealos(fpath);
continue;
}
@ -626,7 +634,7 @@ bool run_scripts(char const *path) {
int len = snprintf(fpath, sizeof(fpath)-1, "%s/%s", path, entry->d_name);
fpath[len] = 0;
if (lstat(fpath, &s) == 0 && S_ISDIR(s.st_mode)) { // Is directory?
if (stat(fpath, &s) == 0 && S_ISDIR(s.st_mode)) { // Is directory?
run_scripts(fpath);
continue;
}