Tcl_SplitPath(3)

πŸ“¦
version 9.0.3 Β· 3 versions
, in alpine 3.23, alpine 3.24, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

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 the filename manual entry. πŸ¦‹
  • Tcl_Size | int *argcPtr (out) β€” gets filled in with the number of path elements in path. you can pass (Tcl_Size *)NULL if you're not using it. if it points to a variable whose type is not Tcl_Size, a compiler warning will be generated. if your extension is compiled with -DTCL_8_API, argcPtr will be filled with -1 for paths with more than INT_MAX elements (which should trigger proper error-handling); otherwise expect it to crash. yes bestie, crash. πŸ’€
  • const char ***argvPtr (out) β€” *argvPtr gets filled in with the address of an array of pointers to the strings that are the extracted elements of path. there will be *argcPtr valid entries in the array, followed by a NULL entry. 🌈
  • Tcl_Size argc (in) β€” number of elements in argv. πŸ’–
  • 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 initialized Tcl_DString to which the result of Tcl_JoinPath will 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