• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 #ifndef _SYS_STAT_H_
29 #define _SYS_STAT_H_
30 
31 #include <sys/cdefs.h>
32 #include <sys/types.h>
33 #include <sys/time.h>
34 #include <linux/stat.h>
35 
36 #include <endian.h>
37 
38 __BEGIN_DECLS
39 
40 #define __STAT64_BODY \
41   unsigned long st_dev; \
42   unsigned long st_ino; \
43   unsigned long st_mode; \
44   unsigned long st_nlink; \
45   uid_t st_uid; /* 32-bit uid_t */ \
46   unsigned char padding[4]; \
47   gid_t st_gid; /* 32-bit gid_t */ \
48   unsigned char padding2[4]; \
49   unsigned long st_rdev; \
50   long st_size; \
51   long st_blksize; \
52   long st_blocks; \
53   long st_atime; \
54   unsigned long st_atime_nsec; \
55   long st_mtime; \
56   unsigned long st_mtime_nsec; \
57   long st_ctime; \
58   unsigned long st_ctime_nsec; \
59   unsigned char padding3[8];
60 
61 struct stat { __STAT64_BODY };
62 struct stat64 { __STAT64_BODY };
63 
64 #undef __STAT64_BODY
65 
66 #define st_atimensec st_atime_nsec
67 #define st_mtimensec st_mtime_nsec
68 #define st_ctimensec st_ctime_nsec
69 
70 #ifdef __USE_BSD
71 /* Permission macros provided by glibc for compatibility with BSDs. */
72 #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
73 #define ALLPERMS    (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
74 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
75 #endif
76 
77 extern int chmod(const char*, mode_t);
78 extern int fchmod(int, mode_t);
79 extern int mkdir(const char*, mode_t);
80 
81 extern int fstat(int, struct stat*);
82 extern int fstat64(int, struct stat64*);
83 extern int fstatat(int, const char*, struct stat*, int);
84 extern int fstatat64(int, const char*, struct stat64*, int);
85 extern int lstat(const char*, struct stat*);
86 extern int lstat64(const char*, struct stat64*);
87 extern int stat(const char*, struct stat*);
88 extern int stat64(const char*, struct stat64*);
89 
90 extern int mknod(const char*, mode_t, dev_t);
91 extern mode_t umask(mode_t);
92 
93 #if defined(__BIONIC_FORTIFY)
94 
95 extern mode_t __umask_chk(mode_t);
96 extern mode_t __umask_real(mode_t) __asm__(__USER_LABEL_PREFIX__ "umask");
97 __errordecl(__umask_invalid_mode, "umask called with invalid mode");
98 
99 __BIONIC_FORTIFY_INLINE
umask(mode_t mode)100 mode_t umask(mode_t mode) {
101 #if !defined(__clang__)
102   if (__builtin_constant_p(mode)) {
103     if ((mode & 0777) != mode) {
104       __umask_invalid_mode();
105     }
106     return __umask_real(mode);
107   }
108 #endif
109   return __umask_chk(mode);
110 }
111 #endif /* defined(__BIONIC_FORTIFY) */
112 
113 extern int mkfifo(const char*, mode_t);
114 
115 extern int fchmodat(int, const char*, mode_t, int);
116 extern int mkdirat(int, const char*, mode_t);
117 extern int mknodat(int, const char*, mode_t, dev_t);
118 
119 #define UTIME_NOW  ((1L << 30) - 1L)
120 #define UTIME_OMIT ((1L << 30) - 2L)
121 extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags);
122 extern int futimens(int fd, const struct timespec times[2]);
123 
124 __END_DECLS
125 
126 #endif /* _SYS_STAT_H_ */
127