Replace a snprintf with format in backup file name generation

This commit is contained in:
Maxime Coste 2015-04-02 13:58:06 +01:00
parent 9edeb08e3a
commit 64e0b6e3f8

View File

@ -231,15 +231,10 @@ void write_buffer_to_backup_file(Buffer& buffer)
StringView dir, file; StringView dir, file;
std::tie(dir,file) = split_path(path); std::tie(dir,file) = split_path(path);
char pattern[PATH_MAX+1]; String pattern = dir.empty() ? format(".{}.kak.XXXXXX", file)
if (not dir.empty()) : format("{}/.{}.kak.XXXXXX", dir, file);
snprintf(pattern, PATH_MAX+1, "%s/.%s.kak.XXXXXX",
(const char*)dir.zstr(), (const char*) file.zstr());
else
snprintf(pattern, PATH_MAX+1, ".%s.kak.XXXXXX",
(const char*)file.zstr());
int fd = mkstemp(pattern); int fd = mkstemp(&pattern[0]);
if (fd >= 0) if (fd >= 0)
{ {
write_buffer_to_fd(buffer, fd); write_buffer_to_fd(buffer, fd);