All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseract::File Class Reference

#include <fileio.h>

Static Public Member Functions

static FILE * OpenOrDie (const string &filename, const string &mode)
 
static FILE * Open (const string &filename, const string &mode)
 
static void WriteStringToFileOrDie (const string &str, const string &filename)
 
static bool Readable (const string &filename)
 
static void ReadFileToStringOrDie (const string &filename, string *out)
 
static bool ReadFileToString (const string &filename, string *out)
 
static string JoinPath (const string &prefix, const string &suffix)
 
static bool Delete (const char *pathname)
 
static bool DeleteMatchingFiles (const char *pattern)
 

Detailed Description

Definition at line 31 of file fileio.h.

Member Function Documentation

bool tesseract::File::Delete ( const char *  pathname)
static

Definition at line 94 of file fileio.cpp.

94  {
95  const int status = unlink(pathname);
96  if (status != 0) {
97  tprintf("ERROR: Unable to delete file %s\n", pathname);
98  return false;
99  }
100  return true;
101 }
#define tprintf(...)
Definition: tprintf.h:31
bool tesseract::File::DeleteMatchingFiles ( const char *  pattern)
static

Definition at line 118 of file fileio.cpp.

118  {
119  glob_t pglob;
120  char **paths;
121  bool all_deleted = true;
122  if (glob(pattern, 0, NULL, &pglob) == 0) {
123  for (paths = pglob.gl_pathv; *paths != NULL; paths++) {
124  all_deleted &= File::Delete(*paths);
125  }
126  globfree(&pglob);
127  }
128  return all_deleted;
129 }
static bool Delete(const char *pathname)
Definition: fileio.cpp:94
#define NULL
Definition: host.h:144
string tesseract::File::JoinPath ( const string &  prefix,
const string &  suffix 
)
static

Definition at line 89 of file fileio.cpp.

89  {
90  return (!prefix.size() || prefix[prefix.size() - 1] == '/') ?
91  prefix + suffix : prefix + "/" + suffix;
92 }
FILE * tesseract::File::Open ( const string &  filename,
const string &  mode 
)
static

Definition at line 39 of file fileio.cpp.

39  {
40  return fopen(filename.c_str(), mode.c_str());
41 }
CMD_EVENTS mode
Definition: pgedit.cpp:116
FILE * tesseract::File::OpenOrDie ( const string &  filename,
const string &  mode 
)
static

Definition at line 43 of file fileio.cpp.

44  {
45  FILE* stream = fopen(filename.c_str(), mode.c_str());
46  if (stream == NULL) {
47  tprintf("Unable to open '%s' in mode '%s'\n", filename.c_str(),
48  mode.c_str());
49  }
50  return stream;
51 }
#define tprintf(...)
Definition: tprintf.h:31
CMD_EVENTS mode
Definition: pgedit.cpp:116
#define NULL
Definition: host.h:144
bool tesseract::File::Readable ( const string &  filename)
static

Definition at line 64 of file fileio.cpp.

64  {
65  FILE* stream = fopen(filename.c_str(), "rb");
66  if (stream == NULL) {
67  return false;
68  }
69  fclose(stream);
70  return true;
71 }
#define NULL
Definition: host.h:144
bool tesseract::File::ReadFileToString ( const string &  filename,
string *  out 
)
static

Definition at line 73 of file fileio.cpp.

73  {
74  FILE* stream = File::Open(filename.c_str(), "rb");
75  if (stream == NULL)
76  return false;
77  InputBuffer in(stream);
78  *out = "";
79  in.Read(out);
80  return in.CloseFile();
81 }
static FILE * Open(const string &filename, const string &mode)
Definition: fileio.cpp:39
#define NULL
Definition: host.h:144
void tesseract::File::ReadFileToStringOrDie ( const string &  filename,
string *  out 
)
static

Definition at line 83 of file fileio.cpp.

83  {
85  "Failed to read file: %s\n", filename.c_str());
86 }
static bool ReadFileToString(const string &filename, string *out)
Definition: fileio.cpp:73
#define ASSERT_HOST_MSG(x, msg...)
Definition: errcode.h:98
void tesseract::File::WriteStringToFileOrDie ( const string &  str,
const string &  filename 
)
static

Definition at line 53 of file fileio.cpp.

54  {
55  FILE* stream = fopen(filename.c_str(), "wb");
56  if (stream == NULL) {
57  tprintf("Unable to open '%s' for writing\n", filename.c_str());
58  return;
59  }
60  fputs(str.c_str(), stream);
61  ASSERT_HOST(fclose(stream) == 0);
62 }
#define tprintf(...)
Definition: tprintf.h:31
#define ASSERT_HOST(x)
Definition: errcode.h:84
#define NULL
Definition: host.h:144

The documentation for this class was generated from the following files: