You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
897B

  1. #include <common.hpp>
  2. #if defined ARCH_WIN
  3. #include <windows.h>
  4. static wchar_t* utf8_to_w(const char* str) {
  5. int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, 0, 0);
  6. wchar_t* strW = (wchar_t*) malloc(len * sizeof(wchar_t));
  7. MultiByteToWideChar(CP_UTF8, 0, str, -1, strW, len);
  8. return strW;
  9. }
  10. FILE* fopen_utf8(const char* filename, const char* mode) {
  11. wchar_t* filenameW = utf8_to_w(filename);
  12. wchar_t* modeW = utf8_to_w(mode);
  13. FILE* file = _wfopen(filenameW, modeW);
  14. free(filenameW);
  15. free(modeW);
  16. return file;
  17. }
  18. int remove_utf8(const char* path) {
  19. wchar_t* pathW = utf8_to_w(path);
  20. int ret = _wremove(pathW);
  21. free(pathW);
  22. return ret;
  23. }
  24. int rename_utf8(const char* oldname, const char* newname) {
  25. wchar_t* oldnameW = utf8_to_w(oldname);
  26. wchar_t* newnameW = utf8_to_w(newname);
  27. int ret = _wrename(oldnameW, newnameW);
  28. free(oldnameW);
  29. free(newnameW);
  30. return ret;
  31. }
  32. #endif