ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
filesystem.h File Reference

Cross-platform filesystem operations. More...

Go to the source code of this file.

Data Structures

struct  platform_stat_t
 File type information from stat() More...
 
struct  platform_dir_entry_t
 Directory entry information for platform_dir_foreach() More...
 
struct  config_file_result_t
 Result of a config file search. More...
 
struct  config_file_list_t
 List of config file search results. More...
 

Macros

#define PLATFORM_O_RDONLY   O_RDONLY
 
#define PLATFORM_O_WRONLY   O_WRONLY
 
#define PLATFORM_O_RDWR   O_RDWR
 
#define PLATFORM_O_CREAT   O_CREAT
 
#define PLATFORM_O_EXCL   O_EXCL
 
#define PLATFORM_O_TRUNC   O_TRUNC
 
#define PLATFORM_O_APPEND   O_APPEND
 
#define PLATFORM_O_BINARY   0
 
#define PATH_DELIM   '/'
 Platform-specific path separator character.
 
#define PATH_SEPARATOR_STR   "/"
 
#define PATH_ENV_SEPARATOR   ":"
 Platform-specific PATH environment variable separator.
 
#define PLATFORM_MAX_PATH_LENGTH   4096
 Maximum path length supported by the operating system.
 
#define PLATFORM_MAX_ENV_VALUE_LENGTH   32768
 Maximum environment variable value length.
 
#define FILE_PERM_PRIVATE   0600
 File permission: Private (owner read/write only)
 
#define DIR_PERM_PRIVATE   0700
 Directory permission: Private (owner read/write/execute only)
 
#define FILE_PERM_PUBLIC_READ   0644
 File permission: Public read, owner write.
 
#define FILE_PERM_MASK   0777
 Permission mask for all permissions.
 
#define PLATFORM_ACCESS_EXISTS   0
 Access modes for platform_access()
 
#define PLATFORM_ACCESS_WRITE   2
 Check if file/directory is writable.
 
#define PLATFORM_ACCESS_READ   4
 Check if file/directory is readable.
 

Typedefs

typedef bool(* platform_dir_foreach_cb) (const platform_dir_entry_t *entry, void *user_data)
 Callback for platform_dir_foreach()
 

Functions

asciichat_error_t platform_stat (const char *path, platform_stat_t *stat_out)
 Get file statistics.
 
int platform_is_regular_file (const char *path)
 Check if a path is a regular file.
 
int platform_is_directory (const char *path)
 Check if a path is a directory.
 
asciichat_error_t platform_mkdir (const char *path, int mode)
 Create a directory.
 
asciichat_error_t platform_mkdir_recursive (const char *path, int mode)
 Create directories recursively (mkdir -p equivalent)
 
asciichat_error_t platform_mkdtemp (char *path_out, size_t path_size, const char *prefix)
 Create a temporary directory with a given prefix.
 
asciichat_error_t platform_rmdir_recursive (const char *path)
 Recursively delete a directory and all its contents.
 
asciichat_error_t platform_dir_foreach (const char *path, platform_dir_foreach_cb callback, void *user_data)
 Iterate over entries in a directory.
 
int platform_create_temp_file (char *path_out, size_t path_size, const char *prefix, int *fd)
 Create a temporary file with a given prefix.
 
int platform_delete_temp_file (const char *path)
 Delete a temporary file.
 
asciichat_error_t platform_temp_file_open (const char *name, const char *path, int *fd_out)
 Open a temporary file for writing.
 
asciichat_error_t platform_truncate_file (const char *path, size_t size)
 Truncate a file to a specific size.
 
bool platform_path_is_absolute (const char *path)
 Check if a path is absolute (not relative)
 
char platform_path_get_separator (void)
 Get the path separator character for current platform.
 
asciichat_error_t platform_path_normalize (const char *input, char *output, size_t output_size)
 Normalize and validate a file path.
 
asciichat_error_t platform_validate_key_file_permissions (const char *key_path)
 Validate that a cryptographic key file has appropriate permissions.
 
asciichat_error_t platform_find_config_file (const char *filename, config_file_list_t *list_out)
 Find config file across multiple standard locations.
 
void config_file_list_destroy (config_file_list_t *list)
 Free config file list resources.
 
const char * platform_get_home_dir (void)
 Get the user's home directory.
 
char * platform_get_config_dir (void)
 Get the application configuration directory.
 
char * platform_get_data_dir (void)
 Get the application data directory.
 
int platform_open (const char *name, const char *pathname, int flags,...)
 Safe file open (open replacement)
 
FILE * platform_fopen (const char *name, const char *filename, const char *mode)
 Safe file open stream (fopen replacement)
 
FILE * platform_tmpfile (void)
 Create a temporary file (tmpfile replacement)
 
FILE * platform_fdopen (const char *name, int fd, const char *mode)
 Convert file descriptor to stream (fdopen replacement)
 
ssize_t platform_read (int fd, void *buf, size_t count)
 Safe file read (read replacement)
 
ssize_t platform_write (int fd, const void *buf, size_t count)
 Safe file write (write replacement)
 
int platform_close (int fd)
 Safe file close (close replacement)
 
int platform_unlink (const char *pathname)
 Delete/unlink file.
 
int platform_chmod (const char *pathname, int mode)
 Change file permissions/mode.
 
const char * platform_path_skip_absolute_prefix (const char *path)
 Skip absolute path prefix (drive letter on Windows)
 
void platform_normalize_path_separators (char *path)
 Normalize path separators for the current platform.
 
int platform_path_strcasecmp (const char *a, const char *b, size_t n)
 Platform-aware path string comparison.
 
const char * file_read_error_message (const char *path)
 Get human-readable error message for file read failure.
 
const char * file_write_error_message (const char *path)
 Get human-readable error message for file write failure.
 
bool file_is_readable (const char *path)
 Check if file is readable.
 
bool file_is_writable (const char *path)
 Check if file is writable.
 
bool platform_get_executable_path (char *exe_path, size_t path_size)
 Get the path to the current executable.
 
bool platform_get_temp_dir (char *temp_dir, size_t path_size)
 Get the system temporary directory path.
 
bool platform_get_cwd (char *cwd, size_t path_size)
 Get the current working directory of the process.
 
int platform_access (const char *path, int mode)
 Check file/directory access permissions.
 
bool platform_is_binary_in_path (const char *bin_name)
 Check if a binary is available in the system PATH.
 
void platform_cleanup_binary_path_cache (void)
 Cleanup the binary PATH cache.
 
int platform_fsync (int fd)
 Synchronize a file descriptor to disk.
 
bool check_binary_in_path_uncached (const char *bin_name)
 Check if a binary is in PATH (uncached, platform-specific implementation)
 

Detailed Description

Cross-platform filesystem operations.

Definition in file filesystem.h.