1Tcl_Access(3) Tcl Library Procedures Tcl_Access(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_Access, Tcl_Stat - check file permissions and other attributes
9
11 #include <tcl.h>
12
13 int
14 Tcl_Access(path, mode)
15
16 int
17 Tcl_Stat(path, statPtr)
18
20 char *path (in) Native name of the file to check the
21 attributes of.
22
23 int mode (in) Mask consisting of one or more of
24 R_OK, W_OK, X_OK and F_OK. R_OK,
25 W_OK and X_OK request checking
26 whether the file exists and has
27 read, write and execute permis‐
28 sions, respectively. F_OK just
29 requests checking for the existence
30 of the file.
31
32 struct stat *statPtr (out) The structure that contains the
33 result.
34_________________________________________________________________
35
36
38 As of Tcl 8.4, the object-based APIs Tcl_FSAccess and Tcl_FSStat should
39 be used in preference to Tcl_Access and Tcl_Stat, wherever possible.
40
41 There are two reasons for calling Tcl_Access and Tcl_Stat rather than
42 calling system level functions access and stat directly. First, the
43 Windows implementation of both functions fixes some bugs in the system
44 level calls. Second, both Tcl_Access and Tcl_Stat (as well as
45 Tcl_OpenFileChannelProc) hook into a linked list of functions. This
46 allows the possibility to reroute file access to alternative media or
47 access methods.
48
49 Tcl_Access checks whether the process would be allowed to read, write
50 or test for existence of the file (or other file system object) whose
51 name is pathname. If pathname is a symbolic link on Unix, then per‐
52 missions of the file referred by this symbolic link are tested.
53
54 On success (all requested permissions granted), zero is returned. On
55 error (at least one bit in mode asked for a permission that is denied,
56 or some other error occurred), -1 is returned.
57
58 Tcl_Stat fills the stat structure statPtr with information about the
59 specified file. You do not need any access rights to the file to get
60 this information but you need search rights to all directories named in
61 the path leading to the file. The stat structure includes info regard‐
62 ing device, inode (always 0 on Windows), privilege mode, nlink (always
63 1 on Windows), user id (always 0 on Windows), group id (always 0 on
64 Windows), rdev (same as device on Windows), size, last access time,
65 last modification time, and creation time.
66
67 If path exists, Tcl_Stat returns 0 and the stat structure is filled
68 with data. Otherwise, -1 is returned, and no stat info is given.
69
70
72 stat, access
73
74
75
76
77Tcl 8.1 Tcl_Access(3)