File: umovestr_cached.c

package info (click to toggle)
strace 6.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 64,424 kB
  • sloc: ansic: 160,349; sh: 9,223; makefile: 3,817; cpp: 944; awk: 353; perl: 267; exp: 62; sed: 9
file content (47 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Check effectiveness of umovestr memory caching.
 *
 * Copyright (c) 2019-2021 Dmitry V. Levin <ldv@strace.io>
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "tests.h"

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/uio.h>

int
main(void)
{
	char *const buf = tail_alloc(DEFAULT_STRLEN);
	fill_memory_ex(buf, DEFAULT_STRLEN, 'a', 'z' - 'a' + 1);

	struct iovec *const io = tail_alloc(sizeof(*io) * DEFAULT_STRLEN);
	for (unsigned int i = 0; i < DEFAULT_STRLEN; ++i) {
		io[i].iov_base = buf + DEFAULT_STRLEN - i;
		io[i].iov_len = i;
	}

	tprintf("%s", "");

	int rc = writev(-1, io, DEFAULT_STRLEN);
	const char *errstr = sprintrc(rc);

	tprintf("writev(-1, [");
	for (unsigned int i = 0; i < DEFAULT_STRLEN; ++i) {
		if (i)
			tprintf(", ");
		tprintf("{iov_base=\"%.*s\", iov_len=%u}",
			(int) io[i].iov_len,
			(char *) io[i].iov_base,
			(unsigned int) io[i].iov_len);
	}
	tprintf("], %u) = %s\n", DEFAULT_STRLEN, errstr);

	tprintf("+++ exited with 0 +++\n");
	return 0;
}