xref: /haiku/src/system/libroot/libroot_init.c (revision 97901ec593ec4dd50ac115c1c35a6d72f6e489a5)
1 /*
2  * Copyright 2003-2009, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <string.h>
8 
9 #include <fork.h>
10 #include <image.h>
11 #include <libroot_private.h>
12 #include <runtime_loader.h>
13 #include <user_runtime.h>
14 
15 
16 void initialize_before(image_id imageID);
17 
18 struct rld_export *__gRuntimeLoader = NULL;
19 	// This little bugger is set to something meaningful by the runtime loader
20 	// Ugly, eh?
21 
22 char *__progname = NULL;
23 int __libc_argc;
24 char **__libc_argv;
25 
26 char _single_threaded = true;
27 	// determines if I/O locking needed; needed for BeOS compatibility
28 
29 thread_id __main_thread_id;
30 char **argv_save;
31 	// needed for BeOS compatibility - they are set in the startup code
32 	// (have a look at the glue/ directory)
33 
34 int _data_offset_main_;
35 	// this is obviously needed for R4.5 compatiblity
36 
37 
38 void
39 initialize_before(image_id imageID)
40 {
41 	char *programPath = __gRuntimeLoader->program_args->args[0];
42 	if (programPath) {
43 		if ((__progname = strrchr(programPath, '/')) == NULL)
44 			__progname = programPath;
45 		else
46 			__progname++;
47 	}
48 
49 	__libc_argc = __gRuntimeLoader->program_args->arg_count;
50 	__libc_argv = __gRuntimeLoader->program_args->args;
51 
52 	__gRuntimeLoader->call_atexit_hooks_for_range
53 		= _call_atexit_hooks_for_range;
54 
55 	__init_time();
56 	__init_heap();
57 	__init_env(__gRuntimeLoader->program_args);
58 	__init_pwd_backend();
59 }
60 
61 
62 void _init_c_library_(void);
63 void
64 _init_c_library_(void)
65 {
66 	// This function is called from the BeOS start_dyn.o - so it's called once
67 	// for every application that was compiled under BeOS.
68 	// Our libroot functions are already initialized above, so we don't have to
69 	// do anything here.
70 }
71 
72