csutil/macosx/csosdefs.h
00001 #ifndef __OSX_csosdefs_h 00002 #define __OSX_csosdefs_h 00003 //============================================================================= 00004 // 00005 // Copyright (C)1999-2002 by Eric Sunshine <sunshine@sunshineco.com> 00006 // 00007 // The contents of this file are copyrighted by Eric Sunshine. This work is 00008 // distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00009 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 00010 // PARTICULAR PURPOSE. You may distribute this file provided that this 00011 // copyright notice is retained. Send comments to <sunshine@sunshineco.com>. 00012 // 00013 //============================================================================= 00014 //----------------------------------------------------------------------------- 00015 // csosdefs.h 00016 // 00017 // MacOS/X-specific interface to common functionality. 00018 // 00019 //----------------------------------------------------------------------------- 00020 00021 //----------------------------------------------------------------------------- 00022 // The 2D graphics driver used by the software renderer on this platform. 00023 //----------------------------------------------------------------------------- 00024 #undef CS_SOFTWARE_2D_DRIVER 00025 #define CS_SOFTWARE_2D_DRIVER "crystalspace.graphics2d.coregraphics" 00026 #define CS_SOFTWARE_2D_DRIVER_COCOA "crystalspace.graphics2d.cocoa" 00027 00028 #undef CS_OPENGL_2D_DRIVER 00029 #define CS_OPENGL_2D_DRIVER "crystalspace.graphics2d.glosx" 00030 00031 #undef CS_SOUND_DRIVER 00032 #define CS_SOUND_DRIVER "crystalspace.sound.driver.coreaudio" 00033 00034 00035 //----------------------------------------------------------------------------- 00036 // Provide CS_MAXPATHLEN, PATH_SEPARATOR, PATH_DELIMITER with proper values. 00037 //----------------------------------------------------------------------------- 00038 #include <sys/param.h> 00039 #define CS_MAXPATHLEN MAXPATHLEN 00040 #define PATH_SEPARATOR '/' 00041 #define PATH_DELIMITER ':' 00042 00043 00044 //----------------------------------------------------------------------------- 00045 // Pull in definitions for getwd(), ntohl(), htonl(), select(), etc. 00046 // NOTE: On MacOS/X, libc.h pulls in sys/mount.h which pulls in net/radix.h 00047 // which defines a macro named Free(). This macro interferes with several 00048 // Crystal Space classes which have methods named Free(), so we must 00049 // #undef it. 00050 //----------------------------------------------------------------------------- 00051 #if defined(CS_SYSDEF_PROVIDE_GETCWD) || \ 00052 defined(CS_SYSDEF_PROVIDE_SOCKETS) || \ 00053 defined(CS_SYSDEF_PROVIDE_SELECT) || \ 00054 defined(CS_SYSDEF_PROVIDE_ACCESS) 00055 #include <libc.h> 00056 #undef Free 00057 #endif 00058 00059 #if defined(CS_SYSDEF_PROVIDE_SELECT) 00060 #include <string.h> // For memset() 00061 #define bzero(b,len) memset(b,0,len) /* bzero used by FD_ZERO */ 00062 #undef CS_SYSDEF_PROVIDE_SELECT 00063 #endif 00064 00065 00066 //----------------------------------------------------------------------------- 00067 // NeXT does not properly support Posix 'dirent', so fake it with 'direct'. 00068 //----------------------------------------------------------------------------- 00069 #ifdef CS_SYSDEF_PROVIDE_DIR 00070 00071 #include <sys/dir.h> 00072 #include <sys/dirent.h> 00073 #define __NEED_GENERIC_ISDIR 00074 00075 #endif // CS_SYSDEF_PROVIDE_DIR 00076 00077 00078 //----------------------------------------------------------------------------- 00079 // Note by Matt Reda: I did some rough testing of QInt() and friends on the 00080 // PowerPC. It appears to work ok, but is actually slower. Some simple 00081 // tests show that QInt() is roughly twice as slow as a cast from double 00082 // to long 00083 //----------------------------------------------------------------------------- 00084 #define CS_NO_IEEE_OPTIMIZATIONS 00085 00086 00087 //----------------------------------------------------------------------------- 00088 // MacOS/X mmap() functionality for memory-mapped I/O. 00089 //----------------------------------------------------------------------------- 00090 #if defined(CS_SYSDEF_PROVIDE_HARDWARE_MMIO) 00091 00092 #define CS_HAS_MEMORY_MAPPED_IO 1 00093 00094 #include <unistd.h> 00095 #include <sys/mman.h> 00096 #include <sys/types.h> 00097 #include <sys/stat.h> 00098 #include <fcntl.h> 00099 00100 // Unix specific memory mapped I/O platform dependent stuff 00101 struct mmioInfo 00102 { 00103 int file; // Handle to the mapped file. 00104 unsigned int file_size; // File size. 00105 unsigned char* data; // Base pointer to the data. 00106 }; 00107 00108 // Fill in the mmioInfo struct by mapping in filename. 00109 // Returns true on success, false otherwise. 00110 inline bool MemoryMapFile(mmioInfo* info, char const* filename) 00111 { 00112 bool ok = false; 00113 struct stat st; 00114 int const fd = open(filename, O_RDONLY); 00115 if (fd != -1 && fstat(fd, &st) != -1) 00116 { 00117 unsigned char* p=(unsigned char*)mmap(0, st.st_size, PROT_READ, 0, fd, 0); 00118 if ((int)p != -1) 00119 { 00120 info->file = fd; 00121 info->data = p; 00122 info->file_size = st.st_size; 00123 ok = true; 00124 } 00125 } 00126 if (!ok && fd != -1) 00127 close(fd); 00128 return ok; 00129 } 00130 00131 inline void UnMemoryMapFile(mmioInfo* info) 00132 { 00133 if (info->data != 0) 00134 munmap(info->data, info->file_size); 00135 if (info->file != -1) 00136 close(info->file); 00137 } 00138 00139 #endif // CS_SYSDEF_PROVIDE_HARDWARE_MMIO 00140 00141 #endif // __OSX_csosdefs_h
Generated for Crystal Space by doxygen 1.2.18