From 107b0a4952bfcbfbb873218bc2eb60e6a97dea9d Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 24 Apr 2009 08:29:02 +0000 Subject: [PATCH] Improved POSIX compatibility (OpenBSD, NetBSD support) git-svn-id: svn://ultimatepp.org/upp/trunk@1095 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/App.cpp | 2 +- uppsrc/Core/Core.upp | 2 +- uppsrc/Core/Cpu.cpp | 14 +++++++++++--- uppsrc/Core/Debug.cpp | 2 +- uppsrc/Core/LocalProcess.cpp | 2 +- uppsrc/Core/Mt.cpp | 2 +- uppsrc/Core/Stream.cpp | 2 +- uppsrc/Core/Util.cpp | 2 +- uppsrc/Core/config.h | 22 ++++++++++++++++++---- uppsrc/CtrlLib/CtrlLib.upp | 6 +----- uppsrc/CtrlLib/init | 2 +- uppsrc/Draw/Draw.upp | 6 +++--- uppsrc/Web/sproc.cpp | 2 +- uppsrc/coff/util.h | 2 +- uppsrc/ide/Core/Host.cpp | 29 ++++++++++++++++++++++++++--- uppsrc/ide/Methods.cpp | 2 +- 16 files changed, 70 insertions(+), 29 deletions(-) diff --git a/uppsrc/Core/App.cpp b/uppsrc/Core/App.cpp index a37ce3c5d..cc6277b5b 100644 --- a/uppsrc/Core/App.cpp +++ b/uppsrc/Core/App.cpp @@ -39,7 +39,7 @@ const char *procexepath_() { static char h[_MAX_PATH + 1]; ONCELOCK { char link[100]; -#ifdef PLATFORM_FREEBSD +#ifdef PLATFORM_BSD sprintf(link, "/proc/%d/file", getpid()); #else sprintf(link, "/proc/%d/exe", getpid()); diff --git a/uppsrc/Core/Core.upp b/uppsrc/Core/Core.upp index ddfdfff01..f7c342ebb 100644 --- a/uppsrc/Core/Core.upp +++ b/uppsrc/Core/Core.upp @@ -11,7 +11,7 @@ library(WIN32 !GUI !GNU !GCC) "ole32 oleaut32 oldnames"; library(LINUX) "pthread dl"; -library(FREEBSD) pthread; +library(BSD) pthread; library(WIN32 !MSC8ARM) "advapi32 shell32 winmm mpr"; diff --git a/uppsrc/Core/Cpu.cpp b/uppsrc/Core/Cpu.cpp index 3cd9888ae..97d52df03 100644 --- a/uppsrc/Core/Cpu.cpp +++ b/uppsrc/Core/Cpu.cpp @@ -57,8 +57,9 @@ bool CpuSSE2() { sCheckCPU(); return sHasSSE2; } bool CpuSSE3() { sCheckCPU(); return sHasSSE3; } #ifdef PLATFORM_POSIX -#ifdef PLATFORM_FREEBSD -#include +#ifdef PLATFORM_BSD +#include +#include #else #include #endif @@ -81,7 +82,14 @@ int CPU_Cores() n += !!(sa & (1 << i)); #endif #elif defined(PLATFORM_POSIX) -#if defined(PLATFORM_FREEBSD) || defined(PLATFORM_SOLARIS) +#ifdef PLATFORM_BSD + int mib[2]; + size_t len = sizeof(n); + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + sysctl(mib, 2, &n, &len, NULL, 0); + n = minmax(n, 1, 256); +#elif defined(PLATFORM_SOLARIS) n = minmax((int)sysconf(_SC_NPROCESSORS_ONLN), 1, 256); #else n = minmax(get_nprocs(), 1, 256); diff --git a/uppsrc/Core/Debug.cpp b/uppsrc/Core/Debug.cpp index ca1966bdb..be6a0a878 100644 --- a/uppsrc/Core/Debug.cpp +++ b/uppsrc/Core/Debug.cpp @@ -46,7 +46,7 @@ static void sLogFile(char *fn, const char *app = ".log") const char *q = strrchr(exe, '/'); if(q) exe = q + 1; - if(!exe) + if(!*exe) exe = "upp"; strcat(path, exe); mkdir(path, 0755); diff --git a/uppsrc/Core/LocalProcess.cpp b/uppsrc/Core/LocalProcess.cpp index 82b0443f1..5b6bd7579 100644 --- a/uppsrc/Core/LocalProcess.cpp +++ b/uppsrc/Core/LocalProcess.cpp @@ -229,7 +229,7 @@ SIGDEF(SIGFPE) SIGDEF(SIGKILL) SIGDEF(SIGSEGV) SIGDEF(SIGPIPE) SIGDEF(SIGALRM) SIGDEF(SIGPIPE) SIGDEF(SIGTERM) SIGDEF(SIGUSR1) SIGDEF(SIGUSR2) SIGDEF(SIGTRAP) SIGDEF(SIGURG) SIGDEF(SIGVTALRM) SIGDEF(SIGXCPU) SIGDEF(SIGXFSZ) SIGDEF(SIGIOT) SIGDEF(SIGIO) SIGDEF(SIGWINCH) -#ifndef PLATFORM_FREEBSD +#ifndef PLATFORM_BSD //SIGDEF(SIGCLD) SIGDEF(SIGPWR) #endif //SIGDEF(SIGSTKFLT) SIGDEF(SIGUNUSED) // not in Solaris, make conditional if needed diff --git a/uppsrc/Core/Mt.cpp b/uppsrc/Core/Mt.cpp index a4aceb717..9a00192a9 100644 --- a/uppsrc/Core/Mt.cpp +++ b/uppsrc/Core/Mt.cpp @@ -179,7 +179,7 @@ void Thread::Sleep(int msec) ::Sleep(msec); #endif #ifdef PLATFORM_POSIX - timespec tval; + ::timespec tval; tval.tv_sec = msec / 1000; tval.tv_nsec = (msec % 1000) * 1000000; nanosleep(&tval, NULL); diff --git a/uppsrc/Core/Stream.cpp b/uppsrc/Core/Stream.cpp index 591554647..307eef7c1 100644 --- a/uppsrc/Core/Stream.cpp +++ b/uppsrc/Core/Stream.cpp @@ -1331,7 +1331,7 @@ bool FileMapping::Map(int64 mapoffset, dword maplen) (dword)(rawoffset >> 32), (dword)(rawoffset >> 0), rawsize); #else rawbase = (byte *)mmap(0, rawsize, PROT_READ | PROT_WRITE, -#ifdef PLATFORM_FREEBSD +#ifdef PLATFORM_BSD MAP_NOSYNC, #else MAP_SHARED, diff --git a/uppsrc/Core/Util.cpp b/uppsrc/Core/Util.cpp index d9943eca1..628b85e84 100644 --- a/uppsrc/Core/Util.cpp +++ b/uppsrc/Core/Util.cpp @@ -164,7 +164,7 @@ char *PermanentCopy(const char *s) #ifndef PLATFORM_WIN32 void Sleep(int msec) { - timespec tval; + ::timespec tval; tval.tv_sec = msec / 1000; tval.tv_nsec = (msec % 1000) * 1000000; nanosleep(&tval, NULL); diff --git a/uppsrc/Core/config.h b/uppsrc/Core/config.h index 1ec4a4d9e..7295fc926 100644 --- a/uppsrc/Core/config.h +++ b/uppsrc/Core/config.h @@ -7,7 +7,7 @@ #define PLATFORM_WIN32 #endif - #if __unix + #if __unix || __unix__ #define PLATFORM_POSIX 1 #ifdef flagGUI @@ -16,9 +16,23 @@ #if __linux #define PLATFORM_LINUX 1 - #else // ToDo - #define PLATFORM_BSD 1 - #define PLATFORM_FREEBSD 1 + #else + #if __FreeBSD__ || __OpenBSD__ || __NetBSD__ + #define PLATFORM_BSD 1 + #if __FreeBSD__ + #define PLATFORM_BSD 1 + #endif + #if __OpenBSD__ + #define PLATFORM_OPENBSD 1 + #endif + #if __NetBSD__ + #define PLATFORM_NETBSD 1 + #endif + #elif __sun + #define PLATFORM_SOLARIS 1 + #else + #error Unknown OS + #endif #endif #endif diff --git a/uppsrc/CtrlLib/CtrlLib.upp b/uppsrc/CtrlLib/CtrlLib.upp index d520b30d9..7aebdbd84 100644 --- a/uppsrc/CtrlLib/CtrlLib.upp +++ b/uppsrc/CtrlLib/CtrlLib.upp @@ -7,11 +7,7 @@ uses CtrlCore, RichText; -uses(LINUX) PdfDraw; - -uses(FREEBSD) PdfDraw; - -uses(OSX11) PdfDraw; +uses(POSIX) PdfDraw; file CtrlLib.h, diff --git a/uppsrc/CtrlLib/init b/uppsrc/CtrlLib/init index ab918cc00..3c1c3859f 100644 --- a/uppsrc/CtrlLib/init +++ b/uppsrc/CtrlLib/init @@ -3,7 +3,7 @@ #include "CtrlCore/init" #include "RichText/init" #include "PdfDraw/init" -#define BLITZ_INDEX__ FC405953C5744B97C1D3FC16A15582A05 +#define BLITZ_INDEX__ F8AE2F5C10EDF2AF9715E3BDBF11A5948 #include "CtrlLib.icpp" #undef BLITZ_INDEX__ #endif diff --git a/uppsrc/Draw/Draw.upp b/uppsrc/Draw/Draw.upp index 8058dcda5..b928cb7aa 100644 --- a/uppsrc/Draw/Draw.upp +++ b/uppsrc/Draw/Draw.upp @@ -6,7 +6,7 @@ acceptflags uses Core; -library((LINUX | FREEBSD) & !NOGTK) "gtk-x11-2.0 gdk-x11-2.0 atk-1.0 gdk_pixbuf-2.0 m pangocairo-1.0 fontconfig Xext Xrender Xinerama Xi Xrandr Xcursor Xfixes pango-1.0 cairo X11 gobject-2.0 gmodule-2.0 glib-2.0"; +library((LINUX | BSD) & !NOGTK) "gtk-x11-2.0 gdk-x11-2.0 atk-1.0 gdk_pixbuf-2.0 m pangocairo-1.0 fontconfig Xext Xrender Xinerama Xi Xrandr Xcursor Xfixes pango-1.0 cairo X11 gobject-2.0 gmodule-2.0 glib-2.0"; library(WIN32 !MSC8ARM) "user32 gdi32"; @@ -16,9 +16,9 @@ library(LINUX) dl; library(LINUX !XLFD) Xft; -library(FREEBSD) X11; +library(BSD) X11; -library(FREEBSD !XLFD) "Xft fontconfig Xrender freetype expat"; +library(BSD !XLFD) "Xft fontconfig Xrender freetype expat"; library(LINUX !XLFD !SHARED) "fontconfig Xrender freetype expat"; diff --git a/uppsrc/Web/sproc.cpp b/uppsrc/Web/sproc.cpp index aa97aecaa..2f74914c5 100644 --- a/uppsrc/Web/sproc.cpp +++ b/uppsrc/Web/sproc.cpp @@ -292,7 +292,7 @@ SIGDEF(SIGFPE) SIGDEF(SIGKILL) SIGDEF(SIGSEGV) SIGDEF(SIGPIPE) SIGDEF(SIGALRM) SIGDEF(SIGPIPE) SIGDEF(SIGTERM) SIGDEF(SIGUSR1) SIGDEF(SIGUSR2) SIGDEF(SIGTRAP) SIGDEF(SIGURG) SIGDEF(SIGVTALRM) SIGDEF(SIGXCPU) SIGDEF(SIGXFSZ) SIGDEF(SIGIOT) SIGDEF(SIGIO) SIGDEF(SIGWINCH) -#ifndef PLATFORM_FREEBSD +#ifndef PLATFORM_BSD //SIGDEF(SIGCLD) SIGDEF(SIGPWR) #endif //SIGDEF(SIGSTKFLT) SIGDEF(SIGUNUSED) // not in Solaris, make conditional if needed diff --git a/uppsrc/coff/util.h b/uppsrc/coff/util.h index b604789a7..cc5d5c89c 100644 --- a/uppsrc/coff/util.h +++ b/uppsrc/coff/util.h @@ -7,7 +7,7 @@ #undef __offsetof #endif -#ifdef PLATFORM_FREEBSD +#ifdef PLATFORM_BSD #include #include #endif diff --git a/uppsrc/ide/Core/Host.cpp b/uppsrc/ide/Core/Host.cpp index f8be0dfea..78791411b 100644 --- a/uppsrc/ide/Core/Host.cpp +++ b/uppsrc/ide/Core/Host.cpp @@ -289,13 +289,36 @@ void LocalHost::AddFlags(Index& cfg) #if defined(PLATFORM_WIN32) cfg.Add("WIN32"); #endif + #ifdef PLATFORM_LINUX cfg.Add("LINUX"); -#elif defined(PLATFORM_FREEBSD) +#endif + +#ifdef PLATFORM_POSIX + cfg.Add("POSIX"); +#endif + +#ifdef PLATFORM_BSD + cfg.Add("BSD"); +#endif + +#ifdef PLATFORM_BSD cfg.Add("FREEBSD"); -#elif defined(PLATFORM_SOLARIS) +#endif + +#ifdef PLATFORM_OPENBSD + cfg.Add("OPENBSD"); +#endif + +#ifdef PLATFORM_NETBSD + cfg.Add("NETBSD"); +#endif + +#ifdef PLATFORM_SOLARIS cfg.Add("SOLARIS"); -#elif defined(PLATFORM_OSX11) +#endif + +#ifdef PLATFORM_OSX11 cfg.Add("OSX11"); #endif } diff --git a/uppsrc/ide/Methods.cpp b/uppsrc/ide/Methods.cpp index ac52726d3..edbc16893 100644 --- a/uppsrc/ide/Methods.cpp +++ b/uppsrc/ide/Methods.cpp @@ -204,7 +204,7 @@ BuildMethods::BuildMethods() remote_os.Add("WINCE"); remote_os.Add("UNIX"); remote_os.Add("SOLARIS"); - remote_os.Add("FREEBSD"); + remote_os.Add("BSD"); method.AddCtrl("REMOTE_TRANSFER", remote_file_access); remote_file_access.Add("0", "direct (SAMBA)"); remote_file_access.Add("1", "indirect (transfer)");