Procházet zdrojové kódy

cmFileSys.h/c: Added cmFileSysCanWriteToDir() and cmFsCanWriteToDir().

master
kevin před 10 roky
rodič
revize
9f4c7bd291
2 změnil soubory, kde provedl 27 přidání a 0 odebrání
  1. 21
    0
      cmFileSys.c
  2. 6
    0
      cmFileSys.h

+ 21
- 0
cmFileSys.c Zobrazit soubor

@@ -248,6 +248,24 @@ bool _cmFileSysIsDir( cmFs_t* p, const cmChar_t* dirStr )
248 248
   return S_ISDIR(s.st_mode);
249 249
 }
250 250
 
251
+bool cmFileSysCanWriteToDir( cmFileSysH_t h, const cmChar_t* dirStr )
252
+{
253
+  cmFs_t*     p = _cmFileSysHandleToPtr(h);
254
+  int result;
255
+
256
+  errno = 0;
257
+
258
+  if((result = access(dirStr,W_OK)) == 0 )
259
+    return true;
260
+
261
+  if( result == EACCES || result==EROFS )
262
+    return false;
263
+
264
+  _cmFileSysError( p, kAccessFailFsRC, errno, "'access' failed on '%s'.",dirStr);
265
+
266
+  return false;  
267
+}
268
+
251 269
 bool cmFileSysIsDir( cmFileSysH_t h, const cmChar_t* dirStr )
252 270
 {
253 271
   cmFs_t*     p = _cmFileSysHandleToPtr(h);
@@ -1129,6 +1147,9 @@ const cmChar_t*      cmFsRsrcDir()
1129 1147
 const cmChar_t*      cmFsUserDir()
1130 1148
 { return cmFileSysUserDir(_cmFsH); }
1131 1149
 
1150
+bool                cmFsCanWriteToDir( const cmChar_t* dirStr )
1151
+{ return cmFileSysCanWriteToDir(_cmFsH,dirStr); }
1152
+
1132 1153
 bool                 cmFsIsDir(  const cmChar_t* dirStr )
1133 1154
 { return cmFileSysIsDir(_cmFsH,dirStr); }
1134 1155
 

+ 6
- 0
cmFileSys.h Zobrazit soubor

@@ -36,6 +36,7 @@ extern "C" {
36 36
     kLinuxFailFsRC,
37 37
     kInvalidDirFsRC,
38 38
     kGenFileFailFsRC,
39
+    kAccessFailFsRC
39 40
   };
40 41
 
41 42
 
@@ -65,6 +66,9 @@ extern "C" {
65 66
   const cmChar_t* cmFileSysRsrcDir(  cmFileSysH_t h ); //< Return the operating system dependent application resource directory for this application.
66 67
   const cmChar_t* cmFileSysUserDir(  cmFileSysH_t h ); //< Return the operating system dependent user directory for this application.
67 68
 
69
+  // Check if a request to create a file will succeed.
70
+  bool cmFileSysCanWriteToDir( cmFileSysH_t h, const cmChar_t* dirStr );
71
+
68 72
   // Test the type of a file system object:
69 73
   //
70 74
   bool     cmFileSysIsDir(  cmFileSysH_t h, const cmChar_t* dirStr ); //< Return true if 'dirStr' refers to an existing directory.
@@ -203,6 +207,8 @@ extern "C" {
203 207
   const cmChar_t* cmFsRsrcDir();
204 208
   const cmChar_t* cmFsUserDir();
205 209
 
210
+  bool            cmFsCanWriteToDir( const cmChar_t* dirStr );
211
+
206 212
   bool            cmFsIsDir(  const cmChar_t* dirStr );
207 213
   bool            cmFsIsFile( const cmChar_t* fnStr ); 
208 214
   bool            cmFsIsLink( const cmChar_t* fnStr ); 

Načítá se…
Zrušit
Uložit