1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <assert.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <sys/stat.h> #include <syscall.h> #include <unistd.h> int stat(const char *path, struct stat *buf) { int fd = open(path, O_RDONLY); if (-1 == fd) { return -1; } int rc = fstat(fd, buf); close(fd); return rc; }