diff options
author | Pádraig Brady <P@draigBrady.com> | 2016-11-02 17:52:12 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2016-11-02 22:59:43 +0000 |
commit | 858f59005a58005117c2af4222ab6d918f67527a (patch) | |
tree | f3d3c58a64b38336e49fa71ab9f9ca6994fbf1ed /lib/backupfile.c | |
parent | 35a51f8031317f5571c5338b60b5457fc9a14cc8 (diff) | |
download | gnulib-858f59005a58005117c2af4222ab6d918f67527a.tar.gz |
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.
Diffstat (limited to 'lib/backupfile.c')
-rw-r--r-- | lib/backupfile.c | 12 |
1 files changed, 11 insertions, 1 deletions
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; |