summaryrefslogtreecommitdiffstats
path: root/examples/mcp.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-27 11:51:08 +0200
committermanuel <manuel@mausz.at>2012-03-27 11:51:08 +0200
commit4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch)
tree868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /examples/mcp.c
parenteae0bd57f0a26314a94785061888d193d186944a (diff)
downloadprogos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz
progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2
progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip
reorganize file structure to match the upstream requirements
Diffstat (limited to 'examples/mcp.c')
-rw-r--r--examples/mcp.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/examples/mcp.c b/examples/mcp.c
new file mode 100644
index 0000000..6091dc8
--- /dev/null
+++ b/examples/mcp.c
@@ -0,0 +1,68 @@
1/* mcp.c
2
3 Copies one file to another, using mmap. */
4
5#include <stdio.h>
6#include <string.h>
7#include <syscall.h>
8
9int
10main (int argc, char *argv[])
11{
12 int in_fd, out_fd;
13 mapid_t in_map, out_map;
14 void *in_data = (void *) 0x10000000;
15 void *out_data = (void *) 0x20000000;
16 int size;
17
18 if (argc != 3)
19 {
20 printf ("usage: cp OLD NEW\n");
21 return EXIT_FAILURE;
22 }
23
24 /* Open input file. */
25 in_fd = open (argv[1]);
26 if (in_fd < 0)
27 {
28 printf ("%s: open failed\n", argv[1]);
29 return EXIT_FAILURE;
30 }
31 size = filesize (in_fd);
32
33 /* Create and open output file. */
34 if (!create (argv[2], size))
35 {
36 printf ("%s: create failed\n", argv[2]);
37 return EXIT_FAILURE;
38 }
39 out_fd = open (argv[2]);
40 if (out_fd < 0)
41 {
42 printf ("%s: open failed\n", argv[2]);
43 return EXIT_FAILURE;
44 }
45
46 /* Map files. */
47 in_map = mmap (in_fd, in_data);
48 if (in_map == MAP_FAILED)
49 {
50 printf ("%s: mmap failed\n", argv[1]);
51 return EXIT_FAILURE;
52 }
53 out_map = mmap (out_fd, out_data);
54 if (out_map == MAP_FAILED)
55 {
56 printf ("%s: mmap failed\n", argv[2]);
57 return EXIT_FAILURE;
58 }
59
60 /* Copy files. */
61 memcpy (out_data, in_data, size);
62
63 /* Unmap files (optional). */
64 munmap (in_map);
65 munmap (out_map);
66
67 return EXIT_SUCCESS;
68}