From c596c0c4daaf5eb89d05e0e39e425af44474f27e Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 19 Apr 2005 16:32:08 +0000 Subject: [PATCH] miscellaneous bits: make get_next_filename() use an unsigned long, make num_of_digits() take a size_t instead of a ssize_t, and rename num_of_digits() to digits() git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2479 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 6 +++--- src/files.c | 8 ++++---- src/proto.h | 2 +- src/utils.c | 5 +---- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7bf06ff4..c110d6f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,8 +9,8 @@ CVS code - load_open_file() - Remove an unneeded clearok(FALSE). (DLR) get_next_filename() - - Use a long instead of an int for the number prepended to the - filename. (DLR) + - Use an unsigned long instead of an int for the number + prepended to the filename. (DLR) do_browser() - Don't treat NANO_CANCEL_KEY as NANO_EXIT_KEY anymore, for consistency. (DLR) @@ -27,7 +27,7 @@ CVS code - (DLR) - utils.c: num_of_digits() - - Use a ssize_t instead of an int. (DLR) + - Use a size_t instead of an int, and rename to digits(). (DLR) - winio.c: do_help() - Don't treat NANO_CANCEL_KEY as NANO_EXIT_KEY anymore, for diff --git a/src/files.c b/src/files.c index 4e550fdd..df105cd0 100644 --- a/src/files.c +++ b/src/files.c @@ -378,11 +378,11 @@ int open_file(const char *filename, bool newfie, FILE **f) * extension exists, we return "". */ char *get_next_filename(const char *name) { - long i = 0; + unsigned long i = 0; char *buf; size_t namelen = strlen(name); - buf = charalloc(namelen + num_of_digits(LONG_MAX) + 7); + buf = charalloc(namelen + digits(ULONG_MAX) + 7); strcpy(buf, name); strcpy(buf + namelen, ".save"); namelen += 5; @@ -392,11 +392,11 @@ char *get_next_filename(const char *name) if (stat(buf, &fs) == -1) return buf; - if (i == LONG_MAX) + if (i == ULONG_MAX) break; i++; - sprintf(buf + namelen, ".%ld", i); + sprintf(buf + namelen, ".%lu", i); } /* We get here only if there is no possible save file. */ diff --git a/src/proto.h b/src/proto.h index 2b4654a7..c22c37f9 100644 --- a/src/proto.h +++ b/src/proto.h @@ -543,7 +543,7 @@ int safe_regexec(const regex_t *preg, const char *string, size_t nmatch, #endif int regexp_bol_or_eol(const regex_t *preg, const char *string); #endif -int num_of_digits(ssize_t n); +int digits(size_t n); void get_homedir(void); bool parse_num(const char *str, ssize_t *val); void align(char **strp); diff --git a/src/utils.c b/src/utils.c index 450dd78a..1ada9933 100644 --- a/src/utils.c +++ b/src/utils.c @@ -54,13 +54,10 @@ int regexp_bol_or_eol(const regex_t *preg, const char *string) } #endif /* HAVE_REGEX_H */ -int num_of_digits(ssize_t n) +int digits(size_t n) { int i = 1; - if (n < 0) - n = -n; - while (n > 10) { n /= 10; i++; -- 2.39.5