![]() |
Public API Reference |
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 and PATH_SEPARATOR with proper values. 00037 //----------------------------------------------------------------------------- 00038 #include <sys/param.h> 00039 #define CS_MAXPATHLEN MAXPATHLEN 00040 #define PATH_SEPARATOR '/' 00041 00042 00043 //----------------------------------------------------------------------------- 00044 // Pull in definitions for getwd(), ntohl(), htonl(), select(), etc. 00045 // NOTE: On MacOS/X, libc.h pulls in sys/mount.h which pulls in net/radix.h 00046 // which defines a macro named Free(). This macro interferes with several 00047 // Crystal Space classes which have methods named Free(), so we must 00048 // #undef it. 00049 //----------------------------------------------------------------------------- 00050 #if defined(CS_SYSDEF_PROVIDE_GETCWD) || \ 00051 defined(CS_SYSDEF_PROVIDE_SOCKETS) || \ 00052 defined(CS_SYSDEF_PROVIDE_SELECT) || \ 00053 defined(CS_SYSDEF_PROVIDE_ACCESS) 00054 #include <libc.h> 00055 #undef Free 00056 #endif 00057 00058 #if defined(CS_SYSDEF_PROVIDE_SELECT) 00059 #include <string.h> // For memset() 00060 #define bzero(b,len) memset(b,0,len) /* bzero used by FD_ZERO */ 00061 #undef CS_SYSDEF_PROVIDE_SELECT 00062 #endif 00063 00064 00065 //----------------------------------------------------------------------------- 00066 // NeXT does not properly support Posix 'dirent', so fake it with 'direct'. 00067 //----------------------------------------------------------------------------- 00068 #ifdef CS_SYSDEF_PROVIDE_DIR 00069 00070 #include <sys/dir.h> 00071 #include <sys/dirent.h> 00072 #define __NEED_GENERIC_ISDIR 00073 00074 #endif // CS_SYSDEF_PROVIDE_DIR 00075 00076 00077 //----------------------------------------------------------------------------- 00078 // Note by Matt Reda: I did some rough testing of QInt() and friends on the 00079 // PowerPC. It appears to work ok, but is actually slower. Some simple 00080 // tests show that QInt() is roughly twice as slow as a cast from double 00081 // to long 00082 //----------------------------------------------------------------------------- 00083 #define CS_NO_IEEE_OPTIMIZATIONS 00084 00085 00086 //----------------------------------------------------------------------------- 00087 // MacOS/X mmap() functionality for memory-mapped I/O. 00088 //----------------------------------------------------------------------------- 00089 #if defined(CS_SYSDEF_PROVIDE_HARDWARE_MMIO) 00090 00091 #define CS_HAS_MEMORY_MAPPED_IO 1 00092 00093 #include <unistd.h> 00094 #include <sys/mman.h> 00095 #include <sys/types.h> 00096 #include <sys/stat.h> 00097 #include <fcntl.h> 00098 00099 // Unix specific memory mapped I/O platform dependent stuff 00100 struct mmioInfo 00101 { 00102 int file; // Handle to the mapped file. 00103 unsigned int file_size; // File size. 00104 unsigned char* data; // Base pointer to the data. 00105 }; 00106 00107 // Fill in the mmioInfo struct by mapping in filename. 00108 // Returns true on success, false otherwise. 00109 inline bool MemoryMapFile(mmioInfo* info, char const* filename) 00110 { 00111 bool ok = false; 00112 struct stat st; 00113 int const fd = open(filename, O_RDONLY); 00114 if (fd != -1 && fstat(fd, &st) != -1) 00115 { 00116 unsigned char* p=(unsigned char*)mmap(0, st.st_size, PROT_READ, 0, fd, 0); 00117 if ((int)p != -1) 00118 { 00119 info->file = fd; 00120 info->data = p; 00121 info->file_size = st.st_size; 00122 ok = true; 00123 } 00124 } 00125 if (!ok && fd != -1) 00126 close(fd); 00127 return ok; 00128 } 00129 00130 inline void UnMemoryMapFile(mmioInfo* info) 00131 { 00132 if (info->data != 0) 00133 munmap(info->data, info->file_size); 00134 if (info->file != -1) 00135 close(info->file); 00136 } 00137 00138 #endif // CS_SYSDEF_PROVIDE_HARDWARE_MMIO 00139 00140 #endif // __OSX_csosdefs_h