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

c++ - Do gcc's __float128 floating point numbers take the current rounding mode into account? -

java - the value of local variable is not used -