file_demo.c
changeset 0 af501b0c1716
child 8 96d16dfe787a
equal deleted inserted replaced
-1:000000000000 0:af501b0c1716
       
     1 /**
       
     2  *     $Id: file_demo.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $
       
     3  * $Source: /development/c/demos/file_demo.c,v $
       
     4  *
       
     5  */
       
     6 
       
     7 #include <stdio.h>
       
     8 #include <stdlib.h>
       
     9 #include <unistd.h>
       
    10 #include <sys/types.h>
       
    11 #include <string.h>
       
    12 #include <fcntl.h>
       
    13 
       
    14 int main (int argc, char **argv)
       
    15 {
       
    16     int fd1;
       
    17     int fd2;
       
    18     int mode;
       
    19     char *str = "Schreib mal was!";
       
    20 
       
    21     if (argc != 2)
       
    22         return -1;
       
    23     mode = strtoul (argv[1], NULL, 8);
       
    24 
       
    25     system ("/bin/rm -f /home/mbroeker/Desktop/test1.txt");
       
    26     system ("/bin/rm -f /home/mbroeker/Desktop/test2.txt");
       
    27 
       
    28     /*
       
    29      * Opens ReadOnly
       
    30      */
       
    31     fd1 = open ("/home/mbroeker/Desktop/test1.txt", O_CREAT, mode);
       
    32     fd2 = open ("/home/mbroeker/Desktop/test2.txt", O_RDWR | O_CREAT, mode);
       
    33 
       
    34     if (fd1)
       
    35         if (write (fd1, str, strlen (str)) == -1)
       
    36             perror ("FD1");
       
    37 
       
    38     if (fd2)
       
    39         if (write (fd2, str, strlen (str) + 1) == -1)
       
    40             perror ("FD2");
       
    41 
       
    42     close (fd1);
       
    43     close (fd2);
       
    44     return 0;
       
    45 }