35 #if !defined(HAVE_FEATURES_H) || defined(ANDROID)
42 : _path(), _type(DT_UNKNOWN)
46 File::File(
const std::string &path,
const unsigned char t)
47 : _path(path), _type(t)
49 resolveAbsolutePath();
54 : _path(path), _type(DT_UNKNOWN)
56 resolveAbsolutePath();
61 void File::removeSlash()
63 std::string::iterator iter = _path.end(); --iter;
71 void File::resolveAbsolutePath()
73 std::string::iterator iter = _path.begin();
84 if( stat(_path.c_str(), &st ) == 0)
94 if ( stat(_path.c_str(), &s) == 0 )
96 int type = s.st_mode & S_IFMT;
132 struct dirent dirp_data;
134 if((dp = opendir(_path.c_str())) == NULL) {
138 while (::readdir_r(dp, &dirp_data, &dirp) == 0)
140 if (dirp == NULL)
break;
145 std::string name = std::string(dirp->d_name);
146 std::stringstream ss; ss <<
getPath() <<
"/" << name;
147 File file(ss.str(), dirp->d_type);
148 files.push_back(file);
162 if (_type == DT_DIR)
return true;
173 #if !defined(ANDROID) && defined(HAVE_FEATURES_H)
174 return std::string(basename(_path.c_str()));
176 char path[_path.length()+1];
177 ::memcpy(&path, _path.c_str(), _path.length()+1);
179 return std::string(basename(path));
185 stringstream ss; ss <<
getPath() <<
"/" << filename;
194 if (_type == DT_UNKNOWN)
return -1;
209 for (list<File>::iterator iter = files.begin(); iter != files.end(); ++iter)
214 if ((ret = file.
remove(recursive)) < 0)
232 size_t pos = _path.find_last_of(
'/');
233 return File(_path.substr(0, pos));
244 ::mkdir(path.
getPath().c_str(), 0700);
253 struct stat filestatus;
254 stat(
getPath().c_str(), &filestatus );
255 return static_cast<size_t>(filestatus.st_size);
260 struct stat filestatus;
261 stat(
getPath().c_str(), &filestatus );
262 return filestatus.st_atime;
267 struct stat filestatus;
268 stat(
getPath().c_str(), &filestatus );
269 return filestatus.st_mtime;
274 struct stat filestatus;
275 stat(
getPath().c_str(), &filestatus );
276 return filestatus.st_ctime;
281 return (other._path == _path);
286 return (_path < other._path);
290 :
File(tmpname(path, prefix))
298 std::string TemporaryFile::tmpname(
const File &path,
const std::string prefix)
306 std::string pattern = path.
getPath() +
"/" + prefix +
"XXXXXX";
308 std::vector<char> name(pattern.length() + 1);
309 ::strcpy(&name[0], pattern.c_str());
311 int fd = mkstemp(&name[0]);
315 return std::string(name.begin(), name.end());