Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartatz committed Oct 3, 2024
1 parent c21e698 commit 01978e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,48 +58,48 @@ char* get_current_directory(void) {
DWORD cwds = 0;

#if defined(_UNICODE)
void* tmp = NULL;
wchat_t* wcwd = NULL;

cwds = GetCurrentDirectoryW(0, NULL);

if (cwds == 0) {
return NULL;
}

tmp = malloc((size_t) cwds);
wcwd = malloc((size_t) cwds * sizeof(*wcwd));

if (tmp == NULL) {
if (wcwd == NULL) {
return NULL;
}

cwds = GetCurrentDirectoryW(cwds, tmp);
cwds = GetCurrentDirectoryW(cwds, wcwd);

if (cwds == 0) {
free(tmp);
free(wcwd);
return NULL;
}

cwds = (DWORD) WideCharToMultiByte(CP_UTF8, 0, tmp, -1, NULL, 0, NULL, NULL);
cwds = (DWORD) WideCharToMultiByte(CP_UTF8, 0, wcwd, -1, NULL, 0, NULL, NULL);

if (cwds == 0) {
free(tmp);
free(wcwd);
return NULL;
}

cwd = malloc((size_t) cwds);

if (cwd == NULL) {
free(tmp);
free(wcwd);
return NULL;
}

if (WideCharToMultiByte(CP_UTF8, 0, tmp, -1, cwd, (int) cwds, NULL, NULL) == 0) {
free(tmp);
if (WideCharToMultiByte(CP_UTF8, 0, wcwd, -1, cwd, (int) cwds, NULL, NULL) == 0) {
free(wcwd);
free(cwd);
return NULL;
}

free(tmp);
free(wcwd);
#else
cwds = GetCurrentDirectoryA(0, NULL);

Expand Down Expand Up @@ -553,7 +553,7 @@ static int raw_create_dir(const char* const directory) {
const size_t prefixs = isabsolute(directory) ? wcslen(WIN10_LONG_PATH_PREFIX) : 0;

const int wdirectorys = MultiByteToWideChar(CP_UTF8, 0, directory, -1, NULL, 0);

printf("%i %s\n", wdirectorys, directory);
if (wdirectorys == 0) {
return -1;
}
Expand Down
4 changes: 3 additions & 1 deletion src/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <sys/wait.h>
#endif

#include "wio.h"

#if defined(_WIN32)
#if defined(_UNICODE)
static const wchar_t WENV_APPDATA[] = L"APPDATA";
Expand Down Expand Up @@ -302,7 +304,7 @@ char* get_temporary_directory(void) {

directorys++;

wdirectory = malloc((size_t) directorys);
wdirectory = malloc((size_t) directorys * sizeof(*wdirectory));

if (wdirectory == NULL) {
return NULL;
Expand Down

0 comments on commit 01978e2

Please sign in to comment.