summary refs log tree commit diff
path: root/pkgs/test/make-binary-wrapper/env.c
blob: fa2e6fc4dd29465b966b01caf74548585eeb8586 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// makeCWrapper /hello/world \
    --set PART1 HELLO \
    --set-default PART2 WORLD \
    --unset SOME_OTHER_VARIABLE \
    --set PART3 $'"!!\n"'

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

#define assert_success(e) do { if ((e) < 0) { perror(#e); abort(); } } while (0)

int main(int argc, char **argv) {
    putenv("PART1=HELLO");
    assert_success(setenv("PART2", "WORLD", 0));
    assert_success(unsetenv("SOME_OTHER_VARIABLE"));
    putenv("PART3=\"!!\n\"");
    argv[0] = "/hello/world";
    return execv("/hello/world", argv);
}