43 #include <sys/types.h>
65 const std::string &filename,
68 const std::string path =
static_cast<DirEntry*
>(entry)->rootSubDir +
90 const std::string &filename)
96 const std::string &filename)
105 #if defined(__native_client__)
109 #elif defined(ANDROID)
151 ptr->rwops_size = &FsDir::rwops_size;
171 std::string filename,
173 std::string &realDir)
196 const std::string path =
static_cast<DirEntry*
>(entry)->rootSubDir +
198 const dirent *next_file =
nullptr;
199 DIR *
const dir = opendir(path.c_str());
202 while ((next_file = readdir(dir)) !=
nullptr)
204 const std::string file = next_file->d_name;
205 if (file ==
"." || file ==
"..")
211 if (lstat(path.c_str(), &statbuf) == 0 &&
212 S_ISLNK(statbuf.st_mode) != 0)
229 names.push_back(file);
239 std::string path =
static_cast<DirEntry*
>(entry)->rootSubDir + dirName;
242 if (stat(path.c_str(), &statbuf) == 0)
244 isDirFlag = (S_ISDIR(statbuf.st_mode) != 0);
264 return lstat(name.c_str(), &statbuf) == 0 &&
265 S_ISLNK(statbuf.st_mode) != 0;
322 const uint32_t objSize,
323 const uint32_t objCount)
333 #ifdef USE_FILE_FOPEN
334 return fread(buffer, objSize, objCount, fd);
336 int max = objSize * objCount;
337 int cnt =
::read(fd, buffer, max);
340 return cnt / objSize;
346 const uint32_t objSize,
347 const uint32_t objCount)
357 #ifdef USE_FILE_FOPEN
358 return fwrite(buffer, objSize, objCount, fd);
360 int max = objSize * objCount;
361 int cnt =
::write(fd, buffer, max);
364 return cnt / objSize;
378 #ifdef USE_FILE_FOPEN
379 const long pos = ftell(fd);
385 fseek(fd, 0, SEEK_END);
386 const long sz = ftell(fd);
387 fseek(fd, pos, SEEK_SET);
391 if (fstat(fd, &statbuf) == -1)
396 return static_cast<int64_t
>(statbuf.st_size);
411 #ifdef USE_FILE_FOPEN
414 return lseek(fd, 0, SEEK_CUR);
430 const int64_t res =
FILESEEK(fd, pos, SEEK_SET);
447 #ifdef USE_FILE_FOPEN
448 const int flag = feof(fd);
451 const int64_t pos = ftell(fd);
454 const int64_t pos = lseek(fd, 0, SEEK_CUR);
456 if (fstat(fd, &statbuf) == -1)
461 const int64_t len =
static_cast<int64_t
>(statbuf.st_size);
463 return static_cast<int>(pos < 0 || len < 0 || pos >= len);
467 std::string filename,
471 const std::string path = dirEntry->
rootSubDir + filename;
487 #ifdef USE_FILE_FOPEN
488 fseek(fd, 0, SEEK_END);
489 const long sz = ftell(fd);
497 fseek(fd, 0, SEEK_SET);
498 fileSize =
static_cast<int>(sz);
501 if (fstat(fd, &statbuf) == -1)
508 fileSize =
static_cast<int>(statbuf.st_size);
514 buffer[fileSize - 1] = 0;
516 #ifdef USE_FILE_FOPEN
517 const int cnt =
CAST_S32(fread(buffer, 1, fileSize, fd));
519 const int cnt =
::read(fd, buffer, fileSize);
540 const std::string path =
static_cast<DirEntry*
>(entry)->rootSubDir +
542 const dirent *next_file =
nullptr;
543 DIR *
const dir = opendir(path.c_str());
546 while ((next_file = readdir(dir)) !=
nullptr)
549 const std::string file = next_file->d_name;
550 if (file ==
"." || file ==
"..")
555 if (lstat(path.c_str(), &statbuf) == 0 &&
556 S_ISLNK(statbuf.st_mode) != 0)
563 const std::string filePath =
pathJoin(path, file);
564 if (stat(filePath.c_str(), &statbuf) == 0)
566 if (S_ISDIR(statbuf.st_mode) != 0)
580 names.push_back(file);
587 const std::string &dirName,
590 const std::string path =
static_cast<DirEntry*
>(entry)->rootSubDir +
592 const dirent *next_file =
nullptr;
593 DIR *
const dir = opendir(path.c_str());
596 while ((next_file = readdir(dir)) !=
nullptr)
599 const std::string file = next_file->d_name;
600 if (file ==
"." || file ==
"..")
605 if (lstat(path.c_str(), &statbuf) == 0 &&
606 S_ISLNK(statbuf.st_mode) != 0)
613 const std::string filePath =
pathJoin(path, file);
614 if (stat(filePath.c_str(), &statbuf) == 0)
616 if (S_ISDIR(statbuf.st_mode) != 0)
630 names.push_back(
pathJoin(dirName, file));
640 const std::string path =
static_cast<DirEntry*
>(entry)->rootSubDir +
642 const dirent *next_file =
nullptr;
643 DIR *
const dir = opendir(path.c_str());
646 while ((next_file = readdir(dir)) !=
nullptr)
649 const std::string file = next_file->d_name;
650 if (file ==
"." || file ==
"..")
655 if (lstat(path.c_str(), &statbuf) == 0 &&
656 S_ISLNK(statbuf.st_mode) != 0)
663 const std::string filePath =
pathJoin(path, file);
664 if (stat(filePath.c_str(), &statbuf) == 0)
666 if (S_ISDIR(statbuf.st_mode) == 0)
680 names.push_back(file);
#define reportAlways(...)
void log(const char *const log_text,...)
#define FILEOPEN_FLAG_APPEND
#define FILEOPEN_FLAG_WRITE
#define FILEOPEN(path, mode)
#define FILEOPEN_FLAG_READ
#define FOR_EACH(type, iter, array)
const char * dirSeparator
int mkdir_r(const char *const pathname)
Create a directory, making leading components first if necessary.
bool existsLocal(const std::string &path)
File * openRead(FsEntry *const entry, std::string filename)
const char * getBaseDir()
File * openAppend(FsEntry *const entry, const std::string &filename)
bool isSymbolicLink(std::string name)
bool exists(FsEntry *const entry, std::string fileName, std::string dirName)
int rwops_write(SDL_RWops *const rw, const void *const ptr, const int size, const int maxnum)
int32_t rwops_seek(SDL_RWops *const rw, const int32_t offset, const int whence)
int rwops_close(SDL_RWops *const rw)
int close(File *const file)
int64_t fileLength(File *const file)
bool setWriteDir(std::string newDir)
void freeList(List *const handle)
File * openInternal(FsEntry *const entry, const std::string &filename, const char *mode)
int eof(File *const file)
void getFilesWithDir(FsEntry *const entry, const std::string &dirName, StringVect &names)
File * openWrite(FsEntry *const entry, const std::string &filename)
int64_t read(File *const file, void *const buffer, const uint32_t objSize, const uint32_t objCount)
bool getRealDir(FsEntry *const entry, std::string filename, std::string dirName, std::string &realDir)
const char * getUserDir()
void getDirs(FsEntry *const entry, std::string dirName, StringVect &names)
const char * loadFile(FsEntry *const entry, std::string filename, int &fileSize)
int seek(File *const file, const uint64_t pos)
void init(const std::string &name)
int rwops_read(SDL_RWops *const rw, void *const ptr, const int size, const int maxnum)
void permitLinks(const bool val)
bool isDirectory(FsEntry *const entry, std::string dirName, bool &isDirFlag)
bool remove(std::string filename)
void getFiles(FsEntry *const entry, std::string dirName, StringVect &names)
void enumerate(FsEntry *const entry, std::string dirName, StringVect &names)
bool mkdir(std::string dirname)
void initFuncs(FsFuncs *const ptr)
int64_t tell(File *const file)
int64_t write(File *const file, const void *const buffer, const uint32_t objSize, const uint32_t objCount)
std::string getRealPath(const std::string &str)
bool checkPath(const std::string &path)
std::string getHomePath()
void prepareFsPath(std::string &path)
std::string getFileDir(const std::string &path)
bool findLast(const std::string &str1, const std::string &str2)
std::string pathJoin(std::string str1, const std::string &str2)
StringVect::const_iterator StringVectCIter
std::vector< std::string > StringVect