Don't truncate checkInputs error string
[supercollider.git] / common / SC_StandAloneInfo_Darwin.cpp
blobc642a60714fbb80a2922f2a32e8386da3586f45b
1 #if defined(__APPLE__) || defined(SC_IPHONE)
3 #include <sys/param.h>
4 #include <stdexcept>
5 #include <cstring> // for strncpy
6 #include <mach-o/dyld.h> // for _NSGetExecutablePath
7 #include <libgen.h>
8 #include <stdlib.h>
10 #include <CoreFoundation/CFString.h>
11 #include <CoreFoundation/CFBundle.h>
12 //#include <CoreServices/CoreServices.h>
14 #include "SC_StandAloneInfo_Darwin.h"
16 bool SC_StandAloneInfo::haveCheckedBundleStatus;
17 char SC_StandAloneInfo::dirPath[PATH_MAX];
19 void SC_StandAloneInfo::SC_StandAloneInfoInit() {
20 char relDir[PATH_MAX];
21 CFStringEncoding encoding = kCFStringEncodingASCII;
22 if(!haveCheckedBundleStatus) {
23 haveCheckedBundleStatus = true;
24 CFURLRef enablerURL = CFBundleCopyResourceURL (
25 CFBundleGetMainBundle(),
26 CFSTR("SCClassLibrary"),
27 NULL,
28 NULL
30 if ( enablerURL ) {
31 // If sclang or SuperCollider binary is run within the .app bundle,
32 // this is how we find the Resources path.
33 CFStringRef rawPath = CFURLCopyFileSystemPath(enablerURL, kCFURLPOSIXPathStyle);
34 rawPath = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/.."), rawPath);
35 CFStringGetCString(rawPath, relDir, PATH_MAX, encoding);
36 } else {
37 // when sclang is run from a symlink, the resource URL above will not be found,
38 // so we need to find the path of the executable.
39 uint32_t bufsize = PATH_MAX, *bufsizep = &bufsize;
40 if(_NSGetExecutablePath(relDir, bufsizep)==0) {
41 realpath(relDir, dirPath); // resolve symlink
42 char *dir = dirname(dirPath);
43 strcpy(dirPath, dir);
44 return;
45 } else {
46 // in case it failed, fall back to current directory
47 getcwd(dirPath, PATH_MAX);
50 realpath(relDir, dirPath);
54 bool SC_StandAloneInfo::IsStandAlone() {
55 #ifdef SC_STANDALONE
56 return true;
57 #else
58 return false;
59 #endif
62 void SC_StandAloneInfo::GetResourceDir(char* pathBuf, int length)
64 if ( !haveCheckedBundleStatus )
66 SC_StandAloneInfoInit();
68 strncpy(pathBuf, dirPath, length);
71 #endif