]> granicus.if.org Git - strace/blob - tests/truncate.c
d740227bed45949789f6b1f8802cc0b6030b70cb
[strace] / tests / truncate.c
1 /*
2  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  */
7
8 #include "tests.h"
9 #include <asm/unistd.h>
10
11 #ifdef __NR_truncate
12
13 # include <stdio.h>
14 # include <unistd.h>
15
16 int
17 main(void)
18 {
19         static const char fname[] = "truncate\nfilename";
20         static const char qname[] = "truncate\\nfilename";
21         const kernel_ulong_t len = (kernel_ulong_t) 0xdefaced0badc0deULL;
22         long rc;
23
24         if (sizeof(len) > sizeof(long))
25                 rc = truncate(fname, len);
26         else
27                 rc = syscall(__NR_truncate, fname, len);
28
29         printf("truncate(\"%s\", %llu) = %ld %s (%m)\n",
30                qname, (unsigned long long) len, rc, errno2name());
31
32         puts("+++ exited with 0 +++");
33         return 0;
34 }
35
36 #else
37
38 SKIP_MAIN_UNDEFINED("__NR_truncate")
39
40 #endif