Question: Develop a program that accepts one command line argument, permissions in octal numbers such as 764, and outputs the permissions in letter format, (Taking the
Develop a program that accepts one command line argument, permissions in octal numbers such as 764, and outputs the permissions in letter format, (Taking the octal number and convert it to the read, write and execute permissions)
for example, rwxrw-r-- of 764. Assume the executable file is a.out. Your running demo is as below.
opus:~ $./a.out 764
rwxrw-r--
Example code)
#include
if (argc > 1) { if ((stat(argv[1], &buff) != -1)) { /*address op*/ printf("Permissions for %s ", argv[1]); for (i=3; i; --i) { printf("%3s", perm[(buff.st_mode & mask)>>(i-1)*N_BITS]); mask >>= N_BITS; /*right shift*/ perm[6],perm[4],perm[4] }/*mask=mask>>N_BITS;*/ putchar(' '); } else { perror(argv[1]); exit(1); } } else { fprintf(stderr, "Usage: %s file_name ", argv[0]); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
