diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-07-16 11:19:51 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-07-16 11:19:51 +0000 |
commit | 16013c560e189bd0c4fb58e038c0f449542dba7a (patch) | |
tree | b9d2777f2e5a8108b684839f04310ffd0de82179 /src/libstddjb | |
parent | 538fd727337959b1d7b8449a578a31fd9a9c62b4 (diff) | |
download | skalibs-16013c560e189bd0c4fb58e038c0f449542dba7a.tar.xz |
Add egidingroups sysdeps, change fd_close() to void and saving errno, propagate changes
Diffstat (limited to 'src/libstddjb')
-rw-r--r-- | src/libstddjb/cdb_mapfile.c | 3 | ||||
-rw-r--r-- | src/libstddjb/child_spawn0.c | 4 | ||||
-rw-r--r-- | src/libstddjb/child_spawn1_internal.c | 6 | ||||
-rw-r--r-- | src/libstddjb/doublefork.c | 2 | ||||
-rw-r--r-- | src/libstddjb/fd_close.c | 11 | ||||
-rw-r--r-- | src/libstddjb/fd_ensure_open.c | 2 | ||||
-rw-r--r-- | src/libstddjb/fd_move.c | 4 | ||||
-rw-r--r-- | src/libstddjb/fd_move2.c | 2 | ||||
-rw-r--r-- | src/libstddjb/filecopy_unsafe.c | 23 | ||||
-rw-r--r-- | src/libstddjb/iobufferk_finish.c | 5 | ||||
-rw-r--r-- | src/libstddjb/ipc_accept.c | 4 | ||||
-rw-r--r-- | src/libstddjb/openreadfileclose.c | 7 | ||||
-rw-r--r-- | src/libstddjb/openreadnclose.c | 2 | ||||
-rw-r--r-- | src/libstddjb/openslurpclose.c | 4 | ||||
-rw-r--r-- | src/libstddjb/pipe_internal.c | 3 | ||||
-rw-r--r-- | src/libstddjb/socket_accept4.c | 2 | ||||
-rw-r--r-- | src/libstddjb/socket_accept6.c | 2 | ||||
-rw-r--r-- | src/libstddjb/socket_internal.c | 3 | ||||
-rw-r--r-- | src/libstddjb/socket_tcp6.c | 4 | ||||
-rw-r--r-- | src/libstddjb/socket_udp6.c | 4 | ||||
-rw-r--r-- | src/libstddjb/socketpair_internal.c | 8 | ||||
-rw-r--r-- | src/libstddjb/touch.c | 11 |
22 files changed, 26 insertions, 90 deletions
diff --git a/src/libstddjb/cdb_mapfile.c b/src/libstddjb/cdb_mapfile.c index 1ffae19..f2c56bb 100644 --- a/src/libstddjb/cdb_mapfile.c +++ b/src/libstddjb/cdb_mapfile.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/cdb.h> @@ -10,9 +9,7 @@ int cdb_mapfile (struct cdb *c, char const *file) if (fd < 0) return 0 ; if (!cdb_init_map(c, fd, 1)) { - int e = errno ; fd_close(fd) ; - errno = e ; return 0 ; } fd_close(fd) ; diff --git a/src/libstddjb/child_spawn0.c b/src/libstddjb/child_spawn0.c index f946515..a01739a 100644 --- a/src/libstddjb/child_spawn0.c +++ b/src/libstddjb/child_spawn0.c @@ -59,10 +59,8 @@ pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const pid = fork() ; if (pid < 0) { - e = errno ; fd_close(p[1]) ; fd_close(p[0]) ; - errno = e ; return 0 ; } if (!pid) @@ -83,9 +81,7 @@ pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const p[1] = fd_read(p[0], (char *)&e, sizeof(e)) ; if (p[1] < 0) { - e = errno ; fd_close(p[0]) ; - errno = e ; return 0 ; } fd_close(p[0]) ; diff --git a/src/libstddjb/child_spawn1_internal.c b/src/libstddjb/child_spawn1_internal.c index feddbc8..eea4f09 100644 --- a/src/libstddjb/child_spawn1_internal.c +++ b/src/libstddjb/child_spawn1_internal.c @@ -77,21 +77,17 @@ pid_t child_spawn1_internal (char const *prog, char const *const *argv, char con pid_t pid ; if (coe(p[0]) < 0 || pipecoe(syncp) < 0) { - e = errno ; fd_close(p[1]) ; fd_close(p[0]) ; - errno = e ; return 0 ; } pid = fork() ; if (pid < 0) { - e = errno ; fd_close(syncp[1]) ; fd_close(syncp[0]) ; fd_close(p[1]) ; fd_close(p[0]) ; - errno = e ; return 0 ; } if (!pid) @@ -117,10 +113,8 @@ err: syncp[1] = fd_read(syncp[0], (char *)&e, sizeof(e)) ; if (syncp[1] < 0) { - e = errno ; fd_close(syncp[0]) ; fd_close(p[!(to & 1)]) ; - errno = e ; return 0 ; } fd_close(syncp[0]) ; diff --git a/src/libstddjb/doublefork.c b/src/libstddjb/doublefork.c index d75a017..da512f8 100644 --- a/src/libstddjb/doublefork.c +++ b/src/libstddjb/doublefork.c @@ -18,10 +18,8 @@ pid_t doublefork () { case -1: { - int e = errno ; fd_close(fd[1]) ; fd_close(fd[0]) ; - errno = e ; return -1 ; } case 0: diff --git a/src/libstddjb/fd_close.c b/src/libstddjb/fd_close.c index cb52d4f..a3c7880 100644 --- a/src/libstddjb/fd_close.c +++ b/src/libstddjb/fd_close.c @@ -4,12 +4,9 @@ #include <errno.h> #include <skalibs/djbunix.h> -int fd_close (int fd) +void fd_close (int fd) { - for (;;) - { - if (!close(fd) || errno == EINPROGRESS) break ; - if (errno != EINTR) return -1 ; - } - return 0 ; + int e = errno ; + while (close(fd) < 0 && errno == EINTR) ; + errno = e ; } diff --git a/src/libstddjb/fd_ensure_open.c b/src/libstddjb/fd_ensure_open.c index 40548c1..c42c90e 100644 --- a/src/libstddjb/fd_ensure_open.c +++ b/src/libstddjb/fd_ensure_open.c @@ -15,9 +15,7 @@ int fd_ensure_open (int fd, int w) if (newfd < 0) return 0 ; if (fd_move(fd, newfd) < 0) { - int e = errno ; fd_close(newfd) ; - errno = e ; return 0 ; } } diff --git a/src/libstddjb/fd_move.c b/src/libstddjb/fd_move.c index d84db80..af9769c 100644 --- a/src/libstddjb/fd_move.c +++ b/src/libstddjb/fd_move.c @@ -11,5 +11,7 @@ int fd_move (int to, int from) do r = dup2(from, to) ; while ((r == -1) && (errno == EINTR)) ; - return (r == -1) ? -1 : fd_close(from) ; + if (r < 0) return r ; + fd_close(from) ; + return 0 ; } diff --git a/src/libstddjb/fd_move2.c b/src/libstddjb/fd_move2.c index e28c2cc..d80ef3e 100644 --- a/src/libstddjb/fd_move2.c +++ b/src/libstddjb/fd_move2.c @@ -18,9 +18,7 @@ int fd_move2 (int to1, int from1, int to2, int from2) } if (fd_copy(to1, from1) == -1) { - int e = errno ; if (from2 != tmp) fd_close(tmp) ; - errno = e ; return -1 ; } if (fd_copy(to2, tmp) == -1) diff --git a/src/libstddjb/filecopy_unsafe.c b/src/libstddjb/filecopy_unsafe.c index 68bcc5b..a6410c1 100644 --- a/src/libstddjb/filecopy_unsafe.c +++ b/src/libstddjb/filecopy_unsafe.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <errno.h> #include <fcntl.h> #include <skalibs/djbunix.h> @@ -10,23 +9,15 @@ int filecopy_unsafe (char const *src, char const *dst, unsigned int mode) int s = open2(src, O_RDONLY) ; if (s < 0) return 0 ; d = open3(dst, O_WRONLY | O_CREAT | O_TRUNC, mode) ; - if (d < 0) - { - int e = errno ; - fd_close(s) ; - errno = e ; - return 0 ; - } - if (fd_cat(s, d) < 0) - { - int e = errno ; - fd_close(d) ; - fd_close(s) ; - errno = e ; - return 0 ; - } + if (d < 0) goto errs ; + if (fd_cat(s, d) < 0) goto errd ; fd_close(d) ; fd_close(s) ; return 1 ; +errd: + fd_close(d) ; +errs: + fd_close(s) ; + return 0 ; } diff --git a/src/libstddjb/iobufferk_finish.c b/src/libstddjb/iobufferk_finish.c index 112174b..4e4a73c 100644 --- a/src/libstddjb/iobufferk_finish.c +++ b/src/libstddjb/iobufferk_finish.c @@ -4,7 +4,6 @@ #ifdef SKALIBS_HASSPLICE -#include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/iobuffer.h> @@ -15,17 +14,13 @@ static void iobufferk_nop (iobufferk *k) static void iobufferk_finish_0 (iobufferk *k) { - int e = errno ; fd_close(k->p[1]) ; - errno = e ; } static void iobufferk_finish_3 (iobufferk *k) { - int e = errno ; fd_close(k->p[1]) ; fd_close(k->p[0]) ; - errno = e ; } iobufferk_finish_func_t_ref const iobufferk_finish_f[4] = diff --git a/src/libstddjb/ipc_accept.c b/src/libstddjb/ipc_accept.c index 5ff82d8..b0b44c3 100644 --- a/src/libstddjb/ipc_accept.c +++ b/src/libstddjb/ipc_accept.c @@ -2,10 +2,10 @@ #include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> -#include <errno.h> #include <sys/socket.h> #include <sys/un.h> #include <string.h> +#include <errno.h> #include <skalibs/bytestr.h> #include <skalibs/djbunix.h> #include <skalibs/webipc.h> @@ -28,9 +28,7 @@ int ipc_accept_internal (int s, char *p, size_t l, int *trunc, unsigned int opti if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } #endif diff --git a/src/libstddjb/openreadfileclose.c b/src/libstddjb/openreadfileclose.c index b636c89..baed267 100644 --- a/src/libstddjb/openreadfileclose.c +++ b/src/libstddjb/openreadfileclose.c @@ -1,7 +1,6 @@ /* ISC license. */ #include <sys/stat.h> -#include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> @@ -27,10 +26,6 @@ int openreadfileclose (char const *file, stralloc *sa, size_t limit) return 1 ; err: - { - int e = errno ; - fd_close(fd) ; - errno = e ; - } + fd_close(fd) ; return 0 ; } diff --git a/src/libstddjb/openreadnclose.c b/src/libstddjb/openreadnclose.c index 57a9bdc..e765499 100644 --- a/src/libstddjb/openreadnclose.c +++ b/src/libstddjb/openreadnclose.c @@ -12,9 +12,7 @@ static ssize_t readnclose (int fd, char *s, size_t n) r = allread(fd, s, n) ; if (errno) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } fd_close(fd) ; diff --git a/src/libstddjb/openslurpclose.c b/src/libstddjb/openslurpclose.c index 5f67d76..50d361e 100644 --- a/src/libstddjb/openslurpclose.c +++ b/src/libstddjb/openslurpclose.c @@ -1,18 +1,14 @@ /* ISC license. */ -#include <errno.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> int openslurpclose (stralloc *sa, char const *fn) { int r ; - int e ; int fd = open_readb(fn) ; if (fd == -1) return 0 ; r = slurp(sa, fd) ; - e = errno ; fd_close(fd) ; - errno = e ; return r ; } diff --git a/src/libstddjb/pipe_internal.c b/src/libstddjb/pipe_internal.c index 48f182a..598ab9c 100644 --- a/src/libstddjb/pipe_internal.c +++ b/src/libstddjb/pipe_internal.c @@ -17,7 +17,6 @@ int pipe_internal (int *p, unsigned int flags) #else #include <unistd.h> -#include <errno.h> #include <skalibs/djbunix.h> int pipe_internal (int *p, unsigned int flags) @@ -32,10 +31,8 @@ int pipe_internal (int *p, unsigned int flags) return 0 ; err: { - int e = errno ; fd_close(pi[1]) ; fd_close(pi[0]) ; - errno = e ; } return -1 ; } diff --git a/src/libstddjb/socket_accept4.c b/src/libstddjb/socket_accept4.c index c77d0e2..40dff91 100644 --- a/src/libstddjb/socket_accept4.c +++ b/src/libstddjb/socket_accept4.c @@ -27,9 +27,7 @@ int socket_accept4_internal (int s, char *ip, uint16_t *port, unsigned int optio if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } #endif diff --git a/src/libstddjb/socket_accept6.c b/src/libstddjb/socket_accept6.c index 6942997..5bd72b4 100644 --- a/src/libstddjb/socket_accept6.c +++ b/src/libstddjb/socket_accept6.c @@ -30,9 +30,7 @@ int socket_accept6_internal (int s, char *ip6, uint16_t *port, unsigned int opti if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } #endif diff --git a/src/libstddjb/socket_internal.c b/src/libstddjb/socket_internal.c index f8b0a1f..848b156 100644 --- a/src/libstddjb/socket_internal.c +++ b/src/libstddjb/socket_internal.c @@ -3,7 +3,6 @@ #include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> #include <sys/socket.h> -#include <errno.h> #include <skalibs/djbunix.h> #ifdef SKALIBS_HASACCEPT4 @@ -22,9 +21,7 @@ int socket_internal (int domain, int type, int protocol, unsigned int flags) if ((((flags & DJBUNIX_FLAG_NB) ? ndelay_on(s) : ndelay_off(s)) < 0) || (((flags & DJBUNIX_FLAG_COE) ? coe(s) : uncoe(s)) < 0)) { - int e = errno ; fd_close(s) ; - errno = e ; return -1 ; } return s ; diff --git a/src/libstddjb/socket_tcp6.c b/src/libstddjb/socket_tcp6.c index df6dd86..cc42f68 100644 --- a/src/libstddjb/socket_tcp6.c +++ b/src/libstddjb/socket_tcp6.c @@ -1,9 +1,9 @@ /* ISC license. */ #include <skalibs/nonposix.h> -#include <errno.h> #include <sys/socket.h> #include <netinet/in.h> +#include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/ip46.h> #include <skalibs/socket.h> @@ -18,9 +18,7 @@ int socket_tcp6_internal (unsigned int flags) int option = 1 ; if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &option, sizeof(option)) < 0) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } } diff --git a/src/libstddjb/socket_udp6.c b/src/libstddjb/socket_udp6.c index c8f5928..6316861 100644 --- a/src/libstddjb/socket_udp6.c +++ b/src/libstddjb/socket_udp6.c @@ -1,9 +1,9 @@ /* ISC license. */ #include <skalibs/nonposix.h> -#include <errno.h> #include <sys/socket.h> #include <netinet/in.h> +#include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/ip46.h> #include <skalibs/socket.h> @@ -18,9 +18,7 @@ int socket_udp6_internal (unsigned int flags) int option = 1 ; if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &option, sizeof(option)) < 0) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } } diff --git a/src/libstddjb/socketpair_internal.c b/src/libstddjb/socketpair_internal.c index a1e64c5..a31228f 100644 --- a/src/libstddjb/socketpair_internal.c +++ b/src/libstddjb/socketpair_internal.c @@ -44,12 +44,8 @@ int socketpair_internal (int domain, int type, int protocol, unsigned int flags, return 0 ; err: - { - int e = errno ; - fd_close(fd[1]) ; - fd_close(fd[0]) ; - errno = e ; - } + fd_close(fd[1]) ; + fd_close(fd[0]) ; return -1 ; } diff --git a/src/libstddjb/touch.c b/src/libstddjb/touch.c index d270251..f71a983 100644 --- a/src/libstddjb/touch.c +++ b/src/libstddjb/touch.c @@ -11,11 +11,12 @@ int touch (char const *file) { + int r ; int fd = open_create(file) ; if (fd < 0) return 0 ; - if (futimens(fd, 0) < 0) return 0 ; + r = futimens(fd, 0) >= 0 ; fd_close(fd) ; - return 1 ; + return r ; } #else @@ -27,9 +28,10 @@ int touch (char const *file) int touch (char const *file) { + int r ; int fd = open_create(file) ; if (fd < 0) return 0 ; - if (futimes(fd, 0) < 0) return 0 ; + r = futimes(fd, 0) >= 0 ; fd_close(fd) ; return 1 ; } @@ -44,8 +46,7 @@ int touch (char const *file) int fd = open_create(file) ; if (fd < 0) return 0 ; fd_close(fd) ; - if (utimes(file, 0) < 0) return 0 ; - return 1 ; + return utimes(file, 0) >= 0 ; } #endif |