]> gitweb @ CieloNegro.org - daemon.git/blobdiff - getprogname.c
getprogname(3) wasn't portable enough.
[daemon.git] / getprogname.c
diff --git a/getprogname.c b/getprogname.c
new file mode 100644 (file)
index 0000000..bff83e4
--- /dev/null
@@ -0,0 +1,20 @@
+#include "getprogname.h"
+#include <string.h>
+
+static const char* _progname = NULL;
+
+const char* getprogname(void) {
+    return _progname;
+}
+
+void setprogname(const char* progname) {
+    const char* last_backslash;
+
+    last_backslash = strrchr(progname, '/');
+    if (last_backslash) {
+        _progname = last_backslash + 1;
+    }
+    else {
+        _progname = progname;
+    }
+}