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

This commit is contained in:
kevin 2014-02-01 12:49:28 -08:00
parent 0cccd0392d
commit 9f4c7bd291
2 changed files with 27 additions and 0 deletions

View File

@ -248,6 +248,24 @@ bool _cmFileSysIsDir( cmFs_t* p, const cmChar_t* dirStr )
return S_ISDIR(s.st_mode); return S_ISDIR(s.st_mode);
} }
bool cmFileSysCanWriteToDir( cmFileSysH_t h, const cmChar_t* dirStr )
{
cmFs_t* p = _cmFileSysHandleToPtr(h);
int result;
errno = 0;
if((result = access(dirStr,W_OK)) == 0 )
return true;
if( result == EACCES || result==EROFS )
return false;
_cmFileSysError( p, kAccessFailFsRC, errno, "'access' failed on '%s'.",dirStr);
return false;
}
bool cmFileSysIsDir( cmFileSysH_t h, const cmChar_t* dirStr ) bool cmFileSysIsDir( cmFileSysH_t h, const cmChar_t* dirStr )
{ {
cmFs_t* p = _cmFileSysHandleToPtr(h); cmFs_t* p = _cmFileSysHandleToPtr(h);
@ -1129,6 +1147,9 @@ const cmChar_t* cmFsRsrcDir()
const cmChar_t* cmFsUserDir() const cmChar_t* cmFsUserDir()
{ return cmFileSysUserDir(_cmFsH); } { return cmFileSysUserDir(_cmFsH); }
bool cmFsCanWriteToDir( const cmChar_t* dirStr )
{ return cmFileSysCanWriteToDir(_cmFsH,dirStr); }
bool cmFsIsDir( const cmChar_t* dirStr ) bool cmFsIsDir( const cmChar_t* dirStr )
{ return cmFileSysIsDir(_cmFsH,dirStr); } { return cmFileSysIsDir(_cmFsH,dirStr); }

View File

@ -36,6 +36,7 @@ extern "C" {
kLinuxFailFsRC, kLinuxFailFsRC,
kInvalidDirFsRC, kInvalidDirFsRC,
kGenFileFailFsRC, kGenFileFailFsRC,
kAccessFailFsRC
}; };
@ -65,6 +66,9 @@ extern "C" {
const cmChar_t* cmFileSysRsrcDir( cmFileSysH_t h ); //< Return the operating system dependent application resource directory for this application. const cmChar_t* cmFileSysRsrcDir( cmFileSysH_t h ); //< Return the operating system dependent application resource directory for this application.
const cmChar_t* cmFileSysUserDir( cmFileSysH_t h ); //< Return the operating system dependent user directory for this application. const cmChar_t* cmFileSysUserDir( cmFileSysH_t h ); //< Return the operating system dependent user directory for this application.
// Check if a request to create a file will succeed.
bool cmFileSysCanWriteToDir( cmFileSysH_t h, const cmChar_t* dirStr );
// Test the type of a file system object: // Test the type of a file system object:
// //
bool cmFileSysIsDir( cmFileSysH_t h, const cmChar_t* dirStr ); //< Return true if 'dirStr' refers to an existing directory. bool cmFileSysIsDir( cmFileSysH_t h, const cmChar_t* dirStr ); //< Return true if 'dirStr' refers to an existing directory.
@ -203,6 +207,8 @@ extern "C" {
const cmChar_t* cmFsRsrcDir(); const cmChar_t* cmFsRsrcDir();
const cmChar_t* cmFsUserDir(); const cmChar_t* cmFsUserDir();
bool cmFsCanWriteToDir( const cmChar_t* dirStr );
bool cmFsIsDir( const cmChar_t* dirStr ); bool cmFsIsDir( const cmChar_t* dirStr );
bool cmFsIsFile( const cmChar_t* fnStr ); bool cmFsIsFile( const cmChar_t* fnStr );
bool cmFsIsLink( const cmChar_t* fnStr ); bool cmFsIsLink( const cmChar_t* fnStr );