| 1 |
'\" |
| 2 |
'\" Copyright (c) 1998-1999 Scriptics Corporation |
| 3 |
'\" |
| 4 |
'\" See the file "license.terms" for information on usage and redistribution |
| 5 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 6 |
'\" |
| 7 |
.TH Tcl_Access 3 8.1 Tcl "Tcl Library Procedures" |
| 8 |
.so man.macros |
| 9 |
.BS |
| 10 |
.SH NAME |
| 11 |
Tcl_Access, Tcl_Stat \- check file permissions and other attributes |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
\fB#include <tcl.h>\fR |
| 15 |
.sp |
| 16 |
int |
| 17 |
\fBTcl_Access\fR(\fIpath\fR, \fImode\fR) |
| 18 |
.sp |
| 19 |
int |
| 20 |
\fBTcl_Stat\fR(\fIpath\fR, \fIstatPtr\fR) |
| 21 |
.SH ARGUMENTS |
| 22 |
.AS "struct stat" *statPtr out |
| 23 |
.AP "const char" *path in |
| 24 |
Native name of the file to check the attributes of. |
| 25 |
.AP int mode in |
| 26 |
Mask consisting of one or more of \fBR_OK\fR, \fBW_OK\fR, \fBX_OK\fR and |
| 27 |
\fBF_OK\fR. \fBR_OK\fR, \fBW_OK\fR and \fBX_OK\fR request checking whether the |
| 28 |
file exists and has read, write and execute permissions, respectively. |
| 29 |
\fBF_OK\fR just requests a check for the existence of the file. |
| 30 |
.AP "struct stat" *statPtr out |
| 31 |
The structure that contains the result. |
| 32 |
.BE |
| 33 |
.SH DESCRIPTION |
| 34 |
.PP |
| 35 |
As of Tcl 8.4, the object-based APIs \fBTcl_FSAccess\fR and \fBTcl_FSStat\fR |
| 36 |
should be used in preference to \fBTcl_Access\fR and \fBTcl_Stat\fR, wherever |
| 37 |
possible. Those functions also support Tcl's virtual filesystem layer, which |
| 38 |
these do not. |
| 39 |
.SS "OBSOLETE FUNCTIONS" |
| 40 |
.PP |
| 41 |
There are two reasons for calling \fBTcl_Access\fR and \fBTcl_Stat\fR rather |
| 42 |
than calling system level functions \fBaccess\fR and \fBstat\fR directly. |
| 43 |
First, the Windows implementation of both functions fixes some bugs in the |
| 44 |
system level calls. Second, both \fBTcl_Access\fR and \fBTcl_Stat\fR (as well |
| 45 |
as \fBTcl_OpenFileChannelProc\fR) hook into a linked list of functions. This |
| 46 |
allows the possibility to reroute file access to alternative media or access |
| 47 |
methods. |
| 48 |
.PP |
| 49 |
\fBTcl_Access\fR checks whether the process would be allowed to read, write or |
| 50 |
test for existence of the file (or other file system object) whose name is |
| 51 |
\fIpath\fR. If \fIpath\fR is a symbolic link on Unix, then permissions of the |
| 52 |
file referred by this symbolic link are tested. |
| 53 |
.PP |
| 54 |
On success (all requested permissions granted), zero is returned. On error (at |
| 55 |
least one bit in mode asked for a permission that is denied, or some other |
| 56 |
error occurred), -1 is returned. |
| 57 |
.PP |
| 58 |
\fBTcl_Stat\fR fills the stat structure \fIstatPtr\fR with information about |
| 59 |
the specified file. You do not need any access rights to the file to get this |
| 60 |
information but you need search rights to all directories named in the path |
| 61 |
leading to the file. The stat structure includes info regarding device, inode |
| 62 |
(always 0 on Windows), privilege mode, nlink (always 1 on Windows), user id |
| 63 |
(always 0 on Windows), group id (always 0 on Windows), rdev (same as device on |
| 64 |
Windows), size, last access time, last modification time, and creation time. |
| 65 |
.PP |
| 66 |
If \fIpath\fR exists, \fBTcl_Stat\fR returns 0 and the stat structure is |
| 67 |
filled with data. Otherwise, -1 is returned, and no stat info is given. |
| 68 |
.SH KEYWORDS |
| 69 |
stat, access |
| 70 |
.SH "SEE ALSO" |
| 71 |
Tcl_FSAccess(3), Tcl_FSStat(3) |