// WECP100/book/accessc.c 20240801
// description: access simple for check file permissions using system call, on LINUX
// machine: laptop window11
// os: linux using wsl on windows11
//> wsl >> Welcome to Ubuntu 22.04.2 LTS //on power shell
//$ cat /etc/os-release >> PRETTY_NAME="Ubuntu 22.04.2 LTS"
//$ uname -a >> inux LAPTOP-2E5CQCBT 6.6.36.3-microsoft-standard-WSL2 #1
// >> Sat Jun 29 07:01:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
// language: gcc --version >> gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
//$ nano text.txt 00 0123456789 ... 06 0123456789
//$ ls -la text.txt -rwxrwxrwx 1 pi pi 84 Jul 27 13:02 text.txt
//$ gcc accessc.c -o accessc
//$ ./accessc text.txt
//$ access:OK
#include< unistd.h> // for access
#include< stdio.h> // for perror() printf()
int main() {
int state =access("text.txt", R_OK|X_OK); // check read and execute permissions.
if (state < 0) perror("access"); //Uses perror to handle errors,
if (state ==0) printf("access:OK\n"); // saccess ccess
}
//--------------------------------------------------