Convert from statfs to more portable statvfs
[INTERPRETER] * NEW: Convert from statfs to more portable statvfs
This commit is contained in:
parent
9e98045363
commit
b1a12236ad
10 changed files with 22 additions and 26 deletions
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -39,11 +39,7 @@
|
|||
|
||||
#ifdef PROJECT_EXEC
|
||||
|
||||
#if defined(OS_FREEBSD) || defined(OS_OPENBSD)
|
||||
#include <sys/mount.h>
|
||||
#else
|
||||
#include <sys/statfs.h>
|
||||
#endif
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <grp.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue