1414#ifndef FOSSIL_SYS_CALL_H
1515#define FOSSIL_SYS_CALL_H
1616
17+ #include < stdint.h>
18+ #include < stddef.h>
19+
1720#ifdef __cplusplus
1821extern " C" {
1922#endif
@@ -47,6 +50,106 @@ void fossil_sys_call_sleep(int milliseconds);
4750 */
4851int fossil_sys_call_create_file (const char *filename);
4952
53+ /* *
54+ * @brief Delete a file.
55+ *
56+ * Removes a file from the filesystem.
57+ *
58+ * @param filename Path to the file to delete.
59+ * @return 0 on success, negative error code on failure.
60+ */
61+ int fossil_sys_call_delete_file (const char *filename);
62+
63+ /* *
64+ * @brief Check if a file exists.
65+ *
66+ * @param filename Path to the file.
67+ * @return 1 if the file exists, 0 if not.
68+ */
69+ int fossil_sys_call_file_exists (const char *filename);
70+
71+ /* *
72+ * @brief Create a directory.
73+ *
74+ * @param dirname Path of the directory to create.
75+ * @return 0 on success, negative error code on failure.
76+ */
77+ int fossil_sys_call_create_directory (const char *dirname);
78+
79+ /* *
80+ * @brief Delete a directory (optionally recursive).
81+ *
82+ * @param dirname Path of the directory to delete.
83+ * @param recursive If non-zero, delete all contents recursively.
84+ * @return 0 on success, negative error code on failure.
85+ */
86+ int fossil_sys_call_delete_directory (const char *dirname, int recursive);
87+
88+ /* *
89+ * @brief Get the current working directory.
90+ *
91+ * @param buffer Buffer to receive the current path.
92+ * @param size Size of the buffer.
93+ * @return 0 on success, negative error code on failure.
94+ */
95+ int fossil_sys_call_getcwd (char *buffer, size_t size);
96+
97+ /* *
98+ * @brief Change the current working directory.
99+ *
100+ * @param path Path to set as current working directory.
101+ * @return 0 on success, negative error code on failure.
102+ */
103+ int fossil_sys_call_chdir (const char *path);
104+
105+ /* *
106+ * @brief List files in a directory.
107+ *
108+ * Returns a list of filenames in a given directory.
109+ * (Could return a dynamically allocated array of strings, or take a callback function.)
110+ *
111+ * @param dirname Path to the directory.
112+ * @param out_list Pointer to array of strings (allocated by function).
113+ * @param out_count Pointer to receive the number of entries.
114+ * @return 0 on success, negative error code on failure.
115+ */
116+ int fossil_sys_call_list_directory (const char *dirname, char ***out_list, size_t *out_count);
117+
118+ /* *
119+ * @brief Check if a path is a directory.
120+ *
121+ * @param path Path to check.
122+ * @return 1 if directory, 0 if not.
123+ */
124+ int fossil_sys_call_is_directory (const char *path);
125+
126+ /* *
127+ * @brief Check if a path is a regular file.
128+ *
129+ * @param path Path to check.
130+ * @return 1 if regular file, 0 if not.
131+ */
132+ int fossil_sys_call_is_file (const char *path);
133+
134+ /* *
135+ * @brief Terminate the current process.
136+ *
137+ * @param exit_code Exit code to return to the operating system.
138+ */
139+ void fossil_sys_call_exit (int exit_code);
140+
141+ /* *
142+ * @brief Execute a command and capture output.
143+ *
144+ * Runs a command and stores stdout in a buffer (similar to popen).
145+ *
146+ * @param command Command string to execute.
147+ * @param buffer Buffer to store output.
148+ * @param size Size of the buffer.
149+ * @return 0 on success, negative error code on failure.
150+ */
151+ int fossil_sys_call_execute_capture (const char *command, char *buffer, size_t size);
152+
50153#ifdef __cplusplus
51154}
52155#include < string>
@@ -66,17 +169,6 @@ namespace fossil {
66169 */
67170 class Syscall {
68171 public:
69-
70- /* *
71- * Execute a system command.
72- *
73- * @param command The command to execute.
74- * @return The return value of the system command.
75- */
76- static int execute (const char *command) {
77- return fossil_sys_call_execute (command);
78- }
79-
80172 /* *
81173 * Execute a system command.
82174 *
@@ -111,18 +203,123 @@ namespace fossil {
111203 * @param filename The name of the file to create.
112204 * @return 0 on success, or a negative error code on failure.
113205 */
114- static int create_file (const char * filename) {
115- return fossil_sys_call_create_file (filename);
206+ static int create_file (const std::string & filename) {
207+ return fossil_sys_call_create_file (filename. c_str () );
116208 }
117209
118210 /* *
119- * Create a new file.
211+ * Delete a file.
120212 *
121- * @param filename The name of the file to create .
122- * @return 0 on success, or a negative error code on failure.
213+ * @param filename Path to the file to delete .
214+ * @return 0 on success, negative error code on failure.
123215 */
124- static int create_file (const std::string &filename) {
125- return fossil_sys_call_create_file (filename.c_str ());
216+ static int delete_file (const std::string &filename) {
217+ return fossil_sys_call_delete_file (filename.c_str ());
218+ }
219+
220+ /* *
221+ * Check if a file exists.
222+ *
223+ * @param filename Path to the file.
224+ * @return 1 if the file exists, 0 if not.
225+ */
226+ static int file_exists (const std::string &filename) {
227+ return fossil_sys_call_file_exists (filename.c_str ());
228+ }
229+
230+ /* *
231+ * Create a directory.
232+ *
233+ * @param dirname Path of the directory to create.
234+ * @return 0 on success, negative error code on failure.
235+ */
236+ static int create_directory (const std::string &dirname) {
237+ return fossil_sys_call_create_directory (dirname.c_str ());
238+ }
239+
240+ /* *
241+ * Delete a directory (optionally recursive).
242+ *
243+ * @param dirname Path of the directory to delete.
244+ * @param recursive If non-zero, delete all contents recursively.
245+ * @return 0 on success, negative error code on failure.
246+ */
247+ static int delete_directory (const std::string &dirname, int recursive) {
248+ return fossil_sys_call_delete_directory (dirname.c_str (), recursive);
249+ }
250+
251+ /* *
252+ * Get the current working directory.
253+ *
254+ * @param buffer Buffer to receive the current path.
255+ * @param size Size of the buffer.
256+ * @return 0 on success, negative error code on failure.
257+ */
258+ static int getcwd (std::string *buffer, size_t size) {
259+ return fossil_sys_call_getcwd (buffer->data (), size);
260+ }
261+
262+ /* *
263+ * Change the current working directory.
264+ *
265+ * @param path Path to set as current working directory.
266+ * @return 0 on success, negative error code on failure.
267+ */
268+ static int chdir (const std::string &path) {
269+ return fossil_sys_call_chdir (path.c_str ());
270+ }
271+
272+ /* *
273+ * List files in a directory.
274+ *
275+ * @param dirname Path to the directory.
276+ * @param out_list Pointer to array of strings (allocated by function).
277+ * @param out_count Pointer to receive the number of entries.
278+ * @return 0 on success, negative error code on failure.
279+ */
280+ static int list_directory (const std::string &dirname, char ***out_list, size_t *out_count) {
281+ return fossil_sys_call_list_directory (dirname.c_str (), out_list, out_count);
282+ }
283+
284+ /* *
285+ * Check if a path is a directory.
286+ *
287+ * @param path Path to check.
288+ * @return 1 if directory, 0 if not.
289+ */
290+ static int is_directory (const std::string &path) {
291+ return fossil_sys_call_is_directory (path.c_str ());
292+ }
293+
294+ /* *
295+ * Check if a path is a regular file.
296+ *
297+ * @param path Path to check.
298+ * @return 1 if regular file, 0 if not.
299+ */
300+ static int is_file (const std::string &path) {
301+ return fossil_sys_call_is_file (path.c_str ());
302+ }
303+
304+ /* *
305+ * Terminate the current process.
306+ *
307+ * @param exit_code Exit code to return to the operating system.
308+ */
309+ static void exit (int exit_code) {
310+ fossil_sys_call_exit (exit_code);
311+ }
312+
313+ /* *
314+ * Execute a command and capture output.
315+ *
316+ * @param command Command string to execute.
317+ * @param buffer Buffer to store output.
318+ * @param size Size of the buffer.
319+ * @return 0 on success, negative error code on failure.
320+ */
321+ static int execute_capture (const std::string &command, std::string *buffer) {
322+ return fossil_sys_call_execute_capture (command.c_str (), buffer->data (), buffer->size ());
126323 }
127324
128325 };
0 commit comments