ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
wasm/stubs/filesystem.c
Go to the documentation of this file.
1
11#include <ascii-chat/log/log.h>
13#include <stdio.h>
14#include <stdbool.h>
15#include <unistd.h>
16#include <stdarg.h>
17#include <stdarg.h>
18#include <fcntl.h>
19
20// File operations - basic WASM stubs
21FILE *platform_fopen(const char *name, const char *filename, const char *mode) {
22 if (!name) {
23 return NULL;
24 }
25 FILE *stream = fopen(filename, mode); // Use standard fopen
26 if (stream) {
27 int fd = fileno(stream);
28 if (fd >= 0) {
29 NAMED_REGISTER_FD(fd, name);
30 }
31 }
32 return stream;
33}
34
35FILE *platform_tmpfile(void) {
36 return tmpfile();
37}
38
39asciichat_error_t platform_mkdir_recursive(const char *path, int mode) {
40 (void)path;
41 (void)mode;
42 return ERROR_PLATFORM_INIT; // Not implemented for WASM
43}
44
46 (void)filename;
47 if (list_out) {
48 list_out->files = NULL;
49 list_out->count = 0;
50 list_out->capacity = 0;
51 }
52 return ASCIICHAT_OK; // No config files in WASM
53}
54
56 (void)list;
57 // No-op
58}
59
60// File descriptor operations
61// NOTE: platform_write is NOT defined here - it's provided by lib/platform/wasm/system.c
62// which has the xterm.js override for browser output
63
64ssize_t platform_read(int fd, void *buf, size_t count) {
65 return read(fd, buf, count);
66}
67
68int platform_open(const char *name, const char *pathname, int flags, ...) {
69 if (!name) {
70 return -1;
71 }
72
73 // Handle optional mode parameter for O_CREAT
74 int fd = -1;
75 int mode = 0;
76 if (flags & 0x0200) { // O_CREAT flag value
77 va_list args;
78 va_start(args, flags);
79 mode = va_arg(args, int);
80 va_end(args);
81 fd = open(pathname, flags, mode);
82 } else {
83 fd = open(pathname, flags);
84 }
85
86 if (fd >= 0) {
87 NAMED_REGISTER_FD(fd, name);
88 log_dev("Opened file descriptor %d for %s at path %s", fd, name, pathname);
89 }
90
91 return fd;
92}
93
94int platform_close(int fd) {
95 return close(fd);
96}
97
98int platform_access(const char *pathname, int mode) {
99 (void)pathname;
100 (void)mode;
101 return -1; // Not accessible in WASM
102}
103
105 return NULL; // No data directory in WASM
106}
Platform abstraction layer umbrella header providing unified cross-platform API.
⚠️‼️ Comprehensive thread-local error context system for ascii-chat
Named object registry for debugging — log identifiable resource names.
Cross-platform filesystem operations.
#define NAMED_REGISTER_FD(fd, name)
Register an existing file descriptor.
asciichat_error_t
Error and exit codes - unified status values (0-255)
Definition error_codes.h:49
@ ERROR_PLATFORM_INIT
Definition error_codes.h:60
@ ASCIICHAT_OK
Definition error_codes.h:51
#define log_dev(...)
Log a DEV message (most verbose, development only)
Definition log/log.h:534
asciichat_error_t platform_find_config_file(const char *filename, config_file_list_t *list_out)
Find config file across multiple standard locations.
FILE * platform_tmpfile(void)
Create a temporary file (tmpfile replacement)
char * platform_get_data_dir(void)
Get the application data directory.
int platform_access(const char *pathname, int mode)
Check file/directory access permissions.
asciichat_error_t platform_mkdir_recursive(const char *path, int mode)
Create directories recursively (mkdir -p equivalent)
int platform_open(const char *name, const char *pathname, int flags,...)
Safe file open (open replacement)
int platform_close(int fd)
Safe file close (close replacement)
FILE * platform_fopen(const char *name, const char *filename, const char *mode)
Safe file open stream (fopen replacement)
ssize_t platform_read(int fd, void *buf, size_t count)
Safe file read (read replacement)
void config_file_list_destroy(config_file_list_t *list)
Free config file list resources.
📝 Logging API with multiple log levels and terminal output control
action_args_t args
ClangTool/LibTooling compatibility shim for stdbool.h.
List of config file search results.
Definition filesystem.h:595
size_t count
Number of results found.
Definition filesystem.h:597
config_file_result_t * files
Array of results (allocated, must be freed)
Definition filesystem.h:596
size_t capacity
Allocated capacity.
Definition filesystem.h:598
WASM browser console logging API.