Fixed small error in mapnode.cpp (didn't cause any harm though)
[oweals/minetest.git] / src / porting.cpp
index 50605587dc1950c5315811d5320cb6480225fa37..7de042ab571143eb1e69b8d6fd958c60c094cd83 100644 (file)
@@ -25,6 +25,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "porting.h"
 #include "config.h"
+#include "debug.h"
+
+#ifdef __APPLE__
+       #include "CoreFoundation/CoreFoundation.h"
+#endif
 
 namespace porting
 {
@@ -47,8 +52,13 @@ void sigint_handler(int sig)
 {
        if(g_killed == false)
        {
-               dstream<<DTIME<<"sigint_handler(): "
+               dstream<<DTIME<<"INFO: sigint_handler(): "
                                <<"Ctrl-C pressed, shutting down."<<std::endl;
+               
+               dstream<<DTIME<<"INFO: sigint_handler(): "
+                               <<"Printing debug stacks"<<std::endl;
+               debug_stacks_print();
+
                g_killed = true;
        }
        else
@@ -130,7 +140,7 @@ void initializePaths()
        char buf[BUFSIZ];
        memset(buf, 0, BUFSIZ);
        // Get path to executable
-       readlink("/proc/self/exe", buf, BUFSIZ-1);
+       assert(readlink("/proc/self/exe", buf, BUFSIZ-1) != -1);
        
        pathRemoveFile(buf, '/');
 
@@ -194,7 +204,7 @@ void initializePaths()
        char buf[BUFSIZ];
        memset(buf, 0, BUFSIZ);
        // Get path to executable
-       readlink("/proc/self/exe", buf, BUFSIZ-1);
+       assert(readlink("/proc/self/exe", buf, BUFSIZ-1) != -1);
        
        pathRemoveFile(buf, '/');
 
@@ -209,9 +219,26 @@ void initializePaths()
        #elif defined(__APPLE__)
                #include <unistd.h>
 
+    // Code based on
+    // http://stackoverflow.com/questions/516200/relative-paths-not-working-in-xcode-c
+    CFBundleRef main_bundle = CFBundleGetMainBundle();
+    CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL(main_bundle);
+    char path[PATH_MAX];
+    if(CFURLGetFileSystemRepresentation(resources_url, TRUE, (UInt8 *)path, PATH_MAX))
+       {
+               dstream<<"Bundle resource path: "<<path<<std::endl;
+               //chdir(path);
+               path_data = std::string(path) + "/data";
+       }
+       else
+    {
+        // error!
+               dstream<<"WARNING: Could not determine bundle resource path"<<std::endl;
+    }
+    CFRelease(resources_url);
+       
        path_userdata = std::string(getenv("HOME")) + "/Library/Application Support/" + APPNAME;
-       path_data = std::string("minetest-mac.app/Contents/Resources/data/");
-
+    
        #endif
 
 #endif // RUN_IN_PLACE