or as number in C language
How to get the file permission on unix in C language?
Use the stat system call.
Listed are the required parts:
#include %26lt;stdio.h%26gt;
#include %26lt;sys/types.h%26gt;
#include %26lt;sys/stat.h%26gt;
struct stat stat_buf;
if ( stat( "File Name", %26amp;stat_buf) == -1)
{
exit (1);
}
printf("Permissions: %o\n", stat_buf.st_mode %26amp; 0777);
Reply:The easiest way is with the stat system-call - that will also give you timestamps, file size, and ownership as well as the protection mode.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment