10
'\0', '\0', '\0', '\0',
11
'\0', '\0', '\0', '\0',
12
'\0', '\0', '\0', '\0',
13
'\0', '\0', '\0', '\0',
14
'\0', '\0', '\0', '\0',
15
'\0', '\0', '\0', '\0',
16
'\0', '\0', '\0', '\0'
20
int main(int argc, char *argv[])
34
printf("Usage: test_truncate_no_open <path>\n");
40
printf("Test filename: [%s]\n", filename);
43
if ((fd = open(filename, (O_WRONLY | O_CREAT | O_EXCL),
44
(S_IRUSR | S_IWUSR))) == -1) {
45
printf("Error attempting to create empty file [%s]\n",
50
size = write(fd , "abc" , 3);
52
printf("data not written to file");
57
fstat = malloc(sizeof(struct stat));
59
printf("Unable to allocate memory\n");
63
stat(filename, fstat);
64
if (fstat->st_size != 3) {
65
printf("test file should be 3 bytes\n");
66
printf("test file is [%d] bytes\n", fstat->st_size);
68
if (unlink(filename)) {
69
printf("error deleting file\n");
79
data_size = DATA_SIZE * 2;
81
data_size = DATA_SIZE;
82
if ((rc = truncate(filename, data_size)) == -1) {
83
printf("Error attempting to truncate [%s] to [%d] bytes\n",
89
fstat = malloc(sizeof(struct stat));
91
printf("Unable to allocate memory\n");
95
stat(filename, fstat);
96
if (fstat->st_size != data_size) {
97
printf("test file should be [%d] bytes\n", data_size);
98
printf("test file is [%d] bytes\n", fstat->st_size);
100
if (unlink(filename)) {
101
printf("error deleting file\n");
109
if ((fd = open(filename, O_RDONLY)) == -1) {
110
printf("Error attempting to open file [%s]\n", filename);
114
size = read(fd, buf, BUF_SIZE);
115
if (size != data_size) {
116
printf("expected to read [%d] bytes; read [%d] bytes instead\n",
122
for (i = 0; i < data_size; i++)
123
if (buf[i] != data[i]) {
124
printf("Data at offset [%d] does not match. Expected "
125
"data = [0x%.2x]; read data = [0x%.2x]\n", i,
132
printf("truncate_no_open test failed; rc = [%d]\n", rc);
134
printf("truncate_no_open test succeeded\n");