This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19 #include <unistd.h>
20
21 #include "signature.h"
22 SIGNATURE_CHECK (truncate, int, (const char *, off_t));
23
24 #include <errno.h>
25 #include <fcntl.h>
26
27 #include "ignore-value.h"
28 #include "macros.h"
29
30 #define BASE "test-truncate.t"
31
32 int
33 main (int argc, char *argv[])
34 {
35
36 ignore_value (system ("rm -rf " BASE "*"));
37
38 {
39 int fd = open (BASE "file", O_RDWR | O_TRUNC | O_CREAT, 0600);
40 ASSERT (fd >= 0);
41 ASSERT (write (fd, "Hello", 5) == 5);
42 close (fd);
43 }
44
45 {
46 int fd = open (BASE "file", O_RDONLY);
47 ASSERT (fd >= 0);
48 ASSERT (lseek (fd, 0, SEEK_END) == 5);
49 close (fd);
50 }
51
52
53 ASSERT (truncate (BASE "file", 314159) == 0);
54 {
55 int fd = open (BASE "file", O_RDONLY);
56 ASSERT (fd >= 0);
57 ASSERT (lseek (fd, 0, SEEK_END) == 314159);
58 close (fd);
59 }
60
61
62 ASSERT (truncate (BASE "file", 3) == 0);
63 {
64 int fd = open (BASE "file", O_RDONLY);
65 ASSERT (fd >= 0);
66 ASSERT (lseek (fd, 0, SEEK_END) == 3);
67 close (fd);
68 }
69
70
71 ASSERT (truncate (BASE "file", 0) == 0);
72 {
73 int fd = open (BASE "file", O_RDONLY);
74 ASSERT (fd >= 0);
75 ASSERT (lseek (fd, 0, SEEK_END) == 0);
76 close (fd);
77 }
78
79
80 {
81 errno = 0;
82 ASSERT (truncate ("/nonexistent", 0) == -1);
83 ASSERT (errno == ENOENT);
84 }
85
86 {
87 errno = 0;
88 ASSERT (truncate (".", 0) == -1);
89 ASSERT (errno == EISDIR
90 || errno == EACCES);
91 }
92
93 {
94 errno = 0;
95 ASSERT (truncate (BASE "file/", 0) == -1);
96 ASSERT (errno == ENOTDIR
97 || errno == EINVAL);
98 }
99
100 {
101 errno = 0;
102 ASSERT (truncate (BASE "file", -3) == -1);
103 ASSERT (errno == EINVAL);
104 }
105
106
107 ASSERT (unlink (BASE "file") == 0);
108
109 return 0;
110 }