#include #include #include #include char cmd[100]; int main(int argc, char * argv[]) { struct stat statbuf; char c; 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_IWUSR & statbuf.st_mode)) { printf("a.out: remove write-protected regular file `%s'?", argv[1]); c = getchar(); if ((c == 'n') || (c == 'N')) { printf("File not removed.\n"); exit(EXIT_SUCCESS); } if (chmod(argv[1], statbuf.st_mode | S_IWUSR) < 0) { perror("chmod"); exit(EXIT_FAILURE); } sprintf(cmd, "rm %s", argv[1]); system(cmd); printf("File %s removed.\n", argv[1]); return(EXIT_SUCCESS); } }