diff mbox series

[18/52] support: Add 'touch' command

Message ID 20210305201518.798584-19-adhemerval.zanella@linaro.org
State New
Headers show
Series Add 64 bit time support on legacy ABIs | expand

Commit Message

Adhemerval Zanella March 5, 2021, 8:14 p.m. UTC
It allow creates empty files with an specific mode.
---
 support/test-container.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/support/test-container.c b/support/test-container.c
index 28cc44d9f1..0d85bfb357 100644
--- a/support/test-container.c
+++ b/support/test-container.c
@@ -104,6 +104,7 @@  int verbose = 0;
 	 cwd PATH
 	 exec FILE
 	 mkdirp MODE DIR
+	 touch MODE FILE
 
        variables:
 	 $B/ build dir, equivalent to $(common-objpfx)
@@ -129,6 +130,7 @@  int verbose = 0;
 	 - 'cwd': set test working directory
 	 - 'exec': change test binary location (may end in /)
 	 - 'mkdirp': A minimal "mkdir -p FILE" command.
+	 - 'touch': A minimal 'touch' command to create empty files.
 
    * mytest.root/postclean.req causes fresh rsync (with delete) after
      test if present
@@ -1018,6 +1020,15 @@  main (int argc, char **argv)
 		TEST_COMPARE (errno, 0);
 		xmkdirp (the_words[2], m);
 	      }
+	    else if (nt == 3 && strcmp (the_words[0], "touch") == 0)
+	      {
+		long int m;
+		errno = 0;
+		m = strtol (the_words[1], NULL, 0);
+		TEST_COMPARE (errno, 0);
+
+		xclose (xopen (the_words[2], O_WRONLY | O_TRUNC | O_CREAT, m));
+	      }
 	    else if (nt > 0 && the_words[0][0] != '#')
 	      {
 		fprintf (stderr, "\033[31minvalid [%s]\033[0m\n", the_words[0]);