#include "stdio_int.h"\r
#include "lib.h"\r
#include <stdio.h>\r
-#include <sys/sys.h>\r
+#include <stdlib.h>\r
+#include <acess/sys.h>\r
\r
#define USE_CPUID 0\r
\r
\r
// === IMPORTS ===\r
extern tLoadedLib gLoadedLibraries[64];\r
-extern int _SysSetFaultHandler(int (*Handler)(int));\r
+extern void *_crt0_exit_handler;\r
+extern void _stdio_init(void);\r
+extern void _call_atexit_handlers(void);\r
\r
// === GLOBALS ===\r
extern char **_envp;\r
-extern struct sFILE _iob[];\r
-extern struct sFILE *stdin;\r
-extern struct sFILE *stdout;\r
-extern struct sFILE *stderr;\r
// --- CPU Features ---\r
#if USE_CPUID\r
tCPUID gCPU_Features;\r
* \param argv Unused - Arguments (NULL for current version of ld-acess)\r
* \param envp Environment Pointer\r
*/\r
-int SoMain(unsigned int BaseAddress, int argc, char **argv, char **envp)\r
+int SoMain(UNUSED(uintptr_t, BaseAddress), UNUSED(int, argc), UNUSED(char **, argv), char **envp)\r
{\r
// Init for env.c\r
_envp = envp;\r
- \r
- // Init FileIO Pointers\r
- stdin = &_iob[0];\r
- stdin->FD = 0; stdin->Flags = FILE_FLAG_MODE_READ;\r
- stdout = &_iob[1];\r
- stdout->FD = 1; stdout->Flags = FILE_FLAG_MODE_WRITE;\r
- stderr = &_iob[2];\r
- stderr->FD = 2; stderr->Flags = FILE_FLAG_MODE_WRITE;\r
+\r
+ #if 0 \r
+ {\r
+ int i = 0;\r
+ char **tmp;\r
+ _SysDebug("envp = %p", envp);\r
+ for(tmp = envp; *tmp; tmp++,i++)\r
+ {\r
+ _SysDebug("envp[%i] = '%s'", i, *tmp);\r
+ }\r
+ }\r
+ #endif\r
+\r
+ _stdio_init(); \r
\r
#if USE_CPUID\r
{\r
}\r
#endif\r
\r
+ _crt0_exit_handler = _call_atexit_handlers;\r
+\r
// Set Error handler\r
_SysSetFaultHandler(ErrorHandler);\r
\r
return -1;\r
}\r
\r
+EXPORT int *libc_geterrno()\r
+{\r
+ return &_errno;\r
+}\r
+\r
#if USE_CPUID\r
/**\r
* \brief Call the CPUID opcode\r