1 /* 2 * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef _ADAPT_SYS_STAT_H 32 #define _ADAPT_SYS_STAT_H 33 34 #include <sys/features.h> 35 #include <sys/types.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 42 #define S_IFMT 0170000 43 44 #define S_IFDIR 0040000 45 #define S_IFCHR 0020000 46 #define S_IFBLK 0060000 47 #define S_IFREG 0100000 48 #define S_IFIFO 0010000 49 #define S_IFLNK 0120000 50 #define S_IFSOCK 0140000 51 52 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 53 #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) 54 #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) 55 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 56 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) 57 #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) 58 #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) 59 60 #ifndef S_IRUSR 61 #define S_ISUID 04000 62 #define S_ISGID 02000 63 #define S_ISVTX 01000 64 #define S_IRUSR 0400 65 #define S_IWUSR 0200 66 #define S_IXUSR 0100 67 #define S_IRWXU 0700 68 #define S_IRGRP 0040 69 #define S_IWGRP 0020 70 #define S_IXGRP 0010 71 #define S_IRWXG 0070 72 #define S_IROTH 0004 73 #define S_IWOTH 0002 74 #define S_IXOTH 0001 75 #define S_IRWXO 0007 76 #endif 77 78 #define st_atime st_atim.tv_sec 79 #define st_mtime st_mtim.tv_sec 80 #define st_ctime st_ctim.tv_sec 81 82 struct stat { 83 dev_t st_dev; 84 int __st_dev_padding; 85 long __st_ino_truncated; 86 mode_t st_mode; 87 nlink_t st_nlink; 88 uid_t st_uid; 89 gid_t st_gid; 90 dev_t st_rdev; 91 int __st_rdev_padding; 92 off_t st_size; 93 blksize_t st_blksize; 94 blkcnt_t st_blocks; 95 struct { 96 long tv_sec; 97 long tv_nsec; 98 } __st_atim32, __st_mtim32, __st_ctim32; 99 ino_t st_ino; 100 struct timespec st_atim; 101 struct timespec st_mtim; 102 struct timespec st_ctim; 103 }; 104 105 int stat(const char *__restrict, struct stat *__restrict); 106 int fstat(int, struct stat *); 107 int mkdir(const char *, mode_t); 108 109 #if defined(_GNU_SOURCE) 110 #define stat64 stat 111 #define fstat64 fstat 112 #define blkcnt64_t blkcnt_t 113 #define fsblkcnt64_t fsblkcnt_t 114 #define fsfilcnt64_t fsfilcnt_t 115 #define ino64_t ino_t 116 #define off64_t off_t 117 #endif 118 119 #ifdef __cplusplus 120 } 121 #endif 122 123 #endif /* !_ADAPT_SYS_STAT_H */ 124