From: Lennart Poettering Date: Mon, 27 Mar 2023 19:57:53 +0000 (+0200) Subject: fd-util: add helper for converting O_RDONLY/WRONLY/RDWR to strings X-Git-Tag: v254-rc1~864^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2b84f4b236f371d169f470e5239815c3cd01890;p=thirdparty%2Fsystemd.git fd-util: add helper for converting O_RDONLY/WRONLY/RDWR to strings --- diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index b968bf948c4..bea9a93ff54 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -935,3 +935,16 @@ int dir_fd_is_root(int dir_fd) { */ return statx_inode_same(&st.sx, &pst.sx) && statx_mount_same(&st.nsx, &pst.nsx); } + +const char *accmode_to_string(int flags) { + switch (flags & O_ACCMODE) { + case O_RDONLY: + return "ro"; + case O_WRONLY: + return "wo"; + case O_RDWR: + return "rw"; + default: + return NULL; + } +} diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index a6353cf48e4..91f3d7fe9d4 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -115,3 +115,5 @@ static inline char *format_proc_fd_path(char buf[static PROC_FD_PATH_MAX], int f #define FORMAT_PROC_FD_PATH(fd) \ format_proc_fd_path((char[PROC_FD_PATH_MAX]) {}, (fd)) + +const char *accmode_to_string(int flags);