Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_fs.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Declares native filesystem helper routines.
4 */
5
6#ifndef PHAROS_NATIVE_FS_H
7#define PHAROS_NATIVE_FS_H
8
9#include <stddef.h>
10#include <stdlib.h>
11
12/** @name Filesystem helpers
13 * @{
14 */
15/**
16 * @brief Creates a directory path and any missing parent directories.
17 * @param path Directory path to ensure exists.
18 * @return 0 on success, or a non-zero status code on failure.
19 */
20int ensure_directory(const char *path);
21/**
22 * @brief Copies one file as binary data.
23 * @param source_path Path to the source file.
24 * @param target_path Path to the destination file.
25 * @return 0 on success, or a non-zero status code on failure.
26 */
27int copy_file_binary(const char *source_path, const char *target_path);
28/**
29 * @brief Recursively copies one directory tree into another location.
30 * @param source_dir Source directory to copy.
31 * @param target_dir Destination directory to populate.
32 * @return 0 on success, or a non-zero status code on failure.
33 */
34int copy_directory_recursive(const char *source_dir, const char *target_dir);
35/**
36 * @brief Recursively removes a directory tree.
37 * @param target_dir Directory tree to remove.
38 * @return 0 on success, or a non-zero status code on failure.
39 */
40int remove_directory_recursive(const char *target_dir);
41/**
42 * @brief Writes a text buffer to a file path.
43 * @param path Destination file path.
44 * @param content Text content to write.
45 * @return 0 on success, or a non-zero status code on failure.
46 */
47int write_text_file(const char *path, const char *content);
48
49/**
50 * @brief Reads the full content of a binary file into a heap-allocated buffer.
51 * @param path File path to read.
52 * @param out_size Receives the byte count (may be NULL).
53 * @return Newly allocated buffer with NUL terminator, or NULL on failure.
54 */
55unsigned char *read_file_bytes_dup_runtime(const char *path, size_t *out_size);
56
57/**
58 * @brief Writes a binary byte range to a file, creating parent directories as needed.
59 * @param path Destination file path.
60 * @param data Bytes to write.
61 * @param length Number of bytes to write.
62 * @return 0 on success, non-zero on failure.
63 */
64int write_binary_file_runtime(const char *path, const unsigned char *data, size_t length);
65
66/** @} */
67#endif
int ensure_directory(const char *path)
Creates a directory path and any missing parent directories.
Definition native_fs.c:31
unsigned char * read_file_bytes_dup_runtime(const char *path, size_t *out_size)
Reads the full content of a binary file into a heap-allocated buffer.
int write_text_file(const char *path, const char *content)
Writes a text buffer to a file path.
Definition native_fs.c:66
int remove_directory_recursive(const char *target_dir)
Recursively removes a directory tree.
Definition native_fs.c:179
int copy_directory_recursive(const char *source_dir, const char *target_dir)
Recursively copies one directory tree into another location.
Definition native_fs.c:132
int copy_file_binary(const char *source_path, const char *target_path)
Copies one file as binary data.
Definition native_fs.c:93
int write_binary_file_runtime(const char *path, const unsigned char *data, size_t length)
Writes a binary byte range to a file, creating parent directories as needed.