Derive-C
Loading...
Searching...
No Matches
null_stream.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <stdio.h>
6#include <sys/types.h>
7
8#if !defined _GNU_SOURCE
9 #error "gnu source must be defined (is in the src/derive-c CMakeLists.txt) to use cookie io"
10#endif
11
12DC_PUBLIC static FILE* dc_null_stream(void) {
13 cookie_io_functions_t io = {
14 .read = NULL,
15 .write = NULL,
16 .seek = NULL,
17 .close = NULL,
18 };
19
20 FILE* f = fopencookie(NULL, "w", io);
21 DC_ASSERT(f, "received nullptr from fopencookie");
22
23 // Set io as unbuffered
24 DC_ASSERT(setvbuf(f, NULL, _IONBF, 0) == 0, "setvbuf failed");
25
26 return f;
27}
#define DC_PUBLIC
Definition namespace.h:25
static DC_PUBLIC FILE * dc_null_stream(void)
Definition null_stream.h:12
#define DC_ASSERT(expr,...)
Definition panic.h:37