1 // Copyright (c) 2012- PPSSPP Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
19 #include "file/file_util.h"
20 #include "Common/FileUtil.h"
21 #include "Core/FileLoaders/LocalFileLoader.h"
23 LocalFileLoader::LocalFileLoader(const std::string
&filename
)
24 : fd_(0), f_(nullptr), filesize_(0), filename_(filename
) {
25 f_
= File::OpenCFile(filename
, "rb");
31 // Android NDK does not support 64-bit file I/O using C streams
32 // so we fall back onto syscalls
35 off64_t off
= lseek64(fd_
, 0, SEEK_END
);
37 lseek64(fd_
, 0, SEEK_SET
);
39 fseek(f_
, 0, SEEK_END
);
40 filesize_
= ftello(f_
);
41 fseek(f_
, 0, SEEK_SET
);
45 LocalFileLoader::~LocalFileLoader() {
51 bool LocalFileLoader::Exists() {
52 // If we couldn't open it for reading, we say it does not exist.
53 if (f_
|| IsDirectory()) {
55 return getFileInfo(filename_
.c_str(), &info
);
60 bool LocalFileLoader::IsDirectory() {
62 if (getFileInfo(filename_
.c_str(), &info
)) {
63 return info
.isDirectory
;
68 s64
LocalFileLoader::FileSize() {
72 std::string
LocalFileLoader::Path() const {
76 void LocalFileLoader::Seek(s64 absolutePos
) {
78 lseek64(fd_
, absolutePos
, SEEK_SET
);
80 fseeko(f_
, absolutePos
, SEEK_SET
);
84 size_t LocalFileLoader::Read(size_t bytes
, size_t count
, void *data
) {
86 return read(fd_
, data
, bytes
* count
) / bytes
;
88 return fread(data
, bytes
, count
, f_
);
92 size_t LocalFileLoader::ReadAt(s64 absolutePos
, size_t bytes
, size_t count
, void *data
) {
94 return Read(bytes
, count
, data
);