coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] mktemp: cut the output info when suffix contains XXX.


From: lvgenggeng
Subject: [PATCH] mktemp: cut the output info when suffix contains XXX.
Date: Tue, 27 Feb 2024 09:41:27 +0800

* src/mktemp.c: When --suffix was supply in cmdline, the template
points to the meraged buffer(dest_name). As X is counted from
template which not contains suffix, So the output should be cut.

Signed-off-by: lvgenggeng <lvgenggeng@uniontech.com>
---
 src/mktemp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/mktemp.c b/src/mktemp.c
index 5f8e5155d..d194aeff5 100644
--- a/src/mktemp.c
+++ b/src/mktemp.c
@@ -156,7 +156,7 @@ main (int argc, char **argv)
   int status = EXIT_SUCCESS;
   size_t x_count;
   size_t suffix_len;
-  char *dest_name;
+  char *dest_name = nullptr;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -255,7 +255,12 @@ main (int argc, char **argv)
     }
   x_count = count_consecutive_X_s (template, suffix - template);
   if (x_count < 3)
-    error (EXIT_FAILURE, 0, _("too few X's in template %s"), quote (template));
+    {
+      /* when suffix was appended to template, template should be cut. */
+      if (template == dest_name)
+        template[suffix - template] = '\0';
+      error (EXIT_FAILURE, 0, _("too few X's in template %s"), quote 
(template));
+    }
 
   if (use_dest_dir)
     {
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]