OSSP CVS Repository

ossp - Check-in [4196]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4196
Date: 2001-Jul-09 21:19:37 (local)
2001-Jul-09 19:19:37 (UTC)
User:simons
Branch:
Comment: Implemented xds_setbuffer().
Tickets:
Inspections:
Files:
ossp-pkg/xds/setbuffer.c      1.2 -> 1.3     34 inserted, 2 deleted

ossp-pkg/xds/setbuffer.c 1.2 -> 1.3

--- setbuffer.c  2001/07/09 17:20:56     1.2
+++ setbuffer.c  2001/07/09 19:19:37     1.3
@@ -25,9 +25,41 @@
    SUCH DAMAGE.
 */
 
+#include "assert.h"
 #include "internal.h"
 
-int xds_setbuffer(xds_t* xds, xds_scope_t flag, void*  buffer, size_t  buffer_len)
+int xds_setbuffer(xds_t* xds, xds_scope_t flag, void* buffer, size_t buffer_len)
     {
-    return XDS_ERR_INVALID_ARG;
+    /* Sanity checks. */
+
+    assert(xds != NULL);
+    assert(flag == XDS_GIFT || flag == XDS_LOAN);
+    assert((buffer != NULL && buffer_len != 0) || flag == XDS_GIFT);
+    if (xds == NULL || (flag != XDS_GIFT && flag != XDS_LOAN) ||
+        ((buffer == NULL || buffer_len == 0) && flag == XDS_LOAN))
+        return XDS_ERR_INVALID_ARG;
+
+    /* Free the old buffer if there is one. */
+
+    if (xds->buffer != NULL)
+        free(xds->buffer);
+    xds->buffer_len = 0;
+
+    if (flag == XDS_GIFT)
+        {
+        xds->buffer = buffer;
+        if (buffer == NULL)
+            xds->buffer_capacity = 0;
+        else
+            xds->buffer_capacity = buffer_len;
+        xds->we_own_buffer = (1==1);
+        }
+    else
+        {
+        xds->buffer = buffer;
+        xds->buffer_capacity = buffer_len;
+        xds->we_own_buffer = (1!=1);
+        }
+
+    return XDS_OK;
     }

CVSTrac 2.0.1