author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Fri, 27 Dec 2013 16:00:09 +0100 | |
changeset 167 | 7c6b221900bf |
parent 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 |
||
138
dff18d1ac2af
Compatibility: We support Linux and BSD
Markus Brökers <mbroeker@largo.homelinux.org>
parents:
131
diff
changeset
|
13 |
#define TESTFILE1 "/tmp/test1.txt" |
dff18d1ac2af
Compatibility: We support Linux and BSD
Markus Brökers <mbroeker@largo.homelinux.org>
parents:
131
diff
changeset
|
14 |
#define TESTFILE2 "/tmp/test2.txt" |
dff18d1ac2af
Compatibility: We support Linux and BSD
Markus Brökers <mbroeker@largo.homelinux.org>
parents:
131
diff
changeset
|
15 |
|
0 | 16 |
int main (int argc, char **argv) |
17 |
{ |
|
18 |
int fd1; |
|
19 |
int fd2; |
|
20 |
int mode; |
|
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
21 |
|
0 | 22 |
char *str = "Schreib mal was!"; |
23 |
||
138
dff18d1ac2af
Compatibility: We support Linux and BSD
Markus Brökers <mbroeker@largo.homelinux.org>
parents:
131
diff
changeset
|
24 |
if (argc != 2) { |
dff18d1ac2af
Compatibility: We support Linux and BSD
Markus Brökers <mbroeker@largo.homelinux.org>
parents:
131
diff
changeset
|
25 |
printf ("Usage: %s <MODE>\n", argv[0]); |
0 | 26 |
return -1; |
138
dff18d1ac2af
Compatibility: We support Linux and BSD
Markus Brökers <mbroeker@largo.homelinux.org>
parents:
131
diff
changeset
|
27 |
} |
0 | 28 |
mode = strtoul (argv[1], NULL, 8); |
29 |
||
138
dff18d1ac2af
Compatibility: We support Linux and BSD
Markus Brökers <mbroeker@largo.homelinux.org>
parents:
131
diff
changeset
|
30 |
unlink (TESTFILE1); |
dff18d1ac2af
Compatibility: We support Linux and BSD
Markus Brökers <mbroeker@largo.homelinux.org>
parents:
131
diff
changeset
|
31 |
unlink (TESTFILE2); |
0 | 32 |
|
33 |
/* |
|
34 |
* Opens ReadOnly |
|
35 |
*/ |
|
138
dff18d1ac2af
Compatibility: We support Linux and BSD
Markus Brökers <mbroeker@largo.homelinux.org>
parents:
131
diff
changeset
|
36 |
fd1 = open (TESTFILE1, O_CREAT, mode); |
dff18d1ac2af
Compatibility: We support Linux and BSD
Markus Brökers <mbroeker@largo.homelinux.org>
parents:
131
diff
changeset
|
37 |
fd2 = open (TESTFILE2, O_RDWR | O_CREAT, mode); |
0 | 38 |
|
39 |
if (fd1) |
|
40 |
if (write (fd1, str, strlen (str)) == -1) |
|
41 |
perror ("FD1"); |
|
42 |
||
43 |
if (fd2) |
|
44 |
if (write (fd2, str, strlen (str) + 1) == -1) |
|
45 |
perror ("FD2"); |
|
46 |
||
47 |
close (fd1); |
|
48 |
close (fd2); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
49 |
|
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
50 |
return EXIT_SUCCESS; |
0 | 51 |
} |