about summary refs log tree commit diff
path: root/pkgs/test/make-binary-wrapper/suffix.c
diff options
context:
space:
mode:
authorTobias Bergkvist <tobias@bergkv.ist>2021-10-04 22:35:09 +0200
committerTobias Bergkvist <tobias@bergkv.ist>2021-10-04 22:35:09 +0200
commitb7d36b8d597df1a9d799fa9d6d8d55137a525570 (patch)
tree716510254e300367537f66567387c9694747c9b3 /pkgs/test/make-binary-wrapper/suffix.c
parentadef70ce7c964e0d1d9d961783036541323b06a7 (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.c33
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 0000000000000..865d76fe34e2a
--- /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