nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 8c7e4f51085545cd7fe9bd1efa30bd07a53a4382
parent 1144d38316ec93ade5c83f84affc0316acb40d93
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Fri, 16 Dec 2016 20:34:38 +0100

tweaks: rename a function to describe what it does

It doesn't align anything -- any allocations are already aligned to
whatever multiple is required -- it just shrinks the allocated space.

Diffstat:
Msrc/browser.c | 2+-
Msrc/files.c | 10++++------
Msrc/nano.c | 2+-
Msrc/proto.h | 2+-
Msrc/utils.c | 4++--
5 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/browser.c b/src/browser.c @@ -379,7 +379,7 @@ char *do_browse_from(const char *inpath) napms(1200); return NULL; } else - align(&path); + snuggly_fit(&path); } } diff --git a/src/files.c b/src/files.c @@ -1343,14 +1343,13 @@ char *get_full_path(const char *origpath) /* If we succeeded, canonicalize it in d_here. */ if (d_here != NULL) { - align(&d_here); - /* If the current directory isn't "/", tack a slash onto the end * of it. */ if (strcmp(d_here, "/") != 0) { d_here = charealloc(d_here, strlen(d_here) + 2); strcat(d_here, "/"); - } + } else + snuggly_fit(&d_here); /* Otherwise, set d_here to "". */ } else { d_here = mallocstrcpy(NULL, ""); @@ -1406,14 +1405,13 @@ char *get_full_path(const char *origpath) /* If we succeeded, canonicalize it in d_there. */ if (d_there != NULL) { - align(&d_there); - /* If the current directory isn't "/", tack a slash onto * the end of it. */ if (strcmp(d_there, "/") != 0) { d_there = charealloc(d_there, strlen(d_there) + 2); strcat(d_there, "/"); - } + } else + snuggly_fit(&d_there); /* Otherwise, make sure that we return NULL. */ } else { path_only = TRUE; diff --git a/src/nano.c b/src/nano.c @@ -227,7 +227,7 @@ partition *partition_filestruct(filestruct *top, size_t top_x, /* Remove all text before top_x at the top of the partition. */ charmove(top->data, top->data + top_x, strlen(top->data) - top_x + 1); - align(&top->data); + snuggly_fit(&top->data); /* Return the partition. */ return p; diff --git a/src/proto.h b/src/proto.h @@ -659,7 +659,7 @@ int digits(ssize_t n); #endif bool parse_num(const char *str, ssize_t *val); bool parse_line_column(const char *str, ssize_t *line, ssize_t *column); -void align(char **str); +void snuggly_fit(char **str); void null_at(char **data, size_t index); void unsunder(char *str, size_t true_len); void sunder(char *str); diff --git a/src/utils.c b/src/utils.c @@ -141,8 +141,8 @@ bool parse_line_column(const char *str, ssize_t *line, ssize_t *column) return retval; } -/* Fix the memory allocation for a string. */ -void align(char **str) +/* Reduce the memory allocation of a string to what is needed. */ +void snuggly_fit(char **str) { assert(str != NULL);