diff --git a/.gitignore b/.gitignore index 8c0c277..aca0dd5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build out *.o tbuild +tbuild.exe test diff --git a/main.c b/main.c index 7682b52..aead009 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -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; }