Skip to content

Commit dd261e8

Browse files
committed
Replace code using _splitpath_s (win32)
That simplifies the code and removes a dependency on "newer" versions of Windows. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent f522b03 commit dd261e8

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/ccutil/mainblk.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
**********************************************************************/
1818

1919
#include <cstdlib>
20+
#include <cstring> // for std::strrchr
2021
#if defined(_WIN32)
2122
#include <io.h> // for _access
2223
#endif
@@ -54,20 +55,15 @@ void CCUtil::main_setup(const char *argv0, const char *basename) {
5455
#if defined(_WIN32)
5556
} else if (datadir == nullptr || _access(datadir.string(), 0) != 0) {
5657
/* Look for tessdata in directory of executable. */
57-
char drive[_MAX_DRIVE];
58-
char dir[_MAX_DIR];
5958
char path[_MAX_PATH];
6059
DWORD length = GetModuleFileName(nullptr, path, sizeof(path));
6160
if (length > 0 && length < sizeof(path)) {
62-
errno_t result = _splitpath_s(path, drive, sizeof(drive),
63-
dir, sizeof(dir), nullptr, 0, nullptr, 0);
64-
if (result == ERANGE) {
65-
tprintf("Error: Path too long: %s\n", path);
61+
char* separator = std::strrchr(path, '\\');
62+
if (separator != nullptr) {
63+
*separator = '\0';
64+
datadir = path;
65+
datadir += "/tessdata";
6666
}
67-
68-
datadir = drive;
69-
datadir += dir;
70-
datadir += "/tessdata";
7167
}
7268
#endif /* _WIN32 */
7369
#if defined(TESSDATA_PREFIX)

0 commit comments

Comments
 (0)