2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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.
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).
21 #include "lorem.h" /* LOREM_genBlock */
22 #include "platform.h" /* Compiler options, SET_BINARY_MODE */
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)
28 char buff[LOREM_BLOCKSIZE] = { 0 };
29 unsigned long long total = 0;
30 size_t genBlockSize = (size_t)MIN(size, LOREM_BLOCKSIZE);
33 SET_BINARY_MODE(stdout);
35 /* Generate Ipsum text, one paragraph at a time */
36 while (total < size) {
38 LOREM_genBlock(buff, genBlockSize, seed++, total == 0, 0);
39 assert(generated <= genBlockSize);
41 assert(total <= size);
45 stdout); /* note: should check potential write error */
46 if (size - total < genBlockSize)
47 genBlockSize = (size_t)(size - total);
49 assert(total == size);