00001
00002 #include "OSDependent/OS.h"
00003
00004 const char OS::DirectorySeparator = '\\';
00005 const char *OS::TemporaryDirectory = "C:\\Temp";
00006 const char *OS::LineSeparator = "\r\n";
00007
00008
00009
00010
00011
00012
00013
00014
00015 const char *
00016 OS::getMyHostName()
00017 {
00018 return NULL;
00019 }
00020
00021
00022
00023
00024 char *
00025 OS::strtok_r(char *s, const char *tokens, char **lasts)
00026 {
00027 if (s == NULL)
00028 s = *lasts;
00029 else
00030 *lasts = s;
00031 if (*s == '\0')
00032 return NULL;
00033 char *end = s + strlen(s);
00034 s = ::strtok(s, tokens);
00035 if (s == NULL)
00036 return NULL;
00037 int l_sub = strlen(s);
00038 *lasts = s + l_sub;
00039 if (end != s + l_sub)
00040 *lasts += 1;
00041 return s;
00042 }
00043
00044
00045 char *
00046 OS::strdup(const char *orig)
00047 {
00048 if(orig==0)
00049 return 0;
00050
00051 char *temp = new char[strlen(orig)+1];
00052 strcpy(temp,orig);
00053
00054 return temp;
00055 }
00056
00057 int
00058 OS::remove(const char *name)
00059 {
00060
00061
00062 return 0;
00063 }
00064
00065 bool
00066 OS::isDirectory(const char *name)
00067 {
00068
00069
00070
00071
00072 return false;
00073 }
00074
00075 int
00076 OS::mkdir(const char *name)
00077 {
00078
00079
00080
00081
00082
00083 return 0;
00084 }
00085
00086 int
00087 OS::rmdir(const char *name)
00088 {
00089
00090
00091 return 0;
00092 }
00093
00094 int
00095 OS::rename(const char *src, const char *dst)
00096 {
00097
00098
00099 return 0;
00100 }
00101
00102 char *
00103 OS::getProcessorName ()
00104 {
00105 static char buf[512];
00106 OSVERSIONINFO osvi;
00107 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00108
00109 ::GetVersionEx (&osvi);
00110
00111 switch(osvi.dwPlatformId) {
00112 case VER_PLATFORM_WIN32s:
00113 case VER_PLATFORM_WIN32_WINDOWS:
00114 OS::strcpy(buf,"windows");
00115 break;
00116 case VER_PLATFORM_WIN32_NT:
00117 OS::strcpy(buf,"windows-nt");
00118 break;
00119 default:
00120 OS::strcpy(buf,"windows-unknown");
00121 break;
00122 }
00123
00124 return(buf);
00125 }
00126
00127 char *
00128 OS::getOSName()
00129 {
00130 static char buf[512];
00131 SYSTEM_INFO si;
00132
00133 ::GetSystemInfo(&si);
00134
00135 if (OS::strcmp(getProcessorName(), "windows-nt") == 0) {
00136 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) {
00137 switch (si.wProcessorLevel) {
00138 case 3:
00139 OS::strcpy(buf,"i386");
00140 break;
00141 case 4:
00142 OS::strcpy(buf,"i486");
00143 break;
00144 case 5:
00145 OS::strcpy(buf, "i586");
00146 break;
00147 default:
00148 OS::strcpy(buf,"intel");
00149 break;
00150 }
00151 } else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_MIPS) {
00152 OS::strcpy(buf,"mips");
00153 } else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ALPHA) {
00154 OS::sprintf(buf, "Alpha%d", si.wProcessorLevel);
00155 } else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_PPC) {
00156 OS::sprintf(buf, "PPC 6%02d", si.wProcessorLevel);
00157 }
00158 } else {
00159 if (si.dwProcessorType == PROCESSOR_INTEL_386) {
00160 OS::strcpy(buf,"i386");
00161 } else if (si.dwProcessorType == PROCESSOR_INTEL_486) {
00162 OS::strcpy(buf,"i486");
00163 } else if (si.dwProcessorType == PROCESSOR_INTEL_PENTIUM) {
00164 OS::strcpy(buf,"i586");
00165 } else OS::strcpy(buf,"intel");
00166 }
00167
00168 return (buf);
00169 }
00170
00171
00172
00173
00174 int
00175 OS::getErrno()
00176 {
00177 int val = 0;
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 return val;
00209 }
00210
00211
00212
00213
00214 char *
00215 OS::getenv(const char *str)
00216 {
00217
00218 return NULL;
00219 }
00220
00221
00222
00223
00224 int
00225 OS::system(const char *fmt, ...)
00226 {
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 return 0;
00240 }
00241
00242
00243 int
00244 OS::sprintf( char *buffer, const char *format, ... )
00245 {
00246 va_list vl;
00247 int i,j=0;
00248 char temp[256];
00249
00250
00251
00252
00253 va_start( vl, format );
00254
00255
00256 for( i = 0; format[i] != '\0'; ++i )
00257 {
00258 union Printable_t
00259 {
00260 int i;
00261 float f;
00262 char c;
00263 char *s;
00264 } Printable;
00265
00266 if(format[i]!='%')
00267 {
00268 buffer[j++]=format[i];
00269 }
00270 else
00271 {
00272 buffer[j]=0;
00273
00274
00275 i++;
00276 switch( format[i] )
00277 {
00278 case 'd':
00279 Printable.i = va_arg( vl, int );
00280 _itoa( Printable.i, temp, 10 );
00281 strcat(buffer, temp);
00282 j+=strlen(temp);
00283 break;
00284
00285 case 'c':
00286 Printable.c = va_arg( vl, char );
00287 buffer[j] = Printable.c ;
00288 j++;
00289 break;
00290
00291 case 's':
00292 Printable.s = va_arg( vl, char * );
00293 strcat(buffer,Printable.s);
00294 j+=strlen(Printable.s);
00295 break;
00296
00297 default:
00298 break;
00299 }
00300 }
00301 }
00302 va_end( vl );
00303
00304 buffer[j]=0;
00305
00306 return j;
00307 }
00308
00309
00310 char OS::setValue (char *key, char *subKey, char* value)
00311 {
00312 LONG lResult;
00313 HKEY hkey;
00314 DWORD dwSize;
00315 WCHAR uniBuffer[512];
00316
00317 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, key, -1, uniBuffer, 1024 );
00318
00319 lResult = RegCreateKeyEx( HKEY_LOCAL_MACHINE, uniBuffer, 0, 0, 0, 0, NULL, &hkey, &dwSize );
00320
00321 if ( ERROR_SUCCESS != lResult )
00322 {
00323 return -1;
00324 }
00325
00326 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, subKey, -1, uniBuffer, 512 );
00327
00328 RegSetValueEx( hkey, uniBuffer, 0, REG_SZ, (const unsigned char*)value, strlen(value)+1);
00329 RegCloseKey( hkey );
00330
00331 return 1;
00332 }
00333
00334
00335 char *OS::getValue (char *key, char *subkey)
00336 {
00337 LONG lResult;
00338 HKEY hkey;
00339 WCHAR uniBuffer[1024];
00340 char value[256];
00341 DWORD dwSize = 256;
00342
00343 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, key, -1, uniBuffer, 1024 );
00344 lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, uniBuffer, 0, 0, &hkey);
00345
00346 if ( ERROR_SUCCESS != lResult )
00347 return 0;
00348
00349 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, subkey, -1, uniBuffer, 1024 );
00350
00351 RegQueryValueEx( hkey, uniBuffer, 0, NULL, (LPBYTE)value, &dwSize);
00352 RegCloseKey( hkey );
00353
00354 return strdup(value);
00355 }
00356
00357
00358 void OS::free(void *p)
00359 {
00360 MemoryManager::globalMemMgr_->freeMem(p);
00361 }
00362
00363 void *OS::malloc(size_t t)
00364 {
00365 return ::malloc(t);
00366 }