diff options
author | vincentdarley <vincentdarley> | 2003-12-12 17:09:27 (GMT) |
---|---|---|
committer | vincentdarley <vincentdarley> | 2003-12-12 17:09:27 (GMT) |
commit | aa01f2adde9514d4744432c6edb9667ea86bd2b2 (patch) | |
tree | 207bbf14b096b450d2cdc97d3ede6460b07d315d /unix | |
parent | 4b258259b47bd0beac3084e2ec7963668038e88c (diff) | |
download | tcl-aa01f2adde9514d4744432c6edb9667ea86bd2b2.zip tcl-aa01f2adde9514d4744432c6edb9667ea86bd2b2.tar.gz tcl-aa01f2adde9514d4744432c6edb9667ea86bd2b2.tar.bz2 |
allow creation of relative links
Diffstat (limited to 'unix')
-rw-r--r-- | unix/tclUnixFile.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index f268ad5..66c31b9 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixFile.c,v 1.34 2003/11/03 12:48:30 vincentdarley Exp $ + * RCS: @(#) $Id: tclUnixFile.c,v 1.35 2003/12/12 17:09:34 vincentdarley Exp $ */ #include "tclInt.h" @@ -735,9 +735,30 @@ TclpObjLink(pathPtr, toPtr, linkAction) * create these. */ if (linkAction & TCL_CREATE_SYMBOLIC_LINK) { - if (symlink(target, src) != 0) return NULL; + int targetLen; + Tcl_DString ds; + Tcl_Obj *transPtr; + /* + * Now we don't want to link to the absolute, normalized path. + * Relative links are quite acceptable, as are links to '~user', + * for example. + */ + transPtr = Tcl_FSGetTranslatedPath(NULL, toPtr); + if (transPtr == NULL) { + return NULL; + } + target = Tcl_GetStringFromObj(transPtr, &targetLen); + target = Tcl_UtfToExternalDString(NULL, target, targetLen, &ds); + Tcl_DecrRefCount(transPtr); + + if (symlink(target, src) != 0) { + toPtr = NULL; + } + Tcl_DStringFree(&ds); } else if (linkAction & TCL_CREATE_HARD_LINK) { - if (link(target, src) != 0) return NULL; + if (link(target, src) != 0) { + return NULL; + } } else { errno = ENODEV; return NULL; |