DRC | 2e7b76b | 2009-04-03 12:04:24 +0000 | [diff] [blame] | 1 | /* Copyright (C)2004 Landmark Graphics Corporation |
| 2 | * Copyright (C)2005 Sun Microsystems, Inc. |
| 3 | * |
| 4 | * This library is free software and may be redistributed and/or modified under |
| 5 | * the terms of the wxWindows Library License, Version 3.1 or (at your option) |
| 6 | * any later version. The full license is in the LICENSE.txt file included |
| 7 | * with this distribution. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * wxWindows Library License for more details. |
| 13 | */ |
| 14 | |
| 15 | #ifndef __RRUTIL_H__ |
| 16 | #define __RRUTIL_H__ |
| 17 | |
| 18 | #ifdef _WIN32 |
| 19 | #include <windows.h> |
| 20 | #define sleep(t) Sleep((t)*1000) |
| 21 | #define usleep(t) Sleep((t)/1000) |
| 22 | #else |
| 23 | #include <unistd.h> |
| 24 | #define stricmp strcasecmp |
| 25 | #define strnicmp strncasecmp |
| 26 | #endif |
| 27 | |
| 28 | #ifndef min |
| 29 | #define min(a,b) ((a)<(b)?(a):(b)) |
| 30 | #endif |
| 31 | |
| 32 | #ifndef max |
| 33 | #define max(a,b) ((a)>(b)?(a):(b)) |
| 34 | #endif |
| 35 | |
| 36 | #define pow2(i) (1<<(i)) |
| 37 | #define isPow2(x) (((x)&(x-1))==0) |
| 38 | |
| 39 | #ifdef sgi |
| 40 | #define _SC_NPROCESSORS_CONF _SC_NPROC_CONF |
| 41 | #endif |
| 42 | |
| 43 | #ifdef sun |
| 44 | #define __inline inline |
| 45 | #endif |
| 46 | |
| 47 | static __inline int numprocs(void) |
| 48 | { |
| 49 | #ifdef _WIN32 |
| 50 | DWORD ProcAff, SysAff, i; int count=0; |
| 51 | if(!GetProcessAffinityMask(GetCurrentProcess(), &ProcAff, &SysAff)) return(1); |
| 52 | for(i=0; i<32; i++) if(ProcAff&(1<<i)) count++; |
| 53 | return(count); |
| 54 | #elif defined (__APPLE__) |
| 55 | return(1); |
| 56 | #else |
| 57 | long count=1; |
| 58 | if((count=sysconf(_SC_NPROCESSORS_CONF))!=-1) return((int)count); |
| 59 | else return(1); |
| 60 | #endif |
| 61 | } |
| 62 | |
| 63 | #define byteswap(i) ( \ |
| 64 | (((i) & 0xff000000) >> 24) | \ |
| 65 | (((i) & 0x00ff0000) >> 8) | \ |
| 66 | (((i) & 0x0000ff00) << 8) | \ |
| 67 | (((i) & 0x000000ff) << 24) ) |
| 68 | |
| 69 | #define byteswap16(i) ( \ |
| 70 | (((i) & 0xff00) >> 8) | \ |
| 71 | (((i) & 0x00ff) << 8) ) |
| 72 | |
| 73 | static __inline int littleendian(void) |
| 74 | { |
| 75 | unsigned int value=1; |
| 76 | unsigned char *ptr=(unsigned char *)(&value); |
| 77 | if(ptr[0]==1 && ptr[3]==0) return 1; |
| 78 | else return 0; |
| 79 | } |
| 80 | |
| 81 | #endif |