Wed, 02 May 2018 18:42:04 +0200
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; +} +``` + +