#ifndef DATGPT_WIN_COMPAT_H #define DATGPT_WIN_COMPAT_H /* Small POSIX spellings used by the shared C sources on native Windows. */ #ifdef _WIN32 #include #include #include #include #include #include #include #include #include #include #ifndef mkdir #define mkdir(path, mode) _mkdir(path) #endif #ifndef fsync #define fsync(fd) _commit(fd) #endif #ifndef getpid #define getpid _getpid #endif #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif #ifndef O_NOFOLLOW #define O_NOFOLLOW 0 #endif #ifndef EKEYREJECTED #define EKEYREJECTED EACCES #endif #ifndef S_ISLNK #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) #endif #ifndef S_IFLNK #define S_IFLNK 0120000 #endif #ifndef fchmod #define fchmod(fd, mode) ((void)(fd), (void)(mode), 0) #endif #ifndef strcasecmp #define strcasecmp _stricmp #endif #ifndef strncasecmp #define strncasecmp _strnicmp #endif static inline char *dat_win_getenv_compat(const char *name) { char *value = getenv(name); if (!value && name && !strcmp(name, "HOME")) value = getenv("USERPROFILE"); return value; } #define getenv dat_win_getenv_compat static inline int dat_win_lstat(const char *path, struct stat *info) { DWORD attributes; if (stat(path, info)) return -1; attributes = GetFileAttributesA(path); if (attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_REPARSE_POINT)) info->st_mode = (info->st_mode & ~S_IFMT) | S_IFLNK; return 0; } #ifndef lstat #define lstat dat_win_lstat #endif static inline int dat_win_readlink(const char *path, char *target, size_t capacity) { (void)path; (void)target; (void)capacity; errno = ENOTSUP; return -1; } static inline int dat_win_symlink(const char *target, const char *path) { (void)target; (void)path; errno = ENOTSUP; return -1; } #ifndef readlink #define readlink dat_win_readlink #endif #ifndef symlink #define symlink dat_win_symlink #endif #endif #endif