token_t * gen_arbitrary(void) { int count, i, print, size, type; token_t *tok; uint8_t *buf; /* Choose the output format. */ print = random() % (sizeof(print_vals) / sizeof(int)); print = print_vals[print]; /* Choose a data type. */ type = random() % (sizeof(type_vals) / sizeof(int)); type = type_vals[type]; /* Determine the size associated with that type. */ switch (type) { case AUR_BYTE: size = AUR_BYTE_SIZE; break; case AUR_SHORT: size = AUR_SHORT_SIZE; break; case AUR_INT32: size = AUR_INT32_SIZE; break; case AUR_INT64: size = AUR_INT64_SIZE; break; } /* Choose the length of the data. */ /* XXX-MAK: Should use symbolic constants. */ /* XXX-MAK: Any larger of a count and au_to_data() segfaults. */ count = random() % (256 - 4); /* Generate the random data. */ buf = malloc(count * size); if (buf == NULL) err(1, "[malloc]"); for (i = 0; i < count * size; i++) /* XXX-MAK: Should use symbolic constants. */ buf[i] = random() % 256; /* Create token. */ tok = au_to_data(print, type, count, (char *) buf); /* Clean up. */ free(buf); return (tok); }
static void generate_data_record(const char *directory, const char *record_filename) { token_t *data_token; data_token = au_to_data(data_token_unit_print, data_token_unit_type, data_token_unit_count, data_token_data); if (data_token == NULL) err(EX_UNAVAILABLE, "au_to_data"); write_record(directory, record_filename, data_token, AUE_NULL); }