| ... | ... | @@ -34,7 +34,6 @@ |
| 34 | 34 | #define ZIG_OS_POSIX |
| 35 | 35 | |
| 36 | 36 | #include <unistd.h> |
| 37 | | #include <errno.h> |
| 38 | 37 | #include <sys/types.h> |
| 39 | 38 | #include <sys/stat.h> |
| 40 | 39 | #include <sys/wait.h> |
| ... | ... | @@ -43,7 +42,11 @@ |
| 43 | 42 | |
| 44 | 43 | #endif |
| 45 | 44 | |
| 45 | #include <stdlib.h> |
| 46 | #include <errno.h> |
| 47 | |
| 46 | 48 | |
| 49 | #if defined(ZIG_OS_POSIX) |
| 47 | 50 | static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args, int *return_code) { |
| 48 | 51 | pid_t pid = fork(); |
| 49 | 52 | if (pid == -1) |
| ... | ... | @@ -63,6 +66,7 @@ static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args, |
| 63 | 66 | waitpid(pid, return_code, 0); |
| 64 | 67 | } |
| 65 | 68 | } |
| 69 | #endif |
| 66 | 70 | |
| 67 | 71 | #if defined(ZIG_OS_WINDOWS) |
| 68 | 72 | static void os_spawn_process_windows(const char *exe, ZigList<const char *> &args, int *return_code) { |
| ... | ... | @@ -106,6 +110,9 @@ void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path) { |
| 106 | 110 | } |
| 107 | 111 | |
| 108 | 112 | int os_path_real(Buf *rel_path, Buf *out_abs_path) { |
| 113 | #if defined(ZIG_OS_WINDOWS) |
| 114 | zig_panic("TODO os_path_real for windows"); |
| 115 | #elif defined(ZIG_OS_POSIX) |
| 109 | 116 | buf_resize(out_abs_path, PATH_MAX + 1); |
| 110 | 117 | char *result = realpath(buf_ptr(rel_path), buf_ptr(out_abs_path)); |
| 111 | 118 | if (!result) { |
| ... | ... | @@ -122,6 +129,9 @@ int os_path_real(Buf *rel_path, Buf *out_abs_path) { |
| 122 | 129 | } |
| 123 | 130 | buf_resize(out_abs_path, strlen(buf_ptr(out_abs_path))); |
| 124 | 131 | return ErrorNone; |
| 132 | #else |
| 133 | #error "missing os_path_real implementation" |
| 134 | #endif |
| 125 | 135 | } |
| 126 | 136 | |
| 127 | 137 | int os_fetch_file(FILE *f, Buf *out_buf) { |
| ... | ... | @@ -199,6 +209,14 @@ static void os_exec_process_posix(const char *exe, ZigList<const char *> &args, |
| 199 | 209 | } |
| 200 | 210 | #endif |
| 201 | 211 | |
| 212 | #if defined(ZIG_OS_WINDOWS) |
| 213 | static void os_exec_process_windows(const char *exe, ZigList<const char *> &args, |
| 214 | int *return_code, Buf *out_stderr, Buf *out_stdout) |
| 215 | { |
| 216 | zig_panic("TODO implement os_exec_process_windows"); |
| 217 | } |
| 218 | #endif |
| 219 | |
| 202 | 220 | void os_exec_process(const char *exe, ZigList<const char *> &args, |
| 203 | 221 | int *return_code, Buf *out_stderr, Buf *out_stdout) |
| 204 | 222 | { |
| ... | ... | @@ -217,7 +235,7 @@ void os_write_file(Buf *full_path, Buf *contents) { |
| 217 | 235 | zig_panic("open failed"); |
| 218 | 236 | } |
| 219 | 237 | size_t amt_written = fwrite(buf_ptr(contents), 1, buf_len(contents), f); |
| 220 | | if (amt_written != buf_len(contents)) |
| 238 | if (amt_written != (size_t)buf_len(contents)) |
| 221 | 239 | zig_panic("write failed: %s", strerror(errno)); |
| 222 | 240 | if (fclose(f)) |
| 223 | 241 | zig_panic("close failed"); |
| ... | ... | @@ -276,7 +294,8 @@ bool os_stderr_tty(void) { |
| 276 | 294 | #endif |
| 277 | 295 | } |
| 278 | 296 | |
| 279 | | int os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path) { |
| 297 | #if defined(ZIG_OS_POSIX) |
| 298 | static int os_buf_to_tmp_file_posix(Buf *contents, Buf *suffix, Buf *out_tmp_path) { |
| 280 | 299 | buf_resize(out_tmp_path, 0); |
| 281 | 300 | buf_appendf(out_tmp_path, "/tmp/XXXXXX%s", buf_ptr(suffix)); |
| 282 | 301 | |
| ... | ... | @@ -298,6 +317,23 @@ int os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path) { |
| 298 | 317 | |
| 299 | 318 | return 0; |
| 300 | 319 | } |
| 320 | #endif |
| 321 | |
| 322 | #if defined(ZIG_OS_WINDOWS) |
| 323 | static int os_buf_to_tmp_file_windows(Buf *contents, Buf *suffix, Buf *out_tmp_path) { |
| 324 | zig_panic("TODO implement os_buf_to_tmp_file_windows"); |
| 325 | } |
| 326 | #endif |
| 327 | |
| 328 | int os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path) { |
| 329 | #if defined(ZIG_OS_WINDOWS) |
| 330 | return os_buf_to_tmp_file_windows(contents, suffix, out_tmp_path); |
| 331 | #elif defined(ZIG_OS_POSIX) |
| 332 | return os_buf_to_tmp_file_posix(contents, suffix, out_tmp_path); |
| 333 | #else |
| 334 | #error "missing os_buf_to_tmp_file implementation" |
| 335 | #endif |
| 336 | } |
| 301 | 337 | |
| 302 | 338 | int os_delete_file(Buf *path) { |
| 303 | 339 | if (remove(buf_ptr(path))) { |