lstat_win.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include <util/system/defaults.h>
  2. #ifdef _win_
  3. #include <util/system/winint.h>
  4. #include "lstat_win.h"
  5. int lstat(const char* fileName, stat_struct* fileStat) {
  6. int len = strlen(fileName);
  7. int convRes = MultiByteToWideChar(CP_UTF8, 0, fileName, len, 0, 0);
  8. if (convRes == 0) {
  9. return -1;
  10. }
  11. WCHAR* buf = malloc(sizeof(WCHAR) * (convRes + 1));
  12. MultiByteToWideChar(CP_UTF8, 0, fileName, len, buf, convRes);
  13. buf[convRes] = 0;
  14. HANDLE findHandle;
  15. WIN32_FIND_DATAW findBuf;
  16. int result;
  17. result = _wstat64(buf, fileStat);
  18. if (result == 0) {
  19. SetLastError(0);
  20. findHandle = FindFirstFileW(buf, &findBuf);
  21. if (findBuf.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT &&
  22. (findBuf.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT || findBuf.dwReserved0 == IO_REPARSE_TAG_SYMLINK))
  23. {
  24. fileStat->st_mode = fileStat->st_mode & ~_S_IFMT | _S_IFLNK;
  25. }
  26. FindClose(findHandle);
  27. }
  28. free(buf);
  29. return result;
  30. }
  31. #endif //_win_