Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You may be interested in <a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/realpath.3.html" rel="noreferrer"><code>realpath(3)</code></a>, or Python's <a href="http://docs.python.org/library/os.path.html#os.path.realpath" rel="noreferrer"><code>os.path.realpath</code></a>. The two aren't exactly the same; the C library call requires that intermediary path components exist, while the Python version does not.</p> <pre class="lang-none prettyprint-override"><code>$ pwd /tmp/foo $ ls -l total 16 -rw-r--r-- 1 miles wheel 0 Jul 11 21:08 a lrwxr-xr-x 1 miles wheel 1 Jul 11 20:49 b -&gt; a lrwxr-xr-x 1 miles wheel 1 Jul 11 20:49 c -&gt; b $ python -c 'import os,sys;print(os.path.realpath(sys.argv[1]))' c /private/tmp/foo/a </code></pre> <p>I know you said you'd prefer something more lightweight than another scripting language, but just in case compiling a binary is insufferable, you can use Python and ctypes (available on Mac OS X 10.5) to wrap the library call:</p> <pre class="lang-py prettyprint-override"><code>#!/usr/bin/python import ctypes, sys libc = ctypes.CDLL('libc.dylib') libc.realpath.restype = ctypes.c_char_p libc.__error.restype = ctypes.POINTER(ctypes.c_int) libc.strerror.restype = ctypes.c_char_p def realpath(path): buffer = ctypes.create_string_buffer(1024) # PATH_MAX if libc.realpath(path, buffer): return buffer.value else: errno = libc.__error().contents.value raise OSError(errno, "%s: %s" % (libc.strerror(errno), buffer.value)) if __name__ == '__main__': print realpath(sys.argv[1]) </code></pre> <p>Ironically, the C version of this script ought to be shorter. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload