|
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can | |
4 * be found in the LICENSE file. | |
5 */ | |
6 | |
7 #include <assert.h> | |
8 #include <errno.h> | |
9 #include <stddef.h> | |
10 #include <stdio.h> | |
11 #include <sys/stat.h> | |
12 | |
13 int main(int argc, char** argv) { | |
14 struct stat st; | |
15 FILE* file; | |
16 int fd; | |
17 if (2 != argc) { | |
18 printf("Usage: sel_ldr test_fstat.nexe test_stat_data\n"); | |
19 return 1; | |
20 } | |
21 st.st_size = 0; | |
22 printf( | |
23 "%d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d\n", | |
eaeltsin
2011/01/19 12:54:28
Probably make the output more verbose? Like
st_
halyavin
2011/01/19 14:19:25
Done. I already print size of stat structure.
| |
24 offsetof(struct stat,st_dev),sizeof(st.st_dev), | |
25 offsetof(struct stat,st_ino),sizeof(st.st_ino), | |
26 offsetof(struct stat,st_mode),sizeof(st.st_mode), | |
27 offsetof(struct stat,st_nlink),sizeof(st.st_nlink), | |
28 offsetof(struct stat,st_uid),sizeof(st.st_uid), | |
29 offsetof(struct stat,st_gid),sizeof(st.st_gid), | |
30 offsetof(struct stat,st_rdev),sizeof(st.st_rdev), | |
31 offsetof(struct stat,st_size),sizeof(st.st_size), | |
32 offsetof(struct stat,st_blksize),sizeof(st.st_blksize), | |
33 offsetof(struct stat,st_blocks),sizeof(st.st_blocks), | |
34 offsetof(struct stat,st_atim),sizeof(st.st_atim), | |
35 sizeof(st)); | |
36 file = fopen( argv[1], "r"); | |
37 assert (NULL != file); | |
38 fd = fileno(file); | |
39 errno = 0; | |
40 assert (0 == fstat(fd, &st)); | |
eaeltsin
2011/01/19 12:54:28
I doubt having meaningful side effects inside asse
halyavin
2011/01/19 14:19:25
Done. I use positive return values though.
| |
41 printf("%d\n",(int)st.st_size); | |
42 assert (0 == errno); | |
43 assert (0 == fclose(file)); | |
44 errno = 0; | |
45 assert (-1 == fstat(-1, &st)); | |
46 assert (EBADF == errno); | |
47 return 0; | |
48 } | |
OLD | NEW |