Skip to content

Commit 67bf906

Browse files
committed
Rework check for readable input file
This reverts commit 1a09644 and implements an alternate check which allows input from stdin. Signed-off-by: Stefan Weil <[email protected]>
1 parent 140bfa4 commit 67bf906

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/api/baseapi.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,15 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
11301130
buf.assign((std::istreambuf_iterator<char>(std::cin)),
11311131
(std::istreambuf_iterator<char>()));
11321132
data = reinterpret_cast<const l_uint8 *>(buf.data());
1133+
} else {
1134+
// Check whether the input file can be read.
1135+
if (FILE* file = fopen(filename, "rb")) {
1136+
fclose(file);
1137+
} else {
1138+
fprintf(stderr, "Error, cannot read input file %s: %s\n",
1139+
filename, strerror(errno));
1140+
return false;
1141+
}
11331142
}
11341143

11351144
// Here is our autodetection

src/api/tesseractmain.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,6 @@ int main(int argc, char** argv) {
534534
return EXIT_SUCCESS;
535535
}
536536

537-
if (FILE* file = fopen(image, "r")) {
538-
fclose(file);
539-
} else {
540-
fprintf(stderr, "Cannot open input file: %s\n", image);
541-
return EXIT_FAILURE;
542-
}
543-
544537
FixPageSegMode(&api, pagesegmode);
545538

546539
if (dpi) {

0 commit comments

Comments
 (0)