1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add program_invocation_short_name(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2013-01-06 21:38:05 +01:00
parent b9d633108d
commit 03ab6cf26e
2 changed files with 12 additions and 0 deletions

View file

@ -33,6 +33,7 @@ __BEGIN_DECLS
@include(errno_values.h)
extern char* program_invocation_name;
extern char* program_invocation_short_name;
__END_DECLS

View file

@ -28,15 +28,26 @@
extern "C" { char program_invocation_name_data[256] = ""; }
extern "C" { char* program_invocation_name = program_invocation_name_data; }
extern "C" { char* program_invocation_short_name; }
extern "C" void init_error_functions();
extern "C" void init_stdio();
extern "C" void init_signal();
static char* find_last_elem(char* str)
{
size_t len = strlen(str);
for ( size_t i = len; i; i-- )
if ( str[i-1] == '/' )
return str + i;
return str;
}
extern "C" void initialize_standard_library(int argc, char* argv[])
{
if ( argc )
strcpy(program_invocation_name, argv[0]);
program_invocation_short_name = find_last_elem(program_invocation_name);
// Initialize stuff such as errno.
init_error_functions();