1 /*
2 * Check printing of file name in strace -y mode.
3 *
4 * Copyright (c) 2018-2021 The strace developers.
5 * All rights reserved.
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10 #include "tests.h"
11
12 #include <fcntl.h>
13 #include <limits.h>
14 #include <stdio.h>
15 #include <unistd.h>
16
17 int
18 main(void)
19 {
20 skip_if_unavailable("/proc/self/fd/");
21
22 char dir[PATH_MAX + 1];
23
24 const struct {
25 const char *path;
26 const char *cstr;
27 const char *fdstr;
28 } checks[] = {
29 { ARG_STR("\1\0020\v\0047\f\58\t\79\n\10\0171\r\0167\218\37 \\\'\"<<0::0>>1~\177\200\377"),
30 "\\1\\0020\\v\\0047\\f\\58\\t\\79\\n\\10\\0171\\r\\0167"
31 "\\218\\37 \\\\\'\\\"\\74\\0740::0\\76\\0761~\\177\\200\\377" },
32 };
33
34 if (!getcwd(dir, sizeof(dir)))
35 perror_msg_and_fail("getcwd");
36
37 for (unsigned int i = 0; i < ARRAY_SIZE(checks); i++) {
38 long fd = open(checks[i].path, O_RDONLY|O_CREAT, 0600);
39 if (fd < 0)
40 perror_msg_and_fail("open(%s)", checks[i].cstr);
41
42 int rc = fsync(fd);
43
44 printf("fsync(%ld<", fd);
45 print_quoted_string_ex(dir, false, ">:");
46 printf("/%s>) = %s\n", checks[i].fdstr, sprintrc(rc));
47
48 close(fd);
49 }
50
51 puts("+++ exited with 0 +++");
52 return 0;
53 }