Changeset 745 for trunk/server/lib/util/data_blob.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/lib/util/data_blob.c
r414 r745 34 34 _PUBLIC_ DATA_BLOB data_blob_named(const void *p, size_t length, const char *name) 35 35 { 36 return data_blob_talloc_named(NULL, p, length, name); 37 } 38 39 /** 40 construct a data blob, using supplied TALLOC_CTX 41 **/ 42 _PUBLIC_ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name) 43 { 36 44 DATA_BLOB ret; 37 45 … … 42 50 43 51 if (p) { 44 ret.data = (uint8_t *)talloc_memdup( NULL, p, length);52 ret.data = (uint8_t *)talloc_memdup(mem_ctx, p, length); 45 53 } else { 46 ret.data = talloc_array( NULL, uint8_t, length);54 ret.data = talloc_array(mem_ctx, uint8_t, length); 47 55 } 48 56 if (ret.data == NULL) { … … 52 60 talloc_set_name_const(ret.data, name); 53 61 ret.length = length; 54 return ret;55 }56 57 /**58 construct a data blob, using supplied TALLOC_CTX59 **/60 _PUBLIC_ DATA_BLOB data_blob_talloc_named(TALLOC_CTX *mem_ctx, const void *p, size_t length, const char *name)61 {62 DATA_BLOB ret = data_blob_named(p, length, name);63 64 if (ret.data) {65 talloc_steal(mem_ctx, ret.data);66 }67 return ret;68 }69 70 71 /**72 reference a data blob, to the supplied TALLOC_CTX.73 Returns a NULL DATA_BLOB on failure74 **/75 _PUBLIC_ DATA_BLOB data_blob_talloc_reference(TALLOC_CTX *mem_ctx, DATA_BLOB *blob)76 {77 DATA_BLOB ret = *blob;78 79 ret.data = talloc_reference(mem_ctx, blob->data);80 81 if (!ret.data) {82 return data_blob(NULL, 0);83 }84 62 return ret; 85 63 } … … 154 132 print the data_blob as hex string 155 133 **/ 156 _PUBLIC_ char *data_blob_hex_string (TALLOC_CTX *mem_ctx, const DATA_BLOB *blob)134 _PUBLIC_ char *data_blob_hex_string_lower(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) 157 135 { 158 136 int i; … … 174 152 } 175 153 154 _PUBLIC_ char *data_blob_hex_string_upper(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob) 155 { 156 int i; 157 char *hex_string; 158 159 hex_string = talloc_array(mem_ctx, char, (blob->length*2)+1); 160 if (!hex_string) { 161 return NULL; 162 } 163 164 for (i = 0; i < blob->length; i++) 165 slprintf(&hex_string[i*2], 3, "%02X", blob->data[i]); 166 167 hex_string[(blob->length*2)] = '\0'; 168 return hex_string; 169 } 170 176 171 /** 177 172 useful for constructing data blobs in test suites, while
Note:
See TracChangeset
for help on using the changeset viewer.