From b1a12236ade61dde06100db7693a46c5d3eb58a3 Mon Sep 17 00:00:00 2001 From: bgermann Date: Wed, 29 Aug 2018 23:59:11 +0200 Subject: [PATCH] Convert from statfs to more portable statvfs [INTERPRETER] * NEW: Convert from statfs to more portable statvfs --- main/gbx/gbx_c_file.c | 8 ++++---- main/gbx/gbx_stream.c | 4 ++-- main/gbx/gbx_stream.h | 6 +++--- main/gbx/gbx_stream_buffer.c | 4 ++-- main/gbx/gbx_stream_direct.c | 8 ++++---- main/gbx/gbx_stream_memory.c | 2 +- main/gbx/gbx_stream_pipe.c | 2 +- main/gbx/gbx_stream_string.c | 2 +- main/gbx/gbx_subr_file.c | 2 +- main/share/gb_file_temp.h | 10 +++------- 10 files changed, 22 insertions(+), 26 deletions(-) diff --git a/main/gbx/gbx_c_file.c b/main/gbx/gbx_c_file.c index aeb3447e8..a849e2102 100644 --- a/main/gbx/gbx_c_file.c +++ b/main/gbx/gbx_c_file.c @@ -98,7 +98,7 @@ static void watch_stream(CSTREAM *_object, int mode, bool on) if (mode & ST_READ) GB_Watch(fd, GB_WATCH_READ, (void *)(on ? callback_read : NULL), (intptr_t)THIS); - if (mode & ST_WRITE) + if (mode & ST_WRIT) GB_Watch(fd, GB_WATCH_WRITE, (void *)(on ? callback_write : NULL), (intptr_t)THIS); } @@ -143,8 +143,8 @@ static CFILE *create_default_stream(FILE *file, int mode) void CFILE_init(void) { CFILE_in = create_default_stream(stdin, ST_READ); - CFILE_out = create_default_stream(stdout, ST_WRITE); - CFILE_err = create_default_stream(stderr, ST_WRITE); + CFILE_out = create_default_stream(stdout, ST_WRIT); + CFILE_err = create_default_stream(stderr, ST_WRIT); } void CFILE_exit(void) @@ -860,7 +860,7 @@ BEGIN_METHOD(Stream_Watch, GB_INTEGER mode; GB_BOOLEAN on) if (mode == R_OK) mode = ST_READ; else if (mode == W_OK) - mode = ST_WRITE; + mode = ST_WRIT; else { GB_Error("Unknown watch"); diff --git a/main/gbx/gbx_stream.c b/main/gbx/gbx_stream.c index e2797eedd..8c014a3df 100644 --- a/main/gbx/gbx_stream.c +++ b/main/gbx/gbx_stream.c @@ -956,7 +956,7 @@ static STREAM *enter_temp_stream(STREAM *stream) _temp_level = 0; if (_temp_stream.type) STREAM_close(&_temp_stream); - STREAM_open(&_temp_stream, NULL, ST_STRING | ST_WRITE); + STREAM_open(&_temp_stream, NULL, ST_STRING | ST_WRIT); } _temp_level++; @@ -1807,7 +1807,7 @@ void STREAM_begin(STREAM *stream) if (!stream->common.redirect) { ALLOC_ZERO(&stream->common.redirect, sizeof(STREAM)); - STREAM_open(stream->common.redirect, NULL, ST_STRING | ST_WRITE); + STREAM_open(stream->common.redirect, NULL, ST_STRING | ST_WRIT); } stream->common.redirected = TRUE; diff --git a/main/gbx/gbx_stream.h b/main/gbx/gbx_stream.h index 679c1b76c..fa08eac1a 100644 --- a/main/gbx/gbx_stream.h +++ b/main/gbx/gbx_stream.h @@ -146,10 +146,10 @@ typedef enum { ST_READ = (1 << 0), - ST_WRITE = (1 << 1), - ST_READ_WRITE = ST_READ + ST_WRITE, + ST_WRIT = (1 << 1), + ST_READ_WRITE = ST_READ + ST_WRIT, ST_MODE = 0x3, - ST_APPEND = (1 << 2), + ST_APPENDING = (1 << 2), ST_CREATE = (1 << 3), ST_ACCESS = 0xF, ST_DIRECT = (1 << 4), diff --git a/main/gbx/gbx_stream_buffer.c b/main/gbx/gbx_stream_buffer.c index 3f702f13a..727c37d53 100644 --- a/main/gbx/gbx_stream_buffer.c +++ b/main/gbx/gbx_stream_buffer.c @@ -51,9 +51,9 @@ static int stream_open(STREAM *stream, const char *path, int mode) if (mode & ST_CREATE) fmode = "w+"; - else if (mode & ST_APPEND) + else if (mode & ST_APPENDING) fmode = "a+"; - else if (mode & ST_WRITE) + else if (mode & ST_WRIT) fmode = "r+"; else fmode = "r"; diff --git a/main/gbx/gbx_stream_direct.c b/main/gbx/gbx_stream_direct.c index c0ef4983d..a870280ea 100644 --- a/main/gbx/gbx_stream_direct.c +++ b/main/gbx/gbx_stream_direct.c @@ -51,7 +51,7 @@ static int stream_open(STREAM *stream, const char *path, int mode) if (mode & ST_CREATE) fmode = O_CREAT | O_TRUNC; // | O_EXCL; - else if (mode & ST_APPEND) + else if (mode & ST_APPENDING) fmode = O_APPEND | O_CREAT; else fmode = 0; @@ -59,14 +59,14 @@ static int stream_open(STREAM *stream, const char *path, int mode) switch (mode & ST_MODE) { case ST_READ: fmode |= O_RDONLY; break; - case ST_WRITE: fmode |= O_WRONLY; break; + case ST_WRIT: fmode |= O_WRONLY; break; case ST_READ_WRITE: fmode |= O_RDWR; break; default: fmode |= O_RDONLY; } if (path[0] == '.' && isdigit(path[1])) { - if ((mode & ST_CREATE) || (mode & ST_APPEND)) + if ((mode & ST_CREATE) || (mode & ST_APPENDING)) THROW(E_ACCESS); if (NUMBER_from_string(NB_READ_INTEGER, &path[1], strlen(path) - 1, &val) || val._integer.value < 0) @@ -81,7 +81,7 @@ static int stream_open(STREAM *stream, const char *path, int mode) return TRUE; if (((mode & ST_MODE) == ST_READ && (omode & O_ACCMODE) == O_WRONLY) - || ((mode & ST_MODE) == ST_WRITE && (omode & O_ACCMODE) == O_RDONLY) + || ((mode & ST_MODE) == ST_WRIT && (omode & O_ACCMODE) == O_RDONLY) || ((mode & ST_MODE) == ST_READ_WRITE && (omode & O_ACCMODE) != O_RDWR)) THROW(E_ACCESS); diff --git a/main/gbx/gbx_stream_memory.c b/main/gbx/gbx_stream_memory.c index 57d52e51e..ae7312c82 100644 --- a/main/gbx/gbx_stream_memory.c +++ b/main/gbx/gbx_stream_memory.c @@ -96,7 +96,7 @@ static int stream_read(STREAM *stream, char *buffer, int len) static int stream_write(STREAM *stream, char *buffer, int len) { - if ((stream->common.mode & ST_WRITE) == 0) + if ((stream->common.mode & ST_WRIT) == 0) THROW(E_ACCESS); CHECK_enter(); diff --git a/main/gbx/gbx_stream_pipe.c b/main/gbx/gbx_stream_pipe.c index f0db2c9f3..7cc475dbd 100644 --- a/main/gbx/gbx_stream_pipe.c +++ b/main/gbx/gbx_stream_pipe.c @@ -57,7 +57,7 @@ static int stream_open(STREAM *stream, const char *path, int mode) switch (mode & ST_MODE) { case ST_READ: fmode |= O_RDONLY; break; - case ST_WRITE: fmode |= O_WRONLY; break; + case ST_WRIT: fmode |= O_WRONLY; break; case ST_READ_WRITE: fmode |= O_RDWR; break; default: fmode |= O_RDONLY; } diff --git a/main/gbx/gbx_stream_string.c b/main/gbx/gbx_stream_string.c index f556955ca..e7ce1a0a7 100644 --- a/main/gbx/gbx_stream_string.c +++ b/main/gbx/gbx_stream_string.c @@ -81,7 +81,7 @@ static int stream_read(STREAM *stream, char *buffer, int len) static int stream_write(STREAM *stream, char *buffer, int len) { - if ((stream->common.mode & ST_WRITE) == 0) + if ((stream->common.mode & ST_WRIT) == 0) THROW(E_ACCESS); stream->string.buffer = STRING_add(stream->string.buffer, buffer, len); diff --git a/main/gbx/gbx_subr_file.c b/main/gbx/gbx_subr_file.c index 8f35a2b8c..14fb8a71c 100755 --- a/main/gbx/gbx_subr_file.c +++ b/main/gbx/gbx_subr_file.c @@ -225,7 +225,7 @@ void SUBR_open(ushort code) { str = SUBR_get_string(PARAM); - if (mode & ST_WRITE) + if (mode & ST_WRIT) { stream.string.buffer = STRING_new(str, STRING_length(str)); } diff --git a/main/share/gb_file_temp.h b/main/share/gb_file_temp.h index 72165a44d..d7edb01a8 100644 --- a/main/share/gb_file_temp.h +++ b/main/share/gb_file_temp.h @@ -39,11 +39,7 @@ #ifdef PROJECT_EXEC -#if defined(OS_FREEBSD) || defined(OS_OPENBSD) -#include -#else -#include -#endif +#include #include #include @@ -1082,12 +1078,12 @@ void FILE_link(const char *src, const char *dst) int64_t FILE_free(const char *path) { - struct statfs info; + struct statvfs info; if (FILE_is_relative(path)) return 0; - statfs(path, &info); + statvfs(path, &info); return (int64_t)(getuid() == 0 ? info.f_bfree : info.f_bavail) * info.f_bsize; }