now the API to add an history entry has a const argument
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/README.markdown b/README.markdown
index 5edb2b2..41e35c7 100644
--- a/README.markdown
+++ b/README.markdown
@@ -23,7 +23,7 @@ Since it's so young I guess there are a few bugs, or the lib may not compile or
The library is currently less than 400 lines of code. In order to use it in your project just look at the *example.c* file in the source distribution, it is trivial. Linenoise is BSD code, so you can use both in free software and commercial software.
-## Tested in...
+## Tested with...
* Linux text only console ($TERM = linux)
* Linux KDE terminal application ($TERM = xterm)
@@ -31,6 +31,7 @@ The library is currently less than 400 lines of code. In order to use it in your
* Mac OS X iTerm ($TERM = xterm)
* Mac OS X default Terminal.app ($TERM = xterm)
* OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
+ * IBM AIX 6.1
Please test it everywhere you can and report back!
diff --git a/linenoise.c b/linenoise.c
index 5950d49..8139630 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -90,7 +90,7 @@ static int history_len = 0;
char **history = NULL;
static void linenoiseAtExit(void);
-int linenoiseHistoryAdd(char *line);
+int linenoiseHistoryAdd(const char *line);
static void freeHistory(void) {
if (history) {
@@ -357,20 +357,22 @@ char *linenoise(const char *prompt) {
}
/* Using a circular buffer is smarter, but a bit more complex to handle. */
-int linenoiseHistoryAdd(char *line) {
+int linenoiseHistoryAdd(const char *line) {
+ char *linecopy;
+
if (history_max_len == 0) return 0;
if (history == 0) {
history = malloc(sizeof(char*)*history_max_len);
if (history == NULL) return 0;
memset(history,0,(sizeof(char*)*history_max_len));
}
- line = strdup(line);
- if (!line) return 0;
+ linecopy = strdup(line);
+ if (!linecopy) return 0;
if (history_len == history_max_len) {
memmove(history,history+1,sizeof(char*)*(history_max_len-1));
history_len--;
}
- history[history_len] = line;
+ history[history_len] = linecopy;
history_len++;
return 1;
}
diff --git a/linenoise.h b/linenoise.h
index ff45e2c..57bf9d1 100644
--- a/linenoise.h
+++ b/linenoise.h
@@ -35,7 +35,7 @@
#define __LINENOISE_H
char *linenoise(const char *prompt);
-int linenoiseHistoryAdd(char *line);
+int linenoiseHistoryAdd(const char *line);
int linenoiseHistorySetMaxLen(int len);
#endif /* __LINENOISE_H */