From 9aa1e20c775ebd0460ebdde8e5d481efce756280 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 1 Jan 2010 09:21:04 +0000 Subject: [PATCH] - Added Blzut3's Solaris patch. SVN r2070 (trunk) --- docs/rh-log.txt | 1 + src/CMakeLists.txt | 5 ++ src/i_net.cpp | 7 ++ src/m_alloc.cpp | 95 ++++++++++++++++++++++++++++ src/p_switch.cpp | 4 +- src/resourcefiles/file_directory.cpp | 43 +++++++++++++ src/sdl/crashcatcher.c | 6 ++ src/sound/fmodsound.cpp | 2 + src/sound/music_dumb.cpp | 4 +- src/w_zip.h | 4 +- 10 files changed, 165 insertions(+), 6 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 36d6d9a2e4..4af0837cdd 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -7,6 +7,7 @@ January 1, 2010 (SBARINFO update) inventory items and armortype in drawswitchableimage. January 1, 2010 (Changes by Graf Zahl) +- Added Blzut3's Solaris patch. - Fixed: Heretic's Weredragon (Beast) should not have a melee state. December 31, 2009 (Changes by Graf Zahl) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3184bc6b7e..a2a5566297 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -774,6 +774,11 @@ add_executable( zdoom WIN32 set_source_files_properties( xlat/parse_xlat.cpp PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/xlat_parser.c" ) set_source_files_properties( sc_man.cpp PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/sc_man_scanner.h" ) +if(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") + # [BL] Solaris requires these to be explicitly linked. + set( ZDOOM_LIBS ${ZDOOM_LIBS} nsl socket) +endif(${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") + target_link_libraries( zdoom ${ZDOOM_LIBS} gme gdtoa dumb lzma ) include_directories( . g_doom diff --git a/src/i_net.cpp b/src/i_net.cpp index 739da291e5..3ff86f7ece 100644 --- a/src/i_net.cpp +++ b/src/i_net.cpp @@ -46,6 +46,9 @@ # include # include # include +# ifdef __sun +# include +# endif #endif #include "doomtype.h" @@ -422,7 +425,11 @@ void StartNetwork (bool autoPort) // create communication socket mysocket = UDPsocket (); BindToLocalPort (mysocket, autoPort ? 0 : DOOMPORT); +#ifndef __sun ioctlsocket (mysocket, FIONBIO, &trueval); +#else + fcntl(mysocket, F_SETFL, trueval | O_NONBLOCK); +#endif } void SendAbort (void) diff --git a/src/m_alloc.cpp b/src/m_alloc.cpp index 569b5c94dc..e81a5ce313 100644 --- a/src/m_alloc.cpp +++ b/src/m_alloc.cpp @@ -52,11 +52,14 @@ #endif #if defined(__APPLE__) #define _msize(p) malloc_size(p) +#elif defined(__sun) +#define _msize(p) (*((size_t*)(p)-1)) #elif !defined(_WIN32) #define _msize(p) malloc_usable_size(p) // from glibc/FreeBSD #endif #ifndef _DEBUG +#if !defined(__sun) void *M_Malloc(size_t size) { void *block = malloc(size); @@ -83,10 +86,50 @@ void *M_Realloc(void *memblock, size_t size) return block; } #else +void *M_Malloc(size_t size) +{ + void *block = malloc(size+sizeof(size_t)); + + if (block == NULL) + I_FatalError("Could not malloc %zu bytes", size); + + size_t *sizeStore = (size_t *) block; + *sizeStore = size; + block = sizeStore+1; + + GC::AllocBytes += _msize(block); + return block; +} + +void *M_Realloc(void *memblock, size_t size) +{ + if(memblock == NULL) + return M_Malloc(size); + + if (memblock != NULL) + { + GC::AllocBytes -= _msize(memblock); + } + void *block = realloc(((size_t*) memblock)-1, size+sizeof(size_t)); + if (block == NULL) + { + I_FatalError("Could not realloc %zu bytes", size); + } + + size_t *sizeStore = (size_t *) block; + *sizeStore = size; + block = sizeStore+1; + + GC::AllocBytes += _msize(block); + return block; +} +#endif +#else #ifdef _MSC_VER #include #endif +#if !defined(__sun) void *M_Malloc_Dbg(size_t size, const char *file, int lineno) { void *block = _malloc_dbg(size, _NORMAL_BLOCK, file, lineno); @@ -112,8 +155,49 @@ void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno) GC::AllocBytes += _msize(block); return block; } +#else +void *M_Malloc_Dbg(size_t size, const char *file, int lineno) +{ + void *block = _malloc_dbg(size+sizeof(size_t), _NORMAL_BLOCK, file, lineno); + + if (block == NULL) + I_FatalError("Could not malloc %zu bytes", size); + + size_t *sizeStore = (size_t *) block; + *sizeStore = size; + block = sizeStore+1; + + GC::AllocBytes += _msize(block); + return block; +} + +void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno) +{ + if(memblock == NULL) + return M_Malloc_Dbg(size, file, lineno); + + if (memblock != NULL) + { + GC::AllocBytes -= _msize(memblock); + } + void *block = _realloc_dbg(((size_t*) memblock)-1, size+sizeof(size_t), _NORMAL_BLOCK, file, lineno); + + if (block == NULL) + { + I_FatalError("Could not realloc %zu bytes", size); + } + + size_t *sizeStore = (size_t *) block; + *sizeStore = size; + block = sizeStore+1; + + GC::AllocBytes += _msize(block); + return block; +} +#endif #endif +#if !defined(__sun) void M_Free (void *block) { if (block != NULL) @@ -122,3 +206,14 @@ void M_Free (void *block) free(block); } } +#else +void M_Free (void *block) +{ + if(block != NULL) + { + GC::AllocBytes -= _msize(block); + free(((size_t*) block)-1); + } +} +#endif + diff --git a/src/p_switch.cpp b/src/p_switch.cpp index 9865b65c1a..f3b642b058 100644 --- a/src/p_switch.cpp +++ b/src/p_switch.cpp @@ -274,11 +274,11 @@ void P_ProcessSwitchDef (FScanner &sc) { if (def2 != NULL) { - free (def2); + M_Free (def2); } if (def1 != NULL) { - free (def1); + M_Free (def1); } return; } diff --git a/src/resourcefiles/file_directory.cpp b/src/resourcefiles/file_directory.cpp index cb250ed1e8..89fb2be9cd 100644 --- a/src/resourcefiles/file_directory.cpp +++ b/src/resourcefiles/file_directory.cpp @@ -41,8 +41,10 @@ #define stat _stat #else #include +#ifndef __sun #include #endif +#endif #include #include #include @@ -197,6 +199,46 @@ int FDirectory::AddDirectory(const char *dirpath) return count; } +#elif defined(__sun) + +int FDirectory::AddDirectory(const char *dirpath) +{ + int count = 0; + TArray scanDirectories; + scanDirectories.Push(dirpath); + for(unsigned int i = 0;i < scanDirectories.Size();i++) + { + DIR* directory = opendir(scanDirectories[i].GetChars()); + if (directory == NULL) + { + Printf("Could not ready directory: %s\n", strerror(errno)); + return NULL; + } + + struct dirent *file; + while((file = readdir(directory)) != NULL) + { + if(file->d_name[0] == '.') //File is hidden or ./.. directory so ignore it. + continue; + + FString fullFileName = scanDirectories[i] + file->d_name; + + struct stat fileStat; + stat(fullFileName.GetChars(), &fileStat); + + if(S_ISDIR(fileStat.st_mode)) + { + scanDirectories.Push(scanDirectories[i] + file->d_name + "/"); + continue; + } + AddEntry(scanDirectories[i] + file->d_name, fileStat.st_size); + count++; + } + closedir(directory); + } + return count; +} + #else //========================================================================== @@ -294,6 +336,7 @@ FileReader *FDirectoryLump::NewReader() { FString fullpath = Owner->Filename; fullpath += FullName; + printf("%s\n", fullpath.GetChars()); return new FileReader(fullpath); } catch (CRecoverableError &) diff --git a/src/sdl/crashcatcher.c b/src/sdl/crashcatcher.c index 3a4c5a0ce4..7dc928407e 100644 --- a/src/sdl/crashcatcher.c +++ b/src/sdl/crashcatcher.c @@ -8,6 +8,12 @@ #include #include +// Solaris doesn't have SA_ONESHOT +// According to the Linux header this is the same. +#ifndef SA_ONESHOT +#define SA_ONESHOT SA_RESETHAND +#endif + static const char *cc_logfile = NULL; static char respfile[256]; diff --git a/src/sound/fmodsound.cpp b/src/sound/fmodsound.cpp index e278563a62..f8f01f2a96 100644 --- a/src/sound/fmodsound.cpp +++ b/src/sound/fmodsound.cpp @@ -46,6 +46,8 @@ extern HWND Window; #endif #ifdef __APPLE__ #include +#elif __sun +#include #else #include #endif diff --git a/src/sound/music_dumb.cpp b/src/sound/music_dumb.cpp index 3b6f29c5c3..1013689343 100644 --- a/src/sound/music_dumb.cpp +++ b/src/sound/music_dumb.cpp @@ -73,7 +73,7 @@ protected: static bool read(SoundStream *stream, void *buff, int len, void *userdata); }; -#pragma pack(push, 1) +#pragma pack(1) typedef struct tagITFILEHEADER { @@ -108,7 +108,7 @@ typedef struct MODMIDICFG char szMidiZXXExt[128*32]; // changed from CHAR } MODMIDICFG, *LPMODMIDICFG; -#pragma pack(pop) +#pragma pack() // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- diff --git a/src/w_zip.h b/src/w_zip.h index 299e755893..40a8a4b1db 100644 --- a/src/w_zip.h +++ b/src/w_zip.h @@ -1,7 +1,7 @@ #ifndef __W_ZIP #define __W_ZIP -#pragma pack(push, 1) +#pragma pack(1) // FZipCentralInfo struct FZipEndOfCentralDirectory { @@ -56,7 +56,7 @@ struct FZipLocalFileHeader }; -#pragma pack(pop) +#pragma pack() #define ZIP_LOCALFILE MAKE_ID('P','K',3,4) #define ZIP_CENTRALFILE MAKE_ID('P','K',1,2)