/* Copyright (C) 2008 Emmanuel Varoquaux This file is part of XOS. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include static char *program_name; static void die() { perror(program_name); _exit(1); } static void fail() { fprintf(stderr, "Failed !\n"); _exit(1); } int main(int argc, char **argv) { int fd; char buf[7]; program_name = argv[0]; printf("1\n"); printf("2\n"); if ((fd = open("dummy", O_RDWR | O_CREAT)) < 0) die(); printf("3\n"); if (remove("dummy") < 0) die(); printf("4\n"); if (open("dummy", O_RDONLY) >= 0) fail(); perror(program_name); printf("5\n"); if (write(fd, "hello!\n", 7) < 0) die(); printf("6\n"); if (read(fd, buf, 7) < 0) die(); printf("7\n"); close(fd); if (open("dummy", O_RDONLY) >= 0) fail(); perror(program_name); printf("8\n"); return 0; }