Function
audit_write
Send standard input to the sandbox.
Since v1.0
int audit_write(
FILE *stream,
const void *buf,
int count)
Parameters 🔗
stream | in | Must be |
buf | in | Byte data to write to stream. |
count | in | Size in bytes of buf. |
Return Value 🔗
Number of bytes written to buf or a negative integer on error.
Discussion 🔗
Writes binary data to standard input. If you need to write a null-terminated string, then you must include the null terminator yourself.
Some standard C functions, like fgets
, will block until they read a new line character or EOF (end-of-file). If the data you've written does not include a new line character, then you can send EOF by calling audit_close.
When authoring tests that read from standard input, it is recommend to set a timeout to ensure if the code hangs while reading, that the test case itself is aborted after the timeout has elapsed.
// Write textual data to stdin for the code being
// tested to read.
audit_write(stdin, "Hello, world!", 13);
// Now begin testing some code that reads from stdin.
// Here, we'll call read() for demonstration purposes.
char buf[16]
int len = read(fileno(stdin), buf, sizeof(buf));