1 #include "creaSystem.h"
7 #include <windows.h> /* GetModuleFileName */
11 #ifdef __APPLE__ /* assume this is OSX */
12 #include <sys/param.h>
13 #include <mach-o/dyld.h> /* _NSGetExecutablePath : must add -framework
14 CoreFoundation to link line */
17 # define PATH_MAX MAXPATHLEN
22 # define PATH_MAX 2048
38 int System::HasTTY() { return false; }
43 return isatty(fileno(stdin));
49 int System::GetAppPath(char *pname, size_t pathsize)
52 /* Oddly, the readlink(2) man page says no NULL is appended. */
53 /* So you have to do it yourself, based on the return value: */
54 pathsize --; /* Preserve a space to add the trailing NULL */
55 long result = readlink("/proc/self/exe", pname, pathsize);
58 pname[result] = 0; /* add the #@!%ing NULL */
60 if ((access(pname, 0) == 0))
61 return 0; /* file exists, return OK */
62 /*else name doesn't seem to exist, return FAIL (falls
68 long result = GetModuleFileName(NULL, pname, pathsize);
71 /* fix up the dir slashes... */
72 int len = strlen(pname);
74 for (idx = 0; idx < len; idx++)
76 if (pname[idx] == '\\') pname[idx] = '/';
79 for (idx = len-1; idx >=0 ; idx--)
81 if (pname[idx] == '/')
88 if ((access(pname, 0) == 0))
89 return 0; /* file exists, return OK */
90 /*else name doesn't seem to exist, return FAIL (falls
96 char *p = getexecname();
99 /* According to the Sun manpages, getexecname will
100 "normally" return an */
101 /* absolute path - BUT might not... AND that IF it is not,
103 /* getcwd() will "usually" be the correct thing... Urgh!
106 /* check pathname is absolute (begins with a / ???) */
107 if (p[0] == '/') /* assume this means we have an
110 strncpy(pname, p, pathsize);
111 if ((access(pname, 0) == 0))
112 return 0; /* file exists, return OK */
114 else /* if not, prepend getcwd() then check if file
117 getcwd(pname, pathsize);
118 long result = strlen(pname);
119 strncat(pname, "/", (pathsize - result));
121 strncat(pname, p, (pathsize - result));
123 if ((access(pname, 0) == 0))
124 return 0; /* file exists, return OK */
125 /*else name doesn't seem to exist, return FAIL
131 #ifdef MACOSX /* assume this is OSX */
133 from http://www.hmug.org/man/3/NSModule.html
135 extern int _NSGetExecutablePath(char *buf, unsigned long
138 _NSGetExecutablePath copies the path of the executable
139 into the buffer and returns 0 if the path was successfully
140 copied in the provided buffer. If the buffer is not large
141 enough, -1 is returned and the expected buffer size is
142 copied in *bufsize. Note that _NSGetExecutablePath will
143 return "a path" to the executable not a "real path" to the
144 executable. That is the path may be a symbolic link and
145 not the real file. And with deep directories the total
146 bufsize needed could be more than MAXPATHLEN.
150 char *given_path = (char*)malloc(MAXPATHLEN * 2);
151 if (!given_path) return status;
153 uint32_t npathsize = MAXPATHLEN * 2;
154 long result = _NSGetExecutablePath(given_path, &npathsize);
156 { /* OK, we got something - now try and resolve the real path...
158 if (realpath(given_path, pname) != NULL)
160 if ((access(pname, 0) == 0))
161 status = 0; /* file exists, return OK */
168 return -1; /* Path Lookup Failed */
172 std::string System::GetDllAppPath(std::string nomdll){
173 std::string path = ".";
175 char currentPath[_MAX_PATH];
176 HMODULE hand = GetModuleHandle(nomdll.c_str());
177 GetModuleFileName(hand, currentPath, _MAX_PATH);
181 path = path.substr(0,path.find_last_of("\\"));
189 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '\\'
191 #define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '/'
194 //=========================================================================
195 std::string System::GetExecutablePath(){
197 //EED int err = get_app_path(name, PATH_MAX);
198 int err = System::GetAppPath(name,PATH_MAX);
201 printf("Could not determine current executable path ? ");
203 // remove the exe name
205 slash = strrchr(name, CREACONTOUR_VALID_FILE_SEPARATOR_CHAR);