summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-11-02 22:39:30 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-11-02 22:39:30 +0100
commitc438603af996e5ac65d3eb92fd9489257178a5e0 (patch)
tree18ce85ec6af44602a5b948ae4e2de5c1a071b480
parent9a2bef433271cd830d318e5b17efc38ac74e34a3 (diff)
downloadxe-c438603af996e5ac65d3eb92fd9489257178a5e0.tar.gz
xe-c438603af996e5ac65d3eb92fd9489257178a5e0.tar.xz
xe-c438603af996e5ac65d3eb92fd9489257178a5e0.zip
export iteration count as $ITER to the child process
-rw-r--r--README.md3
-rw-r--r--xe.c5
2 files changed, 7 insertions, 1 deletions
diff --git a/README.md b/README.md
index 631d590..ad1aea6 100644
--- a/README.md
+++ b/README.md
@@ -44,6 +44,9 @@ Over apply:
 
 If no argument is passed, default to "printf %s\n".
 
+The current iteration is passed as `$ITER` to the child process
+(increased on every exec()).
+
 ## Return code
 
 Like GNU and OpenBSD xargs:
diff --git a/xe.c b/xe.c
index f9c7206..a17f1a4 100644
--- a/xe.c
+++ b/xe.c
@@ -30,7 +30,7 @@ static int maxatonce = 1;
 static int maxjobs = 1;
 static int runjobs = 0;
 static int Rflag, aflag, kflag, nflag, vflag;
-static int iterations = 0;
+static long iterations = 0;
 
 static char *
 xstrdup(const char *s)
@@ -155,6 +155,9 @@ run(char *cmd[])
 
 	pid = fork();
 	if (pid == 0) {  // in child
+		char iter[32];
+		snprintf(iter, sizeof iter, "%ld", iterations);
+		setenv("ITER", iter, 1);
 		// redirect stdin to /dev/null
 		int fd = open("/dev/null", O_RDONLY);
 		if (fd >= 0) {