mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
fd-util: add macro for generating /proc/self/fd/ paths on the fly
This commit is contained in:
parent
3832cb90ba
commit
6e1e4b59f9
@ -7,6 +7,7 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
|
#include "stdio-util.h"
|
||||||
|
|
||||||
/* maximum length of fdname */
|
/* maximum length of fdname */
|
||||||
#define FDNAME_MAX 255
|
#define FDNAME_MAX 255
|
||||||
@ -104,7 +105,20 @@ static inline int make_null_stdio(void) {
|
|||||||
0; \
|
0; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
int fd_reopen(int fd, int flags);
|
int fd_reopen(int fd, int flags);
|
||||||
int read_nr_open(void);
|
int read_nr_open(void);
|
||||||
int btrfs_defrag_fd(int fd);
|
int btrfs_defrag_fd(int fd);
|
||||||
|
|
||||||
|
/* The maximum length a buffer for a /proc/self/fd/<fd> path needs */
|
||||||
|
#define PROC_FD_PATH_MAX \
|
||||||
|
(STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int))
|
||||||
|
|
||||||
|
static inline char *format_proc_fd_path(char buf[static PROC_FD_PATH_MAX], int fd) {
|
||||||
|
assert(buf);
|
||||||
|
assert(fd >= 0);
|
||||||
|
assert_se(snprintf_ok(buf, PROC_FD_PATH_MAX, "/proc/self/fd/%i", fd));
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define FORMAT_PROC_FD_PATH(fd) \
|
||||||
|
format_proc_fd_path((char[PROC_FD_PATH_MAX]) {}, (fd))
|
||||||
|
Loading…
Reference in New Issue
Block a user