summaryrefslogtreecommitdiff
path: root/src/libstddjb/envdir.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-11-24 21:45:56 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-11-24 21:45:56 +0000
commit18e43565574b700befc832ed4d25d25e40951f68 (patch)
tree2c97774819e99132b10dc60403f43e2034e395f9 /src/libstddjb/envdir.c
parent265092c55d40f362a521eee97676e0d51ef17800 (diff)
downloadskalibs-18e43565574b700befc832ed4d25d25e40951f68.tar.xz
Complete revamp of the pathexec functions
- pathexec_run is now called exec_ae a for provided file name (default: argv[0]) e for provided envp (default: environ) - pathexec is now called mexec. m for merge environment. Option letters are: a for provided file name (default: argv[0]) e for provided envp (default: environ) f for provided envp *and* length of the envp m for provided modif string plus its length (the length is always needed because the modifs are null-terminated) n for provided modif string, length *and* number of modifs - functions have a foo0 version for _exit(0) when argv[0] is null - functions have a xfoo version to die if the exec fails - and a xfoo0 - Compatibility #defines and #includes are there until the next major bump
Diffstat (limited to 'src/libstddjb/envdir.c')
-rw-r--r--src/libstddjb/envdir.c85
1 files changed, 0 insertions, 85 deletions
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 ;
- }
-}