Commit 6067608d930fa7fc8eda40b72e1df328dbcb146e
1 parent
235d8f28
Remove needless #ifdef _WIN32 from getWhoami
Showing
3 changed files
with
26 additions
and
8 deletions
libqpdf/QUtil.cc
| ... | ... | @@ -237,13 +237,9 @@ QUtil::setLineBuf(FILE* f) |
| 237 | 237 | char* |
| 238 | 238 | QUtil::getWhoami(char* argv0) |
| 239 | 239 | { |
| 240 | -#ifdef _WIN32 | |
| 241 | - char pathsep = '\\'; | |
| 242 | -#else | |
| 243 | - char pathsep = '/'; | |
| 244 | -#endif | |
| 245 | 240 | char* whoami = 0; |
| 246 | - if ((whoami = strrchr(argv0, pathsep)) == NULL) | |
| 241 | + if (((whoami = strrchr(argv0, '/')) == NULL) && | |
| 242 | + ((whoami = strrchr(argv0, '\\')) == NULL)) | |
| 247 | 243 | { |
| 248 | 244 | whoami = argv0; |
| 249 | 245 | } |
| ... | ... | @@ -251,13 +247,13 @@ QUtil::getWhoami(char* argv0) |
| 251 | 247 | { |
| 252 | 248 | ++whoami; |
| 253 | 249 | } |
| 254 | -#ifdef _WIN32 | |
| 250 | + | |
| 255 | 251 | if ((strlen(whoami) > 4) && |
| 256 | 252 | (strcmp(whoami + strlen(whoami) - 4, ".exe") == 0)) |
| 257 | 253 | { |
| 258 | 254 | whoami[strlen(whoami) - 4] = '\0'; |
| 259 | 255 | } |
| 260 | -#endif | |
| 256 | + | |
| 261 | 257 | return whoami; |
| 262 | 258 | } |
| 263 | 259 | ... | ... |
libtests/qtest/qutil/qutil.out
libtests/qutil.cc
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | #include <sys/stat.h> |
| 5 | 5 | #include <fcntl.h> |
| 6 | 6 | #include <qpdf/QUtil.hh> |
| 7 | +#include <qpdf/PointerHolder.hh> | |
| 7 | 8 | #include <string.h> |
| 8 | 9 | |
| 9 | 10 | #ifdef _WIN32 |
| ... | ... | @@ -125,6 +126,20 @@ void to_utf8_test() |
| 125 | 126 | } |
| 126 | 127 | } |
| 127 | 128 | |
| 129 | +void print_whoami(char const* str) | |
| 130 | +{ | |
| 131 | + PointerHolder<char> dup(true, QUtil::copy_string(str)); | |
| 132 | + std::cout << QUtil::getWhoami(dup.getPointer()) << std::endl; | |
| 133 | +} | |
| 134 | + | |
| 135 | +void get_whoami_test() | |
| 136 | +{ | |
| 137 | + print_whoami("a/b/c/quack1"); | |
| 138 | + print_whoami("a/b/c/quack2.exe"); | |
| 139 | + print_whoami("a\\b\\c\\quack3"); | |
| 140 | + print_whoami("a\\b\\c\\quack4.exe"); | |
| 141 | +} | |
| 142 | + | |
| 128 | 143 | int main(int argc, char* argv[]) |
| 129 | 144 | { |
| 130 | 145 | try |
| ... | ... | @@ -138,6 +153,8 @@ int main(int argc, char* argv[]) |
| 138 | 153 | getenv_test(); |
| 139 | 154 | std::cout << "----" << std::endl; |
| 140 | 155 | to_utf8_test(); |
| 156 | + std::cout << "----" << std::endl; | |
| 157 | + get_whoami_test(); | |
| 141 | 158 | } |
| 142 | 159 | catch (std::exception& e) |
| 143 | 160 | { | ... | ... |