Tutorials/C Programming Tutorial/Syscall open o direct.cpp

From ThorstensHome
Jump to: navigation, search

write.c

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
  int* i;
  i=(int*)malloc(512);
  int fh;
  fh=open("/tmp/test",O_DIRECT|O_WRONLY);
  write(fh,i,512);
  close(fh);
}

How to compile

tweedleburg:~/blktest # g++ write.c
tweedleburg:~/blktest # gcc write.c
write.c: In function ‘main’:
write.c:13:23: error: ‘O_DIRECT’ undeclared (first use in this function)
write.c:13:23: note: each undeclared identifier is reported only once for each function it appears in
tweedleburg:~/blktest # gcc -D_GNU_SOURCE write.c
tweedleburg:~/blktest # 

See also

http://kb.fusionio.com/KB/a45/programming-using-direct-io.aspx

Template:Stub