c - How can I detect the file is forbidden when using open() in linux -


what open() return when try open file without permisson?

when error occurs while using open function, file descriptor set -1.

to find out specific error need check errno. (this have different values depending on error occurred) in case eaccess.

this code,

fd = open ("file.txt",o_rdonly);  if (fd == -1) {     if (errno == eacces)     {         printf ("permission denied \n");     } } 

hope helps!


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -