mame/3rdparty/bx/src/process.cpp
Julian Sikorski 0837e7451a WIP: sync bgfx, bx and bimg with latest upstream (#5723)
* Sync with bgfx upstream revision b91d0b6

* Sync with bx upstream revision d60912b

* Sync with bimg upstream revision bd81f60

* Add astc-codec decoder

* Rename VertexDecl to VertexLayout

* Rename UniformType enum Int1 to Sampler.

* Add NVN stub

* Fix unused-const-variable error on macOS

* Drop redundant explicit language parameters
buildoptions_cpp are only applied to c++ files and buildoptions_objcpp are only
applied to objective c++ files. As such, hardcoding -x offers no benefit while
preventing overrides (such as one needed by 3rdparty/bgfx/src/renderer_vk.cpp on
macOS) from working.

* Re-introduce -x c++ in places where C code is compiled as C++ to prevent clang from throwing a warning

* Build bgfx as Objective-C++ on macOS
It is needed due to included headers

* Enable Direct3D12 and Vulkan bgfx rendering backends

* Enable building of spirv shaders

* Properly escape /c in cmd call

* Comment out dx12 bgfx renderer

* Honor VERBOSE setting during shaders build

* Only invert hlsl shader XYZ_TO_sRGB matrix for opengl

* Add spirv shaders

* OpenGL ES needs transposed matrix too

* Metal needs transposed matrix as well
2019-10-13 07:50:38 -04:00

170 lines
3.7 KiB
C++

/*
* Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
#include "bx_p.h"
#include <bx/process.h>
#include <stdio.h>
#ifndef BX_CONFIG_CRT_PROCESS
# define BX_CONFIG_CRT_PROCESS !(0 \
|| BX_CRT_NONE \
|| BX_PLATFORM_EMSCRIPTEN \
|| BX_PLATFORM_PS4 \
|| BX_PLATFORM_WINRT \
|| BX_PLATFORM_XBOXONE \
)
#endif // BX_CONFIG_CRT_PROCESS
namespace bx
{
#if BX_CONFIG_CRT_PROCESS
#if BX_CRT_MSVC
# define popen _popen
# define pclose _pclose
#endif // BX_CRT_MSVC
ProcessReader::ProcessReader()
: m_file(NULL)
{
}
ProcessReader::~ProcessReader()
{
BX_CHECK(NULL == m_file, "Process not closed!");
}
bool ProcessReader::open(const FilePath& _filePath, const StringView& _args, Error* _err)
{
BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors.");
if (NULL != m_file)
{
BX_ERROR_SET(_err, BX_ERROR_READERWRITER_ALREADY_OPEN, "ProcessReader: File is already open.");
return false;
}
char tmp[kMaxFilePath*2] = "\"";
strCat(tmp, BX_COUNTOF(tmp), _filePath);
strCat(tmp, BX_COUNTOF(tmp), "\" ");
strCat(tmp, BX_COUNTOF(tmp), _args);
m_file = popen(tmp, "r");
if (NULL == m_file)
{
BX_ERROR_SET(_err, BX_ERROR_READERWRITER_OPEN, "ProcessReader: Failed to open process.");
return false;
}
return true;
}
void ProcessReader::close()
{
BX_CHECK(NULL != m_file, "Process not open!");
FILE* file = (FILE*)m_file;
m_exitCode = pclose(file);
m_file = NULL;
}
int32_t ProcessReader::read(void* _data, int32_t _size, Error* _err)
{
BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors."); BX_UNUSED(_err);
FILE* file = (FILE*)m_file;
int32_t size = (int32_t)fread(_data, 1, _size, file);
if (size != _size)
{
if (0 != feof(file) )
{
BX_ERROR_SET(_err, BX_ERROR_READERWRITER_EOF, "ProcessReader: EOF.");
}
else if (0 != ferror(file) )
{
BX_ERROR_SET(_err, BX_ERROR_READERWRITER_READ, "ProcessReader: read error.");
}
return size >= 0 ? size : 0;
}
return size;
}
int32_t ProcessReader::getExitCode() const
{
return m_exitCode;
}
ProcessWriter::ProcessWriter()
: m_file(NULL)
{
}
ProcessWriter::~ProcessWriter()
{
BX_CHECK(NULL == m_file, "Process not closed!");
}
bool ProcessWriter::open(const FilePath& _filePath, const StringView& _args, Error* _err)
{
BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors.");
if (NULL != m_file)
{
BX_ERROR_SET(_err, BX_ERROR_READERWRITER_ALREADY_OPEN, "ProcessWriter: File is already open.");
return false;
}
char tmp[kMaxFilePath*2] = "\"";
strCat(tmp, BX_COUNTOF(tmp), _filePath);
strCat(tmp, BX_COUNTOF(tmp), "\" ");
strCat(tmp, BX_COUNTOF(tmp), _args);
m_file = popen(tmp, "w");
if (NULL == m_file)
{
BX_ERROR_SET(_err, BX_ERROR_READERWRITER_OPEN, "ProcessWriter: Failed to open process.");
return false;
}
return true;
}
void ProcessWriter::close()
{
BX_CHECK(NULL != m_file, "Process not open!");
FILE* file = (FILE*)m_file;
m_exitCode = pclose(file);
m_file = NULL;
}
int32_t ProcessWriter::write(const void* _data, int32_t _size, Error* _err)
{
BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors."); BX_UNUSED(_err);
FILE* file = (FILE*)m_file;
int32_t size = (int32_t)fwrite(_data, 1, _size, file);
if (size != _size)
{
if (0 != ferror(file) )
{
BX_ERROR_SET(_err, BX_ERROR_READERWRITER_WRITE, "ProcessWriter: write error.");
}
return size >= 0 ? size : 0;
}
return size;
}
int32_t ProcessWriter::getExitCode() const
{
return m_exitCode;
}
#endif // BX_CONFIG_CRT_PROCESS
} // namespace bx