diff options
-rw-r--r-- | re.c | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -0,0 +1,35 @@ +#include <err.h> +#include <stdio.h> +#include <unistd.h> + +int +main(int argc, char *argv[]) +{ + char ans[10], file[30]; + FILE *fp; + int i; + + if (argc-1 == 0) { + fprintf(stderr, "usage: %s file ...\n", argv[0]); + return 1; + } + + sprintf(file, "/var/tmp/re.%d", getppid()); + + if (!access(file, F_OK)) { + do + fprintf(stderr, "%s already exists; overwrite? ", file); + while (!gets(ans) || !*ans); + if (ans[0] != 'y') return 1; + } + + if (!(fp = fopen(file, "w"))) + err(1, "fopen"); + + for (i = 1; i < argc; i++) { + fprintf(fp, "%s\n", argv[i]); + printf("%s\n", argv[i]); + } + + fclose(fp); +} |