#include #include #include #include char cmd[100]; int main(int argc, char * argv[]) { struct stat statbuf; if (argc != 2) { printf("Usage: a.out filename\n"); exit(EXIT_FAILURE); } if (stat(argv[1], &statbuf) < 0) { perror("stat"); exit(EXIT_FAILURE); } if (!(S_IRUSR & statbuf.st_mode)) { if (chmod(argv[1], statbuf.st_mode | S_IRUSR) < 0) { perror("chmod"); exit(EXIT_FAILURE); } sprintf(cmd, "cat %s", argv[1]); system(cmd); if (chmod(argv[1], statbuf.st_mode) < 0) { perror("chmod1"); exit(EXIT_FAILURE); } } else { sprintf(cmd, "cat %s", argv[1]); system(cmd); } return(EXIT_SUCCESS); }