////////////////////////////////////////////////////////////////////////// FileWritable //////////////////////////////////////////////////////////////////////////
| 155 | // FileWritable |
| 156 | /////////////////////////////////////////////////////////////////////////////// |
| 157 | bool cFileUtil::FileWritable(const TSTRING& fileName) |
| 158 | { |
| 159 | // if the file does not exist, but could be |
| 160 | // created then return true |
| 161 | if (_taccess(fileName.c_str(), F_OK) != 0) |
| 162 | { |
| 163 | // After some other attempts to see if we could create |
| 164 | // the file, it became easier to just to create the file |
| 165 | // and check for failure. |
| 166 | int fh; |
| 167 | if ((fh = _tcreat(fileName.c_str(), 0777)) == -1) |
| 168 | return false; |
| 169 | |
| 170 | close(fh); |
| 171 | if (_tunlink(fileName.c_str()) != 0) |
| 172 | ASSERT(false); |
| 173 | |
| 174 | return true; |
| 175 | } |
| 176 | else // file exists; make sure it is writable and not a dir |
| 177 | { |
| 178 | return ((_taccess(fileName.c_str(), W_OK) == 0) && !cFileUtil::IsDir(fileName)); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /////////////////////////////////////////////////////////////////////////////// |
| 183 | // BackupFile |