diff options
Diffstat (limited to 'unix/tclUnixFile.c')
-rw-r--r-- | unix/tclUnixFile.c | 129 |
1 files changed, 128 insertions, 1 deletions
diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index 07e43fc..842d1b6 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -9,10 +9,11 @@ * 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.41 2004/07/20 10:12:29 das Exp $ + * RCS: @(#) $Id: tclUnixFile.c,v 1.42 2004/10/07 14:50:23 vincentdarley Exp $ */ #include "tclInt.h" +#include "tclFileSystem.h" static int NativeMatchType(CONST char* nativeName, Tcl_GlobTypeData *types); @@ -903,6 +904,132 @@ TclpFilesystemPathType(pathPtr) /* *--------------------------------------------------------------------------- * + * TclpNativeToNormalized -- + * + * Convert native format to a normalized path object, with refCount + * of zero. + * + * Currently assumes all native paths are actually normalized + * already, so if the path given is not normalized this will + * actually just convert to a valid string path, but not + * necessarily a normalized one. + * + * Results: + * A valid normalized path. + * + * Side effects: + * None. + * + *--------------------------------------------------------------------------- + */ +Tcl_Obj* +TclpNativeToNormalized(clientData) + ClientData clientData; +{ + Tcl_DString ds; + Tcl_Obj *objPtr; + int len; + + CONST char *copy; + Tcl_ExternalToUtfDString(NULL, (CONST char*)clientData, -1, &ds); + + copy = Tcl_DStringValue(&ds); + len = Tcl_DStringLength(&ds); + + objPtr = Tcl_NewStringObj(copy,len); + Tcl_DStringFree(&ds); + + return objPtr; +} + +/* + *--------------------------------------------------------------------------- + * + * TclNativeCreateNativeRep -- + * + * Create a native representation for the given path. + * + * Results: + * The nativePath representation. + * + * Side effects: + * Memory will be allocated. The path may need to be normalized. + * + *--------------------------------------------------------------------------- + */ +ClientData +TclNativeCreateNativeRep(pathPtr) + Tcl_Obj* pathPtr; +{ + char *nativePathPtr; + Tcl_DString ds; + Tcl_Obj* validPathPtr; + int len; + char *str; + + if (TclFSCwdIsNative()) { + /* + * The cwd is native, which means we can use the translated + * path without worrying about normalization (this will also + * usually be shorter so the utf-to-external conversion will + * be somewhat faster). + */ + validPathPtr = Tcl_FSGetTranslatedPath(NULL, pathPtr); + } else { + /* Make sure the normalized path is set */ + validPathPtr = Tcl_FSGetNormalizedPath(NULL, pathPtr); + Tcl_IncrRefCount(validPathPtr); + } + + str = Tcl_GetStringFromObj(validPathPtr, &len); + Tcl_UtfToExternalDString(NULL, str, len, &ds); + len = Tcl_DStringLength(&ds) + sizeof(char); + Tcl_DecrRefCount(validPathPtr); + nativePathPtr = ckalloc((unsigned) len); + memcpy((VOID*)nativePathPtr, (VOID*)Tcl_DStringValue(&ds), (size_t) len); + + Tcl_DStringFree(&ds); + return (ClientData)nativePathPtr; +} + +/* + *--------------------------------------------------------------------------- + * + * TclNativeDupInternalRep -- + * + * Duplicate the native representation. + * + * Results: + * The copied native representation, or NULL if it is not possible + * to copy the representation. + * + * Side effects: + * Memory will be allocated for the copy. + * + *--------------------------------------------------------------------------- + */ +ClientData +TclNativeDupInternalRep(clientData) + ClientData clientData; +{ + char *copy; + size_t len; + + if (clientData == NULL) { + return NULL; + } + + /* ascii representation when running on Unix */ + len = sizeof(char) + (strlen((CONST char*)clientData) * sizeof(char)); + + copy = (char *) ckalloc(len); + memcpy((VOID*)copy, (VOID*)clientData, len); + return (ClientData)copy; +} + +/* + *--------------------------------------------------------------------------- + * * TclpUtime -- * * Set the modification date for a file. |