diff --git a/file_demo.c b/file_demo.c new file mode 100644 --- /dev/null +++ b/file_demo.c @@ -0,0 +1,45 @@ +/** + * $Id: file_demo.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $ + * $Source: /development/c/demos/file_demo.c,v $ + * + */ + +#include +#include +#include +#include +#include +#include + +int main (int argc, char **argv) +{ + int fd1; + int fd2; + int mode; + char *str = "Schreib mal was!"; + + if (argc != 2) + return -1; + mode = strtoul (argv[1], NULL, 8); + + system ("/bin/rm -f /home/mbroeker/Desktop/test1.txt"); + system ("/bin/rm -f /home/mbroeker/Desktop/test2.txt"); + + /* + * Opens ReadOnly + */ + fd1 = open ("/home/mbroeker/Desktop/test1.txt", O_CREAT, mode); + fd2 = open ("/home/mbroeker/Desktop/test2.txt", O_RDWR | O_CREAT, mode); + + if (fd1) + if (write (fd1, str, strlen (str)) == -1) + perror ("FD1"); + + if (fd2) + if (write (fd2, str, strlen (str) + 1) == -1) + perror ("FD2"); + + close (fd1); + close (fd2); + return 0; +}