/* Minetest Copyright (C) 2010 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* Random portability stuff See comments in porting.h */ #if defined(linux) #include #elif defined(__APPLE__) #include #include #elif defined(__FreeBSD__) #include #include #include #endif #include "porting.h" #include "config.h" #include "debug.h" #include "filesys.h" #include "log.h" #include "util/string.h" #include #ifdef __APPLE__ #include "CoreFoundation/CoreFoundation.h" #endif namespace porting { /* Signal handler (grabs Ctrl-C on POSIX systems) */ bool g_killed = false; bool * signal_handler_killstatus(void) { return &g_killed; } #if !defined(_WIN32) // POSIX #include void sigint_handler(int sig) { if(g_killed == false) { dstream< BOOL WINAPI event_handler(DWORD sig) { switch(sig) { case CTRL_C_EVENT: case CTRL_CLOSE_EVENT: case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: if(g_killed == false) { dstream<=0; i--) { if(path[i] == delim) break; } path[i] = 0; } bool detectMSVCBuildDir(char *c_path) { std::string path(c_path); const char *ends[] = {"bin\\Release", "bin\\Build", NULL}; return (removeStringEnd(path, ends) != ""); } void initializePaths() { #if RUN_IN_PLACE /* Use relative paths if RUN_IN_PLACE */ infostream<<"Using relative paths (RUN_IN_PLACE)"<" len = GetEnvironmentVariable("APPDATA", buf, buflen); assert(len < buflen); path_user = std::string(buf) + DIR_DELIM + PROJECT_NAME; /* Linux */ #elif defined(linux) // Get path to executable std::string bindir = ""; { char buf[BUFSIZ]; memset(buf, 0, BUFSIZ); assert(readlink("/proc/self/exe", buf, BUFSIZ-1) != -1); pathRemoveFile(buf, '/'); bindir = buf; } // Find share directory from these. // It is identified by containing the subdirectory "builtin". std::list trylist; std::string static_sharedir = STATIC_SHAREDIR; if(static_sharedir != "" && static_sharedir != ".") trylist.push_back(static_sharedir); trylist.push_back(bindir + "/../share/" + PROJECT_NAME); trylist.push_back(bindir + "/.."); for(std::list::const_iterator i = trylist.begin(); i != trylist.end(); i++) { const std::string &trypath = *i; if(!fs::PathExists(trypath) || !fs::PathExists(trypath + "/builtin")){ dstream<<"WARNING: system-wide share not found at \"" <