diff options
-rwxr-xr-x | etc/flip | 3 | ||||
-rw-r--r-- | etc/flip.c | 31 |
2 files changed, 31 insertions, 3 deletions
diff --git a/etc/flip b/etc/flip deleted file mode 100755 index 614bc67..0000000 --- a/etc/flip +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/perl - -exec (shift @ARGV, pop @ARGV, @ARGV); diff --git a/etc/flip.c b/etc/flip.c new file mode 100644 index 0000000..dcd6bc0 --- /dev/null +++ b/etc/flip.c @@ -0,0 +1,31 @@ +/* + * flip -- put last argument after first argument + * $ cc -O2 -o flip flip.c + */ + +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +int +main(int argc, char *argv[]) +{ + int i; + + if(argc-1 == 0){ + fprintf(stderr, "usage: %s command [arg ...]\n", argv[0]); + return 1; + } + + /* Move last argument after first argument. */ + if(argc-1 > 2){ + for(i = argc; i >= 3; i--) + argv[i] = argv[i-1]; + argv[2] = strdup(argv[argc]); + argv[argc] = NULL; + } + + execvp(argv[1], argv+1); +} |