#include <string.h>\r
#include "lib.h"\r
#include "stdio_int.h"\r
-\r
-#define WRITE_STR(_fd, _str) write(_fd, _str, sizeof(_str))\r
+#include <errno.h>\r
+#include <assert.h>\r
\r
#define DEBUG_BUILD 0\r
\r
#define _stdin 0\r
#define _stdout 1\r
\r
+#define FD_NOTOPEN -1\r
+#define FD_MEMFILE -2\r
+#define FD_MEMSTREAM -3\r
+\r
// === PROTOTYPES ===\r
-EXPORT void itoa(char *buf, uint64_t num, size_t base, int minLength, char pad, int bSigned);\r
struct sFILE *get_file_struct();\r
\r
// === GLOBALS ===\r
struct sFILE *stdout; // Standard Output\r
struct sFILE *stderr; // Standard Error\r
///\note Initialised in SoMain\r
+static const int STDIN_BUFSIZ = 512;\r
+static const int STDOUT_BUFSIZ = 512;\r
\r
// === CODE ===\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
+void _stdio_cleanup(void)\r
+{\r
+ int i;\r
+ for( i = 0; i < STDIO_MAX_STREAMS; i ++ )\r
+ {\r
+ fclose( &_iob[i] );\r
+ }\r
+}\r
+\r
int _fopen_modetoflags(const char *mode)\r
{\r
int flags = 0;\r
// Sanity Check Arguments\r
if(!fp || !file || !mode) return NULL;\r
\r
- if(fp->FD != -1) {\r
+ if(fp->FD != FD_NOTOPEN) {\r
fflush(fp);\r
}\r
\r
}\r
\r
//Open File\r
- if(fp->FD != -1)\r
+ if(fp->FD != FD_NOTOPEN)\r
fp->FD = _SysReopen(fp->FD, file, openFlags);\r
else\r
fp->FD = _SysOpen(file, openFlags);\r
return NULL;\r
}\r
\r
+ // Default to buffered\r
+ // - Disabled until fseek() is fixed\r
+ #if 0\r
+ fp->BufferOfs = 0;\r
+ fp->BufferPos = 0;\r
+ fp->BufferSpace = BUFSIZ;\r
+ fp->Buffer = malloc( fp->BufferSpace );\r
+ fp->Flags |= FILE_FLAG_OURBUFFER;\r
+ #endif\r
+ \r
if( (fp->Flags & FILE_FLAG_MODE_MASK) == FILE_FLAG_MODE_APPEND ) {\r
_SysSeek(fp->FD, 0, SEEK_END); //SEEK_END\r
}\r
\r
ret = get_file_struct();\r
\r
- ret->FD = -2;\r
+ ret->FD = FD_MEMFILE;\r
ret->Flags = _fopen_modetoflags(mode);\r
if(ret->Flags == -1) {\r
ret->Flags = 0;\r
}\r
\r
ret->Buffer = buffer;\r
- ret->BufferStart = 0;\r
- ret->BufferSize = length;\r
+ ret->BufferPos = 0;\r
+ ret->BufferSpace = length;\r
+ \r
+ return ret;\r
+}\r
+\r
+EXPORT FILE *open_memstream(char **bufferptr, size_t *lengthptr)\r
+{\r
+ FILE *ret = get_file_struct();\r
+ ret->FD = FD_MEMSTREAM;\r
+ ret->Flags = FILE_FLAG_MODE_WRITE;\r
+ \r
+ ret->Buffer = NULL;\r
+ ret->BufferPos = 0;\r
+ ret->BufferSpace = 0;\r
+ ret->BufPtr = bufferptr;\r
+ ret->LenPtr = lengthptr;\r
\r
return ret;\r
}\r
\r
EXPORT int fclose(FILE *fp)\r
{\r
+ if( !(fp->Flags & FILE_FLAG_ALLOC) )\r
+ return 0;\r
fflush(fp);\r
- if( fp->FD != -1 ) {\r
+ if( fp->FD >= 0 ) {\r
_SysClose(fp->FD);\r
+ if( fp->Buffer && (fp->Flags & FILE_FLAG_OURBUFFER) ) {\r
+ free(fp->Buffer);\r
+ }\r
+ fp->Buffer = NULL;\r
}\r
fp->Flags = 0;\r
- fp->FD = -1;\r
+ fp->FD = FD_NOTOPEN;\r
return 0;\r
}\r
\r
-EXPORT void fflush(FILE *fp)\r
+EXPORT int setvbuf(FILE *fp, char *buffer, int mode, size_t size)\r
{\r
- if( !fp || fp->FD == -1 )\r
- return ;\r
+ if( !fp ) {\r
+ errno = EINVAL;\r
+ return 1;\r
+ }\r
+\r
+ // Check for memory files\r
+ if( fp->FD == FD_MEMFILE || fp->FD == FD_MEMSTREAM ) {\r
+ errno = EINVAL;\r
+ return 2;\r
+ } \r
+\r
+ // Not strictly needed, as this should only be called before any IO\r
+ fflush(fp);\r
+\r
+ // Eliminate any pre-existing buffer\r
+ if( fp->Buffer ) {\r
+ free( fp->Buffer );\r
+ fp->Buffer = NULL;\r
+ fp->BufferSpace = 0;\r
+ fp->BufferPos = 0;\r
+ }\r
+\r
+ if( mode == _IONBF ) {\r
+ // Do nothing, buffering was disabled above\r
+ }\r
+ else\r
+ {\r
+ // Sanity check buffering mode before allocating\r
+ if( mode != _IOLBF && mode != _IOFBF ) {\r
+ errno = EINVAL;\r
+ return 1;\r
+ }\r
+ // Allocate a buffer if one was not provided\r
+ if( !buffer ) {\r
+ fp->Flags |= FILE_FLAG_OURBUFFER;\r
+ buffer = malloc(size);\r
+ assert(buffer);\r
+ }\r
+ else {\r
+ fp->Flags &= ~FILE_FLAG_OURBUFFER;\r
+ }\r
+ \r
+ // Set buffer pointer and size\r
+ fp->Buffer = buffer;\r
+ fp->BufferSpace = size;\r
+ \r
+ // Set mode flag\r
+ if( mode == _IOLBF )\r
+ fp->Flags |= FILE_FLAG_LINEBUFFERED;\r
+ else\r
+ fp->Flags &= ~FILE_FLAG_LINEBUFFERED;\r
+ }\r
+ \r
+ return 0;\r
+}\r
+\r
+int _fflush_int(FILE *fp)\r
+{\r
+ int ret = 0;\r
+ size_t len;\r
+ \r
+ // Check the buffer contains data\r
+ if( fp->BufferPos == 0 )\r
+ return 0;\r
+ \r
+ switch(fp->Flags & FILE_FLAG_MODE_MASK)\r
+ {\r
+ // Read - Flush input buffer\r
+ case FILE_FLAG_MODE_READ:\r
+ fp->BufferPos = 0;\r
+ break;\r
\r
- if( !(fp->Flags & FILE_FLAG_DIRTY) )\r
+ // Append - Seek to end and write\r
+ case FILE_FLAG_MODE_APPEND:\r
+ _SysSeek(fp->FD, fp->BufferOfs, SEEK_SET);\r
+ len = _SysWrite(fp->FD, fp->Buffer, fp->BufferPos);\r
+ if( len != fp->BufferPos )\r
+ ret = 1;\r
+ if( len <= fp->BufferPos )\r
+ {\r
+ fp->BufferPos -= len;\r
+ }\r
+ fp->BufferOfs = _SysTell(fp->FD);\r
+ break;\r
+ \r
+ // Write - Write buffer\r
+ case FILE_FLAG_MODE_WRITE:\r
+ //_SysDebug("Flushing to %i '%.*s'", fp->FD, fp->BufferPos, fp->Buffer);\r
+ len = _SysWrite(fp->FD, fp->Buffer, fp->BufferPos);\r
+ if( len != fp->BufferPos )\r
+ ret = 1;\r
+ if( len <= fp->BufferPos )\r
+ {\r
+ fp->BufferPos -= len;\r
+ }\r
+ //else {\r
+ // _SysDebug("Flush of %i failed, %s", fp->FD, strerror(errno));\r
+ //}\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+ return ret;\r
+}\r
+\r
+EXPORT void fflush(FILE *fp)\r
+{\r
+ if( !fp || fp->FD == FD_NOTOPEN )\r
return ;\r
\r
// Nothing to do for memory files\r
- if( fp->FD == -2 )\r
+ if( fp->FD == FD_MEMFILE )\r
+ return ;\r
+ // Memory streams, update pointers\r
+ if( fp->FD == FD_MEMSTREAM ) {\r
+ *fp->BufPtr = fp->Buffer;\r
+ *fp->LenPtr = fp->BufferPos;\r
return ;\r
+ }\r
+ \r
+ _fflush_int(fp);\r
}\r
\r
EXPORT void clearerr(FILE *fp)\r
{\r
- if( !fp || fp->FD == -1 )\r
+ if( !fp || fp->FD == FD_NOTOPEN )\r
return ;\r
\r
// TODO: Impliment clearerr()\r
\r
EXPORT int feof(FILE *fp)\r
{\r
- if( !fp || fp->FD == -1 )\r
+ if( !fp || fp->FD == FD_NOTOPEN )\r
return 0;\r
return !!(fp->Flags & FILE_FLAG_EOF);\r
}\r
\r
EXPORT int ferror(FILE *fp)\r
{\r
- if( !fp || fp->FD == -1 )\r
+ if( !fp || fp->FD == FD_NOTOPEN )\r
return 0;\r
return 0;\r
}\r
\r
EXPORT off_t ftell(FILE *fp)\r
{\r
- if(!fp || fp->FD == -1) return -1;\r
+ if(!fp || fp->FD == FD_NOTOPEN) {\r
+ errno = EBADF;\r
+ return -1;\r
+ }\r
\r
- if( fp->FD == -2 )\r
+ if( fp->FD == FD_MEMFILE || fp->FD == FD_MEMSTREAM )\r
return fp->Pos; \r
else\r
return _SysTell(fp->FD);\r
}\r
\r
+int _fseek_memfile(FILE *fp, long int amt, int whence)\r
+{\r
+ switch(whence)\r
+ {\r
+ case SEEK_CUR:\r
+ fp->Pos += amt;\r
+ break;\r
+ case SEEK_SET:\r
+ fp->Pos = amt;\r
+ break;\r
+ case SEEK_END:\r
+ if( fp->BufferSpace < (size_t)amt )\r
+ fp->Pos = 0;\r
+ else\r
+ fp->Pos = fp->BufferSpace - amt;\r
+ break;\r
+ }\r
+ if(fp->Pos > (off_t)fp->BufferSpace) {\r
+ fp->Pos = fp->BufferSpace;\r
+ fp->Flags |= FILE_FLAG_EOF;\r
+ }\r
+ return 0;\r
+}\r
+\r
+int _fseek_memstream(FILE *fp, long int amt, int whence)\r
+{\r
+ switch(whence)\r
+ {\r
+ case SEEK_CUR:\r
+ fp->Pos += amt;\r
+ break;\r
+ case SEEK_SET:\r
+ fp->Pos = amt;\r
+ break;\r
+ case SEEK_END:\r
+ if( fp->BufferSpace < (size_t)amt )\r
+ fp->Pos = 0;\r
+ else\r
+ fp->Pos = fp->BufferSpace - amt;\r
+ break;\r
+ }\r
+ if(fp->Pos > (off_t)fp->BufferSpace) {\r
+ fp->Pos = fp->BufferSpace;\r
+ fp->Flags |= FILE_FLAG_EOF;\r
+ }\r
+ return 0;\r
+}\r
+\r
EXPORT int fseek(FILE *fp, long int amt, int whence)\r
{\r
- if(!fp || fp->FD == -1) return -1;\r
+ if(!fp || fp->FD == FD_NOTOPEN) {\r
+ errno = EBADF;\r
+ return -1;\r
+ }\r
\r
- if( fp->FD == -2 ) {\r
- switch(whence)\r
- {\r
- case SEEK_CUR:\r
- fp->Pos += amt;\r
- break;\r
- case SEEK_SET:\r
- fp->Pos = amt;\r
+ if( fp->FD == FD_MEMFILE ) {\r
+ return _fseek_memfile(fp, amt, whence);\r
+ }\r
+ else if( fp->FD == FD_MEMSTREAM ) {\r
+ return _fseek_memstream(fp, amt, whence);\r
+ }\r
+ else {\r
+ fflush(fp);\r
+ _SysSeek(fp->FD, amt, whence);\r
+ fp->Pos = _SysTell(fp->FD);\r
+ return 0;\r
+ }\r
+}\r
+\r
+size_t _fwrite_unbuffered(FILE *fp, size_t size, size_t num, const void *data)\r
+{\r
+ size_t ret = 0, bytes;\r
+ while( num -- )\r
+ {\r
+ bytes = _SysWrite(fp->FD, data, size);\r
+ if( bytes == (size_t)-1 ) {\r
+ // Oops.\r
+ // TODO: Set error flag\r
break;\r
- case SEEK_END:\r
- if( fp->BufferSize < (size_t)amt )\r
- fp->Pos = 0;\r
- else\r
- fp->Pos = fp->BufferSize - amt;\r
+ }\r
+ if( bytes != size ) {\r
+ _SysDebug("_fwrite_unbuffered: Oops, rollback %i/%i bytes!", bytes, size);\r
+ _SysSeek(fp->FD, -bytes, SEEK_CUR);\r
break;\r
}\r
- if(fp->Pos > (off_t)fp->BufferSize) {\r
- fp->Pos = fp->BufferSize;\r
- fp->Flags |= FILE_FLAG_EOF;\r
+ data = (char*)data + size;\r
+ }\r
+ fp->Pos += ret * size;\r
+ return ret;\r
+}\r
+\r
+size_t _fwrite_memfile(const void *ptr, size_t size, size_t num, FILE *fp)\r
+{\r
+ size_t avail = (fp->BufferSpace - fp->Pos) / size;\r
+ if( avail == 0 )\r
+ fp->Flags |= FILE_FLAG_EOF;\r
+ if( num > avail )\r
+ num = avail;\r
+ size_t bytes = num * size;\r
+ memcpy(fp->Buffer + fp->Pos, ptr, bytes);\r
+ fp->Pos += bytes;\r
+ return num;\r
+}\r
+\r
+size_t _fwrite_memstream(const void *ptr, size_t size, size_t num, FILE *fp)\r
+{\r
+ size_t bytes = size*num;\r
+ // #1. Check if we need to expand\r
+ if( fp->Pos + bytes > fp->BufferSpace )\r
+ {\r
+ void *newbuf = realloc(fp->Buffer, fp->BufferSpace + bytes);\r
+ if( !newbuf ) {\r
+ errno = ENOMEM;\r
+ return -1;\r
}\r
- return 0;\r
+ fp->Buffer = newbuf;\r
+ fp->BufferSpace = fp->Pos + bytes;\r
}\r
- else\r
- return _SysSeek(fp->FD, amt, whence);\r
+ // #2. Write (use the memfile code for that)\r
+ return _fwrite_memfile(ptr, size, num, fp);\r
}\r
\r
/**\r
if( size == 0 || num == 0 )\r
return 0;\r
\r
- if( fp->FD == -2 ) {\r
- size_t avail = (fp->BufferSize - fp->Pos) / size;\r
- if( avail == 0 )\r
- fp->Flags |= FILE_FLAG_EOF;\r
- if( num > avail ) num = avail;\r
- size_t bytes = num * size;\r
- memcpy((char*)fp->Buffer + fp->Pos, ptr, bytes);\r
- fp->Pos += bytes;\r
- ret = num;\r
- }\r
- else { \r
- ret = _SysWrite(fp->FD, ptr, size*num);\r
- ret /= size;\r
+ switch( _GetFileMode(fp) )\r
+ {\r
+ case FILE_FLAG_MODE_READ:\r
+ case FILE_FLAG_MODE_EXEC:\r
+ errno = EBADF;\r
+ return 0;\r
+ case FILE_FLAG_MODE_APPEND:\r
+ fseek(fp, 0, SEEK_END);\r
+ case FILE_FLAG_MODE_WRITE:\r
+ // Handle memory files first\r
+ if( fp->FD == FD_MEMFILE ) {\r
+ return _fwrite_memfile(ptr, size, num, fp);\r
+ }\r
+ else if( fp->FD == FD_MEMSTREAM ) {\r
+ return _fwrite_memstream(ptr, size, num, fp);\r
+ }\r
+ else if( fp->BufferSpace )\r
+ {\r
+ // Buffering enabled\r
+ if( fp->BufferSpace - fp->BufferPos < size*num )\r
+ {\r
+ // If there's not enough space, flush and write-through\r
+ _fflush_int(fp); // TODO: check ret\r
+ ret = _fwrite_unbuffered(fp, size, num, ptr);\r
+ }\r
+ else if( (fp->Flags & FILE_FLAG_LINEBUFFERED) && memchr(ptr,'\n',size*num) )\r
+ {\r
+ // Newline present? Flush though\r
+ _fflush_int(fp); // TODO: check ret\r
+ ret = _fwrite_unbuffered(fp, size, num, ptr);\r
+ }\r
+ else\r
+ {\r
+ // Copy to buffer\r
+ memcpy( fp->Buffer + fp->BufferPos, ptr, size*num );\r
+ fp->BufferPos += size*num;\r
+ ret = num;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ // Bufering disabled, write-though\r
+ ret = _fwrite_unbuffered(fp, size, num, ptr);\r
+ }\r
+ // errno should be set earlier\r
+ break;\r
}\r
\r
return ret;\r
}\r
\r
+size_t _fread_memfile(void *ptr, size_t size, size_t num, FILE *fp)\r
+{\r
+ size_t avail = (fp->BufferSpace - fp->Pos) / size;\r
+ if( avail == 0 )\r
+ fp->Flags |= FILE_FLAG_EOF;\r
+ if( num > avail ) num = avail;\r
+ size_t bytes = num * size;\r
+ memcpy(ptr, fp->Buffer + fp->Pos, bytes);\r
+ fp->Pos += bytes;\r
+ return num;\r
+}\r
+\r
+#if 0\r
+size_t _fread_memstream(void *ptr, size_t size, size_t num, FILE *fp)\r
+{\r
+ errno = ENOTIMPL;\r
+ return -1;\r
+}\r
+#endif\r
+\r
+size_t _fread_buffered(void *ptr, size_t size, FILE *fp)\r
+{\r
+ //_SysDebug("%p: %i-%i <= %i", fp,\r
+ // (int)fp->Pos, (int)fp->BufferOfs, (int)fp->BufferPos);\r
+ if( fp->BufferPos > 0 ) {\r
+ assert( fp->Pos - fp->BufferOfs <= (int)fp->BufferPos );\r
+ }\r
+ if( fp->BufferPos == 0 || fp->Pos - fp->BufferOfs == (int)fp->BufferPos )\r
+ {\r
+ int rv = _SysRead(fp->FD, fp->Buffer, fp->BufferSpace);\r
+ if( rv <= 0 ) {\r
+ fp->Flags |= FILE_FLAG_EOF;\r
+ return 0;\r
+ }\r
+ \r
+ fp->BufferPos = rv;\r
+ fp->BufferOfs = fp->Pos;\r
+ //_SysDebug("%p: Buffered %i at %i", fp, rv, fp->Pos);\r
+ }\r
+ \r
+ size_t inner_ofs = fp->Pos - fp->BufferOfs;\r
+ if(size > fp->BufferPos - inner_ofs)\r
+ size = fp->BufferPos - inner_ofs;\r
+ \r
+ //_SysDebug("%p: Read %i from %i+%i", fp, size,\r
+ // (int)fp->BufferOfs, inner_ofs);\r
+ memcpy(ptr, fp->Buffer + inner_ofs, size);\r
+ fp->Pos += size;\r
+ return size;\r
+}\r
+\r
/**\r
* \fn EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp)\r
* \brief Read from a stream\r
return -1;\r
if( size == 0 || num == 0 )\r
return 0;\r
+ \r
+ if( _GetFileMode(fp) != FILE_FLAG_MODE_READ ) {\r
+ errno = 0;\r
+ return -1;\r
+ }\r
\r
- if( fp->FD == -2 ) {\r
- size_t avail = (fp->BufferSize - fp->Pos) / size;\r
- if( avail == 0 )\r
- fp->Flags |= FILE_FLAG_EOF;\r
- if( num > avail ) num = avail;\r
- size_t bytes = num * size;\r
- memcpy(ptr, (char*)fp->Buffer + fp->Pos, bytes);\r
- fp->Pos += bytes;\r
- ret = num;\r
+ // Don't read if EOF is set\r
+ if( fp->Flags & FILE_FLAG_EOF )\r
+ return 0;\r
+\r
+ \r
+ if( fp->FD == FD_MEMFILE ) {\r
+ return _fread_memfile(ptr, size, num, fp);\r
}\r
- else {\r
- ret = _SysRead(fp->FD, ptr, size*num);\r
+ else if( fp->FD == FD_MEMSTREAM ) {\r
+ //return _fread_memstream(ptr, size, num, fp);\r
+ errno = EBADF;\r
+ return 0;\r
+ }\r
+\r
+ // Standard file\r
+ const size_t bytes = size*num;\r
+\r
+ // TODO: Buffered reads\r
+ if( fp->BufferSpace )\r
+ {\r
+ size_t ofs = 0;\r
+ size_t rv;\r
+ // While not done, and buffered read succeeds\r
+ while( ofs < bytes && (rv = _fread_buffered((char*)ptr + ofs, bytes - ofs, fp)) != 0 )\r
+ {\r
+ ofs += rv;\r
+ }\r
+ \r
+ ret = ofs;\r
+ }\r
+ else\r
+ {\r
+ ret = _SysRead(fp->FD, ptr, bytes);\r
if( ret == (size_t)-1)\r
return -1;\r
- if( ret == 0 && size*num > 0 ) {\r
+ if( ret == 0 && bytes > 0 ) {\r
fp->Flags |= FILE_FLAG_EOF;\r
return 0;\r
}\r
- ret /= size;\r
}\r
- \r
- return ret;\r
+\r
+ // if read was cut short \r
+ if( ret != bytes )\r
+ {\r
+ size_t extra = ret - (ret / size) * size;\r
+ // And it didn't fall short on a member boundary\r
+ if( extra )\r
+ {\r
+ // Need to roll back the file pointer to the end of the last member\r
+ _SysDebug("fread: TODO Roll back %zi bytes due to incomplete object (sz=%zi,n=%zi)",\r
+ extra, size, num\r
+ );\r
+ }\r
+ }\r
+ \r
+ return ret / size;\r
}\r
\r
/**\r
*/\r
EXPORT int fputc(int c, FILE *fp)\r
{\r
- return fwrite(&c, 1, 1, fp);\r
+ char ch = c;\r
+ return fwrite(&ch, 1, 1, fp);\r
}\r
\r
EXPORT int putchar(int c)\r
{\r
c &= 0xFF;\r
- return _SysWrite(_stdout, &c, 1);\r
+ return fputc(c, stdout);\r
}\r
\r
/**\r
\r
EXPORT int getchar(void)\r
{\r
- char ret = 0;\r
- if(_SysRead(_stdin, &ret, 1) != 1) return -1;\r
- return ret;\r
+ return fgetc(stdin);\r
+}\r
+\r
+EXPORT int puts(const char *str)\r
+{\r
+ \r
+ if(!str) return 0;\r
+ int len = strlen(str);\r
+ \r
+ fwrite(str, 1, len, stdout);\r
+ fwrite("\n", 1, 1, stdout);\r
+ return len;\r
}\r
\r
// --- INTERNAL ---\r
*/\r
FILE *get_file_struct()\r
{\r
- int i;\r
- for(i=0;i<STDIO_MAX_STREAMS;i++)\r
+ for(int i=0;i<STDIO_MAX_STREAMS;i++)\r
{\r
if(_iob[i].Flags & FILE_FLAG_ALLOC)\r
continue ;\r
return NULL;\r
}\r
\r
-EXPORT int puts(const char *str)\r
-{\r
- int len;\r
- \r
- if(!str) return 0;\r
- len = strlen(str);\r
- \r
- len = _SysWrite(_stdout, str, len);\r
- _SysWrite(_stdout, "\n", 1);\r
- return len;\r
-}\r
-\r