summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2013-12-16 22:20:28 +0100
committerJay Berkenbilt <ejb@ql.org>2013-12-16 22:21:28 +0100
commit6067608d930fa7fc8eda40b72e1df328dbcb146e (patch)
tree890fb65c1040c849db4e30a7ea3384cec7f51f4c
parent235d8f28f8b7de0f1fea3f8fecc5af6c3917c650 (diff)
downloadqpdf-6067608d930fa7fc8eda40b72e1df328dbcb146e.tar.zst
Remove needless #ifdef _WIN32 from getWhoami
-rw-r--r--libqpdf/QUtil.cc12
-rw-r--r--libtests/qtest/qutil/qutil.out5
-rw-r--r--libtests/qutil.cc17
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 <sys/stat.h>
#include <fcntl.h>
#include <qpdf/QUtil.hh>
+#include <qpdf/PointerHolder.hh>
#include <string.h>
#ifdef _WIN32
@@ -125,6 +126,20 @@ void to_utf8_test()
}
}
+void print_whoami(char const* str)
+{
+ PointerHolder<char> 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)
{