aboutsummaryrefslogtreecommitdiffstats
path: root/main/asterisk.c
diff options
context:
space:
mode:
authorseanbright <seanbright@f38db490-d61c-443f-a65b-d21fe96a405b>2008-10-04 16:20:31 +0000
committerseanbright <seanbright@f38db490-d61c-443f-a65b-d21fe96a405b>2008-10-04 16:20:31 +0000
commit7cc3a7c2b914043881a1fa2c40dc43d3b6fbe5d5 (patch)
tree47979cc3ae7d1376e27a2ab561595b0c702fe234 /main/asterisk.c
parent023c9edb1c9a9649154a9c0530eee441f74a3c5b (diff)
Fix a bug with the last item in CLI history getting duplicated when
read from the .asterisk_history file (and subsequently being duplicated when written). We weren't checking the result of fgets() which meant that we read the same line twice before feof() actually returned non- zero. Also, stop writing out an extra blank line between each item in the history file, fix a minor off-by-one error, and use symbolic constants rather than a hardcoded integer. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@146359 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/asterisk.c')
-rw-r--r--main/asterisk.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 0aa9f9a3d..6f04c82c7 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2371,15 +2371,17 @@ static int ast_el_initialize(void)
return 0;
}
+#define MAX_HISTORY_COMMAND_LENGTH 256
+
static int ast_el_add_history(char *buf)
{
HistEvent ev;
if (el_hist == NULL || el == NULL)
ast_el_initialize();
- if (strlen(buf) > 256)
+ if (strlen(buf) > (MAX_HISTORY_COMMAND_LENGTH - 1))
return 0;
- return (history(el_hist, &ev, H_ENTER, buf));
+ return (history(el_hist, &ev, H_ENTER, ast_strip(ast_strdupa(buf))));
}
static int ast_el_write_history(char *filename)
@@ -2394,7 +2396,7 @@ static int ast_el_write_history(char *filename)
static int ast_el_read_history(char *filename)
{
- char buf[256];
+ char buf[MAX_HISTORY_COMMAND_LENGTH];
FILE *f;
int ret = -1;
@@ -2405,7 +2407,8 @@ static int ast_el_read_history(char *filename)
return ret;
while (!feof(f)) {
- fgets(buf, sizeof(buf), f);
+ if (!fgets(buf, sizeof(buf), f))
+ break;
if (!strcmp(buf, "_HiStOrY_V2_\n"))
continue;
if (ast_all_zeros(buf))