From 18d5a9159f9c66336c40bf91b77dfe3ebe3af31f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 21 Jan 2018 12:09:49 +0000 Subject: [PATCH] Restructured the system() fallback to be usable for C and C++ --- include/osg/os_utils | 37 ++++++++++---------- src/osg/CMakeLists.txt | 1 + src/osg/os_utils.cpp | 28 +++++++++++++++ src/osgPlugins/lua/lua-5.2.3/src/loslib.c | 8 ++--- src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp | 4 +-- src/osgPlugins/tgz/ReaderWriterTGZ.cpp | 4 +-- src/osgPresentation/KeyEventHandler.cpp | 2 +- src/osgPresentation/PickEventHandler.cpp | 2 +- src/osgPresentation/SlideEventHandler.cpp | 4 +-- src/osgPresentation/SlideShowConstructor.cpp | 2 +- 10 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 src/osg/os_utils.cpp diff --git a/include/osg/os_utils b/include/osg/os_utils index 2caf78a9f..b46073f5b 100644 --- a/include/osg/os_utils +++ b/include/osg/os_utils @@ -11,33 +11,32 @@ * OpenSceneGraph Public License for more details. */ -#ifndef OSG_osg_utils -#define OSG_osg_utils 1 +#ifndef OSG_os_utils +#define OSG_os_utils 1 -#include +#include -#if defined(OSG_SYSTEM_SUPPORTED) || defined(OSG_ENVVAR_SUPPORTED) - #include +#ifdef __cplusplus +extern "C" { #endif -#ifdef OSG_ENVVAR_SUPPORTED +/** Cross platform version of C system() function. */ +extern OSG_EXPORT int osg_system(const char* str); + +#ifdef __cplusplus +} +#endif + + +#ifdef __cplusplus + +#if defined(OSG_ENVVAR_SUPPORTED) + #include #include #endif namespace osg { -#ifdef OSG_SYSTEM_SUPPORTED -inline int system(const char* command) -{ - return ::system(command); -} -#else -inline int system(const char* command) -{ - OSG_WARN<<"system("< + +extern "C" { + +int osg_system(const char* command) +{ +#ifdef OSG_SYSTEM_SUPPORTED + return system(command); +#else + printf("osgSystem(%s) not supported.\n", command); +#endif +} + +} + diff --git a/src/osgPlugins/lua/lua-5.2.3/src/loslib.c b/src/osgPlugins/lua/lua-5.2.3/src/loslib.c index 5a7904a6b..6fb877829 100644 --- a/src/osgPlugins/lua/lua-5.2.3/src/loslib.c +++ b/src/osgPlugins/lua/lua-5.2.3/src/loslib.c @@ -19,7 +19,7 @@ #include "lauxlib.h" #include "lualib.h" -#include +#include /* ** list of valid conversion specifiers for the 'strftime' function @@ -80,18 +80,14 @@ static int os_execute (lua_State *L) { -#if defined(OSG_SYSTEM_SUPPORTED) const char *cmd = luaL_optstring(L, 1, NULL); - int stat = system(cmd); + int stat = osg_system(cmd); if (cmd != NULL) return luaL_execresult(L, stat); else { lua_pushboolean(L, stat); /* true if there is a shell */ return 1; } -#else - return 0; -#endif } diff --git a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp index 788875a22..9fa7bc5e3 100644 --- a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp +++ b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp @@ -78,7 +78,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter mkdir( dirname, 0700 ); #endif - if (osg::system( command ) ) { + if (osg_system( command ) ) { return ReadResult::FILE_NOT_HANDLED; } @@ -108,7 +108,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter sprintf( command, "rm -rf %s", dirname ); #endif - if (osg::system( command ) ) { + if (osg_system( command ) ) { return ReadResult::FILE_NOT_HANDLED; } diff --git a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp index d9345bd19..6f1b7f81f 100644 --- a/src/osgPlugins/tgz/ReaderWriterTGZ.cpp +++ b/src/osgPlugins/tgz/ReaderWriterTGZ.cpp @@ -95,7 +95,7 @@ class ReaderWriterTGZ : public osgDB::ReaderWriter OSG_NOTICE<<"Running command '"<getNumChildren() == 0 ) diff --git a/src/osgPresentation/KeyEventHandler.cpp b/src/osgPresentation/KeyEventHandler.cpp index 1b7e7dc6d..84f3c85de 100644 --- a/src/osgPresentation/KeyEventHandler.cpp +++ b/src/osgPresentation/KeyEventHandler.cpp @@ -120,7 +120,7 @@ void KeyEventHandler::doOperation() bool commandRunsInBackground = (_command.find("&")!=std::string::npos); - int result = osg::system(_command.c_str()); + int result = osg_system(_command.c_str()); OSG_INFO<<"system("<<_command<<") result "<c_str()<tick(); - int result = osg::system(itr->c_str()); + int result = osg_system(itr->c_str()); OSG_INFO<<"system("<<*itr<<") result "< previousOptions = _options;