]> Savannah Git Hosting - gnulib.git/commitdiff
backupfile: initialize default suffix within the implementation
authorPádraig Brady <P@draigBrady.com>
Wed, 2 Nov 2016 17:52:12 +0000 (17:52 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 2 Nov 2016 22:59:43 +0000 (22:59 +0000)
* lib/backupfile.c (find_backup_file_name): Initialize the
global variable here, to simplify usage, and to only call
getenv() when needed.

ChangeLog
lib/backupfile.c

index 6e578870a5490b78b73a3a861df6ebd130b9a6ac..fecb478060cbad8ada1f3083d06ba364b5d9b993 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-11-02  Pádraig Brady  <P@draigBrady.com>
+
+       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.
+
 2016-11-01  Paul Eggert  <eggert@cs.ucla.edu>
 
        futimens: remove FIXME for old Linux kernels
index 1fe369eda5923486ec20592cbec06dcc5ad8d990..780d2c9c1f3eeecf94697c614cf7dd99b68bd9c9 100644 (file)
@@ -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;