|
@@ -36,7 +36,7 @@ cmFileRC_t _cmFileError( cmFile_t* p, cmFileRC_t rc, int errNumb, const cmChar_t
|
36
|
36
|
return rc;
|
37
|
37
|
}
|
38
|
38
|
|
39
|
|
-cmFileRC_t cmFileOpen( cmFileH_t* hp, const cmChar_t* fn, enum cmFileOpenFlags_t flags, cmRpt_t* rpt )
|
|
39
|
+cmFileRC_t cmFileOpen( cmFileH_t* hp, const cmChar_t* fn, enum cmFileOpenFlags_t flags, cmRpt_t* rpt )
|
40
|
40
|
{
|
41
|
41
|
char mode[] = "/0/0/0";
|
42
|
42
|
cmFile_t* p = NULL;
|
|
@@ -731,6 +731,57 @@ cmFileRC_t cmFileWriteBool( cmFileH_t h, const bool* buf, unsigned c
|
731
|
731
|
{ return cmFileWrite(h,buf,sizeof(buf[0])*cnt); }
|
732
|
732
|
|
733
|
733
|
|
|
734
|
+cmFileRC_t cmFileWriteStr( cmFileH_t h, const cmChar_t* s )
|
|
735
|
+{
|
|
736
|
+ cmFileRC_t rc;
|
|
737
|
+
|
|
738
|
+ unsigned n = cmTextLength(s);
|
|
739
|
+
|
|
740
|
+ if((rc = cmFileWriteUInt(h,&n,1)) != kOkFileRC )
|
|
741
|
+ return rc;
|
|
742
|
+
|
|
743
|
+ if( n > 0 )
|
|
744
|
+ rc = cmFileWriteChar(h,s,n);
|
|
745
|
+ return rc;
|
|
746
|
+}
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+cmFileRC_t cmFileReadStr( cmFileH_t h, cmChar_t** sRef, unsigned maxCharN )
|
|
750
|
+{
|
|
751
|
+ unsigned n;
|
|
752
|
+ cmFileRC_t rc;
|
|
753
|
+
|
|
754
|
+ assert(sRef != NULL );
|
|
755
|
+
|
|
756
|
+ *sRef = NULL;
|
|
757
|
+
|
|
758
|
+ if( maxCharN == 0 )
|
|
759
|
+ maxCharN = 16384;
|
|
760
|
+
|
|
761
|
+ // read the string length
|
|
762
|
+ if((rc = cmFileReadUInt(h,&n,1)) != kOkFileRC )
|
|
763
|
+ return rc;
|
|
764
|
+
|
|
765
|
+ // verify that string isn't too long
|
|
766
|
+ if( n > maxCharN )
|
|
767
|
+ {
|
|
768
|
+ cmFile_t* p = _cmFileHandleToPtr(h);
|
|
769
|
+ return cmErrMsg(&p->err,kBufAllocFailFileRC,"The stored string is larger than the maximum allowable size.");
|
|
770
|
+ }
|
|
771
|
+
|
|
772
|
+ // allocate a read buffer
|
|
773
|
+ cmChar_t* s = cmMemAllocZ(cmChar_t,n+1);
|
|
774
|
+
|
|
775
|
+ // fill the buffer from the file
|
|
776
|
+ if((rc = cmFileReadChar(h,s,n)) != kOkFileRC )
|
|
777
|
+ return rc;
|
|
778
|
+
|
|
779
|
+ s[n] = 0; // terminate the string
|
|
780
|
+
|
|
781
|
+ *sRef = s;
|
|
782
|
+
|
|
783
|
+ return rc;
|
|
784
|
+}
|
734
|
785
|
|
735
|
786
|
|
736
|
787
|
cmFileRC_t cmFilePrint( cmFileH_t h, const cmChar_t* text )
|
|
@@ -765,3 +816,14 @@ cmFileRC_t cmFilePrintf( cmFileH_t h, const cmChar_t* fmt, ... )
|
765
|
816
|
}
|
766
|
817
|
|
767
|
818
|
|
|
819
|
+cmFileRC_t cmFileLastRC( cmFileH_t h )
|
|
820
|
+{
|
|
821
|
+ cmFile_t* p = _cmFileHandleToPtr(h);
|
|
822
|
+ return cmErrLastRC(&p->err);
|
|
823
|
+}
|
|
824
|
+
|
|
825
|
+cmFileRC_t cmFileSetRC( cmFileH_t h, cmFileRC_t rc )
|
|
826
|
+{
|
|
827
|
+ cmFile_t* p = _cmFileHandleToPtr(h);
|
|
828
|
+ return cmErrSetRC(&p->err,rc);
|
|
829
|
+}
|