OS.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031
00032
00033
00034 #include <stb/base/fixWinCEIssues.h>
00035 #include <stb/base/OS.h>
00036 #include <stb/base/fixWinXPIssues.h>
00037 #include <ace/OS.h>
00038
00039 #ifndef __APPLE__
00040 #include <GL/gl.h>
00041 #else
00042 #include <OpenGL/gl.h>
00043 #endif
00044 #include <cstdio>
00045 #include <sstream>
00046 #include <iostream>
00047 #include <assert.h>
00048
00049
00050 BEGIN_NAMESPACE_STB
00051
00052
00053
00056 hModule
00057 os_LoadLibrary(stb::string fileName)
00058 {
00059 #ifdef STB_IS_WINDOWS
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 std::string fName = fileName;
00075 fName += ".dll";
00076
00077 const char* libNameStr = fName.c_str();
00078 assert(libNameStr);
00079
00080 return ::LoadLibrary(ACE_TEXT_CHAR_TO_TCHAR(libNameStr));
00081 #else
00082 using namespace std;
00083 stb::string pathName, libName;
00084 stb::string::size_type pos = fileName.rfind('/');
00085
00086 if(pos != stb::string::npos) {
00087 ++pos;
00088 pathName = fileName.substr(0, pos);
00089 fileName = fileName.substr(pos, fileName.length() - pos);
00090 }
00091
00092 #ifndef __APPLE__
00093 libName = pathName + "lib" + fileName + ".so";
00094 #else
00095 libName = pathName + "lib" + fileName + ".dylib";
00096 #endif
00097 cerr << " Dynamically loading >" << libName << "< ...";
00098
00099
00100 hModule p = dlopen(libName.c_str(), RTLD_LAZY);
00101 if (!p) {
00102 cerr << " failed: cannot load library: " << dlerror() << '\n';
00103 return 0;
00104 }
00105 cerr << " done." << endl;
00106 return p;
00107 #endif
00108 }
00109
00110
00113 int*
00114 os_GetProcAddress(hModule moduleHandle,const char* procName)
00115 {
00116 #ifdef STB_IS_WINDOWS
00117 return (int*)GetProcAddress(moduleHandle, ACE_TEXT_CHAR_TO_TCHAR(procName));
00118 #else
00119 return (int*)dlsym(moduleHandle, procName);
00120 #endif
00121 }
00122
00123 bool
00124 os_FreeLibrary(hModule libHandle)
00125 {
00126 #ifdef STB_IS_WINDOWS
00127 if(FreeLibrary(libHandle))
00128 return true;
00129 else
00130 return false;
00131 #else
00132 dlclose(libHandle);
00133 return true;
00134 #endif
00135 }
00136
00137
00138 bool
00139 os_correctModuleName(stb::string& fileName, bool nMakeDebug, bool nMakeES)
00140 {
00141
00142
00143
00144 #if defined(_IS_KLIMTES_) && defined(STB_IS_WINXP)
00145 if(nMakeES)
00146 fileName += "_es";
00147 #endif
00148
00149
00150
00151 #if defined(STB_IS_WINDOWS) && defined(STB_IS_DEBUG)
00152 if(nMakeDebug)
00153 fileName += "d";
00154 #endif
00155
00156 return true;
00157 }
00158
00159
00160 END_NAMESPACE_STB
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176