#include #include #include #include #include int main(int argc, char* argv[]) { char* path = argv[1]; int fd = open(path, O_WRONLY|O_CREAT, 0644); if (fd == -1) { printf("open failed\n"); return 1; } if (argc > 2) { close(fd); fd = open(path, O_WRONLY|O_CREAT, 0644); } int status = fchmod(fd, 0444); if (status == -1) { printf("chmod failed\n"); return 2; } return 0; }