coreutils
[Top][All Lists]
Advanced

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

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


From: Pádraig Brady
Subject: Re: [PATCH] mktemp: cut the output info when suffix contains XXX.
Date: Tue, 27 Feb 2024 15:05:54 +0000
User-agent: Mozilla Thunderbird

On 27/02/2024 01:41, lvgenggeng wrote:
* 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)
      {

Right. That would be especially confusing with:

  $ mktemp -u --suffix=XX template.X
  mktemp: too few X's in template ‘template.XXX’

I adjusted the mktemp test, added a NEWS entry and pushed:
https://github.com/coreutils/coreutils/commit/e397ba1a3

thanks!
Pádraig.



reply via email to

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