Skip to content

Commit 28726d6

Browse files
cfriedtstephanosio
authored andcommitted
posix: sys/stat.h: adopt the sys/stat.h header from picolibc
This may be getting ahead of the curve a bit, but here we adopt the `<sys/stat.h>` header from picolibc. It is mostly the same as that of newlib but the picolibc variant seemed to be slightly more "inclusive". Removed the `<_ansi.h>` include. The commit immediately following this declares a few missing types only if they are not already declared. Signed-off-by: Chris Friedt <[email protected]>
1 parent addbec9 commit 28726d6

File tree

1 file changed

+223
-42
lines changed
  • include/zephyr/posix/sys

1 file changed

+223
-42
lines changed

include/zephyr/posix/sys/stat.h

+223-42
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,235 @@
11
/*
2-
* Copyright (c) 2018 Intel Corporation
3-
*
4-
* SPDX-License-Identifier: Apache-2.0
5-
*/
2+
Copyright (c) 1982, 1986, 1993
3+
The Regents of the University of California. 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+
1. Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
3. Neither the name of the University nor the names of its contributors
14+
may be used to endorse or promote products derived from this software
15+
without specific prior written permission.
616
7-
#ifndef ZEPHYR_POSIX_SYS_STAT_H_
8-
#define ZEPHYR_POSIX_SYS_STAT_H_
17+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27+
SUCH DAMAGE.
28+
*/
29+
#ifndef _SYS_STAT_H
30+
#define _SYS_STAT_H
931

1032
#ifdef __cplusplus
1133
extern "C" {
1234
#endif
1335

14-
#define S_IFBLK 0060000
15-
#define S_IFCHR 0020000
16-
#define S_IFIFO 0010000
17-
#define S_IFREG 0100000
18-
#define S_IFDIR 0040000
19-
#define S_IFLNK 0120000
20-
#define S_IFSOCK 0140000
21-
22-
#define S_IRWXU 00700
23-
#define S_IRUSR 00400
24-
#define S_IWUSR 00200
25-
#define S_IXUSR 00100
26-
27-
#define S_IRWXG 00070
28-
#define S_IRGRP 00040
29-
#define S_IWGRP 00020
30-
#define S_IXGRP 00010
31-
32-
#define S_IRWXO 00007
33-
#define S_IROTH 00004
34-
#define S_IWOTH 00002
35-
#define S_IXOTH 00001
36-
37-
/* File open modes */
38-
#define O_ACCMODE 0003
39-
#define O_RDONLY 00
40-
#define O_WRONLY 01
41-
#define O_RDWR 02
42-
43-
struct stat {
44-
unsigned long st_size;
45-
unsigned long st_blksize;
46-
unsigned long st_blocks;
47-
unsigned long st_mode;
36+
#include <time.h>
37+
#include <sys/cdefs.h>
38+
#include <sys/types.h>
39+
#include <sys/_timespec.h>
40+
41+
/* dj's stat defines _STAT_H_ */
42+
#ifndef _STAT_H_
43+
44+
/* It is intended that the layout of this structure not change when the
45+
sizes of any of the basic types change (short, int, long) [via a compile
46+
time option]. */
47+
48+
#ifdef __CYGWIN__
49+
#include <cygwin/stat.h>
50+
#ifdef _LIBC
51+
#define stat64 stat
52+
#endif
53+
#else
54+
struct stat
55+
{
56+
dev_t st_dev;
57+
ino_t st_ino;
58+
mode_t st_mode;
59+
nlink_t st_nlink;
60+
uid_t st_uid;
61+
gid_t st_gid;
62+
#if defined(__linux) && defined(__x86_64__)
63+
int __pad0;
64+
#endif
65+
dev_t st_rdev;
66+
#if defined(__linux) && !defined(__x86_64__)
67+
unsigned short int __pad2;
68+
#endif
69+
off_t st_size;
70+
#if defined(__linux)
71+
blksize_t st_blksize;
72+
blkcnt_t st_blocks;
73+
struct timespec st_atim;
74+
struct timespec st_mtim;
75+
struct timespec st_ctim;
76+
#define st_atime st_atim.tv_sec /* Backward compatibility */
77+
#define st_mtime st_mtim.tv_sec
78+
#define st_ctime st_ctim.tv_sec
79+
#if defined(__linux) && defined(__x86_64__)
80+
__uint64_t __glibc_reserved[3];
81+
#endif
82+
#else
83+
#if defined(__rtems__)
84+
struct timespec st_atim;
85+
struct timespec st_mtim;
86+
struct timespec st_ctim;
87+
blksize_t st_blksize;
88+
blkcnt_t st_blocks;
89+
#else
90+
/* SysV/sco doesn't have the rest... But Solaris, eabi does. */
91+
#if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
92+
time_t st_atime;
93+
time_t st_mtime;
94+
time_t st_ctime;
95+
#else
96+
struct timespec st_atim;
97+
struct timespec st_mtim;
98+
struct timespec st_ctim;
99+
blksize_t st_blksize;
100+
blkcnt_t st_blocks;
101+
#if !defined(__rtems__)
102+
long st_spare4[2];
103+
#endif
104+
#endif
105+
#endif
106+
#endif
48107
};
49108

109+
#if !(defined(__svr4__) && !defined(__PPC__) && !defined(__sun__))
110+
#define st_atime st_atim.tv_sec
111+
#define st_ctime st_ctim.tv_sec
112+
#define st_mtime st_mtim.tv_sec
113+
#endif
114+
115+
#endif
116+
117+
#define _IFMT 0170000 /* type of file */
118+
#define _IFDIR 0040000 /* directory */
119+
#define _IFCHR 0020000 /* character special */
120+
#define _IFBLK 0060000 /* block special */
121+
#define _IFREG 0100000 /* regular */
122+
#define _IFLNK 0120000 /* symbolic link */
123+
#define _IFSOCK 0140000 /* socket */
124+
#define _IFIFO 0010000 /* fifo */
125+
126+
#define S_BLKSIZE 1024 /* size of a block */
127+
128+
#define S_ISUID 0004000 /* set user id on execution */
129+
#define S_ISGID 0002000 /* set group id on execution */
130+
#define S_ISVTX 0001000 /* save swapped text even after use */
131+
#if __BSD_VISIBLE
132+
#define S_IREAD 0000400 /* read permission, owner */
133+
#define S_IWRITE 0000200 /* write permission, owner */
134+
#define S_IEXEC 0000100 /* execute/search permission, owner */
135+
#define S_ENFMT 0002000 /* enforcement-mode locking */
136+
#endif /* !_BSD_VISIBLE */
137+
138+
#define S_IFMT _IFMT
139+
#define S_IFDIR _IFDIR
140+
#define S_IFCHR _IFCHR
141+
#define S_IFBLK _IFBLK
142+
#define S_IFREG _IFREG
143+
#define S_IFLNK _IFLNK
144+
#define S_IFSOCK _IFSOCK
145+
#define S_IFIFO _IFIFO
146+
147+
#ifdef _WIN32
148+
/* The Windows header files define _S_ forms of these, so we do too
149+
for easier portability. */
150+
#define _S_IFMT _IFMT
151+
#define _S_IFDIR _IFDIR
152+
#define _S_IFCHR _IFCHR
153+
#define _S_IFIFO _IFIFO
154+
#define _S_IFREG _IFREG
155+
#define _S_IREAD 0000400
156+
#define _S_IWRITE 0000200
157+
#define _S_IEXEC 0000100
158+
#endif
159+
160+
#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
161+
#define S_IRUSR 0000400 /* read permission, owner */
162+
#define S_IWUSR 0000200 /* write permission, owner */
163+
#define S_IXUSR 0000100/* execute/search permission, owner */
164+
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
165+
#define S_IRGRP 0000040 /* read permission, group */
166+
#define S_IWGRP 0000020 /* write permission, grougroup */
167+
#define S_IXGRP 0000010/* execute/search permission, group */
168+
#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
169+
#define S_IROTH 0000004 /* read permission, other */
170+
#define S_IWOTH 0000002 /* write permission, other */
171+
#define S_IXOTH 0000001/* execute/search permission, other */
172+
173+
#if __BSD_VISIBLE
174+
#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
175+
#define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
176+
#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
177+
#endif
178+
179+
#define S_ISBLK(m) (((m)&_IFMT) == _IFBLK)
180+
#define S_ISCHR(m) (((m)&_IFMT) == _IFCHR)
181+
#define S_ISDIR(m) (((m)&_IFMT) == _IFDIR)
182+
#define S_ISFIFO(m) (((m)&_IFMT) == _IFIFO)
183+
#define S_ISREG(m) (((m)&_IFMT) == _IFREG)
184+
#define S_ISLNK(m) (((m)&_IFMT) == _IFLNK)
185+
#define S_ISSOCK(m) (((m)&_IFMT) == _IFSOCK)
186+
187+
#if defined(__CYGWIN__) || defined(__rtems__)
188+
/* Special tv_nsec values for futimens(2) and utimensat(2). */
189+
#define UTIME_NOW -2L
190+
#define UTIME_OMIT -1L
191+
#endif
192+
193+
int chmod (const char *__path, mode_t __mode );
194+
int fchmod (int __fd, mode_t __mode);
195+
int fstat (int __fd, struct stat *__sbuf );
196+
int mkdir (const char *_path, mode_t __mode );
197+
int mkfifo (const char *__path, mode_t __mode );
198+
int stat (const char *__restrict __path, struct stat *__restrict __sbuf );
199+
mode_t umask (mode_t __mask );
200+
201+
#if defined (__SPU__) || defined(__rtems__) || defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
202+
int lstat (const char *__restrict __path, struct stat *__restrict __buf );
203+
int mknod (const char *__path, mode_t __mode, dev_t __dev );
204+
#endif
205+
206+
#if __ATFILE_VISIBLE && !defined(__INSIDE_CYGWIN__)
207+
int fchmodat (int, const char *, mode_t, int);
208+
int fstatat (int, const char *__restrict , struct stat *__restrict, int);
209+
int mkdirat (int, const char *, mode_t);
210+
int mkfifoat (int, const char *, mode_t);
211+
int mknodat (int, const char *, mode_t, dev_t);
212+
int utimensat (int, const char *, const struct timespec [2], int);
213+
#endif
214+
#if __POSIX_VISIBLE >= 200809 && !defined(__INSIDE_CYGWIN__)
215+
int futimens (int, const struct timespec [2]);
216+
#endif
217+
218+
/* Provide prototypes for most of the _<systemcall> names that are
219+
provided in newlib for some compilers. */
220+
#ifdef _LIBC
221+
int _fstat (int __fd, struct stat *__sbuf );
222+
int _stat (const char *__restrict __path, struct stat *__restrict __sbuf );
223+
int _mkdir (const char *_path, mode_t __mode );
224+
#ifdef __LARGE64_FILES
225+
struct stat64;
226+
int _stat64 (const char *__restrict __path, struct stat64 *__restrict __sbuf );
227+
int _fstat64 (int __fd, struct stat64 *__sbuf );
228+
#endif
229+
#endif
230+
231+
#endif /* !_STAT_H_ */
50232
#ifdef __cplusplus
51233
}
52234
#endif
53-
54-
#endif /* ZEPHYR_POSIX_SYS_STAT_H_ */
235+
#endif /* _SYS_STAT_H */

0 commit comments

Comments
 (0)