Function

audit_read

Retrieve captured standard stream output.

Since v1.0
int audit_read(
FILE *stream, void *buf, int count)

Parameters 🔗

stream in

Must be stdout or stderr.

buf in

Destination buffer of NULL.

count in

Size in bytes of buf or 0 if buf is NULL.

Return Value 🔗

Number of bytes written to buf or a negative integer on error.

Discussion 🔗

Reads binary data from the standard stream stream. Note that this function reads raw bytes. If you're reading a string, then you must null terminate buf yourself.

// Begin testing some code that writes to stdout or stderr.
// Here, we'll write to stdout for demonstration purposes.
fprintf(stdout, "Hello!");

// Back in the test case, read what was written to stdout
// and verify it matches what we expected.
char buf[16];
int len = audit_read(stdout, buf, sizeof(buf));
ASSERT_MEM_EQ(buf, "Hello!", len, 6);