@@ -344,7 +344,6 @@ namespace fossil {
344
344
*/
345
345
class Stream {
346
346
public:
347
- // Existing functions...
348
347
349
348
/* *
350
349
* Reopen a stream with a new file.
@@ -361,6 +360,17 @@ namespace fossil {
361
360
return fossil_fstream_freopen (stream, filename, mode, file);
362
361
}
363
362
363
+ /* *
364
+ * Reopen a stream with a new file.
365
+ *
366
+ * This function reopens a stream with a new file.
367
+ *
368
+ * @param stream Pointer to the fossil_fstream_t structure to reopen.
369
+ * @param filename The name of the file to reopen.
370
+ * @param mode The mode in which to reopen the file.
371
+ * @param file Pointer to the FILE structure to reopen.
372
+ * @return 0 on success, non-zero on failure.
373
+ */
364
374
static int32_t freopen (fossil_fstream_t *stream, const std::string &filename, const std::string &mode, FILE *file) {
365
375
return fossil_fstream_freopen (stream, filename.c_str (), mode.c_str (), file);
366
376
}
@@ -379,6 +389,16 @@ namespace fossil {
379
389
return fossil_fstream_open (stream, filename, mode);
380
390
}
381
391
392
+ /* *
393
+ * Open a stream for file operations.
394
+ *
395
+ * This function opens a file stream, allowing read or write operations on the specified file.
396
+ *
397
+ * @param stream Pointer to the fossil_fstream_t structure to store the opened stream.
398
+ * @param filename The name of the file to be opened.
399
+ * @param mode The mode in which to open the file (e.g., "r" for read, "w" for write).
400
+ * @return 0 on success, non-zero on failure.
401
+ */
382
402
static int32_t open (fossil_fstream_t *stream, const std::string &filename, const std::string &mode) {
383
403
return fossil_fstream_open (stream, filename.c_str (), mode.c_str ());
384
404
}
@@ -490,6 +510,15 @@ namespace fossil {
490
510
return fossil_fstream_save (stream, new_filename);
491
511
}
492
512
513
+ /* *
514
+ * Save an open stream to a new file.
515
+ *
516
+ * This function saves the contents of an open stream to a new file.
517
+ *
518
+ * @param stream Pointer to the fossil_fstream_t structure to be saved.
519
+ * @param new_filename The name of the new file to save to.
520
+ * @return 0 on success, non-zero on failure.
521
+ */
493
522
static int32_t save (fossil_fstream_t *stream, const std::string &new_filename) {
494
523
return fossil_fstream_save (stream, new_filename.c_str ());
495
524
}
@@ -507,6 +536,15 @@ namespace fossil {
507
536
return fossil_fstream_copy (source_filename, destination_filename);
508
537
}
509
538
539
+ /* *
540
+ * Copy a file from the source to the destination.
541
+ *
542
+ * This function copies a file from a source file to a destination file.
543
+ *
544
+ * @param source_filename The name of the source file.
545
+ * @param destination_filename The name of the destination file.
546
+ * @return 0 on success, non-zero on failure.
547
+ */
510
548
static int32_t copy (const std::string &source_filename, const std::string &destination_filename) {
511
549
return fossil_fstream_copy (source_filename.c_str (), destination_filename.c_str ());
512
550
}
@@ -523,6 +561,14 @@ namespace fossil {
523
561
return fossil_fstream_remove (filename);
524
562
}
525
563
564
+ /* *
565
+ * Remove a file stream.
566
+ *
567
+ * This function removes a file stream.
568
+ *
569
+ * @param filename The name of the file to remove.
570
+ * @return 0 on success, non-zero on failure.
571
+ */
526
572
static int32_t remove (const std::string &filename) {
527
573
return fossil_fstream_remove (filename.c_str ());
528
574
}
@@ -540,6 +586,15 @@ namespace fossil {
540
586
return fossil_fstream_rename (old_filename, new_filename);
541
587
}
542
588
589
+ /* *
590
+ * Rename a file or directory.
591
+ *
592
+ * This function renames a file or directory.
593
+ *
594
+ * @param old_filename The current name of the file or directory.
595
+ * @param new_filename The new name to assign to the file or directory.
596
+ * @return 0 on success, non-zero on failure.
597
+ */
543
598
static int32_t rename (const std::string &old_filename, const std::string &new_filename) {
544
599
return fossil_fstream_rename (old_filename.c_str (), new_filename.c_str ());
545
600
}
@@ -594,6 +649,15 @@ namespace fossil {
594
649
return fossil_fstream_rotate (filename, n);
595
650
}
596
651
652
+ /* *
653
+ * Rotate a file stream.
654
+ *
655
+ * This function rotates a file stream.
656
+ *
657
+ * @param filename The name of the file to rotate.
658
+ * @param n The number of rotations to perform.
659
+ * @return 0 on success, non-zero on failure.
660
+ */
597
661
static int32_t rotate (const std::string &filename, int32_t n) {
598
662
return fossil_fstream_rotate (filename.c_str (), n);
599
663
}
@@ -611,6 +675,15 @@ namespace fossil {
611
675
return fossil_fstream_backup (filename, backup_suffix);
612
676
}
613
677
678
+ /* *
679
+ * Create a backup of a file with a specified backup suffix.
680
+ *
681
+ * This function creates a backup of a file with the given suffix.
682
+ *
683
+ * @param filename The name of the file to create a backup for.
684
+ * @param backup_suffix The suffix to be appended to the backup file.
685
+ * @return 0 on success, non-zero on failure.
686
+ */
614
687
static int32_t backup (const std::string &filename, const std::string &backup_suffix) {
615
688
return fossil_fstream_backup (filename.c_str (), backup_suffix.c_str ());
616
689
}
@@ -627,6 +700,14 @@ namespace fossil {
627
700
return fossil_fstream_file_exists (filename);
628
701
}
629
702
703
+ /* *
704
+ * Check if a file exists.
705
+ *
706
+ * This function checks if a file exists.
707
+ *
708
+ * @param filename The name of the file to check for existence.
709
+ * @return 1 if the file exists, 0 if not.
710
+ */
630
711
static int32_t file_exists (const std::string &filename) {
631
712
return fossil_fstream_file_exists (filename.c_str ());
632
713
}
@@ -655,6 +736,14 @@ namespace fossil {
655
736
return fossil_fstream_delete (filename);
656
737
}
657
738
739
+ /* *
740
+ * Delete a file.
741
+ *
742
+ * This function deletes a file.
743
+ *
744
+ * @param filename The name of the file to be deleted.
745
+ * @return 0 on success, non-zero on failure.
746
+ */
658
747
static int32_t delete_file (const std::string &filename) {
659
748
return fossil_fstream_delete (filename.c_str ());
660
749
}
@@ -671,6 +760,14 @@ namespace fossil {
671
760
return fossil_fstream_get_type (filename);
672
761
}
673
762
763
+ /* *
764
+ * Get the type of a file stream.
765
+ *
766
+ * This function retrieves the type of a file stream.
767
+ *
768
+ * @param filename The name of the file to get the type of.
769
+ * @return The type of the file stream.
770
+ */
674
771
static int get_type (const std::string &filename) {
675
772
return fossil_fstream_get_type (filename.c_str ());
676
773
}
@@ -687,6 +784,14 @@ namespace fossil {
687
784
return fossil_fstream_is_readable (filename);
688
785
}
689
786
787
+ /* *
788
+ * Check if a file is readable.
789
+ *
790
+ * This function checks if a file has read permissions.
791
+ *
792
+ * @param filename The name of the file to check.
793
+ * @return 1 if readable, 0 otherwise.
794
+ */
690
795
static int32_t is_readable (const std::string &filename) {
691
796
return fossil_fstream_is_readable (filename.c_str ());
692
797
}
@@ -703,6 +808,14 @@ namespace fossil {
703
808
return fossil_fstream_is_writable (filename);
704
809
}
705
810
811
+ /* *
812
+ * Check if a file is writable.
813
+ *
814
+ * This function checks if a file has write permissions.
815
+ *
816
+ * @param filename The name of the file to check.
817
+ * @return 1 if writable, 0 otherwise.
818
+ */
706
819
static int32_t is_writable (const std::string &filename) {
707
820
return fossil_fstream_is_writable (filename.c_str ());
708
821
}
@@ -719,6 +832,14 @@ namespace fossil {
719
832
return fossil_fstream_is_executable (filename);
720
833
}
721
834
835
+ /* *
836
+ * Check if a file is executable.
837
+ *
838
+ * This function checks if a file has execute permissions.
839
+ *
840
+ * @param filename The name of the file to check.
841
+ * @return 1 if executable, 0 otherwise.
842
+ */
722
843
static int32_t is_executable (const std::string &filename) {
723
844
return fossil_fstream_is_executable (filename.c_str ());
724
845
}
@@ -736,6 +857,15 @@ namespace fossil {
736
857
return fossil_fstream_set_permissions (filename, mode);
737
858
}
738
859
860
+ /* *
861
+ * Set file permissions.
862
+ *
863
+ * This function sets the permissions for a file.
864
+ *
865
+ * @param filename The name of the file to set permissions for.
866
+ * @param mode The permissions to set (POSIX: chmod-style).
867
+ * @return 0 on success, non-zero on failure.
868
+ */
739
869
static int32_t set_permissions (const std::string &filename, int32_t mode) {
740
870
return fossil_fstream_set_permissions (filename.c_str (), mode);
741
871
}
@@ -753,10 +883,23 @@ namespace fossil {
753
883
return fossil_fstream_get_permissions (filename, mode);
754
884
}
755
885
886
+ /* *
887
+ * Get file permissions.
888
+ *
889
+ * This function retrieves the permissions of a file.
890
+ *
891
+ * @param filename The name of the file to retrieve permissions for.
892
+ * @param mode Pointer to store the retrieved permissions (POSIX style).
893
+ * @return 0 on success, non-zero on failure.
894
+ */
756
895
static int32_t get_permissions (const std::string &filename, int32_t *mode) {
757
896
return fossil_fstream_get_permissions (filename.c_str (), mode);
758
897
}
759
898
899
+ };
900
+
901
+ } // namespace io
902
+
760
903
} // namespace fossil
761
904
762
905
#endif
0 commit comments