summaryrefslogtreecommitdiff
path: root/gnu/lib/libreadline/histfile.c
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2003-05-08 05:36:52 +0000
committerBob Beck <beck@cvs.openbsd.org>2003-05-08 05:36:52 +0000
commitb1ca941db1b833d9197edd3f2a2ecd1633bc1d81 (patch)
tree544d1f8821bca7e4b0a7cbba9aca8a71efabb8a3 /gnu/lib/libreadline/histfile.c
parent762627a92975f83878f76ab532715c2a26899234 (diff)
strings
ok tedu@, art@
Diffstat (limited to 'gnu/lib/libreadline/histfile.c')
-rw-r--r--gnu/lib/libreadline/histfile.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/gnu/lib/libreadline/histfile.c b/gnu/lib/libreadline/histfile.c
index 0b3135d2a6b..ad200d3051b 100644
--- a/gnu/lib/libreadline/histfile.c
+++ b/gnu/lib/libreadline/histfile.c
@@ -88,6 +88,7 @@ history_filename (filename)
{
char *return_val, *home;
int home_len;
+ char dot;
return_val = filename ? savestring (filename) : (char *)NULL;
@@ -102,15 +103,13 @@ history_filename (filename)
}
home_len = strlen (home);
- return_val = xmalloc (2 + home_len + 8); /* strlen(".history") == 8 */
- strcpy (return_val, home);
- return_val[home_len] = '/';
#if defined (__MSDOS__)
- strcpy (return_val + home_len + 1, "_history");
+ dot = '_';
#else
- strcpy (return_val + home_len + 1, ".history");
+ dot = '.';
#endif
-
+ if (asprintf(&return_val, "%s/%c%s", home, dot, "history") == -1)
+ memory_error_and_abort("asprintf");
return (return_val);
}
@@ -335,7 +334,6 @@ history_do_write (filename, nelements, overwrite)
Suggested by Peter Ho (peter@robosts.oxford.ac.uk). */
{
HIST_ENTRY **the_history; /* local */
- register int j;
int buffer_size;
char *buffer;
@@ -346,12 +344,12 @@ history_do_write (filename, nelements, overwrite)
/* Allocate the buffer, and fill it. */
buffer = xmalloc (buffer_size);
+ buffer[0] = '\0';
- for (j = 0, i = history_length - nelements; i < history_length; i++)
+ for (i = history_length - nelements; i < history_length; i++)
{
- strcpy (buffer + j, the_history[i]->line);
- j += strlen (the_history[i]->line);
- buffer[j++] = '\n';
+ strlcat (buffer, the_history[i]->line, buffer_size);
+ strlcat (buffer, "\n", buffer_size);
}
write (file, buffer, buffer_size);