Check-in Number:
|
4249 | |
Date: |
2001-Aug-01 11:54:55 (local)
2001-Aug-01 09:54:55 (UTC) |
User: | simons |
Branch: | callback-semantic-rewrite |
Comment: |
- Rewrote callback for the new semantics.
- Deployed the xds_check_arguments() macro. |
Tickets: |
|
Inspections: |
|
Files: |
|
ossp-pkg/xds/xdr-encode-int32.c 1.3 -> 1.3.2.1
--- xdr-encode-int32.c 2001/07/23 15:33:42 1.3
+++ xdr-encode-int32.c 2001/08/01 09:54:55 1.3.2.1
@@ -28,37 +28,44 @@
#include <assert.h>
#include "internal.h"
-int xdr_encode_int32(xds_t* xds, void* engine_context, void* buffer, size_t buffer_size, va_list* args)
+int xdr_encode_int32(xds_t* xds, void* engine_context,
+ void* buffer, size_t buffer_size, size_t* used_buffer_size,
+ va_list* args)
{
+ xds_uint32_t tmp;
+ xds_int32_t value;
+
/* Consistency checks. */
- assert(xds != NULL);
- assert(buffer != NULL);
- assert(buffer_size != 0);
- assert(args != NULL);
- if (xds == NULL || buffer == NULL || buffer_size == 0 || args == NULL)
- return XDS_ERR_INVALID_ARG;
+ xds_check_parameter(xds != NULL);
+ xds_check_parameter(buffer != NULL);
+ xds_check_parameter(buffer_size != 0);
+ xds_check_parameter(used_buffer_size != NULL);
+ xds_check_parameter(args != NULL);
+
+ /* We need 4 bytes in the buffer to format our parameter. If we
+ don't have them, return an overflow error. */
+
+ *used_buffer_size = 4;
+ if (buffer_size < 4)
+ return XDS_ERR_OVERFLOW;
/* Get value and format it into the buffer. */
- if (buffer_size >= 4)
+ value = va_arg(*args, xds_uint32_t);
+ if (value < 0)
{
- xds_uint32_t tmp;
- xds_int32_t value = va_arg(*args, xds_uint32_t);
- if (value < 0)
- {
- value = 0 - value;
- tmp = 0 - (xds_uint32_t)value;
- }
- else
- tmp = (xds_uint32_t)value;
- ((xds_uint8_t*)buffer)[0] = (tmp >> 24) & 0x000000ff;
- ((xds_uint8_t*)buffer)[1] = (tmp >> 16) & 0x000000ff;
- ((xds_uint8_t*)buffer)[2] = (tmp >> 8) & 0x000000ff;
- ((xds_uint8_t*)buffer)[3] = (tmp >> 0) & 0x000000ff;
+ value = 0 - value;
+ tmp = 0 - (xds_uint32_t)value;
}
+ else
+ tmp = (xds_uint32_t)value;
+ ((xds_uint8_t*)buffer)[0] = (tmp >> 24) & 0x000000ff;
+ ((xds_uint8_t*)buffer)[1] = (tmp >> 16) & 0x000000ff;
+ ((xds_uint8_t*)buffer)[2] = (tmp >> 8) & 0x000000ff;
+ ((xds_uint8_t*)buffer)[3] = (tmp >> 0) & 0x000000ff;
/* Done. */
- return 4;
+ return XDS_OK;
}
|
|