Add an argument to copy commands to set the prefix for the buffer name,

allows buffers for different sessions to be named separately.
This commit is contained in:
nicm
2019-04-02 09:03:39 +00:00
parent ffa4d48967
commit 7bcc0d16f2
6 changed files with 127 additions and 50 deletions

View File

@ -158,11 +158,14 @@ paste_free(struct paste_buffer *pb)
* that the caller is responsible for allocating data.
*/
void
paste_add(char *data, size_t size)
paste_add(const char *prefix, char *data, size_t size)
{
struct paste_buffer *pb, *pb1;
u_int limit;
if (prefix == NULL)
prefix = "buffer";
if (size == 0) {
free(data);
return;
@ -181,7 +184,7 @@ paste_add(char *data, size_t size)
pb->name = NULL;
do {
free(pb->name);
xasprintf(&pb->name, "buffer%04u", paste_next_index);
xasprintf(&pb->name, "%s%u", prefix, paste_next_index);
paste_next_index++;
} while (paste_get_name(pb->name) != NULL);
@ -263,7 +266,7 @@ paste_set(char *data, size_t size, const char *name, char **cause)
return (0);
}
if (name == NULL) {
paste_add(data, size);
paste_add(NULL, data, size);
return (0);
}