2 62cbcdae 2024-02-02 op * Copyright (c) 2021, 2024 Omar Polo <op@omarpolo.com>
4 c553191e 2022-01-11 op * Permission to use, copy, modify, and distribute this software for any
5 c553191e 2022-01-11 op * purpose with or without fee is hereby granted, provided that the above
6 c553191e 2022-01-11 op * copyright notice and this permission notice appear in all copies.
8 c553191e 2022-01-11 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 c553191e 2022-01-11 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 c553191e 2022-01-11 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 c553191e 2022-01-11 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 c553191e 2022-01-11 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 c553191e 2022-01-11 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 c553191e 2022-01-11 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 c553191e 2022-01-11 op #include "compat.h"
19 c553191e 2022-01-11 op #include <errno.h>
20 c553191e 2022-01-11 op #include <fcntl.h>
21 c553191e 2022-01-11 op #include <stdlib.h>
22 c553191e 2022-01-11 op #include <string.h>
24 c553191e 2022-01-11 op #include "utils.h"
25 3d89457c 2024-06-18 thomas.ad #include "xwrapper.h"
28 ee0aac2f 2022-05-25 op mark_nonblock_cloexec(int fd)
32 c553191e 2022-01-11 op if ((flags = fcntl(fd, F_GETFL)) == -1)
34 c553191e 2022-01-11 op if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
36 ee0aac2f 2022-05-25 op if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
42 c553191e 2022-01-11 op has_suffix(const char *str, const char *sufx)
46 c553191e 2022-01-11 op l = strlen(str);
47 c553191e 2022-01-11 op s = strlen(sufx);
52 c553191e 2022-01-11 op return !strcmp(str + (l - s), sufx);
56 c553191e 2022-01-11 op hash_alloc(size_t len, void *d)
58 3d89457c 2024-06-18 thomas.ad d = xmalloc(len);
63 c553191e 2022-01-11 op hash_calloc(size_t nmemb, size_t size, void *d)
65 3d89457c 2024-06-18 thomas.ad d = xcalloc(nmemb, size);
70 c553191e 2022-01-11 op hash_free(void *ptr, void *d)