diff options
author | Tobias Bergkvist <tobias@bergkv.ist> | 2021-10-04 22:35:09 +0200 |
---|---|---|
committer | Tobias Bergkvist <tobias@bergkv.ist> | 2021-10-04 22:35:09 +0200 |
commit | b7d36b8d597df1a9d799fa9d6d8d55137a525570 (patch) | |
tree | 716510254e300367537f66567387c9694747c9b3 /pkgs/test/make-binary-wrapper/suffix.c | |
parent | adef70ce7c964e0d1d9d961783036541323b06a7 (diff) |
Add golden tests for make-binary-wrapper.
To run tests after cloning on linux, use the following:
nix-build pkgs/top-level/release.nix -A tests.make-binary-wrapper.x86_64-linux
Diffstat (limited to 'pkgs/test/make-binary-wrapper/suffix.c')
-rw-r--r-- | pkgs/test/make-binary-wrapper/suffix.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/pkgs/test/make-binary-wrapper/suffix.c b/pkgs/test/make-binary-wrapper/suffix.c new file mode 100644 index 000000000000..865d76fe34e2 --- /dev/null +++ b/pkgs/test/make-binary-wrapper/suffix.c @@ -0,0 +1,33 @@ +// makeCWrapper /path/to/executable \ + --suffix PATH : /usr/bin/ \ + --suffix PATH : /usr/local/bin/ + +#include <unistd.h> +#include <stdlib.h> +#include <string.h> + +char *concat3(char *x, char *y, char *z) { + int xn = strlen(x); + int yn = strlen(y); + int zn = strlen(z); + char *res = malloc(sizeof(*res)*(xn + yn + zn + 1)); + strncpy(res, x, xn); + strncpy(res + xn, y, yn); + strncpy(res + xn + yn, z, zn); + res[xn + yn + zn] = '\0'; + return res; +} + +void set_env_suffix(char *env, char *sep, char *val) { + char *existing = getenv(env); + if (existing) val = concat3(existing, sep, val); + setenv(env, val, 1); + if (existing) free(val); +} + +int main(int argc, char **argv) { + set_env_suffix("PATH", ":", "/usr/bin/"); + set_env_suffix("PATH", ":", "/usr/local/bin/"); + argv[0] = "/path/to/executable"; + return execv("/path/to/executable", argv); +}
\ No newline at end of file |