From 6067608d930fa7fc8eda40b72e1df328dbcb146e Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 16 Dec 2013 16:20:28 -0500 Subject: Remove needless #ifdef _WIN32 from getWhoami --- libqpdf/QUtil.cc | 12 ++++-------- libtests/qtest/qutil/qutil.out | 5 +++++ libtests/qutil.cc | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 39ce4088..11a3411c 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -237,13 +237,9 @@ QUtil::setLineBuf(FILE* f) char* QUtil::getWhoami(char* argv0) { -#ifdef _WIN32 - char pathsep = '\\'; -#else - char pathsep = '/'; -#endif char* whoami = 0; - if ((whoami = strrchr(argv0, pathsep)) == NULL) + if (((whoami = strrchr(argv0, '/')) == NULL) && + ((whoami = strrchr(argv0, '\\')) == NULL)) { whoami = argv0; } @@ -251,13 +247,13 @@ QUtil::getWhoami(char* argv0) { ++whoami; } -#ifdef _WIN32 + if ((strlen(whoami) > 4) && (strcmp(whoami + strlen(whoami) - 4, ".exe") == 0)) { whoami[strlen(whoami) - 4] = '\0'; } -#endif + return whoami; } diff --git a/libtests/qtest/qutil/qutil.out b/libtests/qtest/qutil/qutil.out index 0e996dec..4273fe11 100644 --- a/libtests/qtest/qutil/qutil.out +++ b/libtests/qtest/qutil/qutil.out @@ -30,3 +30,8 @@ HAGOOGAMAGOOGLE: 0 0x16059 -> f0 96 81 99 0x7fffffff -> fd bf bf bf bf bf 0x80000000: bounds error in QUtil::toUTF8 +---- +quack1 +quack2 +quack3 +quack4 diff --git a/libtests/qutil.cc b/libtests/qutil.cc index 5e4dd196..b0134e79 100644 --- a/libtests/qutil.cc +++ b/libtests/qutil.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include #ifdef _WIN32 @@ -125,6 +126,20 @@ void to_utf8_test() } } +void print_whoami(char const* str) +{ + PointerHolder dup(true, QUtil::copy_string(str)); + std::cout << QUtil::getWhoami(dup.getPointer()) << std::endl; +} + +void get_whoami_test() +{ + print_whoami("a/b/c/quack1"); + print_whoami("a/b/c/quack2.exe"); + print_whoami("a\\b\\c\\quack3"); + print_whoami("a\\b\\c\\quack4.exe"); +} + int main(int argc, char* argv[]) { try @@ -138,6 +153,8 @@ int main(int argc, char* argv[]) getenv_test(); std::cout << "----" << std::endl; to_utf8_test(); + std::cout << "----" << std::endl; + get_whoami_test(); } catch (std::exception& e) { -- cgit v1.2.3-70-g09d2