This program must compile with basic gcc function within linux. Update the progr
ID: 3635231 • Letter: T
Question
This program must compile with basic gcc function within linux.Update the program to display the file size, owner ID, and file permission of the file.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
struct stat buf;
if (stat(argv[1], &buf) < 0 ) {
printf("Error ");
exit(-1);
}
if (S_ISREG(buf.st_mode))
{
printf("%s: regular file ", argv[1]);
}
else if (S_ISDIR(buf.st_mode))
{
printf("%s: directory ", argv[1]);
}
else
{
printf("%s: unknown type ", argv[1]);
}
return 0;
}
Explanation / Answer
Dear... #include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <stdlib.h>#include <stdio.h>int main(int argc, char *argv[]){struct stat buf;if (stat(argv[1], &buf) < 0 ) {printf("Error ");exit(-1);}if (S_ISREG(buf.st_mode)){printf("%s: regular file ", argv[1]);}else if (S_ISDIR(buf.st_mode)){printf("%s: directory ", argv[1]);}else{printf("%s: unknown type ", argv[1]);} return 0;} Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.