Azure IoT common library
Fork of azure_c_shared_utility by
Diff: buffer.c
- Revision:
- 21:b92006c5b9ff
- Parent:
- 19:2e0811512ceb
- Child:
- 27:8656a313842b
--- a/buffer.c Fri Feb 10 17:01:36 2017 -0800 +++ b/buffer.c Fri Feb 24 14:01:41 2017 -0800 @@ -6,6 +6,7 @@ #include <string.h> #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/buffer_.h" +#include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/xlogging.h" typedef struct BUFFER_TAG @@ -39,7 +40,7 @@ if (handleptr->buffer == NULL) { /*Codes_SRS_BUFFER_02_003: [If allocating memory fails, then BUFFER_create shall return NULL.]*/ - result = __LINE__; + result = __FAILURE__; } else { @@ -111,7 +112,7 @@ if (handle == NULL) { /* Codes_SRS_BUFFER_07_009: [BUFFER_build shall return nonzero if handle is NULL ] */ - result = __LINE__; + result = __FAILURE__; } /* Codes_SRS_BUFFER_01_002: [The size argument can be zero, in which case the underlying buffer held by the buffer instance shall be freed.] */ else if (size == 0) @@ -129,7 +130,7 @@ if (source == NULL) { /* Codes_SRS_BUFFER_01_001: [If size is positive and source is NULL, BUFFER_build shall return nonzero] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -139,7 +140,7 @@ if (newBuffer == NULL) { /* Codes_SRS_BUFFER_07_010: [BUFFER_build shall return nonzero if any error is encountered.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -165,12 +166,12 @@ if (handle == NULL) { /* Codes_SRS_BUFFER_07_006: [If handle is NULL or size is 0 then BUFFER_pre_build shall return a nonzero value.] */ - result = __LINE__; + result = __FAILURE__; } else if (size == 0) { /* Codes_SRS_BUFFER_07_006: [If handle is NULL or size is 0 then BUFFER_pre_build shall return a nonzero value.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -178,14 +179,14 @@ if (b->buffer != NULL) { /* Codes_SRS_BUFFER_07_007: [BUFFER_pre_build shall return nonzero if the buffer has been previously allocated and is not NULL.] */ - result = __LINE__; + result = __FAILURE__; } else { if ((b->buffer = (unsigned char*)malloc(size)) == NULL) { /* Codes_SRS_BUFFER_07_013: [BUFFER_pre_build shall return nonzero if any error is encountered.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -204,7 +205,7 @@ if ((handle == NULL) || (content == NULL)) { /* Codes_SRS_BUFFER_07_020: [If the handle and/or content*is NULL BUFFER_content shall return nonzero.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -223,7 +224,7 @@ if (handle == NULL) { /* Codes_SRS_BUFFER_07_014: [BUFFER_unbuild shall return a nonzero value if BUFFER_HANDLE is NULL.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -238,7 +239,7 @@ else { /* Codes_SRS_BUFFER_07_015: [BUFFER_unbuild shall return a nonzero value if the unsigned char* referenced by BUFFER_HANDLE is NULL.] */ - result = __LINE__; + result = __FAILURE__; } } return result; @@ -251,12 +252,12 @@ if (handle == NULL) { /* Codes_SRS_BUFFER_07_017: [BUFFER_enlarge shall return a nonzero result if any parameters are NULL or zero.] */ - result = __LINE__; + result = __FAILURE__; } else if (enlargeSize == 0) { /* Codes_SRS_BUFFER_07_017: [BUFFER_enlarge shall return a nonzero result if any parameters are NULL or zero.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -265,7 +266,7 @@ if (temp == NULL) { /* Codes_SRS_BUFFER_07_018: [BUFFER_enlarge shall return a nonzero result if any error is encountered.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -284,7 +285,7 @@ if ((handle == NULL) || (size == NULL)) { /* Codes_SRS_BUFFER_07_022: [BUFFER_size shall return a nonzero value for any error that is encountered.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -302,7 +303,7 @@ if ( (handle1 == NULL) || (handle2 == NULL) || (handle1 == handle2) ) { /* Codes_SRS_BUFFER_07_023: [BUFFER_append shall return a nonzero upon any error that is encountered.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -311,12 +312,12 @@ if (b1->buffer == NULL) { /* Codes_SRS_BUFFER_07_023: [BUFFER_append shall return a nonzero upon any error that is encountered.] */ - result = __LINE__; + result = __FAILURE__; } else if (b2->buffer == NULL) { /* Codes_SRS_BUFFER_07_023: [BUFFER_append shall return a nonzero upon any error that is encountered.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -332,7 +333,7 @@ if (temp == NULL) { /* Codes_SRS_BUFFER_07_023: [BUFFER_append shall return a nonzero upon any error that is encountered.] */ - result = __LINE__; + result = __FAILURE__; } else { @@ -355,7 +356,7 @@ if ((handle1 == NULL) || (handle2 == NULL) || (handle1 == handle2)) { /* Codes_SRS_BUFFER_01_005: [ BUFFER_prepend shall return a non-zero upon value any error that is encountered. ]*/ - result = __LINE__; + result = __FAILURE__; } else { @@ -364,12 +365,12 @@ if (b1->buffer == NULL) { /* Codes_SRS_BUFFER_01_005: [ BUFFER_prepend shall return a non-zero upon value any error that is encountered. ]*/ - result = __LINE__; + result = __FAILURE__; } else if (b2->buffer == NULL) { /* Codes_SRS_BUFFER_01_005: [ BUFFER_prepend shall return a non-zero upon value any error that is encountered. ]*/ - result = __LINE__; + result = __FAILURE__; } else { @@ -386,7 +387,7 @@ if (temp == NULL) { /* Codes_SRS_BUFFER_01_005: [ BUFFER_prepend shall return a non-zero upon value any error that is encountered. ]*/ - result = __LINE__; + result = __FAILURE__; } else {