#include <fileio.h>
|
static FILE * | OpenOrDie (const std::string &filename, const std::string &mode) |
|
static FILE * | Open (const std::string &filename, const std::string &mode) |
|
static void | WriteStringToFileOrDie (const std::string &str, const std::string &filename) |
|
static bool | Readable (const std::string &filename) |
|
static bool | ReadFileToString (const std::string &filename, std::string *out) |
|
static std::string | JoinPath (const std::string &prefix, const std::string &suffix) |
|
static bool | Delete (const char *pathname) |
|
static bool | DeleteMatchingFiles (const char *pattern) |
|
Definition at line 43 of file fileio.h.
◆ Delete()
bool tesseract::File::Delete |
( |
const char * |
pathname | ) |
|
|
static |
Definition at line 92 of file fileio.cpp.
92 {
93#if !defined(_WIN32) || defined(__MINGW32__)
94 const int status = unlink(pathname);
95#else
96 const int status = _unlink(pathname);
97#endif
98 if (status != 0) {
99 tprintf(
"ERROR: Unable to delete file '%s$: %s\n", pathname,
100 strerror(errno));
101 return false;
102 }
103 return true;
104}
DLLSYM void tprintf(const char *format,...)
◆ DeleteMatchingFiles()
bool tesseract::File::DeleteMatchingFiles |
( |
const char * |
pattern | ) |
|
|
static |
Definition at line 121 of file fileio.cpp.
121 {
122 glob_t pglob;
123 char **paths;
124 bool all_deleted = true;
125 if (glob(pattern, 0, nullptr, &pglob) == 0) {
126 for (paths = pglob.gl_pathv; *paths != nullptr; paths++) {
128 }
129 globfree(&pglob);
130 }
131 return all_deleted;
132}
static bool Delete(const char *pathname)
◆ JoinPath()
std::string tesseract::File::JoinPath |
( |
const std::string & |
prefix, |
|
|
const std::string & |
suffix |
|
) |
| |
|
static |
Definition at line 86 of file fileio.cpp.
86 {
87 return (prefix.empty() || prefix[prefix.size() - 1] == '/')
88 ? prefix + suffix
89 : prefix + "/" + suffix;
90}
◆ Open()
FILE * tesseract::File::Open |
( |
const std::string & |
filename, |
|
|
const std::string & |
mode |
|
) |
| |
|
static |
Definition at line 42 of file fileio.cpp.
42 {
43 return fopen(filename.c_str(), mode.c_str());
44}
◆ OpenOrDie()
FILE * tesseract::File::OpenOrDie |
( |
const std::string & |
filename, |
|
|
const std::string & |
mode |
|
) |
| |
|
static |
Definition at line 46 of file fileio.cpp.
47 {
48 FILE* stream = fopen(filename.c_str(), mode.c_str());
49 if (stream == nullptr) {
50 tprintf(
"Unable to open '%s' in mode '%s': %s\n", filename.c_str(),
51 mode.c_str(), strerror(errno));
52 }
53 return stream;
54}
◆ Readable()
bool tesseract::File::Readable |
( |
const std::string & |
filename | ) |
|
|
static |
Definition at line 68 of file fileio.cpp.
68 {
69 FILE* stream = fopen(filename.c_str(), "rb");
70 if (stream == nullptr) {
71 return false;
72 }
73 fclose(stream);
74 return true;
75}
◆ ReadFileToString()
bool tesseract::File::ReadFileToString |
( |
const std::string & |
filename, |
|
|
std::string * |
out |
|
) |
| |
|
static |
Definition at line 77 of file fileio.cpp.
77 {
78 FILE* stream =
File::Open(filename.c_str(),
"rb");
79 if (stream == nullptr) return false;
80 InputBuffer in(stream);
81 *out = "";
82 in.Read(out);
83 return in.CloseFile();
84}
static FILE * Open(const std::string &filename, const std::string &mode)
◆ WriteStringToFileOrDie()
void tesseract::File::WriteStringToFileOrDie |
( |
const std::string & |
str, |
|
|
const std::string & |
filename |
|
) |
| |
|
static |
Definition at line 56 of file fileio.cpp.
57 {
58 FILE* stream = fopen(filename.c_str(), "wb");
59 if (stream == nullptr) {
60 tprintf(
"Unable to open '%s' for writing: %s\n",
61 filename.c_str(), strerror(errno));
62 return;
63 }
64 fputs(str.c_str(), stream);
66}
The documentation for this class was generated from the following files: