diff options
author | stanton <stanton> | 1999-04-16 00:46:29 (GMT) |
---|---|---|
committer | stanton <stanton> | 1999-04-16 00:46:29 (GMT) |
commit | 97464e6cba8eb0008cf2727c15718671992b913f (patch) | |
tree | ce9959f2747257d98d52ec8d18bf3b0de99b9535 /mac/tclMacFCmd.c | |
parent | a8c96ddb94d1483a9de5e340b740cb74ef6cafa7 (diff) | |
download | tcl-97464e6cba8eb0008cf2727c15718671992b913f.zip tcl-97464e6cba8eb0008cf2727c15718671992b913f.tar.gz tcl-97464e6cba8eb0008cf2727c15718671992b913f.tar.bz2 |
merged tcl 8.1 branch back into the main trunk
Diffstat (limited to 'mac/tclMacFCmd.c')
-rw-r--r-- | mac/tclMacFCmd.c | 465 |
1 files changed, 296 insertions, 169 deletions
diff --git a/mac/tclMacFCmd.c b/mac/tclMacFCmd.c index 7e8fd22..716237e 100644 --- a/mac/tclMacFCmd.c +++ b/mac/tclMacFCmd.c @@ -4,12 +4,12 @@ * Implements the Macintosh specific portions of the file manipulation * subcommands of the "file" command. * - * Copyright (c) 1996-1997 Sun Microsystems, Inc. + * Copyright (c) 1996-1998 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclMacFCmd.c,v 1.3 1999/04/15 22:38:47 stanton Exp $ + * RCS: @(#) $Id: tclMacFCmd.c,v 1.4 1999/04/16 00:47:20 stanton Exp $ */ #include "tclInt.h" @@ -31,16 +31,16 @@ */ static int GetFileFinderAttributes _ANSI_ARGS_((Tcl_Interp *interp, - int objIndex, char *fileName, + int objIndex, CONST char *fileName, Tcl_Obj **attributePtrPtr)); static int GetFileReadOnly _ANSI_ARGS_((Tcl_Interp *interp, - int objIndex, char *fileName, + int objIndex, CONST char *fileName, Tcl_Obj **readOnlyPtrPtr)); static int SetFileFinderAttributes _ANSI_ARGS_((Tcl_Interp *interp, - int objIndex, char *fileName, + int objIndex, CONST char *fileName, Tcl_Obj *attributePtr)); static int SetFileReadOnly _ANSI_ARGS_((Tcl_Interp *interp, - int objIndex, char *fileName, + int objIndex, CONST char *fileName, Tcl_Obj *readOnlyPtr)); /* @@ -72,14 +72,25 @@ CONST TclFileAttrProcs tclpFileAttrProcs[] = { static pascal Boolean CopyErrHandler _ANSI_ARGS_((OSErr error, short failedOperation, short srcVRefNum, long srcDirID, - const unsigned char *srcName, short dstVRefNum, - long dstDirID, const unsigned char *dstName)); + StringPtr srcName, short dstVRefNum, + long dstDirID,StringPtr dstName)); +static int DoCopyDirectory _ANSI_ARGS_((CONST char *src, + CONST char *dst, Tcl_DString *errorPtr)); +static int DoCopyFile _ANSI_ARGS_((CONST char *src, + CONST char *dst)); +static int DoCreateDirectory _ANSI_ARGS_((CONST char *path)); +static int DoDeleteFile _ANSI_ARGS_((CONST char *path)); +static int DoRemoveDirectory _ANSI_ARGS_((CONST char *path, + int recursive, Tcl_DString *errorPtr)); +static int DoRenameFile _ANSI_ARGS_((CONST char *src, + CONST char *dst)); OSErr FSpGetFLockCompat _ANSI_ARGS_((const FSSpec *specPtr, Boolean *lockedPtr)); static OSErr GenerateUniqueName _ANSI_ARGS_((short vRefNum, long dirID1, long dirID2, Str31 uniqueName)); -static OSErr GetFileSpecs _ANSI_ARGS_((char *path, FSSpec *pathSpecPtr, - FSSpec *dirSpecPtr, Boolean *pathExistsPtr, +static OSErr GetFileSpecs _ANSI_ARGS_((CONST char *path, + FSSpec *pathSpecPtr, FSSpec *dirSpecPtr, + Boolean *pathExistsPtr, Boolean *pathIsDirectoryPtr)); static OSErr MoveRename _ANSI_ARGS_((const FSSpec *srcSpecPtr, const FSSpec *dstSpecPtr, StringPtr copyName)); @@ -89,7 +100,7 @@ static int Pstrequal _ANSI_ARGS_((ConstStr255Param stringA, /* *--------------------------------------------------------------------------- * - * TclpRenameFile -- + * TclpRenameFile, DoRenameFile -- * * Changes the name of an existing file or directory, from src to dst. * If src and dst refer to the same file or directory, does nothing @@ -123,8 +134,29 @@ static int Pstrequal _ANSI_ARGS_((ConstStr255Param stringA, int TclpRenameFile( - char *src, /* Pathname of file or dir to be renamed. */ - char *dst) /* New pathname for file or directory. */ + CONST char *src, /* Pathname of file or dir to be renamed + * (UTF-8). */ + CONST char *dst) /* New pathname of file or directory + * (UTF-8). */ +{ + int result; + Tcl_DString srcString, dstString; + + Tcl_UtfToExternalDString(NULL, src, -1, &srcString); + Tcl_UtfToExternalDString(NULL, dst, -1, &dstString); + result = DoRenameFile(Tcl_DStringValue(&srcString), + Tcl_DStringValue(&dstString)); + Tcl_DStringFree(&srcString); + Tcl_DStringFree(&dstString); + return result; +} + +static int +DoRenameFile( + CONST char *src, /* Pathname of file or dir to be renamed + * (native). */ + CONST char *dst) /* New pathname of file or directory + * (native). */ { FSSpec srcFileSpec, dstFileSpec, dstDirSpec; OSErr err; @@ -157,7 +189,7 @@ TclpRenameFile( * fails, it's because it wasn't empty. */ - if (TclpRemoveDirectory(dst, 0, NULL) != TCL_OK) { + if (DoRemoveDirectory(dst, 0, NULL) != TCL_OK) { return TCL_ERROR; } @@ -230,9 +262,128 @@ TclpRenameFile( } /* + *-------------------------------------------------------------------------- + * + * MoveRename -- + * + * Helper function for TclpRenameFile. Renames a file or directory + * into the same directory or another directory. The target name + * must not already exist in the destination directory. + * + * Don't use FSpMoveRenameCompat because it doesn't work with + * directories or with locked files. + * + * Results: + * Returns a mac error indicating the cause of the failure. + * + * Side effects: + * Creates a temp file in the target directory to handle a rename + * between directories. + * + *-------------------------------------------------------------------------- + */ + +static OSErr +MoveRename( + const FSSpec *srcFileSpecPtr, /* Source object. */ + const FSSpec *dstDirSpecPtr, /* Destination directory. */ + StringPtr copyName) /* New name for object in destination + * directory. */ +{ + OSErr err; + long srcID, dstID; + Boolean srcIsDir, dstIsDir; + Str31 tmpName; + FSSpec dstFileSpec, srcDirSpec, tmpSrcFileSpec, tmpDstFileSpec; + Boolean locked; + + if (srcFileSpecPtr->parID == 1) { + /* + * Trying to rename a volume. + */ + + return badMovErr; + } + if (srcFileSpecPtr->vRefNum != dstDirSpecPtr->vRefNum) { + /* + * Renaming across volumes. + */ + + return diffVolErr; + } + err = FSpGetFLockCompat(srcFileSpecPtr, &locked); + if (locked) { + FSpRstFLockCompat(srcFileSpecPtr); + } + if (err == noErr) { + err = FSpGetDirectoryID(dstDirSpecPtr, &dstID, &dstIsDir); + } + if (err == noErr) { + if (srcFileSpecPtr->parID == dstID) { + /* + * Renaming object within directory. + */ + + err = FSpRenameCompat(srcFileSpecPtr, copyName); + goto done; + } + if (Pstrequal(srcFileSpecPtr->name, copyName)) { + /* + * Moving object to another directory (under same name). + */ + + err = FSpCatMoveCompat(srcFileSpecPtr, dstDirSpecPtr); + goto done; + } + err = FSpGetDirectoryID(srcFileSpecPtr, &srcID, &srcIsDir); + } + if (err == noErr) { + /* + * Fullblown: rename source object to temp name, move temp to + * dest directory, and rename temp to target. + */ + + err = GenerateUniqueName(srcFileSpecPtr->vRefNum, + srcFileSpecPtr->parID, dstID, tmpName); + FSMakeFSSpecCompat(srcFileSpecPtr->vRefNum, srcFileSpecPtr->parID, + tmpName, &tmpSrcFileSpec); + FSMakeFSSpecCompat(dstDirSpecPtr->vRefNum, dstID, tmpName, + &tmpDstFileSpec); + } + if (err == noErr) { + err = FSpRenameCompat(srcFileSpecPtr, tmpName); + } + if (err == noErr) { + err = FSpCatMoveCompat(&tmpSrcFileSpec, dstDirSpecPtr); + if (err == noErr) { + err = FSpRenameCompat(&tmpDstFileSpec, copyName); + if (err == noErr) { + goto done; + } + FSMakeFSSpecCompat(srcFileSpecPtr->vRefNum, srcFileSpecPtr->parID, + NULL, &srcDirSpec); + FSpCatMoveCompat(&tmpDstFileSpec, &srcDirSpec); + } + FSpRenameCompat(&tmpSrcFileSpec, srcFileSpecPtr->name); + } + + done: + if (locked != false) { + if (err == noErr) { + FSMakeFSSpecCompat(dstDirSpecPtr->vRefNum, + dstID, copyName, &dstFileSpec); + FSpSetFLockCompat(&dstFileSpec); + } else { + FSpSetFLockCompat(srcFileSpecPtr); + } + } + return err; +} + +/* *--------------------------------------------------------------------------- * - * TclpCopyFile -- + * TclpCopyFile, DoCopyFile -- * * Copy a single file (not a directory). If dst already exists and * is not a directory, it is removed. @@ -258,8 +409,25 @@ TclpRenameFile( int TclpCopyFile( - char *src, /* Pathname of file to be copied. */ - char *dst) /* Pathname of file to copy to. */ + CONST char *src, /* Pathname of file to be copied (UTF-8). */ + CONST char *dst) /* Pathname of file to copy to (UTF-8). */ +{ + int result; + Tcl_DString srcString, dstString; + + Tcl_UtfToExternalDString(NULL, src, -1, &srcString); + Tcl_UtfToExternalDString(NULL, dst, -1, &dstString); + result = DoCopyFile(Tcl_DStringValue(&srcString), + Tcl_DStringValue(&dstString)); + Tcl_DStringFree(&srcString); + Tcl_DStringFree(&dstString); + return result; +} + +static int +DoCopyFile( + CONST char *src, /* Pathname of file to be copied (native). */ + CONST char *dst) /* Pathname of file to copy to (native). */ { OSErr err, dstErr; Boolean dstExists, dstIsDirectory, dstLocked; @@ -328,7 +496,7 @@ TclpCopyFile( /* *--------------------------------------------------------------------------- * - * TclpDeleteFile -- + * TclpDeleteFile, DoDeleteFile -- * * Removes a single file (not a directory). * @@ -349,13 +517,26 @@ TclpCopyFile( int TclpDeleteFile( - char *path) /* Pathname of file to be removed. */ + CONST char *path) /* Pathname of file to be removed (UTF-8). */ +{ + int result; + Tcl_DString pathString; + + Tcl_UtfToExternalDString(NULL, path, -1, &pathString); + result = DoDeleteFile(Tcl_DStringValue(&pathString)); + Tcl_DStringFree(&pathString); + return result; +} + +static int +DoDeleteFile( + CONST char *path) /* Pathname of file to be removed (native). */ { OSErr err; FSSpec fileSpec; Boolean isDirectory; long dirID; - + err = FSpLocationFromPath(strlen(path), path, &fileSpec); if (err == noErr) { /* @@ -387,7 +568,7 @@ TclpDeleteFile( /* *--------------------------------------------------------------------------- * - * TclpCreateDirectory -- + * TclpCreateDirectory, DoCreateDirectory -- * * Creates the specified directory. All parent directories of the * specified directory must already exist. The directory is @@ -412,7 +593,20 @@ TclpDeleteFile( int TclpCreateDirectory( - char *path) /* Pathname of directory to create. */ + CONST char *path) /* Pathname of directory to create (UTF-8). */ +{ + int result; + Tcl_DString pathString; + + Tcl_UtfToExternalDString(NULL, path, -1, &pathString); + result = DoCreateDirectory(Tcl_DStringValue(&pathString)); + Tcl_DStringFree(&pathString); + return result; +} + +static int +DoCreateDirectory( + CONST char *path) /* Pathname of directory to create (native). */ { OSErr err; FSSpec dirSpec; @@ -435,7 +629,7 @@ TclpCreateDirectory( /* *--------------------------------------------------------------------------- * - * TclpCopyDirectory -- + * TclpCopyDirectory, DoCopyDirectory -- * * Recursively copies a directory. The target directory dst must * not already exist. Note that this function does not merge two @@ -460,10 +654,33 @@ TclpCreateDirectory( int TclpCopyDirectory( - char *src, /* Pathname of directory to be copied. */ - char *dst, /* Pathname of target directory. */ - Tcl_DString *errorPtr) /* If non-NULL, initialized DString for - * error reporting. */ + CONST char *src, /* Pathname of directory to be copied + * (UTF-8). */ + CONST char *dst, /* Pathname of target directory (UTF-8). */ + Tcl_DString *errorPtr) /* If non-NULL, uninitialized or free + * DString filled with UTF-8 name of file + * causing error. */ +{ + int result; + Tcl_DString srcString, dstString; + + Tcl_UtfToExternalDString(NULL, src, -1, &srcString); + Tcl_UtfToExternalDString(NULL, dst, -1, &dstString); + result = DoCopyDirectory(Tcl_DStringValue(&srcString), + Tcl_DStringValue(&dstString), errorPtr); + Tcl_DStringFree(&srcString); + Tcl_DStringFree(&dstString); + return result; +} + +static int +DoCopyDirectory( + CONST char *src, /* Pathname of directory to be copied + * (UTF-8). */ + CONST char *dst, /* Pathname of target directory (UTF-8). */ + Tcl_DString *errorPtr) /* If non-NULL, uninitialized or free + * DString filled with UTF-8 name of file + * causing error. */ { OSErr err, saveErr; long srcID, tmpDirID; @@ -572,7 +789,7 @@ TclpCopyDirectory( if (err != noErr) { errno = TclMacOSErrorToPosixError(err); if (errorPtr != NULL) { - Tcl_DStringAppend(errorPtr, dst, -1); + Tcl_ExternalToUtfDString(NULL, dst, -1, errorPtr); } return TCL_ERROR; } @@ -604,10 +821,10 @@ CopyErrHandler( short failedOperation, /* operation that caused the error */ short srcVRefNum, /* volume ref number of source */ long srcDirID, /* directory id of source */ - const unsigned char *srcName, /* name of source */ + StringPtr srcName, /* name of source */ short dstVRefNum, /* volume ref number of dst */ long dstDirID, /* directory id of dst */ - const unsigned char *dstName) /* name of dst directory */ + StringPtr dstName) /* name of dst directory */ { return true; } @@ -615,7 +832,7 @@ CopyErrHandler( /* *--------------------------------------------------------------------------- * - * TclpRemoveDirectory -- + * TclpRemoveDirectory, DoRemoveDirectory -- * * Removes directory (and its contents, if the recursive flag is set). * @@ -640,13 +857,37 @@ CopyErrHandler( int TclpRemoveDirectory( - char *path, /* Pathname of directory to be removed. */ + CONST char *path, /* Pathname of directory to be removed + * (UTF-8). */ + int recursive, /* If non-zero, removes directories that + * are nonempty. Otherwise, will only remove + * empty directories. */ + Tcl_DString *errorPtr) /* If non-NULL, uninitialized or free + * DString filled with UTF-8 name of file + * causing error. */ +{ + int result; + Tcl_DString pathString; + + Tcl_UtfToExternalDString(NULL, path, -1, &pathString); + result = DoRemoveDirectory(Tcl_DStringValue(&pathString), recursive, + errorPtr); + Tcl_DStringFree(&pathString); + + return result; +} + +static int +DoRemoveDirectory( + CONST char *path, /* Pathname of directory to be removed + * (native). */ int recursive, /* If non-zero, removes directories that * are nonempty. Otherwise, will only remove * empty directories. */ - Tcl_DString *errorPtr) /* If non-NULL, initialized DString for - * error reporting. */ -{ + Tcl_DString *errorPtr) /* If non-NULL, uninitialized or free + * DString filled with UTF-8 name of file + * causing error. */ +{ OSErr err; FSSpec fileSpec; long dirID; @@ -655,6 +896,7 @@ TclpRemoveDirectory( CInfoPBRec pb; Str255 fileName; + locked = 0; err = FSpLocationFromPath(strlen(path), path, &fileSpec); if (err != noErr) { @@ -715,7 +957,7 @@ TclpRemoveDirectory( done: if (err != noErr) { if (errorPtr != NULL) { - Tcl_DStringAppend(errorPtr, path, -1); + Tcl_UtfToExternalDString(NULL, path, -1, errorPtr); } if (locked) { FSpSetFLockCompat(&fileSpec); @@ -725,130 +967,11 @@ TclpRemoveDirectory( } return TCL_OK; } - -/* - *-------------------------------------------------------------------------- - * - * MoveRename -- - * - * Helper function for TclpRenameFile. Renames a file or directory - * into the same directory or another directory. The target name - * must not already exist in the destination directory. - * - * Don't use FSpMoveRenameCompat because it doesn't work with - * directories or with locked files. - * - * Results: - * Returns a mac error indicating the cause of the failure. - * - * Side effects: - * Creates a temp file in the target directory to handle a rename - * between directories. - * - *-------------------------------------------------------------------------- - */ - -static OSErr -MoveRename( - const FSSpec *srcFileSpecPtr, /* Source object. */ - const FSSpec *dstDirSpecPtr, /* Destination directory. */ - StringPtr copyName) /* New name for object in destination - * directory. */ -{ - OSErr err; - long srcID, dstID; - Boolean srcIsDir, dstIsDir; - Str31 tmpName; - FSSpec dstFileSpec, srcDirSpec, tmpSrcFileSpec, tmpDstFileSpec; - Boolean locked; - - if (srcFileSpecPtr->parID == 1) { - /* - * Trying to rename a volume. - */ - - return badMovErr; - } - if (srcFileSpecPtr->vRefNum != dstDirSpecPtr->vRefNum) { - /* - * Renaming across volumes. - */ - - return diffVolErr; - } - err = FSpGetFLockCompat(srcFileSpecPtr, &locked); - if (locked) { - FSpRstFLockCompat(srcFileSpecPtr); - } - if (err == noErr) { - err = FSpGetDirectoryID(dstDirSpecPtr, &dstID, &dstIsDir); - } - if (err == noErr) { - if (srcFileSpecPtr->parID == dstID) { - /* - * Renaming object within directory. - */ - - err = FSpRenameCompat(srcFileSpecPtr, copyName); - goto done; - } - if (Pstrequal(srcFileSpecPtr->name, copyName)) { - /* - * Moving object to another directory (under same name). - */ - - err = FSpCatMoveCompat(srcFileSpecPtr, dstDirSpecPtr); - goto done; - } - err = FSpGetDirectoryID(srcFileSpecPtr, &srcID, &srcIsDir); - } - if (err == noErr) { - /* - * Fullblown: rename source object to temp name, move temp to - * dest directory, and rename temp to target. - */ - - err = GenerateUniqueName(srcFileSpecPtr->vRefNum, - srcFileSpecPtr->parID, dstID, tmpName); - FSMakeFSSpecCompat(srcFileSpecPtr->vRefNum, srcFileSpecPtr->parID, - tmpName, &tmpSrcFileSpec); - FSMakeFSSpecCompat(dstDirSpecPtr->vRefNum, dstID, tmpName, - &tmpDstFileSpec); - } - if (err == noErr) { - err = FSpRenameCompat(srcFileSpecPtr, tmpName); - } - if (err == noErr) { - err = FSpCatMoveCompat(&tmpSrcFileSpec, dstDirSpecPtr); - if (err == noErr) { - err = FSpRenameCompat(&tmpDstFileSpec, copyName); - if (err == noErr) { - goto done; - } - FSMakeFSSpecCompat(srcFileSpecPtr->vRefNum, srcFileSpecPtr->parID, - NULL, &srcDirSpec); - FSpCatMoveCompat(&tmpDstFileSpec, &srcDirSpec); - } - FSpRenameCompat(&tmpSrcFileSpec, srcFileSpecPtr->name); - } - - done: - if (locked != false) { - if (err == noErr) { - FSMakeFSSpecCompat(dstDirSpecPtr->vRefNum, - dstID, copyName, &dstFileSpec); - FSpSetFLockCompat(&dstFileSpec); - } else { - FSpSetFLockCompat(srcFileSpecPtr); - } - } - return err; -} /* *--------------------------------------------------------------------------- * - * GetFileSpecs -- + * GenerateUniqueName -- * * Generate a filename that is not in either of the two specified * directories (on the same volume). @@ -928,7 +1051,7 @@ GenerateUniqueName( static OSErr GetFileSpecs( - char *path, /* The path to query. */ + CONST char *path, /* The path to query. */ FSSpec *pathSpecPtr, /* Filled with information about path. */ FSSpec *dirSpecPtr, /* Filled with information about path's * parent directory. */ @@ -1071,7 +1194,7 @@ static int GetFileFinderAttributes( Tcl_Interp *interp, /* The interp to report errors with. */ int objIndex, /* The index of the attribute option. */ - char *fileName, /* The name of the file. */ + CONST char *fileName, /* The name of the file. */ Tcl_Obj **attributePtrPtr) /* A pointer to return the object with. */ { OSErr err; @@ -1114,7 +1237,7 @@ GetFileFinderAttributes( if (err != noErr) { errno = TclMacOSErrorToPosixError(err); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), - "couldn't get attributes for file \"", fileName, "\": ", + "could not read \"", fileName, "\": ", Tcl_PosixError(interp), (char *) NULL); return TCL_ERROR; } @@ -1146,7 +1269,7 @@ static int GetFileReadOnly( Tcl_Interp *interp, /* The interp to report errors with. */ int objIndex, /* The index of the attribute. */ - char *fileName, /* The name of the file. */ + CONST char *fileName, /* The name of the file. */ Tcl_Obj **readOnlyPtrPtr) /* A pointer to return the object with. */ { OSErr err; @@ -1179,7 +1302,7 @@ GetFileReadOnly( if (err != noErr) { errno = TclMacOSErrorToPosixError(err); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), - "couldn't get attributes for file \"", fileName, "\": ", + "could not read \"", fileName, "\": ", Tcl_PosixError(interp), (char *) NULL); return TCL_ERROR; } @@ -1207,7 +1330,7 @@ static int SetFileFinderAttributes( Tcl_Interp *interp, /* The interp to report errors with. */ int objIndex, /* The index of the attribute. */ - char *fileName, /* The name of the file. */ + CONST char *fileName, /* The name of the file. */ Tcl_Obj *attributePtr) /* The command line object. */ { OSErr err; @@ -1267,7 +1390,7 @@ SetFileFinderAttributes( if (err != noErr) { errno = TclMacOSErrorToPosixError(err); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), - "couldn't set attributes for file \"", fileName, "\": ", + "could not read \"", fileName, "\": ", Tcl_PosixError(interp), (char *) NULL); return TCL_ERROR; } @@ -1295,7 +1418,7 @@ static int SetFileReadOnly( Tcl_Interp *interp, /* The interp to report errors with. */ int objIndex, /* The index of the attribute. */ - char *fileName, /* The name of the file. */ + CONST char *fileName, /* The name of the file. */ Tcl_Obj *readOnlyPtr) /* The command line object. */ { OSErr err; @@ -1338,7 +1461,7 @@ SetFileReadOnly( if (err != noErr) { errno = TclMacOSErrorToPosixError(err); Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), - "couldn't set attributes for file \"", fileName, "\": ", + "could not read \"", fileName, "\": ", Tcl_PosixError(interp), (char *) NULL); return TCL_ERROR; } @@ -1362,7 +1485,6 @@ SetFileReadOnly( * *--------------------------------------------------------------------------- */ - int TclpListVolumes( Tcl_Interp *interp) /* Interpreter to which to pass the volume list */ @@ -1372,6 +1494,7 @@ TclpListVolumes( OSErr theError = noErr; Tcl_Obj *resultPtr, *elemPtr; short volIndex = 1; + Tcl_DString dstr; resultPtr = Tcl_NewObj(); @@ -1386,7 +1509,7 @@ TclpListVolumes( */ while ( 1 ) { - pb.volumeParam.ioNamePtr = (StringPtr) & name; + pb.volumeParam.ioNamePtr = (StringPtr) &name; pb.volumeParam.ioVolIndex = volIndex; theError = PBHGetVInfoSync(&pb); @@ -1394,10 +1517,14 @@ TclpListVolumes( if ( theError != noErr ) { break; } - - elemPtr = Tcl_NewStringObj((char *) name + 1, (int) name[0]); + + Tcl_ExternalToUtfDString(NULL, (char *) &name[1], name[0], &dstr); + elemPtr = Tcl_NewStringObj(Tcl_DStringValue(&dstr), + Tcl_DStringLength(&dstr)); Tcl_AppendToObj(elemPtr, ":", 1); Tcl_ListObjAppendElement(interp, resultPtr, elemPtr); + + Tcl_DStringFree(&dstr); volIndex++; } |