\r
#define DEBUG_BUILD 0\r
\r
+#define LOG_WARN(f,...) _SysDebug("WARN: %s: "f, __func__ ,## __VA_ARGS__)\r
+#define LOG_NOTICE(f,...) _SysDebug("NOTE: %s: "f, __func__ ,## __VA_ARGS__)\r
+\r
// === CONSTANTS ===\r
#define _stdin 0\r
#define _stdout 1\r
\r
// === GLOBALS ===\r
struct sFILE _iob[STDIO_MAX_STREAMS]; // IO Buffer\r
-struct sFILE *stdin; // Standard Input\r
-struct sFILE *stdout; // Standard Output\r
-struct sFILE *stderr; // Standard Error\r
+struct sFILE *stdin = &_iob[0]; // Standard Input\r
+struct sFILE *stdout = &_iob[1]; // Standard Output\r
+struct sFILE *stderr = &_iob[2]; // Standard Error\r
///\note Initialised in SoMain\r
static const int STDIN_BUFSIZ = 512;\r
static const int STDOUT_BUFSIZ = 512;\r
void _stdio_init(void)\r
{\r
// Init FileIO Pointers\r
- stdin = &_iob[0];\r
stdin->FD = 0;\r
stdin->Flags = FILE_FLAG_ALLOC|FILE_FLAG_MODE_READ|FILE_FLAG_LINEBUFFERED|FILE_FLAG_OURBUFFER;\r
stdin->Buffer = malloc(STDIN_BUFSIZ);\r
stdin->BufferSpace = STDIN_BUFSIZ;\r
\r
- stdout = &_iob[1];\r
stdout->FD = 1;\r
stdout->Flags = FILE_FLAG_ALLOC|FILE_FLAG_MODE_WRITE|FILE_FLAG_LINEBUFFERED|FILE_FLAG_OURBUFFER;\r
stdout->Buffer = malloc(STDOUT_BUFSIZ);\r
stdout->BufferSpace = STDOUT_BUFSIZ;\r
\r
- stderr = &_iob[2];\r
stderr->FD = 2;\r
stderr->Flags = FILE_FLAG_ALLOC|FILE_FLAG_MODE_WRITE;\r
}\r
{\r
size_t ret;\r
\r
- if(!fp || fp->FD == -1)\r
+ if(!fp || fp->FD == -1) {\r
+ LOG_WARN("bad fp %p", fp);\r
return -1;\r
+ }\r
if( size == 0 || num == 0 )\r
return 0;\r
\r
if( _GetFileMode(fp) != FILE_FLAG_MODE_READ ) {\r
errno = 0;\r
+ LOG_WARN("not open for read");\r
return -1;\r
}\r
\r
// Don't read if EOF is set\r
- if( fp->Flags & FILE_FLAG_EOF )\r
+ if( fp->Flags & FILE_FLAG_EOF ) {\r
+ LOG_NOTICE("EOF");\r
return 0;\r
+ }\r
\r
\r
if( fp->FD == FD_MEMFILE ) {\r
}\r
else if( fp->FD == FD_MEMSTREAM ) {\r
//return _fread_memstream(ptr, size, num, fp);\r
+ LOG_WARN("Reading from a mem stream");\r
errno = EBADF;\r
return 0;\r
}\r
extra, size, num\r
);\r
}\r
+ LOG_NOTICE("Incomplete read %i/%i bytes (object size %i)",\r
+ ret, bytes, size);\r
}\r
\r
return ret / size;\r
*/\r
int SoMain(UNUSED(uintptr_t, BaseAddress), UNUSED(int, argc), UNUSED(char **, argv), char **envp)\r
{\r
- // Init for env.c\r
environ = envp;\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
// Set Error handler\r
_SysSetFaultHandler(ErrorHandler);\r
\r
- return 1;\r
+ return 0;\r
}\r
\r
int ErrorHandler(int Fault)\r