diff options
Diffstat (limited to 'src/libstddjb')
28 files changed, 0 insertions, 509 deletions
diff --git a/src/libstddjb/env_addmodif.c b/src/libstddjb/env_addmodif.c deleted file mode 100644 index ddd1be3..0000000 --- a/src/libstddjb/env_addmodif.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <sys/types.h> -#include <skalibs/stralloc.h> -#include <skalibs/env.h> - -int env_addmodif (stralloc *sa, char const *s, char const *t) -{ - size_t oldlen = sa->len ; - if (!s) return 1 ; - if (!stralloc_cats(sa, s)) return 0 ; - if ((t && (!stralloc_catb(sa, "=", 1) || !stralloc_cats(sa, t))) - || !stralloc_0(sa)) - { - sa->len = oldlen ; - return 0 ; - } - return 1 ; -} diff --git a/src/libstddjb/env_dump.c b/src/libstddjb/env_dump.c deleted file mode 100644 index 10f5913..0000000 --- a/src/libstddjb/env_dump.c +++ /dev/null @@ -1,54 +0,0 @@ -/* ISC license. */ - -#include <skalibs/nonposix.h> -#include <unistd.h> -#include <sys/stat.h> -#include <string.h> -#include <errno.h> -#include <stdlib.h> -#include <stdio.h> - -#include <skalibs/bytestr.h> -#include <skalibs/env.h> -#include <skalibs/djbunix.h> - - /* XXX: breaks layering, but really openat() should be supported everywhere */ -#include <skalibs/unix-transactional.h> - -#define SUFFIX ":envdump:XXXXXX" - -int env_dump (char const *dir, mode_t mode, char const *const *envp) -{ - int fd ; - size_t dirlen = strlen(dir) ; - char tmpdir[dirlen + sizeof(SUFFIX)] ; - memcpy(tmpdir, dir, dirlen) ; - memcpy(tmpdir + dirlen, SUFFIX, sizeof(SUFFIX)) ; - if (!mkdtemp(tmpdir)) return 0 ; - fd = open_read(tmpdir) ; - if (fd == -1) goto err ; - for (; *envp ; envp++) - { - size_t len = str_chr(*envp, '=') ; - size_t vallen = strlen(*envp + len + 1) ; - char fn[len + 1] ; - memcpy(fn, *envp, len) ; - fn[len] = 0 ; - len = openwritenclose_at(fd, fn, *envp + len + 1, vallen) ; - if (len < vallen) goto cerr ; - } - fd_close(fd) ; - if (chmod(tmpdir, mode) == -1) goto err ; - if (rename(tmpdir, dir) == -1) goto err ; - return 1 ; - - cerr: - fd_close(fd) ; - err: - { - int e = errno ; - rm_rf(tmpdir) ; - errno = e ; - } - return 0 ; -} diff --git a/src/libstddjb/env_get.c b/src/libstddjb/env_get.c deleted file mode 100644 index d809461..0000000 --- a/src/libstddjb/env_get.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include <stdlib.h> -#include <skalibs/posixplz.h> - -char const *env_get (char const *s) -{ - return getenv(s) ; -} diff --git a/src/libstddjb/env_get2.c b/src/libstddjb/env_get2.c deleted file mode 100644 index 5909ea6..0000000 --- a/src/libstddjb/env_get2.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <skalibs/bytestr.h> -#include <skalibs/env.h> - -char const *env_get2 (char const *const *envp, char const *s) -{ - size_t len, i ; - if (!s) return 0 ; - len = strlen(s) ; - for (i = 0 ; envp[i] ; ++i) - if (str_start(envp[i], s) - && (envp[i][len] == '=')) - return envp[i] + len + 1 ; - return 0 ; -} diff --git a/src/libstddjb/env_len.c b/src/libstddjb/env_len.c deleted file mode 100644 index eef30c4..0000000 --- a/src/libstddjb/env_len.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <skalibs/env.h> - -size_t env_len (char const *const *e) -{ - size_t i = 0 ; - while (*e++) i++ ; - return i ; -} diff --git a/src/libstddjb/env_make.c b/src/libstddjb/env_make.c deleted file mode 100644 index 60148f8..0000000 --- a/src/libstddjb/env_make.c +++ /dev/null @@ -1,16 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <errno.h> -#include <skalibs/env.h> - -int env_make (char const **v, size_t argc, char const *s, size_t len) -{ - while (argc--) - { - size_t n = strlen(s) + 1 ; - if (n > len) return (errno = EINVAL, 0) ; - *v++ = s ; s += n ; len -= n ; - } - return 1 ; -} diff --git a/src/libstddjb/env_merge.c b/src/libstddjb/env_merge.c deleted file mode 100644 index 5543e08..0000000 --- a/src/libstddjb/env_merge.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <errno.h> -#include <skalibs/bytestr.h> -#include <skalibs/env.h> - -size_t env_merge (char const **v, size_t vmax, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - size_t n = byte_count(modifs, modiflen, '\0') ; - size_t vlen = envlen ; - size_t i = 0 ; - if (envlen + n + 1 > vmax) return (errno = ENAMETOOLONG, 0) ; - for (; i < envlen ; i++) v[i] = envp[i] ; - for (i = 0 ; i < modiflen ; i += strlen(modifs + i) + 1) - { - size_t split = str_chr(modifs + i, '=') ; - size_t j = 0 ; - for (; j < vlen ; j++) - if (!strncmp(modifs + i, v[j], split) && (v[j][split] == '=')) break ; - if (j < vlen) v[j] = v[--vlen] ; - if (modifs[i + split]) v[vlen++] = modifs + i ; - } - v[vlen++] = 0 ; - return vlen ; -} diff --git a/src/libstddjb/env_string.c b/src/libstddjb/env_string.c deleted file mode 100644 index e30f095..0000000 --- a/src/libstddjb/env_string.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <skalibs/stralloc.h> -#include <skalibs/env.h> - -int env_string (stralloc *sa, char const *const *envp, size_t envlen) -{ - size_t salen = sa->len ; - size_t i = 0 ; - for (; i < envlen ; i++) - { - if (!stralloc_cats(sa, envp[i]) || !stralloc_0(sa)) - { - sa->len = salen ; - return 0 ; - } - } - return 1 ; -} diff --git a/src/libstddjb/envalloc_0.c b/src/libstddjb/envalloc_0.c deleted file mode 100644 index 114f69e..0000000 --- a/src/libstddjb/envalloc_0.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <skalibs/genalloc.h> -#include <skalibs/envalloc.h> - -int envalloc_0 (genalloc *v) -{ - char const *z = 0 ; - return genalloc_append(char const *, v, &z) ; -} diff --git a/src/libstddjb/envalloc_make.c b/src/libstddjb/envalloc_make.c deleted file mode 100644 index f8c459a..0000000 --- a/src/libstddjb/envalloc_make.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ISC license. */ - -#include <skalibs/env.h> -#include <skalibs/genalloc.h> -#include <skalibs/envalloc.h> - -int envalloc_make (genalloc *v, size_t argc, char const *s, size_t len) -{ - int wasnull = !v->s ; - if (!genalloc_readyplus(char const *, v, argc+1)) return 0 ; - if (!env_make(genalloc_s(char const *, v) + genalloc_len(char const *, v), argc, s, len)) - { - if (wasnull) genalloc_free(char const *, v) ; - return 0 ; - } - genalloc_setlen(char const *, v, genalloc_len(char const *, v) + argc) ; - return 1 ; -} diff --git a/src/libstddjb/envalloc_merge.c b/src/libstddjb/envalloc_merge.c deleted file mode 100644 index 2747f50..0000000 --- a/src/libstddjb/envalloc_merge.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ISC license. */ - -#include <skalibs/bytestr.h> -#include <skalibs/env.h> -#include <skalibs/genalloc.h> -#include <skalibs/envalloc.h> - -int envalloc_merge (genalloc *v, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - size_t n = envlen + 1 + byte_count(modifs, modiflen, '\0') ; - if (!genalloc_readyplus(char const *, v, n)) return 0 ; - n = env_merge(genalloc_s(char const *, v) + genalloc_len(char const *, v), n, envp, envlen, modifs, modiflen) ; - genalloc_setlen(char const *, v, genalloc_len(char const *, v) + n) ; - return 1 ; -} diff --git a/src/libstddjb/envalloc_uniq.c b/src/libstddjb/envalloc_uniq.c deleted file mode 100644 index cf60b44..0000000 --- a/src/libstddjb/envalloc_uniq.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <errno.h> -#include <skalibs/bytestr.h> -#include <skalibs/genalloc.h> -#include <skalibs/envalloc.h> - -int envalloc_uniq (genalloc *v, char delim) -{ - unsigned int m = 0 ; - size_t i = 0 ; - for (; i < genalloc_len(char const *, v) ; i++) - { - size_t j = i+1 ; - char const *s = genalloc_s(char const *, v)[i] ; - size_t n = str_chr(s, delim) ; - if (delim && !s[n]) return (errno = EINVAL, -1) ; - for (; j < genalloc_len(char const *, v) ; j++) - { - char const **p = genalloc_s(char const *, v) ; - if (!strncmp(s, p[j], n)) - { - size_t len = genalloc_len(char const *, v) - 1 ; - genalloc_setlen(char const *, v, len) ; - p[j] = p[len] ; - m++ ; - } - } - } - return m ; -} diff --git a/src/libstddjb/envdir.c b/src/libstddjb/envdir.c deleted file mode 100644 index 6992654..0000000 --- a/src/libstddjb/envdir.c +++ /dev/null @@ -1,85 +0,0 @@ -/* ISC license. */ - -#include <unistd.h> -#include <string.h> -#include <errno.h> -#include <skalibs/bytestr.h> -#include <skalibs/env.h> -#include <skalibs/direntry.h> -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> - -#define MAXVARSIZE 4095 - -int envdir_internal (char const *path, stralloc *modifs, unsigned int options, char nullis) -{ - char buf[MAXVARSIZE + 1] ; - unsigned int n = 0 ; - size_t pathlen = strlen(path) ; - size_t modifbase = modifs->len ; - int wasnull = !modifs->s ; - DIR *dir ; - if (!nullis) return (errno = EINVAL, -1) ; - dir = opendir(path) ; - if (!dir) return -1 ; - for (;;) - { - direntry *d ; - size_t len ; - ssize_t r ; - errno = 0 ; - d = readdir(dir) ; - if (!d) break ; - if (d->d_name[0] == '.') continue ; - len = strlen(d->d_name) ; - if (str_chr(d->d_name, '=') < len) continue ; - { - char tmp[pathlen + len + 2] ; - memcpy(tmp, path, pathlen) ; - tmp[pathlen] = '/' ; - memcpy(tmp + pathlen + 1, d->d_name, len + 1) ; - r = openreadnclose(tmp, buf, MAXVARSIZE) ; - } - if (r < 0) - { - if (errno == ENOENT) errno = EIDRM ; - goto err ; - } - else if (r > 0) - { - if (options & SKALIBS_ENVDIR_VERBATIM) - { - if (!(options & SKALIBS_ENVDIR_NOCHOMP) && (buf[r-1] == '\n')) r-- ; - } - else - { - r = byte_chr(buf, r, '\n') ; - if (!(options & SKALIBS_ENVDIR_NOCHOMP)) - { - while (r--) if ((buf[r] != ' ') && (buf[r] != '\t') && (buf[r] != '\r')) break ; - r++ ; - } - } - { - size_t i = 0 ; - for (; i < (size_t)r ; i++) if (!buf[i]) buf[i] = nullis ; - } - buf[r++] = 0 ; - if (!env_addmodif(modifs, d->d_name, buf)) goto err ; - } - else if (!env_addmodif(modifs, d->d_name, 0)) goto err ; - n++ ; - } - if (errno) goto err ; - dir_close(dir) ; - return n ; - - err: - { - int e = errno ; - dir_close(dir) ; - if (wasnull) stralloc_free(modifs) ; else modifs->len = modifbase ; - errno = e ; - return -1 ; - } -} diff --git a/src/libstddjb/pathexec.c b/src/libstddjb/pathexec.c deleted file mode 100644 index da8788c..0000000 --- a/src/libstddjb/pathexec.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -/* MT-unsafe */ - -#include <skalibs/env.h> -#include <skalibs/djbunix.h> -#include <skalibs/posixplz.h> - -void pathexec (char const *const *argv) -{ - pathexec_fromenv(argv, (char const **)environ, env_len((char const **)environ)) ; -} diff --git a/src/libstddjb/pathexec0.c b/src/libstddjb/pathexec0.c deleted file mode 100644 index bfddfdf..0000000 --- a/src/libstddjb/pathexec0.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <unistd.h> -#include <skalibs/djbunix.h> - -void pathexec0 (char const *const *argv) -{ - if (!argv[0]) _exit(0) ; - pathexec(argv) ; -} diff --git a/src/libstddjb/pathexec0_run.c b/src/libstddjb/pathexec0_run.c deleted file mode 100644 index 818877e..0000000 --- a/src/libstddjb/pathexec0_run.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <unistd.h> -#include <skalibs/djbunix.h> - -void pathexec0_run (char const *const *argv, char const *const *envp) -{ - if (!argv[0]) _exit(0) ; - pathexec_run(argv[0], argv, envp) ; -} diff --git a/src/libstddjb/pathexec_fromenv.c b/src/libstddjb/pathexec_fromenv.c deleted file mode 100644 index f9c973b..0000000 --- a/src/libstddjb/pathexec_fromenv.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ISC license. */ - -#include <skalibs/stralloc.h> -#include <skalibs/env.h> -#include <skalibs/djbunix.h> - -static stralloc plus = STRALLOC_ZERO ; - -int pathexec_env (char const *s, char const *t) /* historic, bad name */ -{ - return env_addmodif(&plus, s, t) ; -} - -void pathexec_fromenv (char const *const *argv, char const *const *envp, size_t envlen) -{ - pathexec_r(argv, envp, envlen, plus.s, plus.len) ; -} diff --git a/src/libstddjb/pathexec_r.c b/src/libstddjb/pathexec_r.c deleted file mode 100644 index fe05434..0000000 --- a/src/libstddjb/pathexec_r.c +++ /dev/null @@ -1,8 +0,0 @@ -/* ISC license. */ - -#include <skalibs/djbunix.h> - -void pathexec_r (char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - pathexec_r_name(argv[0], argv, envp, envlen, modifs, modiflen) ; -} diff --git a/src/libstddjb/pathexec_r_name.c b/src/libstddjb/pathexec_r_name.c deleted file mode 100644 index 29c0863..0000000 --- a/src/libstddjb/pathexec_r_name.c +++ /dev/null @@ -1,13 +0,0 @@ -/* ISC license. */ - -#include <skalibs/bytestr.h> -#include <skalibs/env.h> -#include <skalibs/djbunix.h> - -void pathexec_r_name (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - size_t n = envlen + 1 + byte_count(modifs, modiflen, '\0') ; - char const *v[n] ; - if (env_merge(v, n, envp, envlen, modifs, modiflen)) - pathexec_run(file, argv, v) ; -} diff --git a/src/libstddjb/pathexec_run.c b/src/libstddjb/pathexec_run.c deleted file mode 100644 index 5888ba2..0000000 --- a/src/libstddjb/pathexec_run.c +++ /dev/null @@ -1,13 +0,0 @@ -/* ISC license. */ - -#include <stdlib.h> -#include <skalibs/config.h> -#include <skalibs/posixplz.h> -#include <skalibs/djbunix.h> - -void pathexec_run (char const *file, char const *const *argv, char const *const *envp) -{ - char const *path = getenv("PATH") ; - if (!path) path = SKALIBS_DEFAULTPATH ; - execvep(file, argv, envp, path) ; -} diff --git a/src/libstddjb/xexecvep.c b/src/libstddjb/xexecvep.c deleted file mode 100644 index 17a3abf..0000000 --- a/src/libstddjb/xexecvep.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <errno.h> -#include <skalibs/posixplz.h> -#include <skalibs/djbunix.h> -#include <skalibs/strerr2.h> - -void xexecvep (char const *file, char const *const *argv, char const *const *envp, char const *path) -{ - execvep(file, argv, envp, path) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; -} diff --git a/src/libstddjb/xpathexec.c b/src/libstddjb/xpathexec.c deleted file mode 100644 index 473f682..0000000 --- a/src/libstddjb/xpathexec.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <errno.h> - -#include <skalibs/djbunix.h> -#include <skalibs/strerr2.h> - -void xpathexec (char const *const *argv) -{ - pathexec(argv) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; -} diff --git a/src/libstddjb/xpathexec0.c b/src/libstddjb/xpathexec0.c deleted file mode 100644 index ed0848c..0000000 --- a/src/libstddjb/xpathexec0.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <errno.h> - -#include <skalibs/djbunix.h> -#include <skalibs/strerr2.h> - -void xpathexec0 (char const *const *argv) -{ - pathexec0(argv) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; -} diff --git a/src/libstddjb/xpathexec0_run.c b/src/libstddjb/xpathexec0_run.c deleted file mode 100644 index ab3e645..0000000 --- a/src/libstddjb/xpathexec0_run.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <errno.h> - -#include <skalibs/djbunix.h> -#include <skalibs/strerr2.h> - -void xpathexec0_run (char const *const *argv, char const *const *envp) -{ - pathexec0_run(argv, envp) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; -} diff --git a/src/libstddjb/xpathexec_fromenv.c b/src/libstddjb/xpathexec_fromenv.c deleted file mode 100644 index c434331..0000000 --- a/src/libstddjb/xpathexec_fromenv.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <errno.h> - -#include <skalibs/djbunix.h> -#include <skalibs/strerr2.h> - -void xpathexec_fromenv (char const *const *argv, char const *const *envp, size_t envlen) -{ - pathexec_fromenv(argv, envp, envlen) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; -} diff --git a/src/libstddjb/xpathexec_r.c b/src/libstddjb/xpathexec_r.c deleted file mode 100644 index a44fc0f..0000000 --- a/src/libstddjb/xpathexec_r.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <errno.h> - -#include <skalibs/djbunix.h> -#include <skalibs/strerr2.h> - -void xpathexec_r (char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - pathexec_r(argv, envp, envlen, modifs, modiflen) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, argv[0]) ; -} diff --git a/src/libstddjb/xpathexec_r_name.c b/src/libstddjb/xpathexec_r_name.c deleted file mode 100644 index cd118f5..0000000 --- a/src/libstddjb/xpathexec_r_name.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <errno.h> - -#include <skalibs/djbunix.h> -#include <skalibs/strerr2.h> - -void xpathexec_r_name (char const *file, char const *const *argv, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen) -{ - pathexec_r_name(file, argv, envp, envlen, modifs, modiflen) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; -} diff --git a/src/libstddjb/xpathexec_run.c b/src/libstddjb/xpathexec_run.c deleted file mode 100644 index 7c054ee..0000000 --- a/src/libstddjb/xpathexec_run.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <errno.h> - -#include <skalibs/djbunix.h> -#include <skalibs/strerr2.h> - -void xpathexec_run (char const *file, char const *const *argv, char const *const *envp) -{ - pathexec_run(file, argv, envp) ; - strerr_dieexec(errno == ENOENT ? 127 : 126, file) ; -} |