summaryrefslogtreecommitdiff
path: root/cffi/ffiplatform.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2012-11-19 17:21:31 +0100
committerArmin Rigo <arigo@tunes.org>2012-11-19 17:21:31 +0100
commit3576f4a8ad73d41314f9517667698f858eb803f4 (patch)
tree5aab751edf847781a532834037eb3f04dd9e52ce /cffi/ffiplatform.py
parentdc887fb0de4f67359433195017aee4a938f2bb75 (diff)
downloadcffi-3576f4a8ad73d41314f9517667698f858eb803f4.tar.gz
90% of a fix for issue #40.
Diffstat (limited to 'cffi/ffiplatform.py')
-rw-r--r--cffi/ffiplatform.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/cffi/ffiplatform.py b/cffi/ffiplatform.py
index b3eef21..19cabf6 100644
--- a/cffi/ffiplatform.py
+++ b/cffi/ffiplatform.py
@@ -58,3 +58,21 @@ try:
except ImportError:
def samefile(f1, f2):
return os.path.abspath(f1) == os.path.abspath(f2)
+
+def maybe_relative_path(path):
+ if not os.path.isabs(path):
+ return path # already relative
+ dir = path
+ names = []
+ while True:
+ prevdir = dir
+ dir, name = os.path.split(prevdir)
+ if dir == prevdir or not dir:
+ return path # failed to make it relative
+ names.append(name)
+ try:
+ if samefile(dir, os.curdir):
+ names.reverse()
+ return os.path.join(*names)
+ except OSError:
+ pass