aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-10 15:57:35 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-10 15:57:35 +0200
commit25f9384a066b0afe0eaefc96c6e9360b81833ddd (patch)
tree806feab4f4769cf0153f1ed595aed997d706fbe9
parent7720853b49c01e85a22c7e9fc59a31156494807d (diff)
downloadre-name-25f9384a066b0afe0eaefc96c6e9360b81833ddd.tar.gz
Add re
-rw-r--r--re.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/re.c b/re.c
new file mode 100644
index 0000000..07b6846
--- /dev/null
+++ b/re.c
@@ -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);
+}