From 67bf9062df0770e812af9513f7fb71ae9e7c6e98 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sat, 6 Oct 2018 22:00:15 +0200 Subject: [PATCH] Rework check for readable input file This reverts commit 1a096441d05a76e72145859cabb5413bf9464dfa and implements an alternate check which allows input from stdin. Signed-off-by: Stefan Weil --- src/api/baseapi.cpp | 9 +++++++++ src/api/tesseractmain.cpp | 7 ------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index 8356414b..fa27a546 100644 --- a/src/api/baseapi.cpp +++ b/src/api/baseapi.cpp @@ -1130,6 +1130,15 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename, buf.assign((std::istreambuf_iterator(std::cin)), (std::istreambuf_iterator())); data = reinterpret_cast(buf.data()); + } else { + // Check whether the input file can be read. + if (FILE* file = fopen(filename, "rb")) { + fclose(file); + } else { + fprintf(stderr, "Error, cannot read input file %s: %s\n", + filename, strerror(errno)); + return false; + } } // Here is our autodetection diff --git a/src/api/tesseractmain.cpp b/src/api/tesseractmain.cpp index be828c73..c2edb4b0 100644 --- a/src/api/tesseractmain.cpp +++ b/src/api/tesseractmain.cpp @@ -534,13 +534,6 @@ int main(int argc, char** argv) { return EXIT_SUCCESS; } - if (FILE* file = fopen(image, "r")) { - fclose(file); - } else { - fprintf(stderr, "Cannot open input file: %s\n", image); - return EXIT_FAILURE; - } - FixPageSegMode(&api, pagesegmode); if (dpi) {