#include #include #include #include #include #include "common_utils/utils.h" char *append(char *buf, const char *appended, size_t *pcap) { char c; char *buf0 = buf; size_t cap = *pcap; if (buf0 == NULL) return NULL; if (appended == NULL || appended[0] == 0) return buf0; while (cap > 1 && 0 != (c = *appended++)) { *buf++ = c; cap--; } if (cap == 0) { *buf0 = '\0'; return NULL; } *pcap = cap; *buf = 0; return buf; } bool fd_is_valid(int fd) { return fcntl(fd, F_GETFD) != -1 || errno != EBADF; } int parse_boolean_arg(const char *str) { if (0 == strcasecmp(str, "on")) return 1; if (strstarts(str, "en")) return 1; if (strstarts(str, "y")) return 1; if (0 == strcmp(str, "1")) return 1; if (0 == strcasecmp(str, "a")) return 1; if (0 == strcasecmp(str, "off")) return 0; if (0 == strcmp(str, "0")) return 0; if (strstarts(str, "dis")) return 0; if (strstarts(str, "n")) return 0; return -1; }