[master] 892264e01 Add "filewrite" command to put strings into a file

Poul-Henning Kamp phk at FreeBSD.org
Tue Jun 28 08:53:07 UTC 2022


commit 892264e019862a93a91ae7cd96b352aa61f93eec
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Jun 28 08:01:22 2022 +0000

    Add "filewrite" command to put strings into a file

diff --git a/bin/varnishtest/cmds.h b/bin/varnishtest/cmds.h
index 8afee5140..dfc097570 100644
--- a/bin/varnishtest/cmds.h
+++ b/bin/varnishtest/cmds.h
@@ -44,6 +44,7 @@ CMD_GLOBAL(shell)
 #endif
 CMD_TOP(client)
 CMD_TOP(feature)
+CMD_TOP(filewrite)
 CMD_TOP(haproxy)
 #ifdef VTEST_WITH_VTC_LOGEXPECT
 CMD_TOP(logexpect)
diff --git a/bin/varnishtest/vtc_misc.c b/bin/varnishtest/vtc_misc.c
index 59bde405f..3eef2a5fe 100644
--- a/bin/varnishtest/vtc_misc.c
+++ b/bin/varnishtest/vtc_misc.c
@@ -246,6 +246,34 @@ cmd_shell(CMD_ARGS)
 	cmd_shell_engine(vl, ok, av[n], expect, re);
 }
 
+/* SECTION: filewrite filewrite
+ *
+ * Write strings to file
+ *
+ *         filewrite /somefile "Hello" " " "World\n"
+ *
+ */
+
+void v_matchproto_(cmd_f)
+cmd_filewrite(CMD_ARGS)
+{
+	FILE *fo;
+	int n;
+
+	(void)priv;
+
+	if (av == NULL)
+		return;
+	if (av[1] == NULL)
+		vtc_fatal(vl, "Need filename");
+        fo = fopen(av[1], "w");
+	if (fo == NULL)
+		vtc_fatal(vl, "Cannot open %s: %s", av[1], strerror(errno));
+	for (n = 2; av[n] != NULL; n++)
+		fputs(av[n], fo);
+	AZ(fclose(fo));
+}
+
 /* SECTION: setenv setenv
  *
  * Set or change an environment variable::


More information about the varnish-commit mailing list