aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library.js20
-rwxr-xr-xtests/runner.py19
2 files changed, 39 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js
index 1bdd840d..93d54d68 100644
--- a/src/library.js
+++ b/src/library.js
@@ -5886,6 +5886,26 @@ LibraryManager.library = {
},
// ==========================================================================
+ // sys/timeb.h
+ // ==========================================================================
+
+ __timeb_struct_layout: Runtime.generateStructInfo([
+ ['i32', 'time'],
+ ['i16', 'millitm'],
+ ['i16', 'timezone'],
+ ['i16', 'dstflag']
+ ]),
+ ftime__deps: ['__timeb_struct_layout'],
+ ftime: function(p) {
+ var millis = Date.now();
+ {{{ makeSetValue('p', '___timeb_struct_layout.time', 'Math.floor(millis/1000)', 'i32') }}};
+ {{{ makeSetValue('p', '___timeb_struct_layout.millitm', 'millis % 1000', 'i16') }}};
+ {{{ makeSetValue('p', '___timeb_struct_layout.timezone', '0', 'i16') }}}; // TODO
+ {{{ makeSetValue('p', '___timeb_struct_layout.dstflag', '0', 'i16') }}}; // TODO
+ return 0;
+ },
+
+ // ==========================================================================
// sys/times.h
// ==========================================================================
diff --git a/tests/runner.py b/tests/runner.py
index 63f435b2..ef5c8b68 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -3605,6 +3605,25 @@ The current type of b is: 9
extra_emscripten_args=['-H', 'libc/time.h'])
#extra_emscripten_args=['-H', 'libc/fcntl.h,libc/sys/unistd.h,poll.h,libc/math.h,libc/langinfo.h,libc/time.h'])
+ def test_timeb(self):
+ # Confirms they are called in reverse order
+ src = r'''
+ #include <stdio.h>
+ #include <assert.h>
+ #include <sys/timeb.h>
+
+ int main() {
+ timeb tb;
+ tb.timezone = 1;
+ printf("*%d\n", ftime(&tb));
+ assert(tb.time > 10000);
+ assert(tb.timezone == 0);
+ assert(tb.dstflag == 0);
+ return 0;
+ }
+ '''
+ self.do_run(src, '*0\n')
+
def test_intentional_fault(self):
# Some programs intentionally segfault themselves, we should compile that into a throw
src = r'''