unarchive 23153
stop

On 05/04/16 15:49, Rishabh Dave wrote:
> Did fix that - changing function call to GNU style and "suffix_from_env" to
> local variable. The corresponding patch is attached.
> 
> On Mon, Apr 4, 2016 at 10:36 PM, Paul Eggert <egg...@cs.ucla.edu> wrote:
> 
>> On 04/04/2016 09:30 AM, Rishabh Dave wrote:
>>
>>> +  char *suffix_from_env;
>>>     size_t ssize;
>>>     bool simple = true;
>>>   +
>>> +  /* If simple_backup_suffix is '~', check environment if we have any
>>> there. */
>>> +  if (strcmp(simple_backup_suffix, "~") == 0)
>>> +    if ((suffix_from_env = getenv("SIMPLE_BACKUP_SUFFIX")) != NULL)
>>> +      simple_backup_suffix = xstrdup (suffix_from_env);
>>> +

Sorry for the delay.

I'll apply the attached variant to gnulib instead.
That has the property that --suffix=~ will still override
an env variable of SIMPLE_BACKUP_SUFFIX.
It also avoids a redundant malloc, and handles empty env variables.

I'll then apply the coreutils patches in your name.

thanks,
Pádraig
>From b6bbddad76b64001f05b95b2f18dc40e809354d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Wed, 2 Nov 2016 17:52:12 +0000
Subject: [PATCH] backupfile: initialize default suffix within the
 implementation

* lib/backupfile.c (find_backup_file_name): Initialize the
global variable here, to simplify usage, and to only call
getenv() when needed.
---
 lib/backupfile.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/backupfile.c b/lib/backupfile.c
index 1fe369e..291faf5 100644
--- a/lib/backupfile.c
+++ b/lib/backupfile.c
@@ -80,7 +80,7 @@
 
 /* The extension added to file names to produce a simple (as opposed
    to numbered) backup file name. */
-char const *simple_backup_suffix = "~";
+char const *simple_backup_suffix = NULL;
 
 
 /* If FILE (which was of length FILELEN before an extension was
@@ -268,6 +268,16 @@ find_backup_file_name (char const *file, enum backup_type backup_type)
   size_t ssize;
   bool simple = true;
 
+  /* Initialize the default simple backup suffix.  */
+  if (! simple_backup_suffix)
+    {
+      char const* env_suffix = getenv ("SIMPLE_BACKUP_SUFFIX");
+      if (env_suffix && *env_suffix)
+        simple_backup_suffix = env_suffix;
+      else
+        simple_backup_suffix = "~";
+    }
+
   /* Allow room for simple or ".~N~" backups.  The guess must be at
      least sizeof ".~1~", but otherwise will be adjusted as needed.  */
   size_t simple_backup_suffix_size = strlen (simple_backup_suffix) + 1;
-- 
2.5.5

Reply via email to