Wed, 02 May 2018 18:42:04 +0200
doc: MWE for ucx_stream_copy()
docs/src/modules.md | file | annotate | diff | comparison | revisions |
1.1 --- a/docs/src/modules.md Wed May 02 18:10:00 2018 +0200 1.2 +++ b/docs/src/modules.md Wed May 02 18:42:04 2018 +0200 1.3 @@ -288,3 +288,35 @@ 1.4 We also provide several `printf` variants to conveniently print formatted data 1.5 to streams or strings. 1.6 1.7 +### A simple copy program 1.8 + 1.9 +The utilities package provides several stream copy functions. 1.10 +One of them has a very simple interface and can, for instance, be used to copy 1.11 +whole files in a single call. 1.12 +This is a minimal working example: 1.13 +```C 1.14 +#include <stdio.h> 1.15 +#include <ucx/utils.h> 1.16 + 1.17 +int main(int argc, char** argv) { 1.18 + 1.19 + if (argc != 3) { 1.20 + fprintf(stderr, "Use %s <src> <dest>", argv[0]); 1.21 + return 1; 1.22 + } 1.23 + 1.24 + FILE *srcf = fopen(argv[1], "r"); // insert error handling on your own 1.25 + FILE *destf = fopen(argv[2], "w"); 1.26 + 1.27 + size_t n = ucx_stream_copy(srcf, destf, fread, fwrite); 1.28 + printf("%zu bytes copied.\n", n); 1.29 + 1.30 + fclose(srcf); 1.31 + fclose(destf); 1.32 + 1.33 + 1.34 + return 0; 1.35 +} 1.36 +``` 1.37 + 1.38 +