libc: Add program_invocation_name
This is a GNU extension, but I'm fine with adding it to libc. It's guarded by the _GNU_SOURCE feature test macro anyways.
This commit is contained in:
parent
7d20c507b1
commit
8eb986df63
@ -28,4 +28,9 @@ extern int errno;
|
|||||||
#define ENOTSUP 95 // Operation not supported
|
#define ENOTSUP 95 // Operation not supported
|
||||||
#define EOPNOTSUPP 95 // Operation not supported
|
#define EOPNOTSUPP 95 // Operation not supported
|
||||||
|
|
||||||
|
#ifdef _GNU_SOURCE // Give it only to programs that ask for it.
|
||||||
|
/* Name used to invoke calling program. Same value as argv[0] in main(), but can be used globally. */
|
||||||
|
extern char* program_invocation_name;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,3 +1,4 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
int errno;
|
int errno;
|
||||||
|
char* program_invocation_name;
|
@ -51,12 +51,17 @@ static void check_for_file(int fd, FILE** target_stream, const char* path, const
|
|||||||
else { *target_stream = fdopen(fd, mode); }
|
else { *target_stream = fdopen(fd, mode); }
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void initialize_libc()
|
extern char* program_invocation_name;
|
||||||
|
|
||||||
|
extern "C" void initialize_libc(int argc, char** argv)
|
||||||
{
|
{
|
||||||
check_for_file(STDIN_FILENO, &stdin, "/dev/kbd", "r");
|
check_for_file(STDIN_FILENO, &stdin, "/dev/kbd", "r");
|
||||||
check_for_file(STDOUT_FILENO, &stdout, "/dev/console", "rw");
|
check_for_file(STDOUT_FILENO, &stdout, "/dev/console", "rw");
|
||||||
check_for_file(STDERR_FILENO, &stderr, "/dev/console", "rw");
|
check_for_file(STDERR_FILENO, &stderr, "/dev/console", "rw");
|
||||||
|
|
||||||
|
program_invocation_name =
|
||||||
|
argv[0]; // argv[0] should only be nullptr when being init, which shouldn't use program_invocation_name anyways.
|
||||||
|
|
||||||
initialize_random();
|
initialize_random();
|
||||||
atexit(terminate_libc);
|
atexit(terminate_libc);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user