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
     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 +

mercurial