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