summaryrefslogtreecommitdiff
path: root/Mac
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2012-07-17 17:33:46 +0100
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2012-07-17 17:33:46 +0100
commit4e214226b9bac050901d01b9218fef6a98e7c81f (patch)
treef6bee432a077e40b7205d1de0f98e5787ffd2b41 /Mac
parent71a97cf0dda2e9bae0e7d5f72e8f575282b92221 (diff)
downloadcpython-4e214226b9bac050901d01b9218fef6a98e7c81f.tar.gz
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Diffstat (limited to 'Mac')
-rw-r--r--Mac/Tools/pythonw.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/Mac/Tools/pythonw.c b/Mac/Tools/pythonw.c
index f5cdff52d0..1d2db383f9 100644
--- a/Mac/Tools/pythonw.c
+++ b/Mac/Tools/pythonw.c
@@ -28,6 +28,7 @@
#include <dlfcn.h>
#include <stdlib.h>
#include <Python.h>
+#include <mach-o/dyld.h>
extern char** environ;
@@ -158,9 +159,44 @@ main(int argc, char **argv) {
/* Set the original executable path in the environment. */
status = _NSGetExecutablePath(path, &size);
if (status == 0) {
- if (realpath(path, real_path) != NULL) {
- setenv("__PYVENV_LAUNCHER__", real_path, 1);
+ /*
+ * Note: don't call 'realpath', that will
+ * erase symlink information, and that
+ * breaks "pyvenv --symlink"
+ *
+ * It is nice to have the directory name
+ * as a cleaned up absolute path though,
+ * therefore call realpath on dirname(path)
+ */
+ char* slash = strrchr(path, '/');
+ if (slash) {
+ char replaced;
+ replaced = slash[1];
+ slash[1] = 0;
+ if (realpath(path, real_path) == NULL) {
+ err(1, "realpath: %s", path);
+ }
+ slash[1] = replaced;
+ if (strlcat(real_path, slash, sizeof(real_path)) > sizeof(real_path)) {
+ errno = EINVAL;
+ err(1, "realpath: %s", path);
+ }
+
+ } else {
+ if (realpath(".", real_path) == NULL) {
+ err(1, "realpath: %s", path);
+ }
+ if (strlcat(real_path, "/", sizeof(real_path)) > sizeof(real_path)) {
+ errno = EINVAL;
+ err(1, "realpath: %s", path);
+ }
+ if (strlcat(real_path, path, sizeof(real_path)) > sizeof(real_path)) {
+ errno = EINVAL;
+ err(1, "realpath: %s", path);
+ }
}
+
+ setenv("__PYVENV_LAUNCHER__", real_path, 1);
}
/*