Tcl_SplitPath(3tcl)
π Tcl_SplitPath β bestie's guide to path surgery β¨
okay so this is the page for Tcl_SplitPath, Tcl_JoinPath, and Tcl_GetPathType β three lil functions from the Tcl Library Procedures that manipulate platform-dependent file paths π¦ and honestly? they're giving C-level file-handling realness.
πΈ NAME πΈ
Tcl_SplitPath, Tcl_JoinPath, Tcl_GetPathType β they manipulate platform-dependent file paths. that's the whole job. slay. π
β¨ SYNOPSIS β¨
#include <tcl.h>
Tcl_SplitPath(path, argcPtr, argvPtr)
char *
Tcl_JoinPath(argc, argv, resultPtr)
Tcl_PathType
Tcl_GetPathType(path)
π ARGUMENTS π
const char *path(in) β a file path, in whatever form the current platform thinks is normal. (see the filename manual entry for acceptable forms for path names β it's got the lore iykyk.)Tcl_Size | int *argcPtr(out) β gets filled in with the number of path elements inpath. you can pass(Tcl_Size *)NULLwhen you're not using it. β οΈ important tea: if it points to a variable whose type is notTcl_Size, a compiler warning will be generated. and if your extensions is compiled with-DTCL_8_API,argcPtrwill be filled with-1for paths with more thanINT_MAXelements (which should trigger proper error-handling), otherwise expect it to crash π so like. be normal about it.const char ***argvPtr(out) β*argvPtrwill be filled in with the address of an array of pointers to the strings that are the extracted elements ofpath. there will be*argcPtrvalid entries in the array, followed by aNULLentry. πTcl_Size argc(in) β the number of elements inargv.const char *const *argv(in) β an array of path elements to merge together into a single path. π«ΆTcl_DString *resultPtr(in/out) β a pointer to an initializedTcl_DStringto which the result ofTcl_JoinPathwill be appended.
π DESCRIPTION π
so first things first, and bestie i need you to hear me: these procedures have been superseded by the Tcl-value-aware procedures in the FileSystem man page, which are more efficient. π they still work, but the new ones ate.
now, these procedures may be used to disassemble and reassemble file paths in a platform independent manner: they give you C-level access to the exact same functionality as the file split, file join, and file pathtype commands. same vibes, lower level. π
βοΈ Tcl_SplitPath
breaks a path into its constituent elements, returning an array of pointers to the elements using argcPtr and argvPtr. the memory pointed to by *argvPtr is dynamically allocated β and not just the array of pointers, it also holds copies of all the path elements. so it's all on one blob of memory, cute, but guess what:
π¨ it is the caller's responsibility to free all of this storage. Tcl is NOT doing it for you. periodt.
for example, suppose you called Tcl_SplitPath with this:
Tcl_Size argc;
char *path;
char **argv;
...
Tcl_SplitPath(string, &argc, &argv);
then you should eventually free the storage with a call like this:
Tcl_Free(argv);
that's it. that's the cleanup. don't forget it. π
π Tcl_JoinPath
the inverse of Tcl_SplitPath πͺ β it takes a collection of path elements given by argc and argv and generates a result string that is a properly constructed path. the result string is appended to resultPtr, and resultPtr must refer to an initialized Tcl_DString.
π the round trip
if the result of Tcl_SplitPath is passed to Tcl_JoinPath, the result will refer to the same location, but may not be in the same form. why? because Tcl_SplitPath and Tcl_JoinPath eliminate duplicate path separators and return a normalized form for each platform. it's a glow-up, not a move. β¨
π§ Tcl_GetPathType
returns the type of the specified path, where Tcl_PathType is one of:
TCL_PATH_ABSOLUTETCL_PATH_RELATIVETCL_PATH_VOLUME_RELATIVE
(see the filename manual entry for a description of the path types for each platform β every OS does its own thing, no cap.) π
π KEYWORDS π
file, filename, join, path, split, type
okay that's the whole page bestie!! π this was Tcl Library Procedures, version 7.5, Tcl_SplitPath(3tcl), and it's been a whole journey. go free your argv and live your truth. mwah πβ¨π¦
π¦ where this page comes from
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms