Changeset - r13188:946b6b8895b9
[Not reviewed]
master
0 2 0
michi_cc - 15 years ago 2009-10-04 21:08:25
michi_cc@openttd.org
(svn r17705) -Fix: [OSX] Re-enable signal handling on OSX 10.3.9. Trying to link with an undefined symbols that lives in the system library seems to confuse the loader on 10.3.9. Use a different function to circumvent it.
2 files changed with 12 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/os/macosx/macos.h
Show inline comments
 
@@ -54,35 +54,25 @@ void ShowMacErrorDialog(const char *erro
 
		(__builtin_expect(!(e), 0) ? ShowMacAssertDialog ( __func__, __FILE__, __LINE__, #e ): (void)0 )
 
#endif
 

	
 
void GetMacOSVersion(int *return_major, int *return_minor, int *return_bugfix);
 

	
 
/**
 
 * Check if we are at least running on the specified version of Mac OS.
 
 * @param major major version of the os. This would be 10 in the case of 10.4.11.
 
 * @param minor minor version of the os. This would be 4 in the case of 10.4.11.
 
 * @param bugfix bugfix version of the os. This would be 11 in the case of 10.4.11.
 
 * @return true if the running os is at least what we asked, false otherwise.
 
 */
 
static inline bool MacOSVersionIsAtLeast(long major, long minor, long bugfix)
 
{
 
	int version_major, version_minor, version_bugfix;
 
	GetMacOSVersion(&version_major, &version_minor, &version_bugfix);
 

	
 
	if (version_major < major) return false;
 
	if (version_major == major && version_minor < minor) return false;
 
	if (version_major == major && version_minor == minor && version_bugfix < bugfix) return false;
 

	
 
	return true;
 
}
 

	
 
/*
 
 * OSX 10.3.9 has blessed us with a signal with unlikable side effects.
 
 * The most problematic side effect is that it makes OpenTTD 'think' that
 
 * it's running on 10.4.0 or higher and thus tries to link to functions
 
 * that are only defined there. So now we'll remove all and any signal
 
 * handling for OSX < 10.4 and 10.3.9 works as it should at the cost of
 
 * not giving a useful error when savegame loading goes wrong.
 
 */
 
#define signal(sig, func) (MacOSVersionIsAtLeast(10, 4, 0) ? signal(sig, func) : NULL)
 

	
 
#endif /* MACOS_H */
src/os/unix/unix.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file unix.cpp Implementation of Unix specific file handling. */
 

	
 
#include "../../stdafx.h"
 
#include "../../textbuf_gui.h"
 
#include "../../functions.h"
 
#include "../../crashlog.h"
 

	
 

	
 
#include <dirent.h>
 
#include <unistd.h>
 
#include <sys/stat.h>
 
#include <time.h>
 
#include <signal.h>
 

	
 
#if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__)
 
#ifdef __APPLE__
 
	#include <sys/mount.h>
 
#elif (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) || defined(__GLIBC__)
 
	#define HAS_STATVFS
 
#endif
 

	
 
#ifdef HAS_STATVFS
 
#include <sys/statvfs.h>
 
#endif
 

	
 

	
 
#ifdef __MORPHOS__
 
#include <exec/types.h>
 
ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;)
 

	
 
/* The system supplied definition of SIG_IGN does not match */
 
#undef SIG_IGN
 
#define SIG_IGN (void (*)(int))1
 
#endif /* __MORPHOS__ */
 

	
 
#ifdef __AMIGA__
 
#warning add stack symbol to avoid that user needs to set stack manually (tokai)
 
// ULONG __stack =
 
#endif
 

	
 
#if defined(__APPLE__)
 
	#if defined(WITH_SDL)
 
@@ -50,59 +52,58 @@ ULONG __stack = (1024*1024)*2; // maybe 
 
		#include <SDL.h>
 
	#endif
 
#endif
 

	
 
bool FiosIsRoot(const char *path)
 
{
 
#if !defined(__MORPHOS__) && !defined(__AMIGAOS__)
 
	return path[1] == '\0';
 
#else
 
	/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
 
	const char *s = strchr(path, ':');
 
	return s != NULL && s[1] == '\0';
 
#endif
 
}
 

	
 
void FiosGetDrives()
 
{
 
	return;
 
}
 

	
 
bool FiosGetDiskFreeSpace(const char *path, uint64 *tot)
 
{
 
	uint64 free = 0;
 

	
 
#ifdef HAS_STATVFS
 
# ifdef __APPLE__
 
	/* OSX 10.3 lacks statvfs so don't try to use it even though later versions of OSX has it. */
 
	if (MacOSVersionIsAtLeast(10, 4, 0))
 
# endif
 
	{
 
		struct statvfs s;
 
#ifdef __APPLE__
 
	struct statfs s;
 

	
 
		if (statvfs(path, &s) != 0) return false;
 
		free = (uint64)s.f_frsize * s.f_bavail;
 
	}
 
	if (statfs(path, &s) != 0) return false;
 
	free = (uint64)s.f_bsize * s.f_bavail;
 
#elif defined(HAS_STATVFS)
 
	struct statvfs s;
 

	
 
	if (statvfs(path, &s) != 0) return false;
 
	free = (uint64)s.f_frsize * s.f_bavail;
 
#endif
 
	if (tot != NULL) *tot = free;
 
	return true;
 
}
 

	
 
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
 
{
 
	char filename[MAX_PATH];
 

	
 
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
 
	/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
 
	if (FiosIsRoot(path)) {
 
		snprintf(filename, lengthof(filename), "%s:%s", path, ent->d_name);
 
	} else // XXX - only next line!
 
#else
 
	assert(path[strlen(path) - 1] == PATHSEPCHAR);
 
	if (strlen(path) > 2) assert(path[strlen(path) - 2] != PATHSEPCHAR);
 
#endif
 
	snprintf(filename, lengthof(filename), "%s%s", path, ent->d_name);
 

	
 
	return stat(filename, sb) == 0;
 
}
 

	
 
bool FiosIsHiddenFile(const struct dirent *ent)
0 comments (0 inline, 0 general)