/* Test opening of a file with O_DIRECT */ #include #include #include #include #include /* Note: DOES NOT HAVE O_DIRECT! */ /* is a glibc header... */ #include #include int main(void) { char message[] = "Welcome to the winter of my discontent.\n"; int fd = open("testopen.txt", O_RDWR|O_CREAT|O_SYNC|O_DIRECT, S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR); int len; if(fd < 0) { printf("Unable to open file, errno is %d.\n", errno); } else { printf("Got fd %d.\n", fd); if((len = write(fd, message, strlen(message))) < 0) { printf("Unable to write to file, len is %d, errno is %d.\n", len, errno); } else { printf("%d bytes written to file.\n", len); } } close(fd); printf("End of program...\n"); return 0; }