Skip to content

Commit

Permalink
Replace code using _splitpath_s (win32)
Browse files Browse the repository at this point in the history
That simplifies the code and removes a dependency on "newer"
versions of Windows.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Jun 23, 2019
1 parent f522b03 commit dd261e8
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/ccutil/mainblk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
**********************************************************************/

#include <cstdlib>
#include <cstring> // for std::strrchr
#if defined(_WIN32)
#include <io.h> // for _access
#endif
Expand Down Expand Up @@ -54,20 +55,15 @@ void CCUtil::main_setup(const char *argv0, const char *basename) {
#if defined(_WIN32)
} else if (datadir == nullptr || _access(datadir.string(), 0) != 0) {
/* Look for tessdata in directory of executable. */
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char path[_MAX_PATH];
DWORD length = GetModuleFileName(nullptr, path, sizeof(path));
if (length > 0 && length < sizeof(path)) {
errno_t result = _splitpath_s(path, drive, sizeof(drive),
dir, sizeof(dir), nullptr, 0, nullptr, 0);
if (result == ERANGE) {
tprintf("Error: Path too long: %s\n", path);
char* separator = std::strrchr(path, '\\');
if (separator != nullptr) {
*separator = '\0';
datadir = path;
datadir += "/tessdata";
}

datadir = drive;
datadir += dir;
datadir += "/tessdata";
}
#endif /* _WIN32 */
#if defined(TESSDATA_PREFIX)
Expand Down

0 comments on commit dd261e8

Please sign in to comment.