Changeset f2d2c604 in mainline for uspace/lib/c/generic/adt/measured_strings.c
- Timestamp:
- 2010-10-27T21:51:14Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 069015f2
- Parents:
- e7f6389 (diff), 0a3fbc7 (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
re7f6389 rf2d2c604 52 52 * @param[in] string The initial character string to be stored. 53 53 * @param[in] length The length of the given string without the terminating 54 * zero (' /0') character. If the length is zero (0), the55 * actuallength is computed. The given length is used and56 * appended with the terminating zero ('\ \0') character54 * zero ('\0') character. If the length is zero, the actual 55 * length is computed. The given length is used and 56 * appended with the terminating zero ('\0') character 57 57 * otherwise. 58 58 * @returns The new bundled character string with measured length. … … 60 60 */ 61 61 measured_string_ref 62 measured_string_create_bulk(const char * 62 measured_string_create_bulk(const char *string, size_t length) 63 63 { 64 64 measured_string_ref new; … … 66 66 if (length == 0) { 67 67 while (string[length]) 68 ++length;68 length++; 69 69 } 70 70 new = (measured_string_ref) malloc(sizeof(measured_string_t) + … … 104 104 new->value[new->length] = '\0'; 105 105 return new; 106 } else {107 free(new);108 106 } 107 free(new); 109 108 } 110 109 … … 156 155 return EINVAL; 157 156 } 158 if (ERROR_OCCURRED(async_data_write_finalize(callid, lengths,159 sizeof(size_t) * (count + 1)))) {157 if (ERROR_OCCURRED(async_data_write_finalize(callid, lengths, 158 length))) { 160 159 free(lengths); 161 160 return ERROR_CODE; … … 163 162 164 163 *data = malloc(lengths[count]); 165 if (! (*data)) {164 if (!*data) { 166 165 free(lengths); 167 166 return ENOMEM; … … 171 170 *strings = (measured_string_ref) malloc(sizeof(measured_string_t) * 172 171 count); 173 if (! (*strings)) {172 if (!*strings) { 174 173 free(lengths); 175 174 free(*data); … … 178 177 179 178 next = *data; 180 for (index = 0; index < count; ++index) {179 for (index = 0; index < count; index++) { 181 180 (*strings)[index].length = lengths[index]; 182 181 if (lengths[index] > 0) { 183 if ( (!async_data_write_receive(&callid, &length)) ||182 if (!async_data_write_receive(&callid, &length) || 184 183 (length != lengths[index])) { 185 184 free(*data); … … 188 187 return EINVAL; 189 188 } 190 ERROR_PROPAGATE(async_data_write_finalize(callid, next, 191 lengths[index])); 189 if (ERROR_OCCURRED(async_data_write_finalize(callid, 190 next, lengths[index]))) { 191 free(*data); 192 free(*strings); 193 free(lengths); 194 return ERROR_CODE; 195 } 192 196 (*strings)[index].value = next; 193 197 next += lengths[index]; 194 *next = '\0'; 195 ++next; 198 *next++ = '\0'; 196 199 } else { 197 200 (*strings)[index].value = NULL; … … 221 224 222 225 length = 0; 223 for (index = 0; index < count; ++ index) {226 for (index = 0; index < count; index++) { 224 227 lengths[index] = strings[index].length; 225 228 length += lengths[index] + 1; … … 262 265 return ENOMEM; 263 266 264 if ( (!async_data_read_receive(&callid, &length)) ||267 if (!async_data_read_receive(&callid, &length) || 265 268 (length != sizeof(size_t) * (count + 1))) { 266 269 free(lengths); 267 270 return EINVAL; 268 271 } 269 if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, 270 sizeof(size_t) * (count + 1)))) { 272 if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, length))) { 271 273 free(lengths); 272 274 return ERROR_CODE; … … 274 276 free(lengths); 275 277 276 for (index = 0; index < count; ++ index) {278 for (index = 0; index < count; index++) { 277 279 if (strings[index].length > 0) { 278 if ((!async_data_read_receive(&callid, &length))||280 if (!async_data_read_receive(&callid, &length) || 279 281 (length != strings[index].length)) { 280 282 return EINVAL; … … 317 319 char *next; 318 320 319 if ((phone < =0) || (!strings) || (!data) || (count <= 0))321 if ((phone < 0) || (!strings) || (!data) || (count <= 0)) 320 322 return EINVAL; 321 323 … … 331 333 332 334 *data = malloc(lengths[count]); 333 if (! (*data)) {335 if (!*data) { 334 336 free(lengths); 335 337 return ENOMEM; … … 338 340 *strings = (measured_string_ref) malloc(sizeof(measured_string_t) * 339 341 count); 340 if (! (*strings)) {342 if (!*strings) { 341 343 free(lengths); 342 344 free(*data); … … 345 347 346 348 next = *data; 347 for (index = 0; index < count; ++ index) {349 for (index = 0; index < count; index++) { 348 350 (*strings)[index].length = lengths[index]; 349 351 if (lengths[index] > 0) { 350 ERROR_PROPAGATE(async_data_read_start(phone, next, 351 lengths[index])); 352 if (ERROR_OCCURRED(async_data_read_start(phone, next, 353 lengths[index]))) { 354 free(lengths); 355 free(data); 356 free(strings); 357 return ERROR_CODE; 358 } 352 359 (*strings)[index].value = next; 353 360 next += lengths[index]; 354 *next = '\0'; 355 ++ next; 361 *next++ = '\0'; 356 362 } else { 357 363 (*strings)[index].value = NULL; … … 386 392 size_t index; 387 393 388 if ((phone < =0) || (!strings) || (count <= 0))394 if ((phone < 0) || (!strings) || (count <= 0)) 389 395 return EINVAL; 390 396 … … 401 407 free(lengths); 402 408 403 for (index = 0; index < count; ++index) {409 for (index = 0; index < count; index++) { 404 410 if (strings[index].length > 0) { 405 411 ERROR_PROPAGATE(async_data_write_start(phone,
Note:
See TracChangeset
for help on using the changeset viewer.