@@ -43,13 +43,20 @@ typedef char TCHAR;
43
43
#ifndef F_OK
44
44
#define F_OK 4
45
45
#endif
46
+ #ifdef _MSC_VER
47
+ #ifndef PATH_MAX
48
+ #define PATH_MAX MAX_PATH
49
+ #endif
50
+ #endif
46
51
47
52
#else // unix
48
53
49
54
#if defined( __APPLE__ )
50
55
// I'm not sure how we would handle this in raw Darwin
51
56
// without the AvailablilityMacros.
52
57
#include < AvailabilityMacros.h>
58
+ #include < libgen.h>
59
+ #include < mach-o/dyld.h>
53
60
54
61
// >OSG_IOS
55
62
// IOS includes
@@ -116,6 +123,7 @@ typedef char TCHAR;
116
123
#include < osgDB/Registry>
117
124
118
125
#include < errno.h>
126
+ #include < limits.h>
119
127
#include < string.h>
120
128
121
129
#include < stack>
@@ -526,6 +534,59 @@ std::string osgDB::findFileInDirectory(const std::string& fileName,const std::st
526
534
return " " ;
527
535
}
528
536
537
+ /* This function has be taken from the VSG project */
538
+ std::string osgDB::executableFilePath ()
539
+ {
540
+ std::string path;
541
+
542
+ #if defined(WIN32)
543
+ TCHAR buf[PATH_MAX + 1 ];
544
+ DWORD result = GetModuleFileName (NULL , buf, static_cast <DWORD>(std::size (buf) - 1 ));
545
+ if (result && result < std::size (buf))
546
+ path = buf;
547
+ #elif defined(__linux__)
548
+
549
+ std::vector<char > buffer (1024 );
550
+ ssize_t len = 0 ;
551
+ while ((len = ::readlink (" /proc/self/exe" , buffer.data (), buffer.size ())) == static_cast <ssize_t >(buffer.size ()))
552
+ {
553
+ buffer.resize (buffer.size () * 2 );
554
+ }
555
+
556
+ // add terminator to string.
557
+ buffer[len] = ' \0 ' ;
558
+
559
+ return buffer.data ();
560
+
561
+ #elif defined(__APPLE__)
562
+ # if TARGET_OS_MAC
563
+ char realPathName[PATH_MAX + 1 ];
564
+ char buf[PATH_MAX + 1 ];
565
+ uint32_t size = (uint32_t )sizeof (buf);
566
+
567
+ if (!_NSGetExecutablePath (buf, &size))
568
+ {
569
+ realpath (buf, realPathName);
570
+ path = realPathName;
571
+ }
572
+ # elif TARGET_IPHONE_SIMULATOR
573
+ // iOS, tvOS, or watchOS Simulator
574
+ // Not currently implemented
575
+ # elif TARGET_OS_MACCATALYST
576
+ // Mac's Catalyst (ports iOS API into Mac, like UIKit).
577
+ // Not currently implemented
578
+ # elif TARGET_OS_IPHONE
579
+ // iOS, tvOS, or watchOS device
580
+ // Not currently implemented
581
+ # else
582
+ # error "Unknown Apple platform"
583
+ # endif
584
+ #elif defined(__ANDROID__)
585
+ // Not currently implemented
586
+ #endif
587
+ return path;
588
+ }
589
+
529
590
static void appendInstallationLibraryFilePaths (osgDB::FilePathList& filepath)
530
591
{
531
592
#ifdef OSG_DEFAULT_LIBRARY_PATH
0 commit comments