doc: MWE for ucx_stream_copy()

Wed, 02 May 2018 18:42:04 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 02 May 2018 18:42:04 +0200
changeset 279
ee37b179e597
parent 278
7b9170c22786
child 280
6e3c4036a80c

doc: MWE for ucx_stream_copy()

docs/src/modules.md file | annotate | diff | comparison | revisions
--- a/docs/src/modules.md	Wed May 02 18:10:00 2018 +0200
+++ b/docs/src/modules.md	Wed May 02 18:42:04 2018 +0200
@@ -288,3 +288,35 @@
 We also provide several `printf` variants to conveniently print formatted data
 to streams or strings.
 
+### A simple copy program
+
+The utilities package provides several stream copy functions.
+One of them has a very simple interface and can, for instance, be used to copy
+whole files in a single call.
+This is a minimal working example:
+```C
+#include <stdio.h>
+#include <ucx/utils.h>
+
+int main(int argc, char** argv) {
+
+    if (argc != 3) {
+        fprintf(stderr, "Use %s <src> <dest>", argv[0]);
+        return 1;
+    }
+
+    FILE *srcf = fopen(argv[1], "r");     // insert error handling on your own
+    FILE *destf = fopen(argv[2], "w");
+    
+    size_t n =  ucx_stream_copy(srcf, destf, fread, fwrite);
+    printf("%zu bytes copied.\n", n);
+
+    fclose(srcf);
+    fclose(destf);
+
+
+    return 0;
+}
+```
+
+

mercurial