1
1

Limiting the number of backup files to one hundred thousand, well

before finding a unused filename takes an annoying amount of time.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5225 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
Benno Schulenberg 2015-05-08 21:11:30 +00:00
родитель 55d1e1a9b8
Коммит f111c0d6ab
4 изменённых файлов: 13 добавлений и 27 удалений

Просмотреть файл

@ -2,6 +2,10 @@
* src/browser.c (browser_refresh): Take the distant possibility of
terabyte files into account, and in the bargain get rid of the need
to calculate the number of digits in UINT_MAX.
* src/files.c (get_next_filename): Limit the number of backup files
to one hundred thousand -- which should be far more than enough --
before finding a unused filename takes an annoying amount of time.
* src/utils.c (digits): Delete this now unneeded function.
2015-05-03 Benno Schulenberg <bensberg@justemail.net>
* src/browser.c (browser_refresh): Display an ellipsis only when the

Просмотреть файл

@ -991,20 +991,17 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f)
* extension exists, we return "". */
char *get_next_filename(const char *name, const char *suffix)
{
static int ulmax_digits = -1;
unsigned long i = 0;
char *buf;
size_t namelen, suffixlen;
size_t wholenamelen;
assert(name != NULL && suffix != NULL);
if (ulmax_digits == -1)
ulmax_digits = digits(ULONG_MAX);
wholenamelen = strlen(name) + strlen(suffix);
namelen = strlen(name);
suffixlen = strlen(suffix);
buf = charalloc(namelen + suffixlen + ulmax_digits + 2);
/* Reserve space for: the name plus the suffix plus a dot plus
* possibly five digits plus a null byte. */
buf = charalloc(wholenamelen + 7);
sprintf(buf, "%s%s", name, suffix);
while (TRUE) {
@ -1012,11 +1009,12 @@ char *get_next_filename(const char *name, const char *suffix)
if (stat(buf, &fs) == -1)
return buf;
if (i == ULONG_MAX)
/* Limit the number of backup files to a hundred thousand. */
if (++i == 100000)
break;
i++;
sprintf(buf + namelen + suffixlen, ".%lu", i);
sprintf(buf + wholenamelen, ".%lu", i);
}
/* We get here only if there is no possible save file. Blank out

Просмотреть файл

@ -695,7 +695,6 @@ void do_wordlinechar_count(void);
void do_verbatim_input(void);
/* All functions in utils.c. */
int digits(size_t n);
void get_homedir(void);
bool parse_num(const char *str, ssize_t *val);
bool parse_line_column(const char *str, ssize_t *line, ssize_t *column);

Просмотреть файл

@ -30,21 +30,6 @@
#include <ctype.h>
#include <errno.h>
/* Return the number of decimal digits in n. */
int digits(size_t n)
{
int i;
if (n == 0)
i = 1;
else {
for (i = 0; n != 0; n /= 10, i++)
;
}
return i;
}
/* Return the user's home directory. We use $HOME, and if that fails,
* we fall back on the home directory of the effective user ID. */
void get_homedir(void)