author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:58:13 +0100 | |
changeset 20 | 5fec678f931b |
parent 9 | c3fecc82ade6 |
child 27 | 81a574d60c15 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
2 |
* test/demos/file_demo.c |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
*/ |
5 |
||
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
8 |
#include <unistd.h> |
|
9 |
#include <sys/types.h> |
|
10 |
#include <string.h> |
|
11 |
#include <fcntl.h> |
|
12 |
||
13 |
int main (int argc, char **argv) |
|
14 |
{ |
|
15 |
int fd1; |
|
16 |
int fd2; |
|
17 |
int mode; |
|
18 |
char *str = "Schreib mal was!"; |
|
19 |
||
20 |
if (argc != 2) |
|
21 |
return -1; |
|
22 |
mode = strtoul (argv[1], NULL, 8); |
|
23 |
||
24 |
system ("/bin/rm -f /home/mbroeker/Desktop/test1.txt"); |
|
25 |
system ("/bin/rm -f /home/mbroeker/Desktop/test2.txt"); |
|
26 |
||
27 |
/* |
|
28 |
* Opens ReadOnly |
|
29 |
*/ |
|
30 |
fd1 = open ("/home/mbroeker/Desktop/test1.txt", O_CREAT, mode); |
|
31 |
fd2 = open ("/home/mbroeker/Desktop/test2.txt", O_RDWR | O_CREAT, mode); |
|
32 |
||
33 |
if (fd1) |
|
34 |
if (write (fd1, str, strlen (str)) == -1) |
|
35 |
perror ("FD1"); |
|
36 |
||
37 |
if (fd2) |
|
38 |
if (write (fd2, str, strlen (str) + 1) == -1) |
|
39 |
perror ("FD2"); |
|
40 |
||
41 |
close (fd1); |
|
42 |
close (fd2); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
43 |
|
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
44 |
return EXIT_SUCCESS; |
0 | 45 |
} |