diff --git a/cmFileSys.c b/cmFileSys.c index 470c463..a5855fc 100644 --- a/cmFileSys.c +++ b/cmFileSys.c @@ -248,6 +248,24 @@ bool _cmFileSysIsDir( cmFs_t* p, const cmChar_t* dirStr ) 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 ) { cmFs_t* p = _cmFileSysHandleToPtr(h); @@ -1129,6 +1147,9 @@ const cmChar_t* cmFsRsrcDir() const cmChar_t* cmFsUserDir() { return cmFileSysUserDir(_cmFsH); } +bool cmFsCanWriteToDir( const cmChar_t* dirStr ) +{ return cmFileSysCanWriteToDir(_cmFsH,dirStr); } + bool cmFsIsDir( const cmChar_t* dirStr ) { return cmFileSysIsDir(_cmFsH,dirStr); } diff --git a/cmFileSys.h b/cmFileSys.h index 073b1f2..e8a6d88 100644 --- a/cmFileSys.h +++ b/cmFileSys.h @@ -36,6 +36,7 @@ extern "C" { kLinuxFailFsRC, kInvalidDirFsRC, 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* 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: // 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* cmFsUserDir(); + bool cmFsCanWriteToDir( const cmChar_t* dirStr ); + bool cmFsIsDir( const cmChar_t* dirStr ); bool cmFsIsFile( const cmChar_t* fnStr ); bool cmFsIsLink( const cmChar_t* fnStr );