Fix Windows errors on mingw64.
Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
parent
86f69004e5
commit
8b885fdb28
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,5 @@ build
|
|||||||
out
|
out
|
||||||
*.o
|
*.o
|
||||||
tbuild
|
tbuild
|
||||||
|
tbuild.exe
|
||||||
test
|
test
|
||||||
|
28
main.c
28
main.c
@ -4,7 +4,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <dirent.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
|
// Create destination directory if it doesn't exist
|
||||||
|
#if defined(_WIN32)
|
||||||
|
mkdir(dest_path);
|
||||||
|
#else
|
||||||
mkdir(dest_path, 0755);
|
mkdir(dest_path, 0755);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Copy files and directories from source to destination
|
// Copy files and directories from source to destination
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
@ -355,14 +358,15 @@ char *get_username(void) {
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// FIXME: This leaks memory.
|
// FIXME: This leaks memory.
|
||||||
|
|
||||||
TCHAR infoBuf[105];
|
// TCHAR infoBuf[105];
|
||||||
DWORD bufCharCount = 105;
|
// DWORD bufCharCount = 105;
|
||||||
if( !GetUserName( infoBuf, &bufCharCount ) )
|
// if(!GetUserName( infoBuf, &bufCharCount ))
|
||||||
printError( TEXT("GetUserName") );
|
// fputs("Error: Cannot get username: GetUserName failed.\n", stderr);
|
||||||
|
|
||||||
char *c_szText[105];
|
// char *c_szText[105];
|
||||||
wcstombs(c_szText, infoBuf, wcslen(infoBuf) + 1);
|
// wcstombs(c_szText, infoBuf, wcslen(infoBuf) + 1);
|
||||||
return c_szText;
|
// return c_szText;
|
||||||
|
return getenv("USERNAME");
|
||||||
#else
|
#else
|
||||||
uid_t uid = geteuid();
|
uid_t uid = geteuid();
|
||||||
struct passwd *pw = getpwuid(uid);
|
struct passwd *pw = getpwuid(uid);
|
||||||
@ -425,7 +429,11 @@ bool makedir(char const *path) {
|
|||||||
struct stat st = {0};
|
struct stat st = {0};
|
||||||
|
|
||||||
if (stat(path, &st) == -1) {
|
if (stat(path, &st) == -1) {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
mkdir(path);
|
||||||
|
#else
|
||||||
mkdir(path, 0700);
|
mkdir(path, 0700);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, YELLOW "Warning: File already exists. Continuing anyway." RESET);
|
fprintf(stderr, YELLOW "Warning: File already exists. Continuing anyway." RESET);
|
||||||
return false;
|
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);
|
int len = snprintf(fpath, sizeof(fpath)-1, "%s/%s", path, entry->d_name);
|
||||||
fpath[len] = 0;
|
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);
|
convert_to_zealos(fpath);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -626,7 +634,7 @@ bool run_scripts(char const *path) {
|
|||||||
int len = snprintf(fpath, sizeof(fpath)-1, "%s/%s", path, entry->d_name);
|
int len = snprintf(fpath, sizeof(fpath)-1, "%s/%s", path, entry->d_name);
|
||||||
fpath[len] = 0;
|
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);
|
run_scripts(fpath);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user