2 * Test printpath/umovestr.
4 * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2017-2018 The strace developers.
8 * SPDX-License-Identifier: GPL-2.0-or-later
18 #include "test_ucopy.h"
21 test_printpath_at(char *const p, const unsigned int test_max)
33 char *const eop = p + (test_max - 1);
36 for (i = 1; i < test_max; ++i) {
37 const unsigned int i_1 = i - 1;
38 memmove(eop - i, eop - i_1, i_1);
39 eop[-1] = "/.."[i_1 % 3];
41 perror_msg_and_fail("chdir");
42 printf("chdir(\"%s\") = 0\n", eop - i);
47 test_efault(const unsigned int test_max)
49 char *p = tail_alloc(test_max);
50 const char *const efault = p + test_max;
51 memset(p, '/', test_max);
53 for (; p <= efault; ++p) {
54 if (p <= efault - PATH_MAX)
56 printf("chdir(%p) = %s\n", p, sprintrc(chdir(p)));
61 test_enametoolong(void)
63 char *p = tail_alloc(PATH_MAX);
64 memset(p, '/', PATH_MAX);
66 printf("chdir(\"%.*s\"...) = %s\n",
67 PATH_MAX - 1, p, sprintrc(chdir(p)));
71 test_printpath(const unsigned int test_max)
82 const unsigned int page_size = get_page_size();
83 char *p = tail_alloc(test_max + page_size);
85 for (i = 1; i < sizeof(long); ++i)
86 test_printpath_at(p + i, test_max);
87 for (i = 0; i < sizeof(long); ++i)
88 test_printpath_at(p + page_size - i, test_max);
89 test_efault(test_max);