diff --git a/starboard/common/file.cc b/starboard/common/file.cc index 4ce81e6c2871..c0b59d5e08e0 100644 --- a/starboard/common/file.cc +++ b/starboard/common/file.cc @@ -86,11 +86,9 @@ bool SbFileDeleteRecursive(const char* path, bool preserve_root) { // The |path| points to a file. Remove it and return. if (err != kSbFileOk) { - return SbFileDelete(path); + return (unlink(path) == 0); } - SbFileInfo info; - std::vector entry(kSbFileMaxName); while (SbDirectoryGetNext(dir, entry.data(), kSbFileMaxName)) { @@ -110,7 +108,7 @@ bool SbFileDeleteRecursive(const char* path, bool preserve_root) { // Don't forget to close and remove the directory before returning! if (DirectoryCloseLogFailure(path, dir)) { - return preserve_root ? true : SbFileDelete(path); + return preserve_root ? true : (rmdir(path) == 0); } return false; } diff --git a/starboard/common/file.h b/starboard/common/file.h index d9c1bbc0ef73..baf291d7b820 100644 --- a/starboard/common/file.h +++ b/starboard/common/file.h @@ -47,63 +47,52 @@ bool SbFileDeleteRecursive(const char* path, bool preserve_root); // functions call the corresponding SbFile function. class ScopedFile { public: - ScopedFile(const char* path, - int flags, - bool* out_created, - SbFileError* out_error) - : file_(kSbFileInvalid) { - file_ = SbFileOpen(path, flags, out_created, out_error); + ScopedFile(const char* path, int flags, int mode) : file_(-1) { + file_ = open(path, flags, mode); } - ScopedFile(const char* path, int flags, bool* out_created) - : file_(kSbFileInvalid) { - file_ = SbFileOpen(path, flags, out_created, NULL); + ScopedFile(const char* path, int flags) : file_(-1) { + file_ = SbFileOpen(path, flags); } - ScopedFile(const char* path, int flags) : file_(kSbFileInvalid) { - file_ = SbFileOpen(path, flags, NULL, NULL); - } - - ~ScopedFile() { SbFileClose(file_); } + ~ScopedFile() { close(file_); } - SbFile file() const { return file_; } + int file() const { return file_; } - bool IsValid() const { return SbFileIsValid(file_); } + bool IsValid() const { return (file_ >= 0); } - int64_t Seek(SbFileWhence whence, int64_t offset) const { - return SbFileSeek(file_, whence, offset); + off_t Seek(int whence, off_t offset) const { + return lseek(file_, offset, whence); } - int Read(char* data, int size) const { return SbFileRead(file_, data, size); } - - int ReadAll(char* data, int size) const { - return SbFileReadAll(file_, data, size); + ssize_t Read(void* data, size_t size) const { + return read(file_, data, size); } - int Write(const char* data, int size) const { - int result = SbFileWrite(file_, data, size); + int ReadAll(char* data, int size) const { return ReadAll(file_, data, size); } + + ssize_t Write(const void* data, size_t size) const { + ssize_t result = write(file_, data, size); RecordFileWriteStat(result); return result; } - int WriteAll(const char* data, int size) const { - int result = SbFileWriteAll(file_, data, size); + ssize_t WriteAll(const void* data, size_t size) const { + ssize_t result = WriteAll(file_, data, size); RecordFileWriteStat(result); return result; } - bool Truncate(int64_t length) const { return SbFileTruncate(file_, length); } + int Truncate(off_t length) const { return ftruncate(file_, length); } - bool Flush() const { return SbFileFlush(file_); } + int Flush() const { return fsync(file_); } - bool GetInfo(SbFileInfo* out_info) const { - return SbFileGetInfo(file_, out_info); - } + int GetInfo(struct stat* out_info) const { return fstat(file_, out_info); } int64_t GetSize() const { - SbFileInfo file_info; - bool success = GetInfo(&file_info); - return (success ? file_info.size : -1); + struct stat file_info; + int success = GetInfo(&file_info); + return (success == 0 ? file_info.st_size : -1); } // disallow copy and move operations @@ -111,7 +100,7 @@ class ScopedFile { ScopedFile& operator=(const ScopedFile&) = delete; private: - SbFile file_; + int file_; }; } // namespace starboard diff --git a/starboard/loader_app/drain_file.cc b/starboard/loader_app/drain_file.cc index 2b47e4fce7fd..6faf48748a90 100644 --- a/starboard/loader_app/drain_file.cc +++ b/starboard/loader_app/drain_file.cc @@ -165,7 +165,7 @@ bool TryDrain(const char* dir, const char* app_key) { path.append(filename); SbFileError error = kSbFileOk; - int file = open(path.c_str(), O_CREAT | O_WRONLY); + int file = open(path.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); SB_DCHECK(file >= 0); SB_DCHECK(close(file));