diff options
author | Mattias Andrée <m@maandree.se> | 2025-03-21 16:50:15 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-03-21 16:50:15 +0100 |
commit | 96a6575e23b5baebcdd38269b80f47cc02a2627e (patch) | |
tree | 0561580306c882e0e7a4f76c542130bb7ee44537 /src/util.c | |
parent | Refactor (diff) | |
download | redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.gz redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.bz2 redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.xz |
Refactor
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
-rw-r--r-- | src/util.c | 61 |
1 files changed, 18 insertions, 43 deletions
@@ -1,4 +1,5 @@ -/* redshift-ng - Automatically adjust display colour temperature according the Sun +/*- + * redshift-ng - Automatically adjust display colour temperature according the Sun * * Copyright (c) 2009-2018 Jon Lund Steffensen <jonlst@gmail.com> * Copyright (c) 2014-2016, 2025 Mattias Andrée <m@maandree.se> @@ -188,43 +189,28 @@ try_path_opendir(const struct env_path *path_spec, const char **path_out, char * #ifndef WINDOWS -int +void pipe_rdnonblock(int pipefds[2]) { int i, flags; - /* Try to use pipe2(2) create O_CLOEXEC pipe, preferably with O_DIRECT */ + /* Try to use pipe2(2) create O_CLOEXEC pipe */ # if defined(__linux__) && !defined(MISSING_PIPE2) - if (!pipe2(pipefds, O_CLOEXEC | O_DIRECT)) { + if (!pipe2(pipefds, O_CLOEXEC)) goto apply_nonblock; - } else if (errno == EINVAL) { - if (!pipe2(pipefds, O_CLOEXEC)) { - goto apply_nonblock; - } else if (errno != ENOSYS) { - weprintf("pipe2 <buffer> O_CLOEXEC:"); - return -1; - } - } else if (errno != ENOSYS) { - weprintf("pipe2 <buffer> O_CLOEXEC|O_DIRECT:"); - return -1; - } + else if (errno != ENOSYS) + eprintf("pipe2 <buffer> O_CLOEXEC:"); # endif - /* Fallback for when pipe2(2) is not available (also indicates O_DIRECT cannot be used) */ - if (pipe(pipefds)) { - weprintf("pipe:"); - return -1; - } + /* Fallback for when pipe2(2) is not available */ + if (pipe(pipefds)) + eprintf("pipe:"); for (i = 0; i < 2; i++) { flags = fcntl(pipefds[i], F_GETFD); - if (flags == -1) { - weprintf("fcntl <pipe> F_GETFD:"); - goto fail; - } - if (fcntl(pipefds[i], F_SETFD, flags | O_CLOEXEC)) { - weprintf("fcntl <pipe> F_SETFD +O_CLOEXEC:"); - goto fail; - } + if (flags == -1) + eprintf("fcntl <pipe> F_GETFD:"); + if (fcntl(pipefds[i], F_SETFD, flags | O_CLOEXEC)) + eprintf("fcntl <pipe> F_SETFD +O_CLOEXEC:"); } /* Make the read-end non-blocking */ @@ -232,20 +218,9 @@ pipe_rdnonblock(int pipefds[2]) apply_nonblock: # endif flags = fcntl(pipefds[0], F_GETFL); - if (flags == -1) { - weprintf("fcntl <pipe> F_GETFL:"); - goto fail; - } - if (fcntl(pipefds[0], F_SETFL, flags | O_NONBLOCK)) { - weprintf("fcntl <pipe> F_SETFL +O_NONBLOCK:"); - goto fail; - } - - return 0; - -fail: - close(pipefds[0]); - close(pipefds[1]); - return -1; + if (flags == -1) + eprintf("fcntl <pipe> F_GETFL:"); + if (fcntl(pipefds[0], F_SETFL, flags | O_NONBLOCK)) + eprintf("fcntl <pipe> F_SETFL +O_NONBLOCK:"); } #endif |