1 ?MAKE:usensgetexecutablepath: cat rm_try Compile run Setvar
3 ?S:usensgetexecutablepath:
4 ?S: This symbol, if defined, indicates that we can use _NSGetExecutablePath
5 ?S: and realpath to get a full path for the executable, and hence convert
6 ?S: $^X to an absolute path.
8 ?C:USE_NSGETEXECUTABLEPATH:
9 ?C: This symbol, if defined, indicates that we can use _NSGetExecutablePath
10 ?C: and realpath to get a full path for the executable, and hence convert
11 ?C: $^X to an absolute path.
13 ?H:#$usensgetexecutablepath USE_NSGETEXECUTABLEPATH /**/
15 ?LINT:set usensgetexecutablepath
17 : Determine if we can use _NSGetExecutablePath to find executing program
19 echo "Determining whether we can use _NSGetExecutablePath to find executing program..." >&4
21 /* Intentionally a long probe as I'd like to sanity check that the exact
22 approach is going to work, as thinking it will work, but only having it
23 part working at runtime is worse than not having it. */
24 #include <mach-o/dyld.h>
27 #include <sys/param.h>
31 main(int argc, char **argv) {
33 uint32_t size = sizeof(buf);
37 char *argv_leaf = strrchr(argv[0], '/');
41 fprintf(stderr, "Can't locate / in '%s'\n", argv[0]);
45 _NSGetExecutablePath(buf, &size);
46 if (size > MAXPATHLEN * MAXPATHLEN) {
47 fprintf(stderr, "_NSGetExecutablePath size %u is too long for a path\n",
52 buffer = (char *)malloc(size);
58 result = _NSGetExecutablePath(buffer, &size);
60 fprintf(stderr, "_NSGetExecutablePath returned %i for a size of %u\n",
61 result, (unsigned int) size);
65 tidied = realpath(buffer, NULL);
74 fprintf(stderr, "Not an absolute path: '%s'\n", tidied);
78 if (strstr(tidied, "/./")) {
79 fprintf(stderr, "Contains /./: '%s'\n", tidied);
83 if (strstr(tidied, "/../")) {
84 fprintf(stderr, "Contains /../: '%s'\n", tidied);
88 tidied_leaf = strrchr(tidied, '/');
89 if (strcmp(tidied_leaf, argv_leaf) != 0) {
90 fprintf(stderr, "Leafnames differ: '%s' vs '%s'\n", argv[0], tidied);
102 if eval $compile; then
104 echo "You can use _NSGetExecutablePath to find the executing program." >&4
107 echo "Nope, _NSGetExecutablePath doesn't work here." >&4
110 echo "I'm unable to compile the test program." >&4
111 echo "I'll assume no _NSGetExecutablePath here." >&4
114 set usensgetexecutablepath