Files
dnf-utils/sgutil/sgu_mode_rand_insert.h
T
2025-09-01 20:47:58 +08:00

22 lines
1.3 KiB
C

#pragma once
/**
* Inserts random data segments at random positions within an input file and writes the result to an output file.
*
* @param inputFileName The path to the input file to be processed.
* @param outputFileName The path to the output file to write the modified content.
* @param minSize The minimum size (in bytes) of each random data segment to insert.
* @param maxSize The maximum size (in bytes) of each random data segment to insert.
* @param counts The number of random data segments to insert.
* @return true if the operation succeeds; false otherwise.
*
* The function performs the following steps:
* 1. Validates input parameters and file names.
* 2. Opens the input file for reading and the output file for writing in binary mode.
* 3. Determines random insertion offsets within the input file.
* 4. For each offset, copies data from the input file up to the offset, then inserts a randomly sized segment filled with random data.
* 5. After all insertions, copies any remaining data from the input file to the output file.
* 6. Returns true on success, or false if any error occurs during processing.
*/
bool insertRandomDataInFile(const char* inputFileName, const char* outputFileName, int64_t minSize, int64_t maxSize, int32_t counts);