nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1/*
2 * A wrapper around execlineb, which provides all execline
3 * tools on execlineb’s PATH.
4 * It is implemented as a C program, because on non-Linux,
5 * nested shebang lines are not supported.
6 */
7
8#include <stdlib.h>
9#include <string.h>
10
11#include <skalibs/stralloc.h>
12#include <skalibs/djbunix.h>
13#include <skalibs/strerr2.h>
14#include <skalibs/env.h>
15#include <skalibs/exec.h>
16
17#define dienomem() strerr_diefu1sys(111, "stralloc_catb")
18
19// macros from outside
20/* const char* EXECLINEB_PATH; */
21/* const char* EXECLINE_BIN_PATH; */
22
23int main(int argc, char const* argv[], char const *const *envp)
24{
25 PROG = "execlineb-wrapper";
26
27 char const* path = getenv("PATH");
28 stralloc path_modif = STRALLOC_ZERO;
29
30 // modify PATH if unset or EXECLINEB_BIN_PATH is not yet there
31 if ( !path || ! strstr(path, EXECLINE_BIN_PATH())) {
32 // prepend our execline path
33 if ( ! stralloc_cats(&path_modif, "PATH=")
34 || ! stralloc_cats(&path_modif, EXECLINE_BIN_PATH()) ) dienomem();
35 // old path was not empty
36 if ( path && path[0] ) {
37 if ( ! stralloc_catb(&path_modif, ":", 1)
38 || ! stralloc_cats(&path_modif, path) ) dienomem();
39 }
40 // append final \0
41 if ( ! stralloc_0(&path_modif) ) dienomem();
42 }
43
44 // exec into execlineb and append path_modif to the environment
45 xmexec_aem(
46 EXECLINEB_PATH(),
47 argv,
48 envp,
49 path_modif.s, path_modif.len
50 );
51}