Tcl_Access(3tcl)
π Tcl_Access β check file permissions & other attributes π
okay bestie so we're in the 3tcl manual, Tcl Library Procedures section, and today's main characters are Tcl_Access and Tcl_Stat. yes they're giving slightly retro, but they still eat. let's get into it π«Ά
β¨ NAME β¨
Tcl_Access, Tcl_Stat β check file permissions and other attributes
πΈ SYNOPSIS πΈ
#include <tcl.h>
int
Tcl_Access(path, mode)
int
Tcl_Stat(path, statPtr)
π ARGUMENTS π
const char *path(in) β the native name of the file whose attributes we're checking. literally just the path, girl.int mode(in) β a mask made of one or more ofR_OK,W_OK,X_OKandF_OK. so like:R_OK,W_OKandX_OKare asking "does this file exist and can I read / write / execute it?" respectively, andF_OKis just "does the file even exist tho".struct stat *statPtr(out) β the structure that holds the result. it gets filled in for you, she's an output param π
π¦ DESCRIPTION π¦
so the object-based APIs Tcl_FSAccess and Tcl_FSStat should be used in preference to Tcl_Access and Tcl_Stat, wherever possible. like, if you can, use those ones. why? because those functions also support Tcl's virtual filesystem layer, and these two do not. no cap.
π OBSOLETE FUNCTIONS π
there are two reasons you might call Tcl_Access and Tcl_Stat instead of calling the system level functions access and stat directly:
- the Windows implementation of both functions fixes some bugs in the system level calls. so on Windows, these are actually doing you a solid.
- both
Tcl_AccessandTcl_Stat(as well asTcl_OpenFileChannelProc) hook into a linked list of functions. which means there's the possibility to reroute file access to alternative media or access methods. iconic, honestly.
Tcl_Access checks whether the process would be allowed to read, write or test for existence of the file (or other file system object) whose name is path. heads up: if path is a symbolic link on Unix, then the permissions of the file referred by this symbolic link are tested. (so it's following the link, not judging the link itself, iykyk)
on success (all requested permissions granted), zero is returned. π on error β meaning at least one bit in mode asked for a permission that is denied, or some other error occurred β -1 is returned. π
Tcl_Stat fills the stat structure statPtr with information about the specified file. plot twist: you do not need any access rights to the file to get this information, but you do need search rights to all directories named in the path leading to the file. so the vibes of the parent directories matter.
the stat structure includes info regarding:
- device
- inode (always
0on Windows) - privilege mode
- nlink (always
1on Windows) - user id (always
0on Windows) - group id (always
0on Windows) - rdev (same as device on Windows)
- size
- last access time
- last modification time
- creation time
if path exists, Tcl_Stat returns 0 and the stat structure is filled with data. otherwise, -1 is returned, and no stat info is given. π
π₯ KEYWORDS π₯
stat, access
π SEE ALSO π
Tcl_FSAccess(3tcl), Tcl_FSStat(3tcl)
okay that's the whole page, you're so welcome π this was Tcl version 8.1, from the Tcl Library Procedures manual, and the page is Tcl_Access(3tcl). go forth and check those permissions, bestie β you got this πβ¨
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1998-1999 Scriptics Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms