Changeset b5e68c8 in mainline for uspace/lib/c/generic/adt/measured_strings.c
- Timestamp:
- 2011-05-12T16:49:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f36787d7
- Parents:
- e80329d6 (diff), 750636a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/measured_strings.c
re80329d6 rb5e68c8 41 41 #include <unistd.h> 42 42 #include <errno.h> 43 #include <err.h>44 43 #include <async.h> 45 44 … … 56 55 * appended with the terminating zero ('\0') character 57 56 * otherwise. 58 * @return sThe new bundled character string with measured length.59 * @return sNULL if there is not enough memory left.60 */ 61 measured_string_ ref62 measured_string_create_bulk(const char*string, size_t length)63 { 64 measured_string_ refnew;57 * @return The new bundled character string with measured length. 58 * @return NULL if there is not enough memory left. 59 */ 60 measured_string_t * 61 measured_string_create_bulk(const uint8_t *string, size_t length) 62 { 63 measured_string_t *new; 65 64 66 65 if (length == 0) { … … 68 67 length++; 69 68 } 70 new = (measured_string_ ref) malloc(sizeof(measured_string_t) +71 (sizeof( char) * (length + 1)));69 new = (measured_string_t *) malloc(sizeof(measured_string_t) + 70 (sizeof(uint8_t) * (length + 1))); 72 71 if (!new) 73 72 return NULL; 74 73 75 74 new->length = length; 76 new->value = (( char*) new) + sizeof(measured_string_t);77 / / append terminating zero explicitly - to be safe75 new->value = ((uint8_t *) new) + sizeof(measured_string_t); 76 /* Append terminating zero explicitly - to be safe */ 78 77 memcpy(new->value, string, new->length); 79 78 new->value[new->length] = '\0'; … … 85 84 * 86 85 * @param[in] source The source measured string to be copied. 87 * @return sThe copy of the given measured string.88 * @return sNULL if the source parameter is NULL.89 * @return sNULL if there is not enough memory left.90 */ 91 measured_string_ ref measured_string_copy(measured_string_refsource)92 { 93 measured_string_ refnew;86 * @return The copy of the given measured string. 87 * @return NULL if the source parameter is NULL. 88 * @return NULL if there is not enough memory left. 89 */ 90 measured_string_t *measured_string_copy(measured_string_t *source) 91 { 92 measured_string_t *new; 94 93 95 94 if (!source) 96 95 return NULL; 97 96 98 new = (measured_string_ ref) malloc(sizeof(measured_string_t));97 new = (measured_string_t *) malloc(sizeof(measured_string_t)); 99 98 if (new) { 100 new->value = ( char*) malloc(source->length + 1);99 new->value = (uint8_t *) malloc(source->length + 1); 101 100 if (new->value) { 102 101 new->length = source->length; … … 121 120 * actual character strings. 122 121 * @param[in] count The size of the measured strings array. 123 * @return sEOK on success.124 * @return sEINVAL if the strings or data parameter is NULL.125 * @return sEINVAL if the count parameter is zero (0).126 * @return sEINVAL if the sent array differs in size.127 * @return sEINVAL if there is inconsistency in sent measured122 * @return EOK on success. 123 * @return EINVAL if the strings or data parameter is NULL. 124 * @return EINVAL if the count parameter is zero (0). 125 * @return EINVAL if the sent array differs in size. 126 * @return EINVAL if there is inconsistency in sent measured 128 127 * strings' lengths (should not occur). 129 * @return sENOMEM if there is not enough memory left.130 * @return sOther error codes as defined for the128 * @return ENOMEM if there is not enough memory left. 129 * @return Other error codes as defined for the 131 130 * async_data_write_finalize() function. 132 131 */ 133 132 int 134 measured_strings_receive(measured_string_ ref *strings, char**data,133 measured_strings_receive(measured_string_t **strings, uint8_t **data, 135 134 size_t count) 136 135 { 137 ERROR_DECLARE;138 139 136 size_t *lengths; 140 137 size_t index; 141 138 size_t length; 142 char*next;139 uint8_t *next; 143 140 ipc_callid_t callid; 141 int rc; 144 142 145 143 if ((!strings) || (!data) || (count <= 0)) … … 155 153 return EINVAL; 156 154 } 157 if (ERROR_OCCURRED(async_data_write_finalize(callid, lengths,158 length))) {159 free(lengths); 160 return ERROR_CODE;155 rc = async_data_write_finalize(callid, lengths, length); 156 if (rc != EOK) { 157 free(lengths); 158 return rc; 161 159 } 162 160 … … 168 166 (*data)[lengths[count] - 1] = '\0'; 169 167 170 *strings = (measured_string_ ref) malloc(sizeof(measured_string_t) *168 *strings = (measured_string_t *) malloc(sizeof(measured_string_t) * 171 169 count); 172 170 if (!*strings) { … … 187 185 return EINVAL; 188 186 } 189 if (ERROR_OCCURRED(async_data_write_finalize(callid, 190 next, lengths[index]))) { 187 rc = async_data_write_finalize(callid, next, 188 lengths[index]); 189 if (rc != EOK) { 191 190 free(*data); 192 191 free(*strings); 193 192 free(lengths); 194 return ERROR_CODE;193 return rc; 195 194 } 196 195 (*strings)[index].value = next; … … 210 209 * @param[in] strings The measured strings array to be processed. 211 210 * @param[in] count The measured strings array size. 212 * @return sThe computed sizes array.213 * @return sNULL if there is not enough memory left.214 */ 215 static size_t *prepare_lengths(const measured_string_ refstrings, size_t count)211 * @return The computed sizes array. 212 * @return NULL if there is not enough memory left. 213 */ 214 static size_t *prepare_lengths(const measured_string_t *strings, size_t count) 216 215 { 217 216 size_t *lengths; … … 239 238 * @param[in] strings The measured strings array to be transferred. 240 239 * @param[in] count The measured strings array size. 241 * @return sEOK on success.242 * @return sEINVAL if the strings parameter is NULL.243 * @return sEINVAL if the count parameter is zero (0).244 * @return sEINVAL if the calling module does not accept the given240 * @return EOK on success. 241 * @return EINVAL if the strings parameter is NULL. 242 * @return EINVAL if the count parameter is zero (0). 243 * @return EINVAL if the calling module does not accept the given 245 244 * array size. 246 * @return sEINVAL if there is inconsistency in sent measured245 * @return EINVAL if there is inconsistency in sent measured 247 246 * strings' lengths (should not occur). 248 * @return sOther error codes as defined for the247 * @return Other error codes as defined for the 249 248 * async_data_read_finalize() function. 250 249 */ 251 int measured_strings_reply(const measured_string_ref strings, size_t count) 252 { 253 ERROR_DECLARE; 254 250 int measured_strings_reply(const measured_string_t *strings, size_t count) 251 { 255 252 size_t *lengths; 256 253 size_t index; 257 254 size_t length; 258 255 ipc_callid_t callid; 256 int rc; 259 257 260 258 if ((!strings) || (count <= 0)) … … 270 268 return EINVAL; 271 269 } 272 if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, length))) { 273 free(lengths); 274 return ERROR_CODE; 270 rc = async_data_read_finalize(callid, lengths, length); 271 if (rc != EOK) { 272 free(lengths); 273 return rc; 275 274 } 276 275 free(lengths); … … 282 281 return EINVAL; 283 282 } 284 ERROR_PROPAGATE(async_data_read_finalize(callid, 285 strings[index].value, strings[index].length)); 283 rc = async_data_read_finalize(callid, 284 strings[index].value, strings[index].length); 285 if (rc != EOK) 286 return rc; 286 287 } 287 288 } … … 301 302 * actual character strings. 302 303 * @param[in] count The size of the measured strings array. 303 * @return sEOK on success.304 * @return sEINVAL if the strings or data parameter is NULL.305 * @return sEINVAL if the phone or count parameter is not positive.306 * @return sEINVAL if the sent array differs in size.307 * @return sENOMEM if there is not enough memory left.308 * @return sOther error codes as defined for the304 * @return EOK on success. 305 * @return EINVAL if the strings or data parameter is NULL. 306 * @return EINVAL if the phone or count parameter is not positive. 307 * @return EINVAL if the sent array differs in size. 308 * @return ENOMEM if there is not enough memory left. 309 * @return Other error codes as defined for the 309 310 * async_data_read_start() function. 310 311 */ 311 312 int 312 measured_strings_return(int phone, measured_string_ ref *strings, char**data,313 measured_strings_return(int phone, measured_string_t **strings, uint8_t **data, 313 314 size_t count) 314 315 { 315 ERROR_DECLARE;316 317 316 size_t *lengths; 318 317 size_t index; 319 char *next; 318 uint8_t *next; 319 int rc; 320 320 321 321 if ((phone < 0) || (!strings) || (!data) || (count <= 0)) … … 326 326 return ENOMEM; 327 327 328 if (ERROR_OCCURRED(async_data_read_start(phone, lengths, 329 sizeof(size_t) * (count + 1)))) { 330 free(lengths); 331 return ERROR_CODE; 328 rc = async_data_read_start(phone, lengths, 329 sizeof(size_t) * (count + 1)); 330 if (rc != EOK) { 331 free(lengths); 332 return rc; 332 333 } 333 334 … … 338 339 } 339 340 340 *strings = (measured_string_ ref) malloc(sizeof(measured_string_t) *341 *strings = (measured_string_t *) malloc(sizeof(measured_string_t) * 341 342 count); 342 343 if (!*strings) { … … 350 351 (*strings)[index].length = lengths[index]; 351 352 if (lengths[index] > 0) { 352 if (ERROR_OCCURRED(async_data_read_start(phone, next,353 lengths[index]))) {353 rc = async_data_read_start(phone, next, lengths[index]); 354 if (rc != EOK) { 354 355 free(lengths); 355 356 free(data); 356 357 free(strings); 357 return ERROR_CODE;358 return rc; 358 359 } 359 360 (*strings)[index].value = next; … … 377 378 * @param[in] strings The measured strings array to be transferred. 378 379 * @param[in] count The measured strings array size. 379 * @return sEOK on success.380 * @return sEINVAL if the strings parameter is NULL.381 * @return sEINVAL if the phone or count parameter is not positive.382 * @return sOther error codes as defined for the380 * @return EOK on success. 381 * @return EINVAL if the strings parameter is NULL. 382 * @return EINVAL if the phone or count parameter is not positive. 383 * @return Other error codes as defined for the 383 384 * async_data_write_start() function. 384 385 */ 385 386 int 386 measured_strings_send(int phone, const measured_string_ refstrings,387 measured_strings_send(int phone, const measured_string_t *strings, 387 388 size_t count) 388 389 { 389 ERROR_DECLARE;390 391 390 size_t *lengths; 392 391 size_t index; 392 int rc; 393 393 394 394 if ((phone < 0) || (!strings) || (count <= 0)) … … 399 399 return ENOMEM; 400 400 401 if (ERROR_OCCURRED(async_data_write_start(phone, lengths, 402 sizeof(size_t) * (count + 1)))) { 403 free(lengths); 404 return ERROR_CODE; 401 rc = async_data_write_start(phone, lengths, 402 sizeof(size_t) * (count + 1)); 403 if (rc != EOK) { 404 free(lengths); 405 return rc; 405 406 } 406 407 … … 409 410 for (index = 0; index < count; index++) { 410 411 if (strings[index].length > 0) { 411 ERROR_PROPAGATE(async_data_write_start(phone, 412 strings[index].value, strings[index].length)); 412 rc = async_data_write_start(phone, strings[index].value, 413 strings[index].length); 414 if (rc != EOK) 415 return rc; 413 416 } 414 417 }
Note:
See TracChangeset
for help on using the changeset viewer.