Merge branch 'origin/master' commit 'a499e9acdd385b57dd43caf88af3a6f7f53716ba'
This commit is contained in:
+27
-106
@@ -1,5 +1,3 @@
|
||||
/* $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.
|
||||
@@ -17,6 +15,7 @@
|
||||
#include "../../debug.h"
|
||||
#include "../../string_func.h"
|
||||
#include "../../fios.h"
|
||||
#include "../../thread.h"
|
||||
|
||||
|
||||
#include <dirent.h>
|
||||
@@ -43,26 +42,17 @@
|
||||
#include <sys/sysctl.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 =
|
||||
#ifndef NO_THREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#if defined(WITH_SDL)
|
||||
# if defined(WITH_SDL)
|
||||
/* the mac implementation needs this file included in the same file as main() */
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
# include <SDL.h>
|
||||
# endif
|
||||
|
||||
# include "../macosx/macos.h"
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
@@ -73,13 +63,7 @@ ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;)
|
||||
|
||||
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(FileList &file_list)
|
||||
@@ -102,7 +86,7 @@ bool FiosGetDiskFreeSpace(const char *path, uint64 *tot)
|
||||
if (statvfs(path, &s) != 0) return false;
|
||||
free = (uint64)s.f_frsize * s.f_bavail;
|
||||
#endif
|
||||
if (tot != NULL) *tot = free;
|
||||
if (tot != nullptr) *tot = free;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -110,15 +94,8 @@ bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
int res;
|
||||
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
|
||||
/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
|
||||
if (FiosIsRoot(path)) {
|
||||
res = seprintf(filename, lastof(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
|
||||
res = seprintf(filename, lastof(filename), "%s%s", path, ent->d_name);
|
||||
|
||||
/* Could we fully concatenate the path and filename? */
|
||||
@@ -155,9 +132,9 @@ static const char *GetLocalCode()
|
||||
#else
|
||||
/* Strip locale (eg en_US.UTF-8) to only have UTF-8 */
|
||||
const char *locale = GetCurrentLocale("LC_CTYPE");
|
||||
if (locale != NULL) locale = strchr(locale, '.');
|
||||
if (locale != nullptr) locale = strchr(locale, '.');
|
||||
|
||||
return (locale == NULL) ? "" : locale + 1;
|
||||
return (locale == nullptr) ? "" : locale + 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -183,7 +160,7 @@ static const char *convert_tofrom_fs(iconv_t convd, const char *name)
|
||||
|
||||
strecpy(outbuf, name, outbuf + outlen);
|
||||
|
||||
iconv(convd, NULL, NULL, NULL, NULL);
|
||||
iconv(convd, nullptr, nullptr, nullptr, nullptr);
|
||||
if (iconv(convd, &inbuf, &inlen, &outbuf, &outlen) == (size_t)(-1)) {
|
||||
DEBUG(misc, 0, "[iconv] error converting '%s'. Errno %d", name, errno);
|
||||
}
|
||||
@@ -279,13 +256,13 @@ int CDECL main(int argc, char *argv[])
|
||||
cocoaSetupAutoreleasePool();
|
||||
/* This is passed if we are launched by double-clicking */
|
||||
if (argc >= 2 && strncmp(argv[1], "-psn", 4) == 0) {
|
||||
argv[1] = NULL;
|
||||
argv[1] = nullptr;
|
||||
argc = 1;
|
||||
}
|
||||
#endif
|
||||
CrashLog::InitialiseCrashLog();
|
||||
|
||||
SetRandomSeed(time(NULL));
|
||||
SetRandomSeed(time(nullptr));
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
@@ -306,74 +283,7 @@ bool GetClipboardContents(char *buffer, const char *last)
|
||||
#endif
|
||||
|
||||
|
||||
/* multi os compatible sleep function */
|
||||
|
||||
#ifdef __AMIGA__
|
||||
/* usleep() implementation */
|
||||
# include <devices/timer.h>
|
||||
# include <dos/dos.h>
|
||||
|
||||
extern struct Device *TimerBase = NULL;
|
||||
extern struct MsgPort *TimerPort = NULL;
|
||||
extern struct timerequest *TimerRequest = NULL;
|
||||
#endif /* __AMIGA__ */
|
||||
|
||||
void CSleep(int milliseconds)
|
||||
{
|
||||
#if defined(__BEOS__)
|
||||
snooze(milliseconds * 1000);
|
||||
#elif defined(__AMIGA__)
|
||||
{
|
||||
ULONG signals;
|
||||
ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
|
||||
|
||||
/* send IORequest */
|
||||
TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
|
||||
TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000;
|
||||
TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000;
|
||||
SendIO((struct IORequest *)TimerRequest);
|
||||
|
||||
if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) {
|
||||
AbortIO((struct IORequest *)TimerRequest);
|
||||
}
|
||||
WaitIO((struct IORequest *)TimerRequest);
|
||||
}
|
||||
#else
|
||||
usleep(milliseconds * 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef __APPLE__
|
||||
uint GetCPUCoreCount()
|
||||
{
|
||||
uint count = 1;
|
||||
#ifdef HAS_SYSCTL
|
||||
int ncpu = 0;
|
||||
size_t len = sizeof(ncpu);
|
||||
|
||||
#ifdef OPENBSD
|
||||
int name[2];
|
||||
name[0] = CTL_HW;
|
||||
name[1] = HW_NCPU;
|
||||
if (sysctl(name, 2, &ncpu, &len, NULL, 0) < 0) {
|
||||
ncpu = 0;
|
||||
}
|
||||
#else
|
||||
if (sysctlbyname("hw.availcpu", &ncpu, &len, NULL, 0) < 0) {
|
||||
sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);
|
||||
}
|
||||
#endif /* #ifdef OPENBSD */
|
||||
|
||||
if (ncpu > 0) count = ncpu;
|
||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||
long res = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
if (res > 0) count = res;
|
||||
#endif
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void OSOpenBrowser(const char *url)
|
||||
{
|
||||
pid_t child_pid = fork();
|
||||
@@ -394,10 +304,21 @@ void OSOpenBrowser(const char *url)
|
||||
const char *args[3];
|
||||
args[0] = "xdg-open";
|
||||
args[1] = url;
|
||||
args[2] = NULL;
|
||||
args[2] = nullptr;
|
||||
#endif
|
||||
execvp(args[0], const_cast<char * const *>(args));
|
||||
DEBUG(misc, 0, "Failed to open url: %s", url);
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
void SetCurrentThreadName(const char *threadName) {
|
||||
#if !defined(NO_THREADS) && defined(__GLIBC__)
|
||||
#if __GLIBC_PREREQ(2, 12)
|
||||
if (threadName) pthread_setname_np(pthread_self(), threadName);
|
||||
#endif /* __GLIBC_PREREQ(2, 12) */
|
||||
#endif /* !defined(NO_THREADS) && defined(__GLIBC__) */
|
||||
#if defined(__APPLE__)
|
||||
MacOSSetThreadName(threadName);
|
||||
#endif /* defined(__APPLE__) */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user