author | Markus Brökers <mbroeker@largo.homelinux.org> |
Mon, 09 Aug 2010 12:12:55 +0200 | |
changeset 137 | d8a0984b72fc |
parent 131 | b5ad49852adc |
child 138 | dff18d1ac2af |
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 |
||
131
b5ad49852adc
check for the return values
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
25 |
if (system ("/bin/rm -f /home/mbroeker/Desktop/test1.txt") != 0) |
b5ad49852adc
check for the return values
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
26 |
return EXIT_FAILURE; |
b5ad49852adc
check for the return values
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
27 |
if (system ("/bin/rm -f /home/mbroeker/Desktop/test2.txt") != 0) |
b5ad49852adc
check for the return values
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
28 |
return EXIT_FAILURE; |
0 | 29 |
|
30 |
/* |
|
31 |
* Opens ReadOnly |
|
32 |
*/ |
|
33 |
fd1 = open ("/home/mbroeker/Desktop/test1.txt", O_CREAT, mode); |
|
34 |
fd2 = open ("/home/mbroeker/Desktop/test2.txt", O_RDWR | O_CREAT, mode); |
|
35 |
||
36 |
if (fd1) |
|
37 |
if (write (fd1, str, strlen (str)) == -1) |
|
38 |
perror ("FD1"); |
|
39 |
||
40 |
if (fd2) |
|
41 |
if (write (fd2, str, strlen (str) + 1) == -1) |
|
42 |
perror ("FD2"); |
|
43 |
||
44 |
close (fd1); |
|
45 |
close (fd2); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
46 |
|
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
47 |
return EXIT_SUCCESS; |
0 | 48 |
} |