From 858f59005a58005117c2af4222ab6d918f67527a Mon Sep 17 00:00:00 2001
From: =?utf8?q?P=C3=A1draig=20Brady?=
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.
---
ChangeLog | 7 +++++++
lib/backupfile.c | 12 +++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 6e578870a5..fecb478060 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2016-11-02 Pádraig Brady
+
+ 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
futimens: remove FIXME for old Linux kernels
diff --git a/lib/backupfile.c b/lib/backupfile.c
index 1fe369eda5..780d2c9c1f 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.39.5