docs/src/modules.md

changeset 279
ee37b179e597
parent 277
f819fe5e20f5
child 280
6e3c4036a80c
equal deleted inserted replaced
278:7b9170c22786 279:ee37b179e597
286 In this module we provide very general utility function for copy and compare 286 In this module we provide very general utility function for copy and compare
287 operations. 287 operations.
288 We also provide several `printf` variants to conveniently print formatted data 288 We also provide several `printf` variants to conveniently print formatted data
289 to streams or strings. 289 to streams or strings.
290 290
291 ### A simple copy program
292
293 The utilities package provides several stream copy functions.
294 One of them has a very simple interface and can, for instance, be used to copy
295 whole files in a single call.
296 This is a minimal working example:
297 ```C
298 #include <stdio.h>
299 #include <ucx/utils.h>
300
301 int main(int argc, char** argv) {
302
303 if (argc != 3) {
304 fprintf(stderr, "Use %s <src> <dest>", argv[0]);
305 return 1;
306 }
307
308 FILE *srcf = fopen(argv[1], "r"); // insert error handling on your own
309 FILE *destf = fopen(argv[2], "w");
310
311 size_t n = ucx_stream_copy(srcf, destf, fread, fwrite);
312 printf("%zu bytes copied.\n", n);
313
314 fclose(srcf);
315 fclose(destf);
316
317
318 return 0;
319 }
320 ```
321
322

mercurial