2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 sigaddset(&new, SIGHUP);
31 sigprocmask(SIG_BLOCK, &new, &set);
37 sigprocmask(SIG_SETMASK, &set, NULL);
41 starts_with(const char *str, const char *prefix)
48 for (i = 0; prefix[i] != '\0'; ++i)
49 if (str[i] != prefix[i])
55 ends_with(const char *str, const char *sufx)
66 for (j = 0; str[i] != '\0'; i++, j++)
67 if (str[i] != sufx[j])
77 if ((len = lseek(fd, 0, SEEK_END)) == -1)
79 if (lseek(fd, 0, SEEK_SET) == -1)
85 absolutify_path(const char *path)
90 if ((r = strdup(path)) == NULL)
96 if (asprintf(&r, "%s/%s", wd, path) == -1)
103 xstrdup(const char *s)
107 if ((d = strdup(s)) == NULL)