/******************************************************************************* Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. This file is part of the Sortix C Library. The Sortix C Library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The Sortix C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . init.cpp Initializes the process by setting up the heap, signal handling, static memory and other useful things. *******************************************************************************/ #include #include 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(); // It's probably best to initialize the Unix signals early on. init_signal(); // Initialize the dynamic heap. _init_heap(); // Initialize stdio. init_stdio(); }