std::string load_file(const std::string &src) { std::string str; FILE *f = fopen(src.c_str(), "rb"); if (!f) throw file_exception(src); while (!feof(f)) { char buffer[1024]; int len = fread(buffer, 1, sizeof(buffer), f); if (len < 0) throw file_exception(src); str += string(buffer, len); } return str; }
void CFile::Close() { // ASSERT_VALID(this); ASSERT(file_ != INVALID_HANDLE_VALUE); if (!close_file()) throw file_exception(); //CFileException::ThrowOsError((LONG)::GetLastError(), m_strFileName); }
/// Sets state \p s and throws depending on the exception setting. void fstream::set_and_throw (iostate s, const char* op) { if (ios_base::set_and_throw (s)) #if PLATFORM_ANDROID printf("file_exception\n"); #else /* !PLATFORM_ANDROID */ throw file_exception (op, name()); #endif }
/// Get the stat structure. void fstream::stat (struct stat& rs) const { if (fstat (m_fd, &rs)) #if PLATFORM_ANDROID printf("file_exception\n"); #else throw file_exception ("stat", name()); #endif }
// Opens the file that we'll write to and gets its FD void LogBase::openFile() throw (file_exception) { fileDescriptor = open(fileName.c_str(), NEW_FLAG, ALL_PERMISSIONS); if (fileDescriptor < 0) { throw file_exception(file_exception::CREATE_ERR); } fileOpen = true; }
/// Attaches to the given \p nfd. void fstream::attach (int nfd, const char* filename) { assert (filename && "Don't do that"); clear (goodbit); if (nfd < 0 && ios_base::set_and_throw (badbit)) #if PLATFORM_ANDROID printf("file exception\n"); #else /* !PLATFORM_ANDROID */ throw file_exception ("open", filename); #endif close(); m_fd = nfd; m_Filename = filename; }
/// Sets state \p s and throws depending on the exception setting. void fstream::set_and_throw (iostate s, const char* op) { if (ios_base::set_and_throw (s)) throw file_exception (op, name()); }
/// Get the stat structure. void fstream::stat (struct stat& rs) const { if (fstat (m_fd, &rs)) throw file_exception ("stat", name()); }
/// Get the stat structure. void fstream::stat (struct stat& rs) const { if (fstat (m_fd, &rs)) USTL_THROW(file_exception ("stat", name())); }