-/* $OpenBSD: paste.c,v 1.19 2014/05/13 07:34:35 nicm Exp $ */
+/* $OpenBSD: paste.c,v 1.20 2014/05/13 22:54:18 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
int
paste_rename(const char *oldname, const char *newname, char **cause)
{
- struct paste_buffer *pb;
+ struct paste_buffer *pb, *pb_new;
if (cause != NULL)
*cause = NULL;
pb = paste_get_name(oldname);
if (pb == NULL) {
if (cause != NULL)
- xasprintf(cause, "no buffer %s", oldname);
+ xasprintf(cause, "no buffer %s", oldname);
+ return (-1);
+ }
+
+ pb_new = paste_get_name(newname);
+ if (pb_new != NULL) {
+ if (cause != NULL)
+ xasprintf(cause, "buffer %s already exists", newname);
return (-1);
}