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 #pragma GCC diagnostic ignored "-Wnonnull" |
| 14 |
| 15 #define KNOWN_FILE_SIZE 30 |
| 16 |
| 17 int main(int argc, char** argv) { |
| 18 struct stat st; |
| 19 FILE* file; |
| 20 int fd; |
| 21 if (2 != argc) { |
| 22 printf("Usage: sel_ldr test_fstat.nexe test_stat_data\n"); |
| 23 return 1; |
| 24 } |
| 25 st.st_size = 0; |
| 26 printf( |
| 27 "%d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d+%d %d\n", |
| 28 offsetof(struct stat,st_dev),sizeof(st.st_dev), |
| 29 offsetof(struct stat,st_ino),sizeof(st.st_ino), |
| 30 offsetof(struct stat,st_mode),sizeof(st.st_mode), |
| 31 offsetof(struct stat,st_nlink),sizeof(st.st_nlink), |
| 32 offsetof(struct stat,st_uid),sizeof(st.st_uid), |
| 33 offsetof(struct stat,st_gid),sizeof(st.st_gid), |
| 34 offsetof(struct stat,st_rdev),sizeof(st.st_rdev), |
| 35 offsetof(struct stat,st_size),sizeof(st.st_size), |
| 36 offsetof(struct stat,st_blksize),sizeof(st.st_blksize), |
| 37 offsetof(struct stat,st_blocks),sizeof(st.st_blocks), |
| 38 offsetof(struct stat,st_atim),sizeof(st.st_atim), |
| 39 sizeof(st)); |
| 40 file = fopen( argv[1], "r"); |
| 41 assert (NULL != file); |
| 42 fd = fileno(file); |
| 43 errno = 0; |
| 44 assert (0 == fstat(fd, &st)); |
| 45 assert (KNOWN_FILE_SIZE == st.st_size); |
| 46 assert (0 == errno); |
| 47 assert (0 == fclose(file)); |
| 48 errno = 0; |
| 49 assert (-1 == fstat(-1, &st)); |
| 50 assert (EBADF == errno); |
| 51 return 0; |
| 52 } |
OLD | NEW |