git subrepo pull (merge) --force deps/libchdr
[pcsx_rearmed.git] / deps / libchdr / deps / zstd-1.5.6 / tests / loremOut.c
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under both the BSD-style license (found in the
6  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7  * in the COPYING file in the root directory of this source tree).
8  * You may select, at your option, one of the above-listed licenses.
9  */
10
11 /* Implementation notes:
12  * Generates a stream of Lorem ipsum paragraphs to stdout,
13  * up to the requested size, which can be very large (> 4 GB).
14  * Note that, beyond 1 paragraph, this generator produces
15  * a different content than LOREM_genBuffer (even when using same seed).
16  */
17
18 #include "loremOut.h"
19 #include <assert.h>
20 #include <stdio.h>
21 #include "lorem.h"    /* LOREM_genBlock */
22 #include "platform.h" /* Compiler options, SET_BINARY_MODE */
23
24 #define MIN(a, b) ((a) < (b) ? (a) : (b))
25 #define LOREM_BLOCKSIZE (1 << 10)
26 void LOREM_genOut(unsigned long long size, unsigned seed)
27 {
28     char buff[LOREM_BLOCKSIZE] = { 0 };
29     unsigned long long total   = 0;
30     size_t genBlockSize        = (size_t)MIN(size, LOREM_BLOCKSIZE);
31
32     /* init */
33     SET_BINARY_MODE(stdout);
34
35     /* Generate Ipsum text, one paragraph at a time */
36     while (total < size) {
37         size_t generated =
38                 LOREM_genBlock(buff, genBlockSize, seed++, total == 0, 0);
39         assert(generated <= genBlockSize);
40         total += generated;
41         assert(total <= size);
42         fwrite(buff,
43                1,
44                generated,
45                stdout); /* note: should check potential write error */
46         if (size - total < genBlockSize)
47             genBlockSize = (size_t)(size - total);
48     }
49     assert(total == size);
50 }