1 /* 2 * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2001, Travis Geiselbrecht. All rights reserved. 6 * Distributed under the terms of the NewOS License. 7 */ 8 9 10 #include "runtime_loader_private.h" 11 12 #include <syscalls.h> 13 14 #include <string.h> 15 #include <stdio.h> 16 #include <stdlib.h> 17 #include <unistd.h> 18 19 20 char *(*gGetEnv)(const char *name) = NULL; 21 22 23 extern "C" char * 24 getenv(const char *name) 25 { 26 if (gGetEnv != NULL) { 27 // Use libroot's getenv() as soon as it is available to us - the environment 28 // in gProgramArgs is static. 29 return gGetEnv(name); 30 } 31 32 char **environ = gProgramArgs->envp; 33 int32 length = strlen(name); 34 int32 i; 35 36 for (i = 0; environ[i] != NULL; i++) { 37 if (!strncmp(name, environ[i], length) && environ[i][length] == '=') 38 return environ[i] + length + 1; 39 } 40 41 return NULL; 42 } 43 44 45 extern "C" int 46 printf(const char *format, ...) 47 { 48 char buffer[1024]; 49 va_list args; 50 51 va_start(args, format); 52 int length = vsprintf(buffer, format, args); 53 va_end(args); 54 55 _kern_write(STDERR_FILENO, 0, buffer, length); 56 57 return length; 58 } 59