This commit is contained in:
Branimir Karadžić
2018-03-28 21:23:13 -07:00
parent 174be8d975
commit 90998a5872
4 changed files with 40 additions and 13 deletions

View File

@@ -356,23 +356,38 @@ namespace bx
return result;
}
inline int32_t writePrintf(WriterI* _writer, const char* _format, ...)
inline int32_t writePrintfVargs(WriterI* _writer, const char* _format, va_list _argList)
{
va_list argList;
va_start(argList, _format);
va_list argListCopy;
va_copy(argListCopy, _argList);
char temp[2048];
char* out = temp;
char* out = temp;
int32_t max = sizeof(temp);
int32_t len = vsnprintf(out, max, _format, argList);
int32_t len = vsnprintf(out, max, _format, argListCopy);
va_end(argListCopy);
if (len > max)
{
va_copy(argListCopy, _argList);
out = (char*)alloca(len);
len = vsnprintf(out, len, _format, argList);
len = vsnprintf(out, len, _format, argListCopy);
va_end(argListCopy);
}
int32_t size = write(_writer, out, len);
return size;
}
inline int32_t writePrintf(WriterI* _writer, const char* _format, ...)
{
va_list argList;
va_start(argList, _format);
int32_t size = writePrintfVargs(_writer, _format, argList);
va_end(argList);
return size;

View File

@@ -280,6 +280,9 @@ namespace bx
template<typename Ty>
int32_t writeBE(WriterI* _writer, const Ty& _value, Error* _err = NULL);
/// Write formated string.
int32_t writePrintfVargs(WriterI* _writer, const char* _format, va_list _argList);
/// Write formated string.
int32_t writePrintf(WriterI* _writer, const char* _format, ...);

View File

@@ -5,9 +5,9 @@
#include "bx_p.h"
#include <bx/debug.h>
#include <bx/file.h>
#include <bx/math.h>
#include <bx/sort.h>
#include <bx/readerwriter.h>
#if BX_CRT_NONE
@@ -286,8 +286,12 @@ extern "C" int snprintf(char* _out, size_t _max, const char* _format, ...)
extern "C" int printf(const char* _format, ...)
{
BX_UNUSED(_format);
return -1;
va_list argList;
va_start(argList, _format);
bx::WriterI* writer = bx::getStdOut();
int32_t len = bx::writePrintfVargs(writer, _format, argList);
va_end(argList);
return len;
}
struct FILE
@@ -429,6 +433,7 @@ extern "C" int prctl(int _option, unsigned long _arg2, unsigned long _arg3, unsi
extern "C" int chdir(const char* _path)
{
BX_UNUSED(_path);
bx::debugPrintf("chdir(%s) not implemented!\n", _path);
return -1;
}
@@ -441,18 +446,21 @@ extern "C" char* getcwd(char* _buf, size_t _size)
extern "C" char* getenv(const char* _name)
{
BX_UNUSED(_name);
return NULL;
bx::debugPrintf("getenv(%s) not implemented!\n", _name);
return (char*)"";
}
extern "C" int setenv(const char* _name, const char* _value, int _overwrite)
{
BX_UNUSED(_name, _value, _overwrite);
bx::debugPrintf("setenv(%s, %s, %d) not implemented!\n", _name, _value, _overwrite);
return -1;
}
extern "C" int unsetenv(const char* _name)
{
BX_UNUSED(_name);
bx::debugPrintf("unsetenv(%s) not implemented!\n", _name);
return -1;
}
@@ -565,17 +573,17 @@ namespace __cxxabiv1
__extension__ typedef int __guard __attribute__( (mode(__DI__) ) );
extern "C" int __cxa_guard_acquire (__guard* _g)
extern "C" int __cxa_guard_acquire(__guard* _g)
{
return !*(char*)(_g);
}
extern "C" void __cxa_guard_release (__guard* _g)
extern "C" void __cxa_guard_release(__guard* _g)
{
*(char*)_g = 1;
}
extern "C" void __cxa_guard_abort (__guard* _g)
extern "C" void __cxa_guard_abort(__guard* _g)
{
BX_UNUSED(_g);
}

View File

@@ -305,6 +305,7 @@ namespace bx
int32_t size = crt0::read(m_fd, _data, _size);
if (size != _size)
{
BX_UNUSED(_err);
// if (0 != feof(m_file) )
// {
// BX_ERROR_SET(_err, BX_ERROR_READERWRITER_EOF, "FileReader: EOF.");