>From b6bbddad76b64001f05b95b2f18dc40e809354d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?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. --- 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