Tcl_TranslateFileName(3)
π« Tcl_TranslateFileName β a Tcl Library Procedures moment π«
okay bestie, welcome to the manual page for Tcl_TranslateFileName(3), straight out of the Tcl Library Procedures collection. this one's a little vintage, a little deprecated, and honestly kind of a vibe. let's get into it π
β¨ NAME β¨
Tcl_TranslateFileName β converts a file name to its native form. literally just glow-up-ing your filename for the local OS π
π¦ SYNOPSIS π¦
#include <tcl.h>
char *
Tcl_TranslateFileName(interp, name, bufferPtr)
πΈ ARGUMENTS πΈ
Tcl_Interp *interp(in) β the interpreter where we spill the tea if anything goes wrong, i.e. where errors get reported, if any.const char *name(in) β the file name in question. the main character, if you will πTcl_DString *bufferPtr(in/out) β if it's needed, this dynamic string is where the new file name gets stored. when you call this, it should be uninitialized or free β like, don't hand it a whole situation. and the caller must eventually callTcl_DStringFreeto free up anything stored here. no leaving mess behind, we're not that girl π
π DESCRIPTION π
so this utility procedure translates a file name into a platform-specific form. after it's been converted to the appropriate encoding, that form is suitable for passing to the local operating system. specifically: it converts network names into native form. very demure, very mindful, very platform-aware β¨
but β and this is the part where we all collectively gasp β with the advent of the newer Tcl_FSGetNormalizedPath and Tcl_FSGetNativePath, there is no longer any need to use this procedure. like, at all. no cap. π«Ά
and here's why the new girls are eating:
Tcl_FSGetNativePathperforms all the necessary translation and encoding conversion- it's virtual-filesystem aware π
- it caches the native result so repeated calls are faster
- and finally,
Tcl_FSGetNativePathdoes not require you to free anything afterwards. nothing. zero cleanup. iconic.
if Tcl_TranslateFileName does have to 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. and listen β the caller does not need to know whether or not Tcl_TranslateFileName actually used the string, because Tcl_TranslateFileName initializes *bufferPtr even if it doesn't use it, so the call to Tcl_DStringFree will be safe in either case. bestie really said "don't worry about it, I handled it" π
if an error occurs (like, say, 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. and when an error occurs, Tcl_TranslateFileName frees the dynamic string itself, so that the caller need not call Tcl_DStringFree. self-cleaning. we love a low-maintenance icon π
β οΈ okay important one: the caller is responsible for making sure that the interpreter's result has its default empty value when Tcl_TranslateFileName is invoked. yes, that's on you. that's your job. don't make it weird π
π₯ SEE ALSO π₯
π KEYWORDS π
file name, home directory, translate, user
and that's the whole page, bestie. this one came to you from Tcl 8.1, dated the same, with Tcl_TranslateFileName(3) stamped on the bottom like a little signature. go forth and use Tcl_FSGetNativePath instead, fr fr π§β¨
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 1989-1993 The Regents of the University of California
- Copyright (c) 1994-1998 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms