posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
stat.h
Go to the documentation of this file.
1/*
2 * Copyright The Zephyr Project Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
17#ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_SYS_STAT_H_
18#define ZEPHYR_INCLUDE_ZEPHYR_POSIX_SYS_STAT_H_
19
20#include <time.h>
21
22#include <zephyr/toolchain.h>
23#include <zephyr/sys/fdtable.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
30
31/* slightly out of order w.r.t. the specification */
32#if !defined(_BLKCNT_T_DECLARED) && !defined(__blkcnt_t_defined)
33typedef long blkcnt_t;
34#define _BLKCNT_T_DECLARED
35#define __blkcnt_t_defined
36#endif
37
38#if !defined(_BLKSIZE_T_DECLARED) && !defined(__blksize_t_defined)
39typedef unsigned long blksize_t;
40#define _BLKSIZE_T_DECLARED
41#define __blksize_t_defined
42#endif
43
44#if !defined(_DEV_T_DECLARED) && !defined(__dev_t_defined)
45typedef int dev_t;
46#define _DEV_T_DECLARED
47#define __dev_t_defined
48#endif
49
50#if !defined(_GID_T_DECLARED) && !defined(__gid_t_defined)
51typedef unsigned short gid_t;
52#define _GID_T_DECLARED
53#define __gid_t_defined
54#endif
55
56#if !defined(_INO_T_DECLARED) && !defined(__ino_t_defined)
57typedef long ino_t;
58#define _INO_T_DECLARED
59#define __ino_t_defined
60#endif
61
62#if !defined(_MODE_T_DECLARED) && !defined(__mode_t_defined)
63typedef int mode_t;
64#define _MODE_T_DECLARED
65#define __mode_t_defined
66#endif
67
68#if !defined(_NLINK_T_DECLARED) && !defined(__nlink_t_defined)
69typedef unsigned short nlink_t;
70#define _NLINK_T_DECLARED
71#define __nlink_t_defined
72#endif
73
74#if !defined(_OFF_T_DECLARED) && !defined(__off_t_defined)
75typedef long off_t;
76#define _OFF_T_DECLARED
77#define __off_t_defined
78#endif
79
80/* time_t must be defined by the libc time.h */
81#include <time.h>
82
83#if __STDC_VERSION__ >= 201112L
84/* struct timespec must be defined in the libc time.h */
85#else
86/*
87 * there is a workaround needed for picolibc because it doesn't have guards around the definition
88 * of struct timespec
89 */
90#if !defined(_TIMESPEC_DECLARED) && !defined(__timespec_defined) && !defined(CONFIG_PICOLIBC)
91struct timespec {
92 time_t tv_sec;
93 long tv_nsec;
94};
95#define _TIMESPEC_DECLARED
96#define __timespec_defined
97#endif
98#endif
99
100#if !defined(_UID_T_DECLARED) && !defined(__uid_t_defined)
101typedef unsigned short uid_t;
102#define _UID_T_DECLARED
103#define __uid_t_defined
104#endif
105
106#if !(defined(_STAT_DECLARED) || defined(__stat_defined)) || defined(__DOXYGEN__)
108struct stat {
109 dev_t st_dev;
110 ino_t st_ino;
111 mode_t st_mode;
112 nlink_t st_nlink;
113 uid_t st_uid;
114 gid_t st_gid;
115#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
116 dev_t st_rdev;
117#endif
118 off_t st_size;
122#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
123 blkcnt_t st_blksize;
124 blkcnt_t st_blocks;
125#endif
126};
127#define _STAT_DECLARED
128#define __stat_defined
129#endif
130
132#define S_IFMT ZVFS_MODE_IFMT
133
134#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
136#define S_IFBLK ZVFS_MODE_IFBLK
138#define S_IFCHR ZVFS_MODE_IFCHR
140#define S_IFIFO ZVFS_MODE_IFIFO
142#define S_IFREG ZVFS_MODE_IFREG
144#define S_IFDIR ZVFS_MODE_IFDIR
146#define S_IFLNK ZVFS_MODE_IFLNK
148#define S_IFSOCK ZVFS_MODE_IFSOCK
150#define S_IFSHM ZVFS_MODE_IFSHM
151#endif
152
154#define S_IRWXU ZVFS_S_IRWXU
156#define S_IRUSR ZVFS_S_IRUSR
158#define S_IWUSR ZVFS_S_IWUSR
160#define S_IXUSR ZVFS_S_IXUSR
162#define S_IRWXG ZVFS_S_IRWXG
164#define S_IRGRP ZVFS_S_IRGRP
166#define S_IWGRP ZVFS_S_IWGRP
168#define S_IXGRP ZVFS_S_IXGRP
170#define S_IRWXO ZVFS_S_IRWXO
172#define S_IROTH ZVFS_S_IROTH
174#define S_IWOTH ZVFS_S_IWOTH
176#define S_IXOTH ZVFS_S_IXOTH
178#define S_ISUID ZVFS_S_ISUID
180#define S_ISGID ZVFS_S_ISGID
181#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
183#define S_ISVTX ZVFS_S_ISVTX
184#endif
185
187#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
188#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
190#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
192#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
194#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
196#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
198#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
200#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
201#endif
202
203#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
205#define S_TYPEISMQ(buf) (0)
207#define S_TYPEISSEM(buf) (0)
209#define S_TYPEISSHM(st) (((st)->st_mode & S_IFMT) == S_IFSHM)
210#endif
211
212#if defined(_POSIX_TYPED_MEMORY_OBJECTS) || defined(__DOXYGEN__)
214#define S_TYPEISTMO(buf) (0)
215#endif
216
218#define UTIME_NOW -1
220#define UTIME_OMIT -2
221
223int chmod(const char *path, mode_t mode);
225int fchmod(int fildes, mode_t mode);
227int fchmodat(int fd, const char *path, mode_t mode, int flag);
229int fstat(int fildes, struct stat *buf);
231int fstatat(int fd, const char *ZRESTRICT path, struct stat *ZRESTRICT buf, int flag);
233int futimens(int fildes, const struct timespec times[2]);
235int lstat(const char *ZRESTRICT path, struct stat *ZRESTRICT buf);
237int mkdir(const char *path, mode_t mode);
239int mkdirat(int fd, const char *path, mode_t mode);
241int mkfifo(const char *path, mode_t mode);
243int mkfifoat(int fd, const char *path, mode_t mode);
244#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
246int mknod(const char *path, mode_t mode, dev_t dev);
248int mknodat(int fd, const char *path, mode_t mode, dev_t dev);
249#endif
250TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_SHADOW);
252int stat(const char *ZRESTRICT path, struct stat *ZRESTRICT buf);
253TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_SHADOW);
257int utimensat(int fd, const char *path, const struct timespec times[2], int flag);
258
259
260#endif
261
262#ifdef __cplusplus
263}
264#endif
265
266#endif /* ZEPHYR_INCLUDE_ZEPHYR_POSIX_SYS_STAT_H_ */
int mode_t
File permission bits type.
Definition fcntl.h:178
long off_t
File offset type.
Definition aio.h:36
int utimensat(int fd, const char *path, const struct timespec times[2], int flag)
Set file access and modification times relative to a directory descriptor.
mode_t umask(mode_t cmask)
Set the file mode creation mask.
int mkdir(const char *path, mode_t mode)
Create a directory.
int mkfifoat(int fd, const char *path, mode_t mode)
Create a FIFO special file relative to a directory descriptor.
int fchmod(int fildes, mode_t mode)
Change the mode of an open file.
int lstat(const char *ZRESTRICT path, struct stat *ZRESTRICT buf)
Get status of a file (does not follow symbolic links).
int futimens(int fildes, const struct timespec times[2])
Set file access and modification times of an open file (nanosecond resolution).
int chmod(const char *path, mode_t mode)
Change the mode of a file.
int fstat(int fildes, struct stat *buf)
Get status of an open file.
int mkdirat(int fd, const char *path, mode_t mode)
Create a directory relative to a directory descriptor.
int mkfifo(const char *path, mode_t mode)
Create a FIFO special file.
int fstatat(int fd, const char *ZRESTRICT path, struct stat *ZRESTRICT buf, int flag)
Get status of a file relative to a directory descriptor.
int fchmodat(int fd, const char *path, mode_t mode, int flag)
Change the mode of a file relative to a directory descriptor.
clock_t times(struct tms *buf)
Get the process and child process times.
int mknodat(int fd, const char *path, mode_t mode, dev_t dev)
Create a special or regular file relative to a directory descriptor (XSI).
int mknod(const char *path, mode_t mode, dev_t dev)
Create a special or regular file (XSI extension).
File status information returned by stat(), fstat(), and lstat().
Definition stat.h:108
off_t st_size
File size in bytes (regular files).
Definition stat.h:118
nlink_t st_nlink
Number of hard links.
Definition stat.h:112
blkcnt_t st_blocks
Number of 512-byte blocks allocated.
Definition stat.h:124
uid_t st_uid
User ID of the file owner.
Definition stat.h:113
mode_t st_mode
File type and permission bits (S_IF* and S_I* constants).
Definition stat.h:111
blkcnt_t st_blksize
Preferred I/O block size.
Definition stat.h:123
struct timespec st_mtim
Time of last data modification.
Definition stat.h:120
struct timespec st_atim
Time of last access.
Definition stat.h:119
struct timespec st_ctim
Time of last status change.
Definition stat.h:121
ino_t st_ino
File serial number (inode).
Definition stat.h:110
dev_t st_rdev
Device ID (for character/block special files).
Definition stat.h:116
gid_t st_gid
Group ID of the file's group.
Definition stat.h:114
dev_t st_dev
Device ID of the device containing the file.
Definition stat.h:109
Time value with nanosecond resolution.
Definition aio.h:62
long tv_nsec
Nanoseconds [0, 999999999].
Definition aio.h:64
time_t tv_sec
Seconds.
Definition aio.h:63
POSIX time-of-day types and functions (<sys/time.h>)