file_demo.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Dec 2008 17:58:15 +0100
changeset 22 0db9235d68d9
parent 9 c3fecc82ade6
child 27 81a574d60c15
permissions -rw-r--r--
mysql_db is untested because we have no sponsor with a mysql database committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * test/demos/file_demo.c
 * Copyright (C) 2008 Markus Broeker
 */

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

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 EXIT_SUCCESS;
}