2 * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
5 * Copyright 2001, Travis Geiselbrecht. All rights reserved.
6 * Distributed under the terms of the NewOS License.
10 #include "runtime_loader_private.h"
20 char *(*gGetEnv
)(const char *name
) = NULL
;
24 getenv(const char *name
)
26 if (gGetEnv
!= NULL
) {
27 // Use libroot's getenv() as soon as it is available to us - the
28 // environment in gProgramArgs is static.
32 char **environ
= gProgramArgs
->env
;
33 int32 length
= strlen(name
);
36 for (i
= 0; environ
[i
] != NULL
; i
++) {
37 if (!strncmp(name
, environ
[i
], length
) && environ
[i
][length
] == '=')
38 return environ
[i
] + length
+ 1;
46 printf(const char *format
, ...)
51 va_start(args
, format
);
52 int length
= vsnprintf(buffer
, sizeof(buffer
), format
, args
);
55 _kern_write(STDERR_FILENO
, 0, buffer
, length
);
62 dprintf(const char *format
, ...)
67 va_start(list
, format
);
69 vsnprintf(buffer
, sizeof(buffer
), format
, list
);
70 _kern_debug_output(buffer
);
77 __swap_int32(uint32 value
)
79 return value
>> 24 | ((value
>> 8) & 0xff00) | value
<< 24
80 | ((value
<< 8) & 0xff0000);
85 // Copied from libroot/os/thread.c:
89 _get_thread_info(thread_id thread
, thread_info
*info
, size_t size
)
91 if (info
== NULL
|| size
!= sizeof(thread_info
))
94 return _kern_get_thread_info(thread
, info
);
99 snooze(bigtime_t timeout
)
105 /*! Mini atoi(), so we don't have to include the libroot dependencies.
108 atoi(const char* num
)
111 while (*num
>= '0' && *num
<= '9') {
112 result
= (result
* 10) + (*num
- '0');
120 #if RUNTIME_LOADER_TRACING
123 ktrace_printf(const char *format
, ...)
126 va_start(list
, format
);
129 vsnprintf(buffer
, sizeof(buffer
), format
, list
);
130 _kern_ktrace_output(buffer
);
135 #endif // RUNTIME_LOADER_TRACING