File: test_standalone_syscalls.cpp

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 121,860 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,366; asm: 2,415; lisp: 1,869
file content (45 lines) | stat: -rw-r--r-- 1,150 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <assert.h>
#include <emscripten.h>
#include <emscripten/html5.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

int main() {
  // open of standard streams works.
  int fd_in = open("/dev/stdin", 0);
  assert(fd_in == 0);
  int fd_out = open("/dev/stdout", 0);
  assert(fd_out == 1);
  int fd_err = open("/dev/stderr", 0);
  assert(fd_err == 2);

  // ioctl and fcntl fail
  int i = ioctl(1, 0);
  assert(i < 0);
  int f = fcntl(1, 0);
  assert(f < 0);

  // write to standard streams works.
  write(1, "hello, world!", 5);
  write(1, "\n", 1);

  // emscripten_log API works
  emscripten_console_log("log");
  // warnings/errors go to stderr
  emscripten_console_warn("warn");
  emscripten_console_error("error");
  emscripten_console_log("log2");

  // check we can call this, but the test doesn't check the output
  emscripten_get_now();

  // This doesn't do anything because we have no handler registered, but it
  // verifies that `raise` can be included in the build without any non-standard
  // imports being generated.
  raise(SIGCHLD);
  return 0;
}