chiark / gitweb /
Prep v228: Add remaining updates from upstream (2/3)
[elogind.git] / src / basic / musl_missing.c
1 #include <string.h>
2 #include "alloc-util.h"
3
4 #ifndef __GLIBC__
5 char *program_invocation_name       = NULL;
6 char *program_invocation_short_name = NULL;
7 #endif // __GLIBC__
8
9 #include "musl_missing.h"
10
11 static void elogind_free_program_name(void) {
12         if (program_invocation_name)
13                 program_invocation_name       = mfree(program_invocation_name);
14         if (program_invocation_short_name)
15                 program_invocation_short_name = mfree(program_invocation_short_name);
16 }
17
18 void elogind_set_program_name(const char* pcall) {
19         assert(pcall && pcall[0]);
20
21         if ( ( program_invocation_name
22             && strcmp(program_invocation_name, pcall))
23           || ( program_invocation_short_name
24             && strcmp(program_invocation_short_name, basename(pcall)) ) )
25                 elogind_free_program_name();
26
27         if (NULL == program_invocation_name)
28                 program_invocation_name       = strdup(pcall);
29         if (NULL == program_invocation_short_name)
30                 program_invocation_short_name = strdup(basename(pcall));
31
32 #ifndef __GLIBC__
33         atexit(elogind_free_program_name);
34 #endif // __GLIBC__
35 }
36