diff --git a/pkg/urbit/compat/mingw/compat.c b/pkg/urbit/compat/mingw/compat.c index 1fe0c97254..3ab9029b67 100644 --- a/pkg/urbit/compat/mingw/compat.c +++ b/pkg/urbit/compat/mingw/compat.c @@ -1,7 +1,13 @@ #include "c/portable.h" +#include #include #include +// set default CRT file mode to binary +// note that mingw binmode.o does nothing +#undef _fmode +int _fmode = _O_BINARY; + // from https://github.com/git/git/blob/master/compat/mingw.c // ----------------------------------------------------------------------- diff --git a/pkg/urbit/include/c/portable.h b/pkg/urbit/include/c/portable.h index 3700a8065a..5c675a926d 100644 --- a/pkg/urbit/include/c/portable.h +++ b/pkg/urbit/include/c/portable.h @@ -92,10 +92,6 @@ #error "port: headers" # endif -# ifndef O_BINARY -# define O_BINARY 0 -# endif - # ifndef __has_feature # define __has_feature(x) 0 # endif diff --git a/pkg/urbit/noun/events.c b/pkg/urbit/noun/events.c index 0085df8ed7..224eb86d9c 100644 --- a/pkg/urbit/noun/events.c +++ b/pkg/urbit/noun/events.c @@ -170,7 +170,7 @@ u3e_fault(void* adr_v, c3_i ser_i) static c3_o _ce_image_open(u3e_image* img_u) { - c3_i mod_i = O_RDWR | O_BINARY | O_CREAT; + c3_i mod_i = O_RDWR | O_CREAT; c3_c ful_c[8193]; snprintf(ful_c, 8192, "%s", u3P.dir_c); @@ -274,13 +274,13 @@ _ce_patch_create(u3_ce_patch* pat_u) mkdir(ful_c, 0700); snprintf(ful_c, 8192, "%s/.urb/chk/control.bin", u3P.dir_c); - if ( -1 == (pat_u->ctl_i = open(ful_c, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600)) ) { + if ( -1 == (pat_u->ctl_i = open(ful_c, O_RDWR | O_CREAT | O_EXCL, 0600)) ) { fprintf(stderr, "loom: patch open control.bin: %s\r\n", strerror(errno)); c3_assert(0); } snprintf(ful_c, 8192, "%s/.urb/chk/memory.bin", u3P.dir_c); - if ( -1 == (pat_u->mem_i = open(ful_c, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600)) ) { + if ( -1 == (pat_u->mem_i = open(ful_c, O_RDWR | O_CREAT | O_EXCL, 0600)) ) { fprintf(stderr, "loom: patch open memory.bin: %s\r\n", strerror(errno)); c3_assert(0); } @@ -376,12 +376,12 @@ _ce_patch_open(void) mkdir(ful_c, 0700); snprintf(ful_c, 8192, "%s/.urb/chk/control.bin", u3P.dir_c); - if ( -1 == (ctl_i = open(ful_c, O_RDWR | O_BINARY)) ) { + if ( -1 == (ctl_i = open(ful_c, O_RDWR)) ) { return 0; } snprintf(ful_c, 8192, "%s/.urb/chk/memory.bin", u3P.dir_c); - if ( -1 == (mem_i = open(ful_c, O_RDWR | O_BINARY)) ) { + if ( -1 == (mem_i = open(ful_c, O_RDWR)) ) { close(ctl_i); _ce_patch_delete(); diff --git a/pkg/urbit/noun/manage.c b/pkg/urbit/noun/manage.c index 9c7abdcbce..5fd1c82aea 100644 --- a/pkg/urbit/noun/manage.c +++ b/pkg/urbit/noun/manage.c @@ -411,7 +411,7 @@ u3_noun u3m_file(c3_c* pas_c) { struct stat buf_b; - c3_i fid_i = open(pas_c, O_RDONLY | O_BINARY, 0644); + c3_i fid_i = open(pas_c, O_RDONLY, 0644); c3_w fln_w, red_w; c3_y* pad_y; diff --git a/pkg/urbit/noun/trace.c b/pkg/urbit/noun/trace.c index 2b53ae9388..1ee8168c70 100644 --- a/pkg/urbit/noun/trace.c +++ b/pkg/urbit/noun/trace.c @@ -288,7 +288,7 @@ u3t_trace_open(c3_c* dir_c) c3_c lif_c[2056]; snprintf(lif_c, 2056, "%s/%d.json", fil_c, u3_Host.tra_u.fun_w); - u3_Host.tra_u.fil_u = fopen(lif_c, "wb"); + u3_Host.tra_u.fil_u = fopen(lif_c, "w"); u3_Host.tra_u.nid_w = (int)getpid(); fprintf(u3_Host.tra_u.fil_u, "[ "); diff --git a/pkg/urbit/noun/urth.c b/pkg/urbit/noun/urth.c index 8fc0b33145..c92a7d3dad 100644 --- a/pkg/urbit/noun/urth.c +++ b/pkg/urbit/noun/urth.c @@ -549,7 +549,7 @@ _cu_rock_save(c3_c* dir_c, c3_d eve_d, c3_d len_d, c3_y* byt_y) return c3n; } - if ( -1 == (fid_i = open(nam_c, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, 0644)) ) { + if ( -1 == (fid_i = open(nam_c, O_RDWR | O_CREAT | O_TRUNC, 0644)) ) { fprintf(stderr, "rock: open failed (%s, %" PRIu64 "): %s\r\n", dir_c, eve_d, strerror(errno)); c3_free(nam_c); @@ -688,7 +688,7 @@ u3u_mmap_read(c3_c* cap_c, c3_c* pat_c, c3_d* out_d, c3_y** out_y) // open file // - if ( -1 == (fid_i = open(pat_c, O_RDONLY | O_BINARY, 0644)) ) { + if ( -1 == (fid_i = open(pat_c, O_RDONLY, 0644)) ) { fprintf(stderr, "%s: open failed (%s): %s\r\n", cap_c, pat_c, strerror(errno)); return c3n; @@ -741,7 +741,7 @@ u3u_mmap(c3_c* cap_c, c3_c* pat_c, c3_d len_d, c3_y** out_y) // open file // - if ( -1 == (fid_i = open(pat_c, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, 0644)) ) { + if ( -1 == (fid_i = open(pat_c, O_RDWR | O_CREAT | O_TRUNC, 0644)) ) { fprintf(stderr, "%s: open failed (%s): %s\r\n", cap_c, pat_c, strerror(errno)); return c3n; diff --git a/pkg/urbit/vere/dawn.c b/pkg/urbit/vere/dawn.c index a7663235b3..349999102a 100644 --- a/pkg/urbit/vere/dawn.c +++ b/pkg/urbit/vere/dawn.c @@ -520,7 +520,7 @@ _dawn_come(u3_noun stars) c3_c pat_c[64]; snprintf(pat_c, 64, "%s.key", who_c + 1); - FILE* fil_u = fopen(pat_c, "wb"); + FILE* fil_u = fopen(pat_c, "w"); fprintf(fil_u, "%s\n", key_c); fclose(fil_u); } diff --git a/pkg/urbit/vere/io/http.c b/pkg/urbit/vere/io/http.c index e9a7c7d9e4..4e8e2e6d43 100644 --- a/pkg/urbit/vere/io/http.c +++ b/pkg/urbit/vere/io/http.c @@ -1600,7 +1600,7 @@ _http_write_ports_file(u3_httd* htd_u, c3_c *pax_c) c3_c* paf_c = c3_malloc(len_w); snprintf(paf_c, len_w, "%s/%s", pax_c, nam_c); - c3_i por_i = open(paf_c, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, 0666); + c3_i por_i = open(paf_c, O_WRONLY | O_CREAT | O_TRUNC, 0666); c3_free(paf_c); u3_http* htp_u = htd_u->htp_u; diff --git a/pkg/urbit/vere/io/unix.c b/pkg/urbit/vere/io/unix.c index 2885686c4a..a485d5115b 100644 --- a/pkg/urbit/vere/io/unix.c +++ b/pkg/urbit/vere/io/unix.c @@ -225,7 +225,7 @@ _unix_mkdir(c3_c* pax_c) static c3_w _unix_write_file_hard(c3_c* pax_c, u3_noun mim) { - c3_i fid_i = open(pax_c, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, 0666); + c3_i fid_i = open(pax_c, O_WRONLY | O_CREAT | O_TRUNC, 0666); c3_w len_w, rit_w, siz_w, mug_w = 0; c3_y* dat_y; @@ -268,7 +268,7 @@ static void _unix_write_file_soft(u3_ufil* fil_u, u3_noun mim) { struct stat buf_u; - c3_i fid_i = open(fil_u->pax_c, O_RDONLY | O_BINARY, 0644); + c3_i fid_i = open(fil_u->pax_c, O_RDONLY, 0644); c3_ws len_ws, red_ws; c3_w old_w; c3_y* old_y; @@ -692,7 +692,7 @@ _unix_update_file(u3_unix* unx_u, u3_ufil* fil_u) fil_u->dry = c3n; struct stat buf_u; - c3_i fid_i = open(fil_u->pax_c, O_RDONLY | O_BINARY, 0644); + c3_i fid_i = open(fil_u->pax_c, O_RDONLY, 0644); c3_ws len_ws, red_ws; c3_y* dat_y; @@ -795,7 +795,7 @@ _unix_update_dir(u3_unix* unx_u, u3_udir* dir_u) } else { struct stat buf_u; - c3_i fid_i = open(nod_u->pax_c, O_RDONLY | O_BINARY, 0644); + c3_i fid_i = open(nod_u->pax_c, O_RDONLY, 0644); if ( (fid_i < 0) || (fstat(fid_i, &buf_u) < 0) ) { if ( ENOENT != errno ) { @@ -965,7 +965,7 @@ static u3_noun _unix_initial_update_file(c3_c* pax_c, c3_c* bas_c) { struct stat buf_u; - c3_i fid_i = open(pax_c, O_RDONLY | O_BINARY, 0644); + c3_i fid_i = open(pax_c, O_RDONLY, 0644); c3_ws len_ws, red_ws; c3_y* dat_y; @@ -1281,7 +1281,7 @@ u3_unix_acquire(c3_c* pax_c) c3_w pid_w; FILE* loq_u; - if ( NULL != (loq_u = fopen(paf_c, "rb")) ) { + if ( NULL != (loq_u = fopen(paf_c, "r")) ) { if ( 1 != fscanf(loq_u, "%" SCNu32, &pid_w) ) { u3l_log("lockfile %s is corrupt!\n", paf_c); kill(getpid(), SIGTERM); @@ -1319,7 +1319,7 @@ u3_unix_acquire(c3_c* pax_c) unlink(paf_c); } - if ( NULL == (loq_u = fopen(paf_c, "wb")) ) { + if ( NULL == (loq_u = fopen(paf_c, "w")) ) { u3l_log("unix: unable to open %s\n", paf_c); c3_assert(0); } diff --git a/pkg/urbit/vere/king.c b/pkg/urbit/vere/king.c index bf6adea698..bc65fc7e85 100644 --- a/pkg/urbit/vere/king.c +++ b/pkg/urbit/vere/king.c @@ -916,7 +916,7 @@ u3_king_grab(void* vod_p) c3_c man_c[2048]; snprintf(man_c, 2048, "%s/%s-daemon.txt", nam_c, wen_c); - fil_u = fopen(man_c, "wb"); + fil_u = fopen(man_c, "w"); fprintf(fil_u, "%s\r\n", wen_c); c3_free(wen_c); diff --git a/pkg/urbit/vere/walk.c b/pkg/urbit/vere/walk.c index 4d03f12bdd..5c113cbac7 100644 --- a/pkg/urbit/vere/walk.c +++ b/pkg/urbit/vere/walk.c @@ -32,7 +32,7 @@ u3_noun u3_walk_safe(c3_c* pas_c) { struct stat buf_b; - c3_i fid_i = open(pas_c, O_RDONLY | O_BINARY, 0644); + c3_i fid_i = open(pas_c, O_RDONLY, 0644); c3_w fln_w, red_w; c3_y* pad_y; @@ -64,7 +64,7 @@ u3_noun u3_walk_load(c3_c* pas_c) { struct stat buf_b; - c3_i fid_i = open(pas_c, O_RDONLY | O_BINARY, 0644); + c3_i fid_i = open(pas_c, O_RDONLY, 0644); c3_w fln_w, red_w; c3_y* pad_y; @@ -130,7 +130,7 @@ _walk_mkdirp(c3_c* bas_c, u3_noun pax) void u3_walk_save(c3_c* pas_c, u3_noun tim, u3_atom pad, c3_c* bas_c, u3_noun pax) { - c3_i fid_i = open(pas_c, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, 0666); + c3_i fid_i = open(pas_c, O_WRONLY | O_CREAT | O_TRUNC, 0666); c3_w fln_w, rit_w; c3_y* pad_y; diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index c1cff83ea0..8c4001d8d8 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -130,7 +130,7 @@ _cw_serf_stdio(c3_i* inn_i, c3_i* out_i) // we replace [FD 0] (stdin) with a fd pointing to /dev/null // we replace [FD 1] (stdout) with a dup of [FD 2] (stderr) // - c3_i nul_i = open("/dev/null", O_RDWR | O_BINARY, 0); + c3_i nul_i = open("/dev/null", O_RDWR, 0); *inn_i = dup(0); *out_i = dup(1); diff --git a/pkg/urbit/worker/serf.c b/pkg/urbit/worker/serf.c index 2376d8e48a..8ed603b90f 100644 --- a/pkg/urbit/worker/serf.c +++ b/pkg/urbit/worker/serf.c @@ -210,7 +210,7 @@ _serf_grab(u3_serf* sef_u) c3_c man_c[2054]; snprintf(man_c, 2053, "%s/%s-serf.txt", nam_c, wen_c); - fil_u = fopen(man_c, "wb"); + fil_u = fopen(man_c, "w"); fprintf(fil_u, "%s\r\n", wen_c); c3_free(wen_c); @@ -809,7 +809,7 @@ _serf_writ_live_exit(u3_serf* sef_u, c3_w cod_w) c3_c man_c[2054]; snprintf(man_c, 2053, "%s/%s.txt", nam_c, wen_c); - fil_u = fopen(man_c, "wb"); + fil_u = fopen(man_c, "w"); c3_free(wen_c); u3z(wen);