ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
filesystem.c
Go to the documentation of this file.
1
6
7#include <libplatform/filesystem.h>
11#include <stdio.h>
12#include <stdbool.h>
13#include <unistd.h>
14#include <stdarg.h>
15#include <fcntl.h>
16
17// File operations - basic WASM stubs
18FILE *platform_fopen(const char *name, const char *filename, const char *mode) {
19 if (!name) {
20 return NULL;
21 }
22 FILE *stream = fopen(filename, mode); // Use standard fopen
23 if (stream) {
24 int fd = fileno(stream);
25 if (fd >= 0) {
26 NAMED_REGISTER_FD(fd, name);
27 }
28 }
29 return stream;
30}
31
32FILE *platform_tmpfile(void) {
33 return tmpfile();
34}
35
36int platform_mkdir_recursive(const char *path, int mode) {
37 (void)path;
38 (void)mode;
39 return ERROR_PLATFORM_INIT; // Not implemented for WASM
40}
41
42int platform_find_config_file(const char *filename, config_file_list_t *list_out) {
43 (void)filename;
44 if (list_out) {
45 list_out->files = NULL;
46 list_out->count = 0;
47 list_out->capacity = 0;
48 }
49 return ASCIICHAT_OK; // No config files in WASM
50}
51
52void config_file_list_destroy(config_file_list_t *list) {
53 (void)list;
54 // No-op
55}
56
57// File descriptor operations
58// NOTE: platform_write is NOT defined here - it's provided by lib/platform/wasm/system.c
59// which has the xterm.js override for browser output
60
61ssize_t platform_read(int fd, void *buf, size_t count) {
62 return read(fd, buf, count);
63}
64
65int platform_open(const char *name, const char *pathname, int flags, ...) {
66 if (!name) {
67 return -1;
68 }
69
70 // Handle optional mode parameter for O_CREAT
71 int fd = -1;
72 int mode = 0;
73 if (flags & 0x0200) { // O_CREAT flag value
74 va_list args;
75 va_start(args, flags);
76 mode = va_arg(args, int);
77 va_end(args);
78 fd = open(pathname, flags, mode);
79 } else {
80 fd = open(pathname, flags);
81 }
82
83 if (fd >= 0) {
84 NAMED_REGISTER_FD(fd, name);
85 log_dev("Opened file descriptor %d for %s at path %s", fd, name, pathname);
86 }
87
88 return fd;
89}
90
91int platform_close(int fd) {
92 return close(fd);
93}
94
95int platform_access(const char *pathname, int mode) {
96 (void)pathname;
97 (void)mode;
98 return -1; // Not accessible in WASM
99}
100
102 return NULL; // No data directory in WASM
103}
104
105int platform_get_data_dir_candidates(const char *install_prefix, platform_directory_list_t *list_out) {
106 (void)install_prefix;
107 if (!list_out) {
108 return SET_ERRNO(ERROR_INVALID_PARAM, "list_out cannot be NULL");
109 }
110 list_out->candidates = NULL;
111 list_out->count = 0;
112 return ASCIICHAT_OK;
113}
Synchronized per-thread pending error stacks and value snapshots. SET_ERRNO pushes,...
#define SET_ERRNO(code,...)
Named object registry for debugging — log identifiable resource names.
int platform_mkdir_recursive(const char *path, int mode)
Definition filesystem.c:36
int platform_get_data_dir_candidates(const char *install_prefix, platform_directory_list_t *list_out)
Definition filesystem.c:105
int platform_find_config_file(const char *filename, config_file_list_t *list_out)
Definition filesystem.c:42
int platform_access(const char *pathname, int mode)
Definition filesystem.c:95
FILE * platform_tmpfile(void)
Definition filesystem.c:32
char * platform_get_data_dir(void)
Definition filesystem.c:101
int platform_open(const char *name, const char *pathname, int flags,...)
Definition filesystem.c:65
int platform_close(int fd)
Definition filesystem.c:91
FILE * platform_fopen(const char *name, const char *filename, const char *mode)
Definition filesystem.c:18
ssize_t platform_read(int fd, void *buf, size_t count)
Definition filesystem.c:61
void config_file_list_destroy(config_file_list_t *list)
Definition filesystem.c:52
#define NAMED_REGISTER_FD(fd, name)
Register an existing file descriptor.
@ ERROR_PLATFORM_INIT
Definition error_codes.h:59
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
#define log_dev(...)
Log a DEV message (most verbose, development only).
Definition log/log.h:575
action_args_t args
📝 Logging API with multiple log levels and terminal output control