Tcl_SplitPath(3)
okay bestie, welcome to Tcl_SplitPath(3) β it's a Tcl Library Procedures page, and it's all about manipulating platform-dependent file paths. yes, three whole functions, and they're giving very much βold reliable but also lowkey supersededβ energy. let's get into it π
π NAME π
Tcl_SplitPath, Tcl_JoinPath, Tcl_GetPathType β manipulate platform-dependent file paths. that's the whole vibe. β¨
β¨ 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)β the file path, in whatever form is appropriate for the current platform. if you need the acceptable forms for path names, go peek at thefilenamemanual entry. π¦Tcl_Size | int *argcPtr (out)β gets filled in with the number of path elements inpath. you can pass(Tcl_Size *)NULLif you're not using it. if it points to a variable whose type is notTcl_Size, a compiler warning will be generated. if your extension 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. yes bestie, crash. πconst char ***argvPtr (out)β*argvPtrgets 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)β number of elements inargv. πconst char *const *argv (in)β 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 π¦
first things first, bestie: these procedures have been superseded by the Tcl-value-aware procedures in the FileSystem man page, which are more efficient. so like, they still exist and they still work, but the newer ones are the main characters now. periodt.
these procedures may be used to disassemble and reassemble file paths in a platform independent manner. they give you C-level access to the same functionality as the file split, file join, and file pathtype commands. iykyk.
Tcl_SplitPath breaks a path into its constituent elements, returning an array of pointers to the elements using argcPtr and argvPtr. the area of memory pointed to by *argvPtr is dynamically allocated; in addition to the array of pointers, it also holds copies of all the path elements. it is the caller's responsibility to free all of this storage. no cap. for example, suppose that you have called Tcl_SplitPath with the following code:
Tcl_Size argc;
char *path;
char **argv;
...
Tcl_SplitPath(string, &argc, &argv);
then you should eventually free the storage with a call like the following:
Tcl_Free(argv);
Tcl_JoinPath is 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. resultPtr must refer to an initialized Tcl_DString. π«Ά
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. this is because Tcl_SplitPath and Tcl_JoinPath eliminate duplicate path separators and return a normalized form for each platform. so it's the same spot, just a glow-up. π
Tcl_GetPathType returns the type of the specified path, where Tcl_PathType is one of TCL_PATH_ABSOLUTE, TCL_PATH_RELATIVE, or TCL_PATH_VOLUME_RELATIVE. see the filename manual entry for a description of the path types for each platform. π
π₯ KEYWORDS π₯
file, filename, join, path, split, type β that's the tag cloud, bestie. π·οΈ
and that's the page! source/version: Tcl 7.5, manual: Tcl_SplitPath(3). stay slay, free your memory, and don't let the duplicate separators catch you lacking. π
π¦ 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) 1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms