[v2,3/7] support: Add 'touch' command

Message ID 20200805185915.2025314-3-adhemerval.zanella@linaro.org
State Superseded
Headers
Series [v2,1/7] login: Move gnu utmpx to default implementation |

Commit Message

Adhemerval Zanella Aug. 5, 2020, 6:59 p.m. UTC
  It allow creates empty files with an specific mode.
---
 support/test-container.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
  

Patch

diff --git a/support/test-container.c b/support/test-container.c
index e9109f9e3d..b6101b9b94 100644
--- a/support/test-container.c
+++ b/support/test-container.c
@@ -102,6 +102,7 @@  int verbose = 0;
 	 cwd PATH
 	 exec FILE
 	 mkdirp MODE DIR
+	 touch MODE FILE
 
        variables:
 	 $B/ build dir, equivalent to $(common-objpfx)
@@ -127,6 +128,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
@@ -999,6 +1001,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);
+
+		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]);