summaryrefslogtreecommitdiff
path: root/src/libc-glue.hh
diff options
context:
space:
mode:
authorChristian Persch <chpe@src.gnome.org>2020-04-27 20:49:04 +0200
committerChristian Persch <chpe@src.gnome.org>2020-04-27 20:49:04 +0200
commitd7a9beeffee2f5177b5fec79cf5cdc8e5bc4f636 (patch)
treeb3fb2003c8cbf8fc97beef3724bea5fe8276c5d3 /src/libc-glue.hh
parent69ed779091b4165b8ea3894e4d58b986dde946a5 (diff)
downloadvte-d7a9beeffee2f5177b5fec79cf5cdc8e5bc4f636.tar.gz
lib: Move utility function to the file of its only caller
read_ints is only used in spawn.cc, so move it there. Make a note that this code is copied from glib.
Diffstat (limited to 'src/libc-glue.hh')
-rw-r--r--src/libc-glue.hh57
1 files changed, 45 insertions, 12 deletions
diff --git a/src/libc-glue.hh b/src/libc-glue.hh
index d2a3271b..218ebf22 100644
--- a/src/libc-glue.hh
+++ b/src/libc-glue.hh
@@ -102,18 +102,6 @@ constexpr bool operator!=(FD const& lhs, int rhs) { return !(lhs == rhs); }
/* FD convenience functions */
static inline int
-fd_dupfd_cloexec(int oldfd,
- int newfd)
-{
- auto fd = int{};
- do {
- fd = fcntl(F_DUPFD_CLOEXEC, oldfd, newfd);
- } while (fd == -1 && errno == EINTR);
-
- return fd;
-}
-
-static inline int
fd_get_descriptor_flags(int fd)
{
auto flags = int{};
@@ -152,6 +140,45 @@ fd_change_descriptor_flags(int fd,
return fd_set_descriptor_flags(fd, new_flags);
}
+static inline int
+fd_get_status_flags(int fd)
+{
+ auto flags = int{};
+ do {
+ flags = fcntl(fd, F_GETFL, 0);
+ } while (flags == -1 && errno == EINTR);
+
+ return flags;
+}
+
+static inline int
+fd_set_status_flags(int fd,
+ int flags)
+{
+ auto r = int{};
+ do {
+ r = fcntl(fd, F_SETFL, flags);
+ } while (r == -1 && errno == EINTR);
+
+ return r;
+}
+
+static inline int
+fd_change_status_flags(int fd,
+ int set_flags,
+ int unset_flags)
+{
+ auto const flags = fd_get_status_flags(fd);
+ if (flags == -1)
+ return -1;
+
+ auto const new_flags = (flags | set_flags) & ~unset_flags;
+ if (new_flags == flags)
+ return 0;
+
+ return fd_set_status_flags(fd, new_flags);
+}
+
static inline bool
fd_get_cloexec(int fd)
{
@@ -172,6 +199,12 @@ fd_unset_cloexec(int fd)
}
static inline int
+fd_set_nonblock(int fd)
+{
+ return fd_change_status_flags(fd, O_NONBLOCK, 0);
+}
+
+static inline int
fd_dup_cloexec(int oldfd,
int newfd)
{