ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1
19
20#pragma once
21
22#include <stdio.h>
23#include <stdbool.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
37typedef struct {
40 FILE *output;
41} log_io_t;
42
56
69void log_io_stop(log_io_t capture, const char *prefix);
70
93#define LOG_IO_IF(condition, prefix, block) \
94 do { \
95 bool _log_io_enabled = (condition); \
96 log_io_t _log_io = {0}; \
97 if (_log_io_enabled) \
98 _log_io = log_io_start(); \
99 block; \
100 if (_log_io_enabled) \
101 log_io_stop(_log_io, (prefix)); \
102 } while (0)
103
104#define LOG_IO(prefix, block) LOG_IO_IF(true, prefix, block)
105
106#ifdef __cplusplus
107}
108#endif
log_io_t log_io_start(void)
Start capturing stdout and stderr.
Definition io.c:15
void log_io_stop(log_io_t capture, const char *prefix)
Stop capturing and log the accumulated output.
Definition io.c:50
Saved descriptors and temporary file used during stdout/stderr capture.
Definition io.h:37
FILE * output
Temporary capture file, deleted on close.
Definition io.h:40
int saved_stdout_fd
Saved stdout file descriptor.
Definition io.h:38
int saved_stderr_fd
Saved stderr file descriptor.
Definition io.h:39