#include #include #include #include main(int argc, char **argv) { int p, u, f, m; if (argc != 4) { fprintf(stderr, "usage: q4 p m u\n"); exit(1); } p = O_WRONLY; if (strchr(argv[1], 'a') != NULL) p |= O_APPEND; if (strchr(argv[1], 'c') != NULL) p |= O_CREAT; if (strchr(argv[1], 't') != NULL) p |= O_TRUNC; if (strchr(argv[1], 'x') != NULL) p |= O_EXCL; sscanf(argv[2], "%o", &m); if (sscanf(argv[3], "%o", &u) == 1) umask(u); f = open("f1.txt", p, m); write(f, "XXX\n", 4); close(f); system("ls -l f1.txt"); chmod("f1.txt", 0644); system("cat f1.txt"); exit(0); }