/*********************************************************
- * Copyright (C) 1998-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2022 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
void const *data, // IN
size_t size); // IN
+Bool
+DynBuf_Insert(DynBuf *b, // IN/OUT
+ size_t offset, // IN
+ void const *data, // IN
+ size_t size); // IN
+
Bool
DynBuf_Trim(DynBuf *b); // IN/OUT
/*********************************************************
- * Copyright (C) 1998-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2022 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
/*
*-----------------------------------------------------------------------------
*
- * DynBuf_Append --
+ * DynBuf_Insert --
*
- * Append data at the end of a dynamic buffer. 'size' is the size of the
- * data. If it is <= 0, no operation is performed --hpreg
+ * Insert data at a given offset within a dynamic buffer. 'size' is the
+ * size of the data. If it is <= 0, no operation is performed.
*
* Results:
* TRUE on success
*/
Bool
-DynBuf_Append(DynBuf *b, // IN/OUT:
+DynBuf_Insert(DynBuf *b, // IN/OUT:
+ size_t offset, // IN:
void const *data, // IN:
size_t size) // IN:
{
size_t new_size;
ASSERT(b);
+ ASSERT(offset <= b->size);
if (size <= 0) {
return TRUE;
}
}
- memcpy(b->data + b->size, data, size);
+ memmove(b->data + offset + size, b->data + offset, b->size - offset);
+ memcpy(b->data + offset, data, size);
b->size = new_size;
return TRUE;
}
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * DynBuf_Append --
+ *
+ * Append data at the end of a dynamic buffer. 'size' is the size of the
+ * data. If it is <= 0, no operation is performed.
+ *
+ * Results:
+ * TRUE on success
+ * FALSE on failure (not enough memory)
+ *
+ * Side effects:
+ * None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+Bool
+DynBuf_Append(DynBuf *b, // IN/OUT:
+ void const *data, // IN:
+ size_t size) // IN:
+{
+ return DynBuf_Insert(b, b->size, data, size);
+}
+
+
/*
*-----------------------------------------------------------------------------
*