ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
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 <stdbool.h>
23#include <stdio.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
37typedef struct {
40 FILE *output;
41} log_io_t;
42
56
70void log_io_stop(log_io_t capture, const char *prefix);
71
95#define LOG_IO_IF(condition, prefix, block) \
96 do { \
97 bool _log_io_enabled = (condition); \
98 log_io_t _log_io = {0}; \
99 if (_log_io_enabled) \
100 _log_io = log_io_start(); \
101 block; \
102 if (_log_io_enabled) \
103 log_io_stop(_log_io, (prefix)); \
104 } while (asciichat_macro_block_continue())
105
106#define LOG_IO(prefix, block) LOG_IO_IF(true, prefix, block)
107
108#ifdef __cplusplus
109}
110#endif
log_io_t log_io_start(void)
Start capturing stdout and stderr.
Definition io.c:20
void log_io_stop(log_io_t capture, const char *prefix)
Stop capturing and log the accumulated output.
Definition io.c:63
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