38 #if !defined(HAVE_FEATURES_H) || defined(ANDROID)
44 #define FILE_DELIMITER_CHAR '\\'
45 #define FILE_DELIMITER "\\"
47 #define FILE_DELIMITER_CHAR '/'
48 #define FILE_DELIMITER "/"
54 : _type(DT_UNKNOWN), _path()
58 File::File(
const std::string &path,
const unsigned char t)
59 : _type(t), _path(path)
61 resolveAbsolutePath();
66 :_type(DT_UNKNOWN), _path(path)
68 resolveAbsolutePath();
73 void File::removeSlash()
77 std::string::iterator iter = _path.end(); --iter;
85 void File::resolveAbsolutePath()
88 std::string::iterator iter = _path.begin();
100 DWORD st = GetFileAttributesA(_path.c_str());
101 if (st == INVALID_FILE_ATTRIBUTES)
107 if( stat(_path.c_str(), &st ) == 0)
117 DWORD s = GetFileAttributesA(_path.c_str());
118 if (s == INVALID_FILE_ATTRIBUTES) {
121 else if (s & FILE_ATTRIBUTE_DIRECTORY) {
130 if ( stat(_path.c_str(), &s) == 0 )
132 int type = s.st_mode & S_IFMT;
169 struct dirent dirp_data;
171 if((dp = opendir(_path.c_str())) == NULL) {
176 while ((dirp = ::readdir(dp)) != NULL)
178 while (::readdir_r(dp, &dirp_data, &dirp) == 0)
181 if (dirp == NULL)
break;
186 std::string name = std::string(dirp->d_name);
191 File file(ss.str(), dirp->d_type);
193 files.push_back(file);
212 if (
_type == DT_DIR)
return true;
223 #if !defined(ANDROID) && defined(HAVE_FEATURES_H)
224 return std::string(basename(_path.c_str()));
226 char path[_path.length()+1];
227 ::memcpy(&path, _path.c_str(), _path.length()+1);
229 return std::string(basename(path));
247 if (
_type == DT_UNKNOWN)
return -1;
262 for (list<File>::iterator iter = files.begin(); iter != files.end(); ++iter)
267 if ((ret = file.
remove(recursive)) < 0)
285 if (
isRoot())
return (*
this);
288 if (pos == string::npos)
return (*
this);
290 return File(_path.substr(0, pos));
302 ::mkdir(path.
getPath().c_str());
304 ::mkdir(path.
getPath().c_str(), 0700);
314 struct stat filestatus;
315 stat(
getPath().c_str(), &filestatus );
316 return static_cast<size_t>(filestatus.st_size);
321 struct stat filestatus;
322 stat(
getPath().c_str(), &filestatus );
323 return filestatus.st_atime;
328 struct stat filestatus;
329 stat(
getPath().c_str(), &filestatus );
330 return filestatus.st_mtime;
335 struct stat filestatus;
336 stat(
getPath().c_str(), &filestatus );
337 return filestatus.st_ctime;
342 return (other._path == _path);
347 return (_path < other._path);
351 :
File(tmpname(path, prefix))
359 std::string TemporaryFile::tmpname(
const File &path,
const std::string prefix)
369 std::vector<char> name(pattern.length() + 1);
370 ::strcpy(&name[0], pattern.c_str());
382 if (_mktemp(&name[0]) == NULL) {
383 if (errno == EINVAL) {
386 else if (errno == EEXIST) {
391 std::fstream file(&name[0], std::fstream::out | std::fstream::trunc);
396 int fd = mkstemp(&name[0]);
401 return std::string(name.begin(), name.end());