Tcl8.6/Tk8.6 Documentation > Tcl C API, version 8.6.8 > Translate
Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API
Tcl_TranslateFileName(interp, name, bufferPtr)
- Tcl_Interp *interp (in)
- Interpreter in which to report an error, if any.
- const char *name (in)
- File name, which may start with a “~”.
- Tcl_DString *bufferPtr (in/out)
- If needed, this dynamic string is used to store the new file name. At the time of the call it should be uninitialized or free. The caller must eventually call Tcl_DStringFree to free up anything stored here.
However, with the advent of the newer Tcl_FSGetNormalizedPath and Tcl_FSGetNativePath, there is no longer any need to use this procedure. In particular, Tcl_FSGetNativePath performs all the necessary translation and encoding conversion, is virtual-filesystem aware, and caches the native result for faster repeated calls. Finally Tcl_FSGetNativePath does not require you to free anything afterwards.
If Tcl_TranslateFileName has to do tilde substitution or translate the name then it uses the dynamic string at *bufferPtr to hold the new string it generates. After Tcl_TranslateFileName returns a non-NULL result, the caller must eventually invoke Tcl_DStringFree to free any information placed in *bufferPtr. The caller need not know whether or not Tcl_TranslateFileName actually used the string; Tcl_TranslateFileName initializes *bufferPtr even if it does not use it, so the call to Tcl_DStringFree will be safe in either case.
If an error occurs (e.g. because there was no user by the given name) then NULL is returned and an error message will be left in the interpreter's result. When an error occurs, Tcl_TranslateFileName frees the dynamic string itself so that the caller need not call Tcl_DStringFree.
The caller is responsible for making sure that the interpreter's result has its default empty value when Tcl_TranslateFileName is invoked.filename file name, home directory, tilde, translate, user
Copyright © 1994-1998 Sun Microsystems, Inc.