diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/util.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c index c43c5ddf..3a807edb 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <float.h> | 2 | #include <float.h> |
3 | #include <fcntl.h> | ||
3 | #include <math.h> | 4 | #include <math.h> |
4 | #include <stdlib.h> | 5 | #include <stdlib.h> |
5 | #include <string.h> | 6 | #include <string.h> |
@@ -75,3 +76,21 @@ const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel) | |||
75 | sway_assert(false, "Unknown value for wl_output_subpixel."); | 76 | sway_assert(false, "Unknown value for wl_output_subpixel."); |
76 | return NULL; | 77 | return NULL; |
77 | } | 78 | } |
79 | |||
80 | bool set_cloexec(int fd, bool cloexec) { | ||
81 | int flags = fcntl(fd, F_GETFD); | ||
82 | if (flags == -1) { | ||
83 | sway_log_errno(SWAY_ERROR, "fcntl failed"); | ||
84 | return false; | ||
85 | } | ||
86 | if (cloexec) { | ||
87 | flags = flags | FD_CLOEXEC; | ||
88 | } else { | ||
89 | flags = flags & ~FD_CLOEXEC; | ||
90 | } | ||
91 | if (fcntl(fd, F_SETFD, flags) == -1) { | ||
92 | sway_log_errno(SWAY_ERROR, "fcntl failed"); | ||
93 | return false; | ||
94 | } | ||
95 | return true; | ||
96 | } | ||