From: Guillem Jover Date: Sun, 4 Mar 2018 23:37:47 +0000 (+0100) Subject: progname: Port to Windows X-Git-Tag: 0.9.0~21 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=5ba8c5bab05c8315439c351e91ce554d4f092915;p=thirdparty%2Flibbsd.git progname: Port to Windows Define the directory separator depending on the system targetted. Reported-by: Progyan Bhattacharya --- diff --git a/src/progname.c b/src/progname.c index 10c3701..3edbf24 100644 --- a/src/progname.c +++ b/src/progname.c @@ -34,6 +34,12 @@ #include #include +#if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__) +#define LIBBSD_IS_PATHNAME_SEPARATOR(c) ((c) == '/' || (c) == '\\') +#else +#define LIBBSD_IS_PATHNAME_SEPARATOR(c) ((c) == '/') +#endif + #ifdef HAVE___PROGNAME extern const char *__progname; #else @@ -58,11 +64,13 @@ getprogname(void) void setprogname(const char *progname) { - const char *last_slash; + size_t i; - last_slash = strrchr(progname, '/'); - if (last_slash == NULL) - __progname = progname; - else - __progname = last_slash + 1; + for (i = strlen(progname); i > 0; i--) { + if (LIBBSD_IS_PATHNAME_SEPARATOR(progname[i - 1])) { + __progname = progname + i; + return; + } + } + __progname = progname; }