Skip to content

Commit

Permalink
fix getcwd on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
pikasTech committed Dec 3, 2023
1 parent fba5e0b commit fc63ab8
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/PikaPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,13 @@
#include <io.h>
#endif

#if defined(_WIN32)
#include <dirent.h>
#endif

#if defined(__linux) || PIKA_LINUX_COMPATIBLE
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "unistd.h"
#endif

#if (defined(__linux) || PIKA_LINUX_COMPATIBLE)
#include <dirent.h>
#endif

void pikaFree(void* mem, uint32_t size);
void* pikaMalloc(uint32_t size);
int pika_pvsprintf(char** buff, const char* fmt, va_list args);
Expand Down Expand Up @@ -287,8 +279,15 @@ PIKA_WEAK long pika_platform_ftell(FILE* stream) {
}

PIKA_WEAK char* pika_platform_getcwd(char* buf, size_t size) {
#if defined(__linux) || defined(_WIN32)
#if defined(__linux)
return getcwd(buf, size);
#elif defined(_WIN32)
if (!GetCurrentDirectoryA(size, buf)) {
return NULL;
}
else {
return buf;
}
#else
WEAK_FUNCTION_NEED_OVERRIDE_ERROR_LOWLEVEL(_);
#endif
Expand Down Expand Up @@ -479,7 +478,7 @@ PIKA_WEAK char** pika_platform_listdir(const char* path, int* count) {
struct _finddata_t fb;
intptr_t handle = 0;
char dirpath[256] = {0};
char* currentPath = _getcwd(dirpath, 256);
char* currentPath = pika_platform_getcwd(dirpath, sizeof dirpath);
strcat(dirpath, path);
strcat(dirpath, "\\*");

Expand Down

0 comments on commit fc63ab8

Please sign in to comment.