author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Tue, 09 Feb 2010 08:38:01 +0100 | |
changeset 109 | 3d84eda3f16f |
parent 77 | 49e0babccb23 |
child 131 | b5ad49852adc |
permissions | -rw-r--r-- |
0 | 1 |
/** |
77 | 2 |
* file_demo.c |
9
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; |
|
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
18 |
|
0 | 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); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
44 |
|
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
45 |
return EXIT_SUCCESS; |
0 | 46 |
} |