ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
embedded_resources.c File Reference

Embedded resource access implementation. More...

Go to the source code of this file.

Functions

int get_manpage_template (FILE **out_file, const char **out_content, size_t *out_len)
 
int get_manpage_content (FILE **out_file, const char **out_content, size_t *out_len)
 
void release_manpage_resources (FILE *file)
 

Variables

const char embedded_manpage_template []
 
const size_t embedded_manpage_template_len
 

Detailed Description

Embedded resource access implementation.

Provides runtime access to embedded or filesystem-based resources based on build configuration.

Definition in file embedded_resources.c.

Function Documentation

◆ get_manpage_content()

int get_manpage_content ( FILE **  out_file,
const char **  out_content,
size_t *  out_len 
)

Definition at line 87 of file embedded_resources.c.

87 {
88 // Content is now consolidated into the template - return empty
89 if (out_content) {
90 *out_content = "";
91 }
92 if (out_len) {
93 *out_len = 0;
94 }
95 if (out_file) {
96 *out_file = NULL;
97 }
98
99 log_debug("Man page content is now consolidated into template (empty)");
100 return 0;
101}

◆ get_manpage_template()

int get_manpage_template ( FILE **  out_file,
const char **  out_content,
size_t *  out_len 
)

Definition at line 34 of file embedded_resources.c.

34 {
35#ifdef NDEBUG
36 // Release build: Return embedded data
37 if (out_content) {
38 *out_content = embedded_manpage_template;
39 }
40 if (out_len) {
42 }
43 if (out_file) {
44 *out_file = NULL;
45 }
46
47 log_debug("Using embedded man page template (%zu bytes)", embedded_manpage_template_len);
48 return 0;
49#else
50 // Debug build: Read from filesystem
51 if (!out_file) {
52 SET_ERRNO(ERROR_INVALID_PARAM, "out_file cannot be NULL in development mode");
53 return -1;
54 }
55
56 // Construct absolute path using ASCIICHAT_RESOURCE_DIR (set at build time)
57#ifdef ASCIICHAT_RESOURCE_DIR
58 static char path_buffer[PATH_MAX];
59 safe_snprintf(path_buffer, sizeof(path_buffer), "%s/share/man/man1/ascii-chat.1.in", ASCIICHAT_RESOURCE_DIR);
60 const char *path = path_buffer;
61#else
62 // Fallback: try relative path if ASCIICHAT_RESOURCE_DIR not defined
63 const char *path = "share/man/man1/ascii-chat.1.in";
64#endif
65
66 // Use binary mode to ensure fread byte count matches ftell file size.
67 // Text mode on Windows translates \r\n to \n, causing size mismatch.
68 FILE *f = platform_fopen(path, "rb");
69 if (!f) {
70 SET_ERRNO_SYS(ERROR_CONFIG, "Failed to open man page template: %s", path);
71 return -1;
72 }
73
74 *out_file = f;
75 if (out_content) {
76 *out_content = NULL;
77 }
78 if (out_len) {
79 *out_len = 0;
80 }
81
82 log_debug("Using filesystem man page template: %s", path);
83 return 0;
84#endif
85}
const size_t embedded_manpage_template_len
const char embedded_manpage_template[]
int safe_snprintf(char *buffer, size_t buffer_size, const char *format,...)
Safe formatted string printing to buffer.
Definition system.c:456
FILE * platform_fopen(const char *filename, const char *mode)

References embedded_manpage_template, embedded_manpage_template_len, platform_fopen(), and safe_snprintf().

Referenced by manpage_resources_load().

◆ release_manpage_resources()

void release_manpage_resources ( FILE *  file)

Definition at line 103 of file embedded_resources.c.

103 {
104#ifdef NDEBUG
105 // Release build: No-op (embedded data is static, not heap-allocated)
106 (void)file; // Suppress unused parameter warning
107#else
108 // Debug build: Close file handle if present
109 if (file) {
110 fclose(file);
111 }
112#endif
113}

Variable Documentation

◆ embedded_manpage_template

const char embedded_manpage_template[]
extern

Referenced by get_manpage_template().

◆ embedded_manpage_template_len

const size_t embedded_manpage_template_len
extern

Referenced by get_manpage_template().