aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/top
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-02-20 20:17:54 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-02-20 20:17:54 +0000
commit281bdc30dfd58fdc27455100024bc8591d4e2faa (patch)
tree7b4c536b04bf454aeeef07cd6689e0b69c5b321c /usr.bin/top
parent093295ae49379d4e5f8fb9a04ef4dc10c27143f8 (diff)
downloadsrc-281bdc30dfd58fdc27455100024bc8591d4e2faa.tar.gz
src-281bdc30dfd58fdc27455100024bc8591d4e2faa.zip
Notes
Diffstat (limited to 'usr.bin/top')
-rw-r--r--usr.bin/top/display.c54
1 files changed, 24 insertions, 30 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c
index b17be6e83569..708855fb095f 100644
--- a/usr.bin/top/display.c
+++ b/usr.bin/top/display.c
@@ -378,13 +378,13 @@ u_procstates(int total, int *brkdn)
if (ltotal != total)
{
/* move and overwrite */
-if (x_procstate == 0) {
- Move_to(x_procstate, y_procstate);
-}
-else {
- /* cursor is already there...no motion needed */
- assert(lastline == 1);
-}
+ if (x_procstate == 0) {
+ Move_to(x_procstate, y_procstate);
+ }
+ else {
+ /* cursor is already there...no motion needed */
+ assert(lastline == 1);
+ }
printf("%d", total);
/* if number of digits differs, rewrite the label */
@@ -1205,7 +1205,7 @@ line_update(char *old, char *new, int start, int line)
cursor_on_line = true;
putchar(ch);
*old = ch;
- lastcol = 1;
+ lastcol = start + 1;
}
old++;
@@ -1341,33 +1341,27 @@ i_uptime(struct timeval *bt, time_t *tod)
}
}
+#define SETUPBUFFER_MIN_SCREENWIDTH 80
#define SETUPBUFFER_REQUIRED_ADDBUFSIZ 2
static char *
setup_buffer(char *buffer, int addlen)
{
- char *b = NULL;
-
- if (NULL == buffer) {
- setup_buffer_bufsiz = screen_width;
- b = calloc(setup_buffer_bufsiz + addlen +
- SETUPBUFFER_REQUIRED_ADDBUFSIZ,
- sizeof(char));
- } else {
- if (screen_width > setup_buffer_bufsiz) {
- setup_buffer_bufsiz = screen_width;
- free(buffer);
- b = calloc(setup_buffer_bufsiz + addlen +
- SETUPBUFFER_REQUIRED_ADDBUFSIZ,
- sizeof(char));
- } else {
- b = buffer;
- }
- }
+ size_t len;
- if (NULL == b) {
- errx(4, "can't allocate sufficient memory");
- }
+ setup_buffer_bufsiz = screen_width;
+ if (setup_buffer_bufsiz < SETUPBUFFER_MIN_SCREENWIDTH)
+ {
+ setup_buffer_bufsiz = SETUPBUFFER_MIN_SCREENWIDTH;
+ }
+
+ free(buffer);
+ len = setup_buffer_bufsiz + addlen + SETUPBUFFER_REQUIRED_ADDBUFSIZ;
+ buffer = calloc(len, sizeof(char));
+ if (buffer == NULL)
+ {
+ errx(4, "can't allocate sufficient memory");
+ }
- return b;
+ return buffer;
}