1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2017 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
23/** Cross platform version of C system() function. */
24extern OSG_EXPORT int osg_system(const char* str);
35#if defined(OSG_ENVVAR_SUPPORTED)
43inline unsigned int getClampedLength(const char* str, unsigned int maxNumChars=4096)
46 while(i<maxNumChars && str[i]!=0) { ++i; }
50inline std::string getEnvVar(const char* name)
52#ifdef OSG_ENVVAR_SUPPORTED
54 const char* ptr = getenv(name);
55 if (ptr) value.assign(ptr, getClampedLength(ptr));
65inline bool getEnvVar(const char* name, T& value)
67#ifdef OSG_ENVVAR_SUPPORTED
68 const char* ptr = getenv(name);
69 if (!ptr) return false;
71 std::istringstream str(std::string(ptr, getClampedLength(ptr)));
75 OSG_UNUSED2(name, value);
81inline bool getEnvVar(const char* name, std::string& value)
83#ifdef OSG_ENVVAR_SUPPORTED
84 const char* ptr = getenv(name);
85 if (!ptr) return false;
87 value.assign(ptr, getClampedLength(ptr));
90 OSG_UNUSED2(name, value);
95template<typename T1, typename T2>
96inline bool getEnvVar(const char* name, T1& value1, T2& value2)
98#ifdef OSG_ENVVAR_SUPPORTED
99 const char* ptr = getenv(name);
100 if (!ptr) return false;
102 std::istringstream str(std::string(ptr, getClampedLength(ptr)));
103 str >> value1 >> value2;
106 OSG_UNUSED3(name, value1, value2);
111template<typename T1, typename T2, typename T3>
112inline bool getEnvVar(const char* name, T1& value1, T2& value2, T3& value3)
114#ifdef OSG_ENVVAR_SUPPORTED
115 const char* ptr = getenv(name);
116 if (!ptr) return false;
118 std::istringstream str(std::string(ptr, getClampedLength(ptr)));
119 str >> value1 >> value2 >> value3;
122 OSG_UNUSED4(name, value1, value2, value3);
127template<typename T1, typename T2, typename T3, typename T4>
128inline bool getEnvVar(const char* name, T1& value1, T2& value2, T3& value3, T4& value4)
130#ifdef OSG_ENVVAR_SUPPORTED
131 const char* ptr = getenv(name);
132 if (!ptr) return false;
134 std::istringstream str(std::string(ptr, getClampedLength(ptr)));
135 str >> value1 >> value2 >> value3 >> value4;
138 OSG_UNUSED5(name, value1, value2, value3, value4);