1Tcl_SplitPath(3) Tcl Library Procedures Tcl_SplitPath(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_SplitPath, Tcl_JoinPath, Tcl_GetPathType - manipulate platform-
9 dependent file paths
10
12 #include <tcl.h>
13
14 Tcl_SplitPath(path, argcPtr, argvPtr)
15
16 char *
17 Tcl_JoinPath(argc, argv, resultPtr)
18
19 Tcl_PathType
20 Tcl_GetPathType(path)
21
23 const char *path (in) File path in a form appro‐
24 priate for the current plat‐
25 form (see the filename man‐
26 ual entry for acceptable
27 forms for path names).
28
29 int *argcPtr (out) Filled in with number of
30 path elements in path.
31
32 const char ***argvPtr (out) *argvPtr will be filled in
33 with the address of an array
34 of pointers to the strings
35 that are the extracted ele‐
36 ments of path. There will
37 be *argcPtr valid entries in
38 the array, followed by a
39 NULL entry.
40
41 int argc (in) Number of elements in argv.
42
43 const char *const *argv (in) Array of path elements to
44 merge together into a single
45 path.
46
47 Tcl_DString *resultPtr (in/out) A pointer to an initialized
48 Tcl_DString to which the
49 result of Tcl_JoinPath will
50 be appended.
51_________________________________________________________________
52
53
55 These procedures have been superceded by the objectified procedures in
56 the FileSystem man page, which are more efficient.
57
58 These procedures may be used to disassemble and reassemble file paths
59 in a platform independent manner: they provide C-level access to the
60 same functionality as the file split, file join, and file pathtype com‐
61 mands.
62
63 Tcl_SplitPath breaks a path into its constituent elements, returning an
64 array of pointers to the elements using argcPtr and argvPtr. The area
65 of memory pointed to by *argvPtr is dynamically allocated; in addition
66 to the array of pointers, it also holds copies of all the path ele‐
67 ments. It is the caller's responsibility to free all of this storage.
68 For example, suppose that you have called Tcl_SplitPath with the fol‐
69 lowing code:
70 int argc;
71 char *path;
72 char **argv;
73 ...
74 Tcl_SplitPath(string, &argc, &argv);
75 Then you should eventually free the storage with a call like the fol‐
76 lowing:
77 Tcl_Free((char *) argv);
78
79 Tcl_JoinPath is the inverse of Tcl_SplitPath: it takes a collection of
80 path elements given by argc and argv and generates a result string that
81 is a properly constructed path. The result string is appended to
82 resultPtr. ResultPtr must refer to an initialized Tcl_DString.
83
84 If the result of Tcl_SplitPath is passed to Tcl_JoinPath, the result
85 will refer to the same location, but may not be in the same form. This
86 is because Tcl_SplitPath and Tcl_JoinPath eliminate duplicate path sep‐
87 arators and return a normalized form for each platform.
88
89 Tcl_GetPathType returns the type of the specified path, where
90 Tcl_PathType is one of TCL_PATH_ABSOLUTE, TCL_PATH_RELATIVE, or
91 TCL_PATH_VOLUME_RELATIVE. See the filename manual entry for a descrip‐
92 tion of the path types for each platform.
93
94
96 file, filename, join, path, split, type
97
98
99
100Tcl 7.5 Tcl_SplitPath(3)