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

Python Kivy ListView: How to delete selected ListItemButton? -

asp.net mvc 4 - A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name '' -