* Foundation. See file COPYING.
*
*/
-#include "acconfig.h"
#include "common/code_environment.h"
-#include <errno.h>
#include <iostream>
-#include <stdlib.h>
-#include <string.h>
-#include <string>
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
}
}
-std::ostream &operator<<(std::ostream &oss, enum code_environment_t e)
+std::ostream &operator<<(std::ostream &oss, const enum code_environment_t e)
{
oss << code_environment_to_str(e);
return oss;
return prctl(PR_GET_NAME, buf);
}
+#elif defined(HAVE_GETPROGNAME)
+
+int get_process_name(char *buf, int len)
+{
+ if (len <= 0) {
+ return -EINVAL;
+ }
+
+ const char *progname = getprogname();
+ if (progname == nullptr || *progname == '\0') {
+ return -ENOSYS;
+ }
+
+ strncpy(buf, progname, len - 1);
+ buf[len - 1] = '\0';
+ return 0;
+}
+
#else
int get_process_name(char *buf, int len)