2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-30 00:40:52 +00:00

Remove needless #ifdef _WIN32 from getWhoami

This commit is contained in:
Jay Berkenbilt 2013-12-16 16:20:28 -05:00
parent 235d8f28f8
commit 6067608d93
3 changed files with 26 additions and 8 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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)
{