From bb4e152c597837ea05bb9160059152b64312abf9 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 30 Jun 2024 12:49:56 +0300 Subject: [PATCH] (extract_line): optionally return the lengh of the line. Signed-off-by: Andrew Borodin --- lib/util.c | 8 ++++++-- lib/util.h | 2 +- src/usermenu.c | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/util.c b/lib/util.c index 6bbcb5b06..3fb8c54e5 100644 --- a/lib/util.c +++ b/lib/util.c @@ -634,8 +634,8 @@ load_mc_home_file (const char *from, const char *filename, char **allocated_file /* --------------------------------------------------------------------------------------------- */ -const char * -extract_line (const char *s, const char *top) +const const char * +extract_line (const char *s, const char *top, size_t *len) { static char tmp_line[BUF_MEDIUM]; char *t = tmp_line; @@ -643,6 +643,10 @@ extract_line (const char *s, const char *top) while (*s != '\0' && *s != '\n' && (size_t) (t - tmp_line) < sizeof (tmp_line) - 1 && s < top) *t++ = *s++; *t = '\0'; + + if (len != NULL) + *len = (size_t) (t - tmp_line); + return tmp_line; } diff --git a/lib/util.h b/lib/util.h index c03ff6db9..a5be42e9a 100644 --- a/lib/util.h +++ b/lib/util.h @@ -198,7 +198,7 @@ const char *get_group (gid_t gid); const char *get_owner (uid_t uid); /* Returns a copy of *s until a \n is found and is below top */ -const char *extract_line (const char *s, const char *top); +const const char *extract_line (const char *s, const char *top, size_t *len); /* Process spawning */ int my_system (int flags, const char *shell, const char *command); diff --git a/src/usermenu.c b/src/usermenu.c index 21d570480..6081a9bee 100644 --- a/src/usermenu.c +++ b/src/usermenu.c @@ -1149,7 +1149,7 @@ user_menu_cmd (const Widget *edit_widget, const char *menu_file, int selected_en { p = entries[i]; LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0], - extract_line (p, p + MAX_ENTRY_LEN), p, FALSE); + extract_line (p, p + MAX_ENTRY_LEN, NULL), p, FALSE); } /* Select the default entry */ listbox_set_current (listbox->list, selected);