#define _XOPEN_SOURCE 700 #include #include #include #include #include #include #include int main() { int ret = 0, i, j, fd_file; struct stat file_stat; ret = mkdirat(AT_FDCWD, "test_dir", 0777); if (ret && errno != EEXIST) return -1; fd_file = openat(AT_FDCWD, "test_dir/test_file", O_RDWR|O_CREAT|O_NONBLOCK, 07777); if (!fd_file) return -2; if (ftruncate(fd_file, 0)) { ret = -3; goto error_file; } if (fstat(fd_file, &file_stat)) { ret = -4; goto error_file; } printf("%07o\n", file_stat.st_mode); for (i = 1; i <= 16384; i++) { dprintf(fd_file, "%05d-file-contents-", i); for (j = 0; j < 5; j++) dprintf(fd_file, "%06lx", random() & 0xFFFFFFL); dprintf(fd_file, "%02lx\n", random() & 0xFFL); } if (fstat(fd_file, &file_stat)) { ret = -5; goto error_file; } printf("%07o\n", file_stat.st_mode); error_file: close(fd_file); return ret; }