@@ -50,6 +50,16 @@ int32_t fossil_fstream_open(fossil_fstream_t *stream, const char *filename, cons
5050 */
5151void fossil_fstream_close (fossil_fstream_t *stream);
5252
53+ /* *
54+ * Check if a stream is open.
55+ *
56+ * This function checks if a stream is open.
57+ *
58+ * @param stream Pointer to the fossil_fstream_t structure to check.
59+ * @return 1 if the stream is open, 0 if not.
60+ */
61+ int32_t fossil_fstream_is_open (const fossil_fstream_t *stream);
62+
5363/* *
5464 * Read data from an open stream.
5565 *
@@ -185,8 +195,361 @@ int32_t fossil_fstream_delete(const char *filename);
185195 */
186196int32_t fossil_fstream_rename (const char *old_filename, const char *new_filename);
187197
198+ /* *
199+ * Get the type of a file stream.
200+ *
201+ * This function retrieves the type of a file stream.
202+ *
203+ * @param filename The name of the file to get the type of.
204+ * @return The type of the file stream.
205+ */
206+ int fossil_fstream_get_type (const char *filename);
207+
208+ /* *
209+ * Check if a file is readable.
210+ *
211+ * This function checks if a file has read permissions.
212+ *
213+ * @param filename The name of the file to check.
214+ * @return 1 if readable, 0 otherwise.
215+ */
216+ int32_t fossil_fstream_is_readable (const char *filename);
217+
218+ /* *
219+ * Check if a file is writable.
220+ *
221+ * This function checks if a file has write permissions.
222+ *
223+ * @param filename The name of the file to check.
224+ * @return 1 if writable, 0 otherwise.
225+ */
226+ int32_t fossil_fstream_is_writable (const char *filename);
227+
228+ /* *
229+ * Check if a file is executable.
230+ *
231+ * This function checks if a file has execute permissions.
232+ *
233+ * @param filename The name of the file to check.
234+ * @return 1 if executable, 0 otherwise.
235+ */
236+ int32_t fossil_fstream_is_executable (const char *filename);
237+
238+ /* *
239+ * Set file permissions.
240+ *
241+ * This function sets the permissions for a file.
242+ *
243+ * @param filename The name of the file to set permissions for.
244+ * @param mode The permissions to set (POSIX: chmod-style).
245+ * @return 0 on success, non-zero on failure.
246+ */
247+ int32_t fossil_fstream_set_permissions (const char *filename, int32_t mode);
248+
249+ /* *
250+ * Get file permissions.
251+ *
252+ * This function retrieves the permissions of a file.
253+ *
254+ * @param filename The name of the file to retrieve permissions for.
255+ * @param mode Pointer to store the retrieved permissions (POSIX style).
256+ * @return 0 on success, non-zero on failure.
257+ */
258+ int32_t fossil_fstream_get_permissions (const char *filename, int32_t *mode);
259+
188260#ifdef __cplusplus
189261}
262+
263+ /* *
264+ * C++ wrapper for the file stream functions.
265+ */
266+ namespace fossil {
267+ /* *
268+ * IO namespace for file stream functions.
269+ */
270+ namespace io {
271+
272+ /* *
273+ * Class for file stream functions.
274+ */
275+ class Stream {
276+ public:
277+ /* *
278+ * Open a stream for file operations.
279+ *
280+ * This function opens a file stream, allowing read or write operations on the specified file.
281+ *
282+ * @param stream Pointer to the fossil_fstream_t structure to store the opened stream.
283+ * @param filename The name of the file to be opened.
284+ * @param mode The mode in which to open the file (e.g., "r" for read, "w" for write).
285+ * @return 0 on success, non-zero on failure.
286+ */
287+ static int32_t open (fossil_fstream_t *stream, const char *filename, const char *mode) {
288+ return fossil_fstream_open (stream, filename, mode);
289+ }
290+
291+ /* *
292+ * Close an open stream.
293+ *
294+ * This function closes a previously opened stream, releasing associated resources.
295+ *
296+ * @param stream Pointer to the fossil_fstream_t structure to be closed.
297+ */
298+ static void close (fossil_fstream_t *stream) {
299+ fossil_fstream_close (stream);
300+ }
301+
302+ /* *
303+ * Check if a stream is open.
304+ *
305+ * This function checks if a stream is open.
306+ *
307+ * @param stream Pointer to the fossil_fstream_t structure to check.
308+ * @return 1 if the stream is open, 0 if not.
309+ */
310+ static int32_t is_open (const fossil_fstream_t *stream) {
311+ return fossil_fstream_is_open (stream);
312+ }
313+
314+ /* *
315+ * Read data from an open stream.
316+ *
317+ * This function reads data from an open stream into a buffer.
318+ *
319+ * @param stream Pointer to the fossil_fstream_t structure from which to read.
320+ * @param buffer Pointer to the buffer to store the read data.
321+ * @param size Size of each element to be read.
322+ * @param count Number of elements to read.
323+ * @return The total number of elements successfully read.
324+ */
325+ static size_t read (fossil_fstream_t *stream, void *buffer, size_t size, size_t count) {
326+ return fossil_fstream_read (stream, buffer, size, count);
327+ }
328+
329+ /* *
330+ * Write data to an open stream.
331+ *
332+ * This function writes data from a buffer to an open stream.
333+ *
334+ * @param stream Pointer to the fossil_fstream_t structure to which to write.
335+ * @param buffer Pointer to the buffer containing the data to be written.
336+ * @param size Size of each element to be written.
337+ * @param count Number of elements to write.
338+ * @return The total number of elements successfully written.
339+ */
340+ static size_t write (fossil_fstream_t *stream, const void *buffer, size_t size, size_t count) {
341+ return fossil_fstream_write (stream, buffer, size, count);
342+ }
343+
344+ /* *
345+ * Append data to the end of an open stream.
346+ *
347+ * This function appends data from a buffer to the end of an open stream.
348+ *
349+ * @param stream Pointer to the fossil_fstream_t structure to which to append.
350+ * @param buffer Pointer to the buffer containing the data to be appended.
351+ * @param size Size of each element to be appended.
352+ * @param count Number of elements to append.
353+ * @return 0 on success, non-zero on failure.
354+ */
355+ static int32_t append (fossil_fstream_t *stream, const void *buffer, size_t size, int32_t count) {
356+ return fossil_fstream_append (stream, buffer, size, count);
357+ }
358+
359+ /* *
360+ * Seek to a specified position in an open stream.
361+ *
362+ * This function moves the file pointer associated with the stream to a new position.
363+ *
364+ * @param stream Pointer to the fossil_fstream_t structure to seek.
365+ * @param offset The offset from the specified origin.
366+ * @param origin The starting position for the offset (SEEK_SET, SEEK_CUR, SEEK_END).
367+ * @return 0 on success, non-zero on failure.
368+ */
369+ static int32_t seek (fossil_fstream_t *stream, int64_t offset, int32_t origin) {
370+ return fossil_fstream_seek (stream, offset, origin);
371+ }
372+
373+ /* *
374+ * Get the current position of the file pointer in an open stream.
375+ *
376+ * This function retrieves the current position of the file pointer in an open stream.
377+ *
378+ * @param stream Pointer to the fossil_fstream_t structure to get the position of.
379+ * @return The current position of the file pointer.
380+ */
381+ static int32_t tell (fossil_fstream_t *stream) {
382+ return fossil_fstream_tell (stream);
383+ }
384+
385+ /* *
386+ * Save an open stream to a new file.
387+ *
388+ * This function saves the contents of an open stream to a new file.
389+ *
390+ * @param stream Pointer to the fossil_fstream_t structure to be saved.
391+ * @param new_filename The name of the new file to save to.
392+ * @return 0 on success, non-zero on failure.
393+ */
394+ static int32_t save (fossil_fstream_t *stream, const char *new_filename) {
395+ return fossil_fstream_save (stream, new_filename);
396+ }
397+
398+ /* *
399+ * Copy a file from the source to the destination.
400+ *
401+ * This function copies a file from a source file to a destination file.
402+ *
403+ * @param source_filename The name of the source file.
404+ * @param destination_filename The name of the destination file.
405+ * @return 0 on success, non-zero on failure.
406+ */
407+ static int32_t copy (const char *source_filename, const char *destination_filename) {
408+ return fossil_fstream_copy (source_filename, destination_filename);
409+ }
410+
411+ /* *
412+ * Create a backup of a file with a specified backup suffix.
413+ *
414+ * This function creates a backup of a file with the given suffix.
415+ *
416+ * @param filename The name of the file to create a backup for.
417+ * @param backup_suffix The suffix to be appended to the backup file.
418+ * @return 0 on success, non-zero on failure.
419+ */
420+ static int32_t backup (const char *filename, const char *backup_suffix) {
421+ return fossil_fstream_backup (filename, backup_suffix);
422+ }
423+
424+ /* *
425+ * Check if a file exists.
426+ *
427+ * This function checks if a file exists.
428+ *
429+ * @param filename The name of the file to check for existence.
430+ * @return 1 if the file exists, 0 if not.
431+ */
432+ static int32_t file_exists (const char *filename) {
433+ return fossil_fstream_file_exists (filename);
434+ }
435+
436+ /* *
437+ * Get the size of an open stream.
438+ *
439+ * This function retrieves the size of an open stream.
440+ *
441+ * @param stream Pointer to the fossil_fstream_t structure to get the size of.
442+ * @return The size of the open stream.
443+ */
444+ static int32_t get_size (fossil_fstream_t *stream) {
445+ return fossil_fstream_get_size (stream);
446+ }
447+
448+ /* *
449+ * Delete a file.
450+ *
451+ * This function deletes a file.
452+ *
453+ * @param filename The name of the file to be deleted.
454+ * @return 0 on success, non-zero on failure.
455+ */
456+ static int32_t delete_file (const char *filename) {
457+ return fossil_fstream_delete (filename);
458+ }
459+
460+ /* *
461+ * Rename a file or directory.
462+ *
463+ * This function renames a file or directory.
464+ *
465+ * @param old_filename The current name of the file or directory.
466+ * @param new_filename The new name to assign to the file or directory.
467+ * @return 0 on success, non-zero on failure.
468+ */
469+ static int32_t rename (const char *old_filename, const char *new_filename) {
470+ return fossil_fstream_rename (old_filename, new_filename);
471+ }
472+
473+ /* *
474+ * Get the type of a file stream.
475+ *
476+ * This function retrieves the type of a file stream.
477+ *
478+ * @param filename The name of the file to get the type of.
479+ * @return The type of the file stream.
480+ */
481+ static int get_type (const char *filename) {
482+ return fossil_fstream_get_type (filename);
483+ }
484+
485+ /* *
486+ * Check if a file is readable.
487+ *
488+ * This function checks if a file has read permissions.
489+ *
490+ * @param filename The name of the file to check.
491+ * @return 1 if readable, 0 otherwise.
492+ */
493+ static int32_t is_readable (const char *filename) {
494+ return fossil_fstream_is_readable (filename);
495+ }
496+
497+ /* *
498+ * Check if a file is writable.
499+ *
500+ * This function checks if a file has write permissions.
501+ *
502+ * @param filename The name of the file to check.
503+ * @return 1 if writable, 0 otherwise.
504+ */
505+ static int32_t is_writable (const char *filename) {
506+ return fossil_fstream_is_writable (filename);
507+ }
508+
509+ /* *
510+ * Check if a file is executable.
511+ *
512+ * This function checks if a file has execute permissions.
513+ *
514+ * @param filename The name of the file to check.
515+ * @return 1 if executable, 0 otherwise.
516+ */
517+ static int32_t is_executable (const char *filename) {
518+ return fossil_fstream_is_executable (filename);
519+ }
520+
521+ /* *
522+ * Set file permissions.
523+ *
524+ * This function sets the permissions for a file.
525+ *
526+ * @param filename The name of the file to set permissions for.
527+ * @param mode The permissions to set (POSIX: chmod-style).
528+ * @return 0 on success, non-zero on failure.
529+ */
530+ static int32_t set_permissions (const char *filename, int32_t mode) {
531+ return fossil_fstream_set_permissions (filename, mode);
532+ }
533+
534+ /* *
535+ * Get file permissions.
536+ *
537+ * This function retrieves the permissions of a file.
538+ *
539+ * @param filename The name of the file to retrieve permissions for.
540+ * @param mode Pointer to store the retrieved permissions (POSIX style).
541+ * @return 0 on success, non-zero on failure.
542+ */
543+ static int32_t get_permissions (const char *filename, int32_t *mode) {
544+ return fossil_fstream_get_permissions (filename, mode);
545+ }
546+
547+ };
548+
549+ } // namespace io
550+
551+ } // namespace fossil
552+
190553#endif
191554
192555#endif /* FOSSIL_IO_FRAMEWORK_H */
0 commit comments