aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-07-19 21:55:58 +0300
committermax99x <max99x@gmail.com>2011-07-19 21:55:58 +0300
commit51df7dfe82125f8772b1c998121fbbf6e3cdab80 (patch)
treebba34dcf255c2ab240bb9e6123a8be817bc7dcd1
parent28383aec9e3f762c0ac1ac51acad90c3274aa94f (diff)
Implemented <sys/statvfs.h>.
-rw-r--r--src/library.js37
-rw-r--r--tests/runner.py44
2 files changed, 81 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js
index 226d278d..5ad8dc06 100644
--- a/src/library.js
+++ b/src/library.js
@@ -671,6 +671,43 @@ LibraryManager.library = {
// __01lstat64_: 'stat',
// ==========================================================================
+ // sys/statvfs.h
+ // ==========================================================================
+
+ // TODO: Update this to be auto-created.
+ __statvfs_struct_layout: Runtime.generateStructInfo([
+ 'f_bsize', 'f_frsize', 'f_blocks', 'f_bfree', 'f_bavail', 'f_files',
+ 'f_ffree', 'f_favail', 'f_fsid', '__f_unused', 'f_flag', 'f_namemax',
+ '__f_spare'
+ ], '%struct.statvfs'
+ ),
+ statvfs__deps: ['$FS', '__statvfs_struct_layout'],
+ statvfs: function(path, buf) {
+ // http://pubs.opengroup.org/onlinepubs/7908799/xsh/stat.html
+ // int statvfs(const char *restrict path, struct statvfs *restrict buf);
+ // NOTE: None of the constant here are true. We're just returning safe and
+ // sane values.
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_bsize', '4096', 'i32') }}}
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_frsize', '4096', 'i32') }}}
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_blocks', '1000000', 'i32') }}}
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_bfree', '500000', 'i32') }}}
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_bavail', '500000', 'i32') }}}
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_files', 'FS.nextInode', 'i32') }}}
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_ffree', '1000000', 'i32') }}}
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_favail', '1000000', 'i32') }}}
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_fsid', '42', 'i32') }}}
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_flag', '2', 'i32') }}} // ST_NOSUID
+ {{{ makeSetValue('buf', '___statvfs_struct_layout.f_namemax', '255', 'i32') }}}
+ return 0;
+ },
+ fstatvfs__deps: ['statvfs'],
+ fstatvfs: function(fildes, buf) {
+ // int fstatvfs(int fildes, struct statvfs *buf);
+ // http://pubs.opengroup.org/onlinepubs/009604499/functions/statvfs.html
+ return _statvfs(0, buf);
+ },
+
+ // ==========================================================================
_scanString: function() {
// Supports %x, %4x, %d.%d, %s
diff --git a/tests/runner.py b/tests/runner.py
index 4a738c66..ff90e63b 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2173,6 +2173,50 @@ if 'benchmark' not in sys.argv:
expected = open(path_from_root('tests', 'stat', 'output.txt'), 'r').read()
self.do_test(src, expected, post_build=addPreRun)
+ def test_statvfs(self):
+ src = r'''
+ #include <stdio.h>
+ #include <errno.h>
+ #include <sys/statvfs.h>
+
+ int main() {
+ struct statvfs s;
+
+ printf("result: %d\n", statvfs("/test", &s));
+ printf("errno: %d\n", errno);
+
+ printf("f_bsize: %lu\n", s.f_bsize);
+ printf("f_frsize: %lu\n", s.f_frsize);
+ printf("f_blocks: %lu\n", s.f_blocks);
+ printf("f_bfree: %lu\n", s.f_bfree);
+ printf("f_bavail: %lu\n", s.f_bavail);
+ printf("f_files: %lu\n", s.f_files);
+ printf("f_ffree: %lu\n", s.f_ffree);
+ printf("f_favail: %lu\n", s.f_favail);
+ printf("f_fsid: %lu\n", s.f_fsid);
+ printf("f_flag: %lu\n", s.f_flag);
+ printf("f_namemax: %lu\n", s.f_namemax);
+
+ return 0;
+ }
+ '''
+ expected = r'''
+ result: 0
+ errno: 0
+ f_bsize: 4096
+ f_frsize: 4096
+ f_blocks: 1000000
+ f_bfree: 500000
+ f_bavail: 500000
+ f_files: 2
+ f_ffree: 1000000
+ f_favail: 1000000
+ f_fsid: 42
+ f_flag: 2
+ f_namemax: 255
+ '''
+ self.do_test(src, re.sub('(^|\n)\s+', '\\1', expected))
+
def test_libgen(self):
src = r'''
#include <stdio.h>