authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-06-15 22:21:01+03:00
committergravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-06-15 22:21:01+03:00
log2c8a3aaf855475cabef4e8275581a12b06417a02
treeddea504e9125e606ebb664a4bc5871203695e1b9
parent242246f79312f3106290b9b1aea6dfd5a18368b0

Use _wfopen instead of fopen on windows


1 files changed, 25 insertions(+), 0 deletions(-)

src/os.cpp+25
...@@ -1037,7 +1037,12 @@ Error os_exec_process(ZigList<const char *> &args,...@@ -1037,7 +1037,12 @@ Error os_exec_process(ZigList<const char *> &args,
1037}1037}
10381038
1039Error os_write_file(Buf *full_path, Buf *contents) {1039Error os_write_file(Buf *full_path, Buf *contents) {
1040#if defined(ZIG_OS_WINDOWS)
1041 PathSpace path_space = slice_to_prefixed_file_w(buf_to_slice(full_path));
1042 FILE *f = _wfopen(&path_space.data.items[0], L"wb");
1043#else
1040 FILE *f = fopen(buf_ptr(full_path), "wb");1044 FILE *f = fopen(buf_ptr(full_path), "wb");
1045#endif
1041 if (!f) {1046 if (!f) {
1042 zig_panic("os_write_file failed for %s", buf_ptr(full_path));1047 zig_panic("os_write_file failed for %s", buf_ptr(full_path));
1043 }1048 }
...@@ -1072,7 +1077,12 @@ static Error copy_open_files(FILE *src_f, FILE *dest_f) {...@@ -1072,7 +1077,12 @@ static Error copy_open_files(FILE *src_f, FILE *dest_f) {
1072Error os_dump_file(Buf *src_path, FILE *dest_file) {1077Error os_dump_file(Buf *src_path, FILE *dest_file) {
1073 Error err;1078 Error err;
10741079
1080#if defined(ZIG_OS_WINDOWS)
1081 PathSpace path_space = slice_to_prefixed_file_w(buf_to_slice(src_path));
1082 FILE *src_f = _wfopen(&path_space.data.items[0], L"rb");
1083#else
1075 FILE *src_f = fopen(buf_ptr(src_path), "rb");1084 FILE *src_f = fopen(buf_ptr(src_path), "rb");
1085#endif
1076 if (!src_f) {1086 if (!src_f) {
1077 int err = errno;1087 int err = errno;
1078 if (err == ENOENT) {1088 if (err == ENOENT) {
...@@ -1189,7 +1199,12 @@ Error os_update_file(Buf *src_path, Buf *dst_path) {...@@ -1189,7 +1199,12 @@ Error os_update_file(Buf *src_path, Buf *dst_path) {
1189}1199}
11901200
1191Error os_copy_file(Buf *src_path, Buf *dest_path) {1201Error os_copy_file(Buf *src_path, Buf *dest_path) {
1202#if defined(ZIG_OS_WINDOWS)
1203 PathSpace src_path_space = slice_to_prefixed_file_w(buf_to_slice(src_path));
1204 FILE *src_f = _wfopen(&src_path_space.data.items[0], L"rb");
1205#else
1192 FILE *src_f = fopen(buf_ptr(src_path), "rb");1206 FILE *src_f = fopen(buf_ptr(src_path), "rb");
1207#endif
1193 if (!src_f) {1208 if (!src_f) {
1194 int err = errno;1209 int err = errno;
1195 if (err == ENOENT) {1210 if (err == ENOENT) {
...@@ -1200,7 +1215,12 @@ Error os_copy_file(Buf *src_path, Buf *dest_path) {...@@ -1200,7 +1215,12 @@ Error os_copy_file(Buf *src_path, Buf *dest_path) {
1200 return ErrorFileSystem;1215 return ErrorFileSystem;
1201 }1216 }
1202 }1217 }
1218#if defined(ZIG_OS_WINDOWS)
1219 PathSpace dest_path_space = slice_to_prefixed_file_w(buf_to_slice(dest_path));
1220 FILE *dest_f = _wfopen(&dest_path_space.data.items[0], L"wb");
1221#else
1203 FILE *dest_f = fopen(buf_ptr(dest_path), "wb");1222 FILE *dest_f = fopen(buf_ptr(dest_path), "wb");
1223#endif
1204 if (!dest_f) {1224 if (!dest_f) {
1205 int err = errno;1225 int err = errno;
1206 if (err == ENOENT) {1226 if (err == ENOENT) {
...@@ -1221,7 +1241,12 @@ Error os_copy_file(Buf *src_path, Buf *dest_path) {...@@ -1221,7 +1241,12 @@ Error os_copy_file(Buf *src_path, Buf *dest_path) {
1221}1241}
12221242
1223Error os_fetch_file_path(Buf *full_path, Buf *out_contents) {1243Error os_fetch_file_path(Buf *full_path, Buf *out_contents) {
1244#if defined(ZIG_OS_WINDOWS)
1245 PathSpace path_space = slice_to_prefixed_file_w(buf_to_slice(full_path));
1246 FILE *f = _wfopen(&path_space.data.items[0], L"rb");
1247#else
1224 FILE *f = fopen(buf_ptr(full_path), "rb");1248 FILE *f = fopen(buf_ptr(full_path), "rb");
1249#endif
1225 if (!f) {1250 if (!f) {
1226 switch (errno) {1251 switch (errno) {
1227 case EACCES:1252 case EACCES: