|
@@ -7,6 +7,7 @@
|
7
|
7
|
#include "cmMallocDebug.h"
|
8
|
8
|
#include "cmLinkedHeap.h"
|
9
|
9
|
#include "cmFileSys.h"
|
|
10
|
+#include "cmText.h"
|
10
|
11
|
|
11
|
12
|
#include <sys/stat.h>
|
12
|
13
|
#include <errno.h>
|
|
@@ -467,6 +468,45 @@ void cmFileSysFreeFn( cmFileSysH_t h, const cmChar_t* fn )
|
467
|
468
|
cmLHeapFree(p->heapH, (void*)fn);
|
468
|
469
|
}
|
469
|
470
|
|
|
471
|
+cmFsRC_t cmFileSysGenFn( cmFileSysH_t h, const cmChar_t* dir, const cmChar_t* prefixStr, const cmChar_t* extStr, const cmChar_t** fnPtr )
|
|
472
|
+{
|
|
473
|
+ cmFsRC_t rc = kOkFsRC;
|
|
474
|
+ cmFs_t* p = _cmFileSysHandleToPtr(h);
|
|
475
|
+ unsigned maxAttemptCnt = 0xffff;
|
|
476
|
+
|
|
477
|
+ *fnPtr = NULL;
|
|
478
|
+
|
|
479
|
+ assert(dir != NULL);
|
|
480
|
+
|
|
481
|
+ if( prefixStr == NULL )
|
|
482
|
+ prefixStr = "";
|
|
483
|
+
|
|
484
|
+ if( extStr == NULL )
|
|
485
|
+ extStr = "";
|
|
486
|
+
|
|
487
|
+ if( !cmFileSysIsDir(h,dir) )
|
|
488
|
+ return cmErrMsg(&p->err,kOpenDirFailFsRC,"File name generation failed because the directory '%s' does not exist.",cmStringNullGuard(dir));
|
|
489
|
+
|
|
490
|
+ unsigned i;
|
|
491
|
+ for(i=0; *fnPtr==NULL; ++i)
|
|
492
|
+ {
|
|
493
|
+ cmChar_t* fn = cmTsPrintfP(NULL,"%s%i",prefixStr,i);
|
|
494
|
+
|
|
495
|
+ const cmChar_t* path = cmFileSysMakeFn(h,dir,fn,extStr,NULL );
|
|
496
|
+
|
|
497
|
+ if( !cmFileSysIsFile(h,path) )
|
|
498
|
+ *fnPtr = cmMemAllocStr(path);
|
|
499
|
+
|
|
500
|
+ cmFileSysFreeFn(h,path);
|
|
501
|
+ cmMemFree(fn);
|
|
502
|
+
|
|
503
|
+ if( i == maxAttemptCnt )
|
|
504
|
+ return cmErrMsg(&p->err,kGenFileFailFsRC,"File name generation failed because a suitable file name could not be found after %i attempts.",maxAttemptCnt);
|
|
505
|
+ };
|
|
506
|
+
|
|
507
|
+ return rc;
|
|
508
|
+}
|
|
509
|
+
|
470
|
510
|
cmFsRC_t cmFileSysMkDir( cmFileSysH_t h, const cmChar_t* dir )
|
471
|
511
|
{
|
472
|
512
|
cmFs_t* p = _cmFileSysHandleToPtr(h);
|
|
@@ -1113,6 +1153,9 @@ const cmChar_t* cmFsMakeFn( const cmChar_t* dirPrefix, const cmChar_t* fn,
|
1113
|
1153
|
void cmFsFreeFn( const cmChar_t* fn )
|
1114
|
1154
|
{ cmFileSysFreeFn(_cmFsH, fn); }
|
1115
|
1155
|
|
|
1156
|
+cmFsRC_t cmFsGenFn( const cmChar_t* dir, const cmChar_t* prefixStr, const cmChar_t* extStr, const cmChar_t** fnPtr )
|
|
1157
|
+{ return cmFileSysGenFn(_cmFsH,dir,prefixStr,extStr,fnPtr); }
|
|
1158
|
+
|
1116
|
1159
|
cmFsRC_t cmFsMkDir( const cmChar_t* dir )
|
1117
|
1160
|
{ return cmFileSysMkDir(_cmFsH,dir); }
|
1118
|
1161
|
|