Parcourir la source

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

master
kevin il y a 10 ans
Parent
révision
9f4c7bd291
2 fichiers modifiés avec 27 ajouts et 0 suppressions
  1. 21
    0
      cmFileSys.c
  2. 6
    0
      cmFileSys.h

+ 21
- 0
cmFileSys.c Voir le fichier

248
   return S_ISDIR(s.st_mode);
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
 bool cmFileSysIsDir( cmFileSysH_t h, const cmChar_t* dirStr )
269
 bool cmFileSysIsDir( cmFileSysH_t h, const cmChar_t* dirStr )
252
 {
270
 {
253
   cmFs_t*     p = _cmFileSysHandleToPtr(h);
271
   cmFs_t*     p = _cmFileSysHandleToPtr(h);
1129
 const cmChar_t*      cmFsUserDir()
1147
 const cmChar_t*      cmFsUserDir()
1130
 { return cmFileSysUserDir(_cmFsH); }
1148
 { return cmFileSysUserDir(_cmFsH); }
1131
 
1149
 
1150
+bool                cmFsCanWriteToDir( const cmChar_t* dirStr )
1151
+{ return cmFileSysCanWriteToDir(_cmFsH,dirStr); }
1152
+
1132
 bool                 cmFsIsDir(  const cmChar_t* dirStr )
1153
 bool                 cmFsIsDir(  const cmChar_t* dirStr )
1133
 { return cmFileSysIsDir(_cmFsH,dirStr); }
1154
 { return cmFileSysIsDir(_cmFsH,dirStr); }
1134
 
1155
 

+ 6
- 0
cmFileSys.h Voir le fichier

36
     kLinuxFailFsRC,
36
     kLinuxFailFsRC,
37
     kInvalidDirFsRC,
37
     kInvalidDirFsRC,
38
     kGenFileFailFsRC,
38
     kGenFileFailFsRC,
39
+    kAccessFailFsRC
39
   };
40
   };
40
 
41
 
41
 
42
 
65
   const cmChar_t* cmFileSysRsrcDir(  cmFileSysH_t h ); //< Return the operating system dependent application resource directory for this application.
66
   const cmChar_t* cmFileSysRsrcDir(  cmFileSysH_t h ); //< Return the operating system dependent application resource directory for this application.
66
   const cmChar_t* cmFileSysUserDir(  cmFileSysH_t h ); //< Return the operating system dependent user directory for this application.
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
   // Test the type of a file system object:
72
   // Test the type of a file system object:
69
   //
73
   //
70
   bool     cmFileSysIsDir(  cmFileSysH_t h, const cmChar_t* dirStr ); //< Return true if 'dirStr' refers to an existing directory.
74
   bool     cmFileSysIsDir(  cmFileSysH_t h, const cmChar_t* dirStr ); //< Return true if 'dirStr' refers to an existing directory.
203
   const cmChar_t* cmFsRsrcDir();
207
   const cmChar_t* cmFsRsrcDir();
204
   const cmChar_t* cmFsUserDir();
208
   const cmChar_t* cmFsUserDir();
205
 
209
 
210
+  bool            cmFsCanWriteToDir( const cmChar_t* dirStr );
211
+
206
   bool            cmFsIsDir(  const cmChar_t* dirStr );
212
   bool            cmFsIsDir(  const cmChar_t* dirStr );
207
   bool            cmFsIsFile( const cmChar_t* fnStr ); 
213
   bool            cmFsIsFile( const cmChar_t* fnStr ); 
208
   bool            cmFsIsLink( const cmChar_t* fnStr ); 
214
   bool            cmFsIsLink( const cmChar_t* fnStr ); 

Chargement…
Annuler
Enregistrer