1570af302Sopenharmony_ci#include <sys/stat.h> 2570af302Sopenharmony_ci#include <errno.h> 3570af302Sopenharmony_ci#include <string.h> 4570af302Sopenharmony_ci#include <stdio.h> 5570af302Sopenharmony_ci#include <time.h> 6570af302Sopenharmony_ci#include <stdint.h> 7570af302Sopenharmony_ci#include <unistd.h> 8570af302Sopenharmony_ci#include "test.h" 9570af302Sopenharmony_ci 10570af302Sopenharmony_ci#define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0)) 11570af302Sopenharmony_ci 12570af302Sopenharmony_ciextern int __stat_time64(const char *__restrict, struct stat *__restrict); 13570af302Sopenharmony_ci 14570af302Sopenharmony_ciint main(void) 15570af302Sopenharmony_ci{ 16570af302Sopenharmony_ci struct stat st; 17570af302Sopenharmony_ci FILE *f; 18570af302Sopenharmony_ci time_t t; 19570af302Sopenharmony_ci 20570af302Sopenharmony_ci if (TEST(stat(".",&st)==0, "errno = %s\n", strerror(errno))) { 21570af302Sopenharmony_ci TEST(S_ISDIR(st.st_mode), "\n"); 22570af302Sopenharmony_ci TEST(st.st_nlink>0, "%ju\n", (uintmax_t)st.st_nlink); 23570af302Sopenharmony_ci t = time(0); 24570af302Sopenharmony_ci TEST(st.st_ctime<=t, "%jd > %jd\n", (intmax_t)st.st_ctime, (intmax_t)t); 25570af302Sopenharmony_ci TEST(st.st_mtime<=t, "%jd > %jd\n", (intmax_t)st.st_mtime, (intmax_t)t); 26570af302Sopenharmony_ci TEST(st.st_atime<=t, "%jd > %jd\n", (intmax_t)st.st_atime, (intmax_t)t); 27570af302Sopenharmony_ci } 28570af302Sopenharmony_ci 29570af302Sopenharmony_ci if (TEST(__stat_time64(".",&st)==0, "errno = %s\n", strerror(errno))) { 30570af302Sopenharmony_ci TEST(S_ISDIR(st.st_mode), "\n"); 31570af302Sopenharmony_ci TEST(st.st_nlink>0, "%ju\n", (uintmax_t)st.st_nlink); 32570af302Sopenharmony_ci t = time(0); 33570af302Sopenharmony_ci TEST(st.st_ctime<=t, "%jd > %jd\n", (intmax_t)st.st_ctime, (intmax_t)t); 34570af302Sopenharmony_ci TEST(st.st_mtime<=t, "%jd > %jd\n", (intmax_t)st.st_mtime, (intmax_t)t); 35570af302Sopenharmony_ci TEST(st.st_atime<=t, "%jd > %jd\n", (intmax_t)st.st_atime, (intmax_t)t); 36570af302Sopenharmony_ci } 37570af302Sopenharmony_ci 38570af302Sopenharmony_ci if (TEST(stat("/dev/null",&st)==0, "errno = %s\n", strerror(errno))) { 39570af302Sopenharmony_ci TEST(S_ISCHR(st.st_mode), "\n"); 40570af302Sopenharmony_ci } 41570af302Sopenharmony_ci 42570af302Sopenharmony_ci if ((f = tmpfile())) { 43570af302Sopenharmony_ci fputs("hello", f); 44570af302Sopenharmony_ci fflush(f); 45570af302Sopenharmony_ci if (TEST(fstat(fileno(f),&st)==0, "errnp = %s\n", strerror(errno))) { 46570af302Sopenharmony_ci TEST(st.st_uid==geteuid(), "%d vs %d\n", (int)st.st_uid, (int)geteuid()); 47570af302Sopenharmony_ci TEST(st.st_gid==getegid(), "%d vs %d\n", (int)st.st_uid, (int)geteuid()); 48570af302Sopenharmony_ci TEST(st.st_size==5, "%jd vs 5\n", (intmax_t)st.st_size); 49570af302Sopenharmony_ci } 50570af302Sopenharmony_ci fclose(f); 51570af302Sopenharmony_ci } 52570af302Sopenharmony_ci 53570af302Sopenharmony_ci return t_status; 54570af302Sopenharmony_ci} 55