clibs
Tiny but handy utility libraries for C
Loading...
Searching...
No Matches
print.h File Reference

Thread-aware printing macros with redirect support. More...

#include <stdio.h>
Include dependency graph for print.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PRINT(fmt, ...)
 Print to output stream (like printf).
#define PERROR(fmt, ...)
 Print to error stream (like fprintf(stderr,...)).
#define PUTS(fmt, ...)
 Print one line to output stream, with newline.
#define PUTERR(fmt, ...)
 Print one line to error stream, with newline.
#define DEBUG_INFO(fmt, ...)
 Print debug message with file and line info.

Functions

void clibs_set_output (FILE *out, FILE *err)
 Sets thread-local output and error streams.
FILE * clibs_get_out (void)
 Gets current output stream (fallback: stdout).
FILE * clibs_get_err (void)
 Gets current error stream (fallback: stderr).

Detailed Description

Thread-aware printing macros with redirect support.

This module provides print macros (like printf, puts) that redirect output to thread-local FILE* streams, with fallback to stdout/stderr. Intended for portable, lock-free console or file printing.

Author
ByteBard

Macro Definition Documentation

◆ DEBUG_INFO

#define DEBUG_INFO ( fmt,
... )
Value:
do { fprintf(clibs_get_err(), "(%s:%d) " fmt "\n", \
__FILE__, __LINE__, ##__VA_ARGS__); } while (0)
FILE * clibs_get_err(void)
Returns the current thread-local error stream.
Definition clibs_logging.c:35

Print debug message with file and line info.

◆ PERROR

#define PERROR ( fmt,
... )
Value:
do { fprintf(clibs_get_err(), fmt, ##__VA_ARGS__); } while (0)

Print to error stream (like fprintf(stderr,...)).

◆ PRINT

#define PRINT ( fmt,
... )
Value:
do { fprintf(clibs_get_out(), fmt, ##__VA_ARGS__); } while (0)
FILE * clibs_get_out(void)
Returns the current thread-local output stream.
Definition clibs_logging.c:31

Print to output stream (like printf).

◆ PUTERR

#define PUTERR ( fmt,
... )
Value:
do { fprintf(clibs_get_err(), fmt "\n", ##__VA_ARGS__); } while (0)

Print one line to error stream, with newline.

◆ PUTS

#define PUTS ( fmt,
... )
Value:
do { fprintf(clibs_get_out(), fmt "\n", ##__VA_ARGS__); } while (0)

Print one line to output stream, with newline.

Function Documentation

◆ clibs_get_err()

FILE * clibs_get_err ( void )

Gets current error stream (fallback: stderr).

Gets current error stream (fallback: stderr).

Falls back to stderr if no thread-local error stream is set.

Returns
FILE* current error stream.

◆ clibs_get_out()

FILE * clibs_get_out ( void )

Gets current output stream (fallback: stdout).

Gets current output stream (fallback: stdout).

Falls back to stdout if no thread-local output stream is set.

Returns
FILE* current output stream.

◆ clibs_set_output()

void clibs_set_output ( FILE * out,
FILE * err )

Sets thread-local output and error streams.

Parameters
outStream for normal output (default: stdout).
errStream for error output (default: stderr).

Sets thread-local output and error streams.

Parameters
outOutput stream for general messages (default fallback: stdout).
errOutput stream for log messages (default fallback: stderr).