authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-16 19:55:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-16 19:55:49-07:00
logafa5d1ea1223b8eab475c4186faed4385ac95da0
tree7cc4aaf850316ef15bc10bca0c610a67be274bbd
parent194e93a5824309d2eb8bf90b50b9ad4262f1f7ce

os: fix ability to compile for windows


1 files changed, 39 insertions(+), 3 deletions(-)

src/os.cpp+39-3
......@@ -34,7 +34,6 @@
3434#define ZIG_OS_POSIX
3535
3636#include <unistd.h>
37#include <errno.h>
3837#include <sys/types.h>
3938#include <sys/stat.h>
4039#include <sys/wait.h>
......@@ -43,7 +42,11 @@
4342
4443#endif
4544
45#include <stdlib.h>
46#include <errno.h>
47
4648
49#if defined(ZIG_OS_POSIX)
4750static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args, int *return_code) {
4851 pid_t pid = fork();
4952 if (pid == -1)
......@@ -63,6 +66,7 @@ static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args,
6366 waitpid(pid, return_code, 0);
6467 }
6568}
69#endif
6670
6771#if defined(ZIG_OS_WINDOWS)
6872static 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) {
106110}
107111
108112int 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)
109116 buf_resize(out_abs_path, PATH_MAX + 1);
110117 char *result = realpath(buf_ptr(rel_path), buf_ptr(out_abs_path));
111118 if (!result) {
......@@ -122,6 +129,9 @@ int os_path_real(Buf *rel_path, Buf *out_abs_path) {
122129 }
123130 buf_resize(out_abs_path, strlen(buf_ptr(out_abs_path)));
124131 return ErrorNone;
132#else
133#error "missing os_path_real implementation"
134#endif
125135}
126136
127137int 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,
199209}
200210#endif
201211
212#if defined(ZIG_OS_WINDOWS)
213static 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
202220void os_exec_process(const char *exe, ZigList<const char *> &args,
203221 int *return_code, Buf *out_stderr, Buf *out_stdout)
204222{
......@@ -217,7 +235,7 @@ void os_write_file(Buf *full_path, Buf *contents) {
217235 zig_panic("open failed");
218236 }
219237 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))
221239 zig_panic("write failed: %s", strerror(errno));
222240 if (fclose(f))
223241 zig_panic("close failed");
......@@ -276,7 +294,8 @@ bool os_stderr_tty(void) {
276294#endif
277295}
278296
279int os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path) {
297#if defined(ZIG_OS_POSIX)
298static int os_buf_to_tmp_file_posix(Buf *contents, Buf *suffix, Buf *out_tmp_path) {
280299 buf_resize(out_tmp_path, 0);
281300 buf_appendf(out_tmp_path, "/tmp/XXXXXX%s", buf_ptr(suffix));
282301
......@@ -298,6 +317,23 @@ int os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path) {
298317
299318 return 0;
300319}
320#endif
321
322#if defined(ZIG_OS_WINDOWS)
323static 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
328int 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}
301337
302338int os_delete_file(Buf *path) {
303339 if (remove(buf_ptr(path))) {