mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-22 08:02:10 +02:00
progname: Port to Windows
Define the directory separator depending on the system targetted. Reported-by: Progyan Bhattacharya <progyanb@acm.org>
This commit is contained in:
@@ -34,6 +34,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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
|
#ifdef HAVE___PROGNAME
|
||||||
extern const char *__progname;
|
extern const char *__progname;
|
||||||
#else
|
#else
|
||||||
@@ -58,11 +64,13 @@ getprogname(void)
|
|||||||
void
|
void
|
||||||
setprogname(const char *progname)
|
setprogname(const char *progname)
|
||||||
{
|
{
|
||||||
const char *last_slash;
|
size_t i;
|
||||||
|
|
||||||
last_slash = strrchr(progname, '/');
|
for (i = strlen(progname); i > 0; i--) {
|
||||||
if (last_slash == NULL)
|
if (LIBBSD_IS_PATHNAME_SEPARATOR(progname[i - 1])) {
|
||||||
__progname = progname;
|
__progname = progname + i;
|
||||||
else
|
return;
|
||||||
__progname = last_slash + 1;
|
}
|
||||||
|
}
|
||||||
|
__progname = progname;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user